~ubuntu-branches/ubuntu/raring/vice/raring

« back to all changes in this revision

Viewing changes to src/arch/unix/x11/uihotkey.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-03-31 00:37:15 UTC
  • mfrom: (1.1.7 upstream) (9.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090331003715-i5yisvcfv7mgz3eh
Tags: 2.1.dfsg-1
* New major upstream release (closes: #495937).
* Add desktop files (closes: #501181).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * uihotkeys.c - Implementation of UI hotkeys.
3
 
 *
4
 
 * Written by
5
 
 *  Ettore Perazzoli <ettore@comm2000.it>
6
 
 *
7
 
 * This file is part of VICE, the Versatile Commodore Emulator.
8
 
 * See README for copyright notice.
9
 
 *
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.
14
 
 *
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.
19
 
 *
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
23
 
 *  02111-1307  USA.
24
 
 *
25
 
 */
26
 
 
27
 
#include "vice.h"
28
 
 
29
 
#include <stdio.h>
30
 
#include <stdlib.h>
31
 
 
32
 
#include "lib.h"
33
 
#include "uihotkey.h"
34
 
#include "uimenu.h"
35
 
 
36
 
 
37
 
typedef struct {
38
 
    ui_hotkey_modifier_t modifier;
39
 
    ui_keysym_t keysym;
40
 
    ui_callback_t callback;
41
 
    ui_callback_data_t client_data;
42
 
} registered_hotkey_t;
43
 
 
44
 
static registered_hotkey_t *registered_hotkeys = NULL;
45
 
static int num_registered_hotkeys;
46
 
static int num_allocated_hotkeys;
47
 
 
48
 
 
49
 
/* ------------------------------------------------------------------------- */
50
 
 
51
 
int ui_hotkey_init(void)
52
 
{
53
 
    if (registered_hotkeys != NULL) {
54
 
        lib_free(registered_hotkeys);
55
 
        num_registered_hotkeys = num_allocated_hotkeys = 0;
56
 
    }
57
 
    return 0;
58
 
}
59
 
 
60
 
void ui_hotkey_shutdown(void)
61
 
{
62
 
    lib_free(registered_hotkeys);
63
 
}
64
 
 
65
 
/* ------------------------------------------------------------------------- */
66
 
 
67
 
void ui_hotkey_register(ui_hotkey_modifier_t modifier, signed long keysym,
68
 
                        void *callback, void *client_data)
69
 
{
70
 
    registered_hotkey_t *p;
71
 
 
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)));
82
 
    }
83
 
 
84
 
    p = registered_hotkeys + num_registered_hotkeys;
85
 
 
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;
90
 
 
91
 
    num_registered_hotkeys++;
92
 
}
93
 
 
94
 
/* ------------------------------------------------------------------------- */
95
 
 
96
 
int ui_dispatch_hotkeys(int key)
97
 
{
98
 
    int i, ret = 0;
99
 
    registered_hotkey_t *p = registered_hotkeys;
100
 
 
101
 
    /* XXX: Notice that we don't actually check the hotkey modifiers
102
 
       here.  */
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);
107
 
            ret = 1;
108
 
            break;
109
 
        }
110
 
    }
111
 
    return ret;
112
 
}
113