summaryrefslogtreecommitdiff
path: root/clients/resizor.c
diff options
context:
space:
mode:
authorPekka Paalanen <ppaalanen@gmail.com>2011-12-15 15:26:29 +0200
committerPekka Paalanen <ppaalanen@gmail.com>2011-12-22 11:27:50 +0200
commite59d74a9b91692eebde974c495a5c00aafd9fe28 (patch)
tree46dc958086696b14788c72dcdaa12c1d7e377d17 /clients/resizor.c
parentfe6079ac0987d78873d5aa582d780957056b7119 (diff)
resizor: add exit key and cleanups
Make resizor quit when you press Esc key. Call the toytoolkit cleanup functions, properly destroy window, display and frame callback. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Diffstat (limited to 'clients/resizor.c')
-rw-r--r--clients/resizor.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/clients/resizor.c b/clients/resizor.c
index a31e0d7..2f32ad5 100644
--- a/clients/resizor.c
+++ b/clients/resizor.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <cairo.h>
#include <math.h>
+#include <assert.h>
#include <linux/input.h>
#include <wayland-client.h>
@@ -45,6 +46,7 @@ struct resizor {
double target;
double previous;
} height;
+ struct wl_callback *frame_callback;
};
static void
@@ -56,6 +58,8 @@ frame_callback(void *data, struct wl_callback *callback, uint32_t time)
struct resizor *resizor = data;
double force, height;
+ assert(!callback || callback == resizor->frame_callback);
+
height = resizor->height.current;
force = (resizor->height.target - height) / 10.0 +
(resizor->height.previous - height);
@@ -78,12 +82,17 @@ frame_callback(void *data, struct wl_callback *callback, uint32_t time)
window_schedule_redraw(resizor->window);
- if (callback)
- wl_callback_destroy(callback);
+ if (resizor->frame_callback) {
+ wl_callback_destroy(resizor->frame_callback);
+ resizor->frame_callback = NULL;
+ }
if (fabs(resizor->height.previous - resizor->height.target) > 0.1) {
- callback = wl_surface_frame(window_get_wl_surface(resizor->window));
- wl_callback_add_listener(callback, &listener, resizor);
+ resizor->frame_callback =
+ wl_surface_frame(
+ window_get_wl_surface(resizor->window));
+ wl_callback_add_listener(resizor->frame_callback, &listener,
+ resizor);
}
}
@@ -151,6 +160,9 @@ key_handler(struct window *window, struct input *input, uint32_t time,
resizor->height.target = 200;
frame_callback(resizor, NULL, 0);
break;
+ case XK_Escape:
+ display_exit(resizor->display);
+ break;
}
}
@@ -220,20 +232,34 @@ resizor_create(struct display *display)
return resizor;
}
+static void
+resizor_destroy(struct resizor *resizor)
+{
+ if (resizor->frame_callback)
+ wl_callback_destroy(resizor->frame_callback);
+
+ window_destroy(resizor->window);
+ free(resizor);
+}
+
int
main(int argc, char *argv[])
{
- struct display *d;
+ struct display *display;
+ struct resizor *resizor;
- d = display_create(&argc, &argv, NULL);
- if (d == NULL) {
+ display = display_create(&argc, &argv, NULL);
+ if (display == NULL) {
fprintf(stderr, "failed to create display: %m\n");
return -1;
}
- resizor_create (d);
+ resizor = resizor_create(display);
+
+ display_run(display);
- display_run(d);
+ resizor_destroy(resizor);
+ display_destroy(display);
return 0;
}