Skip to content

Commit

Permalink
make force_size_constraints re-usable
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Aug 1, 2024
1 parent ceff3f7 commit 272016d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions xpra/client/gtk3/window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from xpra.gtk.pixbuf import get_pixbuf_from_data
from xpra.gtk.keymap import KEY_TRANSLATIONS
from xpra.common import (
MoveResize,
MoveResize, force_size_constraint,
MOVERESIZE_DIRECTION_STRING, SOURCE_INDICATION_STRING, WORKSPACE_UNSET,
WORKSPACE_ALL, WORKSPACE_NAMES,
)
Expand Down Expand Up @@ -1983,7 +1983,7 @@ def do_moveresize(self) -> None:
if self._client.readonly:
# change size-constraints first,
# so the resize can be honoured:
sc = typedict(self._force_size_constraint(w, h))
sc = typedict(force_size_constraint(w, h))
self._metadata.update(sc)
self.set_metadata(sc)
if move and resize:
Expand Down
61 changes: 27 additions & 34 deletions xpra/client/gui/window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from xpra.client.gui.widget_base import ClientWidgetBase
from xpra.client.gui.window_backing_base import fire_paint_callbacks
from xpra.net.common import PacketElement
from xpra.common import GravityStr, WORKSPACE_UNSET, WORKSPACE_NAMES
from xpra.common import GravityStr, WORKSPACE_UNSET, WORKSPACE_NAMES, force_size_constraint
from xpra.util.parsing import scaleup_value, scaledown_value
from xpra.util.system import is_Wayland
from xpra.util.objects import typedict
Expand Down Expand Up @@ -290,22 +290,13 @@ def is_OR(self) -> bool:
def update_metadata(self, metadata: typedict) -> None:
metalog("update_metadata(%s)", metadata)
if self._client.readonly:
metadata.update(self._force_size_constraint(*self._size))
metadata.update(force_size_constraint(*self._size))
self._metadata.update(metadata)
try:
self.set_metadata(metadata)
except Exception:
metalog.warn("failed to set window metadata to '%s'", metadata, exc_info=True)

def _force_size_constraint(self, *size) -> dict[str, dict[str, Any]]:
return {
"size-constraints": {
"maximum-size": size,
"minimum-size": size,
"base-size": size,
},
}

def _get_window_title(self, metadata) -> str:
try:
title = self._client.title.replace("\0", "")
Expand Down Expand Up @@ -610,30 +601,32 @@ def set_size_constraints(self, size_constraints: typedict, max_window_size: tupl
):
v = size_constraints.intpair(a)
geomlog("intpair(%s)=%s", a, v)
if v:
v1, v2 = v
if a == "maximum-size" and v1 >= 16384 and v2 >= 16384 and WIN32:
# causes problems, see #2714, #3533
if not v:
continue
v1, v2 = v
if a == "maximum-size" and v1 >= 16384 and v2 >= 16384 and WIN32:
# causes problems, see #2714, #3533
continue
sv1 = client.sx(v1)
sv2 = client.sy(v2)
if a in ("base-size", "increment"):
# rounding is not allowed for these values
fsv1 = client.fsx(v1)
fsv2 = client.fsy(v2)

def closetoint(value):
# tolerate some rounding error:
# (ie: 2:3 scaling may not give an integer without a tiny bit of rounding)
return abs(round(value) - value) < 0.00001

if not closetoint(fsv1) or not closetoint(fsv2):
# the scaled value is not close to an int,
# so we can't honour it:
geomlog("cannot honour '%s' due to scaling, scaled values are not both integers: %s, %s",
a, fsv1, fsv2)
continue
sv1 = client.sx(v1)
sv2 = client.sy(v2)
if a in ("base-size", "increment"):
# rounding is not allowed for these values
fsv1 = client.fsx(v1)
fsv2 = client.fsy(v2)

def closetoint(value):
# tolerate some rounding error:
# (ie: 2:3 scaling may not give an integer without a tiny bit of rounding)
return abs(round(value) - value) < 0.00001

if not closetoint(fsv1) or not closetoint(fsv2):
# the scaled value is not close to an int,
# so we can't honour it:
geomlog("cannot honour '%s' due to scaling, scaled values are not both integers: %s, %s",
a, fsv1, fsv2)
continue
hints[h1], hints[h2] = sv1, sv2
hints[h1] = sv1
hints[h2] = sv2
if not OSX:
for (a, h) in (
("minimum-aspect-ratio", "min_aspect"),
Expand Down
15 changes: 13 additions & 2 deletions xpra/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

# noinspection PyPep8

import binascii
import os
import binascii
from enum import Enum, IntEnum
from typing import Final, Protocol, TypeAlias
from typing import Final, Protocol, TypeAlias, Any
from collections.abc import Callable, Sized, MutableSequence

from xpra.util.env import envint, envbool
Expand Down Expand Up @@ -62,6 +62,17 @@ def get_default_video_max_size() -> tuple[int, int]:
return 4096, 4096


def force_size_constraint(width: int, height: int) -> dict[str, dict[str, Any]]:
size = width, height
return {
"size-constraints": {
"maximum-size": size,
"minimum-size": size,
"base-size": size,
},
}


VIDEO_MAX_SIZE = get_default_video_max_size()


Expand Down
8 changes: 2 additions & 6 deletions xpra/server/source/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from xpra.util.str_fn import bytestostr, memoryview_to_bytes
from xpra.util.objects import typedict
from xpra.util.env import envint, envbool
from xpra.common import NotificationID, DEFAULT_METADATA_SUPPORTED
from xpra.common import NotificationID, DEFAULT_METADATA_SUPPORTED, force_size_constraints
from xpra.log import Logger

GLib = gi_import("GLib")
Expand Down Expand Up @@ -397,11 +397,7 @@ def _make_metadata(self, window, propname: str, skip_defaults=False) -> dict[str
if self.readonly:
metalog("overriding size-constraints for readonly mode")
size = window.get_dimensions()
metadata["size-constraints"] = {
"maximum-size": size,
"minimum-size": size,
"base-size": size,
}
metadata["size-constraints"] = force_size_constraints(*size)
return metadata

def new_tray(self, wid: int, window, w: int, h: int) -> None:
Expand Down

0 comments on commit 272016d

Please sign in to comment.