diff --git a/libqtile/widget/widgetbox.py b/libqtile/widget/widgetbox.py index 1d1d4951fe..39b36b5dff 100644 --- a/libqtile/widget/widgetbox.py +++ b/libqtile/widget/widgetbox.py @@ -158,3 +158,15 @@ def toggle(self): self.toggle_widgets() self.set_box_label() self.bar.draw() + + @expose_command() + def open(self): + """Open the widgetbox.""" + if not self.box_is_open: + self.toggle() + + @expose_command() + def close(self): + """Close the widgetbox.""" + if self.box_is_open: + self.toggle() diff --git a/test/widgets/test_widgetbox.py b/test/widgets/test_widgetbox.py index 7933873dfb..f547505d8b 100644 --- a/test/widgets/test_widgetbox.py +++ b/test/widgets/test_widgetbox.py @@ -176,3 +176,38 @@ def test_deprecated_configuration(caplog): box = WidgetBox([tray]) assert box.widgets == [tray] assert "The use of a positional argument in WidgetBox is deprecated." in caplog.text + + +def test_widgetbox_open_close_commands(manager_nospawn, minimal_conf_noscreen): + config = minimal_conf_noscreen + tbox = TextBox(text="Text Box") + widget_box = WidgetBox(widgets=[tbox]) + config.screens = [libqtile.config.Screen(top=libqtile.bar.Bar([widget_box], 10))] + + manager_nospawn.start(config) + + topbar = manager_nospawn.c.bar["top"] + widget = manager_nospawn.c.widget["widgetbox"] + + def count(): + return len(topbar.info()["widgets"]) + + assert count() == 1 + + widget.open() + assert count() == 2 + + widget.open() + assert count() == 2 + + widget.close() + assert count() == 1 + + widget.close() + assert count() == 1 + + widget.toggle() + assert count() == 2 + + widget.toggle() + assert count() == 1