Skip to content

Commit

Permalink
use a utility method to simplify the code - reduces imports, added bo…
Browse files Browse the repository at this point in the history
…nus: prevents race conditions too
  • Loading branch information
totaam committed Apr 12, 2021
1 parent b00992f commit b056e6d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 51 deletions.
7 changes: 7 additions & 0 deletions xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,13 @@ def send_encoding_caps():
server_source.send_hello(capabilities)


######################################################################
# utility method:
def window_sources(self):
from xpra.server.source.windows_mixin import WindowsMixin #pylint: disable=import-outside-toplevel
return tuple(x for x in self._server_sources.values() if isinstance(x, WindowsMixin))


######################################################################
# info:
def _process_info_request(self, proto, packet):
Expand Down
5 changes: 2 additions & 3 deletions xpra/server/shadow/shadow_server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,8 @@ def cmpv(lcd):
from PIL import Image
img = Image.frombuffer("RGBA", (w, h), pixels, "raw", "BGRA", 0, 1)
img.save("cursor-%#x.png" % serial, format="PNG")
for ss in self._server_sources.values():
if hasattr(ss, "send_cursor"):
ss.send_cursor()
for ss in self.window_sources():
ss.send_cursor()

def do_get_cursor_data(self):
#this method is overriden in subclasses with platform specific code
Expand Down
8 changes: 3 additions & 5 deletions xpra/x11/desktop_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from xpra.platform.paths import get_icon, get_icon_filename
from xpra.platform.gui import get_wm_name
from xpra.server import server_features
from xpra.server.source.windows_mixin import WindowsMixin
from xpra.gtk_common.gobject_util import one_arg_signal, no_arg_signal
from xpra.gtk_common.error import XError
from xpra.gtk_common.gtk_util import get_screen_sizes, get_root_size
Expand Down Expand Up @@ -489,10 +488,9 @@ def _window_resized_signaled(self, window):
wid = self._window_to_id[window]
x, y, w, h = window.get_geometry()
geomlog("window_resized_signaled(%s) geometry=%s", window, (x, y, w, h))
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.resize_window(wid, window, w, h)
ss.damage(wid, window, 0, 0, w, h)
for ss in self.window_sources():
ss.resize_window(wid, window, w, h)
ss.damage(wid, window, 0, 0, w, h)


def send_initial_windows(self, ss, sharing=False):
Expand Down
51 changes: 20 additions & 31 deletions xpra/x11/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from xpra.os_util import memoryview_to_bytes, strtobytes, bytestostr, monotonic_time
from xpra.common import CLOBBER_UPGRADE, MAX_WINDOW_SIZE
from xpra.server import server_features
from xpra.server.source.windows_mixin import WindowsMixin
from xpra.gtk_common.gobject_util import one_arg_signal
from xpra.gtk_common.gtk_util import get_default_root_window, get_pixbuf_from_data
from xpra.x11.common import Unmanageable
Expand Down Expand Up @@ -490,7 +489,7 @@ def get_transient_for(self, window):
def parse_hello_ui_window_settings(self, ss, _caps):
#FIXME: with multiple users, don't set any frame size?
frame = None
if isinstance(ss, WindowsMixin):
if ss in self.window_sources():
window_frame_sizes = ss.window_frame_sizes
framelog("parse_hello_ui_window_settings: client window_frame_sizes=%s", window_frame_sizes)
if window_frame_sizes:
Expand Down Expand Up @@ -574,9 +573,7 @@ def _x11_property_changed(self, window, event):
#name, dtype, dformat, value = event
metadata = {"x11-property" : event}
wid = self._window_to_id[window]
for ss in self._server_sources.values():
if not isinstance(ss, WindowsMixin):
continue
for ss in self.window_sources():
ms = getattr(ss, "metadata_supported", ())
if "x11-property" in ms:
ss.send("window-metadata", wid, metadata)
Expand Down Expand Up @@ -626,8 +623,7 @@ def size_notify_clients(self, window, lcce=-1):
return
x, y, nw, nh = self._desktop_manager.window_geometry(window)
resize_counter = self._desktop_manager.get_resize_counter(window, 1)
wsources = [ss for ss in self._server_sources.values() if isinstance(ss, WindowsMixin)]
for ss in wsources:
for ss in self.window_sources():
ss.move_resize_window(wid, window, x, y, nw, nh, resize_counter)
#refresh to ensure the client gets the new window contents:
#TODO: to save bandwidth, we should compare the dimensions and skip the refresh
Expand Down Expand Up @@ -703,9 +699,8 @@ def _or_window_geometry_changed(self, window, _pspec=None):
return
geomlog("or_window_geometry_changed: %s (window=%s)", geom, window)
wid = self._window_to_id[window]
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.or_window_geometry(wid, window, x, y, w, h)
for ss in self.window_sources():
ss.or_window_geometry(wid, window, x, y, w, h)


def add_control_commands(self):
Expand All @@ -725,9 +720,8 @@ def show_all_windows(self):

def _show_desktop(self, wm, show):
log("show_desktop(%s, %s)", wm, show)
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.show_desktop(show)
for ss in self.window_sources():
ss.show_desktop(show)


def _focus(self, server_source, wid, modifiers):
Expand Down Expand Up @@ -792,9 +786,8 @@ def _send_new_or_window_packet(self, window):

