[core] Collapse modules by using middle mouse
When pressing the middle mouse button (and it's not assigned to any other functionality), the module (i.e. all widgets of that module) will disappear and be replaced with the module's icon (or prefix, as fallback) and an ellipsis. fixes #264
This commit is contained in:
parent
455707c583
commit
290f95d6b4
4 changed files with 41 additions and 5 deletions
|
@ -48,6 +48,7 @@ def main():
|
||||||
config=config,
|
config=config,
|
||||||
output=output,
|
output=output,
|
||||||
inp=inp,
|
inp=inp,
|
||||||
|
theme=theme,
|
||||||
)
|
)
|
||||||
signal.signal(10,sig_USR1_handler)
|
signal.signal(10,sig_USR1_handler)
|
||||||
engine.run()
|
engine.run()
|
||||||
|
|
|
@ -41,6 +41,9 @@ class Module(object):
|
||||||
self.error = None
|
self.error = None
|
||||||
self._next = int(time.time())
|
self._next = int(time.time())
|
||||||
self._default_interval = 0
|
self._default_interval = 0
|
||||||
|
self._minimized = False
|
||||||
|
|
||||||
|
self._minimizedWidget = bumblebee.output.Widget(full_text=u"\u2026")
|
||||||
|
|
||||||
self._configFile = None
|
self._configFile = None
|
||||||
for cfg in [os.path.expanduser("~/.bumblebee-status.conf"), os.path.expanduser("~/.config/bumblebee-status.conf")]:
|
for cfg in [os.path.expanduser("~/.bumblebee-status.conf"), os.path.expanduser("~/.config/bumblebee-status.conf")]:
|
||||||
|
@ -56,6 +59,12 @@ class Module(object):
|
||||||
if widgets:
|
if widgets:
|
||||||
self._widgets = widgets if isinstance(widgets, list) else [widgets]
|
self._widgets = widgets if isinstance(widgets, list) else [widgets]
|
||||||
|
|
||||||
|
def toggle_minimize(self):
|
||||||
|
self._minimized = not self._minimized
|
||||||
|
|
||||||
|
def minimized(self):
|
||||||
|
return self._minimized
|
||||||
|
|
||||||
def widgets(self):
|
def widgets(self):
|
||||||
"""Return the widgets to draw for this module"""
|
"""Return the widgets to draw for this module"""
|
||||||
return self._widgets
|
return self._widgets
|
||||||
|
@ -68,6 +77,9 @@ class Module(object):
|
||||||
if widget.name == name:
|
if widget.name == name:
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
|
def minimizedWidget(self):
|
||||||
|
return self._minimizedWidget
|
||||||
|
|
||||||
def errorWidget(self):
|
def errorWidget(self):
|
||||||
msg = self.error
|
msg = self.error
|
||||||
if len(msg) > 10:
|
if len(msg) > 10:
|
||||||
|
@ -78,6 +90,8 @@ class Module(object):
|
||||||
for widget in self._widgets:
|
for widget in self._widgets:
|
||||||
if widget.id == uid:
|
if widget.id == uid:
|
||||||
return widget
|
return widget
|
||||||
|
if self._minimizedWidget.id == uid:
|
||||||
|
return self._minimizedWidget
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
|
@ -110,12 +124,9 @@ class Module(object):
|
||||||
"""Return the config parameter 'name' for this module"""
|
"""Return the config parameter 'name' for this module"""
|
||||||
name = "{}.{}".format(self.name, name)
|
name = "{}.{}".format(self.name, name)
|
||||||
value = self._config["config"].get(name, default)
|
value = self._config["config"].get(name, default)
|
||||||
log.debug("command line parameter {}={}".format(name, str(value)))
|
|
||||||
if value == default:
|
if value == default:
|
||||||
try:
|
try:
|
||||||
log.debug("trying to read {} from configuration file".format(name))
|
|
||||||
value = self._configFile.get("module-parameters", name)
|
value = self._configFile.get("module-parameters", name)
|
||||||
log.debug("configuration file {}={}".format(name, str(value)))
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return value
|
return value
|
||||||
|
@ -133,7 +144,7 @@ class Engine(object):
|
||||||
This class connects input/output, instantiates all
|
This class connects input/output, instantiates all
|
||||||
required modules and drives the "event loop"
|
required modules and drives the "event loop"
|
||||||
"""
|
"""
|
||||||
def __init__(self, config, output=None, inp=None):
|
def __init__(self, config, output=None, inp=None, theme=None):
|
||||||
self._output = output
|
self._output = output
|
||||||
self._config = config
|
self._config = config
|
||||||
self._running = True
|
self._running = True
|
||||||
|
@ -142,6 +153,7 @@ class Engine(object):
|
||||||
self._aliases = self._read_aliases()
|
self._aliases = self._read_aliases()
|
||||||
self.load_modules(config.modules())
|
self.load_modules(config.modules())
|
||||||
self._current_module = None
|
self._current_module = None
|
||||||
|
self._theme = theme
|
||||||
|
|
||||||
if bumblebee.util.asbool(config.get("engine.workspacewheel", "true")):
|
if bumblebee.util.asbool(config.get("engine.workspacewheel", "true")):
|
||||||
if bumblebee.util.asbool(config.get("engine.workspacewrap", "true")):
|
if bumblebee.util.asbool(config.get("engine.workspacewrap", "true")):
|
||||||
|
@ -154,9 +166,18 @@ class Engine(object):
|
||||||
cmd=self._prev_workspace)
|
cmd=self._prev_workspace)
|
||||||
self.input.register_callback(None, bumblebee.input.WHEEL_DOWN,
|
self.input.register_callback(None, bumblebee.input.WHEEL_DOWN,
|
||||||
cmd=self._next_workspace)
|
cmd=self._next_workspace)
|
||||||
|
if bumblebee.util.asbool(config.get("engine.collapsible", "true")):
|
||||||
|
self.input.register_callback(None, bumblebee.input.MIDDLE_MOUSE,
|
||||||
|
cmd=self._toggle_minimize)
|
||||||
|
|
||||||
self.input.start()
|
self.input.start()
|
||||||
|
|
||||||
|
def _toggle_minimize(self, event):
|
||||||
|
for module in self._modules:
|
||||||
|
if module.widget_by_id(event["instance"]):
|
||||||
|
log.debug("module {} found - toggle minimize".format(module.id))
|
||||||
|
module.toggle_minimize()
|
||||||
|
|
||||||
def _prev_workspace(self, event):
|
def _prev_workspace(self, event):
|
||||||
self._change_workspace(-1)
|
self._change_workspace(-1)
|
||||||
|
|
||||||
|
@ -268,9 +289,16 @@ class Engine(object):
|
||||||
self._current_module = module
|
self._current_module = module
|
||||||
module.update_wrapper(module.widgets())
|
module.update_wrapper(module.widgets())
|
||||||
if module.error == None:
|
if module.error == None:
|
||||||
for widget in module.widgets():
|
if module.minimized():
|
||||||
|
widget = module.minimizedWidget()
|
||||||
widget.link_module(module)
|
widget.link_module(module)
|
||||||
|
if self._theme:
|
||||||
|
icon = self._theme.icon(widget)
|
||||||
self._output.draw(widget=widget, module=module, engine=self)
|
self._output.draw(widget=widget, module=module, engine=self)
|
||||||
|
else:
|
||||||
|
for widget in module.widgets():
|
||||||
|
widget.link_module(module)
|
||||||
|
self._output.draw(widget=widget, module=module, engine=self)
|
||||||
else:
|
else:
|
||||||
self._output.draw(widget=module.errorWidget(), module=module, engine=self)
|
self._output.draw(widget=module.errorWidget(), module=module, engine=self)
|
||||||
self._output.flush()
|
self._output.flush()
|
||||||
|
|
|
@ -102,10 +102,12 @@ class I3BarOutput(object):
|
||||||
padding = self._theme.padding(widget)
|
padding = self._theme.padding(widget)
|
||||||
prefix = self._theme.prefix(widget, padding)
|
prefix = self._theme.prefix(widget, padding)
|
||||||
suffix = self._theme.suffix(widget, padding)
|
suffix = self._theme.suffix(widget, padding)
|
||||||
|
|
||||||
if prefix:
|
if prefix:
|
||||||
full_text = u"{}{}".format(prefix, full_text)
|
full_text = u"{}{}".format(prefix, full_text)
|
||||||
if suffix:
|
if suffix:
|
||||||
full_text = u"{}{}".format(full_text, suffix)
|
full_text = u"{}{}".format(full_text, suffix)
|
||||||
|
|
||||||
separator = self._theme.separator(widget)
|
separator = self._theme.separator(widget)
|
||||||
if separator:
|
if separator:
|
||||||
self._widgets.append({
|
self._widgets.append({
|
||||||
|
|
|
@ -100,6 +100,11 @@ class Theme(object):
|
||||||
self._widget = None
|
self._widget = None
|
||||||
self._prevbg = None
|
self._prevbg = None
|
||||||
|
|
||||||
|
def icon(self, widget):
|
||||||
|
icon = self._get(widget, "icon", None)
|
||||||
|
if icon == None:
|
||||||
|
return self._get(widget, "prefix", None)
|
||||||
|
|
||||||
def padding(self, widget):
|
def padding(self, widget):
|
||||||
"""Return padding for widget"""
|
"""Return padding for widget"""
|
||||||
return self._get(widget, "padding", "")
|
return self._get(widget, "padding", "")
|
||||||
|
|
Loading…
Reference in a new issue