mirror of
https://github.com/labwc/labwc.git
synced 2026-03-30 11:10:41 -04:00
Apply coding std to <mouse> code & add .clang-format
The files:
include/config/mousebind.h
src/config/mousebind.c
src/config/rc.xml
were formatted automatically via clang-format using the rules specified
in the .clang-format file. Specifically, the command;
clang-format -i -style=file include/config/mousebind.h \
src/config/mousebind.c src/config/rc.xml
This is unfortunately adding a break before the brace in enum
declarations
This commit is contained in:
parent
10a685a0e4
commit
1ac654f006
4 changed files with 117 additions and 102 deletions
7
.clang-format
Normal file
7
.clang-format
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 8
|
||||||
|
AlwaysBreakAfterReturnType: TopLevel
|
||||||
|
UseTab: ForIndentation
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
|
@ -4,23 +4,30 @@
|
||||||
#include "ssd.h"
|
#include "ssd.h"
|
||||||
#include <wayland-util.h>
|
#include <wayland-util.h>
|
||||||
|
|
||||||
enum action_mouse_did {
|
enum action_mouse_did
|
||||||
|
{
|
||||||
MOUSE_ACTION_DOUBLECLICK,
|
MOUSE_ACTION_DOUBLECLICK,
|
||||||
MOUSE_ACTION_NONE
|
MOUSE_ACTION_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mousebind {
|
struct mousebind {
|
||||||
enum ssd_part_type context; /* ex: titlebar */
|
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 */
|
/* ex: BTN_LEFT, BTN_RIGHT from linux/input_event_codes.h */
|
||||||
const char* action; /* what to do because mouse did previous action */
|
uint32_t button;
|
||||||
|
|
||||||
|
/* ex: doubleclick, press, drag, etc */
|
||||||
|
enum action_mouse_did mouse_action;
|
||||||
|
|
||||||
|
/* what to do because mouse did previous action */
|
||||||
|
const char *action;
|
||||||
|
|
||||||
const char *command;
|
const char *command;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mousebind *
|
struct mousebind *
|
||||||
mousebind_create(const char *context_str, const char *mouse_button_str,
|
mousebind_create(const char *context_str, const char *mouse_button_str,
|
||||||
const char* action_mouse_did_str, const char* action,
|
const char *action_mouse_did_str, const char *action, const char *command);
|
||||||
const char* command);
|
|
||||||
|
|
||||||
#endif /* __LABWC_MOUSEBIND_H */
|
#endif /* __LABWC_MOUSEBIND_H */
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#include "config/mousebind.h"
|
#include "config/mousebind.h"
|
||||||
#include "config/rcxml.h"
|
#include "config/rcxml.h"
|
||||||
#include <wlr/util/log.h>
|
#include <linux/input-event-codes.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <linux/input-event-codes.h>
|
#include <wlr/util/log.h>
|
||||||
|
|
||||||
static enum ssd_part_type
|
static enum ssd_part_type
|
||||||
context_from_str(const char *str)
|
context_from_str(const char *str)
|
||||||
{
|
{
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
return LAB_SSD_NONE;
|
return LAB_SSD_NONE;
|
||||||
}
|
} else if (strcasecmp(str, "Titlebar") == 0) {
|
||||||
else if(strcasecmp(str, "Titlebar") == 0) {
|
|
||||||
return LAB_SSD_PART_TITLEBAR;
|
return LAB_SSD_PART_TITLEBAR;
|
||||||
} else {
|
} else {
|
||||||
return LAB_SSD_NONE;
|
return LAB_SSD_NONE;
|
||||||
|
|
@ -24,8 +23,7 @@ mouse_button_from_str(const char* str)
|
||||||
{
|
{
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
return UINT32_MAX;
|
return UINT32_MAX;
|
||||||
}
|
} else if (strcasecmp(str, "Left") == 0) {
|
||||||
else if(strcasecmp(str, "Left") == 0) {
|
|
||||||
return BTN_LEFT;
|
return BTN_LEFT;
|
||||||
} else if (strcasecmp(str, "Right") == 0) {
|
} else if (strcasecmp(str, "Right") == 0) {
|
||||||
return BTN_RIGHT;
|
return BTN_RIGHT;
|
||||||
|
|
@ -41,8 +39,7 @@ action_mouse_did_from_str(const char* str)
|
||||||
{
|
{
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
return MOUSE_ACTION_NONE;
|
return MOUSE_ACTION_NONE;
|
||||||
}
|
} else if (strcasecmp(str, "doubleclick") == 0) {
|
||||||
else if(strcasecmp(str, "doubleclick") == 0) {
|
|
||||||
return MOUSE_ACTION_DOUBLECLICK;
|
return MOUSE_ACTION_DOUBLECLICK;
|
||||||
} else {
|
} else {
|
||||||
return MOUSE_ACTION_NONE;
|
return MOUSE_ACTION_NONE;
|
||||||
|
|
@ -51,14 +48,14 @@ action_mouse_did_from_str(const char* str)
|
||||||
|
|
||||||
struct mousebind *
|
struct mousebind *
|
||||||
mousebind_create(const char *context_str, const char *mouse_button_str,
|
mousebind_create(const char *context_str, const char *mouse_button_str,
|
||||||
const char* action_mouse_did_str, const char* action,
|
const char *action_mouse_did_str, const char *action, const char *command)
|
||||||
const char* command)
|
|
||||||
{
|
{
|
||||||
struct mousebind *m = calloc(1, sizeof(struct mousebind));
|
struct mousebind *m = calloc(1, sizeof(struct mousebind));
|
||||||
|
|
||||||
enum ssd_part_type context = context_from_str(context_str);
|
enum ssd_part_type context = context_from_str(context_str);
|
||||||
uint32_t button = mouse_button_from_str(mouse_button_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);
|
enum action_mouse_did action_mouse_did =
|
||||||
|
action_mouse_did_from_str(action_mouse_did_str);
|
||||||
|
|
||||||
if (context == LAB_SSD_NONE) {
|
if (context == LAB_SSD_NONE) {
|
||||||
wlr_log(WLR_ERROR, "unknown mouse context (%s)", context_str);
|
wlr_log(WLR_ERROR, "unknown mouse context (%s)", context_str);
|
||||||
|
|
@ -69,7 +66,8 @@ mousebind_create(const char* context_str, const char* mouse_button_str,
|
||||||
goto CREATE_ERROR;
|
goto CREATE_ERROR;
|
||||||
}
|
}
|
||||||
if (action_mouse_did == MOUSE_ACTION_NONE) {
|
if (action_mouse_did == MOUSE_ACTION_NONE) {
|
||||||
wlr_log(WLR_ERROR, "unknown mouse action (%s)", action_mouse_did_str);
|
wlr_log(WLR_ERROR, "unknown mouse action (%s)",
|
||||||
|
action_mouse_did_str);
|
||||||
goto CREATE_ERROR;
|
goto CREATE_ERROR;
|
||||||
}
|
}
|
||||||
if (action == NULL) {
|
if (action == NULL) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,11 @@
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include "config/rcxml.h"
|
||||||
|
#include "common/dir.h"
|
||||||
|
#include "common/nodename.h"
|
||||||
|
#include "common/string-helpers.h"
|
||||||
|
#include "common/zfree.h"
|
||||||
|
#include "config/keybind.h"
|
||||||
|
#include "config/mousebind.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
@ -12,13 +19,6 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "common/dir.h"
|
|
||||||
#include "common/nodename.h"
|
|
||||||
#include "common/string-helpers.h"
|
|
||||||
#include "common/zfree.h"
|
|
||||||
#include "config/keybind.h"
|
|
||||||
#include "config/mousebind.h"
|
|
||||||
#include "config/rcxml.h"
|
|
||||||
|
|
||||||
static bool in_keybind = false;
|
static bool in_keybind = false;
|
||||||
static bool in_mousebind = false;
|
static bool in_mousebind = false;
|
||||||
|
|
@ -26,8 +26,8 @@ static bool is_attribute = false;
|
||||||
static struct keybind *current_keybind;
|
static struct keybind *current_keybind;
|
||||||
static const char *current_mouse_context = "";
|
static const char *current_mouse_context = "";
|
||||||
|
|
||||||
|
enum font_place
|
||||||
enum font_place {
|
{
|
||||||
FONT_PLACE_UNKNOWN = 0,
|
FONT_PLACE_UNKNOWN = 0,
|
||||||
FONT_PLACE_ACTIVEWINDOW,
|
FONT_PLACE_ACTIVEWINDOW,
|
||||||
FONT_PLACE_MENUITEM,
|
FONT_PLACE_MENUITEM,
|
||||||
|
|
@ -54,8 +54,8 @@ struct mouse_action {
|
||||||
static struct mouse_action mouse_actions[MAX_MOUSE_ACTIONS] = {{0}};
|
static struct mouse_action mouse_actions[MAX_MOUSE_ACTIONS] = {{0}};
|
||||||
static int num_mouse_actions = 0;
|
static int num_mouse_actions = 0;
|
||||||
|
|
||||||
|
static void
|
||||||
static void load_default_key_bindings(void);
|
load_default_key_bindings(void);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fill_keybind(char *nodename, char *content)
|
fill_keybind(char *nodename, char *content)
|
||||||
|
|
@ -91,29 +91,27 @@ add_new_mousebinds(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < num_mouse_actions; i++) {
|
for (int i = 0; i < num_mouse_actions; i++) {
|
||||||
struct mousebind *m = mousebind_create(current_mouse_context,
|
struct mousebind *m = mousebind_create(current_mouse_context,
|
||||||
current_mouse_button,
|
current_mouse_button, current_action_mouse_did,
|
||||||
current_action_mouse_did,
|
mouse_actions[i].action, mouse_actions[i].command);
|
||||||
mouse_actions[i].action,
|
|
||||||
mouse_actions[i].command);
|
|
||||||
if (m != NULL) {
|
if (m != NULL) {
|
||||||
wl_list_insert(&rc.mousebinds, &m->link);
|
wl_list_insert(&rc.mousebinds, &m->link);
|
||||||
} else {
|
} else {
|
||||||
wlr_log(WLR_ERROR, "failed to create mousebind\n"
|
wlr_log(WLR_ERROR,
|
||||||
|
"failed to create mousebind\n"
|
||||||
" context: (%s)\n"
|
" context: (%s)\n"
|
||||||
" button: (%s)\n"
|
" button: (%s)\n"
|
||||||
" mouse action (%s)\n"
|
" mouse action (%s)\n"
|
||||||
" action (%s)\n"
|
" action (%s)\n"
|
||||||
" command: (%s)\n",
|
" command: (%s)\n",
|
||||||
current_mouse_context,
|
current_mouse_context, current_mouse_button,
|
||||||
current_mouse_button,
|
current_action_mouse_did, mouse_actions[i].action,
|
||||||
current_action_mouse_did,
|
|
||||||
mouse_actions[i].action,
|
|
||||||
mouse_actions[i].command);
|
mouse_actions[i].command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
num_mouse_actions = 0;
|
num_mouse_actions = 0;
|
||||||
memset(mouse_actions, 0, sizeof(struct mouse_action) * MAX_MOUSE_ACTIONS);
|
memset(
|
||||||
|
mouse_actions, 0, sizeof(struct mouse_action) * MAX_MOUSE_ACTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -136,13 +134,14 @@ fill_mousebind(char* nodename, char* content)
|
||||||
current_mouse_button = content;
|
current_mouse_button = content;
|
||||||
} else if (!strcmp(nodename, "action")) {
|
} else if (!strcmp(nodename, "action")) {
|
||||||
/*
|
/*
|
||||||
* checking for is_attribute fails even though we are looking for the
|
* checking for is_attribute fails even though we are looking
|
||||||
* attribute of mousebind named action. initial thoughts were to check
|
* for the attribute of mousebind named action. initial thoughts
|
||||||
* for is_attribute to distinguish the attribute of mousebind named
|
* were to check for is_attribute to distinguish the attribute
|
||||||
* action from the child of mousebind named action. since the child of
|
* of mousebind named action from the child of mousebind named
|
||||||
* mousebind named action doesn't have any content, I don't think we
|
* action. since the child of mousebind named action doesn't
|
||||||
* need to make this distinction since we already filtered out nodes that
|
* have any content, I don't think we need to make this
|
||||||
* don't have content
|
* distinction since we already filtered out nodes that don't
|
||||||
|
* have content
|
||||||
*/
|
*/
|
||||||
current_action_mouse_did = content;
|
current_action_mouse_did = content;
|
||||||
} else if (is_attribute && !strcmp(nodename, "name.action")) {
|
} else if (is_attribute && !strcmp(nodename, "name.action")) {
|
||||||
|
|
@ -299,16 +298,17 @@ entry(xmlNode *node, char *nodename, char *content)
|
||||||
* - user gave a negative value (which doesn't make sense)
|
* - user gave a negative value (which doesn't make sense)
|
||||||
* - user gave a value which strtol couldn't parse
|
* - user gave a value which strtol couldn't parse
|
||||||
*
|
*
|
||||||
* since strtol() returns 0 on error, all we have to do is check
|
* since strtol() returns 0 on error, all we have to do is
|
||||||
* for to see if strtol() returned 0 or less to handle the error
|
* check for to see if strtol() returned 0 or less to handle the
|
||||||
* cases. in case of error, we just choose not to override the
|
* error cases. in case of error, we just choose not to override
|
||||||
* default value and everything should be fine
|
* the default value and everything should be fine
|
||||||
*/
|
*/
|
||||||
bool valid_doubleclick_time = doubleclick_time_parsed > 0;
|
bool valid_doubleclick_time = doubleclick_time_parsed > 0;
|
||||||
if (valid_doubleclick_time) {
|
if (valid_doubleclick_time) {
|
||||||
rc.doubleclick_time = doubleclick_time_parsed;
|
rc.doubleclick_time = doubleclick_time_parsed;
|
||||||
}
|
}
|
||||||
} else if(is_attribute && !strcasecmp(nodename, "name.context.mouse")) {
|
} else if (is_attribute &&
|
||||||
|
!strcasecmp(nodename, "name.context.mouse")) {
|
||||||
current_mouse_context = content;
|
current_mouse_context = content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +328,8 @@ process_node(xmlNode *node)
|
||||||
entry(node, name, content);
|
entry(node, name, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xml_tree_walk(xmlNode *node);
|
static void
|
||||||
|
xml_tree_walk(xmlNode *node);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
traverse(xmlNode *n)
|
traverse(xmlNode *n)
|
||||||
|
|
@ -521,7 +522,8 @@ rcxml_finish(void)
|
||||||
zfree(rc.theme_name);
|
zfree(rc.theme_name);
|
||||||
|
|
||||||
struct keybind *k, *k_tmp;
|
struct keybind *k, *k_tmp;
|
||||||
wl_list_for_each_safe (k, k_tmp, &rc.keybinds, link) {
|
wl_list_for_each_safe(k, k_tmp, &rc.keybinds, link)
|
||||||
|
{
|
||||||
wl_list_remove(&k->link);
|
wl_list_remove(&k->link);
|
||||||
zfree(k->command);
|
zfree(k->command);
|
||||||
zfree(k->action);
|
zfree(k->action);
|
||||||
|
|
@ -530,7 +532,8 @@ rcxml_finish(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mousebind *m, *m_tmp;
|
struct mousebind *m, *m_tmp;
|
||||||
wl_list_for_each_safe(m, m_tmp, &rc.mousebinds, link) {
|
wl_list_for_each_safe(m, m_tmp, &rc.mousebinds, link)
|
||||||
|
{
|
||||||
wl_list_remove(&m->link);
|
wl_list_remove(&m->link);
|
||||||
zfree(m->command);
|
zfree(m->command);
|
||||||
zfree(m->action);
|
zfree(m->action);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue