commit
6710de9878
@ -0,0 +1,189 @@
|
||||
#include <GLES2/gl2.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-egl.h>
|
||||
#include <wlr/render/egl.h>
|
||||
#include "wlr-input-inhibitor-unstable-v1-client-protocol.h"
|
||||
#include "xdg-shell-client-protocol.h"
|
||||
|
||||
static int width = 500, height = 300;
|
||||
static int keys = 0;
|
||||
|
||||
static struct wl_compositor *compositor = NULL;
|
||||
static struct wl_seat *seat = NULL;
|
||||
static struct xdg_wm_base *wm_base = NULL;
|
||||
static struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager = NULL;
|
||||
static struct zwlr_input_inhibitor_v1 *input_inhibitor = NULL;
|
||||
|
||||
struct wlr_egl egl;
|
||||
struct wl_egl_window *egl_window;
|
||||
struct wlr_egl_surface *egl_surface;
|
||||
|
||||
static void render_frame(void) {
|
||||
eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
if (keys) {
|
||||
glClearColor(1.0, 1.0, 1.0, 1.0);
|
||||
} else {
|
||||
glClearColor(0.8, 0.4, 1.0, 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);
|
||||
render_frame();
|
||||
}
|
||||
|
||||
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 void xdg_toplevel_handle_close(void *data,
|
||||
struct xdg_toplevel *xdg_toplevel) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
||||
.configure = xdg_toplevel_handle_configure,
|
||||
.close = xdg_toplevel_handle_close,
|
||||
};
|
||||
|
||||
static void wl_keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
|
||||
uint32_t format, int32_t fd, uint32_t size) {
|
||||
}
|
||||
static void wl_keyboard_enter(void *data, struct wl_keyboard *wl_keyboard,
|
||||
uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
|
||||
}
|
||||
static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard,
|
||||
uint32_t serial, struct wl_surface *surface) {
|
||||
}
|
||||
static void wl_keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard,
|
||||
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
|
||||
uint32_t mods_locked, uint32_t group) {
|
||||
}
|
||||
static void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
|
||||
int32_t rate, int32_t delay) {
|
||||
}
|
||||
|
||||
static void wl_keyboard_key(void *data, struct wl_keyboard *wl_keyboard,
|
||||
uint32_t serial, uint32_t time, uint32_t key, uint32_t state) {
|
||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
++keys;
|
||||
} else {
|
||||
--keys;
|
||||
}
|
||||
render_frame();
|
||||
}
|
||||
|
||||
static struct wl_keyboard_listener keyboard_listener = {
|
||||
.keymap = wl_keyboard_keymap,
|
||||
.enter = wl_keyboard_enter,
|
||||
.leave = wl_keyboard_leave,
|
||||
.key = wl_keyboard_key,
|
||||
.modifiers = wl_keyboard_modifiers,
|
||||
.repeat_info = wl_keyboard_repeat_info,
|
||||
};
|
||||
|
||||
static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
|
||||
enum wl_seat_capability caps) {
|
||||
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) {
|
||||
struct wl_keyboard *keyboard = wl_seat_get_keyboard(wl_seat);
|
||||
wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void seat_handle_name(void *data, struct wl_seat *wl_seat,
|
||||
const char *name) {
|
||||
// Who cares
|
||||
}
|
||||
|
||||
const struct wl_seat_listener seat_listener = {
|
||||
.capabilities = seat_handle_capabilities,
|
||||
.name = seat_handle_name,
|
||||
};
|
||||
|
||||
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, zwlr_input_inhibit_manager_v1_interface.name) == 0) {
|
||||
input_inhibit_manager = wl_registry_bind(registry, name,
|
||||
&zwlr_input_inhibit_manager_v1_interface, 1);
|
||||
} else if (strcmp(interface, wl_seat_interface.name) == 0) {
|
||||
seat = wl_registry_bind(registry, name, &wl_seat_interface, version);
|
||||
wl_seat_add_listener(seat, &seat_listener, seat);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
struct wl_display *display = wl_display_connect(NULL);
|
||||
assert(display);
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
assert(registry);
|
||||
wl_registry_add_listener(registry, ®istry_listener, NULL);
|
||||
wl_display_dispatch(display);
|
||||
wl_display_roundtrip(display);
|
||||
assert(compositor && seat && wm_base && input_inhibit_manager);
|
||||
|
||||
input_inhibitor = zwlr_input_inhibit_manager_v1_get_inhibitor(
|
||||
input_inhibit_manager);
|
||||
assert(input_inhibitor);
|
||||
|
||||
wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL,
|
||||
WL_SHM_FORMAT_ARGB8888);
|
||||
|
||||
struct wl_surface *surface = wl_compositor_create_surface(compositor);
|
||||
assert(surface);
|
||||
struct xdg_surface *xdg_surface =
|
||||
xdg_wm_base_get_xdg_surface(wm_base, surface);
|
||||
assert(xdg_surface);
|
||||
struct xdg_toplevel *xdg_toplevel = xdg_surface_get_toplevel(xdg_surface);
|
||||
assert(xdg_toplevel);
|
||||
|
||||
xdg_surface_add_listener(xdg_surface, &xdg_surface_listener, NULL);
|
||||
xdg_toplevel_add_listener(xdg_toplevel, &xdg_toplevel_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);
|
||||
|
||||
render_frame();
|
||||
|
||||
while (wl_display_dispatch(display) != -1) {
|
||||
// This space intentionally left blank
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#ifndef WLR_TYPES_INPUT_INHIBITOR_H
|
||||
#define WLR_TYPES_INPUT_INHIBITOR_H
|
||||
#include <wayland-server.h>
|
||||
|
||||
struct wlr_input_inhibit_manager {
|
||||
struct wl_global *wl_global;
|
||||
struct wl_client *active_client;
|
||||
struct wl_resource *active_inhibitor;
|
||||
|
||||
struct wl_listener display_destroy;
|
||||
|
||||
struct {
|
||||
struct wl_signal activate; // struct wlr_input_inhibit_manager *
|
||||
struct wl_signal deactivate; // struct wlr_input_inhibit_manager *
|
||||
} events;
|
||||
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct wlr_input_inhibit_manager *wlr_input_inhibit_manager_create(
|
||||
struct wl_display *display);
|
||||
void wlr_input_inhibit_manager_destroy(
|
||||
struct wlr_input_inhibit_manager *manager);
|
||||
|
||||
#endif
|
@ -0,0 +1,32 @@
|
||||
#ifndef WLR_TYPES_WLR_XDG_OUTPUT_H
|
||||
#define WLR_TYPES_WLR_XDG_OUTPUT_H
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
|
||||
struct wlr_xdg_output {
|
||||
struct wl_list link;
|
||||
struct wl_list resources;
|
||||
|
||||
struct wlr_xdg_output_manager *manager;
|
||||
struct wlr_output_layout_output *layout_output;
|
||||
|
||||
struct wl_listener destroy;
|
||||
};
|
||||
|
||||
struct wlr_xdg_output_manager {
|
||||
struct wl_global *global;
|
||||
|
||||
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 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
|
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="wlr_input_inhibit_unstable_v1">
|
||||
<copyright>
|
||||
Copyright © 2018 Drew DeVault
|
||||
|
||||
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>
|
||||
|
||||
<interface name="zwlr_input_inhibit_manager_v1" version="1">
|
||||
<description summary="inhibits input events to other clients">
|
||||
Clients can use this interface to prevent input events from being sent to
|
||||
any surfaces but its own, which is useful for example in lock screen
|
||||
software. It is assumed that access to this interface will be locked down
|
||||
to whitelisted clients by the compositor.
|
||||
</description>
|
||||
|
||||
<request name="get_inhibitor">
|
||||
<description summary="inhibit input to other clients">
|
||||
Activates the input inhibitor. As long as the inhibitor is active, the
|
||||
compositor will not send input events to other clients.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwlr_input_inhibitor_v1"/>
|
||||
</request>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="already_inhibited" value="0" summary="an input inhibitor is already in use on the compositor"/>
|
||||
</enum>
|
||||
</interface>
|
||||
|
||||
<interface name="zwlr_input_inhibitor_v1" version="1">
|
||||
<description summary="inhibits input to other clients">
|
||||
While this resource exists, input to clients other than the owner of the
|
||||
inhibitor resource will not receive input events. The client that owns
|
||||
this resource will receive all input events normally. The compositor will
|
||||
also disable all of its own input processing (such as keyboard shortcuts)
|
||||
while the inhibitor is active.
|
||||
|
||||
The compositor may continue to send input events to selected clients,
|
||||
such as an on-screen keyboard (via the input-method protocol).
|
||||
</description>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the input inhibitor object">
|
||||
Destroy the inhibitor and allow other clients to receive input.
|
||||
</description>
|
||||
</request>
|
||||
</interface>
|
||||
</protocol>
|
@ -0,0 +1,150 @@
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-server.h>
|
||||
#include "wlr/types/wlr_input_inhibitor.h"
|
||||
#include "wlr-input-inhibitor-unstable-v1-protocol.h"
|
||||
|
||||
static const struct zwlr_input_inhibit_manager_v1_interface inhibit_manager_implementation;
|
||||
static struct zwlr_input_inhibitor_v1_interface input_inhibitor_implementation;
|
||||
|
||||
static struct wlr_input_inhibit_manager *input_inhibit_manager_from_resource(
|
||||
struct wl_resource *resource) {
|
||||
assert(wl_resource_instance_of(resource,
|
||||
&zwlr_input_inhibit_manager_v1_interface,
|
||||
&inhibit_manager_implementation)
|
||||
|| wl_resource_instance_of(resource,
|
||||
&zwlr_input_inhibitor_v1_interface,
|
||||
&input_inhibitor_implementation));
|
||||
return wl_resource_get_user_data(resource);
|
||||
}
|
||||
|
||||
static void input_inhibit_manager_deactivate(
|
||||
struct wlr_input_inhibit_manager *manager) {
|
||||
if (manager->active_client == NULL && manager->active_inhibitor == NULL) {
|
||||
return;
|
||||
}
|
||||
manager->active_client = NULL;
|
||||
manager->active_inhibitor = NULL;
|
||||
wl_signal_emit(&manager->events.deactivate, manager);
|
||||
}
|
||||
|
||||
static void input_inhibitor_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
struct wlr_input_inhibit_manager *manager =
|
||||
input_inhibit_manager_from_resource(resource);
|
||||
input_inhibit_manager_deactivate(manager);
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static void input_inhibitor_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_input_inhibit_manager *manager =
|
||||
input_inhibit_manager_from_resource(resource);
|
||||
input_inhibit_manager_deactivate(manager);
|
||||
}
|
||||
|
||||
static struct zwlr_input_inhibitor_v1_interface input_inhibitor_implementation = {
|
||||
.destroy = input_inhibitor_destroy,
|
||||
};
|
||||
|
||||
static void inhibit_manager_get_inhibitor(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id) {
|
||||
struct wlr_input_inhibit_manager *manager =
|
||||
input_inhibit_manager_from_resource(resource);
|
||||
if (manager->active_client || manager->active_inhibitor) {
|
||||
wl_resource_post_error(resource,
|
||||
ZWLR_INPUT_INHIBIT_MANAGER_V1_ERROR_ALREADY_INHIBITED,
|
||||
"this compositor already has input inhibited");
|
||||
return;
|
||||
}
|
||||
|
||||
struct wl_resource *wl_resource = wl_resource_create(client,
|
||||
&zwlr_input_inhibitor_v1_interface,
|
||||
wl_resource_get_version(resource), id);
|
||||
if (!wl_resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
}
|
||||
wl_resource_set_implementation(wl_resource, &input_inhibitor_implementation,
|
||||
manager, input_inhibitor_resource_destroy);
|
||||
|
||||
manager->active_client = client;
|
||||
manager->active_inhibitor = wl_resource;
|
||||
|
||||
wl_signal_emit(&manager->events.activate, manager);
|
||||
}
|
||||
|
||||
static const struct zwlr_input_inhibit_manager_v1_interface inhibit_manager_implementation = {
|
||||
.get_inhibitor = inhibit_manager_get_inhibitor
|
||||
};
|
||||
|
||||
static void input_manager_resource_destroy(struct wl_resource *resource) {
|
||||
struct wlr_input_inhibit_manager *manager =
|
||||
input_inhibit_manager_from_resource(resource);
|
||||
struct wl_client *client = wl_resource_get_client(resource);
|
||||
if (manager->active_client == client) {
|
||||
input_inhibit_manager_deactivate(manager);
|
||||
}
|
||||
}
|
||||
|
||||
static void inhibit_manager_bind(struct wl_client *wl_client, void *data,
|
||||
uint32_t version, uint32_t id) {
|
||||
struct wlr_input_inhibit_manager *manager = data;
|
||||
assert(wl_client && manager);
|
||||
|
||||
struct wl_resource *wl_resource = wl_resource_create(wl_client,
|
||||
&zwlr_input_inhibit_manager_v1_interface, version, id);
|
||||
if (wl_resource == NULL) {
|
||||
wl_client_post_no_memory(wl_client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(wl_resource,
|
||||
&inhibit_manager_implementation, manager,
|
||||
input_manager_resource_destroy);
|
||||
}
|
||||
|
||||
void wlr_input_inhibit_manager_destroy(
|
||||
struct wlr_input_inhibit_manager *manager) {
|
||||
if (!manager) {
|
||||
return;
|
||||
}
|
||||
if (manager->active_client) {
|
||||
input_inhibitor_destroy(manager->active_client,
|
||||
manager->active_inhibitor);
|
||||
}
|
||||
wl_list_remove(&manager->display_destroy.link);
|
||||
wl_global_destroy(manager->wl_global);
|
||||
free(manager);
|
||||
}
|
||||
|
||||
static void handle_display_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_input_inhibit_manager *manager =
|
||||
wl_container_of(listener, manager, display_destroy);
|
||||
wlr_input_inhibit_manager_destroy(manager);
|
||||
}
|
||||
|
||||
struct wlr_input_inhibit_manager *wlr_input_inhibit_manager_create(
|
||||
struct wl_display *display) {
|
||||
// TODO: Client destroy
|
||||
struct wlr_input_inhibit_manager *manager =
|
||||
calloc(1, sizeof(struct wlr_input_inhibit_manager));
|
||||
if (!manager) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
manager->wl_global = wl_global_create(display,
|
||||
&zwlr_input_inhibit_manager_v1_interface,
|
||||
1, manager, inhibit_manager_bind);
|
||||
if (manager->wl_global == NULL){
|
||||
wl_list_remove(&manager->display_destroy.link);
|
||||
free(manager);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wl_signal_init(&manager->events.activate);
|
||||
wl_signal_init(&manager->events.deactivate);
|
||||
|
||||
manager->display_destroy.notify = handle_display_destroy;
|
||||
wl_display_add_destroy_listener(display, &manager->display_destroy);
|
||||
|
||||
return manager;
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/types/wlr_xdg_output.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "xdg-output-unstable-v1-protocol.h"
|
||||
|
||||
static void xdg_output_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static const struct zxdg_output_v1_interface xdg_output_implementation = {
|
||||
.destroy = xdg_output_destroy,
|
||||
};
|
||||
|
||||
static void xdg_output_manager_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static const struct zxdg_output_manager_v1_interface xdg_output_manager_implementation;
|
||||
|
||||
static void xdg_output_send_details(struct wl_resource *resource,
|
||||
struct wlr_output_layout_output *layout_output) {
|
||||
zxdg_output_v1_send_logical_position(resource,
|
||||
layout_output->x, layout_output->y);
|
||||
zxdg_output_v1_send_logical_size(resource,
|
||||
(float)layout_output->output->width / layout_output->output->scale,
|
||||
(float)layout_output->output->height / layout_output->output->scale);
|
||||
zxdg_output_v1_send_done(resource);
|
||||
}
|
||||
|
||||
static void xdg_output_manager_get_xdg_output(struct wl_client *client,
|
||||
struct wl_resource *resource, uint32_t id, struct wl_resource *output) {
|
||||
assert(wl_resource_instance_of(resource, &zxdg_output_manager_v1_interface,
|
||||
&xdg_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 *wlr_output = wlr_output_from_resource(output);
|
||||
|
||||
struct wlr_output_layout_output *layout_output =
|
||||
wlr_output_layout_get(layout, wlr_output);
|
||||
assert(layout_output);
|
||||
|
||||
struct wl_resource *output_resource = wl_resource_create(client,
|
||||
&zxdg_output_v1_interface, wl_resource_get_version(resource), id);
|
||||
if (!output_resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(output_resource,
|
||||
&xdg_output_implementation, NULL, NULL);
|
||||
xdg_output_send_details(output_resource, layout_output);
|
||||
}
|
||||
|
||||
static const struct zxdg_output_manager_v1_interface xdg_output_manager_implementation = {
|
||||
.destroy = xdg_output_manager_destroy,
|
||||
.get_xdg_output = xdg_output_manager_get_xdg_output,
|
||||
};
|
||||
|
||||
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;
|
||||
assert(wl_client && manager);
|
||||
|
||||
struct wl_resource *wl_resource = wl_resource_create(wl_client,
|
||||
&zxdg_output_manager_v1_interface, version, id);
|
||||
if (wl_resource == NULL) {
|
||||
wl_client_post_no_memory(wl_client);
|
||||
return;
|
||||
}
|
||||
wl_resource_set_implementation(wl_resource,
|
||||
&xdg_output_manager_implementation, manager, NULL);
|
||||
}
|
||||
|
||||
static void destroy_output(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 handle_output_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_xdg_output *output = wl_container_of(listener, output, destroy);
|
||||
destroy_output(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));
|
||||
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);
|
||||
}
|
||||
|
||||
static void xdg_output_manager_send_details(
|
||||
struct wlr_xdg_output_manager *manager) {
|
||||
struct wlr_xdg_output *output;
|
||||
wl_list_for_each(output, &manager->outputs, link) {
|
||||
struct wl_resource *resource;
|
||||
wl_resource_for_each(resource, &output->resources) {
|
||||
xdg_output_send_details(resource, output->layout_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);
|
||||
xdg_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_change);
|
||||
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,
|
||||
1, manager, output_manager_bind);
|
||||
if (!manager->global) {
|
||||
free(manager);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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, *tmp;
|
||||
wl_list_for_each_safe(output, tmp, &manager->outputs, link) {
|
||||
destroy_output(output);
|
||||
}
|
||||
wl_list_remove(&manager->layout_add.link);
|
||||
wl_list_remove(&manager->layout_change.link);
|
||||
wl_list_remove(&manager->layout_destroy.link);
|
||||
free(manager);
|
||||
}
|
Loading…
Reference in new issue