Skip to content

Commit

Permalink
#2539 show xpra's global tray menu if we're running in gnome-shell (s…
Browse files Browse the repository at this point in the history
…ince it usually does not have any usable system tray there...)

git-svn-id: https://xpra.org/svn/Xpra/trunk@26332 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed May 12, 2020
1 parent 0ca3548 commit ae8ff8b
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/xpra/client/gtk3/gtk3_client_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from xpra.client.gtk3.window_menu import WindowMenuHelper
from xpra.gtk_common.gtk_util import WINDOW_NAME_TO_HINT
from xpra.util import envbool
from xpra.os_util import bytestostr
from xpra.os_util import bytestostr, is_gnome
from xpra.log import Logger

log = Logger("gtk", "window")
Expand All @@ -34,8 +34,9 @@
Gdk.WindowTypeHint.DND)


WINDOW_MENU = envbool("XPRA_WINDOW_MENU", True)
WINDOW_ICON = envbool("XPRA_WINDOW_ICON", True)
WINDOW_XPRA_MENU = envbool("XPRA_WINDOW_XPRA_MENU", is_gnome())
WINDOW_MENU = envbool("XPRA_WINDOW_MENU", True)


"""
Expand All @@ -51,24 +52,25 @@ def init_window(self, metadata):
if (WINDOW_MENU or WINDOW_ICON) and self.get_decorated() and not self.is_OR():
self.add_header_bar()

def _resize_pixbuf(self, pixbuf):
tb = self.get_titlebar()
try:
h = tb.get_preferred_size()[-1]-8
except Exception:
h = 32
h = min(128, max(h, 24))
return pixbuf.scale_simple(h, h, GdkPixbuf.InterpType.HYPER)

def set_icon(self, pixbuf):
super().set_icon(pixbuf)
if WINDOW_ICON:
tb = self.get_titlebar()
try:
h = tb.get_preferred_size()[-1]-8
except Exception:
h = 32
h = min(128, max(h, 24))
icon = pixbuf.scale_simple(h, h, GdkPixbuf.InterpType.HYPER)
self.header_bar_image.set_from_pixbuf(icon)
self.header_bar_image.set_from_pixbuf(self._resize_pixbuf(pixbuf))

def add_header_bar(self):
self.menu_helper = WindowMenuHelper(self._client, self)
hb = Gtk.HeaderBar()
hb.set_show_close_button(True)
hb.props.title = self.get_title()
button = Gtk.Button()
if WINDOW_ICON:
self.header_bar_image = Gtk.Image()
pixbuf = self._client.get_pixbuf("transparent.png")
Expand All @@ -77,11 +79,27 @@ def add_header_bar(self):
if WINDOW_MENU:
icon = Gio.ThemedIcon(name="open-menu-symbolic")
image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
button = Gtk.Button()
button.add(image)
button.connect("clicked", self.show_window_menu)
hb.pack_end(button)
if WINDOW_XPRA_MENU:
image = Gtk.Image()
pixbuf = self._client.get_pixbuf("xpra.png")
image.set_from_pixbuf(self._resize_pixbuf(pixbuf))
button = Gtk.Button()
button.add(image)
button.connect("clicked", self.show_xpra_menu)
hb.pack_end(button)
self.set_titlebar(hb)

def show_xpra_menu(self, *args):
mh = getattr(self._client, "menu_helper", None)
if not mh:
from xpra.client.gtk3.tray_menu import GTK3TrayMenu
mh = GTK3TrayMenu(self._client)
mh.popup(0, 0)

def show_window_menu(self, *args):
self.menu_helper.build()
self.menu_helper.popup(0, 0)
Expand Down

0 comments on commit ae8ff8b

Please sign in to comment.