diff --git a/include/rootston/output.h b/include/rootston/output.h index 89fe1d82..81f20788 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -37,9 +37,14 @@ struct roots_output { void output_add_notify(struct wl_listener *listener, void *data); void output_remove_notify(struct wl_listener *listener, void *data); +struct roots_view; +struct roots_drag_icon; + void output_damage_whole_view(struct roots_output *output, struct roots_view *view); void output_damage_from_view(struct roots_output *output, struct roots_view *view); +void output_damage_whole_drag_icon(struct roots_output *output, + struct roots_drag_icon *icon); #endif diff --git a/include/rootston/seat.h b/include/rootston/seat.h index f1061226..fa7d38df 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -46,6 +46,8 @@ struct roots_drag_icon { struct wlr_drag_icon *wlr_drag_icon; struct wl_list link; + double x, y; + struct wl_listener surface_commit; struct wl_listener map; struct wl_listener destroy; @@ -103,6 +105,10 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view); struct roots_seat_view *roots_seat_view_from_view( struct roots_seat *seat, - struct roots_view *view); + struct roots_view *view); + +void roots_drag_icon_update_position(struct roots_drag_icon *icon); + +void roots_drag_icon_damage_whole(struct roots_drag_icon *icon); #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index d8753f44..a09211b7 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -138,6 +138,11 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, } else { wlr_seat_pointer_clear_focus(seat->seat); } + + struct roots_drag_icon *drag_icon; + wl_list_for_each(drag_icon, &seat->drag_icons, link) { + roots_drag_icon_update_position(drag_icon); + } break; case ROOTS_CURSOR_MOVE: view = roots_seat_get_focus(seat); diff --git a/rootston/desktop.c b/rootston/desktop.c index 727710fe..b2d586f4 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -27,6 +27,12 @@ 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; } diff --git a/rootston/output.c b/rootston/output.c index 4cd0cb44..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,14 +187,14 @@ 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 matrix[16]; @@ -206,7 +205,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, 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, @@ -221,17 +220,12 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly, wlr_surface_send_frame_done(surface, when); -surface_damage_finish: - pixman_region32_fini(&surface_damage); +damage_finish: + pixman_region32_fini(&damage); } -static void render_decorations(struct roots_view *view, - struct render_data *data) { - if (!view->decorated) { - return; - } - - struct roots_output *output = data->output; +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; struct wlr_box deco_box; @@ -246,18 +240,56 @@ static void render_decorations(struct roots_view *view, wlr_output_layout_output_coords(output->desktop->layout, wlr_output, &x, &y); - struct wlr_box box = { - .x = x * wlr_output->scale, - .y = y * wlr_output->scale, - .width = deco_box.width * wlr_output->scale, - .height = deco_box.height * wlr_output->scale, - }; + 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; +} + +static void render_decorations(struct roots_view *view, + struct render_data *data) { + if (!view->decorated || view->wlr_surface == NULL) { + return; + } + + struct roots_output *output = data->output; + + struct wlr_box box; + get_decoration_box(view, output, &box); + + // 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_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, - view->rotation, &wlr_output->transform_matrix); - float color[4] = { 0.2, 0.2, 0.2, 1 }; - wlr_render_colored_quad(output->desktop->server->renderer, &color, &matrix); + 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(&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_colored_quad(output->desktop->server->renderer, &color, + &matrix); + } + +damage_finish: + pixman_region32_fini(&damage); } static void render_view(struct roots_view *view, struct render_data *data) { @@ -408,29 +440,15 @@ static void render_output(struct roots_output *output) { } // Render drag icons - struct wlr_drag_icon *drag_icon = NULL; + struct roots_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->seat->drag_icons, link) { - if (!drag_icon->mapped) { + wl_list_for_each(drag_icon, &seat->drag_icons, link) { + if (!drag_icon->wlr_drag_icon->mapped) { continue; } - struct wlr_surface *icon = drag_icon->surface; - struct wlr_cursor *cursor = seat->cursor->cursor; - double icon_x = 0, icon_y = 0; - if (drag_icon->is_pointer) { - icon_x = cursor->x + drag_icon->sx; - icon_y = cursor->y + drag_icon->sy; - render_surface(icon, icon_x, icon_y, 0, &data); - } else { - struct wlr_touch_point *point = - wlr_seat_touch_get_point(seat->seat, drag_icon->touch_id); - if (point) { - icon_x = seat->touch_x + drag_icon->sx; - icon_y = seat->touch_y + drag_icon->sy; - render_surface(icon, icon_x, icon_y, 0, &data); - } - } + render_surface(drag_icon->wlr_drag_icon->surface, + drag_icon->x, drag_icon->y, 0, &data); } } @@ -521,15 +539,35 @@ 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); } +void output_damage_whole_drag_icon(struct roots_output *output, + struct roots_drag_icon *icon) { + surface_for_each_surface(icon->wlr_drag_icon->surface, icon->x, icon->y, 0, + damage_whole_surface, output); +} + static void damage_from_surface(struct wlr_surface *surface, double lx, double ly, float rotation, void *data) { struct roots_output *output = data; diff --git a/rootston/seat.c b/rootston/seat.c index aa88364a..7ff46f98 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -245,6 +245,33 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { seat->cursor->request_set_cursor.notify = handle_request_set_cursor; } +static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener, + void *data) { + struct roots_drag_icon *icon = + wl_container_of(listener, icon, surface_commit); + roots_drag_icon_damage_whole(icon); +} + +static void roots_drag_icon_handle_map(struct wl_listener *listener, + void *data) { + struct roots_drag_icon *icon = + wl_container_of(listener, icon, map); + roots_drag_icon_damage_whole(icon); +} + +static void roots_drag_icon_handle_destroy(struct wl_listener *listener, + void *data) { + struct roots_drag_icon *icon = + wl_container_of(listener, icon, destroy); + roots_drag_icon_damage_whole(icon); + + wl_list_remove(&icon->link); + wl_list_remove(&icon->surface_commit.link); + wl_list_remove(&icon->map.link); + wl_list_remove(&icon->destroy.link); + free(icon); +} + static void roots_seat_handle_new_drag_icon(struct wl_listener *listener, void *data) { struct roots_seat *seat = wl_container_of(listener, seat, new_drag_icon); @@ -258,7 +285,7 @@ static void roots_seat_handle_new_drag_icon(struct wl_listener *listener, icon->wlr_drag_icon = wlr_drag_icon; icon->surface_commit.notify = roots_drag_icon_handle_surface_commit; - wl_signal_add(&wlr_drag_icon->events.surface_commit, &icon->surface_commit); + wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit); icon->map.notify = roots_drag_icon_handle_map; wl_signal_add(&wlr_drag_icon->events.map, &icon->map); icon->destroy.notify = roots_drag_icon_handle_destroy; @@ -267,6 +294,36 @@ static void roots_seat_handle_new_drag_icon(struct wl_listener *listener, wl_list_insert(&seat->drag_icons, &icon->link); } +void roots_drag_icon_update_position(struct roots_drag_icon *icon) { + roots_drag_icon_damage_whole(icon); + + struct wlr_drag_icon *wlr_icon = icon->wlr_drag_icon; + struct roots_seat *seat = icon->seat; + struct wlr_cursor *cursor = seat->cursor->cursor; + if (wlr_icon->is_pointer) { + icon->x = cursor->x + wlr_icon->sx; + icon->y = cursor->y + wlr_icon->sy; + } else { + struct wlr_touch_point *point = + wlr_seat_touch_get_point(seat->seat, wlr_icon->touch_id); + if (point == NULL) { + return; + } + icon->x = seat->touch_x + wlr_icon->sx; + icon->y = seat->touch_y + wlr_icon->sy; + } + + roots_drag_icon_damage_whole(icon); +} + +void roots_drag_icon_damage_whole(struct roots_drag_icon *icon) { + struct roots_output *output; + wl_list_for_each(output, &icon->seat->input->server->desktop->outputs, + link) { + output_damage_whole_drag_icon(output, icon); + } +} + static void seat_view_destroy(struct roots_seat_view *seat_view); static void roots_seat_handle_destroy(struct wl_listener *listener, @@ -274,7 +331,7 @@ static void roots_seat_handle_destroy(struct wl_listener *listener, struct roots_seat *seat = wl_container_of(listener, seat, destroy); // TODO: probably more to be freed here - wl_list_remove(&seat->seat_destroy.link); + wl_list_remove(&seat->destroy.link); struct roots_seat_view *view, *nview; wl_list_for_each_safe(view, nview, &seat->views, link) { @@ -319,7 +376,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { seat->new_drag_icon.notify = roots_seat_handle_new_drag_icon; wl_signal_add(&seat->seat->events.new_drag_icon, &seat->new_drag_icon); - seat->destroy.notify = roots_seat_handle_seat_destroy; + seat->destroy.notify = roots_seat_handle_destroy; wl_signal_add(&seat->seat->events.destroy, &seat->destroy); return seat;