1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_
6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_
8 #include "base/timer/timer.h"
9 #include "ui/events/platform/platform_event_dispatcher.h"
10 #include "ui/gfx/display_change_notifier.h"
11 #include "ui/gfx/screen.h"
12 #include "ui/views/views_export.h"
18 typedef unsigned long XID
;
20 typedef struct _XDisplay Display
;
23 class DesktopScreenX11Test
;
25 // Our singleton screen implementation that talks to xrandr.
26 class VIEWS_EXPORT DesktopScreenX11
: public gfx::Screen
,
27 public ui::PlatformEventDispatcher
{
31 ~DesktopScreenX11() override
;
33 // Overridden from gfx::Screen:
34 gfx::Point
GetCursorScreenPoint() override
;
35 gfx::NativeWindow
GetWindowUnderCursor() override
;
36 gfx::NativeWindow
GetWindowAtScreenPoint(const gfx::Point
& point
) override
;
37 int GetNumDisplays() const override
;
38 std::vector
<gfx::Display
> GetAllDisplays() const override
;
39 gfx::Display
GetDisplayNearestWindow(gfx::NativeView window
) const override
;
40 gfx::Display
GetDisplayNearestPoint(const gfx::Point
& point
) const override
;
41 gfx::Display
GetDisplayMatching(const gfx::Rect
& match_rect
) const override
;
42 gfx::Display
GetPrimaryDisplay() const override
;
43 void AddObserver(gfx::DisplayObserver
* observer
) override
;
44 void RemoveObserver(gfx::DisplayObserver
* observer
) override
;
46 // ui::PlatformEventDispatcher:
47 bool CanDispatchEvent(const ui::PlatformEvent
& event
) override
;
48 uint32_t DispatchEvent(const ui::PlatformEvent
& event
) override
;
51 friend class DesktopScreenX11Test
;
53 // Constructor used in tests.
54 DesktopScreenX11(const std::vector
<gfx::Display
>& test_displays
);
56 // Builds a list of displays from the current screen information offered by
58 std::vector
<gfx::Display
> BuildDisplaysFromXRandRInfo();
60 // We delay updating the display so we can coalesce events.
61 void ConfigureTimerFired();
64 ::Window x_root_window_
;
66 // Whether the x server supports the XRandR extension.
69 // The base of the event numbers used to represent XRandr events used in
70 // decoding events regarding output add/remove.
71 int xrandr_event_base_
;
73 // The display objects we present to chrome.
74 std::vector
<gfx::Display
> displays_
;
76 // The timer to delay configuring outputs. See also the comments in
78 scoped_ptr
<base::OneShotTimer
<DesktopScreenX11
> > configure_timer_
;
80 gfx::DisplayChangeNotifier change_notifier_
;
82 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11
);
87 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_