Skip to content

Commit

Permalink
* refactor get_generic_os_name so we can re-use it in the desktop ser…
Browse files Browse the repository at this point in the history
…ver code

* don't set XDG_CURRENT_DESKTOP when starting a desktop: we're not the window manager
* avoid doing silly roundtrip via cairo when we have a pixbuf: teach window source to handle pixbuf data
* expose "icon" for desktop servers (fallback to generic os name if we don't find an icon for the wm name)

git-svn-id: https://xpra.org/svn/Xpra/trunk@16210 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 6, 2017
1 parent 2025098 commit f1dfbdf
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 42 deletions.
11 changes: 11 additions & 0 deletions src/xpra/os_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ def getUbuntuVersion():
def is_unity():
return os.environ.get("XDG_CURRENT_DESKTOP", "").lower().startswith("unity")

def get_generic_os_name():
for k,v in {
"linux" : "linux",
"darwin" : "osx",
"win" : "win32",
"freebsd" : "freebsd",
}.items():
if sys.platform.startswith(k):
return v
return sys.platform


def load_binary_file(filename):
if not os.path.exists(filename):
Expand Down
3 changes: 2 additions & 1 deletion src/xpra/scripts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ def add_tcp_mdns_rec(host, iport):
if xrd:
os.environ["XDG_RUNTIME_DIR"] = xrd
os.environ["XDG_SESSION_TYPE"] = "x11"
os.environ["XDG_CURRENT_DESKTOP"] = opts.wm_name
if not starting_desktop:
os.environ["XDG_CURRENT_DESKTOP"] = opts.wm_name
configure_imsettings_env(opts.input_method)
if display_name[0] != 'S':
os.environ["DISPLAY"] = display_name
Expand Down
28 changes: 4 additions & 24 deletions src/xpra/server/shadow/root_window_model.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# coding=utf8
# This file is part of Xpra.
# Copyright (C) 2012-2015 Antoine Martin <antoine@devloop.org.uk>
# Copyright (C) 2012-2017 Antoine Martin <antoine@devloop.org.uk>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import sys
import socket

from xpra.log import Logger
log = Logger("shadow")

from xpra.util import prettify_plug_name
from xpra.os_util import get_generic_os_name


class RootWindowModel(object):
Expand Down Expand Up @@ -69,15 +69,6 @@ def get_dynamic_property_names(self):
def get_internal_property_names(self):
return self.internal_property_names

def get_generic_os_name(self):
for k,v in {"linux" : "linux",
"darwin" : "osx",
"win" : "win32",
"freebsd" : "freebsd"}.items():
if sys.platform.startswith(k):
return v
return sys.platform

def get_property(self, prop):
if prop=="title":
return prettify_plug_name(self.window.get_screen().get_display().get_name())
Expand All @@ -99,26 +90,15 @@ def get_property(self, prop):
"minimum-size" : size,
"base-size" : size}
elif prop=="class-instance":
osn = self.get_generic_os_name()
osn = get_generic_os_name()
return ("xpra-%s" % osn, "Xpra-%s" % osn.upper())
elif prop=="icon":
#convert it to a cairo surface..
#because that's what the property is expected to be
try:
import gtk.gdk
from xpra.platform.paths import get_icon
icon_name = self.get_generic_os_name()+".png"
icon = get_icon(icon_name)
log("icon(%s)=%s", icon_name, icon)
if not icon:
return None
import cairo
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, icon.get_width(), icon.get_height())
gc = gtk.gdk.CairoContext(cairo.Context(surf))
gc.set_source_pixbuf(icon, 0, 0)
gc.paint()
log("icon=%s", surf)
return surf
return icon
except:
log("failed to return window icon")
return None
Expand Down
37 changes: 21 additions & 16 deletions src/xpra/server/window/window_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,14 @@ def get_info(self):
info["pixel-format"] = self.pixel_format
idata = self.window_icon_data
if idata:
pixel_data, stride, w, h = idata
pixel_data, pixel_format, stride, w, h = idata
info["icon"] = {
"width" : w,
"height" : h,
"stride" : stride,
"bytes" : len(pixel_data)
}
"pixel_format" : pixel_format,
"width" : w,
"height" : h,
"stride" : stride,
"bytes" : len(pixel_data),
}
return info

