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.
This commit is contained in:
Pi-Yueh Chuang 2019-12-18 16:53:58 -05:00
parent 747214f3da
commit 1cd5e2edf7
No known key found for this signature in database
GPG key ID: 83F49ABBF34F879D

View file

@ -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):