mirror of
https://github.com/wizbright/waybox.git
synced 2025-10-29 05:40:20 -04:00
Fixed some things I overlooked
This commit is contained in:
parent
402827e400
commit
be3d7618ff
3 changed files with 65 additions and 43 deletions
|
|
@ -7,6 +7,7 @@ packages:
|
||||||
- xcb-util-image
|
- xcb-util-image
|
||||||
- libinput
|
- libinput
|
||||||
- libxkbcommon
|
- libxkbcommon
|
||||||
|
- libxml2
|
||||||
sources:
|
sources:
|
||||||
- https://github.com/wizbright/waybox
|
- https://github.com/wizbright/waybox
|
||||||
- https://gitlab.freedesktop.org/wlroots/wlroots
|
- https://gitlab.freedesktop.org/wlroots/wlroots
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ static char *parse_xpath_expr(char *expr, xmlXPathContextPtr ctxt) {
|
||||||
return (char *) ret;
|
return (char *) ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool parse_key_bindings(struct wb_config *config, xmlXPathContextPtr ctxt)
|
static bool parse_key_bindings(struct wb_config *config, xmlXPathContextPtr ctxt) {
|
||||||
{
|
|
||||||
/* Get the key bindings */
|
/* Get the key bindings */
|
||||||
wl_list_init(&config->key_bindings);
|
wl_list_init(&config->key_bindings);
|
||||||
xmlXPathObjectPtr object = xmlXPathEvalExpression((xmlChar *) "//ob:keyboard/ob:keybind", ctxt);
|
xmlXPathObjectPtr object = xmlXPathEvalExpression((xmlChar *) "//ob:keyboard/ob:keybind", ctxt);
|
||||||
|
|
@ -92,7 +91,7 @@ static bool parse_key_bindings(struct wb_config *config, xmlXPathContextPtr ctxt
|
||||||
{
|
{
|
||||||
attr = attr->next;
|
attr = attr->next;
|
||||||
}
|
}
|
||||||
key_bind->action = malloc(sizeof (char) * 64);
|
key_bind->action = malloc(sizeof(char) * 64);
|
||||||
strcpy(key_bind->action, (char *) attr->children->content);
|
strcpy(key_bind->action, (char *) attr->children->content);
|
||||||
wlr_log(WLR_INFO, "Registering action %s", (char *) key_bind->action);
|
wlr_log(WLR_INFO, "Registering action %s", (char *) key_bind->action);
|
||||||
if (strcmp((char *) key_bind->action, "Execute") != 0)
|
if (strcmp((char *) key_bind->action, "Execute") != 0)
|
||||||
|
|
@ -104,7 +103,7 @@ static bool parse_key_bindings(struct wb_config *config, xmlXPathContextPtr ctxt
|
||||||
/* Bad things can happen if the command is greater than 1024 characters */
|
/* Bad things can happen if the command is greater than 1024 characters */
|
||||||
key_bind->cmd = malloc(sizeof(char) * 1024);
|
key_bind->cmd = malloc(sizeof(char) * 1024);
|
||||||
strncpy(key_bind->cmd, (char *) cur_node->children->content, 1023);
|
strncpy(key_bind->cmd, (char *) cur_node->children->content, 1023);
|
||||||
key_bind->cmd[strlen(key_bind->cmd)] = '\0';
|
key_bind->cmd[1023] = '\0';
|
||||||
if (key_bind->action)
|
if (key_bind->action)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -118,8 +117,7 @@ static bool parse_key_bindings(struct wb_config *config, xmlXPathContextPtr ctxt
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init_config(struct wb_server *server)
|
bool init_config(struct wb_server *server) {
|
||||||
{
|
|
||||||
xmlDocPtr doc;
|
xmlDocPtr doc;
|
||||||
if (server->config_file == NULL) {
|
if (server->config_file == NULL) {
|
||||||
char *xdg_config = getenv("XDG_CONFIG_HOME");
|
char *xdg_config = getenv("XDG_CONFIG_HOME");
|
||||||
|
|
@ -134,7 +132,7 @@ bool init_config(struct wb_server *server)
|
||||||
free(rc_file);
|
free(rc_file);
|
||||||
} else {
|
} else {
|
||||||
wlr_log(WLR_INFO, "Using config file %s", server->config_file);
|
wlr_log(WLR_INFO, "Using config file %s", server->config_file);
|
||||||
doc = xmlParseFile(server->config_file);
|
doc = xmlReadFile(server->config_file, NULL, XML_PARSE_RECOVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc == NULL) {
|
if (doc == NULL) {
|
||||||
|
|
@ -157,8 +155,7 @@ bool init_config(struct wb_server *server)
|
||||||
config->keyboard_layout.options = parse_xpath_expr("//ob:keyboard//ob:layout//ob:options", ctxt);
|
config->keyboard_layout.options = parse_xpath_expr("//ob:keyboard//ob:layout//ob:options", ctxt);
|
||||||
config->keyboard_layout.rules = parse_xpath_expr("//ob:keyboard//ob:layout//ob:rules", ctxt);
|
config->keyboard_layout.rules = parse_xpath_expr("//ob:keyboard//ob:layout//ob:rules", ctxt);
|
||||||
config->keyboard_layout.variant = parse_xpath_expr("//ob:keyboard//ob:layout//ob:variant", ctxt);
|
config->keyboard_layout.variant = parse_xpath_expr("//ob:keyboard//ob:layout//ob:variant", ctxt);
|
||||||
if (!parse_key_bindings(config, ctxt))
|
if (!parse_key_bindings(config, ctxt)) {
|
||||||
{
|
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -171,8 +168,10 @@ bool init_config(struct wb_server *server)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinit_config(struct wb_config *config)
|
void deinit_config(struct wb_config *config) {
|
||||||
{
|
if (!config)
|
||||||
|
return;
|
||||||
|
|
||||||
/* Free everything allocated in init_config */
|
/* Free everything allocated in init_config */
|
||||||
struct wb_key_binding *key_binding;
|
struct wb_key_binding *key_binding;
|
||||||
wl_list_for_each(key_binding, &config->key_bindings, link) {
|
wl_list_for_each(key_binding, &config->key_bindings, link) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,38 @@
|
||||||
#include "waybox/seat.h"
|
#include "waybox/seat.h"
|
||||||
#include "waybox/xdg_shell.h"
|
#include "waybox/xdg_shell.h"
|
||||||
|
|
||||||
|
static bool cycle_views(struct wb_server *server) {
|
||||||
|
/* Cycle to the next view */
|
||||||
|
if (wl_list_length(&server->views) < 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct wb_view *current_view = wl_container_of(
|
||||||
|
server->views.prev, current_view, link);
|
||||||
|
struct wb_view *prev_view = wl_container_of(
|
||||||
|
server->views.next, prev_view, link);
|
||||||
|
focus_view(current_view, current_view->xdg_surface->surface);
|
||||||
|
/* Move the current view to the beginning of the list */
|
||||||
|
wl_list_remove(¤t_view->link);
|
||||||
|
wl_list_insert(&server->views, ¤t_view->link);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool cycle_views_reverse(struct wb_server *server) {
|
||||||
|
/* Cycle to the previous view */
|
||||||
|
if (wl_list_length(&server->views) < 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
struct wb_view *current_view = wl_container_of(
|
||||||
|
server->views.next, current_view, link);
|
||||||
|
struct wb_view *next_view = wl_container_of(
|
||||||
|
current_view->link.next, next_view, link);
|
||||||
|
focus_view(next_view, next_view->xdg_surface->surface);
|
||||||
|
/* Move the previous view to the end of the list */
|
||||||
|
wl_list_remove(¤t_view->link);
|
||||||
|
wl_list_insert(server->views.prev, ¤t_view->link);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32_t modifiers) {
|
static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32_t modifiers) {
|
||||||
/*
|
/*
|
||||||
* Here we handle compositor keybindings. This is when the compositor is
|
* Here we handle compositor keybindings. This is when the compositor is
|
||||||
|
|
@ -14,43 +46,33 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct wb_key_binding *key_binding;
|
struct wb_key_binding *key_binding;
|
||||||
|
if (!server->config)
|
||||||
|
{
|
||||||
|
if (modifiers & WLR_MODIFIER_ALT && sym == XKB_KEY_Tab)
|
||||||
|
cycle_views(server);
|
||||||
|
else if (modifiers & (WLR_MODIFIER_ALT|WLR_MODIFIER_SHIFT) &&
|
||||||
|
sym == XKB_KEY_Tab)
|
||||||
|
cycle_views_reverse(server);
|
||||||
|
else if (sym == XKB_KEY_Escape && modifiers & WLR_MODIFIER_CTRL)
|
||||||
|
wl_display_terminate(server->wl_display);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
wl_list_for_each(key_binding, &server->config->key_bindings, link) {
|
wl_list_for_each(key_binding, &server->config->key_bindings, link) {
|
||||||
if (sym == key_binding->sym && modifiers == key_binding->modifiers)
|
if (sym == key_binding->sym && modifiers == key_binding->modifiers)
|
||||||
{
|
{
|
||||||
if ((strcmp("NextWindow", key_binding->action) == 0)) {
|
if ((strcmp("NextWindow", key_binding->action) == 0)) {
|
||||||
/* Cycle to the next view */
|
return cycle_views(server);
|
||||||
if (wl_list_length(&server->views) < 2) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
struct wb_view *current_view = wl_container_of(
|
|
||||||
server->views.prev, current_view, link);
|
|
||||||
struct wb_view *prev_view = wl_container_of(
|
|
||||||
server->views.next, prev_view, link);
|
|
||||||
focus_view(prev_view, prev_view->xdg_surface->surface);
|
|
||||||
/* Move the current view to the beginning of the list */
|
|
||||||
wl_list_remove(¤t_view->link);
|
|
||||||
wl_list_insert(&server->views, ¤t_view->link);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else if ((strcmp("PreviousWindow", key_binding->action) == 0)) {
|
else if ((strcmp("PreviousWindow", key_binding->action) == 0)) {
|
||||||
/* Cycle to the previous view */
|
return cycle_views_reverse(server);
|
||||||
if (wl_list_length(&server->views) < 2) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
struct wb_view *current_view = wl_container_of(
|
|
||||||
server->views.next, current_view, link);
|
|
||||||
struct wb_view *next_view = wl_container_of(
|
|
||||||
current_view->link.next, next_view, link);
|
|
||||||
focus_view(next_view, next_view->xdg_surface->surface);
|
|
||||||
/* Move the previous view to the end of the list */
|
|
||||||
wl_list_remove(¤t_view->link);
|
|
||||||
wl_list_insert(server->views.prev, ¤t_view->link);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else if ((strcmp("Close", key_binding->action) == 0)) {
|
else if ((strcmp("Close", key_binding->action) == 0)) {
|
||||||
struct wb_view *current_view = wl_container_of(
|
struct wb_view *current_view = wl_container_of(
|
||||||
server->views.next, current_view, link);
|
server->views.next, current_view, link);
|
||||||
wlr_xdg_toplevel_send_close(current_view->xdg_surface);
|
wlr_xdg_toplevel_send_close(current_view->xdg_surface);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if ((strcmp("Execute", key_binding->action) == 0)) {
|
else if ((strcmp("Execute", key_binding->action) == 0)) {
|
||||||
if (fork() == 0) {
|
if (fork() == 0) {
|
||||||
|
|
@ -126,23 +148,23 @@ static void handle_new_keyboard(struct wb_server *server,
|
||||||
|
|
||||||
/* We need to prepare an XKB keymap and assign it to the keyboard. */
|
/* We need to prepare an XKB keymap and assign it to the keyboard. */
|
||||||
struct xkb_rule_names rules = {0};
|
struct xkb_rule_names rules = {0};
|
||||||
if (server->config->keyboard_layout.layout)
|
if (server->config && server->config->keyboard_layout.layout)
|
||||||
rules.layout = server->config->keyboard_layout.layout;
|
rules.layout = server->config->keyboard_layout.layout;
|
||||||
else
|
else
|
||||||
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
|
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
|
||||||
if (server->config->keyboard_layout.model)
|
if (server->config && server->config->keyboard_layout.model)
|
||||||
rules.model = server->config->keyboard_layout.model;
|
rules.model = server->config->keyboard_layout.model;
|
||||||
else
|
else
|
||||||
rules.model = getenv("XKB_DEFAULT_MODEL");
|
rules.model = getenv("XKB_DEFAULT_MODEL");
|
||||||
if (server->config->keyboard_layout.options)
|
if (server->config && server->config->keyboard_layout.options)
|
||||||
rules.options = server->config->keyboard_layout.options;
|
rules.options = server->config->keyboard_layout.options;
|
||||||
else
|
else
|
||||||
rules.options = getenv("XKB_DEFAULT_OPTIONS");
|
rules.options = getenv("XKB_DEFAULT_OPTIONS");
|
||||||
if (server->config->keyboard_layout.rules)
|
if (server->config && server->config->keyboard_layout.rules)
|
||||||
rules.rules = server->config->keyboard_layout.rules;
|
rules.rules = server->config->keyboard_layout.rules;
|
||||||
else
|
else
|
||||||
rules.variant = getenv("XKB_DEFAULT_RULES");
|
rules.rules = getenv("XKB_DEFAULT_RULES");
|
||||||
if (server->config->keyboard_layout.variant)
|
if (server->config && server->config->keyboard_layout.variant)
|
||||||
rules.variant = server->config->keyboard_layout.variant;
|
rules.variant = server->config->keyboard_layout.variant;
|
||||||
else
|
else
|
||||||
rules.variant = getenv("XKB_DEFAULT_VARIANT");
|
rules.variant = getenv("XKB_DEFAULT_VARIANT");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue