initial commit

This commit is contained in:
Richard Acayan 2024-04-15 22:11:00 -04:00
commit 1c606d0274
No known key found for this signature in database
GPG key ID: 0346F4894879DB73
36 changed files with 9908 additions and 0 deletions

215
wayland/buffer.c Normal file
View file

@ -0,0 +1,215 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Wayland buffer management.
*
* Copyright (c) 2024, Richard Acayan. All rights reserved.
*/
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/mman.h>
#include <unistd.h>
#include <wayland-client-protocol.h>
#include "wayland.h"
static int commit_buffer_resize(struct ufkbd_wl_buffer *ctx);
static void on_buffer_release(void *data, struct wl_buffer *buf)
{
struct ufkbd_wl_buffer *ctx = data;
if (ctx->resize)
commit_buffer_resize(ctx);
ctx->avail = true;
}
static const struct wl_buffer_listener buf_listener = {
.release = on_buffer_release,
};
static int commit_buffer_resize(struct ufkbd_wl_buffer *ctx)
{
int ret;
wl_buffer_destroy(ctx->buf);
ret = ftruncate(ctx->fd, ctx->size);
if (ret == -1) {
perror("wl: failed to resize shared memory");
return -errno;
}
ctx->ptr = mmap(NULL, ctx->size, PROT_READ | PROT_WRITE, MAP_SHARED, ctx->fd, 0);
if (ctx->ptr == MAP_FAILED) {
perror("wl: failed to map buffer");
return -errno;
}
wl_shm_pool_resize(ctx->pool, ctx->size);
ctx->buf = wl_shm_pool_create_buffer(ctx->pool, 0,
ctx->width, ctx->height,
ctx->width * 4,
WL_SHM_FORMAT_XRGB8888);
if (ctx->buf == NULL) {
fprintf(stderr, "wl: lost a buffer to failed resize\n");
ctx->avail = false;
}
wl_buffer_add_listener(ctx->buf, &buf_listener, ctx);
ctx->resize = false;
return 0;
}
static void on_wl_shm(void *data,
struct wl_registry *reg,
uint32_t name, uint32_t ver)
{
struct ufkbd_wl_buffer *ctx = data;
ctx->wl = wl_registry_bind(reg, name, &wl_shm_interface, ver);
if (ctx->wl == NULL) {
fprintf(stderr, "wl: failed to bind to shared memory\n");
return;
}
ctx->pool = wl_shm_create_pool(ctx->wl, ctx->fd, 4);
if (ctx->pool == NULL) {
fprintf(stderr, "wl: failed to create memory pool\n");
return;
}
ctx->buf = wl_shm_pool_create_buffer(ctx->pool, 0,
1, 1, 4,
WL_SHM_FORMAT_XRGB8888);
if (ctx->buf == NULL) {
fprintf(stderr, "wl: failed to create buffer\n");
return;
}
wl_buffer_add_listener(ctx->buf, &buf_listener, ctx);
}
int ufkbd_wl_buffer_consume(struct ufkbd_wl_buffer *ctx,
struct wl_buffer **buf, void **ptr)
{
if (buf == NULL || ptr == NULL)
return -EINVAL;
if (!ctx->avail)
return -EBUSY;
ctx->avail = false;
*buf = ctx->buf;
*ptr = ctx->ptr;
return 0;
}
int ufkbd_wl_buffer_resize(struct ufkbd_wl_buffer *ctx,
uint32_t width, uint32_t height)
{
int ret;
if (width == 0 && height == 0)
return -EINVAL;
ctx->width = width;
ctx->height = height;
if (ctx->size < ctx->width * ctx->height * 4) {
munmap(ctx->ptr, ctx->size);
ctx->size = ctx->width * ctx->height * 4;
}
if (ctx->avail) {
ret = commit_buffer_resize(ctx);
if (ret)
return ret;
} else {
ctx->resize = true;
}
return 0;
}
int ufkbd_wl_buffer_init(struct ufkbd_wl_buffer *ctx,
struct ufkbd_input_wayland *ufkbd_wl,
unsigned int id)
{
intmax_t pid;
int ret;
ctx->ufkbd = ufkbd_wl->ufkbd;
ctx->id = id;
ctx->avail = true;
ctx->dirty = false;
ctx->resize = false;
ctx->listener.iface = &wl_shm_interface;
ctx->listener.cb = on_wl_shm;
ctx->listener.data = ctx;
pid = getpid();
snprintf(ctx->path, SHM_PATH_SIZE, "/wl_shm_ufkbd_pid%jd_%u", pid, id);
ctx->path[SHM_PATH_SIZE - 1] = '\0';
ctx->fd = shm_open(ctx->path, O_RDWR | O_CREAT | O_EXCL, 0600);
if (ctx->fd == -1) {
perror("wl: failed to create shared memory");
return -errno;
}
ret = ftruncate(ctx->fd, 4);
if (ret) {
perror("wl: failed to allocate 4 bytes on shm");
ret = -errno;
goto err;
}
ctx->ptr = mmap(NULL, 4, PROT_READ | PROT_WRITE, MAP_SHARED, ctx->fd, 0);
if (ctx->ptr == MAP_FAILED) {
perror("wl: failed to map buffer");
ret = -errno;
goto err;
}
ret = ufkbd_wl_global_listener_add(ufkbd_wl, &ctx->listener);
if (ret)
goto err;
ctx->width = 1;
ctx->height = 1;
ctx->size = 4;
return 0;
err:
close(ctx->fd);
shm_unlink(ctx->path);
return ret;
}
void ufkbd_wl_buffer_uninit(struct ufkbd_wl_buffer *ctx)
{
if (ctx->buf != NULL)
wl_buffer_destroy(ctx->buf);
if (ctx->pool != NULL)
wl_shm_pool_destroy(ctx->pool);
if (ctx->wl != NULL)
wl_shm_destroy(ctx->wl);
close(ctx->fd);
shm_unlink(ctx->path);
}

247
wayland/driver.c Normal file
View file

@ -0,0 +1,247 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Wayland driver.
*
* Copyright (c) 2024, Richard Acayan. All rights reserved.
*/
#include <errno.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>
#include "input.h"
#include "ufkbd.h"
#include "wayland.h"
static void on_global_object(void *data,
struct wl_registry *reg,
uint32_t name,
const char *iface,
uint32_t version);
static const struct wl_registry_listener reg_listener = {
.global = on_global_object,
.global_remove = NULL,
};
static void on_global_object(void *data,
struct wl_registry *reg,
uint32_t name,
const char *iface,
uint32_t version)
{
struct ufkbd_input_wayland *ctx = data;
struct ufkbd_wl_global_listener *listener;
size_t i;
// This is assumed to be a small list.
for (i = 0; i < ctx->n_global_listeners; i++) {
listener = ctx->global_listeners[i];
if (!strcmp(iface, listener->iface->name))
listener->cb(listener->data, reg, name, version);
}
}
int ufkbd_wl_global_listener_add(struct ufkbd_input_wayland *ctx,
struct ufkbd_wl_global_listener *listener)
{
size_t idx = ctx->n_global_listeners;
if (idx >= MAX_GLOBAL_LISTENERS) {
fprintf(stderr, "wl: no space for internal callback\n");
return -ENOSPC;
}
ctx->global_listeners[idx] = listener;
ctx->n_global_listeners++;
return 0;
}
static void ufkbd_wayland_listen_one(void *data, bool block)
{
struct ufkbd_input_wayland *ctx = data;
struct pollfd pollfd;
int timeout = 0;
int ret;
if (block)
timeout = -1;
// Some listen events may be queued, so send them.
ret = wl_display_flush(ctx->display);
if (ret < 0)
fprintf(stderr, "warn: failed to flush outgoing events: %d\n", -errno);
pollfd.fd = ctx->fd;
pollfd.events = POLLIN;
pollfd.revents = 0;
ret = poll(&pollfd, 1, timeout);
if (ret == -1)
return;
if (pollfd.revents) {
ret = wl_display_dispatch(ctx->display);
if (ret == -1)
return;
}
}
static void ufkbd_wayland_listen_step(void *data, int timeout)
{
struct ufkbd_input_wayland *ctx = data;
struct pollfd pollfd;
int ret;
// Some listen events may be queued, so send them.
ret = wl_display_flush(ctx->display);
if (ret < 0)
fprintf(stderr, "warn: failed to flush outgoing events: %d\n", -errno);
pollfd.fd = ctx->fd;
pollfd.events = POLLIN;
pollfd.revents = 0;
ret = poll(&pollfd, 1, timeout);
if (ret == -1)
return;
if (pollfd.revents) {
ret = wl_display_dispatch(ctx->display);
if (ret == -1)
return;
}
}
static int ufkbd_wayland_send_key(void *data, int code, bool repeat)
{
struct ufkbd_input_wayland *ctx = data;
ufkbd_wl_input_send_key(ctx->input, code - 8, repeat);
return 0;
}
static int ufkbd_wayland_send_mod(void *data, enum ufkbd_modifier mod, bool pressed)
{
struct ufkbd_input_wayland *ctx = data;
ufkbd_wl_input_send_mod(ctx->input, mod, pressed);
return 0;
}
static int ufkbd_wayland_draw_begin(void *data, size_t *stride, void **ptr)
{
struct ufkbd_input_wayland *ctx = data;
struct wl_buffer *buf;
int ret;
ret = ufkbd_wl_surface_consume_buffer(ctx->surface, &buf, ptr);
if (ret) {
fprintf(stderr, "wl: warn: could not consume buffer: %s\n",
strerror(-ret));
return ret;
}
wl_surface_attach(ctx->surface->wl, buf, 0, 0);
// NOPUSH
*stride = (size_t) ctx->surface->bufs[0].width * 4;
return 0;
}
static void ufkbd_wayland_draw_touch(void *data, int x, int y, int width, int height)
{
struct ufkbd_input_wayland *ctx = data;
wl_surface_damage_buffer(ctx->surface->wl, x, y, width, height);
}
static void ufkbd_wayland_draw_end(void *data)
{
struct ufkbd_input_wayland *ctx = data;
wl_surface_commit(ctx->surface->wl);
}
static void *ufkbd_wayland_init(struct ufkbd_ctx *ufkbd)
{
struct ufkbd_input_wayland *ctx;
int ret;
if (ufkbd == NULL)
return NULL;
ctx = calloc(1, sizeof(*ctx));
if (ctx == NULL)
return NULL;
ctx->ufkbd = ufkbd;
ctx->display = wl_display_connect(NULL);
if (ctx->display == NULL)
goto err_free_ctx;
ctx->registry = wl_display_get_registry(ctx->display);
if (ctx->registry == NULL)
goto err_disconnect;
ret = wl_registry_add_listener(ctx->registry, &reg_listener, ctx);
if (ret)
goto err_destroy_reg;
ret = ufkbd_wl_surface_init(ctx, &ctx->surface);
if (ret)
goto err_destroy_reg;
ret = ufkbd_wl_input_init(ctx, &ctx->input);
if (ret)
goto err_uninit_surface;
ctx->fd = wl_display_get_fd(ctx->display);
return ctx;
err_uninit_surface:
ufkbd_wl_surface_uninit(ctx->surface);
err_destroy_reg:
wl_registry_destroy(ctx->registry);
err_disconnect:
wl_display_disconnect(ctx->display);
err_free_ctx:
free(ctx);
return NULL;
}
static void ufkbd_wayland_uninit(void *data)
{
struct ufkbd_input_wayland *ctx = data;
ufkbd_wl_input_uninit(ctx->input);
ufkbd_wl_surface_uninit(ctx->surface);
wl_registry_destroy(ctx->registry);
wl_display_disconnect(ctx->display);
free(ctx);
}
struct ufkbd_driver ufkbd_wayland = {
.init = ufkbd_wayland_init,
.uninit = ufkbd_wayland_uninit,
.listen_one = ufkbd_wayland_listen_one,
.listen_step = ufkbd_wayland_listen_step,
.send_key = ufkbd_wayland_send_key,
.send_mod = ufkbd_wayland_send_mod,
.draw_begin = ufkbd_wayland_draw_begin,
.draw_touch = ufkbd_wayland_draw_touch,
.draw_end = ufkbd_wayland_draw_end,
};

