aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
Diffstat (limited to 'rootston')
-rw-r--r--rootston/cursor.c131
-rw-r--r--rootston/desktop.c62
-rw-r--r--rootston/input.c2
-rw-r--r--rootston/keyboard.c16
-rw-r--r--rootston/main.c5
-rw-r--r--rootston/output.c10
-rw-r--r--rootston/seat.c184
-rw-r--r--rootston/wl_shell.c31
-rw-r--r--rootston/xdg_shell_v6.c6
-rw-r--r--rootston/xwayland.c22
10 files changed, 188 insertions, 281 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 10bb4dd3..71075aa9 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -58,19 +58,21 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
}
break;
case ROOTS_CURSOR_MOVE:
- if (seat->focus) {
+ view = roots_seat_get_focus(seat);
+ if (view != NULL) {
double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y;
- view_move(seat->focus, cursor->view_x + dx,
+ view_move(view, cursor->view_x + dx,
cursor->view_y + dy);
}
break;
case ROOTS_CURSOR_RESIZE:
- if (seat->focus) {
+ view = roots_seat_get_focus(seat);
+ if (view != NULL) {
double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y;
- double active_x = seat->focus->x;
- double active_y = seat->focus->y;
+ double active_x = view->x;
+ double active_y = view->y;
int width = cursor->view_width;
int height = cursor->view_height;
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
@@ -99,18 +101,18 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
height = 0;
}
- if (active_x != seat->focus->x ||
- active_y != seat->focus->y) {
- view_move_resize(seat->focus, active_x, active_y,
+ if (active_x != view->x ||
+ active_y != view->y) {
+ view_move_resize(view, active_x, active_y,
width, height);
} else {
- view_resize(seat->focus, width, height);
+ view_resize(view, width, height);
}
}
break;
case ROOTS_CURSOR_ROTATE:
- if (seat->focus) {
- struct roots_view *view = seat->focus;
+ view = roots_seat_get_focus(seat);
+ if (view != NULL) {
int ox = view->x + view->wlr_surface->current->width/2,
oy = view->y + view->wlr_surface->current->height/2;
int ux = cursor->offs_x - ox,
@@ -124,7 +126,6 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
}
break;
}
-
}
static void roots_cursor_press_button(struct roots_cursor *cursor,
@@ -141,7 +142,7 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
if (state == WLR_BUTTON_PRESSED &&
view &&
roots_seat_has_meta_pressed(seat)) {
- roots_seat_focus_view(seat, view);
+ roots_seat_set_focus(seat, view);
uint32_t edges;
switch (button) {
@@ -192,7 +193,7 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
cursor->input_events[i].device = device;
cursor->input_events_idx = (i + 1)
% (sizeof(cursor->input_events) / sizeof(cursor->input_events[0]));
- roots_seat_focus_view(seat, view);
+ roots_seat_set_focus(seat, view);
break;
}
}
@@ -354,105 +355,3 @@ void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor,
event->hotspot_y);
cursor->cursor_client = event->seat_client->client;
}
-
-static void handle_drag_icon_commit(struct wl_listener *listener, void *data) {
- struct roots_drag_icon *drag_icon =
- wl_container_of(listener, drag_icon, surface_commit);
- drag_icon->sx += drag_icon->surface->current->sx;
- drag_icon->sy += drag_icon->surface->current->sy;
-}
-
-static void handle_drag_icon_destroy(struct wl_listener *listener, void *data) {
- struct roots_drag_icon *drag_icon =
- wl_container_of(listener, drag_icon, surface_destroy);
- wl_list_remove(&drag_icon->link);
- wl_list_remove(&drag_icon->surface_destroy.link);
- wl_list_remove(&drag_icon->surface_commit.link);
- free(drag_icon);
-}
-
-static struct roots_drag_icon *seat_add_drag_icon(struct roots_seat *seat,
- struct wlr_surface *icon_surface) {
- if (!icon_surface) {
- return NULL;
- }
-
- struct roots_drag_icon *iter_icon;
- wl_list_for_each(iter_icon, &seat->drag_icons, link) {
- if (iter_icon->surface == icon_surface) {
- // already in the list
- return iter_icon;
- }
- }
-
- struct roots_drag_icon *drag_icon =
- calloc(1, sizeof(struct roots_drag_icon));
- drag_icon->mapped = true;
- drag_icon->surface = icon_surface;
- wl_list_insert(&seat->drag_icons, &drag_icon->link);
-
- wl_signal_add(&icon_surface->events.destroy,
- &drag_icon->surface_destroy);
- drag_icon->surface_destroy.notify = handle_drag_icon_destroy;
-
- wl_signal_add(&icon_surface->events.commit,
- &drag_icon->surface_commit);
- drag_icon->surface_commit.notify = handle_drag_icon_commit;
-
- return drag_icon;
-}
-
-static void seat_unmap_drag_icon(struct roots_seat *seat,
- struct wlr_surface *icon_surface) {
- if (!icon_surface) {
- return;
- }
-
- struct roots_drag_icon *icon;
- wl_list_for_each(icon, &seat->drag_icons, link) {
- if (icon->surface == icon_surface) {
- icon->mapped = false;
- }
- }
-}
-
-void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor,
- struct wlr_seat_pointer_grab *grab) {
- if (grab->interface == &wlr_data_device_pointer_drag_interface) {
- struct wlr_drag *drag = grab->data;
- struct roots_drag_icon *icon =
- seat_add_drag_icon(cursor->seat, drag->icon);
- if (icon) {
- icon->is_pointer = true;
- }
- }
-}
-
-void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor,
- struct wlr_seat_pointer_grab *grab) {
- if (grab->interface == &wlr_data_device_pointer_drag_interface) {
- struct wlr_drag *drag = grab->data;
- seat_unmap_drag_icon(cursor->seat, drag->icon);
- }
-}
-
-void roots_cursor_handle_touch_grab_begin(struct roots_cursor *cursor,
- struct wlr_seat_touch_grab *grab) {
- if (grab->interface == &wlr_data_device_touch_drag_interface) {
- struct wlr_drag *drag = grab->data;
- struct roots_drag_icon *icon =
- seat_add_drag_icon(cursor->seat, drag->icon);
- if (icon) {
- icon->is_pointer = false;
- icon->touch_id = drag->grab_touch_id;
- }
- }
-}
-
-void roots_cursor_handle_touch_grab_end(struct roots_cursor *cursor,
- struct wlr_seat_touch_grab *grab) {
- if (grab->interface == &wlr_data_device_touch_drag_interface) {
- struct wlr_drag *drag = grab->data;
- seat_unmap_drag_icon(cursor->seat, drag->icon);
- }
-}
diff --git a/rootston/desktop.c b/rootston/desktop.c
index 3bc5e748..65730807 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -18,29 +18,6 @@
#include "rootston/seat.h"
#include "rootston/xcursor.h"
-// TODO replace me with a signal
-void view_destroy(struct roots_view *view) {
- struct roots_desktop *desktop = view->desktop;
-
- struct roots_input *input = desktop->server->input;
- struct roots_seat *seat;
- wl_list_for_each(seat, &input->seats, link) {
- if (seat->focus == view) {
- seat->focus = NULL;
- seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
- }
- }
-
- for (size_t i = 0; i < desktop->views->length; ++i) {
- struct roots_view *_view = desktop->views->items[i];
- if (view == _view) {
- wlr_list_del(desktop->views, i);
- break;
- }
- }
- free(view);
-}
-
void view_get_box(const struct roots_view *view, struct wlr_box *box) {
box->x = view->x;
box->y = view->y;
@@ -201,12 +178,23 @@ bool view_center(struct roots_view *view) {
return true;
}
+void view_destroy(struct roots_view *view) {
+ wl_signal_emit(&view->events.destroy, view);
+
+ free(view);
+}
+
+void view_init(struct roots_view *view, struct roots_desktop *desktop) {
+ view->desktop = desktop;
+ wl_signal_init(&view->events.destroy);
+}
+
void view_setup(struct roots_view *view) {
struct roots_input *input = view->desktop->server->input;
// TODO what seat gets focus? the one with the last input event?
struct roots_seat *seat;
wl_list_for_each(seat, &input->seats, link) {
- roots_seat_focus_view(seat, view);
+ roots_seat_set_focus(seat, view);
}
view_center(view);
@@ -215,25 +203,10 @@ void view_setup(struct roots_view *view) {
view_update_output(view, &before);
}
-void view_teardown(struct roots_view *view) {
- // TODO replace me with a signal
- /*
- struct wlr_list *views = view->desktop->views;
- if (views->length < 2 || views->items[views->length-1] != view) {
- return;
- }
-
- struct roots_view *prev_view = views->items[views->length-2];
- struct roots_input *input = prev_view->desktop->server->input;
- set_view_focus(input, prev_view->desktop, prev_view);
- */
-}
-
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) {
- for (ssize_t i = desktop->views->length - 1; i >= 0; --i) {
- struct roots_view *view = desktop->views->items[i];
-
+ struct roots_view *view;
+ wl_list_for_each(view, &desktop->views, link) {
if (view->type == ROOTS_WL_SHELL_VIEW &&
view->wl_shell_surface->state ==
WLR_WL_SHELL_SURFACE_STATE_POPUP) {
@@ -322,11 +295,7 @@ struct roots_desktop *desktop_create(struct roots_server *server,
return NULL;
}
- desktop->views = wlr_list_create();
- if (desktop->views == NULL) {
- free(desktop);
- return NULL;
- }
+ wl_list_init(&desktop->views);
wl_list_init(&desktop->outputs);
desktop->output_add.notify = output_add_notify;
@@ -350,7 +319,6 @@ struct roots_desktop *desktop_create(struct roots_server *server,
if (desktop->xcursor_manager == NULL) {
wlr_log(L_ERROR, "Cannot create XCursor manager for theme %s",
cursor_theme);
- wlr_list_free(desktop->views);
free(desktop);
return NULL;
}
diff --git a/rootston/input.c b/rootston/input.c
index a5d710c4..ce20e840 100644
--- a/rootston/input.c
+++ b/rootston/input.c
@@ -116,7 +116,7 @@ bool input_view_has_focus(struct roots_input *input, struct roots_view *view) {
}
struct roots_seat *seat;
wl_list_for_each(seat, &input->seats, link) {
- if (seat->focus == view) {
+ if (view == roots_seat_get_focus(seat)) {
return true;
}
}
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index 39f46a32..f3fc9a85 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -87,20 +87,16 @@ static const char *exec_prefix = "exec ";
static void keyboard_binding_execute(struct roots_keyboard *keyboard,
const char *command) {
- struct roots_server *server = keyboard->input->server;
+ struct roots_seat *seat = keyboard->seat;
if (strcmp(command, "exit") == 0) {
- wl_display_terminate(server->wl_display);
+ wl_display_terminate(keyboard->input->server->wl_display);
} else if (strcmp(command, "close") == 0) {
- if (server->desktop->views->length > 0) {
- struct roots_view *view =
- server->desktop->views->items[server->desktop->views->length-1];
- view_close(view);
+ struct roots_view *focus = roots_seat_get_focus(seat);
+ if (focus != NULL) {
+ view_close(focus);
}
} else if (strcmp(command, "next_window") == 0) {
- if (server->desktop->views->length > 0) {
- struct roots_view *view = server->desktop->views->items[0];
- roots_seat_focus_view(keyboard->seat, view);
- }
+ roots_seat_cycle_focus(seat);
} 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/main.c b/rootston/main.c
index 814d3aef..46548094 100644
--- a/rootston/main.c
+++ b/rootston/main.c
@@ -59,8 +59,9 @@ int main(int argc, char **argv) {
ready(NULL, NULL);
#else
if (server.desktop->xwayland != NULL) {
- struct wl_listener xwayland_ready = { .notify = ready };
- wl_signal_add(&server.desktop->xwayland->events.ready, &xwayland_ready);
+ wl_signal_add(&server.desktop->xwayland->events.ready,
+ &server.desktop->xwayland_ready);
+ server.desktop->xwayland_ready.notify = ready;
} else {
ready(NULL, NULL);
}
diff --git a/rootston/output.c b/rootston/output.c
index 6c8f2519..83ff37fd 100644
--- a/rootston/output.c
+++ b/rootston/output.c
@@ -38,7 +38,7 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh,
static void render_surface(struct wlr_surface *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double lx, double ly, float rotation) {
- if (surface->texture->valid) {
+ if (wlr_surface_has_buffer(surface)) {
int width = surface->current->width;
int height = surface->current->height;
int render_width = width * wlr_output->scale;
@@ -186,15 +186,15 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
wlr_output_make_current(wlr_output);
wlr_renderer_begin(server->renderer, wlr_output);
- for (size_t i = 0; i < desktop->views->length; ++i) {
- struct roots_view *view = desktop->views->items[i];
+ struct roots_view *view;
+ wl_list_for_each_reverse(view, &desktop->views, link) {
render_view(view, desktop, wlr_output, &now);
}
- struct roots_drag_icon *drag_icon = NULL;
+ struct wlr_drag_icon *drag_icon = NULL;
struct roots_seat *seat = NULL;
wl_list_for_each(seat, &server->input->seats, link) {
- wl_list_for_each(drag_icon, &seat->drag_icons, link) {
+ wl_list_for_each(drag_icon, &seat->seat->drag_icons, link) {
if (!drag_icon->mapped) {
continue;
}
diff --git a/rootston/seat.c b/rootston/seat.c
index 1855ca49..737bbd67 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -96,38 +96,6 @@ static void handle_request_set_cursor(struct wl_listener *listener,
roots_cursor_handle_request_set_cursor(cursor, event);
}
-static void handle_pointer_grab_begin(struct wl_listener *listener,
- void *data) {
- struct roots_cursor *cursor =
- wl_container_of(listener, cursor, pointer_grab_begin);
- struct wlr_seat_pointer_grab *grab = data;
- roots_cursor_handle_pointer_grab_begin(cursor, grab);
-}
-
-static void handle_pointer_grab_end(struct wl_listener *listener,
- void *data) {
- struct roots_cursor *cursor =
- wl_container_of(listener, cursor, pointer_grab_end);
- struct wlr_seat_pointer_grab *grab = data;
- roots_cursor_handle_pointer_grab_end(cursor, grab);
-}
-
-static void handle_touch_grab_begin(struct wl_listener *listener,
- void *data) {
- struct roots_cursor *cursor =
- wl_container_of(listener, cursor, touch_grab_begin);
- struct wlr_seat_touch_grab *grab = data;
- roots_cursor_handle_touch_grab_begin(cursor, grab);
-}
-
-static void handle_touch_grab_end(struct wl_listener *listener,
- void *data) {
- struct roots_cursor *cursor =
- wl_container_of(listener, cursor, touch_grab_end);
- struct wlr_seat_touch_grab *grab = data;
- roots_cursor_handle_touch_grab_end(cursor, grab);
-}
-
static void seat_reset_device_mappings(struct roots_seat *seat,
struct wlr_input_device *device) {
struct wlr_cursor *cursor = seat->cursor->cursor;
@@ -249,22 +217,6 @@ static void roots_seat_init_cursor(struct roots_seat *seat) {
wl_signal_add(&seat->seat->events.request_set_cursor,
&seat->cursor->request_set_cursor);
seat->cursor->request_set_cursor.notify = handle_request_set_cursor;
-
- wl_signal_add(&seat->seat->events.pointer_grab_begin,
- &seat->cursor->pointer_grab_begin);
- seat->cursor->pointer_grab_begin.notify = handle_pointer_grab_begin;
-
- wl_signal_add(&seat->seat->events.pointer_grab_end,
- &seat->cursor->pointer_grab_end);
- seat->cursor->pointer_grab_end.notify = handle_pointer_grab_end;
-
- wl_signal_add(&seat->seat->events.touch_grab_begin,
- &seat->cursor->touch_grab_begin);
- seat->cursor->touch_grab_begin.notify = handle_touch_grab_begin;
-
- wl_signal_add(&seat->seat->events.touch_grab_end,
- &seat->cursor->touch_grab_end);
- seat->cursor->touch_grab_end.notify = handle_touch_grab_end;
}
struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
@@ -277,7 +229,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
wl_list_init(&seat->pointers);
wl_list_init(&seat->touch);
wl_list_init(&seat->tablet_tools);
- wl_list_init(&seat->drag_icons);
+ wl_list_init(&seat->views);
seat->input = input;
@@ -533,9 +485,69 @@ bool roots_seat_has_meta_pressed(struct roots_seat *seat) {
return false;
}
-void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) {
- struct roots_desktop *desktop = seat->input->server->desktop;
- if (seat->focus == view) {
+struct roots_view *roots_seat_get_focus(struct roots_seat *seat) {
+ if (!seat->has_focus || wl_list_empty(&seat->views)) {
+ return NULL;
+ }
+ struct roots_seat_view *seat_view =
+ wl_container_of(seat->views.next, seat_view, link);
+ return seat_view->view;
+}
+
+static void seat_view_destroy(struct roots_seat_view *seat_view) {
+ struct roots_seat *seat = seat_view->seat;
+
+ if (seat_view->view == roots_seat_get_focus(seat)) {
+ seat->has_focus = false;
+ seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
+ }
+
+ wl_list_remove(&seat_view->view_destroy.link);
+ wl_list_remove(&seat_view->link);
+ free(seat_view);
+
+ // Focus first view
+ if (!wl_list_empty(&seat->views)) {
+ struct roots_seat_view *first_seat_view = wl_container_of(
+ seat->views.next, first_seat_view, link);
+ roots_seat_set_focus(seat, first_seat_view->view);
+ }
+}
+
+static void seat_view_handle_destroy(struct wl_listener *listener, void *data) {
+ struct roots_seat_view *seat_view =
+ wl_container_of(listener, seat_view, view_destroy);
+ seat_view_destroy(seat_view);
+}
+
+static struct roots_seat_view *seat_add_view(struct roots_seat *seat,
+ struct roots_view *view) {
+ struct roots_seat_view *seat_view =
+ calloc(1, sizeof(struct roots_seat_view));
+ if (seat_view == NULL) {
+ return NULL;
+ }
+ seat_view->seat = seat;
+ seat_view->view = view;
+
+ wl_list_insert(&seat->views, &seat_view->link);
+
+ seat_view->view_destroy.notify = seat_view_handle_destroy;
+ wl_signal_add(&view->events.destroy, &seat_view->view_destroy);
+
+ return seat_view;
+}
+
+void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
+ // Make sure the view will be rendered on top of others, even if it's
+ // already focused in this seat
+ if (view != NULL) {
+ wl_list_remove(&view->link);
+ wl_list_insert(&seat->input->server->desktop->views, &view->link);
+ }
+
+ struct roots_view *prev_focus = roots_seat_get_focus(seat);
+ if (view == prev_focus) {
return;
}
@@ -544,35 +556,69 @@ void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) {
return;
}
- struct roots_view *prev_focus = seat->focus;
- seat->focus = view;
+ struct roots_seat_view *seat_view = NULL;
+ if (view != NULL) {
+ bool found = false;
+ wl_list_for_each(seat_view, &seat->views, link) {
+ if (seat_view->view == view) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ seat_view = seat_add_view(seat, view);
+ if (seat_view == NULL) {
+ wlr_log(L_ERROR, "Allocation failed");
+ return;
+ }
+ }
+ }
+
+ seat->has_focus = false;
- // unfocus the old view if it is not focused by some other seat
- if (prev_focus && !input_view_has_focus(seat->input, prev_focus)) {
+ // Deactivate the old view if it is not focused by some other seat
+ if (prev_focus != NULL && !input_view_has_focus(seat->input, prev_focus)) {
view_activate(prev_focus, false);
}
- if (!seat->focus) {
+ if (view == NULL) {
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
return;
}
- size_t index = 0;
- for (size_t i = 0; i < desktop->views->length; ++i) {
- struct roots_view *_view = desktop->views->items[i];
- if (_view == view) {
- index = i;
- break;
- }
- }
-
view_activate(view, true);
- // TODO: list_swap
- wlr_list_del(desktop->views, index);
- wlr_list_add(desktop->views, view);
+
+ seat->has_focus = true;
+ wl_list_remove(&seat_view->link);
+ wl_list_insert(&seat->views, &seat_view->link);
wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface);
}
+void roots_seat_cycle_focus(struct roots_seat *seat) {
+ if (wl_list_empty(&seat->views)) {
+ return;
+ }
+
+ struct roots_seat_view *first_seat_view = wl_container_of(
+ seat->views.next, first_seat_view, link);
+ if (!seat->has_focus) {
+ roots_seat_set_focus(seat, first_seat_view->view);
+ return;
+ }
+ if (wl_list_length(&seat->views) < 2) {
+ return;
+ }
+
+ // Focus the next view
+ struct roots_seat_view *next_seat_view = wl_container_of(
+ first_seat_view->link.next, next_seat_view, link);
+ roots_seat_set_focus(seat, next_seat_view->view);
+
+ // Move the first view to the end of the list
+ wl_list_remove(&first_seat_view->link);
+ wl_list_insert(seat->views.prev, &first_seat_view->link);
+}
+
void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) {
struct roots_cursor *cursor = seat->cursor;
cursor->mode = ROOTS_CURSOR_MOVE;
diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c
index 96f461fe..d0f5989b 100644
--- a/rootston/wl_shell.c
+++ b/rootston/wl_shell.c
@@ -77,25 +77,17 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_wl_shell_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
- view_teardown(roots_surface->view);
wl_list_remove(&roots_surface->destroy.link);
wl_list_remove(&roots_surface->request_move.link);
wl_list_remove(&roots_surface->request_resize.link);
wl_list_remove(&roots_surface->request_set_maximized.link);
wl_list_remove(&roots_surface->set_state.link);
wl_list_remove(&roots_surface->surface_commit.link);
+ wl_list_remove(&roots_surface->view->link);
view_destroy(roots_surface->view);
free(roots_surface);
}
-static int shell_surface_compare_equals(const void *item, const void *cmp_to) {
- const struct roots_view *view = item;
- if (view->type == ROOTS_WL_SHELL_VIEW && view->wl_shell_surface == cmp_to) {
- return 0;
- }
- return -1;
-}
-
void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop =
wl_container_of(listener, desktop, wl_shell_surface);
@@ -138,17 +130,24 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
view->wlr_surface = surface->surface;
view->resize = resize;
view->close = close;
- view->desktop = desktop;
roots_surface->view = view;
- wlr_list_add(desktop->views, view);
+ view_init(view, desktop);
+ wl_list_insert(&desktop->views, &view->link);
+
view_setup(view);
if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) {
- // we need to map it relative to the parent
- int i = wlr_list_seq_find(desktop->views, shell_surface_compare_equals,
- surface->parent);
- if (i != -1) {
- struct roots_view *parent = desktop->views->items[i];
+ // We need to map it relative to the parent
+ bool found = false;
+ struct roots_view *parent;
+ wl_list_for_each(parent, &desktop->views, link) {
+ if (parent->type == ROOTS_WL_SHELL_VIEW &&
+ parent->wl_shell_surface == surface->parent) {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
view_move(view,
parent->x + surface->transient_state->x,
parent->y + surface->transient_state->y);
diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c
index 6517c8b4..ea19753b 100644
--- a/rootston/xdg_shell_v6.c
+++ b/rootston/xdg_shell_v6.c
@@ -161,11 +161,11 @@ 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);
- view_teardown(roots_xdg_surface->view);
wl_list_remove(&roots_xdg_surface->commit.link);
wl_list_remove(&roots_xdg_surface->destroy.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->view->link);
view_destroy(roots_xdg_surface->view);
free(roots_xdg_surface);
}
@@ -219,9 +219,9 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
view->move_resize = move_resize;
view->maximize = maximize;
view->close = close;
- view->desktop = desktop;
roots_surface->view = view;
- wlr_list_add(desktop->views, view);
+ view_init(view, desktop);
+ wl_list_insert(&desktop->views, &view->link);
view_setup(view);
}
diff --git a/rootston/xwayland.c b/rootston/xwayland.c
index f4e100dc..dfa602b1 100644
--- a/rootston/xwayland.c
+++ b/rootston/xwayland.c
@@ -95,7 +95,8 @@ static void maximize(struct roots_view *view, bool maximized) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, destroy);
- view_teardown(roots_surface->view);
+ struct wlr_xwayland_surface *xwayland_surface =
+ roots_surface->view->xwayland_surface;
wl_list_remove(&roots_surface->destroy.link);
wl_list_remove(&roots_surface->request_configure.link);
wl_list_remove(&roots_surface->request_move.link);
@@ -103,6 +104,9 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&roots_surface->request_maximize.link);
wl_list_remove(&roots_surface->map_notify.link);
wl_list_remove(&roots_surface->unmap_notify.link);
+ if (xwayland_surface->mapped) {
+ wl_list_remove(&roots_surface->view->link);
+ }
view_destroy(roots_surface->view);
free(roots_surface);
}
@@ -174,29 +178,23 @@ static void handle_request_maximize(struct wl_listener *listener, void *data) {
static void handle_map_notify(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, map_notify);
+ struct wlr_xwayland_surface *xsurface = data;
struct roots_view *view = roots_surface->view;
- struct wlr_xwayland_surface *xsurface = view->xwayland_surface;
struct roots_desktop *desktop = view->desktop;
view->wlr_surface = xsurface->surface;
view->x = (double)xsurface->x;
view->y = (double)xsurface->y;
- wlr_list_push(desktop->views, roots_surface->view);
+ wl_list_insert(&desktop->views, &view->link);
}
static void handle_unmap_notify(struct wl_listener *listener, void *data) {
struct roots_xwayland_surface *roots_surface =
wl_container_of(listener, roots_surface, unmap_notify);
- struct roots_desktop *desktop = roots_surface->view->desktop;
roots_surface->view->wlr_surface = NULL;
- for (size_t i = 0; i < desktop->views->length; i++) {
- if (desktop->views->items[i] == roots_surface->view) {
- wlr_list_del(desktop->views, i);
- break;
- }
- }
+ wl_list_remove(&roots_surface->view->link);
}
void handle_xwayland_surface(struct wl_listener *listener, void *data) {
@@ -242,7 +240,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->xwayland_surface = surface;
view->roots_xwayland_surface = roots_surface;
view->wlr_surface = surface->surface;
- view->desktop = desktop;
view->activate = activate;
view->resize = resize;
view->move = move;
@@ -250,7 +247,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
view->maximize = maximize;
view->close = close;
roots_surface->view = view;
- wlr_list_add(desktop->views, view);
+ view_init(view, desktop);
+ wl_list_insert(&desktop->views, &view->link);
if (!surface->override_redirect) {
view_setup(view);