Pointer.c revision 706f2543
105b261ecSmrg/*
205b261ecSmrg
305b261ecSmrgCopyright 1993 by Davor Matic
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software
605b261ecSmrgand its documentation for any purpose is hereby granted without fee,
705b261ecSmrgprovided that the above copyright notice appear in all copies and that
805b261ecSmrgboth that copyright notice and this permission notice appear in
905b261ecSmrgsupporting documentation.  Davor Matic makes no representations about
1005b261ecSmrgthe suitability of this software for any purpose.  It is provided "as
1105b261ecSmrgis" without express or implied warranty.
1205b261ecSmrg
1305b261ecSmrg*/
1405b261ecSmrg
1505b261ecSmrg#ifdef HAVE_XNEST_CONFIG_H
1605b261ecSmrg#include <xnest-config.h>
1705b261ecSmrg#endif
1805b261ecSmrg
1905b261ecSmrg#include <X11/X.h>
2005b261ecSmrg#include <X11/Xproto.h>
2105b261ecSmrg#include "screenint.h"
2205b261ecSmrg#include "inputstr.h"
2305b261ecSmrg#include "input.h"
2405b261ecSmrg#include "misc.h"
2505b261ecSmrg#include "scrnintstr.h"
2605b261ecSmrg#include "servermd.h"
2705b261ecSmrg#include "mipointer.h"
2805b261ecSmrg
2905b261ecSmrg#include "Xnest.h"
3005b261ecSmrg
3105b261ecSmrg#include "Display.h"
3205b261ecSmrg#include "Screen.h"
3305b261ecSmrg#include "Pointer.h"
3405b261ecSmrg#include "Args.h"
3505b261ecSmrg
3605b261ecSmrg#include "xserver-properties.h"
3705b261ecSmrg#include "exevents.h" /* For XIGetKnownProperty */
3805b261ecSmrg
3905b261ecSmrgDeviceIntPtr xnestPointerDevice = NULL;
4005b261ecSmrg
4105b261ecSmrgvoid
4205b261ecSmrgxnestChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl)
4305b261ecSmrg{
4405b261ecSmrg  XChangePointerControl(xnestDisplay, True, True,
4505b261ecSmrg			ctrl->num, ctrl->den, ctrl->threshold);
4605b261ecSmrg}
4705b261ecSmrg
4805b261ecSmrgint
4905b261ecSmrgxnestPointerProc(DeviceIntPtr pDev, int onoff)
5005b261ecSmrg{
5105b261ecSmrg  CARD8 map[MAXBUTTONS];
5205b261ecSmrg  Atom btn_labels[MAXBUTTONS] = {0};
5305b261ecSmrg  Atom axes_labels[2] = {0};
5405b261ecSmrg  int nmap;
5505b261ecSmrg  int i;
5605b261ecSmrg
5705b261ecSmrg  switch (onoff)
5805b261ecSmrg    {
5905b261ecSmrg    case DEVICE_INIT:
6005b261ecSmrg      nmap = XGetPointerMapping(xnestDisplay, map, MAXBUTTONS);
6105b261ecSmrg      for (i = 0; i <= nmap; i++)
6205b261ecSmrg	map[i] = i; /* buttons are already mapped */
6305b261ecSmrg
6405b261ecSmrg      btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
6505b261ecSmrg      btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
6605b261ecSmrg      btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
6705b261ecSmrg      btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
6805b261ecSmrg      btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
6905b261ecSmrg      btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT);
7005b261ecSmrg      btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT);
7105b261ecSmrg
7205b261ecSmrg      axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
7305b261ecSmrg      axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
7405b261ecSmrg
7505b261ecSmrg      XGetPointerControl(xnestDisplay,
7605b261ecSmrg                         &defaultPointerControl.num,
7705b261ecSmrg                         &defaultPointerControl.den,
7805b261ecSmrg                         &defaultPointerControl.threshold);
7905b261ecSmrg      InitPointerDeviceStruct(&pDev->public, map, nmap, btn_labels,
8005b261ecSmrg			      xnestChangePointerControl,
8105b261ecSmrg			      GetMotionHistorySize(), 2, axes_labels);
8205b261ecSmrg      break;
8305b261ecSmrg    case DEVICE_ON:
8405b261ecSmrg      xnestEventMask |= XNEST_POINTER_EVENT_MASK;
8505b261ecSmrg      for (i = 0; i < xnestNumScreens; i++)
8605b261ecSmrg	XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask);
8705b261ecSmrg      break;
8805b261ecSmrg    case DEVICE_OFF:
8905b261ecSmrg      xnestEventMask &= ~XNEST_POINTER_EVENT_MASK;
9005b261ecSmrg      for (i = 0; i < xnestNumScreens; i++)
9105b261ecSmrg	XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask);
9205b261ecSmrg      break;
9305b261ecSmrg    case DEVICE_CLOSE:
9405b261ecSmrg      break;
9505b261ecSmrg    }
9605b261ecSmrg  return Success;
9705b261ecSmrg}
9805b261ecSmrg