316
wayland/input.c Normal file
View file

@ -0,0 +1,316 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Wayland input handling.
*
* Copyright (c) 2024, Richard Acayan. All rights reserved.
*/
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <wayland-client-protocol.h>
#include <xkbcommon/xkbcommon.h>
#include "input.h"
#include "keymap.h"
#include "ufkbd.h"
#include "wayland.h"
#include "wayland/input-method-unstable-v2.h"
#include "wayland/virtual-keyboard-unstable-v1.h"
static void ignore()
{}
static void on_pointer_move(void *data,
struct wl_pointer *pointer __attribute__((unused)),
uint32_t serial __attribute__((unused)),
wl_fixed_t x,
wl_fixed_t y)
{
struct ufkbd_wl_input *ctx = data;
struct ufkbd_input_wayland *ufkbd_wl = ctx->ufkbd_wl;
struct ufkbd_ctx *ufkbd = ufkbd_wl->ufkbd;
ufkbd_input_position(ufkbd, UFKBD_PRESS_MAX - 1, x / 256, y / 256);
}
static void on_pointer_button(void *data,
struct wl_pointer *pointer,
uint32_t serial,
uint32_t time,
uint32_t button,
uint32_t state)
{
struct ufkbd_wl_input *ctx = data;
struct ufkbd_input_wayland *ufkbd_wl = ctx->ufkbd_wl;
struct ufkbd_ctx *ufkbd = ufkbd_wl->ufkbd;
if (state == WL_POINTER_BUTTON_STATE_PRESSED)
ufkbd_input_press(ufkbd, UFKBD_PRESS_MAX - 1);
else if (state == WL_POINTER_BUTTON_STATE_RELEASED)
ufkbd_input_release(ufkbd, UFKBD_PRESS_MAX - 1);
}
static const struct wl_pointer_listener pointer_listener = {
.enter = ignore,
.leave = ignore,
.motion = on_pointer_move,
.button = on_pointer_button,
.axis = ignore,
.frame = ignore,
.axis_source = ignore,
.axis_stop = ignore,
.axis_discrete = ignore,
.axis_value120 = ignore,
.axis_relative_direction = ignore,
};
void on_touch_down(void *data,
struct wl_touch *wl_touch,
uint32_t serial,
uint32_t time,
struct wl_surface *surface,
int32_t id,
wl_fixed_t x,
wl_fixed_t y)
{
struct ufkbd_wl_input *ctx = data;
struct ufkbd_input_wayland *ufkbd_wl = ctx->ufkbd_wl;
struct ufkbd_ctx *ufkbd = ufkbd_wl->ufkbd;
ufkbd_input_position(ufkbd, id, x / 256, y / 256);
ufkbd_input_press(ufkbd, id);
}
void on_touch_up(void *data,
struct wl_touch *wl_touch,
uint32_t serial,
uint32_t time,
int32_t id)
{
struct ufkbd_wl_input *ctx = data;
struct ufkbd_input_wayland *ufkbd_wl = ctx->ufkbd_wl;
struct ufkbd_ctx *ufkbd = ufkbd_wl->ufkbd;
ufkbd_input_release(ufkbd, id);
}
void on_touch_motion(void *data,
struct wl_touch *wl_touch,
uint32_t time,
int32_t id,
wl_fixed_t x,
wl_fixed_t y)
{
struct ufkbd_wl_input *ctx = data;
struct ufkbd_input_wayland *ufkbd_wl = ctx->ufkbd_wl;
struct ufkbd_ctx *ufkbd = ufkbd_wl->ufkbd;
ufkbd_input_position(ufkbd, id, x / 256, y / 256);
}
static const struct wl_touch_listener touch_listener = {
.down = on_touch_down,
.up = on_touch_up,
.motion = on_touch_motion,
.frame = ignore,
.cancel = ignore,
.shape = ignore,
.orientation = ignore,
};
static void on_seat_caps(void *data,
struct wl_seat *seat,
uint32_t capabilities)
{
struct ufkbd_wl_input *ctx = data;
if (capabilities & WL_SEAT_CAPABILITY_TOUCH) {
ctx->touch = wl_seat_get_touch(seat);
if (ctx->touch == NULL)
return;
wl_touch_add_listener(ctx->touch, &touch_listener, ctx);
} else {
if (ctx->touch != NULL)
wl_touch_destroy(ctx->touch);
ctx->touch = NULL;
}
if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
ctx->pointer = wl_seat_get_pointer(seat);
if (ctx->pointer == NULL)
return;
wl_pointer_add_listener(ctx->pointer, &pointer_listener, ctx);
} else {
if (ctx->pointer != NULL)
wl_pointer_destroy(ctx->pointer);
ctx->pointer = NULL;
}
}
static void on_seat_name(void *data,
struct wl_seat *seat,
const char *name)
{
printf("wl: found seat %s\n", name);
}
struct wl_seat_listener seat_listener = {
.name = on_seat_name,
.capabilities = on_seat_caps,
};
static int try_create_virtual_keyboard(struct ufkbd_wl_input *ctx)
{
struct ufkbd_keymap *keymap = ctx->ufkbd_wl->ufkbd->keymap;
if (ctx->manager == NULL)
return -EINVAL;
if (ctx->seat == NULL)
return -EINVAL;
if (ctx->kb != NULL)
return -EEXIST;
ctx->kb = zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(ctx->manager,
ctx->seat);
if (ctx->kb == NULL)
return -ENOMEM;
zwp_virtual_keyboard_v1_keymap(ctx->kb, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
keymap->fd, keymap->size);
return 0;
}
static void on_global_vkman(void *data,
struct wl_registry *reg,
uint32_t name, uint32_t version)
{
struct ufkbd_wl_input *ctx = data;
ctx->manager = wl_registry_bind(reg, name,
&zwp_virtual_keyboard_manager_v1_interface,
version);
if (ctx->manager == NULL)
return;
try_create_virtual_keyboard(ctx);
}
static void on_global_seat(void *data,
struct wl_registry *reg,
uint32_t name, uint32_t version)
{
struct ufkbd_wl_input *ctx = data;
ctx->seat = wl_registry_bind(reg, name, &wl_seat_interface, version);
if (ctx->seat == NULL)
return;
wl_seat_add_listener(ctx->seat, &seat_listener, ctx);
try_create_virtual_keyboard(ctx);
}
int ufkbd_wl_input_send_key(struct ufkbd_wl_input *ctx, int key, bool repeat)
{
if (ctx->kb == NULL)
return -ENODEV;
zwp_virtual_keyboard_v1_key(ctx->kb, 0, key, WL_KEYBOARD_KEY_STATE_PRESSED);
if (!repeat)
zwp_virtual_keyboard_v1_key(ctx->kb, 0, key, WL_KEYBOARD_KEY_STATE_RELEASED);
return 0;
}
int ufkbd_wl_input_send_mod(struct ufkbd_wl_input *ctx, enum ufkbd_modifier mod, bool pressed)
{
int bit;
if (ctx->kb == NULL)
return -ENODEV;
if (mod == UFKBD_MOD_SHIFT)
bit = 0x1;
else if (mod == UFKBD_MOD_CTRL)
bit = 0x4;
else if (mod == UFKBD_MOD_ALT)
bit = 0x8;
else
bit = 0;
if (pressed)
ctx->mod_state |= bit;
else
ctx->mod_state &= ~bit;
zwp_virtual_keyboard_v1_modifiers(ctx->kb, ctx->mod_state, 0, 0, 0);
return 0;
}
int ufkbd_wl_input_init(struct ufkbd_input_wayland *ufkbd_wl,
struct ufkbd_wl_input **out)
{
struct ufkbd_wl_input *ctx;
int ret;
ctx = calloc(1, sizeof(*ctx));
if (ctx == NULL)
return -errno;
ctx->ufkbd_wl = ufkbd_wl;
ctx->listener_seat.iface = &wl_seat_interface;
ctx->listener_seat.cb = on_global_seat;
ctx->listener_seat.data = ctx;
ret = ufkbd_wl_global_listener_add(ufkbd_wl, &ctx->listener_seat);
if (ret)
goto err;
ctx->listener_manager.iface = &zwp_virtual_keyboard_manager_v1_interface;
ctx->listener_manager.cb = on_global_vkman;
ctx->listener_manager.data = ctx;
ret = ufkbd_wl_global_listener_add(ufkbd_wl, &ctx->listener_manager);
if (ret)
goto err;
*out = ctx;
return 0;
err:
free(ctx);
return ret;
}
void ufkbd_wl_input_uninit(struct ufkbd_wl_input *ctx)
{
if (ctx->touch != NULL)
wl_touch_destroy(ctx->touch);
if (ctx->pointer != NULL)
wl_pointer_destroy(ctx->pointer);
if (ctx->seat != NULL)
wl_seat_destroy(ctx->seat);
if (ctx->kb != NULL)
zwp_virtual_keyboard_v1_destroy(ctx->kb);
if (ctx->manager != NULL)
zwp_virtual_keyboard_manager_v1_destroy(ctx->manager);
free(ctx);
}

