korgwm/Config.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« korgwm/Screen.pm ↑ Summary korgwm/Tag.pm »
1 #!/usr/bin/perl
2 # made by: KorG
3 # vim: cc=119 et sw=4 ts=4 :
4 package X11::korgwm::Config;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 0 ▶use YAML::Tiny;
Subroutine BEGIN: called CC=1 SCAR=2.6
10 use X11::korgwm::Common;
11  
12 BEGIN {
13 # Default values
14 $cfg->{debug} = 0;
15 $cfg->{api_host} = "127.0.0.1";
16  
17 ## This may be way too complicated, but thus I'm sure it won't be exploited. Resolves EADDRINUSE
18 $cfg->{api_port} = ($ENV{KORGWM_DEBUG_PORT} // "") =~ m/^(\d+)$/s ? $1 : 27015;
19  
20 $cfg->{api_timeout} = 5;
21 $cfg->{battery_charging_character} = chr(0x2234);
22 $cfg->{battery_format} = "%s";
23 $cfg->{battery_hide_charged} = 1;
24 $cfg->{border_width} = 1;
25 $cfg->{clock_format} = " %a %e %B %H:%M";
26 $cfg->{color_battery_low} = '0xFF0000';
27 $cfg->{color_bg} = '0x262729';
28 $cfg->{color_border_focus} = '0xA3BABF';
29 $cfg->{color_border} = '0x232426';
30 $cfg->{color_expose} = '0x232426';
31 $cfg->{color_fg} = '0xA3BABF';
32 $cfg->{color_urgent_bg} = '0xFFFF00';
33 $cfg->{color_urgent_fg} = '0x464729';
34 $cfg->{color_append_bg} = '0x262729';
35 $cfg->{color_append_fg} = '0xF502C8';
36 $cfg->{expose_spacing} = 15;
37 $cfg->{expose_show_id} = 1;
38 $cfg->{font} = "DejaVu Sans Mono 10";
39 $cfg->{hide_empty_tags} = 1;
40 $cfg->{tag_rotate} = 1;
41 $cfg->{initial_pointer_position} = "center"; # values: undef, "center", "hidden"
42 $cfg->{lang_format} = " %s ";
43 $cfg->{lang_names} = { 0 => chr(0x00a3), 1 => chr(0x20bd) };
44 $cfg->{mouse_follow} = 1;
45 $cfg->{mouse_nowarp} = 0;
46 $cfg->{move_follow} = 1;
47 $cfg->{warp_ignore_korgwm} = 1;
48 $cfg->{notification_server} = 1;
49 $cfg->{panel_end} = [qw( battery clock lang )];
50 $cfg->{panel_height} = 20;
51 $cfg->{panel_hide} = undef;
52 $cfg->{randr_cmd} = "korgwm_xrandr || xrandr --auto";
53 $cfg->{set_root_color} = 0;
54 $cfg->{setxkb_evdev} = 1;
55 $cfg->{title_max_len} = 128;
56 $cfg->{ws_names} = [qw( 1 2 3 4 5 6 7 8 9 )];
57  
58 # Default keyboard layout
59 $cfg->{hotkeys} = {
60 (map {; "mod_$_" => "focus_move($_)" } qw(h j k l)),
61 (map {; "mod_$_" => "tag_select($_)" } 1..9),
62 (map {; "mod_F$_" => "screen_select($_)" } 1..9),
63 (map {; "mod_ctrl_$_" => "tag_append($_)" } 1..9),
64 (map {; "mod_ctrl_$_" => "layout_resize($_)" } qw(h j k l)),
65 (map {; "mod_shift_$_" => "focus_swap($_)" } qw(h j k l)),
66 (map {; "mod_shift_$_" => "win_move_tag($_)" } 1..9),
67 (map {; "mod_shift_F$_" => "win_move_screen($_)" } 1..9),
68 "alt_F4" => "win_close()",
69 "mod_shift_c" => "win_close()",
70 "mod_TAB" => "focus_prev()",
71 "alt_TAB" => "focus_cycle(forward)",
72 "alt_shift_TAB" => "focus_cycle(backward)",
73 "mod_CR" => "exec(xkb-switch -s us; urxvt)",
74 "mod_shift_CR" => "exec(xkb-switch -s us; urxvt -name urxvt-float -g 120x32)",
75 "mod_a" => "win_toggle_always_on()",
76 "mod_shift_ctrl_l" => "exec(lock)",
77 "mod_e" => "expose()",
78 "mod_shift_s" => "mark_window()",
79 "mod_s" => "mark_switch_window()",
80 "mod_f" => "win_toggle_floating()",
81 "mod_p" => "win_toggle_pinned()",
82 "mod_g" => "exec(google-chrome --simulate-outdated-no-au --new-window --incognito)",
83 "mod_shift_g" => "exec(google-chrome --simulate-outdated-no-au --new-window)",
84 "mod_m" => "win_toggle_maximize()",
85 "mod_r" => "exec(xkb-switch -s us; rofi -show drun)",
86 "mod_w" => "exec(firefox --new-instance --private-window)",
87 "mod_shift_w" => "exec(firefox --new-instance)",
88 "mod_-" => "toggle_calendar()",
89 "mod_=" => "exec(galculator)",
90 "mod_ctrl_shift_q" => "exit()",
91 "Print" => "exec(flameshot gui)",
92 "XF86AudioLowerVolume" => "nop()",
93 "XF86AudioMute" => "nop()",
94 "XF86AudioNext" => "exec(playerctl next)",
95 "XF86AudioPlay" => "exec(playerctl play-pause)",
96 "XF86AudioPrev" => "exec(playerctl previous)",
97 "XF86AudioRaiseVolume" => "nop()",
98 "XF86AudioStop" => "exec(playerctl stop)",
99 "XF86MonBrightnessDown" => "nop()",
100 "XF86MonBrightnessUp" => "nop()",
101 "XF86WakeUp" => "nop()",
102 "mod_alt_F1" => "exec(pactl set-sink-mute 0 toggle)",
103 "mod_alt_F2" => "exec(pactl set-sink-volume 0 -10%)",
104 "mod_alt_F3" => "exec(pactl set-sink-volume 0 +10%)",
105 "mod_alt_F5" => "exec(light -U 20)",
106 "mod_alt_F6" => "exec(light -A 20)",
107 "mod_alt_F10" => "layout_set(narrow)",
108 "mod_alt_F11" => "layout_set(columns)",
109 "mod_alt_F12" => "layout_set(grid)",
110 };
111  
112 $cfg->{rules} = {
113 "evolution" => { tag => 3, follow => 0 },
114 "evolution-alarm-notify" => { floating => 1, urgent => 1 },
115 "org.gnome.Evolution" => { screen => 1, tag => 3, follow => 0 },
116 "rofi" => { pinned => 1 },
117 "google-chrome" => { soft_placement => [
118 map { +{ if_screens => $_, screen => 2, tag => 7 } } 2, 3
119 ] },
120 "flameshot" => { pinned => 1, floating => 1 },
121 "galculator" => { floating => 1 },
122 "mattermost" => { follow => 1, placement => [
123 map { +{ if_screens => $_, screen => $_, tag => 4 } } 1..3
124 ] },
125 "urxvt-float" => { floating => 1 },
126 "xeyes" => { floating => 1 },
127 };
128  
129 $cfg->{noclass_whitelist} = ["Event Tester", "glxgears"];
130  
131 $cfg->{autostart} = ["exec(setxkbmap -layout us,ru -option grp:alt_shift_toggle,compose:ralt)"];
132  
133 # Read local configs
134 for my $file (
135 defined $ENV{KORGWM_DEBUG_CONFIG} ? $ENV{KORGWM_DEBUG_CONFIG} : (
136 "/etc/korgwm/korgwm.conf", "/usr/local/etc/korgwm/korgwm.conf",
137 "$ENV{HOME}/.korgwmrc", "$ENV{HOME}/.config/korgwm/korgwm.conf"
138 )
139 ) {
140 next unless -f $file;
141 my $rcfg;
142 eval { $rcfg = YAML::Tiny->read($file) and $rcfg = $rcfg->[0]; 1; } or do {
143 print STDERR "Error parsing config file: $@ ";
144 exit 2;
145 };
146 # TODO did not implement validation yet to allow users shoot the legs
147 %{ $cfg } = (%{ $cfg }, %{ $rcfg });
148 }
149  
150 # Right after reading the config, make a copy of it
151 if (defined $ENV{KORGWM_DEBUG_CONFIG}) {
152 eval "require Storable";
153 Storable->import("dclone");
154 our $debug_config = dclone($cfg);
155 }
156  
157 # Prepare whitelist of windows which we want to see with unset WM_CLASS
158 $cfg->{noclass_whitelist} = { map { ($_, 1) } @{ $cfg->{noclass_whitelist} } };
159  
160 # Normalize numeric values
161 $_ = hexnum for @{ $cfg }{grep /^color_/, keys %{ $cfg }};
162  
163 # Allow new syntax for placement
164 for my $name (keys %{ $cfg->{rules} }) {
165 for my $section (qw( placement soft_placement )) {
166 next unless ref(my $ref = $cfg->{rules}->{$name}->{$section}) eq 'ARRAY';
167  
168 # If at least one HASH, we assume the whole section should be converted to ARRAY
169 next unless first { ref($_) eq 'HASH' } @{ $ref };
170  
171 # $ref has HASH entries, so we need to convert all it's values to array refs
172 my @arr;
173 $arr[$_->{if_screens}] = [$_->{screen}, $_->{tag}] for @{ $ref };
174 $cfg->{rules}->{$name}->{$section} = \@arr;
175 }
176 }
177  
178 # Setup the DEBUG
179 ## Allow override via environment and create a closure
180 $cfg->{debug} = $1 if ($ENV{KORGWM_DEBUG} // "") =~ /^(\d+)$/ and $1 > 0;
181 my $dbglvl = $cfg->{debug};
182  
183 ## Append backtrace for higher levels
184 $Carp::Verbose = 1 if $dbglvl >= 3;
185  
186 ## Export common functions
187 *X11::korgwm::Common::DEBUG_API = ($dbglvl or defined $ENV{KORGWM_DEBUG_API}) ? sub() {1} : sub() {undef};
188  
189 ## Create per-level constant functions
190 ## Create slow S_DEBUG function that can be used within return clause
191 {
192 no strict 'refs';
193 *{"X11::korgwm::Common::DEBUG$_"} = $dbglvl >= $_ ? sub() {1} : sub() {undef} for 1..9;
194 *{"X11::korgwm::Common::S_DEBUG"} = sub($lvl, $msg) { $dbglvl >= $lvl and carp $msg; $dbglvl >= $lvl };
195 }
196 }
197  
198 1;
« korgwm/Screen.pm ↑ Summary korgwm/Tag.pm »