dix: Cleanup of GetPointerEvents
Changed all the checks for x&y valuator so the more complex calculation is only made once. Added TODOs for valuator/axis 2 and above for future correct handling of relative reporting of these. Signed-off-by: Peter Hutterer <peter@cs.unisa.edu.au>
This commit is contained in:
		
							parent
							
								
									a0241d5380
								
							
						
					
					
						commit
						fc1cc0adcb
					
				|  | @ -159,20 +159,22 @@ CreateClassesChangedEvent(EventList* event, | ||||||
|  * Rescale the coord between the two axis ranges. |  * Rescale the coord between the two axis ranges. | ||||||
|  */ |  */ | ||||||
| static int | static int | ||||||
| rescaleValuatorAxis(int coord, int fmin, int fmax, | rescaleValuatorAxis(int coord, AxisInfoPtr from, AxisInfoPtr to, | ||||||
|                     int tmin, int tmax, int smax) |                     int defmax) | ||||||
| { | { | ||||||
|     if(fmin >= fmax) { |     int fmin = 0, tmin = 0, fmax = defmax, tmax = defmax; | ||||||
|         fmin = 0; | 
 | ||||||
|         fmax = smax; |     if(from && from->min_value < from->max_value) { | ||||||
|  |         fmin = from->min_value; | ||||||
|  |         fmax = from->max_value; | ||||||
|     } |     } | ||||||
|     if(tmin >= tmax) { |     if(to && to->min_value < to->max_value) { | ||||||
|         tmin = 0; |         tmin = to->min_value; | ||||||
|         tmax = smax; |         tmax = to->max_value; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     if(fmin == tmin && fmax == tmax) |     if(fmin == tmin && fmax == tmax) | ||||||
|         return coord; |         return coord; | ||||||
| 
 |  | ||||||
|     return (int)(((float)(coord - fmin)) * (tmax - tmin + 1) / |     return (int)(((float)(coord - fmin)) * (tmax - tmin + 1) / | ||||||
|                  (fmax - fmin + 1)) + tmin; |                  (fmax - fmin + 1)) + tmin; | ||||||
| } | } | ||||||
|  | @ -194,13 +196,11 @@ updateSlaveDeviceCoords(DeviceIntPtr master, DeviceIntPtr pDev) | ||||||
|     /* the valuator axis is in device coords and holds the
 |     /* the valuator axis is in device coords and holds the
 | ||||||
|      * position of the pointer, but in device coords. */ |      * position of the pointer, but in device coords. */ | ||||||
|     if(pDev->valuator->numAxes > 0) |     if(pDev->valuator->numAxes > 0) | ||||||
|         pDev->valuator->axisVal[0] = rescaleValuatorAxis(pDev->lastx, 0, scr->width, |         pDev->valuator->axisVal[0] = rescaleValuatorAxis(pDev->lastx, NULL, | ||||||
|                                             pDev->valuator->axes[0].min_value, |                                             pDev->valuator->axes + 0, scr->width); | ||||||
|                                             pDev->valuator->axes[0].max_value, scr->width); |  | ||||||
|     if(pDev->valuator->numAxes > 1) |     if(pDev->valuator->numAxes > 1) | ||||||
|         pDev->valuator->axisVal[1] = rescaleValuatorAxis(pDev->lasty, 0, scr->height, |         pDev->valuator->axisVal[1] = rescaleValuatorAxis(pDev->lasty, NULL, | ||||||
|                                             pDev->valuator->axes[1].min_value, |                                             pDev->valuator->axes + 1, scr->height); | ||||||
|                                             pDev->valuator->axes[1].max_value, scr->height); |  | ||||||
|     /*TODO calculate the other axis as well based on info from the old slave-device */ |     /*TODO calculate the other axis as well based on info from the old slave-device */ | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -707,17 +707,22 @@ FreeEventList(EventListPtr list, int num_events) | ||||||
|  * The DDX is responsible for allocating the event structure in the first |  * The DDX is responsible for allocating the event structure in the first | ||||||
|  * place via InitEventList() and GetMaximumEventsNum(), and for freeing it. |  * place via InitEventList() and GetMaximumEventsNum(), and for freeing it. | ||||||
|  * |  * | ||||||
|  |  * In the generated events rootX/Y will be in absolute screen coords and | ||||||
|  |  * the valuator information in the absolute or relative device coords. | ||||||
|  |  * lastx/y of the device is always in absolute screen coords while the | ||||||
|  |  * device valuator struct contain the absolute device coords. | ||||||
|  */ |  */ | ||||||
| _X_EXPORT int | _X_EXPORT int | ||||||
| GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, | GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, | ||||||
|                  int flags, int first_valuator, int num_valuators, |                  int flags, int first_valuator, int num_valuators, | ||||||
|                  int *valuators) { |                  int *valuators) { | ||||||
|     int num_events = 1; |     int num_events = 1; | ||||||
|     CARD32 ms = 0; |     CARD32 ms; | ||||||
|     deviceKeyButtonPointer *kbp = NULL; |     deviceKeyButtonPointer *kbp = NULL; | ||||||
|     DeviceIntPtr master; |     DeviceIntPtr master; | ||||||
|     int x, y, cx, cy; |     int x, y, cx, cy; | ||||||
|     ScreenPtr scr = miPointerGetScreen(pDev); |     ScreenPtr scr = miPointerGetScreen(pDev); | ||||||
|  |     int *v0 = NULL, *v1 = NULL; | ||||||
| 
 | 
 | ||||||
|     /* Sanity checks. */ |     /* Sanity checks. */ | ||||||
|     if (type != MotionNotify && type != ButtonPress && type != ButtonRelease) |     if (type != MotionNotify && type != ButtonPress && type != ButtonRelease) | ||||||
|  | @ -756,29 +761,34 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, | ||||||
|         events++; |         events++; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /* Fetch pointers into the valuator array for more easy to read code */ | ||||||
|  |     if (num_valuators >= 1 && first_valuator == 0) | ||||||
|  |         v0 = valuators + 0; | ||||||
|  |     if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) | ||||||
|  |         v1 = valuators + 1 - first_valuator; | ||||||
|  | 
 | ||||||
|     /* Set x and y based on whether this is absolute or relative, and
 |     /* Set x and y based on whether this is absolute or relative, and
 | ||||||
|      * accelerate if we need to. */ |      * accelerate if we need to. */ | ||||||
|     x = pDev->valuator->axisVal[0]; |     x = pDev->valuator->axisVal[0]; | ||||||
|     y = pDev->valuator->axisVal[1]; |     y = pDev->valuator->axisVal[1]; | ||||||
|     if (flags & POINTER_ABSOLUTE) { |     if (flags & POINTER_ABSOLUTE) { | ||||||
|         if (num_valuators >= 1 && first_valuator == 0) |         if(v0) x = *v0; | ||||||
|             x = valuators[0]; |         if(v1) y = *v1; | ||||||
|         if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) |         /*TODO: Update the rest of the valuators */ | ||||||
|             y = valuators[1 - first_valuator]; |  | ||||||
| 
 | 
 | ||||||
|         /* Clip both x and y to the defined limits (usually co-ord space limit). */ |         /* Clip both x and y to the defined limits (usually co-ord space limit). */ | ||||||
|         clipAxis(pDev, 0, &x); |         clipAxis(pDev, 0, &x); | ||||||
|         clipAxis(pDev, 1, &y); |         clipAxis(pDev, 1, &y); | ||||||
|  |         /*TODO: Clip the rest of the valuators */ | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         if (flags & POINTER_ACCELERATE) |         if (flags & POINTER_ACCELERATE) | ||||||
|             acceleratePointer(pDev, first_valuator, num_valuators, |             acceleratePointer(pDev, first_valuator, num_valuators, | ||||||
|                               valuators); |                               valuators); | ||||||
| 
 | 
 | ||||||
|         if (first_valuator == 0 && num_valuators >= 1) |         if(v0) x += *v0; | ||||||
|             x += valuators[0]; |         if(v1) y += *v1; | ||||||
|         if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) |         /*TODO: Update the rest of the valuators */ | ||||||
|             y += valuators[1 - first_valuator]; |  | ||||||
| 
 | 
 | ||||||
|         /* if not core -> clip both x and y to the defined limits (usually
 |         /* if not core -> clip both x and y to the defined limits (usually
 | ||||||
|          * co-ord space limit). */ |          * co-ord space limit). */ | ||||||
|  | @ -786,15 +796,14 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, | ||||||
|             clipAxis(pDev, 0, &x); |             clipAxis(pDev, 0, &x); | ||||||
|             clipAxis(pDev, 1, &y); |             clipAxis(pDev, 1, &y); | ||||||
|         } |         } | ||||||
|  |         /*TODO: Clip the rest of the valuators (Yes, here. Only x&y get special treatment) */ | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* scale x&y to screen */ |     /* scale x&y to screen */ | ||||||
|     pDev->lastx = cx = rescaleValuatorAxis(x, pDev->valuator->axes[0].min_value, |     pDev->lastx = cx = rescaleValuatorAxis(x, pDev->valuator->axes + 0, | ||||||
|                                            pDev->valuator->axes[0].max_value, |                                            NULL, scr->width); | ||||||
|                                            0, scr->width, scr->width); |     pDev->lasty = cy = rescaleValuatorAxis(y, pDev->valuator->axes + 1, | ||||||
|     pDev->lasty = cy = rescaleValuatorAxis(y, pDev->valuator->axes[1].min_value, |                                            NULL, scr->height); | ||||||
|                                            pDev->valuator->axes[1].max_value, |  | ||||||
|                                            0, scr->height, scr->height); |  | ||||||
| 
 | 
 | ||||||
