Compare commits

...

37 Commits

Author SHA1 Message Date
Denis Konoplev
3c7dbc8f04 Double size constant 2019-11-14 14:41:44 +03:00
Denis Konoplev
62f7f766d4 Fix formatting 2019-11-14 01:38:14 +03:00
Denis Konoplev
b1926bdb59 Replace lock with volatile 2019-11-14 01:34:31 +03:00
Denis Konoplev
81e60e5e9c Remove redundunt comment 2019-11-14 01:22:37 +03:00
Denis Konoplev
8a8cbd9310 Remove comments 2019-11-14 01:17:43 +03:00
Denis Konoplev
772eef8cd7 Remove redundunt workaround 2019-11-14 00:34:02 +03:00
Denis Konoplev
0e299b0bdb Refactor and fix comments 2019-11-07 15:51:36 +03:00
Denis Konoplev
cdc9e359ee Turn off multitouch 2019-11-07 14:20:11 +03:00
Denis Konoplev
4d8db791a8 Skipped deltas 2019-11-07 14:20:10 +03:00
Denis Konoplev
ff12dc9542 Touch click 2019-11-07 14:20:10 +03:00
Denis Konoplev
914ae8f936 Don't send press events on touch scroll 2019-11-07 14:15:42 +03:00
Denis Konoplev
28cb76df77 Fix scope 2019-11-07 14:15:42 +03:00
Denis Konoplev
934d918311 Touch events for inertial experiment 2019-11-07 14:15:42 +03:00
Denis Konoplev
7bbed87471 Code review 2019-11-07 14:15:41 +03:00
Denis Konoplev
834d57edf6 Refactor 2019-11-07 14:15:41 +03:00
Denis Konoplev
811cea5610 XISelectEvents proper return value 2019-11-07 14:15:40 +03:00
Denis Konoplev
cbc4299f2d Pixel scrolling 2019-11-07 14:15:40 +03:00
Denis Konoplev
fca82dafa1 Move to inner scope 2019-11-07 14:15:40 +03:00
Denis Konoplev
951f4bdc00 Refactor 2019-11-07 14:15:39 +03:00
Denis Konoplev
3c0bc75172 Refactor + modifiers 2019-11-07 14:15:39 +03:00
Denis Konoplev
82fd81ba35 Version querying logging 2019-11-07 14:15:18 +03:00
Denis Konoplev
8ca68e66bb Fix version quering 2019-11-07 14:15:17 +03:00
Denis Konoplev
cb8bb82dc2 Check XInput extension 2019-11-07 14:15:17 +03:00
Denis Konoplev
f2436be7ca Free event data 2019-11-07 14:15:16 +03:00
Denis Konoplev
779e93ee2c Xi select events in more general way 2019-11-07 14:15:16 +03:00
Denis Konoplev
029552b010 XISelectEvents 2019-11-07 14:15:16 +03:00
Denis Konoplev
7e51c75463 TODO modifiers 2019-11-07 14:15:15 +03:00
Denis Konoplev
1034319f69 Click + fake pixel scrolling 2019-11-07 14:15:15 +03:00
Denis Konoplev
bd7695a9f0 Only master devices 2019-11-07 14:15:14 +03:00
Denis Konoplev
bc0c3c9671 Free event data 2019-11-07 14:15:14 +03:00
Denis Konoplev
f440cae2a7 Natural scroll direction 2019-11-07 14:15:14 +03:00
Denis Konoplev
5582217946 Touch handling 2019-11-07 14:15:13 +03:00
Denis Konoplev
c81034edc4 XI2 Constants 2019-11-07 14:15:13 +03:00
Denis Konoplev
2f36acdfa7 XLibWrapper XI2 functions 2019-11-07 14:15:12 +03:00
Denis Konoplev
c5f98324ee X11 native get put double 2019-11-07 14:15:12 +03:00
Denis Konoplev
4fbed06017 Native data types 2019-11-07 14:15:12 +03:00
Denis Konoplev
bdea9f75a5 XI2 headers in xlib wrapper generator 2019-11-07 14:15:11 +03:00
10 changed files with 470 additions and 4 deletions

View File

