pwr_tray 1.0.2__tar.gz → 1.0.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 (33) hide show
  1. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/PKG-INFO +26 -22
  2. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/README.md +25 -21
  3. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/main.py +73 -43
  4. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pyproject.toml +1 -1
  5. pwr_tray-1.0.3/runner +19 -0
  6. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/.gitignore +0 -0
  7. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/LICENSE +0 -0
  8. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/images/pwr-tray-screenshot.png +0 -0
  9. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/IniTool.py +0 -0
  10. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/SwayIdleMgr.py +0 -0
  11. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/Utils.py +0 -0
  12. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/YamlDump.py +0 -0
  13. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/__init__.py +0 -0
  14. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/FullSun-v03.svg +0 -0
  15. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/GoingDown-v03.svg +0 -0
  16. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/PlayingNow-v03.svg +0 -0
  17. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/RisingMoon-v03.svg +0 -0
  18. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetA/pwr-inh-v03.svg +0 -0
  19. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetA/pwr-no-sleep-v03.svg +0 -0
  20. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetA/pwr-uninh-v03.svg +0 -0
  21. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetB/LoBattery-v03.svg +0 -0
  22. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetB/LockOnlyMode-v03.svg +0 -0
  23. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetB/NormMode-v03.svg +0 -0
  24. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetC/New-LockOnly-v03.svg +0 -0
  25. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetC/New-LowBattery-v03.svg +0 -0
  26. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetC/New-NormMode-v03.svg +0 -0
  27. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SetC/New-PresMode-v03.svg +0 -0
  28. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/SettingSun-v03.svg +0 -0
  29. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/StopSign-v03.svg +0 -0
  30. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/Unlocked-v03.svg +0 -0
  31. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/UnlockedMoon-v03.svg +0 -0
  32. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/__init__.py +0 -0
  33. {pwr_tray-1.0.2 → pwr_tray-1.0.3}/pwr_tray/resources/lockpaper.png +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pwr_tray
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: A GTK tray applet for power management for i3/sway/KDE
5
5
  Keywords: power,energy,GTK,applet,tray,kde,i3wm,sway
6
6
  Author-email: Joe Defen <joedef@google.com>
@@ -18,7 +18,7 @@ Project-URL: Homepage, https://github.com/joedefen/pwr-tray
18
18
 
19
19
  # pwr-tray
20
20
 
21
- `pwr-tray` is a GTK5 Tray Applet for Power/Energy Saving and System/DE Controls; currently supported/tested DEs are: i3wm, swaywm, and KDE on X11. `systemd` is required. The `pwr-tray` menu will look similar to:
21
+ `pwr-tray` is a PyQt5 Tray Applet for Power/Energy Saving and System/DE Controls; currently supported/tested DEs are: i3wm, swaywm, and KDE (X11 and Wayland). `systemd` is required. The `pwr-tray` menu will look similar to:
22
22
 
23
23
  <p align="center">
24
24
  <img src="https://github.com/joedefen/pwr-tray/blob/main/images/pwr-tray-screenshot.png?raw=true" alt="screenshot">
@@ -27,14 +27,14 @@ Project-URL: Homepage, https://github.com/joedefen/pwr-tray
27
27
 
28
28
  With just a right-click and a left-click, you can do most operations such as change to Presentation Mode, change screen lock and sleep timeouts, log off, lock and blank your monitors, and more. The `pwr-tray` icon changes based on state:
29
29
 