|     /* This takes care of crossing screens for us, as well as clipping
 |     /* This takes care of crossing screens for us, as well as clipping
 | ||||||
|      * to the current screen.  Right now, we only have one history buffer, |      * to the current screen.  Right now, we only have one history buffer, | ||||||
|  | @ -803,15 +812,11 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, | ||||||
| 
 | 
 | ||||||
|     scr = miPointerGetScreen(pDev); |     scr = miPointerGetScreen(pDev); | ||||||
|     if(cx != pDev->lastx) |     if(cx != pDev->lastx) | ||||||
|         x = rescaleValuatorAxis(pDev->lastx, 0, scr->width, |         x = rescaleValuatorAxis(pDev->lastx, NULL, | ||||||
|                                 pDev->valuator->axes[0].min_value, |                                 pDev->valuator->axes + 0, scr->width); | ||||||
|                                 pDev->valuator->axes[0].max_value, |  | ||||||
|                                 scr->width); |  | ||||||
|     if(cy != pDev->lasty) |     if(cy != pDev->lasty) | ||||||
|         y = rescaleValuatorAxis(pDev->lasty, 0, scr->height, |         y = rescaleValuatorAxis(pDev->lasty, NULL, | ||||||
|                                 pDev->valuator->axes[1].min_value, |                                 pDev->valuator->axes + 1, scr->height); | ||||||
|                                 pDev->valuator->axes[1].max_value, |  | ||||||
|                                 scr->height); |  | ||||||
| 
 | 
 | ||||||
|     updateMotionHistory(pDev, ms, first_valuator, num_valuators, valuators); |     updateMotionHistory(pDev, ms, first_valuator, num_valuators, valuators); | ||||||
| 
 | 
 | ||||||
|  | @ -823,19 +828,17 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons, | ||||||
|     /* update the valuators based on the mode of the InputDevice */ |     /* update the valuators based on the mode of the InputDevice */ | ||||||
|     if(pDev->valuator->mode == Absolute) { |     if(pDev->valuator->mode == Absolute) { | ||||||
|         /* Update the valuators with the true value sent to the client*/ |         /* Update the valuators with the true value sent to the client*/ | ||||||
|         if (first_valuator == 0 && num_valuators >= 1) |         if(v0) *v0 = x; | ||||||
|             valuators[0] = x; |         if(v1) *v1 = y; | ||||||
|         if (first_valuator <= 1 && num_valuators >= (2 - first_valuator)) |         /*TODO Ensure that valuator 2 and onward also are absolute */ | ||||||
|             valuators[1] = y; |  | ||||||
|     } else {/* Relative mode */ |     } else {/* Relative mode */ | ||||||
|         /* If driver reported in absolute, calculate the relative valuator
 |         /* If driver reported in absolute, calculate the relative valuator
 | ||||||
|          * values as a delta from the old absolute values of the valuator |          * values as a delta from the old absolute values of the valuator | ||||||
|          * values. If relative report, keep it as-is.*/ |          * values. If relative report, keep it as-is.*/ | ||||||
|         if (flags & POINTER_ABSOLUTE) { |         if (flags & POINTER_ABSOLUTE) { | ||||||
|             int i; |             int i; | ||||||
|             for (i = first_valuator; i < num_valuators; i++) |             for (i = 0; i < num_valuators; i++) | ||||||
|                 valuators[i] = valuators[i] - pDev->valuator->axisVal[i]; |                 valuators[i] = valuators[i] - pDev->valuator->axisVal[i + first_valuator]; | ||||||
| 
 |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     /* Save the last calculated device axis value in the device
 |     /* Save the last calculated device axis value in the device
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue