a2qlinux 0.7.1__tar.gz → 0.7.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/CHANGELOG.md +35 -0
  2. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/PKG-INFO +2 -2
  3. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/README.md +1 -1
  4. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/_version.py +2 -2
  5. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/bin/questlog_ctl.exe +0 -0
  6. a2qlinux-0.7.3/a2qlinux/bin/version.dll +0 -0
  7. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/bin/wpcap.dll +0 -0
  8. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/diagnose.py +92 -5
  9. a2qlinux-0.7.3/a2qlinux/focus.py +218 -0
  10. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/launcher.py +81 -8
  11. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/pcap_bridge.py +35 -0
  12. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/setup_desktop.py +1 -1
  13. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/update.py +95 -17
  14. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/bridge/build.sh +9 -1
  15. a2qlinux-0.7.3/bridge/focus_hook.c +257 -0
  16. a2qlinux-0.7.3/bridge/focus_hook.def +18 -0
  17. a2qlinux-0.7.3/bridge/tests/focus_hook_test.c +82 -0
  18. a2qlinux-0.7.3/bridge/tests/run_focus_hook_test.py +66 -0
  19. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/docs/ARCHITECTURE.md +258 -17
  20. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/docs/RELEASE.md +6 -2
  21. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/docs/TROUBLESHOOTING.md +8 -0
  22. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/docs/UPDATING.md +8 -5
  23. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/docs/USING.md +15 -1
  24. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/pyproject.toml +1 -1
  25. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_diagnose.py +59 -0
  26. a2qlinux-0.7.3/tests/test_focus.py +57 -0
  27. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_launcher.py +53 -0
  28. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_pcap_bridge.py +26 -0
  29. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_update.py +87 -1
  30. a2qlinux-0.7.3/tools/foreground_probe.c +95 -0
  31. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/.gitignore +0 -0
  32. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/LICENSE +0 -0
  33. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/__init__.py +0 -0
  34. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/config.py +0 -0
  35. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/desktop.py +0 -0
  36. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/kde_overlays.py +0 -0
  37. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/open_folders.py +0 -0
  38. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/steam.py +0 -0
  39. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/a2qlinux/tray.py +0 -0
  40. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/bridge/questlog_ctl.c +0 -0
  41. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/bridge/tests/bridge_client_test.c +0 -0
  42. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/bridge/tests/zorder_guard_test.c +0 -0
  43. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/bridge/wpcap_bridge.c +0 -0
  44. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/docs/INSTALL.md +0 -0
  45. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/docs/README.md +0 -0
  46. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/__init__.py +0 -0
  47. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_config.py +0 -0
  48. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_desktop.py +0 -0
  49. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_kde_overlays.py +0 -0
  50. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_open_folders.py +0 -0
  51. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_replay_stream.py +0 -0
  52. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_setup_desktop.py +0 -0
  53. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_steam.py +0 -0
  54. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tests/test_version.py +0 -0
  55. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tools/__init__.py +0 -0
  56. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tools/pcap2questlog.py +0 -0
  57. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tools/replay_stream.py +0 -0
  58. {a2qlinux-0.7.1 → a2qlinux-0.7.3}/tools/tcp_owner_probe.c +0 -0
@@ -3,6 +3,41 @@
3
3
  What changed for players, release by release. Technical details are in
4
4
  `docs/ARCHITECTURE.md`.
5
5
 
