OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/client/x11_input_handler.h" | 5 #include "remoting/client/x11_input_handler.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "remoting/client/client_context.h" | 8 #include "remoting/client/client_context.h" |
9 #include "remoting/client/host_connection.h" | |
10 #include "remoting/client/x11_view.h" | 9 #include "remoting/client/x11_view.h" |
11 #include "remoting/jingle_glue/jingle_thread.h" | 10 #include "remoting/jingle_glue/jingle_thread.h" |
12 | 11 |
13 // Include Xlib at the end because it clashes with Status in | 12 // Include Xlib at the end because it clashes with Status in |
14 // base/tracked_objects.h. | 13 // base/tracked_objects.h. |
15 #include <X11/Xlib.h> | 14 #include <X11/Xlib.h> |
16 | 15 |
17 namespace remoting { | 16 namespace remoting { |
18 | 17 |
19 X11InputHandler::X11InputHandler(ClientContext* context, | 18 X11InputHandler::X11InputHandler(ClientContext* context, |
20 HostConnection* connection, | 19 HostConnection* connection, |
21 ChromotingView* view) | 20 ChromotingView* view) |
22 : InputHandler(context, connection, view) { | 21 : InputHandler(context, connection, view) { |
23 } | 22 } |
24 | 23 |
25 X11InputHandler::~X11InputHandler() { | 24 X11InputHandler::~X11InputHandler() { |
26 } | 25 } |
27 | 26 |
28 void X11InputHandler::Initialize() { | 27 void X11InputHandler::Initialize() { |
29 ScheduleX11EventHandler(); | 28 ScheduleX11EventHandler(); |
30 } | 29 } |
31 | 30 |
32 void X11InputHandler::DoProcessX11Events() { | 31 void X11InputHandler::DoProcessX11Events() { |
33 DCHECK_EQ(context_->jingle_thread()->message_loop(), MessageLoop::current()); | 32 DCHECK_EQ(context_->jingle_thread()->message_loop(), MessageLoop::current()); |
| 33 |
34 Display* display = static_cast<X11View*>(view_)->display(); | 34 Display* display = static_cast<X11View*>(view_)->display(); |
35 if (XPending(display)) { | 35 if (XPending(display)) { |
36 XEvent e; | 36 XEvent e; |
37 XNextEvent(display, &e); | 37 XNextEvent(display, &e); |
38 if (e.type == Expose) { | 38 switch (e.type) { |
39 // Tell the view to paint again. | 39 case Expose: |
40 view_->Paint(); | 40 // Tell the view to paint again. |
41 } else if (e.type == ButtonPress) { | 41 view_->Paint(); |
42 // TODO(hclam): Implement. | 42 break; |
43 NOTIMPLEMENTED(); | 43 case KeyPress: |
44 } else { | 44 case KeyRelease: |
45 // TODO(hclam): Implement. | 45 // TODO(garykac) Implement. |
46 NOTIMPLEMENTED(); | 46 break; |
| 47 case ButtonPress: |
| 48 HandleMouseButtonEvent(true, e.xbutton.button); |
| 49 HandleMouseMoveEvent(e.xbutton.x, e.xbutton.y); |
| 50 break; |
| 51 case ButtonRelease: |
| 52 HandleMouseButtonEvent(false, e.xbutton.button); |
| 53 HandleMouseMoveEvent(e.xbutton.x, e.xbutton.y); |
| 54 break; |
| 55 case MotionNotify: |
| 56 SendMouseMoveEvent(e.xmotion.x, e.xmotion.y); |
| 57 break; |
| 58 default: |
| 59 LOG(WARNING) << "Unknown event type: " << e.type; |
47 } | 60 } |
48 } | 61 } |
49 | 62 |
50 // Schedule the next event handler. | 63 // Schedule the next event handler. |
51 ScheduleX11EventHandler(); | 64 ScheduleX11EventHandler(); |
52 } | 65 } |
53 | 66 |
54 void X11InputHandler::ScheduleX11EventHandler() { | 67 void X11InputHandler::ScheduleX11EventHandler() { |
55 // Schedule a delayed task to process X11 events in 10ms. | 68 // Schedule a delayed task to process X11 events in 10ms. |
56 static const int kProcessEventsInterval = 10; | 69 static const int kProcessEventsInterval = 10; |
57 context_->jingle_thread()->message_loop()->PostDelayedTask( | 70 context_->jingle_thread()->message_loop()->PostDelayedTask( |
58 FROM_HERE, | 71 FROM_HERE, |
59 NewRunnableMethod(this, &X11InputHandler::DoProcessX11Events), | 72 NewRunnableMethod(this, &X11InputHandler::DoProcessX11Events), |
60 kProcessEventsInterval); | 73 kProcessEventsInterval); |
61 } | 74 } |
62 | 75 |
| 76 void X11InputHandler::HandleMouseMoveEvent(int x, int y) { |
| 77 SendMouseMoveEvent(x, y); |
| 78 } |
| 79 |
| 80 void X11InputHandler::HandleMouseButtonEvent(bool button_down, int xbutton_id) { |
| 81 MouseButton button = MouseButtonUndefined; |
| 82 if (xbutton_id == 1) { |
| 83 button = MouseButtonLeft; |
| 84 } else if (xbutton_id == 2) { |
| 85 button = MouseButtonMiddle; |
| 86 } else if (xbutton_id == 3) { |
| 87 button = MouseButtonRight; |
| 88 } |
| 89 |
| 90 if (button != MouseButtonUndefined) { |
| 91 SendMouseButtonEvent(button_down, button); |
| 92 } |
| 93 } |
| 94 |
63 } // namespace remoting | 95 } // namespace remoting |
OLD | NEW |