mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
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
This commit is contained in:
parent
36f5b49f2a
commit
92891b4dfa
4 changed files with 22 additions and 34 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue