Beispiel #1
0
 def get_default_window_icon(self, size=48):
     #return the icon which would be used from the wmclass
     c_i = self.get_property("class-instance")
     iconlog("get_default_window_icon(%i) class-instance=%s", size, c_i)
     if not c_i or len(c_i) != 2:
         return None
     wmclass_name = c_i[0]
     if not wmclass_name:
         return None
     it = icon_theme_get_default()
     pixbuf = None
     iconlog("get_default_window_icon(%i) icon theme=%s, wmclass_name=%s",
             size, it, wmclass_name)
     for icon_name in (
             "%s-color" % wmclass_name,
             wmclass_name,
             "%s_%ix%i" % (wmclass_name, size, size),
             "application-x-%s" % wmclass_name,
             "%s-symbolic" % wmclass_name,
             "%s.symbolic" % wmclass_name,
     ):
         i = it.lookup_icon(icon_name, size, 0)
         iconlog("lookup_icon(%s)=%s", icon_name, i)
         if not i:
             continue
         try:
             pixbuf = i.load_icon()
             iconlog("load_icon()=%s", pixbuf)
             if pixbuf:
                 w, h = pixbuf.props.width, pixbuf.props.height
                 iconlog("using '%s' pixbuf %ix%i", icon_name, w, h)
                 return w, h, "RGBA", pixbuf.get_pixels()
         except Exception:
             iconlog("%s.load_icon()", i, exc_info=True)
     return None
Beispiel #2
0
 def make_hello(self):
     capabilities = UIXpraClient.make_hello(self)
     capabilities["named_cursors"] = len(cursor_types) > 0
     capabilities.update(get_gtk_version_info())
     #tell the server which icons GTK can use
     #so it knows when it should supply one as fallback
     it = icon_theme_get_default()
     #this would add our bundled icon directory
     #to the search path, but I don't think we have
     #any extra icons that matter in there:
     #from xpra.platform.paths import get_icon_dir
     #d = get_icon_dir()
     #if d not in it.get_search_path():
     #    it.append_search_path(d)
     #    it.rescan_if_needed()
     log("default icon theme: %s", it)
     log("icon search path: %s", it.get_search_path())
     log("contexts: %s", it.list_contexts())
     icons = []
     for context in it.list_contexts():
         icons += it.list_icons(context)
     log("icons: %s", icons)
     capabilities["theme.default.icons"] = list(set(icons))
     if METADATA_SUPPORTED:
         ms = [x.strip() for x in METADATA_SUPPORTED.split(",")]
     else:
         #this is currently unused, and slightly redundant because of metadata.supported below:
         capabilities["window.states"] = [
             "fullscreen", "maximized", "sticky", "above", "below",
             "shaded", "iconified", "skip-taskbar", "skip-pager"
         ]
         ms = list(DEFAULT_METADATA_SUPPORTED)
         #added in 0.15:
         ms += ["command", "workspace", "above", "below", "sticky"]
     if os.name == "posix":
         #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"
         ]
     log("metadata.supported: %s", ms)
     capabilities["metadata.supported"] = ms
     #we need the bindings to support initiate-moveresize (posix only for now):
     from xpra.client.gtk_base.gtk_client_window_base import HAS_X11_BINDINGS
     capabilities["window.initiate-moveresize"] = HAS_X11_BINDINGS
     #window icon bits
     capabilities[
         "encoding.icons.greedy"] = True  #we don't set a default window icon any more
     capabilities["encoding.icons.size"] = 64, 64  #size we want
     capabilities["encoding.icons.max_size"] = 128, 128  #limit
     from xpra.client.window_backing_base import DELTA_BUCKETS
     capabilities["encoding.delta_buckets"] = DELTA_BUCKETS
     return capabilities
