2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2001-2003 Red Hat Inc., Durham, North Carolina.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation on 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 (including the
|
|
|
|
* next paragraph) 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
|
|
|
|
* NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Authors:
|
|
|
|
* David H. Dawes <dawes@xfree86.org>
|
|
|
|
* Kevin E. Martin <kem@redhat.com>
|
|
|
|
* Rickard E. (Rik) Faith <faith@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
*
|
|
|
|
* This file implements common routines used by the backend and console
|
|
|
|
* input devices.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DMX_CONFIG_H
|
|
|
|
#include <dmx-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define DMX_STATE_DEBUG 0
|
|
|
|
|
|
|
|
#include "dmxinputinit.h"
|
|
|
|
#include "dmxcommon.h"
|
|
|
|
#include "dmxconsole.h"
|
|
|
|
#include "dmxprop.h"
|
|
|
|
#include "dmxsync.h"
|
|
|
|
#include "dmxmap.h"
|
|
|
|
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include "mipointer.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
|
|
|
|
#include <unistd.h> /* For usleep() */
|
|
|
|
|
|
|
|
#if DMX_STATE_DEBUG
|
|
|
|
#define DMXDBG0(f) dmxLog(dmxDebug,f)
|
|
|
|
#else
|
|
|
|
#define DMXDBG0(f)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Each device has a private area that is visible only from inside the
|
2012-06-10 07:21:05 -06:00
|
|
|
* driver code. */
|
2006-11-26 11:13:41 -07:00
|
|
|
typedef struct _myPrivate {
|
|
|
|
DMX_COMMON_PRIVATE;
|
|
|
|
} myPrivate;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
dmxCommonKbdSetAR(Display * display, unsigned char *old, unsigned char *new)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
XKeyboardControl kc;
|
2012-06-10 07:21:05 -06:00
|
|
|
XKeyboardState ks;
|
|
|
|
unsigned long mask = KBKey | KBAutoRepeatMode;
|
|
|
|
int i, j;
|
|
|
|
int minKeycode, maxKeycode;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (!old) {
|
|
|
|
XGetKeyboardControl(display, &ks);
|
2012-06-10 07:21:05 -06:00
|
|
|
old = (unsigned char *) ks.auto_repeats;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
XDisplayKeycodes(display, &minKeycode, &maxKeycode);
|
|
|
|
for (i = 1; i < 32; i++) {
|
|
|
|
if (!old || old[i] != new[i]) {
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
if ((new[i] & (1 << j)) != (old[i] & (1 << j))) {
|
2012-06-10 07:21:05 -06:00
|
|
|
kc.key = i * 8 + j;
|
2006-11-26 11:13:41 -07:00
|
|
|
kc.auto_repeat_mode = ((new[i] & (1 << j))
|
|
|
|
? AutoRepeatModeOn
|
|
|
|
: AutoRepeatModeOff);
|
|
|
|
if (kc.key >= minKeycode && kc.key <= maxKeycode)
|
|
|
|
XChangeKeyboardControl(display, mask, &kc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
dmxCommonKbdSetLeds(Display * display, unsigned long new)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
2006-11-26 11:13:41 -07:00
|
|
|
XKeyboardControl kc;
|
|
|
|
|
|
|
|
for (i = 0; i < 32; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
kc.led = i + 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
kc.led_mode = (new & (1 << i)) ? LedModeOn : LedModeOff;
|
|
|
|
XChangeKeyboardControl(display, KBLed | KBLedMode, &kc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
dmxCommonKbdSetCtrl(Display * display, KeybdCtrl * old, KeybdCtrl * new)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
XKeyboardControl kc;
|
2012-06-10 07:21:05 -06:00
|
|
|
unsigned long mask = KBKeyClickPercent | KBAutoRepeatMode;
|
|
|
|
|
|
|
|
if (!old || old->click != new->click || old->autoRepeat != new->autoRepeat) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
kc.key_click_percent = new->click;
|
2012-06-10 07:21:05 -06:00
|
|
|
kc.auto_repeat_mode = new->autoRepeat;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
XChangeKeyboardControl(display, mask, &kc);
|
|
|
|
}
|
|
|
|
|
|
|
|
dmxCommonKbdSetLeds(display, new->leds);
|
2012-06-10 07:21:05 -06:00
|
|
|
dmxCommonKbdSetAR(display, old ? old->autoRepeats : NULL, new->autoRepeats);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
dmxCommonMouSetCtrl(Display * display, PtrCtrl * old, PtrCtrl * new)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
Bool do_accel, do_threshold;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!old
|
|
|
|
|| old->num != new->num
|
2012-06-10 07:21:05 -06:00
|
|
|
|| old->den != new->den || old->threshold != new->threshold) {
|
|
|
|
do_accel = (new->num > 0 && new->den > 0);
|
2006-11-26 11:13:41 -07:00
|
|
|
do_threshold = (new->threshold > 0);
|
|
|
|
if (do_accel || do_threshold) {
|
|
|
|
XChangePointerControl(display, do_accel, do_threshold,
|
|
|
|
new->num, new->den, new->threshold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Update the keyboard control. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonKbdCtrl(DevicePtr pDev, KeybdCtrl * ctrl)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!priv->stateSaved && priv->be)
|
|
|
|
dmxCommonSaveState(priv);
|
|
|
|
if (!priv->display || !priv->stateSaved)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
dmxCommonKbdSetCtrl(priv->display,
|
2012-06-10 07:21:05 -06:00
|
|
|
priv->kctrlset ? &priv->kctrl : NULL, ctrl);
|
|
|
|
priv->kctrl = *ctrl;
|
2006-11-26 11:13:41 -07:00
|
|
|
priv->kctrlset = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Update the mouse control. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonMouCtrl(DevicePtr pDev, PtrCtrl * ctrl)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Don't set the acceleration for the
|
|
|
|
* console, because that should be
|
|
|
|
* controlled by the X server that the
|
|
|
|
* console is running on. Otherwise,
|
|
|
|
* the acceleration for the console
|
|
|
|
* window would be unexpected for the
|
|
|
|
* scale of the window. */
|
2006-11-26 11:13:41 -07:00
|
|
|
if (priv->be) {
|
|
|
|
dmxCommonMouSetCtrl(priv->display,
|
2012-06-10 07:21:05 -06:00
|
|
|
priv->mctrlset ? &priv->mctrl : NULL, ctrl);
|
|
|
|
priv->mctrl = *ctrl;
|
2006-11-26 11:13:41 -07:00
|
|
|
priv->mctrlset = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sound they keyboard bell. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonKbdBell(DevicePtr pDev, int percent,
|
|
|
|
int volume, int pitch, int duration)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
XKeyboardControl kc;
|
2012-06-10 07:21:05 -06:00
|
|
|
XKeyboardState ks;
|
|
|
|
unsigned long mask = KBBellPercent | KBBellPitch | KBBellDuration;
|
|
|
|
|
|
|
|
if (!priv->be)
|
|
|
|
XGetKeyboardControl(priv->display, &ks);
|
|
|
|
kc.bell_percent = volume;
|
|
|
|
kc.bell_pitch = pitch;
|
2006-11-26 11:13:41 -07:00
|
|
|
kc.bell_duration = duration;
|
|
|
|
XChangeKeyboardControl(priv->display, mask, &kc);
|
|
|
|
XBell(priv->display, percent);
|
|
|
|
if (!priv->be) {
|
2012-06-10 07:21:05 -06:00
|
|
|
kc.bell_percent = ks.bell_percent;
|
|
|
|
kc.bell_pitch = ks.bell_pitch;
|
2006-11-26 11:13:41 -07:00
|
|
|
kc.bell_duration = ks.bell_duration;
|
|
|
|
XChangeKeyboardControl(priv->display, mask, &kc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the keyboard mapping. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonKbdGetMap(DevicePtr pDev, KeySymsPtr pKeySyms, CARD8 *pModMap)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
2012-06-10 07:21:05 -06:00
|
|
|
int min_keycode;
|
|
|
|
int max_keycode;
|
|
|
|
int map_width;
|
|
|
|
KeySym *keyboard_mapping;
|
2006-11-26 11:13:41 -07:00
|
|
|
XModifierKeymap *modifier_mapping;
|
2012-06-10 07:21:05 -06:00
|
|
|
int i, j;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Compute pKeySyms. Cast
|
|
|
|
* XGetKeyboardMapping because of
|
|
|
|
* compiler warning on 64-bit machines.
|
|
|
|
* We assume pointers to 32-bit and
|
|
|
|
* 64-bit ints are the same. */
|
2006-11-26 11:13:41 -07:00
|
|
|
XDisplayKeycodes(priv->display, &min_keycode, &max_keycode);
|
2012-06-10 07:21:05 -06:00
|
|
|
keyboard_mapping = (KeySym *) XGetKeyboardMapping(priv->display,
|
|
|
|
min_keycode,
|
|
|
|
max_keycode
|
|
|
|
- min_keycode + 1,
|
|
|
|
&map_width);
|
2006-11-26 11:13:41 -07:00
|
|
|
pKeySyms->minKeyCode = min_keycode;
|
|
|
|
pKeySyms->maxKeyCode = max_keycode;
|
2012-06-10 07:21:05 -06:00
|
|
|
pKeySyms->mapWidth = map_width;
|
|
|
|
pKeySyms->map = keyboard_mapping;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Compute pModMap */
|
|
|
|
modifier_mapping = XGetModifierMapping(priv->display);
|
2007-11-24 10:55:21 -07:00
|
|
|
for (i = 0; i < MAP_LENGTH; i++)
|
|
|
|
pModMap[i] = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
int max_keypermod = modifier_mapping->max_keypermod;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
for (i = 0; i < max_keypermod; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
CARD8 keycode =
|
|
|
|
modifier_mapping->modifiermap[j * max_keypermod + i];
|
2007-11-24 10:55:21 -07:00
|
|
|
if (keycode)
|
|
|
|
pModMap[keycode] |= 1 << j;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
XFreeModifiermap(modifier_mapping);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Fill in the XKEYBOARD parts of the \a info structure for the
|
|
|
|
* specified \a pDev. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonKbdGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
GETDMXINPUTFROMPRIV;
|
|
|
|
char *pt;
|
|
|
|
|
|
|
|
dmxCommonSaveState(priv);
|
|
|
|
if (priv->xkb) {
|
|
|
|
#define NAME(x) \
|
|
|
|
priv->xkb->names->x ? XGetAtomName(priv->display,priv->xkb->names->x) : NULL
|
|
|
|
info->names.keycodes = NAME(keycodes);
|
2012-06-10 07:21:05 -06:00
|
|
|
info->names.types = NAME(types);
|
|
|
|
info->names.compat = NAME(compat);
|
|
|
|
info->names.symbols = NAME(symbols);
|
2006-11-26 11:13:41 -07:00
|
|
|
info->names.geometry = NAME(geometry);
|
2012-06-10 07:21:05 -06:00
|
|
|
info->freenames = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
#undef NAME
|
|
|
|
dmxLogInput(dmxInput,
|
|
|
|
"XKEYBOARD: keycodes = %s\n", info->names.keycodes);
|
|
|
|
dmxLogInput(dmxInput,
|
|
|
|
"XKEYBOARD: symbols = %s\n", info->names.symbols);
|
|
|
|
dmxLogInput(dmxInput,
|
|
|
|
"XKEYBOARD: geometry = %s\n", info->names.geometry);
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((pt = strchr(info->names.keycodes, '+')))
|
|
|
|
*pt = '\0';
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
dmxCommonRestoreState(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn \a pDev on (i.e., take input from \a pDev). */
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
|
|
|
dmxCommonKbdOn(DevicePtr pDev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (priv->be)
|
|
|
|
dmxCommonSaveState(priv);
|
2006-11-26 11:13:41 -07:00
|
|
|
priv->eventMask |= DMX_KEYBOARD_EVENT_MASK;
|
|
|
|
XSelectInput(priv->display, priv->window, priv->eventMask);
|
|
|
|
if (priv->be)
|
|
|
|
XSetInputFocus(priv->display, priv->window, RevertToPointerRoot,
|
|
|
|
CurrentTime);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn \a pDev off. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonKbdOff(DevicePtr pDev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
priv->eventMask &= ~DMX_KEYBOARD_EVENT_MASK;
|
|
|
|
XSelectInput(priv->display, priv->window, priv->eventMask);
|
|
|
|
dmxCommonRestoreState(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn \a pDev on (i.e., take input from \a pDev). */
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
|
|
|
dmxCommonOthOn(DevicePtr pDev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
GETDMXINPUTFROMPRIV;
|
|
|
|
XEventClass event_list[DMX_MAX_XINPUT_EVENT_TYPES];
|
2012-06-10 07:21:05 -06:00
|
|
|
int event_type[DMX_MAX_XINPUT_EVENT_TYPES];
|
|
|
|
int count = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#define ADD(type) \
|
|
|
|
if (count < DMX_MAX_XINPUT_EVENT_TYPES) { \
|
|
|
|
type(priv->xi, event_type[count], event_list[count]); \
|
|
|
|
if (event_type[count]) { \
|
|
|
|
dmxMapInsert(dmxLocal, event_type[count], XI_##type); \
|
|
|
|
++count; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
dmxLog(dmxWarning, "More than %d event types for %s\n", \
|
|
|
|
DMX_MAX_XINPUT_EVENT_TYPES, dmxInput->name); \
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(priv->xi = XOpenDevice(priv->display, dmxLocal->deviceId))) {
|
|
|
|
dmxLog(dmxWarning, "Cannot open %s device (id=%d) on %s\n",
|
|
|
|
dmxLocal->deviceName ? dmxLocal->deviceName : "(unknown)",
|
2014-09-27 11:52:59 -06:00
|
|
|
(int) dmxLocal->deviceId, dmxInput->name);
|
2006-11-26 11:13:41 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ADD(DeviceKeyPress);
|
|
|
|
ADD(DeviceKeyRelease);
|
|
|
|
ADD(DeviceButtonPress);
|
|
|
|
ADD(DeviceButtonRelease);
|
|
|
|
ADD(DeviceMotionNotify);
|
|
|
|
ADD(DeviceFocusIn);
|
|
|
|
ADD(DeviceFocusOut);
|
|
|
|
ADD(ProximityIn);
|
|
|
|
ADD(ProximityOut);
|
|
|
|
ADD(DeviceStateNotify);
|
|
|
|
ADD(DeviceMappingNotify);
|
|
|
|
ADD(ChangeDeviceNotify);
|
|
|
|
XSelectExtensionEvent(priv->display, priv->window, event_list, count);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn \a pDev off. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonOthOff(DevicePtr pDev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (priv->xi)
|
|
|
|
XCloseDevice(priv->display, priv->xi);
|
2006-11-26 11:13:41 -07:00
|
|
|
priv->xi = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Fill the \a info structure with information needed to initialize \a
|
2012-06-10 07:21:05 -06:00
|
|
|
* pDev. */
|
|
|
|
void
|
|
|
|
dmxCommonOthGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
GETDMXINPUTFROMPRIV;
|
2012-06-10 07:21:05 -06:00
|
|
|
XExtensionVersion *ext;
|
|
|
|
XDeviceInfo *devices;
|
|
|
|
Display *display = priv->display;
|
|
|
|
int num;
|
|
|
|
int i, j, k;
|
|
|
|
XextErrorHandler handler;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (!display && !(display = XOpenDisplay(dmxInput->name)))
|
|
|
|
return;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/* Print out information about the XInput Extension. */
|
|
|
|
handler = XSetExtensionErrorHandler(dmxInputExtensionErrorHandler);
|
2012-06-10 07:21:05 -06:00
|
|
|
ext = XGetExtensionVersion(display, INAME);
|
2006-11-26 11:13:41 -07:00
|
|
|
XSetExtensionErrorHandler(handler);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ext && ext != (XExtensionVersion *) NoSuchExtension) {
|
2006-11-26 11:13:41 -07:00
|
|
|
XFree(ext);
|
|
|
|
devices = XListInputDevices(display, &num);
|
|
|
|
for (i = 0; i < num; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (devices[i].id == (XID) dmxLocal->deviceId) {
|
|
|
|
XAnyClassPtr any;
|
|
|
|
XKeyInfoPtr ki;
|
|
|
|
XButtonInfoPtr bi;
|
2006-11-26 11:13:41 -07:00
|
|
|
XValuatorInfoPtr vi;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
for (j = 0, any = devices[i].inputclassinfo;
|
|
|
|
j < devices[i].num_classes;
|
2012-06-10 07:21:05 -06:00
|
|
|
any = (XAnyClassPtr) ((char *) any + any->length), j++) {
|
2006-11-26 11:13:41 -07:00
|
|
|
switch (any->class) {
|
|
|
|
case KeyClass:
|
2012-06-10 07:21:05 -06:00
|
|
|
ki = (XKeyInfoPtr) any;
|
|
|
|
info->keyboard = 1;
|
|
|
|
info->keyClass = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
info->keySyms.minKeyCode = ki->min_keycode;
|
|
|
|
info->keySyms.maxKeyCode = ki->max_keycode;
|
2012-06-10 07:21:05 -06:00
|
|
|
info->kbdFeedbackClass = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
break;
|
|
|
|
case ButtonClass:
|
2012-06-10 07:21:05 -06:00
|
|
|
bi = (XButtonInfoPtr) any;
|
|
|
|
info->buttonClass = 1;
|
|
|
|
info->numButtons = bi->num_buttons;
|
|
|
|
info->ptrFeedbackClass = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
break;
|
|
|
|
case ValuatorClass:
|
2012-06-10 07:21:05 -06:00
|
|
|
/* This assume all axes are either
|
|
|
|
* Absolute or Relative. */
|
|
|
|
vi = (XValuatorInfoPtr) any;
|
|
|
|
info->valuatorClass = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (vi->mode == Absolute)
|
2012-06-10 07:21:05 -06:00
|
|
|
info->numAbsAxes = vi->num_axes;
|
2006-11-26 11:13:41 -07:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
info->numRelAxes = vi->num_axes;
|
2006-11-26 11:13:41 -07:00
|
|
|
for (k = 0; k < vi->num_axes; k++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
info->res[k] = vi->axes[k].resolution;
|
|
|
|
info->minres[k] = vi->axes[k].resolution;
|
|
|
|
info->maxres[k] = vi->axes[k].resolution;
|
|
|
|
info->minval[k] = vi->axes[k].min_value;
|
|
|
|
info->maxval[k] = vi->axes[k].max_value;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FeedbackClass:
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Only keyboard and pointer feedback
|
|
|
|
* are handled at this time. */
|
2006-11-26 11:13:41 -07:00
|
|
|
break;
|
|
|
|
case ProximityClass:
|
2012-06-10 07:21:05 -06:00
|
|
|
info->proximityClass = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
break;
|
|
|
|
case FocusClass:
|
2012-06-10 07:21:05 -06:00
|
|
|
info->focusClass = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
break;
|
|
|
|
case OtherClass:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFreeDeviceList(devices);
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (display != priv->display)
|
|
|
|
XCloseDisplay(display);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Obtain the mouse button mapping. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonMouGetMap(DevicePtr pDev, unsigned char *map, int *nButtons)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
int i;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
*nButtons = XGetPointerMapping(priv->display, map, DMX_MAX_BUTTONS);
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i <= *nButtons; i++)
|
|
|
|
map[i] = i;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void *
|
|
|
|
dmxCommonXSelect(DMXScreenInfo * dmxScreen, void *closure)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
myPrivate *priv = closure;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
XSelectInput(dmxScreen->beDisplay, dmxScreen->scrnWin, priv->eventMask);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
static void
|
|
|
|
dmxCommonFdNotify(int fd, int ready, void *data)
|
|
|
|
{
|
|
|
|
/* This should process input on this fd, but instead all
|
|
|
|
* of that is delayed until the block and wakeup handlers are called
|
|
|
|
*/
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void *
|
|
|
|
dmxCommonAddEnabledDevice(DMXScreenInfo * dmxScreen, void *closure)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2017-12-08 08:01:59 -07:00
|
|
|
SetNotifyFd(XConnectionNumber(dmxScreen->beDisplay), dmxCommonFdNotify, X_NOTIFY_READ, closure);
|
2006-11-26 11:13:41 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void *
|
|
|
|
dmxCommonRemoveEnabledDevice(DMXScreenInfo * dmxScreen, void *closure)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2017-12-08 08:01:59 -07:00
|
|
|
RemoveNotifyFd(XConnectionNumber(dmxScreen->beDisplay));
|
2006-11-26 11:13:41 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn \a pDev on (i.e., take input from \a pDev). */
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
|
|
|
dmxCommonMouOn(DevicePtr pDev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
GETDMXINPUTFROMPRIV;
|
|
|
|
|
|
|
|
priv->eventMask |= DMX_POINTER_EVENT_MASK;
|
|
|
|
if (!priv->be) {
|
|
|
|
XSelectInput(priv->display, priv->window, priv->eventMask);
|
2017-12-08 08:01:59 -07:00
|
|
|
SetNotifyFd(XConnectionNumber(priv->display), dmxCommonFdNotify,X_NOTIFY_READ, pDev);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
dmxPropertyIterate(priv->be, dmxCommonXSelect, priv);
|
|
|
|
dmxPropertyIterate(priv->be, dmxCommonAddEnabledDevice, dmxInput);
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Turn \a pDev off. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxCommonMouOff(DevicePtr pDev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPDEV;
|
|
|
|
GETDMXINPUTFROMPRIV;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
priv->eventMask &= ~DMX_POINTER_EVENT_MASK;
|
|
|
|
if (!priv->be) {
|
2017-12-08 08:01:59 -07:00
|
|
|
RemoveNotifyFd(XConnectionNumber(priv->display));
|
2006-11-26 11:13:41 -07:00
|
|
|
XSelectInput(priv->display, priv->window, priv->eventMask);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
dmxPropertyIterate(priv->be, dmxCommonRemoveEnabledDevice, dmxInput);
|
|
|
|
dmxPropertyIterate(priv->be, dmxCommonXSelect, priv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Given the global coordinates \a x and \a y, determine the screen
|
|
|
|
* with the lowest number on which those coordinates lie. If they are
|
|
|
|
* not on any screen, return -1. The number returned is an index into
|
2010-07-27 13:02:24 -06:00
|
|
|
* \a dmxScreenInfo and is between -1 and \a dmxNumScreens - 1,
|
2006-11-26 11:13:41 -07:00
|
|
|
* inclusive. */
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
|
|
|
dmxFindPointerScreen(int x, int y)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < dmxNumScreens; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ScreenPtr pScreen = screenInfo.screens[i];
|
|
|
|
|
|
|
|
if (x >= pScreen->x && x < pScreen->x + pScreen->width &&
|
|
|
|
y >= pScreen->y && y < pScreen->y + pScreen->height)
|
|
|
|
return i;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns a pointer to the private area for the device that comes just
|
|
|
|
* prior to \a pDevice in the current \a dmxInput device list. This is
|
|
|
|
* used as the private area for the current device in some situations
|
|
|
|
* (e.g., when a keyboard and mouse form a pair that should share the
|
|
|
|
* same private area). If the requested private area cannot be located,
|
|
|
|
* then NULL is returned. */
|
2014-09-27 11:52:59 -06:00
|
|
|
void *
|
2012-06-10 07:21:05 -06:00
|
|
|
dmxCommonCopyPrivate(DeviceIntPtr pDevice)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETDMXLOCALFROMPDEVICE;
|
|
|
|
DMXInputInfo *dmxInput = &dmxInputs[dmxLocal->inputIdx];
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (i = 0; i < dmxInput->numDevs; i++)
|
|
|
|
if (dmxInput->devs[i] == dmxLocal && i)
|
2012-06-10 07:21:05 -06:00
|
|
|
return dmxInput->devs[i - 1]->private;
|
2006-11-26 11:13:41 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This routine saves and resets some important state for the backend
|
|
|
|
* and console device drivers:
|
|
|
|
* - the modifier map is saved and set to 0 (so DMX controls the LEDs)
|
|
|
|
* - the key click, bell, led, and repeat masks are saved and set to the
|
|
|
|
* values that DMX claims to be using
|
|
|
|
*
|
|
|
|
* This routine and #dmxCommonRestoreState are used when the pointer
|
|
|
|
* enters and leaves the console window, or when the backend window is
|
|
|
|
* active or not active (for a full-screen window, this only happens at
|
|
|
|
* server startup and server shutdown).
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
2014-09-27 11:52:59 -06:00
|
|
|
dmxCommonSaveState(void *private)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPRIVATE;
|
2012-06-10 07:21:05 -06:00
|
|
|
XKeyboardState ks;
|
|
|
|
unsigned long i;
|
|
|
|
XModifierKeymap *modmap;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (dmxInput->console)
|
|
|
|
priv = dmxInput->devs[0]->private;
|
|
|
|
if (!priv->display || priv->stateSaved)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
DMXDBG0("dmxCommonSaveState\n");
|
|
|
|
if (dmxUseXKB && (priv->xkb = XkbAllocKeyboard())) {
|
|
|
|
if (XkbGetIndicatorMap(priv->display, XkbAllIndicatorsMask, priv->xkb)
|
|
|
|
|| XkbGetNames(priv->display, XkbAllNamesMask, priv->xkb)) {
|
|
|
|
dmxLogInput(dmxInput, "Could not get XKB information\n");
|
|
|
|
XkbFreeKeyboard(priv->xkb, 0, True);
|
|
|
|
priv->xkb = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
if (priv->xkb->indicators) {
|
|
|
|
priv->savedIndicators = *priv->xkb->indicators;
|
|
|
|
for (i = 0; i < XkbNumIndicators; i++)
|
|
|
|
if (priv->xkb->indicators->phys_indicators & (1 << i)) {
|
|
|
|
priv->xkb->indicators->maps[i].flags
|
|
|
|
= XkbIM_NoAutomatic;
|
|
|
|
}
|
|
|
|
XkbSetIndicatorMap(priv->display, ~0, priv->xkb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XGetKeyboardControl(priv->display, &ks);
|
2012-06-10 07:21:05 -06:00
|
|
|
priv->savedKctrl.click = ks.key_click_percent;
|
|
|
|
priv->savedKctrl.bell = ks.bell_percent;
|
|
|
|
priv->savedKctrl.bell_pitch = ks.bell_pitch;
|
|
|
|
priv->savedKctrl.bell_duration = ks.bell_duration;
|
|
|
|
priv->savedKctrl.leds = ks.led_mask;
|
|
|
|
priv->savedKctrl.autoRepeat = ks.global_auto_repeat;
|
2006-11-26 11:13:41 -07:00
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
priv->savedKctrl.autoRepeats[i] = ks.auto_repeats[i];
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
dmxCommonKbdSetCtrl(priv->display, &priv->savedKctrl,
|
|
|
|
&priv->dmxLocal->kctrl);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
priv->savedModMap = XGetModifierMapping(priv->display);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
modmap = XNewModifiermap(0);
|
2006-11-26 11:13:41 -07:00
|
|
|
XSetModifierMapping(priv->display, modmap);
|
|
|
|
if (dmxInput->scrnIdx != -1)
|
|
|
|
dmxSync(&dmxScreens[dmxInput->scrnIdx], TRUE);
|
|
|
|
XFreeModifiermap(modmap);
|
|
|
|
|
|
|
|
priv->stateSaved = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This routine restores all the information saved by #dmxCommonSaveState. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
2014-09-27 11:52:59 -06:00
|
|
|
dmxCommonRestoreState(void *private)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GETPRIVFROMPRIVATE;
|
|
|
|
int retcode = -1;
|
|
|
|
CARD32 start;
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
if (dmxInput->console)
|
|
|
|
priv = dmxInput->devs[0]->private;
|
|
|
|
if (!priv->stateSaved)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
priv->stateSaved = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
DMXDBG0("dmxCommonRestoreState\n");
|
|
|
|
if (priv->xkb) {
|
|
|
|
*priv->xkb->indicators = priv->savedIndicators;
|
|
|
|
XkbSetIndicatorMap(priv->display, ~0, priv->xkb);
|
|
|
|
XkbFreeKeyboard(priv->xkb, 0, True);
|
|
|
|
priv->xkb = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (start = GetTimeInMillis(); GetTimeInMillis() - start < 5000;) {
|
|
|
|
CARD32 tmp;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
retcode = XSetModifierMapping(priv->display, priv->savedModMap);
|
2007-11-24 10:55:21 -07:00
|
|
|
if (retcode == MappingSuccess)
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (retcode == MappingBusy)
|
|
|
|
dmxLogInput(dmxInput, "Keyboard busy, waiting\n");
|
|
|
|
else
|
|
|
|
dmxLogInput(dmxInput, "Keyboard error, waiting\n");
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Don't generate X11 protocol for a bit */
|
2006-11-26 11:13:41 -07:00
|
|
|
for (tmp = GetTimeInMillis(); GetTimeInMillis() - tmp < 250;) {
|
2012-06-10 07:21:05 -06:00
|
|
|
usleep(250); /* This ends up sleeping only until
|
|
|
|
* the next key press generates an
|
|
|
|
* interruption. We make the delay
|
|
|
|
* relatively short in case the user
|
|
|
|
* pressed they keys quickly. */
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (retcode != MappingSuccess)
|
|
|
|
dmxLog(dmxWarning, "Unable to restore keyboard modifier state!\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
XFreeModifiermap(priv->savedModMap);
|
|
|
|
priv->savedModMap = NULL;
|
|
|
|
|
|
|
|
dmxCommonKbdSetCtrl(priv->display, NULL, &priv->savedKctrl);
|
|
|
|
priv->kctrlset = 0; /* Invalidate copy */
|
|
|
|
}
|