8#define _POSIX_C_SOURCE 200112L
13#include "protocols/wlr-foreign-toplevel-management-unstable-v1-client-header.h"
20struct wl_list toplevel_list;
25 if (!(pending->state & TOPLEVEL_STATE_INVALID)) {
26 current->state = pending->state;
29 pending->state = TOPLEVEL_STATE_INVALID;
32static uint32_t global_id = 0;
34static void toplevel_handle_output_enter(
void *data,
35 struct zwlr_foreign_toplevel_handle_v1 *zwlr_toplevel,
36 struct wl_output *wl_output)
48static void toplevel_handle_output_leave(
void *data,
49 struct zwlr_foreign_toplevel_handle_v1 *zwlr_toplevel,
50 struct wl_output *wl_output)
58 wl_list_for_each_safe(pos, tmp, &toplevel->output_list, link){
59 if (pos->dunst_output->name ==
output->name) {
60 wl_list_remove(&pos->link);
65static uint32_t array_to_state(
struct wl_array *array) {
68 wl_array_for_each(
entry, array) {
69 if (*
entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED)
70 state |= TOPLEVEL_STATE_ACTIVATED;
71 if (*
entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN)
72 state |= TOPLEVEL_STATE_FULLSCREEN;
78static void toplevel_handle_state(
void *data,
79 struct zwlr_foreign_toplevel_handle_v1 *zwlr_toplevel,
80 struct wl_array *state)
85 toplevel->pending.state = array_to_state(state);
88static void toplevel_handle_done(
void *data,
89 struct zwlr_foreign_toplevel_handle_v1 *zwlr_toplevel)
94 bool was_fullscreen = wl_have_fullscreen_window();
95 copy_state(&toplevel->current, &toplevel->pending);
96 bool is_fullscreen = wl_have_fullscreen_window();
98 if (was_fullscreen != is_fullscreen) {
103static void toplevel_handle_closed(
void *data,
104 struct zwlr_foreign_toplevel_handle_v1 *zwlr_toplevel)
108 wl_list_remove(&toplevel->link);
110 wl_list_for_each_safe(pos, tmp, &toplevel->output_list, link){
114 zwlr_foreign_toplevel_handle_v1_destroy(zwlr_toplevel);
117static void toplevel_handle_title(
void *data,
118 struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel,
122 (void)zwlr_foreign_toplevel;
126static void toplevel_handle_app_id(
void *data,
127 struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel,
131 (void)zwlr_foreign_toplevel;
135static const struct zwlr_foreign_toplevel_handle_v1_listener toplevel_impl = {
136 .title = toplevel_handle_title,
137 .app_id = toplevel_handle_app_id,
138 .output_enter = toplevel_handle_output_enter,
139 .output_leave = toplevel_handle_output_leave,
140 .state = toplevel_handle_state,
141 .done = toplevel_handle_done,
142 .closed = toplevel_handle_closed,
145static void toplevel_manager_handle_toplevel(
void *data,
146 struct zwlr_foreign_toplevel_manager_v1 *toplevel_manager,
147 struct zwlr_foreign_toplevel_handle_v1 *zwlr_toplevel)
150 (void)toplevel_manager;
154 fprintf(stderr,
"Failed to allocate memory for toplevel\n");
158 toplevel->id = global_id++;
159 toplevel->zwlr_toplevel = zwlr_toplevel;
160 wl_list_insert(&toplevel_list, &toplevel->link);
161 wl_list_init(&toplevel->output_list);
163 zwlr_foreign_toplevel_handle_v1_add_listener(zwlr_toplevel, &toplevel_impl,
167static void toplevel_manager_handle_finished(
void *data,
168 struct zwlr_foreign_toplevel_manager_v1 *toplevel_manager)
171 zwlr_foreign_toplevel_manager_v1_destroy(toplevel_manager);
174const struct zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_impl = {
175 .toplevel = toplevel_manager_handle_toplevel,
176 .finished = toplevel_manager_handle_finished,
Wayland foreign toplevel support.
Wayland window managment.