Split from #924 which ended up disabling the code.
Some related changes in r12162: different import using AppKit
instead of Foundation
.
As per #924, one can re-enable the power event handler with:
XPRA_OSX_SLEEP_HANDLER=1 Xpra ...
example code found here: http://stackoverflow.com/questions/31091413/
example code found here: https://mail.python.org/pipermail/pythonmac-sig/2011-February/022916.html
Based on the small differences between our code and the two examples above and also seeing the changes in #965, I believe r12268 + r12269 makes our code more likely to handle the power events properly and reliably, hopefully without crashing.. (see commit messages for details).
Tested OK on a mac mini by clicking on "Sleep" in the Apple menu then waiting until the network packets stop coming through to the server, which seems to be the sign that the machine has been put to sleep proper.
So r12271 enables the power event handling code by default again, you can disable it using XPRA_OSX_SLEEP_HANDLER=0
.
Does this work for you? (new osx beta uploaded):
-d osx
, and look like this:
... applicationDidFinishLaunching_(NSConcreteNotification 0x9eb5060 {name = NSApplicationDidFinishLaunchingNotification; object = <NSApplication: 0x4009a0>; userInfo = { NSApplicationLaunchIsDefaultLaunchKey = 1; }}) register_sleep_handlers() ... receiveSleepNotification_(NSConcreteNotification 0x1b4c170 {name = NSWorkspaceWillSleepNotification; object = <NSWorkspace: 0x9eb42c0>}) sleep_callback=<bound method XpraClient.suspend of gtk2.client> cb(sleep_callback)=<bound method XpraClient.suspend of gtk2.client> system is suspending ...
Wishlist level: when we are suspending, we should stop querying the clipboard using the timer (timer_clipboard_check
). Meh.
If there is still a problem with power events (not seen at all or causing crashes), please try both code examples attached to this ticket from a terminal in the GUI session (NOT from ssh, sudo or su,..)
ie:
./Desktop/Xpra.app/Contents/Helpers/Python ./osx_sleepwake_notification.py
Do you get sleep / wake notifications with either of them? Do you get crashes?
Raising: this should be included in 0.17 if we can.
Tested with osx 0.17.0 r12380 client against 0.17.0 r12380 fedora 23 server.
Works like a charm... both when inducing sleep with the apple menu and when just setting the sleep preferences in the system preferences.
One detail that might be worth noting - if the client machine doesn't have the "Wake for network access" box checked then the client connection will timeout after 60 seconds while asleep. Checking the box though, the client seems to suspend indefinitely without timing out (maybe the clipboard querying is an awkward bonus?).
I'll go ahead and take the liberty of closing this one (also confirmed that #965 is still fixed).
#1277 changes this power event delegate code to avoid warnings.
this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/1137