Skip to content

Commit

Permalink
#1247 refactor screen detection and logging code so we can re-use it …
Browse files Browse the repository at this point in the history
…in the desktop server, hook multiple screens for display (but event handling still goes to the primary screen..)

git-svn-id: https://xpra.org/svn/Xpra/trunk@13580 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 6, 2016
1 parent 2c6af55 commit c12aecb
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 69 deletions.
62 changes: 3 additions & 59 deletions src/xpra/client/gtk_base/gtk_client_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from xpra.client.gtk_base.gtk_keyboard_helper import GTKKeyboardHelper
from xpra.client.gtk_base.session_info import SessionInfo
from xpra.platform.paths import get_icon_filename
from xpra.platform.gui import get_window_frame_sizes, get_window_frame_size, system_bell, get_workarea, get_workareas, get_fixed_cursor_size, get_menu_support_function, get_wm_name
from xpra.platform.gui import get_window_frame_sizes, get_window_frame_size, system_bell, get_fixed_cursor_size, get_menu_support_function, get_wm_name

missing_cursor_names = set()

Expand Down Expand Up @@ -425,64 +425,8 @@ def has_transparency(self):


def get_screen_sizes(self, xscale=1, yscale=1):
def xs(v):
return iround(v/xscale)
def ys(v):
return iround(v/yscale)
def swork(*workarea):
return xs(workarea[0]), ys(workarea[1]), xs(workarea[2]), ys(workarea[3])
display = display_get_default()
i=0
screen_sizes = []
n_screens = display.get_n_screens()
screenlog("get_screen_sizes(%f, %f) found %s screens", xscale, yscale, n_screens)
while i<n_screens:
screen = display.get_screen(i)
j = 0
monitors = []
workareas = []
#native "get_workareas()" is only valid for a single screen (but describes all the monitors)
#and it is only implemented on win32 right now
#other platforms only implement "get_workarea()" instead, which is reported against the screen
n_monitors = screen.get_n_monitors()
screenlog(" screen %s has %s monitors", i, n_monitors)
if n_screens==1:
workareas = get_workareas()
if workareas and len(workareas)!=n_monitors:
screenlog(" workareas: %s", workareas)
screenlog(" number of monitors does not match number of workareas!")
workareas = []
while j<screen.get_n_monitors():
geom = screen.get_monitor_geometry(j)
plug_name = ""
if hasattr(screen, "get_monitor_plug_name"):
plug_name = screen.get_monitor_plug_name(j) or ""
wmm = -1
if hasattr(screen, "get_monitor_width_mm"):
wmm = screen.get_monitor_width_mm(j)
hmm = -1
if hasattr(screen, "get_monitor_height_mm"):
hmm = screen.get_monitor_height_mm(j)
monitor = [plug_name, xs(geom.x), ys(geom.y), xs(geom.width), ys(geom.height), wmm, hmm]
screenlog(" monitor %s: %s", j, monitor)
if workareas:
w = workareas[j]
monitor += list(swork(*w))
monitors.append(tuple(monitor))
j += 1
work_x, work_y, work_width, work_height = swork(0, 0, screen.get_width(), screen.get_height())
workarea = get_workarea()
if workarea:
work_x, work_y, work_width, work_height = swork(*workarea)
screenlog(" workarea=%s", workarea)
item = (screen.make_display_name(), xs(screen.get_width()), ys(screen.get_height()),
screen.get_width_mm(), screen.get_height_mm(),
monitors,
work_x, work_y, work_width, work_height)
screenlog(" screen %s: %s", i, item)
screen_sizes.append(item)
i += 1
return screen_sizes
from xpra.gtk_common.gtk_util import get_screen_sizes
return get_screen_sizes(xscale, yscale)


def reset_windows_cursors(self, *args):
Expand Down
63 changes: 63 additions & 0 deletions src/xpra/gtk_common/gtk_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os.path

import array
from xpra.util import iround
from xpra.os_util import strtobytes
from xpra.gtk_common.gobject_compat import import_gtk, import_gdk, import_pixbufloader, import_pango, import_cairo, import_gobject, is_gtk3
gtk = import_gtk()
Expand All @@ -20,6 +21,7 @@
from xpra.log import Logger
log = Logger("gtk", "util")
traylog = Logger("gtk", "tray")
screenlog = Logger("gtk", "screen")


SHOW_ALL_VISUALS = False
Expand Down Expand Up @@ -474,6 +476,67 @@ def get_screens_info():
info[i] = get_screen_info(display, screen)
return info