30
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/FullSun-v03.svg?raw=true" alt="FullSun" width="24" height="24"> Presentation Mode (i.e., the full sun)
31
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/SettingSun-v03.svg?raw=true" alt="SettingSun" width="24" height="24"> SleepAfterLock Mode (i.e., the setting sun)
32
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/RisingMoon-v03.svg?raw=true" alt="RisingMoon" width="24" height="24"> SleepAfterLock Mode and Locking Screen Soon
33
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/Unlocked-v03.svg?raw=true" alt="Unlocked" width="24" height="24"> LockOnly Mode (i.e., the unlocked lock)
34
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/UnlockedMoon-v03.svg?raw=true" alt="UnlockedMoon" width="24" height="24"> LockOnly Mode and Locking Screen Soon
35
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/GoingDown-v03.svg?raw=true" alt="GoingDown" width="24" height="24"> LowBattery State (going down).
36
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/PlayingNow-v03.svg?raw=true" alt="PlayingNow" width="24" height="24"> Inhibited by playing media.
37
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/StopSign-v03.svg?raw=true" alt="StopSign" width="24" height="24"> Inhibited by systemd inhibitors.
30
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/FullSun-v03.svg?raw=true" alt="FullSun" width="24" height="24"> Presentation Mode (i.e., the full sun)
31
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/SettingSun-v03.svg?raw=true" alt="SettingSun" width="24" height="24"> SleepAfterLock Mode (i.e., the setting sun)
32
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/RisingMoon-v03.svg?raw=true" alt="RisingMoon" width="24" height="24"> SleepAfterLock Mode and Locking Screen Soon
33
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/Unlocked-v03.svg?raw=true" alt="Unlocked" width="24" height="24"> LockOnly Mode (i.e., the unlocked lock)
34
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/UnlockedMoon-v03.svg?raw=true" alt="UnlockedMoon" width="24" height="24"> LockOnly Mode and Locking Screen Soon
35
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/GoingDown-v03.svg?raw=true" alt="GoingDown" width="24" height="24"> LowBattery State (going down).
36
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/PlayingNow-v03.svg?raw=true" alt="PlayingNow" width="24" height="24"> Inhibited by playing media.
37
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/StopSign-v03.svg?raw=true" alt="StopSign" width="24" height="24"> Inhibited by systemd inhibitors.
38
38
 
39
39
  ---
40
40
 
@@ -45,31 +45,31 @@ With just a right-click and a left-click, you can do most operations such as cha
45
45
  * Shows system-level commands (DE dependent) that must be installed if missing. Note:
46
46
  * `systemctl` is always required.
47
47
  * Optionally, install `playerctl` if you wish playing media to inhibit screen saving and sleeping.
48
- * If you find you are missing the QT5 foundation, then you'll need to install that; examples:
49
- * `sudo apt install qt5-default` # if debian based
50
- * `sudo pacman -S qt5-base` # if arch based
51
- * `sudo dnf install qt5-qtbase` # if fedora based
48
+ * If you find you are missing PyQt5, then you'll need to install it; examples:
49
+ * `sudo apt install python3-pyqt5` # if debian based
50
+ * `sudo pacman -S python-pyqt5` # if arch based
51
+ * `sudo dnf install python3-qt5` # if fedora based
52
52
 
53
53
  * Then, follow the "Per-DE Specific Notes" below to ensure proper operation. To just kick the tires, you can defer this until ready to go forward.
54
54
  * Read the other sections for customization and everyday use.
55
55
  * From the CLI, you can start/restart pwr-tray in the background with `setsid pwr-tray`; typically, you will "autostart" `pwr-tray` when you log in however your DE/WM manages autostarts.
56
- * `pwr-tray -e` edits the config file (`~/.config/pwr-ini/config.ini`)
57
- * `pwr-tray -f` tails the log file (`~/.config/pwr-ini/debug.log`)
56
+ * `pwr-tray -e` edits the config file (`~/.config/pwr-tray/config.ini`)
57
+ * `pwr-tray -f` tails the log file (`~/.config/pwr-tray/debug.log`)
58
58
 
59
59
  ---
60
60
 
61
61
  ### HowTo Use pwr-tray
