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

« back to all changes in this revision

Viewing changes to src/arch/unix/x11/xaw/x11kbd.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:
42
42
#include "machine.h"
43
43
#include "ui.h"
44
44
#include "uiarch.h"
45
 
 
 
45
#include "uimenu.h"
 
46
 
 
47
void kbd_arch_init(void)
 
48
{
 
49
}
 
50
 
 
51
signed long kbd_arch_keyname_to_keynum(char *keyname)
 
52
{
 
53
    KeySym sym;
 
54
 
 
55
    sym = XStringToKeysym(keyname);
 
56
 
 
57
    if (sym == NoSymbol)
 
58
        return -1;
 
59
 
 
60
    return (signed long)sym;
 
61
}
 
62
 
 
63
const char *kbd_arch_keynum_to_keyname(signed long keynum)
 
64
{
 
65
    return XKeysymToString((KeySym)keynum);
 
66
}
 
67
 
 
68
/* ------------------------------------------------------------------ */
 
69
 
 
70
/* Meta status (used to filter out keypresses when meta is pressed).  */
 
71
static int meta_count = 0;
 
72
static int control_count, shift_count;
 
73
 
 
74
void x11kbd_press(signed long key)
 
75
{
 
76
#ifdef DEBUG_KBD
 
77
    log_debug("KeyPress `%s'.", XKeysymToString(key));
 
78
#endif
 
79
 
 
80
    /* Hotkeys */
 
81
    switch (key) {
 
82
      case XK_Shift_L:
 
83
      case XK_Shift_R:
 
84
        shift_count++;
 
85
        break;
 
86
 
 
87
      case XK_Control_L:
 
88
      case XK_Control_R:
 
89
        control_count++;
 
90
        break;
 
91
      case XK_Meta_L:
 
92
      case XK_Meta_R:
 
93
#ifdef ALT_AS_META
 
94
      case XK_Alt_L:
 
95
      case XK_Alt_R:
 
96
#endif
 
97
#ifdef MODE_SWITCH_AS_META
 
98
      case XK_Mode_switch:
 
99
#endif
 
100
        meta_count++;
 
101
        break;
 
102
    }
 
103
 
 
104
    if ((meta_count != 0) &&
 
105
        ui_dispatch_hotkeys(key))
 
106
        return;
 
107
 
 
108
    if (vsid_mode)
 
109
        return;
 
110
 
 
111
    if (meta_count != 0)
 
112
        return;
 
113
 
 
114
    if (key == NoSymbol)
 
115
        return;
 
116
 
 
117
    keyboard_key_pressed(key);
 
118
}
 
119
 
 
120
void x11kbd_release(signed long key)
 
121
{
 
122
#ifdef DEBUG_KBD
 
123
    log_debug("KeyRelease `%s'.", XKeysymToString(key));
 
124
#endif
 
125
 
 
126
    /* Hotkeys */
 
127
    switch (key) {
 
128
      case XK_Shift_L:
 
129
      case XK_Shift_R:
 
130
        if (shift_count > 0)
 
131
            shift_count--;
 
132
        break;
 
133
      case XK_Control_L:
 
134
      case XK_Control_R:
 
135
        if (control_count > 0)
 
136
            control_count--;
 
137
        break;
 
138
      case XK_Meta_L:
 
139
      case XK_Meta_R:
 
140
#ifdef ALT_AS_META
 
141
      case XK_Alt_L:
 
142
      case XK_Alt_R:
 
143
#endif
 
144
#ifdef MODE_SWITCH_AS_META
 
145
      case XK_Mode_switch:
 
146
#endif
 
147
        if (meta_count > 0)
 
148
            meta_count--;
 
149
        break;
 
150
    }
 
151
 
 
152
    if (vsid_mode)
 
153
        return;
 
154
 
 
155
    if (meta_count != 0)
 
156
        return;
 
157
    if (IsModifierKey(key)) {
 
158
        /* FIXME: This is a dirty kludge.  X11 can sometimes give the
 
159
           KeyPress event with the shifted KeySym, and the KeyRelease one
 
160
           with the same KeySym unshifted, so we loose control of what
 
161
           has been pressed and what has been released (all KeySyms are
 
162
           handled independently here).  For example, if the user does
 
163
           <Press Shift> <Press 1> <Release Shift> <Release 1>, we get
 
164
           <KeyPress Shift>, <KeyPress !>, <KeyRelease Shift>,
 
165
           <KeyRelease 1>.  To avoid disasters, we reset all the keyboard
 
166
           when a modifier has been released, but this heavily simplifies
 
167
           the behavior of multiple keys.  Does anybody know a way to
 
168
           avoid this X11 oddity?  */
 
169
        /*virtual_shift_down = 0;*/
 
170
        keyboard_key_clear();
 
171
        /* TODO: do we have to cleanup joypads here too? */
 
172
    }
 
173
 
 
174
    if (key == NoSymbol)
 
175
        return;
 
176
 
 
177
    keyboard_key_released(key);
 
178
}
 
179
 
 
180
void x11kbd_enter_leave(void)
 
181
{
 
182
    keyboard_key_clear();
 
183
    meta_count = 0;
 
184
    return;
 
185
}
 
186
 
 
187
void x11kbd_focus_change(void)
 
188
{
 
189
    keyboard_key_clear();
 
190
    meta_count = control_count = shift_count = 0;
 
191
    return;
 
192
}
46
193
 
47
194
void kbd_event_handler(Widget w, XtPointer client_data, XEvent *report,
48
195
                       Boolean *ctd)