Skip to content

Commit 90cc735

Browse files
authored
Merge pull request #44 from MestreLion/master
workaround bug in EWMH.getWmPid(). Fix #43
2 parents 4f45962 + 2141008 commit 90cc735

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/pywinctl/_pywinctl_linux.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,17 @@ def getAppName(self) -> str:
826826
:return: name of the app as string
827827
"""
828828
# https://stackoverflow.com/questions/32295395/how-to-get-the-process-name-by-pid-in-linux-using-python
829-
pid = EWMH.getWmPid(self._hWnd)
829+
try:
830+
pid: int | None = EWMH.getWmPid(self._hWnd)
831+
# Workaround a bug in ewmh. Fixed upstream but never released
832+
# See https://github.com/parkouss/pyewmh/commit/acd58697
833+
except TypeError:
834+
return ""
835+
836+
# if the above fix is ever released, EWMH.getWmPid() might return None
837+
if pid is None:
838+
return ""
839+
830840
with subprocess.Popen(f"ps -q {pid} -o comm=", shell=True, stdout=subprocess.PIPE) as p:
831841
stdout, stderr = p.communicate()
832842
return stdout.decode(encoding="utf8").replace("\n", "")

0 commit comments

Comments
 (0)