wlmaker
Loading...
Searching...
No Matches
client.c File Reference
#include "libwlclient.h"
#include <errno.h>
#include <inttypes.h>
#include <libbase/libbase.h>
#include <poll.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/signalfd.h>
#include <sys/types.h>
#include <unistd.h>
#include <wayland-client-core.h>
#include <wayland-client-protocol.h>
#include <wayland-server-core.h>
#include <wayland-util.h>
#include <xkbcommon/xkbcommon.h>
#include "wlmaker-icon-unstable-v1-client-protocol.h"
#include "ext-input-observation-v1-client-protocol.h"
#include "xdg-shell-client-protocol.h"
#include "xdg-decoration-client-protocol.h"
Include dependency graph for client.c:

Classes

struct  _wlclient_t
struct  wlclient_timer_t
struct  object_t

Functions

static void wl_to_bs_log (const char *fmt, va_list args)
static void handle_global_announce (void *data_ptr, struct wl_registry *wl_registry_ptr, uint32_t name, const char *interface_ptr, uint32_t version)
static void handle_global_remove (void *data_ptr, struct wl_registry *registry, uint32_t name)
static wlclient_timer_twlc_timer_create (wlclient_t *client_ptr, uint64_t target_usec, wlclient_callback_t callback, void *callback_ud_ptr)
static void wlc_timer_destroy (wlclient_timer_t *timer_ptr)
static void wlc_seat_setup (wlclient_t *client_ptr)
static void wlc_seat_handle_capabilities (void *data_ptr, struct wl_seat *wl_seat_ptr, uint32_t capabilities)
static void wlc_seat_handle_name (void *data_ptr, struct wl_seat *wl_seat_ptr, const char *name_ptr)
static void wlc_pointer_handle_enter (void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y)
static void wlc_pointer_handle_leave (void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface)
static void wlc_pointer_handle_motion (void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
static void wlc_pointer_handle_button (void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
static void wlc_pointer_handle_axis (void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
static void wlc_pointer_handle_frame (void *data, struct wl_pointer *wl_pointer)
static void wlc_pointer_handle_axis_source (void *data, struct wl_pointer *wl_pointer, uint32_t axis_source)
static void wlc_pointer_handle_axis_stop (void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis)
static void wlc_pointer_handle_axis_discrete (void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete)
static void _wlc_keyboard_handle_keymap (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t format, int32_t fd, uint32_t size)
static void _wlc_keyboard_handle_enter (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, struct wl_surface *wl_surface_ptr, struct wl_array *keys)
static void _wlc_keyboard_handle_leave (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, struct wl_surface *wl_surface_ptr)
static void _wlc_keyboard_handle_key (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
static void _wlc_keyboard_handle_modifiers (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
static void _wlc_keyboard_handle_repeat_info (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, int32_t rate, int32_t delay)
wlclient_twlclient_create (const char *app_id_ptr)
void wlclient_destroy (wlclient_t *wlclient_ptr)
const wlclient_attributes_twlclient_attributes (const wlclient_t *wlclient_ptr)
wlclient_events_twlclient_events (wlclient_t *wlclient_ptr)
void wlclient_run (wlclient_t *wlclient_ptr)
void wlclient_request_terminate (wlclient_t *wlclient_ptr)
bool wlclient_register_timer (wlclient_t *wlclient_ptr, uint64_t target_usec, wlclient_callback_t callback, void *callback_ud_ptr)

Variables

static const struct wl_registry_listener registry_listener
static const struct wl_seat_listener wlc_seat_listener
static const struct wl_pointer_listener wlc_pointer_listener
static const struct wl_keyboard_listener wlc_keyboard_listener
static const object_t objects []

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _wlc_keyboard_handle_enter()

void _wlc_keyboard_handle_enter ( void * data_ptr,
struct wl_keyboard * wl_keyboard_ptr,
uint32_t serial,
struct wl_surface * wl_surface_ptr,
struct wl_array * keys )
static

Called when the given surface gained keyboard focus.

◆ _wlc_keyboard_handle_key()

void _wlc_keyboard_handle_key ( void * data_ptr,
struct wl_keyboard * wl_keyboard_ptr,
uint32_t serial,
uint32_t time,
uint32_t key,
uint32_t state )
static

Called when a key was pressed or released.

◆ _wlc_keyboard_handle_keymap()

void _wlc_keyboard_handle_keymap ( void * data_ptr,
struct wl_keyboard * wl_keyboard_ptr,
uint32_t format,
int32_t fd,
uint32_t size )
static

Called when compositor provides a keymap to memory-map.

◆ _wlc_keyboard_handle_leave()

void _wlc_keyboard_handle_leave ( void * data_ptr,
struct wl_keyboard * wl_keyboard_ptr,
uint32_t serial,
struct wl_surface * wl_surface_ptr )
static

Called when the given surface lost keyboard focus.

◆ _wlc_keyboard_handle_modifiers()

void _wlc_keyboard_handle_modifiers ( void * data_ptr,
struct wl_keyboard * wl_keyboard_ptr,
uint32_t serial,
uint32_t mods_depressed,
uint32_t mods_latched,
uint32_t mods_locked,
uint32_t group )
static

Called when the modifier or group state has changed.

◆ _wlc_keyboard_handle_repeat_info()

void _wlc_keyboard_handle_repeat_info ( void * data_ptr,
struct wl_keyboard * wl_keyboard_ptr,
int32_t rate,
int32_t delay )
static

Called to configure repeat and delay settings.

◆ handle_global_announce()

void handle_global_announce ( void * data_ptr,
struct wl_registry * wl_registry_ptr,
uint32_t name,
const char * interface_name_ptr,
uint32_t version )
static

Handles the announcement of a global object.

Called by struct wl_registry_listener global callback, invoked to notify clients of global objects.

Parameters
data_ptrPoints to a wlclient_t.
wl_registry_ptrThe struct wl_registry this is invoked for.
nameNumeric name of the global object.
interface_name_ptrName of the interface implemented by the object.
versionInterface version.

◆ handle_global_remove()

void handle_global_remove ( void * data_ptr,
struct wl_registry * wl_registry_ptr,
uint32_t name )
static

Handles the removal of a wayland global object.

Called by struct wl_registry_listener global_remove, invoked to notify clients of removed global objects.

Parameters
data_ptrPoints to a wlclient_t.
wl_registry_ptrThe struct wl_registry this is invoked for.
nameNumeric name of the global object.

◆ wl_to_bs_log()

void wl_to_bs_log ( const char * fmt_ptr,
va_list args )
static

Redirects a wayland log call into s_log.

Parameters
fmt_ptr
args

◆ wlc_pointer_handle_axis()

void wlc_pointer_handle_axis ( void * data,
struct wl_pointer * wl_pointer,
uint32_t time,
uint32_t axis,
wl_fixed_t value )
static

Called upon axis events.

◆ wlc_pointer_handle_axis_discrete()

void wlc_pointer_handle_axis_discrete ( void * data,
struct wl_pointer * wl_pointer,
uint32_t axis,
int32_t discrete )
static

Called upon axis click events.

◆ wlc_pointer_handle_axis_source()

void wlc_pointer_handle_axis_source ( void * data,
struct wl_pointer * wl_pointer,
uint32_t axis_source )
static

Called upon axis source events.

◆ wlc_pointer_handle_axis_stop()

void wlc_pointer_handle_axis_stop ( void * data,
struct wl_pointer * wl_pointer,
uint32_t time,
uint32_t axis )
static

Axis stop events.

◆ wlc_pointer_handle_button()

void wlc_pointer_handle_button ( void * data,
struct wl_pointer * wl_pointer,
uint32_t serial,
uint32_t time,
uint32_t button,
uint32_t state )
static

Called upon pointer button events.

◆ wlc_pointer_handle_enter()

void wlc_pointer_handle_enter ( void * data,
struct wl_pointer * wl_pointer,
uint32_t serial,
struct wl_surface * surface,
wl_fixed_t surface_x,
wl_fixed_t surface_y )
static

Called when the client obtains pointer focus.

◆ wlc_pointer_handle_frame()

void wlc_pointer_handle_frame ( void * data,
struct wl_pointer * wl_pointer )
static

Called upon frame events.

◆ wlc_pointer_handle_leave()

void wlc_pointer_handle_leave ( void * data,
struct wl_pointer * wl_pointer,
uint32_t serial,
struct wl_surface * surface )
static

Called when the client looses pointer focus.

◆ wlc_pointer_handle_motion()

void wlc_pointer_handle_motion ( void * data,
struct wl_pointer * wl_pointer,
uint32_t time,
wl_fixed_t surface_x,
wl_fixed_t surface_y )
static

Called upon pointer motion.

◆ wlc_seat_handle_capabilities()

void wlc_seat_handle_capabilities ( void * data_ptr,
struct wl_seat * wl_seat_ptr,
uint32_t capabilities )
static

Handles the seat's capability updates.

Un-/Registers listeners for the pointer, if the capability is available.

Parameters
data_ptr
wl_seat_ptr
capabilities

◆ wlc_seat_handle_name()

void wlc_seat_handle_name ( void * data_ptr,
struct wl_seat * wl_seat_ptr,
const char * name_ptr )
static

Handles the unique identifier callback.

◆ wlc_seat_setup()

void wlc_seat_setup ( wlclient_t * client_ptr)
static

Set up the seat: Registers the client's seat listeners.

◆ wlc_timer_create()

wlclient_timer_t * wlc_timer_create ( wlclient_t * client_ptr,
uint64_t target_usec,
wlclient_callback_t callback,
void * callback_ud_ptr )
static

Creates a timer and registers it with the client.

Parameters
client_ptr
target_usec
callback
callback_ud_ptr
Returns
A pointer to the created timer, or NULL on error. The pointer must be destroyed by wlc_timer_destroy.

◆ wlc_timer_destroy()

void wlc_timer_destroy ( wlclient_timer_t * timer_ptr)
static

Destroys the timer. Note: The timer will NOT be unregistered first.

Parameters
timer_ptr

◆ wlclient_attributes()

const wlclient_attributes_t * wlclient_attributes ( const wlclient_t * wlclient_ptr)

Gets the client attributes.

Parameters
wlclient_ptr
Returns
A pointer to the attributes.

◆ wlclient_create()

wlclient_t * wlclient_create ( const char * app_id_ptr)

Creates a wayland client for simple buffer interactions.

Parameters
app_id_ptrApplication ID or NULL if not set.
Returns
The client state, or NULL on error. The state needs to be free'd via wlclient_destroy.

◆ wlclient_destroy()

void wlclient_destroy ( wlclient_t * wlclient_ptr)

Destroys the wayland client, as created by wlclient_create.

Parameters
wlclient_ptr

◆ wlclient_events()

wlclient_events_t * wlclient_events ( wlclient_t * wlclient_ptr)
Returns
A pointer to wlclient_t::events.

◆ wlclient_register_timer()

bool wlclient_register_timer ( wlclient_t * wlclient_ptr,
uint64_t target_usec,
wlclient_callback_t callback,
void * callback_ud_ptr )

Registers a timer with the client.

Once the system clock reaches (or has passed) target_usec, callback will be called with the provided arguments. This is a one-time registration. For repeated calls, clients need to re-register.

Parameters
wlclient_ptr
target_usec
callback
callback_ud_ptr
Returns
true on success.

◆ wlclient_request_terminate()

void wlclient_request_terminate ( wlclient_t * wlclient_ptr)

Requests termination of the client-s mainloop. This takes effect only once the mainloop wraps up an iteration.

Parameters
wlclient_ptr

◆ wlclient_run()

void wlclient_run ( wlclient_t * wlclient_ptr)

Runs the client's mainloop.

Parameters
wlclient_ptr

Variable Documentation

◆ objects

const object_t objects[]
static
Initial value:
= {
{ &wl_compositor_interface, 4,
offsetof(wlclient_attributes_t, wl_compositor_ptr), NULL },
{ &wl_shm_interface, 1,
offsetof(wlclient_attributes_t, wl_shm_ptr), NULL },
{ &xdg_wm_base_interface, 1,
offsetof(wlclient_attributes_t, xdg_wm_base_ptr), NULL },
{ &wl_seat_interface, 5,
offsetof(wlclient_attributes_t, wl_seat_ptr), wlc_seat_setup },
{ &zwlmaker_icon_manager_v1_interface, 1,
offsetof(wlclient_attributes_t, icon_manager_ptr), NULL },
{ &zxdg_decoration_manager_v1_interface, 1,
offsetof(wlclient_attributes_t, xdg_decoration_manager_ptr), NULL },
{ &ext_input_observation_manager_v1_interface, 1,
offsetof(wlclient_attributes_t, input_observation_manager_ptr), NULL },
{ NULL, 0, 0, NULL }
}
static void wlc_seat_setup(wlclient_t *client_ptr)
Definition client.c:717
Definition libwlclient.h:51

List of wayland objects we want to bind to.

◆ registry_listener

const struct wl_registry_listener registry_listener
static
Initial value:
= {
.global_remove = handle_global_remove,
}
static void handle_global_announce(void *data_ptr, struct wl_registry *wl_registry_ptr, uint32_t name, const char *interface_ptr, uint32_t version)
Definition client.c:603
static void handle_global_remove(void *data_ptr, struct wl_registry *registry, uint32_t name)
Definition client.c:654

Listener for the registry, taking note of registry updates.

◆ wlc_keyboard_listener

const struct wl_keyboard_listener wlc_keyboard_listener
static
Initial value:
= {
}
static void _wlc_keyboard_handle_leave(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, struct wl_surface *wl_surface_ptr)
Definition client.c:951
static void _wlc_keyboard_handle_enter(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, struct wl_surface *wl_surface_ptr, struct wl_array *keys)
Definition client.c:939
static void _wlc_keyboard_handle_repeat_info(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, int32_t rate, int32_t delay)
Definition client.c:1015
static void _wlc_keyboard_handle_key(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
Definition client.c:962
static void _wlc_keyboard_handle_keymap(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t format, int32_t fd, uint32_t size)
Definition client.c:884
static void _wlc_keyboard_handle_modifiers(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
Definition client.c:993

Listeners for the keyboard.

◆ wlc_pointer_listener

const struct wl_pointer_listener wlc_pointer_listener
static
Initial value:
= {
}
static void wlc_pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis)
Definition client.c:862
static void wlc_pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface)
Definition client.c:795
static void wlc_pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
Definition client.c:843
static void wlc_pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
Definition client.c:806
static void wlc_pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source)
Definition client.c:852
static void wlc_pointer_handle_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
Definition client.c:818
static void wlc_pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y)
Definition client.c:782
static void wlc_pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
Definition client.c:831
static void wlc_pointer_handle_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete)
Definition client.c:873

Listeners for the pointer.

◆ wlc_seat_listener

const struct wl_seat_listener wlc_seat_listener
static
Initial value:
= {
}
static void wlc_seat_handle_name(void *data_ptr, struct wl_seat *wl_seat_ptr, const char *name_ptr)
Definition client.c:771
static void wlc_seat_handle_capabilities(void *data_ptr, struct wl_seat *wl_seat_ptr, uint32_t capabilities)
Definition client.c:735

Listeners for the seat.