<div dir="ltr"><div>In retrospect, this should probably go earlier in the series, before the second compositor-wayland patch. It doesn't actually matter, but it makes more sense there.<br></div>--Jason Ekstrand<br></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Oct 27, 2013 at 10:25 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This makes button handling more correct concerning drags. Also,<br>
frame_pointer_button returns the original button location in the case of a<br>
release. This makes filtering of button events much easier for users of<br>
the cair-util frame code.<br>
<br>
Signed-off-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
---<br>
shared/cairo-util.h | 8 ++-<br>
shared/frame.c | 156 ++++++++++++++++++++++++++++++++++++++--------------<br>
2 files changed, 122 insertions(+), 42 deletions(-)<br>
<br>
diff --git a/shared/cairo-util.h b/shared/cairo-util.h<br>
index cce7671..7bcbc29 100644<br>
--- a/shared/cairo-util.h<br>
+++ b/shared/cairo-util.h<br>
@@ -183,7 +183,13 @@ frame_pointer_motion(struct frame *frame, void *pointer, int x, int y);<br>
void<br>
frame_pointer_leave(struct frame *frame, void *pointer);<br>
<br>
-/* May set:<br>
+/* Call to indicate that a button has been pressed/released. The return<br>
+ * value for a button release will be the same as for the corresponding<br>
+ * press. This allows you to more easily track grabs. If you want the<br>
+ * actual location, simply keep the location from the last<br>
+ * frame_pointer_motion call.<br>
+ *<br>
+ * May set:<br>
* FRAME_STATUS_MINIMIZE<br>
* FRAME_STATUS_MAXIMIZE<br>
* FRAME_STATUS_CLOSE<br>
diff --git a/shared/frame.c b/shared/frame.c<br>
index 956e104..a069add 100644<br>
--- a/shared/frame.c<br>
+++ b/shared/frame.c<br>
@@ -54,6 +54,13 @@ struct frame_button {<br>
enum frame_status status_effect;<br>
};<br>
<br>
+struct frame_pointer_button {<br>
+ struct wl_list link;<br>
+ uint32_t button;<br>
+ enum theme_location press_location;<br>
+ struct frame_button *frame_button;<br>
+};<br>
+<br>
struct frame_pointer {<br>
struct wl_list link;<br>
void *data;<br>
@@ -61,7 +68,7 @@ struct frame_pointer {<br>
int x, y;<br>
<br>
struct frame_button *hover_button;<br>
- int active;<br>
+ struct wl_list down_buttons;<br>
};<br>
<br>
struct frame_touch {<br>
@@ -141,10 +148,6 @@ frame_button_leave(struct frame_button *button, struct frame_pointer *pointer)<br>
button->hover_count--;<br>
if (!button->hover_count)<br>
button->frame->status |= FRAME_STATUS_REPAINT;<br>
-<br>
- /* In this case, we won't get a release */<br>
- if (pointer->active)<br>
- button->press_count--;<br>
}<br>
<br>
static void<br>
@@ -162,14 +165,24 @@ static void<br>
frame_button_release(struct frame_button *button)<br>
{<br>
button->press_count--;<br>
- if (!button->press_count)<br>
- button->frame->status |= FRAME_STATUS_REPAINT;<br>
+ if (button->press_count)<br>
+ return;<br>
+<br>
+ button->frame->status |= FRAME_STATUS_REPAINT;<br>
<br>
if (!(button->flags & FRAME_BUTTON_CLICK_DOWN))<br>
button->frame->status |= button->status_effect;<br>
}<br>
<br>
static void<br>
+frame_button_cancel(struct frame_button *button)<br>
+{<br>
+ button->press_count--;<br>
+ if (!button->press_count)<br>
+ button->frame->status |= FRAME_STATUS_REPAINT;<br>
+}<br>
+<br>
+static void<br>
frame_button_repaint(struct frame_button *button, cairo_t *cr)<br>
{<br>
int x, y;<br>
@@ -225,6 +238,7 @@ frame_pointer_get(struct frame *frame, void *data)<br>
return NULL;<br>
<br>
pointer->data = data;<br>
+ wl_list_init(&pointer->down_buttons);<br>
wl_list_insert(&frame->pointers, &pointer->link);<br>
<br>
return pointer;<br>
@@ -616,8 +630,6 @@ frame_pointer_motion(struct frame *frame, void *data, int x, int y)<br>
if (pointer->hover_button)<br>
frame_button_leave(pointer->hover_button, pointer);<br>
<br>
- /* No drags */<br>
- pointer->active = 0;<br>
pointer->hover_button = button;<br>
<br>
if (pointer->hover_button)<br>
@@ -626,24 +638,97 @@ frame_pointer_motion(struct frame *frame, void *data, int x, int y)<br>
return location;<br>
}<br>
<br>
+static void<br>
+frame_pointer_button_destroy(struct frame_pointer_button *button)<br>
+{<br>
+ wl_list_remove(&button->link);<br>
+ free(button);<br>
+}<br>
+<br>
+static void<br>
+frame_pointer_button_press(struct frame *frame, struct frame_pointer *pointer,<br>
+ struct frame_pointer_button *button)<br>
+{<br>
+ if (button->button == BTN_RIGHT) {<br>
+ if (button->press_location == THEME_LOCATION_TITLEBAR)<br>
+ frame->status |= FRAME_STATUS_MENU;<br>
+<br>
+ frame_pointer_button_destroy(button);<br>
+<br>
+ } else if (button->button == BTN_LEFT) {<br>
+ if (pointer->hover_button) {<br>
+ frame_button_press(pointer->hover_button);<br>
+ } else {<br>
+ switch (button->press_location) {<br>
+ case THEME_LOCATION_TITLEBAR:<br>
+ frame->status |= FRAME_STATUS_MOVE;<br>
+<br>
+ frame_pointer_button_destroy(button);<br>
+ break;<br>
+ case THEME_LOCATION_RESIZING_TOP:<br>
+ case THEME_LOCATION_RESIZING_BOTTOM:<br>
+ case THEME_LOCATION_RESIZING_LEFT:<br>
+ case THEME_LOCATION_RESIZING_RIGHT:<br>
+ case THEME_LOCATION_RESIZING_TOP_LEFT:<br>
+ case THEME_LOCATION_RESIZING_TOP_RIGHT:<br>
+ case THEME_LOCATION_RESIZING_BOTTOM_LEFT:<br>
+ case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:<br>
+ frame->status |= FRAME_STATUS_RESIZE;<br>
+<br>
+ frame_pointer_button_destroy(button);<br>
+ break;<br>
+ default:<br>
+ break;<br>
+ }<br>
+ }<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+frame_pointer_button_release(struct frame *frame, struct frame_pointer *pointer,<br>
+ struct frame_pointer_button *button)<br>
+{<br>
+ if (button->button == BTN_LEFT && button->frame_button) {<br>
+ if (button->frame_button == pointer->hover_button)<br>
+ frame_button_release(button->frame_button);<br>
+ else<br>
+ frame_button_cancel(button->frame_button);<br>
+ }<br>
+}<br>
+<br>
+static void<br>
+frame_pointer_button_cancel(struct frame *frame, struct frame_pointer *pointer,<br>
+ struct frame_pointer_button *button)<br>
+{<br>
+ if (button->frame_button)<br>
+ frame_button_cancel(button->frame_button);<br>
+}<br>
+<br>
void<br>
frame_pointer_leave(struct frame *frame, void *data)<br>
{<br>
struct frame_pointer *pointer = frame_pointer_get(frame, data);<br>
+ struct frame_pointer_button *button, *next;<br>
if (!pointer)<br>
return;<br>
<br>
if (pointer->hover_button)<br>
frame_button_leave(pointer->hover_button, pointer);<br>
+<br>
+ wl_list_for_each_safe(button, next, &pointer->down_buttons, link) {<br>
+ frame_pointer_button_cancel(frame, pointer, button);<br>
+ frame_pointer_button_destroy(button);<br>
+ }<br>
<br>
frame_pointer_destroy(pointer);<br>
}<br>
<br>
enum theme_location<br>
frame_pointer_button(struct frame *frame, void *data,<br>
- uint32_t button, enum frame_button_state state)<br>
+ uint32_t btn, enum frame_button_state state)<br>
{<br>
struct frame_pointer *pointer = frame_pointer_get(frame, data);<br>
+ struct frame_pointer_button *button;<br>
enum theme_location location;<br>
<br>
location = theme_get_location(frame->theme, pointer->x, pointer->y,<br>
@@ -654,40 +739,29 @@ frame_pointer_button(struct frame *frame, void *data,<br>
if (!pointer)<br>
return location;<br>
<br>
- if (button == BTN_RIGHT) {<br>
- if (state == FRAME_BUTTON_PRESSED &&<br>
- location == THEME_LOCATION_TITLEBAR)<br>
- frame->status |= FRAME_STATUS_MENU;<br>
-<br>
- } else if (button == BTN_LEFT && state == FRAME_BUTTON_PRESSED) {<br>
- if (pointer->hover_button) {<br>
- pointer->active = 1;<br>
- frame_button_press(pointer->hover_button);<br>
+ if (state == FRAME_BUTTON_PRESSED) {<br>
+ button = malloc(sizeof *button);<br>
+ if (!button)<br>
return location;<br>
- } else {<br>
- switch (location) {<br>
- case THEME_LOCATION_TITLEBAR:<br>
- frame->status |= FRAME_STATUS_MOVE;<br>
- break;<br>
- case THEME_LOCATION_RESIZING_TOP:<br>
- case THEME_LOCATION_RESIZING_BOTTOM:<br>
- case THEME_LOCATION_RESIZING_LEFT:<br>
- case THEME_LOCATION_RESIZING_RIGHT:<br>
- case THEME_LOCATION_RESIZING_TOP_LEFT:<br>
- case THEME_LOCATION_RESIZING_TOP_RIGHT:<br>
- case THEME_LOCATION_RESIZING_BOTTOM_LEFT:<br>
- case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:<br>
- frame->status |= FRAME_STATUS_RESIZE;<br>
- break;<br>
- default:<br>
+<br>
+ button->button = btn;<br>
+ button->press_location = location;<br>
+ button->frame_button = pointer->hover_button;<br>
+ wl_list_insert(&pointer->down_buttons, &button->link);<br>
+<br>
+ frame_pointer_button_press(frame, pointer, button);<br>
+ } else if (state == FRAME_BUTTON_RELEASED) {<br>
+ button = NULL;<br>
+ wl_list_for_each(button, &pointer->down_buttons, link)<br>
+ if (button->button == btn)<br>
break;<br>
- }<br>
- }<br>
- } else if (button == BTN_LEFT && state == FRAME_BUTTON_RELEASED) {<br>
- if (pointer->hover_button && pointer->active)<br>
- frame_button_release(pointer->hover_button);<br>
+ /* Make sure we didn't hit the end */<br>
+ if (&button->link == &pointer->down_buttons)<br>
+ return location;<br>
<br>
- pointer->active = 0;<br>
+ location = button->press_location;<br>
+ frame_pointer_button_release(frame, pointer, button);<br>
+ frame_pointer_button_destroy(button);<br>
}<br>
<br>
return location;<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.1<br>
<br>
</font></span></blockquote></div><br></div>