summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorTorrey Lyons <torrey@mrcla.com>2004-09-22 23:38:33 +0000
committerTorrey Lyons <torrey@mrcla.com>2004-09-22 23:38:33 +0000
commit35a3bf13a8be96bb29dce32399c3684c6baa527d (patch)
treec708203fb23a5a3baef19f30c316cef1a1e44744 /hw
parent1b3fa4d53b287cbe9d38c5f8c9fbbc2298690959 (diff)
Add option for XDarwin to track system keyboard layout changes as they
occur (John Harper and Torrey T. Lyons).
Diffstat (limited to 'hw')
-rw-r--r--hw/darwin/darwin.c26
-rw-r--r--hw/darwin/darwin.h11
-rw-r--r--hw/darwin/darwinEvents.c132
-rw-r--r--hw/darwin/darwinKeyboard.c216
-rw-r--r--hw/darwin/darwinKeyboard.h4
-rw-r--r--hw/darwin/iokit/xfIOKitStartup.c13
-rw-r--r--hw/darwin/quartz/quartzKeyboard.c8
7 files changed, 279 insertions, 131 deletions
diff --git a/hw/darwin/darwin.c b/hw/darwin/darwin.c
index 8c4c0bc9b..86e27c2bc 100644
--- a/hw/darwin/darwin.c
+++ b/hw/darwin/darwin.c
@@ -29,7 +29,7 @@
* holders shall not be used in advertising or otherwise to promote the sale,
* use or other dealings in this Software without prior written authorization.
*/
-/* $XdotOrg: xc/programs/Xserver/hw/darwin/darwin.c,v 1.3 2004/07/30 18:22:12 torrey Exp $ */
+/* $XdotOrg: xc/programs/Xserver/hw/darwin/darwin.c,v 1.4 2004/08/11 23:53:36 torrey Exp $ */
/* $XFree86: xc/programs/Xserver/hw/darwin/darwin.c,v 1.55 2003/11/15 00:07:09 torrey Exp $ */
#include "X.h"
@@ -93,13 +93,16 @@ unsigned int darwinDesiredWidth = 0, darwinDesiredHeight = 0;
int darwinDesiredDepth = -1;
int darwinDesiredRefresh = -1;
char *darwinKeymapFile = "USA.keymapping";
+int darwinSyncKeymap = FALSE;
+int darwinSwapAltMeta = FALSE;
// modifier masks for faking mouse buttons
int darwinFakeMouse2Mask = NX_COMMANDMASK;
int darwinFakeMouse3Mask = NX_ALTERNATEMASK;
-static DeviceIntPtr darwinPointer;
-static DeviceIntPtr darwinKeyboard;
+// devices
+DeviceIntPtr darwinPointer = NULL;
+DeviceIntPtr darwinKeyboard = NULL;
// Common pixmap formats
static PixmapFormatRec formats[] = {
@@ -538,7 +541,7 @@ static char * DarwinFindLibraryFile(
* DarwinParseModifierList
* Parse a list of modifier names and return a corresponding modifier mask
*/
-static int DarwinParseModifierList(
+int DarwinParseModifierList(
const char *constmodifiers) // string containing list of modifier names
{
int result = 0;
@@ -781,6 +784,11 @@ int ddxProcessArgument( int argc, char *argv[], int i )
return 2;
}
+ if ( !strcmp( argv[i], "-swapAltMeta" ) ) {
+ darwinSwapAltMeta = 1;
+ return 1;
+ }
+
if ( !strcmp( argv[i], "-keymap" ) ) {
if ( i == argc-1 ) {
FatalError( "-keymap must be followed by a filename\n" );
@@ -794,6 +802,16 @@ int ddxProcessArgument( int argc, char *argv[], int i )
return 1;
}
+ if ( !strcmp( argv[i], "+synckeymap" ) ) {
+ darwinSyncKeymap = TRUE;
+ return 1;
+ }
+
+ if ( !strcmp( argv[i], "-synckeymap" ) ) {
+ darwinSyncKeymap = FALSE;
+ return 1;
+ }
+
if ( !strcmp( argv[i], "-size" ) ) {
if ( i >= argc-2 ) {
FatalError( "-size must be followed by two numbers\n" );
diff --git a/hw/darwin/darwin.h b/hw/darwin/darwin.h
index e49c450ef..337706b3f 100644
--- a/hw/darwin/darwin.h
+++ b/hw/darwin/darwin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001-2003 Torrey T. Lyons. All Rights Reserved.
+ * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -23,7 +23,7 @@
* holders shall not be used in advertising or otherwise to promote the sale,
* use or other dealings in this Software without prior written authorization.
*/
-/* $XFree86: xc/programs/Xserver/hw/darwin/darwin.h,v 1.19 2003/10/16 23:50:08 torrey Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/darwin/darwin.h,v 1.20 2003/11/15 00:07:09 torrey Exp $ */
#ifndef _DARWIN_H
#define _DARWIN_H
@@ -49,6 +49,7 @@ typedef struct {
// From darwin.c
void DarwinPrintBanner();
+int DarwinParseModifierList(const char *constmodifiers);
void DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo);
void xf86SetRootClip (ScreenPtr pScreen, BOOL enable);
@@ -98,13 +99,17 @@ extern int darwinScreensFound;
extern io_connect_t darwinParamConnect;
extern int darwinEventReadFD;
extern int darwinEventWriteFD;
+extern DeviceIntPtr darwinPointer;
+extern DeviceIntPtr darwinKeyboard;
// User preferences
extern int darwinMouseAccelChange;
extern int darwinFakeButtons;
extern int darwinFakeMouse2Mask;
extern int darwinFakeMouse3Mask;
+extern int darwinSwapAltMeta;
extern char *darwinKeymapFile;
+extern int darwinSyncKeymap;
extern unsigned int darwinDesiredWidth, darwinDesiredHeight;
extern int darwinDesiredDepth;
extern int darwinDesiredRefresh;
@@ -145,4 +150,4 @@ enum {
kXDarwinWindowMoved // window has moved on screen
};
-#endif /* _DARWIN_H */
+#endif /* _DARWIN_H */
diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c
index 49bb67a94..6bfda00d4 100644
--- a/hw/darwin/darwinEvents.c
+++ b/hw/darwin/darwinEvents.c
@@ -2,7 +2,7 @@
* Darwin event queue and event handling
*/
/*
-Copyright (c) 2002 Torrey T. Lyons. All Rights Reserved.
+Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved.
Copyright 2004 Kaleb S. KEITHLEY. All Rights Reserved.
This file is based on mieq.c by Keith Packard,
@@ -29,7 +29,7 @@ Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*/
-/* $XFree86$ */
+/* $XFree86: xc/programs/Xserver/hw/darwin/darwinEvents.c,v 1.6 2004/03/31 22:29:09 torrey Exp $ */
#define NEED_EVENTS
#include "X.h"
@@ -44,6 +44,7 @@ in this Software without prior written authorization from The Open Group.
#include "mipointer.h"
#include "darwin.h"
+#include "darwinKeyboard.h"
#include <sys/types.h>
#include <sys/uio.h>
@@ -51,24 +52,24 @@ in this Software without prior written authorization from The Open Group.
#include <IOKit/hidsystem/IOLLEvent.h>
/* Fake button press/release for scroll wheel move. */
-#define SCROLLWHEELUPFAKE 4
-#define SCROLLWHEELDOWNFAKE 5
+#define SCROLLWHEELUPFAKE 4
+#define SCROLLWHEELDOWNFAKE 5
#define QUEUE_SIZE 256
typedef struct _Event {
- xEvent event;
- ScreenPtr pScreen;
+ xEvent event;
+ ScreenPtr pScreen;
} EventRec, *EventPtr;
typedef struct _EventQueue {
- HWEventQueueType head, tail; /* long for SetInputCheck */
- CARD32 lastEventTime; /* to avoid time running backwards */
- Bool lastMotion;
- EventRec events[QUEUE_SIZE]; /* static allocation for signals */
- DevicePtr pKbd, pPtr; /* device pointer, to get funcs */
- ScreenPtr pEnqueueScreen; /* screen events are being delivered to */
- ScreenPtr pDequeueScreen; /* screen events are being dispatched to */
+ HWEventQueueType head, tail; /* long for SetInputCheck */
+ CARD32 lastEventTime; /* to avoid time running backwards */
+ Bool lastMotion;
+ EventRec events[QUEUE_SIZE]; /* static allocation for signals */
+ DevicePtr pKbd, pPtr; /* device pointer, to get funcs */
+ ScreenPtr pEnqueueScreen; /* screen events are being delivered to */
+ ScreenPtr pDequeueScreen; /* screen events are being dispatched to */
} EventQueueRec, *EventQueuePtr;
static EventQueueRec darwinEventQueue;
@@ -79,7 +80,7 @@ static EventQueueRec darwinEventQueue;
* Press or release the given modifier key, specified by its mask.
*/
static void DarwinPressModifierMask(
- xEvent *xe, // must already have type, time and mouse location
+ xEvent *xe, // must already have type, time and mouse location
int mask) // one of NX_*MASK constants
{
int key = DarwinModifierNXMaskToNXKey(mask);
@@ -225,10 +226,10 @@ DarwinEQEnqueue(
* is "unnecessary", but very useful
*/
if (e->u.keyButtonPointer.time < darwinEventQueue.lastEventTime &&
- darwinEventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000)
+ darwinEventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000)
{
- darwinEventQueue.events[oldtail].event.u.keyButtonPointer.time =
- darwinEventQueue.lastEventTime;
+ darwinEventQueue.events[oldtail].event.u.keyButtonPointer.time =
+ darwinEventQueue.lastEventTime;
}
darwinEventQueue.events[oldtail].pScreen = darwinEventQueue.pEnqueueScreen;
@@ -260,7 +261,7 @@ DarwinEQSwitchScreen(
{
darwinEventQueue.pEnqueueScreen = pScreen;
if (fromDIX)
- darwinEventQueue.pDequeueScreen = pScreen;
+ darwinEventQueue.pDequeueScreen = pScreen;
}
@@ -270,10 +271,10 @@ DarwinEQSwitchScreen(
*/
void ProcessInputEvents(void)
{
- EventRec *e;
- int x, y;
- xEvent xe;
- static int old_flags = 0; // last known modifier state
+ EventRec *e;
+ int x, y;
+ xEvent xe;
+ static int old_flags = 0; // last known modifier state
// button number and modifier mask of currently pressed fake button
static int darwinFakeMouseButtonDown = 0;
static int darwinFakeMouseButtonMask = 0;
@@ -286,10 +287,10 @@ void ProcessInputEvents(void)
while (darwinEventQueue.head != darwinEventQueue.tail)
{
- if (screenIsSaved == SCREEN_SAVER_ON)
- SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
+ if (screenIsSaved == SCREEN_SAVER_ON)
+ SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
- e = &darwinEventQueue.events[darwinEventQueue.head];
+ e = &darwinEventQueue.events[darwinEventQueue.head];
xe = e->event;
// Shift from global screen coordinates to coordinates relative to
@@ -299,36 +300,53 @@ void ProcessInputEvents(void)
xe.u.keyButtonPointer.rootY -= darwinMainScreenY +
dixScreenOrigins[miPointerCurrentScreen()->myNum].y;
- /*
- * Assumption - screen switching can only occur on motion events
- */
- if (e->pScreen != darwinEventQueue.pDequeueScreen)
- {
- darwinEventQueue.pDequeueScreen = e->pScreen;
- x = xe.u.keyButtonPointer.rootX;
- y = xe.u.keyButtonPointer.rootY;
- if (darwinEventQueue.head == QUEUE_SIZE - 1)
- darwinEventQueue.head = 0;
- else
- ++darwinEventQueue.head;
- NewCurrentScreen (darwinEventQueue.pDequeueScreen, x, y);
- }
- else
- {
- if (darwinEventQueue.head == QUEUE_SIZE - 1)
- darwinEventQueue.head = 0;
- else
- ++darwinEventQueue.head;
- switch (xe.u.u.type)
- {
- case KeyPress:
- case KeyRelease:
+ /*
+ * Assumption - screen switching can only occur on motion events
+ */
+ if (e->pScreen != darwinEventQueue.pDequeueScreen)
+ {
+ darwinEventQueue.pDequeueScreen = e->pScreen;
+ x = xe.u.keyButtonPointer.rootX;
+ y = xe.u.keyButtonPointer.rootY;
+ if (darwinEventQueue.head == QUEUE_SIZE - 1)
+ darwinEventQueue.head = 0;
+ else
+ ++darwinEventQueue.head;
+ NewCurrentScreen (darwinEventQueue.pDequeueScreen, x, y);
+ }
+ else
+ {
+ if (darwinEventQueue.head == QUEUE_SIZE - 1)
+ darwinEventQueue.head = 0;
+ else
+ ++darwinEventQueue.head;
+ switch (xe.u.u.type)
+ {
+ case KeyPress:
+ if (old_flags == 0
+ && darwinSyncKeymap && darwinKeymapFile == NULL)
+ {
+ /* See if keymap has changed. */
+
+ static unsigned int last_seed;
+ unsigned int this_seed;
+
+ this_seed = DarwinModeSystemKeymapSeed();
+ if (this_seed != last_seed)
+ {
+ last_seed = this_seed;
+ DarwinKeyboardReload(darwinKeyboard);
+ }
+ }
+ /* fall through */
+
+ case KeyRelease:
xe.u.u.detail += MIN_KEYCODE;
- (*darwinEventQueue.pKbd->processInputProc)
- (&xe, (DeviceIntPtr)darwinEventQueue.pKbd, 1);
- break;
+ (*darwinEventQueue.pKbd->processInputProc)
+ (&xe, (DeviceIntPtr)darwinEventQueue.pKbd, 1);
+ break;
- case ButtonPress:
+ case ButtonPress:
miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
xe.u.keyButtonPointer.rootY,
xe.u.keyButtonPointer.time);
@@ -386,7 +404,7 @@ void ProcessInputEvents(void)
miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
xe.u.keyButtonPointer.rootY,
xe.u.keyButtonPointer.time);
- break;
+ break;
case kXDarwinUpdateModifiers:
{
@@ -424,7 +442,7 @@ void ProcessInputEvents(void)
xe.u.u.type = ButtonRelease;
}
(*darwinEventQueue.pPtr->processInputProc)
- (&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
+ (&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
}
}
break;
@@ -455,8 +473,8 @@ void ProcessInputEvents(void)
default:
// Check for mode specific event
DarwinModeProcessEvent(&xe);
- }
- }
+ }
+ }
}
miPointerUpdate();
diff --git a/hw/darwin/darwinKeyboard.c b/hw/darwin/darwinKeyboard.c
index e60e7a3e1..234a70783 100644
--- a/hw/darwin/darwinKeyboard.c
+++ b/hw/darwin/darwinKeyboard.c
@@ -2,9 +2,9 @@
//
// Keyboard support for the Darwin X Server
//
-// Copyright 2004 Kaleb S. KEITHLEY. All Rights Reserved.
-// Copyright (c) 2001-2003 Torrey T. Lyons. All Rights Reserved.
+// Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
// Copyright (c) 2003 Apple Computer, Inc. All Rights Reserved.
+// Copyright 2004 Kaleb S. KEITHLEY. All Rights Reserved.
//
// The code to parse the Darwin keymap is derived from dumpkeymap.c
// by Eric Sunshine, which includes the following copyright:
@@ -38,7 +38,7 @@
//
//=============================================================================
-/* $XFree86: xc/programs/Xserver/hw/darwin/darwinKeyboard.c,v 1.18 2003/05/14 05:27:55 torrey Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/darwin/darwinKeyboard.c,v 1.21 2004/04/01 00:05:22 torrey Exp $ */
/*
===========================================================================
@@ -81,7 +81,7 @@
// FIXME: It would be nice to support some of the extra keys in XF86keysym.h,
// at least the volume controls that now ship on every Apple keyboard.
-#define UK(a) NoSymbol // unknown symbol
+#define UK(a) NoSymbol // unknown symbol
static KeySym const next_to_x[256] = {
NoSymbol, NoSymbol, NoSymbol, XK_KP_Enter,
@@ -170,13 +170,13 @@ static KeySym const next_to_x[256] = {
XK_thorn, XK_ydiaeresis, NoSymbol, NoSymbol,
};
-#define MIN_SYMBOL 0xAC
+#define MIN_SYMBOL 0xAC
static KeySym const symbol_to_x[] = {
XK_Left, XK_Up, XK_Right, XK_Down
};
int const NUM_SYMBOL = sizeof(symbol_to_x) / sizeof(symbol_to_x[0]);
-#define MIN_FUNCKEY 0x20
+#define MIN_FUNCKEY 0x20
static KeySym const funckey_to_x[] = {
XK_F1, XK_F2, XK_F3, XK_F4,
XK_F5, XK_F6, XK_F7, XK_F8,
@@ -188,8 +188,8 @@ static KeySym const funckey_to_x[] = {
int const NUM_FUNCKEY = sizeof(funckey_to_x) / sizeof(funckey_to_x[0]);
typedef struct {
- KeySym normalSym;
- KeySym keypadSym;
+ KeySym normalSym;
+ KeySym keypadSym;
} darwinKeyPad_t;
static darwinKeyPad_t const normal_to_keypad[] = {
@@ -550,36 +550,36 @@ Bool DarwinParseNXKeyMapping(
// If AlphaLock and Shift modifiers produce different codes,
// we record the Shift case since X handles AlphaLock.
- if (charGenMask & 0x01) { // AlphaLock
+ if (charGenMask & 0x01) { // AlphaLock
parse_next_char_code( keyMapStream, k+1 );
numKeyCodes--;
}
- if (charGenMask & 0x02) { // Shift
+ if (charGenMask & 0x02) { // Shift
parse_next_char_code( keyMapStream, k+1 );
numKeyCodes--;
- if (charGenMask & 0x01) { // Shift-AlphaLock
+ if (charGenMask & 0x01) { // Shift-AlphaLock
get_number(keyMapStream); get_number(keyMapStream);
numKeyCodes--;
}
}
// Skip the Control cases
- if (charGenMask & 0x04) { // Control
+ if (charGenMask & 0x04) { // Control
get_number(keyMapStream); get_number(keyMapStream);
numKeyCodes--;
- if (charGenMask & 0x01) { // Control-AlphaLock
+ if (charGenMask & 0x01) { // Control-AlphaLock
get_number(keyMapStream); get_number(keyMapStream);
numKeyCodes--;
}
- if (charGenMask & 0x02) { // Control-Shift
+ if (charGenMask & 0x02) { // Control-Shift
get_number(keyMapStream); get_number(keyMapStream);
numKeyCodes--;
- if (charGenMask & 0x01) { // Shift-Control-AlphaLock
+ if (charGenMask & 0x01) { // Shift-Control-AlphaLock
get_number(keyMapStream); get_number(keyMapStream);
numKeyCodes--;
}
@@ -587,20 +587,20 @@ Bool DarwinParseNXKeyMapping(
}
// Process Alt cases
- if (charGenMask & 0x08) { // Alt
+ if (charGenMask & 0x08) { // Alt
parse_next_char_code( keyMapStream, k+2 );
numKeyCodes--;
- if (charGenMask & 0x01) { // Alt-AlphaLock
+ if (charGenMask & 0x01) { // Alt-AlphaLock
parse_next_char_code( keyMapStream, k+3 );
numKeyCodes--;
}
- if (charGenMask & 0x02) { // Alt-Shift
+ if (charGenMask & 0x02) { // Alt-Shift
parse_next_char_code( keyMapStream, k+3 );
numKeyCodes--;
- if (charGenMask & 0x01) { // Alt-Shift-AlphaLock
+ if (charGenMask & 0x01) { // Alt-Shift-AlphaLock
get_number(keyMapStream); get_number(keyMapStream);
numKeyCodes--;
}
@@ -636,27 +636,10 @@ Bool DarwinParseNXKeyMapping(
destroy_data_stream( keyMapStream );
xfree( keyMap.mapping );
-#ifdef DUMP_DARWIN_KEYMAP
- ErrorF("Darwin -> X converted keyboard map\n");
- for (i = 0, k = info->keyMap; i < NX_NUMKEYCODES;
- i++, k += GLYPHS_PER_KEY)
- {
- int j;
- ErrorF("0x%02x:", i);
- for (j = 0; j < GLYPHS_PER_KEY; j++) {
- if (k[j] == NoSymbol) {
- ErrorF("\tNoSym");
- } else {
- ErrorF("\t0x%x", k[j]);
- }
- }
- ErrorF("\n");
- }
-#endif
-
return TRUE;
}
+
/*
* DarwinBuildModifierMaps
* Use the keyMap field of keyboard info structure to populate
@@ -668,14 +651,13 @@ DarwinBuildModifierMaps(
{
int i;
KeySym *k;
- int darwinSwapAltMeta = 0;
memset(info->modMap, NoSymbol, sizeof(info->modMap));
memset(info->modifierKeycodes, 0, sizeof(info->modifierKeycodes));
for (i = 0; i < NUM_KEYCODES; i++)
{
- k = info->keyMap + i * GLYPHS_PER_KEY;
+ k = info->keyMap + i * GLYPHS_PER_KEY;
switch (k[0]) {
case XK_Shift_L:
@@ -746,31 +728,79 @@ DarwinBuildModifierMaps(
case XK_Num_Lock:
info->modMap[MIN_KEYCODE + i] = Mod3Mask;
break;
- }
+ }
if (darwinSwapAltMeta)
{
- switch (k[0])
- {
- case XK_Alt_L:
- k[0] = XK_Meta_L;
+ switch (k[0])
+ {
+ case XK_Alt_L:
+ k[0] = XK_Meta_L;
break;
- case XK_Alt_R:
- k[0] = XK_Meta_R;
+ case XK_Alt_R:
+ k[0] = XK_Meta_R;
break;
- case XK_Meta_L:
- k[0] = XK_Alt_L;
+ case XK_Meta_L:
+ k[0] = XK_Alt_L;
break;
- case XK_Meta_R:
- k[0] = XK_Alt_R;
+ case XK_Meta_R:
+ k[0] = XK_Alt_R;
break;
- }
+ }
}
+
+#if ALT_IS_MODE_SWITCH
+ if (k[0] == XK_Alt_L)
+ k[0] = XK_Mode_switch;
+#endif
}
}
/*
+ * DarwinLoadKeyboardMapping
+ * Load the keyboard map from a file or system and convert
+ * it to an equivalent X keyboard map and modifier map.
+ */
+static void
+DarwinLoadKeyboardMapping(KeySymsRec *keySyms)
+{
+ memset(keyInfo.keyMap, 0, sizeof(keyInfo.keyMap));
+
+ if (!DarwinParseNXKeyMapping(&keyInfo)) {
+ if (!DarwinModeReadSystemKeymap(&keyInfo)) {
+ FatalError("Could not build a valid keymap.");
+ }
+ }
+
+ DarwinBuildModifierMaps(&keyInfo);
+
+#ifdef DUMP_DARWIN_KEYMAP
+ ErrorF("Darwin -> X converted keyboard map\n");
+ for (i = 0, k = info->keyMap; i < NX_NUMKEYCODES;
+ i++, k += GLYPHS_PER_KEY)
+ {
+ int j;
+ ErrorF("0x%02x:", i);
+ for (j = 0; j < GLYPHS_PER_KEY; j++) {
+ if (k[j] == NoSymbol) {
+ ErrorF("\tNoSym");
+ } else {
+ ErrorF("\t0x%x", k[j]);
+ }
+ }
+ ErrorF("\n");
+ }
+#endif
+
+ keySyms->map = keyInfo.keyMap;
+ keySyms->mapWidth = GLYPHS_PER_KEY;
+ keySyms->minKeyCode = MIN_KEYCODE;
+ keySyms->maxKeyCode = MAX_KEYCODE;
+}
+
+
+/*
* DarwinKeyboardInit
* Get the Darwin keyboard map and compute an equivalent
* X keyboard map and modifier map. Set the new keyboard
@@ -781,31 +811,89 @@ void DarwinKeyboardInit(
{
KeySymsRec keySyms;
- memset( keyInfo.keyMap, 0, sizeof( keyInfo.keyMap ) );
-
// Open a shared connection to the HID System.
// Note that the Event Status Driver is really just a wrapper
// for a kIOHIDParamConnectType connection.
assert( darwinParamConnect = NXOpenEventStatus() );
- if (!DarwinParseNXKeyMapping(&keyInfo)) {
- if (!DarwinModeReadSystemKeymap(&keyInfo)) {
- FatalError("Could not build a valid keymap.");
- }
- }
-
- DarwinBuildModifierMaps(&keyInfo);
+ DarwinLoadKeyboardMapping(&keySyms);
- keySyms.map = keyInfo.keyMap;
- keySyms.mapWidth = GLYPHS_PER_KEY;
- keySyms.minKeyCode = MIN_KEYCODE;
- keySyms.maxKeyCode = MAX_KEYCODE;
+ /* Initialize the seed, so we don't reload the keymap unnecessarily
+ (and possibly overwrite xinitrc changes) */
+ DarwinModeSystemKeymapSeed();
assert( InitKeyboardDeviceStruct( (DevicePtr)pDev, &keySyms,
keyInfo.modMap, DarwinModeBell,
DarwinChangeKeyboardControl ));
}
+
+/* Borrowed from dix/devices.c */
+static Bool
+InitModMap(register KeyClassPtr keyc)
+{
+ int i, j;
+ CARD8 keysPerModifier[8];
+ CARD8 mask;
+
+ if (keyc->modifierKeyMap != NULL)
+ xfree (keyc->modifierKeyMap);
+
+ keyc->maxKeysPerModifier = 0;
+ for (i = 0; i < 8; i++)
+ keysPerModifier[i] = 0;
+ for (i = 8; i < MAP_LENGTH; i++)
+ {
+ for (j = 0, mask = 1; j < 8; j++, mask <<= 1)
+ {
+ if (mask & keyc->modifierMap[i])
+ {
+ if (++keysPerModifier[j] > keyc->maxKeysPerModifier)
+ keyc->maxKeysPerModifier = keysPerModifier[j];
+ }
+ }
+ }
+ keyc->modifierKeyMap = (KeyCode *)xalloc(8*keyc->maxKeysPerModifier);
+ if (!keyc->modifierKeyMap && keyc->maxKeysPerModifier)
+ return (FALSE);
+ bzero((char *)keyc->modifierKeyMap, 8*(int)keyc->maxKeysPerModifier);
+ for (i = 0; i < 8; i++)
+ keysPerModifier[i] = 0;
+ for (i = 8; i < MAP_LENGTH; i++)
+ {
+ for (j = 0, mask = 1; j < 8; j++, mask <<= 1)
+ {
+ if (mask & keyc->modifierMap[i])
+ {
+ keyc->modifierKeyMap[(j*keyc->maxKeysPerModifier) +
+ keysPerModifier[j]] = i;
+ keysPerModifier[j]++;
+ }
+ }
+ }
+ return TRUE;
+}
+
+
+void
+DarwinKeyboardReload(DeviceIntPtr pDev)
+{
+ KeySymsRec keySyms;
+
+ DarwinLoadKeyboardMapping(&keySyms);
+
+ if (SetKeySymsMap(&pDev->key->curKeySyms, &keySyms)) {
+ /* now try to update modifiers. */
+
+ memmove(pDev->key->modifierMap, keyInfo.modMap, MAP_LENGTH);
+ InitModMap(pDev->key);
+ }
+
+ SendMappingNotify(MappingKeyboard, MIN_KEYCODE, NUM_KEYCODES, 0);
+ SendMappingNotify(MappingModifier, 0, 0, 0);
+}
+
+
//-----------------------------------------------------------------------------
// Modifier translation functions
//
diff --git a/hw/darwin/darwinKeyboard.h b/hw/darwin/darwinKeyboard.h
index 405dcf9d1..0ea9c1d60 100644
--- a/hw/darwin/darwinKeyboard.h
+++ b/hw/darwin/darwinKeyboard.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
+ * Copyright (c) 2003-2004 Torrey T. Lyons. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -45,6 +45,8 @@ typedef struct darwinKeyboardInfo_struct {
unsigned char modifierKeycodes[32][2];
} darwinKeyboardInfo;
+void DarwinKeyboardReload(DeviceIntPtr pDev);
+unsigned int DarwinModeSystemKeymapSeed(void);
Bool DarwinModeReadSystemKeymap(darwinKeyboardInfo *info);
#endif /* DARWIN_KEYBOARD_H */
diff --git a/hw/darwin/iokit/xfIOKitStartup.c b/hw/darwin/iokit/xfIOKitStartup.c
index 80508775e..09c5daa1c 100644
--- a/hw/darwin/iokit/xfIOKitStartup.c
+++ b/hw/darwin/iokit/xfIOKitStartup.c
@@ -4,7 +4,7 @@
*
**************************************************************/
/*
- * Copyright (c) 2001-2003 Torrey T. Lyons. All Rights Reserved.
+ * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -105,6 +105,17 @@ int DarwinModeProcessArgument(
/*
+ * DarwinModeSystemKeymapSeed
+ * Changes to NXKeyMapping are not tracked.
+ */
+unsigned int
+DarwinModeSystemKeymapSeed(void)
+{
+ return 0;
+}
+
+
+/*
* DarwinModeReadSystemKeymap
* IOKit has no alternative to NXKeyMapping API.
*/
diff --git a/hw/darwin/quartz/quartzKeyboard.c b/hw/darwin/quartz/quartzKeyboard.c
index d6a79b578..d2fe922d3 100644
--- a/hw/darwin/quartz/quartzKeyboard.c
+++ b/hw/darwin/quartz/quartzKeyboard.c
@@ -148,7 +148,7 @@ const static struct {
};
unsigned int
-DarwinSystemKeymapSeed (void)
+DarwinModeSystemKeymapSeed (void)
{
static unsigned int seed;
@@ -373,6 +373,12 @@ DarwinModeReadSystemKeymap (darwinKeyboardInfo *info)
#else /* !HAS_KL_API */
+unsigned int
+DarwinModeSystemKeymapSeed (void)
+{
+ return 0;
+}
+
Bool
DarwinModeReadSystemKeymap (darwinKeyboardInfo *info)
{