From 92891b4dfa6d45bf7c08e4c53bc0113ca8adc8bc Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 30 Aug 2021 18:42:38 -0400 Subject: [PATCH] change mousebind code to use already existing enums Also added an #include statement to ssd.h so it would compile without depending on other headers to be #included before it --- include/config/mousebind.h | 21 +++------------------ include/ssd.h | 2 ++ src/config/mousebind.c | 29 +++++++++++++++-------------- src/cursor.c | 4 ++-- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/include/config/mousebind.h b/include/config/mousebind.h index 6fb57ac4..ebe9ca09 100644 --- a/include/config/mousebind.h +++ b/include/config/mousebind.h @@ -1,32 +1,17 @@ #ifndef __LABWC_MOUSEBIND_H #define __LABWC_MOUSEBIND_H +#include "ssd.h" #include -enum mouse_context { - MOUSE_CONTEXT_TITLEBAR, - MOUSE_CONTEXT_NONE -}; - -enum mouse_button { - /* - * These values match the values returned by button event->button and were - * obtained experimentally - */ - MOUSE_BUTTON_LEFT = 272, - MOUSE_BUTTON_RIGHT = 273, - MOUSE_BUTTON_MIDDLE = 274, - MOUSE_BUTTON_NONE = -1 -}; - enum action_mouse_did { MOUSE_ACTION_DOUBLECLICK, MOUSE_ACTION_NONE }; struct mousebind { - enum mouse_context context; /* ex: titlebar */ - enum mouse_button button; /* ex: left, right, middle */ + enum ssd_part_type context; /* ex: titlebar */ + uint32_t button; /* ex: BTN_LEFT, BTN_RIGHT from linux/input_event_codes.h */ enum action_mouse_did mouse_action; /* ex: doubleclick, press, drag, etc */ const char* action; /* what to do because mouse did previous action */ const char* command; diff --git a/include/ssd.h b/include/ssd.h index 111ea729..f29b1940 100644 --- a/include/ssd.h +++ b/include/ssd.h @@ -1,6 +1,8 @@ #ifndef __LABWC_SSD_H #define __LABWC_SSD_H +#include "labwc.h" + /* * Sequence these according to the order they should be processes for * press and hover events. Bear in mind that some of their respective diff --git a/src/config/mousebind.c b/src/config/mousebind.c index e3ffbb83..4dbf6cd8 100644 --- a/src/config/mousebind.c +++ b/src/config/mousebind.c @@ -4,34 +4,35 @@ #include #include #include +#include -static enum mouse_context +static enum ssd_part_type context_from_str(const char* str) { if(str == NULL) { - return MOUSE_CONTEXT_NONE; + return LAB_SSD_NONE; } else if(strcasecmp(str, "Titlebar") == 0) { - return MOUSE_CONTEXT_TITLEBAR; + return LAB_SSD_PART_TITLEBAR; } else { - return MOUSE_CONTEXT_NONE; + return LAB_SSD_NONE; } } -static enum mouse_button +static uint32_t mouse_button_from_str(const char* str) { if(str == NULL) { - return MOUSE_BUTTON_NONE; + return UINT32_MAX; } else if(strcasecmp(str, "Left") == 0) { - return MOUSE_BUTTON_LEFT; + return BTN_LEFT; } else if(strcasecmp(str, "Right") == 0) { - return MOUSE_BUTTON_RIGHT; + return BTN_RIGHT; } else if(strcasecmp(str, "Middle") == 0) { - return MOUSE_BUTTON_MIDDLE; + return BTN_MIDDLE; } else { - return MOUSE_BUTTON_NONE; + return UINT32_MAX; } } @@ -55,15 +56,15 @@ mousebind_create(const char* context_str, const char* mouse_button_str, { struct mousebind* m = calloc(1, sizeof(struct mousebind)); - enum mouse_context context = context_from_str(context_str); - enum mouse_button button = mouse_button_from_str(mouse_button_str); + enum ssd_part_type context = context_from_str(context_str); + uint32_t button = mouse_button_from_str(mouse_button_str); enum action_mouse_did action_mouse_did = action_mouse_did_from_str(action_mouse_did_str); - if(context == MOUSE_CONTEXT_NONE) { + if(context == LAB_SSD_NONE) { wlr_log(WLR_ERROR, "unknown mouse context (%s)", context_str); goto CREATE_ERROR; } - if(button == MOUSE_BUTTON_NONE) { + if(button == UINT32_MAX) { wlr_log(WLR_ERROR, "unknown button (%s)", mouse_button_str); goto CREATE_ERROR; } diff --git a/src/cursor.c b/src/cursor.c index 9801dd41..ab1eb9c1 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -346,9 +346,9 @@ cursor_button(struct wl_listener *listener, void *data) if (is_double_click(rc.doubleclick_time) && view_area == LAB_SSD_PART_TITLEBAR) { struct mousebind* mousebind; wl_list_for_each_reverse(mousebind, &rc.mousebinds, link) { - if( (mousebind->context == MOUSE_CONTEXT_TITLEBAR) && + if( (mousebind->context == LAB_SSD_PART_TITLEBAR) && (mousebind->mouse_action == MOUSE_ACTION_DOUBLECLICK) && - (mousebind->button == (enum mouse_button)event->button) ) { + (mousebind->button == event->button) ) { action(server, mousebind->action, mousebind->command); } } -- 2.52.0