a2qlinux 0.7.2__tar.gz → 0.8.0__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 (61) hide show
  1. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/CHANGELOG.md +49 -0
  2. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/PKG-INFO +2 -2
  3. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/README.md +1 -1
  4. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/_version.py +2 -2
  5. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/bin/questlog_ctl.exe +0 -0
  6. a2qlinux-0.8.0/a2qlinux/bin/version.dll +0 -0
  7. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/bin/wpcap.dll +0 -0
  8. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/diagnose.py +2 -1
  9. a2qlinux-0.8.0/a2qlinux/focus.py +218 -0
  10. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/launcher.py +113 -12
  11. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/pcap_bridge.py +35 -0
  12. a2qlinux-0.8.0/a2qlinux/questlog_versions.py +96 -0
  13. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/setup_desktop.py +11 -3
  14. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/tray.py +32 -4
  15. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/update.py +182 -24
  16. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/bridge/build.sh +9 -1
  17. a2qlinux-0.8.0/bridge/focus_hook.c +257 -0
  18. a2qlinux-0.8.0/bridge/focus_hook.def +18 -0
  19. a2qlinux-0.8.0/bridge/tests/focus_hook_test.c +82 -0
  20. a2qlinux-0.8.0/bridge/tests/run_focus_hook_test.py +66 -0
  21. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/docs/ARCHITECTURE.md +327 -19
  22. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/docs/INSTALL.md +5 -2
  23. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/docs/RELEASE.md +9 -1
  24. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/docs/TROUBLESHOOTING.md +5 -2
  25. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/docs/UPDATING.md +57 -5
  26. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/docs/USING.md +24 -1
  27. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/pyproject.toml +1 -1
  28. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_diagnose.py +12 -0
  29. a2qlinux-0.8.0/tests/test_focus.py +57 -0
  30. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_launcher.py +88 -0
  31. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_pcap_bridge.py +26 -0
  32. a2qlinux-0.8.0/tests/test_questlog_watch.py +97 -0
  33. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_update.py +193 -4
  34. a2qlinux-0.8.0/tools/foreground_probe.c +95 -0
  35. a2qlinux-0.8.0/tools/questlog_watch.py +151 -0
  36. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/.gitignore +0 -0
  37. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/LICENSE +0 -0
  38. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/__init__.py +0 -0
  39. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/config.py +0 -0
  40. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/desktop.py +0 -0
  41. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/kde_overlays.py +0 -0
  42. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/open_folders.py +0 -0
  43. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/a2qlinux/steam.py +0 -0
  44. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/bridge/questlog_ctl.c +0 -0
  45. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/bridge/tests/bridge_client_test.c +0 -0
  46. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/bridge/tests/zorder_guard_test.c +0 -0
  47. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/bridge/wpcap_bridge.c +0 -0
  48. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/docs/README.md +0 -0
  49. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/__init__.py +0 -0
  50. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_config.py +0 -0
  51. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_desktop.py +0 -0
  52. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_kde_overlays.py +0 -0
  53. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_open_folders.py +0 -0
  54. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_replay_stream.py +0 -0
  55. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_setup_desktop.py +0 -0
  56. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_steam.py +0 -0
  57. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tests/test_version.py +0 -0
  58. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tools/__init__.py +0 -0
  59. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tools/pcap2questlog.py +0 -0
  60. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tools/replay_stream.py +0 -0
  61. {a2qlinux-0.7.2 → a2qlinux-0.8.0}/tools/tcp_owner_probe.c +0 -0
@@ -3,6 +3,55 @@
3
3
  What changed for players, release by release. Technical details are in
4
4
  `docs/ARCHITECTURE.md`.
5
5
 
