summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJess VanDerwalker <washu@sonic.net>2012-07-19 10:08:36 -0700
committerJess VanDerwalker <washu@sonic.net>2012-07-25 11:36:51 -0700
commit5b1f36b97142f6fb3139e31e744fdf691ab4290c (patch)
treefc40ba22a39aaee4f12805df37ecaaca576a57d3
parent36ea32aff1bb70ece3bafc117daa01f67e77aa60 (diff)
xtoq: Standalone keymap application.
Added keymap_main.c to function as driver for keymap.c code. main in keymap_main.c takes display to connect to on command line, opens connection and passes the connection on to the keymap.c code through XtoQKeymapReSync. Added build target to src/xtoq/Makefile.am to build stand alone application. In keymap.c, XtoQKeymapReSync and XtoQKeyboardReloadHandler now take xcb_connection_t as parameter. XtoQKeyboardReloadHandler uses call to xcb_change_keyboard_mapping_checked to send keyymap with proper keysyms to X server. References to KeySyms changed to xcb_keysym_t for compatibility with xcb_change_keyboard_mapping_checked. Signed-off-by: Jess VanDerwalker <washu@sonic.net> Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r--src/xtoq/Makefile.am11
-rw-r--r--src/xtoq/keymap.c63
-rw-r--r--src/xtoq/keymap.h2
-rw-r--r--src/xtoq/keymap_main.c53
4 files changed, 101 insertions, 28 deletions
diff --git a/src/xtoq/Makefile.am b/src/xtoq/Makefile.am
index 6a9dac1..8844463 100644
--- a/src/xtoq/Makefile.am
+++ b/src/xtoq/Makefile.am
@@ -28,3 +28,14 @@ xtoq_LDFLAGS = \
xtoq_LDADD = \
$(top_builddir)/src/libxcwm/libxcwm.la
+bin_PROGRAMS = keymap
+keymap_SOURCES = \
+ keymap_main.c \
+ keymap.c \
+ keysym2ucs.c
+keymap_LDFLAGS = \
+ $(XCB_LIBS) \
+ -Wl,-framework,Cocoa \
+ -Wl,-framework,Carbon \
+ -Wl,-framework,IOKit
+
diff --git a/src/xtoq/keymap.c b/src/xtoq/keymap.c
index 8e0038f..65c53d7 100644
--- a/src/xtoq/keymap.c
+++ b/src/xtoq/keymap.c
@@ -52,6 +52,7 @@
#include <assert.h>
/* FIXME: Use xcb instead */
+#include <xcb/xcb.h>
#include <X11/X.h>
#include <X11/keysym.h>
#include <X11/extensions/XKB.h>
@@ -88,7 +89,7 @@ enum {
const static struct {
unsigned short keycode;
- KeySym keysym;
+ xcb_keysym_t keysym;
} known_keys[] = {
{ 55, XK_Meta_L },
{ 56, XK_Shift_L },
@@ -125,7 +126,7 @@ const static struct {
const static struct {
unsigned short keycode;
- KeySym normal, keypad;
+ xcb_keysym_t normal, keypad;
} known_numeric_keys[] = {
{ 65, XK_period, XK_KP_Decimal },
{ 67, XK_asterisk, XK_KP_Multiply },
@@ -161,7 +162,7 @@ const static unsigned short keycode_blacklist[] = { 66, 70, 72, 77 };
FIXME: all the unicode keysyms (apart from circumflex) were guessed. */
const static struct {
- KeySym normal, dead;
+ xcb_keysym_t normal, dead;
} dead_keys[] = {
{ XK_grave, XK_dead_grave },
{ XK_apostrophe, XK_dead_acute }, /* US:"=" on a Czech keyboard */
@@ -192,12 +193,16 @@ const static struct {
typedef struct XtoQKeymapInfo_struct {
// FIXME: Note that this will need to be a XModifierKeymap for use in client-space
char modMap[MAP_LENGTH];
- KeySym keyMap[MAP_LENGTH * GLYPHS_PER_KEY];
+ xcb_keysym_t keyMap[MAP_LENGTH * GLYPHS_PER_KEY];
unsigned char modifierKeycodes[32][2];
} XtoQKeymapInfo;
XtoQKeymapInfo keyInfo;
+/* Internal function definitions. Silence compiler warnings */
+void
+XtoQKeyboardReloadHandler(xcb_connection_t *conn);
+
//-----------------------------------------------------------------------------
// Utility functions to help parse XtoQ keymap
//-----------------------------------------------------------------------------
@@ -211,7 +216,7 @@ static void
XtoQBuildModifierMaps(XtoQKeymapInfo *info)
{
int i;
- KeySym *k;
+ xcb_keysym_t *k;
memset(info->modMap, NoSymbol, sizeof(info->modMap));
memset(info->modifierKeycodes, 0, sizeof(info->modifierKeycodes));
@@ -370,7 +375,7 @@ XtoQKeyboardSetRepeat(DeviceIntPtr pDev, int initialKeyRepeatValue,
#endif
void
-XtoQKeyboardReloadHandler(void)
+XtoQKeyboardReloadHandler(xcb_connection_t *conn)
{
CFIndex initialKeyRepeatValue, keyRepeatValue;
Boolean ok;
@@ -400,25 +405,29 @@ XtoQKeyboardReloadHandler(void)
if (!ok)
keyRepeatValue = 6;
-#if 0
+
//FIXME: Use Xi's ChangeDeviceKeyMapping (note that this won't handle modMap).
// modMap needs to be sent using the core SetModifierMapping request,
// and it probably needs to be in a different format than it is currently.
-
- /* Initialize our keySyms */
- KeySymsRec keySyms;
- keySyms.map = keyInfo.keyMap;
- keySyms.mapWidth = GLYPHS_PER_KEY;
- keySyms.minKeyCode = MIN_KEYCODE;
- keySyms.maxKeyCode = MAX_KEYCODE;
-
- // TODO: We should build the entire XkbDescRec and use XkbCopyKeymap
- /* Apply the mappings to darwinKeyboard */
- //XkbApplyMappingChange(darwinKeyboard, &keySyms, keySyms.minKeyCode,
- // keySyms.maxKeyCode - keySyms.minKeyCode + 1,
- // keyInfo.modMap, serverClient);
- //FIXME: Disabled XtoQKeyboardSetRepeat(darwinKeyboard, initialKeyRepeatValue, keyRepeatValue);
-#endif
+ //FIXME: Disabled XtoQKeyboardSetRepeat(darwinKeyboard, initialKeyRepeatValue, keyRepeatValue)
+
+ /* FIXME: Set the keymap through XCB call. Once this is and
+ * modifier mapping is working, this will be replaced by call to
+ * xcwm */
+ xcb_void_cookie_t cookie;
+ xcb_generic_error_t *error;
+ cookie = xcb_change_keyboard_mapping_checked(conn,
+ NUM_KEYCODES,
+ MIN_KEYCODE,
+ GLYPHS_PER_KEY,
+ keyInfo.keyMap);
+
+ error = xcb_request_check(conn, cookie);
+ if (error) {
+ fprintf(stderr, "ERROR: Failed to change keyboard mapping");
+ fprintf(stderr, "\nError code: %d\n", error->error_code);
+ }
+ xcb_flush(conn);
#if 0 /* FIXME: Don't worry about xmodmap until we're done with everything else */
/* Modify with xmodmap */
@@ -743,8 +752,8 @@ macroman2ucs(unsigned char c)
else return table[c - 128];
}
-static KeySym
-make_dead_key(KeySym in)
+static xcb_keysym_t
+make_dead_key(xcb_keysym_t in)
{
int i;
@@ -766,7 +775,7 @@ XtoQReadSystemKeymap(XtoQKeymapInfo *info)
UInt32 keyboard_type = LMGetKbdType();
int i, j;
OSStatus err;
- KeySym *k;
+ xcb_keysym_t *k;
CFDataRef currentKeyLayoutDataRef = NULL;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
@@ -968,12 +977,12 @@ XtoQReadSystemKeymap(XtoQKeymapInfo *info)
}
void
-XtoQKeymapReSync(void)
+XtoQKeymapReSync(xcb_connection_t *conn)
{
/* Update keyInfo */
memset(keyInfo.keyMap, 0, sizeof(keyInfo.keyMap));
XtoQReadSystemKeymap(&keyInfo);
/* Tell server thread to deal with new keyInfo */
- XtoQKeyboardReloadHandler();
+ XtoQKeyboardReloadHandler(conn);
}
diff --git a/src/xtoq/keymap.h b/src/xtoq/keymap.h
index 64e96d9..35f5ebf 100644
--- a/src/xtoq/keymap.h
+++ b/src/xtoq/keymap.h
@@ -44,6 +44,6 @@ int
XtoQModifierStringToNXMask(const char *string, int separatelr);
void
-XtoQKeymapReSync(void);
+XtoQKeymapReSync(xcb_connection_t *conn);
#endif /* XTOQ_KEYBOARD_H */
diff --git a/src/xtoq/keymap_main.c b/src/xtoq/keymap_main.c
new file mode 100644
index 0000000..6ff606b
--- /dev/null
+++ b/src/xtoq/keymap_main.c
@@ -0,0 +1,53 @@
+/* Copyright (c) 2013 Jess VanDerwalker <jvanderw@freedesktop.org>
+ *
+ * keymap_main.c
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <xcb/xcb.h>
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#include <X11/keysymdef.h>
+#include "keymap.h"
+#include "keysym2ucs.h"
+#include <stdio.h>
+
+/* Simple driver for a keymap standalone keymap application. Once this
+ * application can successfully set the keymap and modifier mapping,
+ * this driver will go away, and the keymap.c code will be integrated
+ * into XtoQ. */
+int
+main (int argc, const char **argv)
+{
+ printf("Generating keymap on display %s\n", argv[1]);
+
+ xcb_connection_t *conn;
+ int conn_screen;
+
+ conn = xcb_connect(argv[1], &conn_screen);
+
+ XtoQKeymapReSync(conn);
+
+ xcb_disconnect(conn);
+
+ return 0;
+}