5
5
from .base import DSIBase
6
6
from .window import WindowBase
7
7
from .image import Image
8
+ from .buttons import MouseButtons
9
+ from .box import Box
8
10
9
11
# built-in modules
10
12
import logging
@@ -290,19 +292,6 @@ class KeyMasks(object):
290
292
Mod5Mask = 128
291
293
292
294
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
-
306
295
class Xlib (object ):
307
296
def __init__ (self ):
308
297
# load libX11.so.6
@@ -454,34 +443,39 @@ def active(self) -> bool:
454
443
return self .xid == get_active_window_xid (self .xlib )
455
444
456
445
@property
457
- def geometry (self ) -> tuple :
446
+ def geometry (self ) -> Box :
458
447
gwa = XWindowAttributes ()
459
448
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
+ )
461
455
462
- def get_image (self , geometry : tuple = None ) -> Image :
456
+ def get_image (self , geometry : Box = None ) -> Image :
463
457
if geometry is None :
464
458
geometry = self .geometry
465
459
466
460
ximage = self .xlib .XGetImage (
467
461
self .xlib .display , # Display
468
462
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
473
467
0x00FFFFFF , # plane_mask
474
468
2 # format = ZPixmap
475
469
)
476
470
477
471
raw_data = ctypes .cast (
478
472
ximage .contents .data ,
479
- POINTER (c_ubyte * geometry [ 3 ] * geometry [ 2 ] * 4 )
473
+ POINTER (c_ubyte * geometry . height * geometry . width * 4 )
480
474
)
481
475
482
476
data = bytearray (raw_data .contents )
483
477
484
- data = Image (data , geometry [ 2 ] , geometry [ 3 ] )
478
+ data = Image (data , geometry . width , geometry . height )
485
479
486
480
# don't forget to free the memory or you will be fucked
487
481
self .xlib .XDestroyImage (ximage )
@@ -524,7 +518,7 @@ def send_str(self, str: str) -> None:
524
518
for chr in str :
525
519
self .send_chr (chr )
526
520
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 :
528
522
if geometry is None :
529
523
geometry = self .geometry
530
524
@@ -533,18 +527,18 @@ def warp_pointer(self, x: int, y: int, geometry: tuple = None) -> None:
533
527
self .xlib .display ,
534
528
self .xid , # src_w
535
529
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 ,
540
534
x ,
541
535
y
542
536
)
543
537
544
538
# flush display or events will run delayed cus thai'r only called on the next update
545
539
self .xlib .XFlush (self .xlib .display )
546
540
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 :
548
542
"""
549
543
Send a mouse click to the window at the given coordinates without moving the pointer.
550
544
Some applications may not respond to the click so it is recommended to also move the pointer with `warp_pointer`.
0 commit comments