6
+ ## [0.7.3] — 2026-11-14
7
+
8
+ ### Fixed
9
+ - Questlog's overlays (meter, timers, tracker, map) no longer stay drawn
10
+ over another program, such as a browser, after switching to it from the
11
+ game: they hide while it is in front and come back with the game. With
12
+ two monitors they also hide while a program on the other monitor is in
13
+ use.
14
+ - Questlog 0.1.54 is installed again. A2Qlinux had refused it ("its capture
15
+ worker calls no libpcap functions any more; a second start no longer
16
+ simply shows its window"), but nothing it relies on changed: Questlog
17
+ only packs its code differently. Players on 0.1.53 get 0.1.54 at the next
18
+ update check after updating A2Qlinux.
19
+ - New Questlog versions now also reach players who start Questlog with the
20
+ game and close it with the game (`after_game = "close"`). The download
21
+ used to wait until the game was closed, and by then A2Qlinux had closed
22
+ too, so the update was almost never fetched. It now runs during play,
23
+ slowed to about 1 MB per second, and installs at the next start as before.
24
+ During play, "Questlog X is ready" shows only in the status window, not
25
+ as a desktop notification.
26
+ - A Questlog version that an older A2Qlinux refused is checked again after
27
+ A2Qlinux is updated, instead of staying refused until the next Questlog
28
+ version.
29
+ - The GitHub issue that `a2qlinux --diagnose --report` opens shows the end
30
+ of A2Qlinux's own log again under "launcher.log"; since 0.7.2 it showed
31
+ part of the new process snapshot there instead. The report file itself
32
+ was complete.
33
+
34
+ ## [0.7.2] — 2026-11-13
35
+
36
+ ### Changed
37
+ - `a2qlinux --diagnose --report` also records what each part of Questlog
38
+ is doing at that moment. When a Questlog window turns black or is "not
39
+ responding", a report made while it is on screen shows what it waits for.
40
+
6
41
  ## [0.7.1] — 2026-11-13
7
42
 
8
43
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: a2qlinux
3
- Version: 0.7.1
3
+ Version: 0.7.3
4
4
  Summary: Questlog Desktop (AION 2 damage meter) on Linux under Proton, with live game traffic.
5
5
  Project-URL: homepage, https://github.com/raman78/A2Qlinux
6
6
  Project-URL: repository, https://github.com/raman78/A2Qlinux
@@ -66,7 +66,7 @@ game:
66
66
  - quitting Questlog without losing its last data and without touching the
67
67
  game or other programs in the prefix;
68
68
  - updating Questlog: its own updater cannot install under Proton, so A2Qlinux
69
- downloads new versions in the background (not while the game runs), checks
69
+ downloads new versions in the background (slowly while the game runs), checks
70
70
  them against what it relies on, installs them at the next start and rolls
71
71
  back if they do not start.
72
72
 
@@ -24,7 +24,7 @@ game:
24
24
  - quitting Questlog without losing its last data and without touching the
25
25
  game or other programs in the prefix;
26
26
  - updating Questlog: its own updater cannot install under Proton, so A2Qlinux
27
- downloads new versions in the background (not while the game runs), checks
27
+ downloads new versions in the background (slowly while the game runs), checks
28
28
  them against what it relies on, installs them at the next start and rolls
29
29
  back if they do not start.
30
30
 
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.7.1'
22
- __version_tuple__ = version_tuple = (0, 7, 1)
21
+ __version__ = version = '0.7.3'
22
+ __version_tuple__ = version_tuple = (0, 7, 3)
23
23
 
24
24
  __commit_id__ = commit_id = None
Binary file
@@ -19,9 +19,10 @@ not. Each check gives one line: fine, a note, or a problem with what to do.
19
19
  7. Whether the game's prefix has a command for Questlog's Open Folder
20
20
  buttons, read from its system.reg (no Wine is started).
21
21
 
22
- With --report it also writes a report file: the diagnosis and the end of
23
- launcher.log and of questlog.log and questlog.log.1 (Questlog's and Wine's
24
- output, this run and the one before), with the home folder, user name, Steam account numbers and
22
+ With --report it also writes a report file: the diagnosis, a snapshot of
23
+ what each of Questlog's processes and threads is doing (process_snapshot),
24
+ and the end of launcher.log and of questlog.log and questlog.log.1
25
+ (Questlog's and Wine's output, this run and the one before), with the home folder, user name, Steam account numbers and
25
26
  network addresses replaced (anonymise). It shows the report and, if the
26
27
  user agrees, opens a new GitHub issue in the browser with the report filled
27
28
  in; the user reviews it and submits it with their own account. Nothing is
@@ -632,12 +633,97 @@ def questlog_log_excerpt(path, head=QUESTLOG_LOG_HEAD, tail=QUESTLOG_LOG_TAIL):
632
633
  return lines[:head] + [f"(... {len(lines) - head - tail} lines left out ...)"] + lines[-tail:]
633
634
 
634
635
 
635
- def build_report(results, qdir, anonymise):
636
+ PROCESS_SAMPLE = 1.0 # s between the two readings of the threads' CPU time in the report's snapshot
637
+
638
+
639
+ def process_role(argv):
640
+ """What a process of Questlog is, from its command line: main, gpu-process, renderer, utility (…)."""
641
+ kind = next((a.split("=", 1)[1] for a in argv if a.startswith("--type=")), None)
642
+ if kind is None:
643
+ return "wineserver" if argv and argv[0].endswith("wineserver") else "main"
644
+ sub = next((a.split("=", 1)[1] for a in argv if a.startswith("--utility-sub-type=")), "")
645
+ return f"{kind} ({sub.split('.')[0]})" if sub else kind
646
+
647
+
648
+ def _thread_readings(pid, proc):
649
+ """{tid: (name, state, kernel wait, CPU ticks)} of one process's threads; {} once it has gone."""
650
+ readings = {}
651
+ try:
652
+ tids = os.listdir(f"{proc}/{pid}/task")
653
+ except OSError:
654
+ return readings
655
+ for tid in tids:
656
+ base = f"{proc}/{pid}/task/{tid}"
657
+ try:
658
+ stat = Path(base, "stat").read_text()
659
+ fields = stat[stat.rindex(")") + 2:].split()
660
+ name = Path(base, "comm").read_text().strip()
661
+ wchan = Path(base, "wchan").read_text().strip()
662
+ except (OSError, ValueError):
663
+ continue
664
+ readings[int(tid)] = (name, fields[0], wchan if wchan not in ("", "0") else "-",
665
+ int(fields[11]) + int(fields[12]))
666
+ return readings
667
+
668
+
669
+ def process_snapshot(pids, proc="/proc", wait=PROCESS_SAMPLE, sleep=time.sleep, ticks=None):
670
+ """The report's lines on what each of Questlog's processes and threads does right now.
671
+
672
+ Each thread: its name (Chromium names them: CrBrowserMain is the main
673
+ process's window thread), its state (R running, S/D waiting), where it
674
+ waits in the kernel, and the CPU time it used between two readings
675
+ `wait` s apart. A thread that answers no window shows either as busy
676
+ (CPU time near the whole interval) or as waiting with none. Idle threads
677
+ that look alike are counted on one line.
678
+ """
679
+ from .launcher import _read
680
+ ticks = ticks or os.sysconf("SC_CLK_TCK")
681
+ first = {pid: _thread_readings(pid, proc) for pid in pids}
682
+ sleep(wait)
683
+ lines = []
684
+ for pid in sorted(pids):
685
+ argv = [a for a in _read(f"{proc}/{pid}/cmdline", 4096).split("\0") if a]
686
+ second = _thread_readings(pid, proc)
687
+ if not second:
688
+ lines.append(f"PID {pid}: gone during the snapshot")
689
+ continue
690
+ used = {tid: max(0, second[tid][3] - first[pid].get(tid, second[tid])[3]) * 1000 // ticks
691
+ for tid in second}
692
+ lines.append(f"PID {pid} {process_role(argv)}: {len(second)} threads, "
693
+ f"{sum(used.values())} ms CPU in {wait:g} s")
694
+ grouped = {}
695
+ for tid in sorted(second):
696
+ name, state, wchan, _ = second[tid]
697
+ if tid == pid or used[tid] or state not in ("S", "I"):
698
+ lines.append(f" {tid:>8} {name:<16} {state} {wchan:<32} {used[tid]:>5} ms")
699
+ else:
700
+ grouped[(name, state, wchan)] = grouped.get((name, state, wchan), 0) + 1
701
+ for (name, state, wchan), count in sorted(grouped.items()):
702
+ lines.append(f" {'x' + str(count):>8} {name:<16} {state} {wchan:<32} {0:>5} ms")
703
+ return lines
704
+
705
+
706
+ def questlog_snapshot(appid=3393110):
707
+ """process_snapshot of Questlog's processes and the Wine session's wineserver; lines."""
708
+ from . import launcher
709
+ found = launcher.game_processes(appid, ["questlog.exe", "wineserver"])
710
+ servers = {pid for pid in found["wineserver"]
711
+ if "-w" not in launcher._read(f"/proc/{pid}/cmdline", 4096).split("\0")[1:]}
712
+ pids = found["questlog.exe"] | servers
713
+ if not found["questlog.exe"]:
714
+ return ["(Questlog is not running)"]
715
+ return process_snapshot(pids)
716
+
717
+
718
+ def build_report(results, qdir, anonymise, snapshot=questlog_snapshot):
636
719
  logs = qdir / "proton-stream"
637
720
  launcher_lines = log_tail(logs / "launcher.log", REPORT_LOG_LINES)
638
721
  parts = [f"A2Qlinux report, {time.strftime('%Y-%m-%d %H:%M %Z')}", "", "## Diagnosis", "",
639
722
  format_results(results), "", f"## launcher.log (last {REPORT_LOG_LINES} lines)", ""]
640
723
  parts += launcher_lines or ["(no launcher.log yet)"]
724
+ parts += ["", f"## Questlog's processes now (threads: state, kernel wait, CPU time in {PROCESS_SAMPLE:g} s)",
725
+ ""]
726
+ parts += snapshot()
641
727
  parts += ["", "## steam_launch.log (last 10 lines)", ""]
642
728
  parts += log_tail(logs / "steam_launch.log", 10) or ["(none)"]
643
729
  parts += ["", "## questlog.log (Questlog's and Wine's output since A2Qlinux last started it)", ""]
@@ -651,7 +737,8 @@ def issue_url(results, report, report_path, anonymise, limit=ISSUE_URL_LIMIT):
651
737
  """A new-issue URL with the diagnosis and as much of the log's end as fits within `limit`."""
652
738
  title = f"Problem report (A2Qlinux {shown_version()})"
653
739
  diagnosis = anonymise(format_results(results)).splitlines()
654
- log_lines = report.split("## launcher.log", 1)[-1].split("## steam_launch.log", 1)[0].strip().splitlines()[1:]
740
+ # launcher.log's section only: up to the next heading, whichever section follows it.
741
+ log_lines = report.split("## launcher.log", 1)[-1].split("\n## ", 1)[0].strip().splitlines()[1:]
655
742
  log_lines = [line for line in log_lines if line.strip()]
656
743
 
657
744
  def head(lines):
@@ -0,0 +1,218 @@
1
+ """Whether the desktop's active window is one of Wine's, for Questlog's overlays (docs/ARCHITECTURE.md §6.12).
2
+
3
+ Questlog's overlays are unmanaged X windows under Wine, which the
4
+ compositor draws above every Linux program, and Wine does not notice when
5
+ a Linux program becomes active: so they stay above a browser or terminal
6
+ after Alt+Tab. X11 itself does know: the window manager - KWin, Mutter or any other, also
7
+ for Xwayland - moves _NET_ACTIVE_WINDOW on the root window (EWMH) to a
8
+ window of its own when a Wayland or other non-Wine window becomes active.
9
+
10
+ ActiveWindowWatch follows that property with Xlib (through ctypes: libX11
11
+ is there wherever Wine's X11 driver runs) and reports "in" while a Wine
12
+ window is active and "out" otherwise. It runs in a child process of the
13
+ launcher (`python -m a2qlinux.focus`, FocusFollower), because Xlib ends the
14
+ whole process when its display connection is lost - as when Xwayland goes
15
+ down with the desktop session - and the launcher must outlive that. The
16
+ launcher passes the state to
17
+ version.dll in Questlog's main process over the capture bridge
18
+ (BridgeServer.set_focus), which while it is "out" tells Questlog that the
19
+ game's window is minimized, the case in which Questlog hides its overlays
20
+ by its own logic. Nothing is changed on the X side:
21
+ the watch only reads.
22
+ """
23
+
24
+ import ctypes
25
+ import ctypes.util
26
+ import os
27
+ import subprocess
28
+ import sys
29
+ import threading
30
+
31
+ IN, OUT = "in", "out"
32
+ PROPERTY_CHANGE_MASK = 1 << 22
33
+ PROPERTY_NOTIFY = 28
34
+ XA_WINDOW = 33
35
+
36
+
37
+ def is_wine_class(wm_class):
38
+ """Whether a WM_CLASS (res_name, res_class) is a Wine window's.
39
+
40
+ Proton names the game's windows steam_app_<appid> and those of other
41
+ programs in the prefix (Questlog, its overlays) steam_proton; plain Wine
42
+ names them after the program, e.g. questlog.exe.
43
+ """
44
+ for part in wm_class:
45
+ part = (part or "").lower()
46
+ if part.startswith("steam_app_") or part == "steam_proton" or part.endswith(".exe"):
47
+ return True
48
+ return False
49
+
50
+
51
+ class _XPropertyEvent(ctypes.Structure):
52
+ _fields_ = [("type", ctypes.c_int), ("serial", ctypes.c_ulong), ("send_event", ctypes.c_int),
53
+ ("display", ctypes.c_void_p), ("window", ctypes.c_ulong), ("atom", ctypes.c_ulong),
54
+ ("time", ctypes.c_ulong), ("state", ctypes.c_int)]
55
+
56
+
57
+ class _XEvent(ctypes.Union):
58
+ _fields_ = [("type", ctypes.c_int), ("xproperty", _XPropertyEvent), ("pad", ctypes.c_long * 24)]
59
+
60
+
61
+ class _XClassHint(ctypes.Structure):
62
+ _fields_ = [("res_name", ctypes.c_void_p), ("res_class", ctypes.c_void_p)] # freed with XFree
63
+
64
+
65
+ _ERROR_HANDLER = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p)
66
+
67
+
68
+ class ActiveWindowWatch:
69
+ """Call on_change(IN | OUT) now and on every change of the desktop's active window's kind.
70
+
71
+ start() returns None when it runs, else the reason it cannot (no DISPLAY,
72
+ no libX11, no display connection); the caller logs that once, and
73
+ Questlog's overlays then stay over other programs as before.
74
+ """
75
+
76
+ def __init__(self, on_change, display=None):
77
+ self.on_change = on_change
78
+ self.display_name = display if display is not None else os.environ.get("DISPLAY", "")
79
+ self.state = None
80
+
81
+ def start(self):
82
+ if not self.display_name:
83
+ return "no X display (DISPLAY is not set)"
84
+ path = ctypes.util.find_library("X11")
85
+ if not path:
86
+ return "libX11 was not found"
87
+ x = ctypes.CDLL(path)
88
+ x.XOpenDisplay.restype = ctypes.c_void_p
89
+ x.XOpenDisplay.argtypes = [ctypes.c_char_p]
90
+ display = x.XOpenDisplay(self.display_name.encode())
91
+ if not display:
92
+ return f"the X display {self.display_name} could not be opened"
93
+ self._x, self._display = x, ctypes.c_void_p(display)
94
+ for name, args, result in (
95
+ ("XDefaultRootWindow", [ctypes.c_void_p], ctypes.c_ulong),
96
+ ("XInternAtom", [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_int], ctypes.c_ulong),
97
+ ("XSelectInput", [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_long], ctypes.c_int),
98
+ ("XNextEvent", [ctypes.c_void_p, ctypes.c_void_p], ctypes.c_int),
99
+ ("XGetWindowProperty", [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_long,
100
+ ctypes.c_long, ctypes.c_int, ctypes.c_ulong,
101
+ ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.c_int),
102
+ ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.c_ulong),
103
+ ctypes.POINTER(ctypes.c_void_p)], ctypes.c_int),
104
+ ("XGetClassHint", [ctypes.c_void_p, ctypes.c_ulong, ctypes.POINTER(_XClassHint)], ctypes.c_int),
105
+ ("XFree", [ctypes.c_void_p], ctypes.c_int),
106
+ ("XSetErrorHandler", [_ERROR_HANDLER], ctypes.c_void_p)):
107
+ getattr(x, name).argtypes, getattr(x, name).restype = args, result
108
+ # A window can go away between reading the property and asking its class;
109
+ # Xlib's default handler would end the launcher for that.
110
+ self._ignore_errors = _ERROR_HANDLER(lambda display, event: 0)
111
+ x.XSetErrorHandler(self._ignore_errors)
112
+ self._root = x.XDefaultRootWindow(self._display)
113
+ self._atom = x.XInternAtom(self._display, b"_NET_ACTIVE_WINDOW", 0)
114
+ x.XSelectInput(self._display, self._root, PROPERTY_CHANGE_MASK)
115
+ self._update()
116
+ threading.Thread(target=self._loop, daemon=True, name="active-window").start()
117
+ return None
118
+
119
+ def _active_window(self):
120
+ kind, fmt = ctypes.c_ulong(), ctypes.c_int()
121
+ count, after, data = ctypes.c_ulong(), ctypes.c_ulong(), ctypes.c_void_p()
122
+ if self._x.XGetWindowProperty(self._display, self._root, self._atom, 0, 1, 0, XA_WINDOW,
123
+ ctypes.byref(kind), ctypes.byref(fmt), ctypes.byref(count),
124
+ ctypes.byref(after), ctypes.byref(data)) != 0 or not data.value:
125
+ return 0
126
+ try:
127
+ return ctypes.cast(data, ctypes.POINTER(ctypes.c_ulong))[0] if count.value else 0
128
+ finally:
129
+ self._x.XFree(data)
130
+
131
+ def _wm_class(self, window):
132
+ hint = _XClassHint()
133
+ if not window or not self._x.XGetClassHint(self._display, window, ctypes.byref(hint)):
134
+ return ("", "")
135
+ names = tuple(ctypes.string_at(value).decode("utf-8", "replace") if value else ""
136
+ for value in (hint.res_name, hint.res_class))
137
+ for value in (hint.res_name, hint.res_class):
138
+ if value:
139
+ self._x.XFree(ctypes.c_void_p(value))
140
+ return names
141
+
142
+ def _update(self):
143
+ state = IN if is_wine_class(self._wm_class(self._active_window())) else OUT
144
+ if state != self.state:
145
+ self.state = state
146
+ self.on_change(state)
147
+
148
+ def _loop(self):
149
+ event = _XEvent()
150
+ while True:
151
+ self._x.XNextEvent(self._display, ctypes.byref(event))
152
+ if event.type == PROPERTY_NOTIFY and event.xproperty.atom == self._atom:
153
+ self._update()
154
+
155
+
156
+ def main():
157
+ """Child process: print "in"/"out" on every change; a reason on stderr and exit code 2 if it cannot run."""
158
+ watch = ActiveWindowWatch(lambda state: print(state, flush=True))
159
+ why_not = watch.start()
160
+ if why_not:
161
+ print(why_not, file=sys.stderr, flush=True)
162
+ return 2
163
+ threading.Event().wait()
164
+ return 0
165
+
166
+
167
+ class FocusFollower:
168
+ """Runs `python -m a2qlinux.focus` and passes each line to on_change; the launcher's side.
169
+
170
+ When the child cannot start watching, or ends (the X display went away),
171
+ the reason is logged, on_change gets "in" - Questlog's overlays then
172
+ stay over other programs as before - and the child is started
173
+ again after RESTART_WAIT seconds, in case the display comes back.
174
+ """
175
+
176
+ RESTART_WAIT = 30
177
+
178
+ def __init__(self, on_change, log, command=None):
179
+ self.on_change, self.log = on_change, log
180
+ self.command = command or [sys.executable, "-m", "a2qlinux.focus"]
181
+ self.stopped = threading.Event()
182
+ self.process = None
183
+
184
+ def start(self):
185
+ threading.Thread(target=self._run, daemon=True, name="focus-follower").start()
186
+
187
+ def _run(self):
188
+ told = None
189
+ while not self.stopped.is_set():
190
+ try:
191
+ self.process = subprocess.Popen(self.command, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
192
+ stderr=subprocess.PIPE, text=True)
193
+ except OSError as error:
194
+ reason = str(error)
195
+ else:
196
+ for line in self.process.stdout:
197
+ if line.strip() in (IN, OUT):
198
+ self.on_change(line.strip())
199
+ code = self.process.wait()
200
+ reason = self.process.stderr.read().strip().splitlines()
201
+ reason = reason[-1] if reason else f"it ended with code {code}"
202
+ self.on_change(IN)
203
+ if self.stopped.is_set():
204
+ return
205
+ if reason != told: # once per distinct reason, not on every restart
206
+ self.log(f"Cannot follow the desktop's active window ({reason}); Questlog's overlays stay over "
207
+ f"other programs when the game is not in front. Trying again every {self.RESTART_WAIT} s.")
208
+ told = reason
209
+ self.stopped.wait(self.RESTART_WAIT)
210
+
211
+ def stop(self):
212
+ self.stopped.set()
213
+ if self.process and self.process.poll() is None:
214
+ self.process.terminate()
215
+
216
+
217
+ if __name__ == "__main__":
218
+ sys.exit(main())
@@ -41,6 +41,7 @@ import time
41
41
 
