OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/local_input_monitor.h" | 5 #include "remoting/host/local_input_monitor.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 @end | 79 @end |
80 | 80 |
81 static CGEventRef LocalMouseMoved(CGEventTapProxy proxy, CGEventType type, | 81 static CGEventRef LocalMouseMoved(CGEventTapProxy proxy, CGEventType type, |
82 CGEventRef event, void* context) { | 82 CGEventRef event, void* context) { |
83 int64_t pid = CGEventGetIntegerValueField(event, kCGEventSourceUnixProcessID); | 83 int64_t pid = CGEventGetIntegerValueField(event, kCGEventSourceUnixProcessID); |
84 if (pid == 0) { | 84 if (pid == 0) { |
85 CGPoint cgMousePos = CGEventGetLocation(event); | 85 CGPoint cgMousePos = CGEventGetLocation(event); |
86 webrtc::DesktopVector mousePos(cgMousePos.x, cgMousePos.y); | 86 webrtc::DesktopVector mousePos(cgMousePos.x, cgMousePos.y); |
87 [static_cast<LocalInputMonitorManager*>(context) localMouseMoved:mousePos]; | 87 [static_cast<LocalInputMonitorManager*>(context) localMouseMoved:mousePos]; |
88 } | 88 } |
89 return NULL; | 89 return nullptr; |
90 } | 90 } |
91 | 91 |
92 @implementation LocalInputMonitorManager | 92 @implementation LocalInputMonitorManager |
93 | 93 |
94 - (id)initWithMonitor:(remoting::LocalInputMonitorMac::EventHandler*)monitor { | 94 - (id)initWithMonitor:(remoting::LocalInputMonitorMac::EventHandler*)monitor { |
95 if ((self = [super init])) { | 95 if ((self = [super init])) { |
96 monitor_ = monitor; | 96 monitor_ = monitor; |
97 | 97 |
98 GTMCarbonEventDispatcherHandler* handler = | 98 GTMCarbonEventDispatcherHandler* handler = |
99 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; | 99 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; |
100 hotKey_ = [handler registerHotKey:kEscKeyCode | 100 hotKey_ = [handler registerHotKey:kEscKeyCode |
101 modifiers:(NSAlternateKeyMask | NSControlKeyMask) | 101 modifiers:(NSAlternateKeyMask | NSControlKeyMask) |
102 target:self | 102 target:self |
103 action:@selector(hotKeyHit:) | 103 action:@selector(hotKeyHit:) |
104 userInfo:nil | 104 userInfo:nil |
105 whenPressed:YES]; | 105 whenPressed:YES]; |
106 if (!hotKey_) { | 106 if (!hotKey_) { |
107 LOG(ERROR) << "registerHotKey failed."; | 107 LOG(ERROR) << "registerHotKey failed."; |
108 } | 108 } |
109 mouseMachPort_.reset(CGEventTapCreate( | 109 mouseMachPort_.reset(CGEventTapCreate( |
110 kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, | 110 kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, |
111 1 << kCGEventMouseMoved, LocalMouseMoved, self)); | 111 1 << kCGEventMouseMoved, LocalMouseMoved, self)); |
112 if (mouseMachPort_) { | 112 if (mouseMachPort_) { |
113 mouseRunLoopSource_ = CFMachPortCreateRunLoopSource( | 113 mouseRunLoopSource_ = CFMachPortCreateRunLoopSource( |
114 NULL, mouseMachPort_, 0); | 114 nullptr, mouseMachPort_, 0); |
115 CFRunLoopAddSource( | 115 CFRunLoopAddSource( |
116 CFRunLoopGetMain(), mouseRunLoopSource_, kCFRunLoopCommonModes); | 116 CFRunLoopGetMain(), mouseRunLoopSource_, kCFRunLoopCommonModes); |
117 } else { | 117 } else { |
118 LOG(ERROR) << "CGEventTapCreate failed."; | 118 LOG(ERROR) << "CGEventTapCreate failed."; |
119 } | 119 } |
120 if (!hotKey_ && !mouseMachPort_) { | 120 if (!hotKey_ && !mouseMachPort_) { |
121 [self release]; | 121 [self release]; |
122 return nil; | 122 return nil; |
123 } | 123 } |
124 } | 124 } |
125 return self; | 125 return self; |
126 } | 126 } |
127 | 127 |
128 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey { | 128 - (void)hotKeyHit:(GTMCarbonHotKey*)hotKey { |
129 monitor_->OnDisconnectShortcut(); | 129 monitor_->OnDisconnectShortcut(); |
130 } | 130 } |
131 | 131 |
132 - (void)localMouseMoved:(const webrtc::DesktopVector&)mousePos { | 132 - (void)localMouseMoved:(const webrtc::DesktopVector&)mousePos { |
133 monitor_->OnLocalMouseMoved(mousePos); | 133 monitor_->OnLocalMouseMoved(mousePos); |
134 } | 134 } |
135 | 135 |
136 - (void)invalidate { | 136 - (void)invalidate { |
137 if (hotKey_) { | 137 if (hotKey_) { |
138 GTMCarbonEventDispatcherHandler* handler = | 138 GTMCarbonEventDispatcherHandler* handler = |
139 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; | 139 [GTMCarbonEventDispatcherHandler sharedEventDispatcherHandler]; |
140 [handler unregisterHotKey:hotKey_]; | 140 [handler unregisterHotKey:hotKey_]; |
141 hotKey_ = NULL; | 141 hotKey_ = nullptr; |
142 } | 142 } |
143 if (mouseRunLoopSource_) { | 143 if (mouseRunLoopSource_) { |
144 CFMachPortInvalidate(mouseMachPort_); | 144 CFMachPortInvalidate(mouseMachPort_); |
145 CFRunLoopRemoveSource( | 145 CFRunLoopRemoveSource( |
146 CFRunLoopGetMain(), mouseRunLoopSource_, kCFRunLoopCommonModes); | 146 CFRunLoopGetMain(), mouseRunLoopSource_, kCFRunLoopCommonModes); |
147 CFRelease(mouseRunLoopSource_); | 147 CFRelease(mouseRunLoopSource_); |
148 mouseMachPort_.reset(0); | 148 mouseMachPort_.reset(0); |
149 mouseRunLoopSource_ = NULL; | 149 mouseRunLoopSource_ = nullptr; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 @end | 153 @end |
154 | 154 |
155 namespace remoting { | 155 namespace remoting { |
156 namespace { | 156 namespace { |
157 | 157 |
158 class LocalInputMonitorMac::Core | 158 class LocalInputMonitorMac::Core |
159 : public base::RefCountedThreadSafe<Core>, | 159 : public base::RefCountedThreadSafe<Core>, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create( | 278 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create( |
279 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 279 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
280 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 280 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
281 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 281 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
282 base::WeakPtr<ClientSessionControl> client_session_control) { | 282 base::WeakPtr<ClientSessionControl> client_session_control) { |
283 return make_scoped_ptr(new LocalInputMonitorMac( | 283 return make_scoped_ptr(new LocalInputMonitorMac( |
284 caller_task_runner, ui_task_runner, client_session_control)); | 284 caller_task_runner, ui_task_runner, client_session_control)); |
285 } | 285 } |
286 | 286 |
287 } // namespace remoting | 287 } // namespace remoting |
OLD | NEW |