summaryrefslogtreecommitdiff
path: root/console-client
diff options
context:
space:
mode:
Diffstat (limited to 'console-client')
-rw-r--r--console-client/xkb/xkb.c508
-rw-r--r--console-client/xkb/xkbtimer.c2
2 files changed, 3 insertions, 507 deletions
diff --git a/console-client/xkb/xkb.c b/console-client/xkb/xkb.c
index 5844ac60..077667dc 100644
--- a/console-client/xkb/xkb.c
+++ b/console-client/xkb/xkb.c
@@ -36,15 +36,9 @@
#define XK_XKB_KEYS
#define XK_MISCELLANY
#include "keysymdef.h"
-#include "driver.h"
-#include "inputdev.h"
+#include <driver.h>
+#include <mach-inputdev.h>
-
-/* The keyboard device in the kernel. */
-static device_t kbd_dev;
-
-/* True if we are in the GNU Mach v1 compatibility mode. */
-int gnumach_v1_compat;
#define NoSymbol 0
@@ -106,12 +100,6 @@ static int indicator_map = 0;
static int stickykeys_active = 1;
-/* The name of the repeater node. */
-static char *repeater_node;
-
-/* The repeater node. */
-static consnode_t cnode;
-
int
debug_printf (const char *f, ...)
{
@@ -127,167 +115,6 @@ debug_printf (const char *f, ...)
return ret;
}
-static scancode_t
-gnumach_v1_input_next ()
-{
- kd_event data_buf;
- scancode_t sc;
-
- do
- {
- /* io_buf_ptr_t is (char *), not (void *). So I have a few
- casts to quiet warnings. */
- mach_msg_type_number_t data_cnt = sizeof (data_buf);
- error_t err = device_read_inband (kbd_dev, 0, -1, sizeof (kd_event),
- (void *) &data_buf, &data_cnt);
-
- if (kbd_repeater_opened && data_buf.type == KEYBD_EVENT)
- {
- kbd_repeat_key (&data_buf);
- data_buf.type = 0;
- continue;
- }
-
- /* XXX The error occured likely because KBD_DEV was closed, so
- terminate. */
- if (err)
- return 0;
- }
- while (data_buf.type != KEYBD_EVENT);
-
- sc = data_buf.value.sc;
- return sc;
-}
-
-
-scancode_t
-read_scancode (void)
-{
- scancode_t sc = 0;
- unsigned char next;
- kd_event data_buf;
-
- /* GNU Mach v1 does provide keyboard input in a different format. */
- if (gnumach_v1_compat)
- {
- int scan = gnumach_v1_input_next ();
- return scan;
- }
-
- /* XXX This should read several characters at once. */
- do
- {
- /* io_buf_ptr_t is (char *), not (void *). So I have a few
- casts to quiet warnings. */
- mach_msg_type_number_t data_cnt = sizeof (data_buf);
-
- error_t err = device_read_inband (kbd_dev, 0, -1, sizeof (kd_event),
- (void *) &data_buf, &data_cnt);
-
- if (kbd_repeater_opened && data_buf.type == KEYBD_EVENT)
- {
- kbd_repeat_key (&data_buf);
- data_buf.type = 0;
- continue;
- }
-
- next = data_buf.value.sc;
- /* XXX The error occured likely because KBD_DEV was closed, so
- terminate. */
- if (err)
- return 0;
-
- }
- while (next == 0xF0); /* XXX Magic constant. */
-
- sc |= next;
- return sc;
-}
-
-/* Read a keycode using the read_scancode routine. The translation from
- scancodes is hardcoded. A configuration file should be used in the
- near future because this is an UGLY HACK. */
-keycode_t
-read_keycode (void)
-{
- scancode_t sc = read_scancode ();
- int release = 0;
-
-
- /* The keypress generated two keycodes. */
- if (sc == 0xE0)
- {
- sc = read_scancode ();
-
- release = sc & 0x80;
- sc &= ~0x80;
-
- switch (sc)
- {
- case 0x1D: /* RCTRL. */
- sc = 101;
- break;
- case 0x38: /* RALT. */
- sc = 105;
- break;
- /* LRGUI MENU. */
- case 0x5B: /* LGUI. */
- sc = 107;
- break;
- case 0x5C: /* RGUI. */
- sc = 108;
- break;
- case 0x5D: /* MENU. */
- sc = 109;
- break;
- case 0x52: /* Insert. */
- sc = 98;
- break;
- case 0x47: /* Home. */
- sc = 89;
- break;
- case 0x49: /* Pg Up. */
- sc = 91;
- break;
- case 0x53: /* Delete. */
- sc = 99;
- break;
- case 0x4F: /* End. */
- sc = 95;
- break;
- case 0x51: /* Pg Down. */
- sc = 97;
- break;
- case 0x48: /* Arrow up. */
- sc = 90;
- break;
- case 0x50: /* Arrow down. */
- sc = 96;
- break;
- case 0x4b: /* Arrow left. */
- sc = 92;
- break;
- case 0x4d: /* Arrow right. */
- sc = 94;
- break;
- case 0x35: /* '/' */
- sc = 104;
- break;
- case 0x1C: /* KP_Enter. */
- sc = 100;
- break;
- default:
- sc += 0x78;
- }
-
- sc |= release;
- }
- else
- release = sc & 0x80;
-
- return sc;
-}
-
static void
interpret_kc (keycode_t kc)
@@ -1328,10 +1155,6 @@ handle_key (keypress_t key)
return sym;
}
-/* CTRL + Alt + Backspace will terminate the console client by
- default, this hardcoded behaviour can be disabled. */
-int ctrlaltbs;
-
void
xkb_input (keypress_t key)
{
@@ -1529,331 +1352,4 @@ xkb_input (keypress_t key)
size = 0;
}
-any_t
-input_loop (any_t foo)
-{
- keycode_t prevkey = 0;
-
- for (;;)
- {
- /* The previous keypress. */
- // static keypress_t prevkey = { 0 };
- keypress_t key;
-
- key.keycode = read_keycode () + min_keys;
- key.rel = key.keycode & 0x80;
- key.redir = 0;
-
-/* if (key.keycode == 9) */
-/* console_exit (); */
-
- // printf ("read keycode: %d\n", key.keycode);
-
- if (!key.rel && key.keycode == prevkey)
- key.repeat = 1;
- else
- key.repeat = 0;
-
- if (key.repeat)
- continue;
-
- /* The keycombination CTRL+Alt+Backspace terminates the console
- client. Keycodes instead of modifiers+symbols are used to
- make it able to exit the client, even when the keymaps are
- faulty. */
- if ((keystate[64].keypressed || keystate[113].keypressed) /* Alt */
- && (keystate[37].keypressed || keystate[109].keypressed) /* CTRL*/
- && keystate[22].keypressed && ctrlaltbs) /* Backspace. */
- console_exit ();
-
- debug_printf ("---%d %d %d---\n", keystate[64].keypressed,
- keystate[37].keypressed, keystate[22].keypressed);
-
- if (!key.repeat)
- xkb_input_key (key.keycode);
- prevkey = key.keycode;
- }
-}
-
-
-/* /\* Read a single symbol. *\/ */
-/* static symbol */
-/* read_symbol (void) */
-/* { */
-/* symbol sym; */
-
-/* for (;;) */
-/* { */
-/* keypress_t key; */
-
-/* /\* A keycode generated by a timer should be handled here. *Somehow* *\/ */
-
-
-/* /\* /\\* Check if this keypress event was the result of a typematic *\/ */
-/* /\* repeat. *\\/ *\/ */
-/* /\* if (!key.rel) *\/ */
-/* /\* { *\/ */
-/* /\* key.repeat = keystate[key.keycode].keypressed; *\/ */
-/* /\* keystate[key.keycode].lmods = lmods; *\/ */
-/* /\* } *\/ */
-/* /\* else *\/ */
-/* /\* { *\/ */
-/* /\* if (keystate[key.keycode].keypressed) *\/ */
-/* /\* key.repeat = 0; *\/ */
-/* /\* else /\\* Keyreleased that was never pressed. *\\/ *\/ */
-/* /\* return 0; *\/ */
-/* /\* } *\/ */
-
-
-
-/* // sym = handle_key (key); */
-/* sym = 0; */
-
-/* // printf ("Key: %d (%d)\n", (int) sym, key.keycode); */
-
-/* // keystate[key.keycode].hwkeypressed = key.rel ? 0 : 1; */
-
-
-/* if (!key.repeat) */
-/* prevkey = key; */
-
-/* /\* Not every keypress results in a symbol, see handle_key. *\/ */
-/* /\* XXX: returning 0 when there is no symbol is incorrect */
-/* behaviour because 0 is a valid symbol value. *\/ */
-/* if (sym != -1) */
-/* return sym; */
-/* } */
-/* } */
-
-static struct arguments
-{
- char *xkbdir;
- char *keymapfile;
- char *keymap;
- char *composefile;
- int ctrlaltbs;
- int pos;
-} arguments = { ctrlaltbs: 1 };
-
error_t parse_xkbconfig (char *xkbdir, char *xkbkeymapfile, char *xkbkeymap);
-
-static error_t xkb_start (void *handle);
-static error_t xkb_init (void **handle, int no_exit, int argc, char *argv[],
- int *next);
-
-/* const char *argp_program_version = "XKB plugin 0.003"; */
-/* const char *argp_program_bug_address = "metgerards@student.han.nl"; */
-static struct argp_option options[] = {
- {"xkbdir", 'x', "DIR", 0,
- "directory containing the XKB configuration files" },
- {"keymapfile", 'f', "FILE", 0,
- "file containing the keymap" },
- {"keymap", 'k', "SECTIONNAME" , 0,
- "choose keymap"},
- {"compose", 'o', "COMPOSEFILE", 0,
- "Compose file to load (default none)"},
- {"ctrlaltbs", 'c', 0 , 0,
- "CTRL + Alt + Backspace will exit the console client (default)."},
- {"no-ctrlaltbs", 'n', 0 , 0,
- "CTRL + Alt + Backspace will not exit the console client."},
- {"repeat", 'r', "NODE", 0, "Set a repeater translator on NODE"},
- {0}
-};
-
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
- struct arguments *arguments = state->input;
-
- switch (key)
- {
- case 'x':
- arguments->xkbdir = arg;
- break;
-
- case 'f':
- arguments->keymapfile = arg;
- break;
-
- case 'k':
- arguments->keymap = arg;
- break;
-
- case 'o':
- arguments->composefile = arg;
- break;
-
- case 'c':
- arguments->ctrlaltbs = 1;
- break;
-
- case 'n':
- arguments->ctrlaltbs = 0;
- break;
-
- case 'r':
- repeater_node = arg;
- break;
-
- case ARGP_KEY_END:
- break;
-
- default:
- return ARGP_ERR_UNKNOWN;
- }
-
- arguments->pos = state->next;
- return 0;
-}
-
-static struct argp argp = {options, parse_opt, 0, 0};
-
-static error_t
-xkb_init (void **handle, int no_exit, int argc, char **argv, int *next)
-{
- error_t err;
- int lastarg;
-
- setlocale(LC_ALL, "");
-
- arguments.pos = 1;
- err = argp_parse (&argp, argc, argv, ARGP_IN_ORDER | ARGP_NO_EXIT
- | ARGP_SILENT, 0, &arguments);
- *next += arguments.pos - 1;
- if (err && err != EINVAL)
- return err;
-
- /* Defaults. */
- if (!arguments.xkbdir)
- arguments.xkbdir = "/home/marco/xkb";
- /* debug: */
-/* arguments.keymapfile = "keymap/hurd"; */
-/* arguments.keymap = "Hurd"; */
-/* arguments.xkbdir = "/home/marco/xkb"; */
-/* arguments.keymapfile = "keymap/xfree86"; */
-/* arguments.keymap = "us"; */
-
-
- ctrlaltbs = arguments.ctrlaltbs;
-
- if (arguments.composefile)
- {
- err = read_composefile (arguments.composefile);
- if (err)
- return err;
- }
-
- xkb_data_init ();
- err = parse_xkbconfig (arguments.xkbdir, arguments.keymapfile,
- arguments.keymap);
-
- if (err)
- return err;
-
- determine_keytypes ();
- interpret_all ();
-
- return 0;
-}
-
-/* static any_t */
-/* input_loop (any_t blaat) */
-/* { */
-
-/* for (;;) */
-/* { */
-/* wchar_t input = read_symbol (); */
-
-
-/* } */
-
-
-static struct input_ops xkb_ops;
-
-static error_t
-xkb_start (void *handle)
-{
- error_t err;
- device_t device_master;
-
- cd = iconv_open ("UTF-8", "WCHAR_T");
- if (cd == (iconv_t) -1)
- return errno;
-
- xkb_init_repeat (100L, 10L);
-
- err = get_privileged_ports (0, &device_master);
- if (err)
- return err;
-
- err = device_open (device_master, D_READ | D_WRITE, "@>=kbd", &kbd_dev);
- if (err == D_NO_SUCH_DEVICE)
- {
- /* GNU Mach v1 has a different device. */
- gnumach_v1_compat = 1;
- err = device_open (device_master, D_READ, "kbd", &kbd_dev);
- }
-
- mach_port_deallocate (mach_task_self (), device_master);
- if (err)
- return err;
-
- if (gnumach_v1_compat)
- {
- int data = KB_EVENT;
- err = device_set_status (kbd_dev, KDSKBDMODE, &data, 1);
- if (err)
- {
- device_close (kbd_dev);
- mach_port_deallocate (mach_task_self (), kbd_dev);
- return err;
- }
- }
-
- driver_add_input (&xkb_ops, NULL);
-
- if (repeater_node)
- kbd_setrepeater (repeater_node, &cnode);
-
- cthread_detach (cthread_fork (input_loop, NULL));
-
- return 0;
-}
-
-static error_t
-xkb_fini (void *handle, int force)
-{
- driver_remove_input (&xkb_ops, NULL);
-
- if (gnumach_v1_compat)
- {
- int data = KB_ASCII;
- device_set_status (kbd_dev, KDSKBDMODE, &data, 1);
- }
- device_close (kbd_dev);
- mach_port_deallocate (mach_task_self (), kbd_dev);
-
- console_unregister_consnode (cnode);
- console_destroy_consnode (cnode);
-
- return 0;
-}
-
-static error_t
-xkb_set_scroll_lock_status (void *handle, int onoff)
-{
- return 0;
-}
-
-struct driver_ops driver_xkb_ops =
- {
- xkb_init,
- xkb_start,
- xkb_fini
- };
-
-static struct input_ops xkb_ops =
- {
- xkb_set_scroll_lock_status,
- NULL
- };
diff --git a/console-client/xkb/xkbtimer.c b/console-client/xkb/xkbtimer.c
index f50bb9ad..4d366de5 100644
--- a/console-client/xkb/xkbtimer.c
+++ b/console-client/xkb/xkbtimer.c
@@ -22,7 +22,7 @@
#include <assert.h>
#include "xkb.h"
-#include "timer.h"
+#include <timer.h>
/* Lock the access to handle_key. */
static struct mutex *lock_key;