aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
Diffstat (limited to 'rootston')
-rw-r--r--rootston/config.c89
-rw-r--r--rootston/cursor.c7
-rw-r--r--rootston/desktop.c45
-rw-r--r--rootston/keyboard.c7
-rw-r--r--rootston/output.c2
-rw-r--r--rootston/rootston.ini.example1
-rw-r--r--rootston/wl_shell.c10
-rw-r--r--rootston/xdg_shell_v6.c11
8 files changed, 86 insertions, 86 deletions
diff --git a/rootston/config.c b/rootston/config.c
index 4918c8dd..5e911e39 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -11,6 +11,7 @@
#include <wlr/util/log.h>
#include <wlr/types/wlr_box.h>
#include "rootston/config.h"
+#include "rootston/input.h"
#include "rootston/ini.h"
static void usage(const char *name, int ret) {
@@ -109,6 +110,42 @@ static uint32_t parse_modifier(const char *symname) {
}
}
+void add_binding_config(struct wl_list *bindings, const char* combination,
+ const char* command) {
+ struct binding_config *bc = calloc(1, sizeof(struct binding_config));
+
+ xkb_keysym_t keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP];
+ char *symnames = strdup(combination);
+ char* symname = strtok(symnames, "+");
+ while (symname) {
+ uint32_t modifier = parse_modifier(symname);
+ if (modifier != 0) {
+ bc->modifiers |= modifier;
+ } else {
+ xkb_keysym_t sym = xkb_keysym_from_name(symname,
+ XKB_KEYSYM_NO_FLAGS);
+ if (sym == XKB_KEY_NoSymbol) {
+ wlr_log(L_ERROR, "got unknown key binding symbol: %s",
+ symname);
+ free(bc);
+ bc = NULL;
+ break;
+ }
+ keysyms[bc->keysyms_len] = sym;
+ bc->keysyms_len++;
+ }
+ symname = strtok(NULL, "+");
+ }
+ free(symnames);
+
+ if (bc) {
+ wl_list_insert(bindings, &bc->link);
+ bc->command = strdup(command);
+ bc->keysyms = malloc(bc->keysyms_len * sizeof(xkb_keysym_t));
+ memcpy(bc->keysyms, keysyms, bc->keysyms_len * sizeof(xkb_keysym_t));
+ }
+}
+
static const char *output_prefix = "output:";
static const char *device_prefix = "device:";
@@ -216,45 +253,7 @@ static int config_ini_handler(void *user, const char *section, const char *name,
wlr_log(L_ERROR, "got unknown keyboard config: %s", name);
}
} else if (strcmp(section, "bindings") == 0) {
- struct binding_config *bc = calloc(1, sizeof(struct binding_config));
- wl_list_insert(&config->bindings, &bc->link);
-
- bc->command = strdup(value);
-
- size_t keysyms_len = 1;
- char *symnames = strdup(name);
- for (char *c = symnames; *c != '\0'; c++) {
- if (*c == '+') {
- *c = '\0';
- keysyms_len++;
- }
- }
-
- // TODO: bc->keysyms is larger than needed
- bc->keysyms = calloc(1, keysyms_len * sizeof(xkb_keysym_t));
- char *symname = symnames;
- for (size_t i = 0; i < keysyms_len; i++) {
- uint32_t modifier = parse_modifier(symname);
- if (modifier != 0) {
- bc->modifiers |= modifier;
- } else {
- xkb_keysym_t sym = xkb_keysym_from_name(symname,
- XKB_KEYSYM_NO_FLAGS);
- if (sym == XKB_KEY_NoSymbol) {
- wlr_log(L_ERROR, "got unknown key binding symbol: %s",
- symname);
- wl_list_remove(&bc->link);
- free(bc->keysyms);
- free(bc);
- break;
- }
- bc->keysyms[bc->keysyms_len] = sym;
- bc->keysyms_len++;
- }
- symname += strlen(symname) + 1;
- }
-
- free(symnames);
+ add_binding_config(&config->bindings, name, value);
} else {
wlr_log(L_ERROR, "got unknown config section: %s", section);
}
@@ -298,15 +297,9 @@ struct roots_config *parse_args(int argc, char *argv[]) {
if (result == -1) {
wlr_log(L_DEBUG, "No config file found. Using empty config.");
-
- struct binding_config *bc = calloc(1, sizeof(struct binding_config));
- wl_list_insert(&config->bindings, &bc->link);
- bc->command = strdup("exit");
- bc->modifiers = WLR_MODIFIER_LOGO;
- bc->keysyms_len = 2;
- bc->keysyms = calloc(1, bc->keysyms_len * sizeof(xkb_keysym_t));
- bc->keysyms[0] = XKB_KEY_Meta_L;
- bc->keysyms[1] = XKB_KEY_q;
+ add_binding_config(&config->bindings, "Logo+Shift+e", "exit");
+ add_binding_config(&config->bindings, "Ctrl+q", "close");
+ add_binding_config(&config->bindings, "Alt+Tab", "next_window");
} else if (result == -2) {
wlr_log(L_ERROR, "Could not allocate memory to parse config file");
exit(1);
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 03189587..65109534 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -1,10 +1,13 @@
-#define _XOPEN_SOURCE 500
+#define _XOPEN_SOURCE 700
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
-// TODO: BSD et al
+#ifdef __linux__
#include <linux/input-event-codes.h>
+#elif __FreeBSD__
+#include <dev/evdev/input-event-codes.h>
+#endif
#include <wayland-server.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/util/log.h>
diff --git a/rootston/desktop.c b/rootston/desktop.c
index d5cac575..a7137255 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -67,35 +67,42 @@ void view_close(struct roots_view *view) {
bool view_center(struct roots_view *view) {
struct wlr_box size;
view_get_size(view, &size);
- if (size.width == 0 && size.height == 0) {
- return false;
- }
struct roots_desktop *desktop = view->desktop;
struct wlr_cursor *cursor = desktop->server->input->cursor;
- struct wlr_output *output = wlr_output_layout_output_at(desktop->layout,
- cursor->x, cursor->y);
- const struct wlr_output_layout_output *output_layout =
- wlr_output_layout_get(desktop->layout, output);
+
+ struct wlr_output *output =
+ wlr_output_layout_output_at(desktop->layout, cursor->x, cursor->y);
+
+ if (!output) {
+ output = wlr_output_layout_get_center_output(desktop->layout);
+ }
+
if (!output) {
+ // empty layout
return false;
}
- view->x = (double)(output->width - size.width) / 2
- + output_layout->x;
- view->y = (double)(output->height - size.height) / 2
- + output_layout->y;
+ const struct wlr_output_layout_output *l_output =
+ wlr_output_layout_get(desktop->layout, output);
+
+ int width, height;
+ wlr_output_effective_resolution(output, &width, &height);
+
+ view->x = (double)(width - size.width) / 2
+ + l_output->x;
+ view->y = (double)(height - size.height) / 2
+ + l_output->y;
+
return true;
}
-bool view_initialize(struct roots_view *view) {
- bool centered = view_center(view);
- if (centered) {
- struct roots_input *input = view->desktop->server->input;
- set_view_focus(input, view->desktop, view);
- wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface);
- }
- return centered;
+void view_initialize(struct roots_view *view) {
+ view_center(view);
+ struct roots_input *input = view->desktop->server->input;
+
+ set_view_focus(input, view->desktop, view);
+ wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface);
}
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index 6f4334af..aee6b098 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -32,6 +32,13 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
if (keyboard->input->last_active_view != NULL) {
view_close(keyboard->input->last_active_view);
}
+ } else if (strcmp(command, "next_window") == 0) {
+ if (server->desktop->views->length > 0) {
+ struct roots_view *view = server->desktop->views->items[0];
+ set_view_focus(keyboard->input, server->desktop, view);
+ wlr_seat_keyboard_notify_enter(keyboard->input->wl_seat,
+ view->wlr_surface);
+ }
} else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) {
const char *shell_cmd = command + strlen(exec_prefix);
pid_t pid = fork();
diff --git a/rootston/output.c b/rootston/output.c
index 2c061739..39a90fe3 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -1,4 +1,4 @@
-#define _POSIX_C_SOURCE 199309L
+#define _POSIX_C_SOURCE 200809L
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example
index 460efa13..4774108a 100644
--- a/rootston/rootston.ini.example
+++ b/rootston/rootston.ini.example
@@ -38,3 +38,4 @@ meta-key = Logo
[bindings]
Logo+Shift+e = exit # Stop the compositor
Logo+q = close # Close the current view
+Alt+Tab = next_window # Cycle through windows
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c
index 34f53c7a..33f54a32 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -50,14 +50,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
}
static void handle_surface_commit(struct wl_listener *listener, void *data) {
- struct roots_wl_shell_surface *roots_surface =
- wl_container_of(listener, roots_surface, surface_commit);
- struct roots_view *view = roots_surface->view;
-
- if (view->wl_shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL &&
- !roots_surface->initialized) {
- roots_surface->initialized = view_initialize(view);
- }
+ // TODO do we need to do anything here?
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -137,4 +130,5 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
view->desktop = desktop;
roots_surface->view = view;
list_add(desktop->views, view);
+ view_initialize(view);
}
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index 9b8d8882..1e21fa02 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -68,14 +68,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) {
}
static void handle_commit(struct wl_listener *listener, void *data) {
- struct roots_xdg_surface_v6 *roots_xdg_surface =
- wl_container_of(listener, roots_xdg_surface, commit);
- struct roots_view *view = roots_xdg_surface->view;
-
- if (view->xdg_surface_v6->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL &&
- !roots_xdg_surface->initialized) {
- roots_xdg_surface->initialized = view_initialize(view);
- }
+ // TODO is there anything we need to do here?
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -141,4 +134,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->desktop = desktop;
roots_surface->view = view;
list_add(desktop->views, view);
+
+ view_initialize(view);
}