Skip to content

Commit

Permalink
tell the client if this is the default icon so it can skip overlaying…
Browse files Browse the repository at this point in the history
… xpra's default icon on top of itself

git-svn-id: https://xpra.org/svn/Xpra/trunk@18189 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jan 29, 2018
1 parent f72a362 commit 6cb71dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/xpra/client/ui_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3566,7 +3566,8 @@ def _process_window_metadata(self, packet):

def _process_window_icon(self, packet):
wid, w, h, coding, data = packet[1:6]
img = self._window_icon_image(wid, w, h, coding, data)
isdefault = len(packet)>=7 and packet[6]
img = self._window_icon_image(wid, w, h, coding, data, isdefault)
window = self._id_to_window.get(wid)
iconlog("_process_window_icon(%s, %s, %s, %s, %s bytes) image=%s, window=%s", wid, w, h, coding, len(data), img, window)
if window and img:
Expand Down Expand Up @@ -3609,7 +3610,7 @@ def set_tray_icon(self):
traylog("set_tray_icon() using default icon")
self.tray.set_icon()

def _window_icon_image(self, wid, width, height, coding, data):
def _window_icon_image(self, wid, width, height, coding, data, isdefault):
#convert the data into a pillow image,
#adding the icon overlay (if enabled)
from PIL import Image
Expand All @@ -3628,7 +3629,7 @@ def _window_icon_image(self, wid, width, height, coding, data):
has_alpha = img.mode=="RGBA"
rowstride = width * (3+int(has_alpha))
icon = img
if self.overlay_image:
if self.overlay_image and not isdefault:
if ICON_SHRINKAGE>0 and ICON_SHRINKAGE<100:
#paste the application icon in the top-left corner,
#shrunk by ICON_SHRINKAGE pct
Expand Down
15 changes: 10 additions & 5 deletions src/xpra/server/window/window_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,14 @@ def get_info(self):
info["pixel-format"] = self.pixel_format
idata = self.window_icon_data
if idata:
pixel_data, pixel_format, stride, w, h = idata
pixel_data, pixel_format, stride, w, h, isdefault = idata
info["icon"] = {
"pixel_format" : pixel_format,
"width" : w,
"height" : h,
"stride" : stride,
"bytes" : len(pixel_data),
"default" : bool(isdefault),
}
return info

Expand Down Expand Up @@ -589,23 +590,27 @@ def send_window_icon(self):
#try to load the icon for this class-instance from the theme:
surf = self.window.get_default_window_icon()
iconlog("send_window_icon window %s using default window icon=%s", self.window, surf)
#TODO: clients could expose a "default-icon" capabitlity,
# then we wouldn't even need to send any icon data, just the flag
isdefault = False
if not surf and self.window_icon_greedy:
#client does not set a default icon, so we must provide one every time
#to make sure that the window icon does get set to something
#(our icon is at least better than the window manager's default)
surf = WindowSource.get_fallback_window_icon_surface()
isdefault = True
iconlog("using fallback window icon")
if surf:
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())
self.window_icon_data = (surf.get_pixels(), "RGBA", surf.get_rowstride(), surf.get_width(), surf.get_height(), isdefault)
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())
self.window_icon_data = (surf.get_data(), "BGRA", surf.get_stride(), surf.get_width(), surf.get_height(), isdefault)
if not self.send_window_icon_due:
self.send_window_icon_due = True
#call compress_clibboard via the work queue
Expand All @@ -620,7 +625,7 @@ def compress_and_send_window_icon(self):
idata = self.window_icon_data
if not idata:
return
pixel_data, pixel_format, stride, w, h = idata
pixel_data, pixel_format, stride, w, h, isdefault = idata
PIL = get_codec("PIL")
max_w, max_h = self.window_icon_max_size
if stride!=w*4:
Expand Down Expand Up @@ -662,7 +667,7 @@ def compress_and_send_window_icon(self):
iconlog("cannot send window icon, supported encodings: %s", self.window_icon_encodings)
return
assert wrapper.datatype in ("premult_argb32", "png"), "invalid wrapper datatype %s" % wrapper.datatype
packet = ("window-icon", self.wid, w, h, wrapper.datatype, wrapper)
packet = ("window-icon", self.wid, w, h, wrapper.datatype, wrapper, isdefault)
iconlog("queuing window icon update: %s", packet)
self.queue_packet(packet, wait_for_more=True)

Expand Down

0 comments on commit 6cb71dd

Please sign in to comment.