[AD] Re: [AL] Problems using new Linux keyboard driver |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
[Moved from [AL]]
On Mon, 2004-12-06 at 23:26 +0000, Grzegorz Adam Hankiewicz wrote:
> I'm running the new exkeys but the three finger salute combination
> doesn't seem to kill the example. Can somebody reproduce this
> under X11?
>
Attached is a patch which adds Allegro's special handling of
Ctrl-Alt-End and of the pause key to the X11 keyboard driver. (Ideally
both should be moved out of the keyboard drivers (now that we have 4
drivers instead of just pckeys.c) and into keyboard.c.)
--
Elias Pschernig
Index: src/x/xkeyboard.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/x/xkeyboard.c,v
retrieving revision 1.8
diff -u -p -r1.8 xkeyboard.c
--- src/x/xkeyboard.c 3 Dec 2004 20:56:27 -0000 1.8
+++ src/x/xkeyboard.c 7 Dec 2004 14:25:04 -0000
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <signal.h>
#include <ctype.h>
#include <X11/Xlocale.h>
#include <X11/Xos.h>
@@ -29,7 +30,6 @@
#include "allegro/internal/aintern.h"
#include "allegro/platform/aintosx.h"
-// TODO: Add "Ctrl-Alt-End" shortcut
// TODO: Once this driver is deemed more stable, reduce debugging output.
#ifdef ALLEGRO_USE_XIM
@@ -42,6 +42,8 @@ static int used[KEY_MAX];
static int sym_per_key;
static int min_keycode, max_keycode;
static KeySym *keysyms = NULL;
+static int main_pid; /* The pid to kill with ctrl-alt-del. */
+static int pause_key = 0; /* Allegro's special pause key state. */
/* This table can be ammended to provide more reasonable defaults for
* mappings other than US/UK. They are used to map X11 KeySyms as found in
@@ -50,8 +52,6 @@ static KeySym *keysyms = NULL;
* keyboards. So with other mappings, the unmapped keys will be distributed
* arbitrarily to the remaining KEY_* codes.
*
- * TODO: Better to just map them to KEY_UNKNOWN1 KEY_UNKNOWN2 ...
- *
* Double mappings should be avoided, else they can lead to different keys
* producing the same KEY_* code on some mappings.
*
@@ -223,7 +223,7 @@ translation_table[] = {
{XK_Caps_Lock, KEY_CAPSLOCK}
};
-/* Table of: Allegro's modifier flag, assiciated X11 flag, toggle method. */
+/* Table of: Allegro's modifier flag, associated X11 flag, toggle method. */
static int modifier_flags[8][3] = {
{KB_SHIFT_FLAG, ShiftMask, 0},
{KB_CAPSLOCK_FLAG, LockMask, 1},
@@ -377,6 +377,20 @@ void _xwin_keyboard_handler(XKeyEvent *e
else
update_shifts (event);
+ /* Special case the pause key. */
+ if (keycode == KEY_PAUSE) {
+ /* Allegro ignore's releasing of the pause key. */
+ if (event->type == KeyRelease)
+ return;
+ if (pause_key) {
+ event->type = KeyRelease;
+ pause_key = 0;
+ }
+ else {
+ pause_key = 1;
+ }
+ }
+
if (event->type == KeyPress) { /* Key pressed. */
int len;
char buffer[16];
@@ -388,7 +402,7 @@ void _xwin_keyboard_handler(XKeyEvent *e
len = Xutf8LookupString(xic, event, buffer, sizeof buffer, NULL, NULL);
else
#endif
- /* XLookupString is supposed to only use ASCII. */
+ /* XLookupString is supposed to only use ASCII. */
len = XLookupString(event, buffer, sizeof buffer, NULL, NULL);
buffer[len] = '\0';
uconvert(buffer, U_UTF8, buffer2, U_UNICODE, sizeof buffer2);
@@ -412,7 +426,19 @@ void _xwin_keyboard_handler(XKeyEvent *e
if (_key_shifts & KB_ALT_FLAG)
unicode = 0;
}
+
_handle_key_press(unicode, keycode);
+
+ /* Detect Ctrl-Alt-End. */
+ if (keycode == KEY_END && (_key_shifts & KB_CTRL_FLAG) &&
+ (_key_shifts & KB_ALT_FLAG)) {
+ #ifndef HAVE_LIBPTHREAD
+ if (_unix_bg_man == &_bg_man_sigalrm)
+ _sigalrm_request_abort();
+ else
+ #endif
+ kill(main_pid, SIGTERM);
+ }
}
}
else { /* Key release. */
@@ -644,6 +670,8 @@ static int x_keyboard_init(void)
if (xkeyboard_installed)
return 0;
+ main_pid = getpid();
+
memcpy (key_names, _keyboard_common_names, sizeof key_names);
XLOCK ();