6
+ ## [0.8.0] — 2026-11-18
7
+
8
+ ### Added
9
+ - A newer Questlog that A2Qlinux cannot install yet no longer goes
10
+ unnoticed once its notification has gone: the tray icon's menu shows a
11
+ line such as "Questlog 0.1.56 not installed: does not fit yet" for as
12
+ long as that holds (hovering over it shows the reason), and
13
+ `a2qlinux-setup` names the installed Questlog and what is known about a
14
+ newer one. A version ready for the next start shows there too.
15
+ - When Questlog has just released a version A2Qlinux cannot work with yet,
16
+ `a2qlinux-setup` on a new machine no longer stops with an error: it
17
+ installs the newest earlier Questlog that works and says so; the newer
18
+ version follows by itself once A2Qlinux works with it.
19
+
20
+ ### Fixed
21
+ - Questlog 0.1.56 is installed again. A2Qlinux had refused it, as it had
22
+ 0.1.55 ("a second start no longer simply shows its window"), although
23
+ Open Questlog works with it as before. Players on 0.1.54 get the newest
24
+ version at the next update check after updating A2Qlinux, and a new
25
+ installation with `a2qlinux-setup` works again.
26
+
27
+ ## [0.7.3] — 2026-11-14
28
+
29
+ ### Fixed
30
+ - Questlog's overlays (meter, timers, tracker, map) no longer stay drawn
31
+ over another program, such as a browser, after switching to it from the
32
+ game: they hide while it is in front and come back with the game. With
33
+ two monitors they also hide while a program on the other monitor is in
34
+ use.
35
+ - Questlog 0.1.54 is installed again. A2Qlinux had refused it ("its capture
36
+ worker calls no libpcap functions any more; a second start no longer
37
+ simply shows its window"), but nothing it relies on changed: Questlog
38
+ only packs its code differently. Players on 0.1.53 get 0.1.54 at the next
39
+ update check after updating A2Qlinux.
40
+ - New Questlog versions now also reach players who start Questlog with the
41
+ game and close it with the game (`after_game = "close"`). The download
42
+ used to wait until the game was closed, and by then A2Qlinux had closed
43
+ too, so the update was almost never fetched. It now runs during play,
44
+ slowed to about 1 MB per second, and installs at the next start as before.
45
+ During play, "Questlog X is ready" shows only in the status window, not
46
+ as a desktop notification.
47
+ - A Questlog version that an older A2Qlinux refused is checked again after
48
+ A2Qlinux is updated, instead of staying refused until the next Questlog
49
+ version.
50
+ - The GitHub issue that `a2qlinux --diagnose --report` opens shows the end
51
+ of A2Qlinux's own log again under "launcher.log"; since 0.7.2 it showed
52
+ part of the new process snapshot there instead. The report file itself
53
+ was complete.
54
+
6
55
  ## [0.7.2] — 2026-11-13
7
56
 
8
57
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: a2qlinux
3
- Version: 0.7.2
3
+ Version: 0.8.0
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.2'
22
- __version_tuple__ = version_tuple = (0, 7, 2)
21
+ __version__ = version = '0.8.0'
22
+ __version_tuple__ = version_tuple = (0, 8, 0)
23
23
 
24
24
  __commit_id__ = commit_id = None
Binary file
@@ -737,7 +737,8 @@ def issue_url(results, report, report_path, anonymise, limit=ISSUE_URL_LIMIT):
737
737
  """A new-issue URL with the diagnosis and as much of the log's end as fits within `limit`."""
738
738
  title = f"Problem report (A2Qlinux {shown_version()})"
739
739
  diagnosis = anonymise(format_results(results)).splitlines()
740
- 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:]
741
742
  log_lines = [line for line in log_lines if line.strip()]
742
743
 
743
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
 
@@ -700,12 +745,18 @@ class Tray:
700
745
  It runs in its own session, so a Ctrl+C meant for this launcher does not
701
746
  reach it; it ends when its stdin closes. If it ends by itself, "tray-died"
702
747
  is put into requests so that Questlog's own icon can be shown again.
748
+
749
+ news: a callable giving update.update_news's (short, full) or None; sent
750
+ to the icon when it starts and on refresh(), so the menu carries a
751
+ refused or staged Questlog version for as long as that holds.
703
752
  """
704
753
 
705
- def __init__(self, requests):
754
+ def __init__(self, requests, news=lambda: None):
706
755
  self.requests = requests
756
+ self.news = news
707
757
  self.process = None
708
758
  self.stopping = False
759
+ self.writing = threading.Lock() # refresh() runs in the update thread
709
760
 
710
761
  def start(self):
711
762
  if self.process and self.process.poll() is None:
@@ -714,6 +765,26 @@ class Tray:
714
765
  self.process = subprocess.Popen([sys.executable, "-m", "a2qlinux.tray"], stdin=subprocess.PIPE,
715
766
  stdout=subprocess.PIPE, start_new_session=True)
716
767
  threading.Thread(target=self._read, args=(self.process,), daemon=True).start()
768
+ self.refresh()
769
+
770
+ def refresh(self):
771
+ """Send the current news to the icon (update.update_news); nothing when it does not run."""
772
+ try:
773
+ news = self.news()
774
+ except Exception as error: # the news must never stop the launcher; say why it is missing
775
+ log(f"Could not work out the update news for the tray icon: {error!r}")
776
+ return
777
+ line = "news" if not news else "news " + "\t".join(part.replace("\t", " ").replace("\n", " ")
778
+ for part in news)
779
+ with self.writing:
780
+ process = self.process
781
+ if not process or process.poll() is not None:
782
+ return
783
+ try:
784
+ process.stdin.write((line + "\n").encode())
785
+ process.stdin.flush()
786
+ except (OSError, ValueError):
787
+ pass # it is ending (stop() may have closed the pipe); _read reports that
717
788
 
718
789
  def _read(self, process):
719
790
  for line in process.stdout:
@@ -798,7 +869,9 @@ def show_questlog_window(start_again):
798
869
  # ------------------------------------------------------------------- launch
799
870
 
800
871
  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
872
+ # Bytes/s a Questlog download may use while AION 2 runs (0.1.54, 129 MB: 123 s measured), so that
873
+ # it never takes a line's whole bandwidth from the game's connection.
874
+ UPDATE_RATE_DURING_GAME = 1 << 20
802
875
  UPDATE_TRIAL = 60 # s: a just-updated Questlog that exits sooner is rolled back
803
876
 
804
877
 
@@ -807,14 +880,34 @@ def notify(text):
807
880
  subprocess.run(["notify-send", f"--app-name={APP_NAME}", f"--icon={ICON}", APP_NAME, text], check=False)
808
881
 
809
882
 
810
- def check_for_updates(questlog_dir, state_dir):
811
- """Thread body: stage new Questlog versions, never while the game runs."""
883
+ def update_rate_limit():
884
+ """The download limit right now: UPDATE_RATE_DURING_GAME while AION 2 runs, else none."""
885
+ return UPDATE_RATE_DURING_GAME if game_processes(APPID, ["aion2.exe"])["aion2.exe"] else None
886
+
887
+
888
+ def notify_unless_playing(text):
889
+ """notify(), except while AION 2 runs: then the line in the status window and the log is enough.
890
+
891
+ For news that asks nothing of the player ("Questlog X is ready", which
892
+ installs by itself at the next start), so that no popup comes up over
893
+ the game.
894
+ """
895
+ if not game_processes(APPID, ["aion2.exe"])["aion2.exe"]:
896
+ notify(text)
897
+
898
+
899
+ def check_for_updates(questlog_dir, state_dir, checked=lambda: None):
900
+ """Thread body: stage new Questlog versions, 60 s after the start and then every UPDATE_CHECK_EVERY.
901
+
902
+ Also while the game runs, with the download slowed (update_rate_limit):
903
+ deferring it to a moment without the game meant that a player who starts
904
+ Questlog with the game and closes it with the game was never checked for.
905
+ """
812
906
  time.sleep(60)
813
907
  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)
908
+ questlog_update.stage(questlog_dir, state_dir, log, notify, rate_limit=update_rate_limit,
909
+ notify_ready=notify_unless_playing)
910
+ checked()
818
911
  time.sleep(UPDATE_CHECK_EVERY)
819
912
 
820
913
 
@@ -1281,8 +1374,11 @@ def launch_questlog(executable, server, protontricks, log_path, hidden=False, ho
1281
1374
  env["QUESTLOG_PROTON_BRIDGE"] = server.environment_value()
1282
1375
  # Wine ships a builtin wpcap.dll and loads it instead of ours even when
1283
1376
  # 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"])
1377
+ # version=n,b: our version.dll beside Questlog.exe instead of Wine's (§6.12); only when it is ours.
1378
+ overrides = [o for o in env.get("WINEDLLOVERRIDES", "").split(";")
1379
+ if o and not o.startswith(("wpcap=", "version="))]
1380
+ focus = ["version=n,b"] if focus_dll_ours(executable.parent) else []
1381
+ env["WINEDLLOVERRIDES"] = ";".join(overrides + ["wpcap=n"] + focus)
1286
1382
  env["PWD"] = str(executable.parent)
1287
1383
  # Inside Steam's container (pressure-vessel) Chromium cannot set up its
1288
1384
  # Windows sandbox: the GPU process fails with error 39 and the renderers
@@ -1367,6 +1463,8 @@ def main():
1367
1463
  raise RuntimeError("Questlog is already running in the game prefix without the capture bridge. "
1368
1464
  "Quit it (tray icon > Quit) and run this again.")
1369
1465
  server = BridgeServer(log)
1466
+ focus_follower = FocusFollower(server.set_focus, log)
1467
+ focus_follower.start()
1370
1468
  status = {"packets": 0}
1371
1469
  captures = Captures(dumpcap, server, args.interface or settings.interface, status, notify=notify)
1372
1470
  captures.scan()
@@ -1382,7 +1480,7 @@ def main():
1382
1480
  "Start the game any time - its traffic then flows to Questlog.")
1383
1481
  log_path = state_dir / "questlog.log"
1384
1482
  start_questlog_log(log_path)
1385
- tray = Tray(requests)
1483
+ tray = Tray(requests, news=lambda: questlog_update.update_news(executable.parent, state_dir))
1386
1484
  quit_control = QuitControl()
1387
1485
 
1388
1486
  trial = {"until": 0.0} # end of a just-installed update's trial run
@@ -1394,6 +1492,7 @@ def main():
1394
1492
  questlog_update.disable_builtin_updater(executable.parent, log)
1395
1493
  if auto_update and questlog_update.install_staged(executable.parent, state_dir, log):
1396
1494
  trial["until"] = time.monotonic() + UPDATE_TRIAL
1495
+ install_focus_dll(executable.parent)
1397
1496
  log(f"Starting Questlog {questlog_update.installed_version(executable.parent) or '(version unknown)'}.")
1398
1497
  started = launch_questlog(executable, server, protontricks, log_path, hidden=hidden)
1399
1498
  start_watch.started(hidden)
@@ -1406,7 +1505,8 @@ def main():
1406
1505
 
1407
1506
  questlog = start_questlog()
1408
1507
  if auto_update:
1409
- threading.Thread(target=check_for_updates, args=(executable.parent, state_dir), daemon=True).start()
1508
+ threading.Thread(target=check_for_updates, args=(executable.parent, state_dir, tray.refresh),
1509
+ daemon=True).start()
1410
1510
  told = False
1411
1511
  game_gone_since = None
1412
1512
  after_exit = None
@@ -1589,6 +1689,7 @@ def main():
1589
1689
  run_ctl(protontricks, "show-tray", log_path)
1590
1690
  captures.stop()
1591
1691
  server.stop()
1692
+ focus_follower.stop()
1592
1693
  except (OSError, RuntimeError) as error:
1593
1694
  print(f"a2qlinux: {error}", file=sys.stderr)
1594
1695
  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()