Add option for XDarwin to track system keyboard layout changes as they
occur (John Harper and Torrey T. Lyons).
This commit is contained in:
parent
1b3fa4d53b
commit
35a3bf13a8
|
@ -29,7 +29,7 @@
|
||||||
* holders shall not be used in advertising or otherwise to promote the sale,
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
* use or other dealings in this Software without prior written authorization.
|
* 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 $ */
|
/* $XFree86: xc/programs/Xserver/hw/darwin/darwin.c,v 1.55 2003/11/15 00:07:09 torrey Exp $ */
|
||||||
|
|
||||||
#include "X.h"
|
#include "X.h"
|
||||||
|
@ -93,13 +93,16 @@ unsigned int darwinDesiredWidth = 0, darwinDesiredHeight = 0;
|
||||||
int darwinDesiredDepth = -1;
|
int darwinDesiredDepth = -1;
|
||||||
int darwinDesiredRefresh = -1;
|
int darwinDesiredRefresh = -1;
|
||||||
char *darwinKeymapFile = "USA.keymapping";
|
char *darwinKeymapFile = "USA.keymapping";
|
||||||
|
int darwinSyncKeymap = FALSE;
|
||||||
|
int darwinSwapAltMeta = FALSE;
|
||||||
|
|
||||||
// modifier masks for faking mouse buttons
|
// modifier masks for faking mouse buttons
|
||||||
int darwinFakeMouse2Mask = NX_COMMANDMASK;
|
int darwinFakeMouse2Mask = NX_COMMANDMASK;
|
||||||
int darwinFakeMouse3Mask = NX_ALTERNATEMASK;
|
int darwinFakeMouse3Mask = NX_ALTERNATEMASK;
|
||||||
|
|
||||||
static DeviceIntPtr darwinPointer;
|
// devices
|
||||||
static DeviceIntPtr darwinKeyboard;
|
DeviceIntPtr darwinPointer = NULL;
|
||||||
|
DeviceIntPtr darwinKeyboard = NULL;
|
||||||
|
|
||||||
// Common pixmap formats
|
// Common pixmap formats
|
||||||
static PixmapFormatRec formats[] = {
|
static PixmapFormatRec formats[] = {
|
||||||
|
@ -538,7 +541,7 @@ static char * DarwinFindLibraryFile(
|
||||||
* DarwinParseModifierList
|
* DarwinParseModifierList
|
||||||
* Parse a list of modifier names and return a corresponding modifier mask
|
* 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
|
const char *constmodifiers) // string containing list of modifier names
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -781,6 +784,11 @@ int ddxProcessArgument( int argc, char *argv[], int i )
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !strcmp( argv[i], "-swapAltMeta" ) ) {
|
||||||
|
darwinSwapAltMeta = 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !strcmp( argv[i], "-keymap" ) ) {
|
if ( !strcmp( argv[i], "-keymap" ) ) {
|
||||||
if ( i == argc-1 ) {
|
if ( i == argc-1 ) {
|
||||||
FatalError( "-keymap must be followed by a filename\n" );
|
FatalError( "-keymap must be followed by a filename\n" );
|
||||||
|
@ -794,6 +802,16 @@ int ddxProcessArgument( int argc, char *argv[], int i )
|
||||||
return 1;
|
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 ( !strcmp( argv[i], "-size" ) ) {
|
||||||
if ( i >= argc-2 ) {
|
if ( i >= argc-2 ) {
|
||||||
FatalError( "-size must be followed by two numbers\n" );
|
FatalError( "-size must be followed by two numbers\n" );
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* 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,
|
* holders shall not be used in advertising or otherwise to promote the sale,
|
||||||
* use or other dealings in this Software without prior written authorization.
|
* 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
|
#ifndef _DARWIN_H
|
||||||
#define _DARWIN_H
|
#define _DARWIN_H
|
||||||
|
@ -49,6 +49,7 @@ typedef struct {
|
||||||
|
|
||||||
// From darwin.c
|
// From darwin.c
|
||||||
void DarwinPrintBanner();
|
void DarwinPrintBanner();
|
||||||
|
int DarwinParseModifierList(const char *constmodifiers);
|
||||||
void DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo);
|
void DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo);
|
||||||
void xf86SetRootClip (ScreenPtr pScreen, BOOL enable);
|
void xf86SetRootClip (ScreenPtr pScreen, BOOL enable);
|
||||||
|
|
||||||
|
@ -98,13 +99,17 @@ extern int darwinScreensFound;
|
||||||
extern io_connect_t darwinParamConnect;
|
extern io_connect_t darwinParamConnect;
|
||||||
extern int darwinEventReadFD;
|
extern int darwinEventReadFD;
|
||||||
extern int darwinEventWriteFD;
|
extern int darwinEventWriteFD;
|
||||||
|
extern DeviceIntPtr darwinPointer;
|
||||||
|
extern DeviceIntPtr darwinKeyboard;
|
||||||
|
|
||||||
// User preferences
|
// User preferences
|
||||||
extern int darwinMouseAccelChange;
|
extern int darwinMouseAccelChange;
|
||||||
extern int darwinFakeButtons;
|
extern int darwinFakeButtons;
|
||||||
extern int darwinFakeMouse2Mask;
|
extern int darwinFakeMouse2Mask;
|
||||||
extern int darwinFakeMouse3Mask;
|
extern int darwinFakeMouse3Mask;
|
||||||
|
extern int darwinSwapAltMeta;
|
||||||
extern char *darwinKeymapFile;
|
extern char *darwinKeymapFile;
|
||||||
|
extern int darwinSyncKeymap;
|
||||||
extern unsigned int darwinDesiredWidth, darwinDesiredHeight;
|
extern unsigned int darwinDesiredWidth, darwinDesiredHeight;
|
||||||
extern int darwinDesiredDepth;
|
extern int darwinDesiredDepth;
|
||||||
extern int darwinDesiredRefresh;
|
extern int darwinDesiredRefresh;
|
||||||
|
@ -145,4 +150,4 @@ enum {
|
||||||
kXDarwinWindowMoved // window has moved on screen
|
kXDarwinWindowMoved // window has moved on screen
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _DARWIN_H */
|
#endif /* _DARWIN_H */
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Darwin event queue and event handling
|
* 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.
|
Copyright 2004 Kaleb S. KEITHLEY. All Rights Reserved.
|
||||||
|
|
||||||
This file is based on mieq.c by Keith Packard,
|
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
|
used in advertising or otherwise to promote the sale, use or other dealings
|
||||||
in this Software without prior written authorization from The Open Group.
|
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
|
#define NEED_EVENTS
|
||||||
#include "X.h"
|
#include "X.h"
|
||||||
|
@ -44,6 +44,7 @@ in this Software without prior written authorization from The Open Group.
|
||||||
#include "mipointer.h"
|
#include "mipointer.h"
|
||||||
|
|
||||||
#include "darwin.h"
|
#include "darwin.h"
|
||||||
|
#include "darwinKeyboard.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/uio.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>
|
#include <IOKit/hidsystem/IOLLEvent.h>
|
||||||
|
|
||||||
/* Fake button press/release for scroll wheel move. */
|
/* Fake button press/release for scroll wheel move. */
|
||||||
#define SCROLLWHEELUPFAKE 4
|
#define SCROLLWHEELUPFAKE 4
|
||||||
#define SCROLLWHEELDOWNFAKE 5
|
#define SCROLLWHEELDOWNFAKE 5
|
||||||
|
|
||||||
#define QUEUE_SIZE 256
|
#define QUEUE_SIZE 256
|
||||||
|
|
||||||
typedef struct _Event {
|
typedef struct _Event {
|
||||||
xEvent event;
|
xEvent event;
|
||||||
ScreenPtr pScreen;
|
ScreenPtr pScreen;
|
||||||
} EventRec, *EventPtr;
|
} EventRec, *EventPtr;
|
||||||
|
|
||||||
typedef struct _EventQueue {
|
typedef struct _EventQueue {
|
||||||
HWEventQueueType head, tail; /* long for SetInputCheck */
|
HWEventQueueType head, tail; /* long for SetInputCheck */
|
||||||
CARD32 lastEventTime; /* to avoid time running backwards */
|
CARD32 lastEventTime; /* to avoid time running backwards */
|
||||||
Bool lastMotion;
|
Bool lastMotion;
|
||||||
EventRec events[QUEUE_SIZE]; /* static allocation for signals */
|
EventRec events[QUEUE_SIZE]; /* static allocation for signals */
|
||||||
DevicePtr pKbd, pPtr; /* device pointer, to get funcs */
|
DevicePtr pKbd, pPtr; /* device pointer, to get funcs */
|
||||||
ScreenPtr pEnqueueScreen; /* screen events are being delivered to */
|
ScreenPtr pEnqueueScreen; /* screen events are being delivered to */
|
||||||
ScreenPtr pDequeueScreen; /* screen events are being dispatched to */
|
ScreenPtr pDequeueScreen; /* screen events are being dispatched to */
|
||||||
} EventQueueRec, *EventQueuePtr;
|
} EventQueueRec, *EventQueuePtr;
|
||||||
|
|
||||||
static EventQueueRec darwinEventQueue;
|
static EventQueueRec darwinEventQueue;
|
||||||
|
@ -79,7 +80,7 @@ static EventQueueRec darwinEventQueue;
|
||||||
* Press or release the given modifier key, specified by its mask.
|
* Press or release the given modifier key, specified by its mask.
|
||||||
*/
|
*/
|
||||||
static void DarwinPressModifierMask(
|
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 mask) // one of NX_*MASK constants
|
||||||
{
|
{
|
||||||
int key = DarwinModifierNXMaskToNXKey(mask);
|
int key = DarwinModifierNXMaskToNXKey(mask);
|
||||||
|
@ -225,10 +226,10 @@ DarwinEQEnqueue(
|
||||||
* is "unnecessary", but very useful
|
* is "unnecessary", but very useful
|
||||||
*/
|
*/
|
||||||
if (e->u.keyButtonPointer.time < darwinEventQueue.lastEventTime &&
|
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.events[oldtail].event.u.keyButtonPointer.time =
|
||||||
darwinEventQueue.lastEventTime;
|
darwinEventQueue.lastEventTime;
|
||||||
}
|
}
|
||||||
darwinEventQueue.events[oldtail].pScreen = darwinEventQueue.pEnqueueScreen;
|
darwinEventQueue.events[oldtail].pScreen = darwinEventQueue.pEnqueueScreen;
|
||||||
|
|
||||||
|
@ -260,7 +261,7 @@ DarwinEQSwitchScreen(
|
||||||
{
|
{
|
||||||
darwinEventQueue.pEnqueueScreen = pScreen;
|
darwinEventQueue.pEnqueueScreen = pScreen;
|
||||||
if (fromDIX)
|
if (fromDIX)
|
||||||
darwinEventQueue.pDequeueScreen = pScreen;
|
darwinEventQueue.pDequeueScreen = pScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -270,10 +271,10 @@ DarwinEQSwitchScreen(
|
||||||
*/
|
*/
|
||||||
void ProcessInputEvents(void)
|
void ProcessInputEvents(void)
|
||||||
{
|
{
|
||||||
EventRec *e;
|
EventRec *e;
|
||||||
int x, y;
|
int x, y;
|
||||||
xEvent xe;
|
xEvent xe;
|
||||||
static int old_flags = 0; // last known modifier state
|
static int old_flags = 0; // last known modifier state
|
||||||
// button number and modifier mask of currently pressed fake button
|
// button number and modifier mask of currently pressed fake button
|
||||||
static int darwinFakeMouseButtonDown = 0;
|
static int darwinFakeMouseButtonDown = 0;
|
||||||
static int darwinFakeMouseButtonMask = 0;
|
static int darwinFakeMouseButtonMask = 0;
|
||||||
|
@ -286,10 +287,10 @@ void ProcessInputEvents(void)
|
||||||
|
|
||||||
while (darwinEventQueue.head != darwinEventQueue.tail)
|
while (darwinEventQueue.head != darwinEventQueue.tail)
|
||||||
{
|
{
|
||||||
if (screenIsSaved == SCREEN_SAVER_ON)
|
if (screenIsSaved == SCREEN_SAVER_ON)
|
||||||
SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
|
SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
|
||||||
|
|
||||||
e = &darwinEventQueue.events[darwinEventQueue.head];
|
e = &darwinEventQueue.events[darwinEventQueue.head];
|
||||||
xe = e->event;
|
xe = e->event;
|
||||||
|
|
||||||
// Shift from global screen coordinates to coordinates relative to
|
// Shift from global screen coordinates to coordinates relative to
|
||||||
|
@ -299,36 +300,53 @@ void ProcessInputEvents(void)
|
||||||
xe.u.keyButtonPointer.rootY -= darwinMainScreenY +
|
xe.u.keyButtonPointer.rootY -= darwinMainScreenY +
|
||||||
dixScreenOrigins[miPointerCurrentScreen()->myNum].y;
|
dixScreenOrigins[miPointerCurrentScreen()->myNum].y;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assumption - screen switching can only occur on motion events
|
* Assumption - screen switching can only occur on motion events
|
||||||
*/
|
*/
|
||||||
if (e->pScreen != darwinEventQueue.pDequeueScreen)
|
if (e->pScreen != darwinEventQueue.pDequeueScreen)
|
||||||
{
|
{
|
||||||
darwinEventQueue.pDequeueScreen = e->pScreen;
|
darwinEventQueue.pDequeueScreen = e->pScreen;
|
||||||
x = xe.u.keyButtonPointer.rootX;
|
x = xe.u.keyButtonPointer.rootX;
|
||||||
y = xe.u.keyButtonPointer.rootY;
|
y = xe.u.keyButtonPointer.rootY;
|
||||||
if (darwinEventQueue.head == QUEUE_SIZE - 1)
|
if (darwinEventQueue.head == QUEUE_SIZE - 1)
|
||||||
darwinEventQueue.head = 0;
|
darwinEventQueue.head = 0;
|
||||||
else
|
else
|
||||||
++darwinEventQueue.head;
|
++darwinEventQueue.head;
|
||||||
NewCurrentScreen (darwinEventQueue.pDequeueScreen, x, y);
|
NewCurrentScreen (darwinEventQueue.pDequeueScreen, x, y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (darwinEventQueue.head == QUEUE_SIZE - 1)
|
if (darwinEventQueue.head == QUEUE_SIZE - 1)
|
||||||
darwinEventQueue.head = 0;
|
darwinEventQueue.head = 0;
|
||||||
else
|
else
|
||||||
++darwinEventQueue.head;
|
++darwinEventQueue.head;
|
||||||
switch (xe.u.u.type)
|
switch (xe.u.u.type)
|
||||||
{
|
{
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
case KeyRelease:
|
if (old_flags == 0
|
||||||
xe.u.u.detail += MIN_KEYCODE;
|
&& darwinSyncKeymap && darwinKeymapFile == NULL)
|
||||||
(*darwinEventQueue.pKbd->processInputProc)
|
{
|
||||||
(&xe, (DeviceIntPtr)darwinEventQueue.pKbd, 1);
|
/* See if keymap has changed. */
|
||||||
break;
|
|
||||||
|
|
||||||
case ButtonPress:
|
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;
|
||||||
|
|
||||||
|
case ButtonPress:
|
||||||
miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
|
miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
|
||||||
xe.u.keyButtonPointer.rootY,
|
xe.u.keyButtonPointer.rootY,
|
||||||
xe.u.keyButtonPointer.time);
|
xe.u.keyButtonPointer.time);
|
||||||
|
@ -386,7 +404,7 @@ void ProcessInputEvents(void)
|
||||||
miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
|
miPointerAbsoluteCursor(xe.u.keyButtonPointer.rootX,
|
||||||
xe.u.keyButtonPointer.rootY,
|
xe.u.keyButtonPointer.rootY,
|
||||||
xe.u.keyButtonPointer.time);
|
xe.u.keyButtonPointer.time);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kXDarwinUpdateModifiers:
|
case kXDarwinUpdateModifiers:
|
||||||
{
|
{
|
||||||
|
@ -424,7 +442,7 @@ void ProcessInputEvents(void)
|
||||||
xe.u.u.type = ButtonRelease;
|
xe.u.u.type = ButtonRelease;
|
||||||
}
|
}
|
||||||
(*darwinEventQueue.pPtr->processInputProc)
|
(*darwinEventQueue.pPtr->processInputProc)
|
||||||
(&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
|
(&xe, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -455,8 +473,8 @@ void ProcessInputEvents(void)
|
||||||
default:
|
default:
|
||||||
// Check for mode specific event
|
// Check for mode specific event
|
||||||
DarwinModeProcessEvent(&xe);
|
DarwinModeProcessEvent(&xe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
miPointerUpdate();
|
miPointerUpdate();
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
//
|
//
|
||||||
// Keyboard support for the Darwin X Server
|
// Keyboard support for the Darwin X Server
|
||||||
//
|
//
|
||||||
// Copyright 2004 Kaleb S. KEITHLEY. All Rights Reserved.
|
// Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
|
||||||
// Copyright (c) 2001-2003 Torrey T. Lyons. All Rights Reserved.
|
|
||||||
// Copyright (c) 2003 Apple Computer, Inc. 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
|
// The code to parse the Darwin keymap is derived from dumpkeymap.c
|
||||||
// by Eric Sunshine, which includes the following copyright:
|
// 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,
|
// 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.
|
// 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] = {
|
static KeySym const next_to_x[256] = {
|
||||||
NoSymbol, NoSymbol, NoSymbol, XK_KP_Enter,
|
NoSymbol, NoSymbol, NoSymbol, XK_KP_Enter,
|
||||||
|
@ -170,13 +170,13 @@ static KeySym const next_to_x[256] = {
|
||||||
XK_thorn, XK_ydiaeresis, NoSymbol, NoSymbol,
|
XK_thorn, XK_ydiaeresis, NoSymbol, NoSymbol,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MIN_SYMBOL 0xAC
|
#define MIN_SYMBOL 0xAC
|
||||||
static KeySym const symbol_to_x[] = {
|
static KeySym const symbol_to_x[] = {
|
||||||
XK_Left, XK_Up, XK_Right, XK_Down
|
XK_Left, XK_Up, XK_Right, XK_Down
|
||||||
};
|
};
|
||||||
int const NUM_SYMBOL = sizeof(symbol_to_x) / sizeof(symbol_to_x[0]);
|
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[] = {
|
static KeySym const funckey_to_x[] = {
|
||||||
XK_F1, XK_F2, XK_F3, XK_F4,
|
XK_F1, XK_F2, XK_F3, XK_F4,
|
||||||
XK_F5, XK_F6, XK_F7, XK_F8,
|
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]);
|
int const NUM_FUNCKEY = sizeof(funckey_to_x) / sizeof(funckey_to_x[0]);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
KeySym normalSym;
|
KeySym normalSym;
|
||||||
KeySym keypadSym;
|
KeySym keypadSym;
|
||||||
} darwinKeyPad_t;
|
} darwinKeyPad_t;
|
||||||
|
|
||||||
static darwinKeyPad_t const normal_to_keypad[] = {
|
static darwinKeyPad_t const normal_to_keypad[] = {
|
||||||
|
@ -550,36 +550,36 @@ Bool DarwinParseNXKeyMapping(
|
||||||
|
|
||||||
// If AlphaLock and Shift modifiers produce different codes,
|
// If AlphaLock and Shift modifiers produce different codes,
|
||||||
// we record the Shift case since X handles AlphaLock.
|
// we record the Shift case since X handles AlphaLock.
|
||||||
if (charGenMask & 0x01) { // AlphaLock
|
if (charGenMask & 0x01) { // AlphaLock
|
||||||
parse_next_char_code( keyMapStream, k+1 );
|
parse_next_char_code( keyMapStream, k+1 );
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (charGenMask & 0x02) { // Shift
|
if (charGenMask & 0x02) { // Shift
|
||||||
parse_next_char_code( keyMapStream, k+1 );
|
parse_next_char_code( keyMapStream, k+1 );
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
|
|
||||||
if (charGenMask & 0x01) { // Shift-AlphaLock
|
if (charGenMask & 0x01) { // Shift-AlphaLock
|
||||||
get_number(keyMapStream); get_number(keyMapStream);
|
get_number(keyMapStream); get_number(keyMapStream);
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip the Control cases
|
// Skip the Control cases
|
||||||
if (charGenMask & 0x04) { // Control
|
if (charGenMask & 0x04) { // Control
|
||||||
get_number(keyMapStream); get_number(keyMapStream);
|
get_number(keyMapStream); get_number(keyMapStream);
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
|
|
||||||
if (charGenMask & 0x01) { // Control-AlphaLock
|
if (charGenMask & 0x01) { // Control-AlphaLock
|
||||||
get_number(keyMapStream); get_number(keyMapStream);
|
get_number(keyMapStream); get_number(keyMapStream);
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (charGenMask & 0x02) { // Control-Shift
|
if (charGenMask & 0x02) { // Control-Shift
|
||||||
get_number(keyMapStream); get_number(keyMapStream);
|
get_number(keyMapStream); get_number(keyMapStream);
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
|
|
||||||
if (charGenMask & 0x01) { // Shift-Control-AlphaLock
|
if (charGenMask & 0x01) { // Shift-Control-AlphaLock
|
||||||
get_number(keyMapStream); get_number(keyMapStream);
|
get_number(keyMapStream); get_number(keyMapStream);
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
}
|
}
|
||||||
|
@ -587,20 +587,20 @@ Bool DarwinParseNXKeyMapping(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process Alt cases
|
// Process Alt cases
|
||||||
if (charGenMask & 0x08) { // Alt
|
if (charGenMask & 0x08) { // Alt
|
||||||
parse_next_char_code( keyMapStream, k+2 );
|
parse_next_char_code( keyMapStream, k+2 );
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
|
|
||||||
if (charGenMask & 0x01) { // Alt-AlphaLock
|
if (charGenMask & 0x01) { // Alt-AlphaLock
|
||||||
parse_next_char_code( keyMapStream, k+3 );
|
parse_next_char_code( keyMapStream, k+3 );
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (charGenMask & 0x02) { // Alt-Shift
|
if (charGenMask & 0x02) { // Alt-Shift
|
||||||
parse_next_char_code( keyMapStream, k+3 );
|
parse_next_char_code( keyMapStream, k+3 );
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
|
|
||||||
if (charGenMask & 0x01) { // Alt-Shift-AlphaLock
|
if (charGenMask & 0x01) { // Alt-Shift-AlphaLock
|
||||||
get_number(keyMapStream); get_number(keyMapStream);
|
get_number(keyMapStream); get_number(keyMapStream);
|
||||||
numKeyCodes--;
|
numKeyCodes--;
|
||||||
}
|
}
|
||||||
|
@ -636,27 +636,10 @@ Bool DarwinParseNXKeyMapping(
|
||||||
destroy_data_stream( keyMapStream );
|
destroy_data_stream( keyMapStream );
|
||||||
xfree( keyMap.mapping );
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DarwinBuildModifierMaps
|
* DarwinBuildModifierMaps
|
||||||
* Use the keyMap field of keyboard info structure to populate
|
* Use the keyMap field of keyboard info structure to populate
|
||||||
|
@ -668,14 +651,13 @@ DarwinBuildModifierMaps(
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
KeySym *k;
|
KeySym *k;
|
||||||
int darwinSwapAltMeta = 0;
|
|
||||||
|
|
||||||
memset(info->modMap, NoSymbol, sizeof(info->modMap));
|
memset(info->modMap, NoSymbol, sizeof(info->modMap));
|
||||||
memset(info->modifierKeycodes, 0, sizeof(info->modifierKeycodes));
|
memset(info->modifierKeycodes, 0, sizeof(info->modifierKeycodes));
|
||||||
|
|
||||||
for (i = 0; i < NUM_KEYCODES; i++)
|
for (i = 0; i < NUM_KEYCODES; i++)
|
||||||
{
|
{
|
||||||
k = info->keyMap + i * GLYPHS_PER_KEY;
|
k = info->keyMap + i * GLYPHS_PER_KEY;
|
||||||
|
|
||||||
switch (k[0]) {
|
switch (k[0]) {
|
||||||
case XK_Shift_L:
|
case XK_Shift_L:
|
||||||
|
@ -746,27 +728,75 @@ DarwinBuildModifierMaps(
|
||||||
case XK_Num_Lock:
|
case XK_Num_Lock:
|
||||||
info->modMap[MIN_KEYCODE + i] = Mod3Mask;
|
info->modMap[MIN_KEYCODE + i] = Mod3Mask;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (darwinSwapAltMeta)
|
if (darwinSwapAltMeta)
|
||||||
{
|
{
|
||||||
switch (k[0])
|
switch (k[0])
|
||||||
{
|
{
|
||||||
case XK_Alt_L:
|
case XK_Alt_L:
|
||||||
k[0] = XK_Meta_L;
|
k[0] = XK_Meta_L;
|
||||||
break;
|
break;
|
||||||
case XK_Alt_R:
|
case XK_Alt_R:
|
||||||
k[0] = XK_Meta_R;
|
k[0] = XK_Meta_R;
|
||||||
break;
|
break;
|
||||||
case XK_Meta_L:
|
case XK_Meta_L:
|
||||||
k[0] = XK_Alt_L;
|
k[0] = XK_Alt_L;
|
||||||
break;
|
break;
|
||||||
case XK_Meta_R:
|
case XK_Meta_R:
|
||||||
k[0] = XK_Alt_R;
|
k[0] = XK_Alt_R;
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -781,31 +811,89 @@ void DarwinKeyboardInit(
|
||||||
{
|
{
|
||||||
KeySymsRec keySyms;
|
KeySymsRec keySyms;
|
||||||
|
|
||||||
memset( keyInfo.keyMap, 0, sizeof( keyInfo.keyMap ) );
|
|
||||||
|
|
||||||
// Open a shared connection to the HID System.
|
// Open a shared connection to the HID System.
|
||||||
// Note that the Event Status Driver is really just a wrapper
|
// Note that the Event Status Driver is really just a wrapper
|
||||||
// for a kIOHIDParamConnectType connection.
|
// for a kIOHIDParamConnectType connection.
|
||||||
assert( darwinParamConnect = NXOpenEventStatus() );
|
assert( darwinParamConnect = NXOpenEventStatus() );
|
||||||
|
|
||||||
if (!DarwinParseNXKeyMapping(&keyInfo)) {
|
DarwinLoadKeyboardMapping(&keySyms);
|
||||||
if (!DarwinModeReadSystemKeymap(&keyInfo)) {
|
|
||||||
FatalError("Could not build a valid keymap.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DarwinBuildModifierMaps(&keyInfo);
|
/* Initialize the seed, so we don't reload the keymap unnecessarily
|
||||||
|
(and possibly overwrite xinitrc changes) */
|
||||||
keySyms.map = keyInfo.keyMap;
|
DarwinModeSystemKeymapSeed();
|
||||||
keySyms.mapWidth = GLYPHS_PER_KEY;
|
|
||||||
keySyms.minKeyCode = MIN_KEYCODE;
|
|
||||||
keySyms.maxKeyCode = MAX_KEYCODE;
|
|
||||||
|
|
||||||
assert( InitKeyboardDeviceStruct( (DevicePtr)pDev, &keySyms,
|
assert( InitKeyboardDeviceStruct( (DevicePtr)pDev, &keySyms,
|
||||||
keyInfo.modMap, DarwinModeBell,
|
keyInfo.modMap, DarwinModeBell,
|
||||||
DarwinChangeKeyboardControl ));
|
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
|
// Modifier translation functions
|
||||||
//
|
//
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -45,6 +45,8 @@ typedef struct darwinKeyboardInfo_struct {
|
||||||
unsigned char modifierKeycodes[32][2];
|
unsigned char modifierKeycodes[32][2];
|
||||||
} darwinKeyboardInfo;
|
} darwinKeyboardInfo;
|
||||||
|
|
||||||
|
void DarwinKeyboardReload(DeviceIntPtr pDev);
|
||||||
|
unsigned int DarwinModeSystemKeymapSeed(void);
|
||||||
Bool DarwinModeReadSystemKeymap(darwinKeyboardInfo *info);
|
Bool DarwinModeReadSystemKeymap(darwinKeyboardInfo *info);
|
||||||
|
|
||||||
#endif /* DARWIN_KEYBOARD_H */
|
#endif /* DARWIN_KEYBOARD_H */
|
||||||
|
|
|
@ -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
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
@ -104,6 +104,17 @@ int DarwinModeProcessArgument(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DarwinModeSystemKeymapSeed
|
||||||
|
* Changes to NXKeyMapping are not tracked.
|
||||||
|
*/
|
||||||
|
unsigned int
|
||||||
|
DarwinModeSystemKeymapSeed(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DarwinModeReadSystemKeymap
|
* DarwinModeReadSystemKeymap
|
||||||
* IOKit has no alternative to NXKeyMapping API.
|
* IOKit has no alternative to NXKeyMapping API.
|
||||||
|
|
|
@ -148,7 +148,7 @@ const static struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
DarwinSystemKeymapSeed (void)
|
DarwinModeSystemKeymapSeed (void)
|
||||||
{
|
{
|
||||||
static unsigned int seed;
|
static unsigned int seed;
|
||||||
|
|
||||||
|
@ -373,6 +373,12 @@ DarwinModeReadSystemKeymap (darwinKeyboardInfo *info)
|
||||||
|
|
||||||
#else /* !HAS_KL_API */
|
#else /* !HAS_KL_API */
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
DarwinModeSystemKeymapSeed (void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
DarwinModeReadSystemKeymap (darwinKeyboardInfo *info)
|
DarwinModeReadSystemKeymap (darwinKeyboardInfo *info)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue