o
    \ck	                     @   s   d dl m Z d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlZedd	 ed
d	 d dlmZmZ eej ejsMedG dd de
ZdS )    )gettextN)Any)Device)launch)AppletPlugin)UnsupportedPlatformErrorGdkX11z3.0Gdk)r	   r   zOnly X11 platform is supportedc                   @   s\   e Zd ZedZdZdZdddZddd	Zd
e	de	de
ddfddZde	ddfddZdS )GameControllerWakelockzSTemporarily suspends the screensaver when a bluetooth game controller is connected.	bwRavenclzinput-gaming-symbolicreturnNc                 C   sF   d| _ tj }|d usJ | }t|tjsJ d|  | _	d S )Nr   z0x%x)
	wake_lockr	   Screenget_defaultget_root_window
isinstancer   	X11Windowget_xidroot_window_id)selfscreenwindow r   O/usr/lib/python3/dist-packages/blueman/plugins/applet/GameControllerWakelock.pyon_load   s   
zGameControllerWakelock.on_loadc                 C   s   | j rd| _ | d d S d S )N   resume)r   xdg_screensaver)r   r   r   r   	on_unload    s   z GameControllerWakelock.on_unloadpathkeyvaluec                 C   sR   |dkr%t |dd d@ }|dks|dkr'|r| d d S | d d S d S d S )	N	Connected)obj_pathClassi  i  i  suspendr   )r   r   )r   r   r    r!   klassr   r   r   on_device_property_changed%   s   z1GameControllerWakelock.on_device_property_changedactionc                 C   s   d| d| j  }|dkr<| jdkrd| _nO| jdkr#|  jd8  _nBt|dd}|r3|  jd8  _n2t| d n)|d	kre| jdkrM|  jd7  _nt|dd}|r]|  jd7  _nt| d td
| j  d S )Nzxdg-screensaver  r   r   r   F)snz failedr%   zNumber of locks: )r   r   r   loggingerrorinfo)r   r(   commandretr   r   r   r   /   s$   


z&GameControllerWakelock.xdg_screensaver)r   N)__name__
__module____qualname_____description__
__author____icon__r   r   strr   r'   r   r   r   r   r   r
      s    


r
   )r   r3   r+   typingr   blueman.bluez.Devicer   blueman.Functionsr   blueman.plugins.AppletPluginr   blueman.plugins.errorsr   girequire_versiongi.repositoryr	   r   r   r   r   	X11Screenr
   r   r   r   r   <module>   s    