Skip to content

Commit

Permalink
v0.7 pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalmat committed Mar 25, 2024
1 parent 7cc9f11 commit 3b22bf8
Show file tree
Hide file tree
Showing 10 changed files with 4,556 additions and 0 deletions.
1,350 changes: 1,350 additions & 0 deletions docstrings.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Requirements needed for development
# Run: `pip install -r requirements.txt`
# Build/Production requirements are found in setup.py
# Run: `pip install -e .`
#
# installs dependencies from setup.py, and the package itself,
# in editable mode
-e .[dev]
5 changes: 5 additions & 0 deletions src/pywinctl/ewmhlib/Props/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from ._props import (Root, DesktopLayout, Window, WindowType, State, StateAction,
MoveResize, DataFormat, Mode, StackMode, HintAction)
141 changes: 141 additions & 0 deletions src/pywinctl/ewmhlib/Props/_props.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from enum import IntEnum
import Xlib.X


class Root:
SUPPORTED = "_NET_SUPPORTED"
CLIENT_LIST = "_NET_CLIENT_LIST"
CLIENT_LIST_STACKING = "_NET_CLIENT_LIST_STACKING"
NUMBER_OF_DESKTOPS = "_NET_NUMBER_OF_DESKTOPS"
DESKTOP_GEOMETRY = "_NET_DESKTOP_GEOMETRY"
DESKTOP_VIEWPORT = "_NET_DESKTOP_VIEWPORT"
CURRENT_DESKTOP = "_NET_CURRENT_DESKTOP"
DESKTOP_NAMES = "_NET_DESKTOP_NAMES"
ACTIVE = "_NET_ACTIVE_WINDOW"
WORKAREA = "_NET_WORKAREA"
SUPPORTING_WM_CHECK = "_NET_SUPPORTING_WM_CHECK"
VIRTUAL_ROOTS = "_NET_VIRTUAL_ROOTS"
SHOWING_DESKTOP = "_NET_SHOWING_DESKTOP"
DESKTOP_LAYOUT = "_NET_DESKTOP_LAYOUT"
# Additional Root properties (always related to a specific window)
CLOSE = "_NET_CLOSE_WINDOW"
MOVERESIZE = "_NET_MOVERESIZE_WINDOW"
WM_MOVERESIZE = "_NET_WM_MOVERESIZE"
RESTACK = "_NET_RESTACK_WINDOW"
REQ_FRAME_EXTENTS = "_NET_REQUEST_FRAME_EXTENTS"
# WM_PROTOCOLS messages
PROTOCOLS = "WM_PROTOCOLS"
PING = "_NET_WM_PING"
SYNC = "_NET_WM_SYNC_REQUEST"


class DesktopLayout(IntEnum):
ORIENTATION_HORZ = 0
ORIENTATION_VERT = 1
TOPLEFT = 0
TOPRIGHT = 1
BOTTOMRIGHT = 2
BOTTOMLEFT = 3


class Window:
NAME = "_NET_WM_NAME"
LEGACY_NAME = "WM_NAME"
VISIBLE_NAME = "_NET_WM_VISIBLE_NAME"
ICON_NAME = "_NET_WM_ICON_NAME"
VISIBLE_ICON_NAME = "_NET_WM_VISIBLE_ICON_NAME"
DESKTOP = "_NET_WM_DESKTOP"
WM_WINDOW_TYPE = "_NET_WM_WINDOW_TYPE"
CHANGE_STATE = "WM_CHANGE_STATE"
WM_STATE = "_NET_WM_STATE"
ALLOWED_ACTIONS = "_NET_WM_ALLOWED_ACTIONS"
STRUT = "_NET_WM_STRUT"
STRUT_PARTIAL = "_NET_WM_STRUT_PARTIAL"
ICON_GEOMETRY = "_NET_WM_ICON_GEOMETRY"
ICON = "_NET_WM_ICON"
PID = "_NET_WM_PID"
HANDLED_ICONS = "_NET_WM_HANDLED_ICONS"
USER_TIME = "_NET_WM_USER_TIME"
FRAME_EXTENTS = "_NET_FRAME_EXTENTS"
# These are Root properties, but always related to a specific window
ACTIVE = "_NET_ACTIVE_WINDOW"
CLOSE = "_NET_CLOSE_WINDOW"
MOVERESIZE = "_NET_MOVERESIZE_WINDOW"
WM_MOVERESIZE = "_NET_WM_MOVERESIZE"
RESTACK = "_NET_RESTACK_WINDOW"
REQ_FRAME_EXTENTS = "_NET_REQUEST_FRAME_EXTENTS"
OPAQUE_REGION = "_NET_WM_OPAQUE_REGION"
BYPASS_COMPOSITOR = "_NET_WM_BYPASS_COMPOSITOR"


