|
|
@ -1,6 +1,7 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright © 2011 Benjamin Franzke |
|
|
|
* Copyright © 2011 Benjamin Franzke |
|
|
|
* Copyright © 2010, 2013 Intel Corporation |
|
|
|
* Copyright © 2010, 2013 Intel Corporation |
|
|
|
|
|
|
|
* Copyright © 2021 Collabora, Ltd. |
|
|
|
* |
|
|
|
* |
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a |
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a |
|
|
|
* copy of this software and associated documentation files (the "Software"), |
|
|
|
* copy of this software and associated documentation files (the "Software"), |
|
|
@ -44,6 +45,10 @@ |
|
|
|
#include "shared/xalloc.h" |
|
|
|
#include "shared/xalloc.h" |
|
|
|
#include <libweston/zalloc.h> |
|
|
|
#include <libweston/zalloc.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "xdg-shell-client-protocol.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int running = 1; |
|
|
|
|
|
|
|
|
|
|
|
struct device { |
|
|
|
struct device { |
|
|
|
enum { KEYBOARD, POINTER } type; |
|
|
|
enum { KEYBOARD, POINTER } type; |
|
|
|
|
|
|
|
|
|
|
@ -61,9 +66,9 @@ struct display { |
|
|
|
struct wl_display *display; |
|
|
|
struct wl_display *display; |
|
|
|
struct wl_registry *registry; |
|
|
|
struct wl_registry *registry; |
|
|
|
struct wl_compositor *compositor; |
|
|
|
struct wl_compositor *compositor; |
|
|
|
struct wl_shell *shell; |
|
|
|
|
|
|
|
struct wl_seat *seat; |
|
|
|
struct wl_seat *seat; |
|
|
|
struct wl_shm *shm; |
|
|
|
struct wl_shm *shm; |
|
|
|
|
|
|
|
struct xdg_wm_base *wm_base; |
|
|
|
uint32_t formats; |
|
|
|
uint32_t formats; |
|
|
|
struct wl_list devices; |
|
|
|
struct wl_list devices; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -72,7 +77,9 @@ struct window { |
|
|
|
struct display *display; |
|
|
|
struct display *display; |
|
|
|
int width, height; |
|
|
|
int width, height; |
|
|
|
struct wl_surface *surface; |
|
|
|
struct wl_surface *surface; |
|
|
|
struct wl_shell_surface *shell_surface; |
|
|
|
struct xdg_toplevel *xdg_toplevel; |
|
|
|
|
|
|
|
struct xdg_surface *xdg_surface; |
|
|
|
|
|
|
|
bool wait_for_configure; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
@ -116,27 +123,54 @@ attach_buffer(struct window *window, int width, int height) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
|
handle_ping(void *data, struct wl_shell_surface *shell_surface, |
|
|
|
handle_xdg_surface_configure(void *data, struct xdg_surface *surface, |
|
|
|
uint32_t serial) |
|
|
|
uint32_t serial) |
|
|
|
{ |
|
|
|
{ |
|
|
|
wl_shell_surface_pong(shell_surface, serial); |
|
|
|
struct window *window = data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xdg_surface_ack_configure(surface, serial); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (window->wait_for_configure) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attach_buffer(window, window->width, window->height); |
|
|
|
|
|
|
|
wl_surface_damage(window->surface, 0, 0, window->width, window->height); |
|
|
|
|
|
|
|
wl_surface_commit(window->surface); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window->wait_for_configure = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct xdg_surface_listener xdg_surface_listener = { |
|
|
|
|
|
|
|
handle_xdg_surface_configure, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
|
handle_configure(void *data, struct wl_shell_surface *shell_surface, |
|
|
|
xdg_wm_base_ping(void *data, struct xdg_wm_base *shell, uint32_t serial) |
|
|
|
uint32_t edges, int32_t width, int32_t height) |
|
|
|
{ |
|
|
|
|
|
|
|
xdg_wm_base_pong(shell, serial); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct xdg_wm_base_listener wm_base_listener = { |
|
|
|
|
|
|
|
xdg_wm_base_ping, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
|
|
|
handle_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, |
|
|
|
|
|
|
|
int32_t width, int32_t height, |
|
|
|
|
|
|
|
struct wl_array *state) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
|
handle_popup_done(void *data, struct wl_shell_surface *shell_surface) |
|
|
|
handle_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
running = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static const struct wl_shell_surface_listener shell_surface_listener = { |
|
|
|
static const struct xdg_toplevel_listener xdg_toplevel_listener = { |
|
|
|
handle_ping, |
|
|
|
handle_toplevel_configure, |
|
|
|
handle_configure, |
|
|
|
handle_toplevel_close, |
|
|
|
handle_popup_done |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static struct window * |
|
|
|
static struct window * |
|
|
@ -149,19 +183,19 @@ create_window(struct display *display, int width, int height) |
|
|
|
window->width = width; |
|
|
|
window->width = width; |
|
|
|
window->height = height; |
|
|
|
window->height = height; |
|
|
|
window->surface = wl_compositor_create_surface(display->compositor); |
|
|
|
window->surface = wl_compositor_create_surface(display->compositor); |
|
|
|
window->shell_surface = wl_shell_get_shell_surface(display->shell, |
|
|
|
|
|
|
|
window->surface); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (window->shell_surface) |
|
|
|
window->xdg_surface = |
|
|
|
wl_shell_surface_add_listener(window->shell_surface, |
|
|
|
xdg_wm_base_get_xdg_surface(display->wm_base, window->surface); |
|
|
|
&shell_surface_listener, window); |
|
|
|
assert(window->xdg_surface); |
|
|
|
|
|
|
|
|
|
|
|
wl_shell_surface_set_title(window->shell_surface, "simple-shm"); |
|
|
|
xdg_surface_add_listener(window->xdg_surface, &xdg_surface_listener, window); |
|
|
|
|
|
|
|
|
|
|
|
wl_shell_surface_set_toplevel(window->shell_surface); |
|
|
|
window->xdg_toplevel = xdg_surface_get_toplevel(window->xdg_surface); |
|
|
|
|
|
|
|
assert(window->xdg_toplevel); |
|
|
|
wl_surface_damage(window->surface, 0, 0, width, height); |
|
|
|
xdg_toplevel_add_listener(window->xdg_toplevel, |
|
|
|
attach_buffer(window, width, height); |
|
|
|
&xdg_toplevel_listener, window); |
|
|
|
|
|
|
|
xdg_toplevel_set_title(window->xdg_toplevel, "multi-resource"); |
|
|
|
|
|
|
|
window->wait_for_configure = true; |
|
|
|
wl_surface_commit(window->surface); |
|
|
|
wl_surface_commit(window->surface); |
|
|
|
|
|
|
|
|
|
|
|
return window; |
|
|
|
return window; |
|
|
@ -170,7 +204,11 @@ create_window(struct display *display, int width, int height) |
|
|
|
static void |
|
|
|
static void |
|
|
|
destroy_window(struct window *window) |
|
|
|
destroy_window(struct window *window) |
|
|
|
{ |
|
|
|
{ |
|
|
|
wl_shell_surface_destroy(window->shell_surface); |
|
|
|
if (window->xdg_surface) |
|
|
|
|
|
|
|
xdg_surface_destroy(window->xdg_surface); |
|
|
|
|
|
|
|
if (window->xdg_toplevel) |
|
|
|
|
|
|
|
xdg_toplevel_destroy(window->xdg_toplevel); |
|
|
|
|
|
|
|
|
|
|
|
wl_surface_destroy(window->surface); |
|
|
|
wl_surface_destroy(window->surface); |
|
|
|
free(window); |
|
|
|
free(window); |
|
|
|
} |
|
|
|
} |
|
|
@ -197,9 +235,10 @@ registry_handle_global(void *data, struct wl_registry *registry, |
|
|
|
d->compositor = |
|
|
|
d->compositor = |
|
|
|
wl_registry_bind(registry, |
|
|
|
wl_registry_bind(registry, |
|
|
|
id, &wl_compositor_interface, 1); |
|
|
|
id, &wl_compositor_interface, 1); |
|
|
|
} else if (strcmp(interface, "wl_shell") == 0) { |
|
|
|
} else if (strcmp(interface, "xdg_wm_base") == 0) { |
|
|
|
d->shell = wl_registry_bind(registry, |
|
|
|
d->wm_base = wl_registry_bind(registry, |
|
|
|
id, &wl_shell_interface, 1); |
|
|
|
id, &xdg_wm_base_interface, 1); |
|
|
|
|
|
|
|
xdg_wm_base_add_listener(d->wm_base, &wm_base_listener, d); |
|
|
|
} else if (strcmp(interface, "wl_shm") == 0) { |
|
|
|
} else if (strcmp(interface, "wl_shm") == 0) { |
|
|
|
d->shm = wl_registry_bind(registry, |
|
|
|
d->shm = wl_registry_bind(registry, |
|
|
|
id, &wl_shm_interface, 1); |
|
|
|
id, &wl_shm_interface, 1); |
|
|
@ -248,6 +287,11 @@ create_display(void) |
|
|
|
exit(1); |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!display->wm_base) { |
|
|
|
|
|
|
|
fprintf(stderr, "xdg-shell required!\n"); |
|
|
|
|
|
|
|
exit(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wl_list_init(&display->devices); |
|
|
|
wl_list_init(&display->devices); |
|
|
|
|
|
|
|
|
|
|
|
return display; |
|
|
|
return display; |
|
|
@ -399,8 +443,8 @@ destroy_display(struct display *display) |
|
|
|
if (display->shm) |
|
|
|
if (display->shm) |
|
|
|
wl_shm_destroy(display->shm); |
|
|
|
wl_shm_destroy(display->shm); |
|
|
|
|
|
|
|
|
|
|
|
if (display->shell) |
|
|
|
if (display->wm_base) |
|
|
|
wl_shell_destroy(display->shell); |
|
|
|
xdg_wm_base_destroy(display->wm_base); |
|
|
|
|
|
|
|
|
|
|
|
if (display->seat) |
|
|
|
if (display->seat) |
|
|
|
wl_seat_destroy(display->seat); |
|
|
|
wl_seat_destroy(display->seat); |
|
|
@ -414,7 +458,6 @@ destroy_display(struct display *display) |
|
|
|
free(display); |
|
|
|
free(display); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int running = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
static void |
|
|
|
signal_int(int signum) |
|
|
|
signal_int(int signum) |
|
|
|