[core] re-enable minimize of widgets
by default, allow toggling the minimized state of a widget via the middle mouse and draw a single unicode char instead of the actual widget, maintaining all states. fixes #661
This commit is contained in:
parent
45d8ed23c9
commit
34dadadf90
6 changed files with 48 additions and 14 deletions
|
@ -19,6 +19,7 @@ import core.module
|
|||
import core.input
|
||||
import core.event
|
||||
|
||||
import util.format
|
||||
|
||||
started = False
|
||||
|
||||
|
@ -110,6 +111,10 @@ def main():
|
|||
modules.reverse()
|
||||
|
||||
output.modules(modules)
|
||||
|
||||
if util.format.asbool(config.get("engine.collapsible", True)) == True:
|
||||
core.input.register(None, core.input.MIDDLE_MOUSE, output.toggle_minimize)
|
||||
|
||||
core.event.trigger("start")
|
||||
started = True
|
||||
while True:
|
||||
|
|
|
@ -184,12 +184,14 @@ class Module(core.input.Object):
|
|||
:rtype: bumblebee_status.widget.Widget
|
||||
"""
|
||||
|
||||
def widget(self, name=None):
|
||||
if not name:
|
||||
def widget(self, name=None, widget_id=None):
|
||||
if not name and not widget_id:
|
||||
return self.widgets()[0]
|
||||
|
||||
for w in self.widgets():
|
||||
if w.name == name:
|
||||
if name and w.name == name:
|
||||
return w
|
||||
if w.id == widget_id:
|
||||
return w
|
||||
return None
|
||||
|
||||
|
|
|
@ -152,6 +152,12 @@ class i3(object):
|
|||
return self.__modules
|
||||
self.__modules = modules if isinstance(modules, list) else [modules]
|
||||
|
||||
def toggle_minimize(self, event):
|
||||
for module in self.__modules:
|
||||
widget = module.widget(widget_id=event["instance"])
|
||||
if widget:
|
||||
widget.minimized = not widget.minimized
|
||||
|
||||
def draw(self, what, args=None):
|
||||
cb = getattr(self, what)
|
||||
data = cb(args) if args else cb()
|
||||
|
@ -187,7 +193,7 @@ class i3(object):
|
|||
except:
|
||||
blk.set("min-width", minwidth)
|
||||
blk.set("align", widget.theme("align"))
|
||||
blk.set("full_text", self.__content[widget])
|
||||
blk.set("full_text", "\u2026" if widget.minimized else self.__content[widget])
|
||||
if widget.get("pango", False):
|
||||
blk.set("markup", "pango")
|
||||
if self.__config.debug():
|
||||
|
|
|
@ -15,6 +15,7 @@ class Widget(util.store.Store, core.input.Object):
|
|||
self.__full_text = full_text
|
||||
self.module = None
|
||||
self.name = name
|
||||
self.minimized = False
|
||||
|
||||
@property
|
||||
def module(self):
|
||||
|
|
|
@ -129,6 +129,13 @@ def test_get_widget_by_name(empty_config, widget_a, widget_b):
|
|||
assert module.widget("i-do-not-exist") == None
|
||||
assert module.widget() == widget_a
|
||||
|
||||
def test_get_widget_by_id(empty_config, widget_a, widget_b):
|
||||
module = SampleModule(config=empty_config, widgets=[widget_a, widget_b])
|
||||
|
||||
assert module.widget(widget_id=widget_a.id) == widget_a
|
||||
assert module.widget(widget_id=widget_b.id) == widget_b
|
||||
assert module.widget(widget_id="i-do-not-exist") == None
|
||||
|
||||
|
||||
def test_default_thresholds(empty_config, widget_a, widget_b):
|
||||
module = SampleModule(config=empty_config, widgets=[widget_a, widget_b])
|
||||
|
|
|
@ -25,6 +25,16 @@ def i3():
|
|||
def module_a(mocker):
|
||||
widget = mocker.MagicMock()
|
||||
widget.full_text.return_value = "test"
|
||||
widget.id = "a"
|
||||
widget.minimized = False
|
||||
return SampleModule(config=core.config.Config([]), widgets=[widget, widget, widget])
|
||||
|
||||
@pytest.fixture
|
||||
def module_b(mocker):
|
||||
widget = mocker.MagicMock()
|
||||
widget.full_text.return_value = "test"
|
||||
widget.id = "b"
|
||||
widget.minimized = False
|
||||
return SampleModule(config=core.config.Config([]), widgets=[widget, widget, widget])
|
||||
|
||||
|
||||
|
@ -46,16 +56,6 @@ def block_a(separatorTheme, module_a):
|
|||
theme=separatorTheme, module=module_a, widget=module_a.widget(),
|
||||
)
|
||||
|
||||
|
||||
# def setUp(self):
|
||||
# self.i3 = core.output.i3()
|
||||
# widget = unittest.mock.MagicMock()
|
||||
# widget.full_text.return_value = "test"
|
||||
# self.someModule = SampleModule(
|
||||
# config=core.config.Config([]), widgets=[widget, widget, widget]
|
||||
# )
|
||||
# self.separator = "***"
|
||||
#
|
||||
def test_start(i3):
|
||||
all_data = i3.start()
|
||||
data = all_data["blocks"]
|
||||
|
@ -83,6 +83,19 @@ def test_register_multiple_modules(i3, module_a):
|
|||
i3.modules([module_a, module_a, module_a])
|
||||
assert i3.modules() == [module_a, module_a, module_a]
|
||||
|
||||
def test_toggle_module(i3, module_a, module_b):
|
||||
i3.modules([module_a, module_b])
|
||||
|
||||
i3.toggle_minimize({ "instance": module_a.widget().id })
|
||||
|
||||
assert module_a.widget().minimized == True
|
||||
assert module_b.widget().minimized == False
|
||||
|
||||
i3.toggle_minimize({ "instance": module_a.widget().id })
|
||||
i3.toggle_minimize({ "instance": module_b.widget().id })
|
||||
|
||||
assert module_a.widget().minimized == False
|
||||
assert module_b.widget().minimized == True
|
||||
|
||||
def test_draw_existing_module(mocker, i3):
|
||||
i3.test_draw = mocker.MagicMock(
|
||||
|
|
Loading…
Reference in a new issue