42
42
  from . import APP_NAME, ICON, config, shown_version
43
43
  from . import update as questlog_update
44
+ from .focus import FocusFollower
44
45
  from .pcap_bridge import BridgeServer, read_records
45
46
 
46
47
  APPID = 3393110
@@ -51,6 +52,8 @@ BRIDGE_DLL = BIN / "wpcap.dll"
51
52
  # Marks our DLL in the prefix (kept from the project's first name: changing it
52
53
  # would make install_bridge_dll take an installed build for a foreign file).
53
54
  BRIDGE_SIGNATURE = b"questlog-proton bridge"
55
+ FOCUS_DLL = BIN / "version.dll" # bridge/focus_hook.c (§6.12)
56
+ FOCUS_SIGNATURE = b"a2qlinux focus hook"
54
57
 
55
58
 
56
59
  LAUNCHER_LOG_LIMIT = 1_000_000 # bytes per file; one older file is kept, so at most twice this on disk
@@ -247,6 +250,48 @@ def install_bridge_dll(prefix):
247
250
  log(f"Installed the capture bridge DLL at {target}.")
248
251
 
249
252
 
253
+ def install_focus_dll(questlog_dir):
254
+ """Put our version.dll beside Questlog.exe (§6.12); True when ours is there.
255
+
256
+ Questlog's folder is replaced by every Questlog update, so this runs
257
+ before every start. A version.dll that is not ours (recognised by its
258
+ signature string) is left alone and reported, and the override is not
259
+ set; Wine may still load that file, as it loads a version.dll beside the
260
+ program by default (§6.12).
261
+ """
262
+ target = Path(questlog_dir) / "version.dll"
263
+ if not FOCUS_DLL.is_file():
264
+ log(f"{FOCUS_DLL} is missing; Questlog's overlays stay over other programs when the game is not "
265
+ "in front (in a source checkout build it with: bash bridge/build.sh).")
266
+ return False
267
+ try:
268
+ ours = FOCUS_DLL.read_bytes()
269
+ if target.exists():
270
+ current = target.read_bytes()
271
+ if current == ours:
272
+ return True
273
+ if FOCUS_SIGNATURE not in current:
274
+ log(f"{target} is not A2Qlinux's; leaving it. Questlog's overlays stay over other programs "
275
+ "when the game is not in front.")
276
+ return False
277
+ temporary = target.with_suffix(".tmp")
278
+ temporary.write_bytes(ours)
279
+ temporary.replace(target)
280
+ except OSError as error:
281
+ log(f"Could not put version.dll beside Questlog ({error}); Questlog's overlays stay over other "
282
+ "programs when the game is not in front.")
283
+ return False
284
+ return True
285
+
286
+
287
+ def focus_dll_ours(questlog_dir):
288
+ """Whether the version.dll beside Questlog.exe is ours, so Wine may load it (version=n,b)."""
289
+ try:
290
+ return FOCUS_SIGNATURE in (Path(questlog_dir) / "version.dll").read_bytes()
291
+ except OSError:
292
+ return False
293
+
294
+
250
295
  def steam_launch_pending(appid):
