diff --git a/.i3/lemonbar/conky_fast b/.i3/lemonbar/conky_fast index 17a9ccc..06a74f1 100644 --- a/.i3/lemonbar/conky_fast +++ b/.i3/lemonbar/conky_fast @@ -15,7 +15,6 @@ conky.config = { } conky.text = [[ -CNK_FAST \ ${time %a %d %b %H:%M:%S} \ ${exec ~/.i3/lemonbar/get_vol.sh} \ ${if_up wlp3s0}${downspeedf wlp3s0} ${upspeedf wlp3s0}\ diff --git a/.i3/lemonbar/conky_slow b/.i3/lemonbar/conky_slow index 79393b0..5a0d199 100644 --- a/.i3/lemonbar/conky_slow +++ b/.i3/lemonbar/conky_slow @@ -15,7 +15,6 @@ conky.config = { } conky.text = [[ -CNK_SLOW \ ${cpu} \ ${mem} \ ${fs_used_perc /} \ diff --git a/.i3/lemonbar/i3_lemonbar_common.py b/.i3/lemonbar/i3_lemonbar_common.py index 7185078..fd8b17c 100755 --- a/.i3/lemonbar/i3_lemonbar_common.py +++ b/.i3/lemonbar/i3_lemonbar_common.py @@ -10,7 +10,6 @@ kill_on_unfocus = [] logger = None health_logger = None -screen_send_cmd = lambda s : None # TODO temporary until move actions to modules write_queue = None # TODO Actually, why is this a queue? Just last element is important # TODO bar mode can be moved to i3Module @@ -25,13 +24,6 @@ class bar_mode(Enum): mode = bar_mode.normal -show_secs = False - -# Keymaps -def_keymap = 'pl' -keymaps = {'firefox': 'se'} -cur_class = '' - # Helper functions ansi_escape = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]') def strip_ansi_unicode(s): diff --git a/.i3/lemonbar/i3_lemonbar_launcher.py b/.i3/lemonbar/i3_lemonbar_launcher.py index cf791aa..4105fb8 100755 --- a/.i3/lemonbar/i3_lemonbar_launcher.py +++ b/.i3/lemonbar/i3_lemonbar_launcher.py @@ -154,8 +154,9 @@ def exec_commands(): try: modules.do_action(data) - except: + except Exception as e: common.logger.debug('Exception occured executing command\n Line in: {}'.format(data)) + common.logger.debug(str(e)) if len(data) == 0: common.logger.debug("Lemonbar output closed") break diff --git a/.i3/lemonbar/i3_lemonbar_modules.py b/.i3/lemonbar/i3_lemonbar_modules.py index fddff5e..94ec5d8 100644 --- a/.i3/lemonbar/i3_lemonbar_modules.py +++ b/.i3/lemonbar/i3_lemonbar_modules.py @@ -38,8 +38,7 @@ class LemonModule(threading.Thread): self._stop_module() def parse(self, line): - # TODO get rid of prefix - data = line[len(self.prefix):].split() + data = line.split() self._parse_data(data) # Update correct field formatted_line = parser.format_line() # Construct entire line @@ -53,11 +52,7 @@ class LemonModule(threading.Thread): action = action_arr[0] if (action in self.actions): func = self.actions[action] - if len(action_arr) == 1: - # Function has no arguments - func() - else: - func(action_arr[1:]) + func(*action_arr[1:]) # Unpack arguments, if any def format_load(data, module, alert): # Helper function to format network modules @@ -79,7 +74,7 @@ def format_load(data, module, alert): class ConkyFastModule(LemonModule): def __init__(self): - self.prefix = 'CNK_FAST' + self.show_secs = False super().__init__() def _start_module(self): @@ -135,7 +130,7 @@ class ConkyFastModule(LemonModule): # Date and time self.date.items = [(config.icon_clock, ' '.join(data[0:3]))] - self.time.items = [('', data[3] if common.show_secs else data[3][:-3])] + self.time.items = [('', data[3] if self.show_secs else data[3][:-3])] def nmtui(self): p = subprocess.Popen(['xterm', '-class', 'FLOAT_TERM', '-e', 'nmtui']) @@ -145,18 +140,17 @@ class ConkyFastModule(LemonModule): p = subprocess.Popen(['pavucontrol', '--class=FLOAT_PAVU']) common.kill_on_unfocus.append(p.pid) - def date_comm(args): + def date_comm(self): subprocess.Popen(['yad', '--no-buttons', '--calendar', '--sticky' , '--on-top' , '--class' , '"YADWIN"', '--posx=1650', '--posy=24' , '--close-on-unfocus']) - def toggle_secs(args): - common.show_secs = not common.show_secs + def toggle_secs(self): + self.show_secs = not self.show_secs class ConkySlowModule(LemonModule): def __init__(self): - self.prefix = 'CNK_SLOW' super().__init__() def _start_module(self): @@ -236,6 +230,7 @@ class ConkySlowModule(LemonModule): common.kill_on_unfocus.append(p.pid) def lang_comm(self): + # TODO Connect to i3Module (or let i3Module connect here to update the keymap) subprocess.Popen(['sh', '/home/kuba/.i3/scripts/lang.sh', 'next']) def dpms_comm(self): @@ -254,6 +249,10 @@ class i3Module(LemonModule): self.win_title = '' self.workspaces = '' + self.def_keymap = 'pl' + self.keymaps = {'firefox': 'se'} + self.cur_class = '' + def _start_module(self): self.i3_ws_obj = wspaces.i3ws(logger=common.logger) @@ -276,9 +275,9 @@ class i3Module(LemonModule): self.i3_ws_obj.focus_callbacks.append(self.parse_title) # Add callbacks for special actions - self.i3_ws_obj.change_callbacks.append(i3Module.set_bg) - self.i3_ws_obj.focus_callbacks.append(i3Module.set_keymap) - self.i3_ws_obj.focus_callbacks.append(i3Module.kill_floating_windows) + self.i3_ws_obj.change_callbacks.append(self.set_bg) + self.i3_ws_obj.focus_callbacks.append(self.set_keymap) + self.i3_ws_obj.focus_callbacks.append(self.kill_floating_windows) def _stop_module(self): parser.g_parser.remove_unit(self.displays) @@ -378,7 +377,7 @@ class i3Module(LemonModule): 9: '9', }.get(int(num), 'default') - def set_bg(i3ws): + def set_bg(self, i3ws): cmd_args = ['sh', '/home/kuba/scripts/set_bg.sh'] for output in i3ws.outputs: if output.active: @@ -386,7 +385,7 @@ class i3Module(LemonModule): cmd_args.append(bg) subprocess.call(cmd_args) - def kill_floating_windows(i3ws): + def kill_floating_windows(self, i3ws): if i3ws.focused_window is None: return @@ -401,26 +400,24 @@ class i3Module(LemonModule): common.logger.debug('Tried killing process {} but it doesn\'t exist'.format(pid)) common.kill_on_unfocus = [] - def set_keymap(i3ws): + def set_keymap(self, i3ws): if i3ws.focused_window is None: return wclass = i3ws.focused_window.window_class - common.cur_class = wclass + self.cur_class = wclass - if wclass in common.keymaps: - new_km = common.keymaps[wclass] + if wclass in self.keymaps: + new_km = self.keymaps[wclass] common.logger.debug('Setting {} as keymap for {}'.format(new_km, wclass)) else: - new_km = common.def_keymap + new_km = self.def_keymap common.logger.debug('Setting default keymap {} for {}'.format(new_km, wclass)) subprocess.call(['/home/kuba/.i3/scripts/lang.sh', 'qset', new_km]) - def i3msg_comm(self, args): - # TODO this is not needed anymore. Use i3ws object directly - subprocess.Popen(['i3-msg'] + args) + def i3msg_comm(self, *cmd): + self.i3_ws_obj.command(' '.join(cmd)) - def set_mode(self, args): - new_mode = args[0] + def set_mode(self, new_mode): if new_mode == "cycle": common.mode = common.mode.cycle() @@ -436,13 +433,11 @@ class ScreenModule(LemonModule): start_flags = ['-d', '-m', '-U', '-L', '-Logfile', config.fifo_screen_log] def __init__(self): - self.prefix = '' super().__init__() def _start_module(self): self.identifier = 'lemonbar_{}_{}'.format(getpass.getuser(), os.getpid()) self.empty_count = 0 - common.screen_send_cmd = self.send_cmd common.create_new_fifo(config.fifo_screen_log) self.send(self.start_flags) # Start screen self.send_cmd('stty -echo') # Do not echo what is written to screen terminal @@ -508,15 +503,14 @@ class ScreenModule(LemonModule): # Send colon command to our screen instance self.send(['-X', 'colon', cmd + '\n']) - def bluetooth(self, args): + def bluetooth(self, *args): btcargs = [a.replace('pxc550', '00:16:94:22:29:0E') for a in args] inp = ' '.join(btcargs) - common.screen_send_cmd('bluetoothctl ' + inp) + self.send_cmd('bluetoothctl ' + inp) class PowerOptionsModule(LemonModule): def __init__(self): - self.prefix = '' super().__init__() def _start_module(self): diff --git a/.i3/lemonbar/i3_workspaces.py b/.i3/lemonbar/i3_workspaces.py index ff0ef79..5bbf84e 100755 --- a/.i3/lemonbar/i3_workspaces.py +++ b/.i3/lemonbar/i3_workspaces.py @@ -141,6 +141,9 @@ class i3ws(object): out += item return self.end_format % out + def command(self, cmd): + self.conn.command(cmd) + def display(self, text): global print_stdout if print_stdout: