Skip to content

Commit

Permalink
#56 assume that we can resize the display precisely
Browse files Browse the repository at this point in the history
remove the bigger / smaller switch
  • Loading branch information
totaam committed Aug 26, 2023
1 parent b2af515 commit 15a72ea
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 53 deletions.
13 changes: 5 additions & 8 deletions xpra/server/mixins/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,11 @@ def _process_desktop_size(self, proto, packet : PacketType) -> None:
self.calculate_desktops()
if len(packet)>=4:
ss.set_screen_sizes(packet[3])
bigger = ss.screen_resize_bigger
log("client requesting new size: %sx%s (bigger=%s)", width, height, bigger)
self.set_screen_size(width, height, bigger)
log("client requesting new size: %sx%s", width, height)
self.set_screen_size(width, height)
if len(packet)>=4:
log.info("received updated display dimensions")
log.info("client display size is %sx%s",
width, height)
log.info("client display size is %sx%s", width, height)
log_screen_sizes(width, height, ss.screen_sizes)
self.calculate_workarea(width, height)
self.apply_refresh_rate(ss)
Expand All @@ -400,10 +398,9 @@ def _process_configure_display(self, proto, packet : PacketType) -> None:
if monitors:
ss.set_monitors(monitors)
if desktop_size:
bigger = ss.screen_resize_bigger
width, height = desktop_size
log("client requesting new size: %sx%s (bigger=%s)", width, height, bigger)
self.set_screen_size(width, height, bigger)
log("client requesting new size: %sx%s", width, height)
self.set_screen_size(width, height)
log.info("received updated display dimensions")
log.info(f"client display size is {width}x{height}")
log_screen_sizes(width, height, ss.screen_sizes)
Expand Down
2 changes: 0 additions & 2 deletions xpra/server/source/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def init_state(self) -> None:
self.desktop_fullscreen : bool = False
self.screen_sizes : list = []
self.monitors : dict[int,Any] = {}
self.screen_resize_bigger : bool = True
self.desktops : int = 1
self.desktop_names : tuple[str, ...] = ()
self.show_desktop_allowed : bool = False
Expand Down Expand Up @@ -68,7 +67,6 @@ def parse_client_caps(self, c : typedict) -> None:
self.desktop_mode_size = c.intpair("desktop_mode_size")
self.desktop_size_unscaled = c.intpair("desktop_size.unscaled")
self.desktop_fullscreen = c.boolget("desktop-fullscreen")
self.screen_resize_bigger = c.boolget("screen-resize-bigger", True)
self.set_screen_sizes(c.tupleget("screen_sizes"))
self.set_monitors(c.dictget("monitors"))
desktop_names = tuple(str(x) for x in c.tupleget("desktop.names"))
Expand Down
4 changes: 2 additions & 2 deletions xpra/x11/desktop/desktop_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def configure_best_screen_size(self) -> tuple[int,int]:
if w<=0 or h<=0 or w>=32768 or h>=32768:
screenlog("configure_best_screen_size() client requested an invalid desktop mode size: %s", requested_size)
return root_w, root_h
return self.set_screen_size(w, h, ss.screen_resize_bigger)
return self.set_screen_size(w, h)

def resize(self, w:int, h:int) -> None:
geomlog("resize(%i, %i)", w, h)
Expand All @@ -91,7 +91,7 @@ def do_resize(self) -> None:
try:
with xsync:
ow, oh = RandR.get_screen_size()
w, h = self.set_screen_size(rw, rh, False)
w, h = self.set_screen_size(rw, rh)
if (ow, oh) == (w, h):
#this is already the resolution we have,
#but the client has other ideas,
Expand Down
6 changes: 3 additions & 3 deletions xpra/x11/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def get_window_info(self, window) -> dict[str,Any]:
##########################################################################
# Manage the virtual screen:
#
def set_screen_size(self, desired_w:int, desired_h:int, bigger=True):
def set_screen_size(self, desired_w:int, desired_h:int):
#clamp all window models to the new screen size:
for window in tuple(self._window_to_id.keys()):
if window.is_tray() or window.is_OR():
Expand All @@ -329,11 +329,11 @@ def set_screen_size(self, desired_w:int, desired_h:int, bigger=True):
with xlog:
d16 = X11RandR.is_dummy16()
screenlog("set_screen_size%s randr=%s, randr_exact_size=%s, is_dummy16()=%s",
(desired_w, desired_h, bigger), self.randr, self.randr_exact_size, d16)
(desired_w, desired_h), self.randr, self.randr_exact_size, d16)
if DUMMY_MONITORS and self.randr and self.randr_exact_size and d16:
if self.mirror_client_monitor_layout():
return desired_w, desired_h
return super().set_screen_size(desired_w, desired_h, bigger)
return super().set_screen_size(desired_w, desired_h)


