summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/common/xf86Switch.c
blob: d11ab417aad871d05c1853bf85d925a2532d770a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * Copyright 1997-1998 by Frederic Lepied, France. <Frederic.Lepied@sugix.frmug.org>       
 *                                                                            
 * 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  Frederic   Lepied not  be  used  in
 * advertising or publicity pertaining to distribution of the software without
 * specific,  written      prior  permission.     Frederic  Lepied   makes  no
 * representations about the suitability of this software for any purpose.  It
 * is provided "as is" without express or implied warranty.                   
 *                                                                            
 * FREDERIC  LEPIED DISCLAIMS ALL   WARRANTIES WITH REGARD  TO  THIS SOFTWARE,
 * INCLUDING ALL IMPLIED   WARRANTIES OF MERCHANTABILITY  AND   FITNESS, IN NO
 * EVENT  SHALL FREDERIC  LEPIED 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.
 *
 */

/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Switch.c,v 3.9 2001/04/20 16:32:31 tsi Exp $ */

#include "xf86.h"
#include "xf86Xinput.h"

/******************************************************************************
 * debugging macro
 *****************************************************************************/
#ifdef DBG
#undef DBG
#endif
#ifdef DEBUG
#undef DEBUG
#endif

static int      debug_level = 0;
#define DEBUG 1
#if DEBUG
#define DBG(lvl, f) {if ((lvl) <= debug_level) f;}
#else
#define DBG(lvl, f)
#endif

/******************************************************************************
 * device records
 *****************************************************************************/

typedef struct 
{
  XID	last;			/* last core pointer */
} SwitchDevRec, *SwitchDevPtr;

/*
 ***************************************************************************
 *
 * xf86SwtConvert --
 *	Convert valuators to X and Y.
 *
 ***************************************************************************
 */
static Bool
xf86SwtConvert(LocalDevicePtr	local,
	       int		first,
	       int		num,
	       int		v0,
	       int		v1,
	       int		v2,
	       int		v3,
	       int		v4,
	       int		v5,
	       int*		x,
	       int*		y)
{
  return FALSE;
}

/*
 * xf86SwitchCoreDevice --
 *      Test if the core device has changed and send a motion event accordingly.
 */
void
xf86SwitchCoreDevice(LocalDevicePtr	local,
		     DeviceIntPtr	core)
{
  SwitchDevPtr        priv;

  if (!local)
      return;
  
  priv = (SwitchDevPtr) local->private;

  if (core->id != priv->last) {
    DBG(3, ErrorF("xf86SwitchCoreDevice new core id=%d old=%d\n", core->id, priv->last));
    priv->last = core->id;
    xf86PostMotionEvent(local->dev, 1, 0, 1, core->id);
  }
}

static void
xf86SwtControlProc(DeviceIntPtr	device,
                    PtrCtrl		*ctrl)
{
  DBG(2, ErrorF("xf86SwtControlProc\n"));
}

/*
 * xf86SwtProc --
 *      Handle the initialization, etc. of a switch
 */
static int
xf86SwtProc(pSwt, what)
     DeviceIntPtr       pSwt;
     int                what;
{
  int			loop;
  int                   nbaxes;
  LocalDevicePtr        local = (LocalDevicePtr)pSwt->public.devicePrivate;
  SwitchDevPtr		priv = (SwitchDevPtr)XI_PRIVATE(pSwt);

  DBG(2, ErrorF("BEGIN xf86SwtProc dev=0x%x priv=0x%x\n", pSwt, priv));
  
  switch (what)
    {
    case DEVICE_INIT: 
      DBG(1, ErrorF("xf86SwtProc pSwt=0x%x what=INIT\n", pSwt));
  
      nbaxes = 1;

      if (InitFocusClassDeviceStruct(pSwt) == FALSE)
        {
          ErrorF("unable to init Focus class device\n");
          return !Success;
        }
          
      if (InitValuatorClassDeviceStruct(pSwt, 
					nbaxes,
					xf86GetMotionEvents, 
					local->history_size,
					Absolute) /* relatif ou absolute */
          == FALSE) 
        {
          ErrorF("unable to allocate Valuator class device\n"); 
          return !Success;
        }
      else 
        {
          for(loop=0; loop<nbaxes; loop++) {
            InitValuatorAxisStruct(pSwt,
                                   loop,
                                   0, /* min val */
                                   1000, /* max val */
                                   1); /* resolution */
          }
	  /* allocate the motion history buffer if needed */
	  xf86MotionHistoryAllocate(local);

          AssignTypeAndName(pSwt, local->atom, local->name);
        }

      break; 
      
    case DEVICE_ON:
      DBG(1, ErrorF("xf86SwtProc  pSwt=0x%x what=ON\n", pSwt));
      pSwt->public.on = TRUE;
    break;
      
    case DEVICE_OFF:
    case DEVICE_CLOSE:
      DBG(1, ErrorF("xf86SwtProc  pSwt=0x%x what=%s\n", pSwt,
                    (what == DEVICE_CLOSE) ? "CLOSE" : "OFF"));
      pSwt->public.on = FALSE;
    break;

    default:
      ErrorF("unsupported mode=%d\n", what);
      return !Success;
      break;
    }
  DBG(2, ErrorF("END   xf86SwtProc dev=0x%x priv=0x%x\n", pSwt, priv));
  return Success;
}

/*
 * xf86SwtAllocate --
 *      Allocate Switch device structures.
 */
static LocalDevicePtr
xf86SwtAllocate()
{
  LocalDevicePtr        local = (LocalDevicePtr) xalloc(sizeof(LocalDeviceRec));
  SwitchDevPtr		priv = (SwitchDevPtr) xalloc(sizeof(SwitchDevRec));
  
  local->name = "SWITCH";
  local->flags = 0;
  local->device_control = xf86SwtProc;
  local->read_input = NULL;
  local->close_proc = NULL;
  local->control_proc = NULL;
  local->switch_mode = NULL;
  local->conversion_proc = xf86SwtConvert;
  local->fd = -1;
  local->atom = 0;
  local->dev = NULL;
  local->private = priv;
  local->type_name = "Switch";
  local->history_size  = 0;
  
  priv->last = -1;
  
  return local;
}

/*
 * switch association
 */
DeviceAssocRec switch_assoc =
{
  " ",                   /* config_section_name */
  xf86SwtAllocate              /* device_allocate */
};

/* end of xf86Switch.c */