Skip to content

Commit

Permalink
ensure we clamp the workspace within the bounds 0 .. _NET_NUMBER_OF_D…
Browse files Browse the repository at this point in the history
…ESKTOPS-1,

and refactor the x property stuff into a utility method

git-svn-id: https://xpra.org/svn/Xpra/trunk@2107 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Nov 12, 2012
1 parent 8ba06c0 commit a10fa34
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/xpra/client_window.py
Expand Up @@ -138,6 +138,22 @@ def queue_draw(gtkwindow, x, y, width, height):
except ImportError, e:
has_wimpiggy_prop = False

def xget_u32_property(target, name):
try:
if not has_wimpiggy_prop:
prop = target.property_get(name)
if not prop or len(prop)!=3 or len(prop[2])!=1:
return None
log("xget_u32_property(%s, %s)=%s", target, name, prop[2][0])
return prop[2][0]
v = prop_get(target, name, "u32", ignore_errors=True)
log("xget_u32_property(%s, %s)=%s", target, name, v)
if type(v)==int:
return v
except Exception, e:
log.error("xget_u32_property error on %s / %s: %s", target, name, e)
return None

CAN_SET_WORKSPACE = False
if not sys.platform.startswith("win") and has_wimpiggy_prop:
try:
Expand Down Expand Up @@ -209,6 +225,11 @@ def set_workspace(self):
from wimpiggy.lowlevel import sendClientMessage, const #@UnresolvedImport
from wimpiggy.error import trap
root = self.get_window().get_screen().get_root_window()
ndesktops = xget_u32_property(root, "_NET_NUMBER_OF_DESKTOPS")
log("set_workspace() ndesktops=%s", ndesktops)
if ndesktops is None or ndesktops<=1:
return
workspace = max(0, min(ndesktops-1, workspace))
event_mask = const["SubstructureNotifyMask"] | const["SubstructureRedirectMask"]
trap.call(sendClientMessage, root, self.get_window(), False, event_mask, "_NET_WM_DESKTOP",
workspace, const["CurrentTime"],
Expand All @@ -225,22 +246,14 @@ def is_tray(self):
def get_workspace(self):
if sys.platform.startswith("win"):
return -1 #windows does not have workspaces
try:
if not has_wimpiggy_prop:
prop = self.window.get_screen().get_root_window().property_get("_NET_CURRENT_DESKTOP")
if not prop or len(prop)!=3 or len(prop[2])!=1:
return -1
log("get_workspace()=%s", prop[2][0])
return prop[2][0]
v = prop_get(self.get_window(), "_NET_WM_DESKTOP", "u32", ignore_errors=True)
log("get_workspace()=%s", v)
if type(v)==int:
return v
except Exception, e:
log.error("failed to detect workspace: %s", e)
window = self.get_window()
root = window.get_screen().get_root_window()
for target, prop in ((window, "_NET_WM_DESKTOP"), (root, "_NET_CURRENT_DESKTOP")):
value = xget_u32_property(target, prop)
if value is not None:
return value
return -1


def new_backing(self, w, h):
from xpra.window_backing import new_backing
self._backing = new_backing(self._id, w, h, self._backing, self._client.supports_mmap, self._client.mmap)
Expand Down

0 comments on commit a10fa34

Please sign in to comment.