2001-08-09 23:16:54 +00:00
|
|
|
/*
|
|
|
|
in_event.c
|
|
|
|
|
|
|
|
input event handling
|
|
|
|
|
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/8/9
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-08-10 02:50:05 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-08-27 01:00:03 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2021-08-30 05:40:19 +00:00
|
|
|
#include "QF/darray.h"
|
2021-11-01 04:05:05 +00:00
|
|
|
|
|
|
|
#include "QF/input/event.h"
|
2001-08-09 23:16:54 +00:00
|
|
|
|
2021-11-22 05:07:30 +00:00
|
|
|
#define IE_EVENT(event) #event,
|
|
|
|
const char *ie_event_names[] = {
|
|
|
|
#include "QF/input/event_names.h"
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2021-08-30 05:40:19 +00:00
|
|
|
typedef struct {
|
|
|
|
ie_handler_t *handler;
|
|
|
|
void *data;
|
|
|
|
} ie_reghandler_t;
|
2001-08-09 23:16:54 +00:00
|
|
|
|
2021-08-30 05:40:19 +00:00
|
|
|
static struct DARRAY_TYPE (ie_reghandler_t) ie_handlers = { .grow = 8, };
|
|
|
|
static unsigned focus;
|
2001-08-09 23:16:54 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
IE_Send_Event (const IE_event_t *event)
|
|
|
|
{
|
2021-11-03 05:08:41 +00:00
|
|
|
if ((1 << event->type) & IE_broadcast_events) {
|
|
|
|
for (size_t i = 0; i < ie_handlers.size; i++) {
|
|
|
|
ie_reghandler_t *reg = &ie_handlers.a[i];
|
|
|
|
if (reg->handler) {
|
|
|
|
reg->handler (event, reg->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-08-30 05:40:19 +00:00
|
|
|
if (focus < ie_handlers.size && ie_handlers.a[focus].handler) {
|
|
|
|
ie_reghandler_t *reg = &ie_handlers.a[focus];
|
|
|
|
return reg->handler (event, reg->data);
|
|
|
|
}
|
2001-08-09 23:16:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2021-08-30 05:40:19 +00:00
|
|
|
IE_Add_Handler (ie_handler_t *event_handler, void *data)
|
2001-08-09 23:16:54 +00:00
|
|
|
{
|
2021-08-30 05:40:19 +00:00
|
|
|
size_t handle;
|
|
|
|
ie_reghandler_t reg = { event_handler, data };
|
|
|
|
|
|
|
|
for (handle = 0; handle < ie_handlers.size; handle++) {
|
|
|
|
if (!ie_handlers.a[handle].handler) {
|
|
|
|
ie_handlers.a[handle] = reg;
|
|
|
|
return handle;
|
2001-08-09 23:16:54 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-30 05:40:19 +00:00
|
|
|
DARRAY_APPEND (&ie_handlers, reg);
|
|
|
|
return handle;
|
2001-08-09 23:16:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IE_Remove_Handler (int handle)
|
|
|
|
{
|
2021-08-30 05:40:19 +00:00
|
|
|
if ((size_t) (ssize_t) handle < ie_handlers.size) {
|
|
|
|
ie_handlers.a[handle].handler = 0;
|
|
|
|
}
|
2001-08-09 23:16:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IE_Set_Focus (int handle)
|
|
|
|
{
|
2021-08-30 05:40:19 +00:00
|
|
|
unsigned h = handle;
|
|
|
|
if (h < ie_handlers.size && ie_handlers.a[handle].handler && focus != h) {
|
2001-08-09 23:43:13 +00:00
|
|
|
IE_event_t event;
|
|
|
|
event.type = ie_lose_focus;
|
|
|
|
IE_Send_Event (&event);
|
|
|
|
focus = handle;
|
|
|
|
event.type = ie_gain_focus;
|
|
|
|
IE_Send_Event (&event);
|
|
|
|
}
|
2001-08-09 23:16:54 +00:00
|
|
|
}
|
2021-11-08 02:20:04 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
IE_Get_Focus (void)
|
|
|
|
{
|
|
|
|
return focus;
|
|
|
|
}
|
2022-05-12 10:01:45 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
in_event_shutdown (void *data)
|
|
|
|
{
|
|
|
|
DARRAY_CLEAR (&ie_handlers);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __attribute__((constructor))
|
|
|
|
in_event_init (void)
|
|
|
|
{
|
|
|
|
//FIXME see in_evdev
|
|
|
|
Sys_RegisterShutdown (in_event_shutdown, 0);
|
|
|
|
}
|