55from .base import DSIBase
66from .window import WindowBase
77from .image import Image
8+ from .buttons import MouseButtons
9+ from .box import Box
810
911# built-in modules
1012import logging
@@ -290,19 +292,6 @@ class KeyMasks(object):
290292 Mod5Mask = 128
291293
292294
293- class ButtonCodes (object ):
294- """
295- https://tronche.com/gui/x/xlib/events/keyboard-pointer/keyboard-pointer.html\n
296- /usr/include/X11/X.h: 259-263
297- """
298- AnyButton = 0
299- Button1 = 1
300- Button2 = 2
301- Button3 = 3
302- Button4 = 4
303- Button5 = 5
304-
305-
306295class Xlib (object ):
307296 def __init__ (self ):
308297 # load libX11.so.6
@@ -454,34 +443,39 @@ def active(self) -> bool:
454443 return self .xid == get_active_window_xid (self .xlib )
455444
456445 @property
457- def geometry (self ) -> tuple :
446+ def geometry (self ) -> Box :
458447 gwa = XWindowAttributes ()
459448 self .xlib .XGetWindowAttributes (self .xlib .display , self .xid , byref (gwa ))
460- return (gwa .x , gwa .y , gwa .width , gwa .height )
449+ return Box (
450+ x = gwa .x ,
451+ y = gwa .y ,
452+ width = gwa .width ,
453+ height = gwa .height
454+ )
461455
462- def get_image (self , geometry : tuple = None ) -> Image :
456+ def get_image (self , geometry : Box = None ) -> Image :
463457 if geometry is None :
464458 geometry = self .geometry
465459
466460 ximage = self .xlib .XGetImage (
467461 self .xlib .display , # Display
468462 self .xid , # Drawable (Window XID)
469- geometry [ 0 ] , # x
470- geometry [ 1 ] , # y
471- geometry [ 2 ] , # width
472- geometry [ 3 ] , # height
463+ geometry . x , # x
464+ geometry . y , # y
465+ geometry . width , # width
466+ geometry . height , # height
473467 0x00FFFFFF , # plane_mask
474468 2 # format = ZPixmap
475469 )
476470
477471 raw_data = ctypes .cast (
478472 ximage .contents .data ,
479- POINTER (c_ubyte * geometry [ 3 ] * geometry [ 2 ] * 4 )
473+ POINTER (c_ubyte * geometry . height * geometry . width * 4 )
480474 )
481475
482476 data = bytearray (raw_data .contents )
483477
484- data = Image (data , geometry [ 2 ] , geometry [ 3 ] )
478+ data = Image (data , geometry . width , geometry . height )
485479
486480 # don't forget to free the memory or you will be fucked
487481 self .xlib .XDestroyImage (ximage )
@@ -524,7 +518,7 @@ def send_str(self, str: str) -> None:
524518 for chr in str :
525519 self .send_chr (chr )
526520
527- def warp_pointer (self , x : int , y : int , geometry : tuple = None ) -> None :
521+ def warp_pointer (self , x : int , y : int , geometry : Box = None ) -> None :
528522 if geometry is None :
529523 geometry = self .geometry
530524
@@ -533,18 +527,18 @@ def warp_pointer(self, x: int, y: int, geometry: tuple = None) -> None:
533527 self .xlib .display ,
534528 self .xid , # src_w
535529 self .xid , # dest_w
536- geometry [ 0 ] ,
537- geometry [ 1 ] ,
538- geometry [ 2 ] ,
539- geometry [ 3 ] ,
530+ geometry . x ,
531+ geometry . y ,
532+ geometry . width ,
533+ geometry . height ,
540534 x ,
541535 y
542536 )
543537
544538 # flush display or events will run delayed cus thai'r only called on the next update
545539 self .xlib .XFlush (self .xlib .display )
546540
547- def send_mouse_click (self , x : int , y : int , button : ButtonCodes = ButtonCodes . Button1 ) -> None :
541+ def send_mouse_click (self , x : int , y : int , button : MouseButtons = MouseButtons . LEFT ) -> None :
548542 """
549543 Send a mouse click to the window at the given coordinates without moving the pointer.
550544 Some applications may not respond to the click so it is recommended to also move the pointer with `warp_pointer`.
0 commit comments