wlmaker
Loading...
Searching...
No Matches
Classes | Functions | Variables
wlclient.c File Reference
#include "wlclient.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 "wlr-layer-shell-unstable-v1-client-protocol.h"
Include dependency graph for wlclient.c:

Classes

struct  _wlmcl_client_t
 
struct  wlmcl_client_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 wlmcl_client_timer_twlmcl_client_timer_create (wlmcl_client_t *client_ptr, uint64_t target_usec, wlmcl_client_callback_t callback, void *callback_ud_ptr)
 
static void wlmcl_client_timer_destroy (wlmcl_client_timer_t *timer_ptr)
 
static void wlmcl_client_seat_setup (wlmcl_client_t *client_ptr)
 
static void wlmcl_client_seat_handle_capabilities (void *data_ptr, struct wl_seat *wl_seat_ptr, uint32_t capabilities)
 
static void wlmcl_client_seat_handle_name (void *data_ptr, struct wl_seat *wl_seat_ptr, const char *name_ptr)
 
static void wlmcl_client_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 wlmcl_client_pointer_handle_leave (void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface)
 
static void wlmcl_client_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 wlmcl_client_pointer_handle_button (void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
 
static void wlmcl_client_pointer_handle_axis (void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
 
static void wlmcl_client_pointer_handle_frame (void *data, struct wl_pointer *wl_pointer)
 
static void wlmcl_client_pointer_handle_axis_source (void *data, struct wl_pointer *wl_pointer, uint32_t axis_source)
 
static void wlmcl_client_pointer_handle_axis_stop (void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis)
 
static void wlmcl_client_pointer_handle_axis_discrete (void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete)
 
static void _wlmcl_client_keyboard_handle_keymap (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t format, int32_t fd, uint32_t size)
 
static void _wlmcl_client_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 _wlmcl_client_keyboard_handle_leave (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, struct wl_surface *wl_surface_ptr)
 
static void _wlmcl_client_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 _wlmcl_client_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 _wlmcl_client_keyboard_handle_repeat_info (void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, int32_t rate, int32_t delay)
 
wlmcl_client_twlmcl_client_create (const char *app_id_ptr)
 
void wlmcl_client_destroy (wlmcl_client_t *wlclient_ptr)
 
const struct wlmcl_client_attributeswlmcl_client_attributes (const wlmcl_client_t *wlclient_ptr)
 
struct wlmcl_client_eventswlmcl_client_events (wlmcl_client_t *wlclient_ptr)
 
void wlmcl_client_run (wlmcl_client_t *wlclient_ptr)
 
void wlmcl_client_request_terminate (wlmcl_client_t *wlclient_ptr)
 
bool wlmcl_client_register_timer (wlmcl_client_t *wlclient_ptr, uint64_t target_usec, wlmcl_client_callback_t callback, void *callback_ud_ptr)
 

Variables

static const struct wl_registry_listener registry_listener
 
static const struct wl_seat_listener wlmcl_client_seat_listener
 
static const struct wl_pointer_listener wlmcl_client_pointer_listener
 
static const struct wl_keyboard_listener wlmcl_client_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

◆ _wlmcl_client_keyboard_handle_enter()

void _wlmcl_client_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.

◆ _wlmcl_client_keyboard_handle_key()

void _wlmcl_client_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.

◆ _wlmcl_client_keyboard_handle_keymap()

void _wlmcl_client_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.

◆ _wlmcl_client_keyboard_handle_leave()

void _wlmcl_client_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.

◆ _wlmcl_client_keyboard_handle_modifiers()

void _wlmcl_client_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.

◆ _wlmcl_client_keyboard_handle_repeat_info()

void _wlmcl_client_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 wlmcl_client_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 wlmcl_client_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

◆ wlmcl_client_attributes()

const struct wlmcl_client_attributes * wlmcl_client_attributes ( const wlmcl_client_t wlmcl_client_ptr)

Gets the client attributes.

Parameters
wlmcl_client_ptr
Returns
A pointer to the attributes.

◆ wlmcl_client_create()

wlmcl_client_t * wlmcl_client_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 wlmcl_client_destroy.

◆ wlmcl_client_destroy()

void wlmcl_client_destroy ( wlmcl_client_t wlmcl_client_ptr)

Destroys the wayland client, as created by wlmcl_client_create.

Parameters
wlmcl_client_ptr

◆ wlmcl_client_events()

struct wlmcl_client_events * wlmcl_client_events ( wlmcl_client_t wlmcl_client_ptr)
Returns
A pointer to wlmcl_client_t::events.

◆ wlmcl_client_pointer_handle_axis()

void wlmcl_client_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.

◆ wlmcl_client_pointer_handle_axis_discrete()

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

Called upon axis click events.

◆ wlmcl_client_pointer_handle_axis_source()

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

Called upon axis source events.

◆ wlmcl_client_pointer_handle_axis_stop()

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

Axis stop events.

◆ wlmcl_client_pointer_handle_button()

void wlmcl_client_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.

◆ wlmcl_client_pointer_handle_enter()

void wlmcl_client_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.

◆ wlmcl_client_pointer_handle_frame()

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

Called upon frame events.

◆ wlmcl_client_pointer_handle_leave()

void wlmcl_client_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.

◆ wlmcl_client_pointer_handle_motion()

void wlmcl_client_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.

◆ wlmcl_client_register_timer()

bool wlmcl_client_register_timer ( wlmcl_client_t wlmcl_client_ptr,
uint64_t  target_usec,
wlmcl_client_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
wlmcl_client_ptr
target_usec
callback
callback_ud_ptr
Returns
true on success.

◆ wlmcl_client_request_terminate()

void wlmcl_client_request_terminate ( wlmcl_client_t wlmcl_client_ptr)

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

Parameters
wlmcl_client_ptr

◆ wlmcl_client_run()

void wlmcl_client_run ( wlmcl_client_t wlmcl_client_ptr)

Runs the client's mainloop.

Parameters
wlmcl_client_ptr

◆ wlmcl_client_seat_handle_capabilities()

void wlmcl_client_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

◆ wlmcl_client_seat_handle_name()

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

Handles the unique identifier callback.

◆ wlmcl_client_seat_setup()

void wlmcl_client_seat_setup ( wlmcl_client_t client_ptr)
static

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

◆ wlmcl_client_timer_create()

wlmcl_client_timer_t * wlmcl_client_timer_create ( wlmcl_client_t client_ptr,
uint64_t  target_usec,
wlmcl_client_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 wlmcl_client_timer_destroy.

◆ wlmcl_client_timer_destroy()

void wlmcl_client_timer_destroy ( wlmcl_client_timer_t timer_ptr)
static

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

Parameters
timer_ptr

Variable Documentation

◆ objects

const object_t objects[]
static
Initial value:
= {
{ &wl_compositor_interface, 4,
offsetof(struct wlmcl_client_attributes, wl_compositor_ptr), NULL },
{ &wl_shm_interface, 1,
offsetof(struct wlmcl_client_attributes, wl_shm_ptr), NULL },
{ &xdg_wm_base_interface, 1,
offsetof(struct wlmcl_client_attributes, xdg_wm_base_ptr), NULL },
{ &wl_seat_interface, 5,
offsetof(struct wlmcl_client_attributes, wl_seat_ptr), wlmcl_client_seat_setup },
{ &zwlmaker_icon_manager_v1_interface, 1,
offsetof(struct wlmcl_client_attributes, icon_manager_ptr), NULL },
{ &zxdg_decoration_manager_v1_interface, 1,
offsetof(struct wlmcl_client_attributes, xdg_decoration_manager_ptr), NULL },
{ &ext_input_observation_manager_v1_interface, 1,
offsetof(struct wlmcl_client_attributes, input_observation_manager_ptr), NULL },
{ &zwlr_layer_shell_v1_interface, 4,
offsetof(struct wlmcl_client_attributes, layer_shell_ptr), NULL },
{ NULL, 0, 0, NULL }
}
Definition wlclient.h:47
static void wlmcl_client_seat_setup(wlmcl_client_t *client_ptr)
Definition wlclient.c:721

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 wlclient.c:607
static void handle_global_remove(void *data_ptr, struct wl_registry *registry, uint32_t name)
Definition wlclient.c:658

Listener for the registry, taking note of registry updates.

◆ wlmcl_client_keyboard_listener

const struct wl_keyboard_listener wlmcl_client_keyboard_listener
static
Initial value:
= {
}
static void _wlmcl_client_keyboard_handle_repeat_info(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, int32_t rate, int32_t delay)
Definition wlclient.c:1019
static void _wlmcl_client_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 wlclient.c:997
static void _wlmcl_client_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 wlclient.c:966
static void _wlmcl_client_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 wlclient.c:943
static void _wlmcl_client_keyboard_handle_leave(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t serial, struct wl_surface *wl_surface_ptr)
Definition wlclient.c:955
static void _wlmcl_client_keyboard_handle_keymap(void *data_ptr, struct wl_keyboard *wl_keyboard_ptr, uint32_t format, int32_t fd, uint32_t size)
Definition wlclient.c:888

Listeners for the keyboard.

◆ wlmcl_client_pointer_listener

const struct wl_pointer_listener wlmcl_client_pointer_listener
static
Initial value:
= {
}
static void wlmcl_client_pointer_handle_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete)
Definition wlclient.c:877
static void wlmcl_client_pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
Definition wlclient.c:835
static void wlmcl_client_pointer_handle_frame(void *data, struct wl_pointer *wl_pointer)
Definition wlclient.c:847
static void wlmcl_client_pointer_handle_button(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
Definition wlclient.c:822
static void wlmcl_client_pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface)
Definition wlclient.c:799
static void wlmcl_client_pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source)
Definition wlclient.c:856
static void wlmcl_client_pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
Definition wlclient.c:810
static void wlmcl_client_pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis)
Definition wlclient.c:866
static void wlmcl_client_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 wlclient.c:786

Listeners for the pointer.

◆ wlmcl_client_seat_listener

const struct wl_seat_listener wlmcl_client_seat_listener
static
Initial value:
= {
}
static void wlmcl_client_seat_handle_capabilities(void *data_ptr, struct wl_seat *wl_seat_ptr, uint32_t capabilities)
Definition wlclient.c:739
static void wlmcl_client_seat_handle_name(void *data_ptr, struct wl_seat *wl_seat_ptr, const char *name_ptr)
Definition wlclient.c:775

Listeners for the seat.