mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-02 03:45:58 +01:00
rootston: damage tracking for drag icons
This commit is contained in:
parent
415a2b7c56
commit
2ad7df8680
9 changed files with 142 additions and 31 deletions
|
@ -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
|
||||
|
|
|
@ -17,12 +17,15 @@ struct roots_seat {
|
|||
struct wl_list views; // roots_seat_view::link
|
||||
bool has_focus;
|
||||
|
||||
struct wl_list drag_icons; // roots_drag_icon::link
|
||||
|
||||
struct wl_list keyboards;
|
||||
struct wl_list pointers;
|
||||
struct wl_list touch;
|
||||
struct wl_list tablet_tools;
|
||||
|
||||
struct wl_listener seat_destroy;
|
||||
struct wl_listener new_drag_icon;
|
||||
struct wl_listener destroy;
|
||||
};
|
||||
|
||||
struct roots_seat_view {
|
||||
|
@ -33,6 +36,18 @@ struct roots_seat_view {
|
|||
struct wl_listener view_destroy;
|
||||
};
|
||||
|
||||
struct roots_drag_icon {
|
||||
struct roots_seat *seat;
|
||||
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;
|
||||
};
|
||||
|
||||
struct roots_pointer {
|
||||
struct roots_seat *seat;
|
||||
struct wlr_input_device *device;
|
||||
|
@ -84,4 +99,8 @@ 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);
|
||||
|
||||
void roots_drag_icon_update_position(struct roots_drag_icon *icon);
|
||||
|
||||
void roots_drag_icon_damage_whole(struct roots_drag_icon *icon);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -71,10 +71,10 @@ struct wlr_drag_icon {
|
|||
bool is_pointer;
|
||||
int32_t touch_id;
|
||||
|
||||
int32_t sx;
|
||||
int32_t sy;
|
||||
int32_t sx, sy;
|
||||
|
||||
struct {
|
||||
struct wl_signal map; // emitted when mapped or unmapped
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
|
||||
|
|
|
@ -209,6 +209,8 @@ struct wlr_seat {
|
|||
struct wl_signal selection;
|
||||
struct wl_signal primary_selection;
|
||||
|
||||
struct wl_signal new_drag_icon;
|
||||
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
|
||||
|
|
|
@ -58,6 +58,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);
|
||||
|
|
|
@ -406,29 +406,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -528,6 +514,12 @@ void output_damage_whole_view(struct roots_output *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;
|
||||
|
|
|
@ -241,19 +241,97 @@ static void roots_seat_init_cursor(struct roots_seat *seat) {
|
|||
seat->cursor->tool_tip.notify = handle_tool_tip;
|
||||
|
||||
wl_signal_add(&seat->seat->events.request_set_cursor,
|
||||
&seat->cursor->request_set_cursor);
|
||||
&seat->cursor->request_set_cursor);
|
||||
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);
|
||||
struct wlr_drag_icon *wlr_drag_icon = data;
|
||||
|
||||
struct roots_drag_icon *icon = calloc(1, sizeof(struct roots_drag_icon));
|
||||
if (icon == NULL) {
|
||||
return;
|
||||
}
|
||||
icon->seat = seat;
|
||||
icon->wlr_drag_icon = wlr_drag_icon;
|
||||
|
||||
icon->surface_commit.notify = roots_drag_icon_handle_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;
|
||||
wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy);
|
||||
|
||||
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_seat_destroy(struct wl_listener *listener,
|
||||
static void roots_seat_handle_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct roots_seat *seat =
|
||||
wl_container_of(listener, seat, seat_destroy);
|
||||
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) {
|
||||
|
@ -262,7 +340,7 @@ static void roots_seat_handle_seat_destroy(struct wl_listener *listener,
|
|||
}
|
||||
|
||||
void roots_seat_destroy(struct roots_seat *seat) {
|
||||
roots_seat_handle_seat_destroy(&seat->seat_destroy, seat->seat);
|
||||
roots_seat_handle_destroy(&seat->destroy, seat->seat);
|
||||
wlr_seat_destroy(seat->seat);
|
||||
}
|
||||
|
||||
|
@ -277,6 +355,7 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
|
|||
wl_list_init(&seat->touch);
|
||||
wl_list_init(&seat->tablet_tools);
|
||||
wl_list_init(&seat->views);
|
||||
wl_list_init(&seat->drag_icons);
|
||||
|
||||
seat->input = input;
|
||||
|
||||
|
@ -295,8 +374,10 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) {
|
|||
|
||||
wl_list_insert(&input->seats, &seat->link);
|
||||
|
||||
seat->seat_destroy.notify = roots_seat_handle_seat_destroy;
|
||||
wl_signal_add(&seat->seat->events.destroy, &seat->seat_destroy);
|
||||
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_destroy;
|
||||
wl_signal_add(&seat->seat->events.destroy, &seat->destroy);
|
||||
|
||||
return seat;
|
||||
}
|
||||
|
|
|
@ -454,6 +454,7 @@ static void wlr_drag_end(struct wlr_drag *drag) {
|
|||
if (drag->icon) {
|
||||
drag->icon->mapped = false;
|
||||
wl_list_remove(&drag->icon_destroy.link);
|
||||
wl_signal_emit(&drag->icon->events.map, drag->icon);
|
||||
}
|
||||
|
||||
free(drag);
|
||||
|
@ -673,8 +674,8 @@ static struct wlr_drag_icon *wlr_drag_icon_create(
|
|||
icon->is_pointer = is_pointer;
|
||||
icon->touch_id = touch_id;
|
||||
icon->mapped = true;
|
||||
wl_list_insert(&client->seat->drag_icons, &icon->link);
|
||||
|
||||
wl_signal_init(&icon->events.map);
|
||||
wl_signal_init(&icon->events.destroy);
|
||||
|
||||
wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy);
|
||||
|
@ -686,6 +687,9 @@ static struct wlr_drag_icon *wlr_drag_icon_create(
|
|||
wl_signal_add(&client->events.destroy, &icon->seat_client_destroy);
|
||||
icon->seat_client_destroy.notify = handle_drag_icon_seat_client_destroy;
|
||||
|
||||
wl_list_insert(&client->seat->drag_icons, &icon->link);
|
||||
wl_signal_emit(&client->seat->events.new_drag_icon, icon);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
|
|
@ -454,7 +454,10 @@ struct wlr_seat *wlr_seat_create(struct wl_display *display, const char *name) {
|
|||
wl_list_init(&wlr_seat->clients);
|
||||
wl_list_init(&wlr_seat->drag_icons);
|
||||
|
||||
wl_signal_init(&wlr_seat->events.new_drag_icon);
|
||||
|
||||
wl_signal_init(&wlr_seat->events.request_set_cursor);
|
||||
|
||||
wl_signal_init(&wlr_seat->events.selection);
|
||||
wl_signal_init(&wlr_seat->events.primary_selection);
|
||||
|
||||
|
|
Loading…
Reference in a new issue