2
* uihotkeys.c - Implementation of UI hotkeys.
5
* Ettore Perazzoli <ettore@comm2000.it>
7
* This file is part of VICE, the Versatile Commodore Emulator.
8
* See README for copyright notice.
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
38
ui_hotkey_modifier_t modifier;
40
ui_callback_t callback;
41
ui_callback_data_t client_data;
42
} registered_hotkey_t;
44
static registered_hotkey_t *registered_hotkeys = NULL;
45
static int num_registered_hotkeys;
46
static int num_allocated_hotkeys;
49
/* ------------------------------------------------------------------------- */
51
int ui_hotkey_init(void)
53
if (registered_hotkeys != NULL) {
54
lib_free(registered_hotkeys);
55
num_registered_hotkeys = num_allocated_hotkeys = 0;
60
void ui_hotkey_shutdown(void)
62
lib_free(registered_hotkeys);
65
/* ------------------------------------------------------------------------- */
67
void ui_hotkey_register(ui_hotkey_modifier_t modifier, signed long keysym,
68
void *callback, void *client_data)
70
registered_hotkey_t *p;
72
if (registered_hotkeys == 0) {
73
num_allocated_hotkeys = 32;
74
registered_hotkeys = lib_malloc(num_allocated_hotkeys
75
* sizeof(registered_hotkey_t));
76
num_registered_hotkeys = 0;
77
} else if (num_registered_hotkeys == num_allocated_hotkeys) {
78
num_allocated_hotkeys *= 2;
79
registered_hotkeys = lib_realloc(registered_hotkeys,
80
(num_allocated_hotkeys
81
* sizeof(registered_hotkey_t)));
84
p = registered_hotkeys + num_registered_hotkeys;
86
p->modifier = modifier;
87
p->keysym = (ui_keysym_t)keysym;
88
p->callback = (ui_callback_t)callback;
89
p->client_data = (ui_callback_data_t)client_data;
91
num_registered_hotkeys++;
94
/* ------------------------------------------------------------------------- */
96
int ui_dispatch_hotkeys(int key)
99
registered_hotkey_t *p = registered_hotkeys;
101
/* XXX: Notice that we don't actually check the hotkey modifiers
103
for (i = 0; i < num_registered_hotkeys; i++, p++) {
104
if (p->keysym == key) {
105
((void *(*)(void *, void *, void *))
106
p->callback)(NULL, p->client_data, NULL);