Initial revision
[xournal.git] / linuxwacom-0.7.0-rotate-patch
blob9bd652746bc661dc7d87bf60aa2adb1c943edbf2
1 diff -Naur linuxwacom-0.7.0/src/wcmCommon.c linuxwacom-0.7.0-rotate/src/wcmCommon.c
2 --- linuxwacom-0.7.0/src/wcmCommon.c    2005-09-19 19:43:14.000000000 -0400
3 +++ linuxwacom-0.7.0-rotate/src/wcmCommon.c     2005-11-22 16:44:41.000000000 -0500
4 @@ -440,6 +440,11 @@
5                 y = x;
6                 x = common->wcmMaxX - tmp_coord;
7         }
8 +       else if (common->wcmRotate == ROTATE_HALF)
9 +       {
10 +               x = common->wcmMaxX - x;
11 +               y = common->wcmMaxY - y;
12 +       }
14         is_absolute = (priv->flags & ABSOLUTE_FLAG);
15         is_core_pointer = xf86IsCorePointer(local->dev);
16 diff -Naur linuxwacom-0.7.0/src/xf86Wacom.c linuxwacom-0.7.0-rotate/src/xf86Wacom.c
17 --- linuxwacom-0.7.0/src/xf86Wacom.c    2005-09-19 19:43:14.000000000 -0400
18 +++ linuxwacom-0.7.0-rotate/src/xf86Wacom.c     2005-12-07 22:57:46.000000000 -0500
19 @@ -199,7 +199,7 @@
20         LocalDevicePtr local = (LocalDevicePtr)pWcm->public.devicePrivate;
21         WacomDevicePtr priv = (WacomDevicePtr)PRIVATE(pWcm);
22         WacomCommonPtr common = priv->common;
23 -       int totalWidth = 0, maxHeight = 0, tabletSize = 0;
24 +       int totalWidth = 0, maxHeight = 0;
25         double screenRatio, tabletRatio;
26         char m1[32], m2[32];                    
27   
28 @@ -335,23 +335,13 @@
29         } /* end bounding rect */
31         /* x and y axes */
32 -       if (priv->twinview == TV_LEFT_RIGHT)
33 -               tabletSize = 2*(priv->bottomX - priv->topX - 2*priv->tvoffsetX);
34 -       else
35 -               tabletSize = priv->bottomX - priv->topX;
37 -       InitValuatorAxisStruct(pWcm, 0, 0, tabletSize, /* max val */
38 -               common->wcmResolX, /* tablet resolution */
39 -               0, common->wcmResolX); /* max_res */
41 -       if (priv->twinview == TV_ABOVE_BELOW)
42 -               tabletSize = 2*(priv->bottomY - priv->topY - 2*priv->tvoffsetY);
43 -       else
44 -               tabletSize = priv->bottomY - priv->topY;
46 -       InitValuatorAxisStruct(pWcm, 1, 0, tabletSize, /* max val */
47 -               common->wcmResolY, /* tablet resolution */
48 -               0, common->wcmResolY); /* max_res */
49 +        InitValuatorAxisStruct(pWcm, 0, priv->topX, priv->bottomX, /* max val */
50 +                common->wcmResolX, /* tablet resolution */
51 +                0, common->wcmResolX); /* max_res */
53 +        InitValuatorAxisStruct(pWcm, 1, priv->topY, priv->bottomY, /* max val */
54 +                common->wcmResolY, /* tablet resolution */
55 +                0, common->wcmResolY); /* max_res */
57         /* pressure */
58         InitValuatorAxisStruct(pWcm, 2, 0,
59 @@ -657,25 +647,40 @@
60  static int xf86WcmSetParam(LocalDevicePtr local, int param, int value)
61  {
62         WacomDevicePtr priv = (WacomDevicePtr)local->private;
63 +       WacomDevicePtr tmppriv;
64         char st[32];
65 +       int oldRotation, dev;
66 +       int tmpTopX, tmpTopY, tmpBottomX, tmpBottomY, oldMaxX, oldMaxY;
68         switch (param) 
69         {
70             case XWACOM_PARAM_TOPX:
71                 xf86ReplaceIntOption(local->options, "TopX", value);
72                 priv->topX = xf86SetIntOption(local->options, "TopX", 0);
73 +                InitValuatorAxisStruct(local->dev, 0, priv->topX, priv->bottomX,
74 +                    priv->common->wcmResolX, /* tablet resolution */
75 +                    0, priv->common->wcmResolX); /* max_res */
76                 break;
77             case XWACOM_PARAM_TOPY:
78                 xf86ReplaceIntOption(local->options, "TopY", value);
79                 priv->topY = xf86SetIntOption(local->options, "TopY", 0);
80 +                InitValuatorAxisStruct(local->dev, 1, priv->topY, priv->bottomY, /* max val */
81 +                    priv->common->wcmResolY, /* tablet resolution */
82 +                    0, priv->common->wcmResolY); /* max_res */
83                 break;
84             case XWACOM_PARAM_BOTTOMX:
85                 xf86ReplaceIntOption(local->options, "BottomX", value);
86                 priv->bottomX = xf86SetIntOption(local->options, "BottomX", 0);
87 +                InitValuatorAxisStruct(local->dev, 0, priv->topX, priv->bottomX,
88 +                    priv->common->wcmResolX, /* tablet resolution */
89 +                    0, priv->common->wcmResolX); /* max_res */
90                 break;
91             case XWACOM_PARAM_BOTTOMY:
92                 xf86ReplaceIntOption(local->options, "BottomY", value);
93                 priv->bottomY = xf86SetIntOption(local->options, "BottomY", 0);
94 +                InitValuatorAxisStruct(local->dev, 1, priv->topY, priv->bottomY, /* max val */
95 +                    priv->common->wcmResolY, /* tablet resolution */
96 +                    0, priv->common->wcmResolY); /* max_res */
97                 break;
98             case XWACOM_PARAM_BUTTON1:
99                 if ((value < 0) || (value > 19)) return BadValue;
100 @@ -782,6 +787,12 @@
101                                 "BottomY", priv->common->wcmMaxY);
102                 priv->bottomY = xf86SetIntOption(local->options,
103                                 "BottomY", priv->common->wcmMaxY);
104 +                InitValuatorAxisStruct(local->dev, 0, priv->topX, priv->bottomX,
105 +                    priv->common->wcmResolX, /* tablet resolution */
106 +                    0, priv->common->wcmResolX); /* max_res */
107 +                InitValuatorAxisStruct(local->dev, 1, priv->topY, priv->bottomY, /* max val */
108 +                    priv->common->wcmResolY, /* tablet resolution */
109 +                    0, priv->common->wcmResolY); /* max_res */
110                 break;
111             case XWACOM_PARAM_GIMP:
112                 if ((value != 0) && (value != 1)) return BadValue;
113 @@ -819,6 +830,103 @@
114                         xf86ReplaceStrOption(local->options, "TPCButton", "off");
115                 }
116                 break;
117 +           case XWACOM_PARAM_ROTATE:
118 +               if ((value < 0) || (value > 3)) return BadValue;
119 +               switch(value) {
120 +                 case ROTATE_NONE:
121 +                   xf86ReplaceStrOption(local->options, "Rotate", "NONE");
122 +                   break;
123 +                 case ROTATE_CW:
124 +                   xf86ReplaceStrOption(local->options, "Rotate", "CW");
125 +                   break;
126 +                 case ROTATE_CCW:
127 +                   xf86ReplaceStrOption(local->options, "Rotate", "CCW");
128 +                   break;
129 +                 case ROTATE_HALF:
130 +                   xf86ReplaceStrOption(local->options, "Rotate", "HALF");
131 +                   break;
132 +                 default:
133 +                   return BadValue;
134 +               }
135 +               oldRotation = priv->common->wcmRotate;
136 +               oldMaxX = priv->common->wcmMaxX;
137 +               oldMaxY = priv->common->wcmMaxY;
138 +               priv->common->wcmRotate = value;
139 +               if (((oldRotation == ROTATE_NONE || oldRotation == ROTATE_HALF) && (value == ROTATE_CW || value == ROTATE_CCW)) ||
140 +                    ((oldRotation == ROTATE_CW || oldRotation == ROTATE_CCW) && (value == ROTATE_NONE || value == ROTATE_HALF)))
141 +                {
142 +                   priv->common->wcmMaxX = oldMaxY;
143 +                   priv->common->wcmMaxY = oldMaxX;
144 +                }
146 +                /* rotate all devices at once! else they get misaligned */
147 +                for (dev=0; dev < priv->common->wcmNumDevices; dev++)
148 +                {
149 +                   tmppriv = (WacomDevicePtr)priv->common->wcmDevices[dev]->private;
150 +                   /* recover the unrotated xy-rectangles */
151 +                   switch (oldRotation) {
152 +                     case ROTATE_CW:
153 +                       tmpTopX = oldMaxY - tmppriv->bottomY;
154 +                       tmpBottomX = oldMaxY - tmppriv->topY;
155 +                       tmpTopY = tmppriv->topX;
156 +                       tmpBottomY = tmppriv->bottomX;
157 +                       break;
158 +                     case ROTATE_CCW:
159 +                       tmpTopX = tmppriv->topY;
160 +                       tmpBottomX = tmppriv->bottomY;
161 +                       tmpTopY = oldMaxX - tmppriv->bottomX;
162 +                       tmpBottomY = oldMaxX - tmppriv->topX;
163 +                       break;
164 +                     case ROTATE_HALF:
165 +                       tmpTopX = oldMaxX - tmppriv->bottomX;
166 +                       tmpBottomX = oldMaxX - tmppriv->topX;
167 +                       tmpTopY = oldMaxY - tmppriv->bottomY;
168 +                       tmpBottomY = oldMaxY - tmppriv->topY;
169 +                       break;
170 +                     default: /* ROTATE_NONE */
171 +                       tmpTopX = tmppriv->topX;
172 +                       tmpBottomX = tmppriv->bottomX;
173 +                       tmpTopY = tmppriv->topY;
174 +                       tmpBottomY = tmppriv->bottomY;
175 +                       break;
176 +                   } 
177 +                   /* and rotate them back */
178 +                   switch (value) {
179 +                     case ROTATE_CW:
180 +                       tmppriv->topX = tmpTopY;
181 +                       tmppriv->bottomX = tmpBottomY;
182 +                       tmppriv->topY = priv->common->wcmMaxY - tmpBottomX;
183 +                       tmppriv->bottomY = priv->common->wcmMaxY - tmpTopX;
184 +                       break;
185 +                     case ROTATE_CCW:
186 +                       tmppriv->topX = priv->common->wcmMaxX - tmpBottomY;
187 +                       tmppriv->bottomX = priv->common->wcmMaxX - tmpTopY;
188 +                       tmppriv->topY = tmpTopX;
189 +                       tmppriv->bottomY = tmpBottomX;
190 +                       break;
191 +                     case ROTATE_HALF:
192 +                       tmppriv->topX = priv->common->wcmMaxX - tmpBottomX;
193 +                       tmppriv->bottomX = priv->common->wcmMaxX - tmpTopX;
194 +                       tmppriv->topY= priv->common->wcmMaxY - tmpBottomY;
195 +                       tmppriv->bottomY = priv->common->wcmMaxY - tmpTopY;
196 +                       break;
197 +                     default: /* ROTATE_NONE */
198 +                       tmppriv->topX = tmpTopX;
199 +                       tmppriv->bottomX = tmpBottomX;
200 +                       tmppriv->topY = tmpTopY;
201 +                       tmppriv->bottomY = tmpBottomY;
202 +                       break;
203 +                   } 
205 +                   InitValuatorAxisStruct(priv->common->wcmDevices[dev]->dev,
206 +                       0, tmppriv->topX, tmppriv->bottomX, priv->common->wcmResolX, /* tablet resolution */
207 +                       0, priv->common->wcmResolX); /* max_res */
209 +                   InitValuatorAxisStruct(priv->common->wcmDevices[dev]->dev,
210 +                       1, tmppriv->topY, tmppriv->bottomY, priv->common->wcmResolY, /* tablet resolution */
211 +                       0, priv->common->wcmResolY); /* max_res */
212 +                }
213 +               break;
214             default:
215                 DBG(10, ErrorF("xf86WcmSetParam invalid param %d\n",param));
216                 return BadMatch;
217 diff -Naur linuxwacom-0.7.0/src/xf86Wacom.h linuxwacom-0.7.0-rotate/src/xf86Wacom.h
218 --- linuxwacom-0.7.0/src/xf86Wacom.h    2005-09-19 19:43:14.000000000 -0400
219 +++ linuxwacom-0.7.0-rotate/src/xf86Wacom.h     2005-11-22 17:06:57.000000000 -0500
220 @@ -150,6 +150,12 @@
221  #define ERASER_PROX     4
222  #define OTHER_PROX      1
225 +#define ROTATE_NONE XWACOM_VALUE_ROTATE_NONE
226 +#define ROTATE_CW XWACOM_VALUE_ROTATE_CW
227 +#define ROTATE_CCW XWACOM_VALUE_ROTATE_CCW
228 +#define ROTATE_HALF XWACOM_VALUE_ROTATE_HALF
230  /******************************************************************************
231   * Forward Declarations
232   *****************************************************************************/
233 @@ -412,10 +418,6 @@
235  #define DEVICE_ISDV4 0x000C
237 -#define ROTATE_NONE 0
238 -#define ROTATE_CW 1
239 -#define ROTATE_CCW 2
241  #define MAX_CHANNELS 2
242  #define MAX_USB_EVENTS 32
244 diff -Naur linuxwacom-0.7.0/src/xsetwacom.c linuxwacom-0.7.0-rotate/src/xsetwacom.c
245 --- linuxwacom-0.7.0/src/xsetwacom.c    2005-09-19 19:43:14.000000000 -0400
246 +++ linuxwacom-0.7.0-rotate/src/xsetwacom.c     2005-11-22 17:17:24.000000000 -0500
247 @@ -190,6 +190,13 @@
248                         "on for Tablet PC. ",
249                         XWACOM_PARAM_TPCBUTTON, VALUE_OPTIONAL, 
250                         RANGE, 0, 1, BOOLEAN_VALUE, 1 },
251 +                       
252 +               { "Rotate",
253 +                       "Sets the rotation of the tablet. "
254 +                       "Values = NONE, CW, CCW, HALF (default is NONE).",
255 +                       XWACOM_PARAM_ROTATE, VALUE_OPTIONAL,
256 +                       RANGE, XWACOM_VALUE_ROTATE_NONE, XWACOM_VALUE_ROTATE_HALF, SINGLE_VALUE,
257 +                       XWACOM_VALUE_ROTATE_NONE },
259                 { "FileModel",
260                         "Writes tablet models to /etc/wacom.dat",
261 @@ -198,7 +205,7 @@
262                 { "FileOption",
263                         "Writes configuration options to /etc/X11/wcm.dev_name",
264                         XWACOM_PARAM_FILEOPTION, VALUE_OPTIONAL },
266 +                       
267                 { NULL }
268         };
270 @@ -403,6 +410,23 @@
271                                 !strcasecmp(pszValues[i],"false") ||
272                                 !strcasecmp(pszValues[i],"relative")))
273                                         nValues[i] = 0;
274 +                       else if (p->nParamID == XWACOM_PARAM_ROTATE)
275 +                       {
276 +                          if (!strcasecmp(pszValues[i],"none"))
277 +                              nValues[i] = XWACOM_VALUE_ROTATE_NONE;
278 +                          else if (!strcasecmp(pszValues[i],"cw"))
279 +                              nValues[i] = XWACOM_VALUE_ROTATE_CW;
280 +                          else if (!strcasecmp(pszValues[i],"ccw"))
281 +                              nValues[i] = XWACOM_VALUE_ROTATE_CCW;
282 +                          else if (!strcasecmp(pszValues[i],"half"))
283 +                              nValues[i] = XWACOM_VALUE_ROTATE_HALF;
284 +                          else
285 +                          {
286 +                               fprintf(stderr,"Set: Value '%s' is "
287 +                                       "invalid.\n",pszValues[i]);
288 +                               return 1;
289 +                          }
290 +                       }
291                         else
292                         {
293                                 fprintf(stderr,"Set: Value '%s' is "
294 diff -Naur linuxwacom-0.7.0/src/Xwacom.h linuxwacom-0.7.0-rotate/src/Xwacom.h
295 --- linuxwacom-0.7.0/src/Xwacom.h       2005-09-19 19:43:14.000000000 -0400
296 +++ linuxwacom-0.7.0-rotate/src/Xwacom.h        2005-11-22 17:06:00.000000000 -0500
297 @@ -44,5 +44,11 @@
298  #define XWACOM_PARAM_GIMP              102
299  #define XWACOM_PARAM_MMT               103
300  #define XWACOM_PARAM_TPCBUTTON         104
301 +#define XWACOM_PARAM_ROTATE             105
303 +#define XWACOM_VALUE_ROTATE_NONE 0
304 +#define XWACOM_VALUE_ROTATE_CW 1
305 +#define XWACOM_VALUE_ROTATE_CCW 2
306 +#define XWACOM_VALUE_ROTATE_HALF 3
308  #endif /* __XF86_XWACOM_H */