clickdot: implement the purpose

Remove all unneeded resizor features, and add the feature why clickdot
exists: put a visible marker to exactly where mouse was clicked.

This app can be used to check input coordinate transformations in a
compositor.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
dev
Pekka Paalanen 13 years ago
parent 6920190013
commit b13e84f4e9
  1. 124
      clients/clickdot.c

@ -1,5 +1,6 @@
/* /*
* Copyright © 2010 Intel Corporation * Copyright © 2010 Intel Corporation
* Copyright © 2012 Collabora, Ltd.
* *
* Permission to use, copy, modify, distribute, and sell this software and its * Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that * documentation for any purpose is hereby granted without fee, provided that
@ -39,58 +40,14 @@ struct clickdot {
struct display *display; struct display *display;
struct window *window; struct window *window;
struct widget *widget; struct widget *widget;
struct window *menu;
int32_t width;
struct {
double current;
double target;
double previous;
} height;
struct wl_callback *frame_callback;
};
static void
frame_callback(void *data, struct wl_callback *callback, uint32_t time)
{
struct clickdot *clickdot = data;
double force, height;
assert(!callback || callback == clickdot->frame_callback);
height = clickdot->height.current; int32_t x, y;
force = (clickdot->height.target - height) / 10.0 +
(clickdot->height.previous - height);
clickdot->height.current =
height + (height - clickdot->height.previous) + force;
clickdot->height.previous = height;
if (clickdot->height.current >= 400) {
clickdot->height.current = 400;
clickdot->height.previous = 400;
}
if (clickdot->height.current <= 200) {
clickdot->height.current = 200;
clickdot->height.previous = 200;
}
widget_schedule_resize(clickdot->widget, clickdot->width, height + 0.5);
if (clickdot->frame_callback) {
wl_callback_destroy(clickdot->frame_callback);
clickdot->frame_callback = NULL;
}
}
static const struct wl_callback_listener listener = {
frame_callback
}; };
static void static void
redraw_handler(struct widget *widget, void *data) redraw_handler(struct widget *widget, void *data)
{ {
static const double r = 10.0;
struct clickdot *clickdot = data; struct clickdot *clickdot = data;
cairo_surface_t *surface; cairo_surface_t *surface;
cairo_t *cr; cairo_t *cr;
@ -109,18 +66,20 @@ redraw_handler(struct widget *widget, void *data)
allocation.height); allocation.height);
cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_set_source_rgba(cr, 0, 0, 0, 0.8);
cairo_fill(cr); cairo_fill(cr);
cairo_destroy(cr);
cairo_surface_destroy(surface); cairo_translate(cr, clickdot->x + 0.5, clickdot->y + 0.5);
cairo_set_line_width(cr, 1.0);
cairo_set_source_rgb(cr, 0.1, 0.9, 0.9);
cairo_move_to(cr, 0.0, -r);
cairo_line_to(cr, 0.0, r);
cairo_move_to(cr, -r, 0.0);
cairo_line_to(cr, r, 0.0);
cairo_arc(cr, 0.0, 0.0, r, 0.0, 2.0 * M_PI);
cairo_stroke(cr);
if (fabs(clickdot->height.previous - clickdot->height.target) > 0.1) { cairo_destroy(cr);
clickdot->frame_callback =
wl_surface_frame(
window_get_wl_surface(clickdot->window));
wl_callback_add_listener(clickdot->frame_callback, &listener,
clickdot);
}
cairo_surface_destroy(surface);
} }
static void static void
@ -142,39 +101,12 @@ key_handler(struct window *window, struct input *input, uint32_t time,
return; return;
switch (sym) { switch (sym) {
case XK_Down:
clickdot->height.target = 400;
frame_callback(clickdot, NULL, 0);
break;
case XK_Up:
clickdot->height.target = 200;
frame_callback(clickdot, NULL, 0);
break;
case XK_Escape: case XK_Escape:
display_exit(clickdot->display); display_exit(clickdot->display);
break; break;
} }
} }
static void
menu_func(struct window *window, int index, void *user_data)
{
fprintf(stderr, "picked entry %d\n", index);
}
static void
show_menu(struct clickdot *clickdot, struct input *input, uint32_t time)
{
int32_t x, y;
static const char *entries[] = {
"Roy", "Pris", "Leon", "Zhora"
};
input_get_position(input, &x, &y);
window_show_menu(clickdot->display, input, time, clickdot->window,
x - 10, y - 10, menu_func, entries, 4);
}
static void static void
button_handler(struct widget *widget, button_handler(struct widget *widget,
struct input *input, uint32_t time, struct input *input, uint32_t time,
@ -182,19 +114,16 @@ button_handler(struct widget *widget,
{ {
struct clickdot *clickdot = data; struct clickdot *clickdot = data;
switch (button) { if (state && button == BTN_LEFT)
case BTN_RIGHT: input_get_position(input, &clickdot->x, &clickdot->y);
if (state)
show_menu(clickdot, input, time); widget_schedule_redraw(widget);
break;
}
} }
static struct clickdot * static struct clickdot *
clickdot_create(struct display *display) clickdot_create(struct display *display)
{ {
struct clickdot *clickdot; struct clickdot *clickdot;
int32_t height;
clickdot = malloc(sizeof *clickdot); clickdot = malloc(sizeof *clickdot);
if (clickdot == NULL) if (clickdot == NULL)
@ -203,24 +132,20 @@ clickdot_create(struct display *display)
clickdot->window = window_create(display, 500, 400); clickdot->window = window_create(display, 500, 400);
clickdot->widget = frame_create(clickdot->window, clickdot); clickdot->widget = frame_create(clickdot->window, clickdot);
window_set_title(clickdot->window, "Wayland Resizor"); window_set_title(clickdot->window, "Wayland ClickDot");
clickdot->display = display; clickdot->display = display;
window_set_key_handler(clickdot->window, key_handler); window_set_key_handler(clickdot->window, key_handler);
window_set_user_data(clickdot->window, clickdot); window_set_user_data(clickdot->window, clickdot);
widget_set_redraw_handler(clickdot->widget, redraw_handler);
window_set_keyboard_focus_handler(clickdot->window, window_set_keyboard_focus_handler(clickdot->window,
keyboard_focus_handler); keyboard_focus_handler);
clickdot->width = 300; widget_set_redraw_handler(clickdot->widget, redraw_handler);
clickdot->height.current = 400;
clickdot->height.previous = clickdot->height.current;
clickdot->height.target = clickdot->height.current;
height = clickdot->height.current + 0.5;
widget_set_button_handler(clickdot->widget, button_handler); widget_set_button_handler(clickdot->widget, button_handler);
widget_schedule_resize(clickdot->widget, clickdot->width, height); widget_schedule_resize(clickdot->widget, 500, 400);
clickdot->x = 250;
clickdot->y = 200;
return clickdot; return clickdot;
} }
@ -228,9 +153,6 @@ clickdot_create(struct display *display)
static void static void
clickdot_destroy(struct clickdot *clickdot) clickdot_destroy(struct clickdot *clickdot)
{ {
if (clickdot->frame_callback)
wl_callback_destroy(clickdot->frame_callback);
widget_destroy(clickdot->widget); widget_destroy(clickdot->widget);
window_destroy(clickdot->window); window_destroy(clickdot->window);
free(clickdot); free(clickdot);

Loading…
Cancel
Save