def set_screen_geometry_attributes(self, w:int, h:int) -> None:
Expand Down
58 changes: 20 additions & 38 deletions xpra/x11/x11_server_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ def configure_best_screen_size(self):
if not self.randr:
return root_w, root_h
sss = tuple(x for x in self._server_sources.values() if x.ui_client)
bigger = True
max_w, max_h = 0, 0
min_w, min_h = 16384, 16384
client_sizes = {}
Expand All @@ -570,32 +569,27 @@ def configure_best_screen_size(self):
min_w = min(min_w, w)
if h>0:
min_h = min(min_h, h)
bigger = bigger and ss.screen_resize_bigger
client_sizes[ss.uuid] = size
if len(client_sizes)>1:
screenlog.info("screen used by %i clients:", len(client_sizes))
for uuid, size in client_sizes.items():
screenlog.info("* %s: %s", uuid, size)
bigger = True
if bigger:
w, h = max_w, max_h
else:
w, h = min_w, min_h
screenlog("current server resolution is %ix%i", root_w, root_h)
screenlog("maximum client resolution is %ix%i", max_w, max_h)
screenlog("minimum client resolution is %ix%i", min_w, min_h)
screenlog("want: %s, so using %ix%i", "bigger" if bigger else "smaller", w, h)
w, h = max_w, max_h
screenlog("using %ix%i", w, h)
if w<=0 or h<=0:
#invalid - use fallback
return root_w, root_h
return self.set_screen_size(w, h, bigger)
return self.set_screen_size(w, h)

def get_best_screen_size(self, desired_w:int, desired_h:int, bigger:bool=True):
r = self.do_get_best_screen_size(desired_w, desired_h, bigger)
screenlog("get_best_screen_size%s=%s", (desired_w, desired_h, bigger), r)
def get_best_screen_size(self, desired_w:int, desired_h:int):
r = self.do_get_best_screen_size(desired_w, desired_h)
screenlog("get_best_screen_size%s=%s", (desired_w, desired_h), r)
return r

def do_get_best_screen_size(self, desired_w:int, desired_h:int, bigger:bool=True):
def do_get_best_screen_size(self, desired_w:int, desired_h:int):
if not self.randr:
return desired_w, desired_h
screen_sizes = self.get_all_screen_sizes()
Expand All @@ -619,34 +613,22 @@ def do_get_best_screen_size(self, desired_w:int, desired_h:int, bigger:bool=True
#re-query:
screen_sizes = self.get_all_screen_sizes()
#try to find the best screen size to resize to:
new_size = None
closest = {}
for w,h in screen_sizes:
if (w<desired_w)==bigger or (h<desired_h)==bigger:
distance = abs(desired_w*desired_h - w*h)
closest[distance] = (w, h)
continue #size is too small/big for client
if new_size:
ew,eh = new_size #pylint: disable=unpacking-non-sequence
if (ew*eh<w*h)==bigger:
continue #we found a better (smaller/bigger) candidate already
new_size = w,h
if not new_size:
distance = abs(desired_w*desired_h - w*h)
closest[distance] = (w, h)
if not closest:
screenlog.warn("Warning: no matching resolution found for %sx%s", desired_w, desired_h)
if closest:
min_dist = sorted(closest.keys())[0]
new_size = closest[min_dist]
screenlog.warn(" using %sx%s instead", *new_size)
else:
root_w, root_h = self.root_window.get_size()
return root_w, root_h
screenlog("best %s resolution for client(%sx%s) is: %s",
["smaller", "bigger"][bigger], desired_w, desired_h, new_size)
root_w, root_h = self.root_window.get_size()
return root_w, root_h
min_dist = sorted(closest.keys())[0]
new_size = closest[min_dist]
screenlog("best %s resolution for client(%sx%s) is: %s", desired_w, desired_h, new_size)
w, h = new_size
return w, h

def set_screen_size(self, desired_w:int, desired_h:int, bigger:bool=True):
screenlog("set_screen_size%s", (desired_w, desired_h, bigger))
def set_screen_size(self, desired_w:int, desired_h:int):
screenlog("set_screen_size%s", (desired_w, desired_h))
root_w, root_h = self.root_window.get_geometry()[2:4]
if not self.randr:
return root_w,root_h
Expand All @@ -655,8 +637,8 @@ def set_screen_size(self, desired_w:int, desired_h:int, bigger:bool=True):
#clients may supply "xdpi" and "ydpi" (v0.15 onwards), or just "dpi", or nothing...
xdpi = self.xdpi or self.dpi
ydpi = self.ydpi or self.dpi
screenlog("set_screen_size(%s, %s, %s) xdpi=%s, ydpi=%s",
desired_w, desired_h, bigger, xdpi, ydpi)
screenlog("set_screen_size(%s, %s) xdpi=%s, ydpi=%s",
desired_w, desired_h, xdpi, ydpi)
wmm, hmm = 0, 0
if xdpi<=0 or ydpi<=0:
#use some sane defaults: either the command line option, or fallback to 96
Expand Down Expand Up @@ -697,7 +679,7 @@ def set_screen_size(self, desired_w:int, desired_h:int, bigger:bool=True):
self.set_dpi(xdpi, ydpi)

#try to find the best screen size to resize to:
w, h = self.get_best_screen_size(desired_w, desired_h, bigger)
w, h = self.get_best_screen_size(desired_w, desired_h)

ui_clients = [s for s in self._server_sources.values() if s.ui_client]
source = None
Expand Down

0 comments on commit 15a72ea

Please sign in to comment.