Merge lp:~andreas-pokorny/unity-system-compositor/override-orientation-dbus-api into lp:unity-system-compositor

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
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
=== modified file 'debian/control'
--- debian/control 2015-01-07 23:33:32 +0000
+++ debian/control 2015-02-06 12:38:32 +0000
@@ -19,7 +19,7 @@
19 libglib2.0-dev,19 libglib2.0-dev,
20 libgles2-mesa-dev,20 libgles2-mesa-dev,
21 libmirclient-dev (>= 0.6.0),21 libmirclient-dev (>= 0.6.0),
22 libmirserver-dev (>= 0.10.0),22 libmirserver-dev (>= 0.11.0),
23 libprotobuf-dev,23 libprotobuf-dev,
24 pkg-config,24 pkg-config,
25 python:any (>= 2.7),25 python:any (>= 2.7),
2626
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-11-06 12:18:08 +0000
+++ src/CMakeLists.txt 2015-02-06 12:38:32 +0000
@@ -16,15 +16,15 @@
1616
17set(USC_SRCS17set(USC_SRCS
18 asio_dm_connection.cpp18 asio_dm_connection.cpp
19 cursor_enabler.cpp
19 dbus_screen.cpp20 dbus_screen.cpp
20 external_spinner.cpp21 external_spinner.cpp
21 powerd_mediator.cpp22 powerd_mediator.cpp
22 powerkey_handler.cpp23 powerkey_handler.cpp
23 screen_state_handler.cpp24 screen_state_handler.cpp
24 server.cpp25 server.cpp
25 session_coordinator.cpp26 shell.cpp
26 session_switcher.cpp27 session_switcher.cpp
27 surface_coordinator.cpp
28 system_compositor.cpp28 system_compositor.cpp
29 worker_thread.cpp29 worker_thread.cpp
30)30)
3131
=== added file 'src/cursor_enabler.cpp'
--- src/cursor_enabler.cpp 1970-01-01 00:00:00 +0000
+++ src/cursor_enabler.cpp 2015-02-06 12:38:32 +0000
@@ -0,0 +1,72 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "cursor_enabler.h"
18
19#include "mir/graphics/cursor.h"
20#include "mir_toolkit/event.h"
21
22namespace mi = mir::input;
23
24CursorEnabler::CursorEnabler(
25 std::shared_ptr<mir::graphics::Cursor> const& cursor,
26 std::chrono::milliseconds remove_pointer_timeout)
27 : cursor_shown(false), remove_delay{static_cast<uint32_t>(remove_pointer_timeout.count())}, last_cursor_movement(0),
28 cursor(cursor)
29{
30 cursor->hide();
31}
32
33CursorEnabler::~CursorEnabler() = default;
34
35bool CursorEnabler::handle(MirEvent const& event)
36{
37 if (mir_event_get_type(&event) != mir_event_type_input)
38 {
39 return false;
40 }
41 auto const* ev = mir_event_get_input_event(&event);
42 if (mir_input_event_type_pointer == mir_input_event_get_type(ev))
43 {
44 enable_cursor();
45 last_cursor_movement = event.motion.event_time;
46 }
47 else if (remove_delay &&
48 mir_input_event_type_touch == mir_input_event_get_type(ev) &&
49 (event.motion.event_time - last_cursor_movement > remove_delay))
50 {
51 disable_cursor();
52 }
53 return false;
54}
55
56void CursorEnabler::enable_cursor()
57{
58 if (!cursor_shown)
59 {
60 cursor->show();
61 cursor_shown = true;
62 }
63}
64
65void CursorEnabler::disable_cursor()
66{
67 if (cursor_shown)
68 {
69 cursor->hide();
70 cursor_shown = false;
71 }
72}
073
=== added file 'src/cursor_enabler.h'
--- src/cursor_enabler.h 1970-01-01 00:00:00 +0000
+++ src/cursor_enabler.h 2015-02-06 12:38:32 +0000
@@ -0,0 +1,58 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef USC_CURSOR_IMAGE_ENABLER_H_
18#define USC_CURSOR_IMAGE_ENABLER_H_
19
20#include "mir/input/event_filter.h"
21
22#include <memory>
23#include <chrono>
24
25namespace mir
26{
27namespace graphics
28{
29class Cursor;
30class CursorImage;
31}
32}
33
34/*
35 * Disables the cursor on construction and waits for the first mir pointer/cursor
36 * event to come by for enabling the cursor again.
37 */
38class CursorEnabler : public mir::input::EventFilter
39{
40public:
41 CursorEnabler(std::shared_ptr<mir::graphics::Cursor> const& cursor,
42 std::chrono::milliseconds remove_pointer_timeout);
43
44 ~CursorEnabler();
45
46 bool handle(MirEvent const& event) override;
47
48private:
49 void enable_cursor();
50 void disable_cursor();
51
52 bool cursor_shown;
53 uint32_t remove_delay;
54 uint32_t last_cursor_movement;
55 std::shared_ptr<mir::graphics::Cursor> const cursor;
56};
57
58#endif
059
=== modified file 'src/dbus_screen.cpp'
--- src/dbus_screen.cpp 2014-10-10 22:43:34 +0000
+++ src/dbus_screen.cpp 2015-02-06 12:38:32 +0000
@@ -20,6 +20,9 @@
20#include "power_state_change_reason.h"20#include "power_state_change_reason.h"
21#include "worker_thread.h"21#include "worker_thread.h"
2222
23#include "mir/input/input_region.h"
24#include "mir/graphics/cursor.h"
25
23#include <atomic>26#include <atomic>
24#include <memory>27#include <memory>
25#include <thread>28#include <thread>
@@ -53,12 +56,17 @@
53}56}
5457
5558
56DBusScreen::DBusScreen(DBusScreenObserver& observer, QObject *parent)59DBusScreen::DBusScreen(DBusScreenObserver& observer,
60 std::shared_ptr<mir::input::InputRegion> const& region,
61 std::shared_ptr<mir::graphics::Cursor> const& cursor,
62 QObject *parent)
57 : QObject(parent),63 : QObject(parent),
58 dbus_adaptor{new DBusScreenAdaptor(this)},64 dbus_adaptor{new DBusScreenAdaptor(this)},
59 service_watcher{new QDBusServiceWatcher()},65 service_watcher{new QDBusServiceWatcher()},
60 observer{&observer},66 observer{&observer},
61 worker_thread{new usc::WorkerThread("USC/DBusHandler")}67 worker_thread{new usc::WorkerThread("USC/DBusHandler")},
68 region(region),
69 cursor(cursor)
62{70{
63 QDBusConnection bus = QDBusConnection::systemBus();71 QDBusConnection bus = QDBusConnection::systemBus();
64 bus.registerObject("/com/canonical/Unity/Screen", this);72 bus.registerObject("/com/canonical/Unity/Screen", this);
@@ -211,3 +219,9 @@
211{219{
212 observer->set_touch_visualization_enabled(enabled);220 observer->set_touch_visualization_enabled(enabled);
213}221}
222
223void DBusScreen::overrideOrientation(unsigned int index, int orientation)
224{
225 region->override_orientation(index, static_cast<MirOrientation>(orientation));
226 cursor->override_orientation(index, static_cast<MirOrientation>(orientation));
227}
214228
=== modified file 'src/dbus_screen.h'
--- src/dbus_screen.h 2014-09-22 17:19:52 +0000
+++ src/dbus_screen.h 2015-02-06 12:38:32 +0000
@@ -30,6 +30,8 @@
3030
31namespace usc {class WorkerThread;}31namespace usc {class WorkerThread;}
3232
33namespace mir { namespace graphics { class Cursor; } namespace input { class InputRegion; } }
34
33class DBusScreenAdaptor;35class DBusScreenAdaptor;
34class DBusScreenObserver;36class DBusScreenObserver;
35class QDBusInterface;37class QDBusInterface;
@@ -42,7 +44,7 @@
42 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Screen")44 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Screen")
4345
44public:46public:
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);
46 virtual ~DBusScreen();48 virtual ~DBusScreen();
4749
48 void emit_power_state_change(MirPowerMode mode, PowerStateChangeReason reason);50 void emit_power_state_change(MirPowerMode mode, PowerStateChangeReason reason);
@@ -59,6 +61,7 @@
59 void setInactivityTimeouts(int poweroff_timeout, int dimmer_timeout);61 void setInactivityTimeouts(int poweroff_timeout, int dimmer_timeout);
60 62
61 void setTouchVisualizationEnabled(bool enabled);63 void setTouchVisualizationEnabled(bool enabled);
64 void overrideOrientation(unsigned int index, int orientation);
6265
63private Q_SLOTS:66private Q_SLOTS:
64 void remove_display_on_requestor(QString const& requestor);67 void remove_display_on_requestor(QString const& requestor);
@@ -72,6 +75,8 @@
72 std::unordered_map<std::string, std::unordered_set<int>> display_requests;75 std::unordered_map<std::string, std::unordered_set<int>> display_requests;
73 DBusScreenObserver* const observer;76 DBusScreenObserver* const observer;
74 std::unique_ptr<usc::WorkerThread> worker_thread;77 std::unique_ptr<usc::WorkerThread> worker_thread;
78 std::shared_ptr<mir::input::InputRegion> const region;
79 std::shared_ptr<mir::graphics::Cursor> const cursor;
75};80};
7681
77#endif /* DBUS_SCREEN_H_ */82#endif /* DBUS_SCREEN_H_ */
7883
=== modified file 'src/powerkey_handler.cpp'
--- src/powerkey_handler.cpp 2014-07-21 21:33:35 +0000
+++ src/powerkey_handler.cpp 2015-02-06 12:38:32 +0000
@@ -44,15 +44,22 @@
44bool PowerKeyHandler::handle(MirEvent const& event)44bool PowerKeyHandler::handle(MirEvent const& event)
45{45{
46 static const int32_t POWER_KEY_CODE = 26;46 static const int32_t POWER_KEY_CODE = 26;
4747
48 if (event.type == mir_event_type_key &&48 if (mir_event_get_type(&event) != mir_event_type_input)
49 event.key.key_code == POWER_KEY_CODE)49 return false;
50 {50 auto input_event = mir_event_get_input_event(&event);
51 if (event.key.action == mir_key_action_down)51 if (mir_input_event_get_type(input_event) != mir_input_event_type_key)
52 power_key_down();52 return false;
53 else if (event.key.action == mir_key_action_up)53 auto kev = mir_input_event_get_key_input_event(input_event);
54 power_key_up();54 if (mir_key_input_event_get_key_code(kev) != POWER_KEY_CODE)
55 }55 return false;
56
57 auto action = mir_key_input_event_get_action(kev);
58 if (action == mir_key_input_event_action_down)
59 power_key_down();
60 else if (action == mir_key_input_event_action_up)
61 power_key_up();
62
56 return false;63 return false;
57}64}
5865
5966
=== modified file 'src/screen_state_handler.cpp'
--- src/screen_state_handler.cpp 2015-01-26 22:59:20 +0000
+++ src/screen_state_handler.cpp 2015-02-06 12:38:32 +0000
@@ -47,7 +47,7 @@
47 std::bind(&ScreenStateHandler::power_off_alarm_notification, this))},47 std::bind(&ScreenStateHandler::power_off_alarm_notification, this))},
48 dimmer_alarm{server->the_main_loop()->create_alarm(48 dimmer_alarm{server->the_main_loop()->create_alarm(
49 std::bind(&ScreenStateHandler::dimmer_alarm_notification, this))},49 std::bind(&ScreenStateHandler::dimmer_alarm_notification, this))},
50 dbus_screen{new DBusScreen(*this)}50 dbus_screen{new DBusScreen(*this, server->the_input_region(), server->the_cursor())}
51{51{
52 /*52 /*
53 * Make sure the compositor is running as certain conditions can53 * Make sure the compositor is running as certain conditions can
@@ -62,13 +62,22 @@
6262
63bool ScreenStateHandler::handle(MirEvent const& event)63bool ScreenStateHandler::handle(MirEvent const& event)
64{64{
65 if (event.type == mir_event_type_motion)65 if (mir_event_get_type(&event) != mir_event_type_input)
66 {66 return false;
67 std::lock_guard<std::mutex> lock{guard};67
68 reset_timers_l();68 auto input_event_type = mir_input_event_get_type(mir_event_get_input_event(&event));
69 if (current_power_mode == MirPowerMode::mir_power_mode_on)69 // TODO: We should consider resetting the timer for key events too
70 powerd_mediator->set_normal_backlight();70 // we have to make sure we wont introduce a bug where pressing the power
71 }71 // key (to turn screen off) or just the volume keys will wake the screen though!
72 if (!(input_event_type == mir_input_event_type_touch
73 || input_event_type == mir_input_event_type_pointer))
74 return false;
75
76 std::lock_guard<std::mutex> lock{guard};
77 reset_timers_l();
78 if (current_power_mode == MirPowerMode::mir_power_mode_on)
79 powerd_mediator->set_normal_backlight();
80
72 return false;81 return false;
73}82}
7483
7584
=== modified file 'src/server.cpp'
--- src/server.cpp 2014-11-28 11:39:04 +0000
+++ src/server.cpp 2015-02-06 12:38:32 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2014 Canonical Ltd.2 * Copyright © 2014-2015 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -18,8 +18,7 @@
1818
19#include "server.h"19#include "server.h"
20#include "external_spinner.h"20#include "external_spinner.h"
21#include "session_coordinator.h"21#include "shell.h"
22#include "surface_coordinator.h"
23#include "asio_dm_connection.h"22#include "asio_dm_connection.h"
24#include "session_switcher.h"23#include "session_switcher.h"
2524
@@ -103,44 +102,23 @@
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);
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);
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);
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);
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);
107107
108 set_command_line(argc, const_cast<char const **>(argv));108 set_command_line(argc, const_cast<char const **>(argv));
109109
110 set_command_line_handler(&ignore_unknown_arguments);110 set_command_line_handler(&ignore_unknown_arguments);
111111
112 wrap_cursor_listener([this](std::shared_ptr<mir::input::CursorListener> const& default_)
113 -> std::shared_ptr<mir::input::CursorListener>
114 {
115 // This is a workaround for u8 desktop preview in 14.04 for the lack of client cursor API.
116 // We need to disable the cursor for XMir but leave it on for the desktop preview.
117 // Luckily as it stands they run inside seperate instances of USC. ~racarr
118 if (enable_hardware_cursor())
119 return default_;
120 else
121 return std::make_shared<NullCursorListener>();
122 });
123
124 override_the_server_status_listener([this]()112 override_the_server_status_listener([this]()
125 -> std::shared_ptr<mir::ServerStatusListener>113 -> std::shared_ptr<mir::ServerStatusListener>
126 {114 {
127 return std::make_shared<ServerStatusListener>(the_focus_controller());115 return std::make_shared<ServerStatusListener>(the_focus_controller());
128 });116 });
129117
130 wrap_session_coordinator([this](std::shared_ptr<ms::SessionCoordinator> const& wrapped)118 wrap_shell([this](std::shared_ptr<msh::Shell> const& wrapped)
131 -> std::shared_ptr<ms::SessionCoordinator>119 -> std::shared_ptr<msh::Shell>
132 {120 {
133 return std::make_shared<SessionCoordinator>(121 return std::make_shared<Shell>(wrapped, the_session_switcher());
134 wrapped,
135 the_session_switcher());
136 });
137
138 wrap_surface_coordinator([this](std::shared_ptr<ms::SurfaceCoordinator> const& wrapped)
139 -> std::shared_ptr<mir::scene::SurfaceCoordinator>
140 {
141 return std::make_shared<SurfaceCoordinator>(
142 wrapped,
143 the_session_switcher());
144 });122 });
145123
146 set_config_filename("unity-system-compositor.conf");124 set_config_filename("unity-system-compositor.conf");
147125
=== modified file 'src/server.h'
--- src/server.h 2014-11-28 11:39:04 +0000
+++ src/server.h 2015-02-06 12:38:32 +0000
@@ -42,6 +42,8 @@
42 using mir::Server::the_display;42 using mir::Server::the_display;
43 using mir::Server::the_compositor;43 using mir::Server::the_compositor;
44 using mir::Server::the_touch_visualizer;44 using mir::Server::the_touch_visualizer;
45 using mir::Server::the_cursor;
46 using mir::Server::the_input_region;
4547
46 virtual std::shared_ptr<Spinner> the_spinner();48 virtual std::shared_ptr<Spinner> the_spinner();
47 virtual std::shared_ptr<DMMessageHandler> the_dm_message_handler();49 virtual std::shared_ptr<DMMessageHandler> the_dm_message_handler();
@@ -72,6 +74,11 @@
72 return the_options()->get("power-key-ignore-timeout", 2000);74 return the_options()->get("power-key-ignore-timeout", 2000);
73 }75 }
7476
77 int remove_pointer_timeout()
78 {
79 return the_options()->get("remove-pointer-timeout", 0);
80 }
81
75 bool enable_hardware_cursor()82 bool enable_hardware_cursor()
76 {83 {
77 return the_options()->get("enable-hardware-cursor", false);84 return the_options()->get("enable-hardware-cursor", false);
7885
=== renamed file 'src/session_coordinator.cpp' => 'src/shell.cpp'
--- src/session_coordinator.cpp 2014-08-01 21:58:43 +0000
+++ src/shell.cpp 2015-02-06 12:38:32 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2014 Canonical Ltd.2 * Copyright © 2014-2015 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -16,10 +16,12 @@
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */17 */
1818
19#include "session_coordinator.h"19#include "shell.h"
20#include "session_switcher.h"20#include "session_switcher.h"
2121
22#include <mir/scene/null_surface_observer.h>
22#include <mir/scene/session.h>23#include <mir/scene/session.h>
24#include <mir/scene/surface.h>
23#include <mir/frontend/session.h>25#include <mir/frontend/session.h>
2426
25#include <iostream>27#include <iostream>
@@ -71,34 +73,59 @@
71 msh::FocusController& focus_controller;73 msh::FocusController& focus_controller;
72};74};
7375
76
77struct SessionReadyObserver : ms::NullSurfaceObserver,
78 std::enable_shared_from_this<SessionReadyObserver>
79{
80 SessionReadyObserver(
81 std::shared_ptr<usc::SessionSwitcher> const& switcher,
82 std::shared_ptr<ms::Surface> const& surface,
83 ms::Session const* session)
84 : switcher{switcher},
85 surface{surface},
86 session{session}
87 {
88 }
89
90 void frame_posted(int) override
91 {
92 ++num_frames_posted;
93 if (num_frames_posted == num_frames_for_session_ready)
94 {
95 switcher->mark_ready(session);
96 surface->remove_observer(shared_from_this());
97 }
98 }
99
100 std::shared_ptr<usc::SessionSwitcher> const switcher;
101 std::shared_ptr<ms::Surface> const surface;
102 ms::Session const* const session;
103 // We need to wait for the second frame before marking the session
104 // as ready. The first frame posted from sessions is a blank frame.
105 // TODO: Solve this issue at its root and remove this workaround
106 int const num_frames_for_session_ready{2};
107 int num_frames_posted{0};
108};
109
74}110}
75111
76usc::SessionCoordinator::SessionCoordinator(112usc::Shell::Shell(
77 std::shared_ptr<ms::SessionCoordinator> const& wrapped,113 std::shared_ptr<msh::Shell> const& wrapped,
78 std::shared_ptr<SessionSwitcher> const& session_switcher)114 std::shared_ptr<SessionSwitcher> const& session_switcher)
79 : msh::SessionCoordinatorWrapper{wrapped},115 : msh::ShellWrapper{wrapped},
80 session_switcher{session_switcher}116 session_switcher{session_switcher}
81{117{
82}118}
83119
84std::shared_ptr<mf::Session>120std::shared_ptr<ms::Session>
85usc::SessionCoordinator::open_session(121usc::Shell::open_session(
86 pid_t client_pid,122 pid_t client_pid,
87 std::string const& name,123 std::string const& name,
88 std::shared_ptr<mf::EventSink> const& sink)124 std::shared_ptr<mf::EventSink> const& sink)
89{125{
90 std::cerr << "Opening session " << name << std::endl;126 std::cerr << "Opening session " << name << std::endl;
91127
92 // We need ms::Session objects because that is what the focus controller128 auto orig = msh::ShellWrapper::open_session(client_pid, name, sink);
93 // works with. But the mf::SessionCoordinator interface deals with mf::Session objects.
94 // So we cast here since in practice, these objects are also ms::Sessions.
95 auto orig = std::dynamic_pointer_cast<ms::Session>(
96 msh::SessionCoordinatorWrapper::open_session(client_pid, name, sink));
97 if (!orig)
98 {
99 std::cerr << "Unexpected non-shell session" << std::endl;
100 return std::shared_ptr<mf::Session>();
101 }
102129
103 auto const usc_session = std::make_shared<UscSession>(orig, *this);130 auto const usc_session = std::make_shared<UscSession>(orig, *this);
104131
@@ -107,12 +134,24 @@
107 return orig;134 return orig;
108}135}
109136
110void usc::SessionCoordinator::close_session(137void usc::Shell::close_session(std::shared_ptr<ms::Session> const& session)
111 std::shared_ptr<mf::Session> const& session)
112{138{
113 std::cerr << "Closing session " << session->name() << std::endl;139 std::cerr << "Closing session " << session->name() << std::endl;
114140
115 msh::SessionCoordinatorWrapper::close_session(session);141 msh::ShellWrapper::close_session(session);
116142
117 session_switcher->remove(session);143 session_switcher->remove(session);
118}144}
145
146mf::SurfaceId usc::Shell::create_surface(std::shared_ptr<ms::Session> const& session, ms::SurfaceCreationParameters const& params)
147{
148 auto const id = msh::ShellWrapper::create_surface(session, params);
149
150 auto const surface = session->surface(id);
151 auto const session_ready_observer = std::make_shared<SessionReadyObserver>(
152 session_switcher, surface, session.get());
153
154 surface->add_observer(session_ready_observer);
155
156 return id;
157}
119158
=== renamed file 'src/session_coordinator.h' => 'src/shell.h'
--- src/session_coordinator.h 2014-07-09 06:58:05 +0000
+++ src/shell.h 2015-02-06 12:38:32 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2014 Canonical Ltd.2 * Copyright © 2014-2015 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -16,35 +16,35 @@
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */17 */
1818
19#ifndef USC_SESSION_COORDINATOR_H_19#ifndef USC_SHELL_H_
20#define USC_SESSION_COORDINATOR_H_20#define USC_SHELL_H_
2121
22#include <mir/shell/session_coordinator_wrapper.h>22#include <mir/shell/shell_wrapper.h>
2323
24#include <memory>24#include <memory>
2525
26namespace mir
27{
28namespace scene { class SurfaceCoordinator; }
29}
3026
31namespace usc27namespace usc
32{28{
33class SessionSwitcher;29class SessionSwitcher;
3430
35class SessionCoordinator : public mir::shell::SessionCoordinatorWrapper31class Shell : public mir::shell::ShellWrapper
36{32{
37public:33public:
38 SessionCoordinator(34 Shell(
39 std::shared_ptr<mir::scene::SessionCoordinator> const& wrapped,35 std::shared_ptr<mir::shell::Shell> const& wrapped,
40 std::shared_ptr<SessionSwitcher> const& session_switcher);36 std::shared_ptr<SessionSwitcher> const& session_switcher);
4137
42private:38private:
43 std::shared_ptr<mir::frontend::Session> open_session(39 std::shared_ptr<mir::scene::Session> open_session(
44 pid_t client_pid,40 pid_t client_pid,
45 std::string const& name,41 std::string const& name,
46 std::shared_ptr<mir::frontend::EventSink> const& sink) override;42 std::shared_ptr<mir::frontend::EventSink> const& sink) override;
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;
44
45 mir::frontend::SurfaceId create_surface(
46 std::shared_ptr<mir::scene::Session> const& session,
47 mir::scene::SurfaceCreationParameters const& params) override;
4848
49 std::shared_ptr<SessionSwitcher> const session_switcher;49 std::shared_ptr<SessionSwitcher> const session_switcher;
50};50};
5151
=== removed file 'src/surface_coordinator.cpp'
--- src/surface_coordinator.cpp 2014-08-01 21:58:43 +0000
+++ src/surface_coordinator.cpp 1970-01-01 00:00:00 +0000
@@ -1,87 +0,0 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#include "surface_coordinator.h"
20#include "session_switcher.h"
21
22#include <mir/scene/null_surface_observer.h>
23#include <mir/scene/surface.h>
24#include <mir/scene/session.h>
25
26namespace ms = mir::scene;
27namespace msh = mir::shell;
28
29namespace
30{
31
32struct SessionReadyObserver : ms::NullSurfaceObserver,
33 std::enable_shared_from_this<SessionReadyObserver>
34{
35 SessionReadyObserver(
36 std::shared_ptr<usc::SessionSwitcher> const& switcher,
37 std::shared_ptr<ms::Surface> const& surface,
38 ms::Session const* session)
39 : switcher{switcher},
40 surface{surface},
41 session{session}
42 {
43 }
44
45 void frame_posted(int) override
46 {
47 ++num_frames_posted;
48 if (num_frames_posted == num_frames_for_session_ready)
49 {
50 switcher->mark_ready(session);
51 surface->remove_observer(shared_from_this());
52 }
53 }
54
55 std::shared_ptr<usc::SessionSwitcher> const switcher;
56 std::shared_ptr<ms::Surface> const surface;
57 ms::Session const* const session;
58 // We need to wait for the second frame before marking the session
59 // as ready. The first frame posted from sessions is a blank frame.
60 // TODO: Solve this issue at its root and remove this workaround
61 int const num_frames_for_session_ready{2};
62 int num_frames_posted{0};
63};
64
65}
66
67usc::SurfaceCoordinator::SurfaceCoordinator(
68 std::shared_ptr<ms::SurfaceCoordinator> const& wrapped,
69 std::shared_ptr<SessionSwitcher> const& session_switcher)
70 : msh::SurfaceCoordinatorWrapper{wrapped},
71 session_switcher{session_switcher}
72{
73}
74
75std::shared_ptr<ms::Surface> usc::SurfaceCoordinator::add_surface(
76 ms::SurfaceCreationParameters const& params,
77 ms::Session* session)
78{
79 auto const surface = msh::SurfaceCoordinatorWrapper::add_surface(params, session);
80
81 auto const session_ready_observer = std::make_shared<SessionReadyObserver>(
82 session_switcher, surface, session);
83
84 surface->add_observer(session_ready_observer);
85
86 return surface;
87}
880
=== removed file 'src/surface_coordinator.h'
--- src/surface_coordinator.h 2014-07-09 06:58:05 +0000
+++ src/surface_coordinator.h 1970-01-01 00:00:00 +0000
@@ -1,47 +0,0 @@
1/*
2 * Copyright © 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
17 */
18
19#ifndef USC_SURFACE_COORDINATOR_H_
20#define USC_SURFACE_COORDINATOR_H_
21
22#include <mir/shell/surface_coordinator_wrapper.h>
23
24#include <memory>
25
26namespace usc
27{
28class SessionSwitcher;
29
30class SurfaceCoordinator : public mir::shell::SurfaceCoordinatorWrapper
31{
32public:
33 SurfaceCoordinator(
34 std::shared_ptr<mir::scene::SurfaceCoordinator> const& wrapped,
35 std::shared_ptr<SessionSwitcher> const& session_switcher);
36
37private:
38 std::shared_ptr<mir::scene::Surface> add_surface(
39 mir::scene::SurfaceCreationParameters const& params,
40 mir::scene::Session* session) override;
41
42 std::shared_ptr<SessionSwitcher> const session_switcher;
43};
44
45}
46
47#endif
480
=== modified file 'src/system_compositor.cpp'
--- src/system_compositor.cpp 2015-01-05 22:38:04 +0000
+++ src/system_compositor.cpp 2015-02-06 12:38:32 +0000
@@ -24,6 +24,7 @@
24#include "spinner.h"24#include "spinner.h"
25#include "screen_state_handler.h"25#include "screen_state_handler.h"
26#include "powerkey_handler.h"26#include "powerkey_handler.h"
27#include "cursor_enabler.h"
2728
28// Qt headers will introduce a #define of "signals"29// Qt headers will introduce a #define of "signals"
29// but some mir headers use "signals" as a variable name in30// but some mir headers use "signals" as a variable name in
@@ -152,6 +153,7 @@
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()};
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()};
154 std::chrono::milliseconds shutdown_timeout{server->shutdown_timeout()};155 std::chrono::milliseconds shutdown_timeout{server->shutdown_timeout()};
156 std::chrono::milliseconds remove_pointer_timeout{server->remove_pointer_timeout()};
155157
156 screen_state_handler = std::make_shared<ScreenStateHandler>(server,158 screen_state_handler = std::make_shared<ScreenStateHandler>(server,
157 std::chrono::duration_cast<std::chrono::milliseconds>(inactivity_display_off_timeout),159 std::chrono::duration_cast<std::chrono::milliseconds>(inactivity_display_off_timeout),
@@ -162,9 +164,15 @@
162 shutdown_timeout,164 shutdown_timeout,
163 *screen_state_handler);165 *screen_state_handler);
164166
167 cursor_image_enabler = std::make_shared<CursorEnabler>(
168 server->the_cursor(),
169 remove_pointer_timeout);
170
165 auto composite_filter = server->the_composite_event_filter();171 auto composite_filter = server->the_composite_event_filter();
166 composite_filter->append(screen_state_handler);172 composite_filter->append(screen_state_handler);
167 composite_filter->append(power_key_handler);173 composite_filter->append(power_key_handler);
174 if (server->enable_hardware_cursor())
175 composite_filter->append(cursor_image_enabler);
168 }176 }
169177
170 app.exec();178 app.exec();
171179
=== modified file 'src/system_compositor.h'
--- src/system_compositor.h 2014-11-28 13:19:29 +0000
+++ src/system_compositor.h 2015-02-06 12:38:32 +0000
@@ -24,6 +24,7 @@
2424
25class ScreenStateHandler;25class ScreenStateHandler;
26class PowerKeyHandler;26class PowerKeyHandler;
27class CursorEnabler;
2728
28namespace usc29namespace usc
29{30{
@@ -46,6 +47,7 @@
46 std::shared_ptr<Spinner> const spinner;47 std::shared_ptr<Spinner> const spinner;
47 std::shared_ptr<ScreenStateHandler> screen_state_handler;48 std::shared_ptr<ScreenStateHandler> screen_state_handler;
48 std::shared_ptr<PowerKeyHandler> power_key_handler;49 std::shared_ptr<PowerKeyHandler> power_key_handler;
50 std::shared_ptr<CursorEnabler> cursor_image_enabler;
49};51};
5052
51}53}
5254
=== modified file 'tests/unit-tests/CMakeLists.txt'
--- tests/unit-tests/CMakeLists.txt 2014-07-09 06:58:05 +0000
+++ tests/unit-tests/CMakeLists.txt 2015-02-06 12:38:32 +0000
@@ -23,6 +23,7 @@
23 usc_unit_tests23 usc_unit_tests
2424
25 test_session_switcher.cpp25 test_session_switcher.cpp
26 test_cursor_enabler.cpp
26)27)
2728
28target_link_libraries(29target_link_libraries(
2930
=== added file 'tests/unit-tests/test_cursor_enabler.cpp'
--- tests/unit-tests/test_cursor_enabler.cpp 1970-01-01 00:00:00 +0000
+++ tests/unit-tests/test_cursor_enabler.cpp 2015-02-06 12:38:32 +0000
@@ -0,0 +1,110 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17 */
18
19#define MIR_INCLUDE_DEPRECATED_EVENT_HEADER
20
21#include "src/cursor_enabler.h"
22
23#include "mir_toolkit/event.h"
24#include "mir/graphics/cursor.h"
25#include "mir/graphics/cursor_image.h"
26
27#include <gtest/gtest.h>
28#include <gmock/gmock.h>
29
30#include <memory>
31#include <vector>
32#include <tuple>
33#include <cstring>
34
35namespace
36{
37struct MockCursor : mir::graphics::Cursor
38{
39 MOCK_METHOD0(show, void());
40 MOCK_METHOD1(show, void(mir::graphics::CursorImage const&));
41 MOCK_METHOD0(hide, void());
42 MOCK_METHOD1(move_to, void(mir::geometry::Point));
43 MOCK_METHOD2(override_orientation, void(uint32_t, MirOrientation));
44};
45
46struct TestCursorEnabler : ::testing::Test
47{
48 std::shared_ptr<::testing::NiceMock<MockCursor>> mock_cursor = std::make_shared<::testing::NiceMock<MockCursor>>();
49 std::chrono::milliseconds never_remove_pointer{0};
50 std::chrono::milliseconds remove_after_five_seconds_of_non_pointing_events{5000};
51
52 MirEvent mouse_event;
53 MirEvent touch_event;
54 MirEvent key_event;
55 TestCursorEnabler()
56 {
57 std::memset(&mouse_event, 0, sizeof mouse_event);
58 std::memset(&touch_event, 0, sizeof touch_event);
59 std::memset(&key_event, 0, sizeof key_event);
60
61 mouse_event.type = mir_event_type_motion;
62 mouse_event.motion.source_id = 0x02002; // android constant for mouse | pointer
63 mouse_event.motion.pointer_count = 1;
64 mouse_event.motion.event_time = 0;
65 mouse_event.motion.pointer_coordinates[0].tool_type = mir_motion_tool_type_mouse;
66
67 touch_event.type = mir_event_type_motion;
68 touch_event.motion.source_id = 0x01002; // android constant for touchscreen | pointer
69 touch_event.motion.pointer_count = 1;
70 touch_event.motion.event_time = 6000;
71 touch_event.motion.pointer_coordinates[0].tool_type = mir_motion_tool_type_finger;
72
73 key_event.type = mir_event_type_key;
74 key_event.key.source_id = 0x0101; // android constant for keyboard | button
75 key_event.key.event_time = 6000;
76 }
77};
78}
79
80TEST_F(TestCursorEnabler, diables_cursor_on_start)
81{
82 using namespace testing;
83 EXPECT_CALL(*mock_cursor, hide());
84
85 CursorEnabler enabler(mock_cursor, never_remove_pointer);
86}
87
88TEST_F(TestCursorEnabler, enable_cursor_on_mouse_event)
89{
90 using namespace testing;
91 EXPECT_CALL(*mock_cursor, hide());
92 EXPECT_CALL(*mock_cursor, show());
93
94 CursorEnabler enabler(mock_cursor, never_remove_pointer);
95 enabler.handle(mouse_event);
96}
97
98TEST_F(TestCursorEnabler, disable_cursor_on_touch_event)
99{
100 using namespace testing;
101 InSequence seq;
102 EXPECT_CALL(*mock_cursor, hide());
103 EXPECT_CALL(*mock_cursor, show());
104 EXPECT_CALL(*mock_cursor, hide());
105
106 CursorEnabler enabler(mock_cursor, remove_after_five_seconds_of_non_pointing_events);
107 enabler.handle(mouse_event);
108 enabler.handle(touch_event);
109}
110
0111
=== modified file 'tests/unit-tests/test_session_switcher.cpp'
--- tests/unit-tests/test_session_switcher.cpp 2014-08-01 21:58:43 +0000
+++ tests/unit-tests/test_session_switcher.cpp 2015-02-06 12:38:32 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright © 2014 Canonical Ltd.2 * Copyright © 2014-2015 Canonical Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as5 * it under the terms of the GNU General Public License version 3 as
@@ -96,13 +96,9 @@
96 : name_{name}96 : name_{name}
97 {}97 {}
9898
99 mir::frontend::SurfaceId create_surface(mir::scene::SurfaceCreationParameters const&) override { return mir::frontend::SurfaceId{0}; }
100 void destroy_surface(mir::frontend::SurfaceId) override {}
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; }
102100
103 std::string name() const override { return name_; }101 std::string name() const override { return name_; }
104 void hide() override {}
105 void show() override {}
106102
107private:103private:
108 std::string const name_;104 std::string const name_;

Subscribers

People subscribed via source and target branches