View file

@ -0,0 +1,73 @@
/* Generated by wayland-scanner 1.22.0 */
/*
* Copyright © 2022 Kenny Levinsen
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface wp_fractional_scale_v1_interface;
static const struct wl_interface *fractional_scale_v1_types[] = {
NULL,
&wp_fractional_scale_v1_interface,
&wl_surface_interface,
};
static const struct wl_message wp_fractional_scale_manager_v1_requests[] = {
{ "destroy", "", fractional_scale_v1_types + 0 },
{ "get_fractional_scale", "no", fractional_scale_v1_types + 1 },
};
WL_PRIVATE const struct wl_interface wp_fractional_scale_manager_v1_interface = {
"wp_fractional_scale_manager_v1", 1,
2, wp_fractional_scale_manager_v1_requests,
0, NULL,
};
static const struct wl_message wp_fractional_scale_v1_requests[] = {
{ "destroy", "", fractional_scale_v1_types + 0 },
};
static const struct wl_message wp_fractional_scale_v1_events[] = {
{ "preferred_scale", "u", fractional_scale_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface wp_fractional_scale_v1_interface = {
"wp_fractional_scale_v1", 1,
1, wp_fractional_scale_v1_requests,
1, wp_fractional_scale_v1_events,
};

View file

@ -0,0 +1,132 @@
/* Generated by wayland-scanner 1.22.0 */
/*
* Copyright © 2008-2011 Kristian Høgsberg
* Copyright © 2010-2011 Intel Corporation
* Copyright © 2012-2013 Collabora, Ltd.
* Copyright © 2012, 2013 Intel Corporation
* Copyright © 2015, 2016 Jan Arne Petersen
* Copyright © 2017, 2018 Red Hat, Inc.
* Copyright © 2018 Purism SPC
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_seat_interface;
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface zwp_input_method_keyboard_grab_v2_interface;
extern const struct wl_interface zwp_input_method_v2_interface;
extern const struct wl_interface zwp_input_popup_surface_v2_interface;
static const struct wl_interface *input_method_unstable_v2_types[] = {
NULL,
NULL,
NULL,
NULL,
NULL,
&zwp_input_popup_surface_v2_interface,
&wl_surface_interface,
&zwp_input_method_keyboard_grab_v2_interface,
&wl_seat_interface,
&zwp_input_method_v2_interface,
};
static const struct wl_message zwp_input_method_v2_requests[] = {
{ "commit_string", "s", input_method_unstable_v2_types + 0 },
{ "set_preedit_string", "sii", input_method_unstable_v2_types + 0 },
{ "delete_surrounding_text", "uu", input_method_unstable_v2_types + 0 },
{ "commit", "u", input_method_unstable_v2_types + 0 },
{ "get_input_popup_surface", "no", input_method_unstable_v2_types + 5 },
{ "grab_keyboard", "n", input_method_unstable_v2_types + 7 },
{ "destroy", "", input_method_unstable_v2_types + 0 },
};
static const struct wl_message zwp_input_method_v2_events[] = {
{ "activate", "", input_method_unstable_v2_types + 0 },
{ "deactivate", "", input_method_unstable_v2_types + 0 },
{ "surrounding_text", "suu", input_method_unstable_v2_types + 0 },
{ "text_change_cause", "u", input_method_unstable_v2_types + 0 },
{ "content_type", "uu", input_method_unstable_v2_types + 0 },
{ "done", "", input_method_unstable_v2_types + 0 },
{ "unavailable", "", input_method_unstable_v2_types + 0 },
};
WL_PRIVATE const struct wl_interface zwp_input_method_v2_interface = {
"zwp_input_method_v2", 1,
7, zwp_input_method_v2_requests,
7, zwp_input_method_v2_events,
};
static const struct wl_message zwp_input_popup_surface_v2_requests[] = {
{ "destroy", "", input_method_unstable_v2_types + 0 },
};
static const struct wl_message zwp_input_popup_surface_v2_events[] = {
{ "text_input_rectangle", "iiii", input_method_unstable_v2_types + 0 },
};
WL_PRIVATE const struct wl_interface zwp_input_popup_surface_v2_interface = {
"zwp_input_popup_surface_v2", 1,
1, zwp_input_popup_surface_v2_requests,
1, zwp_input_popup_surface_v2_events,
};
static const struct wl_message zwp_input_method_keyboard_grab_v2_requests[] = {
{ "release", "", input_method_unstable_v2_types + 0 },
};
static const struct wl_message zwp_input_method_keyboard_grab_v2_events[] = {
{ "keymap", "uhu", input_method_unstable_v2_types + 0 },
{ "key", "uuuu", input_method_unstable_v2_types + 0 },
{ "modifiers", "uuuuu", input_method_unstable_v2_types + 0 },
{ "repeat_info", "ii", input_method_unstable_v2_types + 0 },
};
WL_PRIVATE const struct wl_interface zwp_input_method_keyboard_grab_v2_interface = {
"zwp_input_method_keyboard_grab_v2", 1,
1, zwp_input_method_keyboard_grab_v2_requests,
4, zwp_input_method_keyboard_grab_v2_events,
};
static const struct wl_message zwp_input_method_manager_v2_requests[] = {
{ "get_input_method", "on", input_method_unstable_v2_types + 8 },
{ "destroy", "", input_method_unstable_v2_types + 0 },
};
WL_PRIVATE const struct wl_interface zwp_input_method_manager_v2_interface = {
"zwp_input_method_manager_v2", 1,
2, zwp_input_method_manager_v2_requests,
0, NULL,
};

View file

@ -0,0 +1,493 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="input_method_unstable_v2">
<copyright>
Copyright © 2008-2011 Kristian Høgsberg
Copyright © 2010-2011 Intel Corporation
Copyright © 2012-2013 Collabora, Ltd.
Copyright © 2012, 2013 Intel Corporation
Copyright © 2015, 2016 Jan Arne Petersen
Copyright © 2017, 2018 Red Hat, Inc.
Copyright © 2018 Purism SPC
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<description summary="Protocol for creating input methods">
This protocol allows applications to act as input methods for compositors.
An input method context is used to manage the state of the input method.
Text strings are UTF-8 encoded, their indices and lengths are in bytes.
This document adheres to the RFC 2119 when using words like "must",
"should", "may", etc.
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.
This protocol is copied from the Squeekboard and should be brought
up-to-date with it whenever upstream changes.
</description>
<interface name="zwp_input_method_v2" version="1">
<description summary="input method">
An input method object allows for clients to compose text.
The objects connects the client to a text input in an application, and
lets the client to serve as an input method for a seat.
The zwp_input_method_v2 object can occupy two distinct states: active and
inactive. In the active state, the object is associated to and
communicates with a text input. In the inactive state, there is no
associated text input, and the only communication is with the compositor.
Initially, the input method is in the inactive state.
Requests issued in the inactive state must be accepted by the compositor.
Because of the serial mechanism, and the state reset on activate event,
they will not have any effect on the state of the next text input.
There must be no more than one input method object per seat.
</description>
<event name="activate">
<description summary="input method has been requested">
Notification that a text input focused on this seat requested the input
method to be activated.
This event serves the purpose of providing the compositor with an
active input method.
This event resets all state associated with previous enable, disable,
surrounding_text, text_change_cause, and content_type events, as well
as the state associated with set_preedit_string, commit_string, and
delete_surrounding_text requests. In addition, it marks the
zwp_input_method_v2 object as active, and makes any existing
zwp_input_popup_surface_v2 objects visible.
The surrounding_text, and content_type events must follow before the
next done event if the text input supports the respective
functionality.
State set with this event is double-buffered. It will get applied on
the next zwp_input_method_v2.done event, and stay valid until changed.
</description>
</event>
<event name="deactivate">
<description summary="deactivate event">
Notification that no focused text input currently needs an active
input method on this seat.
This event marks the zwp_input_method_v2 object as inactive. The
compositor must make all existing zwp_input_popup_surface_v2 objects
invisible until the next activate event.
State set with this event is double-buffered. It will get applied on
the next zwp_input_method_v2.done event, and stay valid until changed.
</description>
</event>
<event name="surrounding_text">
<description summary="surrounding text event">
Updates the surrounding plain text around the cursor, excluding the
preedit text.
If any preedit text is present, it is replaced with the cursor for the
purpose of this event.
The argument text is a buffer containing the preedit string, and must
include the cursor position, and the complete selection. It should
contain additional characters before and after these. There is a
maximum length of wayland messages, so text can not be longer than 4000
bytes.
cursor is the byte offset of the cursor within the text buffer.
anchor is the byte offset of the selection anchor within the text
buffer. If there is no selected text, anchor must be the same as
cursor.
If this event does not arrive before the first done event, the input
method may assume that the text input does not support this
functionality and ignore following surrounding_text events.
Values set with this event are double-buffered. They will get applied
and set to initial values on the next zwp_input_method_v2.done
event.
The initial state for affected fields is empty, meaning that the text
input does not support sending surrounding text. If the empty values
get applied, subsequent attempts to change them may have no effect.
</description>
<arg name="text" type="string"/>
<arg name="cursor" type="uint"/>
<arg name="anchor" type="uint"/>
</event>
<event name="text_change_cause">
<description summary="indicates the cause of surrounding text change">
Tells the input method why the text surrounding the cursor changed.
Whenever the client detects an external change in text, cursor, or
anchor position, it must issue this request to the compositor. This
request is intended to give the input method a chance to update the
preedit text in an appropriate way, e.g. by removing it when the user
starts typing with a keyboard.
cause describes the source of the change.
The value set with this event is double-buffered. It will get applied
and set to its initial value on the next zwp_input_method_v2.done
event.
The initial value of cause is input_method.
</description>
<arg name="cause" type="uint" enum="zwp_text_input_v3.change_cause"/>
</event>
<event name="content_type">
<description summary="content purpose and hint">
Indicates the content type and hint for the current
zwp_input_method_v2 instance.
Values set with this event are double-buffered. They will get applied
on the next zwp_input_method_v2.done event.
The initial value for hint is none, and the initial value for purpose
is normal.
</description>
<arg name="hint" type="uint" enum="zwp_text_input_v3.content_hint"/>
<arg name="purpose" type="uint" enum="zwp_text_input_v3.content_purpose"/>
</event>
<event name="done">
<description summary="apply state">
Atomically applies state changes recently sent to the client.
The done event establishes and updates the state of the client, and
must be issued after any changes to apply them.
Text input state (content purpose, content hint, surrounding text, and
change cause) is conceptually double-buffered within an input method
context.
Events modify the pending state, as opposed to the current state in use
by the input method. A done event atomically applies all pending state,
replacing the current state. After done, the new pending state is as
documented for each related request.
Events must be applied in the order of arrival.
Neither current nor pending state are modified unless noted otherwise.
</description>
</event>
<request name="commit_string">
<description summary="commit string">
Send the commit string text for insertion to the application.
Inserts a string at current cursor position (see commit event
sequence). The string to commit could be either just a single character
after a key press or the result of some composing.
The argument text is a buffer containing the string to insert. There is
a maximum length of wayland messages, so text can not be longer than
4000 bytes.
Values set with this event are double-buffered. They must be applied
and reset to initial on the next zwp_text_input_v3.commit request.
The initial value of text is an empty string.
</description>
<arg name="text" type="string"/>
</request>
<request name="set_preedit_string">
<description summary="pre-edit string">
Send the pre-edit string text to the application text input.
Place a new composing text (pre-edit) at the current cursor position.
Any previously set composing text must be removed. Any previously
existing selected text must be removed. The cursor is moved to a new
position within the preedit string.
The argument text is a buffer containing the preedit string. There is
a maximum length of wayland messages, so text can not be longer than
4000 bytes.
The arguments cursor_begin and cursor_end are counted in bytes relative
to the beginning of the submitted string buffer. Cursor should be
hidden by the text input when both are equal to -1.
cursor_begin indicates the beginning of the cursor. cursor_end
indicates the end of the cursor. It may be equal or different than
cursor_begin.
Values set with this event are double-buffered. They must be applied on
the next zwp_input_method_v2.commit event.
The initial value of text is an empty string. The initial value of
cursor_begin, and cursor_end are both 0.
</description>
<arg name="text" type="string"/>
<arg name="cursor_begin" type="int"/>
<arg name="cursor_end" type="int"/>
</request>
<request name="delete_surrounding_text">
<description summary="delete text">
Remove the surrounding text.
before_length and after_length are the number of bytes before and after
the current cursor index (excluding the preedit text) to delete.
If any preedit text is present, it is replaced with the cursor for the
purpose of this event. In effect before_length is counted from the
beginning of preedit text, and after_length from its end (see commit
event sequence).
Values set with this event are double-buffered. They must be applied
and reset to initial on the next zwp_input_method_v2.commit request.
The initial values of both before_length and after_length are 0.
</description>
<arg name="before_length" type="uint"/>
<arg name="after_length" type="uint"/>
</request>
<request name="commit">
<description summary="apply state">
Apply state changes from commit_string, set_preedit_string and
delete_surrounding_text requests.
The state relating to these events is double-buffered, and each one
modifies the pending state. This request replaces the current state
with the pending state.
The connected text input is expected to proceed by evaluating the
changes in the following order:
1. Replace existing preedit string with the cursor.
2. Delete requested surrounding text.
3. Insert commit string with the cursor at its end.
4. Calculate surrounding text to send.
5. Insert new preedit text in cursor position.
6. Place cursor inside preedit text.
The serial number reflects the last state of the zwp_input_method_v2
object known to the client. The value of the serial argument must be
equal to the number of done events already issued by that object. When
the compositor receives a commit request with a serial different than
the number of past done events, it must proceed as normal, except it
should not change the current state of the zwp_input_method_v2 object.
</description>
<arg name="serial" type="uint"/>
</request>
<request name="get_input_popup_surface">
<description summary="create popup surface">
Creates a new zwp_input_popup_surface_v2 object wrapping a given
surface.
The surface gets assigned the "input_popup" role. If the surface
already has an assigned role, the compositor must issue a protocol
error.
</description>
<arg name="id" type="new_id" interface="zwp_input_popup_surface_v2"/>
<arg name="surface" type="object" interface="wl_surface"/>
</request>
<request name="grab_keyboard">
<description summary="grab hardware keyboard">
Allow an input method to receive hardware keyboard input and process
key events to generate text events (with pre-edit) over the wire. This
allows input methods which compose multiple key events for inputting
text like it is done for CJK languages.
The compositor should send all keyboard events on the seat to the grab
holder via the returned wl_keyboard object. Nevertheless, the
compositor may decide not to forward any particular event. The
compositor must not further process any event after it has been
forwarded to the grab holder.
Releasing the resulting wl_keyboard object releases the grab.
</description>
<arg name="keyboard" type="new_id"
interface="zwp_input_method_keyboard_grab_v2"/>
</request>
<event name="unavailable">
<description summary="input method unavailable">
The input method ceased to be available.
The compositor must issue this event as the only event on the object if
there was another input_method object associated with the same seat at
the time of its creation.
The compositor must issue this request when the object is no longer
useable, e.g. due to seat removal.
The input method context becomes inert and should be destroyed after
deactivation is handled. Any further requests and events except for the
destroy request must be ignored.
</description>
</event>
<request name="destroy" type="destructor">
<description summary="destroy the text input">
Destroys the zwp_text_input_v2 object and any associated child
objects, i.e. zwp_input_popup_surface_v2 and
zwp_input_method_keyboard_grab_v2.
</description>
</request>
</interface>
<interface name="zwp_input_popup_surface_v2" version="1">
<description summary="popup surface">
This interface marks a surface as a popup for interacting with an input
method.
The compositor should place it near the active text input area. It must
be visible if and only if the input method is in the active state.
The client must not destroy the underlying wl_surface while the
zwp_input_popup_surface_v2 object exists.
</description>
<event name="text_input_rectangle">
<description summary="set text input area position">
Notify about the position of the area of the text input expressed as a
rectangle in surface local coordinates.
This is a hint to the input method telling it the relative position of
the text being entered.
</description>
<arg name="x" type="int"/>
<arg name="y" type="int"/>
<arg name="width" type="int"/>
<arg name="height" type="int"/>
</event>
<request name="destroy" type="destructor"/>
</interface>
<interface name="zwp_input_method_keyboard_grab_v2" version="1">
<!-- Closely follows wl_keyboard version 6 -->
<description summary="keyboard grab">
The zwp_input_method_keyboard_grab_v2 interface represents an exclusive
grab of the wl_keyboard interface associated with the seat.
</description>
<event name="keymap">
<description summary="keyboard mapping">
This event provides a file descriptor to the client which can be
memory-mapped to provide a keyboard mapping description.
</description>
<arg name="format" type="uint" enum="wl_keyboard.keymap_format"
summary="keymap format"/>
<arg name="fd" type="fd" summary="keymap file descriptor"/>
<arg name="size" type="uint" summary="keymap size, in bytes"/>
</event>
<event name="key">
<description summary="key event">
A key was pressed or released.
The time argument is a timestamp with millisecond granularity, with an
undefined base.
</description>
<arg name="serial" type="uint" summary="serial number of the key event"/>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="key" type="uint" summary="key that produced the event"/>
<arg name="state" type="uint" enum="wl_keyboard.key_state"
summary="physical state of the key"/>
</event>
<event name="modifiers">
<description summary="modifier and group state">
Notifies clients that the modifier and/or group state has changed, and
it should update its local state.
</description>
<arg name="serial" type="uint" summary="serial number of the modifiers event"/>
<arg name="mods_depressed" type="uint" summary="depressed modifiers"/>
<arg name="mods_latched" type="uint" summary="latched modifiers"/>
<arg name="mods_locked" type="uint" summary="locked modifiers"/>
<arg name="group" type="uint" summary="keyboard layout"/>
</event>
<request name="release" type="destructor">
<description summary="release the grab object"/>
</request>
<event name="repeat_info">
<description summary="repeat rate and delay">
Informs the client about the keyboard's repeat rate and delay.
This event is sent as soon as the zwp_input_method_keyboard_grab_v2
object has been created, and is guaranteed to be received by the
client before any key press event.
Negative values for either rate or delay are illegal. A rate of zero
will disable any repeating (regardless of the value of delay).
This event can be sent later on as well with a new value if necessary,
so clients should continue listening for the event past the creation
of zwp_input_method_keyboard_grab_v2.
</description>
<arg name="rate" type="int"
summary="the rate of repeating keys in characters per second"/>
<arg name="delay" type="int"
summary="delay in milliseconds since key down until repeating starts"/>
</event>
</interface>
<interface name="zwp_input_method_manager_v2" version="1">
<description summary="input method manager">
The input method manager allows the client to become the input method on
a chosen seat.
No more than one input method must be associated with any seat at any
given time.
</description>
<request name="get_input_method">
<description summary="request an input method object">
Request a new input zwp_input_method_v2 object associated with a given
seat.
</description>
<arg name="seat" type="object" interface="wl_seat"/>
<arg name="input_method" type="new_id" interface="zwp_input_method_v2"/>
</request>
<request name="destroy" type="destructor">
<description summary="destroy the input method manager">
Destroys the zwp_input_method_manager_v2 object.
The zwp_input_method_v2 objects originating from it remain valid.
</description>
</request>
</interface>
</protocol>

View file

@ -0,0 +1,74 @@
/* Generated by wayland-scanner 1.22.0 */
/*
* Copyright © 2013-2016 Collabora, Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface wp_viewport_interface;
static const struct wl_interface *viewporter_types[] = {
NULL,
NULL,
NULL,
NULL,
&wp_viewport_interface,
&wl_surface_interface,
};
static const struct wl_message wp_viewporter_requests[] = {
{ "destroy", "", viewporter_types + 0 },
{ "get_viewport", "no", viewporter_types + 4 },
};
WL_PRIVATE const struct wl_interface wp_viewporter_interface = {
"wp_viewporter", 1,
2, wp_viewporter_requests,
0, NULL,
};
static const struct wl_message wp_viewport_requests[] = {
{ "destroy", "", viewporter_types + 0 },
{ "set_source", "ffff", viewporter_types + 0 },
{ "set_destination", "ii", viewporter_types + 0 },
};
WL_PRIVATE const struct wl_interface wp_viewport_interface = {
"wp_viewport", 1,
3, wp_viewport_requests,
0, NULL,
};

View file

@ -0,0 +1,77 @@
/* Generated by wayland-scanner 1.22.0 */
/*
* Copyright © 2008-2011 Kristian Høgsberg
* Copyright © 2010-2013 Intel Corporation
* Copyright © 2012-2013 Collabora, Ltd.
* Copyright © 2018 Purism SPC
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_seat_interface;
extern const struct wl_interface zwp_virtual_keyboard_v1_interface;
static const struct wl_interface *virtual_keyboard_unstable_v1_types[] = {
NULL,
NULL,
NULL,
NULL,
&wl_seat_interface,
&zwp_virtual_keyboard_v1_interface,
};
static const struct wl_message zwp_virtual_keyboard_v1_requests[] = {
{ "keymap", "uhu", virtual_keyboard_unstable_v1_types + 0 },
{ "key", "uuu", virtual_keyboard_unstable_v1_types + 0 },
{ "modifiers", "uuuu", virtual_keyboard_unstable_v1_types + 0 },
{ "destroy", "", virtual_keyboard_unstable_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface zwp_virtual_keyboard_v1_interface = {
"zwp_virtual_keyboard_v1", 1,
4, zwp_virtual_keyboard_v1_requests,
0, NULL,
};
static const struct wl_message zwp_virtual_keyboard_manager_v1_requests[] = {
{ "create_virtual_keyboard", "on", virtual_keyboard_unstable_v1_types + 4 },
};
WL_PRIVATE const struct wl_interface zwp_virtual_keyboard_manager_v1_interface = {
"zwp_virtual_keyboard_manager_v1", 1,
1, zwp_virtual_keyboard_manager_v1_requests,
0, NULL,
};

View file

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="virtual_keyboard_unstable_v1">
<copyright>
Copyright © 2008-2011 Kristian Høgsberg
Copyright © 2010-2013 Intel Corporation
Copyright © 2012-2013 Collabora, Ltd.
Copyright © 2018 Purism SPC
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<description>
This protocol is copied from the Squeekboard and should be brought
up-to-date with it whenever upstream changes.
</description>
<interface name="zwp_virtual_keyboard_v1" version="1">
<description summary="virtual keyboard">
The virtual keyboard provides an application with requests which emulate
the behaviour of a physical keyboard.
This interface can be used by clients on its own to provide raw input
events, or it can accompany the input method protocol.
</description>
<request name="keymap">
<description summary="keyboard mapping">
Provide a file descriptor to the compositor which can be
memory-mapped to provide a keyboard mapping description.
Format carries a value from the keymap_format enumeration.
</description>
<arg name="format" type="uint" summary="keymap format"/>
<arg name="fd" type="fd" summary="keymap file descriptor"/>
<arg name="size" type="uint" summary="keymap size, in bytes"/>
</request>
<enum name="error">
<entry name="no_keymap" value="0" summary="No keymap was set"/>
</enum>
<request name="key">
<description summary="key event">
A key was pressed or released.
The time argument is a timestamp with millisecond granularity, with an
undefined base. All requests regarding a single object must share the
same clock.
Keymap must be set before issuing this request.
State carries a value from the key_state enumeration.
</description>
<arg name="time" type="uint" summary="timestamp with millisecond granularity"/>
<arg name="key" type="uint" summary="key that produced the event"/>
<arg name="state" type="uint" summary="physical state of the key"/>
</request>
<request name="modifiers">
<description summary="modifier and group state">
Notifies the compositor that the modifier and/or group state has
changed, and it should update state.
The client should use wl_keyboard.modifiers event to synchronize its
internal state with seat state.
Keymap must be set before issuing this request.
</description>
<arg name="mods_depressed" type="uint" summary="depressed modifiers"/>
<arg name="mods_latched" type="uint" summary="latched modifiers"/>
<arg name="mods_locked" type="uint" summary="locked modifiers"/>
<arg name="group" type="uint" summary="keyboard layout"/>
</request>
<request name="destroy" type="destructor" since="1">
<description summary="destroy the virtual keyboard keyboard object"/>
</request>
</interface>
<interface name="zwp_virtual_keyboard_manager_v1" version="1">
<description summary="virtual keyboard manager">
A virtual keyboard manager allows an application to provide keyboard
input events as if they came from a physical keyboard.
</description>
<enum name="error">
<entry name="unauthorized" value="0" summary="client not authorized to use the interface"/>
</enum>
<request name="create_virtual_keyboard">
<description summary="Create a new virtual keyboard">
Creates a new virtual keyboard associated to a seat.
If the compositor enables a keyboard to perform arbitrary actions, it
should present an error when an untrusted client requests a new
keyboard.
</description>
<arg name="seat" type="object" interface="wl_seat"/>
<arg name="id" type="new_id" interface="zwp_virtual_keyboard_v1"/>
</request>
</interface>
</protocol>

View file

@ -0,0 +1,93 @@
/* Generated by wayland-scanner 1.22.0 */
/*
* Copyright © 2017 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.
*/
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_output_interface;
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface xdg_popup_interface;
extern const struct wl_interface zwlr_layer_surface_v1_interface;
static const struct wl_interface *wlr_layer_shell_unstable_v1_types[] = {
NULL,
NULL,
NULL,
NULL,
&zwlr_layer_surface_v1_interface,
&wl_surface_interface,
&wl_output_interface,
NULL,
NULL,
&xdg_popup_interface,
};
static const struct wl_message zwlr_layer_shell_v1_requests[] = {
{ "get_layer_surface", "no?ous", wlr_layer_shell_unstable_v1_types + 4 },
{ "destroy", "3", wlr_layer_shell_unstable_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface zwlr_layer_shell_v1_interface = {
"zwlr_layer_shell_v1", 4,
2, zwlr_layer_shell_v1_requests,
0, NULL,
};
static const struct wl_message zwlr_layer_surface_v1_requests[] = {
{ "set_size", "uu", wlr_layer_shell_unstable_v1_types + 0 },
{ "set_anchor", "u", wlr_layer_shell_unstable_v1_types + 0 },
{ "set_exclusive_zone", "i", wlr_layer_shell_unstable_v1_types + 0 },
{ "set_margin", "iiii", wlr_layer_shell_unstable_v1_types + 0 },
{ "set_keyboard_interactivity", "u", wlr_layer_shell_unstable_v1_types + 0 },
{ "get_popup", "o", wlr_layer_shell_unstable_v1_types + 9 },
{ "ack_configure", "u", wlr_layer_shell_unstable_v1_types + 0 },
{ "destroy", "", wlr_layer_shell_unstable_v1_types + 0 },
{ "set_layer", "2u", wlr_layer_shell_unstable_v1_types + 0 },
};
static const struct wl_message zwlr_layer_surface_v1_events[] = {
{ "configure", "uuu", wlr_layer_shell_unstable_v1_types + 0 },
{ "closed", "", wlr_layer_shell_unstable_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface zwlr_layer_surface_v1_interface = {
"zwlr_layer_surface_v1", 4,
9, zwlr_layer_surface_v1_requests,
2, zwlr_layer_surface_v1_events,
};

View file

@ -0,0 +1,390 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="wlr_layer_shell_unstable_v1">
<copyright>
Copyright © 2017 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_layer_shell_v1" version="4">
<description summary="create surfaces that are layers of the desktop">
Clients can use this interface to assign the surface_layer role to
wl_surfaces. Such surfaces are assigned to a "layer" of the output and
rendered with a defined z-depth respective to each other. They may also be
anchored to the edges and corners of a screen and specify input handling
semantics. This interface should be suitable for the implementation of
many desktop shell components, and a broad number of other applications
that interact with the desktop.
</description>
<request name="get_layer_surface">
<description summary="create a layer_surface from a surface">
Create a layer surface for an existing surface. This assigns the role of
layer_surface, or raises a protocol error if another role is already
assigned.
Creating a layer surface from a wl_surface which has a buffer attached
or committed is a client error, and any attempts by a client to attach
or manipulate a buffer prior to the first layer_surface.configure call
must also be treated as errors.
After creating a layer_surface object and setting it up, the client
must perform an initial commit without any buffer attached.
The compositor will reply with a layer_surface.configure event.
The client must acknowledge it and is then allowed to attach a buffer
to map the surface.
You may pass NULL for output to allow the compositor to decide which
output to use. Generally this will be the one that the user most
recently interacted with.
Clients can specify a namespace that defines the purpose of the layer
surface.
</description>
<arg name="id" type="new_id" interface="zwlr_layer_surface_v1"/>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="output" type="object" interface="wl_output" allow-null="true"/>
<arg name="layer" type="uint" enum="layer" summary="layer to add this surface to"/>
<arg name="namespace" type="string" summary="namespace for the layer surface"/>
</request>
<enum name="error">
<entry name="role" value="0" summary="wl_surface has another role"/>
<entry name="invalid_layer" value="1" summary="layer value is invalid"/>
<entry name="already_constructed" value="2" summary="wl_surface has a buffer attached or committed"/>
</enum>
<enum name="layer">
<description summary="available layers for surfaces">
These values indicate which layers a surface can be rendered in. They
are ordered by z depth, bottom-most first. Traditional shell surfaces
will typically be rendered between the bottom and top layers.
Fullscreen shell surfaces are typically rendered at the top layer.
Multiple surfaces can share a single layer, and ordering within a
single layer is undefined.
</description>
<entry name="background" value="0"/>
<entry name="bottom" value="1"/>
<entry name="top" value="2"/>
<entry name="overlay" value="3"/>
</enum>
<!-- Version 3 additions -->
<request name="destroy" type="destructor" since="3">
<description summary="destroy the layer_shell object">
This request indicates that the client will not use the layer_shell
object any more. Objects that have been created through this instance
are not affected.
</description>
</request>
</interface>
<interface name="zwlr_layer_surface_v1" version="4">
<description summary="layer metadata interface">
An interface that may be implemented by a wl_surface, for surfaces that
are designed to be rendered as a layer of a stacked desktop-like
environment.
Layer surface state (layer, size, anchor, exclusive zone,
margin, interactivity) is double-buffered, and will be applied at the
time wl_surface.commit of the corresponding wl_surface is called.
Attaching a null buffer to a layer surface unmaps it.
Unmapping a layer_surface means that the surface cannot be shown by the
compositor until it is explicitly mapped again. The layer_surface
returns to the state it had right after layer_shell.get_layer_surface.
The client can re-map the surface by performing a commit without any
buffer attached, waiting for a configure event and handling it as usual.
</description>
<request name="set_size">
<description summary="sets the size of the surface">
Sets the size of the surface in surface-local coordinates. The
compositor will display the surface centered with respect to its
anchors.
If you pass 0 for either value, the compositor will assign it and
inform you of the assignment in the configure event. You must set your
anchor to opposite edges in the dimensions you omit; not doing so is a
protocol error. Both values are 0 by default.
Size is double-buffered, see wl_surface.commit.
</description>
<arg name="width" type="uint"/>
<arg name="height" type="uint"/>
</request>
<request name="set_anchor">
<description summary="configures the anchor point of the surface">
Requests that the compositor anchor the surface to the specified edges
and corners. If two orthogonal edges are specified (e.g. 'top' and
'left'), then the anchor point will be the intersection of the edges
(e.g. the top left corner of the output); otherwise the anchor point
will be centered on that edge, or in the center if none is specified.
Anchor is double-buffered, see wl_surface.commit.
</description>
<arg name="anchor" type="uint" enum="anchor"/>
</request>
<request name="set_exclusive_zone">
<description summary="configures the exclusive geometry of this surface">
Requests that the compositor avoids occluding an area with other
surfaces. The compositor's use of this information is
implementation-dependent - do not assume that this region will not
actually be occluded.
A positive value is only meaningful if the surface is anchored to one
edge or an edge and both perpendicular edges. If the surface is not
anchored, anchored to only two perpendicular edges (a corner), anchored
to only two parallel edges or anchored to all edges, a positive value
will be treated the same as zero.
A positive zone is the distance from the edge in surface-local
coordinates to consider exclusive.
Surfaces that do not wish to have an exclusive zone may instead specify
how they should interact with surfaces that do. If set to zero, the
surface indicates that it would like to be moved to avoid occluding
surfaces with a positive exclusive zone. If set to -1, the surface
indicates that it would not like to be moved to accommodate for other
surfaces, and the compositor should extend it all the way to the edges
it is anchored to.
For example, a panel might set its exclusive zone to 10, so that
maximized shell surfaces are not shown on top of it. A notification
might set its exclusive zone to 0, so that it is moved to avoid
occluding the panel, but shell surfaces are shown underneath it. A
wallpaper or lock screen might set their exclusive zone to -1, so that
they stretch below or over the panel.
The default value is 0.
Exclusive zone is double-buffered, see wl_surface.commit.
</description>
<arg name="zone" type="int"/>
</request>
<request name="set_margin">
<description summary="sets a margin from the anchor point">
Requests that the surface be placed some distance away from the anchor
point on the output, in surface-local coordinates. Setting this value
for edges you are not anchored to has no effect.
The exclusive zone includes the margin.
Margin is double-buffered, see wl_surface.commit.
</description>
<arg name="top" type="int"/>
<arg name="right" type="int"/>
<arg name="bottom" type="int"/>
<arg name="left" type="int"/>
</request>
<enum name="keyboard_interactivity">
<description summary="types of keyboard interaction possible for a layer shell surface">
Types of keyboard interaction possible for layer shell surfaces. The
rationale for this is twofold: (1) some applications are not interested
in keyboard events and not allowing them to be focused can improve the
desktop experience; (2) some applications will want to take exclusive
keyboard focus.
</description>
<entry name="none" value="0">
<description summary="no keyboard focus is possible">
This value indicates that this surface is not interested in keyboard
events and the compositor should never assign it the keyboard focus.
This is the default value, set for newly created layer shell surfaces.
This is useful for e.g. desktop widgets that display information or
only have interaction with non-keyboard input devices.
</description>
</entry>
<entry name="exclusive" value="1">
<description summary="request exclusive keyboard focus">
Request exclusive keyboard focus if this surface is above the shell surface layer.
For the top and overlay layers, the seat will always give
exclusive keyboard focus to the top-most layer which has keyboard
interactivity set to exclusive. If this layer contains multiple
surfaces with keyboard interactivity set to exclusive, the compositor
determines the one receiving keyboard events in an implementation-
defined manner. In this case, no guarantee is made when this surface
will receive keyboard focus (if ever).
For the bottom and background layers, the compositor is allowed to use
normal focus semantics.
This setting is mainly intended for applications that need to ensure
they receive all keyboard events, such as a lock screen or a password
prompt.
</description>
</entry>
<entry name="on_demand" value="2" since="4">
<description summary="request regular keyboard focus semantics">
This requests the compositor to allow this surface to be focused and
unfocused by the user in an implementation-defined manner. The user
should be able to unfocus this surface even regardless of the layer
it is on.
Typically, the compositor will want to use its normal mechanism to
manage keyboard focus between layer shell surfaces with this setting
and regular toplevels on the desktop layer (e.g. click to focus).
Nevertheless, it is possible for a compositor to require a special
interaction to focus or unfocus layer shell surfaces (e.g. requiring
a click even if focus follows the mouse normally, or providing a
keybinding to switch focus between layers).
This setting is mainly intended for desktop shell components (e.g.
panels) that allow keyboard interaction. Using this option can allow
implementing a desktop shell that can be fully usable without the
mouse.
</description>
</entry>
</enum>
<request name="set_keyboard_interactivity">
<description summary="requests keyboard events">
Set how keyboard events are delivered to this surface. By default,
layer shell surfaces do not receive keyboard events; this request can
be used to change this.
This setting is inherited by child surfaces set by the get_popup
request.
Layer surfaces receive pointer, touch, and tablet events normally. If
you do not want to receive them, set the input region on your surface
to an empty region.
Keyboard interactivity is double-buffered, see wl_surface.commit.
</description>
<arg name="keyboard_interactivity" type="uint" enum="keyboard_interactivity"/>
</request>
<request name="get_popup">
<description summary="assign this layer_surface as an xdg_popup parent">
This assigns an xdg_popup's parent to this layer_surface. This popup
should have been created via xdg_surface::get_popup with the parent set
to NULL, and this request must be invoked before committing the popup's
initial state.
See the documentation of xdg_popup for more details about what an
xdg_popup is and how it is used.
</description>
<arg name="popup" type="object" interface="xdg_popup"/>
</request>
<request name="ack_configure">
<description summary="ack a configure event">
When a configure event is received, if a client commits the
surface in response to the configure event, then the client
must make an ack_configure request sometime before the commit
request, passing along the serial of the configure event.
If the client receives multiple configure events before it
can respond to one, it only has to ack the last configure event.
A client is not required to commit immediately after sending
an ack_configure request - it may even ack_configure several times
before its next surface commit.
A client may send multiple ack_configure requests before committing, but
only the last request sent before a commit indicates which configure
event the client really is responding to.
</description>
<arg name="serial" type="uint" summary="the serial from the configure event"/>
</request>
<request name="destroy" type="destructor">
<description summary="destroy the layer_surface">
This request destroys the layer surface.
</description>
</request>
<event name="configure">
<description summary="suggest a surface change">
The configure event asks the client to resize its surface.
Clients should arrange their surface for the new states, and then send
an ack_configure request with the serial sent in this configure event at
some point before committing the new surface.
The client is free to dismiss all but the last configure event it
received.
The width and height arguments specify the size of the window in
surface-local coordinates.
The size is a hint, in the sense that the client is free to ignore it if
it doesn't resize, pick a smaller size (to satisfy aspect ratio or
resize in steps of NxM pixels). If the client picks a smaller size and
is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
surface will be centered on this axis.
If the width or height arguments are zero, it means the client should
decide its own window dimension.
</description>
<arg name="serial" type="uint"/>
<arg name="width" type="uint"/>
<arg name="height" type="uint"/>
</event>
<event name="closed">
<description summary="surface should be closed">
The closed event is sent by the compositor when the surface will no
longer be shown. The output may have been destroyed or the user may
have asked for it to be removed. Further changes to the surface will be
ignored. The client should destroy the resource after receiving this
event, and create a new surface if they so choose.
</description>
</event>
<enum name="error">
<entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
<entry name="invalid_size" value="1" summary="size is invalid"/>
<entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
<entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
</enum>
<enum name="anchor" bitfield="true">
<entry name="top" value="1" summary="the top edge of the anchor rectangle"/>
<entry name="bottom" value="2" summary="the bottom edge of the anchor rectangle"/>
<entry name="left" value="4" summary="the left edge of the anchor rectangle"/>
<entry name="right" value="8" summary="the right edge of the anchor rectangle"/>
</enum>
<!-- Version 2 additions -->
<request name="set_layer" since="2">
<description summary="change the layer of the surface">
Change the layer that the surface is rendered on.
Layer is double-buffered, see wl_surface.commit.
</description>
<arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/>
</request>
</interface>
</protocol>

View file

@ -0,0 +1,183 @@
/* Generated by wayland-scanner 1.22.0 */
/*
* Copyright © 2008-2013 Kristian Høgsberg
* Copyright © 2013 Rafael Antognolli
* Copyright © 2013 Jasper St. Pierre
* Copyright © 2010-2013 Intel Corporation
* Copyright © 2015-2017 Samsung Electronics Co., Ltd
* Copyright © 2015-2017 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_output_interface;
extern const struct wl_interface wl_seat_interface;
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface xdg_popup_interface;
extern const struct wl_interface xdg_positioner_interface;
extern const struct wl_interface xdg_surface_interface;
extern const struct wl_interface xdg_toplevel_interface;
static const struct wl_interface *xdg_shell_types[] = {
NULL,
NULL,
NULL,
NULL,
&xdg_positioner_interface,
&xdg_surface_interface,
&wl_surface_interface,
&xdg_toplevel_interface,
&xdg_popup_interface,
&xdg_surface_interface,
&xdg_positioner_interface,
&xdg_toplevel_interface,
&wl_seat_interface,
NULL,
NULL,
NULL,
&wl_seat_interface,
NULL,
&wl_seat_interface,
NULL,
NULL,
&wl_output_interface,
&wl_seat_interface,
NULL,
&xdg_positioner_interface,
NULL,
};
static const struct wl_message xdg_wm_base_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "create_positioner", "n", xdg_shell_types + 4 },
{ "get_xdg_surface", "no", xdg_shell_types + 5 },
{ "pong", "u", xdg_shell_types + 0 },
};
static const struct wl_message xdg_wm_base_events[] = {
{ "ping", "u", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_wm_base_interface = {
"xdg_wm_base", 6,
4, xdg_wm_base_requests,
1, xdg_wm_base_events,
};
static const struct wl_message xdg_positioner_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "set_size", "ii", xdg_shell_types + 0 },
{ "set_anchor_rect", "iiii", xdg_shell_types + 0 },
{ "set_anchor", "u", xdg_shell_types + 0 },
{ "set_gravity", "u", xdg_shell_types + 0 },
{ "set_constraint_adjustment", "u", xdg_shell_types + 0 },
{ "set_offset", "ii", xdg_shell_types + 0 },
{ "set_reactive", "3", xdg_shell_types + 0 },
{ "set_parent_size", "3ii", xdg_shell_types + 0 },
{ "set_parent_configure", "3u", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_positioner_interface = {
"xdg_positioner", 6,
10, xdg_positioner_requests,
0, NULL,
};
static const struct wl_message xdg_surface_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "get_toplevel", "n", xdg_shell_types + 7 },
{ "get_popup", "n?oo", xdg_shell_types + 8 },
{ "set_window_geometry", "iiii", xdg_shell_types + 0 },
{ "ack_configure", "u", xdg_shell_types + 0 },
};
static const struct wl_message xdg_surface_events[] = {
{ "configure", "u", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_surface_interface = {
"xdg_surface", 6,
5, xdg_surface_requests,
1, xdg_surface_events,
};
static const struct wl_message xdg_toplevel_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "set_parent", "?o", xdg_shell_types + 11 },
{ "set_title", "s", xdg_shell_types + 0 },
{ "set_app_id", "s", xdg_shell_types + 0 },
{ "show_window_menu", "ouii", xdg_shell_types + 12 },
{ "move", "ou", xdg_shell_types + 16 },
{ "resize", "ouu", xdg_shell_types + 18 },
{ "set_max_size", "ii", xdg_shell_types + 0 },
{ "set_min_size", "ii", xdg_shell_types + 0 },
{ "set_maximized", "", xdg_shell_types + 0 },
{ "unset_maximized", "", xdg_shell_types + 0 },
{ "set_fullscreen", "?o", xdg_shell_types + 21 },
{ "unset_fullscreen", "", xdg_shell_types + 0 },
{ "set_minimized", "", xdg_shell_types + 0 },
};
static const struct wl_message xdg_toplevel_events[] = {
{ "configure", "iia", xdg_shell_types + 0 },
{ "close", "", xdg_shell_types + 0 },
{ "configure_bounds", "4ii", xdg_shell_types + 0 },
{ "wm_capabilities", "5a", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_toplevel_interface = {
"xdg_toplevel", 6,
14, xdg_toplevel_requests,
4, xdg_toplevel_events,
};
static const struct wl_message xdg_popup_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "grab", "ou", xdg_shell_types + 22 },
{ "reposition", "3ou", xdg_shell_types + 24 },
};
static const struct wl_message xdg_popup_events[] = {
{ "configure", "iiii", xdg_shell_types + 0 },
{ "popup_done", "", xdg_shell_types + 0 },
{ "repositioned", "3u", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_popup_interface = {
"xdg_popup", 6,
3, xdg_popup_requests,
3, xdg_popup_events,
};

282
wayland/surface.c Normal file
View file

@ -0,0 +1,282 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Wayland buffer manager and surface.
*
* Copyright (c) 2024, Richard Acayan. All rights reserved.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <wayland-client-protocol.h>
#include "graphics.h"
#include "ufkbd.h"
#include "layout.h"
#include "wayland.h"
#include "wayland/viewporter.h"
#include "wayland/wlr-layer-shell-unstable-v1.h"
extern struct ufkbd_driver ufkbd_wayland;
static int ufkbd_wl_surface_resize_buffers(struct ufkbd_wl_surface *ctx,
uint32_t width, uint32_t height);
static void on_surface_configure(void *data,
struct zwlr_layer_surface_v1 *surface,
uint32_t serial,
uint32_t width,
uint32_t height)
{
struct ufkbd_wl_surface *ctx = data;
struct ufkbd_input_wayland *ufkbd_wl = ctx->ufkbd_wl;
struct ufkbd_ctx *ufkbd = ufkbd_wl->ufkbd;
zwlr_layer_surface_v1_ack_configure(surface, serial);
wp_viewport_set_source(ctx->vp, 0, 0, width * 256 * ctx->scale,
height * 256 * ctx->scale);
wp_viewport_set_destination(ctx->vp, width, height);
ufkbd_wl_surface_resize_buffers(ctx, width, height);
ufkbd_layout_resize(ufkbd->layout, width, height);
ufkbd_graphics_draw_layout(ufkbd, ufkbd_wl->ufkbd->layout,
width, height);
}
static void on_surface_closed(void *data,
struct zwlr_layer_surface_v1 *toplev)
{
struct ufkbd_wl_surface *ctx = data;
struct ufkbd_input_wayland *ufkbd_wl = ctx->ufkbd_wl;
struct ufkbd_ctx *ufkbd = ufkbd_wl->ufkbd;
ufkbd_terminate(ufkbd);
}
static const struct zwlr_layer_surface_v1_listener surface_listener = {
.configure = on_surface_configure,
.closed = on_surface_closed,
};
static int try_create_layer_surface(struct ufkbd_wl_surface *ctx)
{
if (ctx->wl == NULL)
return -EINVAL;
if (ctx->shell == NULL)
return -EINVAL;
if (ctx->vper == NULL)
return -EINVAL;
ctx->vp = wp_viewporter_get_viewport(ctx->vper, ctx->wl);
if (ctx->vp == NULL)
return -ENOMEM;
ctx->wlr = zwlr_layer_shell_v1_get_layer_surface(ctx->shell, ctx->wl, NULL, ZWLR_LAYER_SHELL_V1_LAYER_TOP, "ufkbd-osk");
if (ctx->wlr == NULL)
return -ENOMEM;
zwlr_layer_surface_v1_set_anchor(ctx->wlr,
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM);
zwlr_layer_surface_v1_set_size(ctx->wlr, 0, 185);
zwlr_layer_surface_v1_set_exclusive_zone(ctx->wlr, 185);
zwlr_layer_surface_v1_add_listener(ctx->wlr, &surface_listener, ctx);
// Commit the role given to the surface
wl_surface_commit(ctx->wl);
return 0;
}
static void on_global_compositor(void *data,
struct wl_registry *reg,
uint32_t name,
uint32_t version)
{
struct ufkbd_wl_surface *ctx = data;
if (version < WL_COMPOSITOR_CREATE_SURFACE_SINCE_VERSION)
return;
ctx->compositor = wl_registry_bind(reg,
name,
&wl_compositor_interface,
version);
if (ctx->compositor == NULL) {
fprintf(stderr, "warn: could not bind to compositor\n");
return;
}
ctx->wl = wl_compositor_create_surface(ctx->compositor);
if (ctx->wl == NULL) {
fprintf(stderr, "warn: no valid surface\n");
return;
}
try_create_layer_surface(ctx);
}
static void on_global_shell(void *data,
struct wl_registry *reg,
uint32_t name,
uint32_t version)
{
struct ufkbd_wl_surface *ctx = data;
ctx->shell = wl_registry_bind(reg,
name,
&zwlr_layer_shell_v1_interface,
version);
if (ctx->shell == NULL) {
fprintf(stderr, "wl: warn: could not bind to window manager\n");
return;
}
try_create_layer_surface(ctx);
}
static void on_global_viewporter(void *data,
struct wl_registry *reg,
uint32_t name,
uint32_t version)
{
struct ufkbd_wl_surface *ctx = data;
ctx->vper = wl_registry_bind(reg,
name,
&wp_viewporter_interface,
version);
if (ctx->vper == NULL) {
fprintf(stderr, "wl: warn: could not bind to viewporter\n");
return;
}
try_create_layer_surface(ctx);
}
int ufkbd_wl_surface_consume_buffer(struct ufkbd_wl_surface *ctx,
struct wl_buffer **buf, void **ptr)
{
int ret;
if (buf == NULL || ptr == NULL)
return -EINVAL;
ret = ufkbd_wl_buffer_consume(&ctx->bufs[0], buf, ptr);
if (ret != -EBUSY)
return ret;
ret = ufkbd_wl_buffer_consume(&ctx->bufs[1], buf, ptr);
return ret;
}
static int ufkbd_wl_surface_resize_buffers(struct ufkbd_wl_surface *ctx,
uint32_t width, uint32_t height)
{
int ret;
ctx->stride = (size_t) width * 4;
ret = ufkbd_wl_buffer_resize(&ctx->bufs[0],
width * ctx->scale,
height * ctx->scale);
if (ret)
return ret;
return ufkbd_wl_buffer_resize(&ctx->bufs[1],
width * ctx->scale,
height * ctx->scale);
}
int ufkbd_wl_surface_init(struct ufkbd_input_wayland *ufkbd_wl,
struct ufkbd_wl_surface **out)
{
struct ufkbd_wl_surface *ctx;
int ret;
ctx = calloc(1, sizeof(*ctx));
if (ctx == NULL)
return -errno;
ctx->ufkbd_wl = ufkbd_wl;
ctx->scale = 1;
ret = ufkbd_wl_buffer_init(&ctx->bufs[0], ufkbd_wl, 0);
if (ret)
goto err_free_ctx;
ret = ufkbd_wl_buffer_init(&ctx->bufs[1], ufkbd_wl, 1);
if (ret)
goto err_uninit_buf0;
ctx->listener_comp.iface = &wl_compositor_interface;
ctx->listener_comp.cb = on_global_compositor;
ctx->listener_comp.data = ctx;
ret = ufkbd_wl_global_listener_add(ufkbd_wl, &ctx->listener_comp);
if (ret)
goto err_uninit_buf1;
ctx->listener_shell.iface = &zwlr_layer_shell_v1_interface;
ctx->listener_shell.cb = on_global_shell;
ctx->listener_shell.data = ctx;
ret = ufkbd_wl_global_listener_add(ufkbd_wl, &ctx->listener_shell);
if (ret)
goto err_uninit_buf1;
ctx->listener_viewporter.iface = &wp_viewporter_interface;
ctx->listener_viewporter.cb = on_global_viewporter;
ctx->listener_viewporter.data = ctx;
ret = ufkbd_wl_global_listener_add(ufkbd_wl, &ctx->listener_viewporter);
if (ret)
goto err_uninit_buf1;
ufkbd_graphics_set_scale(ctx->ufkbd_wl->ufkbd->graphics, ctx->scale);
*out = ctx;
return 0;
err_uninit_buf1:
ufkbd_wl_buffer_uninit(&ctx->bufs[1]);
err_uninit_buf0:
ufkbd_wl_buffer_uninit(&ctx->bufs[0]);
err_free_ctx:
free(ctx);
return ret;
}
void ufkbd_wl_surface_uninit(struct ufkbd_wl_surface *ctx)
{
if (ctx->vper != NULL)
wp_viewporter_destroy(ctx->vper);
if (ctx->vp != NULL)
wp_viewport_destroy(ctx->vp);
if (ctx->wlr != NULL)
zwlr_layer_surface_v1_destroy(ctx->wlr);
if (ctx->wl != NULL)
wl_surface_destroy(ctx->wl);
if (ctx->shell != NULL)
zwlr_layer_shell_v1_destroy(ctx->shell);
if (ctx->compositor != NULL)
wl_compositor_destroy(ctx->compositor);
ufkbd_wl_buffer_uninit(&ctx->bufs[1]);
ufkbd_wl_buffer_uninit(&ctx->bufs[0]);
free(ctx);
}

149
wayland/wayland.h Normal file
View file

@ -0,0 +1,149 @@
/* SPDX-License-Identifier: GPL-3.0-only */
/*
* Wayland objects.
*
* Copyright (c) 2024, Richard Acayan. All rights reserved.
*/
#ifndef UFKBD_WAYLAND_H
#define UFKBD_WAYLAND_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <xkbcommon/xkbcommon.h>
#include "ufkbd.h"
#define MAX_GLOBAL_LISTENERS 16
#define SHM_PATH_SIZE 256
struct ufkbd_ctx;
struct wl_display;
struct wl_registry;
struct wl_seat;
struct wl_pointer;
struct wl_compositor;
struct xdg_wm_base;
struct wl_surface;
struct wp_viewport;
struct wp_viewporter;
struct xdg_surface;
struct xdg_toplevel;
struct zwp_virtual_keyboard_manager_v1;
struct zwp_virtual_keyboard_v1;
struct zwp_input_method_manager_v2;
struct zwp_input_method_v2;
struct ufkbd_input_wayland;
struct ufkbd_wl_global_listener {
const struct wl_interface *iface;
void (*cb)(void *data, struct wl_registry *reg, uint32_t name, uint32_t version);
void *data;
};
struct ufkbd_wl_input {
struct ufkbd_input_wayland *ufkbd_wl;
struct ufkbd_wl_global_listener listener_seat;
struct ufkbd_wl_global_listener listener_manager;
struct ufkbd_wl_global_listener listener_methodman;
struct wl_seat *seat;
struct wl_pointer *pointer;
struct wl_touch *touch;
struct zwp_virtual_keyboard_manager_v1 *manager;
struct zwp_virtual_keyboard_v1 *kb;
uint32_t mod_state;
};
struct ufkbd_wl_buffer {
struct ufkbd_ctx *ufkbd;
unsigned int id;
struct ufkbd_wl_global_listener listener;
struct wl_shm *wl;
struct wl_shm_pool *pool;
struct wl_buffer *buf;
bool avail, dirty, resize;
void *ptr;
int fd;
uint32_t width, height;
size_t size;
char path[SHM_PATH_SIZE];
};
struct ufkbd_wl_surface {
struct ufkbd_input_wayland *ufkbd_wl;
struct ufkbd_wl_global_listener listener_comp;
struct ufkbd_wl_global_listener listener_shell;
struct ufkbd_wl_global_listener listener_viewporter;
struct wl_compositor *compositor;
struct zwlr_layer_shell_v1 *shell;
struct wl_surface *wl;
struct zwlr_layer_surface_v1 *wlr;
struct wp_viewporter *vper;
struct wp_viewport *vp;
unsigned int scale;
size_t stride;
struct ufkbd_wl_buffer bufs[2];
};
struct ufkbd_input_wayland {
struct ufkbd_ctx *ufkbd;
struct ufkbd_wl_surface *surface;
struct ufkbd_wl_input *input;
struct wl_display *display;
struct wl_registry *registry;
int fd;
size_t n_global_listeners;
struct ufkbd_wl_global_listener *global_listeners[MAX_GLOBAL_LISTENERS];
};
int ufkbd_wl_buffer_consume(struct ufkbd_wl_buffer *ctx,
struct wl_buffer **buf, void **ptr);
int ufkbd_wl_buffer_resize(struct ufkbd_wl_buffer *ctx,
uint32_t width, uint32_t height);
int ufkbd_wl_buffer_init(struct ufkbd_wl_buffer *ctx,
struct ufkbd_input_wayland *ufkbd_wl,
unsigned int id);
void ufkbd_wl_buffer_uninit(struct ufkbd_wl_buffer *ctx);
int ufkbd_wl_surface_consume_buffer(struct ufkbd_wl_surface *ctx,
struct wl_buffer **buf, void **ptr);
int ufkbd_wl_surface_init(struct ufkbd_input_wayland *ufkbd_wl,
struct ufkbd_wl_surface **out);
void ufkbd_wl_surface_uninit(struct ufkbd_wl_surface *ctx);
int ufkbd_wl_input_init(struct ufkbd_input_wayland *ufkbd_wl,
struct ufkbd_wl_input **out);
void ufkbd_wl_input_uninit(struct ufkbd_wl_input *ctx);
int ufkbd_wl_input_send_key(struct ufkbd_wl_input *ctx, int key, bool repeat);
int ufkbd_wl_input_send_mod(struct ufkbd_wl_input *ctx, enum ufkbd_modifier mod, bool pressed);
int ufkbd_wl_global_listener_add(struct ufkbd_input_wayland *ctx,
struct ufkbd_wl_global_listener *listener);
#endif /* UFKBD_WAYLAND_H */