Skip to content

Commit

Permalink
#2023: allow applications to tell us about their window content-type …
Browse files Browse the repository at this point in the history
…using the _XPRA_CONTENT_TYPE window property

git-svn-id: https://xpra.org/svn/Xpra/trunk@20908 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Nov 2, 2018
1 parent 25ca5d2 commit 3c5899d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
38 changes: 38 additions & 0 deletions src/tests/xpra/test_apps/test_window_content_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python

from xpra.gtk_common.gobject_compat import import_gtk
from xpra.gtk_common.gtk_util import WINDOW_TOPLEVEL

from xpra.x11.gtk_x11.gdk_display_source import init_gdk_display_source
init_gdk_display_source()

gtk = import_gtk()


def change_callback(self, window, entry):
print("content_type=%s" % entry.get_text())
if window.get_window():
from xpra.x11.gtk_x11.prop import prop_set
prop_set(window.get_window(), "_XPRA_CONTENT_TYPE", "latin1", entry.get_text().decode())

def main():
window = gtk.Window(WINDOW_TOPLEVEL)
window.set_size_request(400, 100)
window.connect("delete_event", gtk.main_quit)
entry = gtk.Entry()
entry.set_max_length(50)
entry.connect("changed", change_callback, window, entry)
content_type = "text"
import sys
if len(sys.argv)>1:
content_type = sys.argv[1]
entry.set_text(content_type)
entry.show()
window.add(entry)
window.show_all()
gtk.main()
return 0

if __name__ == "__main__":
main()

8 changes: 4 additions & 4 deletions src/xpra/server/window/window_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __init__(self,
self.content_type = ""
self.window_signal_handlers = []
#watch for changes to properties that are used to derive the content-type:
for x in get_content_type_properties():
for x in ["content-type"] + list(get_content_type_properties()):
if x in window.get_dynamic_property_names():
sid = window.connect("notify::%s" % x, self.content_type_changed)
self.window_signal_handlers.append(sid)
Expand Down Expand Up @@ -574,10 +574,10 @@ def _iconic_changed(self, _window, *_args):
else:
self.no_idle()

def content_type_changed(self, window, *_args):
def content_type_changed(self, window, *args):
self.content_type = window.get("content-type") or guess_content_type(window)
log("class-changed(%s, %s) content-type=%s", window, _args, self.content_type)

log("content_type_changed(%s, %s) content-type=%s", window, args, self.content_type)
return True

def set_client_properties(self, properties):
#filter out stuff we don't care about
Expand Down
14 changes: 12 additions & 2 deletions src/xpra/x11/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class BaseWindowModel(CoreX11WindowModel):
"menu": (gobject.TYPE_PYOBJECT,
"Application menu, or None", "",
PARAM_READABLE),
#for our own use:
"content-type": (gobject.TYPE_PYOBJECT,
"What type of content is shown in this window", "",
PARAM_READABLE),
#from _NET_WM_DESKTOP
"workspace": (gobject.TYPE_UINT,
"The workspace this window is on", "",
Expand Down Expand Up @@ -184,11 +188,11 @@ class BaseWindowModel(CoreX11WindowModel):
})
_property_names = CoreX11WindowModel._property_names + [
"transient-for", "fullscreen-monitors", "bypass-compositor", "group-leader", "window-type", "workspace", "strut", "opacity",
"menu",
"menu", "content-type",
#virtual attributes:
"fullscreen", "focused", "maximized", "above", "below", "shaded", "skip-taskbar", "skip-pager", "sticky"]
_dynamic_property_names = CoreX11WindowModel._dynamic_property_names + [
"attention-requested",
"attention-requested", "content-type",
"menu", "workspace", "opacity",
"fullscreen", "focused", "maximized", "above", "below", "shaded", "skip-taskbar", "skip-pager", "sticky"]
_internal_property_names = CoreX11WindowModel._internal_property_names+["state"]
Expand Down Expand Up @@ -484,6 +488,11 @@ def activate_menu(self, action_type, action, state, pdata):
actions_iface.Activate(action, state, pdata)


def _handle_xpra_content_type_change(self):
content_type = self.prop_get("_XPRA_CONTENT_TYPE", "latin1", True) or ""
metalog("content_type=%s", content_type)
self._updateprop("content-type", content_type)

_x11_property_handlers = CoreX11WindowModel._x11_property_handlers.copy()
_x11_property_handlers.update({
"WM_TRANSIENT_FOR" : _handle_transient_for_change,
Expand All @@ -500,6 +509,7 @@ def activate_menu(self, action_type, action, state, pdata):
"_GTK_APPLICATION_OBJECT_PATH" : _handle_gtk_app_menu_change,
"_GTK_APP_MENU_OBJECT_PATH" : _handle_gtk_app_menu_change,
"_GTK_WINDOW_OBJECT_PATH" : _handle_gtk_app_menu_change,
"_XPRA_CONTENT_TYPE" : _handle_xpra_content_type_change,
})


Expand Down

0 comments on commit 3c5899d

Please sign in to comment.