OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/window_tree_host_x11.h" | 5 #include "ui/aura/window_tree_host_x11.h" |
6 | 6 |
7 #include <strings.h> | 7 #include <strings.h> |
8 #include <X11/cursorfont.h> | 8 #include <X11/cursorfont.h> |
9 #include <X11/extensions/Xfixes.h> | 9 #include <X11/extensions/Xfixes.h> |
10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
11 #include <X11/extensions/Xrandr.h> | 11 #include <X11/extensions/Xrandr.h> |
12 #include <X11/Xatom.h> | 12 #include <X11/Xatom.h> |
13 #include <X11/Xcursor/Xcursor.h> | 13 #include <X11/Xcursor/Xcursor.h> |
14 #include <X11/Xlib.h> | 14 #include <X11/Xlib.h> |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 #include <limits> | 17 #include <limits> |
18 #include <string> | 18 #include <string> |
19 | 19 |
20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/debug/trace_event.h" | 22 #include "base/debug/trace_event.h" |
23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
24 #include "base/message_loop/message_pump_x11.h" | |
25 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
26 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
28 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
29 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
30 #include "ui/aura/client/cursor_client.h" | 29 #include "ui/aura/client/cursor_client.h" |
31 #include "ui/aura/client/screen_position_client.h" | 30 #include "ui/aura/client/screen_position_client.h" |
32 #include "ui/aura/env.h" | 31 #include "ui/aura/env.h" |
33 #include "ui/aura/window_event_dispatcher.h" | 32 #include "ui/aura/window_event_dispatcher.h" |
34 #include "ui/base/cursor/cursor.h" | 33 #include "ui/base/cursor/cursor.h" |
35 #include "ui/base/ui_base_switches.h" | 34 #include "ui/base/ui_base_switches.h" |
36 #include "ui/base/view_prop.h" | 35 #include "ui/base/view_prop.h" |
37 #include "ui/base/x/x11_util.h" | 36 #include "ui/base/x/x11_util.h" |
38 #include "ui/compositor/compositor.h" | 37 #include "ui/compositor/compositor.h" |
39 #include "ui/compositor/dip_util.h" | 38 #include "ui/compositor/dip_util.h" |
40 #include "ui/compositor/layer.h" | 39 #include "ui/compositor/layer.h" |
41 #include "ui/events/event.h" | 40 #include "ui/events/event.h" |
42 #include "ui/events/event_switches.h" | 41 #include "ui/events/event_switches.h" |
43 #include "ui/events/event_utils.h" | 42 #include "ui/events/event_utils.h" |
44 #include "ui/events/keycodes/keyboard_codes.h" | 43 #include "ui/events/keycodes/keyboard_codes.h" |
| 44 #include "ui/events/platform/x11/x11_event_source.h" |
45 #include "ui/events/x/device_data_manager.h" | 45 #include "ui/events/x/device_data_manager.h" |
46 #include "ui/events/x/device_list_cache_x.h" | 46 #include "ui/events/x/device_list_cache_x.h" |
47 #include "ui/events/x/touch_factory_x11.h" | 47 #include "ui/events/x/touch_factory_x11.h" |
48 #include "ui/gfx/screen.h" | 48 #include "ui/gfx/screen.h" |
49 | 49 |
50 using std::max; | 50 using std::max; |
51 using std::min; | 51 using std::min; |
52 | 52 |
53 namespace aura { | 53 namespace aura { |
54 | 54 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 swa.override_redirect = default_override_redirect; | 259 swa.override_redirect = default_override_redirect; |
260 xwindow_ = XCreateWindow( | 260 xwindow_ = XCreateWindow( |
261 xdisplay_, x_root_window_, | 261 xdisplay_, x_root_window_, |
262 bounds.x(), bounds.y(), bounds.width(), bounds.height(), | 262 bounds.x(), bounds.y(), bounds.width(), bounds.height(), |
263 0, // border width | 263 0, // border width |
264 CopyFromParent, // depth | 264 CopyFromParent, // depth |
265 InputOutput, | 265 InputOutput, |
266 CopyFromParent, // visual | 266 CopyFromParent, // visual |
267 CWBackPixmap | CWOverrideRedirect, | 267 CWBackPixmap | CWOverrideRedirect, |
268 &swa); | 268 &swa); |
269 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, xwindow_); | 269 if (ui::PlatformEventSource::GetInstance()) |
270 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(this); | 270 ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
271 | 271 |
272 long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask | | 272 long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask | |
273 KeyPressMask | KeyReleaseMask | | 273 KeyPressMask | KeyReleaseMask | |
274 EnterWindowMask | LeaveWindowMask | | 274 EnterWindowMask | LeaveWindowMask | |
275 ExposureMask | VisibilityChangeMask | | 275 ExposureMask | VisibilityChangeMask | |
276 StructureNotifyMask | PropertyChangeMask | | 276 StructureNotifyMask | PropertyChangeMask | |
277 PointerMotionMask; | 277 PointerMotionMask; |
278 XSelectInput(xdisplay_, xwindow_, event_mask); | 278 XSelectInput(xdisplay_, xwindow_, event_mask); |
279 XFlush(xdisplay_); | 279 XFlush(xdisplay_); |
280 | 280 |
(...skipping 28 matching lines...) Expand all Loading... |
309 reinterpret_cast<unsigned char*>(&pid), 1); | 309 reinterpret_cast<unsigned char*>(&pid), 1); |
310 | 310 |
311 XRRSelectInput(xdisplay_, x_root_window_, | 311 XRRSelectInput(xdisplay_, x_root_window_, |
312 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); | 312 RRScreenChangeNotifyMask | RROutputChangeNotifyMask); |
313 Env::GetInstance()->AddObserver(this); | 313 Env::GetInstance()->AddObserver(this); |
314 CreateCompositor(GetAcceleratedWidget()); | 314 CreateCompositor(GetAcceleratedWidget()); |
315 } | 315 } |
316 | 316 |
317 WindowTreeHostX11::~WindowTreeHostX11() { | 317 WindowTreeHostX11::~WindowTreeHostX11() { |
318 Env::GetInstance()->RemoveObserver(this); | 318 Env::GetInstance()->RemoveObserver(this); |
319 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(this); | 319 if (ui::PlatformEventSource::GetInstance()) |
320 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(xwindow_); | 320 ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
321 | 321 |
322 UnConfineCursor(); | 322 UnConfineCursor(); |
323 | 323 |
324 DestroyCompositor(); | 324 DestroyCompositor(); |
325 DestroyDispatcher(); | 325 DestroyDispatcher(); |
326 XDestroyWindow(xdisplay_, xwindow_); | 326 XDestroyWindow(xdisplay_, xwindow_); |
327 } | 327 } |
328 | 328 |
329 uint32_t WindowTreeHostX11::Dispatch(const base::NativeEvent& event) { | 329 bool WindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) { |
| 330 ::Window target = FindEventTarget(event); |
| 331 return target == xwindow_ || target == x_root_window_; |
| 332 } |
| 333 |
| 334 uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { |
330 XEvent* xev = event; | 335 XEvent* xev = event; |
331 | 336 if (FindEventTarget(xev) == x_root_window_) { |
332 if (FindEventTarget(event) == x_root_window_) { | 337 if (xev->type == GenericEvent) |
333 if (event->type == GenericEvent) | 338 DispatchXI2Event(xev); |
334 DispatchXI2Event(event); | 339 return ui::POST_DISPATCH_NONE; |
335 return POST_DISPATCH_NONE; | |
336 } | 340 } |
337 | 341 |
338 switch (xev->type) { | 342 switch (xev->type) { |
339 case EnterNotify: { | 343 case EnterNotify: { |
340 aura::Window* root_window = window(); | 344 aura::Window* root_window = window(); |
341 client::CursorClient* cursor_client = | 345 client::CursorClient* cursor_client = |
342 client::GetCursorClient(root_window); | 346 client::GetCursorClient(root_window); |
343 if (cursor_client) { | 347 if (cursor_client) { |
344 const gfx::Display display = gfx::Screen::GetScreenFor(root_window)-> | 348 const gfx::Display display = gfx::Screen::GetScreenFor(root_window)-> |
345 GetDisplayNearestWindow(root_window); | 349 GetDisplayNearestWindow(root_window); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 UnConfineCursor(); | 421 UnConfineCursor(); |
418 ConfineCursorToRootWindow(); | 422 ConfineCursorToRootWindow(); |
419 } | 423 } |
420 if (size_changed) | 424 if (size_changed) |
421 OnHostResized(bounds.size()); | 425 OnHostResized(bounds.size()); |
422 if (origin_changed) | 426 if (origin_changed) |
423 OnHostMoved(bounds_.origin()); | 427 OnHostMoved(bounds_.origin()); |
424 break; | 428 break; |
425 } | 429 } |
426 case GenericEvent: | 430 case GenericEvent: |
427 DispatchXI2Event(event); | 431 DispatchXI2Event(xev); |
428 break; | 432 break; |
429 case ClientMessage: { | 433 case ClientMessage: { |
430 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); | 434 Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]); |
431 if (message_type == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { | 435 if (message_type == atom_cache_.GetAtom("WM_DELETE_WINDOW")) { |
432 // We have received a close message from the window manager. | 436 // We have received a close message from the window manager. |
433 OnHostCloseRequested(); | 437 OnHostCloseRequested(); |
434 } else if (message_type == atom_cache_.GetAtom("_NET_WM_PING")) { | 438 } else if (message_type == atom_cache_.GetAtom("_NET_WM_PING")) { |
435 XEvent reply_event = *xev; | 439 XEvent reply_event = *xev; |
436 reply_event.xclient.window = x_root_window_; | 440 reply_event.xclient.window = x_root_window_; |
437 | 441 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } else { | 478 } else { |
475 break; | 479 break; |
476 } | 480 } |
477 } | 481 } |
478 | 482 |
479 ui::MouseEvent mouseev(xev); | 483 ui::MouseEvent mouseev(xev); |
480 TranslateAndDispatchMouseEvent(&mouseev); | 484 TranslateAndDispatchMouseEvent(&mouseev); |
481 break; | 485 break; |
482 } | 486 } |
483 } | 487 } |
484 return POST_DISPATCH_NONE; | 488 return ui::POST_DISPATCH_STOP_PROPAGATION; |
485 } | 489 } |
486 | 490 |
487 gfx::AcceleratedWidget WindowTreeHostX11::GetAcceleratedWidget() { | 491 gfx::AcceleratedWidget WindowTreeHostX11::GetAcceleratedWidget() { |
488 return xwindow_; | 492 return xwindow_; |
489 } | 493 } |
490 | 494 |
491 void WindowTreeHostX11::Show() { | 495 void WindowTreeHostX11::Show() { |
492 if (!window_mapped_) { | 496 if (!window_mapped_) { |
493 // Before we map the window, set size hints. Otherwise, some window managers | 497 // Before we map the window, set size hints. Otherwise, some window managers |
494 // will ignore toplevel XMoveWindow commands. | 498 // will ignore toplevel XMoveWindow commands. |
495 XSizeHints size_hints; | 499 XSizeHints size_hints; |
496 size_hints.flags = PPosition | PWinGravity; | 500 size_hints.flags = PPosition | PWinGravity; |
497 size_hints.x = bounds_.x(); | 501 size_hints.x = bounds_.x(); |
498 size_hints.y = bounds_.y(); | 502 size_hints.y = bounds_.y(); |
499 // Set StaticGravity so that the window position is not affected by the | 503 // Set StaticGravity so that the window position is not affected by the |
500 // frame width when running with window manager. | 504 // frame width when running with window manager. |
501 size_hints.win_gravity = StaticGravity; | 505 size_hints.win_gravity = StaticGravity; |
502 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); | 506 XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); |
503 | 507 |
504 XMapWindow(xdisplay_, xwindow_); | 508 XMapWindow(xdisplay_, xwindow_); |
505 | 509 |
506 // We now block until our window is mapped. Some X11 APIs will crash and | 510 // We now block until our window is mapped. Some X11 APIs will crash and |
507 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is | 511 // burn if passed |xwindow_| before the window is mapped, and XMapWindow is |
508 // asynchronous. | 512 // asynchronous. |
509 base::MessagePumpX11::Current()->BlockUntilWindowMapped(xwindow_); | 513 if (ui::X11EventSource::GetInstance()) |
| 514 ui::X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_); |
510 window_mapped_ = true; | 515 window_mapped_ = true; |
511 } | 516 } |
512 } | 517 } |
513 | 518 |
514 void WindowTreeHostX11::Hide() { | 519 void WindowTreeHostX11::Hide() { |
515 if (window_mapped_) { | 520 if (window_mapped_) { |
516 XWithdrawWindow(xdisplay_, xwindow_, 0); | 521 XWithdrawWindow(xdisplay_, xwindow_, 0); |
517 window_mapped_ = false; | 522 window_mapped_ = false; |
518 } | 523 } |
519 } | 524 } |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 } | 919 } |
915 | 920 |
916 namespace test { | 921 namespace test { |
917 | 922 |
918 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { | 923 void SetUseOverrideRedirectWindowByDefault(bool override_redirect) { |
919 default_override_redirect = override_redirect; | 924 default_override_redirect = override_redirect; |
920 } | 925 } |
921 | 926 |
922 } // namespace test | 927 } // namespace test |
923 } // namespace aura | 928 } // namespace aura |
OLD | NEW |