@@ -272,12 +272,14 @@ XEvent.xclient 0
XEvent.xcolormap 0 XEvent.xcolormap 0
XEvent.xconfigure 0 XEvent.xconfigure 0
XEvent.xconfigurerequest 0 XEvent.xconfigurerequest 0
XEvent.xcookie 0
XEvent.xcreatewindow 0 XEvent.xcreatewindow 0
XEvent.xcrossing 0 XEvent.xcrossing 0
XEvent.xdestroywindow 0 XEvent.xdestroywindow 0
XEvent.xerror 0 XEvent.xerror 0
XEvent.xexpose 0 XEvent.xexpose 0
XEvent.xfocus 0 XEvent.xfocus 0
XEvent.xgeneric 0
XEvent.xgraphicsexpose 0 XEvent.xgraphicsexpose 0
XEvent.xgravity 0 XEvent.xgravity 0
XEvent.xkey 0 XEvent.xkey 0
@@ -370,6 +372,22 @@ XGCValues.subwindow_mode 96
XGCValues.tile 64 XGCValues.tile 64
XGCValues.ts_x_origin 80 XGCValues.ts_x_origin 80
XGCValues.ts_y_origin 84 XGCValues.ts_y_origin 84
XGenericEvent 40
XGenericEventCookie 56
XGenericEventCookie.cookie 40
XGenericEventCookie.data 48
XGenericEventCookie.display 24
XGenericEventCookie.evtype 36
XGenericEventCookie.extension 32
XGenericEventCookie.send_event 16
XGenericEventCookie.serial 8
XGenericEventCookie.type 0
XGenericEvent.display 24
XGenericEvent.evtype 36
XGenericEvent.extension 32
XGenericEvent.send_event 16
XGenericEvent.serial 8
XGenericEvent.type 0
XGraphicsExposeEvent 72 XGraphicsExposeEvent 72
XGraphicsExposeEvent.count 56 XGraphicsExposeEvent.count 56
XGraphicsExposeEvent.display 24 XGraphicsExposeEvent.display 24
@@ -396,6 +414,9 @@ XHostAddress 16
XHostAddress.address 8 XHostAddress.address 8
XHostAddress.family 0 XHostAddress.family 0
XHostAddress.length 4 XHostAddress.length 4
XIButtonState 16
XIButtonState.mask 8
XIButtonState.mask_len 0
XIconSize 24 XIconSize 24
XIconSize.height_inc 20 XIconSize.height_inc 20
XIconSize.max_height 12 XIconSize.max_height 12
@@ -403,6 +424,29 @@ XIconSize.max_width 8
XIconSize.min_height 4 XIconSize.min_height 4
XIconSize.min_width 0 XIconSize.min_width 0
XIconSize.width_inc 16 XIconSize.width_inc 16
XIDeviceEvent 200
XIDeviceEvent.buttons 128
XIDeviceEvent.child 80
XIDeviceEvent.detail 56
XIDeviceEvent.deviceid 48
XIDeviceEvent.display 24
XIDeviceEvent.event 72
XIDeviceEvent.event_x 104
XIDeviceEvent.event_y 112
XIDeviceEvent.evtype 36
XIDeviceEvent.extension 32
XIDeviceEvent.flags 120
XIDeviceEvent.group 184
XIDeviceEvent.mods 168
XIDeviceEvent.root 64
XIDeviceEvent.root_x 88
XIDeviceEvent.root_y 96
XIDeviceEvent.send_event 16
XIDeviceEvent.serial 8
XIDeviceEvent.sourceid 52
XIDeviceEvent.time 40
XIDeviceEvent.type 0
XIDeviceEvent.valuators 144
XImage 136 XImage 136
XImage.bitmap_bit_order 32 XImage.bitmap_bit_order 32
XImage.bitmap_pad 36 XImage.bitmap_pad 36
@@ -436,6 +480,11 @@ XIMHotKeyTrigger.modifier_mask 12
XIMHotKeyTriggers 16 XIMHotKeyTriggers 16
XIMHotKeyTriggers.key 8 XIMHotKeyTriggers.key 8
XIMHotKeyTriggers.num_hot_key 0 XIMHotKeyTriggers.num_hot_key 0
XIModifierState 16
XIModifierState.base 0
XIModifierState.effective 12
XIModifierState.latched 4
XIModifierState.locked 8
XIMPreeditCaretCallbackStruct 12 XIMPreeditCaretCallbackStruct 12
XIMPreeditCaretCallbackStruct.direction 4 XIMPreeditCaretCallbackStruct.direction 4
XIMPreeditCaretCallbackStruct.position 0 XIMPreeditCaretCallbackStruct.position 0
@@ -472,6 +521,10 @@ XIMText.string 24
XIMValuesList 16 XIMValuesList 16
XIMValuesList.count_values 0 XIMValuesList.count_values 0
XIMValuesList.supported_values 8 XIMValuesList.supported_values 8
XIValuatorState 24
XIValuatorState.mask 8
XIValuatorState.mask_len 0
XIValuatorState.values 16
XkbAccessXNotifyEvent 64 XkbAccessXNotifyEvent 64
XkbAccessXNotifyEvent.debounce_delay 60 XkbAccessXNotifyEvent.debounce_delay 60
XkbAccessXNotifyEvent.detail 48 XkbAccessXNotifyEvent.detail 48

