Hide keyboard shortcuts

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#!/usr/bin/env python 

2# This file is part of Xpra. 

3# Copyright (C) 2010 Nathaniel Smith <njs@pobox.com> 

4# Copyright (C) 2012-2019 Antoine Martin <antoine@xpra.org> 

5# Xpra is released under the terms of the GNU GPL v2, or, at your option, any 

6# later version. See the file COPYING for details. 

7 

8import os 

9import sys 

10import binascii 

11 

12from xpra.platform import platform_import 

13from xpra.os_util import bytestostr 

14from xpra.log import Logger 

15 

16 

17_init_done = False 

18def init(): 

19 #warning: we currently call init() from multiple places to try 

20 #to ensure we run it as early as possible.. 

21 global _init_done 

22 if not _init_done: 

23 _init_done = True 

24 do_init() 

25 

26def do_init(): 

27 pass 

28 

29_ready_done = False 

30def ready(): 

31 global _ready_done 

32 if not _ready_done: 

33 _ready_done = True 

34 do_ready() 

35 

36def do_ready(): 

37 pass 

38 

39 

40_default_icon = "xpra.png" 

41def set_default_icon(icon_filename): 

42 global _default_icon 

43 _default_icon = icon_filename 

44 

45def get_default_icon(): 

46 global _default_icon 

47 return _default_icon 

48 

49 

50def force_focus(duration=2000): 

51 #only implemented on macos 

52 assert isinstance(duration, int) 

53 

54 

55def use_stdin(): 

56 stdin = sys.stdin 

57 return stdin and stdin.isatty() 

58 

59def get_clipboard_native_class(): 

60 return None 

61 

62#defaults: 

63def get_native_tray_menu_helper_class(): 

64 #classes that generate menus for xpra's system tray 

65 #let the toolkit classes use their own 

66 return None 

67def get_native_tray_classes(*_args): 

68 #the classes we can use for our system tray: 

69 #let the toolkit classes use their own 

70 return [] 

71def get_native_system_tray_classes(*_args): 

72 #the classes we can use for application system tray forwarding: 

73 #let the toolkit classes use their own 

74 return [] 

75def system_bell(*_args): 

76 #let the toolkit classes use their own 

77 return False 

78def get_native_notifier_classes(): 

79 return [] 

80 

81 

82def get_session_type(): 

83 return "" 

84 

85 

86def get_xdpi(): 

87 return -1 

88 

89def get_ydpi(): 

90 return -1 

91 

92 

93def get_icon_size(): 

94 xdpi = get_xdpi() 

95 ydpi = get_ydpi() 

96 if xdpi>0 and ydpi>0: 

97 from xpra.util import iround 

98 dpi = iround((xdpi + ydpi)/2.0) 

99 else: 

100 dpi = 96 

101 if dpi > 144: 

102 return 48 

103 if dpi > 120: 

104 return 32 

105 if dpi > 96: 

106 return 24 

107 return 16 

108 

109def get_antialias_info(): 

110 return {} 

111 

112def get_display_icc_info(): 

113 #per display info 

114 return {} 

115 

116def get_icc_info(): 

117 return default_get_icc_info() 

118 

119def default_get_icc_info(): 

120 ENV_ICC_DATA = os.environ.get("XPRA_ICC_DATA") 

121 if ENV_ICC_DATA: 

122 return { 

123 "source" : "environment-override", 

124 "data" : binascii.unhexlify(ENV_ICC_DATA), 

125 } 

126 return get_pillow_icc_info() 

127 

128def get_pillow_icc_info(): 

129 screenlog = Logger("screen") 

130 info = {} 

131 try: 

132 from PIL import ImageCms 

133 from PIL.ImageCms import get_display_profile 

134 INTENT_STR = {} 

135 for x in ("PERCEPTUAL", "RELATIVE_COLORIMETRIC", "SATURATION", "ABSOLUTE_COLORIMETRIC"): 

136 v = getattr(ImageCms, "INTENT_%s" % x, None) 

137 if v: 

138 INTENT_STR[v] = x.lower().replace("_", "-") 

139 screenlog("get_icc_info() intents=%s", INTENT_STR) 

140 p = get_display_profile() 

141 screenlog("get_icc_info() display_profile=%s", p) 

142 if p: 

143 def getDefaultIntentStr(v): 

144 return INTENT_STR.get(v, "unknown") 

145 def getData(v): 

146 return v.tobytes() 

147 for (k, fn, conv) in ( 

148 ("name", "getProfileName", None), 

149 ("info", "getProfileInfo", None), 

150 ("copyright", "getProfileCopyright", None), 

151 ("manufacturer", "getProfileManufacturer", None), 

152 ("model", "getProfileModel", None), 

153 ("description", "getProfileDescription", None), 

154 ("default-intent", "getDefaultIntent", getDefaultIntentStr), 

155 ("data", "getData", getData), 

156 ): 

157 m = getattr(ImageCms, fn, None) 

158 if m is None: 

159 screenlog("%s lacks %s", ImageCms, fn) 

160 continue 

161 try: 

162 v = m(p) 

163 if conv: 

164 v = conv(v) 

165 info[k] = bytestostr(v).rstrip("\n\r") 

166 except Exception as e: 

167 screenlog("get_icc_info()", exc_info=True) 

168 screenlog("ICC profile error on %s using %s: %s", k, fn, e) 

169 except Exception as e: 

170 screenlog("get_icc_info()", exc_info=True) 

171 screenlog.warn("Warning: cannot query ICC profiles:") 

172 screenlog.warn(" %s", e) 

173 return info 

