summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <rand.chars@gmail.com>2006-09-05 21:22:23 -0500
committerOri Bernstein <ori@localhost.(none)>2006-09-05 21:22:23 -0500
commit3a6759d433d4988d13546b0320b1a652f897061c (patch)
treedbfe23cefe0ea286f8902b97af86fff097ffa374
parente4a26c379f78b68788a2aa061b84100aa25116a4 (diff)
Implemented keyboard initialization. Still segfaulting on startup.
-rw-r--r--hw/xscreen/xs-init.c11
-rw-r--r--hw/xscreen/xs-input.c187
2 files changed, 182 insertions, 16 deletions
diff --git a/hw/xscreen/xs-init.c b/hw/xscreen/xs-init.c
index b40b8784a..90ba5ea5d 100644
--- a/hw/xscreen/xs-init.c
+++ b/hw/xscreen/xs-init.c
@@ -25,17 +25,6 @@
#include "mi.h"
-/**
- * DIX hooks for initializing input and output.
- * XKB stuff is not supported yet, since it's currently missing in
- * XCB.
- **/
-void InitInput(int argc, char *argv[])
-{
- /*shut up GCC.*/
- argc++;
- argv++;
-}
void xsInitPixmapFormats(const XCBSetup *setup, PixmapFormatRec fmts[])
{
diff --git a/hw/xscreen/xs-input.c b/hw/xscreen/xs-input.c
index 67556ca7d..ad633157f 100644
--- a/hw/xscreen/xs-input.c
+++ b/hw/xscreen/xs-input.c
@@ -11,7 +11,7 @@
**/
#ifdef HAVE_XSCREEN_CONFIG_H
-#include <xnest-config.h>
+#include <xs-config.h>
#endif
#include <stdlib.h>
@@ -26,13 +26,25 @@
#include "gcstruct.h"
#include "window.h"
-#include "windowstr.h"
-#include "pixmapstr.h"
-#include "colormapst.h"
+#include "inputstr.h"
#include "scrnintstr.h"
#include "region.h"
+#include "misc.h"
#include "mi.h"
+#include "mipointer.h"
+
+#include "xs-globals.h"
+
+#define UNUSED __attribute__((__unused__))
+
+/**
+ * FIXME: these numbers stolen from Xnest. Are they correct?
+ **/
+#define MAX_BUTTONS 256
+
+static DevicePtr xsPtr;
+static DevicePtr xsKbd;
/**
* DIX hook for processing input events.
@@ -45,7 +57,7 @@ void ProcessInputEvents()
}
/*The backing server should have already filtered invalid modifiers*/
-Bool LegalModifier(unsigned int key, DevicePtr pDev)
+Bool LegalModifier(unsigned int key UNUSED, DevicePtr pDev UNUSED)
{
return TRUE;
}
@@ -54,3 +66,168 @@ void OsVendorInit()
{
}
+void xsChangePointerControl(DeviceIntPtr pDev UNUSED, PtrCtrl *ctl)
+{
+ XCBChangePointerControl(xsConnection,
+ ctl->num, ctl->den,
+ ctl->threshold,
+ TRUE, TRUE);
+}
+/**
+ * Manages initializing and setting up the pointer.
+ **/
+int xsPtrProc(DeviceIntPtr pDev, int state)
+{
+ CARD8 map[MAX_BUTTONS];
+ XCBGetPointerMappingCookie c;
+ XCBGetPointerMappingRep *r;
+ int nmap;
+ int i;
+
+ switch (state)
+ {
+ case DEVICE_INIT:
+ c = XCBGetPointerMapping(xsConnection);
+ r = XCBGetPointerMappingReply(xsConnection, c, NULL);
+ nmap = r->map_len;
+ for (i = 0; i <= nmap; i++)
+ map[i] = i; /* buttons are already mapped */
+ InitPointerDeviceStruct(&pDev->public, map, nmap,
+ miPointerGetMotionEvents,
+ xsChangePointerControl,
+ miPointerGetMotionBufferSize());
+ break;
+
+ /* device is always on, so ignore DEVICE_ON, DEVICE_OFF*/
+ default:
+ break;
+ }
+ return Success;
+}
+
+/**
+ * Keyboard callback functions
+ **/
+
+/* no-op function */
+void xsBell(int vol UNUSED, DeviceIntPtr pDev UNUSED, pointer ctl UNUSED, int wtf_is_this UNUSED)
+{
+ return;
+}
+
+/*no-op function*/
+void xsKbdCtl(DeviceIntPtr pDev UNUSED, KeybdCtrl *ctl UNUSED)
+{
+}
+
+
+/**
+ * Manages initializing and setting up the keyboard.
+ **/
+int xsKbdProc(DeviceIntPtr pDev, int state)
+{
+ const XCBSetup *setup;
+ XCBGetKeyboardMappingCookie mapcook;
+ XCBGetKeyboardMappingRep *maprep;
+ XCBGetModifierMappingCookie modcook;
+ XCBGetModifierMappingRep *modrep;
+ XCBGetKeyboardControlCookie ctlcook;
+ XCBGetKeyboardControlRep *ctlrep;
+
+
+ XCBKEYCODE min;
+ XCBKEYCODE max;
+ XCBKEYSYM *keysyms;
+ XCBKEYCODE *modcodes;
+
+ KeySymsRec keys;
+ CARD8 modmap[MAP_LENGTH] = {0};
+ CARD8 keycode;
+ int i;
+ int j;
+
+ setup = XCBGetSetup(xsConnection);
+ switch (state)
+ {
+ case DEVICE_INIT:
+ min = setup->min_keycode;
+ max = setup->max_keycode;
+
+ /*do all the requests*/
+ mapcook = XCBGetKeyboardMapping(xsConnection, min, max.id - min.id);
+ modcook = XCBGetModifierMapping(xsConnection);
+ ctlcook = XCBGetKeyboardControl(xsConnection);
+
+ /*wait for the keyboard mapping*/
+ maprep = XCBGetKeyboardMappingReply(xsConnection, mapcook, NULL);
+ keysyms = XCBGetKeyboardMappingKeysyms(maprep);
+
+ /* initialize the keycode list*/
+ keys.minKeyCode = min.id;
+ keys.maxKeyCode = max.id;
+ keys.mapWidth = maprep->keysyms_per_keycode;
+ keys.map = (KeySym *)keysyms;
+
+ /*wait for the modifier mapping*/
+ modrep = XCBGetModifierMappingReply(xsConnection, modcook, NULL);
+ modcodes = XCBGetModifierMappingKeycodes(modrep);
+
+
+ /*initialize the modifiers*/
+ for (j = 0; j < 8; j++) {
+ for (i = 0; i < modrep->keycodes_per_modifier; i++) {
+ keycode = modcodes[j * modrep->keycodes_per_modifier + i].id;
+ if (keycode != 0)
+ modmap[keycode] |= 1<<j;
+ }
+ }
+
+ /*wait for the ctl values*/
+ ctlrep = XCBGetKeyboardControlReply(xsConnection, ctlcook, NULL);
+ /*initialize the auto repeats*/
+ memmove(defaultKeyboardControl.autoRepeats,
+ ctlrep->auto_repeats,
+ sizeof(ctlrep->auto_repeats));
+
+ InitKeyboardDeviceStruct(&pDev->public,
+ &keys,
+ modmap,
+ xsBell,
+ xsKbdCtl);
+
+ break;
+ }
+ return Success;
+}
+
+/**
+ * DIX hooks for initializing input and output.
+ * XKB stuff is not supported yet, since it's currently missing in
+ * XCB.
+ **/
+
+void xsBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadMask)
+{
+ /*handle events here*/
+ XCBFlush(xsConnection);
+}
+
+void xsWakeupHandler(pointer blockData, int result, pointer pReadMask)
+{
+ /*handle events here*/
+}
+
+void InitInput(int argc, char *argv[])
+{
+ xsPtr = (DevicePtr) AddInputDevice(xsPtrProc, TRUE);
+ xsKbd = (DevicePtr) AddInputDevice(xsKbdProc, TRUE);
+
+ RegisterPointerDevice((DeviceIntPtr)xsPtr);
+ RegisterKeyboardDevice((DeviceIntPtr)xsKbd);
+
+ mieqInit(xsKbd, xsPtr);
+
+ AddEnabledDevice(XCBGetFileDescriptor(xsConnection));
+ RegisterBlockAndWakeupHandlers(xsBlockHandler, xsWakeupHandler, NULL);
+}
+