def get_screen_sizes(xscale=1, yscale=1):
from xpra.platform.gui import get_workarea, get_workareas
def xs(v):
return iround(v/xscale)
def ys(v):
return iround(v/yscale)
def swork(*workarea):
return xs(workarea[0]), ys(workarea[1]), xs(workarea[2]), ys(workarea[3])
display = display_get_default()
i=0
screen_sizes = []
n_screens = display.get_n_screens()
screenlog("get_screen_sizes(%f, %f) found %s screens", xscale, yscale, n_screens)
while i<n_screens:
screen = display.get_screen(i)
j = 0
monitors = []
workareas = []
#native "get_workareas()" is only valid for a single screen (but describes all the monitors)
#and it is only implemented on win32 right now
#other platforms only implement "get_workarea()" instead, which is reported against the screen
n_monitors = screen.get_n_monitors()
screenlog(" screen %s has %s monitors", i, n_monitors)
if n_screens==1:
workareas = get_workareas()
if workareas and len(workareas)!=n_monitors:
screenlog(" workareas: %s", workareas)
screenlog(" number of monitors does not match number of workareas!")
workareas = []
while j<screen.get_n_monitors():
geom = screen.get_monitor_geometry(j)
plug_name = ""
if hasattr(screen, "get_monitor_plug_name"):
plug_name = screen.get_monitor_plug_name(j) or ""
wmm = -1
if hasattr(screen, "get_monitor_width_mm"):
wmm = screen.get_monitor_width_mm(j)
hmm = -1
if hasattr(screen, "get_monitor_height_mm"):
hmm = screen.get_monitor_height_mm(j)
monitor = [plug_name, xs(geom.x), ys(geom.y), xs(geom.width), ys(geom.height), wmm, hmm]
screenlog(" monitor %s: %s", j, monitor)
if workareas:
w = workareas[j]
monitor += list(swork(*w))
monitors.append(tuple(monitor))
j += 1
work_x, work_y, work_width, work_height = swork(0, 0, screen.get_width(), screen.get_height())
workarea = get_workarea()
if workarea:
work_x, work_y, work_width, work_height = swork(*workarea)
screenlog(" workarea=%s", workarea)
item = (screen.make_display_name(), xs(screen.get_width()), ys(screen.get_height()),
screen.get_width_mm(), screen.get_height_mm(),
monitors,
work_x, work_y, work_width, work_height)
screenlog(" screen %s: %s", i, item)
screen_sizes.append(item)
i += 1
return screen_sizes

def get_screen_info(display, screen):
info = {}
try:
Expand Down
36 changes: 26 additions & 10 deletions src/xpra/x11/desktop_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import gobject
import socket

from xpra.util import updict
from xpra.util import updict, log_screen_sizes
from xpra.platform.gui import get_wm_name
from xpra.gtk_common.gobject_util import one_arg_signal, no_arg_signal
from xpra.gtk_common.error import xswallow
from xpra.gtk_common.gtk_util import get_screen_sizes, get_root_size
from xpra.x11.gtk2.models.model_stub import WindowModelStub
from xpra.x11.gtk2.gdk_bindings import (
add_catchall_receiver, #@UnresolvedImport
Expand Down Expand Up @@ -160,8 +161,12 @@ def __init__(self):
def x11_init(self):
X11ServerBase.x11_init(self)
assert init_x11_filter() is True
root = gtk.gdk.get_default_root_window()
add_event_receiver(root, self)
display = gtk.gdk.display_get_default()
screens = display.get_n_screens()
for n in range(screens):
screen = display.get_screen(n)
root = screen.get_root_window()
add_event_receiver(root, self)
add_catchall_receiver("xpra-motion-event", self)
add_catchall_receiver("xpra-xkb-event", self)
X11Keyboard.selectBellNotification(True)
Expand All @@ -173,6 +178,13 @@ def do_cleanup(self, *args):
with xswallow:
cleanup_all_event_receivers()

def print_screen_info(self):
X11ServerBase.print_screen_info(self)
root_w, root_h = get_root_size()
sss = get_screen_sizes()
log_screen_sizes(root_w, root_h, sss)


def get_server_mode(self):
return "X11 desktop"

Expand All @@ -196,13 +208,17 @@ def make_hello(self, source):
def load_existing_windows(self):
#at present, just one window is forwarded:
#the root window covering the whole display
root = gtk.gdk.get_default_root_window()
model = DesktopModel(root)
model.setup()
windowlog("adding root window model %s", model)
X11ServerBase._add_new_window_common(self, model)
model.managed_connect("client-contents-changed", self._contents_changed)
model.managed_connect("resized", self._window_resized_signaled)
display = gtk.gdk.display_get_default()
screens = display.get_n_screens()
for n in range(screens):
screen = display.get_screen(n)
root = screen.get_root_window()
model = DesktopModel(root)
model.setup()
windowlog("adding root window model %s", model)
X11ServerBase._add_new_window_common(self, model)
model.managed_connect("client-contents-changed", self._contents_changed)
model.managed_connect("resized", self._window_resized_signaled)


def _window_resized_signaled(self, window, *args):
Expand Down

0 comments on commit c12aecb

Please sign in to comment.