1 /* 2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.glass.ui.lens; 27 28 import com.sun.glass.events.TouchEvent; 29 import com.sun.glass.events.MouseEvent; 30 import com.sun.glass.events.KeyEvent; 31 import com.sun.glass.ui.TouchInputSupport; 32 import com.sun.glass.ui.GestureSupport; 33 import com.sun.glass.ui.Application; 34 import com.sun.glass.ui.View; 35 36 import java.lang.Integer; 37 import java.security.AccessController; 38 import java.security.PrivilegedAction; 39 40 41 final class LensTouchInputSupport { 42 43 /** 44 * This property define the size of the tap radius which can be seen as the 45 * 'finger size'. After the first tap, a touch point will be considered 46 * STILL as long as the point coordinates are within the tap radius. When the 47 * point coordinates move outside the tap radius the point will be considered 48 * as 'dragging' and all move events will be reported as long as they are 49 * greater then the touchMoveSensitivity property 50 * Property is used by Lens native input driver 51 * 52 */ 53 static final int touchTapRadius; 54 /** 55 * This property determine the sensitivity of move events from touch. The 56 * bigger the value the less sensitive is the touch screen. In practice move 57 * events with a delta smaller then the value of this property will be 58 * filtered out.The value of the property is in pixels. 59 * Property is used by Lens native input driver 60 */ 61 private static final int touchMoveSensitivity; 62 63 /** 64 * This property enables or disables input device pruning. When input 65 * device pruning is enabled, only the first device input node of a 66 * device is captured. So if an input device driver registers nodes 67 * /dev/input/event2 and /dev/input/event3 for the same devices, only 68 * the first node reported by udev is used. 69 * Input device pruning is off by default. 70 */ 71 private static final boolean pruneInputDevices; 72 73 /** 74 * This property enable/disable multi touch support by the input driver. 75 * When the property is disabled and a multitouch screen is connected, the 76 * input driver will 'downgrade' the screen events to a single touch 77 * point, as if a single touch screen was connected 78 * 79 */ 80 private static final boolean useMultiTouch; 81 82 /** 83 * This property is used for printing raw events, device properties, device 84 * attach / detach, low level Lens input driver decisions etc. Useful for 85 * debugging a new input device that is not recognized or behave wrongly by 86 * the Lens input driver. Property is disabled by default 87 */ 88 private static final boolean enableDeviceTrace; 89 90 static { 91 touchTapRadius = AccessController.doPrivileged( 92 (PrivilegedAction<Integer>) () -> Integer.getInteger("lens.input.touch.TapRadius", 20)); 93 94 touchMoveSensitivity = AccessController.doPrivileged( 95 (PrivilegedAction<Integer>) () -> Integer.getInteger("lens.input.touch.MoveSensitivity", 20)); 96 97 pruneInputDevices = AccessController.doPrivileged( 98 (PrivilegedAction<Boolean>) () -> Boolean.getBoolean("lens.input.pruneDevices")); 99 100 useMultiTouch = AccessController.doPrivileged( 101 (PrivilegedAction<Boolean>) () -> !(Boolean.getBoolean("lens.input.forceSingleTouch"))); 102 103 enableDeviceTrace = AccessController.doPrivileged( 104 (PrivilegedAction<Boolean>) () -> Boolean.getBoolean("lens.input.trace")); 105 106 } 107 108 109 private final static GestureSupport gestures = new GestureSupport(false); 110 private final static TouchInputSupport touches = 111 new TouchInputSupport(gestures.createTouchCountListener(), false); 112 113 static void postTouchEvent(LensView view, int state, long id, 114 int x, int y, int absX, int absY) { 115 touches.notifyBeginTouchEvent(view, 0, true, 1); 116 touches.notifyNextTouchEvent(view, state, id, x, y, absX, absY); 117 touches.notifyEndTouchEvent(view); 118 } 119 120 static void postMultiTouchEvent(LensView view, int[] states, long[] ids, 121 int[] xs, int[] ys, int dx, int dy) { 122 touches.notifyBeginTouchEvent(view, 0, true, states.length); 123 for (int i = 0; i < states.length; i++) { 124 touches.notifyNextTouchEvent(view, states[i], ids[i], 125 xs[i] + dx, ys[i] + dy, 126 xs[i], ys[i]); 127 } 128 touches.notifyEndTouchEvent(view); 129 } 130 } 131