示例#1
0
 def activate_menu(self, widget):
     modifiers_mask = get_default_root_window().get_pointer()[-1]
     log("activate_menu(%s) modifiers_mask=%s", widget, modifiers_mask)
     if (modifiers_mask & SHIFT_MASK) ^ OSX:
         self.handle_click(2)
     else:
         self.handle_click(1)
示例#2
0
 def set_icon_from_pixbuf(self, tray_icon):
     if not tray_icon or not self.tray_widget:
         return
     tw, th = self.get_geometry()[2:]
     w = tray_icon.get_width()
     h = tray_icon.get_height()
     log("set_icon_from_pixbuf(%s) geometry=%s, icon size=%s", tray_icon,
         self.get_geometry(), (w, h))
     if tw != w or th != h:
         if tw != th:
             #paste the scaled icon in the middle of the rectangle:
             minsize = min(tw, th)
             new_icon = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, tw,
                                       th)
             new_icon.fill(0)
             scaled_w, scaled_h = minsize, minsize
             if tw == 24 and th == 64:
                 #special case for the gnome-shell dimensions - stretch height..
                 scaled_w, scaled_h = 24, 48
             tray_icon = tray_icon.scale_simple(scaled_w, scaled_h,
                                                INTERP_HYPER)
             tray_icon.copy_area(0, 0, scaled_w, scaled_h, new_icon,
                                 (tw - scaled_w) // 2, (th - scaled_h) // 2)
             tray_icon = new_icon
         else:
             tray_icon = tray_icon.scale_simple(tw, th, INTERP_HYPER)
     self.tray_widget.set_from_pixbuf(tray_icon)
示例#3
0
 def set_icon_from_pixbuf(self, tray_icon):
     if not tray_icon or not self.tray_widget:
         return
     tw, th = self.get_geometry()[2:4]
     if (tw <= 2 or th <= 2) or (tw == 200 and th == 200):
         log("bogus tray icon size: %ix%i", tw, th)
         tw = th = 48
     w = tray_icon.get_width()
     h = tray_icon.get_height()
     log("set_icon_from_pixbuf(%s) geometry=%s, icon size=%s", tray_icon,
         self.get_geometry(), (w, h))
     if tw != w or th != h:
         if tw != th and not PYTHON3:
             #paste the scaled icon in the middle of the rectangle:
             minsize = min(tw, th)
             new_icon = get_pixbuf_from_data(b"\0" * tw * th * 4, True, tw,
                                             th, tw * 4)
             scaled_w, scaled_h = minsize, minsize
             if tw == 24 and th == 64:
                 #special case for the gnome-shell dimensions - stretch height..
                 scaled_w, scaled_h = 24, 48
             tray_icon = tray_icon.scale_simple(scaled_w, scaled_h,
                                                INTERP_HYPER)
             tray_icon.copy_area(0, 0, scaled_w, scaled_h, new_icon,
                                 (tw - scaled_w) // 2, (th - scaled_h) // 2)
             tray_icon = new_icon
         else:
             tray_icon = tray_icon.scale_simple(tw, th, INTERP_HYPER)
     self.tray_widget.set_from_pixbuf(tray_icon)
示例#4
0
 def may_guess(self):
     log("may_guess() GUESS_GEOMETRY=%s, current guess=%s", GUESS_GEOMETRY,
         self.geometry_guess)
     if GUESS_GEOMETRY:
         x, y = get_default_root_window().get_pointer()[-3:-1]
         w, h = self.get_size()
         self.recalculate_geometry(x, y, w, h)
示例#5
0
 def get_geometry(self):
     assert self.tray_widget
     #on X11, if we don't have an xid, don't bother querying its geometry,
     #as this would trigger some ugly GTK warnings we can do nothing about
     if POSIX and os.environ.get(
             "DISPLAY") and self.tray_widget.get_x11_window_id() == 0:
         ag = None
     else:
         ag = self.tray_widget.get_geometry()
         log("GTKStatusIconTray.get_geometry() %s.get_geometry()=%s",
             self.tray_widget, ag)
     if ag is None:
         #probably win32 or OSX, gnome-shell or KDE5..
         self.may_guess()
         log(
             "GTKStatusIconTray.get_geometry() no geometry value available, returning guess: %s",
             self.geometry_guess)
         return self.geometry_guess
     #gtk3 adds an extra argument.. at the beginning!
     _, geom, _ = ag[-3:]
     x, y, w, h = geom.x, geom.y, geom.width, geom.height
     if x == 0 and y == 0 and w == 200 and h == 200:
         #this isn't right, take a better guess, at least for the size:
         w = 24
         h = 64
     return x, y, w, h
示例#6
0
 def popup_menu(self, widget, button, time, *args):
     modifiers_mask = get_default_root_window().get_pointer()[-1]
     log("popup_menu(%s, %s, %s, %s) modifiers_mask=%s", widget, button,
         time, args, modifiers_mask)
     if (modifiers_mask & SHIFT_MASK) ^ OSX:
         self.handle_click(1)
     else:
         self.handle_click(2)
示例#7
0
 def get_geometry(self):
     ag = self.tray_widget.get_geometry()
     log("GTKStatusIconTray.get_geometry() %s.get_geometry()=%s", self.tray_widget, ag)
     if ag is None:
         #probably win32 or OSX...
         self.may_guess()
         log("GTKStatusIconTray.get_geometry() returning guess: %s", self.geometry_guess)
         return self.geometry_guess
     _, geom, _ = ag
     return geom.x, geom.y, geom.width, geom.height
示例#8
0
 def get_geometry(self):
     ag = self.tray_widget.get_geometry()
     log("GTKStatusIconTray.get_geometry() %s.get_geometry()=%s", self.tray_widget, ag)
     if ag is None:
         # probably win32 or OSX...
         self.may_guess()
         log("GTKStatusIconTray.get_geometry() returning guess: %s", self.geometry_guess)
         return self.geometry_guess
     # gtk3 adds an extra argument.. at the beginning!
     _, geom, _ = ag[-3:]
     return geom.x, geom.y, geom.width, geom.height
示例#9
0
 def set_icon_from_pixbuf(self, tray_icon):
     assert self.tray_widget
     if not tray_icon:
         return
     tw, th = self.get_geometry()[2:]
     w = tray_icon.get_width()
     h = tray_icon.get_height()
     log("set_icon_from_pixbuf(%s) geometry=%s, icon size=%s", tray_icon, self.get_geometry(), (w, h))
     if tw != w or th != h:
         tray_icon = tray_icon.scale_simple(tw, th, INTERP_HYPER)
     self.tray_widget.set_from_pixbuf(tray_icon)
示例#10
0
 def set_icon_from_pixbuf(self, tray_icon):
     assert self.tray_widget
     if not tray_icon:
         return
     tw, th = self.get_geometry()[2:]
     w = tray_icon.get_width()
     h = tray_icon.get_height()
     log("set_icon_from_pixbuf(%s) geometry=%s, icon size=%s", tray_icon,
         self.get_geometry(), (w, h))
     if tw != w or th != h:
         tray_icon = tray_icon.scale_simple(tw, th, INTERP_HYPER)
     self.tray_widget.set_from_pixbuf(tray_icon)
示例#11
0
 def get_geometry(self):
     ag = self.tray_widget.get_geometry()
     log("GTKStatusIconTray.get_geometry() %s.get_geometry()=%s",
         self.tray_widget, ag)
     if ag is None:
         #probably win32 or OSX...
         self.may_guess()
         log("GTKStatusIconTray.get_geometry() returning guess: %s",
             self.geometry_guess)
         return self.geometry_guess
     _, geom, _ = ag
     return geom.x, geom.y, geom.width, geom.height
示例#12
0
 def get_geometry(self):
     ag = self.tray_widget.get_geometry()
     log("GTKStatusIconTray.get_geometry() %s.get_geometry()=%s",
         self.tray_widget, ag)
     if ag is None:
         #probably win32 or OSX...
         self.may_guess()
         log("GTKStatusIconTray.get_geometry() returning guess: %s",
             self.geometry_guess)
         return self.geometry_guess
     #gtk3 adds an extra argument.. at the beginning!
     _, geom, _ = ag[-3:]
     return geom.x, geom.y, geom.width, geom.height
示例#13
0
 def get_geometry(self):
     ag = self.tray_widget.get_geometry()
     log("GTKStatusIconTray.get_geometry() %s.get_geometry()=%s", self.tray_widget, ag)
     if ag is None:
         #probably win32 or OSX...
         self.may_guess()
         log("GTKStatusIconTray.get_geometry() returning guess: %s", self.geometry_guess)
         return self.geometry_guess
     #gtk3 adds an extra argument.. at the beginning!
     _, geom, _ = ag[-3:]
     x, y, w, h = geom.x, geom.y, geom.width, geom.height
     if x==0 and y==0 and w==200 and h==200:
         #this isn't right, take a better guess, at least for the size:
         w = 24
         h = 64
     return x, y, w, h
示例#14
0
 def get_geometry(self):
     ag = self.tray_widget.get_geometry()
     log("GTKStatusIconTray.get_geometry() %s.get_geometry()=%s",
         self.tray_widget, ag)
     if ag is None:
         #probably win32 or OSX...
         self.may_guess()
         log("GTKStatusIconTray.get_geometry() returning guess: %s",
             self.geometry_guess)
         return self.geometry_guess
     #gtk3 adds an extra argument.. at the beginning!
     _, geom, _ = ag[-3:]
     x, y, w, h = geom.x, geom.y, geom.width, geom.height
     if x == 0 and y == 0 and w == 200 and h == 200:
         #this isn't right, take a better guess, at least for the size:
         w = 24
         h = 64
     return x, y, w, h
示例#15
0
 def get_geometry(self):
     assert self.tray_widget
     #on X11, if we don't have an xid, don't bother querying its geometry,
     #as this would trigger some ugly GTK warnings we can do nothing about
     if os.name=="posix" and os.environ.get("DISPLAY") and self.tray_widget.get_x11_window_id()==0:
         ag = None
     else:
         ag = self.tray_widget.get_geometry()
         log("GTKStatusIconTray.get_geometry() %s.get_geometry()=%s", self.tray_widget, ag)
     if ag is None:
         #probably win32 or OSX, gnome-shell or KDE5..
         self.may_guess()
         log("GTKStatusIconTray.get_geometry() no geometry value available, returning guess: %s", self.geometry_guess)
         return self.geometry_guess
     #gtk3 adds an extra argument.. at the beginning!
     _, geom, _ = ag[-3:]
     x, y, w, h = geom.x, geom.y, geom.width, geom.height
     if x==0 and y==0 and w==200 and h==200:
         #this isn't right, take a better guess, at least for the size:
         w = 24
         h = 64
     return x, y, w, h
示例#16
0
 def set_icon_from_pixbuf(self, tray_icon):
     if not tray_icon or not self.tray_widget:
         return
     tw, th = self.get_geometry()[2:]
     w = tray_icon.get_width()
     h = tray_icon.get_height()
     log("set_icon_from_pixbuf(%s) geometry=%s, icon size=%s", tray_icon, self.get_geometry(), (w, h))
     if tw!=w or th!=h:
         if tw!=th:
             #paste the scaled icon in the middle of the rectangle:
             minsize = min(tw, th)
             new_icon = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, tw, th)
             new_icon.fill(0)
             scaled_w, scaled_h = minsize, minsize
             if tw==24 and th==64:
                 #special case for the gnome-shell dimensions - stretch height..
                 scaled_w, scaled_h = 24, 48
             tray_icon = tray_icon.scale_simple(scaled_w, scaled_h, INTERP_HYPER)
             tray_icon.copy_area(0, 0, scaled_w, scaled_h, new_icon, (tw-scaled_w)//2, (th-scaled_h)//2)
             tray_icon = new_icon
         else:
             tray_icon = tray_icon.scale_simple(tw, th, INTERP_HYPER)
     self.tray_widget.set_from_pixbuf(tray_icon)
示例#17
0
 def set_icon_from_pixbuf(self, tray_icon):
     if not tray_icon or not self.tray_widget:
         return
     tw, th = self.get_geometry()[2:4]
     if (tw <= 2 or th <= 2) or (tw == 200 and th == 200):
         log("bogus tray icon size: %ix%i", tw, th)
         tw = th = 48
     w = tray_icon.get_width()
     h = tray_icon.get_height()
     log("set_icon_from_pixbuf(%s) geometry=%s, icon size=%s", tray_icon,
         self.get_geometry(), (w, h))
     if tw != w or th != h:
         if tw != th and not PYTHON3:
             #paste the scaled icon in the middle of the rectangle:
             minsize = min(tw, th)
             new_icon = get_pixbuf_from_data(b"\0" * tw * th * 4, True, tw,
                                             th, tw * 4)
             scaled_w, scaled_h = minsize, minsize
             if tw == 24 and th == 64:
                 #special case for the gnome-shell dimensions - stretch height..
                 scaled_w, scaled_h = 24, 48
             tray_icon = tray_icon.scale_simple(scaled_w, scaled_h,
                                                INTERP_HYPER)
             tray_icon.copy_area(0, 0, scaled_w, scaled_h, new_icon,
                                 (tw - scaled_w) // 2, (th - scaled_h) // 2)
             log(
                 "tray icon scaled to %ix%i and pasted into the middle of %ix%i blank icon",
                 scaled_w, scaled_h, tw, th)
             tray_icon = new_icon
         else:
             tray_icon = tray_icon.scale_simple(tw, th, INTERP_HYPER)
             log("tray icon scaled to %ix%i", tw, th)
     if SAVE:
         filename = "./statusicon-%s.png" % time()
         tray_icon.save(filename, "png")
         log.info("statusicon tray saved to %s", filename)
     self.tray_widget.set_from_pixbuf(tray_icon)
     self.icon_timestamp = monotonic_time()
示例#18
0
 def set_icon_from_pixbuf(self, tray_icon):
     if not tray_icon or not self.tray_widget:
         return
     tw, th = self.get_geometry()[2:4]
     if (tw<=2 or th<=2) or (tw==200 and th==200):
         log("bogus tray icon size: %ix%i", tw, th)
         tw = th = 48
     w = tray_icon.get_width()
     h = tray_icon.get_height()
     log("set_icon_from_pixbuf(%s) geometry=%s, icon size=%s", tray_icon, self.get_geometry(), (w, h))
     if tw!=w or th!=h:
         tray_icon = tray_icon.scale_simple(tw, th, GdkPixbuf.InterpType.HYPER)
         log("tray icon scaled to %ix%i", tw, th)
     if SAVE:
         filename = "./statusicon-%s.png" % time()
         tray_icon.savev(filename, "png")
         log.info("statusicon tray saved to %s", filename)
     self.tray_widget.set_from_pixbuf(tray_icon)
     self.icon_timestamp = monotonic()
示例#19
0
from xpra.gtk_common.gobject_compat import import_gtk, import_gdk
gtk = import_gtk()
gdk = import_gdk()

from xpra.client.tray_base import TrayBase, log
from xpra.gtk_common.gtk_util import get_icon_from_file, get_pixbuf_from_data, get_default_root_window, \
    INTERP_HYPER, SHIFT_MASK, ORIENTATION_VERTICAL, ORIENTATION_HORIZONTAL

ORIENTATION = {
    ORIENTATION_HORIZONTAL: "HORIZONTAL",
    ORIENTATION_VERTICAL: "VERTICAL",
}

GUESS_GEOMETRY = WIN32 or OSX
GUESS_GEOMETRY = envbool("XPRA_GUESS_ICON_GEOMETRY", GUESS_GEOMETRY)
log("tray GUESS_GEOMETRY=%s", GUESS_GEOMETRY)


class GTKStatusIconTray(TrayBase):
    def __init__(self, *args, **kwargs):
        TrayBase.__init__(self, *args, **kwargs)
        self.tray_widget = gtk.StatusIcon()
        self.tray_widget.set_tooltip_text(self.tooltip or "Xpra")
        self.tray_widget.connect('activate', self.activate_menu)
        self.tray_widget.connect('popup-menu', self.popup_menu)
        if self.size_changed_cb:
            self.tray_widget.connect('size-changed', self.size_changed_cb)
        if self.default_icon_filename:
            self.set_icon()
        self.tray_widget.set_visible(True)
示例#20
0
 def popup_menu(self, widget, button, time, *args):
     log("popup_menu(%s, %s, %s, %s)", widget, button, time, args)
     self.may_guess()
     self.click_cb(button, 1, 0)
     self.click_cb(button, 0, 0)
示例#21
0
 def activate_menu(self, widget, *args):
     log("activate_menu(%s, %s)", widget, args)
     self.may_guess()
     self.click_cb(1, 1)
     self.click_cb(1, 0)
示例#22
0
from xpra.gtk_common.gobject_compat import import_gtk, import_gdk, is_gtk3
gtk = import_gtk()
gdk = import_gdk()

from xpra.client.tray_base import TrayBase, log
from xpra.gtk_common.gtk_util import get_icon_from_file, get_pixbuf_from_data, INTERP_HYPER

ORIENTATION = {}
if not is_gtk3():
    #where was this moved to??
    ORIENTATION[gtk.ORIENTATION_HORIZONTAL] = "HORIZONTAL"
    ORIENTATION[gtk.ORIENTATION_VERTICAL]   = "VERTICAL"

GUESS_GEOMETRY = sys.platform.startswith("win") or sys.platform.startswith("darwin")
GUESS_GEOMETRY = envbool("XPRA_GUESS_ICON_GEOMETRY", GUESS_GEOMETRY)
log("tray GUESS_GEOMETRY=%s", GUESS_GEOMETRY)


class GTKStatusIconTray(TrayBase):

    def __init__(self, *args, **kwargs):
        TrayBase.__init__(self, *args, **kwargs)
        self.tray_widget = gtk.StatusIcon()
        self.tray_widget.set_tooltip_text(self.tooltip or "Xpra")
        self.tray_widget.connect('activate', self.activate_menu)
        self.tray_widget.connect('popup-menu', self.popup_menu)
        if self.size_changed_cb:
            self.tray_widget.connect('size-changed', self.size_changed_cb)
        filename = self.get_tray_icon_filename(self.default_icon_filename)
        if filename:
            self.set_icon_from_file(filename)
示例#23
0
 def hide(self, *_args):
     log("%s.set_visible(False)", self.tray_widget)
     if self.tray_widget:
         self.tray_widget.set_visible(False)
示例#24
0
 def show(self, *args):
     log("%s.set_visible(True)", self.tray_widget)
     if self.tray_widget:
         self.tray_widget.set_visible(True)
示例#25
0
 def hide(self, *args):
     log("%s.set_visible(False)", self.tray_widget)
     if self.tray_widget:
         self.tray_widget.set_visible(False)
示例#26
0
 def popup_menu(self, widget, button, time, *args):
     log("popup_menu(%s, %s, %s, %s)", widget, button, time, args)
     self.may_guess()
     if self.click_cb:
         self.click_cb(button, 1, time)
         self.click_cb(button, 0, time)
示例#27
0
 def handle_click(self, button, time=0):
     log("handle_click(%i, %i)", button, time)
     self.may_guess()
     if self.click_cb:
         self.click_cb(button, 1, time)
         self.click_cb(button, 0, time)
示例#28
0
 def may_guess(self):
     log("may_guess() GUESS_GEOMETRY=%s, current guess=%s", GUESS_GEOMETRY, self.geometry_guess)
     if GUESS_GEOMETRY:
         x, y = gdk.get_default_root_window().get_pointer()[:2]
         w, h = self.get_size()
         self.recalculate_geometry(x, y, w, h)
示例#29
0
 def show(self, *_args):
     log("%s.set_visible(True)", self.tray_widget)
     if self.tray_widget:
         self.tray_widget.set_visible(True)
示例#30
0
 def activate_menu(self, widget, *args):
     log("activate_menu(%s, %s)", widget, args)
     self.may_guess()
     if self.click_cb:
         self.click_cb(1, 1)
         self.click_cb(1, 0)