251
296
  """True while Steam is starting the game and Proton waits for a free prefix.
252
297
 
@@ -798,7 +843,9 @@ def show_questlog_window(start_again):
798
843
  # ------------------------------------------------------------------- launch
799
844
 
800
845
  UPDATE_CHECK_EVERY = 6 * 3600 # s between checks for a new Questlog; set from config (update_check_hours)
801
- UPDATE_CHECK_DEFER = 600 # s to wait while the game runs: no 115 MB download during play
846
+ # Bytes/s a Questlog download may use while AION 2 runs (0.1.54, 129 MB: 123 s measured), so that
847
+ # it never takes a line's whole bandwidth from the game's connection.
848
+ UPDATE_RATE_DURING_GAME = 1 << 20
802
849
  UPDATE_TRIAL = 60 # s: a just-updated Questlog that exits sooner is rolled back
803
850
 
804
851
 
@@ -807,14 +854,33 @@ def notify(text):
807
854
  subprocess.run(["notify-send", f"--app-name={APP_NAME}", f"--icon={ICON}", APP_NAME, text], check=False)
808
855
 
809
856
 
857
+ def update_rate_limit():
858
+ """The download limit right now: UPDATE_RATE_DURING_GAME while AION 2 runs, else none."""
859
+ return UPDATE_RATE_DURING_GAME if game_processes(APPID, ["aion2.exe"])["aion2.exe"] else None
860
+
861
+
862
+ def notify_unless_playing(text):
863
+ """notify(), except while AION 2 runs: then the line in the status window and the log is enough.
864
+
865
+ For news that asks nothing of the player ("Questlog X is ready", which
866
+ installs by itself at the next start), so that no popup comes up over
867
+ the game.
868
+ """
869
+ if not game_processes(APPID, ["aion2.exe"])["aion2.exe"]:
870
+ notify(text)
871
+
872
+
810
873
  def check_for_updates(questlog_dir, state_dir):
811
- """Thread body: stage new Questlog versions, never while the game runs."""
874
+ """Thread body: stage new Questlog versions, 60 s after the start and then every UPDATE_CHECK_EVERY.
875
+
876
+ Also while the game runs, with the download slowed (update_rate_limit):
877
+ deferring it to a moment without the game meant that a player who starts
878
+ Questlog with the game and closes it with the game was never checked for.
879
+ """
812
880
  time.sleep(60)
813
881
  while True:
814
- if game_processes(APPID, ["aion2.exe"])["aion2.exe"]:
815
- time.sleep(UPDATE_CHECK_DEFER)
816
- continue
817
- questlog_update.stage(questlog_dir, state_dir, log, notify)
882
+ questlog_update.stage(questlog_dir, state_dir, log, notify, rate_limit=update_rate_limit,
883
+ notify_ready=notify_unless_playing)
818
884
  time.sleep(UPDATE_CHECK_EVERY)
819
885
 
820
886
 
@@ -1281,8 +1347,11 @@ def launch_questlog(executable, server, protontricks, log_path, hidden=False, ho
1281
1347
  env["QUESTLOG_PROTON_BRIDGE"] = server.environment_value()
1282
1348
  # Wine ships a builtin wpcap.dll and loads it instead of ours even when
1283
1349
  # Questlog names our file by full path; "n" makes it take the native file.
1284
- overrides = [o for o in env.get("WINEDLLOVERRIDES", "").split(";") if o and not o.startswith("wpcap=")]
1285
- env["WINEDLLOVERRIDES"] = ";".join(overrides + ["wpcap=n"])
1350
+ # version=n,b: our version.dll beside Questlog.exe instead of Wine's (§6.12); only when it is ours.
1351
+ overrides = [o for o in env.get("WINEDLLOVERRIDES", "").split(";")
1352
+ if o and not o.startswith(("wpcap=", "version="))]
1353
+ focus = ["version=n,b"] if focus_dll_ours(executable.parent) else []
1354
+ env["WINEDLLOVERRIDES"] = ";".join(overrides + ["wpcap=n"] + focus)
1286
1355
  env["PWD"] = str(executable.parent)
1287
1356
  # Inside Steam's container (pressure-vessel) Chromium cannot set up its
1288
1357
  # Windows sandbox: the GPU process fails with error 39 and the renderers
@@ -1367,6 +1436,8 @@ def main():
1367
1436
  raise RuntimeError("Questlog is already running in the game prefix without the capture bridge. "
1368
1437
  "Quit it (tray icon > Quit) and run this again.")
1369
1438
  server = BridgeServer(log)
1439
+ focus_follower = FocusFollower(server.set_focus, log)
1440
+ focus_follower.start()
1370
1441
  status = {"packets": 0}
1371
1442
  captures = Captures(dumpcap, server, args.interface or settings.interface, status, notify=notify)
1372
1443
  captures.scan()
@@ -1394,6 +1465,7 @@ def main():
1394
1465
  questlog_update.disable_builtin_updater(executable.parent, log)
1395
1466
  if auto_update and questlog_update.install_staged(executable.parent, state_dir, log):
1396
1467
  trial["until"] = time.monotonic() + UPDATE_TRIAL
1468
+ install_focus_dll(executable.parent)
1397
1469
  log(f"Starting Questlog {questlog_update.installed_version(executable.parent) or '(version unknown)'}.")
1398
1470
  started = launch_questlog(executable, server, protontricks, log_path, hidden=hidden)
1399
1471
  start_watch.started(hidden)
@@ -1589,6 +1661,7 @@ def main():
1589
1661
  run_ctl(protontricks, "show-tray", log_path)
1590
1662
  captures.stop()
1591
1663
  server.stop()
1664
+ focus_follower.stop()
1592
1665
  except (OSError, RuntimeError) as error:
1593
1666
  print(f"a2qlinux: {error}", file=sys.stderr)
1594
1667
  LOG_FILE.write(f"Ended with an error: {error}")
@@ -11,6 +11,11 @@ connects to this server on 127.0.0.1 and sends one request line:
11
11
  followed by packet records (16-byte
12
12
  record header + frame); or
13
13
  "ERR <reason>\\n" and the server closes
14
+ "QLPB2 <token> focus\\n" -> "in\\n" or "out\\n" now, and again on every
15
+ change, for as long as the connection
16
+ lives (version.dll in Questlog's main
17
+ process: is the desktop's active window
18
+ one of Wine's; a2qlinux/focus.py)
14
19
 
15
20
  The list is what pcap_findalldevs reports, so Questlog picks the interface
16
21
  whose address its game connection uses, as it picks an adapter on Windows.
@@ -154,6 +159,9 @@ class BridgeServer:
154
159
  self.lock = threading.Lock()
155
160
  self.connections = 0
156
161
  self.followed = None # (interface, address) of the last device Questlog opened
162
+ self.focus = "in" # set_focus; "in" until told otherwise: Wine's own answer
163
+ self.focus_clients = []
164
+ self.focus_lock = threading.Lock() # state, clients and sends, so every client sees the changes in order
157
165
  self.stopped = threading.Event()
158
166
  threading.Thread(target=self._accept_loop, daemon=True).start()
159
167
 
@@ -174,6 +182,23 @@ class BridgeServer:
174
182
  for client in channel.clients:
175
183
  client.close()
176
184
 
185
+ def set_focus(self, state):
186
+ """Tell every focus client whether a Wine window ("in") or another one ("out") is active."""
187
+ with self.focus_lock:
188
+ if state == self.focus:
189
+ return
190
+ self.focus = state
191
+ for sock in list(self.focus_clients):
192
+ self._send_focus(sock, state)
193
+
194
+ def _send_focus(self, sock, state):
195
+ """Send one state line; a client that is gone is dropped. Called with focus_lock held."""
196
+ try:
197
+ sock.sendall(f"{state}\n".encode())
198
+ except OSError:
199
+ self.focus_clients.remove(sock)
200
+ sock.close()
201
+
177
202
  def _accept_loop(self):
178
203
  while not self.stopped.is_set():
179
204
  try:
@@ -212,6 +237,12 @@ class BridgeServer:
212
237
  sock.sendall(listing.encode() + b"\n")
213
238
  sock.close()
214
239
  return
240
+ if words == ["focus"]:
241
+ sock.settimeout(5) # a send to a client that stopped reading must not hold the lock
242
+ with self.focus_lock:
243
+ self.focus_clients.append(sock)
244
+ self._send_focus(sock, self.focus)
245
+ return
215
246
  if len(words) != 2 or words[0] != "open":
216
247
  self.log(f"Refused an unknown request from the capture DLL: {' '.join(words)!r}.")
217
248
  sock.sendall(b"ERR Unknown request to the capture bridge (A2Qlinux and its wpcap.dll differ)\n")
@@ -280,6 +311,10 @@ class BridgeServer:
280
311
  pass
281
312
  with self.lock:
282
313
  channels, self.channels = self.channels, {}
314
+ with self.focus_lock:
315
+ focus_clients, self.focus_clients = self.focus_clients, []
316
+ for sock in focus_clients:
317
+ sock.close()
283
318
  for channel in channels.values():
284
319
  for c in channel.clients:
285
320
  c.close()
@@ -245,7 +245,7 @@ def tray_problem():
245
245
 
246
246
 
247
247
  def windows_parts_problem():
248
- missing = [name for name in ("wpcap.dll", "questlog_ctl.exe") if not (BIN / name).is_file()]
248
+ missing = [name for name in ("wpcap.dll", "version.dll", "questlog_ctl.exe") if not (BIN / name).is_file()]
249
249
  if missing:
250
250
  return (f"{', '.join(missing)} missing from {BIN}; in a source checkout run: bash bridge/build.sh "
251
251
  "(needs clang, lld and wine)")