62
- Open the `pwr-tray' menu with a right-click. Then left-click a line to have an effect ...
62
+ Open the `pwr-tray` menu with a right-click. Then left-click a line to have an effect ...
63
63
 
64
64
  Choose from three *major power modes* (to control the effects of timeouts):
65
65
  - **🅟 Presentation ⮜** - Keeps the screen unlocked/on and system up.
66
66
  - **🅛 LockOnly ⮜** - Keeps the system up, but the screen may lock.
67
67
  - **🅢 SleepAfterLock ⮜** - Allows screen locking and system to go down (the "normal" mode).
68
68
 
69
- Ory choose from various locking/blanking/DE operations:
69
+ Or choose from various locking/blanking/DE operations:
70
70
  - **▷ Lock Screen** - locks the screen immediately.
71
71
  - **▷ Blank Monitors** - blanks the screen after locking the screen.
72
- - **▷ Reload i3** - various DE-dependent actions.
72
+ - **▷ Reload** - various DE-dependent actions (reload WM config, etc.).
73
73
  - **▷ Log Off** - terminate your user session.
74
74
 
75
75
  Or choose a new *system state*:
@@ -110,7 +110,8 @@ Or act on the applet itself:
110
110
  Here are the current 'Settings' defaults with explanation.
111
111
  ```
112
112
  [Settings]
113
- i3lock_args = -t -i ./lockpaper.png # arguments when running i3lock for wallpaper
113
+ i3lock_args = -t -i ./lockpaper.png # extra arguments for i3lock
114
+ swaylock_args = -i ./lockpaper.png # extra arguments for swaylock
114
115
  debug_mode = False # more frequent and elaborate logging
115
116
  power_down = False # power down (rather than suspend)
116
117
  turn_off_monitors = False # turn off monitors after locking screen
@@ -159,11 +160,14 @@ bindsym $mod+Escape exec --no-startup-id $screenlock # create shortcut to lock
159
160
  ### sway Specific Notes
160
161
  * Uninstall or disable all competing energy saving programs (e.g., `swayidle`, `xfce4-power-manager`, etc.) when running `sway` whether started by `systemd` or `sway/config` or whatever.
161
162
  * **NOTE**: on `sway`, `pwr-tray` cannot read the idle time and do its usual micromanagement; instead, it runs a `swayidle` command whose arguments may vary with your settings.
162
- * Edit `/etc/system/logind.conf` and uncomment `HandlePowerKey=` and `HandleLidSwitch=`, and set each action to `suspend`; then either reboot or restart `systemd-logind`. That enables the ever-running `swayidle` to handle the suspend / resume events.
163
+ * Edit `/etc/systemd/logind.conf` and uncomment `HandlePowerKey=` and `HandleLidSwitch=`, and set each action to `suspend`; then either reboot or restart `systemd-logind`. That enables the ever-running `swayidle` to handle the suspend / resume events.
163
164
  * Again, find a way to start `pwr-tray`; perhaps adding to sway's config: `exec_always --no-startup-id sleep 2 && ~/.local/bin/pwr-tray`; a delay may be required to let the tray initialize.
164
165
 
165
- ### KDE (X11) Specific Notes
166
+ ### KDE Specific Notes
166
167
  * In Settings/Energy Saving, disable "Screen Energy Saving", "Suspend session", etc., except keep the "Button events handling" and make it as you wish (e.g., "When power button pressed", "Sleep").
167
168
  * In Settings/AutoStart, add the full path of `~/.local/bin/pwr-tray`.
169
+ * `qdbus` (or `qdbus6` on Plasma 6) is required; `pwr-tray` auto-detects which is available.
170
+ * On **KDE Wayland**, idle time is read via D-Bus (`org.freedesktop.ScreenSaver`). Locking uses `loginctl lock-session`.
171
+ * On **KDE X11**, idle time is read via `xprintidle` and screen locking uses `loginctl lock-session`.
168
172
 
169
173
 
@@ -1,6 +1,6 @@
1
1
  # pwr-tray
2
2
 
