Skip to content

Commit

Permalink
#799: implement window group leader on win32 using SHGetPropertyStore…
Browse files Browse the repository at this point in the history
…ForWindow and System.AppUserModel.ID

git-svn-id: https://xpra.org/svn/Xpra/trunk@8601 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jan 31, 2015
1 parent 7bf91b9 commit a409174
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
26 changes: 25 additions & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,30 @@ def add_gui_exe(script, icon, base_name):
add_exe(script, icon, base_name, base="Win32GUI")
#END OF cx_freeze SECTION
else:
#py2exe recipe for win32com:
# ModuleFinder can't handle runtime changes to __path__, but win32com uses them
try:
# py2exe 0.6.4 introduced a replacement modulefinder.
# This means we have to add package paths there, not to the built-in
# one. If this new modulefinder gets integrated into Python, then
# we might be able to revert this some day.
# if this doesn't work, try import modulefinder
try:
import py2exe.mf as modulefinder
except ImportError:
import modulefinder
import win32com, sys
for p in win32com.__path__[1:]:
modulefinder.AddPackagePath("win32com", p)
for extra in ["win32com.propsys"]: #,"win32com.mapi"
__import__(extra)
m = sys.modules[extra]
for p in m.__path__[1:]:
modulefinder.AddPackagePath(extra, p)
except ImportError:
# no build path setup, no worries.
pass

import py2exe #@UnresolvedImport
assert py2exe is not None
EXCLUDED_DLLS = list(py2exe.build_exe.EXCLUDED_DLLS) + ["nvcuda.dll"]
Expand All @@ -1193,7 +1217,7 @@ def add_gui_exe(script, icon, base_name):
"packages" : packages,
"includes" : external_includes,
"excludes" : excludes,
"dll_excludes" : ["w9xpopen.exe", "tcl85.dll", "tk85.dll"],
"dll_excludes" : ["w9xpopen.exe", "tcl85.dll", "tk85.dll", "propsys.dll"],
}
if not zip_ENABLED:
#the filename is actually ignored because we specify "skip_archive"
Expand Down
6 changes: 0 additions & 6 deletions src/xpra/client/gtk2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# later version. See the file COPYING for details.

import os
import sys
import gobject
try:
#we *have to* do this as early as possible on win32..
Expand Down Expand Up @@ -52,9 +51,6 @@ def __init__(self):
self.local_clipboard_requests = 0
self.remote_clipboard_requests = 0

#avoid ugly "not implemented" warning on win32
self.supports_group_leader = not sys.platform.startswith("win")

self._ref_to_group_leader = {}
self._group_leader_wids = {}

Expand Down Expand Up @@ -353,8 +349,6 @@ def window_ungrab(self):


def get_group_leader(self, metadata, override_redirect):
if not self.supports_group_leader:
return None
wid = metadata.intget("transient-for", -1)
if wid>0:
client_window = self._id_to_window.get(wid)
Expand Down
27 changes: 27 additions & 0 deletions src/xpra/platform/win32/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,39 @@ def get_monitor_workarea_for_window(handle):
return None


def noop(*args):
pass


def add_window_hooks(window):
#win32 cannot use set_group by default:
try:
window.get_window().set_group = noop
except:
pass
#gtk2 to window handle:
try:
handle = window.get_window().handle
except:
return
#windows 7 onwards can use AppUserModel to emulate the group leader stuff:
try:
import win32com.propsys #@UnresolvedImport
from win32com.propsys import propsys #@UnresolvedImport
def set_group(leader):
log("win32 hooks: set_group(%s)", leader)
try:
ps = propsys.SHGetPropertyStoreForWindow(handle)
key = propsys.PSGetPropertyKeyFromName("System.AppUserModel.ID")
value = propsys.PROPVARIANTType(leader.handle)
log("win32 hooks: calling %s(%s, %s)", ps.SetValue, key, value)
ps.SetValue(key, value)
except Exception as e:
log.error("failed to set group leader: %s", e)
window.get_window().set_group = set_group
log("hooked group leader override using %s", win32com.propsys)
except Exception as e:
log("unable to implement group leader: %s", e, exc_info=True)
#OR windows never have any decorations or taskbar menu
if not window._override_redirect:
#override set_decorated so we can preserve the taskbar menu for undecorated windows
Expand Down

0 comments on commit a409174

Please sign in to comment.