diff options
Diffstat (limited to 'shutdown')
| -rw-r--r-- | shutdown/SessionButton.cpp | 38 | ||||
| -rw-r--r-- | shutdown/SessionButton.h | 14 | ||||
| -rw-r--r-- | shutdown/SessionController.cpp | 3 | ||||
| -rw-r--r-- | shutdown/SessionView.cpp | 25 | ||||
| -rw-r--r-- | shutdown/SessionView.h | 2 |
5 files changed, 67 insertions, 15 deletions
diff --git a/shutdown/SessionButton.cpp b/shutdown/SessionButton.cpp index ef45506c1..8af0b6ee7 100644 --- a/shutdown/SessionButton.cpp +++ b/shutdown/SessionButton.cpp @@ -22,7 +22,7 @@ #include <Nux/VLayout.h> #include <UnityCore/Variant.h> - +#include <glib/gi18n-lib.h> namespace unity { @@ -38,15 +38,47 @@ namespace style NUX_IMPLEMENT_OBJECT_TYPE(Button); -Button::Button(std::string const& label, std::string const& texture_name, NUX_FILE_LINE_DECL) +Button::Button(Action action, NUX_FILE_LINE_DECL) : nux::View(NUX_FILE_LINE_PARAM) , highlighted(false) + , action([this] { return action_; }) , label([this] { return label_view_->GetText(); }) + , action_(action) { SetAcceptKeyNavFocusOnMouseDown(false); SetAcceptKeyNavFocusOnMouseEnter(true); - std::string texture_prefix = PKGDATADIR"/" + texture_name; + std::string texture_prefix = PKGDATADIR"/"; + std::string label; + + switch (action_) + { + case Action::LOCK: + texture_prefix += "lockscreen"; + label = _("Lock"); + break; + case Action::LOGOUT: + texture_prefix += "logout"; + label = _("Log Out"); + break; + case Action::SUSPEND: + texture_prefix += "suspend"; + label = _("Suspend"); + break; + case Action::HIBERNATE: + texture_prefix += "hibernate"; + label = _("Hibernate"); + break; + case Action::SHUTDOWN: + texture_prefix += "shutdown"; + label = _("Shut Down"); + break; + case Action::REBOOT: + texture_prefix += "restart"; + label = _("Restart"); + break; + } + normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), -1, true)); highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), -1, true)); diff --git a/shutdown/SessionButton.h b/shutdown/SessionButton.h index f9b0ae362..055360048 100644 --- a/shutdown/SessionButton.h +++ b/shutdown/SessionButton.h @@ -37,9 +37,20 @@ class Button : public nux::View, public debug::Introspectable { NUX_DECLARE_OBJECT_TYPE(Button, nux::View); public: - Button(std::string const& label, std::string const& texture_name, NUX_FILE_LINE_PROTO); + enum class Action + { + LOCK, + LOGOUT, + SUSPEND, + HIBERNATE, + SHUTDOWN, + REBOOT + }; + + Button(Action, NUX_FILE_LINE_PROTO); nux::Property<bool> highlighted; + nux::ROProperty<Action> action; nux::ROProperty<std::string> label; sigc::signal<void> activated; @@ -54,6 +65,7 @@ protected: private: friend class TestSessionButton; + Action action_; IconTexture* image_view_; StaticCairoText* label_view_; nux::ObjectPtr<nux::BaseTexture> normal_tex_; diff --git a/shutdown/SessionController.cpp b/shutdown/SessionController.cpp index 0261efaad..d4f7f0bf6 100644 --- a/shutdown/SessionController.cpp +++ b/shutdown/SessionController.cpp @@ -91,6 +91,7 @@ void Controller::Show(View::Mode mode, bool inhibitors) if (Visible() && mode == view_->mode()) return; + ubus_manager_.SendMessage(UBUS_OVERLAY_CLOSE_REQUEST); WindowManager::Default().SaveInputFocus(); if (nux::GetWindowThread()->IsEmbeddedWindow()) @@ -107,7 +108,7 @@ void Controller::Show(View::Mode mode, bool inhibitors) view_window_->ShowWindow(true); view_window_->PushToFront(); view_window_->SetInputFocus(); - nux::GetWindowCompositor().SetKeyFocusArea(view_.GetPointer()); + nux::GetWindowCompositor().SetKeyFocusArea(view_->key_focus_area()); if (fade_animator_.CurrentState() == na::Animation::State::Running) { diff --git a/shutdown/SessionView.cpp b/shutdown/SessionView.cpp index 967f6b16b..a6cafacde 100644 --- a/shutdown/SessionView.cpp +++ b/shutdown/SessionView.cpp @@ -47,7 +47,9 @@ NUX_IMPLEMENT_OBJECT_TYPE(View); View::View(Manager::Ptr const& manager) : mode(Mode::FULL) + , key_focus_area([this] { return key_focus_area_; }) , manager_(manager) + , key_focus_area_(this) { closable = true; auto main_layout = new nux::VLayout(); @@ -170,35 +172,37 @@ void View::Populate() { debug::Introspectable::RemoveAllChildren(); buttons_layout_->Clear(); + key_focus_area_ = this; if (mode() == Mode::LOGOUT) { - auto* button = new Button(_("Lock"), "lockscreen", NUX_TRACKER_LOCATION); + auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen)); AddButton(button); - button = new Button(_("Logout"), "logout", NUX_TRACKER_LOCATION); + button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout)); + key_focus_area_ = button; AddButton(button); } else { if (mode() == Mode::FULL) { - auto* button = new Button(_("Lock"), "lockscreen", NUX_TRACKER_LOCATION); + auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen)); AddButton(button); if (manager_->CanSuspend()) { - button = new Button(_("Suspend"), "suspend", NUX_TRACKER_LOCATION); + button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend)); AddButton(button); } if (manager_->CanHibernate()) { - button = new Button(_("Hibernate"), "hibernate", NUX_TRACKER_LOCATION); + button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate)); AddButton(button); } @@ -206,17 +210,18 @@ void View::Populate() if (manager_->CanShutdown()) { - auto* button = new Button(_("Shutdown"), "shutdown", NUX_TRACKER_LOCATION); - button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown)); + auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION); + button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot)); AddButton(button); - button = new Button(_("Restart"), "restart", NUX_TRACKER_LOCATION); - button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot)); + button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION); + button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown)); + key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_; AddButton(button); } else if (mode() == Mode::FULL) { - auto* button = new Button(_("Logout"), "logout", NUX_TRACKER_LOCATION); + auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout)); AddButton(button); } diff --git a/shutdown/SessionView.h b/shutdown/SessionView.h index 05deb8fa3..b7ec5728f 100644 --- a/shutdown/SessionView.h +++ b/shutdown/SessionView.h @@ -50,6 +50,7 @@ public: nux::Property<Mode> mode; nux::Property<bool> have_inhibitors; + nux::ROProperty<nux::InputArea*> key_focus_area; sigc::signal<void> request_hide; @@ -76,6 +77,7 @@ private: StaticCairoText* title_; StaticCairoText* subtitle_; nux::HLayout* buttons_layout_; + nux::InputArea* key_focus_area_; }; } // namespace session |
