2
* Copyright © 2012 Canonical Ltd.
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.
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.
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/>.
16
* Authored By: Robert Carr <robert.carr@canonical.com>
19
#include "mir/frontend/registration_order_focus_selection_strategy.h"
20
#include "mir/frontend/application_session.h"
21
#include "mir/frontend/application_session_container.h"
28
namespace mf = mir::frontend;
30
mf::RegistrationOrderFocusSelectionStrategy::RegistrationOrderFocusSelectionStrategy(std::shared_ptr<mf::ApplicationSessionContainer> const& app_container) :
31
app_container(app_container)
36
std::weak_ptr<mf::ApplicationSession> mf::RegistrationOrderFocusSelectionStrategy::next_focus_app(std::shared_ptr<mf::ApplicationSession> const& focused_app)
38
auto it = app_container->iterator();
40
if (focused_app == NULL)
47
while (it->is_valid())
49
auto stacked_app = **it;
51
if (found) return stacked_app;
53
if (stacked_app == focused_app)
60
// This is programmer error if not found...
61
// later we can make this use LockingIterators?
67
std::weak_ptr<mf::ApplicationSession> mf::RegistrationOrderFocusSelectionStrategy::previous_focus_app(std::shared_ptr<mf::ApplicationSession> const& focused_app)
69
auto it = app_container->iterator();
71
if (focused_app == NULL)
76
std::weak_ptr<mf::ApplicationSession> last_app = **it;
79
while (it->is_valid())
81
auto stacked_app = **it;
83
if (stacked_app == focused_app)
87
last_app = stacked_app;
90
// If we didn't focus_app it was the first app so we happily return the last app