lemonbar: Trigger formatting on mode cycle and i3ws events

This commit is contained in:
2020-02-02 21:06:05 +01:00
parent b21211fc2b
commit e6dc178e4d
3 changed files with 20 additions and 3 deletions

View File

@@ -368,7 +368,6 @@ ${exec ~/.i3/lemonbar/get_vol.sh}"""
class i3Module(LemonModule): class i3Module(LemonModule):
# Handles outputs (displays), workspaces and active window # Handles outputs (displays), workspaces and active window
# TODO trigger formatting
def __init__(self, lemonbar_wrapper): def __init__(self, lemonbar_wrapper):
super().__init__(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.change_callbacks.append(self.parse_workspaces)
self.i3_ws_obj.focus_callbacks.append(self.parse_title) 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 # Add callbacks for special actions
self.i3_ws_obj.change_callbacks.append(self.set_bg) 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.set_keymap)
@@ -478,6 +480,11 @@ class i3Module(LemonModule):
, parser.block(fg=config.color_sec_b2, bg='-') , parser.block(fg=config.color_sec_b2, bg='-')
, i3ws.focused_window.name]) , 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): def format_displays(self):
return self.displays return self.displays
@@ -536,7 +543,7 @@ class i3Module(LemonModule):
else: else:
new_km = self.def_keymap new_km = self.def_keymap
common.logger.debug('Setting default keymap {} for {}'.format(new_km, wclass)) 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): def i3msg_comm(self, *cmd):
self.i3_ws_obj.command(' '.join(cmd)) self.i3_ws_obj.command(' '.join(cmd))
@@ -550,6 +557,9 @@ class i3Module(LemonModule):
common.mode = m common.mode = m
break break
parsed = parser.format_line()
self.lemonbar_wrapper.buffer_in.put(parsed)
class ScreenModule(LemonModule): class ScreenModule(LemonModule):
""" """
@ignore host kubaArch-Desktop @ignore host kubaArch-Desktop

View File

@@ -140,7 +140,7 @@ class LemonParser:
if unit.alt_scheme == COLOR_SCHEME.INA: if unit.alt_scheme == COLOR_SCHEME.INA:
unit.alt_scheme = COLOR_SCHEME.A1_INA if alt == 1 else COLOR_SCHEME.A2_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 alt = alt + 1 if alt + 1 <= 2 else 1
formatted.append(block(fg='-', bg='-')) # Not sure if needed formatted.append(block(fg='-', bg='-')) # Not sure if needed

View File

@@ -60,6 +60,7 @@ class i3ws(object):
# Callback functions have argument i3ws # Callback functions have argument i3ws
self.change_callbacks = [] self.change_callbacks = []
self.focus_callbacks = [] self.focus_callbacks = []
self.final_callback = None # Called after all other callbacks
def work(self): def work(self):
# While loop to restart connection as long as there is an i3 ipc socket # 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: for cb in self.change_callbacks:
cb(self) 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): def win_focused(self, i3, e):
self.focused_window = i3.get_tree().find_focused() self.focused_window = i3.get_tree().find_focused()
name = self.focused_window.name name = self.focused_window.name
@@ -134,6 +138,9 @@ class i3ws(object):
for cb in self.focus_callbacks: for cb in self.focus_callbacks:
cb(self) cb(self)
if self.final_callback:
self.final_callback(self)
def format(self, workspaces, outputs): def format(self, workspaces, outputs):
# Formats the text according to the workspace data given. # Formats the text according to the workspace data given.
# Only important when running in free standing mode # Only important when running in free standing mode