Skip to content

Commit

Permalink
- added support for raw button masks on Mac OS X
Browse files Browse the repository at this point in the history
- fixed false positive on mouse button states when Mac OS X never sends a mouse up event
  • Loading branch information
marcello3d committed Dec 31, 2009
1 parent 8eaabc2 commit b5adca1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 18 deletions.
9 changes: 6 additions & 3 deletions docs/todo.html
Expand Up @@ -8,20 +8,22 @@ <h2>To-do list</h2>

<h3>Bugs</h3>
<ul>
<li>TabletEvent.isPopupTrigger() won't return the correct value</li>
<li>Releasing mouse button outside of component doesn't send cursor released event</li>
<li><strike></strike>Overlapping windows (or multiple applets) can receive simultaneous events</strike></li>
<li><strike>Overlapping windows (or multiple applets) can receive simultaneous events</strike></li>
<li>Listeners are not freed when a component is disposed/lost</li>
<li><b>Max OS X</b>
<ul>
<li>Clicking "maximize" button creates a mouse down event but no mouse up event... button state gets screwed up</li>
<li><strike>Clicking "maximize" button creates a mouse down event but no mouse up event... button state gets screwed up</strike>
<ul><li>Workaround: reset button state when a mouse moved event is received</li></ul></li>
<li><strike>Scroll gesture isn't smooth</strike></li>
</ul>
</li>
<li><b>Windows</b>
<ul>
<li>Keyboard modifiers are not handled correctly</li>
<li>Mouse buttons won't match the buttons if configured differently in the control panel</li>
<li>Relatively positioned tablet inputs (e.g. mouse) report the wrong coordinates (maybe fallback on mouse
position?)</li>
</ul>
</li>
</ul>
Expand All @@ -32,6 +34,7 @@ <h3>Desired/incomplete features</h3>
<li>Standard mechanism for accessing "raw" tablet buttons independent of system settings</li>
<li>Ability to see extra tablet information (tablet name, vendor, etc)</li>
<li>Extension/installer/versioning support</li>
<li>TabletEvent.isPopupTrigger() won't return the correct value</li>
</ul>

