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 virtual ~DesktopScreenX11();
33 // Overridden from gfx::Screen:
34 virtual gfx::Point
GetCursorScreenPoint() override
;
35 virtual gfx::NativeWindow
GetWindowUnderCursor() override
;
36 virtual gfx::NativeWindow
GetWindowAtScreenPoint(const gfx::Point
& point
)
38 virtual int GetNumDisplays() const override
;
39 virtual std::vector
<gfx::Display
> GetAllDisplays() const override
;
40 virtual gfx::Display
GetDisplayNearestWindow(
41 gfx::NativeView window
) const override
;
42 virtual gfx::Display
GetDisplayNearestPoint(
43 const gfx::Point
& point
) const override
;
44 virtual gfx::Display
GetDisplayMatching(
45 const gfx::Rect
& match_rect
) const override
;
46 virtual gfx::Display
GetPrimaryDisplay() const override
;
47 virtual void AddObserver(gfx::DisplayObserver
* observer
) override
;
48 virtual void RemoveObserver(gfx::DisplayObserver
* observer
) override
;
50 // ui::PlatformEventDispatcher:
51 virtual bool CanDispatchEvent(const ui::PlatformEvent
& event
) override
;
52 virtual uint32_t DispatchEvent(const ui::PlatformEvent
& event
) override
;
55 friend class DesktopScreenX11Test
;
57 // Constructor used in tests.
58 DesktopScreenX11(const std::vector
<gfx::Display
>& test_displays
);
60 // Builds a list of displays from the current screen information offered by
62 std::vector
<gfx::Display
> BuildDisplaysFromXRandRInfo();
64 // We delay updating the display so we can coalesce events.
65 void ConfigureTimerFired();
68 ::Window x_root_window_
;
70 // Whether the x server supports the XRandR extension.
73 // The base of the event numbers used to represent XRandr events used in
74 // decoding events regarding output add/remove.
75 int xrandr_event_base_
;
77 // The display objects we present to chrome.
78 std::vector
<gfx::Display
> displays_
;
80 // The timer to delay configuring outputs. See also the comments in
82 scoped_ptr
<base::OneShotTimer
<DesktopScreenX11
> > configure_timer_
;
84 gfx::DisplayChangeNotifier change_notifier_
;
86 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11
);
91 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_