summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 15:31:40 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-02 15:31:40 +0000
commiteccefee0229e222c0130dca22412b4dccfa3f181 (patch)
tree959ca4d2d1c15bd29b821a6af45ed1c433779fb1 /remoting
parent91ef7b0311e0bea576d5b935b2cd378e04c517ca (diff)
downloadchromium_src-eccefee0229e222c0130dca22412b4dccfa3f181.zip
chromium_src-eccefee0229e222c0130dca22412b4dccfa3f181.tar.gz
chromium_src-eccefee0229e222c0130dca22412b4dccfa3f181.tar.bz2
Add support for hotkey to quit chromoting.
BUG=NONE TEST=Start up chromoting session, try hitting "shift-esc" on host to quit the session. Review URL: http://codereview.chromium.org/7466041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95084 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/DEPS2
-rw-r--r--remoting/host/local_input_monitor_mac.cc34
-rw-r--r--remoting/host/local_input_monitor_mac.mm101
-rw-r--r--remoting/remoting.gyp16
4 files changed, 118 insertions, 35 deletions
diff --git a/remoting/DEPS b/remoting/DEPS
index 05db1ed..324f7a5 100644
--- a/remoting/DEPS
+++ b/remoting/DEPS
@@ -5,4 +5,6 @@ include_rules = [
"-remoting",
"+remoting/base",
"+remoting/proto",
+ "+third_party/GTM",
+ "+third_party/GTM/AppKit",
]
diff --git a/remoting/host/local_input_monitor_mac.cc b/remoting/host/local_input_monitor_mac.cc
deleted file mode 100644
index 5ee3c01..0000000
--- a/remoting/host/local_input_monitor_mac.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/host/local_input_monitor.h"
-
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-
-namespace {
-
-class LocalInputMonitorMac : public remoting::LocalInputMonitor {
- public:
- LocalInputMonitorMac() {}
- virtual void Start(remoting::ChromotingHost* host) OVERRIDE;
- virtual void Stop() OVERRIDE;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(LocalInputMonitorMac);
-};
-
-} // namespace
-
-void LocalInputMonitorMac::Start(remoting::ChromotingHost* host) {
- NOTIMPLEMENTED();
-}
-
-void LocalInputMonitorMac::Stop() {
- NOTIMPLEMENTED();
-}
-
-remoting::LocalInputMonitor* remoting::LocalInputMonitor::Create() {
- return new LocalInputMonitorMac;
-}
diff --git a/remoting/host/local_input_monitor_mac.mm b/remoting/host/local_input_monitor_mac.mm
new file mode 100644
index 0000000..c3955c6
--- /dev/null
+++ b/remoting/host/local_input_monitor_mac.mm
@@ -0,0 +1,101 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/local_input_monitor.h"
+
+#import <AppKit/AppKit.h>
+
+#include "base/compiler_specific.h"
+#include "base/logging.h"
+#include "remoting/host/chromoting_host.h"
+#import "third_party/GTM/AppKit/GTMCarbonEvent.h"
+
+// Esc Key Code is 53.
+// http://boredzo.org/blog/wp-content/uploads/2007/05/IMTx-virtual-keycodes.pdf
+static const NSUInteger kEscKeyCode = 53;
+
+@interface HotKeyMonitor : NSObject {
+ @private
+ GTMCarbonHotKey* hot_key_;
+ remoting::ChromotingHost* host_;
+}
+
+// Called when the hotKey is hit.
+- (void)hotKeyHit:(GTMCarbonHotKey*)hotKey;
+
+// Must be called when the HotKeyMonitor is no longer to be used.
+// Similar to NSTimer in that more than a simple release is required.
+- (void)invalidate;
+
+@end
+
+@implementation HotKeyMonitor
+
+- (id)initWithHost:(remoting::ChromotingHost*)host {
+ if ((self = [super init])) {
+ host_ = host;
+ GTMCarbonEventDispatcherHandler* handler =
+ [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler];
+ hot_key_ = [handler registerHotKey:kEscKeyCode
+ modifiers:NSShiftKeyMask
+ target:self
+ action:@selector(hotKeyHit:)
+ userInfo:nil
+ whenPressed:YES];
+ if (!hot_key_) {
+ [self release];
+ return nil;
+ }
+ }
+ return self;
+}
+
+- (void)hotKeyHit:(GTMCarbonHotKey*)hotKey {
+ host_->Shutdown(NULL);
+}
+
+- (void)invalidate {
+ GTMCarbonEventDispatcherHandler* handler =
+ [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler];
+ [handler unregisterHotKey:hot_key_];
+}
+
+@end
+
+namespace {
+
+class LocalInputMonitorMac : public remoting::LocalInputMonitor {
+ public:
+ LocalInputMonitorMac() : hot_key_monitor_(NULL) {}
+ virtual ~LocalInputMonitorMac();
+ virtual void Start(remoting::ChromotingHost* host) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+
+ private:
+ HotKeyMonitor* hot_key_monitor_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalInputMonitorMac);
+};
+
+} // namespace
+
+LocalInputMonitorMac::~LocalInputMonitorMac() {
+ Stop();
+}
+
+void LocalInputMonitorMac::Start(remoting::ChromotingHost* host) {
+ CHECK(!hot_key_monitor_);
+ hot_key_monitor_ = [[HotKeyMonitor alloc] initWithHost:host];
+ CHECK(hot_key_monitor_);
+}
+
+void LocalInputMonitorMac::Stop() {
+ [hot_key_monitor_ invalidate];
+ [hot_key_monitor_ release];
+ hot_key_monitor_ = nil;
+}
+
+remoting::LocalInputMonitor* remoting::LocalInputMonitor::Create() {
+ return new LocalInputMonitorMac;
+}
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 80799a8..88d526e 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -403,7 +403,7 @@
'host/json_host_config.cc',
'host/json_host_config.h',
'host/local_input_monitor_linux.cc',
- 'host/local_input_monitor_mac.cc',
+ 'host/local_input_monitor_mac.mm',
'host/local_input_monitor_thread_linux.cc',
'host/local_input_monitor_win.cc',
'host/register_support_host_request.cc',
@@ -439,6 +439,20 @@
},
}],
['OS=="mac"', {
+ 'sources': [
+ '../third_party/GTM/AppKit/GTMCarbonEvent.h',
+ '../third_party/GTM/AppKit/GTMCarbonEvent.m',
+ '../third_party/GTM/DebugUtils/GTMDebugSelectorValidation.h',
+ '../third_party/GTM/DebugUtils/GTMTypeCasting.h',
+ '../third_party/GTM/Foundation/GTMObjectSingleton.h',
+ '../third_party/GTM/GTMDefines.h',
+ ],
+ 'include_dirs': [
+ '../third_party/GTM',
+ '../third_party/GTM/AppKit',
+ '../third_party/GTM/DebugUtils',
+ '../third_party/GTM/Foundation',
+ ],
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/OpenGL.framework',