Merge lp:~andreas-pokorny/unity-system-compositor/override-orientation-dbus-api into lp:unity-system-compositor
- override-orientation-dbus-api
- Merge into trunk
Proposed by
Andreas Pokorny
Status: | Work in progress |
---|---|
Proposed branch: | lp:~andreas-pokorny/unity-system-compositor/override-orientation-dbus-api |
Merge into: | lp:unity-system-compositor |
Diff against target: |
971 lines (+396/-224) 19 files modified
debian/control (+1/-1) src/CMakeLists.txt (+2/-2) src/cursor_enabler.cpp (+72/-0) src/cursor_enabler.h (+58/-0) src/dbus_screen.cpp (+16/-2) src/dbus_screen.h (+6/-1) src/powerkey_handler.cpp (+16/-9) src/screen_state_handler.cpp (+17/-8) src/server.cpp (+7/-29) src/server.h (+7/-0) src/shell.cpp (+59/-20) src/shell.h (+13/-13) src/surface_coordinator.cpp (+0/-87) src/surface_coordinator.h (+0/-47) src/system_compositor.cpp (+8/-0) src/system_compositor.h (+2/-0) tests/unit-tests/CMakeLists.txt (+1/-0) tests/unit-tests/test_cursor_enabler.cpp (+110/-0) tests/unit-tests/test_session_switcher.cpp (+1/-5) |
To merge this branch: | bzr merge lp:~andreas-pokorny/unity-system-compositor/override-orientation-dbus-api |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity System Compositor Development Team | Pending | ||
Review via email: mp+248896@code.launchpad.net |
Commit message
Ugly hack to have a different orientation for cursors without changing the orientation
Description of the change
Ugly hack to have a different orientation for cursors without changing the orientation
To post a comment you must log in.
Unmerged revisions
- 205. By Andreas Pokorny
-
add a dbus api to override orientation
- 204. By Andreas Pokorny
-
merge event-2.0 changes back in
*fingers-crossed*
- 203. By Andreas Pokorny
-
keep display on when mouse pointer moves
- 202. By Andreas Pokorny
-
merged mirevent-2.0
- 201. By Andreas Pokorny
-
further cleanup drops all references to cursor image again
- 200. By Andreas Pokorny
-
ok nearly
- 199. By Andreas Pokorny
-
merged msh changes
- 198. By Andreas Pokorny
-
merged event-2.0 changes
- 197. By Andreas Pokorny
-
add test and cleanup further
- 196. By Andreas Pokorny
-
Rework Cursor enablement inside Unity-System-
Compositor
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/control' | |||
2 | --- debian/control 2015-01-07 23:33:32 +0000 | |||
3 | +++ debian/control 2015-02-06 12:38:32 +0000 | |||
4 | @@ -19,7 +19,7 @@ | |||
5 | 19 | libglib2.0-dev, | 19 | libglib2.0-dev, |
6 | 20 | libgles2-mesa-dev, | 20 | libgles2-mesa-dev, |
7 | 21 | libmirclient-dev (>= 0.6.0), | 21 | libmirclient-dev (>= 0.6.0), |
9 | 22 | libmirserver-dev (>= 0.10.0), | 22 | libmirserver-dev (>= 0.11.0), |
10 | 23 | libprotobuf-dev, | 23 | libprotobuf-dev, |
11 | 24 | pkg-config, | 24 | pkg-config, |
12 | 25 | python:any (>= 2.7), | 25 | python:any (>= 2.7), |
13 | 26 | 26 | ||
14 | === modified file 'src/CMakeLists.txt' | |||
15 | --- src/CMakeLists.txt 2014-11-06 12:18:08 +0000 | |||
16 | +++ src/CMakeLists.txt 2015-02-06 12:38:32 +0000 | |||
17 | @@ -16,15 +16,15 @@ | |||
18 | 16 | 16 | ||
19 | 17 | set(USC_SRCS | 17 | set(USC_SRCS |
20 | 18 | asio_dm_connection.cpp | 18 | asio_dm_connection.cpp |
21 | 19 | cursor_enabler.cpp | ||
22 | 19 | dbus_screen.cpp | 20 | dbus_screen.cpp |
23 | 20 | external_spinner.cpp | 21 | external_spinner.cpp |
24 | 21 | powerd_mediator.cpp | 22 | powerd_mediator.cpp |
25 | 22 | powerkey_handler.cpp | 23 | powerkey_handler.cpp |
26 | 23 | screen_state_handler.cpp | 24 | screen_state_handler.cpp |
27 | 24 | server.cpp | 25 | server.cpp |
29 | 25 | session_coordinator.cpp | 26 | shell.cpp |
30 | 26 | session_switcher.cpp | 27 | session_switcher.cpp |
31 | 27 | surface_coordinator.cpp | ||
32 | 28 | system_compositor.cpp | 28 | system_compositor.cpp |
33 | 29 | worker_thread.cpp | 29 | worker_thread.cpp |
34 | 30 | ) | 30 | ) |
35 | 31 | 31 | ||
36 | === added file 'src/cursor_enabler.cpp' | |||
37 | --- src/cursor_enabler.cpp 1970-01-01 00:00:00 +0000 | |||
38 | +++ src/cursor_enabler.cpp 2015-02-06 12:38:32 +0000 | |||
39 | @@ -0,0 +1,72 @@ | |||
40 | 1 | /* | ||
41 | 2 | * Copyright © 2015 Canonical Ltd. | ||
42 | 3 | * | ||
43 | 4 | * This program is free software: you can redistribute it and/or modify | ||
44 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
45 | 6 | * published by the Free Software Foundation. | ||
46 | 7 | * | ||
47 | 8 | * This program is distributed in the hope that it will be useful, | ||
48 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
49 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
50 | 11 | * GNU General Public License for more details. | ||
51 | 12 | * | ||
52 | 13 | * You should have received a copy of the GNU General Public License | ||
53 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
54 | 15 | */ | ||
55 | 16 | |||
56 | 17 | #include "cursor_enabler.h" | ||
57 | 18 | |||
58 | 19 | #include "mir/graphics/cursor.h" | ||
59 | 20 | #include "mir_toolkit/event.h" | ||
60 | 21 | |||
61 | 22 | namespace mi = mir::input; | ||
62 | 23 | |||
63 | 24 | CursorEnabler::CursorEnabler( | ||
64 | 25 | std::shared_ptr<mir::graphics::Cursor> const& cursor, | ||
65 | 26 | std::chrono::milliseconds remove_pointer_timeout) | ||
66 | 27 | : cursor_shown(false), remove_delay{static_cast<uint32_t>(remove_pointer_timeout.count())}, last_cursor_movement(0), | ||
67 | 28 | cursor(cursor) | ||
68 | 29 | { | ||
69 | 30 | cursor->hide(); | ||
70 | 31 | } | ||
71 | 32 | |||
72 | 33 | CursorEnabler::~CursorEnabler() = default; | ||
73 | 34 | |||
74 | 35 | bool CursorEnabler::handle(MirEvent const& event) | ||
75 | 36 | { | ||
76 | 37 | if (mir_event_get_type(&event) != mir_event_type_input) | ||
77 | 38 | { | ||
78 | 39 | return false; | ||
79 | 40 | } | ||
80 | 41 | auto const* ev = mir_event_get_input_event(&event); | ||
81 | 42 | if (mir_input_event_type_pointer == mir_input_event_get_type(ev)) | ||
82 | 43 | { | ||
83 | 44 | enable_cursor(); | ||
84 | 45 | last_cursor_movement = event.motion.event_time; | ||
85 | 46 | } | ||
86 | 47 | else if (remove_delay && | ||
87 | 48 | mir_input_event_type_touch == mir_input_event_get_type(ev) && | ||
88 | 49 | (event.motion.event_time - last_cursor_movement > remove_delay)) | ||
89 | 50 | { | ||
90 | 51 | disable_cursor(); | ||
91 | 52 | } | ||
92 | 53 | return false; | ||
93 | 54 | } | ||
94 | 55 | |||
95 | 56 | void CursorEnabler::enable_cursor() | ||
96 | 57 | { | ||
97 | 58 | if (!cursor_shown) | ||
98 | 59 | { | ||
99 | 60 | cursor->show(); | ||
100 | 61 | cursor_shown = true; | ||
101 | 62 | } | ||
102 | 63 | } | ||
103 | 64 | |||
104 | 65 | void CursorEnabler::disable_cursor() | ||
105 | 66 | { | ||
106 | 67 | if (cursor_shown) | ||
107 | 68 | { | ||
108 | 69 | cursor->hide(); | ||
109 | 70 | cursor_shown = false; | ||
110 | 71 | } | ||
111 | 72 | } | ||
112 | 0 | 73 | ||
113 | === added file 'src/cursor_enabler.h' | |||
114 | --- src/cursor_enabler.h 1970-01-01 00:00:00 +0000 | |||
115 | +++ src/cursor_enabler.h 2015-02-06 12:38:32 +0000 | |||
116 | @@ -0,0 +1,58 @@ | |||
117 | 1 | /* | ||
118 | 2 | * Copyright © 2015 Canonical Ltd. | ||
119 | 3 | * | ||
120 | 4 | * This program is free software: you can redistribute it and/or modify | ||
121 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
122 | 6 | * published by the Free Software Foundation. | ||
123 | 7 | * | ||
124 | 8 | * This program is distributed in the hope that it will be useful, | ||
125 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
126 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
127 | 11 | * GNU General Public License for more details. | ||
128 | 12 | * | ||
129 | 13 | * You should have received a copy of the GNU General Public License | ||
130 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
131 | 15 | */ | ||
132 | 16 | |||
133 | 17 | #ifndef USC_CURSOR_IMAGE_ENABLER_H_ | ||
134 | 18 | #define USC_CURSOR_IMAGE_ENABLER_H_ | ||
135 | 19 | |||
136 | 20 | #include "mir/input/event_filter.h" | ||
137 | 21 | |||
138 | 22 | #include <memory> | ||
139 | 23 | #include <chrono> | ||
140 | 24 | |||
141 | 25 | namespace mir | ||
142 | 26 | { | ||
143 | 27 | namespace graphics | ||
144 | 28 | { | ||
145 | 29 | class Cursor; | ||
146 | 30 | class CursorImage; | ||
147 | 31 | } | ||
148 | 32 | } | ||
149 | 33 | |||
150 | 34 | /* | ||
151 | 35 | * Disables the cursor on construction and waits for the first mir pointer/cursor | ||
152 | 36 | * event to come by for enabling the cursor again. | ||
153 | 37 | */ | ||
154 | 38 | class CursorEnabler : public mir::input::EventFilter | ||
155 | 39 | { | ||
156 | 40 | public: | ||
157 | 41 | CursorEnabler(std::shared_ptr<mir::graphics::Cursor> const& cursor, | ||
158 | 42 | std::chrono::milliseconds remove_pointer_timeout); | ||
159 | 43 | |||
160 | 44 | ~CursorEnabler(); | ||
161 | 45 | |||
162 | 46 | bool handle(MirEvent const& event) override; | ||
163 | 47 | |||
164 | 48 | private: | ||
165 | 49 | void enable_cursor(); | ||
166 | 50 | void disable_cursor(); | ||
167 | 51 | |||
168 | 52 | bool cursor_shown; | ||
169 | 53 | uint32_t remove_delay; | ||
170 | 54 | uint32_t last_cursor_movement; | ||
171 | 55 | std::shared_ptr<mir::graphics::Cursor> const cursor; | ||
172 | 56 | }; | ||
173 | 57 | |||
174 | 58 | #endif | ||
175 | 0 | 59 | ||
176 | === modified file 'src/dbus_screen.cpp' | |||
177 | --- src/dbus_screen.cpp 2014-10-10 22:43:34 +0000 | |||
178 | +++ src/dbus_screen.cpp 2015-02-06 12:38:32 +0000 | |||
179 | @@ -20,6 +20,9 @@ | |||
180 | 20 | #include "power_state_change_reason.h" | 20 | #include "power_state_change_reason.h" |
181 | 21 | #include "worker_thread.h" | 21 | #include "worker_thread.h" |
182 | 22 | 22 | ||
183 | 23 | #include "mir/input/input_region.h" | ||
184 | 24 | #include "mir/graphics/cursor.h" | ||
185 | 25 | |||
186 | 23 | #include <atomic> | 26 | #include <atomic> |
187 | 24 | #include <memory> | 27 | #include <memory> |
188 | 25 | #include <thread> | 28 | #include <thread> |
189 | @@ -53,12 +56,17 @@ | |||
190 | 53 | } | 56 | } |
191 | 54 | 57 | ||
192 | 55 | 58 | ||
194 | 56 | DBusScreen::DBusScreen(DBusScreenObserver& observer, QObject *parent) | 59 | DBusScreen::DBusScreen(DBusScreenObserver& observer, |
195 | 60 | std::shared_ptr<mir::input::InputRegion> const& region, | ||
196 | 61 | std::shared_ptr<mir::graphics::Cursor> const& cursor, | ||
197 | 62 | QObject *parent) | ||
198 | 57 | : QObject(parent), | 63 | : QObject(parent), |
199 | 58 | dbus_adaptor{new DBusScreenAdaptor(this)}, | 64 | dbus_adaptor{new DBusScreenAdaptor(this)}, |
200 | 59 | service_watcher{new QDBusServiceWatcher()}, | 65 | service_watcher{new QDBusServiceWatcher()}, |
201 | 60 | observer{&observer}, | 66 | observer{&observer}, |
203 | 61 | worker_thread{new usc::WorkerThread("USC/DBusHandler")} | 67 | worker_thread{new usc::WorkerThread("USC/DBusHandler")}, |
204 | 68 | region(region), | ||
205 | 69 | cursor(cursor) | ||
206 | 62 | { | 70 | { |
207 | 63 | QDBusConnection bus = QDBusConnection::systemBus(); | 71 | QDBusConnection bus = QDBusConnection::systemBus(); |
208 | 64 | bus.registerObject("/com/canonical/Unity/Screen", this); | 72 | bus.registerObject("/com/canonical/Unity/Screen", this); |
209 | @@ -211,3 +219,9 @@ | |||
210 | 211 | { | 219 | { |
211 | 212 | observer->set_touch_visualization_enabled(enabled); | 220 | observer->set_touch_visualization_enabled(enabled); |
212 | 213 | } | 221 | } |
213 | 222 | |||
214 | 223 | void DBusScreen::overrideOrientation(unsigned int index, int orientation) | ||
215 | 224 | { | ||
216 | 225 | region->override_orientation(index, static_cast<MirOrientation>(orientation)); | ||
217 | 226 | cursor->override_orientation(index, static_cast<MirOrientation>(orientation)); | ||
218 | 227 | } | ||
219 | 214 | 228 | ||
220 | === modified file 'src/dbus_screen.h' | |||
221 | --- src/dbus_screen.h 2014-09-22 17:19:52 +0000 | |||
222 | +++ src/dbus_screen.h 2015-02-06 12:38:32 +0000 | |||
223 | @@ -30,6 +30,8 @@ | |||
224 | 30 | 30 | ||
225 | 31 | namespace usc {class WorkerThread;} | 31 | namespace usc {class WorkerThread;} |
226 | 32 | 32 | ||
227 | 33 | namespace mir { namespace graphics { class Cursor; } namespace input { class InputRegion; } } | ||
228 | 34 | |||
229 | 33 | class DBusScreenAdaptor; | 35 | class DBusScreenAdaptor; |
230 | 34 | class DBusScreenObserver; | 36 | class DBusScreenObserver; |
231 | 35 | class QDBusInterface; | 37 | class QDBusInterface; |
232 | @@ -42,7 +44,7 @@ | |||
233 | 42 | Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Screen") | 44 | Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Screen") |
234 | 43 | 45 | ||
235 | 44 | public: | 46 | public: |
237 | 45 | explicit DBusScreen(DBusScreenObserver& observer, QObject *parent = 0); | 47 | explicit DBusScreen(DBusScreenObserver& observer, std::shared_ptr<mir::input::InputRegion> const& region, std::shared_ptr<mir::graphics::Cursor> const& cursor, QObject *parent = 0); |
238 | 46 | virtual ~DBusScreen(); | 48 | virtual ~DBusScreen(); |
239 | 47 | 49 | ||
240 | 48 | void emit_power_state_change(MirPowerMode mode, PowerStateChangeReason reason); | 50 | void emit_power_state_change(MirPowerMode mode, PowerStateChangeReason reason); |
241 | @@ -59,6 +61,7 @@ | |||
242 | 59 | void setInactivityTimeouts(int poweroff_timeout, int dimmer_timeout); | 61 | void setInactivityTimeouts(int poweroff_timeout, int dimmer_timeout); |
243 | 60 | 62 | ||
244 | 61 | void setTouchVisualizationEnabled(bool enabled); | 63 | void setTouchVisualizationEnabled(bool enabled); |
245 | 64 | void overrideOrientation(unsigned int index, int orientation); | ||
246 | 62 | 65 | ||
247 | 63 | private Q_SLOTS: | 66 | private Q_SLOTS: |
248 | 64 | void remove_display_on_requestor(QString const& requestor); | 67 | void remove_display_on_requestor(QString const& requestor); |
249 | @@ -72,6 +75,8 @@ | |||
250 | 72 | std::unordered_map<std::string, std::unordered_set<int>> display_requests; | 75 | std::unordered_map<std::string, std::unordered_set<int>> display_requests; |
251 | 73 | DBusScreenObserver* const observer; | 76 | DBusScreenObserver* const observer; |
252 | 74 | std::unique_ptr<usc::WorkerThread> worker_thread; | 77 | std::unique_ptr<usc::WorkerThread> worker_thread; |
253 | 78 | std::shared_ptr<mir::input::InputRegion> const region; | ||
254 | 79 | std::shared_ptr<mir::graphics::Cursor> const cursor; | ||
255 | 75 | }; | 80 | }; |
256 | 76 | 81 | ||
257 | 77 | #endif /* DBUS_SCREEN_H_ */ | 82 | #endif /* DBUS_SCREEN_H_ */ |
258 | 78 | 83 | ||
259 | === modified file 'src/powerkey_handler.cpp' | |||
260 | --- src/powerkey_handler.cpp 2014-07-21 21:33:35 +0000 | |||
261 | +++ src/powerkey_handler.cpp 2015-02-06 12:38:32 +0000 | |||
262 | @@ -44,15 +44,22 @@ | |||
263 | 44 | bool PowerKeyHandler::handle(MirEvent const& event) | 44 | bool PowerKeyHandler::handle(MirEvent const& event) |
264 | 45 | { | 45 | { |
265 | 46 | static const int32_t POWER_KEY_CODE = 26; | 46 | static const int32_t POWER_KEY_CODE = 26; |
275 | 47 | 47 | ||
276 | 48 | if (event.type == mir_event_type_key && | 48 | if (mir_event_get_type(&event) != mir_event_type_input) |
277 | 49 | event.key.key_code == POWER_KEY_CODE) | 49 | return false; |
278 | 50 | { | 50 | auto input_event = mir_event_get_input_event(&event); |
279 | 51 | if (event.key.action == mir_key_action_down) | 51 | if (mir_input_event_get_type(input_event) != mir_input_event_type_key) |
280 | 52 | power_key_down(); | 52 | return false; |
281 | 53 | else if (event.key.action == mir_key_action_up) | 53 | auto kev = mir_input_event_get_key_input_event(input_event); |
282 | 54 | power_key_up(); | 54 | if (mir_key_input_event_get_key_code(kev) != POWER_KEY_CODE) |
283 | 55 | } | 55 | return false; |
284 | 56 | |||
285 | 57 | auto action = mir_key_input_event_get_action(kev); | ||
286 | 58 | if (action == mir_key_input_event_action_down) | ||
287 | 59 | power_key_down(); | ||
288 | 60 | else if (action == mir_key_input_event_action_up) | ||
289 | 61 | power_key_up(); | ||
290 | 62 | |||
291 | 56 | return false; | 63 | return false; |
292 | 57 | } | 64 | } |
293 | 58 | 65 | ||
294 | 59 | 66 | ||
295 | === modified file 'src/screen_state_handler.cpp' | |||
296 | --- src/screen_state_handler.cpp 2015-01-26 22:59:20 +0000 | |||
297 | +++ src/screen_state_handler.cpp 2015-02-06 12:38:32 +0000 | |||
298 | @@ -47,7 +47,7 @@ | |||
299 | 47 | std::bind(&ScreenStateHandler::power_off_alarm_notification, this))}, | 47 | std::bind(&ScreenStateHandler::power_off_alarm_notification, this))}, |
300 | 48 | dimmer_alarm{server->the_main_loop()->create_alarm( | 48 | dimmer_alarm{server->the_main_loop()->create_alarm( |
301 | 49 | std::bind(&ScreenStateHandler::dimmer_alarm_notification, this))}, | 49 | std::bind(&ScreenStateHandler::dimmer_alarm_notification, this))}, |
303 | 50 | dbus_screen{new DBusScreen(*this)} | 50 | dbus_screen{new DBusScreen(*this, server->the_input_region(), server->the_cursor())} |
304 | 51 | { | 51 | { |
305 | 52 | /* | 52 | /* |
306 | 53 | * Make sure the compositor is running as certain conditions can | 53 | * Make sure the compositor is running as certain conditions can |
307 | @@ -62,13 +62,22 @@ | |||
308 | 62 | 62 | ||
309 | 63 | bool ScreenStateHandler::handle(MirEvent const& event) | 63 | bool ScreenStateHandler::handle(MirEvent const& event) |
310 | 64 | { | 64 | { |
318 | 65 | if (event.type == mir_event_type_motion) | 65 | if (mir_event_get_type(&event) != mir_event_type_input) |
319 | 66 | { | 66 | return false; |
320 | 67 | std::lock_guard<std::mutex> lock{guard}; | 67 | |
321 | 68 | reset_timers_l(); | 68 | auto input_event_type = mir_input_event_get_type(mir_event_get_input_event(&event)); |
322 | 69 | if (current_power_mode == MirPowerMode::mir_power_mode_on) | 69 | // TODO: We should consider resetting the timer for key events too |
323 | 70 | powerd_mediator->set_normal_backlight(); | 70 | // we have to make sure we wont introduce a bug where pressing the power |
324 | 71 | } | 71 | // key (to turn screen off) or just the volume keys will wake the screen though! |
325 | 72 | if (!(input_event_type == mir_input_event_type_touch | ||
326 | 73 | || input_event_type == mir_input_event_type_pointer)) | ||
327 | 74 | return false; | ||
328 | 75 | |||
329 | 76 | std::lock_guard<std::mutex> lock{guard}; | ||
330 | 77 | reset_timers_l(); | ||
331 | 78 | if (current_power_mode == MirPowerMode::mir_power_mode_on) | ||
332 | 79 | powerd_mediator->set_normal_backlight(); | ||
333 | 80 | |||
334 | 72 | return false; | 81 | return false; |
335 | 73 | } | 82 | } |
336 | 74 | 83 | ||
337 | 75 | 84 | ||
338 | === modified file 'src/server.cpp' | |||
339 | --- src/server.cpp 2014-11-28 11:39:04 +0000 | |||
340 | +++ src/server.cpp 2015-02-06 12:38:32 +0000 | |||
341 | @@ -1,5 +1,5 @@ | |||
342 | 1 | /* | 1 | /* |
344 | 2 | * Copyright © 2014 Canonical Ltd. | 2 | * Copyright © 2014-2015 Canonical Ltd. |
345 | 3 | * | 3 | * |
346 | 4 | * This program is free software: you can redistribute it and/or modify | 4 | * This program is free software: you can redistribute it and/or modify |
347 | 5 | * it under the terms of the GNU General Public License version 3 as | 5 | * it under the terms of the GNU General Public License version 3 as |
348 | @@ -18,8 +18,7 @@ | |||
349 | 18 | 18 | ||
350 | 19 | #include "server.h" | 19 | #include "server.h" |
351 | 20 | #include "external_spinner.h" | 20 | #include "external_spinner.h" |
354 | 21 | #include "session_coordinator.h" | 21 | #include "shell.h" |
353 | 22 | #include "surface_coordinator.h" | ||
355 | 23 | #include "asio_dm_connection.h" | 22 | #include "asio_dm_connection.h" |
356 | 24 | #include "session_switcher.h" | 23 | #include "session_switcher.h" |
357 | 25 | 24 | ||
358 | @@ -103,44 +102,23 @@ | |||
359 | 103 | add_configuration_option("inactivity-display-dim-timeout", "The time in seconds before the screen is dimmed when there are no active sessions", mir::OptionType::integer); | 102 | add_configuration_option("inactivity-display-dim-timeout", "The time in seconds before the screen is dimmed when there are no active sessions", mir::OptionType::integer); |
360 | 104 | add_configuration_option("shutdown-timeout", "The time in milli-seconds the power key must be held to initiate a clean system shutdown", mir::OptionType::integer); | 103 | add_configuration_option("shutdown-timeout", "The time in milli-seconds the power key must be held to initiate a clean system shutdown", mir::OptionType::integer); |
361 | 105 | add_configuration_option("power-key-ignore-timeout", "The time in milli-seconds the power key must be held to ignore - must be less than shutdown-timeout", mir::OptionType::integer); | 104 | add_configuration_option("power-key-ignore-timeout", "The time in milli-seconds the power key must be held to ignore - must be less than shutdown-timeout", mir::OptionType::integer); |
362 | 105 | add_configuration_option("remove_pointer_timeout", "The time in milli-seconds the cursor image stays visible after touch screen is used again - by default the cursor image stays visible", mir::OptionType::integer); | ||
363 | 106 | add_configuration_option("disable-inactivity-policy", "Disables handling user inactivity and power key", mir::OptionType::boolean); | 106 | add_configuration_option("disable-inactivity-policy", "Disables handling user inactivity and power key", mir::OptionType::boolean); |
364 | 107 | 107 | ||
365 | 108 | set_command_line(argc, const_cast<char const **>(argv)); | 108 | set_command_line(argc, const_cast<char const **>(argv)); |
366 | 109 | 109 | ||
367 | 110 | set_command_line_handler(&ignore_unknown_arguments); | 110 | set_command_line_handler(&ignore_unknown_arguments); |
368 | 111 | 111 | ||
369 | 112 | wrap_cursor_listener([this](std::shared_ptr<mir::input::CursorListener> const& default_) | ||
370 | 113 | -> std::shared_ptr<mir::input::CursorListener> | ||
371 | 114 | { | ||
372 | 115 | // This is a workaround for u8 desktop preview in 14.04 for the lack of client cursor API. | ||
373 | 116 | // We need to disable the cursor for XMir but leave it on for the desktop preview. | ||
374 | 117 | // Luckily as it stands they run inside seperate instances of USC. ~racarr | ||
375 | 118 | if (enable_hardware_cursor()) | ||
376 | 119 | return default_; | ||
377 | 120 | else | ||
378 | 121 | return std::make_shared<NullCursorListener>(); | ||
379 | 122 | }); | ||
380 | 123 | |||
381 | 124 | override_the_server_status_listener([this]() | 112 | override_the_server_status_listener([this]() |
382 | 125 | -> std::shared_ptr<mir::ServerStatusListener> | 113 | -> std::shared_ptr<mir::ServerStatusListener> |
383 | 126 | { | 114 | { |
384 | 127 | return std::make_shared<ServerStatusListener>(the_focus_controller()); | 115 | return std::make_shared<ServerStatusListener>(the_focus_controller()); |
385 | 128 | }); | 116 | }); |
386 | 129 | 117 | ||
401 | 130 | wrap_session_coordinator([this](std::shared_ptr<ms::SessionCoordinator> const& wrapped) | 118 | wrap_shell([this](std::shared_ptr<msh::Shell> const& wrapped) |
402 | 131 | -> std::shared_ptr<ms::SessionCoordinator> | 119 | -> std::shared_ptr<msh::Shell> |
403 | 132 | { | 120 | { |
404 | 133 | return std::make_shared<SessionCoordinator>( | 121 | return std::make_shared<Shell>(wrapped, the_session_switcher()); |
391 | 134 | wrapped, | ||
392 | 135 | the_session_switcher()); | ||
393 | 136 | }); | ||
394 | 137 | |||
395 | 138 | wrap_surface_coordinator([this](std::shared_ptr<ms::SurfaceCoordinator> const& wrapped) | ||
396 | 139 | -> std::shared_ptr<mir::scene::SurfaceCoordinator> | ||
397 | 140 | { | ||
398 | 141 | return std::make_shared<SurfaceCoordinator>( | ||
399 | 142 | wrapped, | ||
400 | 143 | the_session_switcher()); | ||
405 | 144 | }); | 122 | }); |
406 | 145 | 123 | ||
407 | 146 | set_config_filename("unity-system-compositor.conf"); | 124 | set_config_filename("unity-system-compositor.conf"); |
408 | 147 | 125 | ||
409 | === modified file 'src/server.h' | |||
410 | --- src/server.h 2014-11-28 11:39:04 +0000 | |||
411 | +++ src/server.h 2015-02-06 12:38:32 +0000 | |||
412 | @@ -42,6 +42,8 @@ | |||
413 | 42 | using mir::Server::the_display; | 42 | using mir::Server::the_display; |
414 | 43 | using mir::Server::the_compositor; | 43 | using mir::Server::the_compositor; |
415 | 44 | using mir::Server::the_touch_visualizer; | 44 | using mir::Server::the_touch_visualizer; |
416 | 45 | using mir::Server::the_cursor; | ||
417 | 46 | using mir::Server::the_input_region; | ||
418 | 45 | 47 | ||
419 | 46 | virtual std::shared_ptr<Spinner> the_spinner(); | 48 | virtual std::shared_ptr<Spinner> the_spinner(); |
420 | 47 | virtual std::shared_ptr<DMMessageHandler> the_dm_message_handler(); | 49 | virtual std::shared_ptr<DMMessageHandler> the_dm_message_handler(); |
421 | @@ -72,6 +74,11 @@ | |||
422 | 72 | return the_options()->get("power-key-ignore-timeout", 2000); | 74 | return the_options()->get("power-key-ignore-timeout", 2000); |
423 | 73 | } | 75 | } |
424 | 74 | 76 | ||
425 | 77 | int remove_pointer_timeout() | ||
426 | 78 | { | ||
427 | 79 | return the_options()->get("remove-pointer-timeout", 0); | ||
428 | 80 | } | ||
429 | 81 | |||
430 | 75 | bool enable_hardware_cursor() | 82 | bool enable_hardware_cursor() |
431 | 76 | { | 83 | { |
432 | 77 | return the_options()->get("enable-hardware-cursor", false); | 84 | return the_options()->get("enable-hardware-cursor", false); |
433 | 78 | 85 | ||
434 | === renamed file 'src/session_coordinator.cpp' => 'src/shell.cpp' | |||
435 | --- src/session_coordinator.cpp 2014-08-01 21:58:43 +0000 | |||
436 | +++ src/shell.cpp 2015-02-06 12:38:32 +0000 | |||
437 | @@ -1,5 +1,5 @@ | |||
438 | 1 | /* | 1 | /* |
440 | 2 | * Copyright © 2014 Canonical Ltd. | 2 | * Copyright © 2014-2015 Canonical Ltd. |
441 | 3 | * | 3 | * |
442 | 4 | * This program is free software: you can redistribute it and/or modify | 4 | * This program is free software: you can redistribute it and/or modify |
443 | 5 | * it under the terms of the GNU General Public License version 3 as | 5 | * it under the terms of the GNU General Public License version 3 as |
444 | @@ -16,10 +16,12 @@ | |||
445 | 16 | * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> | 16 | * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> |
446 | 17 | */ | 17 | */ |
447 | 18 | 18 | ||
449 | 19 | #include "session_coordinator.h" | 19 | #include "shell.h" |
450 | 20 | #include "session_switcher.h" | 20 | #include "session_switcher.h" |
451 | 21 | 21 | ||
452 | 22 | #include <mir/scene/null_surface_observer.h> | ||
453 | 22 | #include <mir/scene/session.h> | 23 | #include <mir/scene/session.h> |
454 | 24 | #include <mir/scene/surface.h> | ||
455 | 23 | #include <mir/frontend/session.h> | 25 | #include <mir/frontend/session.h> |
456 | 24 | 26 | ||
457 | 25 | #include <iostream> | 27 | #include <iostream> |
458 | @@ -71,34 +73,59 @@ | |||
459 | 71 | msh::FocusController& focus_controller; | 73 | msh::FocusController& focus_controller; |
460 | 72 | }; | 74 | }; |
461 | 73 | 75 | ||
462 | 76 | |||
463 | 77 | struct SessionReadyObserver : ms::NullSurfaceObserver, | ||
464 | 78 | std::enable_shared_from_this<SessionReadyObserver> | ||
465 | 79 | { | ||
466 | 80 | SessionReadyObserver( | ||
467 | 81 | std::shared_ptr<usc::SessionSwitcher> const& switcher, | ||
468 | 82 | std::shared_ptr<ms::Surface> const& surface, | ||
469 | 83 | ms::Session const* session) | ||
470 | 84 | : switcher{switcher}, | ||
471 | 85 | surface{surface}, | ||
472 | 86 | session{session} | ||
473 | 87 | { | ||
474 | 88 | } | ||
475 | 89 | |||
476 | 90 | void frame_posted(int) override | ||
477 | 91 | { | ||
478 | 92 | ++num_frames_posted; | ||
479 | 93 | if (num_frames_posted == num_frames_for_session_ready) | ||
480 | 94 | { | ||
481 | 95 | switcher->mark_ready(session); | ||
482 | 96 | surface->remove_observer(shared_from_this()); | ||
483 | 97 | } | ||
484 | 98 | } | ||
485 | 99 | |||
486 | 100 | std::shared_ptr<usc::SessionSwitcher> const switcher; | ||
487 | 101 | std::shared_ptr<ms::Surface> const surface; | ||
488 | 102 | ms::Session const* const session; | ||
489 | 103 | // We need to wait for the second frame before marking the session | ||
490 | 104 | // as ready. The first frame posted from sessions is a blank frame. | ||
491 | 105 | // TODO: Solve this issue at its root and remove this workaround | ||
492 | 106 | int const num_frames_for_session_ready{2}; | ||
493 | 107 | int num_frames_posted{0}; | ||
494 | 108 | }; | ||
495 | 109 | |||
496 | 74 | } | 110 | } |
497 | 75 | 111 | ||
500 | 76 | usc::SessionCoordinator::SessionCoordinator( | 112 | usc::Shell::Shell( |
501 | 77 | std::shared_ptr<ms::SessionCoordinator> const& wrapped, | 113 | std::shared_ptr<msh::Shell> const& wrapped, |
502 | 78 | std::shared_ptr<SessionSwitcher> const& session_switcher) | 114 | std::shared_ptr<SessionSwitcher> const& session_switcher) |
504 | 79 | : msh::SessionCoordinatorWrapper{wrapped}, | 115 | : msh::ShellWrapper{wrapped}, |
505 | 80 | session_switcher{session_switcher} | 116 | session_switcher{session_switcher} |
506 | 81 | { | 117 | { |
507 | 82 | } | 118 | } |
508 | 83 | 119 | ||
511 | 84 | std::shared_ptr<mf::Session> | 120 | std::shared_ptr<ms::Session> |
512 | 85 | usc::SessionCoordinator::open_session( | 121 | usc::Shell::open_session( |
513 | 86 | pid_t client_pid, | 122 | pid_t client_pid, |
514 | 87 | std::string const& name, | 123 | std::string const& name, |
515 | 88 | std::shared_ptr<mf::EventSink> const& sink) | 124 | std::shared_ptr<mf::EventSink> const& sink) |
516 | 89 | { | 125 | { |
517 | 90 | std::cerr << "Opening session " << name << std::endl; | 126 | std::cerr << "Opening session " << name << std::endl; |
518 | 91 | 127 | ||
529 | 92 | // We need ms::Session objects because that is what the focus controller | 128 | auto orig = msh::ShellWrapper::open_session(client_pid, name, sink); |
520 | 93 | // works with. But the mf::SessionCoordinator interface deals with mf::Session objects. | ||
521 | 94 | // So we cast here since in practice, these objects are also ms::Sessions. | ||
522 | 95 | auto orig = std::dynamic_pointer_cast<ms::Session>( | ||
523 | 96 | msh::SessionCoordinatorWrapper::open_session(client_pid, name, sink)); | ||
524 | 97 | if (!orig) | ||
525 | 98 | { | ||
526 | 99 | std::cerr << "Unexpected non-shell session" << std::endl; | ||
527 | 100 | return std::shared_ptr<mf::Session>(); | ||
528 | 101 | } | ||
530 | 102 | 129 | ||
531 | 103 | auto const usc_session = std::make_shared<UscSession>(orig, *this); | 130 | auto const usc_session = std::make_shared<UscSession>(orig, *this); |
532 | 104 | 131 | ||
533 | @@ -107,12 +134,24 @@ | |||
534 | 107 | return orig; | 134 | return orig; |
535 | 108 | } | 135 | } |
536 | 109 | 136 | ||
539 | 110 | void usc::SessionCoordinator::close_session( | 137 | void usc::Shell::close_session(std::shared_ptr<ms::Session> const& session) |
538 | 111 | std::shared_ptr<mf::Session> const& session) | ||
540 | 112 | { | 138 | { |
541 | 113 | std::cerr << "Closing session " << session->name() << std::endl; | 139 | std::cerr << "Closing session " << session->name() << std::endl; |
542 | 114 | 140 | ||
544 | 115 | msh::SessionCoordinatorWrapper::close_session(session); | 141 | msh::ShellWrapper::close_session(session); |
545 | 116 | 142 | ||
546 | 117 | session_switcher->remove(session); | 143 | session_switcher->remove(session); |
547 | 118 | } | 144 | } |
548 | 145 | |||
549 | 146 | mf::SurfaceId usc::Shell::create_surface(std::shared_ptr<ms::Session> const& session, ms::SurfaceCreationParameters const& params) | ||
550 | 147 | { | ||
551 | 148 | auto const id = msh::ShellWrapper::create_surface(session, params); | ||
552 | 149 | |||
553 | 150 | auto const surface = session->surface(id); | ||
554 | 151 | auto const session_ready_observer = std::make_shared<SessionReadyObserver>( | ||
555 | 152 | session_switcher, surface, session.get()); | ||
556 | 153 | |||
557 | 154 | surface->add_observer(session_ready_observer); | ||
558 | 155 | |||
559 | 156 | return id; | ||
560 | 157 | } | ||
561 | 119 | 158 | ||
562 | === renamed file 'src/session_coordinator.h' => 'src/shell.h' | |||
563 | --- src/session_coordinator.h 2014-07-09 06:58:05 +0000 | |||
564 | +++ src/shell.h 2015-02-06 12:38:32 +0000 | |||
565 | @@ -1,5 +1,5 @@ | |||
566 | 1 | /* | 1 | /* |
568 | 2 | * Copyright © 2014 Canonical Ltd. | 2 | * Copyright © 2014-2015 Canonical Ltd. |
569 | 3 | * | 3 | * |
570 | 4 | * This program is free software: you can redistribute it and/or modify | 4 | * This program is free software: you can redistribute it and/or modify |
571 | 5 | * it under the terms of the GNU General Public License version 3 as | 5 | * it under the terms of the GNU General Public License version 3 as |
572 | @@ -16,35 +16,35 @@ | |||
573 | 16 | * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> | 16 | * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> |
574 | 17 | */ | 17 | */ |
575 | 18 | 18 | ||
578 | 19 | #ifndef USC_SESSION_COORDINATOR_H_ | 19 | #ifndef USC_SHELL_H_ |
579 | 20 | #define USC_SESSION_COORDINATOR_H_ | 20 | #define USC_SHELL_H_ |
580 | 21 | 21 | ||
582 | 22 | #include <mir/shell/session_coordinator_wrapper.h> | 22 | #include <mir/shell/shell_wrapper.h> |
583 | 23 | 23 | ||
584 | 24 | #include <memory> | 24 | #include <memory> |
585 | 25 | 25 | ||
586 | 26 | namespace mir | ||
587 | 27 | { | ||
588 | 28 | namespace scene { class SurfaceCoordinator; } | ||
589 | 29 | } | ||
590 | 30 | 26 | ||
591 | 31 | namespace usc | 27 | namespace usc |
592 | 32 | { | 28 | { |
593 | 33 | class SessionSwitcher; | 29 | class SessionSwitcher; |
594 | 34 | 30 | ||
596 | 35 | class SessionCoordinator : public mir::shell::SessionCoordinatorWrapper | 31 | class Shell : public mir::shell::ShellWrapper |
597 | 36 | { | 32 | { |
598 | 37 | public: | 33 | public: |
601 | 38 | SessionCoordinator( | 34 | Shell( |
602 | 39 | std::shared_ptr<mir::scene::SessionCoordinator> const& wrapped, | 35 | std::shared_ptr<mir::shell::Shell> const& wrapped, |
603 | 40 | std::shared_ptr<SessionSwitcher> const& session_switcher); | 36 | std::shared_ptr<SessionSwitcher> const& session_switcher); |
604 | 41 | 37 | ||
605 | 42 | private: | 38 | private: |
607 | 43 | std::shared_ptr<mir::frontend::Session> open_session( | 39 | std::shared_ptr<mir::scene::Session> open_session( |
608 | 44 | pid_t client_pid, | 40 | pid_t client_pid, |
609 | 45 | std::string const& name, | 41 | std::string const& name, |
610 | 46 | std::shared_ptr<mir::frontend::EventSink> const& sink) override; | 42 | std::shared_ptr<mir::frontend::EventSink> const& sink) override; |
612 | 47 | void close_session(std::shared_ptr<mir::frontend::Session> const& session) override; | 43 | void close_session(std::shared_ptr<mir::scene::Session> const& session) override; |
613 | 44 | |||
614 | 45 | mir::frontend::SurfaceId create_surface( | ||
615 | 46 | std::shared_ptr<mir::scene::Session> const& session, | ||
616 | 47 | mir::scene::SurfaceCreationParameters const& params) override; | ||
617 | 48 | 48 | ||
618 | 49 | std::shared_ptr<SessionSwitcher> const session_switcher; | 49 | std::shared_ptr<SessionSwitcher> const session_switcher; |
619 | 50 | }; | 50 | }; |
620 | 51 | 51 | ||
621 | === removed file 'src/surface_coordinator.cpp' | |||
622 | --- src/surface_coordinator.cpp 2014-08-01 21:58:43 +0000 | |||
623 | +++ src/surface_coordinator.cpp 1970-01-01 00:00:00 +0000 | |||
624 | @@ -1,87 +0,0 @@ | |||
625 | 1 | /* | ||
626 | 2 | * Copyright © 2014 Canonical Ltd. | ||
627 | 3 | * | ||
628 | 4 | * This program is free software: you can redistribute it and/or modify | ||
629 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
630 | 6 | * published by the Free Software Foundation. | ||
631 | 7 | * | ||
632 | 8 | * This program is distributed in the hope that it will be useful, | ||
633 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
634 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
635 | 11 | * GNU General Public License for more details. | ||
636 | 12 | * | ||
637 | 13 | * You should have received a copy of the GNU General Public License | ||
638 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
639 | 15 | * | ||
640 | 16 | * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> | ||
641 | 17 | */ | ||
642 | 18 | |||
643 | 19 | #include "surface_coordinator.h" | ||
644 | 20 | #include "session_switcher.h" | ||
645 | 21 | |||
646 | 22 | #include <mir/scene/null_surface_observer.h> | ||
647 | 23 | #include <mir/scene/surface.h> | ||
648 | 24 | #include <mir/scene/session.h> | ||
649 | 25 | |||
650 | 26 | namespace ms = mir::scene; | ||
651 | 27 | namespace msh = mir::shell; | ||
652 | 28 | |||
653 | 29 | namespace | ||
654 | 30 | { | ||
655 | 31 | |||
656 | 32 | struct SessionReadyObserver : ms::NullSurfaceObserver, | ||
657 | 33 | std::enable_shared_from_this<SessionReadyObserver> | ||
658 | 34 | { | ||
659 | 35 | SessionReadyObserver( | ||
660 | 36 | std::shared_ptr<usc::SessionSwitcher> const& switcher, | ||
661 | 37 | std::shared_ptr<ms::Surface> const& surface, | ||
662 | 38 | ms::Session const* session) | ||
663 | 39 | : switcher{switcher}, | ||
664 | 40 | surface{surface}, | ||
665 | 41 | session{session} | ||
666 | 42 | { | ||
667 | 43 | } | ||
668 | 44 | |||
669 | 45 | void frame_posted(int) override | ||
670 | 46 | { | ||
671 | 47 | ++num_frames_posted; | ||
672 | 48 | if (num_frames_posted == num_frames_for_session_ready) | ||
673 | 49 | { | ||
674 | 50 | switcher->mark_ready(session); | ||
675 | 51 | surface->remove_observer(shared_from_this()); | ||
676 | 52 | } | ||
677 | 53 | } | ||
678 | 54 | |||
679 | 55 | std::shared_ptr<usc::SessionSwitcher> const switcher; | ||
680 | 56 | std::shared_ptr<ms::Surface> const surface; | ||
681 | 57 | ms::Session const* const session; | ||
682 | 58 | // We need to wait for the second frame before marking the session | ||
683 | 59 | // as ready. The first frame posted from sessions is a blank frame. | ||
684 | 60 | // TODO: Solve this issue at its root and remove this workaround | ||
685 | 61 | int const num_frames_for_session_ready{2}; | ||
686 | 62 | int num_frames_posted{0}; | ||
687 | 63 | }; | ||
688 | 64 | |||
689 | 65 | } | ||
690 | 66 | |||
691 | 67 | usc::SurfaceCoordinator::SurfaceCoordinator( | ||
692 | 68 | std::shared_ptr<ms::SurfaceCoordinator> const& wrapped, | ||
693 | 69 | std::shared_ptr<SessionSwitcher> const& session_switcher) | ||
694 | 70 | : msh::SurfaceCoordinatorWrapper{wrapped}, | ||
695 | 71 | session_switcher{session_switcher} | ||
696 | 72 | { | ||
697 | 73 | } | ||
698 | 74 | |||
699 | 75 | std::shared_ptr<ms::Surface> usc::SurfaceCoordinator::add_surface( | ||
700 | 76 | ms::SurfaceCreationParameters const& params, | ||
701 | 77 | ms::Session* session) | ||
702 | 78 | { | ||
703 | 79 | auto const surface = msh::SurfaceCoordinatorWrapper::add_surface(params, session); | ||
704 | 80 | |||
705 | 81 | auto const session_ready_observer = std::make_shared<SessionReadyObserver>( | ||
706 | 82 | session_switcher, surface, session); | ||
707 | 83 | |||
708 | 84 | surface->add_observer(session_ready_observer); | ||
709 | 85 | |||
710 | 86 | return surface; | ||
711 | 87 | } | ||
712 | 88 | 0 | ||
713 | === removed file 'src/surface_coordinator.h' | |||
714 | --- src/surface_coordinator.h 2014-07-09 06:58:05 +0000 | |||
715 | +++ src/surface_coordinator.h 1970-01-01 00:00:00 +0000 | |||
716 | @@ -1,47 +0,0 @@ | |||
717 | 1 | /* | ||
718 | 2 | * Copyright © 2014 Canonical Ltd. | ||
719 | 3 | * | ||
720 | 4 | * This program is free software: you can redistribute it and/or modify | ||
721 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
722 | 6 | * published by the Free Software Foundation. | ||
723 | 7 | * | ||
724 | 8 | * This program is distributed in the hope that it will be useful, | ||
725 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
726 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
727 | 11 | * GNU General Public License for more details. | ||
728 | 12 | * | ||
729 | 13 | * You should have received a copy of the GNU General Public License | ||
730 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
731 | 15 | * | ||
732 | 16 | * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com> | ||
733 | 17 | */ | ||
734 | 18 | |||
735 | 19 | #ifndef USC_SURFACE_COORDINATOR_H_ | ||
736 | 20 | #define USC_SURFACE_COORDINATOR_H_ | ||
737 | 21 | |||
738 | 22 | #include <mir/shell/surface_coordinator_wrapper.h> | ||
739 | 23 | |||
740 | 24 | #include <memory> | ||
741 | 25 | |||
742 | 26 | namespace usc | ||
743 | 27 | { | ||
744 | 28 | class SessionSwitcher; | ||
745 | 29 | |||
746 | 30 | class SurfaceCoordinator : public mir::shell::SurfaceCoordinatorWrapper | ||
747 | 31 | { | ||
748 | 32 | public: | ||
749 | 33 | SurfaceCoordinator( | ||
750 | 34 | std::shared_ptr<mir::scene::SurfaceCoordinator> const& wrapped, | ||
751 | 35 | std::shared_ptr<SessionSwitcher> const& session_switcher); | ||
752 | 36 | |||
753 | 37 | private: | ||
754 | 38 | std::shared_ptr<mir::scene::Surface> add_surface( | ||
755 | 39 | mir::scene::SurfaceCreationParameters const& params, | ||
756 | 40 | mir::scene::Session* session) override; | ||
757 | 41 | |||
758 | 42 | std::shared_ptr<SessionSwitcher> const session_switcher; | ||
759 | 43 | }; | ||
760 | 44 | |||
761 | 45 | } | ||
762 | 46 | |||
763 | 47 | #endif | ||
764 | 48 | 0 | ||
765 | === modified file 'src/system_compositor.cpp' | |||
766 | --- src/system_compositor.cpp 2015-01-05 22:38:04 +0000 | |||
767 | +++ src/system_compositor.cpp 2015-02-06 12:38:32 +0000 | |||
768 | @@ -24,6 +24,7 @@ | |||
769 | 24 | #include "spinner.h" | 24 | #include "spinner.h" |
770 | 25 | #include "screen_state_handler.h" | 25 | #include "screen_state_handler.h" |
771 | 26 | #include "powerkey_handler.h" | 26 | #include "powerkey_handler.h" |
772 | 27 | #include "cursor_enabler.h" | ||
773 | 27 | 28 | ||
774 | 28 | // Qt headers will introduce a #define of "signals" | 29 | // Qt headers will introduce a #define of "signals" |
775 | 29 | // but some mir headers use "signals" as a variable name in | 30 | // but some mir headers use "signals" as a variable name in |
776 | @@ -152,6 +153,7 @@ | |||
777 | 152 | std::chrono::seconds inactivity_display_dim_timeout{server->inactivity_display_dim_timeout()}; | 153 | std::chrono::seconds inactivity_display_dim_timeout{server->inactivity_display_dim_timeout()}; |
778 | 153 | std::chrono::milliseconds power_key_ignore_timeout{server->power_key_ignore_timeout()}; | 154 | std::chrono::milliseconds power_key_ignore_timeout{server->power_key_ignore_timeout()}; |
779 | 154 | std::chrono::milliseconds shutdown_timeout{server->shutdown_timeout()}; | 155 | std::chrono::milliseconds shutdown_timeout{server->shutdown_timeout()}; |
780 | 156 | std::chrono::milliseconds remove_pointer_timeout{server->remove_pointer_timeout()}; | ||
781 | 155 | 157 | ||
782 | 156 | screen_state_handler = std::make_shared<ScreenStateHandler>(server, | 158 | screen_state_handler = std::make_shared<ScreenStateHandler>(server, |
783 | 157 | std::chrono::duration_cast<std::chrono::milliseconds>(inactivity_display_off_timeout), | 159 | std::chrono::duration_cast<std::chrono::milliseconds>(inactivity_display_off_timeout), |
784 | @@ -162,9 +164,15 @@ | |||
785 | 162 | shutdown_timeout, | 164 | shutdown_timeout, |
786 | 163 | *screen_state_handler); | 165 | *screen_state_handler); |
787 | 164 | 166 | ||
788 | 167 | cursor_image_enabler = std::make_shared<CursorEnabler>( | ||
789 | 168 | server->the_cursor(), | ||
790 | 169 | remove_pointer_timeout); | ||
791 | 170 | |||
792 | 165 | auto composite_filter = server->the_composite_event_filter(); | 171 | auto composite_filter = server->the_composite_event_filter(); |
793 | 166 | composite_filter->append(screen_state_handler); | 172 | composite_filter->append(screen_state_handler); |
794 | 167 | composite_filter->append(power_key_handler); | 173 | composite_filter->append(power_key_handler); |
795 | 174 | if (server->enable_hardware_cursor()) | ||
796 | 175 | composite_filter->append(cursor_image_enabler); | ||
797 | 168 | } | 176 | } |
798 | 169 | 177 | ||
799 | 170 | app.exec(); | 178 | app.exec(); |
800 | 171 | 179 | ||
801 | === modified file 'src/system_compositor.h' | |||
802 | --- src/system_compositor.h 2014-11-28 13:19:29 +0000 | |||
803 | +++ src/system_compositor.h 2015-02-06 12:38:32 +0000 | |||
804 | @@ -24,6 +24,7 @@ | |||
805 | 24 | 24 | ||
806 | 25 | class ScreenStateHandler; | 25 | class ScreenStateHandler; |
807 | 26 | class PowerKeyHandler; | 26 | class PowerKeyHandler; |
808 | 27 | class CursorEnabler; | ||
809 | 27 | 28 | ||
810 | 28 | namespace usc | 29 | namespace usc |
811 | 29 | { | 30 | { |
812 | @@ -46,6 +47,7 @@ | |||
813 | 46 | std::shared_ptr<Spinner> const spinner; | 47 | std::shared_ptr<Spinner> const spinner; |
814 | 47 | std::shared_ptr<ScreenStateHandler> screen_state_handler; | 48 | std::shared_ptr<ScreenStateHandler> screen_state_handler; |
815 | 48 | std::shared_ptr<PowerKeyHandler> power_key_handler; | 49 | std::shared_ptr<PowerKeyHandler> power_key_handler; |
816 | 50 | std::shared_ptr<CursorEnabler> cursor_image_enabler; | ||
817 | 49 | }; | 51 | }; |
818 | 50 | 52 | ||
819 | 51 | } | 53 | } |
820 | 52 | 54 | ||
821 | === modified file 'tests/unit-tests/CMakeLists.txt' | |||
822 | --- tests/unit-tests/CMakeLists.txt 2014-07-09 06:58:05 +0000 | |||
823 | +++ tests/unit-tests/CMakeLists.txt 2015-02-06 12:38:32 +0000 | |||
824 | @@ -23,6 +23,7 @@ | |||
825 | 23 | usc_unit_tests | 23 | usc_unit_tests |
826 | 24 | 24 | ||
827 | 25 | test_session_switcher.cpp | 25 | test_session_switcher.cpp |
828 | 26 | test_cursor_enabler.cpp | ||
829 | 26 | ) | 27 | ) |
830 | 27 | 28 | ||
831 | 28 | target_link_libraries( | 29 | target_link_libraries( |
832 | 29 | 30 | ||
833 | === added file 'tests/unit-tests/test_cursor_enabler.cpp' | |||
834 | --- tests/unit-tests/test_cursor_enabler.cpp 1970-01-01 00:00:00 +0000 | |||
835 | +++ tests/unit-tests/test_cursor_enabler.cpp 2015-02-06 12:38:32 +0000 | |||
836 | @@ -0,0 +1,110 @@ | |||
837 | 1 | /* | ||
838 | 2 | * Copyright © 2015 Canonical Ltd. | ||
839 | 3 | * | ||
840 | 4 | * This program is free software: you can redistribute it and/or modify | ||
841 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
842 | 6 | * published by the Free Software Foundation. | ||
843 | 7 | * | ||
844 | 8 | * This program is distributed in the hope that it will be useful, | ||
845 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
846 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
847 | 11 | * GNU General Public License for more details. | ||
848 | 12 | * | ||
849 | 13 | * You should have received a copy of the GNU General Public License | ||
850 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
851 | 15 | * | ||
852 | 16 | * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> | ||
853 | 17 | */ | ||
854 | 18 | |||
855 | 19 | #define MIR_INCLUDE_DEPRECATED_EVENT_HEADER | ||
856 | 20 | |||
857 | 21 | #include "src/cursor_enabler.h" | ||
858 | 22 | |||
859 | 23 | #include "mir_toolkit/event.h" | ||
860 | 24 | #include "mir/graphics/cursor.h" | ||
861 | 25 | #include "mir/graphics/cursor_image.h" | ||
862 | 26 | |||
863 | 27 | #include <gtest/gtest.h> | ||
864 | 28 | #include <gmock/gmock.h> | ||
865 | 29 | |||
866 | 30 | #include <memory> | ||
867 | 31 | #include <vector> | ||
868 | 32 | #include <tuple> | ||
869 | 33 | #include <cstring> | ||
870 | 34 | |||
871 | 35 | namespace | ||
872 | 36 | { | ||
873 | 37 | struct MockCursor : mir::graphics::Cursor | ||
874 | 38 | { | ||
875 | 39 | MOCK_METHOD0(show, void()); | ||
876 | 40 | MOCK_METHOD1(show, void(mir::graphics::CursorImage const&)); | ||
877 | 41 | MOCK_METHOD0(hide, void()); | ||
878 | 42 | MOCK_METHOD1(move_to, void(mir::geometry::Point)); | ||
879 | 43 | MOCK_METHOD2(override_orientation, void(uint32_t, MirOrientation)); | ||
880 | 44 | }; | ||
881 | 45 | |||
882 | 46 | struct TestCursorEnabler : ::testing::Test | ||
883 | 47 | { | ||
884 | 48 | std::shared_ptr<::testing::NiceMock<MockCursor>> mock_cursor = std::make_shared<::testing::NiceMock<MockCursor>>(); | ||
885 | 49 | std::chrono::milliseconds never_remove_pointer{0}; | ||
886 | 50 | std::chrono::milliseconds remove_after_five_seconds_of_non_pointing_events{5000}; | ||
887 | 51 | |||
888 | 52 | MirEvent mouse_event; | ||
889 | 53 | MirEvent touch_event; | ||
890 | 54 | MirEvent key_event; | ||
891 | 55 | TestCursorEnabler() | ||
892 | 56 | { | ||
893 | 57 | std::memset(&mouse_event, 0, sizeof mouse_event); | ||
894 | 58 | std::memset(&touch_event, 0, sizeof touch_event); | ||
895 | 59 | std::memset(&key_event, 0, sizeof key_event); | ||
896 | 60 | |||
897 | 61 | mouse_event.type = mir_event_type_motion; | ||
898 | 62 | mouse_event.motion.source_id = 0x02002; // android constant for mouse | pointer | ||
899 | 63 | mouse_event.motion.pointer_count = 1; | ||
900 | 64 | mouse_event.motion.event_time = 0; | ||
901 | 65 | mouse_event.motion.pointer_coordinates[0].tool_type = mir_motion_tool_type_mouse; | ||
902 | 66 | |||
903 | 67 | touch_event.type = mir_event_type_motion; | ||
904 | 68 | touch_event.motion.source_id = 0x01002; // android constant for touchscreen | pointer | ||
905 | 69 | touch_event.motion.pointer_count = 1; | ||
906 | 70 | touch_event.motion.event_time = 6000; | ||
907 | 71 | touch_event.motion.pointer_coordinates[0].tool_type = mir_motion_tool_type_finger; | ||
908 | 72 | |||
909 | 73 | key_event.type = mir_event_type_key; | ||
910 | 74 | key_event.key.source_id = 0x0101; // android constant for keyboard | button | ||
911 | 75 | key_event.key.event_time = 6000; | ||
912 | 76 | } | ||
913 | 77 | }; | ||
914 | 78 | } | ||
915 | 79 | |||
916 | 80 | TEST_F(TestCursorEnabler, diables_cursor_on_start) | ||
917 | 81 | { | ||
918 | 82 | using namespace testing; | ||
919 | 83 | EXPECT_CALL(*mock_cursor, hide()); | ||
920 | 84 | |||
921 | 85 | CursorEnabler enabler(mock_cursor, never_remove_pointer); | ||
922 | 86 | } | ||
923 | 87 | |||
924 | 88 | TEST_F(TestCursorEnabler, enable_cursor_on_mouse_event) | ||
925 | 89 | { | ||
926 | 90 | using namespace testing; | ||
927 | 91 | EXPECT_CALL(*mock_cursor, hide()); | ||
928 | 92 | EXPECT_CALL(*mock_cursor, show()); | ||
929 | 93 | |||
930 | 94 | CursorEnabler enabler(mock_cursor, never_remove_pointer); | ||
931 | 95 | enabler.handle(mouse_event); | ||
932 | 96 | } | ||
933 | 97 | |||
934 | 98 | TEST_F(TestCursorEnabler, disable_cursor_on_touch_event) | ||
935 | 99 | { | ||
936 | 100 | using namespace testing; | ||
937 | 101 | InSequence seq; | ||
938 | 102 | EXPECT_CALL(*mock_cursor, hide()); | ||
939 | 103 | EXPECT_CALL(*mock_cursor, show()); | ||
940 | 104 | EXPECT_CALL(*mock_cursor, hide()); | ||
941 | 105 | |||
942 | 106 | CursorEnabler enabler(mock_cursor, remove_after_five_seconds_of_non_pointing_events); | ||
943 | 107 | enabler.handle(mouse_event); | ||
944 | 108 | enabler.handle(touch_event); | ||
945 | 109 | } | ||
946 | 110 | |||
947 | 0 | 111 | ||
948 | === modified file 'tests/unit-tests/test_session_switcher.cpp' | |||
949 | --- tests/unit-tests/test_session_switcher.cpp 2014-08-01 21:58:43 +0000 | |||
950 | +++ tests/unit-tests/test_session_switcher.cpp 2015-02-06 12:38:32 +0000 | |||
951 | @@ -1,5 +1,5 @@ | |||
952 | 1 | /* | 1 | /* |
954 | 2 | * Copyright © 2014 Canonical Ltd. | 2 | * Copyright © 2014-2015 Canonical Ltd. |
955 | 3 | * | 3 | * |
956 | 4 | * This program is free software: you can redistribute it and/or modify | 4 | * This program is free software: you can redistribute it and/or modify |
957 | 5 | * it under the terms of the GNU General Public License version 3 as | 5 | * it under the terms of the GNU General Public License version 3 as |
958 | @@ -96,13 +96,9 @@ | |||
959 | 96 | : name_{name} | 96 | : name_{name} |
960 | 97 | {} | 97 | {} |
961 | 98 | 98 | ||
962 | 99 | mir::frontend::SurfaceId create_surface(mir::scene::SurfaceCreationParameters const&) override { return mir::frontend::SurfaceId{0}; } | ||
963 | 100 | void destroy_surface(mir::frontend::SurfaceId) override {} | ||
964 | 101 | std::shared_ptr<mir::frontend::Surface> get_surface(mir::frontend::SurfaceId surface) const override { return nullptr; } | 99 | std::shared_ptr<mir::frontend::Surface> get_surface(mir::frontend::SurfaceId surface) const override { return nullptr; } |
965 | 102 | 100 | ||
966 | 103 | std::string name() const override { return name_; } | 101 | std::string name() const override { return name_; } |
967 | 104 | void hide() override {} | ||
968 | 105 | void show() override {} | ||
969 | 106 | 102 | ||
970 | 107 | private: | 103 | private: |
971 | 108 | std::string const name_; | 104 | std::string const name_; |