When the surface attaches to a buffer, all other buffers are available. Export the function used to release a buffer, track the buffer used by the surface, and release unused buffers when a new buffer is attached.
152 lines
3.6 KiB
C
152 lines
3.6 KiB
C
/* 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;
|
|
|
|
int used_buf;
|
|
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);
|
|
void ufkbd_wl_buffer_release(struct ufkbd_wl_buffer *ctx);
|
|
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);
|
|
void ufkbd_wl_surface_release_unused(struct ufkbd_wl_surface *ctx);
|
|
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 */
|