/branches/dynload/uspace/srv/kbd/include/layout.h |
---|
38,9 → 38,17 |
#define KBD_LAYOUT_H_ |
#include <kbd/kbd.h> |
#include <sys/types.h> |
extern char layout_parse_ev(kbd_event_t *); |
typedef struct { |
void (*reset)(void); |
wchar_t (*parse_ev)(kbd_event_t *); |
} layout_op_t; |
extern layout_op_t us_qwerty_op; |
extern layout_op_t us_dvorak_op; |
extern layout_op_t cz_op; |
#endif |
/** |
/branches/dynload/uspace/srv/kbd/include/kbd.h |
---|
38,6 → 38,7 |
#define KBD_KBD_H_ |
#include <key_buffer.h> |
#include <ipc/ipc.h> |
#define KBD_EVENT 1024 |
#define KBD_MS_LEFT 1025 |
45,6 → 46,11 |
#define KBD_MS_MIDDLE 1027 |
#define KBD_MS_MOVE 1028 |
typedef enum { |
KBD_YIELD = IPC_FIRST_USER_METHOD, |
KBD_RECLAIM |
} kbd_request_t; |
extern int cir_service; |
extern int cir_phone; |
/branches/dynload/uspace/srv/kbd/include/key_buffer.h |
---|
55,7 → 55,6 |
extern int keybuffer_available(keybuffer_t *); |
extern int keybuffer_empty(keybuffer_t *); |
extern void keybuffer_push(keybuffer_t *, const kbd_event_t *); |
extern void keybuffer_push0(keybuffer_t *, int c); |
extern int keybuffer_pop(keybuffer_t *, kbd_event_t *); |
#endif |
/branches/dynload/uspace/srv/kbd/include/kbd_port.h |
---|
38,6 → 38,8 |
#define KBD_PORT_H_ |
extern int kbd_port_init(void); |
extern void kbd_port_yield(void); |
extern void kbd_port_reclaim(void); |
#endif |
/branches/dynload/uspace/srv/kbd/include/sun.h |
---|
0,0 → 1,47 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup kbdgen generic |
* @brief Sun keyboard virtual port driver. |
* @ingroup kbd |
* @{ |
*/ |
/** @file |
*/ |
#ifndef KBD_SUN_H_ |
#define KBD_SUN_H_ |
extern int ns16550_port_init(void); |
extern int z8530_port_init(void); |
#endif |
/** |
* @} |
*/ |
/branches/dynload/uspace/srv/kbd/port/gxemul.c |
---|
69,6 → 69,14 |
return 0; |
} |
void kbd_port_yield(void) |
{ |
} |
void kbd_port_reclaim(void) |
{ |
} |
/** Process data sent when a key is pressed. |
* |
* @param keybuffer Buffer of pressed keys. |
/branches/dynload/uspace/srv/kbd/port/ns16550.c |
---|
35,10 → 35,12 |
*/ |
#include <ipc/ipc.h> |
#include <ipc/bus.h> |
#include <async.h> |
#include <sysinfo.h> |
#include <kbd.h> |
#include <kbd_port.h> |
#include <sun.h> |
#include <ddi.h> |
/* NS16550 registers */ |
89,7 → 91,7 |
static uintptr_t ns16550_physical; |
static uintptr_t ns16550_kernel; |
int kbd_port_init(void) |
int ns16550_port_init(void) |
{ |
void *vaddr; |
100,14 → 102,26 |
ns16550_kbd.cmds[0].addr = (void *) (ns16550_kernel + LSR_REG); |
ns16550_kbd.cmds[3].addr = (void *) (ns16550_kernel + RBR_REG); |
ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(), |
0, &ns16550_kbd); |
sysinfo_value("kbd.inr"), &ns16550_kbd); |
return pio_enable((void *) ns16550_physical, 8, &vaddr); |
} |
void ns16550_port_yield(void) |
{ |
} |
void ns16550_port_reclaim(void) |
{ |
} |
static void ns16550_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
{ |
int scan_code = IPC_GET_ARG2(*call); |
kbd_push_scancode(scan_code); |
if (cir_service) |
async_msg_1(cir_phone, BUS_CLEAR_INTERRUPT, |
IPC_GET_METHOD(*call)); |
} |
/** |
/branches/dynload/uspace/srv/kbd/port/msim.c |
---|
69,22 → 69,17 |
return 0; |
} |
void kbd_port_yield(void) |
{ |
} |
void kbd_port_reclaim(void) |
{ |
} |
static void msim_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
{ |
int scan_code = IPC_GET_ARG2(*call); |
// static int esc_count=0; |
// if (scan_code == 0x1b) { |
// esc_count++; |
// if (esc_count == 3) |
// __SYSCALL0(SYS_DEBUG_ENABLE_CONSOLE); |
// } else { |
// esc_count=0; |
// } |
// if (fb_fb) |
// return kbd_arch_process_fb(keybuffer, scan_code); |
kbd_push_scancode(scan_code); |
} |
/branches/dynload/uspace/srv/kbd/port/sun.c |
---|
0,0 → 1,74 |
/* |
* Copyright (c) 2009 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup kbd_port |
* @ingroup kbd |
* @{ |
*/ |
/** @file |
* @brief Sun keyboard virtual port driver. |
*/ |
#include <kbd.h> |
#include <kbd_port.h> |
#include <sun.h> |
#include <sysinfo.h> |
/** Sun keyboard virtual port driver. |
* |
* This is a virtual port driver which can use |
* both ns16550_port_init and z8530_port_init |
* according to the information passed from the |
* kernel. This is just a temporal hack. |
* |
*/ |
int kbd_port_init(void) |
{ |
if (sysinfo_value("kbd.type.z8530")) { |
if (z8530_port_init() == 0) |
return 0; |
} |
if (sysinfo_value("kbd.type.ns16550")) { |
if (ns16550_port_init() == 0) |
return 0; |
} |
return -1; |
} |
void kbd_port_yield(void) |
{ |
} |
void kbd_port_reclaim(void) |
{ |
} |
/** @} |
*/ |
/branches/dynload/uspace/srv/kbd/port/i8042.c |
---|
151,6 → 151,14 |
return 0; |
} |
void kbd_port_yield(void) |
{ |
} |
void kbd_port_reclaim(void) |
{ |
} |
static void i8042_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
{ |
int status = IPC_GET_ARG1(*call); |
/branches/dynload/uspace/srv/kbd/port/ski.c |
---|
42,6 → 42,7 |
#include <kbd_port.h> |
#include <sys/types.h> |
#include <thread.h> |
#include <bool.h> |
#define SKI_GETCHAR 21 |
50,6 → 51,8 |
static void *ski_thread_impl(void *arg); |
static int32_t ski_getchar(void); |
static volatile bool polling_disabled = false; |
/** Initialize Ski port driver. */ |
int kbd_port_init(void) |
{ |
64,6 → 67,16 |
return 0; |
} |
void kbd_port_yield(void) |
{ |
polling_disabled = true; |
} |
void kbd_port_reclaim(void) |
{ |
polling_disabled = false; |
} |
/** Thread to poll Ski for keypresses. */ |
static void *ski_thread_impl(void *arg) |
{ |
71,7 → 84,7 |
(void) arg; |
while (1) { |
while (1) { |
while (polling_disabled == false) { |
c = ski_getchar(); |
if (c == 0) |
break; |
/branches/dynload/uspace/srv/kbd/port/z8530.c |
---|
40,6 → 40,7 |
#include <sysinfo.h> |
#include <kbd.h> |
#include <kbd_port.h> |
#include <sun.h> |
#include <sys/types.h> |
#include <ddi.h> |
82,7 → 83,7 |
static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call); |
int kbd_port_init(void) |
int z8530_port_init(void) |
{ |
async_set_interrupt_received(z8530_irq_handler); |
z8530_cmds[0].addr = (void *) sysinfo_value("kbd.address.kernel") + |
94,6 → 95,14 |
return 0; |
} |
void z8530_port_yield(void) |
{ |
} |
void z8530_port_reclaim(void) |
{ |
} |
static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call) |
{ |
int scan_code = IPC_GET_ARG2(*call); |
/branches/dynload/uspace/srv/kbd/port/sgcn.c |
---|
42,6 → 42,7 |
#include <sysinfo.h> |
#include <stdio.h> |
#include <thread.h> |
#include <bool.h> |
#define POLL_INTERVAL 10000 |
92,6 → 93,7 |
/* polling thread */ |
static void *sgcn_thread_impl(void *arg); |
static volatile bool polling_disabled = false; |
/** |
* Initializes the SGCN driver. |
120,6 → 122,16 |
return 0; |
} |
void kbd_port_yield(void) |
{ |
polling_disabled = true; |
} |
void kbd_port_reclaim(void) |
{ |
polling_disabled = false; |
} |
/** |
* Handler of the "key pressed" event. Reads codes of all the pressed keys from |
* the buffer. |
154,11 → 166,11 |
(void) arg; |
while (1) { |
sgcn_key_pressed(); |
if (polling_disabled == false) |
sgcn_key_pressed(); |
usleep(POLL_INTERVAL); |
} |
} |
/** @} |
*/ |
/branches/dynload/uspace/srv/kbd/port/dummy.c |
---|
42,5 → 42,13 |
return 0; |
} |
void kbd_port_yield(void) |
{ |
} |
void kbd_port_reclaim(void) |
{ |
} |
/** @} |
*/ |
/branches/dynload/uspace/srv/kbd/generic/kbd.c |
---|
70,6 → 70,16 |
int cir_service = 0; |
int cir_phone = -1; |
#define NUM_LAYOUTS 3 |
static layout_op_t *layout[NUM_LAYOUTS] = { |
&us_qwerty_op, |
&us_dvorak_op, |
&cz_op |
}; |
static int active_layout = 0; |
void kbd_push_scancode(int scancode) |
{ |
/* printf("scancode: 0x%x\n", scancode);*/ |
123,11 → 133,32 |
printf("mods: 0x%x\n", mods); |
printf("keycode: %u\n", key); |
*/ |
if (type == KE_PRESS && (mods & KM_LCTRL) && |
key == KC_F1) { |
active_layout = 0; |
layout[active_layout]->reset(); |
return; |
} |
if (type == KE_PRESS && (mods & KM_LCTRL) && |
key == KC_F2) { |
active_layout = 1; |
layout[active_layout]->reset(); |
return; |
} |
if (type == KE_PRESS && (mods & KM_LCTRL) && |
key == KC_F3) { |
active_layout = 2; |
layout[active_layout]->reset(); |
return; |
} |
ev.type = type; |
ev.key = key; |
ev.mods = mods; |
ev.c = layout_parse_ev(&ev); |
ev.c = layout[active_layout]->parse_ev(&ev); |
async_msg_4(phone2cons, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c); |
} |
162,6 → 193,14 |
phone2cons = IPC_GET_ARG5(call); |
retval = 0; |
break; |
case KBD_YIELD: |
kbd_port_yield(); |
retval = 0; |
break; |
case KBD_RECLAIM: |
kbd_port_reclaim(); |
retval = 0; |
break; |
default: |
retval = EINVAL; |
} |
195,6 → 234,9 |
/* Initialize controller driver. */ |
if (kbd_ctl_init() != 0) |
return -1; |
/* Initialize (reset) layout. */ |
layout[active_layout]->reset(); |
/* Initialize key buffer */ |
keybuffer_init(&keybuffer); |
/branches/dynload/uspace/srv/kbd/generic/key_buffer.c |
---|
93,14 → 93,6 |
futex_up(&keybuffer_futex); |
} |
void keybuffer_push0(keybuffer_t *keybuffer, int c) |
{ |
kbd_event_t ev; |
ev.key = c; ev.mods = 0; ev.c = c; |
keybuffer_push(keybuffer, &ev); |
} |
/** Pop event from buffer. |
* |
* @param edst Pointer to where the event should be saved. |
/branches/dynload/uspace/srv/kbd/Makefile |
---|
49,23 → 49,21 |
generic/key_buffer.c |
ARCH_SOURCES = |
GENARCH_SOURCES = |
GENARCH_SOURCES = \ |
layout/cz.c \ |
layout/us_qwerty.c \ |
layout/us_dvorak.c |
ifeq ($(KBD_LAYOUT), us_qwerty) |
GENARCH_SOURCES += layout/us_qwerty.c |
endif |
ifeq ($(KBD_LAYOUT), us_dvorak) |
GENARCH_SOURCES += layout/us_dvorak.c |
endif |
ifeq ($(UARCH), amd64) |
GENARCH_SOURCES += \ |
port/i8042.c \ |
ctl/pc.c |
endif |
ifeq ($(UARCH), arm32) |
GENARCH_SOURCES += \ |
port/gxemul.c |
ifeq ($(CONFIG_FB), y) |
GENARCH_SOURCES += \ |
ctl/gxe_fb.c |
74,29 → 72,35 |
ctl/stty.c |
endif |
endif |
ifeq ($(UARCH), ia32) |
GENARCH_SOURCES += \ |
port/i8042.c \ |
ctl/pc.c |
endif |
ifeq ($(MACHINE), i460GX) |
GENARCH_SOURCES += \ |
port/i8042.c \ |
ctl/pc.c |
endif |
ifeq ($(MACHINE), ski) |
GENARCH_SOURCES += \ |
port/ski.c \ |
ctl/stty.c |
endif |
ifeq ($(MACHINE), msim) |
GENARCH_SOURCES += \ |
port/msim.c \ |
ctl/stty.c |
endif |
ifeq ($(MACHINE), lgxemul) |
GENARCH_SOURCES += \ |
port/gxemul.c |
ifeq ($(CONFIG_FB), y) |
GENARCH_SOURCES += \ |
ctl/gxe_fb.c |
105,26 → 109,38 |
ctl/stty.c |
endif |
endif |
ifeq ($(MACHINE), bgxemul) |
GENARCH_SOURCES += \ |
port/gxemul.c \ |
ctl/stty.c |
port/gxemul.c |
ifeq ($(CONFIG_FB), y) |
GENARCH_SOURCES += \ |
ctl/gxe_fb.c |
else |
GENARCH_SOURCES += \ |
ctl/stty.c |
endif |
endif |
ifeq ($(UARCH), ppc32) |
GENARCH_SOURCES += \ |
port/dummy.c \ |
ctl/stty.c |
endif |
ifeq ($(UARCH), sparc64) |
ifeq ($(MACHINE),serengeti) |
GENARCH_SOURCES += \ |
port/sgcn.c \ |
ctl/stty.c |
else |
GENARCH_SOURCES += \ |
port/z8530.c \ |
ctl/sun.c |
endif |
ifeq ($(MACHINE),serengeti) |
GENARCH_SOURCES += \ |
port/sgcn.c \ |
ctl/stty.c |
else |
GENARCH_SOURCES += \ |
port/sun.c \ |
port/z8530.c \ |
port/ns16550.c \ |
ctl/sun.c |
endif |
endif |
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES))) |
/branches/dynload/uspace/srv/kbd/layout/us_qwerty.c |
---|
36,7 → 36,15 |
#include <kbd/keycode.h> |
#include <layout.h> |
static char map_lcase[] = { |
static void layout_reset(void); |
static wchar_t layout_parse_ev(kbd_event_t *ev); |
layout_op_t us_qwerty_op = { |
layout_reset, |
layout_parse_ev |
}; |
static wchar_t map_lcase[] = { |
[KC_Q] = 'q', |
[KC_W] = 'w', |
[KC_E] = 'e', |
67,7 → 75,7 |
[KC_M] = 'm', |
}; |
static char map_ucase[] = { |
static wchar_t map_ucase[] = { |
[KC_Q] = 'Q', |
[KC_W] = 'W', |
[KC_E] = 'E', |
98,7 → 106,7 |
[KC_M] = 'M', |
}; |
static char map_not_shifted[] = { |
static wchar_t map_not_shifted[] = { |
[KC_BACKTICK] = '`', |
[KC_1] = '1', |
127,7 → 135,7 |
[KC_SLASH] = '/', |
}; |
static char map_shifted[] = { |
static wchar_t map_shifted[] = { |
[KC_BACKTICK] = '~', |
[KC_1] = '!', |
156,7 → 164,7 |
[KC_SLASH] = '?', |
}; |
static char map_neutral[] = { |
static wchar_t map_neutral[] = { |
[KC_BACKSPACE] = '\b', |
[KC_TAB] = '\t', |
[KC_ENTER] = '\n', |
169,7 → 177,7 |
[KC_NENTER] = '\n' |
}; |
static char map_numeric[] = { |
static wchar_t map_numeric[] = { |
[KC_N7] = '7', |
[KC_N8] = '8', |
[KC_N9] = '9', |
184,39 → 192,47 |
[KC_NPERIOD] = '.' |
}; |
static int translate(unsigned int key, char *map, size_t map_length) |
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
{ |
if (key >= map_length) return 0; |
return map[key]; |
if (key >= map_length) |
return 0; |
return map[key]; |
} |
char layout_parse_ev(kbd_event_t *ev) |
static void layout_reset(void) |
{ |
char c; |
} |
static wchar_t layout_parse_ev(kbd_event_t *ev) |
{ |
wchar_t c; |
/* Produce no characters when Ctrl or Alt is pressed. */ |
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
return 0; |
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char)); |
if (c != 0) return c; |
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char)); |
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char)); |
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
if (c != 0) return c; |
if (c != 0) |
return c; |
if ((ev->mods & KM_SHIFT) != 0) |
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char)); |
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char)); |
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
if (c != 0) return c; |
if (c != 0) |
return c; |
if ((ev->mods & KM_NUM_LOCK) != 0) |
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char)); |
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
else |
c = 0; |
/branches/dynload/uspace/srv/kbd/layout/cz.c |
---|
0,0 → 1,403 |
/* |
* Copyright (c) 2009 Jiri Svoboda |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup kbd |
* @brief US QWERTY leyout. |
* @{ |
*/ |
#include <kbd.h> |
#include <kbd/kbd.h> |
#include <kbd/keycode.h> |
#include <bool.h> |
#include <layout.h> |
static void layout_reset(void); |
static wchar_t layout_parse_ev(kbd_event_t *ev); |
enum m_state { |
ms_start, |
ms_hacek, |
ms_carka |
}; |
static enum m_state mstate; |
layout_op_t cz_op = { |
layout_reset, |
layout_parse_ev |
}; |
static wchar_t map_lcase[] = { |
[KC_Q] = 'q', |
[KC_W] = 'w', |
[KC_E] = 'e', |
[KC_R] = 'r', |
[KC_T] = 't', |
[KC_Y] = 'z', |
[KC_U] = 'u', |
[KC_I] = 'i', |
[KC_O] = 'o', |
[KC_P] = 'p', |
[KC_A] = 'a', |
[KC_S] = 's', |
[KC_D] = 'd', |
[KC_F] = 'f', |
[KC_G] = 'g', |
[KC_H] = 'h', |
[KC_J] = 'j', |
[KC_K] = 'k', |
[KC_L] = 'l', |
[KC_Z] = 'y', |
[KC_X] = 'x', |
[KC_C] = 'c', |
[KC_V] = 'v', |
[KC_B] = 'b', |
[KC_N] = 'n', |
[KC_M] = 'm', |
}; |
static wchar_t map_ucase[] = { |
[KC_Q] = 'Q', |
[KC_W] = 'W', |
[KC_E] = 'E', |
[KC_R] = 'R', |
[KC_T] = 'T', |
[KC_Y] = 'Z', |
[KC_U] = 'U', |
[KC_I] = 'I', |
[KC_O] = 'O', |
[KC_P] = 'P', |
[KC_A] = 'A', |
[KC_S] = 'S', |
[KC_D] = 'D', |
[KC_F] = 'F', |
[KC_G] = 'G', |
[KC_H] = 'H', |
[KC_J] = 'J', |
[KC_K] = 'K', |
[KC_L] = 'L', |
[KC_Z] = 'Y', |
[KC_X] = 'X', |
[KC_C] = 'C', |
[KC_V] = 'V', |
[KC_B] = 'B', |
[KC_N] = 'N', |
[KC_M] = 'M', |
}; |
static wchar_t map_not_shifted[] = { |
[KC_BACKTICK] = ';', |
[KC_1] = '+', |
[KC_MINUS] = '=', |
[KC_RBRACKET] = ')', |
[KC_QUOTE] = L'§', |
[KC_COMMA] = ',', |
[KC_PERIOD] = '.', |
[KC_SLASH] = '-', |
}; |
static wchar_t map_shifted[] = { |
[KC_1] = '1', |
[KC_2] = '2', |
[KC_3] = '3', |
[KC_4] = '4', |
[KC_5] = '5', |
[KC_6] = '6', |
[KC_7] = '7', |
[KC_8] = '8', |
[KC_9] = '9', |
[KC_0] = '0', |
[KC_MINUS] = '%', |
[KC_LBRACKET] = '/', |
[KC_RBRACKET] = '(', |
[KC_SEMICOLON] = '"', |
[KC_QUOTE] = '!', |
[KC_BACKSLASH] = '\'', |
[KC_COMMA] = '?', |
[KC_PERIOD] = ':', |
[KC_SLASH] = '_', |
}; |
static wchar_t map_ns_nocaps[] = { |
[KC_2] = L'ě', |
[KC_3] = L'š', |
[KC_4] = L'č', |
[KC_5] = L'ř', |
[KC_6] = L'ž', |
[KC_7] = L'ý', |
[KC_8] = L'á', |
[KC_9] = L'í', |
[KC_0] = L'é', |
[KC_LBRACKET] = L'ú', |
[KC_SEMICOLON] = L'ů' |
}; |
static wchar_t map_ns_caps[] = { |
[KC_2] = L'Ě', |
[KC_3] = L'Š', |
[KC_4] = L'Č', |
[KC_5] = L'Ř', |
[KC_6] = L'Ž', |
[KC_7] = L'Ý', |
[KC_8] = L'Á', |
[KC_9] = L'Í', |
[KC_0] = L'É', |
[KC_LBRACKET] = L'Ú', |
[KC_SEMICOLON] = L'Ů' |
}; |
static wchar_t map_neutral[] = { |
[KC_BACKSPACE] = '\b', |
[KC_TAB] = '\t', |
[KC_ENTER] = '\n', |
[KC_SPACE] = ' ', |
[KC_NSLASH] = '/', |
[KC_NTIMES] = '*', |
[KC_NMINUS] = '-', |
[KC_NPLUS] = '+', |
[KC_NENTER] = '\n' |
}; |
static wchar_t map_numeric[] = { |
[KC_N7] = '7', |
[KC_N8] = '8', |
[KC_N9] = '9', |
[KC_N4] = '4', |
[KC_N5] = '5', |
[KC_N6] = '6', |
[KC_N1] = '1', |
[KC_N2] = '2', |
[KC_N3] = '3', |
[KC_N0] = '0', |
[KC_NPERIOD] = '.' |
}; |
static wchar_t map_hacek_lcase[] = { |
[KC_E] = L'ě', |
[KC_R] = L'ř', |
[KC_T] = L'ť', |
[KC_Y] = L'ž', |
[KC_U] = L'ů', |
[KC_S] = L'š', |
[KC_D] = L'ď', |
[KC_C] = L'č', |
[KC_N] = L'ň' |
}; |
static wchar_t map_hacek_ucase[] = { |
[KC_E] = L'Ě', |
[KC_R] = L'Ř', |
[KC_T] = L'Ť', |
[KC_Y] = L'Ž', |
[KC_U] = L'Ů', |
[KC_S] = L'Š', |
[KC_D] = L'Ď', |
[KC_C] = L'Č', |
[KC_N] = L'Ň' |
}; |
static wchar_t map_carka_lcase[] = { |
[KC_E] = L'é', |
[KC_U] = L'ú', |
[KC_I] = L'í', |
[KC_O] = L'ó', |
[KC_A] = L'á', |
[KC_Z] = L'ý', |
}; |
static wchar_t map_carka_ucase[] = { |
[KC_E] = L'É', |
[KC_U] = L'Ú', |
[KC_I] = L'Í', |
[KC_O] = L'Ó', |
[KC_A] = L'Á', |
[KC_Z] = L'Ý', |
}; |
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
{ |
if (key >= map_length) |
return 0; |
return map[key]; |
} |
static wchar_t parse_ms_hacek(kbd_event_t *ev) |
{ |
wchar_t c; |
mstate = ms_start; |
/* Produce no characters when Ctrl or Alt is pressed. */ |
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
return 0; |
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
c = translate(ev->key, map_hacek_ucase, sizeof(map_hacek_ucase) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_hacek_lcase, sizeof(map_hacek_lcase) / sizeof(wchar_t)); |
return c; |
} |
static wchar_t parse_ms_carka(kbd_event_t *ev) |
{ |
wchar_t c; |
mstate = ms_start; |
/* Produce no characters when Ctrl or Alt is pressed. */ |
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
return 0; |
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
c = translate(ev->key, map_carka_ucase, sizeof(map_carka_ucase) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_carka_lcase, sizeof(map_carka_lcase) / sizeof(wchar_t)); |
return c; |
} |
static wchar_t parse_ms_start(kbd_event_t *ev) |
{ |
wchar_t c; |
/* Produce no characters when Ctrl or Alt is pressed. */ |
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
return 0; |
if (ev->key == KC_EQUALS) { |
if ((ev->mods & KM_SHIFT) != 0) |
mstate = ms_hacek; |
else |
mstate = ms_carka; |
return 0; |
} |
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
if ((ev->mods & KM_SHIFT) == 0) { |
if ((ev->mods & KM_CAPS_LOCK) != 0) |
c = translate(ev->key, map_ns_caps, sizeof(map_ns_caps) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_ns_nocaps, sizeof(map_ns_nocaps) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
} |
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
if ((ev->mods & KM_SHIFT) != 0) |
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
if ((ev->mods & KM_NUM_LOCK) != 0) |
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
else |
c = 0; |
return c; |
} |
static bool key_is_mod(unsigned key) |
{ |
switch (key) { |
case KC_LSHIFT: |
case KC_RSHIFT: |
case KC_LALT: |
case KC_RALT: |
case KC_LCTRL: |
case KC_RCTRL: |
return true; |
default: |
return false; |
} |
} |
static void layout_reset(void) |
{ |
mstate = ms_start; |
} |
static wchar_t layout_parse_ev(kbd_event_t *ev) |
{ |
if (ev->type != KE_PRESS) |
return '\0'; |
if (key_is_mod(ev->key)) |
return '\0'; |
switch (mstate) { |
case ms_start: return parse_ms_start(ev); |
case ms_hacek: return parse_ms_hacek(ev); |
case ms_carka: return parse_ms_carka(ev); |
} |
} |
/** |
* @} |
*/ |
/branches/dynload/uspace/srv/kbd/layout/us_dvorak.c |
---|
36,7 → 36,15 |
#include <kbd/keycode.h> |
#include <layout.h> |
static char map_lcase[] = { |
static void layout_reset(void); |
static wchar_t layout_parse_ev(kbd_event_t *ev); |
layout_op_t us_dvorak_op = { |
layout_reset, |
layout_parse_ev |
}; |
static wchar_t map_lcase[] = { |
[KC_R] = 'p', |
[KC_T] = 'y', |
[KC_Y] = 'f', |
69,7 → 77,7 |
[KC_SLASH] = 'z', |
}; |
static char map_ucase[] = { |
static wchar_t map_ucase[] = { |
[KC_R] = 'P', |
[KC_T] = 'Y', |
[KC_Y] = 'F', |
102,7 → 110,7 |
[KC_SLASH] = 'Z', |
}; |
static char map_not_shifted[] = { |
static wchar_t map_not_shifted[] = { |
[KC_BACKTICK] = '`', |
[KC_1] = '1', |
132,7 → 140,7 |
[KC_Z] = ';', |
}; |
static char map_shifted[] = { |
static wchar_t map_shifted[] = { |
[KC_BACKTICK] = '~', |
[KC_1] = '!', |
162,7 → 170,7 |
[KC_Z] = ':', |
}; |
static char map_neutral[] = { |
static wchar_t map_neutral[] = { |
[KC_BACKSPACE] = '\b', |
[KC_TAB] = '\t', |
[KC_ENTER] = '\n', |
175,7 → 183,7 |
[KC_NENTER] = '\n' |
}; |
static char map_numeric[] = { |
static wchar_t map_numeric[] = { |
[KC_N7] = '7', |
[KC_N8] = '8', |
[KC_N9] = '9', |
190,7 → 198,7 |
[KC_NPERIOD] = '.' |
}; |
static int translate(unsigned int key, char *map, size_t map_length) |
static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length) |
{ |
if (key >= map_length) |
return 0; |
197,36 → 205,40 |
return map[key]; |
} |
char layout_parse_ev(kbd_event_t *ev) |
static void layout_reset(void) |
{ |
char c; |
} |
static wchar_t layout_parse_ev(kbd_event_t *ev) |
{ |
wchar_t c; |
/* Produce no characters when Ctrl or Alt is pressed. */ |
if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
return 0; |
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char)); |
c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char)); |
c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char)); |
c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
if ((ev->mods & KM_SHIFT) != 0) |
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char)); |
c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t)); |
else |
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char)); |
c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t)); |
if (c != 0) |
return c; |
if ((ev->mods & KM_NUM_LOCK) != 0) |
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char)); |
c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t)); |
else |
c = 0; |