Use enum wl_pointer_button_state instead of integer
Instead of using a uint32_t for state everywhere (except on the wire, where that's still the call signature), use the new wl_pointer_button_state enum, and explicit comparisons. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
committed by
Kristian Høgsberg
parent
11d7139989
commit
4dbadb1556
+3
-2
@@ -197,11 +197,12 @@ key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
static void
|
||||
button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button,
|
||||
enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct clickdot *clickdot = data;
|
||||
|
||||
if (state && button == BTN_LEFT)
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED && button == BTN_LEFT)
|
||||
input_get_position(input, &clickdot->dot.x, &clickdot->dot.y);
|
||||
|
||||
widget_schedule_redraw(widget);
|
||||
|
||||
+10
-6
@@ -269,24 +269,26 @@ panel_launcher_leave_handler(struct widget *widget,
|
||||
static void
|
||||
panel_launcher_button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button,
|
||||
enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct panel_launcher *launcher;
|
||||
|
||||
launcher = widget_get_user_data(widget);
|
||||
widget_schedule_redraw(widget);
|
||||
if (state == 0)
|
||||
if (state == WL_POINTER_BUTTON_STATE_RELEASED)
|
||||
panel_launcher_activate(launcher);
|
||||
}
|
||||
|
||||
static void
|
||||
panel_button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button,
|
||||
enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct panel *panel = data;
|
||||
|
||||
if (button == BTN_RIGHT && state)
|
||||
if (button == BTN_RIGHT && state == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
show_menu(panel, input, time);
|
||||
}
|
||||
|
||||
@@ -496,13 +498,15 @@ unlock_dialog_redraw_handler(struct widget *widget, void *data)
|
||||
static void
|
||||
unlock_dialog_button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button,
|
||||
enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct unlock_dialog *dialog = data;
|
||||
struct desktop *desktop = dialog->desktop;
|
||||
|
||||
if (button == BTN_LEFT) {
|
||||
if (state == 0 && !dialog->closing) {
|
||||
if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
|
||||
!dialog->closing) {
|
||||
display_defer(desktop->display, &desktop->unlock_task);
|
||||
dialog->closing = 1;
|
||||
}
|
||||
|
||||
+3
-2
@@ -358,7 +358,8 @@ create_drag_cursor(struct dnd_drag *dnd_drag,
|
||||
static void
|
||||
dnd_button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button, enum wl_pointer_button_state state,
|
||||
void *data)
|
||||
{
|
||||
struct dnd *dnd = data;
|
||||
int32_t x, y;
|
||||
@@ -378,7 +379,7 @@ dnd_button_handler(struct widget *widget,
|
||||
x -= allocation.x;
|
||||
y -= allocation.y;
|
||||
|
||||
if (item && state == 1) {
|
||||
if (item && state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
dnd_drag = malloc(sizeof *dnd_drag);
|
||||
dnd_drag->dnd = dnd;
|
||||
dnd_drag->input = input;
|
||||
|
||||
+6
-3
@@ -210,7 +210,7 @@ key_handler(struct window *window, struct input *input, uint32_t time,
|
||||
*/
|
||||
static void
|
||||
button_handler(struct widget *widget, struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button, enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
int32_t x, y;
|
||||
|
||||
@@ -218,8 +218,11 @@ button_handler(struct widget *widget, struct input *input, uint32_t time,
|
||||
return;
|
||||
|
||||
input_get_position(input, &x, &y);
|
||||
printf("button time: %d, button: %d, state: %d, x: %d, y: %d\n",
|
||||
time, button, state, x, y);
|
||||
printf("button time: %d, button: %d, state: %s, x: %d, y: %d\n",
|
||||
time, button,
|
||||
(state == WL_POINTER_BUTTON_STATE_PRESSED) ? "pressed" :
|
||||
"released",
|
||||
x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-4
@@ -139,22 +139,22 @@ motion_handler(struct widget *widget, struct input *input,
|
||||
static void
|
||||
button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button, enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct flower *flower = data;
|
||||
|
||||
switch (button) {
|
||||
case BTN_LEFT:
|
||||
if (state)
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
window_move(flower->window, input,
|
||||
display_get_serial(flower->display));
|
||||
break;
|
||||
case BTN_MIDDLE:
|
||||
if (state)
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
widget_schedule_redraw(widget);
|
||||
break;
|
||||
case BTN_RIGHT:
|
||||
if (state)
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
window_show_frame_menu(flower->window, input, time);
|
||||
break;
|
||||
}
|
||||
|
||||
+3
-2
@@ -248,12 +248,13 @@ motion_handler(struct widget *widget, struct input *input,
|
||||
|
||||
static void
|
||||
button_handler(struct widget *widget, struct input *input,
|
||||
uint32_t time, uint32_t button, uint32_t state, void *data)
|
||||
uint32_t time, uint32_t button,
|
||||
enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct gears *gears = data;
|
||||
|
||||
if (button == BTN_LEFT) {
|
||||
if (state) {
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
gears->button_down = 1;
|
||||
input_get_position(input,
|
||||
&gears->last_x, &gears->last_y);
|
||||
|
||||
+2
-2
@@ -215,13 +215,13 @@ show_menu(struct resizor *resizor, struct input *input, uint32_t time)
|
||||
static void
|
||||
button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button, enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct resizor *resizor = data;
|
||||
|
||||
switch (button) {
|
||||
case BTN_RIGHT:
|
||||
if (state)
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
show_menu(resizor, input, time);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -217,11 +217,12 @@ lockscreen_draw(struct widget *widget, void *data)
|
||||
static void
|
||||
lockscreen_button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button,
|
||||
enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct lockscreen *lockscreen = data;
|
||||
|
||||
if (state && lockscreen->window) {
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED && lockscreen->window) {
|
||||
window_destroy(lockscreen->window);
|
||||
lockscreen->window = NULL;
|
||||
}
|
||||
|
||||
+3
-2
@@ -2222,13 +2222,14 @@ keyboard_focus_handler(struct window *window,
|
||||
static void
|
||||
button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button,
|
||||
enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct terminal *terminal = data;
|
||||
|
||||
switch (button) {
|
||||
case 272:
|
||||
if (state) {
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
terminal->dragging = 1;
|
||||
input_get_position(input,
|
||||
&terminal->selection_start_x,
|
||||
|
||||
+3
-2
@@ -138,11 +138,12 @@ view_page_down(struct view *view)
|
||||
|
||||
static void
|
||||
button_handler(struct widget *widget, struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button, enum wl_pointer_button_state state,
|
||||
void *data)
|
||||
{
|
||||
struct view *view = data;
|
||||
|
||||
if(!state)
|
||||
if (state == WL_POINTER_BUTTON_STATE_RELEASED)
|
||||
return;
|
||||
|
||||
switch(button) {
|
||||
|
||||
+20
-11
@@ -1352,7 +1352,8 @@ frame_button_leave_handler(struct widget *widget, struct input *input, void *dat
|
||||
static void
|
||||
frame_button_button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button,
|
||||
enum wl_pointer_button_state state, void *data)
|
||||
{
|
||||
struct frame_button *frame_button = data;
|
||||
struct window *window = widget->window;
|
||||
@@ -1361,14 +1362,14 @@ frame_button_button_handler(struct widget *widget,
|
||||
return;
|
||||
|
||||
switch (state) {
|
||||
case 1:
|
||||
case WL_POINTER_BUTTON_STATE_PRESSED:
|
||||
frame_button->state = FRAME_BUTTON_ACTIVE;
|
||||
widget_schedule_redraw(frame_button->widget);
|
||||
|
||||
if (frame_button->type == FRAME_BUTTON_ICON)
|
||||
window_show_frame_menu(window, input, time);
|
||||
return;
|
||||
case 0:
|
||||
case WL_POINTER_BUTTON_STATE_RELEASED:
|
||||
frame_button->state = FRAME_BUTTON_DEFAULT;
|
||||
widget_schedule_redraw(frame_button->widget);
|
||||
break;
|
||||
@@ -1593,7 +1594,8 @@ frame_motion_handler(struct widget *widget,
|
||||
static void
|
||||
frame_button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button, enum wl_pointer_button_state state,
|
||||
void *data)
|
||||
|
||||
{
|
||||
struct frame *frame = data;
|
||||
@@ -1605,7 +1607,8 @@ frame_button_handler(struct widget *widget,
|
||||
frame->widget->allocation.width,
|
||||
frame->widget->allocation.height);
|
||||
|
||||
if (window->display->shell && button == BTN_LEFT && state == 1) {
|
||||
if (window->display->shell && button == BTN_LEFT &&
|
||||
state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
switch (location) {
|
||||
case THEME_LOCATION_TITLEBAR:
|
||||
if (!window->shell_surface)
|
||||
@@ -1642,7 +1645,8 @@ frame_button_handler(struct widget *widget,
|
||||
display->serial, location);
|
||||
break;
|
||||
}
|
||||
} else if (button == BTN_RIGHT && state == 1) {
|
||||
} else if (button == BTN_RIGHT &&
|
||||
state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
||||
window_show_frame_menu(window, input, time);
|
||||
}
|
||||
}
|
||||
@@ -1784,13 +1788,15 @@ input_ungrab(struct input *input)
|
||||
|
||||
static void
|
||||
pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
|
||||
uint32_t time, uint32_t button, uint32_t state)
|
||||
uint32_t time, uint32_t button, uint32_t state_w)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct widget *widget;
|
||||
enum wl_pointer_button_state state = state_w;
|
||||
|
||||
input->display->serial = serial;
|
||||
if (input->focus_widget && input->grab == NULL && state)
|
||||
if (input->focus_widget && input->grab == NULL &&
|
||||
state == WL_POINTER_BUTTON_STATE_PRESSED)
|
||||
input_grab(input, input->focus_widget, button);
|
||||
|
||||
widget = input->grab;
|
||||
@@ -1800,7 +1806,8 @@ pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
|
||||
button, state,
|
||||
input->grab->user_data);
|
||||
|
||||
if (input->grab && input->grab_button == button && !state)
|
||||
if (input->grab && input->grab_button == button &&
|
||||
state == WL_POINTER_BUTTON_STATE_RELEASED)
|
||||
input_ungrab(input);
|
||||
}
|
||||
|
||||
@@ -2845,12 +2852,14 @@ menu_leave_handler(struct widget *widget, struct input *input, void *data)
|
||||
static void
|
||||
menu_button_handler(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state, void *data)
|
||||
uint32_t button, enum wl_pointer_button_state state,
|
||||
void *data)
|
||||
|
||||
{
|
||||
struct menu *menu = data;
|
||||
|
||||
if (state == 0 && time - menu->time > 500) {
|
||||
if (state == WL_POINTER_BUTTON_STATE_PRESSED &&
|
||||
time - menu->time > 500) {
|
||||
/* Either relase after press-drag-release or
|
||||
* click-motion-click. */
|
||||
menu->func(menu->window->parent,
|
||||
|
||||
+2
-1
@@ -189,7 +189,8 @@ typedef int (*widget_motion_handler_t)(struct widget *widget,
|
||||
float x, float y, void *data);
|
||||
typedef void (*widget_button_handler_t)(struct widget *widget,
|
||||
struct input *input, uint32_t time,
|
||||
uint32_t button, uint32_t state,
|
||||
uint32_t button,
|
||||
enum wl_pointer_button_state state,
|
||||
void *data);
|
||||
|
||||
struct window *
|
||||
|
||||
Reference in New Issue
Block a user