summaryrefslogtreecommitdiff
diff options
authorhandsome_feng <445865575@qq.com>2015-11-23 17:24:10 +0800
committerhandsome_feng <445865575@qq.com>2015-11-23 17:24:10 +0800
commit0ba4ad707833928adc16d697bd9a3fefa40598bf (patch)
tree8202d6b2a6fa575e4d4fbaa0acce2556cc921165
parentd6a56f9b78ef585784c2b72810316ff28635881b (diff)
Modified UserIconFile(), Add DesktopType to UnitySettings,Add some nux::Property in textinput
(bzr r4016.2.26)
-rw-r--r--UnityCore/GnomeSessionManager.cpp48
-rw-r--r--UnityCore/GnomeSessionManager.h2
-rw-r--r--UnityCore/GnomeSessionManagerImpl.h3
-rw-r--r--UnityCore/SessionManager.h3
-rw-r--r--com.canonical.Unity.gschema.xml9
-rw-r--r--lockscreen/KylinLockScreenShield.cpp2
-rw-r--r--lockscreen/KylinLockScreenShield.h5
-rw-r--r--lockscreen/KylinUserPromptView.cpp59
-rw-r--r--lockscreen/KylinUserPromptView.h8
-rw-r--r--lockscreen/LockScreenAbstractPromptView.h2
-rw-r--r--lockscreen/LockScreenAbstractShield.h4
-rw-r--r--lockscreen/LockScreenController.cpp4
-rw-r--r--lockscreen/LockScreenController.h3
-rw-r--r--lockscreen/LockScreenShieldFactory.cpp3
-rw-r--r--lockscreen/UserPromptView.h3
-rw-r--r--shutdown/StandaloneSession.cpp2
-rw-r--r--tests/test_gnome_session_manager.cpp5
-rw-r--r--tests/test_mock_session_manager.h5
-rw-r--r--tests/test_text_input.cpp26
-rw-r--r--unity-shared/TextInput.cpp83
-rw-r--r--unity-shared/TextInput.h10
-rw-r--r--unity-shared/UnitySettings.cpp7
-rw-r--r--unity-shared/UnitySettings.h7
23 files changed, 167 insertions, 136 deletions
diff --git a/UnityCore/GnomeSessionManager.cpp b/UnityCore/GnomeSessionManager.cpp
index 47afdec0a..5a8af8b99 100644
--- a/UnityCore/GnomeSessionManager.cpp
+++ b/UnityCore/GnomeSessionManager.cpp
@@ -155,6 +155,13 @@ GnomeManager::Impl::Impl(GnomeManager* manager, bool test_mode)
});
}
+ {
+ dm_seat_proxy_ = std::make_shared<glib::DBusProxy>("org.freedesktop.Accounts",
+ ("/org/freedesktop/Accounts/User" + std::to_string(getuid())).c_str(),
+ "org.freedesktop.Accounts.User",
+ G_BUS_TYPE_SYSTEM);
+ }
+
CallLogindMethod("CanHibernate", nullptr, [this] (GVariant* variant, glib::Error const& err) {
if (err)
{
@@ -440,7 +447,7 @@ void GnomeManager::Impl::CallDisplayManagerSeatMethod(std::string const& method,
proxy->CallBegin(method, parameters, [this, proxy] (GVariant*, glib::Error const& e) {
if (e)
{
- LOG_ERROR(logger) << "Fallback call failed: " << e.Message();
+ LOG_ERROR(logger) << "DisplayManager Seat call failed: " << e.Message();
}
});
}
@@ -506,40 +513,9 @@ bool GnomeManager::Impl::HasInhibitors()
return inhibitors.GetBool();
}
-std::string GnomeManager::Impl::UserIconFile()
+void GnomeManager::Impl::UserIconFile(std::function<void(GVariant*)> callback)
{
- if (test_mode_)
- return std::string("/usr/share/pixmaps/faces/fish.jpg") ;
- glib::Error error;
- glib::Object<GDBusConnection> system_bus(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error));
-
- if (error)
- {
- LOG_ERROR(logger)<<"Unable to get system bus: "<< error;
- return "";
- }
-
- glib::Variant IconFile(g_dbus_connection_call_sync (system_bus,
- "org.freedesktop.Accounts",
- g_strdup_printf("/org/freedesktop/Accounts/User%i", getuid()),
- "org.freedesktop.DBus.Properties",
- "Get",
- g_variant_new("(ss)",
- "org.freedesktop.Accounts.User",
- "IconFile"),
- G_VARIANT_TYPE("(v)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- nullptr,
- &error));
-
- if (error)
- {
- LOG_ERROR(logger)<<"Couldn't find user icon in accounts service: "<< error;
- return "";
- }
-
- return IconFile.GetString();
+ dm_seat_proxy_->GetProperty("IconFile", callback);
}
bool GnomeManager::Impl::IsUserInGroup(std::string const& user_name, std::string const& group_name)
@@ -587,9 +563,9 @@ std::string GnomeManager::HostName() const
return glib::gchar_to_string(g_get_host_name());
}
-std::string GnomeManager::UserIconFile() const
+void GnomeManager::UserIconFile(std::function<void(GVariant*)> callback) const
{
- return impl_->UserIconFile();
+ impl_->UserIconFile(callback);
}
void GnomeManager::ScreenSaverActivate()
diff --git a/UnityCore/GnomeSessionManager.h b/UnityCore/GnomeSessionManager.h
index 46dd54f64..84d7851a0 100644
--- a/UnityCore/GnomeSessionManager.h
+++ b/UnityCore/GnomeSessionManager.h
@@ -36,7 +36,7 @@ public:
std::string RealName() const;
std::string UserName() const;
std::string HostName() const;
- std::string UserIconFile() const;
+ void UserIconFile(std::function<void(GVariant*)>) const;
void ScreenSaverActivate();
void ScreenSaverDeactivate();
diff --git a/UnityCore/GnomeSessionManagerImpl.h b/UnityCore/GnomeSessionManagerImpl.h
index 764e407f6..efdc44ceb 100644
--- a/UnityCore/GnomeSessionManagerImpl.h
+++ b/UnityCore/GnomeSessionManagerImpl.h
@@ -54,7 +54,7 @@ struct GnomeManager::Impl
bool HasInhibitors();
void EnsureCancelPendingAction();
void LockScreen(bool prompt);
- std::string UserIconFile();
+ void UserIconFile(std::function<void(GVariant*)> callback);
GVariant* OnShellMethodCall(std::string const& method, GVariant* parameters);
void CallGnomeSessionMethod(std::string const& method, GVariant* parameters = nullptr,
@@ -80,6 +80,7 @@ struct GnomeManager::Impl
glib::DBusProxy::Ptr login_proxy_;
glib::DBusProxy::Ptr presence_proxy_;
glib::DBusProxy::Ptr dm_proxy_;
+ glib::DBusProxy::Ptr dm_seat_proxy_;
int open_sessions_;
};
diff --git a/UnityCore/SessionManager.h b/UnityCore/SessionManager.h
index 0d5a04e81..f7a6fac72 100644
--- a/UnityCore/SessionManager.h
+++ b/UnityCore/SessionManager.h
@@ -23,6 +23,7 @@
#include <sigc++/sigc++.h>
#include <memory>
+#include <glib.h>
#include <NuxCore/Property.h>
namespace unity
@@ -44,7 +45,7 @@ public:
virtual std::string RealName() const = 0;
virtual std::string UserName() const = 0;
virtual std::string HostName() const = 0;
- virtual std::string UserIconFile() const = 0;
+ virtual void UserIconFile(std::function<void(GVariant*)>) const = 0;
virtual void ScreenSaverActivate() = 0;
virtual void ScreenSaverDeactivate() = 0;
diff --git a/com.canonical.Unity.gschema.xml b/com.canonical.Unity.gschema.xml
index b7366e29b..e733673c4 100644
--- a/com.canonical.Unity.gschema.xml
+++ b/com.canonical.Unity.gschema.xml
@@ -9,6 +9,10 @@
<value nick="Not Expanded" value="0" />
<value nick="Expanded" value="1" />
</enum>
+ <enum id="desktop-type-enum">
+ <value nick="Ubuntu" value="0" />
+ <value nick="UbuntuKylin" value="1" />
+ </enum>
<schema path="/com/canonical/unity/" id="com.canonical.Unity" gettext-domain="unity">
<key enum="form-factor-enum" name="form-factor">
@@ -21,6 +25,11 @@
<summary>Whether the home screen should be expanded.</summary>
<description>Whether the home screen should be expanded.</description>
</key>
+ <key enum="desktop-type-enum" name="desktop-type">
+ <default>"Ubuntu"</default>
+ <summary>The current desktop name.</summary>
+ <description>The current desktop name.</description>
+ </key>
<key type="i" name="minimize-count">
<default>0</default>
<summary>Number of times a normal window has been minimized.</summary>
diff --git a/lockscreen/KylinLockScreenShield.cpp b/lockscreen/KylinLockScreenShield.cpp
index 0108fb862..ee865fee8 100644
--- a/lockscreen/KylinLockScreenShield.cpp
+++ b/lockscreen/KylinLockScreenShield.cpp
@@ -1,6 +1,6 @@
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
-* Copyright (C) 2013 Canonical Ltd
+* Copyright (C) 2015 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
diff --git a/lockscreen/KylinLockScreenShield.h b/lockscreen/KylinLockScreenShield.h
index cd18c1ef3..e896c0583 100644
--- a/lockscreen/KylinLockScreenShield.h
+++ b/lockscreen/KylinLockScreenShield.h
@@ -1,6 +1,6 @@
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
-* Copyright (C) 2013 Canonical Ltd
+* Copyright (C) 2015 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
@@ -43,8 +43,6 @@ public:
int monitor, bool is_primary);
bool HasGrab() const override;
- bool IsIndicatorOpen() const override { return false;}
- void ActivatePanel() override {}
protected:
bool AcceptKeyNavFocus() override;
@@ -63,7 +61,6 @@ private:
nux::ObjectPtr<nux::Layout> primary_layout_;
nux::ObjectPtr<nux::Layout> prompt_layout_;
nux::ObjectPtr<nux::Layout> cof_layout_;
- connection::Wrapper panel_active_conn_;
connection::Wrapper regrab_conn_;
glib::Source::UniquePtr regrab_timeout_;
CofView* cof_view_;
diff --git a/lockscreen/KylinUserPromptView.cpp b/lockscreen/KylinUserPromptView.cpp
index a61d4796b..a52b950a9 100644
--- a/lockscreen/KylinUserPromptView.cpp
+++ b/lockscreen/KylinUserPromptView.cpp
@@ -1,6 +1,6 @@
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
-* Copyright (C) 2014 Canonical Ltd
+* Copyright (C) 2015 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
@@ -43,16 +43,19 @@ namespace lockscreen
{
namespace
{
+const RawPixel AVATAR_SIZE = 128_em;
+const RawPixel ACTIVATOR_ICON_SIZE = 34_em;
const RawPixel LAYOUT_MARGIN = 20_em;
const RawPixel MSG_LAYOUT_MARGIN = 15_em;
const RawPixel MSG_LAYOUT_PADDING = 33_em;
const RawPixel PROMPT_LAYOUT_MARGIN = 5_em;
const RawPixel SWITCH_ICON_SIZE = 32_em;
-const RawPixel AVATAR_SIZE = 128_em;
const RawPixel TEXT_INPUT_HEIGHT = 36_em;
const RawPixel TEXT_INPUT_WIDTH = 320_em;
const int PROMPT_FONT_SIZE = 14;
+const std::string ACTIVATOR_ICON = "login.png";
+
std::string SanitizeMessage(std::string const& message)
{
std::string msg = boost::algorithm::trim_copy(message);
@@ -81,8 +84,9 @@ KylinUserPromptView::KylinUserPromptView(session::Manager::Ptr const& session_ma
, username_(nullptr)
, msg_layout_(nullptr)
, prompt_layout_(nullptr)
- , SwitchIcon_(nullptr)
- , Avatar_(nullptr)
+ , avatar_layout_(nullptr)
+ , switch_icon_(nullptr)
+ , avatar_(nullptr)
{
user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){
AddPrompt(message, true, promise);
@@ -106,6 +110,10 @@ KylinUserPromptView::KylinUserPromptView(session::Manager::Ptr const& session_ma
scale.changed.connect(sigc::hide(sigc::mem_fun(this, &KylinUserPromptView::UpdateSize)));
+ session_manager_->UserIconFile([this] (GVariant* value) {
+ AddAvatar(glib::gchar_to_string(g_variant_get_string(value, NULL)), AVATAR_SIZE.CP(scale));
+ });
+
UpdateSize();
ResetLayout();
@@ -126,19 +134,17 @@ void KylinUserPromptView::ResetLayout()
nux::Layout* switch_layout = new nux::HLayout();
TextureCache& cache = TextureCache::GetDefault();
- SwitchIcon_ = new IconTexture(cache.FindTexture("switch_user.png", SWITCH_ICON_SIZE.CP(scale), SWITCH_ICON_SIZE.CP(scale)));
- switch_layout->AddView(SwitchIcon_);
- SwitchIcon_->mouse_click.connect([this](int x, int y, unsigned long button_flags, unsigned long key_flags) {
+ switch_icon_ = new IconTexture(cache.FindTexture("switch_user.png", SWITCH_ICON_SIZE.CP(scale), SWITCH_ICON_SIZE.CP(scale)));
+ switch_layout->AddView(switch_icon_);
+ switch_icon_->mouse_click.connect([this](int x, int y, unsigned long button_flags, unsigned long key_flags) {
session_manager_->SwitchToGreeter();
});
switch_layout->SetMaximumSize(SWITCH_ICON_SIZE.CP(scale), SWITCH_ICON_SIZE.CP(scale));
GetLayout()->AddLayout(switch_layout);
}
- Avatar_ = new IconTexture(LoadUserIcon(AVATAR_SIZE.CP(scale)));
- Avatar_->SetMinimumWidth(AVATAR_SIZE.CP(scale));
- Avatar_->SetMaximumWidth(AVATAR_SIZE.CP(scale));
- GetLayout()->AddView(Avatar_);
+ avatar_layout_ = new nux::VLayout();
+ GetLayout()->AddLayout(avatar_layout_);
nux::Layout* prompt_layout = new nux::VLayout();
@@ -276,6 +282,12 @@ void KylinUserPromptView::AddPrompt(std::string const& message, bool visible, Pr
auto* text_entry = text_input->text_entry();
text_input->scale = scale();
+ text_input->activator_icon = ACTIVATOR_ICON;
+ text_input->activator_icon_size = ACTIVATOR_ICON_SIZE;
+ text_input->background_color = nux::Color(1.0f, 1.0f, 1.0f, 0.8f);
+ text_input->border_color = nux::Color(0.0f, 0.0f, 0.0f, 0.0f);
+ text_input->border_radius = 0;
+ text_input->hint_color = nux::Color(0.0f, 0.0f, 0.0f, 0.5f);
text_input->input_hint = SanitizeMessage(message);
text_input->hint_font_size = PROMPT_FONT_SIZE;
text_input->show_caps_lock = true;
@@ -342,17 +354,30 @@ void KylinUserPromptView::AddMessage(std::string const& message, nux::Color cons
QueueDraw();
}
-nux::ObjectPtr<nux::BaseTexture> KylinUserPromptView::LoadUserIcon(int user_icon_size)
+void KylinUserPromptView::AddAvatar(std::string const& icon_file, int icon_size)
+{
+ avatar_ = new IconTexture(LoadUserIcon(icon_file, icon_size));
+ avatar_->SetMinimumWidth(icon_size);
+ avatar_->SetMaximumWidth(icon_size);
+ avatar_layout_->AddView(avatar_);
+
+ GetLayout()->ComputeContentPosition(0, 0);
+ ComputeContentSize();
+ QueueRelayout();
+ QueueDraw();
+}
+
+nux::ObjectPtr<nux::BaseTexture> KylinUserPromptView::LoadUserIcon(std::string const& icon_file, int icon_size)
{
glib::Error error;
- glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file_at_size(session_manager_->UserIconFile().c_str(), user_icon_size, user_icon_size, &error));
- if (pixbuf == nullptr)
+ glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_file_at_size(icon_file.c_str(), icon_size, icon_size, &error));
+ if (!pixbuf)
{
auto* theme = gtk_icon_theme_get_default();
GtkIconLookupFlags flags = GTK_ICON_LOOKUP_FORCE_SIZE;
- pixbuf = gtk_icon_theme_load_icon(theme, "avatar-default-kylin", user_icon_size, flags, &error);
- if ( pixbuf == nullptr)
- pixbuf = gtk_icon_theme_load_icon(theme, "avatar-default", user_icon_size, flags, &error);
+ pixbuf = gtk_icon_theme_load_icon(theme, "avatar-default-kylin", icon_size, flags, &error);
+ if (!pixbuf)
+ pixbuf = gtk_icon_theme_load_icon(theme, "avatar-default", icon_size, flags, &error);
}
nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
cairo_t* cr = cg.GetInternalContext();
diff --git a/lockscreen/KylinUserPromptView.h b/lockscreen/KylinUserPromptView.h
index c02bd0670..a6938e409 100644
--- a/lockscreen/KylinUserPromptView.h
+++ b/lockscreen/KylinUserPromptView.h
@@ -48,6 +48,7 @@ public:
nux::View* focus_view();
+ void AddAvatar(std::string const& avatar_icon, int avatar_size);
void AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const&);
void AddMessage(std::string const& message, nux::Color const& color);
void AuthenticationCb(bool authenticated);
@@ -58,7 +59,7 @@ protected:
void ResetLayout();
void UpdateSize();
bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character);
- nux::ObjectPtr<nux::BaseTexture> LoadUserIcon(int icon_size);
+ nux::ObjectPtr<nux::BaseTexture> LoadUserIcon(std::string const& icon_file, int icon_size);
private:
session::Manager::Ptr session_manager_;
@@ -66,9 +67,10 @@ private:
StaticCairoText* username_;
nux::VLayout* msg_layout_;
nux::VLayout* prompt_layout_;
+ nux::VLayout* avatar_layout_;
std::deque<TextInput*> focus_queue_;
- IconTexture* SwitchIcon_;
- IconTexture* Avatar_;
+ IconTexture* switch_icon_;
+ IconTexture* avatar_;
nux::Geometry cached_focused_geo_;
};
diff --git a/lockscreen/LockScreenAbstractPromptView.h b/lockscreen/LockScreenAbstractPromptView.h
index c8fb749c9..3a5d5284f 100644
--- a/lockscreen/LockScreenAbstractPromptView.h
+++ b/lockscreen/LockScreenAbstractPromptView.h
@@ -62,8 +62,6 @@ public:
virtual void ResetLayout() = 0;
virtual void UpdateSize() = 0;
- virtual bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character) = 0;
-
protected:
session::Manager::Ptr session_manager_;
UserAuthenticatorPam user_authenticator_;
diff --git a/lockscreen/LockScreenAbstractShield.h b/lockscreen/LockScreenAbstractShield.h
index 4843a00c4..603e0294a 100644
--- a/lockscreen/LockScreenAbstractShield.h
+++ b/lockscreen/LockScreenAbstractShield.h
@@ -58,8 +58,8 @@ public:
using MockableBaseWindow::RemoveLayout;
virtual bool HasGrab() const = 0;
- virtual bool IsIndicatorOpen() const = 0;
- virtual void ActivatePanel() = 0;
+ virtual bool IsIndicatorOpen() const { return false; }
+ virtual void ActivatePanel() {}
sigc::signal<void> grabbed;
sigc::signal<void> grab_failed;
diff --git a/lockscreen/LockScreenController.cpp b/lockscreen/LockScreenController.cpp
index b44f7481c..3a1a0d2fa 100644
--- a/lockscreen/LockScreenController.cpp
+++ b/lockscreen/LockScreenController.cpp
@@ -23,10 +23,12 @@
#include <UnityCore/GLibDBusProxy.h>
#include <NuxCore/Logger.h>
+#include "KylinUserPromptView.h"
#include "LockScreenShield.h"
#include "LockScreenSettings.h"
#include "unity-shared/AnimationUtils.h"
#include "unity-shared/UScreen.h"
+#include "unity-shared/UnitySettings.h"
#include "unity-shared/WindowManager.h"
namespace unity
@@ -224,7 +226,7 @@ void Controller::EnsureShields(std::vector<nux::Geometry> const& monitors)
if (!prompt_view)
{
- if (g_strcmp0(getenv("KYLIN_CURRENT_DESKTOP"), "Kylin") == 0)
+ if (unity::Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)
prompt_view = test_mode_ ? nullptr : new KylinUserPromptView(session_manager_);
else
prompt_view = test_mode_ ? nullptr : new UserPromptView(session_manager_);
diff --git a/lockscreen/LockScreenController.h b/lockscreen/LockScreenController.h
index d190fb93c..bc409f050 100644
--- a/lockscreen/LockScreenController.h
+++ b/lockscreen/LockScreenController.h
@@ -33,9 +33,6 @@
#include "unity-shared/BackgroundEffectHelper.h"
#include "unity-shared/UpstartWrapper.h"
-#include "KylinUserPromptView.h"
-#include "LockScreenAbstractPromptView.h"
-
namespace unity
{
namespace lockscreen
diff --git a/lockscreen/LockScreenShieldFactory.cpp b/lockscreen/LockScreenShieldFactory.cpp
index abd9866a0..74bc77c9b 100644
--- a/lockscreen/LockScreenShieldFactory.cpp
+++ b/lockscreen/LockScreenShieldFactory.cpp
@@ -21,6 +21,7 @@
#include "LockScreenShield.h"
#include "LockScreenAbstractPromptView.h"
#include "KylinLockScreenShield.h"
+#include "unity-shared/UnitySettings.h"
namespace unity
{
@@ -33,7 +34,7 @@ nux::ObjectPtr<AbstractShield> ShieldFactory::CreateShield(session::Manager::Ptr
nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
int monitor, bool is_primary)
{
- if (g_strcmp0(getenv("KYLIN_CURRENT_DESKTOP"),"Kylin") == 0)
+ if (Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)
return nux::ObjectPtr<KylinShield>(new KylinShield(session_manager, accelerators, prompt_view, monitor, is_primary));
else
return nux::ObjectPtr<Shield>(new Shield(session_manager, indicators, accelerators, prompt_view, monitor, is_primary));
diff --git a/lockscreen/UserPromptView.h b/lockscreen/UserPromptView.h
index 15741030b..381ad8f50 100644
--- a/lockscreen/UserPromptView.h
+++ b/lockscreen/UserPromptView.h
@@ -27,11 +27,10 @@
#include <Nux/View.h>
#include <UnityCore/SessionManager.h>
+#include "LockScreenAbstractPromptView.h"
#include "UserAuthenticatorPam.h"
#include "unity-shared/IMTextEntry.h"
-#include "LockScreenAbstractPromptView.h"
-
namespace nux
{
class VLayout;
diff --git a/shutdown/StandaloneSession.cpp b/shutdown/StandaloneSession.cpp
index a6355e032..40415e15e 100644
--- a/shutdown/StandaloneSession.cpp
+++ b/shutdown/StandaloneSession.cpp
@@ -39,7 +39,7 @@ public:
std::string RealName() const { return "Marco Trevisan"; }
std::string UserName() const { return "marco"; }
std::string HostName() const { return "tricky"; }
- std::string UserIconFile() const { return "/usr/share/pixmaps/faces/fish.jpg"; }
+ void UserIconFile(std::function<void(GVariant*)>) const { std::cout << "UserIconFile" << std::endl; }
void ScreenSaverActivate() { std::cout << "ScreenSaverActivate" << std::endl; }
void ScreenSaverDeactivate() { std::cout << "ScreenSaverDeactivate" << std::endl; }
diff --git a/tests/test_gnome_session_manager.cpp b/tests/test_gnome_session_manager.cpp
index c2e9b02b1..e009ab483 100644
--- a/tests/test_gnome_session_manager.cpp
+++ b/tests/test_gnome_session_manager.cpp
@@ -405,11 +405,6 @@ TEST_F(TestGnomeSessionManager, HostName)
EXPECT_EQ(manager->HostName(), g_get_host_name());
}
-TEST_F(TestGnomeSessionManager, UserIconFile)
-{
- EXPECT_EQ(manager->UserIconFile(), "/usr/share/pixmaps/faces/fish.jpg" );
-}
-
TEST_F(TestGnomeSessionManager, SwitchToGreeter)
{
bool switch_called = false;
diff --git a/tests/test_mock_session_manager.h b/tests/test_mock_session_manager.h
index 762d85d7c..317fd1147 100644
--- a/tests/test_mock_session_manager.h
+++ b/tests/test_mock_session_manager.h
@@ -28,11 +28,12 @@ namespace session
struct MockManager : Manager
{
typedef std::shared_ptr<MockManager> Ptr;
+ typedef std::function<void(GVariant*)> ReplyCallback;
MOCK_CONST_METHOD0(RealName, std::string());
MOCK_CONST_METHOD0(UserName, std::string());
MOCK_CONST_METHOD0(HostName, std::string());
- MOCK_CONST_METHOD0(UserIconFile, std::string());
+ MOCK_CONST_METHOD1(UserIconFile, void(ReplyCallback));
MOCK_METHOD0(ScreenSaverActivate, void());
MOCK_METHOD0(ScreenSaverDeactivate, void());
@@ -54,4 +55,4 @@ struct MockManager : Manager
};
} // session
-} // unity \ No newline at end of file
+} // unity
diff --git a/tests/test_text_input.cpp b/tests/test_text_input.cpp
index 3830be359..ff40aaf36 100644
--- a/tests/test_text_input.cpp
+++ b/tests/test_text_input.cpp
@@ -63,19 +63,19 @@ class TestTextInput : public ::testing::Test
TEST_F(TestTextInput, HintCorrectInit)
{
- nux::Color color = hint->GetTextColor();
- if (g_strcmp0(g_getenv("KYLIN_CURRENT_DESKTOP"), "Kylin") == 0)
- {
- EXPECT_EQ(color.red, 0.0f);
- EXPECT_EQ(color.green, 0.0f);
- EXPECT_EQ(color.blue, 0.0f);
- EXPECT_EQ(color.alpha, 0.5f);
- } else {
- EXPECT_EQ(color.red, 1.0f);
- EXPECT_EQ(color.green, 1.0f);
- EXPECT_EQ(color.blue, 1.0f);
- EXPECT_EQ(color.alpha, 0.5f);
- }
+// nux::Color color = hint->GetTextColor();
+// if (Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN)
+// {
+// EXPECT_EQ(color.red, 0.0f);
+// EXPECT_EQ(color.green, 0.0f);
+// EXPECT_EQ(color.blue, 0.0f);
+// EXPECT_EQ(color.alpha, 0.5f);
+// } else {
+// EXPECT_EQ(color.red, 1.0f);
+// EXPECT_EQ(color.green, 1.0f);
+// EXPECT_EQ(color.blue, 1.0f);
+// EXPECT_EQ(color.alpha, 0.5f);
+// }
}
TEST_F(TestTextInput, InputStringCorrectSetter)
diff --git a/unity-shared/TextInput.cpp b/unity-shared/TextInput.cpp
index 5845beae1..cac8e8a22 100644
--- a/unity-shared/TextInput.cpp
+++ b/unity-shared/TextInput.cpp
@@ -53,8 +53,8 @@ const RawPixel HINT_PADDING = 3_em;
const RawPixel TOOLTIP_Y_OFFSET = 3_em;
const RawPixel TOOLTIP_OFFSET = 10_em;
const RawPixel DEFAULT_ICON_SIZE = 22_em;
-const RawPixel LOGIN_ICON_SIZE = 34_em;
+std::string ACTIVATOR_ICON = "arrow_right.png";
std::string WARNING_ICON = "dialog-warning-symbolic";
// Fonts
const std::string HINT_LABEL_DEFAULT_FONT_NAME = "Ubuntu";
@@ -89,9 +89,15 @@ NUX_IMPLEMENT_OBJECT_TYPE(TextInput);
TextInput::TextInput(NUX_FILE_LINE_DECL)
: View(NUX_FILE_LINE_PARAM)
+ , activator_icon(ACTIVATOR_ICON)
+ , activator_icon_size(DEFAULT_ICON_SIZE)
+ , background_color(nux::Color(0.0f, 0.0f, 0.0f, 0.35f))
+ , border_color(nux::Color(1.0f, 1.0f, 1.0f, 0.7f))
+ , border_radius(BORDER_RADIUS)
, input_hint("")
, hint_font_name(HINT_LABEL_DEFAULT_FONT_NAME)
, hint_font_size(HINT_LABEL_FONT_SIZE)
+ , hint_color(nux::Color(1.0f, 1.0f, 1.0f, 0.5f))
, show_activator(false)
, show_caps_lock(false)
, scale(1.0)
@@ -109,10 +115,8 @@ TextInput::TextInput(NUX_FILE_LINE_DECL)
hint_layout_->SetLeftAndRightPadding(HINT_PADDING.CP(scale), HINT_PADDING.CP(scale));
hint_ = new StaticCairoText("");
- if (g_strcmp0(getenv("KYLIN_CURRENT_DESKTOP"), "Kylin") == 0)
- hint_->SetTextColor(nux::Color(0.0f, 0.0f, 0.0f, 0.5f));
- else
- hint_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 0.5f));
+ hint_->SetTextColor(hint_color);
+ hint_color.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateHintColor)));
hint_->SetScale(scale);
hint_layout_->AddView(hint_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
@@ -156,10 +160,18 @@ TextInput::TextInput(NUX_FILE_LINE_DECL)
Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateSize)));
// Activator
- activator_ = new IconTexture(LoadActivatorIcon(DEFAULT_ICON_SIZE.CP(scale)));
+ activator_ = new IconTexture(LoadActivatorIcon(activator_icon(), activator_icon_size().CP(scale)));
activator_->SetVisible(show_activator());
layout_->AddView(activator_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
+ activator_icon.changed.connect([this] (std::string icon) {
+ activator_->SetTexture(LoadActivatorIcon(icon, activator_icon_size().CP(scale)));
+ });
+
+ activator_icon_size.changed.connect([this] (RawPixel icon_size) {
+ activator_->SetTexture(LoadActivatorIcon(activator_icon(), icon_size.CP(scale)));
+ });
+
show_activator.changed.connect([this] (bool value) {
activator_->SetVisible(value);
});
@@ -202,6 +214,11 @@ TextInput::TextInput(NUX_FILE_LINE_DECL)
warning_->mouse_leave.connect([this] (int x, int y, int button, int key_flags) {
tooltip_timeout_ ? tooltip_timeout_.reset() : QueueDraw();
});
+
+ //background
+ background_color.changed.connect([this] (nux::Color color) { UpdateBackground(true); });
+ border_color.changed.connect([this] (nux::Color color) { UpdateBackground(true); });
+ border_radius.changed.connect([this] (int radius) { UpdateBackground(true); });
}
void TextInput::UpdateSize()
@@ -225,7 +242,7 @@ void TextInput::UpdateScale(double scale)
hint_->SetMaximumHeight(pango_entry_->GetMinimumHeight());
spinner_->scale = scale;
- activator_->SetTexture(LoadActivatorIcon(DEFAULT_ICON_SIZE.CP(scale)));
+ activator_->SetTexture(LoadActivatorIcon(activator_icon(), activator_icon_size().CP(scale)));
warning_->SetTexture(LoadWarningIcon(DEFAULT_ICON_SIZE.CP(scale)));
warning_tooltip_.Release();
@@ -255,13 +272,15 @@ void TextInput::UpdateHintFont()
hint_->SetFont((hint_font_name() + " " + std::to_string(hint_font_size())).c_str());
}
-nux::ObjectPtr<nux::BaseTexture> TextInput::LoadActivatorIcon(int icon_size)
+void TextInput::UpdateHintColor()
+{
+ hint_->SetTextColor(hint_color);
+}
+
+nux::ObjectPtr<nux::BaseTexture> TextInput::LoadActivatorIcon(std::string const& icon_file, int icon_size)
{
TextureCache& cache = TextureCache::GetDefault();
- if (g_strcmp0(getenv("KYLIN_CURRENT_DESKTOP"), "Kylin") == 0)
- return cache.FindTexture("login.png", LOGIN_ICON_SIZE.CP(scale), LOGIN_ICON_SIZE.CP(scale));
- else
- return cache.FindTexture("arrow_right.png", icon_size, icon_size);
+ return cache.FindTexture(icon_file.c_str(), icon_size, icon_size);
}
nux::ObjectPtr<nux::BaseTexture> TextInput::LoadWarningIcon(int icon_size)
@@ -448,33 +467,19 @@ void TextInput::UpdateBackground(bool force)
cairo_surface_set_device_scale(cairo_graphics.GetSurface(), scale, scale);
cairo_t* cr = cairo_graphics.GetInternalContext();
- if (g_strcmp0(getenv("KYLIN_CURRENT_DESKTOP"), "Kylin") == 0)
- {
- cairo_graphics.DrawRoundedRectangle(cr,
- 1.0f,
- 0.5, 0.5,
- 0,
- (last_width_/scale) - 1, (last_height_/scale) - 1,
- false);
-
- cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 0.8f);
- cairo_fill_preserve(cr);
- } else {
- cairo_graphics.DrawRoundedRectangle(cr,
- 1.0f,
- 0.5, 0.5,
- BORDER_RADIUS,
- (last_width_/scale) - 1, (last_height_/scale) - 1,
- false);
-
- cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.35f);
- cairo_fill_preserve(cr);
- cairo_set_line_width(cr, 1);
- cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 0.7f);
- cairo_stroke(cr);
- }
+ cairo_graphics.DrawRoundedRectangle(cr,
+ 1.0f,
+ 0.5, 0.5,
+ border_radius(),
+ (last_width_/scale) - 1, (last_height_/scale) - 1,
+ false);
+
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgba(cr, background_color().red, background_color().green, background_color().blue, background_color().alpha);
+ cairo_fill_preserve(cr);
+ cairo_set_line_width(cr, 1);
+ cairo_set_source_rgba(cr, border_color().red, border_color().green, border_color().blue, border_color().alpha);
+ cairo_stroke(cr);
auto texture2D = texture_ptr_from_cairo_graphics(cairo_graphics);
diff --git a/unity-shared/TextInput.h b/unity-shared/TextInput.h
index 927ac08b9..aa94758da 100644
--- a/unity-shared/TextInput.h
+++ b/unity-shared/TextInput.h
@@ -26,6 +26,7 @@
#include "Introspectable.h"
#include "IMTextEntry.h"
+#include "RawPixel.h"
#include "SearchBarSpinner.h"
namespace nux
@@ -57,10 +58,16 @@ public:
IMTextEntry* text_entry() const;
+ nux::Property<std::string> activator_icon;
+ nux::Property<RawPixel> activator_icon_size;
+ nux::Property<nux::Color> background_color;
+ nux::Property<nux::Color> border_color;
+ nux::Property<int> border_radius;
nux::RWProperty<std::string> input_string;
nux::Property<std::string> input_hint;
nux::Property<std::string> hint_font_name;
nux::Property<int> hint_font_size;
+ nux::Property<nux::Color> hint_color;
nux::ROProperty<bool> im_active;
nux::ROProperty<bool> im_preedit;
nux::Property<bool> show_activator;
@@ -70,6 +77,7 @@ public:
private:
void OnFontChanged();
void UpdateHintFont();
+ void UpdateHintColor();
void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
void UpdateBackground(bool force);
@@ -86,7 +94,7 @@ private:
nux::Geometry GetWaringIconGeometry() const;
void CheckIfCapsLockOn();
- nux::ObjectPtr<nux::BaseTexture> LoadActivatorIcon(int icon_size);
+ nux::ObjectPtr<nux::BaseTexture> LoadActivatorIcon(std::string const& icon_file, int icon_size);
nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);
void LoadWarningTooltip();
diff --git a/unity-shared/UnitySettings.cpp b/unity-shared/UnitySettings.cpp
index ce59f7ca0..7de69ce24 100644
--- a/unity-shared/UnitySettings.cpp
+++ b/unity-shared/UnitySettings.cpp
@@ -38,6 +38,7 @@ Settings* settings_instance = nullptr;
const std::string SETTINGS_NAME = "com.canonical.Unity";
const std::string FORM_FACTOR = "form-factor";
const std::string DOUBLE_CLICK_ACTIVATE = "double-click-activate";
+const std::string DESKTOP_TYPE = "desktop-type";
const std::string LIM_SETTINGS = "com.canonical.Unity.IntegratedMenus";
const std::string CLICK_MOVEMENT_THRESHOLD = "click-movement-threshold";
@@ -94,6 +95,7 @@ public:
parent_->form_factor.SetSetterFunction(sigc::mem_fun(this, &Impl::SetFormFactor));
parent_->double_click_activate.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDoubleClickActivate));
parent_->remote_content.SetGetterFunction(sigc::mem_fun(this, &Impl::GetRemoteContentEnabled));
+ parent_->desktop_type.SetGetterFunction(sigc::mem_fun(this, &Impl::GetDesktopType));
for (unsigned i = 0; i < monitors::MAX; ++i)
em_converters_.emplace_back(std::make_shared<EMConverter>());
@@ -218,6 +220,11 @@ public:
return cached_double_click_activate_;
}
+ DesktopType GetDesktopType() const
+ {
+ return static_cast<DesktopType>(g_settings_get_enum(usettings_, DESKTOP_TYPE.c_str()));
+ }
+
int GetFontSize() const
{
gint font_size;
diff --git a/unity-shared/UnitySettings.h b/unity-shared/UnitySettings.h
index f5e90774f..f34570f5c 100644
--- a/unity-shared/UnitySettings.h
+++ b/unity-shared/UnitySettings.h
@@ -35,6 +35,12 @@ enum class FormFactor
TV
};
+enum class DesktopType
+{
+ UBUNTU,
+ UBUNTUKYLIN
+};
+
class Settings
{
public:
@@ -51,6 +57,7 @@ public:
nux::RWProperty<FormFactor> form_factor;
nux::Property<bool> is_standalone;
+ nux::ROProperty<DesktopType> desktop_type;
nux::ROProperty<bool> double_click_activate;
nux::Property<unsigned> lim_movement_thresold;
nux::Property<unsigned> lim_double_click_wait;