Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* repurpose OR_offset to a generic window offset and use it for handling backings that don't align with the window
* add "offsets" value to backings so they can be painted to the window at an offset

git-svn-id: https://xpra.org/svn/Xpra/trunk@16219 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jul 7, 2017
1 parent 35bb829 commit 42463eb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/xpra/client/gl/gl_window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ def gl_init(self):
w, h = self.size
self.gl_marker("Initializing GL context for window size %s, backing size %s", self.render_size, self.size)
# Initialize viewport and matrices for 2D rendering
glViewport(0, 0, w, h)
x, _, _, y = self.offsets
glViewport(x, y, w, h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, w, h, 0.0, -1.0, 1.0)
Expand Down Expand Up @@ -645,7 +646,8 @@ def do_present_fbo(self):
glClearColor(1.0, 1.0, 1.0, 1.0)

#viewport for painting to window:
glViewport(0, 0, ww, wh)
x, _, _, y = self.offsets
glViewport(x, y, ww, wh)
target = GL_TEXTURE_RECTANGLE_ARB
if ww!=bw or wh!=bh:
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
Expand Down
3 changes: 3 additions & 0 deletions src/xpra/client/gtk2/pixmap_backing.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ def cairo_draw_from_drawable(self, context, drawable):
return False
if w!=ww or h!=wh:
context.scale(float(ww)/w, float(wh)/h)
x, y = self.offsets[:2]
if x!=0 or y!=0:
context.translate(x, y)
context.set_source_pixmap(drawable, 0, 0)
context.set_operator(cairo.OPERATOR_SOURCE)
context.paint()
Expand Down
47 changes: 31 additions & 16 deletions src/xpra/client/gtk_base/gtk_client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def init_window(self, metadata):
self._frozen = False
self.moveresize_timer = None
self.moveresize_event = None
self.OR_offset = None
self.window_offset = None #actual vs reported coordinates
#add platform hooks
self.on_realize_cb = {}
self.connect_after("realize", self.on_realize)
Expand Down Expand Up @@ -304,10 +304,10 @@ def focus_out(*args):
#make sure OR windows are mapped on screen
if self._client._current_screen_sizes:
w, h = self._size
self.OR_offset = self.calculate_OR_offset(x, y, w, h)
if self.OR_offset:
x += self.OR_offset[0]
y += self.OR_offset[1]
self.window_offset = self.calculate_window_offset(x, y, w, h)
if self.window_offset:
x += self.window_offset[0]
y += self.window_offset[1]
if not self.is_OR() and self.get_decorated():
#try to adjust for window frame size if we can figure it out:
#Note: we cannot just call self.get_window_frame_size() here because
Expand All @@ -327,7 +327,7 @@ def focus_out(*args):
self.move(x, y)
self.set_default_size(*self._size)

def calculate_OR_offset(self, wx, wy, ww, wh):
def calculate_window_offset(self, wx, wy, ww, wh):
ss = self._client._current_screen_sizes
if not ss:
return None
Expand Down Expand Up @@ -376,7 +376,7 @@ def calculate_OR_offset(self, wx, wy, ww, wh):
elif wy+wh>y+h:
dy = (y+h) - (wy+wh)
assert dx!=0 or dy!=0
geomlog("calculate_OR_offset%s=%s", (wx, wy, ww, wh), (dx, dy))
geomlog("calculate_window_offset%s=%s", (wx, wy, ww, wh), (dx, dy))
return dx, dy

def when_realized(self, identifier, callback, *args):
Expand Down Expand Up @@ -1233,18 +1233,33 @@ def _set_backing_size(self, ww, wh):
self.new_backing(self._client.cx(ww), self._client.cy(wh))

def resize(self, w, h, resize_counter=0):
log("resize(%s, %s, %s)", w, h, resize_counter)
ww, wh = self.get_size()
geomlog("resize(%s, %s, %s) current size=%s, fullscreen=%s", w, h, resize_counter, (ww, wh), self._fullscreen)
self._resize_counter = resize_counter
gtk.Window.resize(self, w, h)
if (w, h)==(ww, wh):
return
if not self._fullscreen and not self._maximized:
gtk.Window.resize(self, w, h)
else:
#align in the middle:
ox = (ww-w)//2
oy = (wh-h)//2
geomlog("using window offset values %i,%i", ox, oy)
#some backings use top,left values,
#(opengl uses left and botton since the viewport starts at the bottom)
self._backing.offsets = ox, oy, ox, oy
#adjust pointer coordinates:
self.window_offset = ox, oy
self.queue_draw(0, 0, ww, wh)
self._set_backing_size(w, h)

def move_resize(self, x, y, w, h, resize_counter=0):
geomlog("window %i move_resize%s", self._id, (x, y, w, h, resize_counter))
w = max(1, w)
h = max(1, h)
if self.OR_offset:
x += self.OR_offset[0]
y += self.OR_offset[1]
if self.window_offset:
x += self.window_offset[0]
y += self.window_offset[1]
#TODO: check this doesn't move it off-screen!
self._resize_counter = resize_counter
window = self.get_window()
Expand Down Expand Up @@ -1320,9 +1335,9 @@ def do_delete_event(self, event):


def _pointer(self, x, y):
if self.OR_offset:
x -= self.OR_offset[0]
y -= self.OR_offset[1]
if self.window_offset:
x -= self.window_offset[0]
y -= self.window_offset[1]
return self._client.cp(x, y)

def _get_pointer(self, event):
Expand All @@ -1335,7 +1350,7 @@ def _pointer_modifiers(self, event):
modifiers = self._client.mask_to_names(event.state)
buttons = self._event_buttons(event)
v = pointer, modifiers, buttons
mouselog("pointer_modifiers(%s)=%s (x_root=%s, y_root=%s, OR_offset=%s)", event, v, event.x_root, event.y_root, self.OR_offset)
mouselog("pointer_modifiers(%s)=%s (x_root=%s, y_root=%s, window_offset=%s)", event, v, event.x_root, event.y_root, self.window_offset)
return v

def _event_buttons(self, event):
Expand Down
1 change: 1 addition & 0 deletions src/xpra/client/window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, wid, window_alpha, idle_add):
load_video_decoders()
self.wid = wid
self.size = 0, 0
self.offsets = 0, 0, 0, 0 #top,left,bottom,right
self.idle_add = idle_add
self._alpha_enabled = window_alpha
self._backing = None
Expand Down

0 comments on commit 42463eb

Please sign in to comment.