From 29abf93bb6a52101a53ece0b23e3b24c593a737e Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 12 Oct 2017 14:28:37 +0200 Subject: Check pointer focused surface instead of view at cursor --- rootston/cursor.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'rootston') diff --git a/rootston/cursor.c b/rootston/cursor.c index eeb657ad..4c3a9947 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -80,10 +80,16 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { case ROOTS_CURSOR_PASSTHROUGH: view = view_at(desktop, input->cursor->x, input->cursor->y, &surface, &sx, &sy); - if (view != input->client_cursor_view) { + bool set_compositor_cursor = !view && input->cursor_client; + if (view) { + struct wl_client *view_client = + wl_resource_get_client(view->wlr_surface->resource); + set_compositor_cursor = view_client != input->cursor_client; + } + if (set_compositor_cursor) { wlr_log(L_DEBUG, "Switching to compositor cursor"); cursor_set_xcursor_image(input, input->xcursor->images[0]); - input->client_cursor_view = NULL; + input->cursor_client = NULL; } if (view) { wlr_seat_pointer_notify_enter(input->wl_seat, surface, sx, sy); @@ -298,10 +304,8 @@ static void handle_request_set_cursor(struct wl_listener *listener, request_set_cursor); struct wlr_seat_pointer_request_set_cursor_event *event = data; - struct wlr_surface *focused_surface = NULL; - double sx, sy; - struct roots_view *focused_view = view_at(input->server->desktop, - input->cursor->x, input->cursor->y, &focused_surface, &sx, &sy); + struct wlr_surface *focused_surface = + event->seat_handle->wlr_seat->pointer_state.focused_surface; bool ok = focused_surface != NULL; if (focused_surface != NULL) { struct wl_client *focused_client = @@ -309,7 +313,7 @@ static void handle_request_set_cursor(struct wl_listener *listener, ok = event->client == focused_client; } if (!ok) { - wlr_log(L_DEBUG, "Denying request to set cursor outside view"); + wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client"); return; } @@ -321,7 +325,7 @@ static void handle_request_set_cursor(struct wl_listener *listener, event->hotspot_x, event->hotspot_y); } - input->client_cursor_view = focused_view; + input->cursor_client = event->client; } void cursor_initialize(struct roots_input *input) { -- cgit v1.2.3 From 8fd4ae5de86b62e482e338113e94f23ee183d28d Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 14 Oct 2017 12:21:36 +0200 Subject: Fix cursor role name, fix segfault when surface->resource is NULL --- rootston/cursor.c | 4 ++-- types/wlr_output.c | 2 +- types/wlr_seat.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'rootston') diff --git a/rootston/cursor.c b/rootston/cursor.c index 4c3a9947..03189587 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -306,8 +306,8 @@ static void handle_request_set_cursor(struct wl_listener *listener, struct wlr_surface *focused_surface = event->seat_handle->wlr_seat->pointer_state.focused_surface; - bool ok = focused_surface != NULL; - if (focused_surface != NULL) { + bool ok = focused_surface != NULL && focused_surface->resource != NULL; + if (ok) { struct wl_client *focused_client = wl_resource_get_client(focused_surface->resource); ok = event->client == focused_client; diff --git a/types/wlr_output.c b/types/wlr_output.c index b416f9de..bd4799c4 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -231,7 +231,7 @@ static void handle_cursor_surface_destroy(struct wl_listener *listener, void wlr_output_set_cursor_surface(struct wlr_output *output, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { - if (surface && strcmp(surface->role, "cursor") != 0) { + if (surface && strcmp(surface->role, "wl_pointer-cursor") != 0) { return; } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index ef81655c..aea4196b 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -28,7 +28,7 @@ static void wl_pointer_set_cursor(struct wl_client *client, if (surface_resource != NULL) { surface = wl_resource_get_user_data(surface_resource); - if (wlr_surface_set_role(surface, "cursor", resource, + if (wlr_surface_set_role(surface, "wl_pointer-cursor", resource, WL_POINTER_ERROR_ROLE) < 0) { return; } -- cgit v1.2.3 From 19784360f11796eb9cbd27ea6baa2ca0bc39a5f5 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Mon, 16 Oct 2017 14:35:16 -0400 Subject: bug: fix view centering --- include/rootston/view.h | 6 +---- include/wlr/types/wlr_output_layout.h | 6 +++++ include/wlr/types/wlr_xdg_shell_v6.h | 1 + rootston/desktop.c | 45 ++++++++++++++++++++--------------- rootston/wl_shell.c | 10 ++------ rootston/xdg_shell_v6.c | 11 +++------ types/wlr_output_layout.c | 17 +++++++++++++ types/wlr_xdg_shell_v6.c | 10 ++++---- 8 files changed, 62 insertions(+), 44 deletions(-) (limited to 'rootston') diff --git a/include/rootston/view.h b/include/rootston/view.h index af087182..a4fb6f01 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -17,8 +17,6 @@ struct roots_wl_shell_surface { struct wl_listener request_set_maximized; struct wl_listener surface_commit; - - bool initialized; }; struct roots_xdg_surface_v6 { @@ -32,8 +30,6 @@ 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 { @@ -85,6 +81,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); +void view_initialize(struct roots_view *view); #endif diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index fe09106f..ea8dbcd2 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -84,4 +84,10 @@ struct wlr_box *wlr_output_layout_get_box( void wlr_output_layout_add_auto(struct wlr_output_layout *layout, struct wlr_output *output); +/** + * Get the output closest to the center of the layout extents. + */ +struct wlr_output *wlr_output_layout_get_center_output( + struct wlr_output_layout *layout); + #endif diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 48da6604..b0de41e2 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -106,6 +106,7 @@ struct wlr_xdg_surface_v6 { struct wl_list popup_link; bool configured; + bool added; struct wl_event_source *configure_idle; struct wl_list configure_list; diff --git a/rootston/desktop.c b/rootston/desktop.c index d5cac575..a7137255 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -67,35 +67,42 @@ void view_close(struct roots_view *view) { bool view_center(struct roots_view *view) { struct wlr_box size; view_get_size(view, &size); - if (size.width == 0 && size.height == 0) { - return false; - } struct roots_desktop *desktop = view->desktop; struct wlr_cursor *cursor = desktop->server->input->cursor; - struct wlr_output *output = wlr_output_layout_output_at(desktop->layout, - cursor->x, cursor->y); - const struct wlr_output_layout_output *output_layout = - wlr_output_layout_get(desktop->layout, output); + + struct wlr_output *output = + wlr_output_layout_output_at(desktop->layout, cursor->x, cursor->y); + + if (!output) { + output = wlr_output_layout_get_center_output(desktop->layout); + } + if (!output) { + // empty layout return false; } - view->x = (double)(output->width - size.width) / 2 - + output_layout->x; - view->y = (double)(output->height - size.height) / 2 - + output_layout->y; + const struct wlr_output_layout_output *l_output = + wlr_output_layout_get(desktop->layout, output); + + int width, height; + wlr_output_effective_resolution(output, &width, &height); + + view->x = (double)(width - size.width) / 2 + + l_output->x; + view->y = (double)(height - size.height) / 2 + + l_output->y; + 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; +void view_initialize(struct roots_view *view) { + view_center(view); + 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); } struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 34f53c7a..33f54a32 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -50,14 +50,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { } static void handle_surface_commit(struct wl_listener *listener, void *data) { - struct roots_wl_shell_surface *roots_surface = - wl_container_of(listener, roots_surface, surface_commit); - struct roots_view *view = roots_surface->view; - - if (view->wl_shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_TOPLEVEL && - !roots_surface->initialized) { - roots_surface->initialized = view_initialize(view); - } + // TODO do we need to do anything here? } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -137,4 +130,5 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->desktop = desktop; roots_surface->view = view; list_add(desktop->views, view); + view_initialize(view); } diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 9b8d8882..1e21fa02 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -68,14 +68,7 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { } 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; - - if (view->xdg_surface_v6->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL && - !roots_xdg_surface->initialized) { - roots_xdg_surface->initialized = view_initialize(view); - } + // TODO is there anything we need to do here? } static void handle_destroy(struct wl_listener *listener, void *data) { @@ -141,4 +134,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->desktop = desktop; roots_surface->view = view; list_add(desktop->views, view); + + view_initialize(view); } diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 1890074b..8c3f1d88 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -343,3 +343,20 @@ void wlr_output_layout_add_auto(struct wlr_output_layout *layout, l_output->state->auto_configured = true; wlr_output_layout_reconfigure(layout); } + +struct wlr_output *wlr_output_layout_get_center_output( + struct wlr_output_layout *layout) { + if (wl_list_empty(&layout->outputs)) { + return NULL; + } + + struct wlr_box *extents = wlr_output_layout_get_box(layout, NULL); + double center_x = extents->width / 2 + extents->x; + double center_y = extents->height / 2 + extents->y; + + double dest_x = 0, dest_y = 0; + wlr_output_layout_closest_point(layout, NULL, center_x, center_y, + &dest_x, &dest_y); + + return wlr_output_layout_output_at(layout, dest_x, dest_y); +} diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 3f5f22a0..31207c89 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -802,10 +802,7 @@ static void xdg_surface_ack_configure(struct wl_client *client, break; } - if (!surface->configured) { - surface->configured = true; - wl_signal_emit(&surface->client->shell->events.new_surface, surface); - } + surface->configured = true; wl_signal_emit(&surface->events.ack_configure, surface); @@ -1055,6 +1052,11 @@ static void handle_wlr_surface_committed(struct wl_listener *listener, break; } + if (surface->configured && !surface->added) { + surface->added = true; + wl_signal_emit(&surface->client->shell->events.new_surface, surface); + } + wl_signal_emit(&surface->events.commit, surface); } -- cgit v1.2.3