Skip to content

Commit

Permalink
Merge pull request #78 from odknt/improve_linux_support
Browse files Browse the repository at this point in the history
LINUX: Fix getAllMonitors() returns empty list if XDG_CURRENT_DESKTOP is not set
  • Loading branch information
Kalmat committed Oct 4, 2023
2 parents bdf506b + d40663a commit 464f64c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/ewmhlib/_ewmhlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def getDisplays(forceUpdate: bool = False) -> List[Xlib.display.Display]:
global _displays
if forceUpdate:
_displays = []
if not _displays and os.environ['XDG_SESSION_TYPE'].lower() != "wayland":
if not _displays and os.environ.get('XDG_SESSION_TYPE', '').lower() != "wayland":
# Wayland adds a "fake" display (typically ":1") that freezes when trying to get a connection. Using default
# Thanks to SamuMazzi - https://github.com/SamuMazzi for pointing out this issue
files: List[str] = os.listdir("/tmp/.X11-unix")
Expand Down Expand Up @@ -1044,7 +1044,7 @@ def __init__(self, window: Union[int, XWindow]):
self.ewmhRoot: EwmhRoot = defaultEwmhRoot if self.root.id == defaultRoot.id else EwmhRoot(self.root)
self.extensions = _Extensions(self.id, self.display, self.root)

self._currDesktop = os.environ['XDG_CURRENT_DESKTOP'].lower()
self._currDesktop = os.environ.get('XDG_CURRENT_DESKTOP', '').lower()

def getProperty(self, prop: Union[str, int], prop_type: int = Xlib.X.AnyPropertyType) \
-> Optional[Xlib.protocol.request.GetProperty]:
Expand Down
8 changes: 4 additions & 4 deletions src/pywinctl/_pywinctl_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def getActiveWindow() -> Optional[LinuxWindow]:
# https://discourse.gnome.org/t/get-window-id-of-a-window-object-window-get-xwindow-doesnt-exist/10956/3
# https://www.reddit.com/r/gnome/comments/d8x27b/is_there_a_program_that_can_show_keypresses_on/
win_id: Union[str, int] = 0
if os.environ['XDG_SESSION_TYPE'].lower() == "wayland":
if os.environ.get('XDG_SESSION_TYPE', '').lower() == "wayland":
# swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).pid' -> Not working (socket issue)
# pynput / mouse --> Not working (no global events allowed, only application events)
_, activeWindow = _WgetAllWindows()
Expand Down Expand Up @@ -113,7 +113,7 @@ def getAllWindows():
:return: list of Window objects
"""
if os.environ['XDG_SESSION_TYPE'].lower() == "wayland":
if os.environ.get('XDG_SESSION_TYPE', '').lower() == "wayland":
windowsList, _ = _WgetAllWindows()
windows = [str(win["id"]) for win in windowsList if win and win.get("id", False)]
else:
Expand Down Expand Up @@ -328,8 +328,8 @@ def __init__(self, hWnd: Union[XWindow, int, str]):
self._xWin: XWindow = self._win.xWindow
self.watchdog = _WatchDog(self)

self._currDesktop = os.environ['XDG_CURRENT_DESKTOP'].lower()
self._currSessionType = os.environ['XDG_SESSION_TYPE'].lower()
self._currDesktop = os.environ.get('XDG_CURRENT_DESKTOP', '').lower()
self._currSessionType = os.environ.get('XDG_SESSION_TYPE', '').lower()
self._motifHints: List[int] = []

def getExtraFrameSize(self, includeBorder: bool = True) -> Tuple[int, int, int, int]:
Expand Down

0 comments on commit 464f64c

Please sign in to comment.