Skip to content

Commit

Permalink
#2311 try to synchronize X11 properties that aren't using a known win…
Browse files Browse the repository at this point in the history
…dow-manager prefix

git-svn-id: https://xpra.org/svn/Xpra/trunk@22963 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jun 16, 2019
1 parent 8bb6e2b commit f636a10
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/xpra/client/client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ def metadata_replace(match):
if b"command" in metadata:
self.set_command(metadata.strget("command"))

if b"x11-property" in metadata:
self.set_x11_property(*metadata.listget("x11-property"))


def set_x11_property(self, *x11_property):
pass

def set_command(self, command):
pass
Expand Down
6 changes: 4 additions & 2 deletions src/xpra/client/gtk_base/gtk_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,10 @@ def make_hello(self):
#this is only really supported on X11, but posix is easier to check for..
#"strut" and maybe even "fullscreen-monitors" could also be supported on other platforms I guess
ms += ["shaded", "bypass-compositor", "strut", "fullscreen-monitors"]
if HAS_X11_BINDINGS and XSHAPE:
ms += ["shape"]
if HAS_X11_BINDINGS:
ms += ["x11-property"]
if XSHAPE:
ms += ["shape"]
#figure out if we can handle the "global menu" stuff:
if POSIX and not OSX:
try:
Expand Down
16 changes: 14 additions & 2 deletions src/xpra/client/gtk_base/gtk_client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@
CAN_SET_WORKSPACE = False
HAS_X11_BINDINGS = False
USE_X11_BINDINGS = POSIX and envbool("XPRA_USE_X11_BINDINGS", is_X11())
prop_get, prop_set = None, None
prop_get, prop_set, prop_del = None, None, None
if USE_X11_BINDINGS:
try:
from xpra.gtk_common.error import xlog, verify_sync
from xpra.x11.gtk_x11.prop import prop_get, prop_set
from xpra.x11.gtk_x11.prop import prop_get, prop_set, prop_del
from xpra.x11.bindings.window_bindings import constants, X11WindowBindings, SHAPE_KIND #@UnresolvedImport
from xpra.x11.bindings.core_bindings import X11CoreBindings, set_context_check
from xpra.x11.gtk_x11.send_wm import send_wm_workspace
Expand Down Expand Up @@ -886,6 +886,18 @@ def do_set_command():
self.when_realized("command", do_set_command)


def set_x11_property(self, prop_name, dtype, dformat, value):
metalog("set_x11_property%s", (prop_name, dtype, dformat, value))
gdk_window = self.get_window()
if not dtype and not dformat:
#remove prop
prop_del(gdk_window, prop_name)
return
dtype = bytestostr(dtype)
if dtype=="latin1":
value = bytestostr(value)
prop_set(gdk_window, prop_name, dtype, value)

def set_class_instance(self, wmclass_name, wmclass_class):
if not self.is_realized():
#Warning: window managers may ignore the icons we try to set
Expand Down
7 changes: 7 additions & 0 deletions src/xpra/x11/gtk_x11/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ def prop_set(target, key, etype, value):
X11Window.XChangeProperty(get_xwindow(target), key, dtype, dformat, data)


def prop_type_get(target, key):
try:
return X11Window.GetWindowPropertyType(get_xwindow(target), key)
except XError:
return None


# May return None.
def prop_get(target, key, etype, ignore_errors=False, raise_xerrors=False):
if isinstance(etype, (list, tuple)):
Expand Down
23 changes: 22 additions & 1 deletion src/xpra/x11/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import signal

from xpra.util import envbool
from xpra.os_util import bytestostr
from xpra.x11.common import Unmanageable
from xpra.gtk_common.gobject_util import one_arg_signal
from xpra.gtk_common.gtk_util import (
Expand All @@ -19,7 +20,7 @@
from xpra.x11.bindings.window_bindings import X11WindowBindings, constants, SHAPE_KIND #@UnresolvedImport
from xpra.x11.models.model_stub import WindowModelStub
from xpra.x11.gtk_x11.composite import CompositeHelper
from xpra.x11.gtk_x11.prop import prop_get, prop_set
from xpra.x11.gtk_x11.prop import prop_get, prop_set, prop_type_get, PYTHON_TYPES
from xpra.x11.gtk_x11.send_wm import send_wm_delete_window
from xpra.x11.gtk_x11.gdk_bindings import add_event_receiver, remove_event_receiver
from xpra.gtk_common.gobject_compat import import_gobject, import_glib
Expand Down Expand Up @@ -74,6 +75,9 @@
X11_PROPERTIES_DEBUG = {}
PROPERTIES_DEBUG = [prop_debug.strip()
for prop_debug in os.environ.get("XPRA_WINDOW_PROPERTIES_DEBUG", "").split(",")]
X11PROPERTY_SYNC = envbool("XPRA_X11PROPERTY_SYNC", True)
X11PROPERTY_SYNC_BLACKLIST = os.environ.get("XPRA_X11PROPERTY_SYNC_BLACKLIST",
"_GTK,WM_,_NET,Xdnd").split(",")


def sanestr(s):
Expand Down Expand Up @@ -176,6 +180,7 @@ class CoreX11WindowModel(WindowModelStub):
"xpra-focus-in-event" : one_arg_signal,
"xpra-focus-out-event" : one_arg_signal,
"xpra-motion-event" : one_arg_signal,
"x11-property-changed" : one_arg_signal,
}

#things that we expose:
Expand Down Expand Up @@ -502,6 +507,22 @@ def _handle_property_change(self, name):
metalog.info("%s=%s", name, self.prop_get(name, x11proptype, True, False))
if name in PROPERTIES_IGNORED:
return
if X11PROPERTY_SYNC and not any (name.startswith(x) for x in X11PROPERTY_SYNC_BLACKLIST):
try:
with xsync:
prop_type = prop_type_get(self.client_window, name)
metalog("_handle_property_change(%s) property type=%s", name, prop_type)
if prop_type:
dtype, dformat = prop_type
ptype = PYTHON_TYPES.get(bytestostr(dtype))
if ptype:
value = self.prop_get(name, ptype)
metalog("_handle_property_change(%s) value=%s", name, value)
self.emit("x11-property-changed", (name, ptype, dformat, value))
return
except Exception:
metalog("_handle_property_change(%s)", name, exc_info=True)
self.emit("x11-property-changed", (name, "", 0, ""))
handler = self._x11_property_handlers.get(name)
if handler:
try:
Expand Down
12 changes: 12 additions & 0 deletions src/xpra/x11/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def _add_new_window_common(self, window):
window.managed_connect("ungrab", self._window_ungrab)
window.managed_connect("bell", self._bell_signaled)
window.managed_connect("motion", self._motion_signaled)
window.managed_connect("x11-property-changed", self._x11_property_changed)
if not window.is_tray():
window.managed_connect("raised", self._raised_window)
window.managed_connect("initiate-moveresize", self._initiate_moveresize)
Expand All @@ -571,6 +572,17 @@ def _add_new_window_common(self, window):
#but we don't really care, it will get cleaned up soon enough
return wid


def _x11_property_changed(self, window, event):
#name, dtype, dformat, value = event
metadata = {"x11-property" : event}
wid = self._window_to_id[window]
for ss in self._server_sources.values():
ms = getattr(ss, "metadata_supported", ())
if "x11-property" in ms:
ss.send("window-metadata", wid, metadata)


def _add_new_window(self, window):
self._add_new_window_common(window)
x, y, w, h = window.get_property("geometry")
Expand Down

0 comments on commit f636a10

Please sign in to comment.