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# This file is part of Xpra. 

2# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com> 

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. 

6 

7from xpra.util import envbool 

8from xpra.gtk_common.error import xsync 

9from xpra.x11.gtk_x11.prop import prop_get 

10from xpra.x11.bindings.window_bindings import X11WindowBindings #@UnresolvedImport 

11from xpra.log import Logger 

12 

13log = Logger("x11", "window") 

14 

15X11Window = X11WindowBindings() 

16 

17 

18FORCE_REPLACE_WM = envbool("XPRA_FORCE_REPLACE_WM", False) 

19def wm_check(wm_name, upgrading=False): 

20 found_name = False 

21 with xsync: 

22 from gi.repository import Gdk 

23 display = Gdk.Display.get_default() 

24 #there should only be one screen... but let's check all of them 

25 for i in range(display.get_n_screens()): 

26 screen = display.get_screen(i) 

27 root = screen.get_root_window() 

28 wm_prop = "WM_S%s" % i 

29 cwm_prop = "_NEW_WM_CM_S%s" % i 

30 wm_so = X11Window.XGetSelectionOwner(wm_prop) 

31 cwm_so = X11Window.XGetSelectionOwner(cwm_prop) 

32 log("ewmh selection owner for %s: %s", wm_prop, wm_so) 

33 log("compositing window manager %s: %s", cwm_prop, cwm_so) 

34 

35 ewmh_wm = prop_get(root, "_NET_SUPPORTING_WM_CHECK", "window", ignore_errors=True, raise_xerrors=False) 

36 def xid(w): 

37 if w: 

38 return "%#x" % w.get_xid() 

39 return None 

40 log("_NET_SUPPORTING_WM_CHECK for screen %i: %s (root=%s)", i, xid(ewmh_wm), xid(root)) 

41 if not ewmh_wm: 

42 continue 

43 name = prop_get(ewmh_wm, "_NET_WM_NAME", "utf8", ignore_errors=True, raise_xerrors=False) 

44 if upgrading and name and name==wm_name: 

45 log.info("found previous Xpra instance") 

46 found_name = True 

47 elif not name: 

48 log.warn("Warning: no window manager found") 

49 log.warn(" on screen %s using window %#x", i, ewmh_wm.get_xid()) 

50 else: 

51 log.warn("Warning: found an existing window manager") 

52 log.warn(" on screen %s using window %#x: %s", i, ewmh_wm.get_xid(), name or "unknown") 

53 if (wm_so is None or wm_so==0) and (cwm_so is None or cwm_so==0): 

54 if FORCE_REPLACE_WM: 

55 log.warn("XPRA_FORCE_REPLACE_WM is set, replacing it forcibly") 

56 else: 

57 log.error("it does not own the selection '%s' or '%s'", wm_prop, cwm_prop) 

58 log.error("so we cannot take over and make it exit") 

59 log.error("please stop %s so you can run xpra on this display", 

60 name or "the existing window manager") 

61 log.warn("if you are certain that the window manager is already gone,") 

62 log.warn(" you may set XPRA_FORCE_REPLACE_WM=1 to force xpra to continue") 

63 log.warn(" at your own risk") 

64 return False 

65 if upgrading and not found_name: 

66 log.error("Error: xpra server not found") 

67 return False 

68 return True