Skip to content

Commit

Permalink
#826: allow more hooks to be disabled using env vars
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@9136 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 23, 2015
1 parent 4de05f8 commit 0a2fb84
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 44 deletions.
78 changes: 40 additions & 38 deletions src/xpra/platform/win32/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
GROUP_LEADER = WINDOW_HOOKS and os.environ.get("XPRA_WIN32_GROUP_LEADER", "1")=="1"
UNDECORATED_STYLE = WINDOW_HOOKS and os.environ.get("XPRA_WIN32_UNDECORATED_STYLE", "1")=="1"
MAX_SIZE_HINT = WINDOW_HOOKS and os.environ.get("XPRA_WIN32_MAX_SIZE_HINT", "1")=="1"
GEOMETRY = WINDOW_HOOKS and os.environ.get("XPRA_WIN32_GEOMETRY", "1")=="1"


KNOWN_EVENTS = {}
Expand Down Expand Up @@ -215,44 +216,45 @@ def activate_cb(*args):
win32hooks.max_size = None
win32hooks.setup()

#save original geometry function:
window.__apply_geometry_hints = window.apply_geometry_hints
#our function for taking gdk window hints and passing them to the win32 hooks class:
def apply_maxsize_hints(hints):
workw, workh = 0, 0
if not window.get_decorated():
workarea = get_monitor_workarea_for_window(handle)
log("using workarea as window size limit for undecorated window: %s", workarea)
if workarea:
workw, workh = workarea[2:4]
maxw = hints.get("max_width", 0)
maxh = hints.get("max_height", 0)
if workw>0 and workh>0:
#clamp to workspace for undecorated windows:
if maxw>0 and maxh>0:
maxw = min(workw, maxw)
maxh = min(workh, maxh)
else:
maxw, maxh = workw, workh
log("apply_maxsize_hints(%s) for window %s, found max: %sx%s", hints, window, maxw, maxh)
if (maxw>0 and maxw<32767) or (maxh>0 and maxh<32767):
window.win32hooks.max_size = (maxw or 32000), (maxh or 32000)
elif window.win32hooks.max_size:
#was set, clear it
window.win32hooks.max_size = None
#remove them so GTK doesn't try to set attributes,
#which would remove the maximize button:
for x in ("max_width", "max_height"):
if x in hints:
del hints[x]
#our monkey patching method, which calls the function above:
def apply_geometry_hints(hints):
apply_maxsize_hints(hints)
return window.__apply_geometry_hints(hints)
window.apply_geometry_hints = apply_geometry_hints
#apply current geometry hints, if any:
if window.geometry_hints:
apply_maxsize_hints(window.geometry_hints)
if GEOMETRY:
#save original geometry function:
window.__apply_geometry_hints = window.apply_geometry_hints
#our function for taking gdk window hints and passing them to the win32 hooks class:
def apply_maxsize_hints(hints):
workw, workh = 0, 0
if not window.get_decorated():
workarea = get_monitor_workarea_for_window(handle)
log("using workarea as window size limit for undecorated window: %s", workarea)
if workarea:
workw, workh = workarea[2:4]
maxw = hints.get("max_width", 0)
maxh = hints.get("max_height", 0)
if workw>0 and workh>0:
#clamp to workspace for undecorated windows:
if maxw>0 and maxh>0:
maxw = min(workw, maxw)
maxh = min(workh, maxh)
else:
maxw, maxh = workw, workh
log("apply_maxsize_hints(%s) for window %s, found max: %sx%s", hints, window, maxw, maxh)
if (maxw>0 and maxw<32767) or (maxh>0 and maxh<32767):
window.win32hooks.max_size = (maxw or 32000), (maxh or 32000)
elif window.win32hooks.max_size:
#was set, clear it
window.win32hooks.max_size = None
#remove them so GTK doesn't try to set attributes,
#which would remove the maximize button:
for x in ("max_width", "max_height"):
if x in hints:
del hints[x]
#our monkey patching method, which calls the function above:
def apply_geometry_hints(hints):
apply_maxsize_hints(hints)
return window.__apply_geometry_hints(hints)
window.apply_geometry_hints = apply_geometry_hints
#apply current geometry hints, if any:
if window.geometry_hints:
apply_maxsize_hints(window.geometry_hints)

def remove_window_hooks(window):
try:
Expand Down
18 changes: 12 additions & 6 deletions src/xpra/platform/win32/window_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ class MINMAXINFO(ctypes.Structure):
#only hardcoded for handling WM_GETMINMAXINFO,
#but should be pretty easy to tweak if needed.


import os
MINMAXINFO = os.environ.get("XPRA_WIN32_MINMAXINFO", "1")=="1"


class Win32Hooks(object):

def __init__(self, hwnd):
self._hwnd = hwnd
self._message_map = {
win32con.WM_GETMINMAXINFO : self.on_getminmaxinfo,
}
self._message_map = {}
if MINMAXINFO:
self._message_map[win32con.WM_GETMINMAXINFO] = self.on_getminmaxinfo
self.max_size = None
try:
#we only use this code for resizable windows, so use SM_C?SIZEFRAME:
Expand All @@ -50,6 +55,7 @@ def __init__(self, hwnd):
self.frame_height = 4
self.caption_height = 26
log("Win32Hooks: window frame size is %sx%s", self.frame_width, self.frame_height)
log("Win32Hooks: message_map=%s", self._message_map)
self._oldwndproc = None

def setup(self):
Expand Down Expand Up @@ -89,11 +95,11 @@ def cleanup(self, *args):

def _wndproc(self, hwnd, msg, wparam, lparam):
event_name = WNDPROC_EVENT_NAMES.get(msg, msg)
vlog("_wndproc%s event name=%s", (hwnd, msg, wparam, lparam), event_name)
v = win32gui.CallWindowProc(self._oldwndproc, hwnd, msg, wparam, lparam)
callback = self._message_map.get(msg)
vlog("_wndproc%s return value=%s, callback=%s", (hwnd, msg, wparam, lparam), v, callback)
vlog("_wndproc%s event name=%s, callback=%s", (hwnd, msg, wparam, lparam), event_name, callback)
if callback:
#run our callback
callback(hwnd, msg, wparam, lparam)
v = win32gui.CallWindowProc(self._oldwndproc, hwnd, msg, wparam, lparam)
vlog("_wndproc%s return value=%s", (hwnd, msg, wparam, lparam), v)
return v

0 comments on commit 0a2fb84

Please sign in to comment.