Add support for zoom gesture

This commit is contained in:
Liao Junxuan 2023-11-20 19:20:51 +08:00 committed by Sebastian Ramacher
parent 43a65ae878
commit 5244b07d6a
4 changed files with 43 additions and 0 deletions

View file

@ -808,3 +808,28 @@ cb_window_update_icon(ZathuraRenderRequest* GIRARA_UNUSED(request), cairo_surfac
gtk_window_set_icon(GTK_WINDOW(zathura->ui.session->gtk.window), pixbuf);
g_object_unref(pixbuf);
}
void
cb_gesture_zoom_begin(GtkGesture* UNUSED(self), GdkEventSequence* UNUSED(sequence), void* data)
{
zathura_t* zathura = data;
if (zathura == NULL || zathura->document == NULL) {
return;
}
const double current_zoom = zathura_document_get_zoom(zathura->document);
zathura->gesture.initial_zoom = current_zoom;
}
void
cb_gesture_zoom_scale_changed(GtkGestureZoom* UNUSED(self), gdouble scale, void* data)
{
zathura_t* zathura = data;
if (zathura == NULL || zathura->document == NULL) {
return;
}
const double next_zoom = zathura->gesture.initial_zoom * scale;
zathura_document_set_zoom(zathura->document, next_zoom);
render_all(zathura);
refresh_view(zathura);
}

View file

@ -281,5 +281,8 @@ void update_visible_pages(zathura_t* zathura);
*/
void cb_window_update_icon(ZathuraRenderRequest* request, cairo_surface_t* surface, void* data);
void cb_gesture_zoom_begin(GtkGesture* self, GdkEventSequence* sequence, void* data);
void cb_gesture_zoom_scale_changed(GtkGestureZoom* self, gdouble scale, void* data);
#endif // CALLBACKS_H

View file

@ -221,6 +221,13 @@ init_ui(zathura_t* zathura)
zathura->ui.session->events.buffer_changed = cb_buffer_changed;
zathura->ui.session->events.unknown_command = cb_unknown_command;
/* gestures */
GtkGesture* zoom = gtk_gesture_zoom_new(GTK_WIDGET(zathura->ui.session->gtk.view));
g_signal_connect(zoom, "scale-changed", G_CALLBACK(cb_gesture_zoom_scale_changed), zathura);
g_signal_connect(zoom, "begin", G_CALLBACK(cb_gesture_zoom_begin), zathura);
gtk_event_controller_set_propagation_phase(GTK_EVENT_CONTROLLER(zathura->ui.session->gtk.view), GTK_PHASE_BUBBLE);
/* zathura signals */
zathura->signals.refresh_view = g_signal_new(
"refresh-view", GTK_TYPE_WIDGET, G_SIGNAL_RUN_LAST, 0, NULL, NULL,

View file

@ -226,6 +226,14 @@ struct zathura_s
} toggle_presentation_mode;
} shortcut;
/**
* Storage for gestures.
*/
struct {
double initial_zoom;
} gesture;
/**
* Context for MIME type detection
*/