Skip to content

Commit

Permalink
#853 move window models to GTK-version agnostic location and start po…
Browse files Browse the repository at this point in the history
…rting them

git-svn-id: https://xpra.org/svn/Xpra/trunk@20759 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Oct 22, 2018
1 parent 71acded commit 0d2c021
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 60 deletions.
4 changes: 2 additions & 2 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 @@
new_Cursor_for_display, new_Cursor_from_pixbuf, icon_theme_get_default, \
pixbuf_new_from_file, display_get_default, screen_get_default, get_pixbuf_from_data, \
get_default_root_window, get_root_size, get_xwindow, image_new_from_stock, \
get_screen_sizes, Window, \
get_screen_sizes, GDKWindow, \
CLASS_INPUT_ONLY, \
INTERP_BILINEAR, WINDOW_TOPLEVEL, DIALOG_MODAL, DESTROY_WITH_PARENT, MESSAGE_INFO, BUTTONS_CLOSE, ICON_SIZE_BUTTON, GRAB_STATUS_STRING, \
BUTTON_PRESS_MASK, BUTTON_RELEASE_MASK, POINTER_MOTION_MASK, POINTER_MOTION_HINT_MASK, ENTER_NOTIFY_MASK, LEAVE_NOTIFY_MASK
Expand Down Expand Up @@ -1154,7 +1154,7 @@ def get_group_leader(self, wid, metadata, _override_redirect):
title = u"%s group leader for %s" % (self.session_name or u"Xpra", pid)
#group_leader_window = gdk.Window(None, 1, 1, gdk.WINDOW_TOPLEVEL, 0, gdk.INPUT_ONLY, title)
#static new(parent, attributes, attributes_mask)
group_leader_window = Window(wclass=CLASS_INPUT_ONLY, title=title)
group_leader_window = GDKWindow(wclass=CLASS_INPUT_ONLY, title=title)
self._ref_to_group_leader[refkey] = group_leader_window
#avoid warning on win32...
if not WIN32:
Expand Down
4 changes: 4 additions & 0 deletions src/xpra/gtk_common/gtk3/gdk_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ cdef void * pyg_boxed_get(v):

cdef GdkWindow *get_gdkwindow(pywindow):
return <GdkWindow*>unwrap(pywindow, Gdk.Window)

def calc_constrained_size(int width, int height, object hints):
log.warn("Warning: calc_constrained_size not implemented yet for GTK3")
return None
10 changes: 6 additions & 4 deletions src/xpra/gtk_common/gtk_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def popup_menu_workaround(*args):
def is_realized(widget):
return widget.get_realized()

def Window(parent=None, width=1, height=1, window_type=gdk.WindowType.TOPLEVEL, event_mask=0, wclass=gdk.WindowWindowClass.INPUT_OUTPUT, title=None, x=None, y=None, visual=None, **kwargs):
def GDKWindow(parent=None, width=1, height=1, window_type=gdk.WindowType.TOPLEVEL, event_mask=0, wclass=gdk.WindowWindowClass.INPUT_OUTPUT, title=None, x=None, y=None, visual=None, **kwargs):
attributes_mask = 0
attributes = gdk.WindowAttr()
if x is not None:
Expand Down Expand Up @@ -124,7 +124,7 @@ def Window(parent=None, width=1, height=1, window_type=gdk.WindowType.TOPLEVEL,
return gdk.Window(parent, attributes, mask)

def make_temp_window(title):
return Window(title=title)
return GDKWindow(title=title)


def get_pixbuf_from_data(rgb_data, has_alpha, w, h, rowstride):
Expand Down Expand Up @@ -251,6 +251,7 @@ def pixbuf_new_from_data(*args):

GDKWINDOW_TEMP = gdk.WindowType.TEMP
GDKWINDOW_TOPLEVEL = gdk.WindowType.TOPLEVEL
GDKWINDOW_CHILD = gdk.WindowType.CHILD

CLASS_INPUT_OUTPUT = gdk.WindowWindowClass.INPUT_OUTPUT
CLASS_INPUT_ONLY = gdk.WindowWindowClass.INPUT_ONLY
Expand Down Expand Up @@ -429,11 +430,11 @@ def wait_for_contents(clipboard, target):
def get_pixbuf_from_data(rgb_data, has_alpha, w, h, rowstride):
return gdk.pixbuf_new_from_data(rgb_data, gdk.COLORSPACE_RGB, has_alpha, 8, w, h, rowstride)

def Window(parent=None, width=1, height=1, window_type=gdk.WINDOW_TOPLEVEL, event_mask=0, wclass=gdk.INPUT_OUTPUT, title=None, x=-1, y=-1, **kwargs):
def GDKWindow(parent=None, width=1, height=1, window_type=gdk.WINDOW_TOPLEVEL, event_mask=0, wclass=gdk.INPUT_OUTPUT, title=None, x=-1, y=-1, **kwargs):
return gdk.Window(parent, width, height, window_type, event_mask, wclass, title, x, y, **kwargs)

def make_temp_window(title):
return Window(title=title)
return GDKWindow(title=title)

def get_pixbuf_from_window(window, x, y, w, h):
pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, False, 8, w, h)
Expand Down Expand Up @@ -529,6 +530,7 @@ def cairo_set_source_pixbuf(cr, pixbuf, x, y):

