mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-21 20:35:58 +01:00
drag: use unified map logic
This commit is contained in:
parent
743da5c0ae
commit
af4181f388
3 changed files with 17 additions and 32 deletions
|
@ -93,11 +93,8 @@ struct wlr_drag;
|
|||
struct wlr_drag_icon {
|
||||
struct wlr_drag *drag;
|
||||
struct wlr_surface *surface;
|
||||
bool mapped;
|
||||
|
||||
struct {
|
||||
struct wl_signal map;
|
||||
struct wl_signal unmap;
|
||||
struct wl_signal destroy;
|
||||
} events;
|
||||
|
||||
|
|
|
@ -106,16 +106,6 @@ out:
|
|||
wl_signal_emit_mutable(&drag->events.focus, drag);
|
||||
}
|
||||
|
||||
static void drag_icon_set_mapped(struct wlr_drag_icon *icon, bool mapped) {
|
||||
if (mapped && !icon->mapped) {
|
||||
icon->mapped = true;
|
||||
wl_signal_emit_mutable(&icon->events.map, icon);
|
||||
} else if (!mapped && icon->mapped) {
|
||||
icon->mapped = false;
|
||||
wl_signal_emit_mutable(&icon->events.unmap, icon);
|
||||
}
|
||||
}
|
||||
|
||||
static void drag_destroy(struct wlr_drag *drag) {
|
||||
if (drag->cancelling) {
|
||||
return;
|
||||
|
@ -359,16 +349,16 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener,
|
|||
|
||||
static void drag_icon_surface_role_commit(struct wlr_surface *surface) {
|
||||
assert(surface->role == &drag_icon_surface_role);
|
||||
struct wlr_drag_icon *icon = surface->role_data;
|
||||
|
||||
drag_icon_set_mapped(icon, wlr_surface_has_buffer(surface));
|
||||
if (wlr_surface_has_buffer(surface)) {
|
||||
wlr_surface_map(surface);
|
||||
}
|
||||
}
|
||||
|
||||
static void drag_icon_surface_role_destroy(struct wlr_surface *surface) {
|
||||
assert(surface->role == &drag_icon_surface_role);
|
||||
struct wlr_drag_icon *icon = surface->role_data;
|
||||
|
||||
drag_icon_set_mapped(icon, false);
|
||||
wl_signal_emit_mutable(&icon->events.destroy, icon);
|
||||
free(icon);
|
||||
}
|
||||
|
@ -389,14 +379,12 @@ static struct wlr_drag_icon *drag_icon_create(struct wlr_drag *drag,
|
|||
icon->drag = drag;
|
||||
icon->surface = surface;
|
||||
|
||||
wl_signal_init(&icon->events.map);
|
||||
wl_signal_init(&icon->events.unmap);
|
||||
wl_signal_init(&icon->events.destroy);
|
||||
|
||||
icon->surface->role_data = icon;
|
||||
|
||||
if (wlr_surface_has_buffer(surface)) {
|
||||
drag_icon_set_mapped(icon, true);
|
||||
wlr_surface_map(surface);
|
||||
}
|
||||
|
||||
return icon;
|
||||
|
|
|
@ -10,8 +10,8 @@ struct wlr_scene_drag_icon {
|
|||
|
||||
struct wl_listener tree_destroy;
|
||||
struct wl_listener drag_icon_surface_commit;
|
||||
struct wl_listener drag_icon_map;
|
||||
struct wl_listener drag_icon_unmap;
|
||||
struct wl_listener drag_icon_surface_map;
|
||||
struct wl_listener drag_icon_surface_unmap;
|
||||
struct wl_listener drag_icon_destroy;
|
||||
};
|
||||
|
||||
|
@ -24,15 +24,15 @@ static void drag_icon_handle_surface_commit(struct wl_listener *listener, void *
|
|||
node->x + surface->current.dx, node->y + surface->current.dy);
|
||||
}
|
||||
|
||||
static void drag_icon_handle_map(struct wl_listener *listener, void *data) {
|
||||
static void drag_icon_handle_surface_map(struct wl_listener *listener, void *data) {
|
||||
struct wlr_scene_drag_icon *icon =
|
||||
wl_container_of(listener, icon, drag_icon_map);
|
||||
wl_container_of(listener, icon, drag_icon_surface_map);
|
||||
wlr_scene_node_set_enabled(&icon->tree->node, true);
|
||||
}
|
||||
|
||||
static void drag_icon_handle_unmap(struct wl_listener *listener, void *data) {
|
||||
static void drag_icon_handle_surface_unmap(struct wl_listener *listener, void *data) {
|
||||
struct wlr_scene_drag_icon *icon =
|
||||
wl_container_of(listener, icon, drag_icon_unmap);
|
||||
wl_container_of(listener, icon, drag_icon_surface_unmap);
|
||||
wlr_scene_node_set_enabled(&icon->tree->node, false);
|
||||
}
|
||||
|
||||
|
@ -41,8 +41,8 @@ static void drag_icon_handle_tree_destroy(struct wl_listener *listener, void *da
|
|||
wl_container_of(listener, icon, tree_destroy);
|
||||
wl_list_remove(&icon->tree_destroy.link);
|
||||
wl_list_remove(&icon->drag_icon_surface_commit.link);
|
||||
wl_list_remove(&icon->drag_icon_map.link);
|
||||
wl_list_remove(&icon->drag_icon_unmap.link);
|
||||
wl_list_remove(&icon->drag_icon_surface_map.link);
|
||||
wl_list_remove(&icon->drag_icon_surface_unmap.link);
|
||||
wl_list_remove(&icon->drag_icon_destroy.link);
|
||||
free(icon);
|
||||
}
|
||||
|
@ -76,16 +76,16 @@ struct wlr_scene_tree *wlr_scene_drag_icon_create(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
wlr_scene_node_set_enabled(&icon->tree->node, drag_icon->mapped);
|
||||
wlr_scene_node_set_enabled(&icon->tree->node, drag_icon->surface->mapped);
|
||||
|
||||
icon->tree_destroy.notify = drag_icon_handle_tree_destroy;
|
||||
wl_signal_add(&icon->tree->node.events.destroy, &icon->tree_destroy);
|
||||
icon->drag_icon_surface_commit.notify = drag_icon_handle_surface_commit;
|
||||
wl_signal_add(&drag_icon->surface->events.commit, &icon->drag_icon_surface_commit);
|
||||
icon->drag_icon_map.notify = drag_icon_handle_map;
|
||||
wl_signal_add(&drag_icon->events.map, &icon->drag_icon_map);
|
||||
icon->drag_icon_unmap.notify = drag_icon_handle_unmap;
|
||||
wl_signal_add(&drag_icon->events.unmap, &icon->drag_icon_unmap);
|
||||
icon->drag_icon_surface_map.notify = drag_icon_handle_surface_map;
|
||||
wl_signal_add(&drag_icon->surface->events.map, &icon->drag_icon_surface_map);
|
||||
icon->drag_icon_surface_unmap.notify = drag_icon_handle_surface_unmap;
|
||||
wl_signal_add(&drag_icon->surface->events.unmap, &icon->drag_icon_surface_unmap);
|
||||
icon->drag_icon_destroy.notify = drag_icon_handle_destroy;
|
||||
wl_signal_add(&drag_icon->events.destroy, &icon->drag_icon_destroy);
|
||||
|
||||
|
|
Loading…
Reference in a new issue