3
- `pwr-tray` is a GTK5 Tray Applet for Power/Energy Saving and System/DE Controls; currently supported/tested DEs are: i3wm, swaywm, and KDE on X11. `systemd` is required. The `pwr-tray` menu will look similar to:
3
+ `pwr-tray` is a PyQt5 Tray Applet for Power/Energy Saving and System/DE Controls; currently supported/tested DEs are: i3wm, swaywm, and KDE (X11 and Wayland). `systemd` is required. The `pwr-tray` menu will look similar to:
4
4
 
5
5
  <p align="center">
6
6
  <img src="https://github.com/joedefen/pwr-tray/blob/main/images/pwr-tray-screenshot.png?raw=true" alt="screenshot">
@@ -9,14 +9,14 @@
9
9
 
10
10
  With just a right-click and a left-click, you can do most operations such as change to Presentation Mode, change screen lock and sleep timeouts, log off, lock and blank your monitors, and more. The `pwr-tray` icon changes based on state:
11
11
 
12
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/FullSun-v03.svg?raw=true" alt="FullSun" width="24" height="24"> Presentation Mode (i.e., the full sun)
13
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/SettingSun-v03.svg?raw=true" alt="SettingSun" width="24" height="24"> SleepAfterLock Mode (i.e., the setting sun)
14
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/RisingMoon-v03.svg?raw=true" alt="RisingMoon" width="24" height="24"> SleepAfterLock Mode and Locking Screen Soon
15
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/Unlocked-v03.svg?raw=true" alt="Unlocked" width="24" height="24"> LockOnly Mode (i.e., the unlocked lock)
16
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/UnlockedMoon-v03.svg?raw=true" alt="UnlockedMoon" width="24" height="24"> LockOnly Mode and Locking Screen Soon
17
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/GoingDown-v03.svg?raw=true" alt="GoingDown" width="24" height="24"> LowBattery State (going down).
18
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/PlayingNow-v03.svg?raw=true" alt="PlayingNow" width="24" height="24"> Inhibited by playing media.
19
- * <img src="https://github.com/joedefen/pwr-tray/blob/main/src/pwr_tray/resources/StopSign-v03.svg?raw=true" alt="StopSign" width="24" height="24"> Inhibited by systemd inhibitors.
12
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/FullSun-v03.svg?raw=true" alt="FullSun" width="24" height="24"> Presentation Mode (i.e., the full sun)
13
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/SettingSun-v03.svg?raw=true" alt="SettingSun" width="24" height="24"> SleepAfterLock Mode (i.e., the setting sun)
14
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/RisingMoon-v03.svg?raw=true" alt="RisingMoon" width="24" height="24"> SleepAfterLock Mode and Locking Screen Soon
15
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/Unlocked-v03.svg?raw=true" alt="Unlocked" width="24" height="24"> LockOnly Mode (i.e., the unlocked lock)
16
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/UnlockedMoon-v03.svg?raw=true" alt="UnlockedMoon" width="24" height="24"> LockOnly Mode and Locking Screen Soon
17
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/GoingDown-v03.svg?raw=true" alt="GoingDown" width="24" height="24"> LowBattery State (going down).
18
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/PlayingNow-v03.svg?raw=true" alt="PlayingNow" width="24" height="24"> Inhibited by playing media.
19
+ * <img src="https://github.com/joedefen/pwr-tray/blob/main/pwr_tray/resources/StopSign-v03.svg?raw=true" alt="StopSign" width="24" height="24"> Inhibited by systemd inhibitors.
20
20
 
21
21
  ---
22
22
 
@@ -27,31 +27,31 @@ With just a right-click and a left-click, you can do most operations such as cha
27
27
  * Shows system-level commands (DE dependent) that must be installed if missing. Note:
28
28
  * `systemctl` is always required.
29
29
  * Optionally, install `playerctl` if you wish playing media to inhibit screen saving and sleeping.
