Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8202296: Monocle MouseInput doesn't send keyboard modifiers in events. #170

Closed
wants to merge 5 commits into from
@@ -105,7 +105,9 @@ void setState(MouseState newState, boolean synthesized) {
MonocleView oldView = (MonocleView) oldWindow.getView();
if (oldView != null) {
// send exit event
int modifiers = state.getModifiers(); // TODO: include key modifiers
KeyState keyState = new KeyState();
KeyInput.getInstance().getState(keyState);
int modifiers = state.getModifiers() | keyState.getModifiers();
int button = state.getButton();
boolean isPopupTrigger = false; // TODO
int oldX = state.getX();
@@ -145,7 +147,9 @@ void setState(MouseState newState, boolean synthesized) {
int relY = y - window.getY();
// send enter event
if (oldWindow != window && view != null) {
int modifiers = state.getModifiers(); // TODO: include key modifiers
KeyState keyState = new KeyState();
KeyInput.getInstance().getState(keyState);
int modifiers = state.getModifiers() | keyState.getModifiers();
int button = state.getButton();
boolean isPopupTrigger = false; // TODO
postMouseEvent(view, MouseEvent.ENTER, button,
@@ -156,7 +160,9 @@ void setState(MouseState newState, boolean synthesized) {
if (oldWindow != window | newAbsoluteLocation) {
boolean isDrag = !state.getButtonsPressed().isEmpty();
int eventType = isDrag ? MouseEvent.DRAG : MouseEvent.MOVE;
int modifiers = state.getModifiers(); // TODO: include key modifiers
KeyState keyState = new KeyState();
KeyInput.getInstance().getState(keyState);
int modifiers = state.getModifiers() | keyState.getModifiers();
int button = state.getButton();
boolean isPopupTrigger = false; // TODO
postMouseEvent(view, eventType, button,
@@ -172,11 +178,14 @@ void setState(MouseState newState, boolean synthesized) {
for (int i = 0; i < buttons.size(); i++) {
int button = buttons.get(i);
pressState.pressButton(button);
KeyState keyState = new KeyState();
KeyInput.getInstance().getState(keyState);
int modifiers = pressState.getModifiers() | keyState.getModifiers();
// send press event
boolean isPopupTrigger = false; // TODO
postMouseEvent(view, MouseEvent.DOWN, button,
relX, relY, x, y,
pressState.getModifiers(), isPopupTrigger,
modifiers, isPopupTrigger,
synthesized);
}
}
@@ -190,11 +199,14 @@ void setState(MouseState newState, boolean synthesized) {
for (int i = 0; i < buttons.size(); i++) {
int button = buttons.get(i);
releaseState.releaseButton(button);
KeyState keyState = new KeyState();
KeyInput.getInstance().getState(keyState);
int modifiers = releaseState.getModifiers() | keyState.getModifiers();
// send release event
boolean isPopupTrigger = false; // TODO
postMouseEvent(view, MouseEvent.UP, button,
relX, relY, x, y,
releaseState.getModifiers(), isPopupTrigger,
modifiers, isPopupTrigger,
synthesized);
}
}
@@ -208,7 +220,9 @@ void setState(MouseState newState, boolean synthesized) {
default: dY = 0.0; break;
}
if (dY != 0.0) {
int modifiers = newState.getModifiers();
KeyState keyState = new KeyState();
KeyInput.getInstance().getState(keyState);
int modifiers = newState.getModifiers() | keyState.getModifiers();
RunnableProcessor.runLater(() -> {
view.notifyScroll(relX, relY, x, y, 0.0, dY,
modifiers, 1, 0, 0, 0, 1.0, 1.0);
@@ -30,6 +30,7 @@
import javafx.geometry.Point2D;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.robot.Robot;

import org.junit.Before;
@@ -38,6 +39,13 @@
import org.junit.rules.TestName;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
* This is a generic test for Glass robot. It is in the monocle.input package
@@ -54,6 +62,52 @@ public void setUpScreen() throws Exception {
TestApplication.showFullScreenScene();
}

@Test
public void clickKeyModifierTest() throws Exception {
runWithKeyPress(KeyCode.CONTROL, MouseButton.PRIMARY, "Clicked at 300, 400 with modifier 'CTRL'", evt -> {
assertTrue("Ctrl should be down",evt.isControlDown());
});
runWithKeyPress(KeyCode.SHIFT, MouseButton.PRIMARY, "Clicked at 300, 400 with modifier 'SHIFT'", evt -> {
assertTrue("Shift should be down",evt.isShiftDown());
});
runWithKeyPress(KeyCode.ALT, MouseButton.PRIMARY, "Clicked at 300, 400 with modifier 'ALT'", evt -> {
assertTrue("Alt should be down",evt.isAltDown());
});
}

private void runWithKeyPress(KeyCode code, MouseButton button, String message, Consumer<MouseEvent> test) throws Exception {
TestApplication.getStage().getScene().setOnMouseClicked(
(e) -> {
test.accept(e);
TestLogShim.format("Clicked at %.0f, %.0f with modifier '%s'", e.getScreenX(), e.getScreenY(), modifierString(e));
}
);

Platform.runLater(() -> {
Robot robot = new Robot();
robot.mouseMove(300, 400);
robot.keyPress(code);
robot.mousePress(button);
robot.mouseRelease(button);
robot.keyRelease(code);
});
TestLogShim.waitForLog(message);
}

private static String modifierString(MouseEvent evt) {
List<String> modifiers = new ArrayList<>();
if(evt.isAltDown()) {
modifiers.add("ALT");
}
if(evt.isControlDown()) {
modifiers.add("CTRL");
}
if(evt.isShiftDown()) {
modifiers.add("SHIFT");
}
return modifiers.stream().collect(Collectors.joining(", "));
}

@Test
public void clickTest() throws Exception {
TestApplication.getStage().getScene().setOnMouseClicked(
ProTip! Use n and p to navigate between commits in a pull request.