174 

175 

176#global workarea for all screens 

177def get_workarea(): 

178 return None 

179 

180#per monitor workareas (assuming a single screen) 

181def get_workareas(): 

182 return [] 

183 

184def get_number_of_desktops(): 

185 return 1 

186 

187def get_desktop_names(): 

188 return [] 

189 

190def get_vrefresh(): 

191 return -1 

192 

193def get_mouse_config(): 

194 return {} 

195 

196def get_double_click_time(): 

197 return -1 

198 

199def get_double_click_distance(): 

200 return -1, -1 

201 

202def get_fixed_cursor_size(): 

203 return -1, -1 

204 

205def get_cursor_size(): 

206 return -1 

207 

208def get_window_min_size(): 

209 return 0, 0 

210 

211def get_window_max_size(): 

212 return 2**15-1, 2**15-1 

213 

214def get_window_frame_size(_x, _y, _w, _h): 

215 return None 

216 

217def get_window_frame_sizes(): 

218 return {} 

219 

220 

221def add_window_hooks(_window): 

222 pass 

223 

224def remove_window_hooks(_window): 

225 pass 

226 

227 

228def show_desktop(_show): 

229 pass 

230 

231def set_fullscreen_monitors(_window, _fsm, _source_indication=0): 

232 pass 

233 

234def set_shaded(_window, _shaded): 

235 pass 

236 

237 

238def gl_check(): 

239 return None #no problem 

240 

241def get_wm_name(): 

242 return None 

243 

244 

245def can_access_display(): 

246 return True 

247 

248 

249take_screenshot = None 

250ClientExtras = None 

251 

252 

253def get_info_base(): 

254 def fname(v): 

255 try: 

256 return v.__name__ 

257 except AttributeError: 

258 return str(v) 

259 def fnames(l): 

260 return [fname(x) for x in l] 

261 return { 

262 "native-clipboard" : fname(get_clipboard_native_class()), 

263 "native_tray_menu_helper" : fname(get_native_tray_menu_helper_class()), 

264 "native_trays" : fnames(get_native_tray_classes()), 

265 "native_system_trays" : fnames(get_native_system_tray_classes()), 

266 "system_bell" : fname(system_bell), 

267 "native_notifiers" : fnames(get_native_notifier_classes()), 

268 "wm_name" : get_wm_name() or "", 

269 "workarea" : get_workarea() or "", 

270 "workareas" : get_workareas(), 

271 "desktops" : get_number_of_desktops(), 

272 "desktop_names" : get_desktop_names(), 

273 "session-type" : get_session_type(), 

274 "vertical-refresh" : get_vrefresh(), 

275 "fixed_cursor_size" : get_fixed_cursor_size(), 

276 "cursor_size" : get_cursor_size(), 

277 "icon_size" : get_icon_size(), 

278 "mouse" : get_mouse_config(), 

279 "double_click" : { 

280 "time" : get_double_click_time(), 

281 "distance" : get_double_click_distance(), 

282 }, 

283 "dpi" : { 

284 "x" : get_xdpi(), 

285 "y" : get_ydpi(), 

286 }, 

287 "antialias" : get_antialias_info(), 

288 "icc" : get_icc_info(), 

289 "display-icc" : get_display_icc_info(), 

290 "window_frame" : get_window_frame_sizes(), 

291 "can_access_display" : can_access_display(), 

292 } 

293 

294get_info = get_info_base 

295 

296 

297platform_import(globals(), "gui", False, 

298 "do_ready", 

299 "do_init", 

300 "force_focus", 

301 "gl_check", 

302 "use_stdin", 

303 "get_wm_name", 

304 "show_desktop", "set_fullscreen_monitors", "set_shaded", 

305 "ClientExtras", 

306 "take_screenshot", 

307 "get_clipboard_native_class", 

308 "get_native_tray_menu_helper_class", 

309 "get_native_tray_classes", 

310 "get_native_system_tray_classes", 

311 "get_native_notifier_classes", 

312 "get_session_type", 

313 "get_vrefresh", "get_workarea", "get_workareas", 

314 "get_number_of_desktops", "get_desktop_names", 

315 "get_antialias_info", "get_icc_info", "get_display_icc_info", "get_xdpi", "get_ydpi", 

316 "get_icon_size", 

317 "get_window_min_size", "get_window_max_size", 

318 "get_mouse_config", 

319 "get_double_click_time", "get_double_click_distance", 

320 "get_fixed_cursor_size", "get_cursor_size", "get_window_frame_sizes", 

321 "add_window_hooks", "remove_window_hooks", 

322 "system_bell", 

323 "can_access_display", 

324 "get_info") 

325 

326 

327def main(): 

328 from xpra.platform import program_context 

329 from xpra.util import print_nested_dict 

330 from xpra.os_util import OSX, POSIX 

331 from xpra.log import enable_color 

332 with program_context("GUI-Properties"): 

333 enable_color() 

334 init() 

335 verbose = "-v" in sys.argv or "--verbose" in sys.argv 

336 if verbose: 

337 from xpra.log import get_all_loggers 

338 for x in get_all_loggers(): 

339 x.enable_debug() 

340 

341 #naughty, but how else can I hook this up? 

342 if POSIX and not OSX: 

343 from xpra.x11.bindings.posix_display_source import init_posix_display_source #@UnresolvedImport 

344 init_posix_display_source() 

345 i = get_info() 

346 print_nested_dict(i, hex_keys=("data", "icc-data", "icc-profile")) 

347 return 0 

348 

349 

350if __name__ == "__main__": 

351 sys.exit(main())