diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 5e138c11..392b0271 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "rootston/view.h" #include "rootston/config.h" @@ -21,7 +22,7 @@ struct roots_output { }; struct roots_desktop { - struct wl_list views; + list_t *views; struct wl_list outputs; struct timespec last_frame; diff --git a/include/rootston/input.h b/include/rootston/input.h index 0ace6cd1..aeab9c0d 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -106,5 +106,9 @@ void cursor_load_config(struct roots_config *config, struct wlr_cursor *cursor, struct roots_input *input, struct roots_desktop *desktop); +const struct roots_input_event *get_input_event(struct roots_input *input, + uint32_t serial); +void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, + struct roots_view *view); #endif diff --git a/include/rootston/view.h b/include/rootston/view.h index 9cc2fe04..da3b189d 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -56,7 +56,6 @@ struct roots_view { struct roots_xwayland_surface *roots_xwayland_surface; }; struct wlr_surface *wlr_surface; - struct wl_list link; // TODO: This would probably be better as a field that's updated on a // configure event from the xdg_shell // If not then this should follow the typical type/impl pattern we use 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 #include #include #include @@ -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); }