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

Side by Side Diff: ui/events/platform/x11/x11_event_source.cc

Issue 1913913004: Regularly poll the X11 event queue. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rebase Created 4 years, 7 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
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/events/platform/x11/x11_event_source.h" 5 #include "ui/events/platform/x11/x11_event_source.h"
6 6
7 #include <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 #include <X11/X.h> 8 #include <X11/X.h>
9 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
10 #include <X11/XKBlib.h> 10 #include <X11/XKBlib.h>
11 11
12 #include "base/command_line.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "ui/events/devices/x11/device_data_manager_x11.h" 14 #include "ui/events/devices/x11/device_data_manager_x11.h"
15 #include "ui/events/event_switches.h"
14 #include "ui/events/event_utils.h" 16 #include "ui/events/event_utils.h"
15 #include "ui/events/platform/platform_event_dispatcher.h" 17 #include "ui/events/platform/platform_event_dispatcher.h"
16 #include "ui/events/platform/x11/x11_hotplug_event_handler.h" 18 #include "ui/events/platform/x11/x11_hotplug_event_handler.h"
17 #include "ui/gfx/x/x11_types.h" 19 #include "ui/gfx/x/x11_types.h"
18 20
19 namespace ui { 21 namespace ui {
20 22
21 namespace { 23 namespace {
22 24
23 int g_xinput_opcode = -1; 25 int g_xinput_opcode = -1;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 76
75 } // namespace 77 } // namespace
76 78
77 X11EventSource::X11EventSource(XDisplay* display) 79 X11EventSource::X11EventSource(XDisplay* display)
78 : display_(display), 80 : display_(display),
79 continue_stream_(true) { 81 continue_stream_(true) {
80 CHECK(display_); 82 CHECK(display_);
81 DeviceDataManagerX11::CreateInstance(); 83 DeviceDataManagerX11::CreateInstance();
82 InitializeXInput2(display_); 84 InitializeXInput2(display_);
83 InitializeXkb(display_); 85 InitializeXkb(display_);
86
87 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
88 dispatch_one_event_per_loop_ =
89 cmdline->HasSwitch(switches::kDispatchOneEventPerLoop);
84 } 90 }
85 91
86 X11EventSource::~X11EventSource() { 92 X11EventSource::~X11EventSource() {
87 } 93 }
88 94
89 // static 95 // static
90 X11EventSource* X11EventSource::GetInstance() { 96 X11EventSource* X11EventSource::GetInstance() {
91 return static_cast<X11EventSource*>(PlatformEventSource::GetInstance()); 97 return static_cast<X11EventSource*>(PlatformEventSource::GetInstance());
92 } 98 }
93 99
94 //////////////////////////////////////////////////////////////////////////////// 100 ////////////////////////////////////////////////////////////////////////////////
95 // X11EventSource, public 101 // X11EventSource, public
96 102
97 void X11EventSource::DispatchXEvents() { 103 bool X11EventSource::DispatchXEvents() {
98 DCHECK(display_); 104 DCHECK(display_);
99 // Handle all pending events. 105
100 // It may be useful to eventually align this event dispatch with vsync, but 106 int pending_events = XPending(display_);
101 // not yet. 107 if (!pending_events)
102 continue_stream_ = true; 108 return false;
103 while (XPending(display_) && continue_stream_) { 109 do {
104 XEvent xevent; 110 XEvent xevent;
105 XNextEvent(display_, &xevent); 111 XNextEvent(display_, &xevent);
106 DispatchEvent(&xevent); 112 DispatchEvent(&xevent);
107 } 113 } while (--pending_events && continue_stream_ &&
114 !dispatch_one_event_per_loop_);
115 return true;
108 } 116 }
109 117
110 void X11EventSource::BlockUntilWindowMapped(XID window) { 118 void X11EventSource::BlockUntilWindowMapped(XID window) {
111 XEvent event; 119 XEvent event;
112 do { 120 do {
113 // Block until there's a message of |event_mask| type on |w|. Then remove 121 // Block until there's a message of |event_mask| type on |w|. Then remove
114 // it from the queue and stuff it in |event|. 122 // it from the queue and stuff it in |event|.
115 XWindowEvent(display_, window, StructureNotifyMask, &event); 123 XWindowEvent(display_, window, StructureNotifyMask, &event);
116 DispatchEvent(&event); 124 DispatchEvent(&event);
117 } while (event.type != MapNotify); 125 } while (event.type != MapNotify);
(...skipping 27 matching lines...) Expand all
145 153
146 void X11EventSource::OnDispatcherListChanged() { 154 void X11EventSource::OnDispatcherListChanged() {
147 if (!hotplug_event_handler_) { 155 if (!hotplug_event_handler_) {
148 hotplug_event_handler_.reset(new X11HotplugEventHandler()); 156 hotplug_event_handler_.reset(new X11HotplugEventHandler());
149 // Force the initial device query to have an update list of active devices. 157 // Force the initial device query to have an update list of active devices.
150 hotplug_event_handler_->OnHotplugEvent(); 158 hotplug_event_handler_->OnHotplugEvent();
151 } 159 }
152 } 160 }
153 161
154 } // namespace ui 162 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/platform/x11/x11_event_source.h ('k') | ui/events/platform/x11/x11_event_source_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698