diff options
Diffstat (limited to 'hw/kdrive')
37 files changed, 3044 insertions, 1603 deletions
diff --git a/hw/kdrive/Makefile.am b/hw/kdrive/Makefile.am index c8832ebac..fa1dba90a 100644 --- a/hw/kdrive/Makefile.am +++ b/hw/kdrive/Makefile.am @@ -3,10 +3,14 @@ VESA_SUBDIRS = vesa ati chips epson i810 mach64 mga neomagic nvidia pm2 r128 \ smi via endif -if KDRIVEFBDEV +if BUILD_KDRIVEFBDEVLIB FBDEV_SUBDIRS = fbdev endif +if XFAKESERVER +XFAKE_SUBDIRS = fake +endif + if XSDLSERVER XSDL_SUBDIRS = sdl endif @@ -22,7 +26,7 @@ SUBDIRS = \ $(FBDEV_SUBDIRS) \ $(VESA_SUBDIRS) \ $(XEPHYR_SUBDIRS) \ - fake + $(XFAKE_SUBDIRS) DIST_SUBDIRS = vesa ati chips epson i810 mach64 mga neomagic nvidia pm2 r128 \ smi via fbdev sdl ephyr src linux fake sis300 diff --git a/hw/kdrive/ati/ati_stub.c b/hw/kdrive/ati/ati_stub.c index 01ebc3139..d0bc4ca6b 100644 --- a/hw/kdrive/ati/ati_stub.c +++ b/hw/kdrive/ati/ati_stub.c @@ -53,7 +53,15 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) void InitInput(int argc, char **argv) { - KdInitInput(&LinuxMouseFuncs, &LinuxKeyboardFuncs); + KdKeyboardInfo *ki = NULL; + + KdAddPointerDriver(&LinuxMouseDriver); + ki = KdNewKeyboard(); + if (ki) { + ki->driver = &LinuxKeyboardDriver; + KdAddKeyboard(ki); + } + KdInitInput(); } void diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am index f423bfe40..6982d80d9 100644 --- a/hw/kdrive/ephyr/Makefile.am +++ b/hw/kdrive/ephyr/Makefile.am @@ -33,7 +33,6 @@ Xephyr_LDADD = \ libxephyr-hostx.a \ ../../../exa/libexa.la \ @KDRIVE_LIBS@ \ - @KDRIVE_LIBS@ \ $(TSLIB_LIBS) \ @XEPHYR_LIBS@ diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c index fbb16a465..92fd83195 100644 --- a/hw/kdrive/ephyr/ephyr.c +++ b/hw/kdrive/ephyr/ephyr.c @@ -36,10 +36,16 @@ #include "inputstr.h" extern int KdTsPhyScreen; -extern DeviceIntPtr pKdKeyboard; +KdKeyboardInfo *ephyrKbd; +KdPointerInfo *ephyrMouse; +EphyrKeySyms ephyrKeySyms; static int mouseState = 0; +typedef struct _EphyrInputPrivate { + Bool enabled; +} EphyrKbdPrivate, EphyrPointerPrivate; + Bool EphyrWantGrayScale = 0; Bool @@ -206,15 +212,14 @@ ephyrMapFramebuffer (KdScreenInfo *screen) { EphyrScrPriv *scrpriv = screen->driver; EphyrPriv *priv = screen->card->driver; - KdMouseMatrix m; + KdPointerMatrix m; int buffer_height; EPHYR_DBG(" screen->width: %d, screen->height: %d", screen->width, screen->height); - KdComputeMouseMatrix (&m, scrpriv->randr, screen->width, screen->height); - - KdSetMouseMatrix (&m); + KdComputePointerMatrix (&m, scrpriv->randr, screen->width, screen->height); + KdSetPointerMatrix (&m); priv->bytes_per_line = ((screen->width * screen->fb[0].bitsPerPixel + 31) >> 5) << 2; @@ -719,8 +724,9 @@ ephyrUpdateModifierState(unsigned int state) kptr = &keyc->down[key >> 3]; bit = 1 << (key & 7); - if (*kptr & bit) - KdEnqueueKeyboardEvent(key, TRUE); /* release */ + if (*kptr & bit && ephyrKbd && + ((EphyrKbdPrivate *)ephyrKbd->driverPrivate)->enabled) + KdEnqueueKeyboardEvent(ephyrKbd, key, TRUE); /* release */ if (--count == 0) break; @@ -732,7 +738,9 @@ ephyrUpdateModifierState(unsigned int state) for (key = 0; key < MAP_LENGTH; key++) if (keyc->modifierMap[key] & mask) { - KdEnqueueKeyboardEvent(key, FALSE); /* press */ + if (keyc->modifierMap[key] & mask && ephyrKbd && + ((EphyrKbdPrivate *)ephyrKbd->driverPrivate)->enabled) + KdEnqueueKeyboardEvent(ephyrKbd, key, FALSE); /* press */ break; } } @@ -748,31 +756,47 @@ ephyrPoll(void) switch (ev.type) { case EPHYR_EV_MOUSE_MOTION: - KdEnqueueMouseEvent(kdMouseInfo, mouseState, - ev.data.mouse_motion.x, - ev.data.mouse_motion.y); + if (!ephyrMouse || + !((EphyrPointerPrivate *)ephyrMouse->driverPrivate)->enabled) + continue; + KdEnqueuePointerEvent(ephyrMouse, mouseState, + ev.data.mouse_motion.x, + ev.data.mouse_motion.y, + 0); break; case EPHYR_EV_MOUSE_PRESS: + if (!ephyrMouse || + !((EphyrPointerPrivate *)ephyrMouse->driverPrivate)->enabled) + continue; ephyrUpdateModifierState(ev.key_state); mouseState |= ev.data.mouse_down.button_num; - KdEnqueueMouseEvent(kdMouseInfo, mouseState|KD_MOUSE_DELTA, 0, 0); + KdEnqueuePointerEvent(ephyrMouse, mouseState|KD_MOUSE_DELTA, 0, 0, 0); break; case EPHYR_EV_MOUSE_RELEASE: + if (!ephyrMouse || + !((EphyrPointerPrivate *)ephyrMouse->driverPrivate)->enabled) + continue; ephyrUpdateModifierState(ev.key_state); mouseState &= ~ev.data.mouse_up.button_num; - KdEnqueueMouseEvent(kdMouseInfo, mouseState|KD_MOUSE_DELTA, 0, 0); + KdEnqueuePointerEvent(ephyrMouse, mouseState|KD_MOUSE_DELTA, 0, 0, 0); break; case EPHYR_EV_KEY_PRESS: + if (!ephyrKbd || + !((EphyrKbdPrivate *)ephyrKbd->driverPrivate)->enabled) + continue; ephyrUpdateModifierState(ev.key_state); - KdEnqueueKeyboardEvent (ev.data.key_down.scancode, FALSE); + KdEnqueueKeyboardEvent (ephyrKbd, ev.data.key_down.scancode, FALSE); break; case EPHYR_EV_KEY_RELEASE: + if (!ephyrKbd || + !((EphyrKbdPrivate *)ephyrKbd->driverPrivate)->enabled) + continue; ephyrUpdateModifierState(ev.key_state); - KdEnqueueKeyboardEvent (ev.data.key_up.scancode, TRUE); + KdEnqueueKeyboardEvent (ephyrKbd, ev.data.key_up.scancode, TRUE); break; default: @@ -833,59 +857,115 @@ ephyrPutColors (ScreenPtr pScreen, int fb, int n, xColorItem *pdefs) /* Mouse calls */ -static Bool -MouseInit (void) +static Status +MouseInit (KdPointerInfo *pi) +{ + pi->driverPrivate = (EphyrPointerPrivate *) + xcalloc(sizeof(EphyrPointerPrivate), 1); + ((EphyrPointerPrivate *)pi->driverPrivate)->enabled = FALSE; + ephyrMouse = pi; + /* FIXME DO NOT COMMIT */ + KdAddPointerDriver(&EphyrMouseDriver); + ErrorF("SUCCESS!\n"); + return Success; +} + +static Status +MouseEnable (KdPointerInfo *pi) { - return TRUE; + ((EphyrPointerPrivate *)pi->driverPrivate)->enabled = TRUE; + ErrorF("SUCCESS ENABLE!\n"); + return Success; } static void -MouseFini (void) +MouseDisable (KdPointerInfo *pi) { - ; + ((EphyrPointerPrivate *)pi->driverPrivate)->enabled = FALSE; + return; } -KdMouseFuncs EphyrMouseFuncs = { +static void +MouseFini (KdPointerInfo *pi) +{ + ephyrMouse = NULL; + return; +} + +KdPointerDriver EphyrMouseDriver = { + "ephyr", MouseInit, + MouseEnable, + MouseDisable, MouseFini, + NULL, }; /* Keyboard */ -static void -EphyrKeyboardLoad (void) +static Status +EphyrKeyboardInit (KdKeyboardInfo *ki) { - EPHYR_DBG("mark"); + ki->driverPrivate = (EphyrKbdPrivate *) + xcalloc(sizeof(EphyrKbdPrivate), 1); + /* FIXME blah blah overrunning memory blah blah */ + ki->minScanCode = ki->keySyms.minKeyCode = 0; + ki->maxScanCode = ki->keySyms.maxKeyCode = 255; + ephyrKbd = ki; + return Success; +} - hostx_load_keymap(); +static Status +EphyrKeyboardEnable (KdKeyboardInfo *ki) +{ + hostx_load_keymap(); + if (!ephyrKeySyms.map) { + ErrorF("Couldn't load keymap from host\n"); + return BadAlloc; + } + ki->keySyms.minKeyCode = ephyrKeySyms.minKeyCode; + ki->keySyms.maxKeyCode = ephyrKeySyms.maxKeyCode; + ki->minScanCode = ki->keySyms.minKeyCode; + ki->maxScanCode = ki->keySyms.maxKeyCode; + ki->keySyms.mapWidth = ephyrKeySyms.mapWidth; + ki->keySyms.map = ephyrKeySyms.map; + ((EphyrKbdPrivate *)ki->driverPrivate)->enabled = TRUE; + + return Success; } -static int -EphyrKeyboardInit (void) +static void +EphyrKeyboardDisable (KdKeyboardInfo *ki) { - return 0; + ((EphyrKbdPrivate *)ki->driverPrivate)->enabled = FALSE; } static void -EphyrKeyboardFini (void) +EphyrKeyboardFini (KdKeyboardInfo *ki) { + /* not xfree: we call malloc from hostx.c. */ + free(ki->keySyms.map); + ephyrKbd = NULL; + return; } static void -EphyrKeyboardLeds (int leds) +EphyrKeyboardLeds (KdKeyboardInfo *ki, int leds) { } static void -EphyrKeyboardBell (int volume, int frequency, int duration) +EphyrKeyboardBell (KdKeyboardInfo *ki, int volume, int frequency, int duration) { } -KdKeyboardFuncs EphyrKeyboardFuncs = { - EphyrKeyboardLoad, +KdKeyboardDriver EphyrKeyboardDriver = { + "ephyr", EphyrKeyboardInit, + EphyrKeyboardEnable, EphyrKeyboardLeds, EphyrKeyboardBell, + EphyrKeyboardDisable, EphyrKeyboardFini, - 0, + NULL, }; diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h index 707cb0168..f49d920d1 100644 --- a/hw/kdrive/ephyr/ephyr.h +++ b/hw/kdrive/ephyr/ephyr.h @@ -31,7 +31,6 @@ #include "os.h" /* for OsSignal() */ #include "kdrive.h" -#include "kkeymap.h" #include "hostx.h" #include "exa.h" @@ -68,7 +67,9 @@ typedef struct _ephyrScrPriv { EphyrFakexaPriv *fakexa; } EphyrScrPriv; -extern KdCardFuncs ephyrFuncs; +extern KdCardFuncs ephyrFuncs; +extern KdKeyboardInfo *ephyrKbd; +extern KdPointerInfo *ephyrMouse; Bool ephyrInitialize (KdCardInfo *card, EphyrPriv *priv); @@ -167,9 +168,9 @@ ephyrShadowUpdate (ScreenPtr pScreen, shadowBufPtr pBuf); void ephyrUpdateModifierState(unsigned int state); -extern KdMouseFuncs EphyrMouseFuncs; +extern KdPointerDriver EphyrMouseDriver; -extern KdKeyboardFuncs EphyrKeyboardFuncs; +extern KdKeyboardDriver EphyrKeyboardDriver; extern KdOsFuncs EphyrOsFuncs; diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c index 1aa608e93..021abd65f 100644 --- a/hw/kdrive/ephyr/ephyrinit.c +++ b/hw/kdrive/ephyr/ephyrinit.c @@ -51,7 +51,24 @@ InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv) void InitInput (int argc, char **argv) { - KdInitInput (&EphyrMouseFuncs, &EphyrKeyboardFuncs); + KdKeyboardInfo *ki; + KdPointerInfo *pi; + + ki = KdNewKeyboard(); + if (!ki) + FatalError("Couldn't create Xephyr keyboard\n"); + ki->driver = &EphyrKeyboardDriver; + ki->name = KdSaveString("Xephyr virtual keyboard"); + KdAddKeyboard(ki); + + pi = KdNewPointer(); + if (!pi) + FatalError("Couldn't create Xephyr pointer\n"); + pi->driver = &EphyrMouseDriver; + pi->name = KdSaveString("Xephyr virtual mouse"); + KdAddPointer(pi); + + KdInitInput(); } void diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c index 32a46dcf4..b23532fe0 100644 --- a/hw/kdrive/ephyr/hostx.c +++ b/hw/kdrive/ephyr/hostx.c @@ -77,14 +77,8 @@ static EphyrHostXVars HostX = { "?", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; static int HostXWantDamageDebug = 0; -extern KeySym EphyrKeymap[]; - -extern KeySym kdKeymap[]; -extern int kdMinScanCode; -extern int kdMaxScanCode; -extern int kdMinKeyCode; -extern int kdMaxKeyCode; -extern int kdKeymapWidth; +extern EphyrKeySyms ephyrKeySyms; + extern int monitorResolution; static void @@ -403,9 +397,9 @@ hostx_get_bpp(void) } void -hostx_get_visual_masks (unsigned long *rmsk, - unsigned long *gmsk, - unsigned long *bmsk) +hostx_get_visual_masks (CARD32 *rmsk, + CARD32 *gmsk, + CARD32 *bmsk) { if (host_depth_matches_server()) { @@ -681,6 +675,13 @@ hostx_load_keymap(void) max_keycode - min_keycode + 1, &host_width); + + ephyrKeySyms.map = (KeySym *)calloc(sizeof(KeySym), + (max_keycode - min_keycode + 1) * + width); + if (!ephyrKeySyms.map) + return; + /* Try and copy the hosts keymap into our keymap to avoid loads * of messing around. * @@ -695,13 +696,9 @@ hostx_load_keymap(void) EPHYR_DBG("keymap width, host:%d kdrive:%d", host_width, width); - /* all kdrive vars - see kkeymap.c */ - - kdMinScanCode = min_keycode; - kdMaxScanCode = max_keycode; - kdMinKeyCode = min_keycode; - kdMaxKeyCode = max_keycode; - kdKeymapWidth = width; + ephyrKeySyms.minKeyCode = min_keycode; + ephyrKeySyms.maxKeyCode = max_keycode; + ephyrKeySyms.mapWidth = (width > 4) ? 4 : width; XFree(keymap); } diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h index d3f6da3d3..4e3c6af33 100644 --- a/hw/kdrive/ephyr/hostx.h +++ b/hw/kdrive/ephyr/hostx.h @@ -26,6 +26,9 @@ #ifndef _XLIBS_STUFF_H_ #define _XLIBS_STUFF_H_ +#include <X11/X.h> +#include <X11/Xmd.h> + #define EPHYR_WANT_DEBUG 0 #if (EPHYR_WANT_DEBUG) @@ -48,6 +51,14 @@ typedef enum EphyrHostXEventType } EphyrHostXEventType; +/* I can't believe it's not a KeySymsRec. */ +typedef struct { + int minKeyCode; + int maxKeyCode; + int mapWidth; + KeySym *map; +} EphyrKeySyms; + struct EphyrHostXEvent { EphyrHostXEventType type; @@ -126,9 +137,9 @@ int hostx_get_bpp(void); void -hostx_get_visual_masks (unsigned long *rmsk, - unsigned long *gmsk, - unsigned long *bmsk); +hostx_get_visual_masks (CARD32 *rmsk, + CARD32 *gmsk, + CARD32 *bmsk); void hostx_set_cmap_entry(unsigned char idx, unsigned char r, diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c index d56512b3f..ca515f9b6 100644 --- a/hw/kdrive/fake/fake.c +++ b/hw/kdrive/fake/fake.c @@ -158,7 +158,7 @@ Bool fakeMapFramebuffer (KdScreenInfo *screen) { FakeScrPriv *scrpriv = screen->driver; - KdMouseMatrix m; + KdPointerMatrix m; FakePriv *priv = screen->card->driver; if (scrpriv->randr != RR_Rotate_0) @@ -166,9 +166,9 @@ fakeMapFramebuffer (KdScreenInfo *screen) else scrpriv->shadow = FALSE; - KdComputeMouseMatrix (&m, scrpriv->randr, screen->width, screen->height); + KdComputePointerMatrix (&m, scrpriv->randr, screen->width, screen->height); - KdSetMouseMatrix (&m); + KdSetPointerMatrix (&m); priv->bytes_per_line = ((screen->width * screen->fb[0].bitsPerPixel + 31) >> 5) << 2; if (priv->base) diff --git a/hw/kdrive/fake/fake.h b/hw/kdrive/fake/fake.h index 4d90d3169..f7c8c3431 100644 --- a/hw/kdrive/fake/fake.h +++ b/hw/kdrive/fake/fake.h @@ -130,9 +130,9 @@ fakeRandRInit (ScreenPtr pScreen); #endif -extern KdMouseFuncs FakeMouseFuncs; +extern KdPointerDriver FakePointerDriver; -extern KdKeyboardFuncs FakeKeyboardFuncs; +extern KdKeyboardDriver FakeKeyboardDriver; extern KdOsFuncs FakeOsFuncs; diff --git a/hw/kdrive/fake/fakeinit.c b/hw/kdrive/fake/fakeinit.c index c5ee4bc3f..dd88bc5a7 100644 --- a/hw/kdrive/fake/fakeinit.c +++ b/hw/kdrive/fake/fakeinit.c @@ -44,7 +44,22 @@ InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv) void InitInput (int argc, char **argv) { - KdInitInput (&FakeMouseFuncs, &FakeKeyboardFuncs); + KdPointerInfo *pi; + KdKeyboardInfo *ki; + + pi = KdNewPointer (); + if (!pi) + return; + pi->driver = &FakePointerDriver; + KdAddPointer(pi); + + ki = KdNewKeyboard (); + if (!ki) + return; + ki->driver = &FakeKeyboardDriver; + KdAddKeyboard(ki); + + KdInitInput (); } void diff --git a/hw/kdrive/fake/kbd.c b/hw/kdrive/fake/kbd.c index 9cf4de060..db224c995 100644 --- a/hw/kdrive/fake/kbd.c +++ b/hw/kdrive/fake/kbd.c @@ -27,7 +27,6 @@ #include <kdrive-config.h> #endif #include "fake.h" -#include "kkeymap.h" #include <X11/keysym.h> #define FAKE_WIDTH 2 @@ -155,41 +154,58 @@ KeySym FakeKeymap[] = { /* 116 123 */ NoSymbol, NoSymbol, /* tiny button */ }; -static void -FakeKeyboardLoad (void) +static Status +FakeKeyboardInit (KdKeyboardInfo *ki) +{ + ki->keySyms.minKeyCode = 1; + ki->keySyms.maxKeyCode = (sizeof (FakeKeymap) / sizeof (FakeKeymap[0])) / FAKE_WIDTH; + ki->keySyms.mapWidth = FAKE_WIDTH; + if (ki->keySyms.map) + xfree(ki->keySyms.map); + ki->keySyms.map = (KeySym *)xalloc(sizeof(FakeKeymap)); + if (!ki->keySyms.map) + return BadAlloc; + memcpy (ki->keySyms.map, FakeKeymap, sizeof (FakeKeymap)); + + return Success; +} + +static Status +FakeKeyboardEnable (KdKeyboardInfo *ki) { - kdMinScanCode = 1; - kdKeymapWidth = FAKE_WIDTH; - kdMaxScanCode = (sizeof (FakeKeymap) / sizeof (FakeKeymap[0])) / FAKE_WIDTH; - memcpy (kdKeymap, FakeKeymap, sizeof (FakeKeymap)); + return Success; } -static int -FakeKeyboardInit (void) +static void +FakeKeyboardDisable (KdKeyboardInfo *ki) { - return 0; + return; } static void -FakeKeyboardFini (void) +FakeKeyboardFini (KdKeyboardInfo *ki) { + xfree(ki->keySyms.map); + ki->keySyms.map = NULL; } static void -FakeKeyboardLeds (int leds) +FakeKeyboardLeds (KdKeyboardInfo *ki, int leds) { } static void -FakeKeyboardBell (int volume, int frequency, int duration) +FakeKeyboardBell (KdKeyboardInfo *ki, int volume, int frequency, int duration) { } -KdKeyboardFuncs FakeKeyboardFuncs = { - FakeKeyboardLoad, +KdKeyboardDriver FakeKeyboardDriver = { + "fake", FakeKeyboardInit, + FakeKeyboardEnable, FakeKeyboardLeds, FakeKeyboardBell, + FakeKeyboardDisable, FakeKeyboardFini, - 0, + NULL, }; diff --git a/hw/kdrive/fake/mouse.c b/hw/kdrive/fake/mouse.c index 714a45123..beb6ff524 100644 --- a/hw/kdrive/fake/mouse.c +++ b/hw/kdrive/fake/mouse.c @@ -35,19 +35,35 @@ #include "scrnintstr.h" #include "kdrive.h" -static Bool -MouseInit (void) +static Status +MouseInit (KdPointerInfo *pi) { - return TRUE; + return Success; +} + +static Status +MouseEnable (KdPointerInfo *pi) +{ + return Success; +} + +static void +MouseDisable (KdPointerInfo *pi) +{ + return; } static void -MouseFini (void) +MouseFini (KdPointerInfo *pi) { + return; } -KdMouseFuncs FakeMouseFuncs = { +KdPointerDriver FakePointerDriver = { + "fake", MouseInit, + MouseEnable, + MouseDisable, MouseFini, }; diff --git a/hw/kdrive/fbdev/Makefile.am b/hw/kdrive/fbdev/Makefile.am index fce6df9f4..39e9ba4c6 100644 --- a/hw/kdrive/fbdev/Makefile.am +++ b/hw/kdrive/fbdev/Makefile.am @@ -4,8 +4,6 @@ INCLUDES = \ noinst_LIBRARIES = libfbdev.a -bin_PROGRAMS = Xfbdev - if TSLIB TSLIB_FLAG = -lts endif @@ -14,6 +12,9 @@ libfbdev_a_SOURCES = \ fbdev.c \ fbdev.h +if KDRIVEFBDEV +bin_PROGRAMS = Xfbdev + Xfbdev_SOURCES = \ fbinit.c @@ -26,4 +27,4 @@ Xfbdev_LDADD = \ Xfbdev_DEPENDENCIES = \ libfbdev.a \ @KDRIVE_LIBS@ - +endif diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c index 86384f0a4..8ff32efcb 100644 --- a/hw/kdrive/fbdev/fbdev.c +++ b/hw/kdrive/fbdev/fbdev.c @@ -323,7 +323,7 @@ Bool fbdevMapFramebuffer (KdScreenInfo *screen) { FbdevScrPriv *scrpriv = screen->driver; - KdMouseMatrix m; + KdPointerMatrix m; FbdevPriv *priv = screen->card->driver; if (scrpriv->randr != RR_Rotate_0) @@ -331,9 +331,9 @@ fbdevMapFramebuffer (KdScreenInfo *screen) else scrpriv->shadow = FALSE; - KdComputeMouseMatrix (&m, scrpriv->randr, screen->width, screen->height); + KdComputePointerMatrix (&m, scrpriv->randr, screen->width, screen->height); - KdSetMouseMatrix (&m); + KdSetPointerMatrix (&m); screen->width = priv->var.xres; screen->height = priv->var.yres; diff --git a/hw/kdrive/fbdev/fbinit.c b/hw/kdrive/fbdev/fbinit.c index ba9d1c695..9d7c492d9 100644 --- a/hw/kdrive/fbdev/fbinit.c +++ b/hw/kdrive/fbdev/fbinit.c @@ -45,10 +45,18 @@ InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv) void InitInput (int argc, char **argv) { - KdInitInput (&LinuxMouseFuncs, &LinuxKeyboardFuncs); -#ifdef TOUCHSCREEN - KdAddMouseDriver (&TsFuncs); + KdKeyboardInfo *ki; + + KdAddKeyboardDriver (&LinuxKeyboardDriver); + KdAddPointerDriver (&LinuxMouseDriver); +#ifdef TSLIB + KdAddPointerDriver (&TsDriver); #endif + + ki = KdParseKeyboard ("keybd"); + KdAddKeyboard(ki); + + KdInitInput (); } void diff --git a/hw/kdrive/itsy/kbd.c b/hw/kdrive/itsy/kbd.c index 76062c5a8..beb4685d4 100644 --- a/hw/kdrive/itsy/kbd.c +++ b/hw/kdrive/itsy/kbd.c @@ -27,7 +27,6 @@ #include <kdrive-config.h> #endif #include "itsy.h" -#include "kkeymap.h" #include <X11/keysym.h> #include <linux/itsy_buttons.h> @@ -167,28 +166,44 @@ ItsyKeyboardLoad (void) { KeySym *k; - itsyButtonState = 0; - kdMinScanCode = 1; - kdKeymapWidth = ITSY_WIDTH; - kdMaxScanCode = (sizeof (ItsyKeymap) / sizeof (ItsyKeymap[0])) / ITSY_WIDTH; - memcpy (kdKeymap, ItsyKeymap, sizeof (ItsyKeymap)); } -int -ItsyKeyboardInit (void) +static Status +ItsyKeyboardInit (KdKeyboardInfo *ki) { - int butPort; + if (!ki) + return BadImplementation; + + ki->driverPrivate = open ("/dev/buttons", 0); - butPort = open ("/dev/buttons", 0); - fprintf (stderr, "butPort %d\n", butPort); - return butPort; + itsyButtonState = 0; + ki->keySyms.minKeyCode = 1; + ki->keySyms.maxKeyCode = (sizeof (ItsyKeymap) / sizeof (ItsyKeymap[0])) / ITSY_WIDTH; + ki->minScanCode = ki->keySyms.minKeyCode; + ki->maxScanCode = ki->keySyms.maxKeyCode; + ki->keySyms.mapWidth = ITSY_WIDTH; + + if (ki->keySyms.map) + xfree(ki->keySyms.map); + ki->keySyms.map = xalloc(sizeof(ItsyKeymap)); + if (!ki->keySyms.map) + return BadAlloc; + memcpy (kdKeymap, ItsyKeymap, sizeof (ItsyKeymap)); + + return Success; } -void -ItsyKeyboardFini (int fd) +static void +ItsyKeyboardDisable (KdKeybdInfo *ki) { if (fd >= 0) - close (fd); + close ((int)ki->driverPrivate); +} + +static void +ItsyKeyboardFini (KdKeybdInfo *ki) +{ + return; } void @@ -227,11 +242,13 @@ ItsyKeyboardBell (int volume, int frequency, int duration) } KdKeyboardFuncs itsyKeyboardFuncs = { - ItsyKeyboardLoad, + "itsy", ItsyKeyboardInit, + ItsyKeyboardEnable, ItsyKeyboardRead, ItsyKeyboardLeds, ItsyKeyboardBell, + ItsyKeyboardDisable ItsyKeyboardFini, - 0, + NULL, }; diff --git a/hw/kdrive/itsy/ts.c b/hw/kdrive/itsy/ts.c index c773c0e4f..180d1fd12 100644 --- a/hw/kdrive/itsy/ts.c +++ b/hw/kdrive/itsy/ts.c @@ -63,7 +63,7 @@ itsyTsReadBytes (int fd, char *buf, int len, int min) } void -itsyTsRead (int tsPort) +itsyTsRead (KdPointerInfo *pi, int tsPort) { ts_event event; long buf[3]; @@ -89,7 +89,7 @@ itsyTsRead (int tsPort) x = 0; y = 0; } - KdEnqueueMouseEvent (flags, x, y); + KdEnqueuePointerEvent (pi, flags, x, y, 0); } } @@ -204,7 +204,8 @@ itsyTsFini (int tsPort) close (tsPort); } -KdMouseFuncs itsyTsMouseFuncs = { +KdPointerDriver itsyTsMouseDriver = { + "itsyts", itsyTsInit, itsyTsRead, itsyTsFini diff --git a/hw/kdrive/linux/bus.c b/hw/kdrive/linux/bus.c index be61f891a..8cf5f901f 100644 --- a/hw/kdrive/linux/bus.c +++ b/hw/kdrive/linux/bus.c @@ -55,7 +55,7 @@ BusRead (int adbPort, void *closure) flags |= KD_BUTTON_2; if ((buf[0] & 1) == 0) flags |= KD_BUTTON_3; - KdEnqueueMouseEvent (kdMouseInfo, flags, dx, dy); + KdEnqueuePointerEvent (closure, flags, dx, dy, 0); } } @@ -66,36 +66,71 @@ char *BusNames[] = { #define NUM_BUS_NAMES (sizeof (BusNames) / sizeof (BusNames[0])) -int BusInputType; +static int +BusInit (KdPointerInfo *pi) +{ + int i, fd = 0; + + if (!pi->path || (strcmp(pi->path, "auto") == 0)) + { + for (i = 0; i < NUM_BUS_NAMES; i++) + { + if ((fd = open (BusNames[i], 0)) > 0) + { + close(fd); + if (pi->path) + xfree(pi->path); + pi->path = KdSaveString(BusNames[i]); + return Success; + } + } + } + else + { + if ((fd = open(pi->path, 0)) > 0) + { + close(fd); + return Success; + } + } + + return !Success; +} static int -BusInit (void) +BusEnable (KdPointerInfo *pi) { - int i; - int busPort; - int n = 0; + int fd = open(pi->path, 0); - if (!BusInputType) - BusInputType = KdAllocInputType (); - - for (i = 0; i < NUM_BUS_NAMES; i++) + if (fd > 0) + { + KdRegisterFd(fd, BusRead, pi); + pi->driverPrivate = (void *)fd; + return Success; + } + else { - busPort = open (BusNames[i], 0); - { - KdRegisterFd (BusInputType, busPort, BusRead, 0); - n++; - } + return !Success; } - return n; } static void -BusFini (void) +BusDisable (KdPointerInfo *pi) +{ + KdUnregisterFd(pi, (int)pi->driverPrivate, TRUE); +} + +static void +BusFini (KdPointerInfo *pi) { - KdUnregisterFds (BusInputType, TRUE); + return; } -KdMouseFuncs BusMouseFuncs = { +KdPointerDriver BusMouseDriver = { + "bus", BusInit, - BusFini + BusEnable, + BusDisable, + BusFini, + NULL }; diff --git a/hw/kdrive/linux/evdev.c b/hw/kdrive/linux/evdev.c index d83b13a6e..6c08cfa62 100644 --- a/hw/kdrive/linux/evdev.c +++ b/hw/kdrive/linux/evdev.c @@ -43,98 +43,100 @@ #define ISBITSET(x,y) ((x)[LONG(y)] & BIT(y)) #define OFF(x) ((x)%BITS_PER_LONG) #define LONG(x) ((x)/BITS_PER_LONG) -#define BIT(x) (1 << OFF(x)) +#define BIT(x) (1 << OFF(x)) #define SETBIT(x,y) ((x)[LONG(y)] |= BIT(y)) #define CLRBIT(x,y) ((x)[LONG(y)] &= ~BIT(y)) #define ASSIGNBIT(x,y,z) ((x)[LONG(y)] = ((x)[LONG(y)] & ~BIT(y)) | (z << OFF(y))) typedef struct _kevdevMouse { /* current device state */ - int rel[REL_MAX + 1]; - int abs[ABS_MAX + 1]; - int prevabs[ABS_MAX + 1]; - long key[NBITS(KEY_MAX + 1)]; + int rel[REL_MAX + 1]; + int abs[ABS_MAX + 1]; + int prevabs[ABS_MAX + 1]; + long key[NBITS(KEY_MAX + 1)]; /* supported device info */ - long relbits[NBITS(REL_MAX + 1)]; - long absbits[NBITS(ABS_MAX + 1)]; - long keybits[NBITS(KEY_MAX + 1)]; + long relbits[NBITS(REL_MAX + 1)]; + long absbits[NBITS(ABS_MAX + 1)]; + long keybits[NBITS(KEY_MAX + 1)]; struct input_absinfo absinfo[ABS_MAX + 1]; - int max_rel; - int max_abs; + int max_rel; + int max_abs; + + int fd; } Kevdev; static void -EvdevMotion (KdMouseInfo *mi) +EvdevMotion (KdPointerInfo *pi) { - Kevdev *ke = mi->driver; - int i; + Kevdev *ke = pi->driverPrivate; + int i; for (i = 0; i <= ke->max_rel; i++) - if (ke->rel[i]) - { - int a; - ErrorF ("rel"); - for (a = 0; a <= ke->max_rel; a++) - { - if (ISBITSET (ke->relbits, a)) - ErrorF (" %d=%d", a, ke->rel[a]); - ke->rel[a] = 0; - } - ErrorF ("\n"); - break; - } + if (ke->rel[i]) + { + int a; + ErrorF ("rel"); + for (a = 0; a <= ke->max_rel; a++) + { + if (ISBITSET (ke->relbits, a)) + ErrorF (" %d=%d", a, ke->rel[a]); + ke->rel[a] = 0; + } + ErrorF ("\n"); + break; + } for (i = 0; i < ke->max_abs; i++) - if (ke->abs[i] != ke->prevabs[i]) - { - int a; - ErrorF ("abs"); - for (a = 0; a <= ke->max_abs; a++) - { - if (ISBITSET (ke->absbits, a)) - ErrorF (" %d=%d", a, ke->abs[a]); - ke->prevabs[a] = ke->abs[a]; - } - ErrorF ("\n"); - break; - } + if (ke->abs[i] != ke->prevabs[i]) + { + int a; + ErrorF ("abs"); + for (a = 0; a <= ke->max_abs; a++) + { + if (ISBITSET (ke->absbits, a)) + ErrorF (" %d=%d", a, ke->abs[a]); + ke->prevabs[a] = ke->abs[a]; + } + ErrorF ("\n"); + break; + } } static void EvdevRead (int evdevPort, void *closure) { - KdMouseInfo *mi = closure; - Kevdev *ke = mi->driver; - int i; - struct input_event events[NUM_EVENTS]; - int n; + KdPointerInfo *pi = closure; + Kevdev *ke = pi->driverPrivate; + int i; + struct input_event events[NUM_EVENTS]; + int n; n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event)); if (n <= 0) - return; + return; n /= sizeof (struct input_event); for (i = 0; i < n; i++) { - switch (events[i].type) { - case EV_SYN: - break; - case EV_KEY: - EvdevMotion (mi); - ASSIGNBIT(ke->key,events[i].code, events[i].value); - if (events[i].code < 0x100) - ErrorF ("key %d %d\n", events[i].code, events[i].value); - else - ErrorF ("key 0x%x %d\n", events[i].code, events[i].value); - break; - case EV_REL: - ke->rel[events[i].code] += events[i].value; - break; - case EV_ABS: - ke->abs[events[i].code] = events[i].value; - break; - } + switch (events[i].type) { + case EV_SYN: + break; + case EV_KEY: + EvdevMotion (pi); + ASSIGNBIT(ke->key,events[i].code, events[i].value); + if (events[i].code < 0x100) + ErrorF ("key %d %d\n", events[i].code, events[i].value); + else + ErrorF ("key 0x%x %d\n", events[i].code, events[i].value); + break; + case EV_REL: + ke->rel[events[i].code] += events[i].value; + break; + case EV_ABS: + ke->abs[events[i].code] = events[i].value; + break; + } } - EvdevMotion (mi); + EvdevMotion (pi); } int EvdevInputType; @@ -148,143 +150,153 @@ char *kdefaultEvdev[] = { #define NUM_DEFAULT_EVDEV (sizeof (kdefaultEvdev) / sizeof (kdefaultEvdev[0])) -static Bool -EvdevInit (void) +static Status +EvdevInit (KdPointerInfo *pi) { - int i; - int fd; - KdMouseInfo *mi, *next; - int n = 0; - char *prot; + int i; + int fd; + int n = 0; + char *prot; + + if (!pi->path) { + for (i = 0; i < NUM_DEFAULT_EVDEV; i++) { + fd = open (kdefaultEvdev[i], 2); + if (fd >= 0) { + pi->path = KdSaveString (kdefaultEvdev[i]); + break; + } + } + } + else { + fd = open (pi->path, 2); + if (fd < 0) { + ErrorF("Failed to open evdev device %s\n", pi->path); + return BadMatch; + } + } + + return Success; +} - if (!EvdevInputType) - EvdevInputType = KdAllocInputType (); +static Status +EvdevEnable (KdPointerInfo *pi) +{ + int fd; - for (mi = kdMouseInfo; mi; mi = next) + if (!pi || !pi->path) + return BadImplementation; + + fd = open(pi->path, 2); + if (fd < 0) + return BadMatch; + + unsigned long ev[NBITS(EV_MAX)]; + Kevdev *ke; + + if (ioctl (fd, EVIOCGBIT(0 /*EV*/, sizeof (ev)), ev) < 0) + { + perror ("EVIOCGBIT 0"); + close (fd); + return BadMatch; + } + ke = xalloc (sizeof (Kevdev)); + if (!ke) + { + close (fd); + return BadAlloc; + } + memset (ke, '\0', sizeof (Kevdev)); + if (ISBITSET (ev, EV_KEY)) { - next = mi->next; - prot = mi->prot; - if (mi->inputType) - continue; - if (!mi->name) - { - for (i = 0; i < NUM_DEFAULT_EVDEV; i++) - { - fd = open (kdefaultEvdev[i], 2); - if (fd >= 0) - { - mi->name = KdSaveString (kdefaultEvdev[i]); - break; - } - } - } - else - fd = open (mi->name, 2); - - if (fd >= 0) - { - unsigned long ev[NBITS(EV_MAX)]; - Kevdev *ke; - - if (ioctl (fd, EVIOCGBIT(0 /*EV*/, sizeof (ev)), ev) < 0) - { - perror ("EVIOCGBIT 0"); - close (fd); - continue; - } - ke = xalloc (sizeof (Kevdev)); - if (!ke) - { - close (fd); - continue; - } - memset (ke, '\0', sizeof (Kevdev)); - if (ISBITSET (ev, EV_KEY)) - { - if (ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (ke->keybits)), - ke->keybits) < 0) - { - perror ("EVIOCGBIT EV_KEY"); - xfree (ke); - close (fd); - continue; - } - } - if (ISBITSET (ev, EV_REL)) - { - if (ioctl (fd, EVIOCGBIT (EV_REL, sizeof (ke->relbits)), - ke->relbits) < 0) - { - perror ("EVIOCGBIT EV_REL"); - xfree (ke); - close (fd); - continue; - } - for (ke->max_rel = REL_MAX; ke->max_rel >= 0; ke->max_rel--) - if (ISBITSET(ke->relbits, ke->max_rel)) - break; - } - if (ISBITSET (ev, EV_ABS)) - { - int i; + if (ioctl (fd, EVIOCGBIT (EV_KEY, sizeof (ke->keybits)), + ke->keybits) < 0) + { + perror ("EVIOCGBIT EV_KEY"); + xfree (ke); + close (fd); + return BadMatch; + } + } + if (ISBITSET (ev, EV_REL)) + { + if (ioctl (fd, EVIOCGBIT (EV_REL, sizeof (ke->relbits)), + ke->relbits) < 0) + { + perror ("EVIOCGBIT EV_REL"); + xfree (ke); + close (fd); + return BadMatch; + } + for (ke->max_rel = REL_MAX; ke->max_rel >= 0; ke->max_rel--) + if (ISBITSET(ke->relbits, ke->max_rel)) + break; + } + if (ISBITSET (ev, EV_ABS)) + { + int i; - if (ioctl (fd, EVIOCGBIT (EV_ABS, sizeof (ke->absbits)), - ke->absbits) < 0) - { - perror ("EVIOCGBIT EV_ABS"); - xfree (ke); - close (fd); - continue; - } - for (ke->max_abs = ABS_MAX; ke->max_abs >= 0; ke->max_abs--) - if (ISBITSET(ke->absbits, ke->max_abs)) - break; - for (i = 0; i <= ke->max_abs; i++) - { - if (ISBITSET (ke->absbits, i)) - if (ioctl (fd, EVIOCGABS(i), &ke->absinfo[i]) < 0) - { - perror ("EVIOCGABS"); - break; - } - ke->prevabs[i] = ABS_UNSET; - } - if (i <= ke->max_abs) - { - xfree (ke); - close (fd); - continue; - } - } - mi->driver = ke; - mi->inputType = EvdevInputType; - if (KdRegisterFd (EvdevInputType, fd, EvdevRead, (void *) mi)) - n++; - } + if (ioctl (fd, EVIOCGBIT (EV_ABS, sizeof (ke->absbits)), + ke->absbits) < 0) + { + perror ("EVIOCGBIT EV_ABS"); + xfree (ke); + close (fd); + return BadMatch; + } + for (ke->max_abs = ABS_MAX; ke->max_abs >= 0; ke->max_abs--) + if (ISBITSET(ke->absbits, ke->max_abs)) + break; + for (i = 0; i <= ke->max_abs; i++) + { + if (ISBITSET (ke->absbits, i)) + if (ioctl (fd, EVIOCGABS(i), &ke->absinfo[i]) < 0) + { + perror ("EVIOCGABS"); + break; + } + ke->prevabs[i] = ABS_UNSET; + } + if (i <= ke->max_abs) + { + xfree (ke); + close (fd); + return BadValue; + } + } + if (!KdRegisterFd (fd, EvdevRead, pi)) { + xfree (ke); + close (fd); + return BadAlloc; } - return TRUE; + pi->driverPrivate = ke; + return Success; } static void -EvdevFini (void) +EvdevDisable (KdPointerInfo *pi) { - KdMouseInfo *mi; + Kevdev *ke; - KdUnregisterFds (EvdevInputType, TRUE); - for (mi = kdMouseInfo; mi; mi = mi->next) - { - if (mi->inputType == EvdevInputType) - { - xfree (mi->driver); - mi->driver = 0; - mi->inputType = 0; - } - } + if (!pi || !pi->driverPrivate) + return; + + KdUnregisterFd (pi, ke->fd, TRUE); + xfree (ke); + pi->driverPrivate = 0; +} + +static void +EvdevFini (KdPointerInfo *pi) +{ } -KdMouseFuncs LinuxEvdevMouseFuncs = { +KdPointerDriver LinuxEvdevMouseDriver = { + "evdev", EvdevInit, + EvdevEnable, + EvdevDisable, EvdevFini, + NULL, }; #if 0 diff --git a/hw/kdrive/linux/keyboard.c b/hw/kdrive/linux/keyboard.c index cfafbb38f..9400e6b28 100644 --- a/hw/kdrive/linux/keyboard.c +++ b/hw/kdrive/linux/keyboard.c @@ -2,31 +2,40 @@ * $RCSId: xc/programs/Xserver/hw/kdrive/linux/keyboard.c,v 1.10 2001/11/08 10:26:24 keithp Exp $ * * Copyright © 1999 Keith Packard + * XKB integration © 2006 Nokia Corporation, author: Tomas Frydrych <tf@o-hand.com> * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. + * LinuxKeyboardRead() XKB code based on xf86KbdLnx.c: + * Copyright © 1990,91 by Thomas Roell, Dinkelscherben, Germany. + * Copyright © 1994-2001 by The XFree86 Project, Inc. * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) 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 copyright holder(s) and author(s). */ #ifdef HAVE_CONFIG_H #include <kdrive-config.h> #endif #include "kdrive.h" -#include "kkeymap.h" #include <linux/keyboard.h> #include <linux/kd.h> #define XK_PUBLISHING @@ -34,7 +43,7 @@ #include <termios.h> #include <sys/ioctl.h> -extern int LinuxConsoleFd; +extern int LinuxConsoleFd; static const KeySym linux_to_x[256] = { NoSymbol, NoSymbol, NoSymbol, NoSymbol, @@ -103,7 +112,108 @@ static const KeySym linux_to_x[256] = { XK_udiaeresis, XK_yacute, XK_thorn, XK_ydiaeresis }; -static unsigned char tbl[KD_MAX_WIDTH] = +#ifdef XKB +/* + * Getting a keycode from scancode + * + * With XKB + * -------- + * + * We have to enqueue keyboard events using standard X keycodes which correspond + * to AT scancode + 8; this means that we need to translate the Linux scancode + * provided by the kernel to an AT scancode -- this translation is not linear + * and requires that we use a LUT. + * + * + * Without XKB + * ----------- + * + * We can use custom keycodes, which makes things simpler; we define our custom + * keycodes as Linux scancodes + KD_KEY_OFFSET +*/ + +/* + This LUT translates AT scancodes into Linux ones -- the keymap we create + for the core X keyboard protocol has to be AT-scancode based so that it + corresponds to the Xkb keymap. +*/ +static unsigned char at2lnx[] = +{ + 0x0, /* no valid scancode */ + 0x01, /* KEY_Escape */ 0x02, /* KEY_1 */ + 0x03, /* KEY_2 */ 0x04, /* KEY_3 */ + 0x05, /* KEY_4 */ 0x06, /* KEY_5 */ + 0x07, /* KEY_6 */ 0x08, /* KEY_7 */ + 0x09, /* KEY_8 */ 0x0a, /* KEY_9 */ + 0x0b, /* KEY_0 */ 0x0c, /* KEY_Minus */ + 0x0d, /* KEY_Equal */ 0x0e, /* KEY_BackSpace */ + 0x0f, /* KEY_Tab */ 0x10, /* KEY_Q */ + 0x11, /* KEY_W */ 0x12, /* KEY_E */ + 0x13, /* KEY_R */ 0x14, /* KEY_T */ + 0x15, /* KEY_Y */ 0x16, /* KEY_U */ + 0x17, /* KEY_I */ 0x18, /* KEY_O */ + 0x19, /* KEY_P */ 0x1a, /* KEY_LBrace */ + 0x1b, /* KEY_RBrace */ 0x1c, /* KEY_Enter */ + 0x1d, /* KEY_LCtrl */ 0x1e, /* KEY_A */ + 0x1f, /* KEY_S */ 0x20, /* KEY_D */ + 0x21, /* KEY_F */ 0x22, /* KEY_G */ + 0x23, /* KEY_H */ 0x24, /* KEY_J */ + 0x25, /* KEY_K */ 0x26, /* KEY_L */ + 0x27, /* KEY_SemiColon */ 0x28, /* KEY_Quote */ + 0x29, /* KEY_Tilde */ 0x2a, /* KEY_ShiftL */ + 0x2b, /* KEY_BSlash */ 0x2c, /* KEY_Z */ + 0x2d, /* KEY_X */ 0x2e, /* KEY_C */ + 0x2f, /* KEY_V */ 0x30, /* KEY_B */ + 0x31, /* KEY_N */ 0x32, /* KEY_M */ + 0x33, /* KEY_Comma */ 0x34, /* KEY_Period */ + 0x35, /* KEY_Slash */ 0x36, /* KEY_ShiftR */ + 0x37, /* KEY_KP_Multiply */ 0x38, /* KEY_Alt */ + 0x39, /* KEY_Space */ 0x3a, /* KEY_CapsLock */ + 0x3b, /* KEY_F1 */ 0x3c, /* KEY_F2 */ + 0x3d, /* KEY_F3 */ 0x3e, /* KEY_F4 */ + 0x3f, /* KEY_F5 */ 0x40, /* KEY_F6 */ + 0x41, /* KEY_F7 */ 0x42, /* KEY_F8 */ + 0x43, /* KEY_F9 */ 0x44, /* KEY_F10 */ + 0x45, /* KEY_NumLock */ 0x46, /* KEY_ScrollLock */ + 0x47, /* KEY_KP_7 */ 0x48, /* KEY_KP_8 */ + 0x49, /* KEY_KP_9 */ 0x4a, /* KEY_KP_Minus */ + 0x4b, /* KEY_KP_4 */ 0x4c, /* KEY_KP_5 */ + 0x4d, /* KEY_KP_6 */ 0x4e, /* KEY_KP_Plus */ + 0x4f, /* KEY_KP_1 */ 0x50, /* KEY_KP_2 */ + 0x51, /* KEY_KP_3 */ 0x52, /* KEY_KP_0 */ + 0x53, /* KEY_KP_Decimal */ 0x54, /* KEY_SysReqest */ + 0x00, /* 0x55 */ 0x56, /* KEY_Less */ + 0x57, /* KEY_F11 */ 0x58, /* KEY_F12 */ + 0x66, /* KEY_Home */ 0x67, /* KEY_Up */ + 0x68, /* KEY_PgUp */ 0x69, /* KEY_Left */ + 0x5d, /* KEY_Begin */ 0x6a, /* KEY_Right */ + 0x6b, /* KEY_End */ 0x6c, /* KEY_Down */ + 0x6d, /* KEY_PgDown */ 0x6e, /* KEY_Insert */ + 0x6f, /* KEY_Delete */ 0x60, /* KEY_KP_Enter */ + 0x61, /* KEY_RCtrl */ 0x77, /* KEY_Pause */ + 0x63, /* KEY_Print */ 0x62, /* KEY_KP_Divide */ + 0x64, /* KEY_AltLang */ 0x65, /* KEY_Break */ + 0x00, /* KEY_LMeta */ 0x00, /* KEY_RMeta */ + 0x7A, /* KEY_Menu/FOCUS_PF11*/0x00, /* 0x6e */ + 0x7B, /* FOCUS_PF12 */ 0x00, /* 0x70 */ + 0x00, /* 0x71 */ 0x00, /* 0x72 */ + 0x59, /* FOCUS_PF2 */ 0x78, /* FOCUS_PF9 */ + 0x00, /* 0x75 */ 0x00, /* 0x76 */ + 0x5A, /* FOCUS_PF3 */ 0x5B, /* FOCUS_PF4 */ + 0x5C, /* FOCUS_PF5 */ 0x5D, /* FOCUS_PF6 */ + 0x5E, /* FOCUS_PF7 */ 0x5F, /* FOCUS_PF8 */ + 0x7C, /* JAP_86 */ 0x79, /* FOCUS_PF10 */ + 0x00, /* 0x7f */ +}; + +#define NUM_AT_KEYS (sizeof(at2lnx)/sizeof(at2lnx[0])) +#define LNX_KEY_INDEX(n) n < NUM_AT_KEYS ? at2lnx[n] : 0 + +#else /* not XKB */ +#define LNX_KEY_INDEX(n) n +#endif + +static unsigned char tbl[KD_MAX_WIDTH] = { 0, 1 << KG_SHIFT, @@ -112,24 +222,31 @@ static unsigned char tbl[KD_MAX_WIDTH] = }; static void -readKernelMapping(void) +readKernelMapping(KdKeyboardInfo *ki) { KeySym *k; int i, j; struct kbentry kbe; int minKeyCode, maxKeyCode; int row; + int fd; + + if (!ki) + return; + fd = LinuxConsoleFd; + minKeyCode = NR_KEYS; maxKeyCode = 0; row = 0; + ki->keySyms.mapWidth = KD_MAX_WIDTH; for (i = 0; i < NR_KEYS && row < KD_MAX_LENGTH; ++i) { - kbe.kb_index = i; + kbe.kb_index = LNX_KEY_INDEX(i); - k = kdKeymap + row * KD_MAX_WIDTH; + k = ki->keySyms.map + row * ki->keySyms.mapWidth; - for (j = 0; j < KD_MAX_WIDTH; ++j) + for (j = 0; j < ki->keySyms.mapWidth; ++j) { unsigned short kval; @@ -137,7 +254,7 @@ readKernelMapping(void) kbe.kb_table = tbl[j]; kbe.kb_value = 0; - if (ioctl(LinuxConsoleFd, KDGKBENT, &kbe)) + if (ioctl(fd, KDGKBENT, &kbe)) continue; kval = KVAL(kbe.kb_value); @@ -362,7 +479,7 @@ readKernelMapping(void) if (minKeyCode == NR_KEYS) continue; - + if (k[3] == k[2]) k[3] = NoSymbol; if (k[2] == k[1]) k[2] = NoSymbol; if (k[1] == k[0]) k[1] = NoSymbol; @@ -370,28 +487,212 @@ readKernelMapping(void) if (k[3] == k[0] && k[2] == k[1] && k[2] == NoSymbol) k[3] =NoSymbol; row++; } - kdMinScanCode = minKeyCode; - kdMaxScanCode = maxKeyCode; + ki->minScanCode = minKeyCode; + ki->maxScanCode = maxKeyCode; } -static void -LinuxKeyboardLoad (void) -{ - readKernelMapping (); -} +#ifdef XKB + +/* + * We need these to handle extended scancodes correctly (I could just use the + * numbers below, but this makes the code more readable + */ + +/* The prefix codes */ +#define KEY_Prefix0 /* special 0x60 */ 96 +#define KEY_Prefix1 /* special 0x61 */ 97 + +/* The raw scancodes */ +#define KEY_Enter /* Enter 0x1c */ 28 +#define KEY_LCtrl /* Ctrl(left) 0x1d */ 29 +#define KEY_Slash /* / (Slash) ? 0x35 */ 53 +#define KEY_KP_Multiply /* * 0x37 */ 55 +#define KEY_Alt /* Alt(left) 0x38 */ 56 +#define KEY_F3 /* F3 0x3d */ 61 +#define KEY_F4 /* F4 0x3e */ 62 +#define KEY_F5 /* F5 0x3f */ 63 +#define KEY_F6 /* F6 0x40 */ 64 +#define KEY_F7 /* F7 0x41 */ 65 +#define KEY_ScrollLock /* ScrollLock 0x46 */ 70 +#define KEY_KP_7 /* 7 Home 0x47 */ 71 +#define KEY_KP_8 /* 8 Up 0x48 */ 72 +#define KEY_KP_9 /* 9 PgUp 0x49 */ 73 +#define KEY_KP_Minus /* - (Minus) 0x4a */ 74 +#define KEY_KP_4 /* 4 Left 0x4b */ 75 +#define KEY_KP_5 /* 5 0x4c */ 76 +#define KEY_KP_6 /* 6 Right 0x4d */ 77 +#define KEY_KP_Plus /* + (Plus) 0x4e */ 78 +#define KEY_KP_1 /* 1 End 0x4f */ 79 +#define KEY_KP_2 /* 2 Down 0x50 */ 80 +#define KEY_KP_3 /* 3 PgDown 0x51 */ 81 +#define KEY_KP_0 /* 0 Insert 0x52 */ 82 +#define KEY_KP_Decimal /* . (Decimal) Delete 0x53 */ 83 +#define KEY_Home /* Home 0x59 */ 89 +#define KEY_Up /* Up 0x5a */ 90 +#define KEY_PgUp /* PgUp 0x5b */ 91 +#define KEY_Left /* Left 0x5c */ 92 +#define KEY_Begin /* Begin 0x5d */ 93 +#define KEY_Right /* Right 0x5e */ 94 +#define KEY_End /* End 0x5f */ 95 +#define KEY_Down /* Down 0x60 */ 96 +#define KEY_PgDown /* PgDown 0x61 */ 97 +#define KEY_Insert /* Insert 0x62 */ 98 +#define KEY_Delete /* Delete 0x63 */ 99 +#define KEY_KP_Enter /* Enter 0x64 */ 100 +#define KEY_RCtrl /* Ctrl(right) 0x65 */ 101 +#define KEY_Pause /* Pause 0x66 */ 102 +#define KEY_Print /* Print 0x67 */ 103 +#define KEY_KP_Divide /* Divide 0x68 */ 104 +#define KEY_AltLang /* AtlLang(right) 0x69 */ 105 +#define KEY_Break /* Break 0x6a */ 106 +#define KEY_LMeta /* Left Meta 0x6b */ 107 +#define KEY_RMeta /* Right Meta 0x6c */ 108 +#define KEY_Menu /* Menu 0x6d */ 109 +#define KEY_F13 /* F13 0x6e */ 110 +#define KEY_F14 /* F14 0x6f */ 111 +#define KEY_F15 /* F15 0x70 */ 112 +#define KEY_F16 /* F16 0x71 */ 113 +#define KEY_F17 /* F17 0x72 */ 114 +#define KEY_KP_DEC /* KP_DEC 0x73 */ 115 + +#endif /* XKB */ + static void LinuxKeyboardRead (int fd, void *closure) { unsigned char buf[256], *b; int n; + unsigned char prefix = 0, scancode = 0; - while ((n = read (fd, buf, sizeof (buf))) > 0) - { + while ((n = read (fd, buf, sizeof (buf))) > 0) { b = buf; - while (n--) - { - KdEnqueueKeyboardEvent (b[0] & 0x7f, b[0] & 0x80); + while (n--) { +#ifdef XKB + if (!noXkbExtension) { + /* + * With xkb we use RAW mode for reading the console, which allows us + * process extended scancodes. + * + * See if this is a prefix extending the following keycode + */ + if (!prefix && ((b[0] & 0x7f) == KEY_Prefix0)) + { + prefix = KEY_Prefix0; + ErrorF("Prefix0"); + /* swallow this up */ + b++; + continue; + } + else if (!prefix && ((b[0] & 0x7f) == KEY_Prefix1)) + { + prefix = KEY_Prefix1; + ErrorF("Prefix1"); + /* swallow this up */ + b++; + continue; + } + scancode = b[0] & 0x7f; + + switch (prefix) { + /* from xf86Events.c */ + case KEY_Prefix0: + { + ErrorF("Prefix0 scancode: 0x%02x\n", scancode); + switch (scancode) { + case KEY_KP_7: + scancode = KEY_Home; break; /* curs home */ + case KEY_KP_8: + scancode = KEY_Up; break; /* curs up */ + case KEY_KP_9: + scancode = KEY_PgUp; break; /* curs pgup */ + case KEY_KP_4: + scancode = KEY_Left; break; /* curs left */ + case KEY_KP_5: + scancode = KEY_Begin; break; /* curs begin */ + case KEY_KP_6: + scancode = KEY_Right; break; /* curs right */ + case KEY_KP_1: + scancode = KEY_End; break; /* curs end */ + case KEY_KP_2: + scancode = KEY_Down; break; /* curs down */ + case KEY_KP_3: + scancode = KEY_PgDown; break; /* curs pgdown */ + case KEY_KP_0: + scancode = KEY_Insert; break; /* curs insert */ + case KEY_KP_Decimal: + scancode = KEY_Delete; break; /* curs delete */ + case KEY_Enter: + scancode = KEY_KP_Enter; break; /* keypad enter */ + case KEY_LCtrl: + scancode = KEY_RCtrl; break; /* right ctrl */ + case KEY_KP_Multiply: + scancode = KEY_Print; break; /* print */ + case KEY_Slash: + scancode = KEY_KP_Divide; break; /* keyp divide */ + case KEY_Alt: + scancode = KEY_AltLang; break; /* right alt */ + case KEY_ScrollLock: + scancode = KEY_Break; break; /* curs break */ + case 0x5b: + scancode = KEY_LMeta; break; + case 0x5c: + scancode = KEY_RMeta; break; + case 0x5d: + scancode = KEY_Menu; break; + case KEY_F3: + scancode = KEY_F13; break; + case KEY_F4: + scancode = KEY_F14; break; + case KEY_F5: + scancode = KEY_F15; break; + case KEY_F6: + scancode = KEY_F16; break; + case KEY_F7: + scancode = KEY_F17; break; + case KEY_KP_Plus: + scancode = KEY_KP_DEC; break; + /* Ignore virtual shifts (E0 2A, E0 AA, E0 36, E0 B6) */ + case 0x2A: + case 0x36: + b++; + prefix = 0; + continue; + default: + ErrorF("Unreported Prefix0 scancode: 0x%02x\n", + scancode); + /* + * "Internet" keyboards are generating lots of new + * codes. Let them pass. There is little consistency + * between them, so don't bother with symbolic names at + * this level. + */ + scancode += 0x78; + } + break; + } + + case KEY_Prefix1: + { + /* we do no handle these */ + ErrorF("Prefix1 scancode: 0x%02x\n", scancode); + b++; + prefix = 0; + continue; + } + + default: /* should not happen*/ + case 0: /* do nothing */ + ErrorF("Plain scancode: 0x%02x\n", scancode); + } + + prefix = 0; + } + /* without xkb we use mediumraw mode -- enqueue the scancode as is */ + else +#endif + scancode = b[0] & 0x7f; + KdEnqueueKeyboardEvent (closure, scancode, b[0] & 0x80); b++; } } @@ -399,19 +700,30 @@ LinuxKeyboardRead (int fd, void *closure) static int LinuxKbdTrans; static struct termios LinuxTermios; -static int LinuxKbdType; -static int -LinuxKeyboardEnable (int fd, void *closure) +static Status +LinuxKeyboardEnable (KdKeyboardInfo *ki) { struct termios nTty; unsigned char buf[256]; int n; + int fd; + + if (!ki) + return !Success; + + fd = LinuxConsoleFd; + ki->driverPrivate = (void *) fd; ioctl (fd, KDGKBMODE, &LinuxKbdTrans); tcgetattr (fd, &LinuxTermios); - - ioctl(fd, KDSKBMODE, K_MEDIUMRAW); +#ifdef XKB + if (!noXkbExtension) + ioctl(fd, KDSKBMODE, K_RAW); + else +#else + ioctl(fd, KDSKBMODE, K_MEDIUMRAW); +#endif nTty = LinuxTermios; nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); nTty.c_oflag = 0; @@ -422,54 +734,74 @@ LinuxKeyboardEnable (int fd, void *closure) cfsetispeed(&nTty, 9600); cfsetospeed(&nTty, 9600); tcsetattr(fd, TCSANOW, &nTty); + /* Our kernel cleverly ignores O_NONBLOCK. Sigh. */ +#if 0 /* * Flush any pending keystrokes */ while ((n = read (fd, buf, sizeof (buf))) > 0) ; - return fd; +#endif + KdRegisterFd (fd, LinuxKeyboardRead, ki); + return Success; } static void -LinuxKeyboardDisable (int fd, void *closure) +LinuxKeyboardDisable (KdKeyboardInfo *ki) { - ioctl(LinuxConsoleFd, KDSKBMODE, LinuxKbdTrans); - tcsetattr(LinuxConsoleFd, TCSANOW, &LinuxTermios); + int fd; + + if (!ki) + return; + + fd = (int) ki->driverPrivate; + + KdUnregisterFd(ki, fd, FALSE); + ioctl(fd, KDSKBMODE, LinuxKbdTrans); + tcsetattr(fd, TCSANOW, &LinuxTermios); } -static int -LinuxKeyboardInit (void) +static Status +LinuxKeyboardInit (KdKeyboardInfo *ki) { - if (!LinuxKbdType) - LinuxKbdType = KdAllocInputType (); - - KdRegisterFd (LinuxKbdType, LinuxConsoleFd, LinuxKeyboardRead, 0); - LinuxKeyboardEnable (LinuxConsoleFd, 0); - KdRegisterFdEnableDisable (LinuxConsoleFd, - LinuxKeyboardEnable, - LinuxKeyboardDisable); - return 1; + if (!ki) + return !Success; + + if (ki->path) + xfree(ki->path); + ki->path = KdSaveString("console"); + if (ki->name) + xfree(ki->name); + ki->name = KdSaveString("Linux console keyboard"); + + readKernelMapping (ki); + + return Success; } static void -LinuxKeyboardFini (void) +LinuxKeyboardFini (KdKeyboardInfo *ki) { - LinuxKeyboardDisable (LinuxConsoleFd, 0); - KdUnregisterFds (LinuxKbdType, FALSE); } static void -LinuxKeyboardLeds (int leds) +LinuxKeyboardLeds (KdKeyboardInfo *ki, int leds) { - ioctl (LinuxConsoleFd, KDSETLED, leds & 7); + if (!ki) + return; + + ioctl ((int)ki->driverPrivate, KDSETLED, leds & 7); } static void -LinuxKeyboardBell (int volume, int pitch, int duration) +LinuxKeyboardBell (KdKeyboardInfo *ki, int volume, int pitch, int duration) { + if (!ki) + return; + if (volume && pitch) { - ioctl(LinuxConsoleFd, KDMKTONE, + ioctl((int)ki->driverPrivate, KDMKTONE, ((1193190 / pitch) & 0xffff) | (((unsigned long)duration * volume / 50) << 16)); @@ -477,11 +809,13 @@ LinuxKeyboardBell (int volume, int pitch, int duration) } } -KdKeyboardFuncs LinuxKeyboardFuncs = { - LinuxKeyboardLoad, +KdKeyboardDriver LinuxKeyboardDriver = { + "keyboard", LinuxKeyboardInit, + LinuxKeyboardEnable, LinuxKeyboardLeds, LinuxKeyboardBell, + LinuxKeyboardDisable, LinuxKeyboardFini, - 3, + NULL, }; diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c index be11ec539..e75f8d55b 100644 --- a/hw/kdrive/linux/linux.c +++ b/hw/kdrive/linux/linux.c @@ -456,6 +456,7 @@ LinuxFini (void) } } close(LinuxConsoleFd); /* make the vt-manager happy */ + LinuxConsoleFd = -1; fd = open ("/dev/tty0", O_RDWR|O_NDELAY, 0); if (fd >= 0) { diff --git a/hw/kdrive/linux/mouse.c b/hw/kdrive/linux/mouse.c index 5fe997864..77ec3b37b 100644 --- a/hw/kdrive/linux/mouse.c +++ b/hw/kdrive/linux/mouse.c @@ -206,10 +206,10 @@ MouseWriteBytes (int fd, unsigned char *c, int n, int timeout) typedef struct _kmouseProt { char *name; - Bool (*Complete) (KdMouseInfo *mi, unsigned char *ev, int ne); - int (*Valid) (KdMouseInfo *mi, unsigned char *ev, int ne); - Bool (*Parse) (KdMouseInfo *mi, unsigned char *ev, int ne); - Bool (*Init) (KdMouseInfo *mi); + Bool (*Complete) (KdPointerInfo *pi, unsigned char *ev, int ne); + int (*Valid) (KdPointerInfo *pi, unsigned char *ev, int ne); + Bool (*Parse) (KdPointerInfo *pi, unsigned char *ev, int ne); + Bool (*Init) (KdPointerInfo *pi); unsigned char headerMask, headerValid; unsigned char dataMask, dataValid; Bool tty; @@ -238,9 +238,9 @@ typedef struct _kmouse { unsigned long state; /* private per protocol, init to prot->state */ } Kmouse; -static int mouseValid (KdMouseInfo *mi, unsigned char *ev, int ne) +static int mouseValid (KdPointerInfo *pi, unsigned char *ev, int ne) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; const KmouseProt *prot = km->prot; int i; @@ -255,24 +255,24 @@ static int mouseValid (KdMouseInfo *mi, unsigned char *ev, int ne) return 0; } -static Bool threeComplete (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool threeComplete (KdPointerInfo *pi, unsigned char *ev, int ne) { return ne == 3; } -static Bool fourComplete (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool fourComplete (KdPointerInfo *pi, unsigned char *ev, int ne) { return ne == 4; } -static Bool fiveComplete (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool fiveComplete (KdPointerInfo *pi, unsigned char *ev, int ne) { return ne == 5; } -static Bool MouseReasonable (KdMouseInfo *mi, unsigned long flags, int dx, int dy) +static Bool MouseReasonable (KdPointerInfo *pi, unsigned long flags, int dx, int dy) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; if (km->stage == MouseWorking) return TRUE; @@ -296,9 +296,9 @@ static Bool MouseReasonable (KdMouseInfo *mi, unsigned long flags, int dx, int d /* * Standard PS/2 mouse protocol */ -static Bool ps2Parse (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool ps2Parse (KdPointerInfo *pi, unsigned char *ev, int ne) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; int dx, dy, dz; unsigned long flags; unsigned long flagsrelease = 0; @@ -333,21 +333,21 @@ static Bool ps2Parse (KdMouseInfo *mi, unsigned char *ev, int ne) if (ev[0] & 0x20) dy -= 256; dy = -dy; - if (!MouseReasonable (mi, flags, dx, dy)) + if (!MouseReasonable (pi, flags, dx, dy)) return FALSE; if (km->stage == MouseWorking) { - KdEnqueueMouseEvent (mi, flags, dx, dy); + KdEnqueuePointerEvent (pi, flags, dx, dy, 0); if (flagsrelease) { flags &= ~flagsrelease; - KdEnqueueMouseEvent (mi, flags, dx, dy); + KdEnqueuePointerEvent (pi, flags, dx, dy, 0); } } return TRUE; } -static Bool ps2Init (KdMouseInfo *mi); +static Bool ps2Init (KdPointerInfo *pi); static const KmouseProt ps2Prot = { "ps/2", @@ -450,9 +450,9 @@ static unsigned char intelli_init[] = { #define NINIT_INTELLI 3 static int -ps2SkipInit (KdMouseInfo *mi, int ninit, Bool ret_next) +ps2SkipInit (KdPointerInfo *pi, int ninit, Bool ret_next) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; int c = -1; int skipping; Bool waiting; @@ -481,9 +481,9 @@ ps2SkipInit (KdMouseInfo *mi, int ninit, Bool ret_next) } static Bool -ps2Init (KdMouseInfo *mi) +ps2Init (KdPointerInfo *pi) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; int skipping; Bool waiting; int id; @@ -499,7 +499,7 @@ ps2Init (KdMouseInfo *mi) return FALSE; skipping = 0; waiting = FALSE; - id = ps2SkipInit (mi, 0, TRUE); + id = ps2SkipInit (pi, 0, TRUE); switch (id) { case 3: init = wheel_3button_init; @@ -524,13 +524,13 @@ ps2Init (KdMouseInfo *mi) * initialization string. Make sure any partial event is * skipped */ - (void) ps2SkipInit (mi, ninit, FALSE); + (void) ps2SkipInit (pi, ninit, FALSE); return TRUE; } -static Bool busParse (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool busParse (KdPointerInfo *pi, unsigned char *ev, int ne) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; int dx, dy; unsigned long flags; @@ -543,10 +543,10 @@ static Bool busParse (KdMouseInfo *mi, unsigned char *ev, int ne) flags |= KD_BUTTON_2; if ((ev[0] & 1) == 0) flags |= KD_BUTTON_3; - if (!MouseReasonable (mi, flags, dx, dy)) + if (!MouseReasonable (pi, flags, dx, dy)) return FALSE; if (km->stage == MouseWorking) - KdEnqueueMouseEvent (mi, flags, dx, dy); + KdEnqueuePointerEvent (pi, flags, dx, dy, 0); return TRUE; } @@ -561,9 +561,9 @@ static const KmouseProt busProt = { * Standard MS serial protocol, three bytes */ -static Bool msParse (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool msParse (KdPointerInfo *pi, unsigned char *ev, int ne) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; int dx, dy; unsigned long flags; @@ -576,10 +576,10 @@ static Bool msParse (KdMouseInfo *mi, unsigned char *ev, int ne) dx = (signed char)(((ev[0] & 0x03) << 6) | (ev[1] & 0x3F)); dy = (signed char)(((ev[0] & 0x0C) << 4) | (ev[2] & 0x3F)); - if (!MouseReasonable (mi, flags, dx, dy)) + if (!MouseReasonable (pi, flags, dx, dy)) return FALSE; if (km->stage == MouseWorking) - KdEnqueueMouseEvent (mi, flags, dx, dy); + KdEnqueuePointerEvent (pi, flags, dx, dy, 0); return TRUE; } @@ -600,9 +600,9 @@ static const KmouseProt msProt = { * first byte of a synchronized protocol stream and see if it's got * any bits turned on that can't occur in that fourth byte */ -static Bool logiComplete (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool logiComplete (KdPointerInfo *pi, unsigned char *ev, int ne) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; if ((ev[0] & 0x40) == 0x40) return ne == 3; @@ -611,9 +611,9 @@ static Bool logiComplete (KdMouseInfo *mi, unsigned char *ev, int ne) return FALSE; } -static int logiValid (KdMouseInfo *mi, unsigned char *ev, int ne) +static int logiValid (KdPointerInfo *pi, unsigned char *ev, int ne) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; const KmouseProt *prot = km->prot; int i; @@ -632,9 +632,9 @@ static int logiValid (KdMouseInfo *mi, unsigned char *ev, int ne) return 0; } -static Bool logiParse (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool logiParse (KdPointerInfo *pi, unsigned char *ev, int ne) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; int dx, dy; unsigned long flags; @@ -660,10 +660,10 @@ static Bool logiParse (KdMouseInfo *mi, unsigned char *ev, int ne) flags |= km->state & (KD_BUTTON_1|KD_BUTTON_3); } - if (!MouseReasonable (mi, flags, dx, dy)) + if (!MouseReasonable (pi, flags, dx, dy)) return FALSE; if (km->stage == MouseWorking) - KdEnqueueMouseEvent (mi, flags, dx, dy); + KdEnqueuePointerEvent (pi, flags, dx, dy, 0); return TRUE; } @@ -682,9 +682,9 @@ static const KmouseProt logiProt = { /* * Mouse systems protocol, 5 bytes */ -static Bool mscParse (KdMouseInfo *mi, unsigned char *ev, int ne) +static Bool mscParse (KdPointerInfo *pi, unsigned char *ev, int ne) { - Kmouse *km = mi->driver; + Kmouse *km = pi->driverPrivate; int dx, dy; unsigned long flags; @@ -699,10 +699,10 @@ static Bool mscParse (KdMouseInfo *mi, unsigned char *ev, int ne) dx = (signed char)(ev[1]) + (signed char)(ev[3]); dy = - ((signed char)(ev[2]) + (signed char)(ev[4])); - if (!MouseReasonable (mi, flags, dx, dy)) + if (!MouseReasonable (pi, flags, dx, dy)) return FALSE; if (km->stage == MouseWorking) - KdEnqueueMouseEvent (mi, flags, dx, dy); + KdEnqueuePointerEvent (pi, flags, dx, dy, 0); return TRUE; } @@ -810,8 +810,8 @@ MouseNextProtocol (Kmouse *km) static void MouseRead (int mousePort, void *closure) { - KdMouseInfo *mi = closure; - Kmouse *km = mi->driver; + KdPointerInfo *pi = closure; + Kmouse *km = pi->driverPrivate; unsigned char event[MAX_MOUSE]; int ne; int c; @@ -835,7 +835,7 @@ MouseRead (int mousePort, void *closure) break; } event[ne++] = c; - i = (*km->prot->Valid) (mi, event, ne); + i = (*km->prot->Valid) (pi, event, ne); if (i != 0) { #ifdef DEBUG @@ -867,9 +867,9 @@ MouseRead (int mousePort, void *closure) } else { - if ((*km->prot->Complete) (mi, event, ne)) + if ((*km->prot->Complete) (pi, event, ne)) { - if ((*km->prot->Parse) (mi, event, ne)) + if ((*km->prot->Parse) (pi, event, ne)) { switch (km->stage) { @@ -896,7 +896,7 @@ MouseRead (int mousePort, void *closure) km->invalid = 0; km->tested = 0; km->valid = 0; - if (km->prot->Init && !(*km->prot->Init) (mi)) + if (km->prot->Init && !(*km->prot->Init) (pi)) km->stage = MouseBroken; } break; @@ -923,9 +923,9 @@ MouseRead (int mousePort, void *closure) int MouseInputType; char *kdefaultMouse[] = { + "/dev/input/mice", "/dev/mouse", "/dev/psaux", - "/dev/input/mice", "/dev/adbmouse", "/dev/ttyS0", "/dev/ttyS1", @@ -933,81 +933,97 @@ char *kdefaultMouse[] = { #define NUM_DEFAULT_MOUSE (sizeof (kdefaultMouse) / sizeof (kdefaultMouse[0])) -static Bool -MouseInit (void) +static Status +MouseInit (KdPointerInfo *pi) { int i; int fd; Kmouse *km; - KdMouseInfo *mi, *next; - int n = 0; - char *prot; - if (!MouseInputType) - MouseInputType = KdAllocInputType (); - - for (mi = kdMouseInfo; mi; mi = next) - { - next = mi->next; - prot = mi->prot; - if (mi->inputType) - continue; - if (!mi->name) - { - for (i = 0; i < NUM_DEFAULT_MOUSE; i++) - { - fd = open (kdefaultMouse[i], 2); - if (fd >= 0) - { - mi->name = KdSaveString (kdefaultMouse[i]); - break; - } - } - } - else - fd = open (mi->name, 2); + if (!pi) + return BadImplementation; + + if (!pi->path || strcmp(pi->path, "auto") == 0) { + for (i = 0; i < NUM_DEFAULT_MOUSE; i++) { + fd = open (kdefaultMouse[i], 2); + if (fd >= 0) { + pi->path = KdSaveString (kdefaultMouse[i]); + break; + } + } + } + else { + fd = open (pi->path, 2); + } - if (fd >= 0) - { - km = (Kmouse *) xalloc (sizeof (Kmouse)); - if (km) - { - km->iob.fd = fd; - km->iob.avail = km->iob.used = 0; - km->prot = 0; - km->i_prot = 0; - km->tty = isatty (fd); - mi->driver = km; - mi->inputType = MouseInputType; - MouseFirstProtocol (km, mi->prot); - if (KdRegisterFd (MouseInputType, fd, MouseRead, (void *) mi)) - n++; - } - else - close (fd); - } + if (fd < 0) + return BadMatch; + + close(fd); + + km = (Kmouse *) xalloc (sizeof (Kmouse)); + if (km) { + km->iob.avail = km->iob.used = 0; + MouseFirstProtocol(km, "exps/2"); + km->i_prot = 0; + km->tty = isatty (fd); + km->iob.fd = -1; + pi->driverPrivate = km; } - return TRUE; + else { + close (fd); + return BadAlloc; + } + + return Success; } -static void -MouseFini (void) +static Status +MouseEnable (KdPointerInfo *pi) { - KdMouseInfo *mi; + Kmouse *km; + + if (!pi || !pi->driverPrivate || !pi->path) + return BadImplementation; - KdUnregisterFds (MouseInputType, TRUE); - for (mi = kdMouseInfo; mi; mi = mi->next) + km = pi->driverPrivate; + + km->iob.fd = open(pi->path, 2); + if (km->iob.fd < 0) + return BadMatch; + + if (!KdRegisterFd (km->iob.fd, MouseRead, pi)) { - if (mi->inputType == MouseInputType) - { - xfree (mi->driver); - mi->driver = 0; - mi->inputType = 0; - } + close(km->iob.fd); + return BadAlloc; } + + return Success; +} + +static void +MouseDisable (KdPointerInfo *pi) +{ + Kmouse *km; + if (!pi || !pi->driverPrivate) + return; + + km = pi->driverPrivate; + KdUnregisterFd (pi, km->iob.fd, TRUE); +} + +static void +MouseFini (KdPointerInfo *pi) +{ + xfree (pi->driverPrivate); + pi->driverPrivate = NULL; } -KdMouseFuncs LinuxMouseFuncs = { +KdPointerDriver LinuxMouseDriver = { + "mouse", MouseInit, + MouseEnable, + MouseDisable, MouseFini, + NULL, }; diff --git a/hw/kdrive/linux/ms.c b/hw/kdrive/linux/ms.c index 7f046bdc3..e62cebc39 100644 --- a/hw/kdrive/linux/ms.c +++ b/hw/kdrive/linux/ms.c @@ -90,41 +90,50 @@ MsRead (int port, void *closure) dy = (char)(((b[0] & 0x0C) << 4) | (b[2] & 0x3F)); n -= 3; b += 3; - KdEnqueueMouseEvent (kdMouseInfo, flags, dx, dy); + KdEnqueuePointerEvent (closure, flags, dx, dy, 0); } } } -int MsInputType; +static Status +MsInit (KdPointerInfo *pi) +{ + if (!pi) + return BadImplementation; + + if (!pi->path || strcmp(pi->path, "auto")) + pi->path = KdSaveString("/dev/mouse"); + if (!pi->name) + pi->name = KdSaveString("Microsoft protocol mouse"); + + return Success; +} -static int -MsInit (void) +static Status +MsEnable (KdPointerInfo *pi) { int port; - char *device = "/dev/mouse"; struct termios t; int ret; - if (!MsInputType) - MsInputType = KdAllocInputType (); - port = open (device, O_RDWR | O_NONBLOCK); + port = open (pi->path, O_RDWR | O_NONBLOCK); if(port < 0) { - ErrorF("Couldn't open %s (%d)\n", device, (int)errno); + ErrorF("Couldn't open %s (%d)\n", pi->path, (int)errno); return 0; } else if (port == 0) { ErrorF("Opening %s returned 0! Please complain to Keith.\n", - device); + pi->path); goto bail; } if(!isatty(port)) { - ErrorF("%s is not a tty\n", device); + ErrorF("%s is not a tty\n", pi->path); goto bail; } ret = tcgetattr(port, &t); if(ret < 0) { - ErrorF("Couldn't tcgetattr(%s): %d\n", device, errno); + ErrorF("Couldn't tcgetattr(%s): %d\n", pi->path, errno); goto bail; } t.c_iflag &= ~ (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | @@ -140,24 +149,36 @@ MsInit (void) t.c_cc[VTIME] = 0; ret = tcsetattr(port, TCSANOW, &t); if(ret < 0) { - ErrorF("Couldn't tcsetattr(%s): %d\n", device, errno); + ErrorF("Couldn't tcsetattr(%s): %d\n", pi->path, errno); goto bail; } - if (KdRegisterFd (MsInputType, port, MsRead, (void *) 0)) - return 1; + if (KdRegisterFd (port, MsRead, pi)) + return TRUE; + pi->driverPrivate = (void *)port; + + return Success; bail: close(port); - return 0; + return BadMatch; +} + +static void +MsDisable (KdPointerInfo *pi) +{ + KdUnregisterFd (pi, (int)pi->driverPrivate, TRUE); } static void -MsFini (void) +MsFini (KdPointerInfo *pi) { - KdUnregisterFds (MsInputType, TRUE); } -KdMouseFuncs MsMouseFuncs = { +KdPointerDriver MsMouseDriver = { + "ms", MsInit, - MsFini + MsEnable, + MsDisable, + MsFini, + NULL, }; diff --git a/hw/kdrive/linux/ps2.c b/hw/kdrive/linux/ps2.c index b59dbfac7..5d523a210 100644 --- a/hw/kdrive/linux/ps2.c +++ b/hw/kdrive/linux/ps2.c @@ -112,42 +112,78 @@ Ps2Read (int ps2Port, void *closure) dy = -dy; n -= 3; b += 3; - KdEnqueueMouseEvent (kdMouseInfo, flags, dx, dy); + KdEnqueuePointerEvent (closure, flags, dx, dy, 0); } } } -int Ps2InputType; - -static int -Ps2Init (void) +static Status +Ps2Init (KdPointerInfo *pi) { - int i; - int ps2Port; - int n; - - if (!Ps2InputType) - Ps2InputType = KdAllocInputType (); - n = 0; - for (i = 0; i < NUM_PS2_NAMES; i++) - { - ps2Port = open (Ps2Names[i], 0); - if (ps2Port >= 0) - { - if (KdRegisterFd (Ps2InputType, ps2Port, Ps2Read, (void *) i)) - n++; + int ps2Port, i; + + if (!pi->path) { + for (i = 0; i < NUM_PS2_NAMES; i++) { + ps2Port = open (Ps2Names[i], 0); + if (ps2Port >= 0) { + pi->path = KdSaveString (Ps2Names[i]); + break; + } } } - return n; + else { + ps2Port = open (pi->path, 0); + } + + if (ps2Port < 0) + return BadMatch; + + close(ps2Port); + if (!pi->name) + pi->name = KdSaveString ("PS/2 Mouse"); + + return Success; +} + +static Status +Ps2Enable (KdPointerInfo *pi) +{ + int fd; + + if (!pi) + return BadImplementation; + + fd = open (pi->path, 0); + if (fd < 0) + return BadMatch; + + if (!KdRegisterFd (fd, Ps2Read, pi)) { + close(fd); + return BadAlloc; + } + + pi->driverPrivate = (void *)fd; + + return Success; +} + + +static void +Ps2Disable (KdPointerInfo *pi) +{ + KdUnregisterFd (pi, (int)pi->driverPrivate, TRUE); } static void -Ps2Fini (void) +Ps2Fini (KdPointerInfo *pi) { - KdUnregisterFds (Ps2InputType, TRUE); } -KdMouseFuncs Ps2MouseFuncs = { +KdPointerDriver Ps2MouseDriver = { + "ps2", Ps2Init, - Ps2Fini + Ps2Enable, + Ps2Disable, + Ps2Fini, + NULL, }; diff --git a/hw/kdrive/linux/ts.c b/hw/kdrive/linux/ts.c index 70c736117..701fdc891 100644 --- a/hw/kdrive/linux/ts.c +++ b/hw/kdrive/linux/ts.c @@ -75,7 +75,7 @@ TsReadBytes (int fd, char *buf, int len, int min) static void TsRead (int tsPort, void *closure) { - KdMouseInfo *mi = closure; + KdPointerInfo *pi = closure; TS_EVENT event; int n; long x, y; @@ -117,7 +117,7 @@ TsRead (int tsPort, void *closure) lastx = 0; lasty = 0; } - KdEnqueueMouseEvent (mi, flags, x, y); + KdEnqueuePointerEvent (pi, flags, x, y, 0); } } @@ -129,95 +129,83 @@ char *TsNames[] = { #define NUM_TS_NAMES (sizeof (TsNames) / sizeof (TsNames[0])) -int TsInputType; - -static int -TsEnable (int fd, void *closure) -{ - KdMouseInfo *mi = (KdMouseInfo *)closure; - - return open (mi->name, 0); -} - -static void -TsDisable (int fd, void *closure) -{ - close (fd); -} - -static int -TsInit (void) +static Status +TsInit (KdPointerInfo *pi) { int i; int fd; - KdMouseInfo *mi, *next; int n = 0; - if (!TsInputType) - TsInputType = KdAllocInputType (); - - for (mi = kdMouseInfo; mi; mi = next) - { - next = mi->next; - if (mi->inputType) - continue; - if (!mi->name) - { - for (i = 0; i < NUM_TS_NAMES; i++) - { - fd = open (TsNames[i], 0); - if (fd >= 0) - { - mi->name = KdSaveString (TsNames[i]); - break; - } - } - } - else - fd = open (mi->name, 0); - if (fd >= 0) - { - struct h3600_ts_calibration cal; - /* - * Check to see if this is a touch screen - */ - if (ioctl (fd, TS_GET_CAL, &cal) != -1) - { - mi->driver = (void *) fd; - mi->inputType = TsInputType; - if (KdRegisterFd (TsInputType, fd, TsRead, (void *) mi)) - { - /* Set callbacks for vt switches etc */ - KdRegisterFdEnableDisable (fd, TsEnable, TsDisable); - - n++; - } - } - else - close (fd); + if (!pi->path || strcmp(pi->path, "auto") == 0) { + for (i = 0; i < NUM_TS_NAMES; i++) { + fd = open (TsNames[i], 0); + if (fd >= 0) { + pi->path = KdSaveString (TsNames[i]); + break; + } } } + else { + fd = open (pi->path, 0); + } + + if (fd < 0) { + ErrorF("TsInit: Couldn't open %s\n", pi->path); + return BadMatch; + } + close(fd); + + pi->name = KdSaveString("H3600 Touchscreen"); - return 0; + return Success; } -static void -TsFini (void) +static Status +TsEnable (KdPointerInfo *pi) { - KdMouseInfo *mi; + int fd; - KdUnregisterFds (TsInputType, TRUE); - for (mi = kdMouseInfo; mi; mi = mi->next) - { - if (mi->inputType == TsInputType) - { - mi->driver = 0; - mi->inputType = 0; + if (!pi || !pi->path) + return BadImplementation; + + fd = open(pi->path, 0); + + if (fd < 0) { + ErrorF("TsInit: Couldn't open %s\n", pi->path); + return BadMatch; + } + + struct h3600_ts_calibration cal; + /* + * Check to see if this is a touch screen + */ + if (ioctl (fd, TS_GET_CAL, &cal) != -1) { + mi->driverPrivate = (void *) fd; + if (!KdRegisterFd (fd, TsRead, (void *) mi)) { + close(fd); + return BadAlloc; } } + else { + ErrorF("TsEnable: %s is not a touchscreen\n", pi->path); + close (fd); + return BadMatch; + } + + return Success; +} + +static void +TsFini (KdPointerInfo *pi) +{ + KdUnregisterFds (pi, (int)pi->driverPrivate, TRUE); + mi->driverPrivate = NULL; } -KdMouseFuncs TsFuncs = { +KdPointerDriver TsDriver = { TsInit, - TsFini + TsEnable, + TsDisable, + TsFini, + NULL, }; diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c index c4caff922..aa57e87bb 100644 --- a/hw/kdrive/linux/tslib.c +++ b/hw/kdrive/linux/tslib.c @@ -1,73 +1,39 @@ /* - * $RCSId: xc/programs/Xserver/hw/kdrive/linux/tslib.c,v 1.1 2002/11/01 22:27:49 keithp Exp $ - * TSLIB based touchscreen driver for TinyX + * TSLIB based touchscreen driver for KDrive + * Porting to new input API and event queueing by Daniel Stone. * Derived from ts.c by Keith Packard * Derived from ps2.c by Jim Gettys * * Copyright © 1999 Keith Packard * Copyright © 2000 Compaq Computer Corporation * Copyright © 2002 MontaVista Software Inc. - * Copyright © 2005 OpenedHand Ltd. + * Copyright © 2006 Nokia Corporation * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard or Compaq not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard and Compaq makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. + * documentation, and that the name of the authors and/or copyright holders + * not be used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. The authors and/or + * copyright holders make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. * - * KEITH PACKARD AND COMPAQ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, - * IN NO EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Michael Taht or MontaVista not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Michael Taht and Montavista make no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * MICHAEL TAHT AND MONTAVISTA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, - * IN NO EVENT SHALL EITHER BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Matthew Allum or OpenedHand not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Matthew Allum and OpenedHand make no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * MATTHEW ALLUM AND OPENEDHAND DISCLAIM ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, - * IN NO EVENT SHALL EITHER BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * THE AUTHORS AND/OR COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS AND/OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H +#ifdef HAVE_KDRIVE_CONFIG_H #include <kdrive-config.h> #endif + #define NEED_EVENTS #include <X11/X.h> #include <X11/Xproto.h> @@ -77,186 +43,171 @@ #include "kdrive.h" #include <sys/ioctl.h> #include <tslib.h> - -static struct tsdev *tsDev = NULL; - -static char *TsNames[] = { - NULL, /* set via TSLIB_TSDEVICE */ - "/dev/ts", - "/dev/touchscreen/0", +#include <dirent.h> +#include <linux/input.h> + +struct TslibPrivate { + int fd; + int lastx, lasty; + struct tsdev *tsDev; + void (*raw_event_hook)(int x, int y, int pressure, void *closure); + void *raw_event_closure; + int phys_screen; }; -#define NUM_TS_NAMES (sizeof (TsNames) / sizeof (TsNames[0])) - -/* For XCalibrate extension */ -void (*tslib_raw_event_hook)(int x, int y, int pressure, void *closure); -void *tslib_raw_event_closure; - -int TsInputType = 0; -int KdTsPhyScreen = 0; /* XXX Togo .. */ static void -TsRead (int tsPort, void *closure) +TsRead (int fd, void *closure) { - KdMouseInfo *mi = closure; - struct ts_sample event; - long x, y; - unsigned long flags; - - if (tslib_raw_event_hook) - { - /* XCalibrate Ext */ - if (ts_read_raw(tsDev, &event, 1) == 1) - { - tslib_raw_event_hook (event.x, - event.y, - event.pressure, - tslib_raw_event_closure); - } - return; - } + KdPointerInfo *pi = closure; + struct TslibPrivate *private = pi->driverPrivate; + struct ts_sample event; + long x = 0, y = 0; + unsigned long flags; + + if (private->raw_event_hook) { + while (ts_read_raw(private->tsDev, &event, 1) == 1) + private->raw_event_hook (event.x, event.y, event.pressure, + private->raw_event_closure); + return; + } - while (ts_read(tsDev, &event, 1) == 1) - { - flags = (event.pressure) ? KD_BUTTON_1 : 0; - x = event.x; - y = event.y; - - KdEnqueueMouseEvent (mi, flags, x, y); - } + while (ts_read(private->tsDev, &event, 1) == 1) { +#ifdef DEBUG + ErrorF("[tslib] originally from (%d, %d)\n", event.x, event.y); +#endif + if (event.pressure) { + if (event.pressure > pi->dixdev->touchscreen->button_threshold) + flags = KD_BUTTON_8; + else + flags = KD_BUTTON_1; + + /* + * Here we test for the touch screen driver actually being on the + * touch screen, if it is we send absolute coordinates. If not, + * then we send delta's so that we can track the entire vga screen. + */ + if (KdCurScreen == private->phys_screen) { + x = event.x; + y = event.y; + } else { + flags |= KD_MOUSE_DELTA; + if ((private->lastx == 0) || (private->lasty == 0)) { + x = event.x; + y = event.y; + } else { + x = event.x - private->lastx; + y = event.y - private->lasty; + } + } + private->lastx = x; + private->lasty = y; + } else { + flags = 0; + x = private->lastx; + y = private->lasty; + } + +#ifdef DEBUG + ErrorF("event at (%lu, %lu), pressure is %d, sending flags %lu\n", x, y, event.pressure, flags); +#endif + KdEnqueuePointerEvent (pi, flags, x, y, event.pressure); + } } -static int -TsLibOpen(char *dev) +static Status +TslibEnable (KdPointerInfo *pi) { - if(!(tsDev = ts_open(dev, 0))) - return -1; + struct TslibPrivate *private = pi->driverPrivate; + + private->holdThumbEvents = 1; + private->raw_event_hook = NULL; + private->raw_event_closure = NULL; + private->tsDev = ts_open(pi->path, 0); + private->fd = ts_fd(private->tsDev); + if (!private->tsDev || ts_config(private->tsDev) || private->fd < 0) { + ErrorF("[tslib/TslibEnable] failed to open %s\n", pi->path); + if (private->fd > 0); + close(private->fd); + return BadAlloc; + } + if (pi->dixdev && pi->dixdev->touchscreen && + pi->dixdev->touchscreen->button_threshold == 0) + pi->dixdev->touchscreen->button_threshold = 115; - if (ts_config(tsDev)) - return -1; +#ifdef DEBUG + ErrorF("[tslib/TslibEnable] successfully enabled %s\n", pi->path); +#endif - return ts_fd(tsDev); + KdRegisterFd(private->fd, TsRead, pi); + + return Success; } -static int -TslibEnable (int not_needed_fd, void *closure) -{ - KdMouseInfo *mi = closure; - int fd = 0; - - if ((fd = TsLibOpen(mi->name)) == -1) - ErrorF ("Unable to re-enable TSLib ( on %s )", mi->name); - - return fd; -} static void -TslibDisable (int fd, void *closure) +TslibDisable (KdPointerInfo *pi) { - if (tsDev) - ts_close(tsDev); - tsDev = NULL; + struct TslibPrivate *private = pi->driverPrivate; + + if (private->fd) { + KdUnregisterFd(pi, private->fd); + close(private->fd); + } + if (private->tsDev) + ts_close(private->tsDev); + private->fd = 0; + private->tsDev = NULL; } -static int -TslibInit (void) + +static Status +TslibInit (KdPointerInfo *pi) { - int i, j = 0; - KdMouseInfo *mi, *next; - int fd = 0; - int req_type; + int fd = 0, i = 0; + char devpath[PATH_MAX], devname[TS_NAME_SIZE]; + DIR *inputdir = NULL; + struct dirent *inputent = NULL; + struct tsdev *tsDev = NULL; + struct TslibPrivate *private = NULL; + + if (!pi || !pi->dixdev) + return !Success; + + pi->driverPrivate = (struct TslibPrivate *) + xcalloc(sizeof(struct TslibPrivate), 1); + if (!pi->driverPrivate) + return !Success; + + private = pi->driverPrivate; + /* hacktastic */ + private->phys_screen = 0; + pi->nAxes = 3; + pi->name = KdSaveString("Touchscreen"); + pi->inputClass = KD_TOUCHSCREEN; +#ifdef DEBUG + ErrorF("[tslib/TslibInit] successfully inited for device %s\n", pi->path); +#endif - if (!TsInputType) - { - TsInputType = KdAllocInputType (); - KdParseMouse(0); /* allocate safe slot in kdMouseInfo */ - req_type = 0; - } - else req_type = TsInputType; /* is being re-inited */ - - for (mi = kdMouseInfo; mi; mi = next) - { - next = mi->next; - - /* find a usuable slot */ - if (mi->inputType != req_type) - continue; - - /* Check for tslib env var device setting */ - if ((TsNames[0] = getenv("TSLIB_TSDEVICE")) == NULL) - j++; - - if (!mi->name) - { - for (i = j; i < NUM_TS_NAMES; i++) - { - fd = TsLibOpen(TsNames[i]); - - if (fd >= 0) - { - mi->name = KdSaveString (TsNames[i]); - break; - } - } - } - else - fd = TsLibOpen(mi->name); - - if (fd >= 0 && tsDev != NULL) - { - mi->driver = (void *) fd; - mi->inputType = TsInputType; - - KdRegisterFd (TsInputType, fd, TsRead, (void *) mi); - - /* Set callbacks for vt switches etc */ - KdRegisterFdEnableDisable (fd, TslibEnable, TslibDisable); - - return TRUE; - } - } - - ErrorF ("Failed to open TSLib device, tried "); - for (i = j; i < NUM_TS_NAMES; i++) - ErrorF ("%s ", TsNames[i]); - ErrorF (".\n"); - if (!TsNames[0]) - ErrorF ("Try setting TSLIB_TSDEVICE to valid /dev entry?\n"); - - if (fd > 0) - close(fd); - - return FALSE; + return Success; } + static void -TslibFini (void) +TslibFini (KdPointerInfo *pi) { - KdMouseInfo *mi; - - KdUnregisterFds (TsInputType, TRUE); - for (mi = kdMouseInfo; mi; mi = mi->next) - { - if (mi->inputType == TsInputType) - { - if(mi->driver) - { - ts_close(tsDev); - tsDev = NULL; - } - mi->driver = 0; - - /* If below is set to 0, then MouseInit() will trash it, - * setting to 'mouse type' ( via server reset). Therefore - * Leave it alone and work around in TslibInit() ( see - * req_type ). - */ - /* mi->inputType = 0; */ - } + if (pi->driverPrivate) { + xfree(pi->driverPrivate); + pi->driverPrivate = NULL; } } -KdMouseFuncs TsFuncs = { + +KdPointerDriver TsDriver = { + "tslib", TslibInit, - TslibFini + TslibEnable, + TslibDisable, + TslibFini, + NULL, }; diff --git a/hw/kdrive/src/Makefile.am b/hw/kdrive/src/Makefile.am index 53d50950d..20fae554a 100644 --- a/hw/kdrive/src/Makefile.am +++ b/hw/kdrive/src/Makefile.am @@ -24,7 +24,7 @@ libkdrive_a_SOURCES = \ kdrive.h \ kinfo.c \ kinput.c \ - kkeymap.h \ + kkeymap.c \ kmap.c \ kmode.c \ knoop.c \ @@ -37,5 +37,4 @@ libkdrive_a_SOURCES = \ $(top_srcdir)/mi/miinitext.c libkdrivestubs_a_SOURCES = \ - $(top_srcdir)/Xi/stubs.c \ $(top_srcdir)/fb/fbcmap.c diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c index 52e56e90b..05102ab11 100644 --- a/hw/kdrive/src/kdrive.c +++ b/hw/kdrive/src/kdrive.c @@ -43,6 +43,12 @@ #include "dpmsproc.h" #endif +#ifdef HAVE_EXECINFO_H +#include <execinfo.h> +#endif + +#include <signal.h> + typedef struct _kdDepths { CARD8 depth; CARD8 bpp; @@ -60,6 +66,8 @@ KdDepths kdDepths[] = { #define NUM_KD_DEPTHS (sizeof (kdDepths) / sizeof (kdDepths[0])) +#define KD_DEFAULT_BUTTONS 5 + int kdScreenPrivateIndex; unsigned long kdGeneration; @@ -76,6 +84,8 @@ Bool kdSwitchPending; char *kdSwitchCmd; DDXPointRec kdOrigin; +static Bool kdCaughtSignal = FALSE; + /* * Carry arguments from InitOutput through driver initialization * to KdScreenInit @@ -368,6 +378,9 @@ AbortDDX(void) (*kdOsFuncs->Fini) (); KdDoSwitchCmd ("stop"); } + + if (kdCaughtSignal) + abort(); } void @@ -379,7 +392,7 @@ ddxGiveUp () Bool kdDumbDriver; Bool kdSoftCursor; -static char * +char * KdParseFindNext (char *cur, char *delim, char *save, char *last) { while (*cur && !strchr (delim, *cur)) @@ -560,97 +573,6 @@ KdSaveString (char *str) return n; } -/* - * Parse mouse information. Syntax: - * - * <device>,<nbutton>,<protocol>{,<option>}... - * - * options: {nmo} pointer mapping (e.g. {321}) - * 2button emulate middle button - * 3button dont emulate middle button - */ - -void -KdParseMouse (char *arg) -{ - char save[1024]; - char delim; - KdMouseInfo *mi; - int i; - - mi = KdMouseInfoAdd (); - if (!mi) - return; - mi->name = 0; - mi->prot = 0; - mi->emulateMiddleButton = kdEmulateMiddleButton; - mi->transformCoordinates = !kdRawPointerCoordinates; - mi->nbutton = 3; - for (i = 0; i < KD_MAX_BUTTON; i++) - mi->map[i] = i + 1; - - if (!arg) - return; - if (strlen (arg) >= sizeof (save)) - return; - arg = KdParseFindNext (arg, ",", save, &delim); - if (!save[0]) - return; - mi->name = KdSaveString (save); - if (delim != ',') - return; - - arg = KdParseFindNext (arg, ",", save, &delim); - if (!save[0]) - return; - - if ('1' <= save[0] && save[0] <= '0' + KD_MAX_BUTTON && save[1] == '\0') - { - mi->nbutton = save[0] - '0'; - if (mi->nbutton > KD_MAX_BUTTON) - { - UseMsg (); - return; - } - } - - if (!delim != ',') - return; - - arg = KdParseFindNext (arg, ",", save, &delim); - - if (save[0]) - mi->prot = KdSaveString (save); - - while (delim == ',') - { - arg = KdParseFindNext (arg, ",", save, &delim); - if (save[0] == '{') - { - char *s = save + 1; - i = 0; - while (*s && *s != '}') - { - if ('1' <= *s && *s <= '0' + mi->nbutton) - mi->map[i] = *s - '0'; - else - UseMsg (); - s++; - } - } - else if (!strcmp (save, "2button")) - mi->emulateMiddleButton = TRUE; - else if (!strcmp (save, "3button")) - mi->emulateMiddleButton = FALSE; - else if (!strcmp (save, "rawcoord")) - mi->transformCoordinates = FALSE; - else if (!strcmp (save, "transform")) - mi->transformCoordinates = TRUE; - else - UseMsg (); - } -} - void KdParseRgba (char *rgba) { @@ -697,6 +619,8 @@ KdProcessArgument (int argc, char **argv, int i) { KdCardInfo *card; KdScreenInfo *screen; + KdPointerInfo *pi; + KdKeyboardInfo *ki; if (!strcmp (argv[i], "-card")) { @@ -736,6 +660,11 @@ KdProcessArgument (int argc, char **argv, int i) kdDontZap = TRUE; return 1; } + if (!strcmp (argv[i], "-nozap")) + { + kdDontZap = TRUE; + return 1; + } if (!strcmp (argv[i], "-3button")) { kdEmulateMiddleButton = FALSE; @@ -785,14 +714,6 @@ KdProcessArgument (int argc, char **argv, int i) UseMsg (); return 2; } - if (!strcmp (argv[i], "-mouse")) - { - if ((i+1) < argc) - KdParseMouse (argv[i+1]); - else - UseMsg (); - return 2; - } if (!strcmp (argv[i], "-rgba")) { if ((i+1) < argc) @@ -814,6 +735,20 @@ KdProcessArgument (int argc, char **argv, int i) { return 1; } + if (!strcmp (argv[i], "-mouse") || + !strcmp (argv[i], "-pointer")) { + if (i + 1 >= argc) + UseMsg(); + KdAddConfigPointer(argv[i + 1]); + return 2; + } + if (!strcmp (argv[i], "-keybd")) { + if (i + 1 >= argc) + UseMsg(); + KdAddConfigKeyboard(argv[i + 1]); + return 2; + } + #ifdef PSEUDO8 return p8ProcessArgument (argc, argv, i); #else @@ -1420,6 +1355,39 @@ KdDepthToFb (ScreenPtr pScreen, int depth) #endif +#ifdef HAVE_BACKTRACE +/* shamelessly ripped from xf86Events.c */ +void +KdBacktrace (int signum) +{ + void *array[32]; /* more than 32 and you have bigger problems */ + size_t size, i; + char **strings; + + signal(signum, SIG_IGN); + + size = backtrace (array, 32); + fprintf (stderr, "\nBacktrace (%d deep):\n", size); + strings = backtrace_symbols (array, size); + for (i = 0; i < size; i++) + fprintf (stderr, "%d: %s\n", i, strings[i]); + free (strings); + + kdCaughtSignal = TRUE; + if (signum == SIGSEGV) + FatalError("Segmentation fault caught\n"); + else if (signum > 0) + FatalError("Signal %d caught\n", signum); +} +#else +void +KdBacktrace (int signum) +{ + kdCaughtSignal = TRUE; + FatalError("Segmentation fault caught\n"); +} +#endif + void KdInitOutput (ScreenInfo *pScreenInfo, int argc, @@ -1427,6 +1395,10 @@ KdInitOutput (ScreenInfo *pScreenInfo, { KdCardInfo *card; KdScreenInfo *screen; + + /* kind of a hack: we want Composite enabled, but it's disabled per + * default. */ + noCompositeExtension = FALSE; if (!kdCardInfo) { @@ -1464,6 +1436,8 @@ KdInitOutput (ScreenInfo *pScreenInfo, for (card = kdCardInfo; card; card = card->next) for (screen = card->screenList; screen; screen = screen->next) KdAddScreen (pScreenInfo, screen, argc, argv); + + signal(SIGSEGV, KdBacktrace); } #ifdef DPMSExtension diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h index c371263d3..843f92175 100644 --- a/hw/kdrive/src/kdrive.h +++ b/hw/kdrive/src/kdrive.h @@ -47,6 +47,10 @@ #include "shadow.h" #include "randrstr.h" +#ifdef XKB +#include <X11/extensions/XKBstr.h> +#endif + extern WindowPtr *WindowTable; #define KD_DPMS_NORMAL 0 @@ -63,6 +67,8 @@ extern WindowPtr *WindowTable; #define KD_MAX_CARD_ADDRESS 8 #endif +#define Status int + /* * Configuration information per video card */ @@ -215,7 +221,7 @@ typedef struct { #endif } KdPrivScreenRec, *KdPrivScreenPtr; -typedef enum _kdMouseState { +typedef enum _kdPointerState { start, button_1_pend, button_1_down, @@ -226,51 +232,135 @@ typedef enum _kdMouseState { synth_2_down_3, synth_2_down_1, num_input_states -} KdMouseState; - -#define KD_MAX_BUTTON 7 - -typedef struct _KdMouseInfo { - struct _KdMouseInfo *next; - void *driver; - void *closure; - char *name; - char *prot; - char map[KD_MAX_BUTTON]; - int nbutton; - Bool emulateMiddleButton; - unsigned long emulationTimeout; - Bool timeoutPending; - KdMouseState mouseState; - Bool eventHeld; - xEvent heldEvent; - unsigned char buttonState; - int emulationDx, emulationDy; - int inputType; - Bool transformCoordinates; -} KdMouseInfo; - -extern KdMouseInfo *kdMouseInfo; +} KdPointerState; + +#define KD_MAX_BUTTON 16 + +#define KD_KEYBOARD 1 +#define KD_MOUSE 2 +#define KD_TOUCHSCREEN 3 + +typedef struct _KdPointerInfo KdPointerInfo; + +typedef struct _KdPointerDriver { + char *name; + Status (*Init) (KdPointerInfo *); + Status (*Enable) (KdPointerInfo *); + void (*Disable) (KdPointerInfo *); + void (*Fini) (KdPointerInfo *); + struct _KdPointerDriver *next; +} KdPointerDriver; + +struct _KdPointerInfo { + DeviceIntPtr dixdev; + char *name; + char *path; + InputOption *options; + int inputClass; + + CARD8 map[KD_MAX_BUTTON]; + int nButtons; + int nAxes; + + Bool emulateMiddleButton; + unsigned long emulationTimeout; + int emulationDx, emulationDy; + + Bool timeoutPending; + KdPointerState mouseState; + Bool eventHeld; + struct { + int type; + int x; + int y; + int z; + int flags; + int absrel; + } heldEvent; + unsigned char buttonState; + Bool transformCoordinates; + int pressureThreshold; + + KdPointerDriver *driver; + void *driverPrivate; + + struct _KdPointerInfo *next; +}; extern int KdCurScreen; -KdMouseInfo *KdMouseInfoAdd (void); -void KdMouseInfoDispose (KdMouseInfo *mi); -void KdParseMouse (char *); +void KdAddPointerDriver (KdPointerDriver *driver); +void KdRemovePointerDriver (KdPointerDriver *driver); +KdPointerInfo *KdNewPointer (void); +void KdFreePointer (KdPointerInfo *); +int KdAddPointer (KdPointerInfo *ki); +int KdAddConfigPointer (char *pointer); +void KdRemovePointer (KdPointerInfo *ki); -typedef struct _KdMouseFuncs { - Bool (*Init) (void); - void (*Fini) (void); -} KdMouseFuncs; -typedef struct _KdKeyboardFuncs { - void (*Load) (void); - int (*Init) (void); - void (*Leds) (int); - void (*Bell) (int, int, int); - void (*Fini) (void); - int LockLed; -} KdKeyboardFuncs; +#define KD_KEY_COUNT 248 +#define KD_MIN_KEYCODE 8 +#define KD_MAX_KEYCODE 255 +#define KD_MAX_WIDTH 4 +#define KD_MAX_LENGTH (KD_MAX_KEYCODE - KD_MIN_KEYCODE + 1) + +typedef struct { + KeySym modsym; + int modbit; +} KdKeySymModsRec; + +extern const KeySym kdDefaultKeymap[KD_MAX_LENGTH * KD_MAX_WIDTH]; +extern const int kdDefaultKeymapWidth; +extern const CARD8 kdDefaultModMap[MAP_LENGTH]; +extern const KeySymsRec kdDefaultKeySyms; + +typedef struct _KdKeyboardInfo KdKeyboardInfo; + +typedef struct _KdKeyboardDriver { + char *name; + Bool (*Init) (KdKeyboardInfo *); + Bool (*Enable) (KdKeyboardInfo *); + void (*Leds) (KdKeyboardInfo *, int); + void (*Bell) (KdKeyboardInfo *, int, int, int); + void (*Disable) (KdKeyboardInfo *); + void (*Fini) (KdKeyboardInfo *); + struct _KdKeyboardDriver *next; +} KdKeyboardDriver; + +struct _KdKeyboardInfo { + struct _KdKeyboardInfo *next; + DeviceIntPtr dixdev; + void *closure; + char *name; + char *path; + int inputClass; +#ifdef XKB + XkbDescPtr xkb; +#endif + int LockLed; + + CARD8 keyState[KD_KEY_COUNT/8]; + int minScanCode; + int maxScanCode; + CARD8 modmap[MAP_LENGTH]; + KeySymsRec keySyms; + + int leds; + int bellPitch; + int bellDuration; + InputOption *options; + + KdKeyboardDriver *driver; + void *driverPrivate; +}; + +void KdAddKeyboardDriver (KdKeyboardDriver *driver); +void KdRemoveKeyboardDriver (KdKeyboardDriver *driver); +KdKeyboardInfo *KdNewKeyboard (void); +void KdFreeKeyboard (KdKeyboardInfo *ki); +int KdAddConfigKeyboard (char *pointer); +int KdAddKeyboard (KdKeyboardInfo *ki); +void KdRemoveKeyboard (KdKeyboardInfo *ki); typedef struct _KdOsFuncs { int (*Init) (void); @@ -307,9 +397,9 @@ typedef struct _KdMonitorTiming { extern const KdMonitorTiming kdMonitorTimings[]; extern const int kdNumMonitorTimings; -typedef struct _KdMouseMatrix { +typedef struct _KdPointerMatrix { int matrix[2][3]; -} KdMouseMatrix; +} KdPointerMatrix; typedef struct _KaaTrapezoid { float tl, tr, ty; @@ -628,8 +718,14 @@ KdParseScreen (KdScreenInfo *screen, char * KdSaveString (char *str); -void -KdParseMouse (char *arg); +KdPointerInfo * +KdParsePointer (char *arg); + +KdKeyboardInfo * +KdParseKeyboard (char *arg); + +char * +KdParseFindNext (char *cur, char *delim, char *save, char *last); void KdParseRgba (char *rgba); @@ -677,6 +773,9 @@ KdInitOutput (ScreenInfo *pScreenInfo, void KdSetSubpixelOrder (ScreenPtr pScreen, Rotation randr); + +void +KdBacktrace (int signum); /* kinfo.c */ KdCardInfo * @@ -699,53 +798,51 @@ KdScreenInfoDispose (KdScreenInfo *si); /* kinput.c */ void -KdInitInput(KdMouseFuncs *, KdKeyboardFuncs *); +KdInitInput(void); void -KdAddMouseDriver(KdMouseFuncs *); +KdAddPointerDriver(KdPointerDriver *); -int -KdAllocInputType (void); +void +KdAddKeyboardDriver(KdKeyboardDriver *); Bool -KdRegisterFd (int type, int fd, void (*read) (int fd, void *closure), void *closure); +KdRegisterFd (int fd, void (*read) (int fd, void *closure), void *closure); void -KdRegisterFdEnableDisable (int fd, - int (*enable) (int fd, void *closure), - void (*disable) (int fd, void *closure)); +KdUnregisterFds (void *closure, Bool do_close); void -KdUnregisterFds (int type, Bool do_close); - -void -KdEnqueueKeyboardEvent(unsigned char scan_code, - unsigned char is_up); +KdEnqueueKeyboardEvent(KdKeyboardInfo *ki, unsigned char scan_code, + unsigned char is_up); #define KD_BUTTON_1 0x01 #define KD_BUTTON_2 0x02 #define KD_BUTTON_3 0x04 #define KD_BUTTON_4 0x08 #define KD_BUTTON_5 0x10 +#define KD_BUTTON_8 0x80 #define KD_MOUSE_DELTA 0x80000000 void -KdEnqueueMouseEvent(KdMouseInfo *mi, unsigned long flags, int x, int y); +KdEnqueuePointerEvent(KdPointerInfo *pi, unsigned long flags, int rx, int ry, + int rz); void -KdEnqueueMotionEvent (KdMouseInfo *mi, int x, int y); +_KdEnqueuePointerEvent(KdPointerInfo *pi, int type, int x, int y, int z, + int b, int absrel, Bool force); void KdReleaseAllKeys (void); void -KdSetLed (int led, Bool on); +KdSetLed (KdKeyboardInfo *ki, int led, Bool on); void -KdSetMouseMatrix (KdMouseMatrix *matrix); +KdSetPointerMatrix (KdPointerMatrix *pointer); void -KdComputeMouseMatrix (KdMouseMatrix *matrix, Rotation randr, int width, int height); +KdComputePointerMatrix (KdPointerMatrix *pointer, Rotation randr, int width, int height); void KdBlockHandler (int screen, @@ -768,19 +865,17 @@ KdEnableInput (void); void ProcessInputEvents (void); -extern KdMouseFuncs LinuxMouseFuncs; -extern KdMouseFuncs LinuxEvdevFuncs; -extern KdMouseFuncs Ps2MouseFuncs; -extern KdMouseFuncs BusMouseFuncs; -extern KdMouseFuncs MsMouseFuncs; -#ifdef TOUCHSCREEN -extern KdMouseFuncs TsFuncs; -#endif -extern KdKeyboardFuncs LinuxKeyboardFuncs; +extern KdPointerDriver LinuxMouseDriver; +extern KdPointerDriver LinuxEvdevDriver; +extern KdPointerDriver Ps2MouseDriver; +extern KdPointerDriver BusMouseDriver; +extern KdPointerDriver MsMouseDriver; +extern KdPointerDriver TsDriver; +extern KdKeyboardDriver LinuxKeyboardDriver; extern KdOsFuncs LinuxFuncs; -extern KdMouseFuncs VxWorksMouseFuncs; -extern KdKeyboardFuncs VxWorksKeyboardFuncs; +extern KdPointerDriver VxWorksMouseDriver; +extern KdKeyboardDriver VxWorksKeyboardDriver; extern KdOsFuncs VxWorksFuncs; /* kmap.c */ diff --git a/hw/kdrive/src/kinfo.c b/hw/kdrive/src/kinfo.c index 3ba7687c2..1d81ed396 100644 --- a/hw/kdrive/src/kinfo.c +++ b/hw/kdrive/src/kinfo.c @@ -101,7 +101,7 @@ KdScreenInfoDispose (KdScreenInfo *si) KdCardInfo *ci = si->card; KdScreenInfo **prev; - for (prev = &ci->screenList; *prev; prev = &(*prev)->next) + for (prev = &ci->screenList; *prev; prev = &(*prev)->next) { if (*prev == si) { *prev = si->next; @@ -110,38 +110,63 @@ KdScreenInfoDispose (KdScreenInfo *si) KdCardInfoDispose (ci); break; } + } } -KdMouseInfo *kdMouseInfo; - -KdMouseInfo * -KdMouseInfoAdd (void) +KdPointerInfo * +KdNewPointer (void) { - KdMouseInfo *mi, **prev; - - mi = (KdMouseInfo *) xalloc (sizeof (KdMouseInfo)); - if (!mi) - return 0; - bzero (mi, sizeof (KdMouseInfo)); - for (prev = &kdMouseInfo; *prev; prev = &(*prev)->next); - *prev = mi; - return mi; + KdPointerInfo *pi; + + pi = (KdPointerInfo *)xcalloc(1, sizeof(KdPointerInfo)); + if (!pi) + return NULL; + + pi->name = KdSaveString("Generic Pointer"); + pi->path = NULL; + pi->inputClass = KD_MOUSE; + pi->driver = NULL; + pi->driverPrivate = NULL; + pi->next = NULL; + pi->options = NULL; + pi->nAxes = 3; + + return pi; } void -KdMouseInfoDispose (KdMouseInfo *mi) +KdFreePointer(KdPointerInfo *pi) { - KdMouseInfo **prev; - - for (prev = &kdMouseInfo; *prev; prev = &(*prev)->next) - if (*prev == mi) - { - *prev = mi->next; - if (mi->name) - xfree (mi->name); - if (mi->prot) - xfree (mi->prot); - xfree (mi); - break; - } + InputOption *option, *prev = NULL; + + if (pi->name) + xfree(pi->name); + if (pi->path) + xfree(pi->path); + + for (option = pi->options; option; option = option->next) { + if (prev) + xfree(prev); + if (option->key) + xfree(option->key); + if (option->value) + xfree(option->value); + prev = option; + } + + if (prev) + xfree(prev); + + xfree(pi); +} + +void +KdFreeKeyboard(KdKeyboardInfo *ki) +{ + if (ki->name) + xfree(ki->name); + if (ki->path) + xfree(ki->path); + ki->next = NULL; + xfree(ki); } diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c index f671eb698..94c3abd28 100644 --- a/hw/kdrive/src/kinput.c +++ b/hw/kdrive/src/kinput.c @@ -2,20 +2,21 @@ * Id: kinput.c,v 1.1 1999/11/02 03:54:46 keithp Exp $ * * Copyright © 1999 Keith Packard + * Copyright © 2006 Nokia Corporation * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in + * documentation, and that the name of the authors not be used in * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no + * specific, written prior permission. The authors make no * representations about the suitability of this software for any purpose. It * is provided "as is" without express or implied warranty. * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR @@ -34,7 +35,6 @@ #if HAVE_X11_XF86KEYSYM_H #include <X11/XF86keysym.h> #endif -#include "kkeymap.h" #include <signal.h> #include <stdio.h> #ifdef sun @@ -45,58 +45,60 @@ #include <X11/extensions/XKBsrv.h> #endif -static DeviceIntPtr pKdKeyboard, pKdPointer; +#ifdef XINPUT +#include <X11/extensions/XI.h> +#include <X11/extensions/XIproto.h> +#include "exevents.h" +#include "extinit.h" +#include "exglobals.h" +#endif + +#define AtomFromName(x) MakeAtom(x, strlen(x), 1) + +struct KdConfigDevice { + char *line; + struct KdConfigDevice *next; +}; + +/* kdKeyboards and kdPointers hold all the real devices. */ +static KdKeyboardInfo *kdKeyboards = NULL; +static KdPointerInfo *kdPointers = NULL; +static struct KdConfigDevice *kdConfigKeyboards = NULL; +static struct KdConfigDevice *kdConfigPointers = NULL; -#define MAX_MOUSE_DRIVERS 4 +static KdKeyboardDriver *kdKeyboardDrivers = NULL; +static KdPointerDriver *kdPointerDrivers = NULL; -static KdMouseFuncs *kdMouseFuncs[MAX_MOUSE_DRIVERS]; -static int kdNMouseFuncs; -static KdKeyboardFuncs *kdKeyboardFuncs; -static int kdBellPitch; -static int kdBellDuration; -static int kdLeds; static Bool kdInputEnabled; static Bool kdOffScreen; static unsigned long kdOffScreenTime; -static KdMouseMatrix kdMouseMatrix = { +static KdPointerMatrix kdPointerMatrix = { { { 1, 0, 0 }, { 0, 1, 0 } } }; -int kdMouseButtonCount; -int kdMinScanCode; -int kdMaxScanCode; -int kdMinKeyCode; -int kdMaxKeyCode; -int kdKeymapWidth = KD_MAX_WIDTH; -KeySym kdKeymap[KD_MAX_LENGTH * KD_MAX_WIDTH]; -CARD8 kdModMap[MAP_LENGTH]; -KeySymsRec kdKeySyms; - - -void -KdResetInputMachine (void); +void KdResetInputMachine (void); -#define KD_KEY_COUNT 248 - -CARD8 kdKeyState[KD_KEY_COUNT/8]; - -#define IsKeyDown(key) ((kdKeyState[(key) >> 3] >> ((key) & 7)) & 1) +#define IsKeyDown(ki, key) ((ki->keyState[(key) >> 3] >> ((key) & 7)) & 1) +#define KEYMAP(ki) (ki->dixdev->key->curKeySyms) +#define KEYMAPDDX(ki) (ki->keySyms) +#define KEYCOL1(ki, k) (KEYMAP(ki).map[((k)-(KEYMAP(ki).minKeyCode))*KEYMAP(ki).mapWidth]) +#define KEYCOL1DDX(ki, k) (KEYMAPDDX(ki).map[((k)-(KEYMAPDDX(ki).minKeyCode))*KEYMAPDDX(ki).mapWidth]) #define KD_MAX_INPUT_FDS 8 typedef struct _kdInputFd { - int type; - int fd; - void (*read) (int fd, void *closure); - int (*enable) (int fd, void *closure); - void (*disable) (int fd, void *closure); - void *closure; + int fd; + void (*read) (int fd, void *closure); + int (*enable) (int fd, void *closure); + void (*disable) (int fd, void *closure); + void *closure; } KdInputFd; -KdInputFd kdInputFds[KD_MAX_INPUT_FDS]; -int kdNumInputFds; -int kdInputTypeSequence; +static KdInputFd kdInputFds[KD_MAX_INPUT_FDS]; +static int kdNumInputFds; + +extern Bool kdRawPointerCoordinates; static void KdSigio (int sig) @@ -137,8 +139,10 @@ KdAssertSigioBlocked (char *where) sigemptyset (&set); sigprocmask (SIG_BLOCK, &set, &old); - if (!sigismember (&old, SIGIO)) + if (!sigismember (&old, SIGIO)) { ErrorF ("SIGIO not blocked at %s\n", where); + KdBacktrace(); + } } #else @@ -155,6 +159,17 @@ static int kdnFds; #define NOBLOCK FNDELAY #endif +void +KdResetInputMachine (void) +{ + KdPointerInfo *pi; + + for (pi = kdPointers; pi; pi = pi->next) { + pi->mouseState = start; + pi->eventHeld = FALSE; + } +} + static void KdNonBlockFd (int fd) { @@ -205,98 +220,126 @@ KdRemoveFd (int fd) } } -int -KdAllocInputType (void) -{ - return ++kdInputTypeSequence; -} - Bool -KdRegisterFd (int type, int fd, void (*read) (int fd, void *closure), void *closure) +KdRegisterFd (int fd, void (*read) (int fd, void *closure), void *closure) { if (kdNumInputFds == KD_MAX_INPUT_FDS) return FALSE; - kdInputFds[kdNumInputFds].type = type; kdInputFds[kdNumInputFds].fd = fd; kdInputFds[kdNumInputFds].read = read; kdInputFds[kdNumInputFds].enable = 0; kdInputFds[kdNumInputFds].disable = 0; kdInputFds[kdNumInputFds].closure = closure; - ++kdNumInputFds; + kdNumInputFds++; if (kdInputEnabled) KdAddFd (fd); return TRUE; } void -KdRegisterFdEnableDisable (int fd, - int (*enable) (int fd, void *closure), - void (*disable) (int fd, void *closure)) -{ - int i; - - for (i = 0; i < kdNumInputFds; i++) - if (kdInputFds[i].fd == fd) - { - kdInputFds[i].enable = enable; - kdInputFds[i].disable = disable; - break; - } -} - -void -KdUnregisterFds (int type, Bool do_close) +KdUnregisterFd (void *closure, int fd, Bool do_close) { int i, j; - for (i = 0; i < kdNumInputFds;) - { - if (kdInputFds[i].type == type) - { + for (i = 0; i < kdNumInputFds; i++) { + if (kdInputFds[i].closure == closure && + kdInputFds[i].fd == fd) { if (kdInputEnabled) KdRemoveFd (kdInputFds[i].fd); if (do_close) close (kdInputFds[i].fd); - --kdNumInputFds; + kdNumInputFds--; for (j = i; j < kdNumInputFds; j++) kdInputFds[j] = kdInputFds[j+1]; + break; } - else - i++; } } void KdDisableInput (void) { - int i; + KdKeyboardInfo *ki; + KdPointerInfo *pi; + int found = 0, i = 0; - KdBlockSigio (); + KdBlockSigio(); - for (i = 0; i < kdNumInputFds; i++) - { - KdRemoveFd (kdInputFds[i].fd); - if (kdInputFds[i].disable) - (*kdInputFds[i].disable) (kdInputFds[i].fd, kdInputFds[i].closure); + for (ki = kdKeyboards; ki; ki = ki->next) { + if (ki->driver && ki->driver->Disable) + (*ki->driver->Disable) (ki); + } + + for (pi = kdPointers; pi; pi = pi->next) { + if (pi->driver && pi->driver->Disable) + (*pi->driver->Disable) (pi); + } + + if (kdNumInputFds) { + ErrorF("[KdDisableInput] Buggy drivers: still %d input fds left!", + kdNumInputFds); + i = 0; + while (i < kdNumInputFds) { + found = 0; + for (ki = kdKeyboards; ki; ki = ki->next) { + if (ki == kdInputFds[i].closure) { + ErrorF(" fd %d belongs to keybd driver %s\n", + kdInputFds[i].fd, + ki->driver && ki->driver->name ? + ki->driver->name : "(unnamed!)"); + found = 1; + break; + } + } + + if (found) { + i++; + continue; + } + + for (pi = kdPointers; pi; pi = pi->next) { + if (pi == kdInputFds[i].closure) { + ErrorF(" fd %d belongs to pointer driver %s\n", + kdInputFds[i].fd, + pi->driver && pi->driver->name ? + pi->driver->name : "(unnamed!)"); + break; + } + } + + if (found) { + i++; + continue; + } + + ErrorF(" fd %d not claimed by any active device!\n", + kdInputFds[i].fd); + KdUnregisterFd(kdInputFds[i].closure, kdInputFds[i].fd, TRUE); + } } + kdInputEnabled = FALSE; } void KdEnableInput (void) { - xEvent xE; - int i; + xEvent xE; + KdKeyboardInfo *ki; + KdPointerInfo *pi; kdInputEnabled = TRUE; - for (i = 0; i < kdNumInputFds; i++) - { - KdNonBlockFd (kdInputFds[i].fd); - if (kdInputFds[i].enable) - kdInputFds[i].fd = (*kdInputFds[i].enable) (kdInputFds[i].fd, kdInputFds[i].closure); - KdAddFd (kdInputFds[i].fd); + + for (ki = kdKeyboards; ki; ki = ki->next) { + if (ki->driver && ki->driver->Enable) + (*ki->driver->Enable) (ki); } - + + for (pi = kdPointers; pi; pi = pi->next) { + if (pi->driver && pi->driver->Enable) + (*pi->driver->Enable) (pi); + } + /* reset screen saver */ xE.u.keyButtonPointer.time = GetTimeInMillis (); NoticeEventTime (&xE); @@ -304,45 +347,178 @@ KdEnableInput (void) KdUnblockSigio (); } -static int -KdMouseProc(DeviceIntPtr pDevice, int onoff) +KdKeyboardDriver * +KdFindKeyboardDriver (char *name) { - BYTE map[KD_MAX_BUTTON]; - DevicePtr pDev = (DevicePtr)pDevice; - int i; + KdKeyboardDriver *ret; + + /* ask a stupid question ... */ + if (!name) + return NULL; + for (ret = kdKeyboardDrivers; ret; ret = ret->next) { + if (strcmp(ret->name, name) == 0) + return ret; + } + + return NULL; +} + +KdPointerDriver * +KdFindPointerDriver (char *name) +{ + KdPointerDriver *ret; + + /* ask a stupid question ... */ + if (!name) + return NULL; + + for (ret = kdPointerDrivers; ret; ret = ret->next) { + if (strcmp(ret->name, name) == 0) + return ret; + } + + return NULL; +} + +static int +KdPointerProc(DeviceIntPtr pDevice, int onoff) +{ + DevicePtr pDev = (DevicePtr)pDevice; + int i; + KdPointerInfo *pi; +#ifdef XINPUT + Atom xiclass; +#endif + if (!pDev) return BadImplementation; - + + for (pi = kdPointers; pi; pi = pi->next) { + if (pi->dixdev && pi->dixdev->id == pDevice->id) + break; + } + + if (!pi || !pi->dixdev || pi->dixdev->id != pDevice->id) { + ErrorF("[KdPointerProc] Failed to find pointer for device %d!\n", + pDevice->id); + return BadImplementation; + } + switch (onoff) { case DEVICE_INIT: - for (i = 1; i <= kdMouseButtonCount; i++) - map[i] = i; - InitPointerDeviceStruct(pDev, map, kdMouseButtonCount, + ErrorF("initialising pointer %s ...\n", pi->name); + if (!pi->driver) { + if (!pi->driverPrivate) { + ErrorF("no driver specified for %s\n", pi->name); + return BadImplementation; + } + + pi->driver = KdFindPointerDriver(pi->driverPrivate); + if (!pi->driver) { + ErrorF("Couldn't find pointer driver %s\n", + pi->driverPrivate ? (char *) pi->driverPrivate : + "(unnamed)"); + return !Success; + } + xfree(pi->driverPrivate); + pi->driverPrivate = NULL; + } + + if (!pi->driver->Init) { + ErrorF("no init function\n"); + return BadImplementation; + } + + for (i = 1; i <= pi->nButtons; i++) + pi->map[i] = i; + + if ((*pi->driver->Init) (pi) != Success) { + return !Success; + } + + InitPointerDeviceStruct(pDev, pi->map, pi->nButtons, miPointerGetMotionEvents, (PtrCtrlProcPtr)NoopDDA, miPointerGetMotionBufferSize()); - break; + +#ifdef XINPUT + if (pi->inputClass == KD_TOUCHSCREEN) { + InitTouchscreenClassDeviceStruct(pDevice); + xiclass = AtomFromName(XI_TOUCHSCREEN); + } + else { + xiclass = AtomFromName(XI_MOUSE); + } + + AssignTypeAndName(pi->dixdev, xiclass, + pi->name ? pi->name : "Generic KDrive Pointer"); +#endif + + return Success; case DEVICE_ON: - pDev->on = TRUE; - pKdPointer = pDevice; - for (i = 0; i < kdNMouseFuncs; i++) - (*kdMouseFuncs[i]->Init)(); - break; + if (pDev->on == TRUE) + return Success; + + if (!pi->driver->Enable) { + ErrorF("no enable function\n"); + return BadImplementation; + } + + if ((*pi->driver->Enable) (pi) == Success) { + ErrorF("initialised fine, returning success\n"); + pDev->on = TRUE; + return Success; + } + else { + return BadImplementation; + } + + return Success; + case DEVICE_OFF: + if (pDev->on == FALSE) { + return Success; + } + + if (!pi->driver->Disable) { + return BadImplementation; + } + else { + (*pi->driver->Disable) (pi); + pDev->on = FALSE; + return Success; + } + + return Success; + case DEVICE_CLOSE: - if (pDev->on) - { - pDev->on = FALSE; - pKdPointer = 0; - for (i = 0; i < kdNMouseFuncs; i++) - (*kdMouseFuncs[i]->Fini) (); - } - break; + ErrorF("D_C\n"); + if (pDev->on) { + if (!pi->driver->Disable) { + return BadImplementation; + } + (*pi->driver->Disable) (pi); + ErrorF("disabled\n"); + pDev->on = FALSE; + } + + if (!pi->driver->Fini) + return BadImplementation; + + (*pi->driver->Fini) (pi); + ErrorF("finished\n"); + + KdRemovePointer(pi); + ErrorF("removed\n"); + + return Success; } - return Success; + + /* NOTREACHED */ + return BadImplementation; } Bool @@ -354,34 +530,54 @@ LegalModifier(unsigned int key, DevicePtr pDev) static void KdBell (int volume, DeviceIntPtr pDev, pointer ctrl, int something) { - if (kdInputEnabled) - (*kdKeyboardFuncs->Bell) (volume, kdBellPitch, kdBellDuration); + KdKeyboardInfo *ki = NULL; + + for (ki = kdKeyboards; ki; ki = ki->next) { + if (ki->dixdev && (ki->dixdev->id == pDev->id)) + break; + } + + if (!ki || !ki->dixdev || ki->dixdev->id != pDev->id || !ki->driver) + return; + + if (kdInputEnabled) { + if (ki->driver->Bell) + (*ki->driver->Bell) (ki, volume, ki->bellPitch, ki->bellDuration); + } } static void -KdSetLeds (void) +KdSetLeds (KdKeyboardInfo *ki, int leds) { - if (kdInputEnabled) - (*kdKeyboardFuncs->Leds) (kdLeds); + if (!ki || !ki->driver) + return; + + if (kdInputEnabled) { + if (ki->driver->Leds) + (*ki->driver->Leds) (ki, leds); + } } void -KdSetLed (int led, Bool on) +KdSetLed (KdKeyboardInfo *ki, int led, Bool on) { - NoteLedState (pKdKeyboard, led, on); - kdLeds = pKdKeyboard->kbdfeed->ctrl.leds; - KdSetLeds (); + if (!ki || !ki->dixdev || !ki->dixdev->kbdfeed) + return; + + NoteLedState (ki->dixdev, led, on); + KdSetLeds (ki, ki->dixdev->kbdfeed->ctrl.leds); } void -KdSetMouseMatrix (KdMouseMatrix *matrix) +KdSetPointerMatrix (KdPointerMatrix *matrix) { - kdMouseMatrix = *matrix; + kdPointerMatrix = *matrix; } void -KdComputeMouseMatrix (KdMouseMatrix *m, Rotation randr, int width, int height) +KdComputePointerMatrix (KdPointerMatrix *m, Rotation randr, int width, + int height) { int x_dir = 1, y_dir = 1; int i, j; @@ -422,73 +618,25 @@ KdComputeMouseMatrix (KdMouseMatrix *m, Rotation randr, int width, int height) static void KdKbdCtrl (DeviceIntPtr pDevice, KeybdCtrl *ctrl) { - kdLeds = ctrl->leds; - kdBellPitch = ctrl->bell_pitch; - kdBellDuration = ctrl->bell_duration; - KdSetLeds (); -} + KdKeyboardInfo *ki; -static int -KdKeybdProc(DeviceIntPtr pDevice, int onoff) -{ - Bool ret; - DevicePtr pDev = (DevicePtr)pDevice; -#ifdef XKB - XkbComponentNamesRec names; -#endif + for (ki = kdKeyboards; ki; ki = ki->next) { + if (ki->dixdev && ki->dixdev->id == pDevice->id) + break; + } - if (!pDev) - return BadImplementation; + if (!ki || !ki->dixdev || ki->dixdev->id != pDevice->id || !ki->driver) + return; - switch (onoff) - { - case DEVICE_INIT: - if (pDev != LookupKeyboardDevice()) - { - return !Success; - } -#ifndef XKB - ret = InitKeyboardDeviceStruct(pDev, - &kdKeySyms, - kdModMap, - KdBell, KdKbdCtrl); -#else - memset(&names, 0, sizeof(XkbComponentNamesRec)); - - XkbSetRulesDflts ("base", "pc101", "us", NULL, NULL); - ret = XkbInitKeyboardDeviceStruct ((DeviceIntPtr) pDev, - &names, - &kdKeySyms, - kdModMap, - KdBell, KdKbdCtrl); -#endif - if (!ret) - return BadImplementation; - break; - case DEVICE_ON: - pDev->on = TRUE; - pKdKeyboard = pDevice; - if (kdKeyboardFuncs) - (*kdKeyboardFuncs->Init) (); - break; - case DEVICE_OFF: - case DEVICE_CLOSE: - pKdKeyboard = 0; - if (pDev->on) - { - pDev->on = FALSE; - if (kdKeyboardFuncs) - (*kdKeyboardFuncs->Fini) (); - } - break; - } - return Success; + KdSetLeds(ki, ctrl->leds); + ki->bellPitch = ctrl->bell_pitch; + ki->bellDuration = ctrl->bell_duration; } extern KeybdCtrl defaultKeyboardControl; static void -KdInitAutoRepeats (void) +KdInitAutoRepeats (KdKeyboardInfo *ki) { int key_code; unsigned char mask; @@ -499,7 +647,7 @@ KdInitAutoRepeats (void) memset (repeats, '\0', 32); for (key_code = KD_MIN_KEYCODE; key_code <= KD_MAX_KEYCODE; key_code++) { - if (!kdModMap[key_code]) + if (!ki->modmap[key_code]) { i = key_code >> 3; mask = 1 << (key_code & 7); @@ -525,7 +673,6 @@ const KdKeySymModsRec kdKeySymMods[] = { { XK_Hyper_L, Mod3Mask }, { XK_Hyper_R, Mod3Mask }, { XK_Mode_switch, Mod4Mask }, -#ifdef TOUCHSCREEN /* PDA specific hacks */ #ifdef XF86XK_Start { XF86XK_Start, ControlMask }, @@ -538,13 +685,12 @@ const KdKeySymModsRec kdKeySymMods[] = { #ifdef XF86XK_Calendar { XF86XK_Calendar, Mod3Mask } #endif -#endif }; #define NUM_SYM_MODS (sizeof(kdKeySymMods) / sizeof(kdKeySymMods[0])) static void -KdInitModMap (void) +KdInitModMap (KdKeyboardInfo *ki) { int key_code; int row; @@ -552,79 +698,589 @@ KdInitModMap (void) KeySym *syms; int i; - width = kdKeySyms.mapWidth; - for (key_code = kdMinKeyCode; key_code <= kdMaxKeyCode; key_code++) + width = ki->keySyms.mapWidth; + for (key_code = ki->keySyms.minKeyCode; key_code <= ki->keySyms.maxKeyCode; key_code++) { - kdModMap[key_code] = 0; - syms = kdKeymap + (key_code - kdMinKeyCode) * width; + ki->modmap[key_code] = 0; + syms = ki->keySyms.map + (key_code - ki->keySyms.minKeyCode) * width; for (row = 0; row < width; row++, syms++) { for (i = 0; i < NUM_SYM_MODS; i++) { if (*syms == kdKeySymMods[i].modsym) - kdModMap[key_code] |= kdKeySymMods[i].modbit; + ki->modmap[key_code] |= kdKeySymMods[i].modbit; } } } } +static int +KdKeyboardProc(DeviceIntPtr pDevice, int onoff) +{ + Bool ret; + DevicePtr pDev = (DevicePtr)pDevice; + KdKeyboardInfo *ki; +#ifdef XKB + XkbComponentNamesRec names; +#endif +#ifdef XINPUT + Atom xiclass; +#endif + + if (!pDev) + return BadImplementation; + + for (ki = kdKeyboards; ki; ki = ki->next) { + if (ki->dixdev && ki->dixdev->id == pDevice->id) + break; + } + + if (!ki || !ki->dixdev || ki->dixdev->id != pDevice->id) { + return BadImplementation; + } + + switch (onoff) + { + case DEVICE_INIT: +#ifdef DEBUG + ErrorF("initialising keyboard %s\n", ki->name); +#endif + if (!ki->driver) { + if (!ki->driverPrivate) { + ErrorF("no driver specified!\n"); + return BadImplementation; + } + + ki->driver = KdFindKeyboardDriver(ki->driverPrivate); + if (!ki->driver) { + ErrorF("Couldn't find keyboard driver %s\n", + ki->driverPrivate ? (char *) ki->driverPrivate : + "(unnamed)"); + return !Success; + } + xfree(ki->driverPrivate); + ki->driverPrivate = NULL; + } + + if (!ki->driver->Init) { + ErrorF("Keyboard %s: no init function\n", ki->name); + return BadImplementation; + } + + if ((*ki->driver->Init) (ki) != Success) { + return !Success; + } + + KdInitModMap(ki); + KdInitAutoRepeats(ki); + +#ifndef XKB + if (!noXkbExtension) { + memset(&names, 0, sizeof(XkbComponentNamesRec)); + if (XkbInitialMap) + names.keymap = XkbInitialMap; + + XkbSetRulesDflts ("base", "pc105", "us", NULL, NULL); + ret = XkbInitKeyboardDeviceStruct (pDevice, + &names, + &ki->keySyms, + ki->modmap, + KdBell, KdKbdCtrl); + } + else +#endif + ret = InitKeyboardDeviceStruct(pDev, + &ki->keySyms, + ki->modmap, + KdBell, KdKbdCtrl); + if (!ret) { + ErrorF("Couldn't initialise keyboard %s\n", ki->name); + return BadImplementation; + } + +#ifdef XINPUT + xiclass = AtomFromName(XI_KEYBOARD); + AssignTypeAndName(pDevice, xiclass, + ki->name ? ki->name : "Generic KDrive Keyboard"); +#endif + + KdResetInputMachine(); + + return Success; + + case DEVICE_ON: + if (pDev->on == TRUE) + return Success; + + if (!ki->driver->Enable) + return BadImplementation; + + if ((*ki->driver->Enable) (ki) != Success) { + return BadMatch; + } + + pDev->on = TRUE; + return Success; + + case DEVICE_OFF: + if (pDev->on == FALSE) + return Success; + + if (!ki->driver->Disable) + return BadImplementation; + + (*ki->driver->Disable) (ki); + pDev->on = FALSE; + + return Success; + + break; + + case DEVICE_CLOSE: + if (pDev->on) { + if (!ki->driver->Disable) + return BadImplementation; + + (*ki->driver->Disable) (ki); + pDev->on = FALSE; + } + + if (!ki->driver->Fini) + return BadImplementation; + + (*ki->driver->Fini) (ki); + + KdRemoveKeyboard(ki); + + return Success; + } + + /* NOTREACHED */ + return BadImplementation; +} + +void +KdAddPointerDriver (KdPointerDriver *driver) +{ + KdPointerDriver **prev; + + if (!driver) + return; + + for (prev = &kdPointerDrivers; *prev; prev = &(*prev)->next) { + if (*prev == driver) + return; + } + *prev = driver; +} + void -KdAddMouseDriver(KdMouseFuncs *pMouseFuncs) +KdRemovePointerDriver (KdPointerDriver *driver) { - if (kdNMouseFuncs < MAX_MOUSE_DRIVERS) - kdMouseFuncs[kdNMouseFuncs++] = pMouseFuncs; + KdPointerDriver *tmp; + + if (!driver) + return; + + /* FIXME remove all pointers using this driver */ + for (tmp = kdPointerDrivers; tmp; tmp = tmp->next) { + if (tmp->next == driver) + tmp->next = driver->next; + } + if (tmp == driver) + tmp = NULL; } void -KdInitInput(KdMouseFuncs *pMouseFuncs, - KdKeyboardFuncs *pKeyboardFuncs) +KdAddKeyboardDriver (KdKeyboardDriver *driver) { - DeviceIntPtr pKeyboard, pPointer; - KdMouseInfo *mi; + KdKeyboardDriver **prev; + + if (!driver) + return; + + for (prev = &kdKeyboardDrivers; *prev; prev = &(*prev)->next) { + if (*prev == driver) + return; + } + *prev = driver; +} + +void +KdRemoveKeyboardDriver (KdKeyboardDriver *driver) +{ + KdKeyboardDriver *tmp; + + if (!driver) + return; + + /* FIXME remove all keyboards using this driver */ + for (tmp = kdKeyboardDrivers; tmp; tmp = tmp->next) { + if (tmp->next == driver) + tmp->next = driver->next; + } + if (tmp == driver) + tmp = NULL; +} + +KdKeyboardInfo * +KdNewKeyboard (void) +{ + KdKeyboardInfo *ki = xcalloc(sizeof(KdKeyboardInfo), 1); + + if (!ki) + return NULL; - if (!kdMouseInfo) - KdParseMouse (0); - kdMouseButtonCount = 0; - for (mi = kdMouseInfo; mi; mi = mi->next) - { - if (mi->nbutton > kdMouseButtonCount) - kdMouseButtonCount = mi->nbutton; - } - - kdNMouseFuncs = 0; - KdAddMouseDriver (pMouseFuncs); - kdKeyboardFuncs = pKeyboardFuncs; - memset (kdKeyState, '\0', sizeof (kdKeyState)); - if (kdKeyboardFuncs) - (*kdKeyboardFuncs->Load) (); - kdMinKeyCode = kdMinScanCode + KD_KEY_OFFSET; - kdMaxKeyCode = kdMaxScanCode + KD_KEY_OFFSET; - kdKeySyms.map = kdKeymap; - kdKeySyms.minKeyCode = kdMinKeyCode; - kdKeySyms.maxKeyCode = kdMaxKeyCode; - kdKeySyms.mapWidth = kdKeymapWidth; - kdLeds = 0; - kdBellPitch = 1000; - kdBellDuration = 200; - kdInputEnabled = TRUE; - KdInitModMap (); - KdInitAutoRepeats (); - KdResetInputMachine (); - pPointer = AddInputDevice(KdMouseProc, TRUE); - pKeyboard = AddInputDevice(KdKeybdProc, TRUE); - RegisterPointerDevice(pPointer); - RegisterKeyboardDevice(pKeyboard); - miRegisterPointerDevice(screenInfo.screens[0], pPointer); - mieqInit(&pKeyboard->public, &pPointer->public); + ki->keySyms.map = (KeySym *)xcalloc(sizeof(KeySym), + KD_MAX_LENGTH * + kdDefaultKeySyms.mapWidth); + if (!ki->keySyms.map) { + xfree(ki); + return NULL; + } + + memcpy(ki->keySyms.map, kdDefaultKeySyms.map, + sizeof(KeySym) * (KD_MAX_LENGTH * kdDefaultKeySyms.mapWidth)); + ki->keySyms.minKeyCode = kdDefaultKeySyms.minKeyCode; + ki->keySyms.maxKeyCode = kdDefaultKeySyms.maxKeyCode; + ki->keySyms.mapWidth = kdDefaultKeySyms.mapWidth; + ki->minScanCode = 0; + ki->maxScanCode = 0; + ki->leds = 0; + ki->bellPitch = 1000; + ki->bellDuration = 200; + ki->next = NULL; + ki->options = NULL; + + return ki; +} + +int +KdAddConfigKeyboard (char *keyboard) +{ + struct KdConfigDevice **prev, *new; + + if (!keyboard) + return Success; + + new = (struct KdConfigDevice *) xcalloc(sizeof(struct KdConfigDevice), 1); + if (!new) + return BadAlloc; + + new->line = xstrdup(keyboard); + new->next = NULL; + + for (prev = &kdConfigKeyboards; *prev; prev = &(*prev)->next); + *prev = new; + + return Success; +} + +int +KdAddKeyboard (KdKeyboardInfo *ki) +{ + KdKeyboardInfo **prev; + + if (!ki) + return !Success; + + ki->dixdev = AddInputDevice(KdKeyboardProc, TRUE); + if (!ki->dixdev) { + ErrorF("Couldn't register keyboard device %s\n", + ki->name ? ki->name : "(unnamed)"); + return !Success; + } + #ifdef XINPUT - { - static long zero1, zero2; + RegisterOtherDevice(ki->dixdev); +#endif + +#ifdef DEBUG + ErrorF("added keyboard %s with dix id %d\n", ki->name, ki->dixdev->id); +#endif + + for (prev = &kdKeyboards; *prev; prev = &(*prev)->next); + *prev = ki; + + return Success; +} + +void +KdRemoveKeyboard (KdKeyboardInfo *ki) +{ + KdKeyboardInfo **prev; + + if (!ki) + return; - //SetExtInputCheck (&zero1, &zero2); - ErrorF("Extended Input Devices not yet supported. Impelement it at line %d in %s\n", - __LINE__, __FILE__); + for (prev = &kdKeyboards; *prev; prev = &(*prev)->next) { + if (*prev == ki) { + *prev = ki->next; + break; + } } + + KdFreeKeyboard(ki); +} + +int +KdAddConfigPointer (char *pointer) +{ + struct KdConfigDevice **prev, *new; + + if (!pointer) + return Success; + + new = (struct KdConfigDevice *) xcalloc(sizeof(struct KdConfigDevice), 1); + if (!new) + return BadAlloc; + + new->line = xstrdup(pointer); + new->next = NULL; + + for (prev = &kdConfigPointers; *prev; prev = &(*prev)->next); + *prev = new; + + return Success; +} + +int +KdAddPointer (KdPointerInfo *pi) +{ + KdPointerInfo **prev; + + if (!pi) + return Success; + + pi->mouseState = start; + pi->eventHeld = FALSE; + + pi->dixdev = AddInputDevice(KdPointerProc, TRUE); + if (!pi->dixdev) { + ErrorF("Couldn't add pointer device %s\n", + pi->name ? pi->name : "(unnamed)"); + return BadDevice; + } + +#ifdef XINPUT + RegisterOtherDevice(pi->dixdev); +#endif + + for (prev = &kdPointers; *prev; prev = &(*prev)->next); + *prev = pi; + + return Success; +} + +void +KdRemovePointer (KdPointerInfo *pi) +{ + KdPointerInfo **prev; + + if (!pi) + return; + + for (prev = &kdPointers; *prev; prev = &(*prev)->next) { + if (*prev == pi) { + *prev = pi->next; + break; + } + } + + KdFreePointer(pi); +} + +KdKeyboardInfo * +KdParseKeyboard (char *arg) +{ + char save[1024]; + char delim; + KdKeyboardInfo *ki = NULL; + + ki = KdNewKeyboard(); + if (!ki) + return NULL; + + ki->name = strdup("Unknown KDrive Keyboard"); + ki->path = NULL; + ki->driver = NULL; + ki->driverPrivate = NULL; +#ifdef XKB + ki->xkb = NULL; #endif + ki->next = NULL; + + if (!arg) + { + ErrorF("keybd: no arg\n"); + KdFreeKeyboard (ki); + return NULL; + } + + if (strlen (arg) >= sizeof (save)) + { + ErrorF("keybd: arg too long\n"); + KdFreeKeyboard (ki); + return NULL; + } + + arg = KdParseFindNext (arg, ",", save, &delim); + if (!save[0]) + { + ErrorF("keybd: failed on save[0]\n"); + KdFreeKeyboard (ki); + return NULL; + } + + if (strcmp (save, "auto") == 0) + ki->driverPrivate = NULL; + else + ki->driverPrivate = xstrdup(save); + + /* FIXME actually implement options */ + + return ki; +} + +KdPointerInfo * +KdParsePointer (char *arg) +{ + char save[1024]; + char delim; + KdPointerInfo *pi = NULL; + InputOption *options = NULL, *newopt = NULL, **tmpo = NULL; + int i = 0; + + pi = KdNewPointer(); + if (!pi) + return NULL; + pi->emulateMiddleButton = kdEmulateMiddleButton; + pi->transformCoordinates = !kdRawPointerCoordinates; + pi->nButtons = 3; + pi->inputClass = KD_MOUSE; + + for (i = 0; i < KD_MAX_BUTTON; i++) + pi->map[i] = i + 1; + + if (!arg) + { + ErrorF("mouse: no arg\n"); + KdFreePointer (pi); + return NULL; + } + + if (strlen (arg) >= sizeof (save)) + { + ErrorF("mouse: arg too long\n"); + KdFreePointer (pi); + return NULL; + } + arg = KdParseFindNext (arg, ",", save, &delim); + if (!save[0]) + { + ErrorF("failed on save[0]\n"); + KdFreePointer (pi); + return NULL; + } + + if (strcmp(save, "auto") == 0) + pi->driverPrivate = NULL; + else + pi->driverPrivate = xstrdup(save); + + if (delim != ',') + { + return pi; + } + + arg = KdParseFindNext (arg, ",", save, &delim); + + while (delim == ',') + { + arg = KdParseFindNext (arg, ",", save, &delim); + if (save[0] == '{') + { + char *s = save + 1; + i = 0; + while (*s && *s != '}') + { + if ('1' <= *s && *s <= '0' + pi->nButtons) + pi->map[i] = *s - '0'; + else + UseMsg (); + s++; + } + } + else if (!strcmp (save, "emulatemiddle")) + pi->emulateMiddleButton = TRUE; + else if (!strcmp (save, "noemulatemiddle")) + pi->emulateMiddleButton = FALSE; + else if (!strcmp (save, "transformcoord")) + pi->transformCoordinates = TRUE; + else if (!strcmp (save, "rawcoord")) + pi->transformCoordinates = FALSE; + else + { + newopt = (InputOption *) xalloc(sizeof (InputOption)); + if (!newopt) + { + KdFreePointer(pi); + return NULL; + } + bzero(newopt, sizeof (InputOption)); + + for (tmpo = &options; *tmpo; tmpo = &(*tmpo)->next) + *tmpo = newopt; + + if (strchr(arg, '=')) + { + i = (strchr(arg, '=') - arg); + newopt->key = (char *)xalloc(i+1); + strncpy(newopt->key, arg, i+1); + newopt->value = xstrdup(strchr(arg, '=') + 1); + } + else + { + newopt->key = xstrdup(save); + newopt->value = NULL; + } + newopt->next = NULL; + } + } + + if (options) + pi->options = options; + + return pi; +} + + +void +KdInitInput (void) +{ + KdPointerInfo *pi; + KdKeyboardInfo *ki; + struct KdConfigDevice *dev; + int i = 0; + + kdInputEnabled = TRUE; + + for (dev = kdConfigPointers; dev; dev = dev->next) { + pi = KdParsePointer(dev->line); + if (!pi) + ErrorF("Failed to parse pointer\n"); + if (KdAddPointer(pi) != Success) + ErrorF("Failed to add pointer!\n"); + } + for (dev = kdConfigKeyboards; dev; dev = dev->next) { + ki = KdParseKeyboard(dev->line); + if (!ki) + ErrorF("Failed to parse keyboard\n"); + if (KdAddKeyboard(ki) != Success) + ErrorF("Failed to add keyboard!\n"); + } + + mieqInit(NULL, NULL); } /* @@ -786,7 +1442,7 @@ typedef enum _inputAction { typedef struct _inputTransition { KdInputAction actions[MAX_ACTIONS]; - KdMouseState nextState; + KdPointerState nextState; } KdInputTransition; static const @@ -931,32 +1587,22 @@ KdInputTransition kdInputMachine[num_input_states][num_input_class] = { #define EMULATION_WINDOW 10 #define EMULATION_TIMEOUT 100 -#define EventX(e) ((e)->u.keyButtonPointer.rootX) -#define EventY(e) ((e)->u.keyButtonPointer.rootY) - static int -KdInsideEmulationWindow (KdMouseInfo *mi, xEvent *ev) +KdInsideEmulationWindow (KdPointerInfo *pi, int x, int y, int z) { - if (ev->u.keyButtonPointer.pad1) - { - mi->emulationDx += EventX(ev); - mi->emulationDy += EventY(ev); - } - else - { - mi->emulationDx = EventX(&mi->heldEvent) - EventX(ev); - mi->emulationDy = EventY(&mi->heldEvent) - EventY(ev); - } - return (abs (mi->emulationDx) < EMULATION_WINDOW && - abs (mi->emulationDy) < EMULATION_WINDOW); + pi->emulationDx = pi->heldEvent.x - x; + pi->emulationDy = pi->heldEvent.y - y; + + return (abs (pi->emulationDx) < EMULATION_WINDOW && + abs (pi->emulationDy) < EMULATION_WINDOW); } static KdInputClass -KdClassifyInput (KdMouseInfo *mi, xEvent *ev) +KdClassifyInput (KdPointerInfo *pi, int type, int x, int y, int z, int b) { - switch (ev->u.u.type) { + switch (type) { case ButtonPress: - switch (ev->u.u.detail) { + switch (b) { case 1: return down_1; case 2: return down_2; case 3: return down_3; @@ -964,7 +1610,7 @@ KdClassifyInput (KdMouseInfo *mi, xEvent *ev) } break; case ButtonRelease: - switch (ev->u.u.detail) { + switch (b) { case 1: return up_1; case 2: return up_2; case 3: return up_3; @@ -972,7 +1618,7 @@ KdClassifyInput (KdMouseInfo *mi, xEvent *ev) } break; case MotionNotify: - if (mi->eventHeld && !KdInsideEmulationWindow(mi, ev)) + if (pi->eventHeld && !KdInsideEmulationWindow(pi, x, y, z)) return outside_box; else return motion; @@ -1021,116 +1667,98 @@ static void KdQueueEvent (xEvent *ev) { KdAssertSigioBlocked ("KdQueueEvent"); - if (ev->u.u.type == MotionNotify) - { - if (ev->u.keyButtonPointer.pad1) - { - ev->u.keyButtonPointer.pad1 = 0; - miPointerDeltaCursor (ev->u.keyButtonPointer.rootX, - ev->u.keyButtonPointer.rootY, - ev->u.keyButtonPointer.time); - } - else - { - miPointerAbsoluteCursor(ev->u.keyButtonPointer.rootX, - ev->u.keyButtonPointer.rootY, - ev->u.keyButtonPointer.time); - } - } - else - { - mieqEnqueue (ev); - } + mieqEnqueue (ev); } -static void -KdRunMouseMachine (KdMouseInfo *mi, KdInputClass c, xEvent *ev) +/* We return true if we're stealing the event. */ +static Bool +KdRunMouseMachine (KdPointerInfo *pi, KdInputClass c, int type, int x, int y, + int z, int b, int absrel) { const KdInputTransition *t; - int a; + int a; - t = &kdInputMachine[mi->mouseState][c]; + c = KdClassifyInput(pi, type, x, y, z, b); + t = &kdInputMachine[pi->mouseState][c]; for (a = 0; a < MAX_ACTIONS; a++) { switch (t->actions[a]) { case noop: break; case hold: - mi->eventHeld = TRUE; - mi->emulationDx = 0; - mi->emulationDy = 0; - mi->heldEvent = *ev; + pi->eventHeld = TRUE; + pi->emulationDx = 0; + pi->emulationDy = 0; + pi->heldEvent.type = type; + pi->heldEvent.x = x; + pi->heldEvent.y = y; + pi->heldEvent.z = z; + pi->heldEvent.flags = b; + pi->heldEvent.absrel = absrel; + return TRUE; break; case setto: - mi->emulationTimeout = GetTimeInMillis () + EMULATION_TIMEOUT; - mi->timeoutPending = TRUE; + pi->emulationTimeout = GetTimeInMillis () + EMULATION_TIMEOUT; + pi->timeoutPending = TRUE; break; case deliver: - KdQueueEvent (ev); + _KdEnqueuePointerEvent (pi, pi->heldEvent.type, pi->heldEvent.x, + pi->heldEvent.y, pi->heldEvent.z, + pi->heldEvent.flags, pi->heldEvent.absrel, + TRUE); break; case release: - mi->eventHeld = FALSE; - mi->timeoutPending = FALSE; - KdQueueEvent (&mi->heldEvent); + pi->eventHeld = FALSE; + pi->timeoutPending = FALSE; + _KdEnqueuePointerEvent (pi, pi->heldEvent.type, pi->heldEvent.x, + pi->heldEvent.y, pi->heldEvent.z, + pi->heldEvent.flags, pi->heldEvent.absrel, + TRUE); + return TRUE; break; case clearto: - mi->timeoutPending = FALSE; + pi->timeoutPending = FALSE; break; case gen_down_2: - ev->u.u.detail = 2; - mi->eventHeld = FALSE; - KdQueueEvent (ev); + _KdEnqueuePointerEvent (pi, ButtonPress, x, y, z, 2, absrel, + TRUE); + pi->eventHeld = FALSE; + return TRUE; break; case gen_up_2: - ev->u.u.detail = 2; - KdQueueEvent (ev); + _KdEnqueuePointerEvent (pi, ButtonRelease, x, y, z, 2, absrel, + TRUE); + return TRUE; break; } } - mi->mouseState = t->nextState; -} - -void -KdResetInputMachine (void) -{ - KdMouseInfo *mi; - - for (mi = kdMouseInfo; mi; mi = mi->next) - { - mi->mouseState = start; - mi->eventHeld = FALSE; - } + pi->mouseState = t->nextState; + return FALSE; } -static void -KdHandleMouseEvent (KdMouseInfo *mi, xEvent *ev) +static int +KdHandlePointerEvent (KdPointerInfo *pi, int type, int x, int y, int z, int b, + int absrel) { - if (mi->emulateMiddleButton) - KdRunMouseMachine (mi, KdClassifyInput (mi, ev), ev); - else - KdQueueEvent (ev); + if (pi->emulateMiddleButton) + return KdRunMouseMachine (pi, KdClassifyInput(pi, type, x, y, z, b), + type, x, y, z, b, absrel); + return FALSE; } static void -KdReceiveTimeout (KdMouseInfo *mi) +KdReceiveTimeout (KdPointerInfo *pi) { - KdRunMouseMachine (mi, timeout, 0); + KdRunMouseMachine (pi, timeout, 0, 0, 0, 0, 0, 0); } -#define KILL_SEQUENCE ((1L << KK_CONTROL)|(1L << KK_ALT)|(1L << KK_F8)|(1L << KK_F10)) -#define SPECIAL_SEQUENCE ((1L << KK_CONTROL) | (1L << KK_ALT)) -#define SETKILLKEY(b) (KdSpecialKeys |= (1L << (b))) -#define CLEARKILLKEY(b) (KdSpecialKeys &= ~(1L << (b))) -#define KEYMAP (pKdKeyboard->key->curKeySyms) -#define KEYCOL1(k) (KEYMAP.map[((k)-kdMinKeyCode)*KEYMAP.mapWidth]) +#define KILL_SEQUENCE ((1L << KK_CONTROL)|(1L << KK_ALT)|(1L << KK_F8)|(1L << KK_F10)) +#define SPECIAL_SEQUENCE ((1L << KK_CONTROL) | (1L << KK_ALT)) +#define SETKILLKEY(b) (KdSpecialKeys |= (1L << (b))) +#define CLEARKILLKEY(b) (KdSpecialKeys &= ~(1L << (b))) CARD32 KdSpecialKeys = 0; -#if 0 -/* already defined in opaque.h */ -extern char dispatchException; -#endif - /* * kdCheckTermination * @@ -1145,44 +1773,28 @@ extern char dispatchException; extern int nClients; static void -KdCheckSpecialKeys(xEvent *xE) +KdCheckSpecialKeys(KdKeyboardInfo *ki, int type, int sym) { - KeySym sym = KEYCOL1(xE->u.u.detail); - - if (!pKdKeyboard) return; + if (!ki) + return; /* * Ignore key releases */ - - if (xE->u.u.type == KeyRelease) return; -#ifdef XIPAQ - /* - * Check for buttons 1, 2 and 3 on the iPAQ - */ - if (sym == XK_Pointer_Button1 && kdMouseInfo) { - KdEnqueueMouseEvent(kdMouseInfo, KD_MOUSE_DELTA | KD_BUTTON_1, 0, 0); - return; - } - if (sym == XK_Pointer_Button2 && kdMouseInfo) { - KdEnqueueMouseEvent(kdMouseInfo, KD_MOUSE_DELTA | KD_BUTTON_2, 0, 0); - return; - } - if (sym == XK_Pointer_Button3 && kdMouseInfo) { - KdEnqueueMouseEvent(kdMouseInfo, KD_MOUSE_DELTA | KD_BUTTON_3, 0, 0); - return; - } -#endif + if (type == KeyRelease) + return; + + /* Some iPaq keyboard -> mouse button mapping used to be here, but I + * refuse to perpetuate this madness. -daniels */ /* * Check for control/alt pressed */ - if ((pKdKeyboard->key->state & (ControlMask|Mod1Mask)) != + if ((ki->dixdev->key->state & (ControlMask|Mod1Mask)) != (ControlMask|Mod1Mask)) return; - - + /* * Let OS function see keysym first */ @@ -1194,6 +1806,8 @@ KdCheckSpecialKeys(xEvent *xE) /* * Now check for backspace or delete; these signal the * X server to terminate + * + * I can't believe it's not XKB. -daniels */ switch (sym) { case XK_BackSpace: @@ -1219,150 +1833,164 @@ KdCheckSpecialKeys(xEvent *xE) */ static void -KdHandleKeyboardEvent (xEvent *ev) +KdHandleKeyboardEvent (KdKeyboardInfo *ki, int type, int key) { - int key = ev->u.u.detail; - int byte; - CARD8 bit; - KdMouseInfo *mi; + int byte; + CARD8 bit; + KdPointerInfo *pi; byte = key >> 3; bit = 1 << (key & 7); - switch (ev->u.u.type) { + + switch (type) { case KeyPress: - kdKeyState[byte] |= bit; + ki->keyState[byte] |= bit; break; case KeyRelease: - kdKeyState[byte] &= ~bit; + ki->keyState[byte] &= ~bit; break; } - for (mi = kdMouseInfo; mi; mi = mi->next) - KdRunMouseMachine (mi, keyboard, 0); - KdQueueEvent (ev); + + for (pi = kdPointers; pi; pi = pi->next) + KdRunMouseMachine (pi, keyboard, 0, 0, 0, 0, 0, 0); } void KdReleaseAllKeys (void) { - xEvent xE; - int key; + xEvent *xE; + int key, nEvents, i; + KdKeyboardInfo *ki; KdBlockSigio (); - for (key = 0; key < KD_KEY_COUNT; key++) - if (IsKeyDown(key)) - { - xE.u.keyButtonPointer.time = GetTimeInMillis(); - xE.u.u.type = KeyRelease; - xE.u.u.detail = key; - KdHandleKeyboardEvent (&xE); - } + + for (ki = kdKeyboards; ki; ki = ki->next) { + for (key = ki->keySyms.minKeyCode; key < ki->keySyms.maxKeyCode; + key++) { + if (IsKeyDown(ki, key)) { + KdHandleKeyboardEvent(ki, KeyRelease, key); + nEvents = GetKeyboardEvents(&xE, ki->dixdev, KeyRelease, key); + for (i = 0; i < nEvents; i++) + KdQueueEvent (xE++); + } + } + } + KdUnblockSigio (); } static void KdCheckLock (void) { - KeyClassPtr keyc = pKdKeyboard->key; - Bool isSet, shouldBeSet; - - if (kdKeyboardFuncs->LockLed) - { - isSet = (kdLeds & (1 << (kdKeyboardFuncs->LockLed-1))) != 0; - shouldBeSet = (keyc->state & LockMask) != 0; - if (isSet != shouldBeSet) - { - KdSetLed (kdKeyboardFuncs->LockLed, shouldBeSet); - } + KeyClassPtr keyc = NULL; + Bool isSet = FALSE, shouldBeSet = FALSE; + KdKeyboardInfo *tmp = NULL; + + for (tmp = kdKeyboards; tmp; tmp = tmp->next) { + if (tmp->LockLed && tmp->dixdev && tmp->dixdev->key) { + keyc = tmp->dixdev->key; + isSet = (tmp->leds & (1 << (tmp->LockLed-1))) != 0; + shouldBeSet = (keyc->state & LockMask) != 0; + if (isSet != shouldBeSet) + KdSetLed (tmp, tmp->LockLed, shouldBeSet); + } } } void -KdEnqueueKeyboardEvent(unsigned char scan_code, - unsigned char is_up) +KdEnqueueKeyboardEvent(KdKeyboardInfo *ki, + unsigned char scan_code, + unsigned char is_up) { - unsigned char key_code; - xEvent xE; - KeyClassPtr keyc; - - if (!pKdKeyboard) + unsigned char key_code; + KeyClassPtr keyc = NULL; + KeybdCtrl *ctrl = NULL; + int type, nEvents, i; + xEvent *xE = NULL; + +#ifdef DEBUG + ErrorF("enqueuing kb event (scancode %d, %s)\n", scan_code, is_up ? "up" : "down"); + ErrorF("event is from %s\n", ki->name); +#endif + + if (!ki || !ki->dixdev || !ki->dixdev->kbdfeed || !ki->dixdev->key) return; - keyc = pKdKeyboard->key; - xE.u.keyButtonPointer.time = GetTimeInMillis(); + keyc = ki->dixdev->key; + ctrl = &ki->dixdev->kbdfeed->ctrl; - if (kdMinScanCode <= scan_code && scan_code <= kdMaxScanCode) + if (scan_code >= ki->minScanCode && scan_code <= ki->maxScanCode) { - key_code = scan_code + KD_MIN_KEYCODE - kdMinScanCode; + key_code = scan_code + KD_MIN_KEYCODE - ki->minScanCode; /* * Set up this event -- the type may be modified below */ if (is_up) - xE.u.u.type = KeyRelease; + type = KeyRelease; else - xE.u.u.type = KeyPress; - xE.u.u.detail = key_code; + type = KeyPress; - switch (KEYCOL1(key_code)) + /* HRNGH */ + switch (KEYCOL1(ki, key_code)) { case XK_Num_Lock: case XK_Scroll_Lock: case XK_Shift_Lock: case XK_Caps_Lock: - if (xE.u.u.type == KeyRelease) + if (type == KeyRelease) return; - if (IsKeyDown (key_code)) - xE.u.u.type = KeyRelease; + if (IsKeyDown (ki, key_code)) + type = KeyRelease; else - xE.u.u.type = KeyPress; + type = KeyPress; } /* * Check pressed keys which are already down */ - if (IsKeyDown (key_code) && xE.u.u.type == KeyPress) - { - KeybdCtrl *ctrl = &pKdKeyboard->kbdfeed->ctrl; - + if (IsKeyDown (ki, key_code) && type == KeyPress) { /* * Check auto repeat */ if (!ctrl->autoRepeat || keyc->modifierMap[key_code] || !(ctrl->autoRepeats[key_code >> 3] & (1 << (key_code & 7)))) - { return; - } + /* * X delivers press/release even for autorepeat */ - xE.u.u.type = KeyRelease; - KdHandleKeyboardEvent (&xE); - xE.u.u.type = KeyPress; + nEvents = GetKeyboardEvents(&xE, ki->dixdev, KeyRelease, key_code); + for (i = 0; i < nEvents; i++) + KdQueueEvent(xE++); + nEvents = GetKeyboardEvents(&xE, ki->dixdev, KeyPress, key_code); + for (i = 0; i < nEvents; i++) + KdQueueEvent(xE++); } /* * Check released keys which are already up */ - else if (!IsKeyDown (key_code) && xE.u.u.type == KeyRelease) - { + else if (!IsKeyDown (ki, key_code) && type == KeyRelease) { return; - } - KdCheckSpecialKeys (&xE); - KdHandleKeyboardEvent (&xE); - } -} + } -#define SetButton(mi, b, v, s) \ -{\ - xE.u.u.detail = mi->map[b]; \ - xE.u.u.type = v; \ - KdHandleMouseEvent (mi, &xE); \ + KdCheckSpecialKeys(ki, type, key_code); + KdHandleKeyboardEvent(ki, type, key_code); + nEvents = GetKeyboardEvents(&xE, ki->dixdev, type, key_code); +#ifdef DEBUG + ErrorF("KdEnqueueKeyboardEvent: got %d events from GKE\n", nEvents); +#endif + for (i = 0; i < nEvents; i++) + KdQueueEvent(xE++); + } + else { + ErrorF("driver %s wanted to post scancode %d outside of [%d, %d]!\n", + ki->name, scan_code, ki->minScanCode, ki->maxScanCode); + } } -#define Press(mi, b) SetButton(mi, b, ButtonPress, "Down") -#define Release(mi, b) SetButton(mi, b, ButtonRelease, "Up") - /* - * kdEnqueueMouseEvent + * kdEnqueuePointerEvent * * This function converts hardware mouse event information into X event * information. A mouse movement event is passed off to MI to generate @@ -1371,8 +1999,9 @@ KdEnqueueKeyboardEvent(unsigned char scan_code, */ static void -KdMouseAccelerate (DeviceIntPtr device, int *dx, int *dy) +KdMouseAccelerate (KdPointerInfo *pi, int *dx, int *dy) { + DeviceIntPtr device = pi->dixdev; PtrCtrl *pCtrl = &device->ptrfeed->ctrl; double speed = sqrt (*dx * *dx + *dy * *dy); double accel; @@ -1402,92 +2031,111 @@ KdMouseAccelerate (DeviceIntPtr device, int *dx, int *dy) *dy = accel * *dy; } +/* FIXME do something a little more clever to deal with multiple axes here */ void -KdEnqueueMouseEvent(KdMouseInfo *mi, unsigned long flags, int rx, int ry) +KdEnqueuePointerEvent(KdPointerInfo *pi, unsigned long flags, int rx, int ry, + int rz) { - CARD32 ms; - xEvent xE; - unsigned char buttons; - int x, y; - int (*matrix)[3] = kdMouseMatrix.matrix; - unsigned long button; - int n; - - if (!pKdPointer) + CARD32 ms; + unsigned char buttons; + int x, y, z; + int (*matrix)[3] = kdPointerMatrix.matrix; + unsigned long button; + int n; + int dixflags; + + if (!pi) return; ms = GetTimeInMillis(); - - if (flags & KD_MOUSE_DELTA) - { - if (mi->transformCoordinates) - { + + /* we don't need to transform z, so we don't. */ + if (flags & KD_MOUSE_DELTA) { + if (pi->transformCoordinates) { x = matrix[0][0] * rx + matrix[0][1] * ry; y = matrix[1][0] * rx + matrix[1][1] * ry; } - else - { + else { x = rx; y = ry; } - KdMouseAccelerate (pKdPointer, &x, &y); - xE.u.keyButtonPointer.pad1 = 1; + /* screw this, use the DIX's acceleration (stolen from XFree86) + * instead. + * KdMouseAccelerate (pi, &x, &y); */ } - else - { - if (mi->transformCoordinates) - { - x = matrix[0][0] * rx + matrix[0][1] * ry + matrix[0][2]; - y = matrix[1][0] * rx + matrix[1][1] * ry + matrix[1][2]; + else { + if (pi->transformCoordinates) { + x = matrix[0][0] * rx + matrix[0][1] * ry; + y = matrix[1][0] * rx + matrix[1][1] * ry; } - else - { + else { x = rx; y = ry; } - xE.u.keyButtonPointer.pad1 = 0; } - xE.u.keyButtonPointer.time = ms; - xE.u.keyButtonPointer.rootX = x; - xE.u.keyButtonPointer.rootY = y; + z = rz; - xE.u.u.type = MotionNotify; - xE.u.u.detail = 0; - KdHandleMouseEvent (mi, &xE); +#ifdef DEBUG + ErrorF("sending motion notification for (%d, %d, %d)\n", x, y, z); + ErrorF(" comes from (%d, %d, %d)\n", rx, ry, rz); + ErrorF(" is %s\n", (flags & KD_MOUSE_DELTA) ? "relative" : "absolute"); +#endif + + if (flags & KD_MOUSE_DELTA) + dixflags = POINTER_RELATIVE & POINTER_ACCELERATE; + else + dixflags = POINTER_ABSOLUTE; + + _KdEnqueuePointerEvent(pi, MotionNotify, x, y, z, 0, dixflags, FALSE); buttons = flags; - for (button = KD_BUTTON_1, n = 0; button <= KD_BUTTON_5; button <<= 1, n++) - { - if ((mi->buttonState & button) ^ (buttons & button)) - { - if (buttons & button) - { - Press(mi, n); - } - else - { - Release(mi, n); - } + for (button = KD_BUTTON_1, n = 1; button <= pi->nButtons; + button <<= 1, n++) { + if (((pi->buttonState & button) ^ (buttons & button)) && + !(buttons & button)) { +#ifdef DEBUG + ErrorF(" posting button release %d\n", n); +#endif + _KdEnqueuePointerEvent(pi, ButtonRelease, x, y, z, n, + dixflags, FALSE); } } - mi->buttonState = buttons; + for (button = KD_BUTTON_1, n = 1; button <= pi->nButtons; + button <<= 1, n++) { + if (((pi->buttonState & button) ^ (buttons & button)) && + (buttons & button)) { +#ifdef DEBUG + ErrorF(" posting button press %d\n", n); +#endif + _KdEnqueuePointerEvent(pi, ButtonPress, x, y, z, n, + dixflags, FALSE); + } + } + + pi->buttonState = buttons; } void -KdEnqueueMotionEvent (KdMouseInfo *mi, int x, int y) +_KdEnqueuePointerEvent (KdPointerInfo *pi, int type, int x, int y, int z, + int b, int absrel, Bool force) { - xEvent xE; - CARD32 ms; - - ms = GetTimeInMillis(); - - xE.u.u.type = MotionNotify; - xE.u.keyButtonPointer.time = ms; - xE.u.keyButtonPointer.rootX = x; - xE.u.keyButtonPointer.rootY = y; + xEvent *xE = NULL; + int n = 0, i = 0; + int valuators[3] = { x, y, z }; + +#ifdef DEBUG + ErrorF("mouse enqueuing event from device %s (%d, %d, %d; %d)\n", + pi->name, x, y, z, b); +#endif + + /* TRUE from KdHandlePointerEvent, means 'we swallowed the event'. */ + if (!force && KdHandlePointerEvent(pi, type, x, y, z, b, absrel)) + return; - KdHandleMouseEvent (mi, &xE); + n = GetPointerEvents(&xE, pi->dixdev, type, b, absrel, 3, valuators); + for (i = 0; i < n; i++) + KdQueueEvent(xE++); } void @@ -1496,16 +2144,16 @@ KdBlockHandler (int screen, pointer timeout, pointer readmask) { - KdMouseInfo *mi; + KdPointerInfo *pi; int myTimeout=0; - for (mi = kdMouseInfo; mi; mi = mi->next) + for (pi = kdPointers; pi; pi = pi->next) { - if (mi->timeoutPending) + if (pi->timeoutPending) { int ms; - ms = mi->emulationTimeout - GetTimeInMillis (); + ms = pi->emulationTimeout - GetTimeInMillis (); if (ms < 1) ms = 1; if(ms<myTimeout || myTimeout==0) @@ -1531,7 +2179,7 @@ KdWakeupHandler (int screen, int result = (int) lresult; fd_set *pReadmask = (fd_set *) readmask; int i; - KdMouseInfo *mi; + KdPointerInfo *pi; if (kdInputEnabled && result > 0) { @@ -1543,15 +2191,15 @@ KdWakeupHandler (int screen, KdUnblockSigio (); } } - for (mi = kdMouseInfo; mi; mi = mi->next) + for (pi = kdPointers; pi; pi = pi->next) { - if (mi->timeoutPending) + if (pi->timeoutPending) { - if ((long) (GetTimeInMillis () - mi->emulationTimeout) >= 0) + if ((long) (GetTimeInMillis () - pi->emulationTimeout) >= 0) { - mi->timeoutPending = FALSE; + pi->timeoutPending = FALSE; KdBlockSigio (); - KdReceiveTimeout (mi); + KdReceiveTimeout (pi); KdUnblockSigio (); } } @@ -1686,3 +2334,156 @@ ProcessInputEvents () KdProcessSwitch (); KdCheckLock (); } + +/* We don't want to allow people to change the core devices, because the DIX + * does magical repeating goodness for us. */ +int +ChangeKeyboardDevice(DeviceIntPtr pOldDev, DeviceIntPtr pDev) +{ + return BadDevice; +} + +int +ChangePointerDevice(DeviceIntPtr pOldDev, DeviceIntPtr pDev, int x, int y) +{ + return BadDevice; +} + +/* FIXME use XSECURITY to work out whether the client should be allowed to + * open and close. */ +void +OpenInputDevice(DeviceIntPtr pDev, ClientPtr client, int *status) +{ + if (!pDev) + *status = BadDevice; + else + *status = Success; +} + +int +CloseInputDevice(DeviceIntPtr pDev, ClientPtr client) +{ + if (!pDev) + return BadDevice; + + return Success; +} + +/* We initialise all input devices at startup. */ +int +AddOtherInputDevices(void) +{ + return Success; +} + +/* At the moment, absolute/relative is up to the client. */ +int +SetDeviceMode(register ClientPtr client, DeviceIntPtr pDev, int mode) +{ + return BadMatch; +} + +int +SetDeviceValuators(register ClientPtr client, DeviceIntPtr pDev, + int *valuators, int first_valuator, int num_valuators) +{ + return BadMatch; +} + +int +ChangeDeviceControl(register ClientPtr client, DeviceIntPtr pDev, + xDeviceCtl *control) +{ + switch (control->control) { + case DEVICE_RESOLUTION: + /* FIXME do something more intelligent here */ + return BadMatch; + + case DEVICE_TOUCHSCREEN: + if (!pDev->touchscreen) + return BadDevice; + else + return Success; + + case DEVICE_CORE: + return Success; + + default: + return BadMatch; + } + + /* NOTREACHED */ + return BadImplementation; +} + +int +NewInputDeviceRequest(InputOption *options) +{ + InputOption *option = NULL; + KdPointerInfo *pi = NULL; + KdKeyboardInfo *ki = NULL; + + ErrorF("handling NIDR\n"); + + for (option = options; option; option = option->next) { + if (strcmp(option->key, "type") == 0) { + if (strcmp(option->value, "pointer") == 0) { + pi = KdNewPointer(); + if (!pi) + return BadAlloc; + pi->options = options; + } + else if (strcmp(option->value, "keyboard") == 0) { + ki = KdNewKeyboard(); + if (!ki) + return BadAlloc; + ki->options = options; + } + else { + ErrorF("unrecognised device type!\n"); + return BadValue; + } + } + } + + for (option = options; option; option = option->next) { + ErrorF("option '%s': '%s'\n", option->key, option->value); + if (strcmp(option->key, "driver") == 0) { + if (pi) { + pi->driver = KdFindPointerDriver(option->value); + if (!pi->driver) { + ErrorF("couldn't find driver!\n"); + KdFreePointer(pi); + return BadValue; + } + } + else if (ki) { + ki->driver = KdFindKeyboardDriver(option->value); + if (!ki->driver) { + ErrorF("couldn't find driver!\n"); + KdFreeKeyboard(ki); + return BadValue; + } + } + } + } + + if (pi) { + if (KdAddPointer(pi) != Success || + ActivateDevice(pi->dixdev) != Success || + EnableDevice(pi->dixdev) != TRUE) { + ErrorF("couldn't add or enable pointer\n"); + return BadImplementation; + } + } + else if (ki) { + if (KdAddKeyboard(ki) != Success || + ActivateDevice(ki->dixdev) != Success || + EnableDevice(ki->dixdev) != TRUE) { + ErrorF("couldn't add or enable keyboard\n"); + return BadImplementation; + } + } + + ErrorF("done handling NIDR\n"); +} diff --git a/hw/kdrive/src/kkeymap.c b/hw/kdrive/src/kkeymap.c index 66383e7f3..ce4596fc8 100644 --- a/hw/kdrive/src/kkeymap.c +++ b/hw/kdrive/src/kkeymap.c @@ -28,14 +28,13 @@ #endif #include "kdrive.h" #include <X11/keysym.h> -#include "kkeymap.h" /* * Map scan codes (both regular and synthesized from extended keys) * to X keysyms */ -KeySym kdKeymap[(MAX_SCANCODE - MIN_SCANCODE + 1) * MAX_WIDTH] = { +const KeySym kdDefaultKeymap[KD_MAX_LENGTH * KD_MAX_WIDTH] = { /* These are directly mapped from DOS scanset 0 */ /* 1 8 */ XK_Escape, NoSymbol, /* 2 9 */ XK_1, XK_exclam, @@ -152,58 +151,13 @@ KeySym kdKeymap[(MAX_SCANCODE - MIN_SCANCODE + 1) * MAX_WIDTH] = { /* 110 117 */ NoSymbol, NoSymbol, /* 111 118 */ NoSymbol, NoSymbol, /* 112 119 */ NoSymbol, NoSymbol, -; - -/* - * Map extended keys to additional scancodes - */ -KdExtendMap kdExtendMap[] = { - 0x1d, 89, /* Control_R */ - 0x1c, 90, /* KP_Enter */ - 0x35, 91, /* KP_Divide */ - 0x37, 92, /* Sys_Req */ - 0x38, 93, /* Alt_R */ - 0x45, 94, /* Num_Lock */ - 0x47, 95, /* Home */ - 0x48, 96, /* Up */ - 0x49, 97, /* Page_Up */ - 0x4b, 98, /* Left */ - 0x4d, 99, /* Right */ - 0x4f, 100, /* End */ - 0x50, 101, /* Down */ - 0x51, 102, /* Page_Down */ - 0x52, 103, /* Insert */ - 0x53, 104, /* Delete */ - 0x5b, 105, /* Super_L (Windows_L) */ - 0x5c, 106, /* Super_R (Windows_R) */ - 0x5d, 107, /* Menu */ - 0x46, 69, /* Break (with control pressed) */ }; -#define NUM_EXTEND (sizeof (kdExtendMap)/ sizeof (kdExtendMap[0])) - -int kdNumExtend = NUM_EXTEND; - -/* - * Map keys on Japanese keyboard far from zero back to reasonable values - */ -KdExtendMap kdJapanMap[] = { - 0x70, 108, /* next to Alt key */ - 0x73, 109, /* dash/vbar */ - 0x79, 110, /* right of space bar */ - 0x7b, 111, /* left of space bar */ - 0x7d, 112, /* Yen */ -}; - -#define NUM_JAPAN (sizeof (kdJapanMap)/sizeof (kdJapanMap[0])) - -int kdNumJapan = NUM_JAPAN; - /* * List of locking key codes */ -CARD8 kdLockMap[] = { +CARD8 kdLockMap[] = { 65, 101, 77, @@ -218,7 +172,7 @@ int kdNumLock = NUM_LOCK; * the KEYMAP_LOCKING_ALTGR flag is set in CEKeymapFlags */ -CARD8 kdOptionalLockMap[] = { +CARD8 kdOptionalLockMap[] = { 100, }; @@ -226,13 +180,13 @@ CARD8 kdOptionalLockMap[] = { int kdNumOptionalLock = NUM_OPTIONAL_LOCK; -CARD8 kdModMap[MAP_LENGTH]; +const CARD8 kdDefaultModMap[MAP_LENGTH]; -unsigned long kdKeymapFlags = 0; +unsigned long kdDefaultKeymapFlags = 0; -KeySymsRec kdKeySyms = { - kdKeymap, - MIN_KEYCODE, - MAX_KEYCODE, - 2 +const KeySymsRec kdDefaultKeySyms = { + kdDefaultKeymap, + KD_MIN_KEYCODE, + KD_MAX_KEYCODE, + KD_MAX_WIDTH }; diff --git a/hw/kdrive/src/kloadmap.c b/hw/kdrive/src/kloadmap.c index bc003d485..b62b2deb2 100644 --- a/hw/kdrive/src/kloadmap.c +++ b/hw/kdrive/src/kloadmap.c @@ -27,7 +27,6 @@ #include <kdrive-config.h> #endif #include "kdrive.h" -#include "kkeymap.h" #ifdef WINDOWS #define KM_BUF 1024 diff --git a/hw/kdrive/vesa/vesa.c b/hw/kdrive/vesa/vesa.c index 67d2d438a..766cacdc8 100644 --- a/hw/kdrive/vesa/vesa.c +++ b/hw/kdrive/vesa/vesa.c @@ -871,7 +871,7 @@ vesaComputeFramebufferMapping (KdScreenInfo *screen) VesaScreenPrivPtr pscr = screen->driver; int depth, bpp, fbbpp; Pixel allbits; - KdMouseMatrix m; + KdPointerMatrix m; if (vesa_linear_fb) { @@ -970,10 +970,10 @@ vesaComputeFramebufferMapping (KdScreenInfo *screen) pscr->mapping = VESA_WINDOWED; pscr->shadow = TRUE; } - KdComputeMouseMatrix (&m, pscr->randr, - pscr->mode.XResolution, pscr->mode.YResolution); + KdComputePointerMatrix (&m, pscr->randr, + pscr->mode.XResolution, pscr->mode.YResolution); - KdSetMouseMatrix (&m); + KdSetPointerMatrix (&m); screen->width = pscr->mode.XResolution; screen->height = pscr->mode.YResolution; diff --git a/hw/kdrive/vesa/vesainit.c b/hw/kdrive/vesa/vesainit.c index 933715731..4f552d1a1 100644 --- a/hw/kdrive/vesa/vesainit.c +++ b/hw/kdrive/vesa/vesainit.c @@ -71,7 +71,16 @@ InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv) void InitInput (int argc, char **argv) { - KdInitInput(&LinuxMouseFuncs, &LinuxKeyboardFuncs); + KdKeyboardInfo *ki = NULL; + + KdAddPointerDriver(&LinuxMouseDriver); + KdAddKeyboardDriver(&LinuxKeyboardDriver); + ki = KdNewKeyboard(); + if (ki) { + ki->driver = &LinuxKeyboardDriver; + KdAddKeyboard(ki); + } + KdInitInput(); } void diff --git a/hw/kdrive/vxworks/vxkbd.c b/hw/kdrive/vxworks/vxkbd.c index 1c23aa915..b421e923e 100644 --- a/hw/kdrive/vxworks/vxkbd.c +++ b/hw/kdrive/vxworks/vxkbd.c @@ -171,7 +171,7 @@ static int kbdFd = -1; #include <event.h> #include <kbd_ioctl.h> -extern KeybdCtrl defaultKeyboardControl; +extern KeyboardCtrl defaultKeyboardControl; static void VxWorksSetAutorepeat (unsigned char *repeats, Bool on) @@ -235,7 +235,7 @@ void VxWorksKeyboardLeds (int leds) { DeviceIntPtr pKeyboard = (DeviceIntPtr) LookupKeyboardDevice (); - KeybdCtrl *ctrl = &pKeyboard->kbdfeed->ctrl; + KeyboardCtrl *ctrl = &pKeyboard->kbdfeed->ctrl; led_ioctl_info led_info; int i; |