mirror of
https://github.com/labwc/labwc.git
synced 2025-11-06 13:29:58 -05:00
First implemenation of <mouse> in rc.xml
Can successfully parse the following XML and and implement the action:
<mouse>
<context name="TitleBar">
<mousebind button="Left" action="DoubleClick">
<action name="ToggleMaximize"/>
</mousebind>
</context>
</mouse>
The XML parsing code for this looks A LOT different than the already
existing XML parsing code. It may have to be reworked
This commit is contained in:
parent
75564d6b8d
commit
dfdb4e4b0e
6 changed files with 335 additions and 1 deletions
90
src/config/mousebind.c
Normal file
90
src/config/mousebind.c
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include "config/mousebind.h"
|
||||
#include "config/rcxml.h"
|
||||
#include <wlr/util/log.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static enum mouse_context
|
||||
context_from_str(const char* str)
|
||||
{
|
||||
if(str == NULL) {
|
||||
return MOUSE_CONTEXT_NONE;
|
||||
}
|
||||
else if(strcasecmp(str, "Titlebar") == 0) {
|
||||
return MOUSE_CONTEXT_TITLEBAR;
|
||||
} else {
|
||||
return MOUSE_CONTEXT_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static enum mouse_button
|
||||
mouse_button_from_str(const char* str)
|
||||
{
|
||||
if(str == NULL) {
|
||||
return MOUSE_BUTTON_NONE;
|
||||
}
|
||||
else if(strcasecmp(str, "Left") == 0) {
|
||||
return MOUSE_BUTTON_LEFT;
|
||||
} else if(strcasecmp(str, "Right") == 0) {
|
||||
return MOUSE_BUTTON_RIGHT;
|
||||
} else if(strcasecmp(str, "Middle") == 0) {
|
||||
return MOUSE_BUTTON_MIDDLE;
|
||||
} else {
|
||||
return MOUSE_BUTTON_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static enum action_mouse_did
|
||||
action_mouse_did_from_str(const char* str)
|
||||
{
|
||||
if(str == NULL) {
|
||||
return MOUSE_ACTION_NONE;
|
||||
}
|
||||
else if(strcasecmp(str, "doubleclick") == 0) {
|
||||
return MOUSE_ACTION_DOUBLECLICK;
|
||||
} else {
|
||||
return MOUSE_ACTION_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
struct mousebind*
|
||||
mousebind_create(const char* context_str, const char* mouse_button_str,
|
||||
const char* action_mouse_did_str, const char* action,
|
||||
const char* command)
|
||||
{
|
||||
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 action_mouse_did action_mouse_did = action_mouse_did_from_str(action_mouse_did_str);
|
||||
|
||||
if(context == MOUSE_CONTEXT_NONE) {
|
||||
wlr_log(WLR_ERROR, "unknown mouse context (%s)", context_str);
|
||||
goto CREATE_ERROR;
|
||||
}
|
||||
if(button == MOUSE_BUTTON_NONE) {
|
||||
wlr_log(WLR_ERROR, "unknown button (%s)", mouse_button_str);
|
||||
goto CREATE_ERROR;
|
||||
}
|
||||
if(action_mouse_did == MOUSE_ACTION_NONE) {
|
||||
wlr_log(WLR_ERROR, "unknown mouse action (%s)", action_mouse_did_str);
|
||||
goto CREATE_ERROR;
|
||||
}
|
||||
if(action == NULL) {
|
||||
wlr_log(WLR_ERROR, "action is NULL\n");
|
||||
goto CREATE_ERROR;
|
||||
}
|
||||
|
||||
m->context = context;
|
||||
m->button = button;
|
||||
m->mouse_action = action_mouse_did;
|
||||
m->action = strdup(action); /* TODO: replace with strndup? */
|
||||
m->command = strdup(command);
|
||||
|
||||
return m;
|
||||
|
||||
CREATE_ERROR:
|
||||
free(m);
|
||||
return NULL;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue