|
2 | 2 | # Internal version : 2.0.0 date: 2026-05-24 00:00 |
3 | 3 | # Owner: Luc LEBOSSE all copyrights |
4 | 4 | # License: LGPL3 |
5 | | -"""macOS NSApplication activation-policy helpers (ctypes, no pyobjc dependency). |
| 5 | +"""macOS NSApplication activation-policy helpers — stubs only. |
6 | 6 |
|
7 | | -Regular → Dock icon visible, app menu visible (normal windowed app). |
8 | | -Accessory → No Dock icon, no app menu (menu-bar / tray-only app). |
9 | | -
|
10 | | -Call set_policy_regular() before showing the main window and |
11 | | -set_policy_accessory() after hiding it to the system tray. |
| 7 | +Dynamic policy switching (Accessory ↔ Regular) was tested but found to |
| 8 | +interfere with QSystemTrayIcon availability on macOS 11 Big Sur when called |
| 9 | +before the system tray is initialised. These are no-ops until a reliable |
| 10 | +sequencing solution is found. |
12 | 11 | """ |
13 | 12 |
|
14 | 13 | from __future__ import annotations |
15 | 14 |
|
16 | | -import sys |
17 | | - |
18 | | -if sys.platform != "darwin": |
19 | | - |
20 | | - def set_policy_regular() -> None: |
21 | | - pass |
22 | | - |
23 | | - def set_policy_accessory() -> None: |
24 | | - pass |
25 | | - |
26 | | -else: |
27 | | - import ctypes |
28 | | - import ctypes.util |
29 | | - |
30 | | - _lib = ctypes.cdll.LoadLibrary(ctypes.util.find_library("objc") or "libobjc.dylib") |
31 | | - _lib.objc_getClass.restype = ctypes.c_void_p |
32 | | - _lib.objc_getClass.argtypes = [ctypes.c_char_p] |
33 | | - _lib.sel_registerName.restype = ctypes.c_void_p |
34 | | - _lib.sel_registerName.argtypes = [ctypes.c_char_p] |
35 | | - |
36 | | - _POLICY_REGULAR = 0 # NSApplicationActivationPolicyRegular |
37 | | - _POLICY_ACCESSORY = 1 # NSApplicationActivationPolicyAccessory |
38 | | - |
39 | | - def _shared_app() -> int: |
40 | | - # Get NSApp — set argtypes/restype for this specific call signature |
41 | | - _lib.objc_msgSend.restype = ctypes.c_void_p |
42 | | - _lib.objc_msgSend.argtypes = [ctypes.c_void_p, ctypes.c_void_p] |
43 | | - return _lib.objc_msgSend( |
44 | | - _lib.objc_getClass(b"NSApplication"), |
45 | | - _lib.sel_registerName(b"sharedApplication"), |
46 | | - ) |
47 | 15 |
|
48 | | - def _set_policy(policy: int) -> None: |
49 | | - try: |
50 | | - # Resolve NSApp first — _shared_app() modifies argtypes internally, |
51 | | - # so it must be called before we set the 3-arg signature below. |
52 | | - nsapp = _shared_app() |
53 | | - _lib.objc_msgSend.restype = ctypes.c_void_p |
54 | | - _lib.objc_msgSend.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_long] |
55 | | - _lib.objc_msgSend( |
56 | | - nsapp, |
57 | | - _lib.sel_registerName(b"setActivationPolicy:"), |
58 | | - ctypes.c_long(policy), |
59 | | - ) |
60 | | - except Exception: |
61 | | - pass |
| 16 | +def set_policy_regular() -> None: |
| 17 | + pass |
62 | 18 |
|
63 | | - def set_policy_regular() -> None: |
64 | | - """Dock icon + app menu visible (normal windowed app).""" |
65 | | - _set_policy(_POLICY_REGULAR) |
66 | 19 |
|
67 | | - def set_policy_accessory() -> None: |
68 | | - """No Dock icon, no app menu (tray/menu-bar app).""" |
69 | | - _set_policy(_POLICY_ACCESSORY) |
| 20 | +def set_policy_accessory() -> None: |
| 21 | + pass |
0 commit comments