View File

@@ -127,6 +127,22 @@ XKeymapEvent
display long display long
window long window long
key_vector array byte 32 key_vector array byte 32
XGenericEvent
type int
serial long
send_event Bool
display long
extension int
evtype int
XGenericEventCookie
type int
serial long
send_event Bool
display long
extension int
evtype int
cookie int
data pointer
XDestroyWindowEvent XDestroyWindowEvent
type int type int
serial long serial long
@@ -814,6 +830,8 @@ XEvent
xmapping struct XMappingEvent xmapping struct XMappingEvent
xerror struct XErrorEvent xerror struct XErrorEvent
xkeymap struct XKeymapEvent xkeymap struct XKeymapEvent
xgeneric struct XGenericEvent
xcookie struct XGenericEventCookie
pad array long 24 pad array long 24
XkbAnyEvent XkbAnyEvent
@@ -1039,3 +1057,42 @@ XkbEvent
accessx struct XkbAccessXNotifyEvent accessx struct XkbAccessXNotifyEvent
device struct XkbExtensionDeviceNotifyEvent device struct XkbExtensionDeviceNotifyEvent
core struct XEvent core struct XEvent
XIButtonState
mask_len int
mask pointer byte
XIValuatorState
mask_len int
mask pointer byte
values pointer double
XIModifierState
base int
latched int
locked int
effective int
XIDeviceEvent
type int
serial long
send_event Bool
display long
extension int
evtype int
time ulong
deviceid int
sourceid int
detail int
root long
event long
child long
root_x double
root_y double
event_x double
event_y double
flags int
buttons struct XIButtonState
valuators struct XIValuatorState
mods struct XIModifierState
group struct XIModifierState

View File