class WindowType:
DESKTOP = "_NET_WM_WINDOW_TYPE_DESKTOP"
DOCK = "_NET_WM_WINDOW_TYPE_DOCK"
TOOLBAR = "_NET_WM_WINDOW_TYPE_TOOLBAR"
MENU = "_NET_WM_WINDOW_TYPE_MENU"
UTILITY = "_NET_WM_WINDOW_TYPE_UTILITY"
SPLASH = "_NET_WM_WINDOW_TYPE_SPLASH"
DIALOG = "_NET_WM_WINDOW_TYPE_DIALOG"
NORMAL = "_NET_WM_WINDOW_TYPE_NORMAL"


class State:
NULL = "0"
MODAL = "_NET_WM_STATE_MODAL"
STICKY = "_NET_WM_STATE_STICKY"
MAXIMIZED_VERT = "_NET_WM_STATE_MAXIMIZED_VERT"
MAXIMIZED_HORZ = "_NET_WM_STATE_MAXIMIZED_HORZ"
SHADED = "_NET_WM_STATE_SHADED"
SKIP_TASKBAR = "_NET_WM_STATE_SKIP_TASKBAR"
SKIP_PAGER = "_NET_WM_STATE_SKIP_PAGER"
HIDDEN = "_NET_WM_STATE_HIDDEN"
FULLSCREEN = "_NET_WM_STATE_FULLSCREEN"
ABOVE = "_NET_WM_STATE_ABOVE"
BELOW = "_NET_WM_STATE_BELOW"
DEMANDS_ATTENTION = "_NET_WM_STATE_DEMANDS_ATTENTION"
FOCUSED = "_NET_WM_STATE_FOCUSED"


class StateAction(IntEnum):
REMOVE = 0
ADD = 1
TOGGLE = 2


class MoveResize(IntEnum):
SIZE_TOPLEFT = 0
SIZE_TOP = 1
SIZE_TOPRIGHT = 2
SIZE_RIGHT = 3
SIZE_BOTTOMRIGHT = 4
SIZE_BOTTOM = 5
SIZE_BOTTOMLEFT = 6
SIZE_LEFT = 7
MOVE = 8 # movement only
SIZE_KEYBOARD = 9 # size via keyboard
MOVE_KEYBOARD = 10 # move via keyboard


class DataFormat(IntEnum):
# I guess 16 is not used in Python (no difference between short and long int)
STR = 8
INT = 32


class Mode(IntEnum):
REPLACE = Xlib.X.PropModeReplace
APPEND = Xlib.X.PropModeAppend
PREPEND = Xlib.X.PropModePrepend


class StackMode(IntEnum):
ABOVE = Xlib.X.Above
BELOW = Xlib.X.Below


class HintAction(IntEnum):
KEEP = -1
REMOVE = -2
4 changes: 4 additions & 0 deletions src/pywinctl/ewmhlib/Structs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from ._structs import (ScreensInfo, DisplaysInfo, WmHints, Aspect, WmNormalHints)
123 changes: 123 additions & 0 deletions src/pywinctl/ewmhlib/Structs/_structs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-#from typing import List

from typing_extensions import TypedDict
from typing import List

from ctypes import Structure, c_int32, c_ulong, c_uint32
import Xlib.xobject
from Xlib.protocol.rq import Struct
from Xlib.xobject.drawable import Window as XWindow


class ScreensInfo(TypedDict):
"""
Container class to handle ScreensInfo struct:
- screen_number (str): int (sequential)
- is_default (bool): ''True'' if the screen is the default screen
- screen (Xlib.Struct): screen Struct (see Xlib documentation)
- root (Xlib.xobject.drawable.Window): root X-Window object belonging to screen
"""
screen_number: str
is_default: bool
screen: Struct
root: XWindow