30
- * If you find you are missing the QT5 foundation, then you'll need to install that; examples:
31
- * `sudo apt install qt5-default` # if debian based
32
- * `sudo pacman -S qt5-base` # if arch based
33
- * `sudo dnf install qt5-qtbase` # if fedora based
30
+ * If you find you are missing PyQt5, then you'll need to install it; examples:
31
+ * `sudo apt install python3-pyqt5` # if debian based
32
+ * `sudo pacman -S python-pyqt5` # if arch based
33
+ * `sudo dnf install python3-qt5` # if fedora based
34
34
 
35
35
  * Then, follow the "Per-DE Specific Notes" below to ensure proper operation. To just kick the tires, you can defer this until ready to go forward.
36
36
  * Read the other sections for customization and everyday use.
37
37
  * From the CLI, you can start/restart pwr-tray in the background with `setsid pwr-tray`; typically, you will "autostart" `pwr-tray` when you log in however your DE/WM manages autostarts.
38
- * `pwr-tray -e` edits the config file (`~/.config/pwr-ini/config.ini`)
39
- * `pwr-tray -f` tails the log file (`~/.config/pwr-ini/debug.log`)
38
+ * `pwr-tray -e` edits the config file (`~/.config/pwr-tray/config.ini`)
39
+ * `pwr-tray -f` tails the log file (`~/.config/pwr-tray/debug.log`)
40
40
 
41
41
  ---
42
42
 
43
43
  ### HowTo Use pwr-tray
44
- Open the `pwr-tray' menu with a right-click. Then left-click a line to have an effect ...
44
+ Open the `pwr-tray` menu with a right-click. Then left-click a line to have an effect ...
45
45
 
46
46
  Choose from three *major power modes* (to control the effects of timeouts):
47
47
  - **🅟 Presentation ⮜** - Keeps the screen unlocked/on and system up.
48
48
  - **🅛 LockOnly ⮜** - Keeps the system up, but the screen may lock.
49
49
  - **🅢 SleepAfterLock ⮜** - Allows screen locking and system to go down (the "normal" mode).
50
50
 
51
- Ory choose from various locking/blanking/DE operations:
51
+ Or choose from various locking/blanking/DE operations:
52
52
  - **▷ Lock Screen** - locks the screen immediately.
53
53
  - **▷ Blank Monitors** - blanks the screen after locking the screen.
54
- - **▷ Reload i3** - various DE-dependent actions.
54
+ - **▷ Reload** - various DE-dependent actions (reload WM config, etc.).
55
55
  - **▷ Log Off** - terminate your user session.
56
56
 
57
57
  Or choose a new *system state*:
@@ -92,7 +92,8 @@ Or act on the applet itself:
92
92
  Here are the current 'Settings' defaults with explanation.
93
93
  ```
94
94
  [Settings]
95
- i3lock_args = -t -i ./lockpaper.png # arguments when running i3lock for wallpaper
95
+ i3lock_args = -t -i ./lockpaper.png # extra arguments for i3lock
96
+ swaylock_args = -i ./lockpaper.png # extra arguments for swaylock
96
97
  debug_mode = False # more frequent and elaborate logging
97
98
  power_down = False # power down (rather than suspend)
98
99
  turn_off_monitors = False # turn off monitors after locking screen
@@ -141,10 +142,13 @@ bindsym $mod+Escape exec --no-startup-id $screenlock # create shortcut to lock
141
142
  ### sway Specific Notes
142
143
  * Uninstall or disable all competing energy saving programs (e.g., `swayidle`, `xfce4-power-manager`, etc.) when running `sway` whether started by `systemd` or `sway/config` or whatever.
143
144
  * **NOTE**: on `sway`, `pwr-tray` cannot read the idle time and do its usual micromanagement; instead, it runs a `swayidle` command whose arguments may vary with your settings.
