<s> __docformat__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> from ctypes import * <EOL> import unicodedata <EOL> import warnings <EOL> import pyglet <EOL> from pyglet . window import WindowException , NoSuchDisplayException , MouseCursorException , MouseCursor , DefaultMouseCursor , ImageMouseCursor , BaseWindow , _PlatformEventHandler , _ViewEventHandler <EOL> from pyglet . window import key <EOL> from pyglet . window import mouse <EOL> from pyglet . event import EventDispatcher <EOL> from pyglet . canvas . xlib import XlibCanvas <EOL> from pyglet . libs . x11 import xlib <EOL> from pyglet . libs . x11 import cursorfont <EOL> from pyglet . compat import asbytes <EOL> try : <EOL> from pyglet . libs . x11 import xsync <EOL> _have_xsync = True <EOL> except : <EOL> _have_xsync = False <EOL> class mwmhints_t ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , c_uint32 ) , <EOL> ( '<STR_LIT>' , c_uint32 ) , <EOL> ( '<STR_LIT>' , c_uint32 ) , <EOL> ( '<STR_LIT>' , c_int32 ) , <EOL> ( '<STR_LIT:status>' , c_uint32 ) <EOL> ] <EOL> XA_CARDINAL = <NUM_LIT:6> <EOL> _have_utf8 = hasattr ( xlib . _lib , '<STR_LIT>' ) <EOL> _motion_map = { <EOL> ( key . UP , False ) : key . MOTION_UP , <EOL> ( key . RIGHT , False ) : key . MOTION_RIGHT , <EOL> ( key . DOWN , False ) : key . MOTION_DOWN , <EOL> ( key . LEFT , False ) : key . MOTION_LEFT , <EOL> ( key . RIGHT , True ) : key . MOTION_NEXT_WORD , <EOL> ( key . LEFT , True ) : key . MOTION_PREVIOUS_WORD , <EOL> ( key . HOME , False ) : key . MOTION_BEGINNING_OF_LINE , <EOL> ( key . END , False ) : key . MOTION_END_OF_LINE , <EOL> ( key . PAGEUP , False ) : key . MOTION_PREVIOUS_PAGE , <EOL> ( key . PAGEDOWN , False ) : key . MOTION_NEXT_PAGE , <EOL> ( key . HOME , True ) : key . MOTION_BEGINNING_OF_FILE , <EOL> ( key . END , True ) : key . MOTION_END_OF_FILE , <EOL> ( key . BACKSPACE , False ) : key . MOTION_BACKSPACE , <EOL> ( key . DELETE , False ) : key . MOTION_DELETE , <EOL> } <EOL> class XlibException ( WindowException ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> class XlibMouseCursor ( MouseCursor ) : <EOL> drawable = False <EOL> def __init__ ( self , cursor ) : <EOL> self . cursor = cursor <EOL> XlibEventHandler = _PlatformEventHandler <EOL> ViewEventHandler = _ViewEventHandler <EOL> class XlibWindow ( BaseWindow ) : <EOL> _x_display = None <EOL> _x_screen_id = None <EOL> _x_ic = None <EOL> _window = None <EOL> _minimum_size = None <EOL> _maximum_size = None <EOL> _override_redirect = False <EOL> _x = <NUM_LIT:0> <EOL> _y = <NUM_LIT:0> <EOL> _width = <NUM_LIT:0> <EOL> _height = <NUM_LIT:0> <EOL> _mouse_exclusive_client = None <EOL> _mouse_buttons = [ False ] * <NUM_LIT:6> <EOL> _keyboard_exclusive = False <EOL> _active = True <EOL> _applied_mouse_exclusive = False <EOL> _applied_keyboard_exclusive = False <EOL> _mapped = False <EOL> _lost_context = False <EOL> _lost_context_state = False <EOL> _enable_xsync = False <EOL> _current_sync_value = None <EOL> _current_sync_valid = False <EOL> _needs_resize = False <EOL> _default_event_mask = ( <NUM_LIT> <EOL> & ~ xlib . PointerMotionHintMask <EOL> & ~ xlib . ResizeRedirectMask <EOL> & ~ xlib . SubstructureNotifyMask ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . _event_handlers = { } <EOL> self . _view_event_handlers = { } <EOL> for name in self . _platform_event_names : <EOL> if not hasattr ( self , name ) : <EOL> continue <EOL> func = getattr ( self , name ) <EOL> for message in func . _platform_event_data : <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> self . _view_event_handlers [ message ] = func <EOL> else : <EOL> self . _event_handlers [ message ] = func <EOL> super ( XlibWindow , self ) . __init__ ( * args , ** kwargs ) <EOL> def _recreate ( self , changes ) : <EOL> if ( '<STR_LIT>' in changes or '<STR_LIT>' in changes ) : <EOL> self . context . detach ( ) <EOL> xlib . XDestroyWindow ( self . _x_display , self . _window ) <EOL> del self . display . _window_map [ self . _window ] <EOL> del self . display . _window_map [ self . _view ] <EOL> self . _window = None <EOL> self . _mapped = False <EOL> if '<STR_LIT>' in changes : <EOL> self . _lost_context = True <EOL> self . _lost_context_state = True <EOL> self . _create ( ) <EOL> def _create ( self ) : <EOL> if self . _window and self . _mapped : <EOL> self . _unmap ( ) <EOL> self . _x_display = self . display . _display <EOL> self . _x_screen_id = self . display . x_screen <EOL> if not self . _window : <EOL> root = xlib . XRootWindow ( self . _x_display , self . _x_screen_id ) <EOL> visual_info = self . config . get_visual_info ( ) <EOL> visual = visual_info . visual <EOL> visual_id = xlib . XVisualIDFromVisual ( visual ) <EOL> default_visual = xlib . XDefaultVisual ( <EOL> self . _x_display , self . _x_screen_id ) <EOL> default_visual_id = xlib . XVisualIDFromVisual ( default_visual ) <EOL> window_attributes = xlib . XSetWindowAttributes ( ) <EOL> if visual_id != default_visual_id : <EOL> window_attributes . colormap = xlib . XCreateColormap ( <EOL> self . _x_display , root , visual , xlib . AllocNone ) <EOL> else : <EOL> window_attributes . colormap = xlib . XDefaultColormap ( <EOL> self . _x_display , self . _x_screen_id ) <EOL> window_attributes . bit_gravity = xlib . StaticGravity <EOL> mask = xlib . CWColormap | xlib . CWBitGravity | xlib . CWBackPixel <EOL> if self . _fullscreen : <EOL> width , height = self . screen . width , self . screen . height <EOL> self . _view_x = ( width - self . _width ) // <NUM_LIT:2> <EOL> self . _view_y = ( height - self . _height ) // <NUM_LIT:2> <EOL> else : <EOL> width , height = self . _width , self . _height <EOL> self . _view_x = self . _view_y = <NUM_LIT:0> <EOL> self . _window = xlib . XCreateWindow ( self . _x_display , root , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , width , height , <NUM_LIT:0> , visual_info . depth , <EOL> xlib . InputOutput , visual , mask , <EOL> byref ( window_attributes ) ) <EOL> self . _view = xlib . XCreateWindow ( self . _x_display , <EOL> self . _window , self . _view_x , self . _view_y , <EOL> self . _width , self . _height , <NUM_LIT:0> , visual_info . depth , <EOL> xlib . InputOutput , visual , mask , <EOL> byref ( window_attributes ) ) ; <EOL> xlib . XMapWindow ( self . _x_display , self . _view ) <EOL> xlib . XSelectInput ( <EOL> self . _x_display , self . _view , self . _default_event_mask ) <EOL> self . display . _window_map [ self . _window ] = self . dispatch_platform_event <EOL> self . display . _window_map [ self . _view ] = self . dispatch_platform_event_view <EOL> self . canvas = XlibCanvas ( self . display , self . _view ) <EOL> self . context . attach ( self . canvas ) <EOL> self . context . set_vsync ( self . _vsync ) <EOL> self . _enable_xsync = ( pyglet . options [ '<STR_LIT>' ] and <EOL> self . display . _enable_xsync and <EOL> self . config . double_buffer ) <EOL> protocols = [ ] <EOL> protocols . append ( xlib . XInternAtom ( self . _x_display , <EOL> asbytes ( '<STR_LIT>' ) , False ) ) <EOL> if self . _enable_xsync : <EOL> protocols . append ( xlib . XInternAtom ( self . _x_display , <EOL> asbytes ( '<STR_LIT>' ) , <EOL> False ) ) <EOL> protocols = ( c_ulong * len ( protocols ) ) ( * protocols ) <EOL> xlib . XSetWMProtocols ( self . _x_display , self . _window , <EOL> protocols , len ( protocols ) ) <EOL> if self . _enable_xsync : <EOL> value = xsync . XSyncValue ( ) <EOL> self . _sync_counter = xlib . XID ( <EOL> xsync . XSyncCreateCounter ( self . _x_display , value ) ) <EOL> atom = xlib . XInternAtom ( self . _x_display , <EOL> asbytes ( '<STR_LIT>' ) , False ) <EOL> ptr = pointer ( self . _sync_counter ) <EOL> xlib . XChangeProperty ( self . _x_display , self . _window , <EOL> atom , XA_CARDINAL , <NUM_LIT:32> , <EOL> xlib . PropModeReplace , <EOL> cast ( ptr , POINTER ( c_ubyte ) ) , <NUM_LIT:1> ) <EOL> attributes = xlib . XSetWindowAttributes ( ) <EOL> attributes_mask = <NUM_LIT:0> <EOL> self . _override_redirect = False <EOL> if self . _fullscreen : <EOL> if pyglet . options [ '<STR_LIT>' ] : <EOL> attributes . override_redirect = self . _fullscreen <EOL> attributes_mask |= xlib . CWOverrideRedirect <EOL> self . _override_redirect = True <EOL> else : <EOL> self . _set_wm_state ( '<STR_LIT>' ) <EOL> if self . _fullscreen : <EOL> xlib . XMoveResizeWindow ( self . _x_display , self . _window , <EOL> self . screen . x , self . screen . y , <EOL> self . screen . width , self . screen . height ) <EOL> else : <EOL> xlib . XResizeWindow ( self . _x_display , self . _window , <EOL> self . _width , self . _height ) <EOL> xlib . XChangeWindowAttributes ( self . _x_display , self . _window , <EOL> attributes_mask , byref ( attributes ) ) <EOL> styles = { <EOL> self . WINDOW_STYLE_DEFAULT : '<STR_LIT>' , <EOL> self . WINDOW_STYLE_DIALOG : '<STR_LIT>' , <EOL> self . WINDOW_STYLE_TOOL : '<STR_LIT>' , <EOL> } <EOL> if self . _style in styles : <EOL> self . _set_atoms_property ( '<STR_LIT>' , <EOL> ( styles [ self . _style ] , ) ) <EOL> elif self . _style == self . WINDOW_STYLE_BORDERLESS : <EOL> MWM_HINTS_DECORATIONS = <NUM_LIT:1> << <NUM_LIT:1> <EOL> PROP_MWM_HINTS_ELEMENTS = <NUM_LIT:5> <EOL> mwmhints = mwmhints_t ( ) <EOL> mwmhints . flags = MWM_HINTS_DECORATIONS <EOL> mwmhints . decorations = <NUM_LIT:0> <EOL> name = xlib . XInternAtom ( self . _x_display , '<STR_LIT>' , False ) <EOL> xlib . XChangeProperty ( self . _x_display , self . _window , <EOL> name , name , <NUM_LIT:32> , xlib . PropModeReplace , <EOL> cast ( pointer ( mwmhints ) , POINTER ( c_ubyte ) ) , <EOL> PROP_MWM_HINTS_ELEMENTS ) <EOL> if not self . _resizable and not self . _fullscreen : <EOL> self . set_minimum_size ( self . _width , self . _height ) <EOL> self . set_maximum_size ( self . _width , self . _height ) <EOL> self . set_caption ( self . _caption ) <EOL> if _have_utf8 and not self . _x_ic : <EOL> if not self . display . _x_im : <EOL> xlib . XSetLocaleModifiers ( asbytes ( '<STR_LIT>' ) ) <EOL> self . display . _x_im = xlib . XOpenIM ( self . _x_display , None , None , None ) <EOL> xlib . XFlush ( self . _x_display ) ; <EOL> xlib . XCreateIC . argtypes = [ xlib . XIM , <EOL> c_char_p , c_int , <EOL> c_char_p , xlib . Window , <EOL> c_char_p , xlib . Window , <EOL> c_void_p ] <EOL> self . _x_ic = xlib . XCreateIC ( self . display . _x_im , <EOL> asbytes ( '<STR_LIT>' ) , xlib . XIMPreeditNothing | xlib . XIMStatusNothing , <EOL> asbytes ( '<STR_LIT>' ) , self . _window , <EOL> asbytes ( '<STR_LIT>' ) , self . _window , <EOL> None ) <EOL> filter_events = c_ulong ( ) <EOL> xlib . XGetICValues ( self . _x_ic , <EOL> '<STR_LIT>' , byref ( filter_events ) , <EOL> None ) <EOL> self . _default_event_mask |= filter_events . value <EOL> xlib . XSetICFocus ( self . _x_ic ) <EOL> self . switch_to ( ) <EOL> if self . _visible : <EOL> self . set_visible ( True ) <EOL> self . set_mouse_platform_visible ( ) <EOL> self . _applied_mouse_exclusive = None <EOL> self . _update_exclusivity ( ) <EOL> def _map ( self ) : <EOL> if self . _mapped : <EOL> return <EOL> xlib . XSelectInput ( <EOL> self . _x_display , self . _window , xlib . StructureNotifyMask ) <EOL> xlib . XMapRaised ( self . _x_display , self . _window ) <EOL> e = xlib . XEvent ( ) <EOL> while True : <EOL> xlib . XNextEvent ( self . _x_display , e ) <EOL> if e . type == xlib . MapNotify : <EOL> break <EOL> xlib . XSelectInput ( <EOL> self . _x_display , self . _window , self . _default_event_mask ) <EOL> self . _mapped = True <EOL> if self . _override_redirect : <EOL> self . activate ( ) <EOL> self . dispatch_event ( '<STR_LIT>' , self . _width , self . _height ) <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> def _unmap ( self ) : <EOL> if not self . _mapped : <EOL> return <EOL> xlib . XSelectInput ( <EOL> self . _x_display , self . _window , xlib . StructureNotifyMask ) <EOL> xlib . XUnmapWindow ( self . _x_display , self . _window ) <EOL> e = xlib . XEvent ( ) <EOL> while True : <EOL> xlib . XNextEvent ( self . _x_display , e ) <EOL> if e . type == xlib . UnmapNotify : <EOL> break <EOL> xlib . XSelectInput ( <EOL> self . _x_display , self . _window , self . _default_event_mask ) <EOL> self . _mapped = False <EOL> def _get_root ( self ) : <EOL> attributes = xlib . XWindowAttributes ( ) <EOL> xlib . XGetWindowAttributes ( self . _x_display , self . _window , <EOL> byref ( attributes ) ) <EOL> return attributes . root <EOL> def close ( self ) : <EOL> if not self . _window : <EOL> return <EOL> self . context . destroy ( ) <EOL> self . _unmap ( ) <EOL> if self . _window : <EOL> xlib . XDestroyWindow ( self . _x_display , self . _window ) <EOL> del self . display . _window_map [ self . _window ] <EOL> self . _window = None <EOL> if _have_utf8 : <EOL> xlib . XDestroyIC ( self . _x_ic ) <EOL> self . _x_ic = None <EOL> super ( XlibWindow , self ) . close ( ) <EOL> def switch_to ( self ) : <EOL> if self . context : <EOL> self . context . set_current ( ) <EOL> def flip ( self ) : <EOL> self . draw_mouse_cursor ( ) <EOL> if self . context : <EOL> self . context . flip ( ) <EOL> self . _sync_resize ( ) <EOL> def set_vsync ( self , vsync ) : <EOL> if pyglet . options [ '<STR_LIT>' ] is not None : <EOL> vsync = pyglet . options [ '<STR_LIT>' ] <EOL> self . _vsync = vsync <EOL> self . context . set_vsync ( vsync ) <EOL> def set_caption ( self , caption ) : <EOL> if caption is None : <EOL> caption = '<STR_LIT>' <EOL> self . _caption = caption <EOL> self . _set_text_property ( '<STR_LIT>' , caption , allow_utf8 = False ) <EOL> self . _set_text_property ( '<STR_LIT>' , caption , allow_utf8 = False ) <EOL> self . _set_text_property ( '<STR_LIT>' , caption ) <EOL> self . _set_text_property ( '<STR_LIT>' , caption ) <EOL> def get_caption ( self ) : <EOL> return self . _caption <EOL> def set_size ( self , width , height ) : <EOL> if self . _fullscreen : <EOL> raise WindowException ( '<STR_LIT>' ) <EOL> self . _width = width <EOL> self . _height = height <EOL> if not self . _resizable : <EOL> self . set_minimum_size ( width , height ) <EOL> self . set_maximum_size ( width , height ) <EOL> xlib . XResizeWindow ( self . _x_display , self . _window , width , height ) <EOL> self . _update_view_size ( ) <EOL> self . dispatch_event ( '<STR_LIT>' , width , height ) <EOL> def _update_view_size ( self ) : <EOL> xlib . XResizeWindow ( self . _x_display , self . _view , <EOL> self . _width , self . _height ) <EOL> def get_size ( self ) : <EOL> return self . _width , self . _height <EOL> def set_location ( self , x , y ) : <EOL> attributes = xlib . XWindowAttributes ( ) <EOL> xlib . XGetWindowAttributes ( self . _x_display , self . _window , <EOL> byref ( attributes ) ) <EOL> x -= attributes . x <EOL> y -= attributes . y <EOL> xlib . XMoveWindow ( self . _x_display , self . _window , x , y ) <EOL> def get_location ( self ) : <EOL> child = xlib . Window ( ) <EOL> x = c_int ( ) <EOL> y = c_int ( ) <EOL> xlib . XTranslateCoordinates ( self . _x_display , <EOL> self . _window , <EOL> self . _get_root ( ) , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> byref ( x ) , <EOL> byref ( y ) , <EOL> byref ( child ) ) <EOL> return x . value , y . value <EOL> def activate ( self ) : <EOL> xlib . XSetInputFocus ( self . _x_display , self . _window , <EOL> xlib . RevertToParent , xlib . CurrentTime ) <EOL> def set_visible ( self , visible = True ) : <EOL> if visible : <EOL> self . _map ( ) <EOL> else : <EOL> self . _unmap ( ) <EOL> self . _visible = visible <EOL> def set_minimum_size ( self , width , height ) : <EOL> self . _minimum_size = width , height <EOL> self . _set_wm_normal_hints ( ) <EOL> def set_maximum_size ( self , width , height ) : <EOL> self . _maximum_size = width , height <EOL> self . _set_wm_normal_hints ( ) <EOL> def minimize ( self ) : <EOL> xlib . XIconifyWindow ( self . _x_display , self . _window , self . _x_screen_id ) <EOL> def maximize ( self ) : <EOL> self . _set_wm_state ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def set_mouse_platform_visible ( self , platform_visible = None ) : <EOL> if platform_visible is None : <EOL> platform_visible = self . _mouse_visible and not self . _mouse_cursor . drawable <EOL> if not platform_visible : <EOL> black = xlib . XBlackPixel ( self . _x_display , self . _x_screen_id ) <EOL> black = xlib . XColor ( ) <EOL> bmp = xlib . XCreateBitmapFromData ( self . _x_display , self . _window , <EOL> c_buffer ( <NUM_LIT:8> ) , <NUM_LIT:8> , <NUM_LIT:8> ) <EOL> cursor = xlib . XCreatePixmapCursor ( self . _x_display , bmp , bmp , <EOL> black , black , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> xlib . XDefineCursor ( self . _x_display , self . _window , cursor ) <EOL> xlib . XFreeCursor ( self . _x_display , cursor ) <EOL> xlib . XFreePixmap ( self . _x_display , bmp ) <EOL> else : <EOL> if isinstance ( self . _mouse_cursor , XlibMouseCursor ) : <EOL> xlib . XDefineCursor ( self . _x_display , self . _window , <EOL> self . _mouse_cursor . cursor ) <EOL> else : <EOL> xlib . XUndefineCursor ( self . _x_display , self . _window ) <EOL> def set_mouse_position ( self , x , y ) : <EOL> xlib . XWarpPointer ( self . _x_display , <EOL> <NUM_LIT:0> , <EOL> self . _window , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> x , self . _height - y , <EOL> ) <EOL> def _update_exclusivity ( self ) : <EOL> mouse_exclusive = self . _active and self . _mouse_exclusive <EOL> keyboard_exclusive = self . _active and self . _keyboard_exclusive <EOL> if mouse_exclusive != self . _applied_mouse_exclusive : <EOL> if mouse_exclusive : <EOL> self . set_mouse_platform_visible ( False ) <EOL> xlib . XGrabPointer ( self . _x_display , self . _window , <EOL> True , <EOL> <NUM_LIT:0> , <EOL> xlib . GrabModeAsync , <EOL> xlib . GrabModeAsync , <EOL> self . _window , <EOL> <NUM_LIT:0> , <EOL> xlib . CurrentTime ) <EOL> x = self . _width / <NUM_LIT:2> <EOL> y = self . _height / <NUM_LIT:2> <EOL> self . _mouse_exclusive_client = x , y <EOL> self . set_mouse_position ( x , y ) <EOL> elif self . _fullscreen and not self . screen . _xinerama : <EOL> self . set_mouse_position ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> r = xlib . XGrabPointer ( self . _x_display , self . _view , <EOL> True , <NUM_LIT:0> , <EOL> xlib . GrabModeAsync , <EOL> xlib . GrabModeAsync , <EOL> self . _view , <EOL> <NUM_LIT:0> , <EOL> xlib . CurrentTime ) <EOL> if r : <EOL> self . _applied_mouse_exclusive = None <EOL> return <EOL> self . set_mouse_platform_visible ( ) <EOL> else : <EOL> xlib . XUngrabPointer ( self . _x_display , xlib . CurrentTime ) <EOL> self . set_mouse_platform_visible ( ) <EOL> self . _applied_mouse_exclusive = mouse_exclusive <EOL> if keyboard_exclusive != self . _applied_keyboard_exclusive : <EOL> if keyboard_exclusive : <EOL> xlib . XGrabKeyboard ( self . _x_display , <EOL> self . _window , <EOL> False , <EOL> xlib . GrabModeAsync , <EOL> xlib . GrabModeAsync , <EOL> xlib . CurrentTime ) <EOL> else : <EOL> xlib . XUngrabKeyboard ( self . _x_display , xlib . CurrentTime ) <EOL> self . _applied_keyboard_exclusive = keyboard_exclusive <EOL> def set_exclusive_mouse ( self , exclusive = True ) : <EOL> if exclusive == self . _mouse_exclusive : <EOL> return <EOL> self . _mouse_exclusive = exclusive <EOL> self . _update_exclusivity ( ) <EOL> def set_exclusive_keyboard ( self , exclusive = True ) : <EOL> if exclusive == self . _keyboard_exclusive : <EOL> return <EOL> self . _keyboard_exclusive = exclusive <EOL> self . _update_exclusivity ( ) <EOL> def get_system_mouse_cursor ( self , name ) : <EOL> if name == self . CURSOR_DEFAULT : <EOL> return DefaultMouseCursor ( ) <EOL> cursor_shapes = { <EOL> self . CURSOR_CROSSHAIR : cursorfont . XC_crosshair , <EOL> self . CURSOR_HAND : cursorfont . XC_hand2 , <EOL> self . CURSOR_HELP : cursorfont . XC_question_arrow , <EOL> self . CURSOR_NO : cursorfont . XC_pirate , <EOL> self . CURSOR_SIZE : cursorfont . XC_fleur , <EOL> self . CURSOR_SIZE_UP : cursorfont . XC_top_side , <EOL> self . CURSOR_SIZE_UP_RIGHT : cursorfont . XC_top_right_corner , <EOL> self . CURSOR_SIZE_RIGHT : cursorfont . XC_right_side , <EOL> self . CURSOR_SIZE_DOWN_RIGHT : cursorfont . XC_bottom_right_corner , <EOL> self . CURSOR_SIZE_DOWN : cursorfont . XC_bottom_side , <EOL> self . CURSOR_SIZE_DOWN_LEFT : cursorfont . XC_bottom_left_corner , <EOL> self . CURSOR_SIZE_LEFT : cursorfont . XC_left_side , <EOL> self . CURSOR_SIZE_UP_LEFT : cursorfont . XC_top_left_corner , <EOL> self . CURSOR_SIZE_UP_DOWN : cursorfont . XC_sb_v_double_arrow , <EOL> self . CURSOR_SIZE_LEFT_RIGHT : cursorfont . XC_sb_h_double_arrow , <EOL> self . CURSOR_TEXT : cursorfont . XC_xterm , <EOL> self . CURSOR_WAIT : cursorfont . XC_watch , <EOL> self . CURSOR_WAIT_ARROW : cursorfont . XC_watch , <EOL> } <EOL> if name not in cursor_shapes : <EOL> raise MouseCursorException ( '<STR_LIT>' % name ) <EOL> cursor = xlib . XCreateFontCursor ( self . _x_display , cursor_shapes [ name ] ) <EOL> return XlibMouseCursor ( cursor ) <EOL> def set_icon ( self , * images ) : <EOL> import sys <EOL> format = { <EOL> ( '<STR_LIT>' , <NUM_LIT:4> ) : '<STR_LIT>' , <EOL> ( '<STR_LIT>' , <NUM_LIT:8> ) : '<STR_LIT>' , <EOL> ( '<STR_LIT>' , <NUM_LIT:4> ) : '<STR_LIT>' , <EOL> ( '<STR_LIT>' , <NUM_LIT:8> ) : '<STR_LIT>' <EOL> } [ ( sys . byteorder , sizeof ( c_ulong ) ) ] <EOL> data = '<STR_LIT>' <EOL> for image in images : <EOL> image = image . get_image_data ( ) <EOL> pitch = - ( image . width * len ( format ) ) <EOL> s = c_buffer ( sizeof ( c_ulong ) * <NUM_LIT:2> ) <EOL> memmove ( s , cast ( ( c_ulong * <NUM_LIT:2> ) ( image . width , image . height ) , <EOL> POINTER ( c_ubyte ) ) , len ( s ) ) <EOL> data += s . raw + image . get_data ( format , pitch ) <EOL> buffer = ( c_ubyte * len ( data ) ) ( ) <EOL> memmove ( buffer , data , len ( data ) ) <EOL> atom = xlib . XInternAtom ( self . _x_display , '<STR_LIT>' , False ) <EOL> xlib . XChangeProperty ( self . _x_display , self . _window , atom , XA_CARDINAL , <EOL> <NUM_LIT:32> , xlib . PropModeReplace , buffer , len ( data ) / sizeof ( c_ulong ) ) <EOL> def _set_wm_normal_hints ( self ) : <EOL> hints = xlib . XAllocSizeHints ( ) . contents <EOL> if self . _minimum_size : <EOL> hints . flags |= xlib . PMinSize <EOL> hints . min_width , hints . min_height = self . _minimum_size <EOL> if self . _maximum_size : <EOL> hints . flags |= xlib . PMaxSize <EOL> hints . max_width , hints . max_height = self . _maximum_size <EOL> xlib . XSetWMNormalHints ( self . _x_display , self . _window , byref ( hints ) ) <EOL> def _set_text_property ( self , name , value , allow_utf8 = True ) : <EOL> atom = xlib . XInternAtom ( self . _x_display , asbytes ( name ) , False ) <EOL> if not atom : <EOL> raise XlibException ( '<STR_LIT>' % name ) <EOL> assert type ( value ) in ( str , unicode ) <EOL> property = xlib . XTextProperty ( ) <EOL> if _have_utf8 and allow_utf8 : <EOL> buf = create_string_buffer ( value . encode ( '<STR_LIT:utf8>' ) ) <EOL> result = xlib . Xutf8TextListToTextProperty ( self . _x_display , <EOL> cast ( pointer ( buf ) , c_char_p ) , <NUM_LIT:1> , xlib . XUTF8StringStyle , <EOL> byref ( property ) ) <EOL> if result < <NUM_LIT:0> : <EOL> raise XlibException ( '<STR_LIT>' ) <EOL> else : <EOL> buf = create_string_buffer ( value . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) ) <EOL> result = xlib . XStringListToTextProperty ( <EOL> cast ( pointer ( buf ) , c_char_p ) , <NUM_LIT:1> , byref ( property ) ) <EOL> if result < <NUM_LIT:0> : <EOL> raise XlibException ( '<STR_LIT>' ) <EOL> xlib . XSetTextProperty ( self . _x_display , <EOL> self . _window , byref ( property ) , atom ) <EOL> def _set_atoms_property ( self , name , values , mode = xlib . PropModeReplace ) : <EOL> name_atom = xlib . XInternAtom ( self . _x_display , asbytes ( name ) , False ) <EOL> atoms = [ ] <EOL> for value in values : <EOL> atoms . append ( xlib . XInternAtom ( self . _x_display , asbytes ( value ) , False ) ) <EOL> atom_type = xlib . XInternAtom ( self . _x_display , asbytes ( '<STR_LIT>' ) , False ) <EOL> if len ( atoms ) : <EOL> atoms_ar = ( xlib . Atom * len ( atoms ) ) ( * atoms ) <EOL> xlib . XChangeProperty ( self . _x_display , self . _window , <EOL> name_atom , atom_type , <NUM_LIT:32> , mode , <EOL> cast ( pointer ( atoms_ar ) , POINTER ( c_ubyte ) ) , len ( atoms ) ) <EOL> else : <EOL> xlib . XDeleteProperty ( self . _x_display , self . _window , net_wm_state ) <EOL> def _set_wm_state ( self , * states ) : <EOL> net_wm_state = xlib . XInternAtom ( self . _x_display , '<STR_LIT>' , False ) <EOL> atoms = [ ] <EOL> for state in states : <EOL> atoms . append ( xlib . XInternAtom ( self . _x_display , state , False ) ) <EOL> atom_type = xlib . XInternAtom ( self . _x_display , '<STR_LIT>' , False ) <EOL> if len ( atoms ) : <EOL> atoms_ar = ( xlib . Atom * len ( atoms ) ) ( * atoms ) <EOL> xlib . XChangeProperty ( self . _x_display , self . _window , <EOL> net_wm_state , atom_type , <NUM_LIT:32> , xlib . PropModePrepend , <EOL> cast ( pointer ( atoms_ar ) , POINTER ( c_ubyte ) ) , len ( atoms ) ) <EOL> else : <EOL> xlib . XDeleteProperty ( self . _x_display , self . _window , net_wm_state ) <EOL> e = xlib . XEvent ( ) <EOL> e . xclient . type = xlib . ClientMessage <EOL> e . xclient . message_type = net_wm_state <EOL> e . xclient . display = cast ( self . _x_display , POINTER ( xlib . Display ) ) <EOL> e . xclient . window = self . _window <EOL> e . xclient . format = <NUM_LIT:32> <EOL> e . xclient . data . l [ <NUM_LIT:0> ] = xlib . PropModePrepend <EOL> for i , atom in enumerate ( atoms ) : <EOL> e . xclient . data . l [ i + <NUM_LIT:1> ] = atom <EOL> xlib . XSendEvent ( self . _x_display , self . _get_root ( ) , <EOL> False , xlib . SubstructureRedirectMask , byref ( e ) ) <EOL> def dispatch_events ( self ) : <EOL> self . dispatch_pending_events ( ) <EOL> self . _allow_dispatch_event = True <EOL> e = xlib . XEvent ( ) <EOL> _x_display = self . _x_display <EOL> _window = self . _window <EOL> _view = self . _view <EOL> while xlib . XCheckWindowEvent ( _x_display , _window , <EOL> <NUM_LIT> , byref ( e ) ) : <EOL> if e . xany . type not in ( xlib . KeyPress , xlib . KeyRelease ) : <EOL> if xlib . XFilterEvent ( e , <NUM_LIT:0> ) : <EOL> continue <EOL> self . dispatch_platform_event ( e ) <EOL> while xlib . XCheckWindowEvent ( _x_display , _view , <EOL> <NUM_LIT> , byref ( e ) ) : <EOL> if e . xany . type not in ( xlib . KeyPress , xlib . KeyRelease ) : <EOL> if xlib . XFilterEvent ( e , <NUM_LIT:0> ) : <EOL> continue <EOL> self . dispatch_platform_event_view ( e ) <EOL> while xlib . XCheckTypedWindowEvent ( _x_display , _window , <EOL> xlib . ClientMessage , byref ( e ) ) : <EOL> self . dispatch_platform_event ( e ) <EOL> if self . _needs_resize : <EOL> self . dispatch_event ( '<STR_LIT>' , self . _width , self . _height ) <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> self . _needs_resize = False <EOL> self . _allow_dispatch_event = False <EOL> def dispatch_pending_events ( self ) : <EOL> while self . _event_queue : <EOL> EventDispatcher . dispatch_event ( self , * self . _event_queue . pop ( <NUM_LIT:0> ) ) <EOL> if self . _lost_context : <EOL> self . _lost_context = False <EOL> EventDispatcher . dispatch_event ( self , '<STR_LIT>' ) <EOL> if self . _lost_context_state : <EOL> self . _lost_context_state = False <EOL> EventDispatcher . dispatch_event ( self , '<STR_LIT>' ) <EOL> def dispatch_platform_event ( self , e ) : <EOL> if self . _applied_mouse_exclusive is None : <EOL> self . _update_exclusivity ( ) <EOL> event_handler = self . _event_handlers . get ( e . type ) <EOL> if event_handler : <EOL> event_handler ( e ) <EOL> def dispatch_platform_event_view ( self , e ) : <EOL> event_handler = self . _view_event_handlers . get ( e . type ) <EOL> if event_handler : <EOL> event_handler ( e ) <EOL> @ staticmethod <EOL> def _translate_modifiers ( state ) : <EOL> modifiers = <NUM_LIT:0> <EOL> if state & xlib . ShiftMask : <EOL> modifiers |= key . MOD_SHIFT <EOL> if state & xlib . ControlMask : <EOL> modifiers |= key . MOD_CTRL <EOL> if state & xlib . LockMask : <EOL> modifiers |= key . MOD_CAPSLOCK <EOL> if state & xlib . Mod1Mask : <EOL> modifiers |= key . MOD_ALT <EOL> if state & xlib . Mod2Mask : <EOL> modifiers |= key . MOD_NUMLOCK <EOL> if state & xlib . Mod4Mask : <EOL> modifiers |= key . MOD_WINDOWS <EOL> if state & xlib . Mod5Mask : <EOL> modifiers |= key . MOD_SCROLLLOCK <EOL> return modifiers <EOL> '''<STR_LIT>''' <EOL> def _event_text_symbol ( self , ev ) : <EOL> text = None <EOL> symbol = xlib . KeySym ( ) <EOL> buffer = create_string_buffer ( <NUM_LIT> ) <EOL> count = xlib . XLookupString ( ev . xkey , <EOL> buffer , len ( buffer ) - <NUM_LIT:1> , <EOL> byref ( symbol ) , None ) <EOL> filtered = xlib . XFilterEvent ( ev , ev . xany . window ) <EOL> if ev . type == xlib . KeyPress and not filtered : <EOL> status = c_int ( ) <EOL> if _have_utf8 : <EOL> encoding = '<STR_LIT:utf8>' <EOL> count = xlib . Xutf8LookupString ( self . _x_ic , <EOL> ev . xkey , <EOL> buffer , len ( buffer ) - <NUM_LIT:1> , <EOL> byref ( symbol ) , byref ( status ) ) <EOL> if status . value == xlib . XBufferOverflow : <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> else : <EOL> encoding = '<STR_LIT:ascii>' <EOL> count = xlib . XLookupString ( ev . xkey , <EOL> buffer , len ( buffer ) - <NUM_LIT:1> , <EOL> byref ( symbol ) , None ) <EOL> if count : <EOL> status . value = xlib . XLookupBoth <EOL> if status . value & ( xlib . XLookupChars | xlib . XLookupBoth ) : <EOL> text = buffer . value [ : count ] . decode ( encoding ) <EOL> if text and unicodedata . category ( text ) == '<STR_LIT>' and text != '<STR_LIT:\r>' : <EOL> text = None <EOL> symbol = symbol . value <EOL> if ev . xkey . keycode == <NUM_LIT:0> and not filtered : <EOL> symbol = None <EOL> if symbol and symbol not in key . _key_names and ev . xkey . keycode : <EOL> symbol = ord ( unichr ( symbol ) . lower ( ) ) <EOL> if symbol not in key . _key_names : <EOL> symbol = key . user_key ( ev . xkey . keycode ) <EOL> if filtered : <EOL> return None , symbol <EOL> return text , symbol <EOL> def _event_text_motion ( self , symbol , modifiers ) : <EOL> if modifiers & key . MOD_ALT : <EOL> return None <EOL> ctrl = modifiers & key . MOD_CTRL != <NUM_LIT:0> <EOL> return _motion_map . get ( ( symbol , ctrl ) , None ) <EOL> @ ViewEventHandler <EOL> @ XlibEventHandler ( xlib . KeyPress ) <EOL> @ XlibEventHandler ( xlib . KeyRelease ) <EOL> def _event_key_view ( self , ev ) : <EOL> if ev . type == xlib . KeyRelease : <EOL> saved = [ ] <EOL> while True : <EOL> auto_event = xlib . XEvent ( ) <EOL> result = xlib . XCheckWindowEvent ( self . _x_display , <EOL> self . _window , xlib . KeyPress | xlib . KeyRelease , <EOL> byref ( auto_event ) ) <EOL> if not result : <EOL> break <EOL> saved . append ( auto_event ) <EOL> if auto_event . type == xlib . KeyRelease : <EOL> continue <EOL> if ev . xkey . keycode == auto_event . xkey . keycode : <EOL> text , symbol = self . _event_text_symbol ( auto_event ) <EOL> modifiers = self . _translate_modifiers ( ev . xkey . state ) <EOL> modifiers_ctrl = modifiers & ( key . MOD_CTRL | key . MOD_ALT ) <EOL> motion = self . _event_text_motion ( symbol , modifiers ) <EOL> if motion : <EOL> if modifiers & key . MOD_SHIFT : <EOL> self . dispatch_event ( <EOL> '<STR_LIT>' , motion ) <EOL> else : <EOL> self . dispatch_event ( '<STR_LIT>' , motion ) <EOL> elif text and not modifiers_ctrl : <EOL> self . dispatch_event ( '<STR_LIT>' , text ) <EOL> ditched = saved . pop ( ) <EOL> for auto_event in reversed ( saved ) : <EOL> xlib . XPutBackEvent ( self . _x_display , byref ( auto_event ) ) <EOL> return <EOL> else : <EOL> break <EOL> for auto_event in reversed ( saved ) : <EOL> xlib . XPutBackEvent ( self . _x_display , byref ( auto_event ) ) <EOL> text , symbol = self . _event_text_symbol ( ev ) <EOL> modifiers = self . _translate_modifiers ( ev . xkey . state ) <EOL> modifiers_ctrl = modifiers & ( key . MOD_CTRL | key . MOD_ALT ) <EOL> motion = self . _event_text_motion ( symbol , modifiers ) <EOL> if ev . type == xlib . KeyPress : <EOL> if symbol : <EOL> self . dispatch_event ( '<STR_LIT>' , symbol , modifiers ) <EOL> if motion : <EOL> if modifiers & key . MOD_SHIFT : <EOL> self . dispatch_event ( '<STR_LIT>' , motion ) <EOL> else : <EOL> self . dispatch_event ( '<STR_LIT>' , motion ) <EOL> elif text and not modifiers_ctrl : <EOL> self . dispatch_event ( '<STR_LIT>' , text ) <EOL> elif ev . type == xlib . KeyRelease : <EOL> if symbol : <EOL> self . dispatch_event ( '<STR_LIT>' , symbol , modifiers ) <EOL> @ XlibEventHandler ( xlib . KeyPress ) <EOL> @ XlibEventHandler ( xlib . KeyRelease ) <EOL> def _event_key ( self , ev ) : <EOL> return self . _event_key_view ( ev ) <EOL> @ ViewEventHandler <EOL> @ XlibEventHandler ( xlib . MotionNotify ) <EOL> def _event_motionnotify_view ( self , ev ) : <EOL> x = ev . xmotion . x <EOL> y = self . height - ev . xmotion . y <EOL> if self . _mouse_in_window : <EOL> dx = x - self . _mouse_x <EOL> dy = y - self . _mouse_y <EOL> else : <EOL> dx = dy = <NUM_LIT:0> <EOL> if self . _applied_mouse_exclusive and ( ev . xmotion . x , ev . xmotion . y ) == self . _mouse_exclusive_client : <EOL> self . _mouse_x = x <EOL> self . _mouse_y = y <EOL> return <EOL> if self . _applied_mouse_exclusive : <EOL> ex , ey = self . _mouse_exclusive_client <EOL> xlib . XWarpPointer ( self . _x_display , <EOL> <NUM_LIT:0> , <EOL> self . _window , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <NUM_LIT:0> , <EOL> ex , ey ) <EOL> self . _mouse_x = x <EOL> self . _mouse_y = y <EOL> self . _mouse_in_window = True <EOL> buttons = <NUM_LIT:0> <EOL> if ev . xmotion . state & xlib . Button1MotionMask : <EOL> buttons |= mouse . LEFT <EOL> if ev . xmotion . state & xlib . Button2MotionMask : <EOL> buttons |= mouse . MIDDLE <EOL> if ev . xmotion . state & xlib . Button3MotionMask : <EOL> buttons |= mouse . RIGHT <EOL> if buttons : <EOL> modifiers = self . _translate_modifiers ( ev . xmotion . state ) <EOL> self . dispatch_event ( '<STR_LIT>' , <EOL> x , y , dx , dy , buttons , modifiers ) <EOL> else : <EOL> self . dispatch_event ( '<STR_LIT>' , x , y , dx , dy ) <EOL> @ XlibEventHandler ( xlib . MotionNotify ) <EOL> def _event_motionnotify ( self , ev ) : <EOL> buttons = <NUM_LIT:0> <EOL> if ev . xmotion . state & xlib . Button1MotionMask : <EOL> buttons |= mouse . LEFT <EOL> if ev . xmotion . state & xlib . Button2MotionMask : <EOL> buttons |= mouse . MIDDLE <EOL> if ev . xmotion . state & xlib . Button3MotionMask : <EOL> buttons |= mouse . RIGHT <EOL> if buttons : <EOL> x = ev . xmotion . x - self . _view_x <EOL> y = self . _height - ( ev . xmotion . y - self . _view_y ) <EOL> if self . _mouse_in_window : <EOL> dx = x - self . _mouse_x <EOL> dy = y - self . _mouse_y <EOL> else : <EOL> dx = dy = <NUM_LIT:0> <EOL> self . _mouse_x = x <EOL> self . _mouse_y = y <EOL> modifiers = self . _translate_modifiers ( ev . xmotion . state ) <EOL> self . dispatch_event ( '<STR_LIT>' , <EOL> x , y , dx , dy , buttons , modifiers ) <EOL> @ XlibEventHandler ( xlib . ClientMessage ) <EOL> def _event_clientmessage ( self , ev ) : <EOL> atom = ev . xclient . data . l [ <NUM_LIT:0> ] <EOL> if atom == xlib . XInternAtom ( ev . xclient . display , <EOL> asbytes ( '<STR_LIT>' ) , False ) : <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> elif ( self . _enable_xsync and <EOL> atom == xlib . XInternAtom ( ev . xclient . display , <EOL> asbytes ( '<STR_LIT>' ) , False ) ) : <EOL> lo = ev . xclient . data . l [ <NUM_LIT:2> ] <EOL> hi = ev . xclient . data . l [ <NUM_LIT:3> ] <EOL> self . _current_sync_value = xsync . XSyncValue ( hi , lo ) <EOL> def _sync_resize ( self ) : <EOL> if self . _enable_xsync and self . _current_sync_valid : <EOL> if xsync . XSyncValueIsZero ( self . _current_sync_value ) : <EOL> self . _current_sync_valid = False <EOL> return <EOL> xsync . XSyncSetCounter ( self . _x_display , <EOL> self . _sync_counter , <EOL> self . _current_sync_value ) <EOL> self . _current_sync_value = None <EOL> self . _current_sync_valid = False <EOL> @ ViewEventHandler <EOL> @ XlibEventHandler ( xlib . ButtonPress ) <EOL> @ XlibEventHandler ( xlib . ButtonRelease ) <EOL> def _event_button ( self , ev ) : <EOL> x = ev . xbutton . x <EOL> y = self . height - ev . xbutton . y <EOL> button = <NUM_LIT:1> << ( ev . xbutton . button - <NUM_LIT:1> ) <EOL> modifiers = self . _translate_modifiers ( ev . xbutton . state ) <EOL> if ev . type == xlib . ButtonPress : <EOL> if self . _override_redirect and not self . _active : <EOL> self . activate ( ) <EOL> if ev . xbutton . button == <NUM_LIT:4> : <EOL> self . dispatch_event ( '<STR_LIT>' , x , y , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> elif ev . xbutton . button == <NUM_LIT:5> : <EOL> self . dispatch_event ( '<STR_LIT>' , x , y , <NUM_LIT:0> , - <NUM_LIT:1> ) <EOL> elif ev . xbutton . button < len ( self . _mouse_buttons ) : <EOL> self . _mouse_buttons [ ev . xbutton . button ] = True <EOL> self . dispatch_event ( '<STR_LIT>' , <EOL> x , y , button , modifiers ) <EOL> else : <EOL> if ev . xbutton . button < <NUM_LIT:4> : <EOL> self . _mouse_buttons [ ev . xbutton . button ] = False <EOL> self . dispatch_event ( '<STR_LIT>' , <EOL> x , y , button , modifiers ) <EOL> @ ViewEventHandler <EOL> @ XlibEventHandler ( xlib . Expose ) <EOL> def _event_expose ( self , ev ) : <EOL> if ev . xexpose . count > <NUM_LIT:0> : return <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> @ ViewEventHandler <EOL> @ XlibEventHandler ( xlib . EnterNotify ) <EOL> def _event_enternotify ( self , ev ) : <EOL> state = ev . xcrossing . state <EOL> self . _mouse_buttons [ <NUM_LIT:1> ] = state & xlib . Button1Mask <EOL> self . _mouse_buttons [ <NUM_LIT:2> ] = state & xlib . Button2Mask <EOL> self . _mouse_buttons [ <NUM_LIT:3> ] = state & xlib . Button3Mask <EOL> self . _mouse_buttons [ <NUM_LIT:4> ] = state & xlib . Button4Mask <EOL> self . _mouse_buttons [ <NUM_LIT:5> ] = state & xlib . Button5Mask <EOL> x = self . _mouse_x = ev . xcrossing . x <EOL> y = self . _mouse_y = self . height - ev . xcrossing . y <EOL> self . _mouse_in_window = True <EOL> self . dispatch_event ( '<STR_LIT>' , x , y ) <EOL> @ ViewEventHandler <EOL> @ XlibEventHandler ( xlib . LeaveNotify ) <EOL> def _event_leavenotify ( self , ev ) : <EOL> x = self . _mouse_x = ev . xcrossing . x <EOL> y = self . _mouse_y = self . height - ev . xcrossing . y <EOL> self . _mouse_in_window = False <EOL> self . dispatch_event ( '<STR_LIT>' , x , y ) <EOL> @ XlibEventHandler ( xlib . ConfigureNotify ) <EOL> def _event_configurenotify ( self , ev ) : <EOL> if self . _enable_xsync and self . _current_sync_value : <EOL> self . _current_sync_valid = True <EOL> if self . _fullscreen : <EOL> return <EOL> self . switch_to ( ) <EOL> w , h = ev . xconfigure . width , ev . xconfigure . height <EOL> x , y = ev . xconfigure . x , ev . xconfigure . y <EOL> if self . _width != w or self . _height != h : <EOL> self . _update_view_size ( ) <EOL> self . _width = w <EOL> self . _height = h <EOL> self . _needs_resize = True <EOL> if self . _x != x or self . _y != y : <EOL> self . dispatch_event ( '<STR_LIT>' , x , y ) <EOL> self . _x = x <EOL> self . _y = y <EOL> @ XlibEventHandler ( xlib . FocusIn ) <EOL> def _event_focusin ( self , ev ) : <EOL> self . _active = True <EOL> self . _update_exclusivity ( ) <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> xlib . XSetICFocus ( self . _x_ic ) <EOL> @ XlibEventHandler ( xlib . FocusOut ) <EOL> def _event_focusout ( self , ev ) : <EOL> self . _active = False <EOL> self . _update_exclusivity ( ) <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> xlib . XUnsetICFocus ( self . _x_ic ) <EOL> @ XlibEventHandler ( xlib . MapNotify ) <EOL> def _event_mapnotify ( self , ev ) : <EOL> self . _mapped = True <EOL> self . dispatch_event ( '<STR_LIT>' ) <EOL> self . _update_exclusivity ( ) <EOL> @ XlibEventHandler ( xlib . UnmapNotify ) <EOL> def _event_unmapnotify ( self , ev ) : <EOL> self . _mapped = False <EOL> self . dispatch_event ( '<STR_LIT>' ) </s>