GDKWINDOW_TEMP = gdk.WINDOW_TEMP
GDKWINDOW_TOPLEVEL = gdk.WINDOW_TOPLEVEL
GDKWINDOW_CHILD = gdk.WINDOW_CHILD

CLASS_INPUT_OUTPUT = gdk.INPUT_OUTPUT
CLASS_INPUT_ONLY = gdk.INPUT_ONLY
Expand Down
6 changes: 2 additions & 4 deletions src/xpra/x11/desktop_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import gobject
import socket

from xpra.os_util import get_generic_os_name, PYTHON3
if PYTHON3:
raise ImportError("desktop server needs porting to python3 / gtk3")
from xpra.os_util import get_generic_os_name
from xpra.util import updict, log_screen_sizes
from xpra.platform.paths import get_icon
from xpra.platform.gui import get_wm_name
Expand All @@ -31,7 +29,7 @@
)
from xpra.x11.bindings.window_bindings import X11WindowBindings #@UnresolvedImport
from xpra.x11.xroot_props import XRootPropWatcher
from xpra.x11.gtk2.window_damage import WindowDamageHandler
from xpra.x11.gtk_x11.window_damage import WindowDamageHandler
X11Window = X11WindowBindings()
from xpra.x11.bindings.keyboard_bindings import X11KeyboardBindings #@UnresolvedImport
X11Keyboard = X11KeyboardBindings()
Expand Down
4 changes: 2 additions & 2 deletions src/xpra/x11/gtk2/composite.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This file is part of Xpra.
# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
# Copyright (C) 2012-2016 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2012-2018 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import gobject

from xpra.log import Logger
from xpra.x11.gtk2.window_damage import WindowDamageHandler
from xpra.x11.gtk_x11.window_damage import WindowDamageHandler
log = Logger("x11", "window")

