]> git.mdlowis.com Git - proto/labwc.git/commitdiff
change mousebind code to use already existing enums
authoralex <alex@compy-sid>
Mon, 30 Aug 2021 22:42:38 +0000 (18:42 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 1 Sep 2021 06:05:37 +0000 (07:05 +0100)
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
include/ssd.h
src/config/mousebind.c
src/cursor.c

index 6fb57ac49b68699a03e44f233cd583539c408fb3..ebe9ca09f9ee8627618da9a575248e400442a821 100644 (file)
@@ -1,32 +1,17 @@
 #ifndef __LABWC_MOUSEBIND_H
 #define __LABWC_MOUSEBIND_H
 
+#include "ssd.h"
 #include <wayland-util.h>
 
-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;
index 111ea729311d712f3ceba5d58cf4f6188386c12b..f29b19406e25b9f8871b3268a178f79e130ecf21 100644 (file)
@@ -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
index e3ffbb839c7d9bab53ae828681c57718b84b800b..4dbf6cd8c69334a635f8ddc0aa9849874a7d2a23 100644 (file)
@@ -4,34 +4,35 @@
 #include <wlr/util/log.h>
 #include <strings.h>
 #include <unistd.h>
+#include <linux/input-event-codes.h>
 
-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;
        }
index 9801dd41dd87b1f40d53383269dd55270ef1aa39..ab1eb9c125761b6e611e8d056f7c8e461efacf85 100644 (file)
@@ -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);
                        }
                }