summaryrefslogtreecommitdiff
path: root/clients/image.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-10-30 15:42:20 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-10-30 15:42:20 -0400
commit719b2158e724099063fc980ceaa35a92830f13c5 (patch)
tree7d360aab6f371660ebf928e12001874e6a0b08a4 /clients/image.c
parenta369ff52739e8bca84faa6de9c4115f3e84ef818 (diff)
downloadweston-719b2158e724099063fc980ceaa35a92830f13c5.tar.gz
image: Add keyhandler to handle keyboard zoom
Diffstat (limited to 'clients/image.c')
-rw-r--r--clients/image.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/clients/image.c b/clients/image.c
index 2804dbf1..2cdce416 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -293,6 +293,37 @@ zoom(struct image *image, double scale)
}
static void
+key_handler(struct window *window, struct input *input, uint32_t time,
+ uint32_t key, uint32_t sym, enum wl_keyboard_key_state state,
+ void *data)
+{
+ struct image *image = data;
+
+ if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
+ return;
+
+ switch (sym) {
+ case XKB_KEY_minus:
+ zoom(image, 0.8);
+ window_schedule_redraw(image->window);
+ break;
+ case XKB_KEY_equal:
+ case XKB_KEY_plus:
+ zoom(image, 1.2);
+ window_schedule_redraw(image->window);
+ break;
+ case XKB_KEY_1:
+ image->matrix.xx = 1.0;
+ image->matrix.xy = 0.0;
+ image->matrix.yx = 0.0;
+ image->matrix.yy = 1.0;
+ clamp_view(image);
+ window_schedule_redraw(image->window);
+ break;
+ }
+}
+
+static void
axis_handler(struct widget *widget, struct input *input, uint32_t time,
uint32_t axis, wl_fixed_t value, void *data)
{
@@ -382,6 +413,7 @@ image_create(struct display *display, const char *filename,
widget_set_motion_handler(image->widget, motion_handler);
widget_set_button_handler(image->widget, button_handler);
widget_set_axis_handler(image->widget, axis_handler);
+ window_set_key_handler(image->window, key_handler);
widget_schedule_resize(image->widget, 500, 400);
return image;