Permalink
Browse files

Ensure the mouse is within bounds when queuing events

Fixes #123
  • Loading branch information...
SquidDev committed Feb 5, 2019
1 parent 169bae7 commit bb2d8da0ef9d472cf0bacf4c62cf2e64815f0c41
Showing with 7 additions and 3 deletions.
  1. +7 −3 plugin-api/src/main/java/net/clgd/ccemux/api/emulation/EmulatedComputer.java
@@ -135,20 +135,24 @@ public void terminate() {
* Queues a mouse click event
*/
public void click(int button, int x, int y, boolean release) {
queueEvent(release ? "mouse_up" : "mouse_click", new Object[] { button, x, y });
if (inTerminal(x, y)) queueEvent(release ? "mouse_up" : "mouse_click", new Object[] { button, x, y });
}

/**
* Queues a mouse drag event
*/
public void drag(int button, int x, int y) {
queueEvent("mouse_drag", new Object[] { button, x, y });
if (inTerminal(x, y)) queueEvent("mouse_drag", new Object[] { button, x, y });
}

/**
* Queues a mouse scroll event
*/
public void scroll(int lines, int x, int y) {
queueEvent("mouse_scroll", new Object[] { lines, x, y });
if (inTerminal(x, y)) queueEvent("mouse_scroll", new Object[] { lines, x, y });
}

private boolean inTerminal(int x, int y) {
return x >= 1 && x <= terminal.getWidth() && y >= 1 && y <= terminal.getHeight();
}
}

0 comments on commit bb2d8da

Please sign in to comment.