From c0708b9358234861858ab8a74db71ec2075728dc Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 7 May 2026 22:08:55 +0900 Subject: [PATCH] feat: foreground window (WIP) --- dzgui/const/constants.py | 2 +- dzgui/init/proc.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dzgui/const/constants.py b/dzgui/const/constants.py index 5cbda52..2035553 100644 --- a/dzgui/const/constants.py +++ b/dzgui/const/constants.py @@ -65,4 +65,4 @@ CHANGELOG_PATH = "data/CHANGELOG.md" CSS_PATH = "data/app.css" LOG_FILTERS = ("CRITICAL", "WARNING", "INFO", "DEBUG") -FOREGROUND_CMDS = ("wmctrlu", "xdotool") +FOREGROUND_CMDS = ("wmctrl", "xdotool") diff --git a/dzgui/init/proc.py b/dzgui/init/proc.py index e23c80d..8d094c3 100644 --- a/dzgui/init/proc.py +++ b/dzgui/init/proc.py @@ -43,8 +43,14 @@ def has_cmd(cmd: str) -> bool: def foreground(cmd: str, pid: int) -> None: if cmd == "wmctrl": - # TODO: convert wid from hexadecimal - args = [cmd, "-a", "DZGUI"] + proc = subprocess.run(["wmctrl", "-ilp"], capture_output=True, text=True) + lines = proc.stdout.splitlines() + for line in lines: + els = line.split(" ") + if str(pid) in els: + wid = els[0] + break + subprocess.run(["wmctrl", "-ia", wid]) elif cmd == "xdotool": args = [cmd, "search", "--onlyvisible", "--name", "DZGUI", "windowactivate"] - subprocess.Popen([*args]) + subprocess.Popen([*args])