diff options
-rw-r--r-- | backend/drm/atomic.c | 12 | ||||
-rw-r--r-- | backend/drm/drm.c | 46 | ||||
-rw-r--r-- | examples/gamma-control.c | 195 | ||||
-rw-r--r-- | examples/meson.build | 12 | ||||
-rw-r--r-- | examples/toplevel-decoration.c | 253 | ||||
-rw-r--r-- | include/rootston/desktop.h | 15 | ||||
-rw-r--r-- | include/rootston/view.h | 9 | ||||
-rw-r--r-- | include/wlr/interfaces/wlr_output.h | 2 | ||||
-rw-r--r-- | include/wlr/types/wlr_gamma_control_v1.h | 31 | ||||
-rw-r--r-- | include/wlr/types/wlr_output.h | 14 | ||||
-rw-r--r-- | include/wlr/types/wlr_xdg_decoration_v1.h | 68 | ||||
-rw-r--r-- | include/wlr/types/wlr_xdg_shell.h | 18 | ||||
-rw-r--r-- | include/wlr/xwayland.h | 8 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | protocol/meson.build | 10 | ||||
-rw-r--r-- | protocol/wlr-gamma-control-unstable-v1.xml | 126 | ||||
-rw-r--r-- | rootston/desktop.c | 26 | ||||
-rw-r--r-- | rootston/xdg_shell.c | 70 | ||||
-rw-r--r-- | types/meson.build | 2 | ||||
-rw-r--r-- | types/wlr_gamma_control.c | 4 | ||||
-rw-r--r-- | types/wlr_gamma_control_v1.c | 264 | ||||
-rw-r--r-- | types/wlr_output.c | 9 | ||||
-rw-r--r-- | types/wlr_xdg_decoration_v1.c | 302 | ||||
-rw-r--r-- | types/xdg_shell/wlr_xdg_surface.c | 45 | ||||
-rw-r--r-- | types/xdg_shell/wlr_xdg_toplevel.c | 32 |
25 files changed, 1509 insertions, 66 deletions
diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c index 61d2f6e1..40a272a1 100644 --- a/backend/drm/atomic.c +++ b/backend/drm/atomic.c @@ -199,14 +199,18 @@ static bool atomic_crtc_move_cursor(struct wlr_drm_backend *drm, static bool atomic_crtc_set_gamma(struct wlr_drm_backend *drm, struct wlr_drm_crtc *crtc, uint16_t *r, uint16_t *g, uint16_t *b, uint32_t size) { - struct drm_color_lut gamma[size]; - // Fallback to legacy gamma interface when gamma properties are not available // (can happen on older intel gpu's that support gamma but not degamma) if (crtc->props.gamma_lut == 0) { return legacy_iface.crtc_set_gamma(drm, crtc, r, g, b, size); } + struct drm_color_lut *gamma = malloc(size * sizeof(struct drm_color_lut)); + if (gamma == NULL) { + wlr_log(WLR_ERROR, "Failed to allocate gamma table"); + return false; + } + for (uint32_t i = 0; i < size; i++) { gamma[i].red = r[i]; gamma[i].green = g[i]; @@ -218,10 +222,12 @@ static bool atomic_crtc_set_gamma(struct wlr_drm_backend *drm, } if (drmModeCreatePropertyBlob(drm->fd, gamma, - sizeof(struct drm_color_lut) * size, &crtc->gamma_lut)) { + size * sizeof(struct drm_color_lut), &crtc->gamma_lut)) { + free(gamma); wlr_log_errno(WLR_ERROR, "Unable to create property blob"); return false; } + free(gamma); struct atomic atom; atomic_begin(crtc, &atom); diff --git a/backend/drm/drm.c b/backend/drm/drm.c index c4674235..9d030dff 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -228,30 +228,54 @@ static bool drm_connector_swap_buffers(struct wlr_output *output, return true; } -static void drm_connector_set_gamma(struct wlr_output *output, - uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { +static void fill_empty_gamma_table(uint32_t size, + uint16_t *r, uint16_t *g, uint16_t *b) { + for (uint32_t i = 0; i < size; ++i) { + uint16_t val = (uint32_t)0xffff * i / (size - 1); + r[i] = g[i] = b[i] = val; + } +} + +static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; - bool ok; if (conn->crtc) { - ok = drm->iface->crtc_set_gamma(drm, conn->crtc, r, g, b, size); - if (ok) { - wlr_output_update_needs_swap(output); - } + return drm->iface->crtc_get_gamma_size(drm, conn->crtc); } + return 0; } -static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) { +static bool drm_connector_set_gamma(struct wlr_output *output, + uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; - if (conn->crtc) { - return drm->iface->crtc_get_gamma_size(drm, conn->crtc); + if (!conn->crtc) { + return false; } - return 0; + uint16_t *reset_table = NULL; + if (size == 0) { + size = drm_connector_get_gamma_size(output); + reset_table = malloc(3 * size * sizeof(uint16_t)); + if (reset_table == NULL) { + wlr_log(WLR_ERROR, "Failed to allocate gamma table"); + return false; + } + r = reset_table; + g = reset_table + size; + b = reset_table + 2 * size; + fill_empty_gamma_table(size, r, g, b); + } + + bool ok = drm->iface->crtc_set_gamma(drm, conn->crtc, r, g, b, size); + if (ok) { + wlr_output_update_needs_swap(output); + } + free(reset_table); + return ok; } static bool drm_connector_export_dmabuf(struct wlr_output *output, diff --git a/examples/gamma-control.c b/examples/gamma-control.c new file mode 100644 index 00000000..a060b883 --- /dev/null +++ b/examples/gamma-control.c @@ -0,0 +1,195 @@ +#define _POSIX_C_SOURCE 200809L +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/types.h> +#include <unistd.h> +#include <wayland-client-protocol.h> +#include <wayland-client.h> +#include "wlr-gamma-control-unstable-v1-client-protocol.h" + +struct output { + struct wl_output *wl_output; + struct zwlr_gamma_control_v1 *gamma_control; + uint32_t ramp_size; + int table_fd; + uint16_t *table; + struct wl_list link; +}; + +static struct wl_list outputs; +static struct zwlr_gamma_control_manager_v1 *gamma_control_manager = NULL; + +static int create_anonymous_file(off_t size) { + char template[] = "/tmp/wlroots-shared-XXXXXX"; + int fd = mkstemp(template); + if (fd < 0) { + return -1; + } + + int ret; + do { + errno = 0; + ret = ftruncate(fd, size); + } while (errno == EINTR); + if (ret < 0) { + close(fd); + return -1; + } + + unlink(template); + return fd; +} + +static int create_gamma_table(uint32_t ramp_size, uint16_t **table) { + size_t table_size = ramp_size * 3 * sizeof(uint16_t); + int fd = create_anonymous_file(table_size); + if (fd < 0) { + fprintf(stderr, "failed to create anonymous file\n"); + return -1; + } + + void *data = + mmap(NULL, table_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (data == MAP_FAILED) { + fprintf(stderr, "failed to mmap()\n"); + close(fd); + return -1; + } + + *table = data; + return fd; +} + +static void gamma_control_handle_gamma_size(void *data, + struct zwlr_gamma_control_v1 *gamma_control, uint32_t ramp_size) { + struct output *output = data; + output->ramp_size = ramp_size; + output->table_fd = create_gamma_table(ramp_size, &output->table); + if (output->table_fd < 0) { + exit(EXIT_FAILURE); + } +} + +static void gamma_control_handle_failed(void *data, + struct zwlr_gamma_control_v1 *gamma_control) { + fprintf(stderr, "failed to set gamma table\n"); + exit(EXIT_FAILURE); +} + +static const struct zwlr_gamma_control_v1_listener gamma_control_listener = { + .gamma_size = gamma_control_handle_gamma_size, + .failed = gamma_control_handle_failed, +}; + +static void registry_handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) { + if (strcmp(interface, wl_output_interface.name) == 0) { + struct output *output = calloc(1, sizeof(struct output)); + output->wl_output = wl_registry_bind(registry, name, + &wl_output_interface, 1); + wl_list_insert(&outputs, &output->link); + } else if (strcmp(interface, + zwlr_gamma_control_manager_v1_interface.name) == 0) { + gamma_control_manager = wl_registry_bind(registry, name, + &zwlr_gamma_control_manager_v1_interface, 1); + } +} + +static void registry_handle_global_remove(void *data, + struct wl_registry *registry, uint32_t name) { + // Who cares? +} + +static const struct wl_registry_listener registry_listener = { + .global = registry_handle_global, + .global_remove = registry_handle_global_remove, +}; + +static void fill_gamma_table(uint16_t *table, uint32_t ramp_size, + double contrast, double brightness, double gamma) { + uint16_t *r = table; + uint16_t *g = table + ramp_size; + uint16_t *b = table + 2 * ramp_size; + for (uint32_t i = 0; i < ramp_size; ++i) { + double val = (double)i / (ramp_size - 1); + val = contrast * pow(val, 1.0 / gamma) + (brightness - 1); + if (val > 1.0) { + val = 1.0; + } else if (val < 0.0) { + val = 0.0; + } + r[i] = g[i] = b[i] = (uint16_t)(UINT16_MAX * val); + } +} + +static const char usage[] = "usage: gamma-control [options]\n" + " -h show this help message\n" + " -c <value> set contrast (default: 1)\n" + " -b <value> set brightness (default: 1)\n" + " -g <value> set gamma (default: 1)\n"; + +int main(int argc, char *argv[]) { + wl_list_init(&outputs); + + double contrast = 1, brightness = 1, gamma = 1; + int opt; + while ((opt = getopt(argc, argv, "hc:b:g:")) != -1) { + switch (opt) { + case 'c': + contrast = strtod(optarg, NULL); + break; + case 'b': + brightness = strtod(optarg, NULL); + break; + case 'g': + gamma = strtod(optarg, NULL); + break; + case 'h': + default: + fprintf(stderr, usage); + return opt == 'h' ? EXIT_SUCCESS : EXIT_FAILURE; + } + } + + struct wl_display *display = wl_display_connect(NULL); + if (display == NULL) { + fprintf(stderr, "failed to create display\n"); + return -1; + } + + struct wl_registry *registry = wl_display_get_registry(display); + wl_registry_add_listener(registry, ®istry_listener, NULL); + wl_display_dispatch(display); + wl_display_roundtrip(display); + + if (gamma_control_manager == NULL) { + fprintf(stderr, + "compositor doesn't support wlr-gamma-control-unstable-v1\n"); + return EXIT_FAILURE; + } + + struct output *output; + wl_list_for_each(output, &outputs, link) { + output->gamma_control = zwlr_gamma_control_manager_v1_get_gamma_control( + gamma_control_manager, output->wl_output); + zwlr_gamma_control_v1_add_listener(output->gamma_control, + &gamma_control_listener, output); + } + wl_display_roundtrip(display); + + wl_list_for_each(output, &outputs, link) { + fill_gamma_table(output->table, output->ramp_size, + contrast, brightness, gamma); + zwlr_gamma_control_v1_set_gamma(output->gamma_control, + output->table_fd); + } + + while (wl_display_dispatch(display) != -1) { + // This space is intentionnally left blank + } + + return EXIT_SUCCESS; +} diff --git a/examples/meson.build b/examples/meson.build index 18f44fde..25ad7566 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -50,6 +50,12 @@ executable( dependencies: [wayland_cursor, wayland_client, wlr_protos, wlroots] ) +executable( + 'gamma-control', + 'gamma-control.c', + dependencies: [wayland_cursor, wayland_client, wlr_protos, wlroots] +) + if libavutil.found() and libavcodec.found() and libavformat.found() executable( 'dmabuf-capture', @@ -66,3 +72,9 @@ if libpng.found() dependencies: [wayland_client, wlr_protos, wlroots, libpng] ) endif + +executable( + 'toplevel-decoration', + 'toplevel-decoration.c', + dependencies: [wayland_client, wlr_protos, wlroots] +) diff --git a/examples/toplevel-decoration.c b/examples/toplevel-decoration.c new file mode 100644 index 00000000..e930c417 --- /dev/null +++ b/examples/toplevel-decoration.c @@ -0,0 +1,253 @@ +#include <GLES2/gl2.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wayland-client.h> +#include <wayland-egl.h> +#include <wlr/render/egl.h> +#include "xdg-shell-client-protocol.h" +#include "xdg-decoration-unstable-v1-client-protocol.h" + +/** + * Usage: toplevel-decoration [mode] + * Creates an xdg-toplevel supporting decoration negotiation. If `mode` is + * specified, the client will prefer this decoration mode. + */ + +static int width = 500, height = 300; + +static struct wl_compositor *compositor = NULL; +static struct xdg_wm_base *wm_base = NULL; +static struct zxdg_decoration_manager_v1 *decoration_manager = NULL; + +struct wlr_egl egl; +struct wl_egl_window *egl_window; +struct wlr_egl_surface *egl_surface; + +struct zxdg_toplevel_decoration_v1 *decoration; +enum zxdg_toplevel_decoration_v1_mode client_preferred_mode, current_mode; + +static const char *get_mode_name(enum zxdg_toplevel_decoration_v1_mode mode) { + switch (mode) { + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: + return "client-side decorations"; + case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: + return "server-side decorations"; + } + abort(); +} + +static void request_preferred_mode(void) { + enum zxdg_toplevel_decoration_v1_mode mode = client_preferred_mode; + if (mode == 0) { + printf("Requesting compositor preferred mode\n"); + zxdg_toplevel_decoration_v1_unset_mode(decoration); + return; + } + if (mode == current_mode) { + return; + } + + printf("Requesting %s\n", get_mode_name(mode)); + zxdg_toplevel_decoration_v1_set_mode(decoration, mode); +} + +static void draw(void) { + eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context); + + float color[] = {1.0, 1.0, 0.0, 1.0}; + if (current_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE) { + color[0] = 0.0; + } + + glViewport(0, 0, width, height); + glClearColor(color[0], color[1], color[2], 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + eglSwapBuffers(egl.display, egl_surface); +} + +static void xdg_surface_handle_configure(void *data, + struct xdg_surface *xdg_surface, uint32_t serial) { + xdg_surface_ack_configure(xdg_surface, serial); + wl_egl_window_resize(egl_window, width, height, 0, 0); + draw(); +} + +static const struct xdg_surface_listener xdg_surface_listener = { + .configure = xdg_surface_handle_configure, +}; + +static void xdg_toplevel_handle_configure(void *data, + struct xdg_toplevel *xdg_toplevel, int32_t w, int32_t h, + struct wl_array *states) { + width = w; + height = h; +} + +static const struct xdg_toplevel_listener xdg_toplevel_listener = { + .configure = xdg_toplevel_handle_configure, +}; + +static void decoration_handle_configure(void *data, + struct zxdg_toplevel_decoration_v1 *decoration, + enum zxdg_toplevel_decoration_v1_mode mode) { + printf("Using %s\n", get_mode_name(mode)); + current_mode = mode; +} + +static const struct zxdg_toplevel_decoration_v1_listener decoration_listener = { + .configure = decoration_handle_configure, +}; + +static void pointer_handle_enter(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface, + wl_fixed_t sx, wl_fixed_t sy) { + // No-op +} + +static void pointer_handle_leave(void *data, struct wl_pointer *pointer, + uint32_t serial, struct wl_surface *surface) { + // No-op +} + +static void pointer_handle_motion(void *data, struct wl_pointer *pointer, + uint32_t time, wl_fixed_t sx, wl_fixed_t sy) { + // No-op +} + +static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, + uint32_t serial, uint32_t time, uint32_t button, + enum wl_pointer_button_state state) { + if (state == WL_POINTER_BUTTON_STATE_PRESSED) { + // Toggle mode + if (client_preferred_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE) { + client_preferred_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; + } else { + client_preferred_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; + } + request_preferred_mode(); + } +} + +static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, + uint32_t time, enum wl_pointer_axis axis, wl_fixed_t value) { + // No-op +} + +static const struct wl_pointer_listener pointer_listener = { + .enter = pointer_handle_enter, + .leave = pointer_handle_leave, + .motion = pointer_handle_motion, + .button = pointer_handle_button, + .axis = pointer_handle_axis, +}; + +static void seat_handle_capabilities(void *data, struct wl_seat *seat, + enum wl_seat_capability caps) { + if (caps & WL_SEAT_CAPABILITY_POINTER) { + struct wl_pointer *pointer = wl_seat_get_pointer(seat); + wl_pointer_add_listener(pointer, &pointer_listener, NULL); + } +} + +static const struct wl_seat_listener seat_listener = { + .capabilities = seat_handle_capabilities, +}; + +static void handle_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) { + if (strcmp(interface, wl_compositor_interface.name) == 0) { + compositor = wl_registry_bind(registry, name, &wl_compositor_interface, + 1); + } else if (strcmp(interface, xdg_wm_base_interface.name) == 0) { + wm_base = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1); + } else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) { + decoration_manager = wl_registry_bind(registry, name, + &zxdg_decoration_manager_v1_interface, 1); + } else if (strcmp(interface, wl_seat_interface.name) == 0) { + struct wl_seat *seat = + wl_registry_bind(registry, name, &wl_seat_interface, 1); + wl_seat_add_listener(seat, &seat_listener, NULL); + } +} + +static void handle_global_remove(void *data, struct wl_registry *registry, + uint32_t name) { + // Who cares? +} + +static const struct wl_registry_listener registry_listener = { + .global = handle_global, + .global_remove = handle_global_remove, +}; + +int main(int argc, char **argv) { + if (argc == 2) { + char *mode = argv[1]; + if (strcmp(mode, "client") == 0) { + client_preferred_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; + } else if (strcmp(mode, "server") == 0) { + client_preferred_mode = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; + } else { + fprintf(stderr, "Invalid decoration mode\n"); + return EXIT_FAILURE; + } + } + + struct wl_display *display = wl_display_connect(NULL); + if (display == NULL) { + fprintf(stderr, "Failed to create display\n"); + return EXIT_FAILURE; + } + + struct wl_registry *registry = wl_display_get_registry(display); + wl_registry_add_listener(registry, ®istry_listener, NULL); + wl_display_dispatch(display); + wl_display_roundtrip(display); + + if (compositor == NULL) { + fprintf(stderr, "wl-compositor not available\n"); + return EXIT_FAILURE; + } + if (wm_base == NULL) { + fprintf(stderr, "xdg-shell not available\n"); + return EXIT_FAILURE; + } + if (decoration_manager == NULL) { + fprintf(stderr, "xdg-decoration not available\n"); + return EXIT_FAILURE; + } + + wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, + WL_SHM_FORMAT_ARGB8888); + + struct wl_surface *surface = wl_compositor_create_surface(compositor); + struct xdg_surface *xdg_surface = + xdg_wm_base_get_xdg_surface(wm_base, surface); + struct xdg_toplevel *xdg_toplevel = xdg_surface_get_toplevel(xdg_surface); + decoration = zxdg_decoration_manager_v1_get_toplevel_decoration( + decoration_manager, xdg_toplevel); + + wl_display_roundtrip(display); + request_preferred_mode(); + + xdg_surface_add_listener(xdg_surface, &xdg_surface_listener, NULL); + xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_listener, NULL); + zxdg_toplevel_decoration_v1_add_listener(decoration, &decoration_listener, + NULL); + wl_surface_commit(surface); + + egl_window = wl_egl_window_create(surface, width, height); + egl_surface = wlr_egl_create_surface(&egl, egl_window); + + wl_display_roundtrip(display); + + draw(); + + while (wl_display_dispatch(display) != -1) { + // This space is intentionally left blank + } + + return EXIT_SUCCESS; +} diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 2d28fa10..363a16f0 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -4,7 +4,9 @@ #include <wayland-server.h> #include <wlr/config.h> #include <wlr/types/wlr_compositor.h> +#include <wlr/types/wlr_gamma_control_v1.h> #include <wlr/types/wlr_gamma_control.h> +#include <wlr/types/wlr_idle_inhibit_v1.h> #include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_input_inhibitor.h> #include <wlr/types/wlr_layer_shell.h> @@ -13,17 +15,14 @@ #include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output.h> #include <wlr/types/wlr_primary_selection.h> +#include <wlr/types/wlr_screencopy_v1.h> #include <wlr/types/wlr_screenshooter.h> #include <wlr/types/wlr_virtual_keyboard_v1.h> #include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_xcursor_manager.h> +#include <wlr/types/wlr_xdg_decoration_v1.h> #include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell.h> -#include <wlr/types/wlr_list.h> -#include <wlr/types/wlr_idle.h> -#include <wlr/types/wlr_idle_inhibit_v1.h> -#include <wlr/types/wlr_screencopy_v1.h> -#include "rootston/view.h" #include "rootston/config.h" #include "rootston/output.h" #include "rootston/view.h" @@ -45,9 +44,11 @@ struct roots_desktop { struct wlr_xdg_shell_v6 *xdg_shell_v6; struct wlr_xdg_shell *xdg_shell; struct wlr_gamma_control_manager *gamma_control_manager; + struct wlr_gamma_control_manager_v1 *gamma_control_manager_v1; struct wlr_screenshooter *screenshooter; struct wlr_export_dmabuf_manager_v1 *export_dmabuf_manager_v1; struct wlr_server_decoration_manager *server_decoration_manager; + struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager; struct wlr_primary_selection_device_manager *primary_selection_device_manager; struct wlr_idle *idle; struct wlr_idle_inhibit_manager_v1 *idle_inhibit; @@ -64,7 +65,7 @@ struct roots_desktop { struct wl_listener xdg_shell_surface; struct wl_listener wl_shell_surface; struct wl_listener layer_shell_surface; - struct wl_listener decoration_new; + struct wl_listener xdg_toplevel_decoration; struct wl_listener input_inhibit_activate; struct wl_listener input_inhibit_deactivate; struct wl_listener virtual_keyboard_new; @@ -94,6 +95,7 @@ void view_apply_damage(struct roots_view *view); void view_damage_whole(struct roots_view *view); void view_update_position(struct roots_view *view, double x, double y); void view_update_size(struct roots_view *view, uint32_t width, uint32_t height); +void view_update_decorated(struct roots_view *view, bool decorated); void view_initial_focus(struct roots_view *view); void view_map(struct roots_view *view, struct wlr_surface *surface); void view_unmap(struct roots_view *view); @@ -101,6 +103,7 @@ void view_arrange_maximized(struct roots_view *view); void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); void handle_xdg_shell_surface(struct wl_listener *listener, void *data); +void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data); void handle_wl_shell_surface(struct wl_listener *listener, void *data); void handle_layer_shell_surface(struct wl_listener *listener, void *data); void handle_xwayland_surface(struct wl_listener *listener, void *data); diff --git a/include/rootston/view.h b/include/rootston/view.h index 4e3859d5..69cbc87c 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -4,6 +4,7 @@ #include <wlr/config.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_surface.h> +#include <wlr/types/wlr_xdg_decoration_v1.h> #include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell.h> @@ -190,6 +191,14 @@ struct roots_xdg_popup { struct wl_listener new_popup; }; +struct roots_xdg_toplevel_decoration { + struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration; + struct roots_xdg_surface *surface; + struct wl_listener destroy; + struct wl_listener request_mode; + struct wl_listener surface_commit; +}; + void view_get_box(const struct roots_view *view, struct wlr_box *box); void view_activate(struct roots_view *view, bool active); void view_move(struct roots_view *view, double x, double y); diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 2224932f..4860a5b6 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -28,7 +28,7 @@ struct wlr_output_impl { void (*destroy)(struct wlr_output *output); bool (*make_current)(struct wlr_output *output, int *buffer_age); bool (*swap_buffers)(struct wlr_output *output, pixman_region32_t *damage); - void (*set_gamma)(struct wlr_output *output, + bool (*set_gamma)(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); uint32_t (*get_gamma_size)(struct wlr_output *output); bool (*export_dmabuf)(struct wlr_output *output, diff --git a/include/wlr/types/wlr_gamma_control_v1.h b/include/wlr/types/wlr_gamma_control_v1.h new file mode 100644 index 00000000..5a173323 --- /dev/null +++ b/include/wlr/types/wlr_gamma_control_v1.h @@ -0,0 +1,31 @@ +#ifndef WLR_TYPES_WLR_GAMMA_CONTROL_V1_H +#define WLR_TYPES_WLR_GAMMA_CONTROL_V1_H + +#include <wayland-server.h> + +struct wlr_gamma_control_manager_v1 { + struct wl_global *global; + struct wl_list resources; + struct wl_list controls; // wlr_gamma_control_v1::link + + struct wl_listener display_destroy; + + void *data; +}; + +struct wlr_gamma_control_v1 { + struct wl_resource *resource; + struct wlr_output *output; + struct wl_list link; + + struct wl_listener output_destroy_listener; + + void *data; +}; + +struct wlr_gamma_control_manager_v1 *wlr_gamma_control_manager_v1_create( + struct wl_display *display); +void wlr_gamma_control_manager_v1_destroy( + struct wlr_gamma_control_manager_v1 *manager); + +#endif diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index f8452d12..3a9f3c41 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -174,9 +174,19 @@ bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, * it is a no-op. */ void wlr_output_schedule_frame(struct wlr_output *output); -void wlr_output_set_gamma(struct wlr_output *output, - uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); +/** + * Returns the maximum length of each gamma ramp, or 0 if unsupported. + */ uint32_t wlr_output_get_gamma_size(struct wlr_output *output); +/** + * Sets the gamma table for this output. `r`, `g` and `b` are gamma ramps for + * red, green and blue. `size` is the length of the ramps and must not exceed + * the value returned by `wlr_output_get_gamma_size`. + * + * Providing zero-sized ramps resets the gamma table. + */ +bool wlr_output_set_gamma(struct wlr_output *output, + uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b); bool wlr_output_export_dmabuf(struct wlr_output *output, struct wlr_dmabuf_attributes *attribs); void wlr_output_set_fullscreen_surface(struct wlr_output *output, diff --git a/include/wlr/types/wlr_xdg_decoration_v1.h b/include/wlr/types/wlr_xdg_decoration_v1.h new file mode 100644 index 00000000..10d3a1aa --- /dev/null +++ b/include/wlr/types/wlr_xdg_decoration_v1.h @@ -0,0 +1,68 @@ +#ifndef WLR_TYPES_WLR_XDG_DECORATION_V1 +#define WLR_TYPES_WLR_XDG_DECORATION_V1 + +#include <wayland-server.h> +#include <wlr/types/wlr_xdg_shell.h> + +enum wlr_xdg_toplevel_decoration_v1_mode { + WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE = 0, + WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE = 1, + WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE = 2, +}; + +struct wlr_xdg_decoration_manager_v1 { + struct wl_global *global; + struct wl_list resources; + struct wl_list decorations; // wlr_xdg_toplevel_decoration::link + + struct wl_listener display_destroy; + + struct { + struct wl_signal new_toplevel_decoration; // struct wlr_xdg_toplevel_decoration * + } events; + + void *data; +}; + +struct wlr_xdg_toplevel_decoration_v1_configure { + struct wl_list link; // wlr_xdg_toplevel_decoration::configure_list + struct wlr_xdg_surface_configure *surface_configure; + enum wlr_xdg_toplevel_decoration_v1_mode mode; +}; + +struct wlr_xdg_toplevel_decoration_v1 { + struct wl_resource *resource; + struct wlr_xdg_surface *surface; + struct wlr_xdg_decoration_manager_v1 *manager; + struct wl_list link; // wlr_xdg_decoration_manager_v1::link + + bool added; + enum wlr_xdg_toplevel_decoration_v1_mode current_mode; + enum wlr_xdg_toplevel_decoration_v1_mode client_pending_mode; + enum wlr_xdg_toplevel_decoration_v1_mode server_pending_mode; + + struct wl_list configure_list; // wlr_xdg_toplevel_decoration_v1_configure::link + + struct { + struct wl_signal destroy; + struct wl_signal request_mode; + } events; + + struct wl_listener surface_destroy; + struct wl_listener surface_configure; + struct wl_listener surface_ack_configure; + struct wl_listener surface_commit; + + void *data; +}; + +struct wlr_xdg_decoration_manager_v1 * + wlr_xdg_decoration_manager_v1_create(struct wl_display *display); +void wlr_xdg_decoration_manager_v1_destroy( + struct wlr_xdg_decoration_manager_v1 *manager); + +uint32_t wlr_xdg_toplevel_decoration_v1_set_mode( + struct wlr_xdg_toplevel_decoration_v1 *decoration, + enum wlr_xdg_toplevel_decoration_v1_mode mode); + +#endif diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 98538e7f..a067c62e 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -133,6 +133,7 @@ struct wlr_xdg_toplevel { }; struct wlr_xdg_surface_configure { + struct wlr_xdg_surface *surface; struct wl_list link; // wlr_xdg_surface::configure_list uint32_t serial; @@ -196,6 +197,10 @@ struct wlr_xdg_surface { * surface has been hidden or is about to be destroyed. */ struct wl_signal unmap; + + // for protocol extensions + struct wl_signal configure; // wlr_xdg_surface_configure + struct wl_signal ack_configure; // wlr_xdg_surface_configure } events; void *data; @@ -234,6 +239,8 @@ struct wlr_xdg_surface *wlr_xdg_surface_from_resource( struct wl_resource *resource); struct wlr_xdg_surface *wlr_xdg_surface_from_popup_resource( struct wl_resource *resource); +struct wlr_xdg_surface *wlr_xdg_surface_from_toplevel_resource( + struct wl_resource *resource); struct wlr_box wlr_xdg_positioner_get_geometry( struct wlr_xdg_positioner *positioner); @@ -360,7 +367,8 @@ struct wlr_xdg_surface *wlr_xdg_surface_from_wlr_surface( * * The x and y value can be <0 */ -void wlr_xdg_surface_get_geometry(struct wlr_xdg_surface *surface, struct wlr_box *box); +void wlr_xdg_surface_get_geometry(struct wlr_xdg_surface *surface, + struct wlr_box *box); /** * Call `iterator` on each surface and popup in the xdg-surface tree, with the @@ -368,7 +376,13 @@ void wlr_xdg_surface_get_geometry(struct wlr_xdg_surface *surface, struct wlr_bo * from root to leaves (in rendering order). */ void wlr_xdg_surface_for_each_surface(struct wlr_xdg_surface *surface, - wlr_surface_iterator_func_t iterator, void *user_data); + wlr_surface_iterator_func_t iterator, void *user_data); + +/** + * Schedule a surface configuration. This should only be called by protocols + * extending the shell. + */ +uint32_t wlr_xdg_surface_schedule_configure(struct wlr_xdg_surface *surface); /** * Call `iterator` on each popup in the xdg-surface tree, with the popup's diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index 39644dc1..2eda768a 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -184,6 +184,14 @@ struct wlr_xwayland_resize_event { uint32_t edges; }; +/** Create an Xwayland server. + * + * The server supports a lazy mode in which Xwayland is only started when a + * client tries to connect. + * + * Note: wlr_xwayland will setup a global SIGUSR1 handler on the compositor + * process. + */ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, struct wlr_compositor *compositor, bool lazy); diff --git a/meson.build b/meson.build index 6b401597..fb610377 100644 --- a/meson.build +++ b/meson.build @@ -53,7 +53,7 @@ add_project_arguments('-DWL_HIDE_DEPRECATED', language: 'c') wayland_server = dependency('wayland-server', version: '>=1.15') wayland_client = dependency('wayland-client') wayland_egl = dependency('wayland-egl') -wayland_protos = dependency('wayland-protocols', version: '>=1.14') +wayland_protos = dependency('wayland-protocols', version: '>=1.15') egl = dependency('egl') glesv2 = dependency('glesv2') drm = dependency('libdrm') diff --git a/protocol/meson.build b/protocol/meson.build index b7a6e80a..73a3156a 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -31,9 +31,10 @@ protocols = [ [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'], [wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'], [wl_protocol_dir, 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml'], - [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], - [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'], [wl_protocol_dir, 'unstable/tablet/tablet-unstable-v2.xml'], + [wl_protocol_dir, 'unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'], + [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'], + [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], 'gamma-control.xml', 'gtk-primary-selection.xml', 'idle.xml', @@ -41,18 +42,21 @@ protocols = [ 'server-decoration.xml', 'virtual-keyboard-unstable-v1.xml', 'wlr-export-dmabuf-unstable-v1.xml', + 'wlr-gamma-control-unstable-v1.xml', 'wlr-input-inhibitor-unstable-v1.xml', 'wlr-layer-shell-unstable-v1.xml', 'wlr-screencopy-unstable-v1.xml', ] client_protocols = [ - [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'], [wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'], + [wl_protocol_dir, 'unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'], + [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], 'idle.xml', 'screenshooter.xml', 'wlr-export-dmabuf-unstable-v1.xml', + 'wlr-gamma-control-unstable-v1.xml', 'wlr-input-inhibitor-unstable-v1.xml', 'wlr-layer-shell-unstable-v1.xml', 'wlr-screencopy-unstable-v1.xml', diff --git a/protocol/wlr-gamma-control-unstable-v1.xml b/protocol/wlr-gamma-control-unstable-v1.xml new file mode 100644 index 00000000..f55f3fe5 --- /dev/null +++ b/protocol/wlr-gamma-control-unstable-v1.xml @@ -0,0 +1,126 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="wlr_gamma_control_unstable_v1"> + <copyright> + Copyright © 2015 Giulio camuffo + Copyright © 2018 Simon Ser + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + the copyright holders not be used in advertising or publicity + pertaining to distribution of the software without specific, + written prior permission. The copyright holders make no + representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied + warranty. + + THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + THIS SOFTWARE. + </copyright> + + <description summary="manage gamma tables of outputs"> + This protocol allows a privileged client to set the gamma tables for + outputs. + + Warning! The protocol described in this file is experimental and + backward incompatible changes may be made. Backward compatible changes + may be added together with the corresponding interface version bump. + Backward incompatible changes are done by bumping the version number in + the protocol and interface names and resetting the interface version. + Once the protocol is to be declared stable, the 'z' prefix and the + version number in the protocol and interface names are removed and the + interface version number is reset. + </description> + + <interface name="zwlr_gamma_control_manager_v1" version="1"> + <description summary="manager to create per-output gamma controls"> + This interface is a manager that allows creating per-output gamma + controls. + </description> + + <request name="get_gamma_control"> + <description summary="get a gamma control for an output"> + Create a gamma control that can be used to adjust gamma tables for the + provided output. + </description> + <arg name="id" type="new_id" interface="zwlr_gamma_control_v1"/> + <arg name="output" type="object" interface="wl_output"/> + </request> + + <request name="destroy" type="destructor"> + <description summary="destroy the manager"> + All objects created by the manager will still remain valid, until their + appropriate destroy request has been called. + </description> + </request> + </interface> + + <interface name="zwlr_gamma_control_v1" version="1"> + <description summary="adjust gamma tables for an output"> + This interface allows a client to adjust gamma tables for a particular + output. + + The client will receive the gamma size, and will then be able to set gamma + tables. At any time the compositor can send a failed event indicating that + this object is no longer valid. + + There must always be at most one gamma control object per output, which + has exclusive access to this particular output. When the gamma control + object is destroyed, the gamma table is restored to its original value. + </description> + + <event name="gamma_size"> + <description summary="size of gamma ramps"> + Advertise the size of each gamma ramp. + + This event is sent immediately when the gamma control object is created. + </description> + <arg name="size" type="uint" summary="number of elements in a ramp"/> + </event> + + <enum name="error"> + <entry name="invalid_gamma" value="1" summary="invalid gamma tables"/> + </enum> + + <request name="set_gamma"> + <description summary="set the gamma table"> + Set the gamma table. The file descriptor can be memory-mapped to provide + the raw gamma table, which contains successive gamma ramps for the red, + green and blue channels. Each gamma ramp is an array of 16-byte unsigned + integers which has the same length as the gamma size. + + The file descriptor data must have the same length as three times the + gamma size. + </description> + <arg name="fd" type="fd" summary="gamma table file descriptor"/> + </request> + + <event name="failed"> + <description summary="object no longer valid"> + This event indicates that the gamma control is no longer valid. This + can happen for a number of reasons, including: + - The output doesn't support gamma tables + - Setting the gamma tables failed + - Another client already has exclusive gamma control for this output + - The compositor has transfered gamma control to another client + + Upon receiving this event, the client should destroy this object. + </description> + </event> + + <request name="destroy" type="destructor"> + <description summary="destroy this control"> + Destroys the gamma control object. If the object is still valid, this + restores the original gamma tables. + </description> + </request> + </interface> +</protocol> diff --git a/rootston/desktop.c b/rootston/desktop.c index 17bf7ec4..658611e3 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -9,6 +9,7 @@ #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_export_dmabuf_v1.h> #include <wlr/types/wlr_gamma_control.h> +#include <wlr/types/wlr_gamma_control_v1.h> #include <wlr/types/wlr_idle_inhibit_v1.h> #include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_input_inhibitor.h> @@ -552,6 +553,23 @@ void view_update_size(struct roots_view *view, uint32_t width, uint32_t height) view_damage_whole(view); } +void view_update_decorated(struct roots_view *view, bool decorated) { + if (view->decorated == decorated) { + return; + } + + view_damage_whole(view); + view->decorated = decorated; + if (decorated) { + view->border_width = 4; + view->titlebar_height = 12; + } else { + view->border_width = 0; + view->titlebar_height = 0; + } + view_damage_whole(view); +} + static bool view_at(struct roots_view *view, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (view->type == ROOTS_WL_SHELL_VIEW && @@ -851,6 +869,8 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->gamma_control_manager = wlr_gamma_control_manager_create( server->wl_display); + desktop->gamma_control_manager_v1 = wlr_gamma_control_manager_v1_create( + server->wl_display); desktop->screenshooter = wlr_screenshooter_create(server->wl_display); desktop->export_dmabuf_manager_v1 = wlr_export_dmabuf_manager_v1_create(server->wl_display); @@ -884,6 +904,12 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->screencopy = wlr_screencopy_manager_v1_create(server->wl_display); + desktop->xdg_decoration_manager = + wlr_xdg_decoration_manager_v1_create(server->wl_display); + wl_signal_add(&desktop->xdg_decoration_manager->events.new_toplevel_decoration, + &desktop->xdg_toplevel_decoration); + desktop->xdg_toplevel_decoration.notify = handle_xdg_toplevel_decoration; + return desktop; } diff --git a/rootston/xdg_shell.c b/rootston/xdg_shell.c index 0c438be4..e5ab9efd 100644 --- a/rootston/xdg_shell.c +++ b/rootston/xdg_shell.c @@ -265,6 +265,7 @@ static void destroy(struct roots_view *view) { wl_list_remove(&roots_xdg_surface->request_resize.link); wl_list_remove(&roots_xdg_surface->request_maximize.link); wl_list_remove(&roots_xdg_surface->request_fullscreen.link); + roots_xdg_surface->view->xdg_surface->data = NULL; free(roots_xdg_surface); } @@ -439,6 +440,7 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { &roots_surface->request_fullscreen); roots_surface->new_popup.notify = handle_new_popup; wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup); + surface->data = roots_surface; struct roots_view *view = view_create(desktop); if (!view) { @@ -465,3 +467,71 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { view_set_fullscreen(view, true, NULL); } } + + + +static void decoration_handle_destroy(struct wl_listener *listener, + void *data) { + struct roots_xdg_toplevel_decoration *decoration = + wl_container_of(listener, decoration, destroy); + + view_update_decorated(decoration->surface->view, false); + wl_list_remove(&decoration->destroy.link); + wl_list_remove(&decoration->request_mode.link); + wl_list_remove(&decoration->surface_commit.link); + free(decoration); +} + +static void decoration_handle_request_mode(struct wl_listener *listener, + void *data) { + struct roots_xdg_toplevel_decoration *decoration = + wl_container_of(listener, decoration, request_mode); + + enum wlr_xdg_toplevel_decoration_v1_mode mode = + decoration->wlr_decoration->client_pending_mode; + if (mode == WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE) { + mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; + } + wlr_xdg_toplevel_decoration_v1_set_mode(decoration->wlr_decoration, mode); +} + +static void decoration_handle_surface_commit(struct wl_listener *listener, + void *data) { + struct roots_xdg_toplevel_decoration *decoration = + wl_container_of(listener, decoration, surface_commit); + + bool decorated = decoration->wlr_decoration->current_mode == + WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; + view_update_decorated(decoration->surface->view, decorated); +} + +void handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data) { + struct roots_desktop *desktop = + wl_container_of(listener, desktop, xdg_toplevel_decoration); + struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration = data; + + wlr_log(WLR_DEBUG, "new xdg toplevel decoration"); + + struct roots_xdg_surface *xdg_surface = wlr_decoration->surface->data; + assert(xdg_surface != NULL); + struct wlr_xdg_surface *wlr_xdg_surface = xdg_surface->view->xdg_surface; + + struct roots_xdg_toplevel_decoration *decoration = + calloc(1, sizeof(struct roots_xdg_toplevel_decoration)); + if (decoration == NULL) { + return; + } + decoration->wlr_decoration = wlr_decoration; + decoration->surface = xdg_surface; + + decoration->destroy.notify = decoration_handle_destroy; + wl_signal_add(&wlr_decoration->events.destroy, &decoration->destroy); + decoration->request_mode.notify = decoration_handle_request_mode; + wl_signal_add(&wlr_decoration->events.request_mode, + &decoration->request_mode); + decoration->surface_commit.notify = decoration_handle_surface_commit; + wl_signal_add(&wlr_xdg_surface->surface->events.commit, + &decoration->surface_commit); + + decoration_handle_request_mode(&decoration->request_mode, wlr_decoration); +} diff --git a/types/meson.build b/types/meson.build index 89aa967f..23c6cd13 100644 --- a/types/meson.build +++ b/types/meson.build @@ -25,6 +25,7 @@ lib_wlr_types = static_library( 'wlr_cursor.c', 'wlr_export_dmabuf_v1.c', 'wlr_gamma_control.c', + 'wlr_gamma_control_v1.c', 'wlr_idle_inhibit_v1.c', 'wlr_idle.c', 'wlr_input_device.c', @@ -53,6 +54,7 @@ lib_wlr_types = static_library( 'wlr_virtual_keyboard_v1.c', 'wlr_wl_shell.c', 'wlr_xcursor_manager.c', + 'wlr_xdg_decoration_v1.c', 'wlr_xdg_output.c', 'wlr_screencopy_v1.c', ), diff --git a/types/wlr_gamma_control.c b/types/wlr_gamma_control.c index 5b871335..8dbe1c22 100644 --- a/types/wlr_gamma_control.c +++ b/types/wlr_gamma_control.c @@ -25,7 +25,7 @@ static void gamma_control_destroy(struct wlr_gamma_control *gamma_control) { static const struct gamma_control_interface gamma_control_impl; -struct wlr_gamma_control *gamma_control_from_resource( +static struct wlr_gamma_control *gamma_control_from_resource( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &gamma_control_interface, &gamma_control_impl)); @@ -83,7 +83,7 @@ static const struct gamma_control_interface gamma_control_impl = { static const struct gamma_control_manager_interface gamma_control_manager_impl; -struct wlr_gamma_control_manager *gamma_control_manager_from_resource( +static struct wlr_gamma_control_manager *gamma_control_manager_from_resource( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &gamma_control_manager_interface, &gamma_control_manager_impl)); diff --git a/types/wlr_gamma_control_v1.c b/types/wlr_gamma_control_v1.c new file mode 100644 index 00000000..54ab7e9d --- /dev/null +++ b/types/wlr_gamma_control_v1.c @@ -0,0 +1,264 @@ +#include <assert.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> +#include <wayland-server.h> +#include <wlr/interfaces/wlr_output.h> +#include <wlr/types/wlr_gamma_control_v1.h> +#include <wlr/types/wlr_output.h> +#include <wlr/util/log.h> +#include "util/signal.h" +#include "wlr-gamma-control-unstable-v1-protocol.h" + +#define GAMMA_CONTROL_MANAGER_V1_VERSION 1 + +static void gamma_control_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static void gamma_control_destroy(struct wlr_gamma_control_v1 *gamma_control) { + if (gamma_control == NULL) { + return; + } + wlr_output_set_gamma(gamma_control->output, 0, NULL, NULL, NULL); + wl_resource_set_user_data(gamma_control->resource, NULL); + wl_list_remove(&gamma_control->output_destroy_listener.link); + wl_list_remove(&gamma_control->link); + free(gamma_control); +} + +static void gamma_control_send_failed( + struct wlr_gamma_control_v1 *gamma_control) { + zwlr_gamma_control_v1_send_failed(gamma_control->resource); + gamma_control_destroy(gamma_control); +} + +static const struct zwlr_gamma_control_v1_interface gamma_control_impl; + +static struct wlr_gamma_control_v1 *gamma_control_from_resource( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, &zwlr_gamma_control_v1_interface, + &gamma_control_impl)); + return wl_resource_get_user_data(resource); +} + +static void gamma_control_handle_resource_destroy(struct wl_resource *resource) { + struct wlr_gamma_control_v1 *gamma_control = + gamma_control_from_resource(resource); + gamma_control_destroy(gamma_control); +} + +static void gamma_control_handle_output_destroy(struct wl_listener *listener, + void *data) { + struct wlr_gamma_control_v1 *gamma_control = + wl_container_of(listener, gamma_control, output_destroy_listener); + gamma_control_destroy(gamma_control); +} + +static void gamma_control_handle_set_gamma(struct wl_client *client, + struct wl_resource *gamma_control_resource, int fd) { + struct wlr_gamma_control_v1 *gamma_control = + gamma_control_from_resource(gamma_control_resource); + if (gamma_control == NULL) { + goto error_fd; + } + + uint32_t ramp_size = wlr_output_get_gamma_size(gamma_control->output); + size_t table_size = ramp_size * 3 * sizeof(uint16_t); + + // Refuse to block when reading + int fd_flags = fcntl(fd, F_GETFL, 0); + if (fd_flags == -1) { + wlr_log_errno(WLR_ERROR, "failed to get FD flags"); + gamma_control_send_failed(gamma_control); + goto error_fd; + } + if (fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK) == -1) { + wlr_log_errno(WLR_ERROR, "failed to set FD flags"); + gamma_control_send_failed(gamma_control); + goto error_fd; + } + + // Use the heap since gamma tables can be large + uint16_t *table = malloc(table_size); + if (table == NULL) { + wl_resource_post_no_memory(gamma_control_resource); + goto error_fd; + } + + ssize_t n_read = read(fd, table, table_size); + if (n_read < 0) { + wlr_log_errno(WLR_ERROR, "failed to read gamma table"); + gamma_control_send_failed(gamma_control); + goto error_table; + } else if ((size_t)n_read != table_size) { + wl_resource_post_error(gamma_control_resource, + ZWLR_GAMMA_CONTROL_V1_ERROR_INVALID_GAMMA, + "The gamma ramps don't have the correct size"); + goto error_table; + } + close(fd); + fd = -1; + + uint16_t *r = table; + uint16_t *g = table + ramp_size; + uint16_t *b = table + 2 * ramp_size; + + bool ok = wlr_output_set_gamma(gamma_control->output, ramp_size, r, g, b); + if (!ok) { + gamma_control_send_failed(gamma_control); + goto error_table; + } + free(table); + + return; + +error_table: + free(table); +error_fd: + close(fd); +} + +static const struct zwlr_gamma_control_v1_interface gamma_control_impl = { + .destroy = gamma_control_handle_destroy, + .set_gamma = gamma_control_handle_set_gamma, +}; + +static const struct zwlr_gamma_control_manager_v1_interface + gamma_control_manager_impl; + +static struct wlr_gamma_control_manager_v1 *gamma_control_manager_from_resource( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, + &zwlr_gamma_control_manager_v1_interface, &gamma_control_manager_impl)); + return wl_resource_get_user_data(resource); +} + +static void gamma_control_manager_get_gamma_control(struct wl_client *client, + struct wl_resource *manager_resource, uint32_t id, + struct wl_resource *output_resource) { + struct wlr_gamma_control_manager_v1 *manager = + gamma_control_manager_from_resource(manager_resource); + struct wlr_output *output = wlr_output_from_resource(output_resource); + + struct wlr_gamma_control_v1 *gamma_control = + calloc(1, sizeof(struct wlr_gamma_control_v1)); + if (gamma_control == NULL) { + wl_client_post_no_memory(client); + return; + } + gamma_control->output = output; + + uint32_t version = wl_resource_get_version(manager_resource); + gamma_control->resource = wl_resource_create(client, + &zwlr_gamma_control_v1_interface, version, id); + if (gamma_control->resource == NULL) { + free(gamma_control); + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(gamma_control->resource, &gamma_control_impl, + gamma_control, gamma_control_handle_resource_destroy); + + wl_signal_add(&output->events.destroy, + &gamma_control->output_destroy_listener); + gamma_control->output_destroy_listener.notify = + gamma_control_handle_output_destroy; + + wl_list_init(&gamma_control->link); + + if (!output->impl->set_gamma) { + zwlr_gamma_control_v1_send_failed(gamma_control->resource); + gamma_control_destroy(gamma_control); + return; + } + + struct wlr_gamma_control_v1 *gc; + wl_list_for_each(gc, &manager->controls, link) { + if (gc->output == output) { + zwlr_gamma_control_v1_send_failed(gc->resource); + gamma_control_destroy(gc); + return; + } + } + + wl_list_remove(&gamma_control->link); + wl_list_insert(&manager->controls, &gamma_control->link); + zwlr_gamma_control_v1_send_gamma_size(gamma_control->resource, + wlr_output_get_gamma_size(output)); +} + +static const struct zwlr_gamma_control_manager_v1_interface + gamma_control_manager_impl = { + .get_gamma_control = gamma_control_manager_get_gamma_control, +}; + +static void gamma_control_manager_handle_resource_destroy( + struct wl_resource *resource) { + wl_list_remove(wl_resource_get_link(resource)); +} + +static void gamma_control_manager_bind(struct wl_client *client, void *data, + uint32_t version, uint32_t id) { + struct wlr_gamma_control_manager_v1 *manager = data; + + struct wl_resource *resource = wl_resource_create(client, + &zwlr_gamma_control_manager_v1_interface, version, id); + if (resource == NULL) { + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(resource, &gamma_control_manager_impl, + manager, gamma_control_manager_handle_resource_destroy); + wl_list_insert(&manager->resources, wl_resource_get_link(resource)); +} + +void wlr_gamma_control_manager_v1_destroy( + struct wlr_gamma_control_manager_v1 *manager) { + if (!manager) { + return; + } + wl_list_remove(&manager->display_destroy.link); + struct wlr_gamma_control_v1 *gamma_control, *tmp; + wl_list_for_each_safe(gamma_control, tmp, &manager->controls, link) { + wl_resource_destroy(gamma_control->resource); + } + struct wl_resource *resource, *resource_tmp; + wl_resource_for_each_safe(resource, resource_tmp, &manager->resources) { + wl_resource_destroy(resource); + } + wl_global_destroy(manager->global); + free(manager); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_gamma_control_manager_v1 *manager = + wl_container_of(listener, manager, display_destroy); + wlr_gamma_control_manager_v1_destroy(manager); +} + +struct wlr_gamma_control_manager_v1 *wlr_gamma_control_manager_v1_create( + struct wl_display *display) { + struct wlr_gamma_control_manager_v1 *manager = + calloc(1, sizeof(struct wlr_gamma_control_manager_v1)); + if (!manager) { + return NULL; + } + + manager->global = wl_global_create(display, + &zwlr_gamma_control_manager_v1_interface, + GAMMA_CONTROL_MANAGER_V1_VERSION, manager, gamma_control_manager_bind); + if (manager->global == NULL) { + free(manager); + return NULL; + } + + wl_list_init(&manager->resources); + wl_list_init(&manager->controls); + + manager->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &manager->display_destroy); + + return manager; +} diff --git a/types/wlr_output.c b/types/wlr_output.c index a1d00c0c..2ebf2acd 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -552,11 +552,12 @@ void wlr_output_schedule_frame(struct wlr_output *output) { wl_event_loop_add_idle(ev, schedule_frame_handle_idle_timer, output); } -void wlr_output_set_gamma(struct wlr_output *output, - uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { - if (output->impl->set_gamma) { - output->impl->set_gamma(output, size, r, g, b); +bool wlr_output_set_gamma(struct wlr_output *output, uint32_t size, + uint16_t *r, uint16_t *g, uint16_t *b) { + if (!output->impl->set_gamma) { + return false; } + return output->impl->set_gamma(output, size, r, g, b); } uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { diff --git a/types/wlr_xdg_decoration_v1.c b/types/wlr_xdg_decoration_v1.c new file mode 100644 index 00000000..d6aecb87 --- /dev/null +++ b/types/wlr_xdg_decoration_v1.c @@ -0,0 +1,302 @@ +#include <assert.h> +#include <stdbool.h> +#include <stdlib.h> +#include <wlr/types/wlr_xdg_decoration_v1.h> +#include <wlr/util/log.h> +#include "util/signal.h" +#include "xdg-decoration-unstable-v1-protocol.h" + +#define DECORATION_MANAGER_VERSION 1 + +static const struct zxdg_toplevel_decoration_v1_interface + toplevel_decoration_impl; + +static struct wlr_xdg_toplevel_decoration_v1 *toplevel_decoration_from_resource( + struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, + &zxdg_toplevel_decoration_v1_interface, &toplevel_decoration_impl)); + return wl_resource_get_user_data(resource); +} + +static void toplevel_decoration_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static void toplevel_decoration_handle_set_mode(struct wl_client *client, + struct wl_resource *resource, + enum zxdg_toplevel_decoration_v1_mode mode) { + struct wlr_xdg_toplevel_decoration_v1 *decoration = + toplevel_decoration_from_resource(resource); + + decoration->client_pending_mode = + (enum wlr_xdg_toplevel_decoration_v1_mode)mode; + wlr_signal_emit_safe(&decoration->events.request_mode, decoration); +} + +static void toplevel_decoration_handle_unset_mode(struct wl_client *client, + struct wl_resource *resource) { + struct wlr_xdg_toplevel_decoration_v1 *decoration = + toplevel_decoration_from_resource(resource); + + decoration->client_pending_mode = WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE; + wlr_signal_emit_safe(&decoration->events.request_mode, decoration); +} + +static const struct zxdg_toplevel_decoration_v1_interface + toplevel_decoration_impl = { + .destroy = toplevel_decoration_handle_destroy, + .set_mode = toplevel_decoration_handle_set_mode, + .unset_mode = toplevel_decoration_handle_unset_mode, +}; + +uint32_t wlr_xdg_toplevel_decoration_v1_set_mode( + struct wlr_xdg_toplevel_decoration_v1 *decoration, + enum wlr_xdg_toplevel_decoration_v1_mode mode) { + assert(mode != WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_NONE); + decoration->server_pending_mode = mode; + return wlr_xdg_surface_schedule_configure(decoration->surface); +} + +static void toplevel_decoration_handle_resource_destroy( + struct wl_resource *resource) { + struct wlr_xdg_toplevel_decoration_v1 *decoration = + toplevel_decoration_from_resource(resource); + wlr_signal_emit_safe(&decoration->events.destroy, decoration); + wl_list_remove(&decoration->surface_commit.link); + wl_list_remove(&decoration->surface_destroy.link); + wl_list_remove(&decoration->surface_configure.link); + wl_list_remove(&decoration->surface_ack_configure.link); + struct wlr_xdg_toplevel_decoration_v1_configure *configure, *tmp; + wl_list_for_each_safe(configure, tmp, &decoration->configure_list, link) { + free(configure); + } + wl_list_remove(&decoration->link); + free(decoration); +} + +static void toplevel_decoration_handle_surface_destroy( + struct wl_listener *listener, void *data) { + struct wlr_xdg_toplevel_decoration_v1 *decoration = + wl_container_of(listener, decoration, surface_destroy); + wl_resource_destroy(decoration->resource); +} + +static void toplevel_decoration_handle_surface_configure( + struct wl_listener *listener, void *data) { + struct wlr_xdg_toplevel_decoration_v1 *decoration = + wl_container_of(listener, decoration, surface_configure); + struct wlr_xdg_surface_configure *surface_configure = data; + + if (decoration->current_mode == decoration->server_pending_mode) { + return; + } + + struct wlr_xdg_toplevel_decoration_v1_configure *configure = + calloc(1, sizeof(struct wlr_xdg_toplevel_decoration_v1_configure)); + if (configure == NULL) { + return; + } + configure->surface_configure = surface_configure; + configure->mode = decoration->server_pending_mode; + wl_list_insert(decoration->configure_list.prev, &configure->link); + + zxdg_toplevel_decoration_v1_send_configure(decoration->resource, + configure->mode); +} + +static void toplevel_decoration_handle_surface_ack_configure( + struct wl_listener *listener, void *data) { + struct wlr_xdg_toplevel_decoration_v1 *decoration = + wl_container_of(listener, decoration, surface_ack_configure); + struct wlr_xdg_surface_configure *surface_configure = data; + + bool found = false; + struct wlr_xdg_toplevel_decoration_v1_configure *configure; + wl_list_for_each(configure, &decoration->configure_list, link) { + if (configure->surface_configure == surface_configure) { + found = true; + break; + } + } + if (!found) { + return; + } + + decoration->current_mode = configure->mode; + + wl_list_remove(&configure->link); + free(configure); +} + +static void toplevel_decoration_handle_surface_commit( + struct wl_listener *listener, void *data) { + struct wlr_xdg_toplevel_decoration_v1 *decoration = + wl_container_of(listener, decoration, surface_commit); + struct wlr_xdg_decoration_manager_v1 *manager = decoration->manager; + + if (decoration->surface->added) { + wl_list_remove(&decoration->surface_commit.link); + wl_list_init(&decoration->surface_commit.link); + + decoration->added = true; + wlr_signal_emit_safe(&manager->events.new_toplevel_decoration, + decoration); + } +} + + +static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl; + +static struct wlr_xdg_decoration_manager_v1 * + decoration_manager_from_resource(struct wl_resource *resource) { + assert(wl_resource_instance_of(resource, + &zxdg_decoration_manager_v1_interface, + &decoration_manager_impl)); + return wl_resource_get_user_data(resource); +} + +static void decoration_manager_handle_get_toplevel_decoration( + struct wl_client *client, struct wl_resource *manager_resource, + uint32_t id, struct wl_resource *toplevel_resource) { + struct wlr_xdg_decoration_manager_v1 *manager = + decoration_manager_from_resource(manager_resource); + struct wlr_xdg_surface *surface = + wlr_xdg_surface_from_toplevel_resource(toplevel_resource); + assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); + + if (wlr_surface_has_buffer(surface->surface)) { + wl_resource_post_error(manager_resource, + ZXDG_TOPLEVEL_DECORATION_V1_ERROR_UNCONFIGURED_BUFFER, + "xdg_toplevel_decoration must not have a buffer at creation"); + return; + } + + struct wlr_xdg_toplevel_decoration_v1 *decoration = + calloc(1, sizeof(struct wlr_xdg_toplevel_decoration_v1)); + if (decoration == NULL) { + wl_client_post_no_memory(client); + return; + } + decoration->manager = manager; + decoration->surface = surface; + + uint32_t version = wl_resource_get_version(manager_resource); + decoration->resource = wl_resource_create(client, + &zxdg_toplevel_decoration_v1_interface, version, id); + if (decoration->resource == NULL) { + free(decoration); + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(decoration->resource, + &toplevel_decoration_impl, decoration, + toplevel_decoration_handle_resource_destroy); + + wlr_log(WLR_DEBUG, "new xdg_toplevel_decoration %p (res %p)", decoration, + decoration->resource); + + wl_list_init(&decoration->configure_list); + wl_signal_init(&decoration->events.destroy); + wl_signal_init(&decoration->events.request_mode); + + wl_signal_add(&surface->events.destroy, &decoration->surface_destroy); + decoration->surface_destroy.notify = + toplevel_decoration_handle_surface_destroy; + wl_signal_add(&surface->events.configure, &decoration->surface_configure); + decoration->surface_configure.notify = + toplevel_decoration_handle_surface_configure; + wl_signal_add(&surface->events.ack_configure, + &decoration->surface_ack_configure); + decoration->surface_ack_configure.notify = + toplevel_decoration_handle_surface_ack_configure; + wl_list_init(&decoration->surface_commit.link); + + wl_list_insert(&manager->decorations, &decoration->link); + + if (surface->added) { + decoration->added = true; + wlr_signal_emit_safe(&manager->events.new_toplevel_decoration, + decoration); + } else { + wl_list_remove(&decoration->surface_commit.link); + wl_signal_add(&surface->surface->events.commit, + &decoration->surface_commit); + decoration->surface_commit.notify = + toplevel_decoration_handle_surface_commit; + } +} + +static const struct zxdg_decoration_manager_v1_interface + decoration_manager_impl = { + .get_toplevel_decoration = decoration_manager_handle_get_toplevel_decoration, +}; + +void decoration_manager_handle_resource_destroy(struct wl_resource *resource) { + wl_list_remove(wl_resource_get_link(resource)); +} + +static void decoration_manager_bind(struct wl_client *client, void *data, + uint32_t version, uint32_t id) { + struct wlr_xdg_decoration_manager_v1 *manager = data; + + struct wl_resource *resource = wl_resource_create(client, + &zxdg_decoration_manager_v1_interface, version, id); + if (resource == NULL) { + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(resource, &decoration_manager_impl, + manager, decoration_manager_handle_resource_destroy); + + wl_list_insert(&manager->resources, wl_resource_get_link(resource)); +} + +static void handle_display_destroy(struct wl_listener *listener, void *data) { + struct wlr_xdg_decoration_manager_v1 *manager = + wl_container_of(listener, manager, display_destroy); + wlr_xdg_decoration_manager_v1_destroy(manager); +} + +struct wlr_xdg_decoration_manager_v1 * + wlr_xdg_decoration_manager_v1_create(struct wl_display *display) { + struct wlr_xdg_decoration_manager_v1 *manager = + calloc(1, sizeof(struct wlr_xdg_decoration_manager_v1)); + if (manager == NULL) { + return NULL; + } + manager->global = wl_global_create(display, + &zxdg_decoration_manager_v1_interface, DECORATION_MANAGER_VERSION, + manager, decoration_manager_bind); + if (manager->global == NULL) { + free(manager); + return NULL; + } + wl_list_init(&manager->resources); + wl_list_init(&manager->decorations); + wl_signal_init(&manager->events.new_toplevel_decoration); + + manager->display_destroy.notify = handle_display_destroy; + wl_display_add_destroy_listener(display, &manager->display_destroy); + + return manager; +} + +void wlr_xdg_decoration_manager_v1_destroy( + struct wlr_xdg_decoration_manager_v1 *manager) { + if (manager == NULL) { + return; + } + wl_list_remove(&manager->display_destroy.link); + struct wlr_xdg_toplevel_decoration_v1 *decoration, *tmp_decoration; + wl_list_for_each_safe(decoration, tmp_decoration, &manager->decorations, + link) { + wl_resource_destroy(decoration->resource); + } + struct wl_resource *resource, *tmp_resource; + wl_resource_for_each_safe(resource, tmp_resource, &manager->resources) { + wl_resource_destroy(resource); + } + wl_global_destroy(manager->global); + free(manager); +} diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index 0ff47a04..e32b7f18 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -111,6 +111,7 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client, struct wlr_xdg_surface_configure *configure, *tmp; wl_list_for_each_safe(configure, tmp, &surface->configure_list, link) { if (configure->serial < serial) { + wlr_signal_emit_safe(&surface->events.ack_configure, configure); xdg_surface_configure_destroy(configure); } else if (configure->serial == serial) { found = true; @@ -140,6 +141,7 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client, surface->configured = true; surface->configure_serial = serial; + wlr_signal_emit_safe(&surface->events.ack_configure, configure); xdg_surface_configure_destroy(configure); } @@ -157,6 +159,7 @@ static void surface_send_configure(void *user_data) { wl_list_insert(surface->configure_list.prev, &configure->link); configure->serial = surface->configure_next_serial; + configure->surface = surface; switch (surface->role) { case WLR_XDG_SURFACE_ROLE_NONE: @@ -174,26 +177,15 @@ static void surface_send_configure(void *user_data) { break; } + wlr_signal_emit_safe(&surface->events.configure, configure); + xdg_surface_send_configure(surface->resource, configure->serial); } -uint32_t schedule_xdg_surface_configure( - struct wlr_xdg_surface *surface) { +static uint32_t schedule_configure(struct wlr_xdg_surface *surface, + bool pending_same) { struct wl_display *display = wl_client_get_display(surface->client->client); struct wl_event_loop *loop = wl_display_get_event_loop(display); - bool pending_same = false; - - switch (surface->role) { - case WLR_XDG_SURFACE_ROLE_NONE: - assert(0 && "not reached"); - break; - case WLR_XDG_SURFACE_ROLE_TOPLEVEL: - pending_same = - compare_xdg_surface_toplevel_state(surface->toplevel); - break; - case WLR_XDG_SURFACE_ROLE_POPUP: - break; - } if (surface->configure_idle != NULL) { if (!pending_same) { @@ -218,6 +210,27 @@ uint32_t schedule_xdg_surface_configure( } } +uint32_t schedule_xdg_surface_configure(struct wlr_xdg_surface *surface) { + bool pending_same = false; + + switch (surface->role) { + case WLR_XDG_SURFACE_ROLE_NONE: + assert(0 && "not reached"); + break; + case WLR_XDG_SURFACE_ROLE_TOPLEVEL: + pending_same = compare_xdg_surface_toplevel_state(surface->toplevel); + break; + case WLR_XDG_SURFACE_ROLE_POPUP: + break; + } + + return schedule_configure(surface, pending_same); +} + +uint32_t wlr_xdg_surface_schedule_configure(struct wlr_xdg_surface *surface) { + return schedule_configure(surface, false); +} + static void xdg_surface_handle_get_popup(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *parent_resource, @@ -417,6 +430,8 @@ struct wlr_xdg_surface *create_xdg_surface( wl_signal_init(&xdg_surface->events.new_popup); wl_signal_init(&xdg_surface->events.map); wl_signal_init(&xdg_surface->events.unmap); + wl_signal_init(&xdg_surface->events.configure); + wl_signal_init(&xdg_surface->events.ack_configure); wl_signal_add(&xdg_surface->surface->events.destroy, &xdg_surface->surface_destroy); diff --git a/types/xdg_shell/wlr_xdg_toplevel.c b/types/xdg_shell/wlr_xdg_toplevel.c index 3bf7fd67..77398c7e 100644 --- a/types/xdg_shell/wlr_xdg_toplevel.c +++ b/types/xdg_shell/wlr_xdg_toplevel.c @@ -200,7 +200,7 @@ void handle_xdg_surface_toplevel_committed(struct wlr_xdg_surface *surface) { static const struct xdg_toplevel_interface xdg_toplevel_implementation; -static struct wlr_xdg_surface *xdg_surface_from_xdg_toplevel_resource( +struct wlr_xdg_surface *wlr_xdg_surface_from_toplevel_resource( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &xdg_toplevel_interface, &xdg_toplevel_implementation)); @@ -210,11 +210,11 @@ static struct wlr_xdg_surface *xdg_surface_from_xdg_toplevel_resource( static void xdg_toplevel_handle_set_parent(struct wl_client *client, struct wl_resource *resource, struct wl_resource *parent_resource) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); struct wlr_xdg_surface *parent = NULL; if (parent_resource != NULL) { - parent = xdg_surface_from_xdg_toplevel_resource(parent_resource); + parent = wlr_xdg_surface_from_toplevel_resource(parent_resource); } surface->toplevel->parent = parent; @@ -224,7 +224,7 @@ static void xdg_toplevel_handle_set_parent(struct wl_client *client, static void xdg_toplevel_handle_set_title(struct wl_client *client, struct wl_resource *resource, const char *title) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); char *tmp; tmp = strdup(title); @@ -240,7 +240,7 @@ static void xdg_toplevel_handle_set_title(struct wl_client *client, static void xdg_toplevel_handle_set_app_id(struct wl_client *client, struct wl_resource *resource, const char *app_id) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); char *tmp; tmp = strdup(app_id); @@ -257,7 +257,7 @@ static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); @@ -288,7 +288,7 @@ static void xdg_toplevel_handle_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); @@ -317,7 +317,7 @@ static void xdg_toplevel_handle_resize(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, uint32_t edges) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); @@ -346,7 +346,7 @@ static void xdg_toplevel_handle_resize(struct wl_client *client, static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); surface->toplevel->client_pending.max_width = width; surface->toplevel->client_pending.max_height = height; } @@ -354,7 +354,7 @@ static void xdg_toplevel_handle_set_max_size(struct wl_client *client, static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); surface->toplevel->client_pending.min_width = width; surface->toplevel->client_pending.min_height = height; } @@ -362,7 +362,7 @@ static void xdg_toplevel_handle_set_min_size(struct wl_client *client, static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); surface->toplevel->client_pending.maximized = true; wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } @@ -370,7 +370,7 @@ static void xdg_toplevel_handle_set_maximized(struct wl_client *client, static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); surface->toplevel->client_pending.maximized = false; wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); } @@ -378,7 +378,7 @@ static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); struct wlr_output *output = NULL; if (output_resource != NULL) { @@ -399,7 +399,7 @@ static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); surface->toplevel->client_pending.fullscreen = false; @@ -415,7 +415,7 @@ static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, static void xdg_toplevel_handle_set_minimized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); wlr_signal_emit_safe(&surface->toplevel->events.request_minimize, surface); } @@ -443,7 +443,7 @@ static const struct xdg_toplevel_interface xdg_toplevel_implementation = { static void xdg_toplevel_handle_resource_destroy(struct wl_resource *resource) { struct wlr_xdg_surface *surface = - xdg_surface_from_xdg_toplevel_resource(resource); + wlr_xdg_surface_from_toplevel_resource(resource); if (surface != NULL) { destroy_xdg_toplevel(surface); } |