144
- * Edit `/etc/system/logind.conf` and uncomment `HandlePowerKey=` and `HandleLidSwitch=`, and set each action to `suspend`; then either reboot or restart `systemd-logind`. That enables the ever-running `swayidle` to handle the suspend / resume events.
145
+ * Edit `/etc/systemd/logind.conf` and uncomment `HandlePowerKey=` and `HandleLidSwitch=`, and set each action to `suspend`; then either reboot or restart `systemd-logind`. That enables the ever-running `swayidle` to handle the suspend / resume events.
145
146
  * Again, find a way to start `pwr-tray`; perhaps adding to sway's config: `exec_always --no-startup-id sleep 2 && ~/.local/bin/pwr-tray`; a delay may be required to let the tray initialize.
146
147
 
147
- ### KDE (X11) Specific Notes
148
+ ### KDE Specific Notes
148
149
  * In Settings/Energy Saving, disable "Screen Energy Saving", "Suspend session", etc., except keep the "Button events handling" and make it as you wish (e.g., "When power button pressed", "Sleep").
149
150
  * In Settings/AutoStart, add the full path of `~/.local/bin/pwr-tray`.
151
+ * `qdbus` (or `qdbus6` on Plasma 6) is required; `pwr-tray` auto-detects which is available.
152
+ * On **KDE Wayland**, idle time is read via D-Bus (`org.freedesktop.ScreenSaver`). Locking uses `loginctl lock-session`.
153
+ * On **KDE X11**, idle time is read via `xprintidle` and screen locking uses `loginctl lock-session`.
150
154
 
@@ -71,7 +71,6 @@ class PwrTray:
71
71
  if is_wayland:
72
72
  env = 'kde-wayland'
73
73
  prt(f'ENV: {env} {desktop_session=} {wayland_display=}')
74
- assert False, f'unsupported env: {env}'
75
74
  return 'kde-wayland', is_wayland
76
75
  if display:
77
76
  env = 'kde-x11'
@@ -101,6 +100,7 @@ class PwrTray:
101
100
  'monitors_off': '',
102
101
  'locker': '',
103
102
  'get_idle_ms': '',
103
+ 'get_idle_s': '',
104
104
  'reset_idle': '',
105
105
  'reload_wm': '',
106
106
  'restart_wm': '',
@@ -137,29 +137,11 @@ class PwrTray:
137
137
  'restart_wm': 'killall plasmashell && kstart5 plasmashell && sleep 3 && pwr-tray',
138
138
  'must_haves': 'loginctl qdbus'.split(),
