Merge pull request #1043 from acrisci/drag-icon-unmap

drag-icon map and unmap fixes
This commit is contained in:
emersion 2018-06-07 11:18:58 +01:00 committed by GitHub
commit 6f895081e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 7 deletions

View File

@ -59,6 +59,7 @@ struct roots_drag_icon {
struct wl_listener surface_commit; struct wl_listener surface_commit;
struct wl_listener map; struct wl_listener map;
struct wl_listener unmap;
struct wl_listener destroy; struct wl_listener destroy;
}; };

View File

@ -88,7 +88,8 @@ struct wlr_drag_icon {
int32_t sx, sy; int32_t sx, sy;
struct { struct {
struct wl_signal map; // emitted when mapped or unmapped struct wl_signal map;
struct wl_signal unmap;
struct wl_signal destroy; struct wl_signal destroy;
} events; } events;

View File

@ -260,7 +260,7 @@ static void roots_drag_icon_handle_surface_commit(struct wl_listener *listener,
void *data) { void *data) {
struct roots_drag_icon *icon = struct roots_drag_icon *icon =
wl_container_of(listener, icon, surface_commit); wl_container_of(listener, icon, surface_commit);
roots_drag_icon_damage_whole(icon); roots_drag_icon_update_position(icon);
} }
static void roots_drag_icon_handle_map(struct wl_listener *listener, static void roots_drag_icon_handle_map(struct wl_listener *listener,
@ -270,6 +270,13 @@ static void roots_drag_icon_handle_map(struct wl_listener *listener,
roots_drag_icon_damage_whole(icon); roots_drag_icon_damage_whole(icon);
} }
static void roots_drag_icon_handle_unmap(struct wl_listener *listener,
void *data) {
struct roots_drag_icon *icon =
wl_container_of(listener, icon, unmap);
roots_drag_icon_damage_whole(icon);
}
static void roots_drag_icon_handle_destroy(struct wl_listener *listener, static void roots_drag_icon_handle_destroy(struct wl_listener *listener,
void *data) { void *data) {
struct roots_drag_icon *icon = struct roots_drag_icon *icon =
@ -278,7 +285,7 @@ static void roots_drag_icon_handle_destroy(struct wl_listener *listener,
wl_list_remove(&icon->link); wl_list_remove(&icon->link);
wl_list_remove(&icon->surface_commit.link); wl_list_remove(&icon->surface_commit.link);
wl_list_remove(&icon->map.link); wl_list_remove(&icon->unmap.link);
wl_list_remove(&icon->destroy.link); wl_list_remove(&icon->destroy.link);
free(icon); free(icon);
} }
@ -297,12 +304,16 @@ static void roots_seat_handle_new_drag_icon(struct wl_listener *listener,
icon->surface_commit.notify = roots_drag_icon_handle_surface_commit; icon->surface_commit.notify = roots_drag_icon_handle_surface_commit;
wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit); wl_signal_add(&wlr_drag_icon->surface->events.commit, &icon->surface_commit);
icon->unmap.notify = roots_drag_icon_handle_unmap;
wl_signal_add(&wlr_drag_icon->events.unmap, &icon->unmap);
icon->map.notify = roots_drag_icon_handle_map; icon->map.notify = roots_drag_icon_handle_map;
wl_signal_add(&wlr_drag_icon->events.map, &icon->map); wl_signal_add(&wlr_drag_icon->events.map, &icon->map);
icon->destroy.notify = roots_drag_icon_handle_destroy; icon->destroy.notify = roots_drag_icon_handle_destroy;
wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy); wl_signal_add(&wlr_drag_icon->events.destroy, &icon->destroy);
wl_list_insert(&seat->drag_icons, &icon->link); wl_list_insert(&seat->drag_icons, &icon->link);
roots_drag_icon_update_position(icon);
} }
void roots_drag_icon_update_position(struct roots_drag_icon *icon) { void roots_drag_icon_update_position(struct roots_drag_icon *icon) {

View File

@ -98,6 +98,16 @@ static void drag_set_focus(struct wlr_drag *drag,
wlr_signal_emit_safe(&drag->events.focus, drag); wlr_signal_emit_safe(&drag->events.focus, drag);
} }
static void drag_icon_set_mapped(struct wlr_drag_icon *icon, bool mapped) {
if (mapped && !icon->mapped) {
icon->mapped = true;
wlr_signal_emit_safe(&icon->events.map, icon);
} else if (!mapped && icon->mapped) {
icon->mapped = false;
wlr_signal_emit_safe(&icon->events.unmap, icon);
}
}
static void drag_end(struct wlr_drag *drag) { static void drag_end(struct wlr_drag *drag) {
if (!drag->cancelling) { if (!drag->cancelling) {
drag->cancelling = true; drag->cancelling = true;
@ -115,9 +125,8 @@ static void drag_end(struct wlr_drag *drag) {
drag_set_focus(drag, NULL, 0, 0); drag_set_focus(drag, NULL, 0, 0);
if (drag->icon) { if (drag->icon) {
drag->icon->mapped = false;
wl_list_remove(&drag->icon_destroy.link); wl_list_remove(&drag->icon_destroy.link);
wlr_signal_emit_safe(&drag->icon->events.map, drag->icon); drag_icon_set_mapped(drag->icon, false);
} }
wlr_signal_emit_safe(&drag->events.destroy, drag); wlr_signal_emit_safe(&drag->events.destroy, drag);
@ -310,9 +319,10 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener,
static void drag_icon_destroy(struct wlr_drag_icon *icon) { static void drag_icon_destroy(struct wlr_drag_icon *icon) {
if (!icon) { if (icon == NULL) {
return; return;
} }
drag_icon_set_mapped(icon, false);
wlr_signal_emit_safe(&icon->events.destroy, icon); wlr_signal_emit_safe(&icon->events.destroy, icon);
wlr_surface_set_role_committed(icon->surface, NULL, NULL); wlr_surface_set_role_committed(icon->surface, NULL, NULL);
wl_list_remove(&icon->surface_destroy.link); wl_list_remove(&icon->surface_destroy.link);
@ -333,6 +343,8 @@ static void drag_icon_handle_surface_commit(struct wlr_surface *surface,
struct wlr_drag_icon *icon = role_data; struct wlr_drag_icon *icon = role_data;
icon->sx += icon->surface->current->sx; icon->sx += icon->surface->current->sx;
icon->sy += icon->surface->current->sy; icon->sy += icon->surface->current->sy;
drag_icon_set_mapped(icon, wlr_surface_has_buffer(surface));
} }
static void drag_icon_handle_seat_client_destroy(struct wl_listener *listener, static void drag_icon_handle_seat_client_destroy(struct wl_listener *listener,
@ -355,9 +367,9 @@ static struct wlr_drag_icon *drag_icon_create(
icon->client = client; icon->client = client;
icon->is_pointer = is_pointer; icon->is_pointer = is_pointer;
icon->touch_id = touch_id; icon->touch_id = touch_id;
icon->mapped = true;
wl_signal_init(&icon->events.map); wl_signal_init(&icon->events.map);
wl_signal_init(&icon->events.unmap);
wl_signal_init(&icon->events.destroy); wl_signal_init(&icon->events.destroy);
wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy); wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy);
@ -372,6 +384,10 @@ static struct wlr_drag_icon *drag_icon_create(
wl_list_insert(&client->seat->drag_icons, &icon->link); wl_list_insert(&client->seat->drag_icons, &icon->link);
wlr_signal_emit_safe(&client->seat->events.new_drag_icon, icon); wlr_signal_emit_safe(&client->seat->events.new_drag_icon, icon);
if (wlr_surface_has_buffer(icon_surface)) {
drag_icon_set_mapped(icon, true);
}
return icon; return icon;
} }