<s> import time <EOL> import xcb . xproto <EOL> import xpybutil <EOL> import xpybutil . event as event <EOL> import xpybutil . ewmh as ewmh <EOL> import xpybutil . motif as motif <EOL> import xpybutil . icccm as icccm <EOL> import xpybutil . rect as rect <EOL> import xpybutil . util as util <EOL> import xpybutil . window as window <EOL> from debug import debug <EOL> import config <EOL> import state <EOL> import tile <EOL> clients = { } <EOL> ignore = [ ] <EOL> class Client ( object ) : <EOL> def __init__ ( self , wid ) : <EOL> self . wid = wid <EOL> self . name = ewmh . get_wm_name ( self . wid ) . reply ( ) or '<STR_LIT>' <EOL> debug ( '<STR_LIT>' % self ) <EOL> window . listen ( self . wid , '<STR_LIT>' , '<STR_LIT>' ) <EOL> event . connect ( '<STR_LIT>' , self . wid , self . cb_property_notify ) <EOL> event . connect ( '<STR_LIT>' , self . wid , self . cb_focus_in ) <EOL> event . connect ( '<STR_LIT>' , self . wid , self . cb_focus_out ) <EOL> self . parentid = window . get_parent_window ( self . wid ) <EOL> window . listen ( self . parentid , '<STR_LIT>' ) <EOL> event . connect ( '<STR_LIT>' , self . parentid , <EOL> self . cb_configure_notify ) <EOL> self . floating = getattr ( config , '<STR_LIT>' , False ) <EOL> self . moving = False <EOL> self . desk = ewmh . get_wm_desktop ( self . wid ) . reply ( ) <EOL> tile . update_client_add ( self ) <EOL> self . save ( ) <EOL> def remove ( self ) : <EOL> tile . update_client_removal ( self ) <EOL> debug ( '<STR_LIT>' % self ) <EOL> event . disconnect ( '<STR_LIT>' , self . parentid ) <EOL> event . disconnect ( '<STR_LIT>' , self . wid ) <EOL> event . disconnect ( '<STR_LIT>' , self . wid ) <EOL> event . disconnect ( '<STR_LIT>' , self . wid ) <EOL> def activate ( self ) : <EOL> ewmh . request_active_window_checked ( self . wid , source = <NUM_LIT:1> ) . check ( ) <EOL> def unmaximize ( self ) : <EOL> vatom = util . get_atom ( '<STR_LIT>' ) <EOL> hatom = util . get_atom ( '<STR_LIT>' ) <EOL> ewmh . request_wm_state_checked ( self . wid , <NUM_LIT:0> , vatom , hatom ) . check ( ) <EOL> def save ( self ) : <EOL> self . saved_geom = window . get_geometry ( self . wid ) <EOL> self . saved_state = ewmh . get_wm_state ( self . wid ) . reply ( ) <EOL> def restore ( self ) : <EOL> debug ( '<STR_LIT>' % self ) <EOL> if getattr ( config , '<STR_LIT>' , False ) : <EOL> motif . set_hints_checked ( self . wid , <NUM_LIT:2> , decoration = <NUM_LIT:1> ) . check ( ) <EOL> if getattr ( config , '<STR_LIT>' , False ) : <EOL> ewmh . request_wm_state_checked ( self . wid , <NUM_LIT:0> , util . get_atom ( '<STR_LIT>' ) ) . check ( ) <EOL> if self . saved_state : <EOL> fullymaxed = False <EOL> vatom = util . get_atom ( '<STR_LIT>' ) <EOL> hatom = util . get_atom ( '<STR_LIT>' ) <EOL> if vatom in self . saved_state and hatom in self . saved_state : <EOL> fullymaxed = True <EOL> ewmh . request_wm_state_checked ( self . wid , <NUM_LIT:1> , vatom , hatom ) . check ( ) <EOL> elif vatom in self . saved_state : <EOL> ewmh . request_wm_state_checked ( self . wid , <NUM_LIT:1> , vatom ) . check ( ) <EOL> elif hatom in self . saved_state : <EOL> ewmh . request_wm_state_checked ( self . wid , <NUM_LIT:1> , hatom ) . check ( ) <EOL> if fullymaxed : <EOL> return <EOL> mnow = rect . get_monitor_area ( window . get_geometry ( self . wid ) , <EOL> state . monitors ) <EOL> mold = rect . get_monitor_area ( self . saved_geom , state . monitors ) <EOL> x , y , w , h = self . saved_geom <EOL> if mnow != mold : <EOL> nowx , nowy , noww , nowh = mnow <EOL> oldx , oldy , oldw , oldh = mold <EOL> xrat , yrat = float ( noww ) / float ( oldw ) , float ( nowh ) / float ( oldh ) <EOL> x = nowx + ( x - oldx ) * xrat <EOL> y = nowy + ( y - oldy ) * yrat <EOL> w *= xrat <EOL> h *= yrat <EOL> window . moveresize ( self . wid , x , y , w , h ) <EOL> def moveresize ( self , x = None , y = None , w = None , h = None ) : <EOL> if self . moving : <EOL> print '<STR_LIT>' % self <EOL> return <EOL> try : <EOL> window . moveresize ( self . wid , x , y , w , h ) <EOL> except : <EOL> pass <EOL> def is_button_pressed ( self ) : <EOL> try : <EOL> pointer = xpybutil . conn . core . QueryPointer ( self . wid ) . reply ( ) <EOL> if pointer is None : <EOL> return False <EOL> if ( xcb . xproto . KeyButMask . Button1 & pointer . mask or <EOL> xcb . xproto . KeyButMask . Button3 & pointer . mask ) : <EOL> return True <EOL> except xcb . xproto . BadWindow : <EOL> pass <EOL> return False <EOL> def cb_focus_in ( self , e ) : <EOL> if self . moving and e . mode == xcb . xproto . NotifyMode . Ungrab : <EOL> state . GRAB = None <EOL> self . moving = False <EOL> tile . update_client_moved ( self ) <EOL> def cb_focus_out ( self , e ) : <EOL> if e . mode == xcb . xproto . NotifyMode . Grab : <EOL> state . GRAB = self <EOL> def cb_configure_notify ( self , e ) : <EOL> if state . GRAB is self and self . is_button_pressed ( ) : <EOL> self . moving = True <EOL> def cb_property_notify ( self , e ) : <EOL> aname = util . get_atom_name ( e . atom ) <EOL> try : <EOL> if aname == '<STR_LIT>' : <EOL> if should_ignore ( self . wid ) : <EOL> untrack_client ( self . wid ) <EOL> return <EOL> olddesk = self . desk <EOL> self . desk = ewmh . get_wm_desktop ( self . wid ) . reply ( ) <EOL> if self . desk is not None and self . desk != olddesk : <EOL> tile . update_client_desktop ( self , olddesk ) <EOL> else : <EOL> self . desk = olddesk <EOL> elif aname == '<STR_LIT>' : <EOL> if should_ignore ( self . wid ) : <EOL> untrack_client ( self . wid ) <EOL> return <EOL> except xcb . xproto . BadWindow : <EOL> pass <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . name [ <NUM_LIT:0> : <NUM_LIT:30> ] , self . wid ) <EOL> def update_clients ( ) : <EOL> client_list = ewmh . get_client_list_stacking ( ) . reply ( ) <EOL> client_list = list ( reversed ( client_list ) ) <EOL> for c in client_list : <EOL> if c not in clients : <EOL> track_client ( c ) <EOL> for c in clients . keys ( ) : <EOL> if c not in client_list : <EOL> untrack_client ( c ) <EOL> def track_client ( client ) : <EOL> assert client not in clients <EOL> try : <EOL> if not should_ignore ( client ) : <EOL> if state . PYTYLE_STATE == '<STR_LIT>' : <EOL> time . sleep ( <NUM_LIT> ) <EOL> clients [ client ] = Client ( client ) <EOL> except xcb . xproto . BadWindow : <EOL> debug ( '<STR_LIT>' <EOL> '<STR_LIT>' % client ) <EOL> untrack_client ( client ) <EOL> def untrack_client ( client ) : <EOL> if client not in clients : <EOL> return <EOL> c = clients [ client ] <EOL> del clients [ client ] <EOL> c . remove ( ) <EOL> def should_ignore ( client ) : <EOL> if client in ignore : <EOL> return True <EOL> nm = ewmh . get_wm_name ( client ) . reply ( ) <EOL> wm_class = icccm . get_wm_class ( client ) . reply ( ) <EOL> if wm_class is not None : <EOL> try : <EOL> inst , cls = wm_class <EOL> matchNames = set ( [ inst . lower ( ) , cls . lower ( ) ] ) <EOL> if matchNames . intersection ( config . ignore ) : <EOL> debug ( '<STR_LIT>' % nm ) <EOL> return True <EOL> if hasattr ( config , '<STR_LIT>' ) and config . tile_only : <EOL> if not matchNames . intersection ( config . tile_only ) : <EOL> debug ( '<STR_LIT>' <EOL> '<STR_LIT:list>' % nm ) <EOL> return True <EOL> except ValueError : <EOL> pass <EOL> if icccm . get_wm_transient_for ( client ) . reply ( ) is not None : <EOL> debug ( '<STR_LIT>' % nm ) <EOL> ignore . append ( client ) <EOL> return True <EOL> wtype = ewmh . get_wm_window_type ( client ) . reply ( ) <EOL> if wtype : <EOL> for atom in wtype : <EOL> aname = util . get_atom_name ( atom ) <EOL> if aname in ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> debug ( '<STR_LIT>' % ( nm , aname ) ) <EOL> ignore . append ( client ) <EOL> return True <EOL> wstate = ewmh . get_wm_state ( client ) . reply ( ) <EOL> if wstate is None : <EOL> debug ( '<STR_LIT>' % nm ) <EOL> return True <EOL> for atom in wstate : <EOL> aname = util . get_atom_name ( atom ) <EOL> if aname == '<STR_LIT>' : <EOL> debug ( '<STR_LIT>' % nm ) <EOL> return True <EOL> if aname in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> debug ( '<STR_LIT>' % ( nm , aname ) ) <EOL> return True <EOL> d = ewmh . get_wm_desktop ( client ) . reply ( ) <EOL> if d == <NUM_LIT> : <EOL> debug ( '<STR_LIT>' '<STR_LIT>' % nm ) <EOL> return True <EOL> return False <EOL> def cb_property_notify ( e ) : <EOL> aname = util . get_atom_name ( e . atom ) <EOL> if aname == '<STR_LIT>' : <EOL> update_clients ( ) <EOL> event . connect ( '<STR_LIT>' , xpybutil . root , cb_property_notify ) </s>