139
139
  }, 'kde-wayland': {
140
- # sudo apt-get install xdg-utils
140
+ 'get_idle_s': 'qdbus org.freedesktop.ScreenSaver /ScreenSaver GetSessionIdleTime',
141
141
  'reset_idle': 'qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity',
142
- # gdbus introspect --session --dest org.gnome.SessionManager
143
- # --object-path /org/gnome/SessionManager
144
- # gdbus call --session --dest org.gnome.SessionManager
145
- # --object-path /org/gnome/SessionManager
146
- # --method org.gnome.SessionManager.GetIdleTime
147
- # from pydbus import SessionBus
148
- # import time
149
- # def get_idle_time():
150
- # bus = SessionBus()
151
- # screensaver = bus.get("org.freedesktop.ScreenSaver")
152
- # # The GetSessionIdleTime method returns the idle time in seconds.
153
- # idle_time = screensaver.GetSessionIdleTime()
154
- # return idle_time
155
- # if __name__ == "__main__":
156
- # while True:
157
- # idle_time = get_idle_time()
158
- # print(f"Idle time in seconds: {idle_time}")
159
- # time.sleep(5)
160
142
  'locker': 'loginctl lock-session',
161
- 'must_haves': 'loginctl qdbus'.split(),
162
-
143
+ 'logoff': 'qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout 0 0 0',
144
+ 'must_haves': 'loginctl'.split(),
163
145
  }, 'gnome-x11': {
164
146
 
165
147
  }, 'gnome-wayland': {
@@ -260,6 +242,16 @@ class PwrTray:
260
242
  if shutil.which(must_have) is None:
261
243
  dont_haves.append(must_have)
262
244
  assert not dont_haves, f'commands NOT on $PATH: {dont_haves}'
245
+
246
+ if self.graphical in ('kde-x11', 'kde-wayland'):
247
+ qdbus_cmd = shutil.which('qdbus') or shutil.which('qdbus6')
248
+ assert qdbus_cmd, 'neither qdbus nor qdbus6 found on $PATH'
249
+ qdbus_name = os.path.basename(qdbus_cmd)
250
+ if qdbus_name != 'qdbus':
251
+ for key, val in list(self.variables.items()):
252
+ if isinstance(val, str) and 'qdbus ' in val:
253
+ self.variables[key] = val.replace('qdbus ', f'{qdbus_name} ')
254
+
263
255
  self.has_playerctl = bool(shutil.which('playerctl'))
264
256
 
265
257
 
@@ -271,6 +263,9 @@ class PwrTray:
271
263
  self.tray_icon.activated.connect(self.on_tray_icon_activated)
272
264
  if self.idle_manager:
273
265
  self.idle_manager_start()
266
+ self._resume_proc = self._start_resume_monitor()
267
+ self._resume_buf = b''
268
+
274
269
  self.timer = QTimer()
275
270
  self.timer.setInterval(100) # 100 is initial ... gets recomputed
276
271
  self.timer.timeout.connect(self.on_timeout)
@@ -362,8 +357,13 @@ class PwrTray:
362
357
  def update_running_idle_s(self):
363
358
  """ Update the running idle seconds (called after each regular timeout) """
364
359
  cmd = self.variables['get_idle_ms']
360
+ scale = 1
361
+ if not cmd:
362
+ cmd = self.variables.get('get_idle_s', '')
363
+ scale = 1000
365
364
  if cmd:
366
- xidle_ms = int(subprocess.check_output(cmd.split()).strip())
365
+ xidle = int(subprocess.check_output(cmd.split()).strip())
366
+ xidle_ms = xidle * scale
367
367
  xidle_ms *= 2 if self.quick else 1 # time warp
368
368
  self.running_idle_s = round(xidle_ms/1000, 3)
369
369
 
@@ -499,9 +499,10 @@ class PwrTray:
499
499
  if self.DB():
500
500
  prt('DB', f'on_timeout() {self.loop=}/{self.loop_sample} ...')
501
501
  if not QSystemTrayIcon.isSystemTrayAvailable():
502
- prt('SystemTray is gone ... exiting')
503
- self.exit_wm(None)
502
+ prt('SystemTray is gone ... restarting')
503
+ self.restart_self(None)
504
504
 
505
+ self._check_resume()
505
506
  self.reconfig()
506
507
  if self.idle_manager:
507
508
  self.idle_manager.checkup()
@@ -645,7 +646,11 @@ class PwrTray:
645
646
  self.menu.addAction(item)
646
647
  self.menu_items.append(item)
647
648
 
648
- self.menu = QMenu()
649
+ first_menu = self.menu is None
650
+ if first_menu:
651
+ self.menu = QMenu()
652
+ else:
653
+ self.menu.clear()
649
654
  self.menu_items = []
650
655
 
651
656
  if rows:
@@ -703,8 +708,9 @@ class PwrTray:
703
708
 
704
709
  add_item('↺ Restart this Applet', self.restart_self)
705
710
 
706
- self.tray_icon.setContextMenu(self.menu)
707
-
711
+ if first_menu:
712
+ self.tray_icon.setContextMenu(self.menu)
713
+
708
714
  if not self.tray_icon.isVisible():
709
715
  prt('self.tray_icon.isVisible() is False ... restarting app')
710
716
  time.sleep(0.5)
@@ -770,7 +776,9 @@ class PwrTray:
770
776
  if this:
771
777
  this.tray_icon.hide()
772
778
  PwrTray.save_picks()
773
- subprocess.Popen([sys.executable] + sys.argv)
779
+ project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
780
+ args = [sys.executable, '-m', 'pwr_tray.main'] + sys.argv[1:]
781
+ subprocess.Popen(args, cwd=project_root)
774
782
  os._exit(0)
775
783
 
776
784
  @staticmethod
@@ -795,6 +803,9 @@ class PwrTray:
795
803
  if this.graphical in ('i3', ):
796
804
  PwrTray.run_command('locker')
797
805
  PwrTray.run_command('suspend')
806
+ # systemctl suspend blocks until resume; restart to restore tray icon
807
+ prt('suspend: resumed, restarting applet...')
808
+ PwrTray.restart_self(None)
798
809
 
799
810
  @staticmethod
800
811
  def poweroff(_):
@@ -888,20 +899,39 @@ class PwrTray:
888
899
  this.save_picks()
889
900
  this.idle_manager_start()
890
901
 
891
- # Function to check for ACPI events
892
- @staticmethod
893
- def acpi_event_listener():
894
- acpi_pipe = subprocess.Popen(["acpi_listen"], stdout=subprocess.PIPE)
895
- for line in acpi_pipe.stdout:
896
- this = PwrTray.singleton
897
- if this and b"resume" in line:
898
- prt('acpi event:', line)
899
- # Reset idle timer
900
- this.reset_xidle_ms()
901
- elif this:
902
- prt('UNSELECTED acpi event:', line)
903
- # Reset idle timer
904
- this.reset_xidle_ms()
902
+ def _start_resume_monitor(self):
903
+ """Start dbus-monitor subprocess for resume detection (non-blocking)."""
904
+ try:
905
+ proc = subprocess.Popen(
906
+ ['dbus-monitor', '--system',
907
+ "type='signal',interface='org.freedesktop.login1.Manager',"
908
+ "member='PrepareForSleep'"],
909
+ stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
910
+ os.set_blocking(proc.stdout.fileno(), False)
911
+ prt('resume monitor: started')
912
+ return proc
913
+ except FileNotFoundError:
914
+ prt('WARN: dbus-monitor not found; resume detection disabled')
915
+ return None
916
+
917
+ def _check_resume(self):
918
+ """Poll dbus-monitor for resume signal (called from on_timeout)."""
919
+ if not self._resume_proc:
920
+ return
921
+ try:
922
+ chunk = os.read(self._resume_proc.stdout.fileno(), 4096)
923
+ if chunk:
924
+ self._resume_buf += chunk
925
+ if b'boolean false' in self._resume_buf:
926
+ prt('resume detected, restarting...')
927
+ self.restart_self(None)
928
+ # Prevent unbounded growth; keep tail for partial matches
929
+ if len(self._resume_buf) > 1024:
930
+ self._resume_buf = self._resume_buf[-512:]
931
+ except BlockingIOError:
932
+ pass
933
+ except OSError:
934
+ pass
905
935
  @staticmethod
906
936
  def goodbye(message=''):
907
937
  prt(f'ENDED {message}')
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
4
4
 
5
5
  [project]
6
6
  name = "pwr_tray"
7
- version = "1.0.2"
7
+ version = "1.0.3"
8
8
  description = "A GTK tray applet for power management for i3/sway/KDE"
9
9
  authors = [
10
10
  { name = "Joe Defen", email = "joedef@google.com" }
pwr_tray-1.0.3/runner ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ runner - Development wrapper for app
4
+ Located in the top-level app directory.
5
+ Allows running app from source for debugging with support for command-line arguments.
6
+
7
+ Usage:
8
+ ./runner {options-and-args}
9
+ ./runner --help (show all available options)
10
+ """
11
+
12
+ import runpy
13
+ import sys
14
+
15
+ if __name__ == '__main__':
16
+ # Set program name but preserve all command-line arguments
17
+ sys.argv[0] = 'pwr-tray'
18
+ # Run the dwipe.main module with alter_sys=True to propagate sys.argv
19
+ runpy.run_module('pwr_tray.main', run_name='__main__', alter_sys=True)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes