<s> from __future__ import division <EOL> from . . import bar , xcbq , window <EOL> from . import base <EOL> import xcffib <EOL> from xcffib . xproto import ( ClientMessageEvent , ClientMessageData , EventMask , <EOL> SetMode ) <EOL> XEMBED_PROTOCOL_VERSION = <NUM_LIT:0> <EOL> class Icon ( window . _Window ) : <EOL> _windowMask = EventMask . StructureNotify | EventMask . PropertyChange | EventMask . Exposure <EOL> def __init__ ( self , win , qtile , systray ) : <EOL> window . _Window . __init__ ( self , win , qtile ) <EOL> self . systray = systray <EOL> self . update_size ( ) <EOL> def update_size ( self ) : <EOL> icon_size = self . systray . icon_size <EOL> self . updateHints ( ) <EOL> try : <EOL> width = self . hints [ "<STR_LIT>" ] <EOL> height = self . hints [ "<STR_LIT>" ] <EOL> except KeyError : <EOL> width = icon_size <EOL> height = icon_size <EOL> if height > icon_size : <EOL> width = width * icon_size // height <EOL> height = icon_size <EOL> if height <= <NUM_LIT:0> : <EOL> width = icon_size <EOL> height = icon_size <EOL> self . width = width <EOL> self . height = height <EOL> return False <EOL> def handle_PropertyNotify ( self , e ) : <EOL> name = self . qtile . conn . atoms . get_name ( e . atom ) <EOL> if name == "<STR_LIT>" : <EOL> info = self . window . get_property ( '<STR_LIT>' , unpack = int ) <EOL> if info and info [ <NUM_LIT:1> ] : <EOL> self . systray . bar . draw ( ) <EOL> return False <EOL> def handle_DestroyNotify ( self , event ) : <EOL> wid = event . window <EOL> del ( self . qtile . windowMap [ wid ] ) <EOL> del ( self . systray . icons [ wid ] ) <EOL> self . systray . bar . draw ( ) <EOL> return False <EOL> handle_UnmapNotify = handle_DestroyNotify <EOL> class Systray ( window . _Window , base . _Widget ) : <EOL> """<STR_LIT>""" <EOL> _windowMask = EventMask . StructureNotify | EventMask . Exposure <EOL> orientations = base . ORIENTATION_HORIZONTAL <EOL> defaults = [ <EOL> ( '<STR_LIT>' , <NUM_LIT:20> , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:5> , '<STR_LIT>' ) , <EOL> ] <EOL> def __init__ ( self , ** config ) : <EOL> base . _Widget . __init__ ( self , bar . CALCULATED , ** config ) <EOL> self . add_defaults ( Systray . defaults ) <EOL> self . icons = { } <EOL> self . screen = <NUM_LIT:0> <EOL> def calculate_length ( self ) : <EOL> width = sum ( i . width for i in self . icons . values ( ) ) <EOL> width += self . padding * len ( self . icons ) <EOL> return width <EOL> def _configure ( self , qtile , bar ) : <EOL> base . _Widget . _configure ( self , qtile , bar ) <EOL> win = qtile . conn . create_window ( - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> window . _Window . __init__ ( self , xcbq . Window ( qtile . conn , win . wid ) , qtile ) <EOL> qtile . windowMap [ win . wid ] = self <EOL> if qtile . currentScreen : <EOL> self . screen = qtile . currentScreen . index <EOL> self . bar = bar <EOL> atoms = qtile . conn . atoms <EOL> qtile . conn . conn . core . SetSelectionOwner ( <EOL> win . wid , <EOL> atoms [ '<STR_LIT>' . format ( self . screen ) ] , <EOL> xcffib . CurrentTime <EOL> ) <EOL> data = [ <EOL> xcffib . CurrentTime , <EOL> atoms [ '<STR_LIT>' . format ( self . screen ) ] , <EOL> win . wid , <NUM_LIT:0> , <NUM_LIT:0> <EOL> ] <EOL> union = ClientMessageData . synthetic ( data , "<STR_LIT:I>" * <NUM_LIT:5> ) <EOL> event = ClientMessageEvent . synthetic ( <EOL> format = <NUM_LIT:32> , <EOL> window = qtile . root . wid , <EOL> type = atoms [ '<STR_LIT>' ] , <EOL> data = union <EOL> ) <EOL> qtile . root . send_event ( event , mask = EventMask . StructureNotify ) <EOL> def handle_ClientMessage ( self , event ) : <EOL> atoms = self . qtile . conn . atoms <EOL> opcode = event . type <EOL> data = event . data . data32 <EOL> message = data [ <NUM_LIT:1> ] <EOL> wid = data [ <NUM_LIT:2> ] <EOL> conn = self . qtile . conn . conn <EOL> parent = self . bar . window . window <EOL> if opcode == atoms [ '<STR_LIT>' ] and message == <NUM_LIT:0> : <EOL> w = xcbq . Window ( self . qtile . conn , wid ) <EOL> icon = Icon ( w , self . qtile , self ) <EOL> self . icons [ wid ] = icon <EOL> self . qtile . windowMap [ wid ] = icon <EOL> conn . core . ChangeSaveSet ( SetMode . Insert , wid ) <EOL> conn . core . ReparentWindow ( wid , parent . wid , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> conn . flush ( ) <EOL> info = icon . window . get_property ( '<STR_LIT>' , unpack = int ) <EOL> if not info : <EOL> self . bar . draw ( ) <EOL> return False <EOL> if info [ <NUM_LIT:1> ] : <EOL> self . bar . draw ( ) <EOL> return False <EOL> def draw ( self ) : <EOL> xoffset = self . padding <EOL> self . drawer . clear ( self . background or self . bar . background ) <EOL> self . drawer . draw ( offsetx = self . offset , width = self . length ) <EOL> for pos , icon in enumerate ( self . icons . values ( ) ) : <EOL> icon . window . set_attribute ( backpixmap = self . drawer . pixmap ) <EOL> icon . place ( <EOL> self . offset + xoffset , <EOL> self . bar . height // <NUM_LIT:2> - self . icon_size // <NUM_LIT:2> , <EOL> icon . width , self . icon_size , <EOL> <NUM_LIT:0> , <EOL> None <EOL> ) <EOL> if icon . hidden : <EOL> icon . unhide ( ) <EOL> data = [ <EOL> self . qtile . conn . atoms [ "<STR_LIT>" ] , <EOL> xcffib . xproto . Time . CurrentTime , <EOL> <NUM_LIT:0> , <EOL> self . bar . window . window . wid , <EOL> XEMBED_PROTOCOL_VERSION <EOL> ] <EOL> u = xcffib . xproto . ClientMessageData . synthetic ( data , "<STR_LIT:I>" * <NUM_LIT:5> ) <EOL> event = xcffib . xproto . ClientMessageEvent . synthetic ( <EOL> format = <NUM_LIT:32> , <EOL> window = icon . window . wid , <EOL> type = self . qtile . conn . atoms [ "<STR_LIT>" ] , <EOL> data = u <EOL> ) <EOL> self . window . send_event ( event ) <EOL> xoffset += icon . width + self . padding <EOL> def finalize ( self ) : <EOL> base . _Widget . finalize ( self ) <EOL> atoms = self . qtile . conn . atoms <EOL> self . qtile . conn . conn . core . SetSelectionOwner ( <EOL> <NUM_LIT:0> , <EOL> atoms [ '<STR_LIT>' . format ( self . screen ) ] , <EOL> xcffib . CurrentTime , <EOL> ) <EOL> self . hide ( ) </s>
