From b04a9a248d4cf3d0e93e1b39ee9eedc9da359173 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 20 Nov 2017 17:27:36 +0100 Subject: Initial fullscreen support --- rootston/desktop.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 7 deletions(-) (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index cf5a8cdc..be74b619 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -89,6 +89,19 @@ void view_move_resize(struct roots_view *view, double x, double y, view_resize(view, width, height); } +static struct wlr_output *view_get_output(struct roots_view *view) { + struct wlr_box view_box; + view_get_box(view, &view_box); + + double output_x, output_y; + wlr_output_layout_closest_point(view->desktop->layout, NULL, + view->x + (double)view_box.width/2, + view->y + (double)view_box.height/2, + &output_x, &output_y); + return wlr_output_layout_output_at(view->desktop->layout, output_x, + output_y); +} + void view_maximize(struct roots_view *view, bool maximized) { if (view->maximized == maximized) { return; @@ -109,13 +122,7 @@ void view_maximize(struct roots_view *view, bool maximized) { view->saved.width = view_box.width; view->saved.height = view_box.height; - double output_x, output_y; - wlr_output_layout_closest_point(view->desktop->layout, NULL, - view->x + (double)view_box.width/2, - view->y + (double)view_box.height/2, - &output_x, &output_y); - struct wlr_output *output = wlr_output_layout_output_at( - view->desktop->layout, output_x, output_y); + struct wlr_output *output = view_get_output(view); struct wlr_box *output_box = wlr_output_layout_get_box(view->desktop->layout, output); @@ -133,6 +140,54 @@ void view_maximize(struct roots_view *view, bool maximized) { } } +void view_set_fullscreen(struct roots_view *view, bool fullscreen, + struct wlr_output *output) { + bool was_fullscreen = view->fullscreen_output != NULL; + if (was_fullscreen == fullscreen) { + // TODO: support changing the output? + return; + } + + // TODO: check if client is focused? + + if (view->set_fullscreen) { + view->set_fullscreen(view, fullscreen); + } + + if (!was_fullscreen && fullscreen) { + if (output == NULL) { + output = view_get_output(view); + } + + struct wlr_box view_box; + view_get_box(view, &view_box); + + view->saved.x = view->x; + view->saved.y = view->y; + view->saved.rotation = view->rotation; + view->saved.width = view_box.width; + view->saved.height = view_box.height; + + struct wlr_box *output_box = + wlr_output_layout_get_box(view->desktop->layout, output); + view_move_resize(view, output_box->x, output_box->y, output_box->width, + output_box->height); + view->rotation = 0; + + wlr_output_set_fullscreen_surface(output, view->wlr_surface); + view->fullscreen_output = output; + } + + if (was_fullscreen && !fullscreen) { + view_move_resize(view, view->saved.x, view->saved.y, view->saved.width, + view->saved.height); + view->rotation = view->saved.rotation; + + wlr_output_set_fullscreen_surface(view->fullscreen_output, NULL); + view->fullscreen_output = NULL; + } +} + void view_close(struct roots_view *view) { if (view->close) { view->close(view); -- cgit v1.2.3 From abab2902f5051bcde93b34b5a57bf9bae93b3bab Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 20 Nov 2017 19:45:10 +0100 Subject: Check for subsurfaces and popups before using wlr_output_set_fullscreen_surface --- include/rootston/desktop.h | 5 +++-- include/rootston/view.h | 2 +- rootston/desktop.c | 16 +++++++++++++--- rootston/output.c | 27 ++++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 7 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index c245eb09..8bf1f6eb 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -19,13 +19,14 @@ struct roots_output { struct wlr_output *wlr_output; struct wl_listener frame; struct timespec last_frame; - struct wl_list link; + struct wl_list link; // roots_desktop:outputs + struct roots_view *fullscreen_view; }; struct roots_desktop { struct wl_list views; // roots_view::link - struct wl_list outputs; + struct wl_list outputs; // roots_output::link struct timespec last_frame; struct roots_server *server; diff --git a/include/rootston/view.h b/include/rootston/view.h index 77bbfbec..44a98115 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -57,7 +57,7 @@ struct roots_view { float rotation; bool maximized; - struct wlr_output *fullscreen_output; + struct roots_output *fullscreen_output; struct { double x, y; uint32_t width, height; diff --git a/rootston/desktop.c b/rootston/desktop.c index be74b619..b48da44b 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -174,8 +174,14 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen, output_box->height); view->rotation = 0; - wlr_output_set_fullscreen_surface(output, view->wlr_surface); - view->fullscreen_output = output; + struct roots_output *roots_output; + wl_list_for_each(roots_output, &view->desktop->outputs, link) { + if (roots_output->wlr_output == output) { + roots_output->fullscreen_view = view; + view->fullscreen_output = roots_output; + break; + } + } } if (was_fullscreen && !fullscreen) { @@ -183,7 +189,7 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen, view->saved.height); view->rotation = view->saved.rotation; - wlr_output_set_fullscreen_surface(view->fullscreen_output, NULL); + view->fullscreen_output->fullscreen_view = NULL; view->fullscreen_output = NULL; } } @@ -236,6 +242,10 @@ bool view_center(struct roots_view *view) { void view_destroy(struct roots_view *view) { wl_signal_emit(&view->events.destroy, view); + if (view->fullscreen_output) { + view->fullscreen_output->fullscreen_view = NULL; + } + wl_list_remove(&view->link); free(view); } diff --git a/rootston/output.c b/rootston/output.c index 35a5dac3..82618b06 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -174,6 +174,22 @@ static void render_view(struct roots_view *view, struct roots_desktop *desktop, } } +static bool has_standalone_surface(struct roots_view *view) { + if (!wl_list_empty(&view->wlr_surface->subsurface_list)) { + wlr_log(L_DEBUG, "has subsurfaces"); + return false; + } + + switch (view->type) { + case ROOTS_XDG_SHELL_V6_VIEW: + return wl_list_empty(&view->xdg_surface_v6->popups); + case ROOTS_WL_SHELL_VIEW: + return wl_list_empty(&view->wl_shell_surface->popups); + case ROOTS_XWAYLAND_VIEW: + return true; + } +} + static void output_frame_notify(struct wl_listener *listener, void *data) { struct wlr_output *wlr_output = data; struct roots_output *output = wl_container_of(listener, output, frame); @@ -186,11 +202,20 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { wlr_output_make_current(wlr_output); wlr_renderer_begin(server->renderer, wlr_output); - if (wlr_output->fullscreen_surface != NULL) { + if (output->fullscreen_view != NULL) { + if (has_standalone_surface(output->fullscreen_view)) { + wlr_output_set_fullscreen_surface(wlr_output, + output->fullscreen_view->wlr_surface); + } else { + wlr_output_set_fullscreen_surface(wlr_output, NULL); + render_view(output->fullscreen_view, desktop, wlr_output, &now); + } wlr_renderer_end(server->renderer); wlr_output_swap_buffers(wlr_output); output->last_frame = desktop->last_frame = now; return; + } else { + wlr_output_set_fullscreen_surface(wlr_output, NULL); } struct roots_view *view; -- cgit v1.2.3 From 9e29621ec32f6142f482780c764e6e93af31b806 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 21 Nov 2017 10:14:50 +0100 Subject: Always center fullscreen view on screen --- rootston/desktop.c | 5 +++++ rootston/output.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index 7a780cb9..0eb63dc4 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -53,6 +53,10 @@ static void view_update_output(const struct roots_view *view, } void view_move(struct roots_view *view, double x, double y) { + if (view->x == x && view->y == y) { + return; + } + struct wlr_box before; view_get_box(view, &before); if (view->move) { @@ -61,6 +65,7 @@ void view_move(struct roots_view *view, double x, double y) { view->x = x; view->y = y; } + view_update_output(view, &before); } void view_activate(struct roots_view *view, bool activate) { diff --git a/rootston/output.c b/rootston/output.c index d62c0b0d..bf684f2f 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -194,11 +195,26 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { wlr_renderer_begin(server->renderer, wlr_output); if (output->fullscreen_view != NULL) { + // Make sure the view is centered on screen + const struct wlr_box *output_box = + wlr_output_layout_get_box(desktop->layout, wlr_output); + struct wlr_box view_box; + view_get_box(output->fullscreen_view, &view_box); + double view_x = (double)(output_box->width - view_box.width) / 2 + + output_box->x; + double view_y = (double)(output_box->height - view_box.height) / 2 + + output_box->y; + view_move(output->fullscreen_view, view_x, view_y); + if (has_standalone_surface(output->fullscreen_view)) { wlr_output_set_fullscreen_surface(wlr_output, output->fullscreen_view->wlr_surface); } else { wlr_output_set_fullscreen_surface(wlr_output, NULL); + + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); + render_view(output->fullscreen_view, desktop, wlr_output, &now); } wlr_renderer_end(server->renderer); -- cgit v1.2.3 From 9a6f799d8f72c1dcd24e22749d43eb2ed54681c6 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 21 Nov 2017 10:37:53 +0100 Subject: Add fullscreen command, fix view_at with fullscreen views --- include/rootston/desktop.h | 6 +- rootston/cursor.c | 9 ++- rootston/desktop.c | 183 ++++++++++++++++++++++++++------------------- rootston/keyboard.c | 6 ++ 4 files changed, 122 insertions(+), 82 deletions(-) (limited to 'rootston/desktop.c') diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 8bf1f6eb..e5c5f806 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -60,11 +60,13 @@ struct roots_server; struct roots_desktop *desktop_create(struct roots_server *server, struct roots_config *config); void desktop_destroy(struct roots_desktop *desktop); +struct roots_output *desktop_output_from_wlr_output( + struct roots_desktop *desktop, struct wlr_output *output); +struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, + double ly, struct wlr_surface **surface, double *sx, double *sy); void view_init(struct roots_view *view, struct roots_desktop *desktop); void view_destroy(struct roots_view *view); -struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, - struct wlr_surface **surface, double *sx, double *sy); void view_activate(struct roots_view *view, bool activate); void output_add_notify(struct wl_listener *listener, void *data); diff --git a/rootston/cursor.c b/rootston/cursor.c index 71075aa9..b3c87b30 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -37,7 +37,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, double sx, sy; switch (cursor->mode) { case ROOTS_CURSOR_PASSTHROUGH: - view = view_at(desktop, cursor->cursor->x, cursor->cursor->y, + view = desktop_view_at(desktop, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); bool set_compositor_cursor = !view && cursor->cursor_client; if (view) { @@ -137,7 +137,8 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, struct wlr_surface *surface; double sx, sy; - struct roots_view *view = view_at(desktop, lx, ly, &surface, &sx, &sy); + struct roots_view *view = + desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); if (state == WLR_BUTTON_PRESSED && view && @@ -237,7 +238,7 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, return; } double sx, sy; - view_at(desktop, lx, ly, &surface, &sx, &sy); + desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); uint32_t serial = 0; if (surface) { @@ -291,7 +292,7 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, } double sx, sy; - view_at(desktop, lx, ly, &surface, &sx, &sy); + desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); if (surface) { wlr_seat_touch_point_focus(cursor->seat->seat, surface, diff --git a/rootston/desktop.c b/rootston/desktop.c index 0eb63dc4..1a21a7c2 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -163,6 +163,11 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen, if (output == NULL) { output = view_get_output(view); } + struct roots_output *roots_output = + desktop_output_from_wlr_output(view->desktop, output); + if (roots_output == NULL) { + return; + } struct wlr_box view_box; view_get_box(view, &view_box); @@ -179,14 +184,8 @@ void view_set_fullscreen(struct roots_view *view, bool fullscreen, output_box->height); view->rotation = 0; - struct roots_output *roots_output; - wl_list_for_each(roots_output, &view->desktop->outputs, link) { - if (roots_output->wlr_output == output) { - roots_output->fullscreen_view = view; - view->fullscreen_output = roots_output; - break; - } - } + roots_output->fullscreen_view = view; + view->fullscreen_output = roots_output; } if (was_fullscreen && !fullscreen) { @@ -273,83 +272,104 @@ void view_setup(struct roots_view *view) { view_update_output(view, &before); } -struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, +static bool view_at(struct roots_view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { - 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) { - continue; - } + if (view->type == ROOTS_WL_SHELL_VIEW && + view->wl_shell_surface->state == WLR_WL_SHELL_SURFACE_STATE_POPUP) { + return false; + } - double view_sx = lx - view->x; - double view_sy = ly - view->y; - - struct wlr_surface_state *state = view->wlr_surface->current; - struct wlr_box box = { - .x = 0, - .y = 0, - .width = state->buffer_width / state->scale, - .height = state->buffer_height / state->scale, - }; - if (view->rotation != 0.0) { - // Coordinates relative to the center of the view - double ox = view_sx - (double)box.width/2, - oy = view_sy - (double)box.height/2; - // Rotated coordinates - double rx = cos(view->rotation)*ox - sin(view->rotation)*oy, - ry = cos(view->rotation)*oy + sin(view->rotation)*ox; - view_sx = rx + (double)box.width/2; - view_sy = ry + (double)box.height/2; - } + double view_sx = lx - view->x; + double view_sy = ly - view->y; + + struct wlr_surface_state *state = view->wlr_surface->current; + struct wlr_box box = { + .x = 0, + .y = 0, + .width = state->buffer_width / state->scale, + .height = state->buffer_height / state->scale, + }; + if (view->rotation != 0.0) { + // Coordinates relative to the center of the view + double ox = view_sx - (double)box.width/2, + oy = view_sy - (double)box.height/2; + // Rotated coordinates + double rx = cos(view->rotation)*ox - sin(view->rotation)*oy, + ry = cos(view->rotation)*oy + sin(view->rotation)*ox; + view_sx = rx + (double)box.width/2; + view_sy = ry + (double)box.height/2; + } - if (view->type == ROOTS_XDG_SHELL_V6_VIEW) { - double popup_sx, popup_sy; - struct wlr_xdg_surface_v6 *popup = - wlr_xdg_surface_v6_popup_at(view->xdg_surface_v6, - view_sx, view_sy, &popup_sx, &popup_sy); - - if (popup) { - *sx = view_sx - popup_sx; - *sy = view_sy - popup_sy; - *surface = popup->surface; - return view; - } + if (view->type == ROOTS_XDG_SHELL_V6_VIEW) { + double popup_sx, popup_sy; + struct wlr_xdg_surface_v6 *popup = + wlr_xdg_surface_v6_popup_at(view->xdg_surface_v6, + view_sx, view_sy, &popup_sx, &popup_sy); + + if (popup) { + *sx = view_sx - popup_sx; + *sy = view_sy - popup_sy; + *surface = popup->surface; + return true; } + } - if (view->type == ROOTS_WL_SHELL_VIEW) { - double popup_sx, popup_sy; - struct wlr_wl_shell_surface *popup = - wlr_wl_shell_surface_popup_at(view->wl_shell_surface, - view_sx, view_sy, &popup_sx, &popup_sy); - - if (popup) { - *sx = view_sx - popup_sx; - *sy = view_sy - popup_sy; - *surface = popup->surface; - return view; - } + if (view->type == ROOTS_WL_SHELL_VIEW) { + double popup_sx, popup_sy; + struct wlr_wl_shell_surface *popup = + wlr_wl_shell_surface_popup_at(view->wl_shell_surface, + view_sx, view_sy, &popup_sx, &popup_sy); + + if (popup) { + *sx = view_sx - popup_sx; + *sy = view_sy - popup_sy; + *surface = popup->surface; + return true; } + } - double sub_x, sub_y; - struct wlr_subsurface *subsurface = - wlr_surface_subsurface_at(view->wlr_surface, - view_sx, view_sy, &sub_x, &sub_y); - if (subsurface) { - *sx = view_sx - sub_x; - *sy = view_sy - sub_y; - *surface = subsurface->surface; - return view; + double sub_x, sub_y; + struct wlr_subsurface *subsurface = + wlr_surface_subsurface_at(view->wlr_surface, + view_sx, view_sy, &sub_x, &sub_y); + if (subsurface) { + *sx = view_sx - sub_x; + *sy = view_sy - sub_y; + *surface = subsurface->surface; + return true; + } + + if (wlr_box_contains_point(&box, view_sx, view_sy) && + pixman_region32_contains_point(&view->wlr_surface->current->input, + view_sx, view_sy, NULL)) { + *sx = view_sx; + *sy = view_sy; + *surface = view->wlr_surface; + return true; + } + + return false; +} + +struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx, + double ly, struct wlr_surface **surface, double *sx, double *sy) { + struct wlr_output *wlr_output = + wlr_output_layout_output_at(desktop->layout, lx, ly); + if (wlr_output != NULL) { + struct roots_output *output = + desktop_output_from_wlr_output(desktop, wlr_output); + if (output != NULL && output->fullscreen_view != NULL) { + if (view_at(output->fullscreen_view, lx, ly, surface, sx, sy)) { + return output->fullscreen_view; + } else { + return NULL; + } } + } - if (wlr_box_contains_point(&box, view_sx, view_sy) && - pixman_region32_contains_point( - &view->wlr_surface->current->input, - view_sx, view_sy, NULL)) { - *sx = view_sx; - *sy = view_sy; - *surface = view->wlr_surface; + struct roots_view *view; + wl_list_for_each(view, &desktop->views, link) { + if (view_at(view, lx, ly, surface, sx, sy)) { return view; } } @@ -445,3 +465,14 @@ struct roots_desktop *desktop_create(struct roots_server *server, void desktop_destroy(struct roots_desktop *desktop) { // TODO } + +struct roots_output *desktop_output_from_wlr_output( + struct roots_desktop *desktop, struct wlr_output *output) { + struct roots_output *roots_output; + wl_list_for_each(roots_output, &desktop->outputs, link) { + if (roots_output->wlr_output == output) { + return roots_output; + } + } + return NULL; +} diff --git a/rootston/keyboard.c b/rootston/keyboard.c index f3fc9a85..6ad99077 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -95,6 +95,12 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard, if (focus != NULL) { view_close(focus); } + } else if (strcmp(command, "fullscreen") == 0) { + struct roots_view *focus = roots_seat_get_focus(seat); + if (focus != NULL) { + bool is_fullscreen = focus->fullscreen_output != NULL; + view_set_fullscreen(focus, !is_fullscreen, NULL); + } } else if (strcmp(command, "next_window") == 0) { roots_seat_cycle_focus(seat); } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { -- cgit v1.2.3 From 3262661e1e77db11d7e4939aa377804046df43f5 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 21 Nov 2017 20:58:15 +0100 Subject: Fix HiDPI support --- rootston/desktop.c | 6 ++---- types/wlr_output.c | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'rootston/desktop.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index eb18e716..bb3af258 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -36,7 +36,7 @@ static void view_update_output(const struct roots_view *view, struct wlr_box box; view_get_box(view, &box); wl_list_for_each(output, &desktop->outputs, link) { - bool intersected = before->x != -1 && wlr_output_layout_intersects( + bool intersected = before != NULL && wlr_output_layout_intersects( desktop->layout, output->wlr_output, before->x, before->y, before->x + before->width, before->y + before->height); @@ -280,9 +280,7 @@ void view_setup(struct roots_view *view) { } view_center(view); - struct wlr_box before; - view_get_box(view, &before); - view_update_output(view, &before); + view_update_output(view, NULL); } static bool view_at(struct roots_view *view, double lx, double ly, diff --git a/types/wlr_output.c b/types/wlr_output.c index 2ee95162..3f0e1c21 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -253,8 +253,8 @@ void wlr_output_make_current(struct wlr_output *output) { static void output_fullscreen_surface_render(struct wlr_output *output, struct wlr_surface *surface, const struct timespec *when) { - int x = (output->width - surface->current->width) / 2; - int y = (output->height - surface->current->height) / 2; + int x = (output->width - surface->current->buffer_width) / 2; + int y = (output->height - surface->current->buffer_height) / 2; glViewport(0, 0, output->width, output->height); glClearColor(0, 0, 0, 0); -- cgit v1.2.3