aboutsummaryrefslogtreecommitdiff
path: root/examples/compositor.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/compositor.c')
-rw-r--r--examples/compositor.c127
1 files changed, 124 insertions, 3 deletions
diff --git a/examples/compositor.c b/examples/compositor.c
index 995c1b7d..fb5d8dfd 100644
--- a/examples/compositor.c
+++ b/examples/compositor.c
@@ -56,6 +56,19 @@ struct sample_state {
struct wl_listener cursor_motion_absolute;
struct wl_listener cursor_button;
struct wl_listener cursor_axis;
+
+ struct wl_listener new_xdg_surface_v6;
+};
+
+struct example_xdg_surface_v6 {
+ struct wlr_xdg_surface_v6 *surface;
+
+ struct wl_listener destroy_listener;
+ struct wl_listener ping_timeout_listener;
+ struct wl_listener request_minimize_listener;
+ struct wl_listener request_move_listener;
+ struct wl_listener request_resize_listener;
+ struct wl_listener request_show_window_menu_listener;
};
/*
@@ -85,6 +98,103 @@ static void output_frame_handle_surface(struct sample_state *sample,
}
}
}
+
+static void handle_xdg_surface_v6_ping_timeout(struct wl_listener *listener,
+ void *data) {
+ struct wlr_xdg_surface_v6 *surface = data;
+ wlr_log(L_DEBUG, "got ping timeout for surface: %s", surface->title);
+}
+
+static void handle_xdg_surface_v6_destroy(struct wl_listener *listener,
+ void *data) {
+ struct example_xdg_surface_v6 *example_surface =
+ wl_container_of(listener, example_surface, destroy_listener);
+ wl_list_remove(&example_surface->destroy_listener.link);
+ wl_list_remove(&example_surface->ping_timeout_listener.link);
+ wl_list_remove(&example_surface->request_move_listener.link);
+ wl_list_remove(&example_surface->request_resize_listener.link);
+ wl_list_remove(&example_surface->request_show_window_menu_listener.link);
+ wl_list_remove(&example_surface->request_minimize_listener.link);
+ free(example_surface);
+}
+
+static void handle_xdg_surface_v6_request_move(struct wl_listener *listener,
+ void *data) {
+ struct example_xdg_surface_v6 *example_surface =
+ wl_container_of(listener, example_surface, request_move_listener);
+ struct wlr_xdg_toplevel_v6_move_event *e = data;
+ wlr_log(L_DEBUG, "TODO: surface requested move: %s", e->surface->title);
+}
+
+static void handle_xdg_surface_v6_request_resize(struct wl_listener *listener,
+ void *data) {
+ struct example_xdg_surface_v6 *example_surface =
+ wl_container_of(listener, example_surface, request_resize_listener);
+ struct wlr_xdg_toplevel_v6_resize_event *e = data;
+ wlr_log(L_DEBUG, "TODO: surface requested resize: %s", e->surface->title);
+}
+
+static void handle_xdg_surface_v6_request_show_window_menu(
+ struct wl_listener *listener, void *data) {
+ struct example_xdg_surface_v6 *example_surface =
+ wl_container_of(listener, example_surface,
+ request_show_window_menu_listener);
+ struct wlr_xdg_toplevel_v6_show_window_menu_event *e = data;
+ wlr_log(L_DEBUG, "TODO: surface requested to show window menu: %s",
+ e->surface->title);
+}
+
+static void handle_xdg_surface_v6_request_minimize(
+ struct wl_listener *listener, void *data) {
+ struct example_xdg_surface_v6 *example_surface =
+ wl_container_of(listener, example_surface, request_minimize_listener);
+ wlr_log(L_DEBUG, "TODO: surface requested to be minimized: %s",
+ example_surface->surface->title);
+}
+
+static void handle_new_xdg_surface_v6(struct wl_listener *listener,
+ void *data) {
+ struct wlr_xdg_surface_v6 *surface = data;
+ wlr_log(L_DEBUG, "new xdg surface: title=%s, app_id=%s",
+ surface->title, surface->app_id);
+
+ wlr_xdg_surface_v6_ping(surface);
+
+ struct example_xdg_surface_v6 *esurface =
+ calloc(1, sizeof(struct example_xdg_surface_v6));
+ if (esurface == NULL) {
+ return;
+ }
+
+ esurface->surface = surface;
+
+ wl_signal_add(&surface->events.destroy, &esurface->destroy_listener);
+ esurface->destroy_listener.notify = handle_xdg_surface_v6_destroy;
+
+ wl_signal_add(&surface->events.ping_timeout,
+ &esurface->ping_timeout_listener);
+ esurface->ping_timeout_listener.notify = handle_xdg_surface_v6_ping_timeout;
+
+ wl_signal_add(&surface->events.request_move,
+ &esurface->request_move_listener);
+ esurface->request_move_listener.notify = handle_xdg_surface_v6_request_move;
+
+ wl_signal_add(&surface->events.request_resize,
+ &esurface->request_resize_listener);
+ esurface->request_resize_listener.notify =
+ handle_xdg_surface_v6_request_resize;
+
+ wl_signal_add(&surface->events.request_show_window_menu,
+ &esurface->request_show_window_menu_listener);
+ esurface->request_show_window_menu_listener.notify =
+ handle_xdg_surface_v6_request_show_window_menu;
+
+ wl_signal_add(&surface->events.request_minimize,
+ &esurface->request_minimize_listener);
+ esurface->request_minimize_listener.notify =
+ handle_xdg_surface_v6_request_minimize;
+}
+
static void handle_output_frame(struct output_state *output,
struct timespec *ts) {
struct compositor_state *state = output->compositor;
@@ -100,9 +210,12 @@ static void handle_output_frame(struct output_state *output,
wl_shell_surface->surface);
}
struct wlr_xdg_surface_v6 *xdg_surface;
- wl_list_for_each(xdg_surface, &sample->xdg_shell->surfaces, link) {
- output_frame_handle_surface(sample, wlr_output, ts,
- xdg_surface->surface);
+ struct wlr_xdg_client_v6 *xdg_client;
+ wl_list_for_each(xdg_client, &sample->xdg_shell->clients, link) {
+ wl_list_for_each(xdg_surface, &xdg_client->surfaces, link) {
+ output_frame_handle_surface(sample, wlr_output, ts,
+ xdg_surface->surface->resource);
+ }
}
struct wlr_x11_window *x11_window;
wl_list_for_each(x11_window, &sample->xwayland->displayable_windows, link) {
@@ -309,6 +422,12 @@ int main(int argc, char *argv[]) {
state.wl_shell = wlr_wl_shell_create(compositor.display);
state.xdg_shell = wlr_xdg_shell_v6_create(compositor.display);
+ // shell events
+ wl_signal_add(&state.xdg_shell->events.new_surface,
+ &state.new_xdg_surface_v6);
+ state.new_xdg_surface_v6.notify = handle_new_xdg_surface_v6;
+
+
state.data_device_manager =
wlr_data_device_manager_create(compositor.display);
@@ -341,6 +460,8 @@ int main(int argc, char *argv[]) {
wl_display_run(compositor.display);
+ wl_list_remove(&state.new_xdg_surface_v6.link);
+
wlr_xwayland_destroy(state.xwayland);
close(state.keymap_fd);
wlr_seat_destroy(state.wl_seat);