<h3>Misc</h3>
Expand Down
21 changes: 19 additions & 2 deletions src/cello/jtablet/event/TabletEvent.java
Expand Up @@ -103,7 +103,7 @@ public TabletEvent(Component source, Type type, long when, int modifiers,
this.scrollX = deltaX;
this.scrollY = deltaY;
this.zoomFactor = zoom;
this.rawTabletButtonMask = 0;
this.rawTabletButtonMask = rawTabletButtonMask;
}
/**
* Wrap a {@link MouseEvent} as a TabletEvent.
Expand Down Expand Up @@ -137,6 +137,7 @@ public TabletEvent(MouseEvent e, Type type, TabletDevice device) {
* @param type
* @param when
* @param modifiers
* @param rawTabletButtonMask
* @param device
* @param x
* @param y
Expand All @@ -163,6 +164,7 @@ public TabletEvent(Component source, Type type, long when, int modifiers, int ra
* @param type
* @param when
* @param modifiers
* @param rawTabletButtonMask
* @param device
* @param x
* @param y
Expand Down Expand Up @@ -242,7 +244,18 @@ public String toString() {
sb.append(",zoom=").append(zoomFactor);
}
if (rawTabletButtonMask != 0) {
sb.append(",rawTabletButtonMask=").append(Integer.toString(rawTabletButtonMask, 2));
sb.append(",rawTabletButtons=");
boolean first = true;
for (int i=0; i<31; i++) {
if ((rawTabletButtonMask&(1<<i)) != 0) {
if (first) {
first = false;
} else {
sb.append(',');
}
sb.append(Integer.toString(i+1));
}
}
}
sb.append("] on ").append(source);

Expand Down Expand Up @@ -521,4 +534,8 @@ public float getZoomFactor() {
public int getRawTabletButtonMask() {
return rawTabletButtonMask;
}
@Override
public boolean isPopupTrigger() {
throw new UnsupportedOperationException("isPopupTrigger() is not supported by JTablet");
}
}
4 changes: 3 additions & 1 deletion src/cello/jtablet/impl/ScreenTabletManager.java
Expand Up @@ -382,7 +382,8 @@ protected void generateDeviceEvents(TabletDevice device, long when, int keyModif
}
protected void generatePointEvents(long when, int keyModifiers,
float x, float y, float pressure, float tiltX, float tiltY,
float sidePressure, float rotation, int rawTabletButtonMask,
float sidePressure, float rotation,
int rawTabletButtonMask,
int button, boolean buttonJustPressed, boolean buttonJustReleased) {

int buttonMask = lastButtonMask;
Expand Down Expand Up @@ -427,6 +428,7 @@ protected void generatePointEvents(long when, int keyModifiers,

boolean pressed = pressure > PRESSED_THRESHOLD;


if (buttonJustReleased || buttonJustPressed) {
fireScreenTabletEvent(new TabletEvent(
SCREEN_COMPONENT,
Expand Down
87 changes: 75 additions & 12 deletions src/cello/jtablet/impl/jpen/platform/NativeCocoaInterface.java
Expand Up @@ -67,12 +67,13 @@ protected void postScrollEvent(
double eventTimeSeconds,
int cocoaModifierFlags,
float screenX, float screenY,
boolean isDeviceDelta,
float deviceDeltaX, float deviceDeltaY
) {
long when = System.currentTimeMillis();
int keyModifiers = getMouseEventModifiers(cocoaModifierFlags);
generateScrollEvent(when, keyModifiers, screenX, screenY,
deviceDeltaX*DEVICE_DELTA_FACTOR, deviceDeltaY*DEVICE_DELTA_FACTOR);
float factor = isDeviceDelta ? DEVICE_DELTA_FACTOR : 1;
generateScrollEvent(when, keyModifiers, screenX, screenY, deviceDeltaX*factor, deviceDeltaY*factor);
}
@Override
protected void postMagnifyEvent(
Expand Down Expand Up @@ -181,6 +182,7 @@ protected TabletDevice makeDevice(final long uniqueId, int capabilityMask, int p
return new CocoaDevice(type,Long.toHexString(uniqueId),supportsButtons,supportsDeviceId,supportsPressure,supportsRotation,supportsSidePressure, supportsTiltXY);
}

private boolean leftButton, rightButton, otherButton;

@Override
protected void postEvent(int type,
Expand All @@ -197,45 +199,106 @@ protected void postEvent(int type,

boolean buttonJustPressed = false, buttonJustReleased = false;
int button = MouseEvent.NOBUTTON;

long when = System.currentTimeMillis();
int keyModifiers = getMouseEventModifiers(cocoaModifierFlags);

// tilt is in range of -1 ~ 1, where 1 is 64 degrees
tiltX *= TILT_TO_RADIANS;
// Avoid negative zero...
if (tiltY != 0) {
tiltY = -tiltY * TILT_TO_RADIANS;
}

switch (type) {
case NS_EVENT_TYPE_LeftMouseDown:
buttonJustPressed = true;
button = MouseEvent.BUTTON1;
leftButton = true;
break;
case NS_EVENT_TYPE_LeftMouseUp:
buttonJustReleased = true;
button = MouseEvent.BUTTON1;
leftButton = false;
break;
case NS_EVENT_TYPE_RightMouseDown:
buttonJustPressed = true;
button = MouseEvent.BUTTON3;
rightButton = true;
break;
case NS_EVENT_TYPE_RightMouseUp:
buttonJustReleased = true;
button = MouseEvent.BUTTON3;
rightButton = false;
break;
case NS_EVENT_TYPE_OtherMouseDown:
buttonJustPressed = true;
button = MouseEvent.BUTTON2;
otherButton = true;
break;
case NS_EVENT_TYPE_OtherMouseUp:
buttonJustReleased = true;
button = MouseEvent.BUTTON2;
otherButton = false;
break;
case NS_EVENT_TYPE_MouseMoved:
// For some reason when you click maximize on a window, you get a MouseDown event, but no MouseUp...
// To work around that issue, if I ever get a mousemoved event when I think a button is pressed, we
// can simply generate a fake button up event.
if (leftButton) {
generatePointEvents(
when,
keyModifiers,
x, y,
pressure,
tiltX, tiltY,
tangentialPressure,
rotation,
rawTabletButtonMask,
MouseEvent.BUTTON1,
false,
true
);
leftButton = false;
}
if (rightButton) {
generatePointEvents(
when,
keyModifiers,
x, y,
pressure,
tiltX, tiltY,
tangentialPressure,
rotation,
rawTabletButtonMask,
MouseEvent.BUTTON1,
false,
true
);
rightButton = false;
}
if (otherButton) {
generatePointEvents(
when,
keyModifiers,
x, y,
pressure,
tiltX, tiltY,
tangentialPressure,
rotation,
rawTabletButtonMask,
MouseEvent.BUTTON1,
false,
true
);
otherButton = false;
}
break;
}

long when = System.currentTimeMillis();
int modifiers = getMouseEventModifiers(cocoaModifierFlags);

// tilt is in range of -1 ~ 1, where 1 is 64 degrees
tiltX *= TILT_TO_RADIANS;
// Avoid negative zero...
if (tiltY != 0) {
tiltY = -tiltY * TILT_TO_RADIANS;
}
generatePointEvents(
when,
modifiers,
keyModifiers,
x, y,
pressure,
tiltX, tiltY,
Expand Down

0 comments on commit b5adca1

Please sign in to comment.