Skip to content

Commit

Permalink
Add basic touch zoom support
Browse files Browse the repository at this point in the history
  • Loading branch information
Frenzie authored and jrfonseca committed Aug 22, 2024
1 parent 9027dc1 commit aaa2464
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions xdot/ui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit aaa2464

Please sign in to comment.