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

Side by Side Diff: ui/platform_window/x11/x11_window.cc

Issue 399743003: x11: Listen for and process XInput2 events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/platform_window/x11/x11_window.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/platform_window/x11/x11_window.h" 5 #include "ui/platform_window/x11/x11_window.h"
6 6
7 #include <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 #include <X11/Xatom.h> 8 #include <X11/Xatom.h>
9 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
10 #include <X11/Xutil.h> 10 #include <X11/Xutil.h>
11 11
12 #include "ui/events/event.h" 12 #include "ui/events/event.h"
13 #include "ui/events/event_utils.h" 13 #include "ui/events/event_utils.h"
14 #include "ui/events/platform/platform_event_dispatcher.h" 14 #include "ui/events/platform/platform_event_dispatcher.h"
15 #include "ui/events/platform/platform_event_source.h" 15 #include "ui/events/platform/platform_event_source.h"
16 #include "ui/events/platform/x11/x11_event_source.h" 16 #include "ui/events/platform/x11/x11_event_source.h"
17 #include "ui/events/x/touch_factory_x11.h"
17 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/x/x11_atom_cache.h" 19 #include "ui/gfx/x/x11_atom_cache.h"
19 #include "ui/gfx/x/x11_types.h" 20 #include "ui/gfx/x/x11_types.h"
20 #include "ui/platform_window/platform_window_delegate.h" 21 #include "ui/platform_window/platform_window_delegate.h"
21 22
22 namespace ui { 23 namespace ui {
23 24
24 namespace { 25 namespace {
25 26
26 const char* kAtomsToCache[] = { 27 const char* kAtomsToCache[] = {
(...skipping 13 matching lines...) Expand all
40 } // namespace 41 } // namespace
41 42
42 X11Window::X11Window(PlatformWindowDelegate* delegate) 43 X11Window::X11Window(PlatformWindowDelegate* delegate)
43 : delegate_(delegate), 44 : delegate_(delegate),
44 xdisplay_(gfx::GetXDisplay()), 45 xdisplay_(gfx::GetXDisplay()),
45 xwindow_(None), 46 xwindow_(None),
46 xroot_window_(DefaultRootWindow(xdisplay_)), 47 xroot_window_(DefaultRootWindow(xdisplay_)),
47 atom_cache_(xdisplay_, kAtomsToCache), 48 atom_cache_(xdisplay_, kAtomsToCache),
48 window_mapped_(false) { 49 window_mapped_(false) {
49 CHECK(delegate_); 50 CHECK(delegate_);
51 TouchFactory::SetTouchDeviceListFromCommandLine();
50 } 52 }
51 53
52 X11Window::~X11Window() { 54 X11Window::~X11Window() {
53 Destroy(); 55 Destroy();
54 } 56 }
55 57
56 void X11Window::Destroy() { 58 void X11Window::Destroy() {
57 if (xwindow_ == None) 59 if (xwindow_ == None)
58 return; 60 return;
59 61
60 // Stop processing events. 62 // Stop processing events.
61 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); 63 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
62 XDestroyWindow(xdisplay_, xwindow_); 64 XDestroyWindow(xdisplay_, xwindow_);
63 xwindow_ = None; 65 xwindow_ = None;
64 } 66 }
65 67
68 void X11Window::ProcessXInput2Event(XEvent* xev) {
69 if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev))
70 return;
71 EventType event_type = EventTypeFromNative(xev);
72 switch (event_type) {
73 case ET_KEY_PRESSED:
74 case ET_KEY_RELEASED: {
75 KeyEvent key_event(xev, false);
76 delegate_->DispatchEvent(&key_event);
77 break;
78 }
79 case ET_MOUSE_PRESSED:
80 case ET_MOUSE_MOVED:
81 case ET_MOUSE_DRAGGED:
82 case ET_MOUSE_RELEASED: {
83 MouseEvent mouse_event(xev);
84 delegate_->DispatchEvent(&mouse_event);
85 break;
86 }
87 case ET_MOUSEWHEEL: {
88 MouseWheelEvent wheel_event(xev);
89 delegate_->DispatchEvent(&wheel_event);
90 break;
91 }
92 case ET_SCROLL_FLING_START:
93 case ET_SCROLL_FLING_CANCEL:
94 case ET_SCROLL: {
95 ScrollEvent scroll_event(xev);
96 delegate_->DispatchEvent(&scroll_event);
97 break;
98 }
99 case ET_TOUCH_MOVED:
100 case ET_TOUCH_PRESSED:
101 case ET_TOUCH_CANCELLED:
102 case ET_TOUCH_RELEASED: {
103 TouchEvent touch_event(xev);
104 delegate_->DispatchEvent(&touch_event);
105 break;
106 }
107 default:
108 break;
109 }
110 }
111
66 void X11Window::Show() { 112 void X11Window::Show() {
67 if (window_mapped_) 113 if (window_mapped_)
68 return; 114 return;
69 115
70 CHECK(PlatformEventSource::GetInstance()); 116 CHECK(PlatformEventSource::GetInstance());
71 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); 117 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
72 118
73 XSetWindowAttributes swa; 119 XSetWindowAttributes swa;
74 memset(&swa, 0, sizeof(swa)); 120 memset(&swa, 0, sizeof(swa));
75 swa.background_pixmap = None; 121 swa.background_pixmap = None;
(...skipping 17 matching lines...) Expand all
93 StructureNotifyMask | PropertyChangeMask | 139 StructureNotifyMask | PropertyChangeMask |
94 PointerMotionMask; 140 PointerMotionMask;
95 XSelectInput(xdisplay_, xwindow_, event_mask); 141 XSelectInput(xdisplay_, xwindow_, event_mask);
96 142
97 unsigned char mask[XIMaskLen(XI_LASTEVENT)]; 143 unsigned char mask[XIMaskLen(XI_LASTEVENT)];
98 memset(mask, 0, sizeof(mask)); 144 memset(mask, 0, sizeof(mask));
99 145
100 XISetMask(mask, XI_TouchBegin); 146 XISetMask(mask, XI_TouchBegin);
101 XISetMask(mask, XI_TouchUpdate); 147 XISetMask(mask, XI_TouchUpdate);
102 XISetMask(mask, XI_TouchEnd); 148 XISetMask(mask, XI_TouchEnd);
149 XISetMask(mask, XI_ButtonPress);
150 XISetMask(mask, XI_ButtonRelease);
151 XISetMask(mask, XI_Motion);
152 XISetMask(mask, XI_KeyPress);
153 XISetMask(mask, XI_KeyRelease);
103 154
104 XIEventMask evmask; 155 XIEventMask evmask;
105 evmask.deviceid = XIAllDevices; 156 evmask.deviceid = XIAllDevices;
106 evmask.mask_len = sizeof(mask); 157 evmask.mask_len = sizeof(mask);
107 evmask.mask = mask; 158 evmask.mask = mask;
108 XISelectEvents(xdisplay_, xwindow_, &evmask, 1); 159 XISelectEvents(xdisplay_, xwindow_, &evmask, 1);
109 XFlush(xdisplay_); 160 XFlush(xdisplay_);
110 161
111 ::Atom protocols[2]; 162 ::Atom protocols[2];
112 protocols[0] = atom_cache_.GetAtom("WM_DELETE_WINDOW"); 163 protocols[0] = atom_cache_.GetAtom("WM_DELETE_WINDOW");
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 336
286 XSendEvent(xdisplay_, 337 XSendEvent(xdisplay_,
287 reply_event.xclient.window, 338 reply_event.xclient.window,
288 False, 339 False,
289 SubstructureRedirectMask | SubstructureNotifyMask, 340 SubstructureRedirectMask | SubstructureNotifyMask,
290 &reply_event); 341 &reply_event);
291 XFlush(xdisplay_); 342 XFlush(xdisplay_);
292 } 343 }
293 break; 344 break;
294 } 345 }
346
347 case GenericEvent: {
348 ProcessXInput2Event(xev);
349 break;
350 }
295 } 351 }
296 return POST_DISPATCH_STOP_PROPAGATION; 352 return POST_DISPATCH_STOP_PROPAGATION;
297 } 353 }
298 354
299 } // namespace ui 355 } // namespace ui
OLDNEW
« no previous file with comments | « ui/platform_window/x11/x11_window.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698