From aaa24643cbee4ab4785acd947012146c40cd7846 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Thu, 22 Aug 2024 16:05:45 +0200 Subject: [PATCH] Add basic touch zoom support --- xdot/ui/window.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xdot/ui/window.py b/xdot/ui/window.py index f1f5bc9..5c6eaac 100644 --- a/xdot/ui/window.py +++ b/xdot/ui/window.py @@ -97,6 +97,9 @@ def __init__(self): self.history_back = [] self.history_forward = [] + self.zoom_gesture = Gtk.GestureZoom.new(self) + self.zoom_gesture.connect("scale-changed", self.on_scale_changed) + def error_dialog(self, message): self.emit('error', message) @@ -477,6 +480,13 @@ def on_area_size_allocate(self, area, allocation): if self.zoom_to_fit_on_resize: self.zoom_to_fit() + def on_scale_changed(self, gesture, scale): + point, x, y = gesture.get_point() + if point: + pos = (x, y) + new_zoom_ratio = self.zoom_ratio * math.exp(math.log(scale) / 3) + self.zoom_image(new_zoom_ratio, pos=pos) + def animate_to(self, x, y): del self.history_forward[:] self.history_back.append(self.get_current_pos())