aboutsummaryrefslogtreecommitdiff
path: root/fastiv-view.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-11-11 22:51:20 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-11-11 22:59:31 +0100
commitf341c8f8c3185aa3688fb96d34d180b2aee1b11d (patch)
tree280dee91c035aa36c128c762e784943ae3a9f0a6 /fastiv-view.c
parentcfd2e5d9a53d5f447db5e4b22584104d4790da61 (diff)
downloadfiv-f341c8f8c3185aa3688fb96d34d180b2aee1b11d.tar.gz
fiv-f341c8f8c3185aa3688fb96d34d180b2aee1b11d.tar.xz
fiv-f341c8f8c3185aa3688fb96d34d180b2aee1b11d.zip
Make the 1 key reset the zoom
Diffstat (limited to 'fastiv-view.c')
-rw-r--r--fastiv-view.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/fastiv-view.c b/fastiv-view.c
index 948db9e..52d2ed4 100644
--- a/fastiv-view.c
+++ b/fastiv-view.c
@@ -99,7 +99,8 @@ fastiv_view_realize(GtkWidget *widget)
// Assuming here that we can't ask for a higher-precision Visual
// than what we get automatically.
.visual = gtk_widget_get_visual(widget),
- .event_mask = gtk_widget_get_events(widget) | GDK_SCROLL_MASK,
+ .event_mask = gtk_widget_get_events(widget) | GDK_SCROLL_MASK |
+ GDK_KEY_PRESS_MASK,
};
// We need this window to receive input events at all.
@@ -189,6 +190,22 @@ fastiv_view_scroll_event(GtkWidget *widget, GdkEventScroll *event)
}
}
+static gboolean
+fastiv_view_key_press_event(GtkWidget *widget, GdkEventKey *event)
+{
+ FastivView *self = FASTIV_VIEW(widget);
+ if (event->state & gtk_accelerator_get_default_mod_mask())
+ return FALSE;
+
+ switch (event->keyval) {
+ case GDK_KEY_1:
+ self->scale = 1;
+ gtk_widget_queue_resize(widget);
+ return TRUE;
+ }
+ return FALSE;
+}
+
static void
fastiv_view_class_init(FastivViewClass *klass)
{
@@ -201,6 +218,7 @@ fastiv_view_class_init(FastivViewClass *klass)
widget_class->realize = fastiv_view_realize;
widget_class->draw = fastiv_view_draw;
widget_class->scroll_event = fastiv_view_scroll_event;
+ widget_class->key_press_event = fastiv_view_key_press_event;
// TODO(p): Later override "screen_changed", recreate Pango layouts there,
// if we get to have any, or otherwise reflect DPI changes.
@@ -210,6 +228,8 @@ fastiv_view_class_init(FastivViewClass *klass)
static void
fastiv_view_init(FastivView *self)
{
+ gtk_widget_set_can_focus(GTK_WIDGET(self), TRUE);
+
self->scale = 1.0;
}