aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-09-28 19:48:55 -0400
committerDrew DeVault <sir@cmpwn.com>2017-09-28 19:48:55 -0400
commitada7fde6fbb1d4cc85f61ef03c8139bf92a9ca10 (patch)
tree5e78ec1fa50e8942a28eb71da96b40aa87273e53 /rootston
parent033036712ade73a872f1034ddb47235be11a74aa (diff)
DRY up focus and implement z ordering
Diffstat (limited to 'rootston')
-rw-r--r--rootston/cursor.c31
-rw-r--r--rootston/desktop.c16
-rw-r--r--rootston/output.c4
-rw-r--r--rootston/wl_shell.c19
-rw-r--r--rootston/xdg_shell_v6.c19
-rw-r--r--rootston/xwayland.c2
6 files changed, 50 insertions, 41 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 89f5874e..2742e7cd 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -9,6 +9,26 @@
#include "rootston/input.h"
#include "rootston/desktop.h"
+const struct roots_input_event *get_input_event(struct roots_input *input,
+ uint32_t serial) {
+ size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
+ for (size_t i = 0; i < len; ++i) {
+ if (input->input_events[i].cursor
+ && input->input_events[i].serial == serial) {
+ return &input->input_events[i];
+ }
+ }
+ return NULL;
+}
+
+void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor,
+ struct roots_view *view) {
+ input->mode = ROOTS_CURSOR_MOVE;
+ input->offs_x = cursor->x - view->x;
+ input->offs_y = cursor->y - view->y;
+ wlr_seat_pointer_clear_focus(input->wl_seat);
+}
+
void cursor_update_position(struct roots_input *input, uint32_t time) {
struct roots_desktop *desktop = input->server->desktop;
struct roots_view *view;
@@ -44,12 +64,19 @@ static void set_view_focus(struct roots_input *input,
if (input->active_view == view) {
return;
}
- struct roots_view *_view;
- wl_list_for_each(_view, &desktop->views, link) {
+ size_t index = 0;
+ for (size_t i = 0; i < desktop->views->length; ++i) {
+ struct roots_view *_view = desktop->views->items[i];
view_activate(_view, _view == view);
+ if (view == _view) {
+ index = i;
+ }
}
input->active_view = view;
input->mode = ROOTS_CURSOR_PASSTHROUGH;
+ // TODO: list_swap
+ list_del(desktop->views, index);
+ list_add(desktop->views, view);
}
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
diff --git a/rootston/desktop.c b/rootston/desktop.c
index 697c83df..cd417755 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 199309L
+#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <wlr/types/wlr_box.h>
@@ -13,7 +14,14 @@
#include "rootston/server.h"
void view_destroy(struct roots_view *view) {
- wl_list_remove(&view->link);
+ struct roots_desktop *desktop = view->desktop;
+ for (size_t i = 0; i < desktop->views->length; ++i) {
+ struct roots_view *_view = desktop->views->items[i];
+ if (view == _view) {
+ list_del(desktop->views, i);
+ break;
+ }
+ }
free(view);
}
@@ -34,8 +42,8 @@ void view_activate(struct roots_view *view, bool activate) {
}
struct roots_view *view_at(struct roots_desktop *desktop, int x, int y) {
- struct roots_view *view;
- wl_list_for_each(view, &desktop->views, link) {
+ for (size_t i = 0; i < desktop->views->length; ++i) {
+ struct roots_view *view = desktop->views->items[i];
struct wlr_box box;
view_get_input_bounds(view, &box);
box.x += view->x;
@@ -52,7 +60,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop));
wlr_log(L_DEBUG, "Initializing roots desktop");
- wl_list_init(&desktop->views);
+ assert(desktop->views = list_create());
wl_list_init(&desktop->outputs);
wl_list_init(&desktop->output_add.link);
desktop->output_add.notify = output_add_notify;
diff --git a/rootston/output.c b/rootston/output.c
index 0f015fb6..5aeb71b1 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -50,8 +50,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_output_make_current(wlr_output);
wlr_renderer_begin(server->renderer, wlr_output);
- struct roots_view *view;
- wl_list_for_each(view, &desktop->views, link) {
+ for (size_t i = 0; i < desktop->views->length; ++i) {
+ struct roots_view *view = desktop->views->items[i];
int width = view->wlr_surface->current.buffer_width;
int height = view->wlr_surface->current.buffer_height;
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c
index 72725c7f..4189e910 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -16,24 +16,11 @@ static void handle_move(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_surface->view;
struct roots_input *input = view->desktop->server->input;
struct wlr_wl_shell_surface_move_event *e = data;
-
- // TODO: Some of this might want to live in cursor.c I guess
- struct roots_input_event *event = NULL;
- size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
- for (size_t i = 0; i < len; ++i) {
- if (input->input_events[i].cursor
- && input->input_events[i].serial == e->serial) {
- event = &input->input_events[i];
- break;
- }
- }
+ const struct roots_input_event *event = get_input_event(input, e->serial);
if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
return;
}
- input->mode = ROOTS_CURSOR_MOVE;
- input->offs_x = input->cursor->x - view->x;
- input->offs_y = input->cursor->y - view->y;
- wlr_seat_pointer_clear_focus(input->wl_seat);
+ view_begin_move(input, event->cursor, view);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -80,5 +67,5 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
view->wlr_surface = surface->surface;
view->desktop = desktop;
roots_surface->view = view;
- wl_list_insert(&desktop->views, &view->link);
+ list_add(desktop->views, view);
}
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index 4a809930..e8edaa8f 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -30,24 +30,11 @@ static void handle_request_move(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_xdg_surface->view;
struct roots_input *input = view->desktop->server->input;
struct wlr_xdg_toplevel_v6_move_event *e = data;
-
- // TODO: Some of this might want to live in cursor.c I guess
- struct roots_input_event *event = NULL;
- size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
- for (size_t i = 0; i < len; ++i) {
- if (input->input_events[i].cursor
- && input->input_events[i].serial == e->serial) {
- event = &input->input_events[i];
- break;
- }
- }
+ const struct roots_input_event *event = get_input_event(input, e->serial);
if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
return;
}
- input->mode = ROOTS_CURSOR_MOVE;
- input->offs_x = input->cursor->x - view->x;
- input->offs_y = input->cursor->y - view->y;
- wlr_seat_pointer_clear_focus(input->wl_seat);
+ view_begin_move(input, event->cursor, view);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -96,5 +83,5 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->activate = activate;
view->desktop = desktop;
roots_surface->view = view;
- wl_list_insert(&desktop->views, &view->link);
+ list_add(desktop->views, view);
}
diff --git a/rootston/xwayland.c b/rootston/xwayland.c
index 88965f0d..aaf55b37 100644
--- a/rootston/xwayland.c
+++ b/rootston/xwayland.c
@@ -45,5 +45,5 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->desktop = desktop;
view->activate = x11_activate;
roots_surface->view = view;
- wl_list_insert(&desktop->views, &view->link);
+ list_add(desktop->views, view);
}