This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 2b7d85a804de2382d10e8f6ea2153b0e47b3e6e0 (commit) from 790d61419cab392ce0c0b2468bf43f2c554c666b (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/2b7d85a804de2382d10e8f6ea2153b0e47b3e...
commit 2b7d85a804de2382d10e8f6ea2153b0e47b3e6e0 Author: Cyril Hrubis metan@ucw.cz Date: Sat May 12 18:12:58 2012 +0200
backend, input: Add optional support for console keys.
diff --git a/include/backends/GP_LinuxFB.h b/include/backends/GP_LinuxFB.h index 1fac9a4..2dcc1c9 100644 --- a/include/backends/GP_LinuxFB.h +++ b/include/backends/GP_LinuxFB.h @@ -35,7 +35,9 @@ * deinitalized and the structure is freed by backed->Exit(backend); call. * * Upon failure NULL is returned. + * + * If flag is set, the konsole kbd is used to push events into event queue. */ -GP_Backend *GP_BackendLinuxFBInit(const char *path); +GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag);
#endif /* BACKENDS_GP_FRAMEBUFFER_H */ diff --git a/include/backends/GP_LinuxFB.h b/include/input/GP_InputDriverKBD.h similarity index 77% copy from include/backends/GP_LinuxFB.h copy to include/input/GP_InputDriverKBD.h index 1fac9a4..4212bd7 100644 --- a/include/backends/GP_LinuxFB.h +++ b/include/input/GP_InputDriverKBD.h @@ -20,22 +20,17 @@ * * *****************************************************************************/
-#ifndef BACKENDS_GP_FRAMEBUFFER_H -#define BACKENDS_GP_FRAMEBUFFER_H +/* + + + */
-#include "GP_Backend.h" +#ifndef GP_INPUT_DRIVER_KBD_H +#define GP_INPUT_DRIVER_KBD_H
/* - * Initalize framebuffer. - * - * The path should point to framebuffer device eg. "/dev/fb0" for first - * framebuffer device. - * - * The GP_Backend structure is allocated and returned, the resources are - * deinitalized and the structure is freed by backed->Exit(backend); call. - * - * Upon failure NULL is returned. + * Converts KBD event to GFXprim event and puts it into the queue. */ -GP_Backend *GP_BackendLinuxFBInit(const char *path); +void GP_InputDriverKBDEventPut(unsigned char ev);
-#endif /* BACKENDS_GP_FRAMEBUFFER_H */ +#endif /* GP_INPUT_DRIVER_KBD_H */ diff --git a/libs/backends/GP_BackendInit.c b/libs/backends/GP_BackendInit.c index 0f8e8d4..fb49b92 100644 --- a/libs/backends/GP_BackendInit.c +++ b/libs/backends/GP_BackendInit.c @@ -121,7 +121,7 @@ static GP_Backend *backend_fb_init(char *params, const char *caption, if (params != NULL) fb = params;
- return GP_BackendLinuxFBInit(fb); + return GP_BackendLinuxFBInit(fb, 1); }
static void backend_x11_help(FILE *help, const char *err) diff --git a/libs/backends/GP_LinuxFB.c b/libs/backends/GP_LinuxFB.c index 3a511c3..654989d 100644 --- a/libs/backends/GP_LinuxFB.c +++ b/libs/backends/GP_LinuxFB.c @@ -27,12 +27,15 @@ #include <fcntl.h> #include <string.h> #include <errno.h> +#include <termios.h> +#include <unistd.h>
#include <linux/fb.h> #include <linux/kd.h> #include <linux/vt.h>
#include "core/GP_Debug.h" +#include "input/GP_InputDriverKBD.h" #include "GP_LinuxFB.h"
struct fb_priv { @@ -48,23 +51,23 @@ struct fb_priv { /* * Allocates and switches to newly allocated console. */ -static int allocate_console(struct fb_priv *fb) +static int allocate_console(struct fb_priv *fb, int flag) { struct vt_stat vts; int fd, nr; char buf[255];
/* allocate and switch to new console */ - fd = open("/dev/tty1", O_WRONLY); + fd = open("/dev/tty0", O_WRONLY);
if (fd < 0) { - GP_DEBUG(1, "Opening console /dev/tty1 failed: %s", + GP_DEBUG(1, "Opening console /dev/tty0 failed: %s", strerror(errno)); return -1; } if (ioctl(fd, VT_OPENQRY, &nr) < 0) { - GP_DEBUG(1, "Failed to ioctl VT_OPENQRY /dev/tty1: %s", + GP_DEBUG(1, "Failed to ioctl VT_OPENQRY /dev/tty0: %s", strerror(errno)); close(fd); return -1; @@ -100,14 +103,35 @@ static int allocate_console(struct fb_priv *fb) close(fd); return -1; } - + /* turn off blinking cursor */ if (ioctl(fd, KDSETMODE, KD_GRAPHICS) < 0) { GP_DEBUG(1, "Failed to ioctl KDSETMODE %s: %s", buf, strerror(errno)); close(fd); + return -1; } + + /* set keyboard to raw mode */ + if (flag) { + struct termios t; + cfmakeraw(&t); + + if (tcsetattr(fd, TCSANOW, &t) < 0) { + GP_DEBUG(1, "Failed to tcsetattr(): %s", + strerror(errno)); + close(fd); + return -1; + } + if (ioctl(fd, KDSKBMODE, K_MEDIUMRAW) < 0) { + GP_DEBUG(1, "Failed to ioctl KDSKBMODE %s: %s", + buf, strerror(errno)); + close(fd); + return -1; + } + } + fb->con_nr = nr; fb->con_fd = fd;
@@ -130,6 +154,18 @@ static void fb_update_rect_noop(GP_Backend *self __attribute__((unused)),
}
+static void fb_poll(GP_Backend *self) +{ + struct fb_priv *fb = GP_BACKEND_PRIV(self); + unsigned char buf[16]; + int i, res; + + res = read(fb->con_fd, buf, sizeof(buf)); + + for (i = 0; i < res; i++) + GP_InputDriverKBDEventPut(buf[i]); +} + static void fb_exit(GP_Backend *self) { struct fb_priv *fb = GP_BACKEND_PRIV(self); @@ -149,7 +185,7 @@ static void fb_exit(GP_Backend *self) free(self); }
-GP_Backend *GP_BackendLinuxFBInit(const char *path) +GP_Backend *GP_BackendLinuxFBInit(const char *path, int flag) { GP_Backend *backend; struct fb_priv *fb; @@ -165,7 +201,7 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path)
fb = GP_BACKEND_PRIV(backend);
- if (allocate_console(fb)) + if (allocate_console(fb, flag)) goto err1;
/* open and mmap framebuffer */ @@ -240,7 +276,7 @@ GP_Backend *GP_BackendLinuxFBInit(const char *path) backend->Exit = fb_exit; backend->SetAttributes = NULL; backend->fd_list = NULL; - backend->Poll = NULL; + backend->Poll = flag ? fb_poll : NULL;
return backend; err3: diff --git a/libs/input/GP_InputDriverKBD.c b/libs/input/GP_InputDriverKBD.c new file mode 100644 index 0000000..c598c37 --- /dev/null +++ b/libs/input/GP_InputDriverKBD.c @@ -0,0 +1,79 @@ +/***************************************************************************** + * This file is part of gfxprim library. * + * * + * Gfxprim is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * Gfxprim is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with gfxprim; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * * + *****************************************************************************/ + +#include "core/GP_Debug.h" +#include "GP_Event.h" +#include "GP_InputDriverKBD.h" + +/* KBD raw mode keycodes */ +static uint16_t keycode_table[] = { + GP_KEY_ESC, GP_KEY_1, GP_KEY_2, GP_KEY_3, + GP_KEY_4, GP_KEY_5, GP_KEY_6, GP_KEY_7, + GP_KEY_8, GP_KEY_9, GP_KEY_0, GP_KEY_MINUS, + GP_KEY_EQUAL, GP_KEY_BACKSPACE, GP_KEY_TAB, GP_KEY_Q, + GP_KEY_W, GP_KEY_E, GP_KEY_R, GP_KEY_T, + GP_KEY_Y, GP_KEY_U, GP_KEY_I, GP_KEY_O, + GP_KEY_P, GP_KEY_LEFT_BRACE, GP_KEY_RIGHT_BRACE, GP_KEY_ENTER, + GP_KEY_LEFT_CTRL, GP_KEY_A, GP_KEY_S, GP_KEY_D, + GP_KEY_F, GP_KEY_G, GP_KEY_H, GP_KEY_J, + GP_KEY_K, GP_KEY_L, GP_KEY_SEMICOLON, GP_KEY_APOSTROPHE, + GP_KEY_GRAVE, GP_KEY_LEFT_SHIFT, GP_KEY_BACKSLASH, GP_KEY_Z, + GP_KEY_X, GP_KEY_C, GP_KEY_V, GP_KEY_B, + GP_KEY_N, GP_KEY_M, GP_KEY_COMMA, 0, + GP_KEY_SLASH, GP_KEY_RIGHT_SHIFT, GP_KEY_KP_ASTERISK, GP_KEY_LEFT_ALT, + GP_KEY_SPACE, GP_KEY_CAPS_LOCK, GP_KEY_F1, GP_KEY_F2, + GP_KEY_F3, GP_KEY_F4, GP_KEY_F5, GP_KEY_F6, + GP_KEY_F7, GP_KEY_F8, GP_KEY_F9, GP_KEY_F10, + GP_KEY_NUM_LOCK, GP_KEY_SCROLL_LOCK, GP_KEY_KP_7, GP_KEY_KP_8, + GP_KEY_KP_MINUS, GP_KEY_KP_9, GP_KEY_KP_4, GP_KEY_KP_5, + GP_KEY_KP_6, GP_KEY_KP_PLUS, GP_KEY_KP_1, GP_KEY_KP_2, + GP_KEY_KP_3, GP_KEY_KP_0, GP_KEY_KP_COMMA, 0, + 0, 0, GP_KEY_F11, GP_KEY_F12, + 0, 0, 0, 0, + 0, 0, 0, GP_KEY_KP_ENTER, + GP_KEY_RIGHT_CTRL, GP_KEY_KP_ASTERISK, 0/*PRINT_SCREEN*/, GP_KEY_RIGHT_ALT, + 0, GP_KEY_HOME, 0, GP_KEY_PAGE_UP, + 0, 0, GP_KEY_END, 0, + GP_KEY_PAGE_DOWN, GP_KEY_INSERT, +}; + +static const uint16_t keycode_table_size = sizeof(keycode_table)/2; + +void GP_InputDriverKBDEventPut(unsigned char ev) +{ + int press = !(ev & 0x80); + int keycode = ev & 0x7f; + int key; + + printf("Press %i keycode %in", press, keycode); + + if (keycode > 0 && keycode <= keycode_table_size) { + key = keycode_table[keycode - 1]; + + if (key != 0) { + GP_EventPushKey(key, press, NULL); + return; + } + } + + GP_DEBUG(0, "Unmapped key %i", keycode); +}
-----------------------------------------------------------------------
Summary of changes: include/backends/GP_LinuxFB.h | 4 +- include/input/{GP_Input.h => GP_InputDriverKBD.h} | 15 +++-- libs/backends/GP_BackendInit.c | 2 +- libs/backends/GP_LinuxFB.c | 52 ++++++++++++-- libs/input/GP_InputDriverKBD.c | 79 +++++++++++++++++++++ 5 files changed, 137 insertions(+), 15 deletions(-) copy include/input/{GP_Input.h => GP_InputDriverKBD.h} (88%) create mode 100644 libs/input/GP_InputDriverKBD.c
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.