From 0f5d96c69f72770a40504a02f0429d6c03c60e0e Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 5 May 2012 05:22:41 +0000 Subject: [PATCH] forgot to add the new files git-svn-id: svn+ssh://svn.code.sf.net/p/spacenav/code/trunk/spacenavd@138 ef983eb1-d774-4af8-acfd-baaf7b16a646 --- src/kbemu.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/kbemu.h | 29 +++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/kbemu.c create mode 100644 src/kbemu.h diff --git a/src/kbemu.c b/src/kbemu.c new file mode 100644 index 0000000..1a61b6f --- /dev/null +++ b/src/kbemu.c @@ -0,0 +1,62 @@ +/* +spacenavd - a free software replacement driver for 6dof space-mice. +Copyright (C) 2007-2012 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "config.h" + +#ifdef USE_X11 +#include +#include +#include "kbemu.h" + +static Display *dpy; + +void kbemu_set_display(Display *d) +{ + dpy = d; +} + +KeySym kbemu_keysym(const char *str) +{ + return XStringToKeysym(str); +} + +void send_kbevent(KeySym key, int press) +{ + XEvent xevent; + Window win; + int rev_state; + + if(!dpy) return; + + XGetInputFocus(dpy, &win, &rev_state); + + xevent.type = press ? KeyPress : KeyRelease; + xevent.xkey.display = dpy; + xevent.xkey.root = DefaultRootWindow(dpy); + xevent.xkey.window = win; + xevent.xkey.subwindow = None; + xevent.xkey.keycode = XKeysymToKeycode(dpy, key); + xevent.xkey.state = 0; + xevent.xkey.time = CurrentTime; + xevent.xkey.x = xevent.xkey.y = 1; + xevent.xkey.x_root = xevent.xkey.y_root = 1; + + XSendEvent(dpy, win, True, press ? KeyPressMask : KeyReleaseMask, &xevent); + XFlush(dpy); +} +#endif /* USE_X11 */ diff --git a/src/kbemu.h b/src/kbemu.h new file mode 100644 index 0000000..ac0f7bd --- /dev/null +++ b/src/kbemu.h @@ -0,0 +1,29 @@ +/* +spacenavd - a free software replacement driver for 6dof space-mice. +Copyright (C) 2007-2012 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#ifndef KBEMU_H_ +#define KBEMU_H_ + +#include +#include + +void kbemu_set_display(Display *dpy); +KeySym kbemu_keysym(const char *str); + +void send_kbevent(KeySym key, int press); + +#endif /* KBEMU_H_ */