diff --git a/.i3/lemonbar/i3_lemonbar_modules.py b/.i3/lemonbar/i3_lemonbar_modules.py index 915a890..b454fa4 100644 --- a/.i3/lemonbar/i3_lemonbar_modules.py +++ b/.i3/lemonbar/i3_lemonbar_modules.py @@ -368,7 +368,6 @@ ${exec ~/.i3/lemonbar/get_vol.sh}""" class i3Module(LemonModule): # Handles outputs (displays), workspaces and active window - # TODO trigger formatting def __init__(self, lemonbar_wrapper): super().__init__(lemonbar_wrapper) @@ -398,6 +397,9 @@ class i3Module(LemonModule): self.i3_ws_obj.change_callbacks.append(self.parse_workspaces) self.i3_ws_obj.focus_callbacks.append(self.parse_title) + # Callback after all other actions should flush the bar + self.i3_ws_obj.final_callback = self.update_bar + # Add callbacks for special actions self.i3_ws_obj.change_callbacks.append(self.set_bg) self.i3_ws_obj.focus_callbacks.append(self.set_keymap) @@ -478,6 +480,11 @@ class i3Module(LemonModule): , parser.block(fg=config.color_sec_b2, bg='-') , i3ws.focused_window.name]) + + def update_bar(self, i3ws): + parsed = parser.format_line() # Construct entire line + self.lemonbar_wrapper.buffer_in.put(parsed) + def format_displays(self): return self.displays @@ -536,7 +543,7 @@ class i3Module(LemonModule): else: 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]) # TODO it is this script that writes to fifo, triggering the formatting + subprocess.call(['/home/kuba/.i3/scripts/lang.sh', 'qset', new_km]) # TODO rework lang script (after fifo for executing commands) def i3msg_comm(self, *cmd): self.i3_ws_obj.command(' '.join(cmd)) @@ -550,6 +557,9 @@ class i3Module(LemonModule): common.mode = m break + parsed = parser.format_line() + self.lemonbar_wrapper.buffer_in.put(parsed) + class ScreenModule(LemonModule): """ @ignore host kubaArch-Desktop diff --git a/.i3/lemonbar/i3_lemonbar_parser.py b/.i3/lemonbar/i3_lemonbar_parser.py index aed2c69..d7bb5c3 100755 --- a/.i3/lemonbar/i3_lemonbar_parser.py +++ b/.i3/lemonbar/i3_lemonbar_parser.py @@ -140,7 +140,7 @@ class LemonParser: if unit.alt_scheme == COLOR_SCHEME.INA: unit.alt_scheme = COLOR_SCHEME.A1_INA if alt == 1 else COLOR_SCHEME.A2_INA - formatted.append(unit.format()) + formatted.append(unit.format()) # TODO cache last format alt = alt + 1 if alt + 1 <= 2 else 1 formatted.append(block(fg='-', bg='-')) # Not sure if needed diff --git a/.i3/lemonbar/i3_workspaces.py b/.i3/lemonbar/i3_workspaces.py index 31709ff..9c75375 100755 --- a/.i3/lemonbar/i3_workspaces.py +++ b/.i3/lemonbar/i3_workspaces.py @@ -60,6 +60,7 @@ class i3ws(object): # Callback functions have argument i3ws self.change_callbacks = [] self.focus_callbacks = [] + self.final_callback = None # Called after all other callbacks def work(self): # While loop to restart connection as long as there is an i3 ipc socket @@ -124,6 +125,9 @@ class i3ws(object): for cb in self.change_callbacks: cb(self) + if self.final_callback: # TODO ideally this would not be called on change if win_focused comes right after + self.final_callback(self) + def win_focused(self, i3, e): self.focused_window = i3.get_tree().find_focused() name = self.focused_window.name @@ -134,6 +138,9 @@ class i3ws(object): for cb in self.focus_callbacks: cb(self) + if self.final_callback: + self.final_callback(self) + def format(self, workspaces, outputs): # Formats the text according to the workspace data given. # Only important when running in free standing mode