xpra icon
Bug tracker and wiki

Ticket #476: gtk-menus.patch

File gtk-menus.patch, 5.6 KB (added by Antoine Martin, 4 years ago)

stub for adding gtk menus as a window property we can export

  • xpra/server/source.py

     
    100100        if wid:
    101101            return {"transient-for" : wid}
    102102        return {}
    103     elif propname in ("window-type", "shape"):
     103    elif propname in ("window-type", "shape", "menu"):
    104104        #always send unchanged:
    105105        return {propname : raw()}
    106106    elif propname in ("iconic", "fullscreen", "maximized", "decorations", "above", "below", "shaded", "sticky", "skip-taskbar", "skip-pager", "modal", "focused"):
  • xpra/x11/gtk2/models/base.py

     
    44# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
    55# later version. See the file COPYING for details.
    66
     7import os
    78
    89from xpra.util import WORKSPACE_UNSET, WORKSPACE_ALL
    910from xpra.x11.gtk_x11.prop import prop_set, prop_get
     
    1920geomlog = Logger("x11", "window", "geometry")
    2021
    2122
     23dbus_helper = None
     24MENU_FORWARDING = os.environ.get("XPRA_MENU_FORWARDING", "1")=="1"
     25if MENU_FORWARDING:
     26    try:
     27        from xpra.dbus.helper import DBusHelper
     28        dbus_helper = DBusHelper()
     29    except Exception as e:
     30        log.warn("Warning: menu forwarding is disabled:")
     31        log.warn(" cannot load dbus helper: %s", e)
     32        MENU_FORWARDING = False
     33
     34
    2235X11Window = X11WindowBindings()
    2336
    2437#_NET_WM_STATE:
     
    7184                      "Does this window ever accept keyboard input?", "",
    7285                      True,
    7386                      gobject.PARAM_READWRITE),
    74         #
     87        #from WM_NORMAL_HINTS
    7588        "size-hints": (gobject.TYPE_PYOBJECT,
    7689                       "Client hints on constraining its size", "",
    7790                       gobject.PARAM_READABLE),
     
    88101        "strut": (gobject.TYPE_PYOBJECT,
    89102                  "Struts requested by window, or None", "",
    90103                  gobject.PARAM_READABLE),
     104        #from _GTK_*MENU*
     105        "menu": (gobject.TYPE_PYOBJECT,
     106                  "Application menu, or None", "",
     107                  gobject.PARAM_READABLE),
    91108        #from _NET_WM_DESKTOP
    92109        "workspace": (gobject.TYPE_UINT,
    93110                "The workspace this window is on", "",
     
    151168        })
    152169    _property_names = CoreX11WindowModel._property_names + [
    153170                      "size-hints", "transient-for", "fullscreen-monitors", "bypass-compositor", "group-leader", "window-type", "workspace", "strut",
     171                      "menu",
    154172                      #virtual attributes:
    155173                      "fullscreen", "focused", "maximized", "above", "below", "shaded", "skip-taskbar", "skip-pager", "sticky"]
    156174    _dynamic_property_names = CoreX11WindowModel._dynamic_property_names + [
    157175                              "size-hints", "attention-requested",
     176                              "menu",
    158177                              "fullscreen", "focused", "maximized", "above", "below", "shaded", "skip-taskbar", "skip-pager", "sticky"]
    159178    _internal_property_names = CoreX11WindowModel._internal_property_names+["state"]
    160179    _initial_x11_properties = CoreX11WindowModel._initial_x11_properties + [
     
    166185                              "_NET_WM_STRUT",
    167186                              "_NET_WM_STRUT_PARTIAL",      #redundant as it uses the same function as _NET_WM_STRUT
    168187                              "_NET_WM_WINDOW_OPACITY",
    169                               "WM_HINTS"]
     188                              "WM_HINTS",
     189                              "_GTK_APP_MENU_OBJECT_PATH",
     190                              ]
    170191    _DEFAULT_NET_WM_ALLOWED_ACTIONS = ["_NET_WM_ACTION_%s" % x for x in (
    171192        "CLOSE", "MOVE", "RESIZE", "FULLSCREEN",
    172193        "MINIMIZE", "SHADE", "STICK",
     
    357378            if self._setup_done:
    358379                self._update_client_geometry()
    359380
     381    def _handle_gtk_app_menu_change(self):
     382        #ie: /org/gnome/baobab/menus/appmenu
     383        menu_path = self.prop_get("_GTK_APP_MENU_OBJECT_PATH", "utf8", True)
     384        #ie: /org/gnome/baobab/window/1
     385        window_path = self.prop_get("_GTK_WINDOW_OBJECT_PATH", "utf8", True)
     386        #ie: /org/gnome/baobab
     387        app_path = self.prop_get("_GTK_APPLICATION_OBJECT_PATH", "utf8", True)
     388        #ie: :1.745
     389        bus_name = self.prop_get("_GTK_UNIQUE_BUS_NAME", "utf8", True)
     390        #ie: org.gnome.baobab
     391        app_id = self.prop_get("_GTK_APPLICATION_ID", "utf8", True)
     392        def nomenu():
     393            self._internal_set_property("menu", {})
     394        props = {
     395                "app-menu-path"     : menu_path,
     396                "window-path"       : window_path,
     397                "application-path"  : app_path,
     398                "bus-name"          : bus_name,
     399                "application-id"    : app_id,
     400                }
     401        metalog.info("gtk menu properties: %s", props)
     402        if not MENU_FORWARDING:
     403            nomenu()
     404        #dbus_helper.call_function(bus_name, path, interface, function, args, ok_cb, err_cb)
    360405
     406
    361407    _x11_property_handlers = CoreX11WindowModel._x11_property_handlers.copy()
    362408    _x11_property_handlers.update({
    363409        "WM_TRANSIENT_FOR"              : _handle_transient_for_change,
     
    370416        "_NET_WM_WINDOW_OPACITY"        : _handle_opacity_change,
    371417        "WM_HINTS"                      : _handle_wm_hints_change,
    372418        "WM_NORMAL_HINTS"               : _handle_wm_normal_hints_change,
     419        "_GTK_APP_MENU_OBJECT_PATH"     : _handle_gtk_app_menu_change,
    373420        })
    374421
    375422