Skip to content

Commit

Permalink
#3320 generalize monitor matching so MS Windows servers can use it
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Oct 30, 2021
1 parent 2b76d44 commit 5f6d15a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 44 deletions.
35 changes: 15 additions & 20 deletions xpra/platform/win32/shadow_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from xpra.util import envbool, prettify_plug_name, csv, XPRA_APP_ID, XPRA_IDLE_NOTIFICATION_ID
from xpra.scripts.config import InitException
from xpra.server.gtk_server_base import GTKServerBase
from xpra.server.shadow.gtk_shadow_server_base import GTKShadowServerBase, MULTI_WINDOW
from xpra.server.shadow.gtk_shadow_server_base import GTKShadowServerBase
from xpra.server.shadow.root_window_model import RootWindowModel
from xpra.platform.win32 import constants as win32con
from xpra.platform.win32.gui import get_desktop_name, get_fixed_cursor_size
Expand Down Expand Up @@ -407,29 +407,24 @@ def setup_capture(self):
w, h = get_root_window_size()
return init_capture(w, h, self.pixel_depth)

def makeRootWindowModels(self):
log("makeRootWindowModels() root=%s", self.root)
self.capture = self.setup_capture()

def get_root_window_model_class(self):
if SEAMLESS:
model_class = SeamlessRootWindowModel
else:
model_class = RootWindowModel
if not MULTI_WINDOW:
return (model_class(self.root, self.capture),)
models = []
monitors = get_monitors()
for i, monitor in enumerate(monitors):
return SeamlessRootWindowModel
return RootWindowModel

def get_shadow_monitors(self):
#convert to the format expected by GTKShadowServerBase:
monitors = []
for i, monitor in enumerate(get_monitors()):
geom = monitor["Monitor"]
x1, y1, x2, y2 = geom
assert x1<x2 and y1<y2
model = model_class(self.root, self.capture)
model.title = monitor["Device"].lstrip("\\\\.\\")
model.geometry = x1, y1, x2-x1, y2-y1
screenlog("monitor %i: %10s geometry=%s (from %s)", i, model.title, model.geometry, geom)
models.append(model)
screenlog("makeRootWindowModels: model(%s)=%s", monitor, model)
log("makeRootWindowModels()=%s", models)
return models
plug_name = monitor["Device"].lstrip("\\\\.\\")
monitors.append((plug_name, x1, y1, x2-x1, y2-y1, 1))
screenlog("monitor %i: %10s coordinates: %s", i, plug_name, geom)
log("get_shadow_monitors()=%s", monitors)
return monitors


def refresh(self):
Expand Down
11 changes: 7 additions & 4 deletions xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2123,12 +2123,15 @@ def run_glcheck(opts):


def pick_shadow_display(dotxpra, args, uid=getuid(), gid=getgid()):
if len(args)==1 and args[0]:
if OSX or WIN32:
return args[0]
if args[0][0]==":":
#display_name was provided:
return args[0]
if OSX or WIN32:
#no need for a specific display
return "Main"
if len(args)==1 and args[0] and args[0][0]==":":
#display_name was provided:
return args[0]
return guess_X11_display(dotxpra, None, uid, gid)


Expand Down Expand Up @@ -3108,7 +3111,7 @@ def get_displays(dotxpra=None, display_names=None):
continue
uid, gid = v[:2]
displays[display] = {"uid" : uid, "gid" : gid}
log("get_displays displays=%s", displays)
log("get_displays%s=%s", (dotxpra, display_names), displays)
return displays

def run_list_sessions(args, options):
Expand Down
60 changes: 40 additions & 20 deletions xpra/server/shadow/gtk_shadow_server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,43 +129,63 @@ def recreate_window_models(self):
def setup_capture(self):
raise NotImplementedError()

def makeRootWindowModels(self):
log("makeRootWindowModels() root=%s", self.root)
self.capture = self.setup_capture()
if not MULTI_WINDOW:
return (RootWindowModel(self.root, self.capture),)
models = []
def get_root_window_model_class(self):
return RootWindowModel

def get_shadow_monitors(self):
display = self.root.get_display()
screen = self.root.get_screen()
n = screen.get_n_monitors()
match = self.display_options.split(",")
found = []
n = display.get_n_monitors()
monitors = []
for i in range(n):
geom = screen.get_monitor_geometry(i)
x, y, width, height = geom.x, geom.y, geom.width, geom.height
m = display.get_monitor(i)
geom = m.get_geometry()
try:
scale_factor = screen.get_monitor_scale_factor(i)
scale_factor = m.get_scale_factor()
except Exception as e:
screenlog("no scale factor: %s", e)
scale_factor = 1
else:
screenlog("scale factor for monitor %i: %i", i, scale_factor)
title = prettify_plug_name(self.root.get_screen().get_display().get_name())
plug_name = None
if hasattr(screen, "get_monitor_plug_name"):
try:
plug_name = screen.get_monitor_plug_name(i)
if title or n>1:
except Exception:
pass
if not plug_name:
plug_name = m.get_model()
monitors.append((plug_name, geom.x, geom.y, geom.width, geom.height, scale_factor))
screenlog("get_shadow_monitors()=%s", monitors)
return monitors

def makeRootWindowModels(self):
screenlog("makeRootWindowModels() root=%s, display_options=%s", self.root, self.display_options)
self.capture = self.setup_capture()
model_class = self.get_root_window_model_class()
if not MULTI_WINDOW:
return (model_class(self.root, self.capture),)
models = []
monitors = self.get_shadow_monitors()
match_str = self.display_options
display_name = prettify_plug_name(self.root.get_screen().get_display().get_name())
found = []
for i, monitor in enumerate(monitors):
plug_name, x, y, width, height, scale_factor = monitor
title = display_name
if plug_name or i>1:
title = plug_name or str(i)
found.append(plug_name or title)
if match and not(title in match or plug_name in match):
if match_str and not(title in match_str or plug_name in match_str):
screenlog.info(" skipped monitor %s", plug_name or title)
continue
model = RootWindowModel(self.root, self.capture)
model = model_class(self.root, self.capture)
model.title = title
model.geometry = (x, y, width, height)
models.append(model)
screenlog("monitor %i: %10s geometry=%s", i, title, model.geometry)
screenlog("monitor %i: %10s geometry=%s, scale factor=%s", i, title, model.geometry, scale_factor)
screenlog("makeRootWindowModels()=%s", models)
if not models and match:
screenlog.warn("Warning: no monitors found matching %s", self.display_options)
if not models and match_str:
screenlog.warn("Warning: no monitors found matching %r", match_str)
screenlog.warn(" only found: %s", csv(found))
return models

Expand Down

0 comments on commit 5f6d15a

Please sign in to comment.