Skip to content

Commit

Permalink
#965: add dock event listener and restore the minimized windows when …
Browse files Browse the repository at this point in the history
…it is clicked

git-svn-id: https://xpra.org/svn/Xpra/trunk@12162 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Mar 18, 2016
1 parent 2832d93 commit 3453e59
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/xpra/platform/darwin/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def cb(menu_item):

def add_window_hooks(window):
window.connect("focus-in-event", window_focused)
client = getattr(window, "_client", None)
if client:
init_dock_listener(client)

def remove_window_hooks(window):
try:
Expand Down Expand Up @@ -290,16 +293,19 @@ def take_screenshot():


try:
import Foundation #@UnresolvedImport
import AppKit #@UnresolvedImport
import PyObjCTools.AppHelper as AppHelper #@UnresolvedImport
NSObject = Foundation.NSObject
NSWorkspace = AppKit.NSWorkspace
from AppKit import NSObject, NSApplication, NSWorkspace #@UnresolvedImport
except Exception as e:
log.warn("failed to load critical modules for sleep notification support: %s", e)
log.warn("Warning: failed to load critical modules")
log.warn(" %s", e)
log.warn(" cannot enable sleep notification support")
log.warn(" and dock click notification")
NSObject = object
NSApplication = None
NSWorkspace = None


class NotificationHandler(NSObject):
"""Class that handles the sleep notifications."""

Expand All @@ -320,6 +326,31 @@ def handleWakeNotification_(self, aNotification):
log.error("Error in wake callback %s", self.wake_callback, exc_info=True)


dock_listener = None
def init_dock_listener(client):
global dock_listener
if dock_listener:
return
try:
import objc #@UnresolvedImport
shared_app = NSApplication.sharedApplication()

class Delegate(NSObject):
@objc.signature('B@:#B')
def applicationShouldHandleReopen_hasVisibleWindows_(self, ns_app, flag):
log("applicationShouldHandleReopen_hasVisibleWindows%s", (ns_app, flag))
client.deiconify_windows()
return True

delegate = Delegate.alloc().init()
delegate.retain()
shared_app.setDelegate_(delegate)
dock_listener = delegate
except:
log.error("Error setting up dock listener", exc_info=True)
dock_listener = False


class ClientExtras(object):
def __init__(self, client, opts):
swap_keys = opts and opts.swap_keys
Expand Down

0 comments on commit 3453e59

Please sign in to comment.