aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
Diffstat (limited to 'rootston')
-rw-r--r--rootston/config.c12
-rw-r--r--rootston/cursor.c74
-rw-r--r--rootston/desktop.c18
-rw-r--r--rootston/input.c40
-rw-r--r--rootston/keyboard.c14
-rw-r--r--rootston/main.c13
-rw-r--r--rootston/meson.build1
-rw-r--r--rootston/output.c1
-rw-r--r--rootston/rootston.ini.example12
-rw-r--r--rootston/touch.c26
-rw-r--r--rootston/wl_shell.c19
-rw-r--r--rootston/xdg_shell_v6.c11
-rw-r--r--rootston/xwayland.c2
13 files changed, 177 insertions, 66 deletions
diff --git a/rootston/config.c b/rootston/config.c
index 5ed299a7..c9c892f9 100644
--- a/rootston/config.c
+++ b/rootston/config.c
@@ -16,12 +16,13 @@
static void usage(const char *name, int ret) {
fprintf(stderr,
- "usage: %s [-C <FILE>]\n"
+ "usage: %s [-C <FILE>] [-E <COMMAND>]\n"
"\n"
" -C <FILE> Path to the configuration file\n"
" (default: rootston.ini).\n"
" See `rootston.ini.example` for config\n"
- " file documentation.\n", name);
+ " file documentation.\n"
+ " -E <COMMAND> Command that will be ran at startup.\n" , name);
exit(ret);
}
@@ -273,11 +274,14 @@ struct roots_config *parse_args(int argc, char *argv[]) {
wl_list_init(&config->bindings);
int c;
- while ((c = getopt(argc, argv, "C:h")) != -1) {
+ while ((c = getopt(argc, argv, "C:E:h")) != -1) {
switch (c) {
case 'C':
config->config_path = strdup(optarg);
break;
+ case 'E':
+ config->startup_cmd = strdup(optarg);
+ break;
case 'h':
case '?':
usage(argv[0], c != 'h');
@@ -302,7 +306,7 @@ struct roots_config *parse_args(int argc, char *argv[]) {
if (result == -1) {
wlr_log(L_DEBUG, "No config file found. Using sensible defaults.");
config->keyboard.meta_key = WLR_MODIFIER_LOGO;
- add_binding_config(&config->bindings, "Logo+Shift+e", "exit");
+ 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) {
diff --git a/rootston/cursor.c b/rootston/cursor.c
index b312392d..3be4c2a6 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -1,4 +1,5 @@
#define _XOPEN_SOURCE 700
+#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
@@ -82,8 +83,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
double sx, sy;
switch (input->mode) {
case ROOTS_CURSOR_PASSTHROUGH:
- view = view_at(desktop, input->cursor->x, input->cursor->y, &surface,
- &sx, &sy);
+ view = view_at(desktop, input->cursor->x, input->cursor->y,
+ &surface, &sx, &sy);
bool set_compositor_cursor = !view && input->cursor_client;
if (view) {
struct wl_client *view_client =
@@ -286,6 +287,56 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
(uint32_t)(event->time_usec / 1000), event->button, event->state);
}
+static void handle_touch_down(struct wl_listener *listener, void *data) {
+ struct wlr_event_touch_down *event = data;
+ struct roots_input *input =
+ wl_container_of(listener, input, cursor_touch_down);
+ struct roots_touch_point *point =
+ calloc(1, sizeof(struct roots_touch_point));
+ point->device = event->device->data;
+ point->slot = event->slot;
+ point->x = event->x_mm / event->width_mm;
+ point->y = event->y_mm / event->height_mm;
+ wlr_cursor_warp_absolute(input->cursor, event->device, point->x, point->y);
+ cursor_update_position(input, (uint32_t)(event->time_usec / 1000));
+ wl_list_insert(&input->touch_points, &point->link);
+ do_cursor_button_press(input, input->cursor, event->device,
+ (uint32_t)(event->time_usec / 1000), BTN_LEFT, 1);
+}
+
+static void handle_touch_up(struct wl_listener *listener, void *data) {
+ struct wlr_event_touch_up *event = data;
+ struct roots_input *input =
+ wl_container_of(listener, input, cursor_touch_up);
+ struct roots_touch_point *point;
+ wl_list_for_each(point, &input->touch_points, link) {
+ if (point->slot == event->slot) {
+ wl_list_remove(&point->link);
+ break;
+ }
+ }
+ do_cursor_button_press(input, input->cursor, event->device,
+ (uint32_t)(event->time_usec / 1000), BTN_LEFT, 0);
+}
+
+static void handle_touch_motion(struct wl_listener *listener, void *data) {
+ struct wlr_event_touch_motion *event = data;
+ struct roots_input *input =
+ wl_container_of(listener, input, cursor_touch_motion);
+ struct roots_touch_point *point;
+ wl_list_for_each(point, &input->touch_points, link) {
+ if (point->slot == event->slot) {
+ point->x = event->x_mm / event->width_mm;
+ point->y = event->y_mm / event->height_mm;
+ wlr_cursor_warp_absolute(input->cursor, event->device,
+ point->x, point->y);
+ cursor_update_position(input,
+ (uint32_t)(event->time_usec / 1000));
+ break;
+ }
+ }
+}
+
static void handle_tool_axis(struct wl_listener *listener, void *data) {
struct roots_input *input = wl_container_of(listener, input, cursor_tool_axis);
struct wlr_event_tablet_tool_axis *event = data;
@@ -343,35 +394,40 @@ static void handle_request_set_cursor(struct wl_listener *listener,
void cursor_initialize(struct roots_input *input) {
struct wlr_cursor *cursor = input->cursor;
- wl_list_init(&input->cursor_motion.link);
+ // TODO: Does this belong here
+ wl_list_init(&input->touch_points);
+
wl_signal_add(&cursor->events.motion, &input->cursor_motion);
input->cursor_motion.notify = handle_cursor_motion;
- wl_list_init(&input->cursor_motion_absolute.link);
wl_signal_add(&cursor->events.motion_absolute,
&input->cursor_motion_absolute);
input->cursor_motion_absolute.notify = handle_cursor_motion_absolute;
- wl_list_init(&input->cursor_button.link);
wl_signal_add(&cursor->events.button, &input->cursor_button);
input->cursor_button.notify = handle_cursor_button;
- wl_list_init(&input->cursor_axis.link);
wl_signal_add(&cursor->events.axis, &input->cursor_axis);
input->cursor_axis.notify = handle_cursor_axis;
- wl_list_init(&input->cursor_tool_axis.link);
+ wl_signal_add(&cursor->events.touch_down, &input->cursor_touch_down);
+ input->cursor_touch_down.notify = handle_touch_down;
+
+ wl_signal_add(&cursor->events.touch_up, &input->cursor_touch_up);
+ input->cursor_touch_up.notify = handle_touch_up;
+
+ wl_signal_add(&cursor->events.touch_motion, &input->cursor_touch_motion);
+ input->cursor_touch_motion.notify = handle_touch_motion;
+
wl_signal_add(&cursor->events.tablet_tool_axis, &input->cursor_tool_axis);
input->cursor_tool_axis.notify = handle_tool_axis;
- wl_list_init(&input->cursor_tool_tip.link);
wl_signal_add(&cursor->events.tablet_tool_tip, &input->cursor_tool_tip);
input->cursor_tool_tip.notify = handle_tool_tip;
wl_signal_add(&input->wl_seat->events.pointer_grab_end, &input->pointer_grab_end);
input->pointer_grab_end.notify = handle_pointer_grab_end;
- wl_list_init(&input->request_set_cursor.link);
wl_signal_add(&input->wl_seat->events.request_set_cursor,
&input->request_set_cursor);
input->request_set_cursor.notify = handle_request_set_cursor;
diff --git a/rootston/desktop.c b/rootston/desktop.c
index 641315a8..70767f92 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -202,17 +202,23 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
struct roots_desktop *desktop_create(struct roots_server *server,
struct roots_config *config) {
- struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop));
wlr_log(L_DEBUG, "Initializing roots desktop");
- assert(desktop->views = list_create());
+ struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop));
+ if (desktop == NULL) {
+ return NULL;
+ }
+
+ desktop->views = list_create();
+ if (desktop->views == NULL) {
+ free(desktop);
+ return NULL;
+ }
wl_list_init(&desktop->outputs);
- wl_list_init(&desktop->output_add.link);
- desktop->output_add.notify = output_add_notify;
- wl_list_init(&desktop->output_remove.link);
- desktop->output_remove.notify = output_remove_notify;
+ desktop->output_add.notify = output_add_notify;
wl_signal_add(&server->backend->events.output_add, &desktop->output_add);
+ desktop->output_remove.notify = output_remove_notify;
wl_signal_add(&server->backend->events.output_remove,
&desktop->output_remove);
diff --git a/rootston/input.c b/rootston/input.c
index 86a87e24..5dc7d16d 100644
--- a/rootston/input.c
+++ b/rootston/input.c
@@ -37,7 +37,7 @@ static void input_add_notify(struct wl_listener *listener, void *data) {
pointer_add(device, input);
break;
case WLR_INPUT_DEVICE_TOUCH:
- //touch_add(device, input);
+ touch_add(device, input);
break;
case WLR_INPUT_DEVICE_TABLET_TOOL:
tablet_tool_add(device, input);
@@ -58,7 +58,7 @@ static void input_remove_notify(struct wl_listener *listener, void *data) {
pointer_remove(device, input);
break;
case WLR_INPUT_DEVICE_TOUCH:
- //touch_remove(device, input);
+ touch_remove(device, input);
break;
case WLR_INPUT_DEVICE_TABLET_TOOL:
tablet_tool_remove(device, input);
@@ -74,15 +74,34 @@ struct roots_input *input_create(struct roots_server *server,
assert(server->desktop);
struct roots_input *input = calloc(1, sizeof(struct roots_input));
- assert(input);
+ if (input == NULL) {
+ return NULL;
+ }
input->config = config;
input->server = server;
- assert(input->theme = wlr_xcursor_theme_load("default", 16));
- assert(input->xcursor = wlr_xcursor_theme_get_cursor(input->theme, "left_ptr"));
+ input->theme = wlr_xcursor_theme_load("default", 16);
+ if (input->theme == NULL) {
+ wlr_log(L_ERROR, "Cannot load xcursor theme");
+ free(input);
+ return NULL;
+ }
+ input->xcursor = wlr_xcursor_theme_get_cursor(input->theme, "left_ptr");
+ if (input->xcursor == NULL) {
+ wlr_log(L_ERROR, "Cannot load xcursor from theme");
+ wlr_xcursor_theme_destroy(input->theme);
+ free(input);
+ return NULL;
+ }
- assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0"));
+ input->wl_seat = wlr_seat_create(server->wl_display, "seat0");
+ if (input->wl_seat == NULL) {
+ wlr_log(L_ERROR, "Cannot create seat");
+ wlr_xcursor_theme_destroy(input->theme);
+ free(input);
+ return NULL;
+ }
wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD
| WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH);
@@ -91,15 +110,10 @@ struct roots_input *input_create(struct roots_server *server,
wl_list_init(&input->touch);
wl_list_init(&input->tablet_tools);
- wl_list_init(&input->input_add.link);
input->input_add.notify = input_add_notify;
- wl_list_init(&input->input_remove.link);
+ wl_signal_add(&server->backend->events.input_add, &input->input_add);
input->input_remove.notify = input_remove_notify;
-
- wl_signal_add(&server->backend->events.input_add,
- &input->input_add);
- wl_signal_add(&server->backend->events.input_remove,
- &input->input_remove);
+ wl_signal_add(&server->backend->events.input_remove, &input->input_remove);
input->cursor = wlr_cursor_create();
cursor_initialize(input);
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index aee6b098..61604da0 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -127,10 +127,12 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) {
void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1);
+ if (keyboard == NULL) {
+ return;
+ }
device->data = keyboard;
keyboard->device = device;
keyboard->input = input;
- wl_list_init(&keyboard->key.link);
keyboard->key.notify = keyboard_key_notify;
wl_signal_add(&device->keyboard->events.key, &keyboard->key);
wl_list_insert(&input->keyboards, &keyboard->link);
@@ -142,11 +144,15 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) {
rules.layout = getenv("XKB_DEFAULT_LAYOUT");
rules.variant = getenv("XKB_DEFAULT_VARIANT");
rules.options = getenv("XKB_DEFAULT_OPTIONS");
- struct xkb_context *context;
- assert(context = xkb_context_new(XKB_CONTEXT_NO_FLAGS));
+ struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
+ if (context == NULL) {
+ wlr_log(L_ERROR, "Cannot create XKB context");
+ return;
+ }
wlr_keyboard_set_keymap(device->keyboard, xkb_map_new_from_names(context,
- &rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
+ &rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
xkb_context_unref(context);
+
wlr_seat_attach_keyboard(input->wl_seat, device);
}
diff --git a/rootston/main.c b/rootston/main.c
index 5a60000c..b80c2efd 100644
--- a/rootston/main.c
+++ b/rootston/main.c
@@ -1,6 +1,7 @@
#define _POSIX_C_SOURCE 200112L
#include <assert.h>
#include <stdlib.h>
+#include <unistd.h>
#include <wayland-server.h>
#include <wlr/backend.h>
#include <wlr/render.h>
@@ -42,6 +43,18 @@ int main(int argc, char **argv) {
}
setenv("WAYLAND_DISPLAY", socket, true);
+
+ if (server.config->startup_cmd != NULL) {
+ const char *cmd = server.config->startup_cmd;
+ pid_t pid = fork();
+ if (pid < 0) {
+ wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
+ return 1;
+ } else if (pid == 0) {
+ execl("/bin/sh", "/bin/sh", "-c", cmd, (void *)NULL);
+ }
+ }
+
wl_display_run(server.wl_display);
wlr_backend_destroy(server.backend);
return 0;
diff --git a/rootston/meson.build b/rootston/meson.build
index 7ff79f8e..f2621450 100644
--- a/rootston/meson.build
+++ b/rootston/meson.build
@@ -9,6 +9,7 @@ sources = [
'output.c',
'pointer.c',
'tablet_tool.c',
+ 'touch.c',
'xdg_shell_v6.c',
'wl_shell.c',
]
diff --git a/rootston/output.c b/rootston/output.c
index 95e052fb..99f70bcf 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -177,7 +177,6 @@ void output_add_notify(struct wl_listener *listener, void *data) {
output->desktop = desktop;
output->wlr_output = wlr_output;
output->frame.notify = output_frame_notify;
- wl_list_init(&output->frame.link);
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&desktop->outputs, &output->link);
diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example
index 4774108a..433dc78f 100644
--- a/rootston/rootston.ini.example
+++ b/rootston/rootston.ini.example
@@ -34,8 +34,12 @@ meta-key = Logo
# Keybindings
# Maps key combinations with commands to execute
-# Use the prefix "exec" to execute a shell command
+# Commands include:
+# - "exit" to stop the compositor
+# - "exec" to execute a shell command
+# - "close" to close the current view
+# - "next_window" to cycle through windows
[bindings]
-Logo+Shift+e = exit # Stop the compositor
-Logo+q = close # Close the current view
-Alt+Tab = next_window # Cycle through windows
+Logo+Shift+E = exit
+Logo+q = close
+Alt+Tab = next_window
diff --git a/rootston/touch.c b/rootston/touch.c
new file mode 100644
index 00000000..f6d9b11a
--- /dev/null
+++ b/rootston/touch.c
@@ -0,0 +1,26 @@
+#include <stdlib.h>
+#include <wayland-server.h>
+#include <wlr/types/wlr_input_device.h>
+#include <wlr/types/wlr_pointer.h>
+#include "rootston/input.h"
+
+// TODO: we'll likely want touch events to both control the cursor *and* be
+// submitted directly to the seat.
+
+void touch_add(struct wlr_input_device *device, struct roots_input *input) {
+ struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1);
+ device->data = touch;
+ touch->device = device;
+ touch->input = input;
+ wl_list_insert(&input->touch, &touch->link);
+ wlr_cursor_attach_input_device(input->cursor, device);
+ cursor_load_config(input->server->config, input->cursor,
+ input, input->server->desktop);
+}
+
+void touch_remove(struct wlr_input_device *device, struct roots_input *input) {
+ struct roots_touch *touch = device->data;
+ wlr_cursor_detach_input_device(input->cursor, device);
+ wl_list_remove(&touch->link);
+ free(touch);
+}
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c
index 2c6047b1..248514f0 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -57,11 +57,8 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
wl_list_remove(&roots_surface->destroy.link);
- wl_list_remove(&roots_surface->ping_timeout.link);
wl_list_remove(&roots_surface->request_move.link);
wl_list_remove(&roots_surface->request_resize.link);
- wl_list_remove(&roots_surface->request_set_fullscreen.link);
- wl_list_remove(&roots_surface->request_set_maximized.link);
view_destroy(roots_surface->view);
free(roots_surface);
}
@@ -88,25 +85,22 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
if (!roots_surface) {
return;
}
- wl_list_init(&roots_surface->destroy.link);
roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
- wl_list_init(&roots_surface->ping_timeout.link);
- wl_list_init(&roots_surface->request_move.link);
roots_surface->request_move.notify = handle_request_move;
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
- wl_list_init(&roots_surface->request_resize.link);
roots_surface->request_resize.notify = handle_request_resize;
wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize);
- wl_list_init(&roots_surface->request_set_fullscreen.link);
- wl_list_init(&roots_surface->request_set_maximized.link);
- wl_list_init(&roots_surface->surface_commit.link);
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
+ if (!view) {
+ free(roots_surface);
+ return;
+ }
view->type = ROOTS_WL_SHELL_VIEW;
view->wl_shell_surface = surface;
@@ -121,9 +115,8 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) {
// we need to map it relative to the parent
- int i =
- list_seq_find(desktop->views,
- shell_surface_compare_equals, surface->parent);
+ int i = list_seq_find(desktop->views, shell_surface_compare_equals,
+ surface->parent);
if (i != -1) {
struct roots_view *parent = desktop->views->items[i];
view_set_position(view,
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index 1e21fa02..028545df 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -74,12 +74,10 @@ static void handle_commit(struct wl_listener *listener, void *data) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xdg_surface_v6 *roots_xdg_surface =
wl_container_of(listener, roots_xdg_surface, destroy);
+ wl_list_remove(&roots_xdg_surface->commit.link);
wl_list_remove(&roots_xdg_surface->destroy.link);
- wl_list_remove(&roots_xdg_surface->ping_timeout.link);
wl_list_remove(&roots_xdg_surface->request_move.link);
wl_list_remove(&roots_xdg_surface->request_resize.link);
- wl_list_remove(&roots_xdg_surface->request_show_window_menu.link);
- wl_list_remove(&roots_xdg_surface->request_minimize.link);
view_destroy(roots_xdg_surface->view);
free(roots_xdg_surface);
}
@@ -105,22 +103,15 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
if (!roots_surface) {
return;
}
- wl_list_init(&roots_surface->commit.link);
roots_surface->commit.notify = handle_commit;
wl_signal_add(&surface->events.commit, &roots_surface->commit);
- wl_list_init(&roots_surface->destroy.link);
roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
- wl_list_init(&roots_surface->ping_timeout.link);
- wl_list_init(&roots_surface->request_minimize.link);
- wl_list_init(&roots_surface->request_move.link);
roots_surface->request_move.notify = handle_request_move;
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
- wl_list_init(&roots_surface->request_resize.link);
roots_surface->request_resize.notify = handle_request_resize;
wl_signal_add(&surface->events.request_resize,
&roots_surface->request_resize);
- wl_list_init(&roots_surface->request_show_window_menu.link);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
view->type = ROOTS_XDG_SHELL_V6_VIEW;
diff --git a/rootston/xwayland.c b/rootston/xwayland.c
index d7885e94..6ef33403 100644
--- a/rootston/xwayland.c
+++ b/rootston/xwayland.c
@@ -75,10 +75,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
if (roots_surface == NULL) {
return;
}
- wl_list_init(&roots_surface->destroy.link);
roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
- wl_list_init(&roots_surface->request_configure.link);
roots_surface->request_configure.notify = handle_request_configure;
wl_signal_add(&surface->events.request_configure,
&roots_surface->request_configure);