@@ -1142,6 +1142,8 @@ public class WrapperGenerator {
pw.println("/* This file is an automatically generated file, please do not edit this file, modify the XlibParser.java file instead !*/\n" ); pw.println("/* This file is an automatically generated file, please do not edit this file, modify the XlibParser.java file instead !*/\n" );
pw.println("#include <X11/Xlib.h>\n#include <X11/Xutil.h>\n#include <X11/Xos.h>\n#include <X11/Xatom.h>\n#include <stdio.h>\n"); pw.println("#include <X11/Xlib.h>\n#include <X11/Xutil.h>\n#include <X11/Xos.h>\n#include <X11/Xatom.h>\n#include <stdio.h>\n");
pw.println("#include <X11/extensions/Xdbe.h>"); pw.println("#include <X11/extensions/Xdbe.h>");
pw.println("#include <X11/extensions/XI2.h>");
pw.println("#include <X11/extensions/XInput2.h>");
pw.println("#include <X11/XKBlib.h>"); pw.println("#include <X11/XKBlib.h>");
pw.println("#include \"awt_p.h\""); pw.println("#include \"awt_p.h\"");
pw.println("#include \"color.h\""); pw.println("#include \"color.h\"");

View File

@@ -374,6 +374,20 @@ class Native {
return res; return res;
} }
/**
* Access to C double data(eight bytes)
*/
static final int DOUBLE_SIZE = 8;
static double getDouble(long ptr) { return unsafe.getDouble(ptr); }
static double getDouble(long ptr, int index) { return getDouble(ptr + DOUBLE_SIZE * index); }
/**
* Stores to C double data(eight bytes)
*/
static void putDouble(long ptr, double data) { unsafe.putDouble(ptr, data); }
static void putDouble(long ptr, int index, double data) {
putDouble(ptr + index * DOUBLE_SIZE, data);
}
/** /**
* Access to C "unsigned long" date type, which is XID in X * Access to C "unsigned long" date type, which is XID in X

View File

@@ -55,7 +55,9 @@ public class XBaseWindow {
VISIBLE = "visible", // whether it is visible by default VISIBLE = "visible", // whether it is visible by default
SAVE_UNDER = "save under", // save content under this window SAVE_UNDER = "save under", // save content under this window
BACKING_STORE = "backing store", // enables double buffering BACKING_STORE = "backing store", // enables double buffering
BIT_GRAVITY = "bit gravity"; // copy old content on geometry change BIT_GRAVITY = "bit gravity", // copy old content on geometry change
XI_EVENT_MASK = "xi event mask", // xi event mask, Long
XI_DEVICE_ID = "xi device id"; // xi device id, Integer
private XCreateWindowParams delayedParams; private XCreateWindowParams delayedParams;
Set<Long> children = new HashSet<Long>(); Set<Long> children = new HashSet<Long>();
@@ -394,6 +396,19 @@ public class XBaseWindow {
throw new IllegalStateException("Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details"); throw new IllegalStateException("Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details");
} }
XToolkit.addToWinMap(window, this); XToolkit.addToWinMap(window, this);
Long xiEventMask = (Long) params.get(XI_EVENT_MASK);
if (xiEventMask != null && XToolkit.isXInputEnabled()) {
Integer xiDeviceId = (Integer) params.get(XI_DEVICE_ID);
if (xiDeviceId == null) {
xiDeviceId = XConstants.XIAllDevices;
}
int status = XToolkit.XISelectEvents(XToolkit.getDisplay(), window, xiEventMask, xiDeviceId);
if (status != XConstants.Success) {
throw new IllegalStateException("Couldn't select XI events. Status: " + status);
}
}
} finally { } finally {
xattr.dispose(); xattr.dispose();
} }
@@ -1065,6 +1080,10 @@ public class XBaseWindow {
width = scaleDown(xe.get_width()); width = scaleDown(xe.get_width());
height = scaleDown(xe.get_height()); height = scaleDown(xe.get_height());
} }
public void handleTouchEvent(XEvent xev) {
}
/** /**
* Checks ButtonRelease released all Mouse buttons * Checks ButtonRelease released all Mouse buttons
*/ */
@@ -1104,6 +1123,12 @@ public class XBaseWindow {
if (target == null || !isGrabbedEvent(ev, target)) { if (target == null || !isGrabbedEvent(ev, target)) {
target = XToolkit.windowToXWindow(ev.get_xany().get_window()); target = XToolkit.windowToXWindow(ev.get_xany().get_window());
} }
if (target == null && ev.get_type() == XConstants.GenericEvent &&
XlibWrapper.XGetEventData(ev.get_xgeneric().get_display(), ev.pData)) {
target = XToolkit.windowToXWindow(XToolkit.GetXIDeviceEvent(ev.get_xcookie()).get_event());
}
if (target != null && target.checkInitialised()) { if (target != null && target.checkInitialised()) {
target.dispatchEvent(ev); target.dispatchEvent(ev);
} }
@@ -1170,6 +1195,17 @@ public class XBaseWindow {
case XConstants.CreateNotify: case XConstants.CreateNotify:
handleCreateNotify(xev); handleCreateNotify(xev);
break; break;
case XConstants.GenericEvent:
switch (xev.get_xgeneric().get_evtype()) {
case XConstants.XI_TouchBegin:
case XConstants.XI_TouchUpdate:
case XConstants.XI_TouchEnd:
handleTouchEvent(xev);
break;
default:
break;
}
break;
} }
} }
protected boolean isEventDisabled(XEvent e) { protected boolean isEventDisabled(XEvent e) {

View File

@@ -170,7 +170,8 @@ public final class XConstants {
public static final int ColormapNotify = 32 ; public static final int ColormapNotify = 32 ;
public static final int ClientMessage = 33 ; public static final int ClientMessage = 33 ;
public static final int MappingNotify = 34 ; public static final int MappingNotify = 34 ;
public static final int LASTEvent = 35 ; /* must be bigger than any event # */ public static final int GenericEvent = 35 ;
public static final int LASTEvent = 36 ; /* must be bigger than any event # */
/* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer, /* Key masks. Used as modifiers to GrabButton and GrabKey, results of QueryPointer,
@@ -674,4 +675,70 @@ public final class XConstants {
public static final long XkbModifierMapMask = (1L<<2); public static final long XkbModifierMapMask = (1L<<2);
public static final long XkbVirtualModsMask = (1L<<6); //server map public static final long XkbVirtualModsMask = (1L<<6); //server map
/* Fake device ID's for event selection */
public static final int XIAllDevices = 0;
public static final int XIAllMasterDevices = 1;
/* XI Event types */
public static final int XI_DeviceChanged = 1;
public static final int XI_KeyPress = 2;
public static final int XI_KeyRelease = 3;
public static final int XI_ButtonPress = 4;
public static final int XI_ButtonRelease = 5;
public static final int XI_Motion = 6;
public static final int XI_Enter = 7;
public static final int XI_Leave = 8;
public static final int XI_FocusIn = 9;
public static final int XI_FocusOut = 10;
public static final int XI_HierarchyChanged = 11;
public static final int XI_PropertyEvent = 12;
public static final int XI_RawKeyPress = 13;
public static final int XI_RawKeyRelease = 14;
public static final int XI_RawButtonPress = 15;
public static final int XI_RawButtonRelease = 16;
public static final int XI_RawMotion = 17;
public static final int XI_TouchBegin = 18;/* XI 2.2 */
public static final int XI_TouchUpdate = 19;
public static final int XI_TouchEnd = 20;
public static final int XI_TouchOwnership = 21;
public static final int XI_RawTouchBegin = 22;
public static final int XI_RawTouchUpdate = 23;
public static final int XI_RawTouchEnd = 24;
public static final int XI_BarrierHit = 25;/* XI 2.3 */
public static final int XI_BarrierLeave = 26;
public static final int XI_LASTEVENT = XI_BarrierLeave;
/* NOTE: XI2LASTEVENT in xserver/include/inputstr.h must be the same value
* as XI_LASTEVENT if the server is supposed to handle masks etc. for this
* type of event. */
/* Event masks.
* Note: the protocol spec defines a mask to be of (1 << type). Clients are
* free to create masks by bitshifting instead of using these defines.
*/
public static final long XI_DeviceChangedMask = 1L << XI_DeviceChanged;
public static final long XI_KeyPressMask = 1L << XI_KeyPress;
public static final long XI_KeyReleaseMask = 1L << XI_KeyRelease;
public static final long XI_ButtonPressMask = 1L << XI_ButtonPress;
public static final long XI_ButtonReleaseMask = 1L << XI_ButtonRelease;
public static final long XI_MotionMask = 1L << XI_Motion;
public static final long XI_EnterMask = 1L << XI_Enter;
public static final long XI_LeaveMask = 1L << XI_Leave;
public static final long XI_FocusInMask = 1L << XI_FocusIn;
public static final long XI_FocusOutMask = 1L << XI_FocusOut;
public static final long XI_HierarchyChangedMask = 1L << XI_HierarchyChanged;
public static final long XI_PropertyEventMask = 1L << XI_PropertyEvent;
public static final long XI_RawKeyPressMask = 1L << XI_RawKeyPress;
public static final long XI_RawKeyReleaseMask = 1L << XI_RawKeyRelease;
public static final long XI_RawButtonPressMask = 1L << XI_RawButtonPress;
public static final long XI_RawButtonReleaseMask = 1L << XI_RawButtonRelease;
public static final long XI_RawMotionMask = 1L << XI_RawMotion;
public static final long XI_TouchBeginMask = 1L << XI_TouchBegin;
public static final long XI_TouchEndMask = 1L << XI_TouchEnd;
public static final long XI_TouchOwnershipChangedMask = 1L << XI_TouchOwnership;
public static final long XI_TouchUpdateMask = 1L << XI_TouchUpdate;
public static final long XI_RawTouchBeginMask = 1L << XI_RawTouchBegin;
public static final long XI_RawTouchEndMask = 1L << XI_RawTouchEnd;
public static final long XI_RawTouchUpdateMask = 1L << XI_RawTouchUpdate;
public static final long XI_BarrierHitMask = 1L << XI_BarrierHit;
public static final long XI_BarrierLeaveMask = 1L << XI_BarrierLeave;
} }

View File

@@ -340,6 +340,7 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
log.finer("X locale modifiers are not supported, using default"); log.finer("X locale modifiers are not supported, using default");
} }
tryXKB(); tryXKB();
checkXInput();
AwtScreenData defaultScreen = new AwtScreenData(XToolkit.getDefaultScreenData()); AwtScreenData defaultScreen = new AwtScreenData(XToolkit.getDefaultScreenData());
awt_defaultFg = defaultScreen.get_blackpixel(); awt_defaultFg = defaultScreen.get_blackpixel();
@@ -741,6 +742,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
XBaseWindow.ungrabInput(); XBaseWindow.ungrabInput();
processException(thr); processException(thr);
} finally { } finally {
// free event data if XGetEventData was called
XlibWrapper.XFreeEventData(getDisplay(), ev.pData);
awtUnlock(); awtUnlock();
} }
} }
@@ -2573,6 +2576,58 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
} }
} }
private static volatile boolean hasXInputExtension = false;
public static boolean isXInputEnabled() {
return hasXInputExtension;
}
public static void checkXInput() {
awtLock();
try {
String extensionName = "XInputExtension";
boolean hasExtension = XlibWrapper.XQueryExtension(XToolkit.getDisplay(), extensionName,
XlibWrapper.iarg1, XlibWrapper.iarg2, XlibWrapper.iarg3);
if (!hasExtension) {
log.warning("X Input extension isn't available, error: {0}", Native.getInt(XlibWrapper.iarg1));
return;
}
final int requiredMajor = 2;
final int requiredMinor = 2;
Native.putInt(XlibWrapper.iarg1, requiredMajor);
Native.putInt(XlibWrapper.iarg2, requiredMinor);
int status = XlibWrapper.XIQueryVersion(XToolkit.getDisplay(), XlibWrapper.iarg1, XlibWrapper.iarg2);
if (status == XConstants.BadRequest) {
log.warning("X Input2 not supported in the server");
return;
}
int major = Native.getInt(XlibWrapper.iarg1);
int minor = Native.getInt(XlibWrapper.iarg2);
if (major >= requiredMajor && minor >= requiredMinor) {
hasXInputExtension = true;
} else {
log.warning("Desired version is 2.2, server version is {0}.{1}", major, minor);
}
} finally {
awtUnlock();
}
}
public static XIDeviceEvent GetXIDeviceEvent(XGenericEventCookie cookie) {
return new XIDeviceEvent(cookie.get_data());
}
public static int XISelectEvents(long display, long window, long mask, int deviceid) {
if (isXInputEnabled()) {
return XlibWrapper.XISelectEvents(display, window, mask, deviceid);
} else {
log.warning("Attempting to select xi events while xinput isn't available");
return XConstants.BadRequest;
}
}
private static long eventNumber; private static long eventNumber;
public static long getEventNumber() { public static long getEventNumber() {
awtLock(); awtLock();

View File

@@ -37,8 +37,6 @@ import sun.util.logging.PlatformLogger;
import sun.awt.*; import sun.awt.*;
import sun.awt.image.PixelConverter;
import sun.java2d.SunGraphics2D; import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData; import sun.java2d.SurfaceData;
@@ -59,6 +57,14 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
static long lastButton = 0; static long lastButton = 0;
static WeakReference<XWindow> lastWindowRef = null; static WeakReference<XWindow> lastWindowRef = null;
static int clickCount = 0; static int clickCount = 0;
private static int touchBeginX = 0, touchBeginY = 0;
private static int trackingId = 0;
private static boolean isTouchScroll = false;
private static final int TOUCH_CLICK_RADIUS = 3;
// all touch scrolls are measured in pixels
private static final int TOUCH_BEGIN = 2;
private static final int TOUCH_UPDATE = 3;
private static final int TOUCH_END = 4;
// used to check if we need to re-create surfaceData. // used to check if we need to re-create surfaceData.
int oldWidth = -1; int oldWidth = -1;
@@ -223,6 +229,11 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
params.putIfNull(BACKING_STORE, XToolkit.getBackingStoreType()); params.putIfNull(BACKING_STORE, XToolkit.getBackingStoreType());
params.putIfNull(XI_EVENT_MASK, XConstants.XI_TouchBeginMask |
XConstants.XI_TouchUpdateMask |
XConstants.XI_TouchEndMask);
params.putIfNull(XI_DEVICE_ID, XConstants.XIAllMasterDevices);
XToolkit.awtLock(); XToolkit.awtLock();
try { try {
if (wm_protocols == null) { if (wm_protocols == null) {
@@ -769,6 +780,112 @@ class XWindow extends XBaseWindow implements X11ComponentPeer {
} }
} }
public void handleTouchEvent(XEvent xev) {
super.handleTouchEvent(xev);
XIDeviceEvent dev = XToolkit.GetXIDeviceEvent(xev.get_xcookie());
// TODO remove this after TouchEvents support
// own touch processing by tracking id
if (isTouchReleased()) {
trackingId = dev.get_detail();
} else if (!isOwningTouch(dev.get_detail())) {
return;
}
int x = scaleDown((int) dev.get_event_x());
int y = scaleDown((int) dev.get_event_y());
if (dev.get_event() != window) {
Point localXY = toLocal(x, y);
x = localXY.x;
y = localXY.y;
}
int button = XConstants.buttons[0];
int modifiers = getModifiers(dev.get_mods().get_effective(), button, 0);
// turning off shift modifier
modifiers &= ~InputEvent.SHIFT_DOWN_MASK;
long jWhen = XToolkit.nowMillisUTC_offset(dev.get_time());
switch (dev.get_evtype()) {
case XConstants.XI_TouchBegin:
isTouchScroll = false;
touchBeginX = x;
touchBeginY = y;
break;
case XConstants.XI_TouchUpdate:
if (isInsideTouchClickBoundaries(x, y)) {
return;
}
if (!isTouchScroll) {
sendWheelEventFromTouch(dev, jWhen, modifiers, touchBeginX, touchBeginY, TOUCH_BEGIN, 1);
isTouchScroll = true;
}
if (lastY - y != 0) {
sendWheelEventFromTouch(dev, jWhen, modifiers, x, y, TOUCH_UPDATE, lastY - y);
}
// horizontal scroll
if (lastX - x != 0) {
modifiers |= InputEvent.SHIFT_DOWN_MASK;
sendWheelEventFromTouch(dev, jWhen, modifiers, x, y, TOUCH_UPDATE, lastX - x);
}
break;
case XConstants.XI_TouchEnd:
if (isTouchScroll) {
sendWheelEventFromTouch(dev, jWhen, modifiers, x, y, TOUCH_END, 1);
} else {
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_PRESSED, jWhen, modifiers, touchBeginX, touchBeginY, button);
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_RELEASED, jWhen, modifiers, touchBeginX, touchBeginY, button);
sendMouseEventFromTouch(dev, MouseEvent.MOUSE_CLICKED, jWhen, modifiers, touchBeginX, touchBeginY, button);
}
// release touch processing
trackingId = 0;
break;
}
lastX = x;
lastY = y;
}
private boolean isInsideTouchClickBoundaries(int x, int y) {
return Math.abs(touchBeginX - x) <= TOUCH_CLICK_RADIUS &&
Math.abs(touchBeginY - y) <= TOUCH_CLICK_RADIUS;
}
private static boolean isOwningTouch(int fingerId) {
return trackingId == fingerId;
}
private static boolean isTouchReleased() {
return trackingId == 0;
}
private void sendWheelEventFromTouch(XIDeviceEvent dev, long jWhen, int modifiers, int x, int y, int type, int delta) {
postEventToEventQueue(
new MouseWheelEvent(getEventSource(), MouseEvent.MOUSE_WHEEL, jWhen,
modifiers,
x, y,
scaleDown((int) dev.get_root_x()),
scaleDown((int) dev.get_root_y()),
0, false, type,
1, delta));
}
private void sendMouseEventFromTouch(XIDeviceEvent dev, int type, long jWhen, int modifiers, int x, int y, int button) {
postEventToEventQueue(
new MouseEvent(getEventSource(), type, jWhen,
modifiers,
x, y,
scaleDown((int) dev.get_root_x()),
scaleDown((int) dev.get_root_y()),
1,
false, button));
}
public void handleMotionNotify(XEvent xev) { public void handleMotionNotify(XEvent xev) {
super.handleMotionNotify(xev); super.handleMotionNotify(xev);
XMotionEvent xme = xev.get_xmotion(); XMotionEvent xme = xev.get_xmotion();

View File

@@ -564,6 +564,12 @@ static native String XSetLocaleModifiers(String modifier_list);
static native void SetZOrder(long display, long window, long above); static native void SetZOrder(long display, long window, long above);
static native int XIQueryVersion(long display, long major_version_iptr, long minor_version_iptr);
static native int XISelectEvents(long display, long window, long mask, int deviceid);
static native boolean XGetEventData(long display, long ptr);
static native void XFreeEventData(long display, long ptr);
/* Global memory area used for X lib parameter passing */ /* Global memory area used for X lib parameter passing */
static final long lbuffer = unsafe.allocateMemory(64); // array to hold 8 longs static final long lbuffer = unsafe.allocateMemory(64); // array to hold 8 longs

View File

@@ -37,6 +37,8 @@
#include <string.h> #include <string.h>
#include <X11/extensions/Xdbe.h> #include <X11/extensions/Xdbe.h>
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#include <X11/extensions/XI2.h>
#include <X11/extensions/XInput2.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/Sunkeysym.h> #include <X11/Sunkeysym.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
@@ -2317,6 +2319,63 @@ Java_sun_awt_X11_XlibWrapper_SetZOrder
value_mask, &wc ); value_mask, &wc );
} }
/*
* Class: XlibWrapper
* Method: XIQueryVersion
*/
JNIEXPORT jint JNICALL
Java_sun_awt_X11_XlibWrapper_XIQueryVersion
(JNIEnv *env, jclass clazz, jlong display, jlong major_version_iptr, jlong minor_version_iptr)
{
return XIQueryVersion((Display *)jlong_to_ptr(display),
jlong_to_ptr(major_version_iptr), jlong_to_ptr(minor_version_iptr));
}
/*
* Class: XlibWrapper
* Method: XISelectEvents
*/
JNIEXPORT jint JNICALL
Java_sun_awt_X11_XlibWrapper_XISelectEvents
(JNIEnv *env, jclass clazz, jlong display, jlong window, jlong mask, jint deviceid)
{
XIEventMask evmask;
evmask.deviceid = (int)deviceid;
evmask.mask_len = XIMaskLen(XI_LASTEVENT);
union jlong_to_char_ptr
{
jlong value;
unsigned char mask[8];
} converter;
converter.value = mask;
evmask.mask = &converter.mask;
return XISelectEvents((Display *)jlong_to_ptr(display), (Window)jlong_to_ptr(window),
&evmask, /*num masks*/ 1);
}
/*
* Class: XlibWrapper
* Method: XGetEventData
*/
JNIEXPORT jboolean JNICALL
Java_sun_awt_X11_XlibWrapper_XGetEventData
(JNIEnv *env, jclass clazz, jlong display, jlong ptr)
{
return XGetEventData((Display *)jlong_to_ptr(display),
(XGenericEventCookie *)ptr_to_jlong(ptr)) ? JNI_TRUE : JNI_FALSE;
}
/*
* Class: XlibWrapper
* Method: XFreeEventData
*/
JNIEXPORT void JNICALL
Java_sun_awt_X11_XlibWrapper_XFreeEventData
(JNIEnv *env, jclass clazz, jlong display, jlong ptr)
{
return XFreeEventData((Display *)jlong_to_ptr(display), (XGenericEventCookie *)ptr_to_jlong(ptr));
}
/* /*
* Class: XlibWrapper * Class: XlibWrapper
* Method: SetBitmapShape * Method: SetBitmapShape