Implement cursor visibility and quit key shortcuts

Fixes #1255
This commit is contained in:
Cameron Gutman
2023-09-23 02:20:26 -04:00
parent 978a879c43
commit 081cca48fb
6 changed files with 140 additions and 79 deletions

View File

@@ -110,6 +110,9 @@ public class EvdevCaptureProvider extends InputCaptureProvider {
break;
}
// Note: The EvdevReader process already filters input events when grabbing
// is not enabled, so we don't need to that here.
switch (event.type) {
case EvdevEvent.EV_SYN:
if (deltaX != 0 || deltaY != 0) {
@@ -231,35 +234,8 @@ public class EvdevCaptureProvider extends InputCaptureProvider {
}
@Override
public void enableCapture() {
super.enableCapture();
if (!started) {
// Start the handler thread if it's our first time
// capturing
handlerThread.start();
started = true;
}
else {
// This may be called on the main thread
runInNetworkSafeContextSynchronously(new Runnable() {
@Override
public void run() {
// Send a request to regrab if we're already capturing
if (!shutdown && evdevOut != null) {
try {
evdevOut.write(REGRAB_REQUEST);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
}
@Override
public void disableCapture() {
super.disableCapture();
public void showCursor() {
super.showCursor();
// This may be called on the main thread
runInNetworkSafeContextSynchronously(new Runnable() {
@Override
@@ -275,6 +251,39 @@ public class EvdevCaptureProvider extends InputCaptureProvider {
});
}
@Override
public void hideCursor() {
super.hideCursor();
// This may be called on the main thread
runInNetworkSafeContextSynchronously(new Runnable() {
@Override
public void run() {
// Send a request to regrab if we're already capturing
if (started && !shutdown && evdevOut != null) {
try {
evdevOut.write(REGRAB_REQUEST);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
@Override
public void enableCapture() {
if (!started) {
// Start the handler thread if it's our first time
// capturing
handlerThread.start();
started = true;
}
// Call the superclass only after we've started the handler thread.
// It will invoke hideCursor() when we call it.
super.enableCapture();
}
@Override
public void destroy() {
// We need to stop the process in this context otherwise