Skip to content

Commit

Permalink
fix pointer overlay with desktop-scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Aug 15, 2024
1 parent b6b6a1c commit 533af10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
12 changes: 6 additions & 6 deletions xpra/client/gl/backing.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ def do_present_fbo(self, context) -> None:
GL_COLOR_BUFFER_BIT, sampling)

if self.pointer_overlay:
self.draw_pointer()
self.draw_pointer(xscale, yscale)
glViewport(*viewport)

if self.paint_spinner or FORCE_SPINNER:
Expand Down Expand Up @@ -878,7 +878,7 @@ def draw_spinner(self) -> None:

glBindVertexArray(0)

def draw_pointer(self) -> None:
def draw_pointer(self, xscale=1.0, yscale=1.0) -> None:
px, py, _, _, _, start_time = self.pointer_overlay
elapsed = monotonic() - start_time
log("pointer_overlay=%s, elapsed=%.1f, timeout=%s, cursor-data=%s",
Expand All @@ -889,12 +889,12 @@ def draw_pointer(self) -> None:
return
if not self.cursor_data:
return
w = self.cursor_data[3]
h = self.cursor_data[4]
w = round(self.cursor_data[3] * xscale)
h = round(self.cursor_data[4] * yscale)
xhot = self.cursor_data[5]
yhot = self.cursor_data[6]
x = px - xhot
y = py - yhot
x = round((px - xhot) * xscale)
y = round((py - yhot) * yscale)
texture = int(self.textures[TEX_CURSOR])
self.overlay_texture(texture, x, y, w, h)

Expand Down
22 changes: 12 additions & 10 deletions xpra/client/gtk3/cairo_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,28 @@ def cairo_paint_pointer_overlay(context, cursor_data, px: int, py: int, start_ti
if elapsed > 6:
return
# pylint: disable=import-outside-toplevel
from xpra.gtk.pixbuf import get_pixbuf_from_data
from xpra.codecs.argb.argb import unpremultiply_argb
try:
from xpra.client.gtk3.cairo_workaround import make_image_surface
except ImportError:
return

cw = cursor_data[3]
ch = cursor_data[4]
xhot = cursor_data[5]
yhot = cursor_data[6]
pixels = cursor_data[8]
x = px - xhot
y = py - yhot

alpha = max(0.0, (5.0 - elapsed) / 5.0)
log("cairo_paint_pointer_overlay%s drawing pointer with cairo, alpha=%s",
(context, x, y, start_time), alpha)
bgra = memoryview_to_bytes(pixels)
img = make_image_surface(Format.ARGB32, "BGRA", bgra, cw, ch, cw * 4)
context.translate(x, y)
context.rectangle(0, 0, cw, ch)
argb = unpremultiply_argb(pixels)
img_data = memoryview_to_bytes(argb)
pixbuf = get_pixbuf_from_data(img_data, True, cw, ch, cw * 4)
context.set_source_surface(img, 0, 0)
context.set_operator(Operator.OVER)
Gdk.cairo_set_source_pixbuf(context, pixbuf, 0, 0)
context.paint_with_alpha(alpha)
context.paint()


class CairoBackingBase(WindowBackingBase):
Expand Down Expand Up @@ -277,11 +279,13 @@ def cairo_draw(self, context) -> None:
context.set_operator(Operator.SOURCE)
context.set_source_surface(backing, 0, 0)
context.paint()

if self.pointer_overlay and self.cursor_data:
px, py, _size, start_time = self.pointer_overlay[2:]
spx = round(w * px / ww)
spy = round(h * py / wh)
cairo_paint_pointer_overlay(context, self.cursor_data, x + spx, y + spy, start_time)

if self.is_show_fps() and self.fps_image:
x, y = 10, 10
context.translate(x, y)
Expand All @@ -290,8 +294,6 @@ def cairo_draw(self, context) -> None:
context.paint()
self.cancel_fps_refresh()

# width, height = self.fps_buffer_size

def refresh_screen() -> None:
self.fps_refresh_timer = 0
b = self._backing
Expand Down

0 comments on commit 533af10

Please sign in to comment.