11#!/usr/bin/python3
22# -*- coding: utf-8 -*-
33
4+ """
5+ All X11 specific DSI functions
6+ """
7+
48# built-in modules
59from typing import Optional
610import logging
3236
3337# Setup Xlib Structures
3438
39+ # pylint: disable=too-few-public-methods
40+
3541
3642class Display (Structure ):
3743 """
@@ -168,6 +174,7 @@ class XErrorEvent(Structure):
168174 """
169175
170176 def __repr__ (self ) -> str :
177+ # pylint: disable-next=line-too-long
171178 return f"XErrorEvent(type={ self .type } , serial={ self .serial } , error_code={ self .error_code } , request_code={ self .request_code } , minor_code={ self .minor_code } )"
172179
173180 _fields_ = [
@@ -187,6 +194,9 @@ def __repr__(self) -> str:
187194
188195@ctypes .CFUNCTYPE (c_int , POINTER (Display ), POINTER (XErrorEvent ))
189196def error_handler (_ , event ):
197+ """
198+ A C function that handles X11 errors.
199+ """
190200 logger .error ("%s" , event .contents )
191201 return 0
192202
@@ -294,6 +304,10 @@ class KeyMasks:
294304
295305
296306class Xlib :
307+ """
308+ A class that provides access to Xlib functions.
309+ """
310+
297311 def __init__ (self ):
298312 # load libX11.so.6
299313 x11 = ctypes .util .find_library ("X11" )
@@ -374,7 +388,7 @@ def __getattribute__(self, __name: str):
374388 return self .xlib .__getattribute__ (__name )
375389
376390
377- def get_window_property (xlib : Xlib , window_xid : int , property : str , type : _SimpleCData ):
391+ def get_window_property (xlib : Xlib , window_xid : int , property_name : str , return_type : _SimpleCData ):
378392 """
379393 https://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html
380394 """
@@ -388,7 +402,7 @@ def get_window_property(xlib: Xlib, window_xid: int, property: str, type: _Simpl
388402 xlib .display ,
389403 window_xid ,
390404 xlib .XInternAtom (
391- xlib .display , c_char_p (property .encode ('utf-8' )),
405+ xlib .display , c_char_p (property_name .encode ('utf-8' )),
392406 False
393407 ),
394408 0 ,
@@ -405,7 +419,7 @@ def get_window_property(xlib: Xlib, window_xid: int, property: str, type: _Simpl
405419 if prop_return :
406420 data = cast (
407421 prop_return ,
408- POINTER (type )
422+ POINTER (return_type )
409423 ).contents .value
410424 else :
411425 data = None
@@ -417,6 +431,10 @@ def get_window_property(xlib: Xlib, window_xid: int, property: str, type: _Simpl
417431
418432
419433class Window (WindowBase ):
434+ """
435+ An class for interacting with a window on X11.
436+ """
437+
420438 def __init__ (self , xid : int , xlib : Xlib ) -> None :
421439 self .xid = xid
422440 self .xlib = xlib
@@ -481,7 +499,7 @@ def get_image(self, geometry: Optional[Box] = None) -> Image:
481499
482500 return data
483501
484- def send_chr (self , chr : chr ) -> None :
502+ def send_chr (self , character : chr ) -> None :
485503 """Send a character to the window
486504
487505 Args:
@@ -492,10 +510,10 @@ def send_chr(self, chr: chr) -> None:
492510 key = XEvent (type = EventTypes .KeyPress ).xkey # KeyPress
493511 key .keycode = self .xlib .XKeysymToKeycode (
494512 self .xlib .display ,
495- self .xlib .XStringToKeysym (c_char_p (chr .encode ('utf-8' )))
513+ self .xlib .XStringToKeysym (c_char_p (character .encode ('utf-8' )))
496514 ) # https://github.com/python-xlib/python-xlib/blob/master/Xlib/keysymdef/latin1.py
497515 key .window = key .root = self .xid
498- key .state = KeyMasks .ShiftMask if chr .isupper () else 0
516+ key .state = KeyMasks .ShiftMask if character .isupper () else 0
499517
500518 self .xlib .XSendEvent (
501519 self .xlib .display , # Display *display
@@ -508,14 +526,14 @@ def send_chr(self, chr: chr) -> None:
508526 # flush display or events will run delayed cus thai'r only called on the next update
509527 self .xlib .XFlush (self .xlib .display )
510528
511- def send_str (self , str : str ) -> None :
529+ def send_str (self , string : str ) -> None :
512530 """Send a string to the window
513531
514532 Args:
515533 str (str): The string to send
516534 """
517- for chr in str :
518- self .send_chr (chr )
535+ for character in string :
536+ self .send_chr (character )
519537
520538 def warp_pointer (self , x : int , y : int , geometry : Optional [Box ] = None ) -> None :
521539 if geometry is None :
@@ -538,10 +556,12 @@ def warp_pointer(self, x: int, y: int, geometry: Optional[Box] = None) -> None:
538556 self .xlib .XFlush (self .xlib .display )
539557
540558 def send_mouse_click (self , x : int , y : int , button : MouseButtons = MouseButtons .LEFT ) -> None :
559+ # pylint: disable=line-too-long
541560 """
542561 Send a mouse click to the window at the given coordinates without moving the pointer.
543562 Some applications may not respond to the click so it is recommended to also move the pointer with `warp_pointer`.
544563 """
564+ # pylint: enable=line-too-long
545565 event = XEvent (type = EventTypes .ButtonPress ).xbutton
546566 event .window = event .root = self .xid
547567 event .button = button
@@ -622,20 +642,20 @@ def get_all_windows(xlib: Xlib) -> list:
622642 Get all window XIDs. By recursively getting all connected windows.
623643 """
624644 final = get_connected_xids (xlib , xlib .root_window )
625- next = final .copy ()
645+ next_window = final .copy ()
626646
627647 run = True
628648 while run :
629649 run = False
630650 next_temp = []
631- for xid in next :
651+ for xid in next_window :
632652 xids = get_connected_xids (xlib , xid )
633653 if len (xids ) > 0 :
634654 run = True
635655 next_temp += xids
636656
637- next = next_temp
638- final += next
657+ next_window = next_temp
658+ final += next_window
639659
640660 final_windows = []
641661
@@ -646,6 +666,10 @@ def get_all_windows(xlib: Xlib) -> list:
646666
647667
648668class DSI (DSIBase ):
669+ """
670+ Main DSI class
671+ """
672+
649673 def __init__ (self ):
650674 self .xlib = Xlib ()
651675
0 commit comments