#define _POSIX_C_SOURCE 200809L
#include "config/mousebind.h"
#include "config/rcxml.h"
-#include <wlr/util/log.h>
+#include <linux/input-event-codes.h>
#include <strings.h>
#include <unistd.h>
-#include <linux/input-event-codes.h>
+#include <wlr/util/log.h>
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;
- }
- else if(strcasecmp(str, "Titlebar") == 0) {
+ } else if (strcasecmp(str, "Titlebar") == 0) {
return LAB_SSD_PART_TITLEBAR;
} else {
return LAB_SSD_NONE;
}
static uint32_t
-mouse_button_from_str(const char* str)
+mouse_button_from_str(const char *str)
{
- if(str == NULL) {
+ if (str == NULL) {
return UINT32_MAX;
- }
- else if(strcasecmp(str, "Left") == 0) {
+ } else if (strcasecmp(str, "Left") == 0) {
return BTN_LEFT;
- } else if(strcasecmp(str, "Right") == 0) {
+ } else if (strcasecmp(str, "Right") == 0) {
return BTN_RIGHT;
- } else if(strcasecmp(str, "Middle") == 0) {
+ } else if (strcasecmp(str, "Middle") == 0) {
return BTN_MIDDLE;
} else {
return UINT32_MAX;
}
static enum action_mouse_did
-action_mouse_did_from_str(const char* str)
+action_mouse_did_from_str(const char *str)
{
- if(str == NULL) {
+ if (str == NULL) {
return MOUSE_ACTION_NONE;
- }
- else if(strcasecmp(str, "doubleclick") == 0) {
+ } 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 *
+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));
+ struct mousebind *m = calloc(1, sizeof(struct mousebind));
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);
+ 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);
goto CREATE_ERROR;
}
- if(button == UINT32_MAX) {
+ if (button == UINT32_MAX) {
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);
+ 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) {
+ if (action == NULL) {
wlr_log(WLR_ERROR, "action is NULL\n");
goto CREATE_ERROR;
}
m->button = button;
m->mouse_action = action_mouse_did;
m->action = strdup(action); /* TODO: replace with strndup? */
- if(command && !strcasecmp(action, "Execute")) {
+ if (command && !strcasecmp(action, "Execute")) {
m->command = strdup(command);
}
#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 <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <wayland-server-core.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_mousebind = false;
static bool is_attribute = false;
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_ACTIVEWINDOW,
FONT_PLACE_MENUITEM,
* unchecked mousebind params. we fill these out one at a time, then pass them
* all to mousebind_create() once we are ready
*/
-static const char* current_mouse_button = "";
-static const char* current_action_mouse_did= "";
+static const char *current_mouse_button = "";
+static const char *current_action_mouse_did = "";
struct mouse_action {
- const char* action;
- const char* command;
+ const char *action;
+ const char *command;
};
/*
* A given mousebind can have multiple actions associated with it.
static struct mouse_action mouse_actions[MAX_MOUSE_ACTIONS] = {{0}};
static int num_mouse_actions = 0;
-
-static void load_default_key_bindings(void);
+static void
+load_default_key_bindings(void);
static void
fill_keybind(char *nodename, char *content)
static void
add_new_mousebinds(void)
{
- for(int i = 0; i < num_mouse_actions; i++) {
- struct mousebind* m = mousebind_create(current_mouse_context,
- current_mouse_button,
- current_action_mouse_did,
- mouse_actions[i].action,
- mouse_actions[i].command);
- if(m != NULL) {
+ for (int i = 0; i < num_mouse_actions; i++) {
+ struct mousebind *m = mousebind_create(current_mouse_context,
+ current_mouse_button, current_action_mouse_did,
+ mouse_actions[i].action, mouse_actions[i].command);
+ if (m != NULL) {
wl_list_insert(&rc.mousebinds, &m->link);
} else {
- wlr_log(WLR_ERROR, "failed to create mousebind\n"
- " context: (%s)\n"
- " button: (%s)\n"
- " mouse action (%s)\n"
- " action (%s)\n"
- " command: (%s)\n",
- current_mouse_context,
- current_mouse_button,
- current_action_mouse_did,
- mouse_actions[i].action,
- mouse_actions[i].command);
+ wlr_log(WLR_ERROR,
+ "failed to create mousebind\n"
+ " context: (%s)\n"
+ " button: (%s)\n"
+ " mouse action (%s)\n"
+ " action (%s)\n"
+ " command: (%s)\n",
+ current_mouse_context, current_mouse_button,
+ current_action_mouse_did, mouse_actions[i].action,
+ mouse_actions[i].command);
}
}
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
-fill_mousebind(char* nodename, char* content)
+fill_mousebind(char *nodename, char *content)
{
/*
* Example of what we're parsing:
* <action name="ToggleMaximize"/>
* </mousebind>
*/
- if(!content) {
+ if (!content) {
return;
}
string_truncate_at_pattern(nodename, ".mousebind.context.mouse");
- if(is_attribute && !strcmp(nodename, "button")) {
+ if (is_attribute && !strcmp(nodename, "button")) {
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
- * attribute of mousebind named action. initial thoughts were to check
- * for is_attribute to distinguish the attribute of mousebind named
- * action from the child of mousebind named action. since the child of
- * mousebind named action doesn't have any content, I don't think we
- * need to make this distinction since we already filtered out nodes that
- * don't have content
+ * checking for is_attribute fails even though we are looking
+ * for the attribute of mousebind named action. initial thoughts
+ * were to check for is_attribute to distinguish the attribute
+ * of mousebind named action from the child of mousebind named
+ * action. since the child of mousebind named action doesn't
+ * have any content, I don't think we need to make this
+ * distinction since we already filtered out nodes that don't
+ * have content
*/
current_action_mouse_did = content;
- } else if(is_attribute && !strcmp(nodename, "name.action")) {
- if(num_mouse_actions < MAX_MOUSE_ACTIONS) {
+ } else if (is_attribute && !strcmp(nodename, "name.action")) {
+ if (num_mouse_actions < MAX_MOUSE_ACTIONS) {
num_mouse_actions++;
- mouse_actions[num_mouse_actions-1].action = content;
+ mouse_actions[num_mouse_actions - 1].action = content;
}
- } else if(!strcmp(nodename, "command.action")) {
- mouse_actions[num_mouse_actions-1].command = content;
+ } else if (!strcmp(nodename, "command.action")) {
+ mouse_actions[num_mouse_actions - 1].command = content;
}
}
}
break;
- /* TODO: implement for all font places */
+ /* TODO: implement for all font places */
default:
break;
} else if (!strcasecmp(nodename, "RaiseOnFocus.focus")) {
rc.focus_follow_mouse = true;
rc.raise_on_focus = get_bool(content);
- } else if(!strcasecmp(nodename, "doubleClickTime.mouse")) {
+ } else if (!strcasecmp(nodename, "doubleClickTime.mouse")) {
long doubleclick_time_parsed = strtol(content, NULL, 10);
/*
* - user gave a negative value (which doesn't make sense)
* - user gave a value which strtol couldn't parse
*
- * since strtol() returns 0 on error, all we have to do is check
- * for to see if strtol() returned 0 or less to handle the error
- * cases. in case of error, we just choose not to override the
- * default value and everything should be fine
+ * since strtol() returns 0 on error, all we have to do is
+ * check for to see if strtol() returned 0 or less to handle the
+ * error cases. in case of error, we just choose not to override
+ * the default value and everything should be fine
*/
bool valid_doubleclick_time = doubleclick_time_parsed > 0;
- if(valid_doubleclick_time) {
+ if (valid_doubleclick_time) {
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;
}
}
entry(node, name, content);
}
-static void xml_tree_walk(xmlNode *node);
+static void
+xml_tree_walk(xmlNode *node);
static void
traverse(xmlNode *n)
traverse(n);
in_keybind = false;
continue;
- }
- if(!strcasecmp((char *)n->name, "mousebind")) {
+ }
+ if (!strcasecmp((char *)n->name, "mousebind")) {
in_mousebind = true;
traverse(n);
in_mousebind = false;
char *line = NULL;
size_t len = 0;
struct buf b;
- static char rcxml[4096] = { 0 };
+ static char rcxml[4096] = {0};
rcxml_init();
zfree(rc.theme_name);
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);
zfree(k->command);
zfree(k->action);
}
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);
zfree(m->command);
zfree(m->action);