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 71fb36b2881535c76334f93cc3808dc22941f31d (commit) from de77d6cd49f5ec5cb956161d1599c08fda673561 (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/71fb36b2881535c76334f93cc3808dc22941f...
commit 71fb36b2881535c76334f93cc3808dc22941f31d Author: Cyril Hrubis metan@ucw.cz Date: Fri May 4 17:06:29 2012 +0200
backeds: Improve X11 backend.
* Fix region update to update only the actuall region * Add basic key event support * Fix compilation without Xlib.
diff --git a/include/input/GP_InputDriverX11.h b/include/input/GP_InputDriverX11.h new file mode 100644 index 0000000..117a3e0 --- /dev/null +++ b/include/input/GP_InputDriverX11.h @@ -0,0 +1,39 @@ +/***************************************************************************** + * 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 * + * * + *****************************************************************************/ + +/* + + + */ + +#ifndef GP_INPUT_DRIVER_X11_H +#define GP_INPUT_DRIVER_X11_H + +#include <stdint.h> +#include <X11/Xlib.h> + +/* + * Converts X11 event to GFXprim event and puts it into the queue. + */ +void GP_InputDriverX11EventPut(XEvent *ev); + +#endif /* GP_INPUT_DRIVER_X11_H */ diff --git a/libs/backends/GP_X11.c b/libs/backends/GP_X11.c index 30bd65d..f12ade8 100644 --- a/libs/backends/GP_X11.c +++ b/libs/backends/GP_X11.c @@ -20,11 +20,16 @@ * * *****************************************************************************/
+#include "../../config.h" + +#ifdef HAVE_LIBX11 + #include <X11/Xlib.h> #include <X11/Xutil.h>
-#include "GP_X11.h" #include "core/GP_Debug.h" +#include "input/GP_InputDriverX11.h" +#include "GP_X11.h"
struct x11_priv { Display *dpy; @@ -50,13 +55,29 @@ static void x11_exit(GP_Backend *self) free(self); }
+static void x11_update_rect(GP_Backend *self, GP_Coord x0, GP_Coord y0, + GP_Coord x1, GP_Coord y1) +{ + struct x11_priv *x11 = GP_BACKEND_PRIV(self); + + GP_DEBUG(4, "Updating rect %ix%i-%ix%i", x0, y0, x1, y1); + + XLockDisplay(x11->dpy); + + XPutImage(x11->dpy, x11->win, DefaultGC(x11->dpy, x11->scr), + x11->img, x0, y0, x0, y0, x1-x0, y1-y0); + XFlush(x11->dpy); + + XUnlockDisplay(x11->dpy); +} + static void x11_flip(GP_Backend *self) { struct x11_priv *x11 = GP_BACKEND_PRIV(self); unsigned int w = x11->context->w; unsigned int h = x11->context->h;
- GP_DEBUG(3, "Flipping context"); + GP_DEBUG(4, "Flipping context");
XLockDisplay(x11->dpy);
@@ -79,11 +100,21 @@ static void x11_poll(GP_Backend *self)
switch (ev.type) { case Expose: - x11_flip(self); + GP_DEBUG(4, "Expose %ix%i-%ix%i %i", + ev.xexpose.x, ev.xexpose.y, + ev.xexpose.width, ev.xexpose.height, + ev.xexpose.count); + x11_update_rect(self, ev.xexpose.x, ev.xexpose.y, + ev.xexpose.x + ev.xexpose.width, + ev.xexpose.y + ev.xexpose.height); break; case MapNotify: GP_DEBUG(1, "Shown"); break; + case KeyPress: + case KeyRelease: + GP_InputDriverX11EventPut(&ev); + break; } } @@ -142,7 +173,8 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y, }
/* Select events */ - XSelectInput(x11->dpy, x11->win, StructureNotifyMask|ExposureMask); + XSelectInput(x11->dpy, x11->win, StructureNotifyMask | ExposureMask | + KeyPressMask | KeyReleaseMask);
/* Set window caption */ XmbSetWMProperties(x11->dpy, x11->win, caption, caption, @@ -153,7 +185,6 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y, XFlush(x11->dpy);
/* - enum GP_PixelType pixel_type; pixel_type = GP_PixelRGBLookup(vscri.red.length, vscri.red.offset, vscri.green.length, vscri.green.offset, @@ -172,7 +203,7 @@ GP_Backend *GP_BackendX11Init(const char *display, int x, int y, backend->name = "X11"; backend->context = x11->context; backend->Flip = x11_flip; - backend->UpdateRect = NULL; + backend->UpdateRect = x11_update_rect; backend->Exit = x11_exit; backend->fd_list = NULL; backend->Poll = x11_poll; @@ -188,3 +219,16 @@ err0: free(backend); return NULL; } + +#else + +#include "GP_Backend.h" + +GP_Backend *GP_BackendX11Init(const char *display, int x, int y, + unsigned int w, unsigned int h, + const char *caption) +{ + return NULL; +} + +#endif /* HAVE_LIBX11 */ diff --git a/libs/input/GP_InputDriverX11.c b/libs/input/GP_InputDriverX11.c new file mode 100644 index 0000000..d3b21c1 --- /dev/null +++ b/libs/input/GP_InputDriverX11.c @@ -0,0 +1,112 @@ +/***************************************************************************** + * 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 "../../config.h" + +#include "core/GP_Debug.h" +#include "GP_Event.h" +#include "GP_InputDriverX11.h" + +#ifdef HAVE_LIBX11 + +/* X11 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, + 0, 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, GP_KEY_DOT, + GP_KEY_SLASH, GP_KEY_RIGHT_SHIFT, 0, 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, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, GP_KEY_F11, GP_KEY_F12, + 0, 0, 0, 0, + 0, 0, 0, 0, + GP_KEY_RIGHT_CTRL, 0, /* PRINTSCREEN */0, GP_KEY_RIGHT_ALT, + 0, GP_KEY_HOME, GP_KEY_UP, GP_KEY_PAGE_UP, + GP_KEY_LEFT, GP_KEY_RIGHT, GP_KEY_END, GP_KEY_DOWN, + GP_KEY_PAGE_DOWN, 0, GP_KEY_DELETE, +}; + +static const uint16_t keycode_table_size = sizeof(keycode_table)/2; + +void GP_InputDriverX11EventPut(XEvent *ev) +{ + int key = 0, keycode, press = 0; + + switch (ev->type) { + /* + case SDL_MOUSEMOTION: + GP_EventPushRel(ev->motion.xrel, ev->motion.yrel, NULL); + break; + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + switch (ev->button.button) { + case 1: + key = GP_BTN_LEFT; + break; + case 2: + key = GP_BTN_MIDDLE; + break; + case 3: + key = GP_BTN_RIGHT; + break; + default: + return; + } + + GP_EventPush(GP_EV_KEY, key, ev->button.state, NULL); + break; + */ + case KeyPress: + press = 1; + case KeyRelease: + keycode = ev->xkey.keycode; + + if (keycode > 8 && keycode - 9 <= keycode_table_size) + key = keycode_table[keycode - 9]; + + if (key == 0) { + GP_DEBUG(0, "Unmapped X11 keycode %02x", keycode); + return; + } + + GP_DEBUG(0, "Mapped X11 keycode %02x", keycode); + GP_EventPushKey(key, press, NULL); + break; + } +} + +#endif /* HAVE_LIBX11 */
-----------------------------------------------------------------------
Summary of changes: include/input/{GP_Input.h => GP_InputDriverX11.h} | 20 ++-- libs/backends/GP_X11.c | 56 +++++++++- libs/input/GP_InputDriverX11.c | 112 +++++++++++++++++++++ 3 files changed, 173 insertions(+), 15 deletions(-) copy include/input/{GP_Input.h => GP_InputDriverX11.h} (86%) create mode 100644 libs/input/GP_InputDriverX11.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.