def _send_new_tray_window_packet(self, wid, window):
ww, wh = window.get_dimensions()
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.new_tray(wid, window, ww, wh)
for ss in self.window_sources():
ss.new_tray(wid, window, ww, wh)
self.refresh_window(window)


Expand All @@ -816,9 +809,8 @@ def _window_grab(self, window, event):
if grab_id<0 or self._has_grab==grab_id:
return
self._has_grab = grab_id
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.pointer_grab(self._has_grab)
for ss in self.window_sources():
ss.pointer_grab(self._has_grab)

def _window_ungrab(self, window, event):
grab_id = self._window_to_id.get(window, -1)
Expand All @@ -827,9 +819,8 @@ def _window_ungrab(self, window, event):
if not self._has_grab:
return
self._has_grab = 0
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.pointer_ungrab(grab_id)
for ss in self.window_sources():
ss.pointer_ungrab(grab_id)


def _initiate_moveresize(self, window, event):
Expand All @@ -838,7 +829,7 @@ def _initiate_moveresize(self, window, event):
#x_root, y_root, direction, button, source_indication = event.data
wid = self._window_to_id[window]
#find clients that handle windows:
wsources = [ss for ss in self._server_sources.values() if isinstance(ss, WindowsMixin)]
wsources = self.window_sources()
if not wsources:
return
#prefer the "UI driver" if we find it:
Expand All @@ -858,9 +849,8 @@ def _restack_window(self, window, detail, sibling):
self.last_raised = None
if detail==0 and self._has_focus==wid: #Above=0
return
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.restack_window(wid, window, detail, sibling)
for ss in self.window_sources():
ss.restack_window(wid, window, detail, sibling)


def _set_window_state(self, proto, wid, window, new_window_state):
Expand Down Expand Up @@ -956,9 +946,8 @@ def _process_unmap_window(self, proto, packet):
self._set_window_state(proto, wid, window, packet[3])
if self._desktop_manager.is_shown(window):
geomlog("client %s unmapped window %s - %s", ss, wid, window)
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.unmap_window(wid, window)
for ss in self.window_sources():
ss.unmap_window(wid, window)
window.unmap()
iconified = len(packet)>=3 and bool(packet[2])
if iconified and not window.get_property("iconic"):
Expand Down Expand Up @@ -1049,8 +1038,8 @@ def _process_configure_window(self, proto, packet):
if resized and SHARING_SYNC_SIZE:
#try to ensure this won't trigger a resizing loop:
counter = max(0, resize_counter-1)
for s in self._server_sources.values():
if s!=ss and isinstance(s, WindowsMixin):
for s in self.window_sources():
if s!=ss:
s.resize_window(wid, window, aw, ah, resize_counter=counter)
damage |= owx!=ax or owy!=ay or resized
if not shown and not skip_geometry:
Expand Down
20 changes: 8 additions & 12 deletions xpra/x11/x11_server_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from xpra.gtk_common.error import XError, xswallow, xsync, xlog, trap, verify_sync
from xpra.gtk_common.gtk_util import get_default_root_window
from xpra.server.server_uuid import save_uuid, get_uuid
from xpra.server.source.windows_mixin import WindowsMixin
from xpra.x11.vfb_util import parse_resolution
from xpra.x11.fakeXinerama import find_libfakeXinerama, save_fakeXinerama_config, cleanup_fakeXinerama
from xpra.x11.gtk_x11.prop import prop_get, prop_set
Expand Down Expand Up @@ -788,9 +787,8 @@ def do_xpra_cursor_event(self, event):
return
cursorlog("cursor_event: %s", event)
self.last_cursor_serial = event.cursor_serial
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
ss.send_cursor()
for ss in self.window_sources():
ss.send_cursor()


def _motion_signaled(self, model, event):
Expand All @@ -815,10 +813,9 @@ def do_xpra_xkb_event(self, event):
#this method is a catch-all for events on windows we don't manage,
#so we use wid=0 for that:
wid = 0
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
name = strtobytes(event.bell_name or "")
ss.bell(wid, event.device, event.percent, event.pitch, event.duration, event.bell_class, event.bell_id, name)
for ss in self.window_sources():
name = strtobytes(event.bell_name or "")
ss.bell(wid, event.device, event.percent, event.pitch, event.duration, event.bell_class, event.bell_id, name)


def _bell_signaled(self, wm, event):
Expand All @@ -829,10 +826,9 @@ def _bell_signaled(self, wm, event):
if event.window!=get_default_root_window() and event.window_model is not None:
wid = self._window_to_id.get(event.window_model, 0)
log("_bell_signaled(%s,%r) wid=%s", wm, event, wid)
for ss in self._server_sources.values():
if isinstance(ss, WindowsMixin):
name = strtobytes(event.bell_name or "")
ss.bell(wid, event.device, event.percent, event.pitch, event.duration, event.bell_class, event.bell_id, name)
for ss in self.window_sources():
name = strtobytes(event.bell_name or "")
ss.bell(wid, event.device, event.percent, event.pitch, event.duration, event.bell_class, event.bell_id, name)


def get_screen_number(self, _wid):
Expand Down

0 comments on commit b056e6d

Please sign in to comment.