summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorJason Ekstrand <jason@jlekstrand.net>2013-10-13 19:08:40 -0500
committerKristian Høgsberg <krh@bitplanet.net>2013-10-14 12:27:55 -0700
commit3f66cf92ed8d0642c20e135894c455b5937ec18b (patch)
tree05c1b8b553e9d440e65dd95fe0a5170d091d37ae /shared
parent01c9ec3477c92509b8d53ae3e518a6d9b5b50aad (diff)
downloadweston-3f66cf92ed8d0642c20e135894c455b5937ec18b.tar.gz
Use cairo-util frame in tinytoolkit
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Diffstat (limited to 'shared')
-rw-r--r--shared/cairo-util.h6
-rw-r--r--shared/frame.c92
2 files changed, 97 insertions, 1 deletions
diff --git a/shared/cairo-util.h b/shared/cairo-util.h
index da1cef95..d679bcbd 100644
--- a/shared/cairo-util.h
+++ b/shared/cairo-util.h
@@ -192,7 +192,11 @@ enum theme_location
frame_pointer_button(struct frame *frame, void *pointer,
uint32_t button, enum frame_button_state state);
-/* TODO: Add Touch */
+void
+frame_touch_down(struct frame *frame, void *data, int32_t id, int x, int y);
+
+void
+frame_touch_up(struct frame *frame, void *data, int32_t id);
void
frame_repaint(struct frame *frame, cairo_t *cr);
diff --git a/shared/frame.c b/shared/frame.c
index 508870c4..fc859507 100644
--- a/shared/frame.c
+++ b/shared/frame.c
@@ -64,6 +64,15 @@ struct frame_pointer {
int active;
};
+struct frame_touch {
+ struct wl_list link;
+ void *data;
+
+ int x, y;
+
+ struct frame_button *button;
+};
+
struct frame {
int32_t width, height;
char *title;
@@ -82,6 +91,7 @@ struct frame {
struct wl_list buttons;
struct wl_list pointers;
+ struct wl_list touches;
};
static struct frame_button *
@@ -227,6 +237,32 @@ frame_pointer_destroy(struct frame_pointer *pointer)
free(pointer);
}
+static struct frame_touch *
+frame_touch_get(struct frame *frame, void *data)
+{
+ struct frame_touch *touch;
+
+ wl_list_for_each(touch, &frame->touches, link)
+ if (touch->data == data)
+ return touch;
+
+ touch = calloc(1, sizeof *touch);
+ if (!touch)
+ return NULL;
+
+ touch->data = data;
+ wl_list_insert(&frame->touches, &touch->link);
+
+ return touch;
+}
+
+static void
+frame_touch_destroy(struct frame_touch *touch)
+{
+ wl_list_remove(&touch->link);
+ free(touch);
+}
+
struct frame *
frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons,
const char *title)
@@ -253,6 +289,7 @@ frame_create(struct theme *t, int32_t width, int32_t height, uint32_t buttons,
wl_list_init(&frame->buttons);
wl_list_init(&frame->pointers);
+ wl_list_init(&frame->touches);
button = frame_button_create(frame, DATADIR "/weston/icon_window.png",
FRAME_STATUS_MENU,
@@ -645,6 +682,61 @@ frame_pointer_button(struct frame *frame, void *data,
}
void
+frame_touch_down(struct frame *frame, void *data, int32_t id, int x, int y)
+{
+ struct frame_touch *touch = frame_touch_get(frame, data);
+ struct frame_button *button = frame_find_button(frame, x, y);
+ enum theme_location location;
+
+ if (id > 0)
+ return;
+
+ if (button) {
+ touch->button = button;
+ frame_button_press(touch->button);
+ return;
+ }
+
+ location = theme_get_location(frame->theme, x, y,
+ frame->width, frame->height,
+ frame->flags & FRAME_FLAG_MAXIMIZED ?
+ THEME_FRAME_MAXIMIZED : 0);
+
+ switch (location) {
+ case THEME_LOCATION_TITLEBAR:
+ frame->status |= FRAME_STATUS_MOVE;
+ break;
+ case THEME_LOCATION_RESIZING_TOP:
+ case THEME_LOCATION_RESIZING_BOTTOM:
+ case THEME_LOCATION_RESIZING_LEFT:
+ case THEME_LOCATION_RESIZING_RIGHT:
+ case THEME_LOCATION_RESIZING_TOP_LEFT:
+ case THEME_LOCATION_RESIZING_TOP_RIGHT:
+ case THEME_LOCATION_RESIZING_BOTTOM_LEFT:
+ case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:
+ frame->status |= FRAME_STATUS_RESIZE;
+ break;
+ default:
+ break;
+ }
+}
+
+void
+frame_touch_up(struct frame *frame, void *data, int32_t id)
+{
+ struct frame_touch *touch = frame_touch_get(frame, data);
+
+ if (id > 0)
+ return;
+
+ if (touch->button) {
+ frame_button_release(touch->button);
+ frame_touch_destroy(touch);
+ return;
+ }
+}
+
+void
frame_repaint(struct frame *frame, cairo_t *cr)
{
struct frame_button *button;