Merge pull request #489 from piyueh/bluetooth-dbus

Bluetooth module: dbus object path and popup menu
This commit is contained in:
tobi-wan-kenobi 2019-12-22 14:02:31 +01:00 committed by GitHub
commit 0ebd2bd854
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,8 @@ Parameters:
* bluetooth.device : the device to read state from (default is hci0) * bluetooth.device : the device to read state from (default is hci0)
* bluetooth.manager : application to launch on click (blueman-manager) * bluetooth.manager : application to launch on click (blueman-manager)
* bluetooth.dbus_destination : dbus destination (defaults to org.blueman.Mechanism) * 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)
""" """
@ -35,9 +37,19 @@ class Module(bumblebee.engine.Module):
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
cmd=self.manager) cmd=self.manager)
# 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, engine.input.register_callback(self,
button=bumblebee.input.RIGHT_MOUSE, button=bumblebee.input.RIGHT_MOUSE,
cmd=self.popup) cmd=self.popup)
else:
engine.input.register_callback(self,
button=bumblebee.input.RIGHT_MOUSE,
cmd=self._toggle)
def status(self, widget): def status(self, widget):
"""Get status.""" """Get status."""
@ -85,11 +97,10 @@ class Module(bumblebee.engine.Module):
# show menu and get return code # show menu and get return code
ret = menu.show(widget) ret = menu.show(widget)
if ret == 0: if ret == 0:
logging.debug('bt: toggling bluetooth')
# first (and only) item selected. # first (and only) item selected.
self._toggle() self._toggle()
def _toggle(self): def _toggle(self, widget=None):
"""Toggle bluetooth state.""" """Toggle bluetooth state."""
if self._status == "On": if self._status == "On":
state = "false" state = "false"
@ -97,11 +108,13 @@ class Module(bumblebee.engine.Module):
state = "true" state = "true"
dst = self.parameter("dbus_destination", "org.blueman.Mechanism") dst = self.parameter("dbus_destination", "org.blueman.Mechanism")
dst_path = self.parameter("dbus_destination_path", "/")
cmd = "dbus-send --system --print-reply --dest={}"\ cmd = "dbus-send --system --print-reply --dest={}"\
" / org.blueman.Mechanism.SetRfkillState"\ " {} org.blueman.Mechanism.SetRfkillState"\
" boolean:{}".format(dst, state) " boolean:{}".format(dst, dst_path, state)
logging.debug('bt: toggling bluetooth')
bumblebee.util.execute(cmd) bumblebee.util.execute(cmd)
def state(self, widget): def state(self, widget):