From 1cd5e2edf7cd5bbaea8c4ebd2efda3831f76c0a8 Mon Sep 17 00:00:00 2001 From: Pi-Yueh Chuang Date: Wed, 18 Dec 2019 16:53:58 -0500 Subject: [PATCH] add a parameter to control bluetooth popup menu The right-click popup menu in the bluetooth module does not work well in Sway (a i3wm-compatible Wayland WM). This is known issue to Sway. Given that the popup menu is simply to turn on/off the bluetooth device, the graphical popup is really not necessary. This commit adds a parameter to control whether a popup menu should be used when a right-click happens, or we simply turn on/off the device without the menu. --- bumblebee/modules/bluetooth.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/bumblebee/modules/bluetooth.py b/bumblebee/modules/bluetooth.py index a43f43b..fc5d5b5 100644 --- a/bumblebee/modules/bluetooth.py +++ b/bumblebee/modules/bluetooth.py @@ -6,6 +6,7 @@ Parameters: * bluetooth.manager : application to launch on click (blueman-manager) * bluetooth.dbus_destination : dbus destination (defaults to org.blueman.Mechanism) * bluetooth.dbus_destination_path : dbus destination path (defaults to /) + * bluetooth.right_click_popup : use popup menu when right-clicked (defaults to True) """ @@ -36,9 +37,19 @@ class Module(bumblebee.engine.Module): engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd=self.manager) - engine.input.register_callback(self, - button=bumblebee.input.RIGHT_MOUSE, - cmd=self.popup) + + # determine whether to use pop-up menu or simply toggle the device on/off + right_click_popup = bumblebee.util.asbool( + self.parameter("right_click_popup", True)) + + if right_click_popup: + engine.input.register_callback(self, + button=bumblebee.input.RIGHT_MOUSE, + cmd=self.popup) + else: + engine.input.register_callback(self, + button=bumblebee.input.RIGHT_MOUSE, + cmd=self._toggle) def status(self, widget): """Get status.""" @@ -86,11 +97,10 @@ class Module(bumblebee.engine.Module): # show menu and get return code ret = menu.show(widget) if ret == 0: - logging.debug('bt: toggling bluetooth') # first (and only) item selected. self._toggle() - def _toggle(self): + def _toggle(self, widget=None): """Toggle bluetooth state.""" if self._status == "On": state = "false" @@ -104,6 +114,7 @@ class Module(bumblebee.engine.Module): " {} org.blueman.Mechanism.SetRfkillState"\ " boolean:{}".format(dst, dst_path, state) + logging.debug('bt: toggling bluetooth') bumblebee.util.execute(cmd) def state(self, widget):