From 58117c17cd28f48106756ed037601143197f3dbf Mon Sep 17 00:00:00 2001 From: Aaron Neyer Date: Wed, 11 Dec 2013 20:29:21 -0500 Subject: [PATCH] add in Ctrl-alt-shift-Q to quit, and do better edge detection --- .../src/com/limelight/gui/StreamFrame.java | 11 +++++++- .../com/limelight/input/KeyboardHandler.java | 14 +++++++++- .../src/com/limelight/input/MouseHandler.java | 28 ++++++++++++------- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/limelight-pc/src/com/limelight/gui/StreamFrame.java b/limelight-pc/src/com/limelight/gui/StreamFrame.java index ce555fd..a217ed3 100644 --- a/limelight-pc/src/com/limelight/gui/StreamFrame.java +++ b/limelight-pc/src/com/limelight/gui/StreamFrame.java @@ -31,9 +31,13 @@ public class StreamFrame extends JFrame { private MouseHandler mouse; private JProgressBar spinner; private JLabel spinnerLabel; + + private NvConnection conn; public void build(NvConnection conn, boolean fullscreen) { - keyboard = new KeyboardHandler(conn); + this.conn = conn; + + keyboard = new KeyboardHandler(conn, this); mouse = new MouseHandler(conn, this); this.addKeyListener(keyboard); @@ -123,4 +127,9 @@ public class StreamFrame extends JFrame { spinnerLabel.setVisible(false); } + public void close() { + dispose(); + conn.stop(); + } + } diff --git a/limelight-pc/src/com/limelight/input/KeyboardHandler.java b/limelight-pc/src/com/limelight/input/KeyboardHandler.java index 9c84dc6..97da017 100644 --- a/limelight-pc/src/com/limelight/input/KeyboardHandler.java +++ b/limelight-pc/src/com/limelight/input/KeyboardHandler.java @@ -3,15 +3,18 @@ package com.limelight.input; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import com.limelight.gui.StreamFrame; import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.input.KeyboardPacket; public class KeyboardHandler implements KeyListener { private static KeyboardTranslator translator; + private StreamFrame parent; - public KeyboardHandler(NvConnection conn) { + public KeyboardHandler(NvConnection conn, StreamFrame parent) { translator = new KeyboardTranslator(conn); + this.parent = parent; } @Override @@ -30,6 +33,15 @@ public class KeyboardHandler implements KeyListener { if ((modifiers & KeyEvent.ALT_DOWN_MASK) != 0) { modifier |= KeyboardPacket.MODIFIER_ALT; } + + if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0 && + (modifiers & KeyEvent.ALT_DOWN_MASK) != 0 && + (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0 && + event.getKeyCode() == KeyEvent.VK_Q) { + System.out.println("quitting"); + parent.close(); + System.exit(0); + } translator.sendKeyDown(keyMap, modifier); } diff --git a/limelight-pc/src/com/limelight/input/MouseHandler.java b/limelight-pc/src/com/limelight/input/MouseHandler.java index 2c9702e..43584b4 100644 --- a/limelight-pc/src/com/limelight/input/MouseHandler.java +++ b/limelight-pc/src/com/limelight/input/MouseHandler.java @@ -21,7 +21,6 @@ public class MouseHandler implements MouseListener, MouseMotionListener { private int lastX = 0; private int lastY = 0; - public MouseHandler(NvConnection conn, JFrame parent) { this.conn = conn; this.parent = parent; @@ -44,9 +43,9 @@ public class MouseHandler implements MouseListener, MouseMotionListener { @Override public void mouseExited(MouseEvent e) { - robot.mouseMove(size.width / 2, size.height / 2); - lastX = size.width / 2; - lastY = size.height / 2; + parent.getSize(size); + moveMouse((int)parent.getLocation().getX() + (size.width/2), + (int)parent.getLocation().getY() + (size.height/2)); } @Override @@ -106,15 +105,24 @@ public class MouseHandler implements MouseListener, MouseMotionListener { parent.getSize(size); - if (x < size.width / 2 - 500 || x > size.width / 2 + 500) { - robot.mouseMove(size.width / 2, y); - lastX = size.width / 2; + int leftEdge = (int) parent.getLocation().getX(); + int rightEdge = leftEdge + size.width; + int upperEdge = (int) parent.getLocation().getY(); + int lowerEdge = upperEdge + size.height; + + if (x < leftEdge + 100 || x > rightEdge - 100) { + moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2); } - if (y < size.height / 2 - 300 || y > size.height / 2 + 300) { - robot.mouseMove(x, size.height / 2); - lastY = size.height / 2; + if (y < upperEdge + 100 || y > lowerEdge - 100) { + moveMouse((leftEdge+rightEdge)/2, (upperEdge+lowerEdge)/2); } } + private void moveMouse(int x, int y) { + robot.mouseMove(x, y); + lastX = x; + lastY = y; + } + }