Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/aura/desktop_host.h" | 5 #include "ui/aura/desktop_host.h" |
| 6 | 6 |
| 7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 | 9 |
| 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include <X11/extensions/XInput2.h> | 26 #include <X11/extensions/XInput2.h> |
| 27 #include <X11/Xlib.h> | 27 #include <X11/Xlib.h> |
| 28 | 28 |
| 29 using std::max; | 29 using std::max; |
| 30 using std::min; | 30 using std::min; |
| 31 | 31 |
| 32 namespace aura { | 32 namespace aura { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // The events reported for slave devices can have incorrect information for some | |
| 37 // fields. This utility function is used to check for such inconsistencies. | |
| 38 void CheckXEventForConsistency(XEvent* xevent) { | |
| 39 static bool expect_master_event = false; | |
| 40 static XIDeviceEvent slave_event; | |
| 41 static gfx::Point slave_location; | |
|
sky
2011/11/30 16:38:04
Statics should only be primitive types.
| |
| 42 | |
| 43 if (!xevent || xevent->type != GenericEvent) { | |
| 44 expect_master_event = false; | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xevent->xcookie.data); | |
| 49 if (xievent->evtype != XI_Motion && | |
| 50 xievent->evtype != XI_ButtonPress && | |
| 51 xievent->evtype != XI_ButtonRelease) { | |
| 52 expect_master_event = false; | |
| 53 return; | |
| 54 } | |
| 55 | |
| 56 if (xievent->sourceid == xievent->deviceid) { | |
| 57 // This is a slave event. We shouldn't have been expecting a master event. | |
| 58 CHECK(!expect_master_event); | |
| 59 slave_event = *xievent; | |
| 60 slave_location = ui::EventLocationFromNative(xevent); | |
| 61 expect_master_event = true; | |
| 62 } else if (expect_master_event) { | |
| 63 CHECK_EQ(slave_location.x(), ui::EventLocationFromNative(xevent).x()); | |
| 64 CHECK_EQ(slave_location.y(), ui::EventLocationFromNative(xevent).y()); | |
| 65 | |
| 66 CHECK_EQ(slave_event.type, xievent->type); | |
| 67 CHECK_EQ(slave_event.evtype, xievent->evtype); | |
| 68 CHECK_EQ(slave_event.detail, xievent->detail); | |
| 69 CHECK_EQ(slave_event.flags, xievent->flags); | |
| 70 CHECK_EQ(slave_event.buttons.mask_len, xievent->buttons.mask_len); | |
| 71 CHECK_EQ(slave_event.valuators.mask_len, xievent->valuators.mask_len); | |
| 72 CHECK_EQ(slave_event.mods.base, xievent->mods.base); | |
| 73 CHECK_EQ(slave_event.mods.latched, xievent->mods.latched); | |
| 74 CHECK_EQ(slave_event.mods.locked, xievent->mods.locked); | |
| 75 CHECK_EQ(slave_event.mods.effective, xievent->mods.effective); | |
| 76 | |
| 77 expect_master_event = false; | |
| 78 } | |
| 79 } | |
| 80 | |
| 36 // Returns X font cursor shape from an Aura cursor. | 81 // Returns X font cursor shape from an Aura cursor. |
| 37 int CursorShapeFromNative(gfx::NativeCursor native_cursor) { | 82 int CursorShapeFromNative(gfx::NativeCursor native_cursor) { |
| 38 switch (native_cursor) { | 83 switch (native_cursor) { |
| 39 case aura::kCursorNull: | 84 case aura::kCursorNull: |
| 40 return XC_left_ptr; | 85 return XC_left_ptr; |
| 41 case aura::kCursorPointer: | 86 case aura::kCursorPointer: |
| 42 return XC_left_ptr; | 87 return XC_left_ptr; |
| 43 case aura::kCursorCross: | 88 case aura::kCursorCross: |
| 44 return XC_crosshair; | 89 return XC_crosshair; |
| 45 case aura::kCursorHand: | 90 case aura::kCursorHand: |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 | 179 |
| 135 // If we can't get the cookie, abort the check. | 180 // If we can't get the cookie, abort the check. |
| 136 if (!XGetEventData(next_event.xgeneric.display, &next_event.xcookie)) | 181 if (!XGetEventData(next_event.xgeneric.display, &next_event.xcookie)) |
| 137 return num_coalesed; | 182 return num_coalesed; |
| 138 | 183 |
| 139 // If this isn't from a valid device, throw the event away, as | 184 // If this isn't from a valid device, throw the event away, as |
| 140 // that's what the message pump would do. Device events come in pairs | 185 // that's what the message pump would do. Device events come in pairs |
| 141 // with one from the master and one from the slave so there will | 186 // with one from the master and one from the slave so there will |
| 142 // always be at least one pending. | 187 // always be at least one pending. |
| 143 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { | 188 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { |
| 189 CheckXEventForConsistency(&next_event); | |
| 144 XFreeEventData(display, &next_event.xcookie); | 190 XFreeEventData(display, &next_event.xcookie); |
| 145 XNextEvent(display, &next_event); | 191 XNextEvent(display, &next_event); |
| 146 continue; | 192 continue; |
| 147 } | 193 } |
| 148 | 194 |
| 149 if (next_event.type == GenericEvent && | 195 if (next_event.type == GenericEvent && |
| 150 next_event.xgeneric.evtype == XI_Motion) { | 196 next_event.xgeneric.evtype == XI_Motion) { |
| 151 XIDeviceEvent* next_xievent = | 197 XIDeviceEvent* next_xievent = |
| 152 static_cast<XIDeviceEvent*>(next_event.xcookie.data); | 198 static_cast<XIDeviceEvent*>(next_event.xcookie.data); |
| 153 // Confirm that the motion event is targeted at the same window | 199 // Confirm that the motion event is targeted at the same window |
| 154 // and that no buttons or modifiers have changed. | 200 // and that no buttons or modifiers have changed. |
| 155 if (xievent->event == next_xievent->event && | 201 if (xievent->event == next_xievent->event && |
| 156 xievent->child == next_xievent->child && | 202 xievent->child == next_xievent->child && |
| 157 xievent->buttons.mask_len == next_xievent->buttons.mask_len && | 203 xievent->buttons.mask_len == next_xievent->buttons.mask_len && |
| 158 (memcmp(xievent->buttons.mask, | 204 (memcmp(xievent->buttons.mask, |
| 159 next_xievent->buttons.mask, | 205 next_xievent->buttons.mask, |
| 160 xievent->buttons.mask_len) == 0) && | 206 xievent->buttons.mask_len) == 0) && |
| 161 xievent->mods.base == next_xievent->mods.base && | 207 xievent->mods.base == next_xievent->mods.base && |
| 162 xievent->mods.latched == next_xievent->mods.latched && | 208 xievent->mods.latched == next_xievent->mods.latched && |
| 163 xievent->mods.locked == next_xievent->mods.locked && | 209 xievent->mods.locked == next_xievent->mods.locked && |
| 164 xievent->mods.effective == next_xievent->mods.effective) { | 210 xievent->mods.effective == next_xievent->mods.effective) { |
| 165 XFreeEventData(display, &next_event.xcookie); | 211 XFreeEventData(display, &next_event.xcookie); |
| 166 // Free the previous cookie. | 212 // Free the previous cookie. |
| 167 if (num_coalesed > 0) | 213 if (num_coalesed > 0) |
| 168 XFreeEventData(display, &last_event->xcookie); | 214 XFreeEventData(display, &last_event->xcookie); |
| 169 // Get the event and its cookie data. | 215 // Get the event and its cookie data. |
| 170 XNextEvent(display, last_event); | 216 XNextEvent(display, last_event); |
| 171 XGetEventData(display, &last_event->xcookie); | 217 XGetEventData(display, &last_event->xcookie); |
| 218 CheckXEventForConsistency(last_event); | |
| 172 ++num_coalesed; | 219 ++num_coalesed; |
| 173 continue; | 220 continue; |
| 174 } else { | 221 } else { |
| 175 // This isn't an event we want so free its cookie data. | 222 // This isn't an event we want so free its cookie data. |
| 176 XFreeEventData(display, &next_event.xcookie); | 223 XFreeEventData(display, &next_event.xcookie); |
| 177 } | 224 } |
| 178 } | 225 } |
| 179 break; | 226 break; |
| 180 } | 227 } |
| 181 return num_coalesed; | 228 return num_coalesed; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 root_window_(DefaultRootWindow(xdisplay_)), | 320 root_window_(DefaultRootWindow(xdisplay_)), |
| 274 current_cursor_(aura::kCursorNull), | 321 current_cursor_(aura::kCursorNull), |
| 275 bounds_(bounds) { | 322 bounds_(bounds) { |
| 276 xwindow_ = XCreateSimpleWindow(xdisplay_, root_window_, | 323 xwindow_ = XCreateSimpleWindow(xdisplay_, root_window_, |
| 277 bounds.x(), bounds.y(), | 324 bounds.x(), bounds.y(), |
| 278 bounds.width(), bounds.height(), | 325 bounds.width(), bounds.height(), |
| 279 0, 0, 0); | 326 0, 0, 0); |
| 280 | 327 |
| 281 long event_mask = ButtonPressMask | ButtonReleaseMask | | 328 long event_mask = ButtonPressMask | ButtonReleaseMask | |
| 282 KeyPressMask | KeyReleaseMask | | 329 KeyPressMask | KeyReleaseMask | |
| 330 EnterWindowMask | LeaveWindowMask | | |
| 283 ExposureMask | VisibilityChangeMask | | 331 ExposureMask | VisibilityChangeMask | |
| 284 StructureNotifyMask | PropertyChangeMask | | 332 StructureNotifyMask | PropertyChangeMask | |
| 285 PointerMotionMask; | 333 PointerMotionMask; |
| 286 XSelectInput(xdisplay_, xwindow_, event_mask); | 334 XSelectInput(xdisplay_, xwindow_, event_mask); |
| 287 XSelectInput(xdisplay_, root_window_, StructureNotifyMask); | 335 XSelectInput(xdisplay_, root_window_, StructureNotifyMask); |
| 288 XFlush(xdisplay_); | 336 XFlush(xdisplay_); |
| 289 | 337 |
| 290 // TODO(sadrul): reenable once 103981 is fixed. | |
| 291 #if defined(TOUCH_UI) | |
| 292 if (base::MessagePumpForUI::HasXInput2()) | 338 if (base::MessagePumpForUI::HasXInput2()) |
|
DaveMoore
2011/11/30 16:51:51
Do we ever expect to run in an environment w/out X
sadrul
2011/11/30 16:53:50
XInput2 is usually not available when running over
| |
| 293 ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); | 339 ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); |
| 294 #endif | |
| 295 } | 340 } |
| 296 | 341 |
| 297 DesktopHostLinux::~DesktopHostLinux() { | 342 DesktopHostLinux::~DesktopHostLinux() { |
| 298 XDestroyWindow(xdisplay_, xwindow_); | 343 XDestroyWindow(xdisplay_, xwindow_); |
| 299 | 344 |
| 300 // Clears XCursorCache. | 345 // Clears XCursorCache. |
| 301 ui::GetXCursor(ui::kCursorClearXCursorCache); | 346 ui::GetXCursor(ui::kCursorClearXCursorCache); |
| 302 } | 347 } |
| 303 | 348 |
| 304 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( | 349 base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( |
| 305 XEvent* xev) { | 350 XEvent* xev) { |
| 306 DLOG(WARNING) << "DispatchEvent:" << xev->type; | 351 DLOG(WARNING) << "DispatchEvent:" << xev->type; |
| 307 | 352 |
| 308 bool handled = false; | 353 bool handled = false; |
| 354 | |
| 355 CheckXEventForConsistency(xev); | |
| 356 | |
| 309 switch (xev->type) { | 357 switch (xev->type) { |
| 310 case Expose: | 358 case Expose: |
| 311 desktop_->Draw(); | 359 desktop_->Draw(); |
| 312 handled = true; | 360 handled = true; |
| 313 break; | 361 break; |
| 314 case KeyPress: { | 362 case KeyPress: { |
| 315 KeyEvent keydown_event(xev, false); | 363 KeyEvent keydown_event(xev, false); |
| 316 handled = desktop_->DispatchKeyEvent(&keydown_event); | 364 handled = desktop_->DispatchKeyEvent(&keydown_event); |
| 317 if (ShouldSendCharEventForKeyboardCode(keydown_event.key_code())) { | 365 if (ShouldSendCharEventForKeyboardCode(keydown_event.key_code())) { |
| 318 KeyEvent char_event(xev, true); | 366 KeyEvent char_event(xev, true); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 return new DesktopHostLinux(bounds); | 596 return new DesktopHostLinux(bounds); |
| 549 } | 597 } |
| 550 | 598 |
| 551 // static | 599 // static |
| 552 gfx::Size DesktopHost::GetNativeScreenSize() { | 600 gfx::Size DesktopHost::GetNativeScreenSize() { |
| 553 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 601 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
| 554 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 602 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
| 555 } | 603 } |
| 556 | 604 |
| 557 } // namespace aura | 605 } // namespace aura |
| OLD | NEW |