Beispiel #3
0
 def make_hello(self):
     capabilities = UIXpraClient.make_hello(self)
     capabilities["named_cursors"] = len(cursor_types)>0
     capabilities.update(get_gtk_version_info())
     #tell the server which icons GTK can use
     #so it knows when it should supply one as fallback
     it = icon_theme_get_default()
     #this would add our bundled icon directory
     #to the search path, but I don't think we have
     #any extra icons that matter in there:
     #from xpra.platform.paths import get_icon_dir
     #d = get_icon_dir()
     #if d not in it.get_search_path():
     #    it.append_search_path(d)
     #    it.rescan_if_needed()
     log("default icon theme: %s", it)
     log("icon search path: %s", it.get_search_path())
     log("contexts: %s", it.list_contexts())
     icons = []
     for context in it.list_contexts():
         icons += it.list_icons(context)
     log("icons: %s", icons)
     capabilities["theme.default.icons"] = list(set(icons))
     if METADATA_SUPPORTED:
         ms = [x.strip() for x in METADATA_SUPPORTED.split(",")]
     else:
         #this is currently unused, and slightly redundant because of metadata.supported below:
         capabilities["window.states"] = ["fullscreen", "maximized", "sticky", "above", "below", "shaded", "iconified", "skip-taskbar", "skip-pager"]
         ms = list(DEFAULT_METADATA_SUPPORTED)
         #added in 0.15:
         ms += ["command", "workspace", "above", "below", "sticky"]
     if os.name=="posix":
         #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"]
     log("metadata.supported: %s", ms)
     capabilities["metadata.supported"] = ms
     #we need the bindings to support initiate-moveresize (posix only for now):
     from xpra.client.gtk_base.gtk_client_window_base import HAS_X11_BINDINGS
     capabilities["window.initiate-moveresize"] = HAS_X11_BINDINGS
     #window icon bits
     capabilities["encoding.icons.greedy"] = True            #we don't set a default window icon any more
     capabilities["encoding.icons.size"] = 64, 64            #size we want
     capabilities["encoding.icons.max_size"] = 128, 128      #limit
     from xpra.client.window_backing_base import DELTA_BUCKETS
     capabilities["encoding.delta_buckets"] = DELTA_BUCKETS
     return capabilities
Beispiel #4
0
 def get_notification_icon(self, icon_string):
     #the string may be:
     # * a path which we will load using pillow
     # * a name we lookup in the current them
     if not icon_string:
         return ()
     img = None
     from PIL import Image
     if os.path.isabs(icon_string):
         if os.path.exists(icon_string) and os.path.isfile(icon_string):
             img = Image.open(icon_string)
             w, h = img.size
     else:
         #try to find it in the theme:
         theme = icon_theme_get_default()
         if theme:
             try:
                 icon = theme.load_icon(icon_string, gtk.ICON_SIZE_BUTTON,
                                        0)
             except Exception as e:
                 notifylog(
                     "failed to load icon '%s' from default theme: %s",
                     icon_string, e)
             else:
                 data = icon.get_pixels()
                 w = icon.get_width()
                 h = icon.get_height()
                 rowstride = icon.get_rowstride()
                 mode = "RGB"
                 if icon.get_has_alpha():
                     mode = "RGBA"
                 img = Image.frombytes(mode, (w, h), data, "raw", mode,
                                       rowstride)
     if img:
         if w > 256 or h > 256:
             img = img.resize((256, 256), Image.ANTIALIAS)
             w = h = 256
         buf = BytesIOClass()
         img.save(buf, "PNG")
         cpixels = buf.getvalue()
         buf.close()
         return "png", w, h, cpixels
     return ()
Beispiel #5
0
 def get_default_window_icon(self):
     #return the icon which would be used from the wmclass
     c_i = self.get_property("class-instance")
     if not c_i or len(c_i) != 2:
         return None
     wmclass_name, wmclass_class = [x.encode("utf-8") for x in c_i]
     iconlog("get_default_window_icon() using %s",
             (wmclass_name, wmclass_class))
     if not wmclass_name:
         return None
     it = icon_theme_get_default()
     p = None
     for fmt in ("%s-color", "%s", "%s_48x48", "application-x-%s",
                 "%s-symbolic", "%s.symbolic"):
         icon_name = fmt % wmclass_name
         i = it.lookup_icon(icon_name, 48, 0)
         iconlog("%s.lookup_icon(%s)=%s", it, icon_name, i)
         if not i:
             continue
         try:
             p = i.load_icon()
             iconlog("%s.load_icon()=%s", i, p)
             if p:
                 break
         except Exception:
             iconlog("%s.load_icon()", i, exc_info=True)
     if p is None:
         return None
     #to make it consistent with the "icon" property,
     #return a cairo surface..
     surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, p.get_width(),
                               p.get_height())
     gc = gdk.CairoContext(cairo.Context(surf))
     gc.set_source_pixbuf(p, 0, 0)
     gc.paint()
     iconlog("get_default_window_icon()=%s", surf)
     return surf
