Skip to content

Game controller wakelock #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added a GameControllerWakelock plugin that temporarily suspends the s…
…creensaver if a joystick or gamepad is connected via bluetooth

Necessary changes for upstream compatibility

Added cschramm's proposed change for compatibility with BlueZ5

Fixed device class check

Using the root X-window's ID instead of a fake GTK window now
Added error handling and reporting

Fixed a regression in the class retrieval line

Use gtk to obtain root window id
Adopted infirit's proposed changes with a minor fix

Fixed support for multiple devices
  • Loading branch information
bwRavencl committed Feb 7, 2015
commit 2f74cc6b70ffc3c5c00e0c83ead3660bd582f44c
63 changes: 63 additions & 0 deletions blueman/plugins/applet/GameControllerWakelock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import blueman.bluez as bluez
from blueman.Functions import *
from blueman.main.SignalTracker import SignalTracker
from blueman.main.Device import Device
from blueman.plugins.AppletPlugin import AppletPlugin
from gi.repository import Gdk, GdkX11
import subprocess

class GameControllerWakelock(AppletPlugin):
__description__ = _("Temporarily suspends the screensaver when a bluetooth game controller is connected.")
__author__ = "bwRavencl"
__icon__ = "input-gaming"

def on_load(self, applet):
self.wake_lock = 0
self.root_window_id = "0x%x" % Gdk.Screen.get_default().get_root_window().get_xid()

self.signals = SignalTracker()
self.signals.Handle("bluez", bluez.Device(), self.on_device_property_changed, "PropertyChanged", path_keyword="path")

def on_unload(self):
if self.wake_lock:
self.wake_lock = 1
self.suspend_screensaver("resume")
self.signals.DisconnectAll()

def on_device_property_changed(self, key, value, path):
if key == "Connected":
klass = Device(path).get_properties()["Class"] & 0x1fff

if klass == 0x504 or klass == 0x508:
if value:
self.xdg_screensaver("suspend")
else:
self.xdg_screensaver("resume")

def xdg_screensaver(self, action):
if action == "resume":
if self.wake_lock == 0:
pass
elif self.wake_lock > 1:
self.wake_lock -= 1
pass
elif action == "suspend" and self.wake_lock >= 1:
self.wake_lock += 1
pass

command = ["xdg-screensaver", action, self.root_window_id]

try:
process = subprocess.Popen(command, stderr=subprocess.PIPE)
_, stderr = process.communicate()

if process.returncode != 0:
dprint(" ".join(command) + " failed with: " + stderr)
pass

if action == "suspend":
self.wake_lock += 1
elif action == "resume":
self.wake_lock = 0
except:
dprint(traceback.format_exc())
2 changes: 1 addition & 1 deletion blueman/plugins/applet/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bluemandir = $(pythondir)/blueman/plugins/applet

blueman_PYTHON = AppIndicator.py ExitItem.py ShowConnected.py AuthAgent.py DhcpClient.py NMPANSupport.py DBusService.py DiscvManager.py NetUsage.py Headset.py __init__.py KillSwitch.py Menu.py Networking.py PowerManager.py PPPSupport.py NMDUNSupport.py RecentConns.py SerialManager.py StandardItems.py StatusIcon.py TransferService.py
blueman_PYTHON = AppIndicator.py ExitItem.py ShowConnected.py AuthAgent.py DhcpClient.py NMPANSupport.py DBusService.py DiscvManager.py NetUsage.py Headset.py __init__.py KillSwitch.py Menu.py Networking.py PowerManager.py PPPSupport.py NMDUNSupport.py RecentConns.py SerialManager.py StandardItems.py StatusIcon.py TransferService.py GameControllerWakelock.py

CLEANFILES = \
$(BUILT_SOURCES)
Expand Down