from xpra.gtk_common.gobject_util import one_arg_signal, AutoPropGObjectMixin
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/x11/gtk2/wm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from xpra.x11.gtk_x11.selection import ManagerSelection
from xpra.x11.gtk2.world_window import WorldWindow
from xpra.x11.gtk2.window import WindowModel, configure_bits
from xpra.x11.gtk2.gdk_bindings import (
from xpra.x11.gtk_x11.gdk_bindings import (
add_event_receiver, #@UnresolvedImport
add_fallback_receiver, remove_fallback_receiver, #@UnresolvedImport
get_children, #@UnresolvedImport
Expand Down
16 changes: 14 additions & 2 deletions src/xpra/x11/gtk_x11/gdk_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@
from xpra.gtk_common.gobject_compat import is_gtk3, try_import_GdkX11
if is_gtk3():
try_import_GdkX11()
from xpra.x11.gtk3 import gdk_bindings
from xpra.x11.gtk3 import gdk_bindings #@UnresolvedImport, @UnusedImport
else:
from xpra.x11.gtk2 import gdk_bindings
from xpra.x11.gtk2 import gdk_bindings #@UnresolvedImport, @Reimport

get_pywindow = gdk_bindings.get_pywindow
get_xatom = gdk_bindings.get_xatom
add_event_receiver = gdk_bindings.add_event_receiver
remove_event_receiver = gdk_bindings.remove_event_receiver
add_fallback_receiver = gdk_bindings.add_fallback_receiver
remove_fallback_receiver = gdk_bindings.remove_fallback_receiver
get_children = gdk_bindings.get_children
init_x11_filter = gdk_bindings.init_x11_filter
cleanup_x11_filter = gdk_bindings.cleanup_x11_filter
cleanup_all_event_receivers = gdk_bindings.cleanup_all_event_receivers
get_pywindow = gdk_bindings.get_pywindow
get_xvisual = gdk_bindings.get_xvisual
get_parent = gdk_bindings.get_parent

if is_gtk3():
try_import_GdkX11()
from xpra.gtk_common.gtk3 import gdk_bindings #@UnresolvedImport, @UnusedImport, @Reimport
else:
from xpra.gtk_common.gtk2 import gdk_bindings #@UnresolvedImport, @Reimport

get_display_for = gdk_bindings.get_display_for
calc_constrained_size = gdk_bindings.calc_constrained_size
8 changes: 4 additions & 4 deletions src/xpra/x11/gtk_x11/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from xpra.x11.gtk_x11.prop import prop_set, prop_get
from xpra.gtk_common.gobject_compat import import_gdk, import_gobject, is_gtk3
from xpra.gtk_common.gtk_util import (
display_get_default, get_default_root_window, get_xwindow, Window,
display_get_default, get_default_root_window, get_xwindow, GDKWindow,
STRUCTURE_MASK, EXPOSURE_MASK, PROPERTY_CHANGE_MASK,
WINDOW_TOPLEVEL, CLASS_INPUT_OUTPUT
)
Expand Down Expand Up @@ -110,8 +110,8 @@ def undock(window):
log("undocking %s", window)
wxid = get_xwindow(window)
rxid = get_xwindow(root)
X11Window.Unmap(xwid)
X11Window.Reparent(xwid, rxid, 0, 0)
X11Window.Unmap(wxid)
X11Window.Reparent(wxid, rxid, 0, 0)
with xswallow:
owner = X11Window.XGetSelectionOwner(SELECTION)
if owner==get_xwindow(self.tray_window):
Expand Down Expand Up @@ -153,7 +153,7 @@ def setup_tray_window(self):
colormap = screen.get_rgb_colormap()
kwargs["colormap"] = colormap
assert visual is not None, "failed to obtain visual"
self.tray_window = Window(root, width=1, height=1,
self.tray_window = GDKWindow(root, width=1, height=1,
title="Xpra-SystemTray",
visual=visual,
**kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is part of Xpra.
# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
# Copyright (C) 2012-2016 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2012-2018 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

Expand All @@ -9,7 +9,7 @@

from xpra.util import envbool
from xpra.gtk_common.gobject_util import one_arg_signal
from xpra.x11.gtk2.gdk_bindings import (
from xpra.x11.gtk_x11.gdk_bindings import (
add_event_receiver, #@UnresolvedImport
remove_event_receiver, #@UnresolvedImport
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import gobject

from xpra.util import WORKSPACE_UNSET, WORKSPACE_ALL
from xpra.x11.gtk_x11.prop import prop_set, prop_get
from xpra.x11.gtk2.models.core import CoreX11WindowModel, xswallow
from xpra.x11.models.core import CoreX11WindowModel, xswallow
from xpra.x11.bindings.window_bindings import X11WindowBindings, constants #@UnresolvedImport
from xpra.x11.gtk2.gdk_bindings import get_pywindow, get_pyatom #@UnresolvedImport
from xpra.x11.gtk_x11.gdk_bindings import get_pywindow, get_pyatom #@UnresolvedImport
from xpra.x11.gtk_x11.prop import prop_set, prop_get
from xpra.gtk_common.gtk_util import atom_intern

from xpra.log import Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
from xpra.gtk_common.gtk_util import get_xwindow
from xpra.gtk_common.error import XError, xsync, xswallow
from xpra.x11.bindings.window_bindings import X11WindowBindings, constants, SHAPE_KIND #@UnresolvedImport
from xpra.x11.gtk2.composite import CompositeHelper
from xpra.x11.models.model_stub import WindowModelStub
from xpra.x11.gtk_x11.prop import prop_get, prop_set
from xpra.x11.gtk_x11.send_wm import send_wm_delete_window
from xpra.x11.gtk2.composite import CompositeHelper
from xpra.x11.gtk2.models.model_stub import WindowModelStub
from xpra.x11.gtk2.gdk_bindings import (
from xpra.x11.gtk_x11.gdk_bindings import (
add_event_receiver, #@UnresolvedImport
remove_event_receiver, #@UnresolvedImport
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# This file is part of Xpra.
# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
# Copyright (C) 2011-2016 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2011-2018 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

import os
import gobject

from xpra.gtk_common.gobject_util import AutoPropGObjectMixin
from xpra.gtk_common.gobject_compat import import_gobject
gobject = import_gobject()

from xpra.log import Logger
log = Logger("x11", "window")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


from xpra.x11.common import Unmanageable
from xpra.x11.gtk2.models.base import BaseWindowModel, gobject
from xpra.x11.models.base import BaseWindowModel, gobject
from xpra.x11.bindings.window_bindings import X11WindowBindings #@UnresolvedImport

X11Window = X11WindowBindings()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This file is part of Xpra.
# Copyright (C) 2008, 2009 Nathaniel Smith <njs@pobox.com>
# Copyright (C) 2011-2014 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2011-2018 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from xpra.x11.gtk2.models.core import CoreX11WindowModel, gobject
from xpra.x11.models.core import CoreX11WindowModel, gobject
from xpra.log import Logger
log = Logger("x11", "window", "tray")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
# later version. See the file COPYING for details.


import gtk
from gtk import gdk
import cairo

from xpra.util import envint, envbool
from xpra.gtk_common.gobject_util import one_arg_signal, non_none_list_accumulator, SIGNAL_RUN_LAST
from xpra.gtk_common.error import XError
Expand All @@ -17,19 +13,25 @@
from xpra.x11.prop_conv import MotifWMHints
from xpra.x11.bindings.window_bindings import X11WindowBindings #@UnresolvedImport
from xpra.x11.common import Unmanageable
from xpra.x11.gtk2.models.size_hints_util import sanitize_size_hints
from xpra.x11.models.size_hints_util import sanitize_size_hints
from xpra.x11.common import MAX_WINDOW_SIZE
from xpra.x11.gtk2.models.base import BaseWindowModel, constants
from xpra.x11.gtk2.models.core import sanestr, gobject, xswallow, xsync
from xpra.x11.gtk2.gdk_bindings import (
add_event_receiver, #@UnresolvedImport
remove_event_receiver, #@UnresolvedImport
)
from xpra.gtk_common.gtk2.gdk_bindings import (
get_display_for, #@UnresolvedImport
calc_constrained_size, #@UnresolvedImport
)
from xpra.gtk_common.gtk_util import get_default_root_window
from xpra.x11.models.base import BaseWindowModel, constants
from xpra.x11.models.core import sanestr, gobject, xswallow, xsync
from xpra.x11.gtk_x11.gdk_bindings import (
add_event_receiver, #@UnresolvedImport
remove_event_receiver, #@UnresolvedImport
get_display_for, #@UnresolvedImport
calc_constrained_size, #@UnresolvedImport
)
from xpra.gtk_common.gtk_util import (
get_default_root_window, get_xwindow,
GDKWindow, GDKWINDOW_CHILD, PROPERTY_CHANGE_MASK,
)
from xpra.gtk_common.gobject_compat import import_gtk, import_gdk, import_cairo
gtk = import_gtk()
gdk = import_gdk()
cairo = import_cairo()


from xpra.log import Logger
log = Logger("x11", "window")
Expand Down Expand Up @@ -184,15 +186,15 @@ def setup(self):
# x11_get_server_time on this window.
# clamp this window to the desktop size:
x, y = self._clamp_to_desktop(ox, oy, ow, oh)
self.corral_window = gdk.Window(self.parking_window,
self.corral_window = GDKWindow(self.parking_window,
x=x, y=y, width=ow, height=oh,
window_type=gdk.WINDOW_CHILD,
wclass=gdk.INPUT_OUTPUT,
event_mask=gdk.PROPERTY_CHANGE_MASK,
window_type=GDKWINDOW_CHILD,
event_mask=PROPERTY_CHANGE_MASK,
title = "CorralWindow-%#x" % self.xid)
log("setup() corral_window=%#x", self.corral_window.xid)
cxid = get_xwindow(self.corral_window)
log("setup() corral_window=%#x", cxid)
prop_set(self.corral_window, "_NET_WM_NAME", "utf8", u"Xpra-CorralWindow-%#x" % self.xid)
X11Window.substructureRedirect(self.corral_window.xid)
X11Window.substructureRedirect(cxid)
add_event_receiver(self.corral_window, self)

# The child might already be mapped, in case we inherited it from
Expand All @@ -209,7 +211,7 @@ def setup(self):
self.in_save_set = True

log("setup() reparenting")
X11Window.Reparent(self.xid, self.corral_window.xid, 0, 0)
X11Window.Reparent(self.xid, cxid, 0, 0)
self.client_reparented = True

geomlog("setup() geometry")
Expand Down Expand Up @@ -475,16 +477,17 @@ def _do_update_client_geometry(self, window_size_cb, window_position_cb):
X11Window.configureAndNotify(self.xid, 0, 0, w, h)

def do_xpra_configure_event(self, event):
geomlog("WindowModel.do_xpra_configure_event(%s) corral=%#x, client=%#x, managed=%s", event, self.corral_window.xid, self.xid, self._managed)
cxid = get_xwindow(self.corral_window)
geomlog("WindowModel.do_xpra_configure_event(%s) corral=%#x, client=%#x, managed=%s", event, cxid, self.xid, self._managed)
if not self._managed:
return
if event.window==self.corral_window:
#we only care about events on the client window
geomlog("WindowModel.do_xpra_configure_event: event is on the corral window %#x, ignored", self.corral_window.xid)
geomlog("WindowModel.do_xpra_configure_event: event is on the corral window %#x, ignored", cxid)
return
if event.window!=self.client_window:
#we only care about events on the client window
geomlog("WindowModel.do_xpra_configure_event: event is not on the client window but on %#x, ignored", event.window.xid)
geomlog("WindowModel.do_xpra_configure_event: event is not on the client window but on %#x, ignored", get_xwindow(event.window))
return
if self.corral_window is None or not self.corral_window.is_visible():
geomlog("WindowModel.do_xpra_configure_event: corral window is not visible")
Expand All @@ -499,7 +502,7 @@ def do_xpra_configure_event(self, event):
self.resize_corral_window(event.x, event.y, event.width, event.height)
except XError as e:
geomlog("do_xpra_configure_event(%s)", event, exc_info=True)
geomlog.warn("Warning: failed to resize corral window %#x", self.corral_window.xid)
geomlog.warn("Warning: failed to resize corral window %#x", cxid)
geomlog.warn(" %s", e)

def resize_corral_window(self, x, y, w, h):
Expand Down Expand Up @@ -531,8 +534,9 @@ def resize_corral_window(self, x, y, w, h):
self._updateprop("geometry", (x, y, cw, ch))

def do_child_configure_request_event(self, event):
cxid = get_xwindow(self.corral_window)
hints = self.get_property("size-hints")
geomlog("do_child_configure_request_event(%s) client=%#x, corral=%#x, value_mask=%s, size-hints=%s", event, self.xid, self.corral_window.xid, configure_bits(event.value_mask), hints)
geomlog("do_child_configure_request_event(%s) client=%#x, corral=%#x, value_mask=%s, size-hints=%s", event, self.xid, cxid, configure_bits(event.value_mask), hints)
if event.value_mask & CWStackMode:
geomlog(" restack above=%s, detail=%s", event.above, event.detail)
# Also potentially update our record of what the app has requested:
Expand Down

0 comments on commit 0d2c021

Please sign in to comment.