class DisplaysInfo(TypedDict):
"""
Container class to handle DisplaysInfo struct:
- name: Display name (as per Xlib.display.Display(name))
- is_default: ''True'' if the display is the default display
- screens: list of ScreensInfo structs belonging to display
"""
display: Xlib.display.Display
name: str
is_default: bool
screens: List[ScreensInfo]


"""
Perhaps unnecesary since structs below are defined in Xlib.xobject.icccm.*, though in a more complex way.
"""
class WmHints(TypedDict):
"""
Container class to handle WmHints struct:
Example:
{
'flags': 103,
'input': 1,
'initial_state': 1,
'icon_pixmap': <Pixmap 0x02a22304>,
'icon_window': <Window 0x00000000>,
'icon_x': 0,
'icon_y': 0,
'icon_mask': <Pixmap 0x02a2230b>,
'window_group': <Window 0x02a00001>
}
"""
flags: int
input_mode: int
initial_state: int
icon_pixmap: Xlib.xobject.drawable.Pixmap
icon_window: Xlib.xobject.drawable.Window
icon_x: int
icon_y: int
icon_mask: Xlib.xobject.drawable.Pixmap
window_group: Xlib.xobject.drawable.Window


class Aspect(TypedDict):
"""Container class to handle Aspect struct (num, denum)"""
num: int
denum: int


class WmNormalHints(TypedDict):
"""
Container class to handle WmNormalHints
Example:
{
'flags': 848,
'min_width': 387,
'min_height': 145,
'max_width': 0,
'max_height': 0,
'width_inc': 9,
'height_inc': 18,
'min_aspect': <class 'Xlib.protocol.rq.DictWrapper'>({'num': 0, 'denum': 0}),
'max_aspect': <class 'Xlib.protocol.rq.DictWrapper'>({'num': 0, 'denum': 0}),
'base_width': 66,
'base_height': 101,
'win_gravity': 1
}
"""
flags: int
min_width: int
min_height: int
max_width: int
max_height: int
width_inc: int
height_inc: int
min_aspect: Aspect
max_aspect: Aspect
base_width: int
base_height: int
win_gravity: int


class _XWindowAttributes(Structure):
_fields_ = [('x', c_int32), ('y', c_int32),
('width', c_int32), ('height', c_int32), ('border_width', c_int32),
('depth', c_int32), ('visual', c_ulong), ('root', c_ulong),
('class', c_int32), ('bit_gravity', c_int32),
('win_gravity', c_int32), ('backing_store', c_int32),
('backing_planes', c_ulong), ('backing_pixel', c_ulong),
('save_under', c_int32), ('colourmap', c_ulong),
('mapinstalled', c_uint32), ('map_state', c_uint32),
('all_event_masks', c_ulong), ('your_event_mask', c_ulong),
('do_not_propagate_mask', c_ulong), ('override_redirect', c_int32), ('screen', c_ulong)]
30 changes: 30 additions & 0 deletions src/pywinctl/ewmhlib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


__all__ = [
"version", "displaysCount", "getDisplays", "getDisplaysInfo", "getRoots",
"defaultDisplay", "defaultScreen", "defaultRoot", "defaultEwmhRoot",
"getDisplayFromRoot", "getScreenFromRoot",
"getDisplayFromWindow", "getScreenFromWindow", "getRootFromWindow",
"getProperty", "getPropertyValue", "changeProperty", "sendMessage",
"EwmhRoot", "EwmhWindow",
"Props", "Structs"
]

__version__ = "0.0.1"


def version(numberOnly: bool = True):
"""Returns the current version of ewmhlib module, in the form ''x.x.xx'' as string"""
return ("" if numberOnly else "EWMHlib-")+__version__


from ._main import (displaysCount, getDisplays, getDisplaysInfo, getRoots,
defaultDisplay, defaultScreen, defaultRoot, defaultEwmhRoot,
getDisplayFromRoot, getScreenFromRoot,
getDisplayFromWindow, getScreenFromWindow, getRootFromWindow,
getProperty, getPropertyValue, changeProperty, sendMessage,
EwmhRoot, EwmhWindow,
Props, Structs
)
Loading

0 comments on commit 3b22bf8

Please sign in to comment.