Coverage for /home/antoine/projects/xpra-git/dist/python3/lib64/python/xpra/server/shadow/root_window_model.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2# This file is part of Xpra.
3# Copyright (C) 2012-2020 Antoine Martin <antoine@xpra.org>
4# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
5# later version. See the file COPYING for details.
7import socket
9from xpra.util import prettify_plug_name
10from xpra.os_util import (
11 get_generic_os_name, do_get_generic_os_name,
12 load_binary_file, get_linux_distribution,
13 )
14from xpra.platform.paths import get_icon_filename
15from xpra.log import Logger
17log = Logger("shadow")
20class RootWindowModel:
22 def __init__(self, root_window, capture=None):
23 self.window = root_window
24 self.geometry = root_window.get_geometry()[:4]
25 self.capture = capture
26 self.property_names = [
27 "title", "class-instance",
28 "client-machine", "window-type",
29 "size-hints", "icons", "shadow",
30 "depth",
31 ]
32 self.dynamic_property_names = []
33 self.internal_property_names = ["content-type"]
35 def __repr__(self):
36 return "RootWindowModel(%s : %24s)" % (self.capture, self.geometry)
38 def get_info(self) -> dict:
39 info = {}
40 c = self.capture
41 if c:
42 info["capture"] = c.get_info()
43 return info
45 def take_screenshot(self):
46 return self.capture.take_screenshot()
48 def get_image(self, x, y, width, height):
49 ox, oy = self.geometry[:2]
50 image = self.capture.get_image(ox+x, oy+y, width, height)
51 if image and (ox>0 or oy>0):
52 #adjust x and y of where the image is displayed on the client (target_x and target_y)
53 #not where the image lives within the current buffer (x and y)
54 image.set_target_x(x)
55 image.set_target_y(y)
56 return image
58 def unmanage(self, exiting=False):
59 pass
61 def suspend(self):
62 pass
64 def is_managed(self):
65 return True
67 def is_tray(self):
68 return False
70 def is_OR(self):
71 return False
73 def has_alpha(self):
74 return False
76 def uses_XShm(self):
77 return False
79 def is_shadow(self):
80 return True
82 def get_default_window_icon(self, _size):
83 return None
85 def acknowledge_changes(self):
86 pass
88 def get_dimensions(self):
89 #used by get_window_info only
90 return self.geometry[2:4]
92 def get_geometry(self):
93 return self.geometry
96 def get_property_names(self):
97 return self.property_names
99 def get_dynamic_property_names(self):
100 return self.dynamic_property_names
102 def get_internal_property_names(self):
103 return self.internal_property_names
105 def get_property(self, prop):
106 #subclasses can define properties as attributes:
107 attr_name = prop.replace("-", "_")
108 if hasattr(self, attr_name):
109 return getattr(self, attr_name)
110 #otherwise fallback to default behaviour:
111 if prop=="title":
112 return prettify_plug_name(self.window.get_screen().get_display().get_name())
113 if prop=="client-machine":
114 return socket.gethostname()
115 if prop=="window-type":
116 return ["NORMAL"]
117 if prop=="fullscreen":
118 return False
119 if prop=="shadow":
120 return True
121 if prop=="depth":
122 return 24
123 if prop=="scaling":
124 return None
125 if prop=="opacity":
126 return None
127 if prop=="size-hints":
128 size = self.get_dimensions()
129 return {
130 "maximum-size" : size,
131 "minimum-size" : size,
132 "base-size" : size,
133 }
134 if prop=="class-instance":
135 osn = do_get_generic_os_name()
136 if osn=="Linux":
137 try:
138 osn += "-"+get_linux_distribution()[0].replace(" ", "-")
139 except Exception: # pragma: no cover
140 pass
141 return ("xpra-%s" % osn.lower(), "Xpra %s" % osn.replace("-", " "))
142 if prop=="icons":
143 try:
144 icon_name = get_icon_filename((get_generic_os_name() or "").lower()+".png")
145 from PIL import Image
146 img = Image.open(icon_name)
147 log("Image(%s)=%s", icon_name, img)
148 if img:
149 icon_data = load_binary_file(icon_name)
150 assert icon_data
151 w, h = img.size
152 img.close()
153 icon = (w, h, "png", icon_data)
154 icons = (icon,)
155 return icons
156 except Exception: # pragma: no cover
157 log("failed to return window icon")
158 return ()
159 if prop=="content-type":
160 return "desktop"
161 raise ValueError("invalid property: %s" % prop)
163 def get(self, name, default_value=None):
164 try:
165 return self.get_property(name)
166 except ValueError as e:
167 log("get(%s, %s) %s on %s", name, default_value, e, self)
168 return default_value
171 def managed_connect(self, *args): # pragma: no cover
172 log.warn("ignoring managed signal connect request: %s", args)
174 def connect(self, *args): # pragma: no cover
175 log.warn("ignoring signal connect request: %s", args)
177 def disconnect(self, *args): # pragma: no cover
178 log.warn("ignoring signal disconnect request: %s", args)