def get_quality_speed_info(self):
Expand Down Expand Up @@ -542,12 +543,16 @@ def send_window_icon(self):
surf = WindowSource.get_fallback_window_icon_surface()
iconlog("using fallback window icon")
if surf:
#for debugging, save to a file so we can see it:
#surf.write_to_png("S-%s-%s.png" % (self.wid, int(time.time())))
#extract the data from the cairo surface for processing in the work queue:
import cairo
assert surf.get_format() == cairo.FORMAT_ARGB32
self.window_icon_data = (surf.get_data(), surf.get_stride(), surf.get_width(), surf.get_height())
if hasattr(surf, "get_pixels"):
#looks like a gdk.Pixbuf:
self.window_icon_data = (surf.get_pixels(), "RGBA", surf.get_rowstride(), surf.get_width(), surf.get_height())
else:
#for debugging, save to a file so we can see it:
#surf.write_to_png("S-%s-%s.png" % (self.wid, int(time.time())))
#extract the data from the cairo surface
import cairo
assert surf.get_format() == cairo.FORMAT_ARGB32
self.window_icon_data = (surf.get_data(), "BGRA", surf.get_stride(), surf.get_width(), surf.get_height())
if not self.send_window_icon_due:
self.send_window_icon_due = True
#call compress_clibboard via the work queue
Expand All @@ -562,7 +567,7 @@ def compress_and_send_window_icon(self):
idata = self.window_icon_data
if not idata:
return
pixel_data, stride, w, h = idata
pixel_data, pixel_format, stride, w, h = idata
PIL = get_codec("PIL")
max_w, max_h = self.window_icon_max_size
if stride!=w*4:
Expand All @@ -574,10 +579,10 @@ def compress_and_send_window_icon(self):
#or if we want to save window icons
has_png = PIL and ("png" in self.window_icon_encodings)
has_premult = "premult_argb32" in self.window_icon_encodings
use_png = has_png and (SAVE_WINDOW_ICONS or w>max_w or h>max_h or not has_premult)
use_png = has_png and (SAVE_WINDOW_ICONS or w>max_w or h>max_h or (not has_premult) or (pixel_format!="BGRA"))
iconlog("compress_and_send_window_icon: %sx%s, sending as png=%s", w, h, use_png)
if use_png:
img = PIL.Image.frombuffer("RGBA", (w,h), pixel_data, "raw", "BGRA", 0, 1)
img = PIL.Image.frombuffer("RGBA", (w,h), pixel_data, "raw", pixel_format, 0, 1)
icon_w, icon_h = self.window_icon_size
if w>icon_w or h>icon_h:
#scale the icon down to the size the client wants
Expand All @@ -598,7 +603,7 @@ def compress_and_send_window_icon(self):
filename = "server-window-%i-icon-%i.png" % (self.wid, int(time.time()))
img.save(filename, 'PNG')
iconlog("server window icon saved to %s", filename)
elif "premult_argb32" in self.window_icon_encodings:
elif ("premult_argb32" in self.window_icon_encodings) and pixel_format=="BGRA":
wrapper = self.compressed_wrapper("premult_argb32", str(pixel_data))
else:
iconlog("cannot send window icon, supported encodings: %s", self.window_icon_encodings)
Expand Down
18 changes: 17 additions & 1 deletion src/xpra/x11/desktop_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import socket

from xpra.util import updict, log_screen_sizes
from xpra.os_util import get_generic_os_name
from xpra.platform.paths import get_icon
from xpra.platform.gui import get_wm_name
from xpra.gtk_common.gobject_util import one_arg_signal, no_arg_signal
from xpra.gtk_common.error import xswallow
Expand Down Expand Up @@ -68,7 +70,7 @@ class DesktopModel(WindowModelStub, WindowDamageHandler):
}


_property_names = ["xid", "client-machine", "window-type", "shadow", "size-hints", "class-instance", "focused", "title", "depth"]
_property_names = ["xid", "client-machine", "window-type", "shadow", "size-hints", "class-instance", "focused", "title", "depth", "icon"]
_dynamic_property_names = ["size-hints"]

def __init__(self, root):
Expand Down Expand Up @@ -104,6 +106,11 @@ def uses_XShm(self):
return bool(self._xshm_handle)


def get_default_window_icon(self):
icon_name = get_generic_os_name()+".png"
return get_icon(icon_name)


def get_property(self, prop):
if prop=="xid":
return self.client_window.xid
Expand All @@ -119,6 +126,15 @@ def get_property(self, prop):
return True
elif prop=="class-instance":
return ("xpra-desktop", "Xpra-Desktop")
elif prop=="icon":
try:
icon_name = get_wm_name()+".png"
icon = get_icon(icon_name)
log("get_icon(%s)=%s", icon_name, icon)
return icon
except:
log("failed to return window icon")
return None
else:
return gobject.GObject.get_property(self, prop)

Expand Down

0 comments on commit f1dfbdf

Please sign in to comment.