diff options
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/cursor.c | 103 | ||||
-rw-r--r-- | rootston/desktop.c | 63 | ||||
-rw-r--r-- | rootston/output.c | 138 | ||||
-rw-r--r-- | rootston/seat.c | 48 | ||||
-rw-r--r-- | rootston/xwayland.c | 7 |
5 files changed, 292 insertions, 67 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c index 824cd917..a09211b7 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -30,19 +30,93 @@ void roots_cursor_destroy(struct roots_cursor *cursor) { // TODO } +static void seat_view_deco_motion(struct roots_seat_view *view, double deco_sx, double deco_sy) { + struct roots_cursor *cursor = view->seat->cursor; + + double sx = deco_sx; + double sy = deco_sy; + if (view->has_button_grab) { + sx = view->grab_sx; + sy = view->grab_sy; + } + + enum roots_deco_part parts = view_get_deco_part(view->view, sx, sy); + + bool is_titlebar = (parts & ROOTS_DECO_PART_TITLEBAR); + uint32_t edges = 0; + if (parts & ROOTS_DECO_PART_LEFT_BORDER) { + edges |= WLR_EDGE_LEFT; + } else if (parts & ROOTS_DECO_PART_RIGHT_BORDER) { + edges |= WLR_EDGE_RIGHT; + } else if (parts & ROOTS_DECO_PART_BOTTOM_BORDER) { + edges |= WLR_EDGE_BOTTOM; + } else if (parts & ROOTS_DECO_PART_TOP_BORDER) { + edges |= WLR_EDGE_TOP; + } + + if (view->has_button_grab) { + if (is_titlebar) { + roots_seat_begin_move(view->seat, view->view); + } else if (edges) { + roots_seat_begin_resize(view->seat, view->view, edges); + } + view->has_button_grab = false; + } else { + if (is_titlebar) { + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + cursor->default_xcursor, cursor->cursor); + } else if (edges) { + const char *resize_name = wlr_xcursor_get_resize_name(edges); + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + resize_name, cursor->cursor); + } + } +} + +static void seat_view_deco_leave(struct roots_seat_view *view) { + struct roots_cursor *cursor = view->seat->cursor; + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + cursor->default_xcursor, cursor->cursor); + view->has_button_grab = false; +} + +static void seat_view_deco_button(struct roots_seat_view *view, double sx, + double sy, uint32_t button, uint32_t state) { + if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED) { + view->has_button_grab = true; + view->grab_sx = sx; + view->grab_sy = sy; + } else { + view->has_button_grab = false; + } + + enum roots_deco_part parts = view_get_deco_part(view->view, sx, sy); + if (state == WLR_BUTTON_RELEASED && (parts & ROOTS_DECO_PART_TITLEBAR)) { + struct roots_cursor *cursor = view->seat->cursor; + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + cursor->default_xcursor, cursor->cursor); + } +} + static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t time) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; struct roots_seat *seat = cursor->seat; struct roots_view *view; - struct wlr_surface *surface; + struct wlr_surface *surface = NULL; double sx, sy; switch (cursor->mode) { case ROOTS_CURSOR_PASSTHROUGH: view = desktop_view_at(desktop, cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); - bool set_compositor_cursor = !view && cursor->cursor_client; - if (view) { + struct roots_seat_view *seat_view = + roots_seat_view_from_view(seat, view); + if (cursor->pointer_view && (surface || seat_view != cursor->pointer_view)) { + seat_view_deco_leave(cursor->pointer_view); + cursor->pointer_view = NULL; + } + bool set_compositor_cursor = !view && !surface && cursor->cursor_client; + if (view && surface) { struct wl_client *view_client = wl_resource_get_client(view->wlr_surface->resource); set_compositor_cursor = view_client != cursor->cursor_client; @@ -52,7 +126,13 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, cursor->default_xcursor, cursor->cursor); cursor->cursor_client = NULL; } - if (view) { + if (view && !surface) { + if (seat_view) { + cursor->pointer_view = seat_view; + seat_view_deco_motion(seat_view, sx, sy); + } + } if (view && surface) { + // motion over a view surface wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy); wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy); } else { @@ -136,7 +216,7 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, struct roots_desktop *desktop = seat->input->server->desktop; bool is_touch = device->type == WLR_INPUT_DEVICE_TOUCH; - struct wlr_surface *surface; + struct wlr_surface *surface = NULL; double sx, sy; struct roots_view *view = desktop_view_at(desktop, lx, ly, &surface, &sx, &sy); @@ -171,6 +251,13 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, } return; } + + if (view && !surface) { + if (cursor->pointer_view) { + seat_view_deco_button(cursor->pointer_view, sx, sy, button, state); + } + } + if (state == WLR_BUTTON_RELEASED && cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { cursor->mode = ROOTS_CURSOR_PASSTHROUGH; @@ -179,8 +266,10 @@ static void roots_cursor_press_button(struct roots_cursor *cursor, } } - if (!is_touch) { - wlr_seat_pointer_notify_button(seat->seat, time, button, state); + if (view && surface) { + if (!is_touch) { + wlr_seat_pointer_notify_button(seat->seat, time, button, state); + } } switch (state) { diff --git a/rootston/desktop.c b/rootston/desktop.c index 4bb1de5f..b2d586f4 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -19,6 +19,7 @@ #include "rootston/server.h" #include "rootston/seat.h" #include "rootston/xcursor.h" +#include "rootston/view.h" void view_get_box(const struct roots_view *view, struct wlr_box *box) { box->x = view->x; @@ -26,11 +27,66 @@ void view_get_box(const struct roots_view *view, struct wlr_box *box) { if (view->get_size) { view->get_size(view, box); } else { + if (view->wlr_surface == NULL) { + // View is unmapped + box->width = box->height = 0; + return; + } + box->width = view->wlr_surface->current->width; box->height = view->wlr_surface->current->height; } } +void view_get_deco_box(const struct roots_view *view, struct wlr_box *box) { + view_get_box(view, box); + if (!view->decorated) { + return; + } + + box->x -= view->border_width; + box->y -= (view->border_width + view->titlebar_height); + box->width += view->border_width * 2; + box->height += (view->border_width * 2 + view->titlebar_height); +} + +enum roots_deco_part view_get_deco_part(struct roots_view *view, double sx, double sy) { + if (!view->decorated) { + return ROOTS_DECO_PART_NONE; + } + + int sw = view->wlr_surface->current->width; + int sh = view->wlr_surface->current->height; + int bw = view->border_width; + int titlebar_h = view->titlebar_height; + + if (sx > 0 && sx < sw && sy < 0 && sy > -view->titlebar_height) { + return ROOTS_DECO_PART_TITLEBAR; + } + + enum roots_deco_part parts = 0; + if (sy >= -(titlebar_h + bw) && + sy <= sh + bw) { + if (sx < 0 && sx > -bw) { + parts |= ROOTS_DECO_PART_LEFT_BORDER; + } else if (sx > sw && sx < sw + bw) { + parts |= ROOTS_DECO_PART_RIGHT_BORDER; + } + } + + if (sx >= -bw && sx <= sw + bw) { + if (sy > sh && sy <= sh + bw) { + parts |= ROOTS_DECO_PART_BOTTOM_BORDER; + } else if (sy >= -(titlebar_h + bw) && sy < 0) { + parts |= ROOTS_DECO_PART_TOP_BORDER; + } + } + + // TODO corners + + return parts; +} + static void view_update_output(const struct roots_view *view, const struct wlr_box *before) { struct roots_desktop *desktop = view->desktop; @@ -468,6 +524,13 @@ static bool view_at(struct roots_view *view, double lx, double ly, return true; } + if (view_get_deco_part(view, view_sx, view_sy)) { + *sx = view_sx; + *sy = view_sy; + *surface = NULL; + 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)) { diff --git a/rootston/output.c b/rootston/output.c index 1b2a17d8..2283ad16 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -174,7 +174,6 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, struct render_data *data = _data; struct roots_output *output = data->output; struct timespec *when = data->when; - pixman_region32_t *damage = data->damage; if (!wlr_surface_has_buffer(surface)) { return; @@ -188,63 +187,95 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, } // TODO: output scale, output transform support - pixman_region32_t surface_damage; - pixman_region32_init(&surface_damage); - pixman_region32_union_rect(&surface_damage, &surface_damage, box.x, box.y, + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_union_rect(&damage, &damage, box.x, box.y, box.width, box.height); - pixman_region32_intersect(&surface_damage, &surface_damage, damage); - bool damaged = pixman_region32_not_empty(&surface_damage); + pixman_region32_intersect(&damage, &damage, data->damage); + bool damaged = pixman_region32_not_empty(&damage); if (!damaged) { - goto surface_damage_finish; + goto damage_finish; } - float transform[16]; - wlr_matrix_translate(&transform, box.x, box.y, 0); - - if (rotation != 0) { - float translate_center[16]; - wlr_matrix_translate(&translate_center, box.width/2, box.height/2, 0); + float matrix[16]; + enum wl_output_transform transform = + wlr_output_transform_invert(surface->current->transform); + wlr_matrix_project_box(&matrix, &box, transform, rotation, + &output->wlr_output->transform_matrix); - float rotate[16]; - wlr_matrix_rotate(&rotate, rotation); + int nrects; + pixman_box32_t *rects = + pixman_region32_rectangles(&damage, &nrects); + for (int i = 0; i < nrects; ++i) { + struct wlr_box scissor = { + .x = rects[i].x1, + .y = output->wlr_output->height - rects[i].y2, + .width = rects[i].x2 - rects[i].x1, + .height = rects[i].y2 - rects[i].y1, + }; + wlr_renderer_scissor(output->desktop->server->renderer, &scissor); + wlr_render_with_matrix(output->desktop->server->renderer, + surface->texture, &matrix); + } - float translate_origin[16]; - wlr_matrix_translate(&translate_origin, -box.width/2, -box.height/2, 0); + wlr_surface_send_frame_done(surface, when); - wlr_matrix_mul(&transform, &translate_center, &transform); - wlr_matrix_mul(&transform, &rotate, &transform); - wlr_matrix_mul(&transform, &translate_origin, &transform); - } +damage_finish: + pixman_region32_fini(&damage); +} - float scale[16]; - wlr_matrix_scale(&scale, box.width, box.height, 1); +static void get_decoration_box(struct roots_view *view, + struct roots_output *output, struct wlr_box *box) { + struct wlr_output *wlr_output = output->wlr_output; - wlr_matrix_mul(&transform, &scale, &transform); + struct wlr_box deco_box; + view_get_deco_box(view, &deco_box); + double sx = deco_box.x - view->x; + double sy = deco_box.y - view->y; + rotate_child_position(&sx, &sy, deco_box.width, deco_box.height, + view->wlr_surface->current->width, + view->wlr_surface->current->height, view->rotation); + double x = sx + view->x; + double y = sy + view->y; + + wlr_output_layout_output_coords(output->desktop->layout, wlr_output, &x, &y); + + box->x = x * wlr_output->scale; + box->y = y * wlr_output->scale; + box->width = deco_box.width * wlr_output->scale; + box->height = deco_box.height * wlr_output->scale; +} - if (surface->current->transform != WL_OUTPUT_TRANSFORM_NORMAL) { - float surface_translate_center[16]; - wlr_matrix_translate(&surface_translate_center, 0.5, 0.5, 0); +static void render_decorations(struct roots_view *view, + struct render_data *data) { + if (!view->decorated || view->wlr_surface == NULL) { + return; + } - float surface_transform[16]; - wlr_matrix_transform(surface_transform, - wlr_output_transform_invert(surface->current->transform)); + struct roots_output *output = data->output; - float surface_translate_origin[16]; - wlr_matrix_translate(&surface_translate_origin, -0.5, -0.5, 0); + struct wlr_box box; + get_decoration_box(view, output, &box); - wlr_matrix_mul(&transform, &surface_translate_center, - &transform); - wlr_matrix_mul(&transform, &surface_transform, &transform); - wlr_matrix_mul(&transform, &surface_translate_origin, - &transform); + // TODO: output scale, output transform support + pixman_region32_t damage; + pixman_region32_init(&damage); + pixman_region32_union_rect(&damage, &damage, box.x, box.y, + box.width, box.height); + pixman_region32_intersect(&damage, &damage, data->damage); + bool damaged = pixman_region32_not_empty(&damage); + if (!damaged) { + goto damage_finish; } float matrix[16]; - wlr_matrix_mul(&output->wlr_output->transform_matrix, &transform, &matrix); + wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, + view->rotation, &output->wlr_output->transform_matrix); + float color[] = { 0.2, 0.2, 0.2, 1 }; int nrects; pixman_box32_t *rects = - pixman_region32_rectangles(&surface_damage, &nrects); + pixman_region32_rectangles(&damage, &nrects); for (int i = 0; i < nrects; ++i) { struct wlr_box scissor = { .x = rects[i].x1, @@ -253,14 +284,17 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, .height = rects[i].y2 - rects[i].y1, }; wlr_renderer_scissor(output->desktop->server->renderer, &scissor); - wlr_render_with_matrix(output->desktop->server->renderer, - surface->texture, &matrix); + wlr_render_colored_quad(output->desktop->server->renderer, &color, + &matrix); } - wlr_surface_send_frame_done(surface, when); +damage_finish: + pixman_region32_fini(&damage); +} -surface_damage_finish: - pixman_region32_fini(&surface_damage); +static void render_view(struct roots_view *view, struct render_data *data) { + render_decorations(view, data); + view_for_each_surface(view, render_surface, data); } static bool has_standalone_surface(struct roots_view *view) { @@ -402,7 +436,7 @@ static void render_output(struct roots_output *output) { // Render all views struct roots_view *view; wl_list_for_each_reverse(view, &desktop->views, link) { - view_for_each_surface(view, render_surface, &data); + render_view(view, &data); } // Render drag icons @@ -505,12 +539,26 @@ static void damage_whole_surface(struct wlr_surface *surface, schedule_render(output); } +static void damage_whole_decoration(struct roots_view *view, + struct roots_output *output) { + if (!view->decorated || view->wlr_surface == NULL) { + return; + } + + struct wlr_box box; + get_decoration_box(view, output, &box); + + pixman_region32_union_rect(&output->damage, &output->damage, + box.x, box.y, box.width, box.height); +} + void output_damage_whole_view(struct roots_output *output, struct roots_view *view) { if (!view_accept_damage(output, view)) { return; } + damage_whole_decoration(view, output); view_for_each_surface(view, damage_whole_surface, output); } diff --git a/rootston/seat.c b/rootston/seat.c index e5f38b0b..7ff46f98 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -654,6 +654,10 @@ static void seat_view_destroy(struct roots_seat_view *seat_view) { seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH; } + if (seat_view == seat->cursor->pointer_view) { + seat->cursor->pointer_view = NULL; + } + wl_list_remove(&seat_view->view_destroy.link); wl_list_remove(&seat_view->link); free(seat_view); @@ -682,7 +686,7 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat, seat_view->seat = seat; seat_view->view = view; - wl_list_insert(&seat->views, &seat_view->link); + wl_list_insert(seat->views.prev, &seat_view->link); seat_view->view_destroy.notify = seat_view_handle_destroy; wl_signal_add(&view->events.destroy, &seat_view->view_destroy); @@ -690,6 +694,31 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat, return seat_view; } +struct roots_seat_view *roots_seat_view_from_view( + struct roots_seat *seat, struct roots_view *view) { + if (view == NULL) { + return NULL; + } + + bool found = false; + struct roots_seat_view *seat_view = NULL; + 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 NULL; + } + } + + 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 @@ -707,22 +736,11 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { view->xwayland_surface->override_redirect) { return; } - 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_view = roots_seat_view_from_view(seat, view); + if (seat_view == NULL) { + return; } } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 24315e1a..c0bc9ae7 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -314,6 +314,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->type = ROOTS_XWAYLAND_VIEW; view->x = (double)surface->x; view->y = (double)surface->y; + view->xwayland_surface = surface; view->roots_xwayland_surface = roots_surface; view->wlr_surface = surface->surface; @@ -329,6 +330,12 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_list_insert(&desktop->views, &view->link); if (!surface->override_redirect) { + if (surface->decorations == WLR_XWAYLAND_SURFACE_DECORATIONS_ALL) { + view->decorated = true; + view->border_width = 4; + view->titlebar_height = 12; + } + view_setup(view); } } |