Beispiel #6
0
 def make_hello(self):
     capabilities = UIXpraClient.make_hello(self)
     capabilities["named_cursors"] = len(cursor_types) > 0
     capabilities.update(flatten_dict(get_gtk_version_info()))
     #tell the server which icons GTK can use
     #so it knows when it should supply one as fallback
     it = icon_theme_get_default()
     #this would add our bundled icon directory
     #to the search path, but I don't think we have
     #any extra icons that matter in there:
     #from xpra.platform.paths import get_icon_dir
     #d = get_icon_dir()
     #if d not in it.get_search_path():
     #    it.append_search_path(d)
     #    it.rescan_if_needed()
     log("default icon theme: %s", it)
     log("icon search path: %s", it.get_search_path())
     log("contexts: %s", it.list_contexts())
     icons = []
     for context in it.list_contexts():
         icons += it.list_icons(context)
     log("icons: %s", icons)
     capabilities["theme.default.icons"] = list(set(icons))
     if METADATA_SUPPORTED:
         ms = [x.strip() for x in METADATA_SUPPORTED.split(",")]
     else:
         #this is currently unused, and slightly redundant because of metadata.supported below:
         capabilities["window.states"] = [
             "fullscreen", "maximized", "sticky", "above", "below",
             "shaded", "iconified", "skip-taskbar", "skip-pager"
         ]
         ms = list(DEFAULT_METADATA_SUPPORTED)
         #added in 0.15:
         ms += [
             "command", "workspace", "above", "below", "sticky",
             "set-initial-position"
         ]  #0.17
     if os.name == "posix":
         #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:
         ms += ["shape"]
     if self._set_window_menu:
         ms += ["menu"]
     #figure out if we can handle the "global menu" stuff:
     if os.name == "posix" and not sys.platform.startswith("darwin"):
         try:
             from xpra.dbus.helper import DBusHelper
             assert DBusHelper
         except:
             pass
     log("metadata.supported: %s", ms)
     capabilities["metadata.supported"] = ms
     #we need the bindings to support initiate-moveresize (posix only for now):
     updict(
         capabilities, "window", {
             "initiate-moveresize": HAS_X11_BINDINGS,
             "configure.pointer": True,
             "frame_sizes": self.get_window_frame_sizes()
         })
     from xpra.client.window_backing_base import DELTA_BUCKETS
     updict(
         capabilities,
         "encoding",
         {
             "icons.greedy":
             True,  #we don't set a default window icon any more
             "icons.size": (64, 64),  #size we want
             "icons.max_size": (128, 128),  #limit
             "delta_buckets": DELTA_BUCKETS,
         })
     return capabilities
Beispiel #7
0
 def make_hello(self):
     capabilities = UIXpraClient.make_hello(self)
     capabilities["named_cursors"] = len(cursor_types)>0
     capabilities.update(flatten_dict(get_gtk_version_info()))
     #tell the server which icons GTK can use
     #so it knows when it should supply one as fallback
     it = icon_theme_get_default()
     #this would add our bundled icon directory
     #to the search path, but I don't think we have
     #any extra icons that matter in there:
     #from xpra.platform.paths import get_icon_dir
     #d = get_icon_dir()
     #if d not in it.get_search_path():
     #    it.append_search_path(d)
     #    it.rescan_if_needed()
     log("default icon theme: %s", it)
     log("icon search path: %s", it.get_search_path())
     log("contexts: %s", it.list_contexts())
     icons = []
     for context in it.list_contexts():
         icons += it.list_icons(context)
     log("icons: %s", icons)
     capabilities["theme.default.icons"] = list(set(icons))
     if METADATA_SUPPORTED:
         ms = [x.strip() for x in METADATA_SUPPORTED.split(",")]
     else:
         #this is currently unused, and slightly redundant because of metadata.supported below:
         capabilities["window.states"] = ["fullscreen", "maximized", "sticky", "above", "below", "shaded", "iconified", "skip-taskbar", "skip-pager"]
         ms = list(DEFAULT_METADATA_SUPPORTED)
         #added in 0.15:
         ms += ["command", "workspace", "above", "below", "sticky",
                "set-initial-position"]  #0.17
     if os.name=="posix":
         #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:
         ms += ["shape"]
     if self._set_window_menu:
         ms += ["menu"]
     #figure out if we can handle the "global menu" stuff:
     if os.name=="posix" and not sys.platform.startswith("darwin"):
         try:
             from xpra.dbus.helper import DBusHelper
             assert DBusHelper
         except:
             pass
     log("metadata.supported: %s", ms)
     capabilities["metadata.supported"] = ms
     #we need the bindings to support initiate-moveresize (posix only for now):
     updict(capabilities, "window", {
            "initiate-moveresize"    : HAS_X11_BINDINGS,
            "configure.pointer"      : True,
            "frame_sizes"            : self.get_window_frame_sizes()
            })
     from xpra.client.window_backing_base import DELTA_BUCKETS
     updict(capabilities, "encoding", {
                 "icons.greedy"      : True,         #we don't set a default window icon any more
                 "icons.size"        : (64, 64),     #size we want
                 "icons.max_size"    : (128, 128),   #limit
                 "delta_buckets"     : DELTA_BUCKETS,
                 })
     return capabilities