Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: remoting/client/x11_input_handler.cc

Issue 3341005: Add mouse/keyboard event support to Chromoting client (Pepper and X11). (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: review comments Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/client/x11_input_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/x11_view.h" 9 #include "remoting/client/x11_view.h"
10 #include "remoting/jingle_glue/jingle_thread.h" 10 #include "remoting/jingle_glue/jingle_thread.h"
11 11
12 // Include Xlib at the end because it clashes with Status in 12 // Include Xlib at the end because it clashes with Status in
13 // base/tracked_objects.h. 13 // base/tracked_objects.h.
14 #include <X11/Xlib.h> 14 #include <X11/Xlib.h>
15 #include <X11/Xutil.h>
15 16
16 namespace remoting { 17 namespace remoting {
17 18
18 X11InputHandler::X11InputHandler(ClientContext* context, 19 X11InputHandler::X11InputHandler(ClientContext* context,
19 HostConnection* connection, 20 HostConnection* connection,
20 ChromotingView* view) 21 ChromotingView* view)
21 : InputHandler(context, connection, view) { 22 : InputHandler(context, connection, view) {
22 } 23 }
23 24
24 X11InputHandler::~X11InputHandler() { 25 X11InputHandler::~X11InputHandler() {
(...skipping 10 matching lines...) Expand all
35 if (XPending(display)) { 36 if (XPending(display)) {
36 XEvent e; 37 XEvent e;
37 XNextEvent(display, &e); 38 XNextEvent(display, &e);
38 switch (e.type) { 39 switch (e.type) {
39 case Expose: 40 case Expose:
40 // Tell the view to paint again. 41 // Tell the view to paint again.
41 view_->Paint(); 42 view_->Paint();
42 break; 43 break;
43 case KeyPress: 44 case KeyPress:
44 case KeyRelease: 45 case KeyRelease:
45 // TODO(garykac) Implement. 46 HandleKeyEvent(&e);
46 break; 47 break;
47 case ButtonPress: 48 case ButtonPress:
48 HandleMouseButtonEvent(true, e.xbutton.button); 49 HandleMouseButtonEvent(true, e.xbutton.button);
49 HandleMouseMoveEvent(e.xbutton.x, e.xbutton.y); 50 HandleMouseMoveEvent(e.xbutton.x, e.xbutton.y);
50 break; 51 break;
51 case ButtonRelease: 52 case ButtonRelease:
52 HandleMouseButtonEvent(false, e.xbutton.button); 53 HandleMouseButtonEvent(false, e.xbutton.button);
53 HandleMouseMoveEvent(e.xbutton.x, e.xbutton.y); 54 HandleMouseMoveEvent(e.xbutton.x, e.xbutton.y);
54 break; 55 break;
55 case MotionNotify: 56 case MotionNotify:
(...skipping 10 matching lines...) Expand all
66 67
67 void X11InputHandler::ScheduleX11EventHandler() { 68 void X11InputHandler::ScheduleX11EventHandler() {
68 // Schedule a delayed task to process X11 events in 10ms. 69 // Schedule a delayed task to process X11 events in 10ms.
69 static const int kProcessEventsInterval = 10; 70 static const int kProcessEventsInterval = 10;
70 context_->jingle_thread()->message_loop()->PostDelayedTask( 71 context_->jingle_thread()->message_loop()->PostDelayedTask(
71 FROM_HERE, 72 FROM_HERE,
72 NewRunnableMethod(this, &X11InputHandler::DoProcessX11Events), 73 NewRunnableMethod(this, &X11InputHandler::DoProcessX11Events),
73 kProcessEventsInterval); 74 kProcessEventsInterval);
74 } 75 }
75 76
77 void X11InputHandler::HandleKeyEvent(void* event) {
78 XEvent* e = reinterpret_cast<XEvent*>(event);
79 char buffer[128];
80 int buffsize = sizeof(buffer) - 1;
81 KeySym keysym;
82 XLookupString(&e->xkey, buffer, buffsize, &keysym, NULL);
83 SendKeyEvent(e->type == KeyPress, static_cast<int>(keysym));
84 }
85
76 void X11InputHandler::HandleMouseMoveEvent(int x, int y) { 86 void X11InputHandler::HandleMouseMoveEvent(int x, int y) {
77 SendMouseMoveEvent(x, y); 87 SendMouseMoveEvent(x, y);
78 } 88 }
79 89
80 void X11InputHandler::HandleMouseButtonEvent(bool button_down, int xbutton_id) { 90 void X11InputHandler::HandleMouseButtonEvent(bool button_down, int xbutton_id) {
81 MouseButton button = MouseButtonUndefined; 91 MouseButton button = MouseButtonUndefined;
82 if (xbutton_id == 1) { 92 if (xbutton_id == 1) {
83 button = MouseButtonLeft; 93 button = MouseButtonLeft;
84 } else if (xbutton_id == 2) { 94 } else if (xbutton_id == 2) {
85 button = MouseButtonMiddle; 95 button = MouseButtonMiddle;
86 } else if (xbutton_id == 3) { 96 } else if (xbutton_id == 3) {
87 button = MouseButtonRight; 97 button = MouseButtonRight;
88 } 98 }
89 99
90 if (button != MouseButtonUndefined) { 100 if (button != MouseButtonUndefined) {
91 SendMouseButtonEvent(button_down, button); 101 SendMouseButtonEvent(button_down, button);
92 } 102 }
93 } 103 }
94 104
95 } // namespace remoting 105 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/x11_input_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698