From d09d01236ba5804320bc9ad7d592c5077205f878 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 8 Oct 2017 12:17:25 +0200 Subject: Center xdg shell views --- rootston/xdg_shell_v6.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index c0124d60..c9c2368a 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -67,6 +67,17 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { view_begin_resize(input, event->cursor, view, e->edges); } +static void handle_commit(struct wl_listener *listener, void *data) { + struct roots_xdg_surface_v6 *roots_xdg_surface = + wl_container_of(listener, roots_xdg_surface, commit); + struct roots_view *view = roots_xdg_surface->view; + + bool centered = view_center(view); + if (centered) { + wl_list_remove(&listener->link); + } +} + 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); @@ -98,7 +109,12 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_surface = calloc(1, sizeof(struct roots_xdg_surface_v6)); - // TODO: all of the trimmings + 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); @@ -115,7 +131,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { struct roots_view *view = calloc(1, sizeof(struct roots_view)); view->type = ROOTS_XDG_SHELL_V6_VIEW; - view->x = view->y = 200; view->xdg_surface_v6 = surface; view->roots_xdg_surface_v6 = roots_surface; view->wlr_surface = surface->surface; -- cgit v1.2.3 From 3c6f2f29bf1e1fed571b7ee0715bb65151399c63 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 8 Oct 2017 17:28:19 +0200 Subject: Do not remove the commit listener --- include/rootston/view.h | 2 ++ rootston/xdg_shell_v6.c | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/view.h b/include/rootston/view.h index 4d0cc5e0..85a6c1e7 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -28,6 +28,8 @@ struct roots_xdg_surface_v6 { struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_show_window_menu; + + bool initialized; }; struct roots_xwayland_surface { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index c9c2368a..2471b3ee 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -72,9 +72,11 @@ static void handle_commit(struct wl_listener *listener, void *data) { wl_container_of(listener, roots_xdg_surface, commit); struct roots_view *view = roots_xdg_surface->view; - bool centered = view_center(view); - if (centered) { - wl_list_remove(&listener->link); + if (!roots_xdg_surface->initialized) { + bool centered = view_center(view); + if (centered) { + roots_xdg_surface->initialized = true; + } } } -- cgit v1.2.3 From 518ef46ef2c15bdfd2a1e0274fe2bf628639a310 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 8 Oct 2017 18:19:05 +0200 Subject: Activate new views --- include/rootston/input.h | 3 +++ include/rootston/view.h | 1 + rootston/cursor.c | 7 +++---- rootston/desktop.c | 10 ++++++++++ rootston/wl_shell.c | 5 +---- rootston/xdg_shell_v6.c | 5 +---- 6 files changed, 19 insertions(+), 12 deletions(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/include/rootston/input.h b/include/rootston/input.h index e20446ea..9caf66c0 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -132,4 +132,7 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view, uint32_t edges); +void set_view_focus(struct roots_input *input, struct roots_desktop *desktop, + struct roots_view *view); + #endif diff --git a/include/rootston/view.h b/include/rootston/view.h index f8a828cd..ccc934d4 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -83,5 +83,6 @@ void view_activate(struct roots_view *view, bool active); void view_resize(struct roots_view *view, uint32_t width, uint32_t height); void view_close(struct roots_view *view); bool view_center(struct roots_view *view); +bool view_initialize(struct roots_view *view); #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 8eb22459..605920cc 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -123,8 +123,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { } } -static void set_view_focus(struct roots_input *input, - struct roots_desktop *desktop, struct roots_view *view) { +void set_view_focus(struct roots_input *input, struct roots_desktop *desktop, + struct roots_view *view) { if (input->active_view == view) { return; } @@ -140,8 +140,7 @@ static void set_view_focus(struct roots_input *input, struct roots_view *_view = desktop->views->items[i]; if (_view != view) { view_activate(_view, false); - } - if (view == _view) { + } else { index = i; } } diff --git a/rootston/desktop.c b/rootston/desktop.c index ee813130..75030ad2 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -103,6 +103,16 @@ bool view_center(struct roots_view *view) { return true; } +bool view_initialize(struct roots_view *view) { + bool centered = view_center(view); + if (centered) { + struct roots_input *input = view->desktop->server->input; + set_view_focus(input, view->desktop, view); + wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); + } + return centered; +} + static struct wlr_subsurface *subsurface_at(struct wlr_surface *surface, double sx, double sy, double *sub_x, double *sub_y) { struct wlr_subsurface *subsurface; diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 81c41f76..eb977367 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -56,10 +56,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { if (view->wl_shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL && !roots_surface->initialized) { - bool centered = view_center(view); - if (centered) { - roots_surface->initialized = true; - } + roots_surface->initialized = view_initialize(view); } } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 2471b3ee..44acab4e 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -73,10 +73,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct roots_view *view = roots_xdg_surface->view; if (!roots_xdg_surface->initialized) { - bool centered = view_center(view); - if (centered) { - roots_xdg_surface->initialized = true; - } + roots_xdg_surface->initialized = view_initialize(view); } } -- cgit v1.2.3 From b72da6cc44cf19688686383065557425d55ae9ed Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 8 Oct 2017 18:21:39 +0200 Subject: Only center toplevel xdg shell views --- rootston/xdg_shell_v6.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'rootston/xdg_shell_v6.c') diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 44acab4e..9b8d8882 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -72,7 +72,8 @@ static void handle_commit(struct wl_listener *listener, void *data) { wl_container_of(listener, roots_xdg_surface, commit); struct roots_view *view = roots_xdg_surface->view; - if (!roots_xdg_surface->initialized) { + if (view->xdg_surface_v6->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL && + !roots_xdg_surface->initialized) { roots_xdg_surface->initialized = view_initialize(view); } } -- cgit v1.2.3