OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ | 5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ |
6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ | 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
| 12 #include "base/cancelable_callback.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/timer/timer.h" | |
14 #include "ui/display/display_change_notifier.h" | 14 #include "ui/display/display_change_notifier.h" |
15 #include "ui/display/screen.h" | 15 #include "ui/display/screen.h" |
16 #include "ui/events/platform/platform_event_dispatcher.h" | 16 #include "ui/events/platform/platform_event_dispatcher.h" |
| 17 #include "ui/views/linux_ui/device_scale_factor_observer.h" |
17 #include "ui/views/views_export.h" | 18 #include "ui/views/views_export.h" |
18 | 19 |
19 typedef unsigned long XID; | 20 typedef unsigned long XID; |
20 typedef XID Window; | 21 typedef XID Window; |
21 typedef struct _XDisplay Display; | 22 typedef struct _XDisplay Display; |
22 | 23 |
23 namespace views { | 24 namespace views { |
24 class DesktopScreenX11Test; | 25 class DesktopScreenX11Test; |
25 | 26 |
26 namespace test { | 27 namespace test { |
27 class DesktopScreenX11TestApi; | 28 class DesktopScreenX11TestApi; |
28 } | 29 } |
29 | 30 |
30 // Our singleton screen implementation that talks to xrandr. | 31 // Our singleton screen implementation that talks to xrandr. |
31 class VIEWS_EXPORT DesktopScreenX11 : public display::Screen, | 32 class VIEWS_EXPORT DesktopScreenX11 : public display::Screen, |
32 public ui::PlatformEventDispatcher { | 33 public ui::PlatformEventDispatcher, |
| 34 public views::DeviceScaleFactorObserver { |
33 public: | 35 public: |
34 DesktopScreenX11(); | 36 DesktopScreenX11(); |
35 | 37 |
36 ~DesktopScreenX11() override; | 38 ~DesktopScreenX11() override; |
37 | 39 |
38 // Overridden from display::Screen: | 40 // Overridden from display::Screen: |
39 gfx::Point GetCursorScreenPoint() override; | 41 gfx::Point GetCursorScreenPoint() override; |
40 bool IsWindowUnderCursor(gfx::NativeWindow window) override; | 42 bool IsWindowUnderCursor(gfx::NativeWindow window) override; |
41 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; | 43 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; |
42 int GetNumDisplays() const override; | 44 int GetNumDisplays() const override; |
43 const std::vector<display::Display>& GetAllDisplays() const override; | 45 const std::vector<display::Display>& GetAllDisplays() const override; |
44 display::Display GetDisplayNearestWindow( | 46 display::Display GetDisplayNearestWindow( |
45 gfx::NativeView window) const override; | 47 gfx::NativeView window) const override; |
46 display::Display GetDisplayNearestPoint( | 48 display::Display GetDisplayNearestPoint( |
47 const gfx::Point& point) const override; | 49 const gfx::Point& point) const override; |
48 display::Display GetDisplayMatching( | 50 display::Display GetDisplayMatching( |
49 const gfx::Rect& match_rect) const override; | 51 const gfx::Rect& match_rect) const override; |
50 display::Display GetPrimaryDisplay() const override; | 52 display::Display GetPrimaryDisplay() const override; |
51 void AddObserver(display::DisplayObserver* observer) override; | 53 void AddObserver(display::DisplayObserver* observer) override; |
52 void RemoveObserver(display::DisplayObserver* observer) override; | 54 void RemoveObserver(display::DisplayObserver* observer) override; |
53 | 55 |
54 // ui::PlatformEventDispatcher: | 56 // ui::PlatformEventDispatcher: |
55 bool CanDispatchEvent(const ui::PlatformEvent& event) override; | 57 bool CanDispatchEvent(const ui::PlatformEvent& event) override; |
56 uint32_t DispatchEvent(const ui::PlatformEvent& event) override; | 58 uint32_t DispatchEvent(const ui::PlatformEvent& event) override; |
57 | 59 |
| 60 // views::DeviceScaleFactorObserver: |
| 61 void OnDeviceScaleFactorChanged() override; |
| 62 |
58 static void UpdateDeviceScaleFactorForTest(); | 63 static void UpdateDeviceScaleFactorForTest(); |
59 | 64 |
60 private: | 65 private: |
61 friend class DesktopScreenX11Test; | 66 friend class DesktopScreenX11Test; |
62 friend class test::DesktopScreenX11TestApi; | 67 friend class test::DesktopScreenX11TestApi; |
63 | 68 |
64 // Constructor used in tests. | 69 // Constructor used in tests. |
65 DesktopScreenX11(const std::vector<display::Display>& test_displays); | 70 DesktopScreenX11(const std::vector<display::Display>& test_displays); |
66 | 71 |
67 // Builds a list of displays from the current screen information offered by | 72 // Builds a list of displays from the current screen information offered by |
68 // the X server. | 73 // the X server. |
69 std::vector<display::Display> BuildDisplaysFromXRandRInfo(); | 74 std::vector<display::Display> BuildDisplaysFromXRandRInfo(); |
70 | 75 |
71 // We delay updating the display so we can coalesce events. | 76 // Removes |delayed_configuration_task_| from the task queue (if |
72 void ConfigureTimerFired(); | 77 // it's in the queue) and adds it back at the end of the queue. |
| 78 void RestartDelayedConfigurationTask(); |
73 | 79 |
74 // Updates |displays_| and sets FontRenderParams's scale factor. | 80 // Updates |displays_| with the latest XRandR info. |
| 81 void UpdateDisplays(); |
| 82 |
| 83 // Updates |displays_| from |displays| and sets FontRenderParams's scale |
| 84 // factor. |
75 void SetDisplaysInternal(const std::vector<display::Display>& displays); | 85 void SetDisplaysInternal(const std::vector<display::Display>& displays); |
76 | 86 |
77 Display* xdisplay_; | 87 Display* xdisplay_; |
78 ::Window x_root_window_; | 88 ::Window x_root_window_; |
79 | 89 |
80 // Whether the x server supports the XRandR extension. | 90 // Whether the x server supports the XRandR extension. |
81 bool has_xrandr_; | 91 bool has_xrandr_; |
82 | 92 |
83 // The base of the event numbers used to represent XRandr events used in | 93 // The base of the event numbers used to represent XRandr events used in |
84 // decoding events regarding output add/remove. | 94 // decoding events regarding output add/remove. |
85 int xrandr_event_base_; | 95 int xrandr_event_base_; |
86 | 96 |
87 // The display objects we present to chrome. | 97 // The display objects we present to chrome. |
88 std::vector<display::Display> displays_; | 98 std::vector<display::Display> displays_; |
89 | 99 |
90 // The index into displays_ that represents the primary display. | 100 // The index into displays_ that represents the primary display. |
91 size_t primary_display_index_; | 101 size_t primary_display_index_; |
92 | 102 |
93 // The timer to delay configuring outputs. See also the comments in | 103 // The task to delay configuring outputs. We delay updating the |
94 // Dispatch(). | 104 // display so we can coalesce events. |
95 std::unique_ptr<base::OneShotTimer> configure_timer_; | 105 base::CancelableCallback<void()> delayed_configuration_task_; |
96 | 106 |
97 display::DisplayChangeNotifier change_notifier_; | 107 display::DisplayChangeNotifier change_notifier_; |
98 | 108 |
| 109 base::WeakPtrFactory<DesktopScreenX11> weak_factory_; |
| 110 |
99 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11); | 111 DISALLOW_COPY_AND_ASSIGN(DesktopScreenX11); |
100 }; | 112 }; |
101 | 113 |
102 } // namespace views | 114 } // namespace views |
103 | 115 |
104 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ | 116 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_X11_H_ |
OLD | NEW |