DRY up focus and implement z ordering

This commit is contained in:
Drew DeVault 2017-09-28 19:48:55 -04:00
parent 033036712a
commit ada7fde6fb
9 changed files with 56 additions and 43 deletions

View File

@ -8,6 +8,7 @@
#include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_wl_shell.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/types/wlr_gamma_control.h> #include <wlr/types/wlr_gamma_control.h>
#include <wlr/util/list.h>
#include "rootston/view.h" #include "rootston/view.h"
#include "rootston/config.h" #include "rootston/config.h"
@ -21,7 +22,7 @@ struct roots_output {
}; };
struct roots_desktop { struct roots_desktop {
struct wl_list views; list_t *views;
struct wl_list outputs; struct wl_list outputs;
struct timespec last_frame; struct timespec last_frame;

View File

@ -106,5 +106,9 @@ void cursor_load_config(struct roots_config *config,
struct wlr_cursor *cursor, struct wlr_cursor *cursor,
struct roots_input *input, struct roots_input *input,
struct roots_desktop *desktop); 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 #endif

View File

@ -56,7 +56,6 @@ struct roots_view {
struct roots_xwayland_surface *roots_xwayland_surface; struct roots_xwayland_surface *roots_xwayland_surface;
}; };
struct wlr_surface *wlr_surface; struct wlr_surface *wlr_surface;
struct wl_list link;
// TODO: This would probably be better as a field that's updated on a // TODO: This would probably be better as a field that's updated on a
// configure event from the xdg_shell // configure event from the xdg_shell
// If not then this should follow the typical type/impl pattern we use // If not then this should follow the typical type/impl pattern we use

View File

@ -9,6 +9,26 @@
#include "rootston/input.h" #include "rootston/input.h"
#include "rootston/desktop.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) { void cursor_update_position(struct roots_input *input, uint32_t time) {
struct roots_desktop *desktop = input->server->desktop; struct roots_desktop *desktop = input->server->desktop;
struct roots_view *view; struct roots_view *view;
@ -44,12 +64,19 @@ static void set_view_focus(struct roots_input *input,
if (input->active_view == view) { if (input->active_view == view) {
return; return;
} }
struct roots_view *_view; size_t index = 0;
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];
view_activate(_view, _view == view); view_activate(_view, _view == view);
if (view == _view) {
index = i;
}
} }
input->active_view = view; input->active_view = view;
input->mode = ROOTS_CURSOR_PASSTHROUGH; 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) { static void handle_cursor_motion(struct wl_listener *listener, void *data) {

View File

@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 199309L #define _POSIX_C_SOURCE 199309L
#include <assert.h>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <wlr/types/wlr_box.h> #include <wlr/types/wlr_box.h>
@ -13,7 +14,14 @@
#include "rootston/server.h" #include "rootston/server.h"
void view_destroy(struct roots_view *view) { 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); 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_at(struct roots_desktop *desktop, int x, int y) {
struct roots_view *view; for (size_t i = 0; i < desktop->views->length; ++i) {
wl_list_for_each(view, &desktop->views, link) { struct roots_view *view = desktop->views->items[i];
struct wlr_box box; struct wlr_box box;
view_get_input_bounds(view, &box); view_get_input_bounds(view, &box);
box.x += view->x; 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)); struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop));
wlr_log(L_DEBUG, "Initializing 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->outputs);
wl_list_init(&desktop->output_add.link); wl_list_init(&desktop->output_add.link);
desktop->output_add.notify = output_add_notify; desktop->output_add.notify = output_add_notify;

View File

@ -50,8 +50,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_output_make_current(wlr_output); wlr_output_make_current(wlr_output);
wlr_renderer_begin(server->renderer, wlr_output); wlr_renderer_begin(server->renderer, wlr_output);
struct roots_view *view; for (size_t i = 0; i < desktop->views->length; ++i) {
wl_list_for_each(view, &desktop->views, link) { struct roots_view *view = desktop->views->items[i];
int width = view->wlr_surface->current.buffer_width; int width = view->wlr_surface->current.buffer_width;
int height = view->wlr_surface->current.buffer_height; int height = view->wlr_surface->current.buffer_height;

View File

@ -16,24 +16,11 @@ static void handle_move(struct wl_listener *listener, void *data) {
struct roots_view *view = roots_surface->view; struct roots_view *view = roots_surface->view;
struct roots_input *input = view->desktop->server->input; struct roots_input *input = view->desktop->server->input;
struct wlr_wl_shell_surface_move_event *e = data; struct wlr_wl_shell_surface_move_event *e = data;
const struct roots_input_event *event = get_input_event(input, e->serial);
// 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;
}
}
if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
return; return;
} }
input->mode = ROOTS_CURSOR_MOVE; view_begin_move(input, event->cursor, view);
input->offs_x = input->cursor->x - view->x;
input->offs_y = input->cursor->y - view->y;
wlr_seat_pointer_clear_focus(input->wl_seat);
} }
static void handle_destroy(struct wl_listener *listener, void *data) { 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->wlr_surface = surface->surface;
view->desktop = desktop; view->desktop = desktop;
roots_surface->view = view; roots_surface->view = view;
wl_list_insert(&desktop->views, &view->link); list_add(desktop->views, view);
} }

View File

@ -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_view *view = roots_xdg_surface->view;
struct roots_input *input = view->desktop->server->input; struct roots_input *input = view->desktop->server->input;
struct wlr_xdg_toplevel_v6_move_event *e = data; struct wlr_xdg_toplevel_v6_move_event *e = data;
const struct roots_input_event *event = get_input_event(input, e->serial);
// 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;
}
}
if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
return; return;
} }
input->mode = ROOTS_CURSOR_MOVE; view_begin_move(input, event->cursor, view);
input->offs_x = input->cursor->x - view->x;
input->offs_y = input->cursor->y - view->y;
wlr_seat_pointer_clear_focus(input->wl_seat);
} }
static void handle_destroy(struct wl_listener *listener, void *data) { 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->activate = activate;
view->desktop = desktop; view->desktop = desktop;
roots_surface->view = view; roots_surface->view = view;
wl_list_insert(&desktop->views, &view->link); list_add(desktop->views, view);
} }

View File

@ -45,5 +45,5 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->desktop = desktop; view->desktop = desktop;
view->activate = x11_activate; view->activate = x11_activate;
roots_surface->view = view; roots_surface->view = view;
wl_list_insert(&desktop->views, &view->link); list_add(desktop->views, view);
} }