Skip to content

Commit

Permalink
show a more useful process title
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Nov 13, 2023
1 parent cbd29de commit e9a225f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
10 changes: 10 additions & 0 deletions fs/libexec/xpra/xpra_signal_listener
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import signal
from collections.abc import Callable


# use a more readable process name if specified:
if len(sys.argv) > 1:
argstr = " ".join(sys.argv)
name = "xpra_signal_listener"
pos = argstr.find(name)
if pos >= 0:
from xpra.os_util import set_proc_title
set_proc_title(argstr[pos+len(name):].strip())


def cb(signame: str):
sys.stdout.write("%s\n" % signame)
sys.stdout.flush()
Expand Down
39 changes: 24 additions & 15 deletions xpra/client/mixins/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from xpra.platform.paths import get_icon_filename, get_resources_dir, get_python_execfile_command
from xpra.scripts.config import FALSE_OPTIONS
from xpra.util.thread import start_thread
from xpra.util.str_fn import std
from xpra.os_util import (
bytestostr, memoryview_to_bytes,
OSX, POSIX, is_Ubuntu, first_time,
Expand Down Expand Up @@ -80,17 +81,23 @@
ICON_SHRINKAGE : int = envint("XPRA_ICON_SHRINKAGE", 75)
SAVE_WINDOW_ICONS : bool = envbool("XPRA_SAVE_WINDOW_ICONS", False)
SAVE_CURSORS : bool = envbool("XPRA_SAVE_CURSORS", False)
SIGNAL_WATCHER : bool = envbool("XPRA_SIGNAL_WATCHER", POSIX and not OSX)
SIGNAL_WATCHER_COMMAND : str = os.environ.get("XPRA_SIGNAL_WATCHER_COMMAND", "xpra_signal_listener")
if SIGNAL_WATCHER:
SIGNAL_WATCHER = False
for prefix in ("/usr", get_resources_dir()):
cmd = prefix+"/libexec/xpra/"+SIGNAL_WATCHER_COMMAND
if os.path.exists(cmd):
SIGNAL_WATCHER_COMMAND = cmd
SIGNAL_WATCHER = True
if not SIGNAL_WATCHER:
log.warn("Warning: %r not found", SIGNAL_WATCHER_COMMAND)


def find_signal_watcher_command() -> str:
if not envbool("XPRA_SIGNAL_WATCHER", POSIX and not OSX):
return ""
cmd = os.environ.get("XPRA_SIGNAL_WATCHER_COMMAND", "xpra_signal_listener")
if cmd and os.path.isabs(cmd):
return cmd
if cmd:
for prefix in ("/usr", get_resources_dir()):
pcmd = prefix+"/libexec/xpra/"+cmd
if os.path.exists(pcmd):
return pcmd
log.warn("Warning: %r not found", cmd)


SIGNAL_WATCHER_COMMAND = find_signal_watcher_command()

FAKE_SUSPEND_RESUME : int = envint("XPRA_FAKE_SUSPEND_RESUME", 0)
MOUSE_SCROLL_SQRT_SCALE : bool = envbool("XPRA_MOUSE_SCROLL_SQRT_SCALE", OSX)
Expand Down Expand Up @@ -865,7 +872,7 @@ def make_new_window(self, wid: int, wx: int, wy: int, ww: int, wh: int, bw: int,
# find a "transient-for" value using the pid to find a suitable window
# if possible, choosing the currently focused window (if there is one..)
pid = metadata.intget("pid", 0)
watcher_pid = self.assign_signal_watcher_pid(wid, pid)
watcher_pid = self.assign_signal_watcher_pid(wid, pid, metadata.strget("title", ""))
if override_redirect and pid>0 and metadata.intget("transient-for", 0)==0 and metadata.strget("role")=="popup":
tfor = None
twid = 0
Expand Down Expand Up @@ -930,13 +937,15 @@ def should_force_grab(self, metadata: typedict) -> bool:

######################################################################
# listen for process signals using a watcher process:
def assign_signal_watcher_pid(self, wid: int, pid: int) -> int:
if not SIGNAL_WATCHER or not pid:
def assign_signal_watcher_pid(self, wid: int, pid: int, title="") -> int:
if not SIGNAL_WATCHER_COMMAND or not pid:
return 0
proc = self._pid_to_signalwatcher.get(pid)
if proc is None or proc.poll():
from xpra.util.child_reaper import getChildReaper
cmd = get_python_execfile_command()+[SIGNAL_WATCHER_COMMAND]
if not title:
title = str(pid)
cmd = get_python_execfile_command()+[SIGNAL_WATCHER_COMMAND]+[f"signal watcher for {std(title)}"]
execlog(f"assign_signal_watcher_pid({wid}, {pid}) starting {cmd}")
try:
proc = Popen(cmd,
Expand Down

0 comments on commit e9a225f

Please sign in to comment.