2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2020-06-09 21:40:46 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2020-09-28 20:53:59 +01:00
|
|
|
#include <assert.h>
|
2020-06-05 23:04:54 +01:00
|
|
|
#include <ctype.h>
|
2021-08-29 18:31:57 -04:00
|
|
|
#include <errno.h>
|
2020-09-28 20:41:41 +01:00
|
|
|
#include <fcntl.h>
|
2020-06-05 23:04:54 +01:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
|
#include <libxml/tree.h>
|
2020-09-28 20:41:41 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <strings.h>
|
2020-06-05 23:04:54 +01:00
|
|
|
#include <unistd.h>
|
2020-06-16 07:21:53 +01:00
|
|
|
#include <wayland-server-core.h>
|
2021-07-22 21:30:17 +01:00
|
|
|
#include <wlr/util/log.h>
|
2021-09-06 21:54:00 +01:00
|
|
|
#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"
|
2020-06-05 23:04:54 +01:00
|
|
|
|
2021-09-24 22:04:03 +01:00
|
|
|
static bool in_keybind;
|
|
|
|
|
static bool in_mousebind;
|
2020-06-19 22:00:22 +01:00
|
|
|
static struct keybind *current_keybind;
|
2021-09-06 21:54:00 +01:00
|
|
|
static struct mousebind *current_mousebind;
|
|
|
|
|
static const char *current_mouse_context;
|
2020-06-05 23:04:54 +01:00
|
|
|
|
2021-09-24 22:04:03 +01:00
|
|
|
enum font_place {
|
2020-07-31 11:11:50 +01:00
|
|
|
FONT_PLACE_UNKNOWN = 0,
|
|
|
|
|
FONT_PLACE_ACTIVEWINDOW,
|
2021-08-20 20:27:52 +01:00
|
|
|
FONT_PLACE_MENUITEM,
|
2020-07-31 11:11:50 +01:00
|
|
|
/* TODO: Add all places based on Openbox's rc.xml */
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
static void load_default_key_bindings(void);
|
2021-08-22 17:00:22 +01:00
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
fill_keybind(char *nodename, char *content)
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!content) {
|
2020-06-19 22:00:22 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-02-16 21:03:38 +00:00
|
|
|
string_truncate_at_pattern(nodename, ".keybind.keyboard");
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!strcmp(nodename, "key")) {
|
2020-09-02 21:05:28 +01:00
|
|
|
current_keybind = keybind_create(content);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-07-19 07:07:33 +01:00
|
|
|
/*
|
|
|
|
|
* We expect <keybind key=""> to come first
|
|
|
|
|
* If a invalid keybind has been provided, keybind_create() complains
|
|
|
|
|
* so we just silently ignore it here.
|
|
|
|
|
*/
|
|
|
|
|
if (!current_keybind) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-05 23:04:54 +01:00
|
|
|
if (!strcmp(nodename, "name.action")) {
|
2020-06-19 22:00:22 +01:00
|
|
|
current_keybind->action = strdup(content);
|
|
|
|
|
} else if (!strcmp(nodename, "command.action")) {
|
|
|
|
|
current_keybind->command = strdup(content);
|
2021-07-20 19:54:57 +01:00
|
|
|
} else if (!strcmp(nodename, "direction.action")) {
|
|
|
|
|
current_keybind->command = strdup(content);
|
2020-10-31 15:27:22 +00:00
|
|
|
} else if (!strcmp(nodename, "menu.action")) {
|
|
|
|
|
current_keybind->command = strdup(content);
|
2020-06-05 23:04:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 22:03:41 -04:00
|
|
|
static void
|
2021-08-31 17:43:49 -04:00
|
|
|
fill_mousebind(char *nodename, char *content)
|
2021-08-30 22:03:41 -04:00
|
|
|
{
|
|
|
|
|
/*
|
2021-09-06 21:54:00 +01:00
|
|
|
* Example of what we are parsing:
|
2021-08-30 22:03:41 -04:00
|
|
|
* <mousebind button="Left" action="DoubleClick">
|
|
|
|
|
* <action name="ToggleMaximize"/>
|
|
|
|
|
* </mousebind>
|
|
|
|
|
*/
|
2021-09-06 21:54:00 +01:00
|
|
|
|
|
|
|
|
if (!strcmp(nodename, "mousebind.context.mouse")) {
|
|
|
|
|
wlr_log(WLR_INFO, "create mousebind for %s",
|
|
|
|
|
current_mouse_context);
|
|
|
|
|
current_mousebind = mousebind_create(current_mouse_context);
|
|
|
|
|
}
|
2021-08-31 17:43:49 -04:00
|
|
|
if (!content) {
|
2021-08-30 22:03:41 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string_truncate_at_pattern(nodename, ".mousebind.context.mouse");
|
|
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
if (!strcmp(nodename, "button")) {
|
|
|
|
|
current_mousebind->button = mousebind_button_from_str(content);
|
2021-08-31 17:43:49 -04:00
|
|
|
} else if (!strcmp(nodename, "action")) {
|
2021-09-06 21:54:00 +01:00
|
|
|
/* <mousebind button="" action="EVENT"> */
|
|
|
|
|
current_mousebind->mouse_event =
|
|
|
|
|
mousebind_event_from_str(content);
|
|
|
|
|
} else if (!strcmp(nodename, "name.action")) {
|
|
|
|
|
current_mousebind->action = strdup(content);
|
2021-08-31 17:43:49 -04:00
|
|
|
} else if (!strcmp(nodename, "command.action")) {
|
2021-09-06 21:54:00 +01:00
|
|
|
current_mousebind->command = strdup(content);
|
2021-08-30 22:03:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static bool
|
|
|
|
|
get_bool(const char *s)
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!s) {
|
2020-06-05 23:04:54 +01:00
|
|
|
return false;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (!strcasecmp(s, "yes")) {
|
2020-06-05 23:04:54 +01:00
|
|
|
return true;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (!strcasecmp(s, "true")) {
|
2020-06-05 23:04:54 +01:00
|
|
|
return true;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-05 23:04:54 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-09 09:10:26 -04:00
|
|
|
static enum libinput_config_accel_profile
|
|
|
|
|
get_accel_profile(const char *s)
|
|
|
|
|
{
|
|
|
|
|
if (!s) {
|
|
|
|
|
return LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
|
|
|
|
|
}
|
|
|
|
|
if (!strcasecmp(s, "flat")) {
|
|
|
|
|
return LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
|
|
|
|
|
}
|
|
|
|
|
if (!strcasecmp(s, "adaptive")) {
|
|
|
|
|
return LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
|
|
|
|
|
}
|
|
|
|
|
return LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
fill_font(char *nodename, char *content, enum font_place place)
|
2020-07-31 11:11:50 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!content) {
|
2020-07-31 11:11:50 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-02-16 21:03:38 +00:00
|
|
|
string_truncate_at_pattern(nodename, ".font.theme");
|
2020-07-31 11:11:50 +01:00
|
|
|
|
2021-07-19 20:46:32 +01:00
|
|
|
switch (place) {
|
|
|
|
|
case FONT_PLACE_UNKNOWN:
|
|
|
|
|
/*
|
|
|
|
|
* If <theme><font></font></theme> is used without a place=""
|
|
|
|
|
* attribute, we set all font variables
|
|
|
|
|
*/
|
|
|
|
|
if (!strcmp(nodename, "name")) {
|
|
|
|
|
rc.font_name_activewindow = strdup(content);
|
2021-08-20 20:27:52 +01:00
|
|
|
rc.font_name_menuitem = strdup(content);
|
2021-07-19 20:46:32 +01:00
|
|
|
} else if (!strcmp(nodename, "size")) {
|
|
|
|
|
rc.font_size_activewindow = atoi(content);
|
2021-08-20 20:27:52 +01:00
|
|
|
rc.font_size_menuitem = atoi(content);
|
2021-07-19 20:46:32 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case FONT_PLACE_ACTIVEWINDOW:
|
|
|
|
|
if (!strcmp(nodename, "name")) {
|
|
|
|
|
rc.font_name_activewindow = strdup(content);
|
|
|
|
|
} else if (!strcmp(nodename, "size")) {
|
|
|
|
|
rc.font_size_activewindow = atoi(content);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2021-08-20 20:27:52 +01:00
|
|
|
case FONT_PLACE_MENUITEM:
|
|
|
|
|
if (!strcmp(nodename, "name")) {
|
|
|
|
|
rc.font_name_menuitem = strdup(content);
|
|
|
|
|
} else if (!strcmp(nodename, "size")) {
|
|
|
|
|
rc.font_size_menuitem = atoi(content);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2021-07-19 20:46:32 +01:00
|
|
|
|
2021-08-31 17:43:49 -04:00
|
|
|
/* TODO: implement for all font places */
|
2021-07-19 20:46:32 +01:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-07-31 11:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static enum font_place
|
|
|
|
|
enum_font_place(const char *place)
|
2020-07-31 11:11:50 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!place) {
|
2020-07-31 11:11:50 +01:00
|
|
|
return FONT_PLACE_UNKNOWN;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
if (!strcasecmp(place, "ActiveWindow")) {
|
2020-07-31 11:11:50 +01:00
|
|
|
return FONT_PLACE_ACTIVEWINDOW;
|
2021-08-20 20:27:52 +01:00
|
|
|
} else if (!strcasecmp(place, "MenuItem")) {
|
|
|
|
|
return FONT_PLACE_MENUITEM;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-07-31 11:11:50 +01:00
|
|
|
return FONT_PLACE_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
entry(xmlNode *node, char *nodename, char *content)
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
2021-07-19 20:46:32 +01:00
|
|
|
/* current <theme><font place=""></font></theme> */
|
2020-07-31 11:11:50 +01:00
|
|
|
static enum font_place font_place = FONT_PLACE_UNKNOWN;
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!nodename) {
|
2020-06-05 23:04:54 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-02-16 21:03:38 +00:00
|
|
|
string_truncate_at_pattern(nodename, ".openbox_config");
|
2021-07-16 17:30:07 +01:00
|
|
|
string_truncate_at_pattern(nodename, ".labwc_config");
|
2020-07-31 11:11:50 +01:00
|
|
|
|
2021-03-30 22:40:41 +01:00
|
|
|
if (getenv("LABWC_DEBUG_CONFIG_NODENAMES")) {
|
|
|
|
|
printf("%s: %s\n", nodename, content);
|
2020-06-05 23:04:54 +01:00
|
|
|
}
|
2020-07-31 11:11:50 +01:00
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
if (in_keybind) {
|
|
|
|
|
fill_keybind(nodename, content);
|
|
|
|
|
}
|
|
|
|
|
if (in_mousebind) {
|
|
|
|
|
fill_mousebind(nodename, content);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-22 19:09:31 +01:00
|
|
|
/* handle nodes without content, e.g. <keyboard><default /> */
|
|
|
|
|
if (!strcmp(nodename, "default.keyboard")) {
|
|
|
|
|
load_default_key_bindings();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* handle the rest */
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!content) {
|
2020-06-05 23:04:54 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-09-22 20:25:57 +01:00
|
|
|
if (!strcmp(nodename, "place.font.theme")) {
|
2020-07-31 11:11:50 +01:00
|
|
|
font_place = enum_font_place(content);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-07-31 11:11:50 +01:00
|
|
|
|
2021-07-16 17:38:17 +01:00
|
|
|
if (!strcmp(nodename, "decoration.core")) {
|
|
|
|
|
if (!strcmp(content, "client")) {
|
|
|
|
|
rc.xdg_shell_server_side_deco = false;
|
|
|
|
|
} else {
|
|
|
|
|
rc.xdg_shell_server_side_deco = true;
|
|
|
|
|
}
|
2021-08-22 14:32:19 +01:00
|
|
|
} else if (!strcmp(nodename, "gap.core")) {
|
|
|
|
|
rc.gap = atoi(content);
|
2020-09-28 20:41:41 +01:00
|
|
|
} else if (!strcmp(nodename, "name.theme")) {
|
2020-07-09 22:41:54 +01:00
|
|
|
rc.theme_name = strdup(content);
|
2021-03-30 22:39:52 +01:00
|
|
|
} else if (!strcmp(nodename, "cornerradius.theme")) {
|
|
|
|
|
rc.corner_radius = atoi(content);
|
2020-09-28 20:41:41 +01:00
|
|
|
} else if (!strcmp(nodename, "name.font.theme")) {
|
2020-07-31 11:11:50 +01:00
|
|
|
fill_font(nodename, content, font_place);
|
2020-09-28 20:41:41 +01:00
|
|
|
} else if (!strcmp(nodename, "size.font.theme")) {
|
2020-07-31 11:11:50 +01:00
|
|
|
fill_font(nodename, content, font_place);
|
2021-05-27 02:11:11 +03:00
|
|
|
} else if (!strcasecmp(nodename, "FollowMouse.focus")) {
|
|
|
|
|
rc.focus_follow_mouse = get_bool(content);
|
2021-05-28 21:31:02 +01:00
|
|
|
} else if (!strcasecmp(nodename, "RaiseOnFocus.focus")) {
|
2021-05-27 02:11:11 +03:00
|
|
|
rc.focus_follow_mouse = true;
|
|
|
|
|
rc.raise_on_focus = get_bool(content);
|
2021-08-31 17:43:49 -04:00
|
|
|
} else if (!strcasecmp(nodename, "doubleClickTime.mouse")) {
|
2021-08-30 22:03:41 -04:00
|
|
|
long doubleclick_time_parsed = strtol(content, NULL, 10);
|
2021-09-22 20:36:55 +01:00
|
|
|
if (doubleclick_time_parsed > 0) {
|
2021-08-30 22:03:41 -04:00
|
|
|
rc.doubleclick_time = doubleclick_time_parsed;
|
2021-09-22 20:36:55 +01:00
|
|
|
} else {
|
|
|
|
|
wlr_log(WLR_ERROR, "invalid doubleClickTime");
|
2021-08-30 22:03:41 -04:00
|
|
|
}
|
2021-09-22 20:25:57 +01:00
|
|
|
} else if (!strcasecmp(nodename, "name.context.mouse")) {
|
2021-08-30 22:03:41 -04:00
|
|
|
current_mouse_context = content;
|
2021-10-09 09:10:26 -04:00
|
|
|
} else if (!strcasecmp(nodename, "PointerSpeed.libinput")) {
|
|
|
|
|
rc.pointer_speed = atof(content);
|
|
|
|
|
} else if (!strcasecmp(nodename, "NaturalScroll.libinput")) {
|
|
|
|
|
rc.natural_scroll = get_bool(content) ? 1 : 0;
|
|
|
|
|
} else if (!strcasecmp(nodename, "LeftHanded.libinput")) {
|
|
|
|
|
rc.left_handed = get_bool(content) ? 1 : 0;
|
|
|
|
|
} else if (!strcasecmp(nodename, "Tap.libinput")) {
|
|
|
|
|
rc.tap = get_bool(content) ? LIBINPUT_CONFIG_TAP_ENABLED :
|
|
|
|
|
LIBINPUT_CONFIG_TAP_DISABLED;
|
|
|
|
|
} else if (!strcasecmp(nodename, "MiddleEmulation.libinput")) {
|
|
|
|
|
rc.middle_emu = get_bool(content) ?
|
|
|
|
|
LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED :
|
|
|
|
|
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
|
|
|
|
|
} else if (!strcasecmp(nodename, "DisableWhileTyping.libinput")) {
|
|
|
|
|
rc.dwt = get_bool(content) ? LIBINPUT_CONFIG_DWT_ENABLED :
|
|
|
|
|
LIBINPUT_CONFIG_DWT_DISABLED;
|
|
|
|
|
} else if (!strcasecmp(nodename, "AccelerationProfile.libinput")) {
|
|
|
|
|
rc.accel_profile = get_accel_profile(content);
|
2021-10-09 15:16:02 -04:00
|
|
|
} else if (!strcasecmp(nodename, "RepeatRate.keyboard")) {
|
|
|
|
|
rc.repeat_rate = atoi(content);
|
|
|
|
|
} else if (!strcasecmp(nodename, "RepeatDelay.keyboard")) {
|
|
|
|
|
rc.repeat_delay = atoi(content);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-05 23:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
process_node(xmlNode *node)
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
|
|
|
|
char *content;
|
|
|
|
|
static char buffer[256];
|
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
|
|
content = (char *)node->content;
|
2020-09-28 20:41:41 +01:00
|
|
|
if (xmlIsBlankNode(node)) {
|
2020-06-05 23:04:54 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-05 23:04:54 +01:00
|
|
|
name = nodename(node, buffer, sizeof(buffer));
|
|
|
|
|
entry(node, name, content);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-06 21:54:00 +01:00
|
|
|
static void xml_tree_walk(xmlNode *node);
|
2020-06-05 23:04:54 +01:00
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
traverse(xmlNode *n)
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
|
|
|
|
process_node(n);
|
2020-09-28 20:41:41 +01:00
|
|
|
for (xmlAttr *attr = n->properties; attr; attr = attr->next) {
|
2020-06-05 23:04:54 +01:00
|
|
|
xml_tree_walk(attr->children);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-05 23:04:54 +01:00
|
|
|
xml_tree_walk(n->children);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
xml_tree_walk(xmlNode *node)
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
|
|
|
|
for (xmlNode *n = node; n && n->name; n = n->next) {
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!strcasecmp((char *)n->name, "comment")) {
|
2020-06-05 23:04:54 +01:00
|
|
|
continue;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-06-05 23:04:54 +01:00
|
|
|
if (!strcasecmp((char *)n->name, "keybind")) {
|
2020-06-19 22:00:22 +01:00
|
|
|
in_keybind = true;
|
2020-06-05 23:04:54 +01:00
|
|
|
traverse(n);
|
2020-06-19 22:00:22 +01:00
|
|
|
in_keybind = false;
|
2020-06-05 23:04:54 +01:00
|
|
|
continue;
|
2021-08-31 17:43:49 -04:00
|
|
|
}
|
|
|
|
|
if (!strcasecmp((char *)n->name, "mousebind")) {
|
2021-08-30 22:03:41 -04:00
|
|
|
in_mousebind = true;
|
|
|
|
|
traverse(n);
|
|
|
|
|
in_mousebind = false;
|
2021-08-29 14:22:49 -04:00
|
|
|
continue;
|
2020-06-05 23:04:54 +01:00
|
|
|
}
|
|
|
|
|
traverse(n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 21:40:46 +01:00
|
|
|
/* Exposed in header file to allow unit tests to parse buffers */
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
|
|
|
|
rcxml_parse_xml(struct buf *b)
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
2020-06-09 21:40:46 +01:00
|
|
|
xmlDoc *d = xmlParseMemory(b->buf, b->len);
|
2020-06-05 23:04:54 +01:00
|
|
|
if (!d) {
|
2021-07-23 21:15:55 +01:00
|
|
|
wlr_log(WLR_ERROR, "xmlParseMemory()");
|
2020-06-05 23:04:54 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
xml_tree_walk(xmlDocGetRootElement(d));
|
|
|
|
|
xmlFreeDoc(d);
|
|
|
|
|
xmlCleanupParser();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
rcxml_init()
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
2020-09-25 19:42:40 +01:00
|
|
|
static bool has_run;
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
if (has_run) {
|
2020-09-25 19:42:40 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-25 19:42:40 +01:00
|
|
|
has_run = true;
|
2020-06-05 23:04:54 +01:00
|
|
|
LIBXML_TEST_VERSION
|
2020-09-25 19:42:40 +01:00
|
|
|
wl_list_init(&rc.keybinds);
|
2021-08-29 14:22:49 -04:00
|
|
|
wl_list_init(&rc.mousebinds);
|
2021-03-30 22:39:52 +01:00
|
|
|
rc.xdg_shell_server_side_deco = true;
|
|
|
|
|
rc.corner_radius = 8;
|
|
|
|
|
rc.font_size_activewindow = 10;
|
2021-08-20 20:27:52 +01:00
|
|
|
rc.font_size_menuitem = 10;
|
2021-08-29 18:31:57 -04:00
|
|
|
rc.doubleclick_time = 500;
|
2021-10-09 09:10:26 -04:00
|
|
|
rc.pointer_speed = -2;
|
|
|
|
|
rc.natural_scroll = -1;
|
|
|
|
|
rc.left_handed = -1;
|
|
|
|
|
rc.tap = LIBINPUT_CONFIG_TAP_ENABLED;
|
|
|
|
|
rc.accel_profile = -1;
|
|
|
|
|
rc.middle_emu = -1;
|
|
|
|
|
rc.dwt = -1;
|
2021-10-09 15:16:02 -04:00
|
|
|
rc.repeat_rate = 25;
|
|
|
|
|
rc.repeat_delay = 600;
|
2020-06-19 22:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-06 22:04:56 +01:00
|
|
|
static struct {
|
|
|
|
|
const char *binding, *action, *command;
|
|
|
|
|
} key_combos[] = {
|
|
|
|
|
{ "A-Tab", "NextWindow", NULL },
|
|
|
|
|
{ "A-Escape", "Exit", NULL },
|
|
|
|
|
{ "W-Return", "Execute", "alacritty" },
|
|
|
|
|
{ "A-F3", "Execute", "bemenu-run" },
|
|
|
|
|
{ "A-F4", "Close", NULL },
|
|
|
|
|
{ "W-a", "ToggleMaximize", NULL },
|
|
|
|
|
{ "A-Left", "MoveToEdge", "left" },
|
|
|
|
|
{ "A-Right", "MoveToEdge", "right" },
|
|
|
|
|
{ "A-Up", "MoveToEdge", "up" },
|
|
|
|
|
{ "A-Down", "MoveToEdge", "down" },
|
2021-10-14 19:37:57 +01:00
|
|
|
{ "XF86_AudioLowerVolume", "Execute", "amixer sset Master 5%-" },
|
|
|
|
|
{ "XF86_AudioRaiseVolume", "Execute", "amixer sset Master 5%+" },
|
|
|
|
|
{ "XF86_AudioMute", "Execute", "amixer sset Master toggle" },
|
|
|
|
|
{ "XF86_MonBrightnessUp", "Execute", "brightnessctl set +10%" },
|
|
|
|
|
{ "XF86_MonBrightnessDown", "Execute", "brightnessctl set 10%-" },
|
2021-09-06 22:04:56 +01:00
|
|
|
{ NULL, NULL, NULL },
|
|
|
|
|
};
|
2020-06-19 22:00:22 +01:00
|
|
|
|
2021-08-22 17:00:22 +01:00
|
|
|
static void
|
|
|
|
|
load_default_key_bindings(void)
|
|
|
|
|
{
|
2021-09-06 22:04:56 +01:00
|
|
|
for (int i = 0; key_combos[i].binding; i++) {
|
|
|
|
|
struct keybind *k = keybind_create(key_combos[i].binding);
|
|
|
|
|
if (!k) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
k->action = strdup(key_combos[i].action);
|
|
|
|
|
if (key_combos[i].command) {
|
|
|
|
|
k->command = strdup(key_combos[i].command);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-22 17:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-06 22:02:02 +01:00
|
|
|
static struct {
|
|
|
|
|
const char *context, *button, *event, *action, *command;
|
|
|
|
|
} mouse_combos[] = {
|
|
|
|
|
{ "TitleBar", "Left", "DoubleClick", "ToggleMaximize", NULL },
|
|
|
|
|
{ NULL, NULL, NULL, NULL, NULL },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
load_default_mouse_bindings(void)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; mouse_combos[i].context; i++) {
|
|
|
|
|
struct mousebind *m = mousebind_create(mouse_combos[i].context);
|
|
|
|
|
m->button = mousebind_button_from_str(mouse_combos[i].button);
|
|
|
|
|
m->mouse_event = mousebind_event_from_str(mouse_combos[i].event);
|
|
|
|
|
m->action = strdup(mouse_combos[i].action);
|
|
|
|
|
if (mouse_combos[i].command) {
|
|
|
|
|
m->command = strdup(mouse_combos[i].command);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
post_processing(void)
|
2020-06-19 22:00:22 +01:00
|
|
|
{
|
|
|
|
|
if (!wl_list_length(&rc.keybinds)) {
|
2021-07-22 21:30:17 +01:00
|
|
|
wlr_log(WLR_INFO, "load default key bindings");
|
2021-08-22 17:00:22 +01:00
|
|
|
load_default_key_bindings();
|
2020-06-19 22:00:22 +01:00
|
|
|
}
|
2021-09-06 22:02:02 +01:00
|
|
|
if (!wl_list_length(&rc.mousebinds)) {
|
|
|
|
|
wlr_log(WLR_INFO, "load default mouse bindings");
|
|
|
|
|
load_default_mouse_bindings();
|
|
|
|
|
}
|
2020-08-05 20:14:17 +01:00
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!rc.font_name_activewindow) {
|
2020-08-21 19:47:50 +01:00
|
|
|
rc.font_name_activewindow = strdup("sans");
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2021-08-20 20:27:52 +01:00
|
|
|
if (!rc.font_name_menuitem) {
|
|
|
|
|
rc.font_name_menuitem = strdup("sans");
|
|
|
|
|
}
|
2020-06-05 23:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
rcxml_path(char *buf, size_t len)
|
2020-07-18 11:28:39 +01:00
|
|
|
{
|
2020-09-28 20:41:41 +01:00
|
|
|
if (!strlen(config_dir())) {
|
2020-09-14 18:17:36 +01:00
|
|
|
return;
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-14 18:17:36 +01:00
|
|
|
snprintf(buf, len, "%s/rc.xml", config_dir());
|
2020-07-18 11:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static void
|
|
|
|
|
find_config_file(char *buffer, size_t len, const char *filename)
|
2020-09-25 19:42:40 +01:00
|
|
|
{
|
|
|
|
|
if (filename) {
|
|
|
|
|
snprintf(buffer, len, "%s", filename);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
rcxml_path(buffer, len);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
|
|
|
|
rcxml_read(const char *filename)
|
2020-06-05 23:04:54 +01:00
|
|
|
{
|
2020-06-09 21:40:46 +01:00
|
|
|
FILE *stream;
|
|
|
|
|
char *line = NULL;
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
struct buf b;
|
2021-08-31 17:43:49 -04:00
|
|
|
static char rcxml[4096] = {0};
|
2020-06-09 21:40:46 +01:00
|
|
|
|
2020-06-19 22:00:22 +01:00
|
|
|
rcxml_init();
|
|
|
|
|
|
2020-07-18 11:28:39 +01:00
|
|
|
/*
|
2020-09-25 19:42:40 +01:00
|
|
|
* rcxml_read() can be called multiple times, but we only set rcxml[]
|
|
|
|
|
* the first time. The specified 'filename' is only respected the first
|
|
|
|
|
* time.
|
2020-07-18 11:28:39 +01:00
|
|
|
*/
|
2020-09-28 20:41:41 +01:00
|
|
|
if (rcxml[0] == '\0') {
|
2020-09-25 19:42:40 +01:00
|
|
|
find_config_file(rcxml, sizeof(rcxml), filename);
|
2020-09-28 20:41:41 +01:00
|
|
|
}
|
2020-09-14 18:17:36 +01:00
|
|
|
if (rcxml[0] == '\0') {
|
2021-07-22 21:30:17 +01:00
|
|
|
wlr_log(WLR_INFO, "cannot find rc.xml config file");
|
2020-09-14 18:17:36 +01:00
|
|
|
goto no_config;
|
|
|
|
|
}
|
2020-09-25 19:42:40 +01:00
|
|
|
|
|
|
|
|
/* Reading file into buffer before parsing - better for unit tests */
|
2020-07-18 11:28:39 +01:00
|
|
|
stream = fopen(rcxml, "r");
|
2020-06-09 21:40:46 +01:00
|
|
|
if (!stream) {
|
2021-07-23 21:15:55 +01:00
|
|
|
wlr_log(WLR_ERROR, "cannot read (%s)", rcxml);
|
2020-09-14 18:17:36 +01:00
|
|
|
goto no_config;
|
2020-06-09 21:40:46 +01:00
|
|
|
}
|
2021-07-22 21:30:17 +01:00
|
|
|
wlr_log(WLR_INFO, "read config file %s", rcxml);
|
2020-06-09 21:40:46 +01:00
|
|
|
buf_init(&b);
|
2020-06-18 20:39:55 +01:00
|
|
|
while (getline(&line, &len, stream) != -1) {
|
2020-06-09 21:40:46 +01:00
|
|
|
char *p = strrchr(line, '\n');
|
|
|
|
|
if (p)
|
|
|
|
|
*p = '\0';
|
|
|
|
|
buf_add(&b, line);
|
|
|
|
|
}
|
|
|
|
|
free(line);
|
|
|
|
|
fclose(stream);
|
|
|
|
|
rcxml_parse_xml(&b);
|
|
|
|
|
free(b.buf);
|
2020-09-14 18:17:36 +01:00
|
|
|
no_config:
|
2020-06-19 22:00:22 +01:00
|
|
|
post_processing();
|
2020-06-05 23:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
void
|
|
|
|
|
rcxml_finish(void)
|
2020-08-13 20:18:48 +01:00
|
|
|
{
|
2021-02-21 21:59:53 +00:00
|
|
|
zfree(rc.font_name_activewindow);
|
2021-08-20 20:27:52 +01:00
|
|
|
zfree(rc.font_name_menuitem);
|
2021-02-21 21:59:53 +00:00
|
|
|
zfree(rc.theme_name);
|
2020-08-13 20:18:48 +01:00
|
|
|
|
|
|
|
|
struct keybind *k, *k_tmp;
|
2021-09-06 21:54:00 +01:00
|
|
|
wl_list_for_each_safe(k, k_tmp, &rc.keybinds, link) {
|
2020-08-13 20:18:48 +01:00
|
|
|
wl_list_remove(&k->link);
|
2021-02-21 21:59:53 +00:00
|
|
|
zfree(k->command);
|
|
|
|
|
zfree(k->action);
|
|
|
|
|
zfree(k->keysyms);
|
|
|
|
|
zfree(k);
|
2020-08-13 20:18:48 +01:00
|
|
|
}
|
2021-08-29 14:22:49 -04:00
|
|
|
|
|
|
|
|
struct mousebind *m, *m_tmp;
|
2021-09-06 21:54:00 +01:00
|
|
|
wl_list_for_each_safe(m, m_tmp, &rc.mousebinds, link) {
|
2021-08-29 14:22:49 -04:00
|
|
|
wl_list_remove(&m->link);
|
|
|
|
|
zfree(m->command);
|
|
|
|
|
zfree(m->action);
|
|
|
|
|
zfree(m);
|
|
|
|
|
}
|
2020-08-13 20:18:48 +01:00
|
|
|
}
|