From b3cb22c003d15a2f9f638af4816b803beb836f14 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 14 Sep 2018 19:29:08 +0200 Subject: xdg-output: add _v1 suffix --- include/wlr/types/meson.build | 2 +- include/wlr/types/wlr_xdg_output.h | 47 ------- include/wlr/types/wlr_xdg_output_v1.h | 47 +++++++ rootston/desktop.c | 6 +- types/meson.build | 2 +- types/wlr_xdg_output.c | 256 ---------------------------------- types/wlr_xdg_output_v1.c | 256 ++++++++++++++++++++++++++++++++++ 7 files changed, 308 insertions(+), 308 deletions(-) delete mode 100644 include/wlr/types/wlr_xdg_output.h create mode 100644 include/wlr/types/wlr_xdg_output_v1.h delete mode 100644 types/wlr_xdg_output.c create mode 100644 types/wlr_xdg_output_v1.c diff --git a/include/wlr/types/meson.build b/include/wlr/types/meson.build index 8c81cb0e..fd354795 100644 --- a/include/wlr/types/meson.build +++ b/include/wlr/types/meson.build @@ -35,7 +35,7 @@ install_headers( 'wlr_wl_shell.h', 'wlr_xcursor_manager.h', 'wlr_xdg_decoration_v1.h', - 'wlr_xdg_output.h', + 'wlr_xdg_output_v1.h', 'wlr_xdg_shell.h', 'wlr_xdg_shell_v6.h', subdir: 'wlr/types', diff --git a/include/wlr/types/wlr_xdg_output.h b/include/wlr/types/wlr_xdg_output.h deleted file mode 100644 index 60611307..00000000 --- a/include/wlr/types/wlr_xdg_output.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This an unstable interface of wlroots. No guarantees are made regarding the - * future consistency of this API. - */ -#ifndef WLR_USE_UNSTABLE -#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" -#endif - -#ifndef WLR_TYPES_WLR_XDG_OUTPUT_H -#define WLR_TYPES_WLR_XDG_OUTPUT_H -#include -#include - -struct wlr_xdg_output { - struct wlr_xdg_output_manager *manager; - struct wl_list resources; - struct wl_list link; - - struct wlr_output_layout_output *layout_output; - - int32_t x, y; - int32_t width, height; - - struct wl_listener destroy; -}; - -struct wlr_xdg_output_manager { - struct wl_global *global; - struct wl_list resources; - struct wlr_output_layout *layout; - - struct wl_list outputs; - - struct wl_listener layout_add; - struct wl_listener layout_change; - struct wl_listener layout_destroy; - - struct { - struct wl_signal destroy; - } events; -}; - -struct wlr_xdg_output_manager *wlr_xdg_output_manager_create( - struct wl_display *display, struct wlr_output_layout *layout); -void wlr_xdg_output_manager_destroy(struct wlr_xdg_output_manager *manager); - -#endif diff --git a/include/wlr/types/wlr_xdg_output_v1.h b/include/wlr/types/wlr_xdg_output_v1.h new file mode 100644 index 00000000..d4279fb9 --- /dev/null +++ b/include/wlr/types/wlr_xdg_output_v1.h @@ -0,0 +1,47 @@ +/* + * This an unstable interface of wlroots. No guarantees are made regarding the + * future consistency of this API. + */ +#ifndef WLR_USE_UNSTABLE +#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features" +#endif + +#ifndef WLR_TYPES_WLR_XDG_OUTPUT_V1_H +#define WLR_TYPES_WLR_XDG_OUTPUT_V1_H +#include +#include + +struct wlr_xdg_output_v1 { + struct wlr_xdg_output_manager_v1 *manager; + struct wl_list resources; + struct wl_list link; + + struct wlr_output_layout_output *layout_output; + + int32_t x, y; + int32_t width, height; + + struct wl_listener destroy; +}; + +struct wlr_xdg_output_manager_v1 { + struct wl_global *global; + struct wl_list resources; + struct wlr_output_layout *layout; + + struct wl_list outputs; + + struct wl_listener layout_add; + struct wl_listener layout_change; + struct wl_listener layout_destroy; + + struct { + struct wl_signal destroy; + } events; +}; + +struct wlr_xdg_output_manager_v1 *wlr_xdg_output_manager_v1_create( + struct wl_display *display, struct wlr_output_layout *layout); +void wlr_xdg_output_manager_v1_destroy(struct wlr_xdg_output_manager_v1 *manager); + +#endif diff --git a/rootston/desktop.c b/rootston/desktop.c index efb7581a..28aa4f34 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -19,10 +19,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include #include "rootston/layers.h" @@ -795,7 +795,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->config = config; desktop->layout = wlr_output_layout_create(); - wlr_xdg_output_manager_create(server->wl_display, desktop->layout); + wlr_xdg_output_manager_v1_create(server->wl_display, desktop->layout); desktop->layout_change.notify = handle_layout_change; wl_signal_add(&desktop->layout->events.change, &desktop->layout_change); diff --git a/types/meson.build b/types/meson.build index 23c6cd13..51740c88 100644 --- a/types/meson.build +++ b/types/meson.build @@ -55,7 +55,7 @@ lib_wlr_types = static_library( 'wlr_wl_shell.c', 'wlr_xcursor_manager.c', 'wlr_xdg_decoration_v1.c', - 'wlr_xdg_output.c', + 'wlr_xdg_output_v1.c', 'wlr_screencopy_v1.c', ), include_directories: wlr_inc, diff --git a/types/wlr_xdg_output.c b/types/wlr_xdg_output.c deleted file mode 100644 index 8c7a1fcb..00000000 --- a/types/wlr_xdg_output.c +++ /dev/null @@ -1,256 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "xdg-output-unstable-v1-protocol.h" -#include "util/signal.h" - -#define OUTPUT_MANAGER_VERSION 2 - -static void output_handle_destroy(struct wl_client *client, - struct wl_resource *resource) { - wl_resource_destroy(resource); -} - -static const struct zxdg_output_v1_interface output_implementation = { - .destroy = output_handle_destroy, -}; - -static void output_handle_resource_destroy(struct wl_resource *resource) { - wl_list_remove(wl_resource_get_link(resource)); -} - -static void output_send_details(struct wlr_xdg_output *xdg_output, - struct wl_resource *resource) { - struct wlr_output *output = xdg_output->layout_output->output; - - zxdg_output_v1_send_logical_position(resource, - xdg_output->x, xdg_output->y); - zxdg_output_v1_send_logical_size(resource, - xdg_output->width, xdg_output->height); - - uint32_t version = wl_resource_get_version(resource); - if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { - zxdg_output_v1_send_name(resource, output->name); - } - if (version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION) { - char description[128]; - snprintf(description, sizeof(description), "%s %s %s (%s)", - output->make, output->model, output->serial, output->name); - zxdg_output_v1_send_description(resource, description); - } - - zxdg_output_v1_send_done(resource); -} - -static void output_update(struct wlr_xdg_output *xdg_output) { - struct wlr_output_layout_output *layout_output = xdg_output->layout_output; - bool updated = false; - - if (layout_output->x != xdg_output->x || layout_output->y != xdg_output->y) { - xdg_output->x = layout_output->x; - xdg_output->y = layout_output->y; - updated = true; - } - - int width, height; - wlr_output_effective_resolution(layout_output->output, &width, &height); - if (xdg_output->width != width || xdg_output->height != height) { - xdg_output->width = width; - xdg_output->height = height; - updated = true; - } - - if (updated) { - struct wl_resource *resource; - wl_resource_for_each(resource, &xdg_output->resources) { - output_send_details(xdg_output, resource); - } - } -} - -static void output_destroy(struct wlr_xdg_output *output) { - struct wl_resource *resource, *tmp; - wl_resource_for_each_safe(resource, tmp, &output->resources) { - wl_list_remove(wl_resource_get_link(resource)); - wl_list_init(wl_resource_get_link(resource)); - } - wl_list_remove(&output->destroy.link); - wl_list_remove(&output->link); - free(output); -} - - -static void output_manager_handle_destroy(struct wl_client *client, - struct wl_resource *resource) { - wl_resource_destroy(resource); -} - -static const struct zxdg_output_manager_v1_interface - output_manager_implementation; - -static void output_manager_handle_get_xdg_output(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - struct wl_resource *output_resource) { - assert(wl_resource_instance_of(resource, &zxdg_output_manager_v1_interface, - &output_manager_implementation)); - - struct wlr_xdg_output_manager *manager = - wl_resource_get_user_data(resource); - struct wlr_output_layout *layout = manager->layout; - struct wlr_output *output = wlr_output_from_resource(output_resource); - - struct wlr_output_layout_output *layout_output = - wlr_output_layout_get(layout, output); - assert(layout_output); - - struct wlr_xdg_output *_xdg_output, *xdg_output = NULL; - wl_list_for_each(_xdg_output, &manager->outputs, link) { - if (_xdg_output->layout_output == layout_output) { - xdg_output = _xdg_output; - break; - } - } - assert(xdg_output); - - struct wl_resource *xdg_output_resource = wl_resource_create(client, - &zxdg_output_v1_interface, wl_resource_get_version(resource), id); - if (!xdg_output_resource) { - wl_client_post_no_memory(client); - return; - } - wl_resource_set_implementation(xdg_output_resource, &output_implementation, - NULL, output_handle_resource_destroy); - - wl_list_insert(&xdg_output->resources, - wl_resource_get_link(xdg_output_resource)); - - output_send_details(xdg_output, xdg_output_resource); -} - -static const struct zxdg_output_manager_v1_interface - output_manager_implementation = { - .destroy = output_manager_handle_destroy, - .get_xdg_output = output_manager_handle_get_xdg_output, -}; - -static void output_manager_handle_resource_destroy( - struct wl_resource *resource) { - wl_list_remove(wl_resource_get_link(resource)); -} - -static void output_manager_bind(struct wl_client *wl_client, void *data, - uint32_t version, uint32_t id) { - struct wlr_xdg_output_manager *manager = data; - - struct wl_resource *resource = wl_resource_create(wl_client, - &zxdg_output_manager_v1_interface, version, id); - if (resource == NULL) { - wl_client_post_no_memory(wl_client); - return; - } - wl_resource_set_implementation(resource, &output_manager_implementation, - manager, output_manager_handle_resource_destroy); - wl_list_insert(&manager->resources, wl_resource_get_link(resource)); -} - -static void handle_output_destroy(struct wl_listener *listener, void *data) { - struct wlr_xdg_output *output = wl_container_of(listener, output, destroy); - output_destroy(output); -} - -static void add_output(struct wlr_xdg_output_manager *manager, - struct wlr_output_layout_output *layout_output) { - struct wlr_xdg_output *output = calloc(1, sizeof(struct wlr_xdg_output)); - if (output == NULL) { - return; - } - wl_list_init(&output->resources); - output->manager = manager; - output->layout_output = layout_output; - output->destroy.notify = handle_output_destroy; - wl_signal_add(&layout_output->events.destroy, &output->destroy); - wl_list_insert(&manager->outputs, &output->link); - output_update(output); -} - -static void output_manager_send_details( - struct wlr_xdg_output_manager *manager) { - struct wlr_xdg_output *output; - wl_list_for_each(output, &manager->outputs, link) { - output_update(output); - } -} - -static void handle_layout_add(struct wl_listener *listener, void *data) { - struct wlr_xdg_output_manager *manager = - wl_container_of(listener, manager, layout_add); - struct wlr_output_layout_output *layout_output = data; - add_output(manager, layout_output); -} - -static void handle_layout_change(struct wl_listener *listener, void *data) { - struct wlr_xdg_output_manager *manager = - wl_container_of(listener, manager, layout_change); - output_manager_send_details(manager); -} - -static void handle_layout_destroy(struct wl_listener *listener, void *data) { - struct wlr_xdg_output_manager *manager = - wl_container_of(listener, manager, layout_destroy); - wlr_xdg_output_manager_destroy(manager); -} - -struct wlr_xdg_output_manager *wlr_xdg_output_manager_create( - struct wl_display *display, struct wlr_output_layout *layout) { - assert(display && layout); - struct wlr_xdg_output_manager *manager = - calloc(1, sizeof(struct wlr_xdg_output_manager)); - if (manager == NULL) { - return NULL; - } - manager->layout = layout; - manager->global = wl_global_create(display, - &zxdg_output_manager_v1_interface, OUTPUT_MANAGER_VERSION, manager, - output_manager_bind); - if (!manager->global) { - free(manager); - return NULL; - } - - wl_list_init(&manager->resources); - wl_list_init(&manager->outputs); - struct wlr_output_layout_output *layout_output; - wl_list_for_each(layout_output, &layout->outputs, link) { - add_output(manager, layout_output); - } - - wl_signal_init(&manager->events.destroy); - - manager->layout_add.notify = handle_layout_add; - wl_signal_add(&layout->events.add, &manager->layout_add); - manager->layout_change.notify = handle_layout_change; - wl_signal_add(&layout->events.change, &manager->layout_change); - manager->layout_destroy.notify = handle_layout_destroy; - wl_signal_add(&layout->events.destroy, &manager->layout_destroy); - return manager; -} - -void wlr_xdg_output_manager_destroy(struct wlr_xdg_output_manager *manager) { - struct wlr_xdg_output *output, *output_tmp; - wl_list_for_each_safe(output, output_tmp, &manager->outputs, link) { - output_destroy(output); - } - struct wl_resource *resource, *resource_tmp; - wl_resource_for_each_safe(resource, resource_tmp, &manager->resources) { - wl_resource_destroy(resource); - } - wlr_signal_emit_safe(&manager->events.destroy, manager); - wl_list_remove(&manager->layout_add.link); - wl_list_remove(&manager->layout_change.link); - wl_list_remove(&manager->layout_destroy.link); - free(manager); -} diff --git a/types/wlr_xdg_output_v1.c b/types/wlr_xdg_output_v1.c new file mode 100644 index 00000000..5e8419ae --- /dev/null +++ b/types/wlr_xdg_output_v1.c @@ -0,0 +1,256 @@ +#include +#include +#include +#include +#include +#include +#include +#include "xdg-output-unstable-v1-protocol.h" +#include "util/signal.h" + +#define OUTPUT_MANAGER_VERSION 2 + +static void output_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static const struct zxdg_output_v1_interface output_implementation = { + .destroy = output_handle_destroy, +}; + +static void output_handle_resource_destroy(struct wl_resource *resource) { + wl_list_remove(wl_resource_get_link(resource)); +} + +static void output_send_details(struct wlr_xdg_output_v1 *xdg_output, + struct wl_resource *resource) { + struct wlr_output *output = xdg_output->layout_output->output; + + zxdg_output_v1_send_logical_position(resource, + xdg_output->x, xdg_output->y); + zxdg_output_v1_send_logical_size(resource, + xdg_output->width, xdg_output->height); + + uint32_t version = wl_resource_get_version(resource); + if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { + zxdg_output_v1_send_name(resource, output->name); + } + if (version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION) { + char description[128]; + snprintf(description, sizeof(description), "%s %s %s (%s)", + output->make, output->model, output->serial, output->name); + zxdg_output_v1_send_description(resource, description); + } + + zxdg_output_v1_send_done(resource); +} + +static void output_update(struct wlr_xdg_output_v1 *xdg_output) { + struct wlr_output_layout_output *layout_output = xdg_output->layout_output; + bool updated = false; + + if (layout_output->x != xdg_output->x || layout_output->y != xdg_output->y) { + xdg_output->x = layout_output->x; + xdg_output->y = layout_output->y; + updated = true; + } + + int width, height; + wlr_output_effective_resolution(layout_output->output, &width, &height); + if (xdg_output->width != width || xdg_output->height != height) { + xdg_output->width = width; + xdg_output->height = height; + updated = true; + } + + if (updated) { + struct wl_resource *resource; + wl_resource_for_each(resource, &xdg_output->resources) { + output_send_details(xdg_output, resource); + } + } +} + +static void output_destroy(struct wlr_xdg_output_v1 *output) { + struct wl_resource *resource, *tmp; + wl_resource_for_each_safe(resource, tmp, &output->resources) { + wl_list_remove(wl_resource_get_link(resource)); + wl_list_init(wl_resource_get_link(resource)); + } + wl_list_remove(&output->destroy.link); + wl_list_remove(&output->link); + free(output); +} + + +static void output_manager_handle_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static const struct zxdg_output_manager_v1_interface + output_manager_implementation; + +static void output_manager_handle_get_xdg_output(struct wl_client *client, + struct wl_resource *resource, uint32_t id, + struct wl_resource *output_resource) { + assert(wl_resource_instance_of(resource, &zxdg_output_manager_v1_interface, + &output_manager_implementation)); + + struct wlr_xdg_output_manager_v1 *manager = + wl_resource_get_user_data(resource); + struct wlr_output_layout *layout = manager->layout; + struct wlr_output *output = wlr_output_from_resource(output_resource); + + struct wlr_output_layout_output *layout_output = + wlr_output_layout_get(layout, output); + assert(layout_output); + + struct wlr_xdg_output_v1 *_xdg_output, *xdg_output = NULL; + wl_list_for_each(_xdg_output, &manager->outputs, link) { + if (_xdg_output->layout_output == layout_output) { + xdg_output = _xdg_output; + break; + } + } + assert(xdg_output); + + struct wl_resource *xdg_output_resource = wl_resource_create(client, + &zxdg_output_v1_interface, wl_resource_get_version(resource), id); + if (!xdg_output_resource) { + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(xdg_output_resource, &output_implementation, + NULL, output_handle_resource_destroy); + + wl_list_insert(&xdg_output->resources, + wl_resource_get_link(xdg_output_resource)); + + output_send_details(xdg_output, xdg_output_resource); +} + +static const struct zxdg_output_manager_v1_interface + output_manager_implementation = { + .destroy = output_manager_handle_destroy, + .get_xdg_output = output_manager_handle_get_xdg_output, +}; + +static void output_manager_handle_resource_destroy( + struct wl_resource *resource) { + wl_list_remove(wl_resource_get_link(resource)); +} + +static void output_manager_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id) { + struct wlr_xdg_output_manager_v1 *manager = data; + + struct wl_resource *resource = wl_resource_create(wl_client, + &zxdg_output_manager_v1_interface, version, id); + if (resource == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + wl_resource_set_implementation(resource, &output_manager_implementation, + manager, output_manager_handle_resource_destroy); + wl_list_insert(&manager->resources, wl_resource_get_link(resource)); +} + +static void handle_output_destroy(struct wl_listener *listener, void *data) { + struct wlr_xdg_output_v1 *output = wl_container_of(listener, output, destroy); + output_destroy(output); +} + +static void add_output(struct wlr_xdg_output_manager_v1 *manager, + struct wlr_output_layout_output *layout_output) { + struct wlr_xdg_output_v1 *output = calloc(1, sizeof(struct wlr_xdg_output_v1)); + if (output == NULL) { + return; + } + wl_list_init(&output->resources); + output->manager = manager; + output->layout_output = layout_output; + output->destroy.notify = handle_output_destroy; + wl_signal_add(&layout_output->events.destroy, &output->destroy); + wl_list_insert(&manager->outputs, &output->link); + output_update(output); +} + +static void output_manager_send_details( + struct wlr_xdg_output_manager_v1 *manager) { + struct wlr_xdg_output_v1 *output; + wl_list_for_each(output, &manager->outputs, link) { + output_update(output); + } +} + +static void handle_layout_add(struct wl_listener *listener, void *data) { + struct wlr_xdg_output_manager_v1 *manager = + wl_container_of(listener, manager, layout_add); + struct wlr_output_layout_output *layout_output = data; + add_output(manager, layout_output); +} + +static void handle_layout_change(struct wl_listener *listener, void *data) { + struct wlr_xdg_output_manager_v1 *manager = + wl_container_of(listener, manager, layout_change); + output_manager_send_details(manager); +} + +static void handle_layout_destroy(struct wl_listener *listener, void *data) { + struct wlr_xdg_output_manager_v1 *manager = + wl_container_of(listener, manager, layout_destroy); + wlr_xdg_output_manager_v1_destroy(manager); +} + +struct wlr_xdg_output_manager_v1 *wlr_xdg_output_manager_v1_create( + struct wl_display *display, struct wlr_output_layout *layout) { + assert(display && layout); + struct wlr_xdg_output_manager_v1 *manager = + calloc(1, sizeof(struct wlr_xdg_output_manager_v1)); + if (manager == NULL) { + return NULL; + } + manager->layout = layout; + manager->global = wl_global_create(display, + &zxdg_output_manager_v1_interface, OUTPUT_MANAGER_VERSION, manager, + output_manager_bind); + if (!manager->global) { + free(manager); + return NULL; + } + + wl_list_init(&manager->resources); + wl_list_init(&manager->outputs); + struct wlr_output_layout_output *layout_output; + wl_list_for_each(layout_output, &layout->outputs, link) { + add_output(manager, layout_output); + } + + wl_signal_init(&manager->events.destroy); + + manager->layout_add.notify = handle_layout_add; + wl_signal_add(&layout->events.add, &manager->layout_add); + manager->layout_change.notify = handle_layout_change; + wl_signal_add(&layout->events.change, &manager->layout_change); + manager->layout_destroy.notify = handle_layout_destroy; + wl_signal_add(&layout->events.destroy, &manager->layout_destroy); + return manager; +} + +void wlr_xdg_output_manager_v1_destroy(struct wlr_xdg_output_manager_v1 *manager) { + struct wlr_xdg_output_v1 *output, *output_tmp; + wl_list_for_each_safe(output, output_tmp, &manager->outputs, link) { + output_destroy(output); + } + struct wl_resource *resource, *resource_tmp; + wl_resource_for_each_safe(resource, resource_tmp, &manager->resources) { + wl_resource_destroy(resource); + } + wlr_signal_emit_safe(&manager->events.destroy, manager); + wl_list_remove(&manager->layout_add.link); + wl_list_remove(&manager->layout_change.link); + wl_list_remove(&manager->layout_destroy.link); + free(manager); +} -- cgit v1.2.3