Skip to content

Commit

Permalink
#924:
Browse files Browse the repository at this point in the history
* make it possible to disable the power event handler via env var
* make it possible to run the power event handler as a standalone utility

git-svn-id: https://xpra.org/svn/Xpra/trunk@11122 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Nov 3, 2015
1 parent c9f9e0e commit 886e0f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
8 changes: 8 additions & 0 deletions osx/Helpers/PowerMonitor
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

#call the "Python" wrapper:
exe_name=$(basename $0)
full_path=$(cd "$(dirname "$0")"; pwd -P)
PYTHON="$full_path/PythonExecWrapper"

exec "$PYTHON" "$exe_name" -c "import sys;sys.argv[0]=\"$full_path/$exe_name\";from xpra.platform.darwin.gui import main;main()" "$@"
44 changes: 29 additions & 15 deletions src/xpra/platform/darwin/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import os
from xpra.log import Logger
log = Logger("osx", "events")

SLEEP_HANDLER = os.environ.get("XPRA_OSX_SLEEP_HANDLER", "1")=="1"


exit_cb = None
def quit_handler(*args):
Expand Down Expand Up @@ -297,15 +300,15 @@ class NotificationHandler(NSObject):
"""Class that handles the sleep notifications."""

def handleSleepNotification_(self, aNotification):
log("handleSleepNotification(%s)", aNotification)
log("handleSleepNotification(%s) sleep_callback=%s", aNotification, self.sleep_callback)
if self.sleep_callback:
try:
self.sleep_callback()
except:
log.error("Error in sleep callback %s", self.sleep_callback, exc_info=True)

def handleWakeNotification_(self, aNotification):
log("handleWakeNotification(%s)", aNotification)
log("handleWakeNotification(%s) wake_callback=%s", aNotification, self.wake_callback)
if self.wake_callback:
try:
self.wake_callback()
Expand All @@ -314,12 +317,14 @@ def handleWakeNotification_(self, aNotification):


class ClientExtras(object):
def __init__(self, client, opts, blocking=False):
def __init__(self, client, opts):
swap_keys = opts and opts.swap_keys
log("ClientExtras.__init__(%s, %s, %s) swap_keys=%s", client, opts, blocking, swap_keys)
log("ClientExtras.__init__(%s, %s) swap_keys=%s", client, opts, swap_keys)
self.client = client
self.blocking = blocking
self.setup_event_loop()
self.notificationCenter = None
self.handler = None
if SLEEP_HANDLER:
self.setup_event_loop()
if opts and client:
log("setting swap_keys=%s using %s", swap_keys, client.keyboard_helper)
if client.keyboard_helper and client.keyboard_helper.keyboard:
Expand All @@ -333,8 +338,6 @@ def cleanup(self):
def stop_event_loop(self):
if self.notificationCenter:
self.notificationCenter = None
if self.blocking:
AppHelper.stopEventLoop()
if self.handler:
self.handler = None

Expand All @@ -347,27 +350,38 @@ def setup_event_loop(self):
ws = NSWorkspace.sharedWorkspace()
self.notificationCenter = ws.notificationCenter()
self.handler = NotificationHandler.new()
self.handler.sleep_callback = self.client.suspend
self.handler.wake_callback = self.client.resume
if self.client:
self.handler.sleep_callback = self.client.suspend
self.handler.wake_callback = self.client.resume
else:
self.handler.sleep_callback = None
self.handler.wake_callback = None
self.notificationCenter.addObserver_selector_name_object_(
self.handler, "handleSleepNotification:",
AppKit.NSWorkspaceWillSleepNotification, None)
self.notificationCenter.addObserver_selector_name_object_(
self.handler, "handleWakeNotification:",
AppKit.NSWorkspaceDidWakeNotification, None)
log("starting console event loop with notifcation center=%s and handler=%s", self.notificationCenter, self.handler)
if self.blocking:
#this is for running standalone
AppHelper.runConsoleEventLoop(installInterrupt=self.blocking)
#when not blocking, we rely on another part of the code


def run(self):
#this is for running standalone
AppHelper.runConsoleEventLoop(installInterrupt=True)
#when running from the GTK main loop, we rely on another part of the code
#to run the event loop for us

def stop(self):
AppHelper.stopEventLoop()


def main():
from xpra.platform import init, clean
try:
init("OSX Extras")
ClientExtras(None, None, True)
log.enable_debug()
ce = ClientExtras(None, None)
ce.run()
finally:
clean()

Expand Down

0 comments on commit 886e0f1

Please sign in to comment.