|
Revision 201, 3.5 kB
(checked in by bjourne, 6 years ago)
|
Introduce a new test in tests/test-tool-selector.c and fix the
existing one which complained because the window. Also, don't mind if
the grab fails, it isn't critical.
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
#include <stdlib.h> |
|---|
| 21 |
#include "mouse_handler.h" |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
MouseHandler * |
|---|
| 33 |
mouse_handler_new (GdkCursor *grab_cursor) |
|---|
| 34 |
{ |
|---|
| 35 |
MouseHandler *mh = g_new0 (MouseHandler, 1); |
|---|
| 36 |
mh->pressed = FALSE; |
|---|
| 37 |
mh->dragging = FALSE; |
|---|
| 38 |
mh->drag_base.x = 0; |
|---|
| 39 |
mh->drag_base.y = 0; |
|---|
| 40 |
mh->drag_ofs.x = 0; |
|---|
| 41 |
mh->drag_ofs.y = 0; |
|---|
| 42 |
mh->grab_cursor = grab_cursor; |
|---|
| 43 |
return mh; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
static gboolean |
|---|
| 47 |
mouse_handler_grab_pointer (MouseHandler *mh, |
|---|
| 48 |
GdkWindow *window, |
|---|
| 49 |
guint32 time) |
|---|
| 50 |
{ |
|---|
| 51 |
int mask = (GDK_POINTER_MOTION_MASK |
|---|
| 52 |
| GDK_POINTER_MOTION_HINT_MASK |
|---|
| 53 |
| GDK_BUTTON_RELEASE_MASK); |
|---|
| 54 |
int retval = gdk_pointer_grab (window, |
|---|
| 55 |
FALSE, |
|---|
| 56 |
mask, |
|---|
| 57 |
NULL, |
|---|
| 58 |
mh->grab_cursor, |
|---|
| 59 |
time); |
|---|
| 60 |
return retval == GDK_GRAB_SUCCESS; |
|---|
| 61 |
|
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
gboolean |
|---|
| 76 |
mouse_handler_button_press (MouseHandler *mh, |
|---|
| 77 |
GdkEventButton *ev) |
|---|
| 78 |
{ |
|---|
| 79 |
if (ev->button != 1) |
|---|
| 80 |
return FALSE; |
|---|
| 81 |
mouse_handler_grab_pointer (mh, ev->window, ev->time); |
|---|
| 82 |
mh->pressed = TRUE; |
|---|
| 83 |
mh->drag_base.x = ev->x; |
|---|
| 84 |
mh->drag_base.y = ev->y; |
|---|
| 85 |
mh->drag_ofs.x = ev->x; |
|---|
| 86 |
mh->drag_ofs.y = ev->y; |
|---|
| 87 |
return TRUE; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
gboolean |
|---|
| 91 |
mouse_handler_button_release (MouseHandler *mh, |
|---|
| 92 |
GdkEventButton *ev) |
|---|
| 93 |
{ |
|---|
| 94 |
if (ev->button != 1) |
|---|
| 95 |
return FALSE; |
|---|
| 96 |
gdk_pointer_ungrab (ev->time); |
|---|
| 97 |
mh->pressed = FALSE; |
|---|
| 98 |
mh->dragging = FALSE; |
|---|
| 99 |
return FALSE; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
void |
|---|
| 103 |
mouse_handler_motion_notify (MouseHandler *mh, |
|---|
| 104 |
GdkEventMotion *ev) |
|---|
| 105 |
{ |
|---|
| 106 |
if (mh->pressed) |
|---|
| 107 |
mh->dragging = TRUE; |
|---|
| 108 |
|
|---|
| 109 |
mh->drag_ofs.x = ev->x; |
|---|
| 110 |
mh->drag_ofs.y = ev->y; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
Pos |
|---|
| 114 |
mouse_handler_get_drag_delta (MouseHandler *mh) |
|---|
| 115 |
{ |
|---|
| 116 |
Pos p; |
|---|
| 117 |
p.x = mh->drag_base.x - mh->drag_ofs.x; |
|---|
| 118 |
p.y = mh->drag_base.y - mh->drag_ofs.y; |
|---|
| 119 |
return p; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|