libei/src/libei-event.c
Peter Hutterer 5f2afdf806 Fix a bunch of compiler warnings
Most are signed vs unsigned, the remaining ones are an unused
variables/functions.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-03-01 23:28:49 +00:00

201 lines
4.9 KiB
C

/*
* Copyright © 2021 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 "config.h"
#include "libei-private.h"
OBJECT_IMPLEMENT_REF(ei_event);
_public_
OBJECT_IMPLEMENT_UNREF(ei_event);
_public_
OBJECT_IMPLEMENT_GETTER(ei_event, type, enum ei_event_type);
_public_
OBJECT_IMPLEMENT_GETTER(ei_event, device, struct ei_device*);
_public_
OBJECT_IMPLEMENT_GETTER(ei_event, seat, struct ei_seat*);
const char *
ei_event_type_to_string(enum ei_event_type type)
{
switch(type) {
CASE_RETURN_STRING(EI_EVENT_CONNECT);
CASE_RETURN_STRING(EI_EVENT_DISCONNECT);
CASE_RETURN_STRING(EI_EVENT_SEAT_ADDED);
CASE_RETURN_STRING(EI_EVENT_SEAT_REMOVED);
CASE_RETURN_STRING(EI_EVENT_DEVICE_ADDED);
CASE_RETURN_STRING(EI_EVENT_DEVICE_REMOVED);
CASE_RETURN_STRING(EI_EVENT_DEVICE_PAUSED);
CASE_RETURN_STRING(EI_EVENT_DEVICE_RESUMED);
CASE_RETURN_STRING(EI_EVENT_KEYBOARD_MODIFIERS);
CASE_RETURN_STRING(EI_EVENT_PROPERTY);
}
assert(!"Unhandled event type");
}
static void
ei_event_destroy(struct ei_event *event)
{
switch (event->type) {
case EI_EVENT_CONNECT:
case EI_EVENT_DISCONNECT:
case EI_EVENT_SEAT_ADDED:
case EI_EVENT_SEAT_REMOVED:
case EI_EVENT_DEVICE_ADDED:
case EI_EVENT_DEVICE_REMOVED:
case EI_EVENT_DEVICE_PAUSED:
case EI_EVENT_DEVICE_RESUMED:
case EI_EVENT_KEYBOARD_MODIFIERS:
break;
case EI_EVENT_PROPERTY:
free(event->prop.name);
free(event->prop.value);
break;
}
ei_device_unref(event->device);
ei_seat_unref(event->seat);
}
static
OBJECT_IMPLEMENT_CREATE(ei_event);
static
OBJECT_IMPLEMENT_PARENT(ei_event, ei);
struct ei_event *
ei_event_new(struct ei *ei)
{
return ei_event_create(&ei->object);
}
struct ei_event *
ei_event_new_for_device(struct ei_device *device)
{
struct ei_event *event = ei_event_new(ei_device_get_context(device));
event->seat = ei_seat_ref(ei_device_get_seat(device));
event->device = ei_device_ref(device);
return event;
}
static struct ei *
ei_event_get_context(struct ei_event *event)
{
return ei_event_parent(event);
}
static inline bool
check_event_type(struct ei_event *event,
const char *function_name,
...)
{
bool rc = false;
va_list args;
unsigned int type_permitted;
enum ei_event_type type = ei_event_get_type(event);
va_start(args, function_name);
type_permitted = va_arg(args, unsigned int);
while (type_permitted != (unsigned int)-1) {
if (type_permitted == type) {
rc = true;
break;
}
type_permitted = va_arg(args, unsigned int);
}
va_end(args);
if (!rc)
log_bug_client(ei_event_get_context(event),
"Invalid event type %u passed to %s()\n",
type, function_name);
return rc;
}
#define require_event_type(event_, retval_, ...) \
if (!check_event_type(event_, __func__, __VA_ARGS__, -1)) \
return retval_; \
_public_ uint32_t
ei_event_keyboard_get_xkb_mods_depressed(struct ei_event *event)
{
require_event_type(event, 0, EI_EVENT_KEYBOARD_MODIFIERS);
return event->modifiers.depressed;
}
_public_ uint32_t
ei_event_keyboard_get_xkb_mods_latched(struct ei_event *event)
{
require_event_type(event, 0, EI_EVENT_KEYBOARD_MODIFIERS);
return event->modifiers.latched;
}
_public_ uint32_t
ei_event_keyboard_get_xkb_mods_locked(struct ei_event *event)
{
require_event_type(event, 0, EI_EVENT_KEYBOARD_MODIFIERS);
return event->modifiers.locked;
}
_public_ uint32_t
ei_event_keyboard_get_xkb_group(struct ei_event *event)
{
require_event_type(event, 0, EI_EVENT_KEYBOARD_MODIFIERS);
return event->modifiers.group;
}
_public_ const char *
ei_event_property_get_name(struct ei_event *event)
{
require_event_type(event, NULL,
EI_EVENT_PROPERTY);
return event->prop.name;
}
_public_ const char *
ei_event_property_get_value(struct ei_event *event)
{
require_event_type(event, NULL,
EI_EVENT_PROPERTY);
return event->prop.value;
}
_public_ uint32_t
ei_event_property_get_permissions(struct ei_event *event)
{
require_event_type(event, 0,
EI_EVENT_PROPERTY);
return event->prop.permissions;
}