Merge lp:~gordallott/unity/hud into lp:unity

Proposed by Gord Allott
Status: Merged
Approved by: Gord Allott
Approved revision: no longer in the source branch.
Merged at revision: 1900
Proposed branch: lp:~gordallott/unity/hud
Merge into: lp:unity
Prerequisite: lp:~gordallott/unity/rename-ubus-place-view-messages
Diff against target: 4304 lines (+3163/-177)
45 files modified
CMakeLists.txt (+1/-1)
UnityCore/CMakeLists.txt (+2/-0)
UnityCore/GLibDBusProxy.cpp (+0/-4)
UnityCore/Hud.cpp (+255/-0)
UnityCore/Hud.h (+127/-0)
manual-tests/Hud.txt (+57/-0)
plugins/unityshell/src/DashController.cpp (+12/-0)
plugins/unityshell/src/DashStyle.cpp (+136/-4)
plugins/unityshell/src/DashStyle.h (+9/-2)
plugins/unityshell/src/DashView.h (+1/-1)
plugins/unityshell/src/FilterAllButton.cpp (+1/-0)
plugins/unityshell/src/HudButton.cpp (+208/-0)
plugins/unityshell/src/HudButton.h (+81/-0)
plugins/unityshell/src/HudController.cpp (+385/-0)
plugins/unityshell/src/HudController.h (+113/-0)
plugins/unityshell/src/HudIcon.cpp (+95/-0)
plugins/unityshell/src/HudIcon.h (+73/-0)
plugins/unityshell/src/HudIconTextureSource.cpp (+110/-0)
plugins/unityshell/src/HudIconTextureSource.h (+51/-0)
plugins/unityshell/src/HudView.cpp (+398/-0)
plugins/unityshell/src/HudView.h (+118/-0)
plugins/unityshell/src/IMTextEntry.cpp (+1/-4)
plugins/unityshell/src/IMTextEntry.h (+0/-3)
plugins/unityshell/src/IconTexture.cpp (+12/-3)
plugins/unityshell/src/IconTexture.h (+5/-2)
plugins/unityshell/src/OverlayRenderer.cpp (+5/-5)
plugins/unityshell/src/OverlayRenderer.h (+1/-1)
plugins/unityshell/src/SearchBar.cpp (+124/-55)
plugins/unityshell/src/SearchBar.h (+11/-8)
plugins/unityshell/src/SearchBarSpinner.cpp (+1/-4)
plugins/unityshell/src/SearchBarSpinner.h (+2/-5)
plugins/unityshell/src/UBusMessages.h (+2/-0)
plugins/unityshell/src/unity-search-bar-accessible.cpp (+3/-3)
plugins/unityshell/src/unitya11y.cpp (+1/-1)
plugins/unityshell/src/unityshell.cpp (+67/-21)
plugins/unityshell/src/unityshell.h (+8/-1)
plugins/unityshell/unityshell.xml.in (+46/-41)
po/POTFILES.in (+1/-1)
standalone-clients/CMakeLists.txt (+41/-4)
standalone-clients/StandaloneHud.cpp (+171/-0)
tests/CMakeLists.txt (+4/-1)
tests/test_hud.cpp (+104/-0)
tests/test_service_hud.c (+268/-0)
tests/test_service_hud.h (+46/-0)
tests/test_service_main.c (+6/-2)
To merge this branch: bzr merge lp:~gordallott/unity/hud
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
John Lea (community) design review Approve
Andrea Azzarone (community) Needs Fixing
Mirco Müller (community) Needs Fixing
Thomi Richards (community) Needs Fixing
Marco Biscaro (community) Needs Fixing
Review via email: mp+90085@code.launchpad.net

This proposal supersedes a proposal from 2012-01-25.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote : Posted in a previous version of this proposal

50 - self->owner_->connected.emit();

Why is this needed?

review: Needs Information
Revision history for this message
Marco Biscaro (marcobiscaro2112) wrote :

- lens_ = service_lens_new();
- model_ = service_model_new();
+ //lens_ = service_lens_new();
+ //model_ = service_model_new();
+ hud_ = service_hud_new();

If this lines are no longer necessary, they can be removed instead of commented.

- g_object_unref(lens_);
- g_object_unref(model_);
+ //g_object_unref(lens_);
+ //g_object_unref(model_);
+ g_object_unref(hud_);

The same thing here.

Revision history for this message
Marco Biscaro (marcobiscaro2112) :
review: Needs Fixing
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi,

There are a few introspection / autopilot issues with this branch:

Your HUDController derives from Introspectable, but you never use it. You need to:
 1) Add it to the introspection tree.At Diff line 2729 (where you create the HUDController instance) you need to call "AddChild(hud_controller_.get());". If the HUDController is ever deleted, you need to call "RemoveChild(hud_controller_.get());" BEFFORE the deletion takes place.

 2) Add properties to the HUD controller that will be useful in autopilot tests.

You need to repeat this process with all child objects of the HUDController that derive from Introspectable.

Finally, the string returned from "GetName" should be "HUDController" - you don't need to qualify it with "unity.hud".

In HUDIcon.h you #include "Introspectable.h", but never use it.

In HUDView.h, you've declared a "const gchar* GetName()" method, which is from Introspectable, but there's two problems:
 1) You don't derive from Introsopectable (as noted above, you should).
 2) That's not the correct method signiture - the return type is "std::string", and the method is const.

In the same class, make sure you add the search bar to the introspection tree - that way we can get the current search string.

Finally, it'd be really nice to have some autopilot tests written when this is merged. I don't mind helping you with this.

Cheers,

review: Needs Fixing
Revision history for this message
Gord Allott (gordallott) wrote :

> Hi,
>
> There are a few introspection / autopilot issues with this branch:
>
> Your HUDController derives from Introspectable, but you never use it. You need
> to:
> 1) Add it to the introspection tree.At Diff line 2729 (where you create the
> HUDController instance) you need to call "AddChild(hud_controller_.get());".
> If the HUDController is ever deleted, you need to call
> "RemoveChild(hud_controller_.get());" BEFFORE the deletion takes place.
>
> 2) Add properties to the HUD controller that will be useful in autopilot
> tests.
>
>
> You need to repeat this process with all child objects of the HUDController
> that derive from Introspectable.
>
> Finally, the string returned from "GetName" should be "HUDController" - you
> don't need to qualify it with "unity.hud".
>
> In HUDIcon.h you #include "Introspectable.h", but never use it.
>
> In HUDView.h, you've declared a "const gchar* GetName()" method, which is from
> Introspectable, but there's two problems:
> 1) You don't derive from Introsopectable (as noted above, you should).
> 2) That's not the correct method signiture - the return type is
> "std::string", and the method is const.
>
> In the same class, make sure you add the search bar to the introspection tree
> - that way we can get the current search string.
>

Very much so, Introspection was on my todo list for earlier in the week before last minute changes bumped it off, will fix that up

> Finally, it'd be really nice to have some autopilot tests written when this is
> merged. I don't mind helping you with this.
>

Already have a guy from Systems helping out there, for now manual but he's going through and converting them :)

> Cheers,

Revision history for this message
Gord Allott (gordallott) wrote :

> - lens_ = service_lens_new();
> - model_ = service_model_new();
> + //lens_ = service_lens_new();
> + //model_ = service_model_new();
> + hud_ = service_hud_new();
>
> If this lines are no longer necessary, they can be removed instead of
> commented.
>
> - g_object_unref(lens_);
> - g_object_unref(model_);
> + //g_object_unref(lens_);
> + //g_object_unref(model_);
> + g_object_unref(hud_);
>
> The same thing here.

Actually was just left over debugging code ;)

Revision history for this message
Michal Hruby (mhr3) wrote :

49 self->connected_ = true;
50 - self->owner_->connected.emit();

So can we at least not fool IsConnected() users (ie remove the "self->connected_ = true;" as well pls)

150 + GVariant* query_key = g_variant_get_child_value(query, 2);

Please check that the variant has at least 2 children (or at least that query_key != NULL)

153 + GVariant* queries = g_variant_get_child_value(query, 1);
173, 176, 189, 192

Same

Revision history for this message
Mirco Müller (macslow) wrote :

Getting this error during compilation atm:

CMakeFiles/test-gtest-dbus.dir/test_hud.cpp.o: In function `TestBody':
/tmp/fasel/unity/tests/test_hud.cpp:30: undefined reference to `unity::hud::Hud::Hud(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/fasel/unity/tests/test_hud.cpp:93: undefined reference to `unity::hud::Hud::RequestQuery(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/fasel/unity/tests/test_hud.cpp:100: undefined reference to `unity::hud::Hud::CloseQuery()'
collect2: ld returned 1 exit status
make[2]: *** [tests/test-gtest-dbus] Error 1
make[1]: *** [tests/CMakeFiles/test-gtest-dbus.dir/all] Error 2
make: *** [all] Error 2

review: Needs Fixing
Revision history for this message
Mirco Müller (macslow) wrote :

Above mentioned issue solved... typical cmake picking up the wrong libunity-core.so *sigh³*

Revision history for this message
Mirco Müller (macslow) wrote :

Is the HUD really meant to use the exact same button-visuals from the dash? Does Design demand that?

Should the HUD-searchbar not be of the same width as the Dash-searchbar (in non-fullscreen state at least)?

Please get into the habbit of using const int/float in an unnamed namespace instead of "magic" numbers for padding/margins/sizes... you don't use that consistently across this branch... check:

...
+ layout_->AddLayout(new nux::SpaceLayout(8,8,8,8), 0);
...
+ icon_layout->SetVerticalExternalMargin(12);
...
+ search_bar_ = new unity::SearchBar(940, true);
...
+ button_views_->SetHorizontalExternalMargin(12);
+ button_views_->SetMaximumWidth(940);
...
+ hud_controller_->launcher_width = optionGetIconSize() + 18;

review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) wrote :

997 + nux::Geometry content_geo = view_->GetGeometry();
998 + nux::Geometry geo = GetIdealWindowGeometry();

If is it possible, please do something like this:

997 + nux::Geometry const& content_geo = view_->GetGeometry();
998 + nux::Geometry geo(GetIdealWindowGeometry());

or at least:
997 + nux::Geometry content_geo(view_->GetGeometry());
998 + nux::Geometry geo(GetIdealWindowGeometry());

Revision history for this message
Andrea Azzarone (azzar1) :
review: Needs Fixing
Revision history for this message
John Lea (johnlea) wrote :

A great improvement, still a bunch of outstanding changes required but a good step in the right direction. Branch approved, look forward to seeing the next iteration with further finesse.

review: Approve (design review)
Revision history for this message
Gord Allott (gordallott) wrote :

approving as latest revision just fixed up conflicts

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2012-02-03 15:02:15 +0000
+++ CMakeLists.txt 2012-02-06 11:00:29 +0000
@@ -113,7 +113,7 @@
113 SET (BOOT_LOGGER_FLAG "-DENABLE_LOGGER")113 SET (BOOT_LOGGER_FLAG "-DENABLE_LOGGER")
114endif (BOOT_LOGGER)114endif (BOOT_LOGGER)
115115
116SET (MAINTAINER_CFLAGS "-Werror -Wall -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self -Warray-bounds")116SET (MAINTAINER_CFLAGS "-Wall -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self -Warray-bounds")
117option (DISABLE_MAINTAINER_CFLAGS "Disable maintainer CFlags" OFF)117option (DISABLE_MAINTAINER_CFLAGS "Disable maintainer CFlags" OFF)
118if (DISABLE_MAINTAINER_CFLAGS)118if (DISABLE_MAINTAINER_CFLAGS)
119 SET (MAINTAINER_CFLAGS "")119 SET (MAINTAINER_CFLAGS "")
120120
=== modified file 'UnityCore/CMakeLists.txt'
--- UnityCore/CMakeLists.txt 2012-01-18 13:32:26 +0000
+++ UnityCore/CMakeLists.txt 2012-02-06 11:00:29 +0000
@@ -21,6 +21,7 @@
21 GLibSignal-inl.h21 GLibSignal-inl.h
22 GLibWrapper.h22 GLibWrapper.h
23 GLibWrapper-inl.h23 GLibWrapper-inl.h
24 Hud.h
24 HomeLens.h25 HomeLens.h
25 IndicatorEntry.h26 IndicatorEntry.h
26 Indicator.h27 Indicator.h
@@ -54,6 +55,7 @@
54 GLibDBusProxy.cpp55 GLibDBusProxy.cpp
55 GLibSignal.cpp56 GLibSignal.cpp
56 GLibWrapper.cpp57 GLibWrapper.cpp
58 Hud.cpp
57 HomeLens.cpp59 HomeLens.cpp
58 Indicator.cpp60 Indicator.cpp
59 IndicatorEntry.cpp61 IndicatorEntry.cpp
6062
=== modified file 'UnityCore/GLibDBusProxy.cpp'
--- UnityCore/GLibDBusProxy.cpp 2012-01-19 11:01:58 +0000
+++ UnityCore/GLibDBusProxy.cpp 2012-02-06 11:00:29 +0000
@@ -141,11 +141,7 @@
141 gpointer impl)141 gpointer impl)
142{142{
143 DBusProxy::Impl* self = static_cast<DBusProxy::Impl*>(impl);143 DBusProxy::Impl* self = static_cast<DBusProxy::Impl*>(impl);
144
145 LOG_DEBUG(logger) << self->name_ << " appeared";144 LOG_DEBUG(logger) << self->name_ << " appeared";
146
147 self->connected_ = true;
148 self->owner_->connected.emit();
149}145}
150146
151void DBusProxy::Impl::OnNameVanished(GDBusConnection* connection,147void DBusProxy::Impl::OnNameVanished(GDBusConnection* connection,
152148
=== added file 'UnityCore/Hud.cpp'
--- UnityCore/Hud.cpp 1970-01-01 00:00:00 +0000
+++ UnityCore/Hud.cpp 2012-02-06 11:00:29 +0000
@@ -0,0 +1,255 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Gordon Allott <gord.allott@canonical.com>
18 */
19//
20#include "Hud.h"
21
22#include <gio/gio.h>
23#include <glib.h>
24#include <NuxCore/Logger.h>
25#include "GLibWrapper.h"
26#include "GLibDBusProxy.h"
27
28#include "config.h"
29
30#include <sigc++/bind.h>
31
32namespace unity
33{
34namespace hud
35{
36
37namespace
38{
39nux::logging::Logger logger("unity.hud.hud");
40const int request_number_of_results = 6;
41}
42
43// Impl classes
44class HudImpl
45{
46public:
47 HudImpl(std::string const& dbus_name,
48 std::string const& dbus_path,
49 Hud *parent)
50 : query_key_(NULL)
51 , proxy_(dbus_name, dbus_path, "com.canonical.hud")
52 , parent_(parent)
53 {
54 LOG_DEBUG(logger) << "Hud init with name: " << dbus_name << "and path: " << dbus_path;
55 proxy_.connected.connect([&]() {
56 LOG_DEBUG(logger) << "Hud Connected";
57 parent_->connected = true;
58 });
59
60 proxy_.Connect("UpdatedQuery", sigc::mem_fun(this, &HudImpl::UpdateQueryCallback));
61 }
62
63 void QueryCallback(GVariant* data);
64 void UpdateQueryCallback(GVariant* data);
65 void BuildQueries(GVariant* query_array);
66 void ExecuteByKey(GVariant* key, unsigned int timestamp);
67 void ExecuteQueryByStringCallback(GVariant* query, unsigned int timestamp);
68 void CloseQuery();
69
70 GVariant* query_key_;
71 Hud::Queries queries_;
72 glib::DBusProxy proxy_;
73 Hud* parent_;
74};
75
76void HudImpl::ExecuteByKey(GVariant* key, unsigned int timestamp)
77{
78 LOG_DEBUG(logger) << "Executing by Key";
79
80 GVariantBuilder tuple;
81 g_variant_builder_init(&tuple, G_VARIANT_TYPE_TUPLE);
82 g_variant_builder_add_value(&tuple, g_variant_new_variant(key));
83 g_variant_builder_add_value(&tuple, g_variant_new_uint32(timestamp));
84
85 proxy_.Call("ExecuteQuery", g_variant_builder_end(&tuple));
86}
87
88void HudImpl::ExecuteQueryByStringCallback(GVariant* query, unsigned int timestamp)
89{
90 if (g_variant_n_children(query) < 3)
91 {
92 LOG_ERROR(logger) << "Received (" << g_variant_n_children(query) << ") children in a query, expected 3";
93 return;
94 }
95
96 queries_.clear();
97
98 GVariant* query_key = g_variant_get_child_value(query, 2);
99 query_key_ = query_key;
100
101 GVariant* queries = g_variant_get_child_value(query, 1);
102 BuildQueries(queries);
103 g_variant_unref(queries);
104
105 if (queries_.empty() == false)
106 {
107 // we now execute based off the first result
108 ExecuteByKey(queries_.front()->key, timestamp);
109 CloseQuery();
110 }
111}
112
113void HudImpl::QueryCallback(GVariant* query)
114{
115 if (g_variant_n_children(query) < 3)
116 {
117 LOG_ERROR(logger) << "Received (" << g_variant_n_children(query) << ") children in a query, expected 3";
118 return;
119 }
120 queries_.clear();
121
122 // extract the information from the GVariants
123 GVariant* target = g_variant_get_child_value(query, 0);
124 g_variant_unref(target);
125
126 GVariant* query_key = g_variant_get_child_value(query, 2);
127 query_key_ = query_key;
128
129 GVariant* queries = g_variant_get_child_value(query, 1);
130 BuildQueries(queries);
131 g_variant_unref(queries);
132
133 parent_->queries_updated.emit(queries_);
134}
135
136void HudImpl::UpdateQueryCallback(GVariant* query)
137{
138 if (g_variant_n_children(query) < 3)
139 {
140 LOG_ERROR(logger) << "Received (" << g_variant_n_children(query) << ") children in a query, expected 3";
141 return;
142 }
143 // as we are expecting an update, we want to check
144 // and make sure that we are the actual receivers of
145 // the signal
146
147 GVariant* query_key = g_variant_get_child_value(query, 2);
148 if (g_variant_equal(query_key_, query_key))
149 {
150 GVariant* queries = g_variant_get_child_value(query, 1);
151 BuildQueries(queries);
152 g_variant_unref(queries);
153 }
154}
155
156void HudImpl::BuildQueries(GVariant* query_array)
157{
158 GVariantIter iter;
159 g_variant_iter_init(&iter, query_array);
160 glib::String formatted_text;
161 glib::String icon;
162 glib::String item_icon;
163 glib::String completion_text;
164 glib::String shortcut;
165 GVariant* key = NULL;
166
167 while (g_variant_iter_loop(&iter, "(sssssv)",
168 &formatted_text, &icon, &item_icon, &completion_text, &shortcut, &key))
169 {
170 queries_.push_back(Query::Ptr(new Query(formatted_text,
171 icon,
172 item_icon,
173 completion_text,
174 shortcut,
175 key)));
176 }
177}
178
179void HudImpl::CloseQuery()
180{
181 if (query_key_ == NULL)
182 {
183 LOG_WARN(logger) << "Attempted to close the hud connection without starting it";
184 }
185 else
186 {
187 GVariant* paramaters = g_variant_new("(v)", query_key_);
188 proxy_.Call("CloseQuery", paramaters);
189 g_variant_unref(query_key_);
190 query_key_ = NULL;
191 queries_.clear();
192 }
193}
194
195
196Hud::Hud(std::string const& dbus_name,
197 std::string const& dbus_path)
198 : connected(false)
199 , pimpl_(new HudImpl(dbus_name, dbus_path, this))
200{
201 pimpl_->parent_ = this;
202}
203
204Hud::~Hud()
205{
206 delete pimpl_;
207}
208
209void Hud::RequestQuery(std::string const& search_string)
210{
211 LOG_DEBUG(logger) << "Getting Query: " << search_string;
212 if (pimpl_->query_key_ != NULL)
213 {
214 CloseQuery();
215 }
216
217 GVariant* paramaters = g_variant_new("(si)",
218 search_string.c_str(),
219 request_number_of_results);
220 pimpl_->proxy_.Call("StartQuery", paramaters, sigc::mem_fun(this->pimpl_, &HudImpl::QueryCallback));
221}
222
223
224void Hud::ExecuteQuery(Query::Ptr query, unsigned int timestamp)
225{
226 LOG_DEBUG(logger) << "Executing query: " << query->formatted_text;
227 pimpl_->ExecuteByKey(query->key, timestamp);
228}
229
230void Hud::ExecuteQueryBySearch(std::string execute_string, unsigned int timestamp)
231{
232 //Does a search then executes the result based on that search
233 LOG_DEBUG(logger) << "Executing by string" << execute_string;
234 if (pimpl_->query_key_ != NULL)
235 {
236 CloseQuery();
237 }
238
239 GVariant* paramaters = g_variant_new("(si)",
240 execute_string.c_str(),
241 1);
242
243 auto functor = sigc::mem_fun(this->pimpl_, &HudImpl::ExecuteQueryByStringCallback);
244
245 pimpl_->proxy_.Call("StartQuery", paramaters, sigc::bind(functor, timestamp));
246}
247
248void Hud::CloseQuery()
249{
250 //Send close hint to the hud
251 pimpl_->CloseQuery();
252}
253
254}
255}
0256
=== added file 'UnityCore/Hud.h'
--- UnityCore/Hud.h 1970-01-01 00:00:00 +0000
+++ UnityCore/Hud.h 2012-02-06 11:00:29 +0000
@@ -0,0 +1,127 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Gordon Allott <gord.allott@canonical.com>
18 */
19
20#ifndef UNITY_HUD_H
21#define UNITY_HUD_H
22
23#include <deque>
24#include <string>
25#include <memory>
26#include <NuxCore/Property.h>
27#include <glib/gvariant.h>
28
29namespace unity
30{
31namespace hud
32{
33
34
35class Query
36{
37public:
38 typedef std::shared_ptr<Query> Ptr;
39
40 Query(std::string const& formatted_text_, std::string const& icon_name_,
41 std::string const& item_icon_, std::string const& completion_text_,
42 std::string const& shortcut_, GVariant* key_)
43 : formatted_text(formatted_text_)
44 , icon_name(icon_name_)
45 , item_icon(item_icon_)
46 , completion_text(completion_text_)
47 , shortcut(shortcut_)
48 , key(key_)
49 {
50 g_variant_ref(key);
51 }
52
53 ~Query()
54 {
55 g_variant_unref(key);
56 }
57
58 Query(const Query &rhs);
59 Query& operator=(Query);
60
61 std::string formatted_text; // Pango formatted text
62 std::string icon_name; // icon name using standard lookups
63 std::string item_icon; // Future API
64 std::string completion_text; // Non formatted text f or completion
65 std::string shortcut; // Shortcut key
66 GVariant *key;
67};
68
69
70class HudImpl;
71class Hud
72{
73public:
74 typedef std::shared_ptr<Hud> Ptr;
75 typedef std::deque<Query::Ptr> Queries;
76
77 /*
78 * Constructor for the hud
79 * \param dbus_name string that specifies the name of the hud service
80 * \param dbus_path string that specifies the path of the hud service
81 */
82 Hud(std::string const& dbus_name,
83 std::string const& dbus_path);
84
85 ~Hud();
86
87 Hud(const Hud &rhs);
88 Hud& operator=(Hud);
89
90 nux::Property<std::string> target;
91 nux::Property<bool> connected;
92
93 /*
94 * Queries the service for new suggestions, will fire off the
95 * suggestion_search_finished signal when the suggestions are returned
96 */
97 void RequestQuery(std::string const& search_string);
98
99 /*
100 * Executes a Query
101 */
102 void ExecuteQuery(Query::Ptr query, unsigned int timestamp);
103
104 /*
105 * Executes a query that returns from a search,
106 * Implicitly calls CloseQuery();
107 */
108 void ExecuteQueryBySearch(std::string execute_string, unsigned int timestamp);
109
110 /*
111 * Closes the query connection, call when the hud closes
112 */
113 void CloseQuery();
114
115 /*
116 * Returns a deque of Query types when the service provides them
117 */
118 sigc::signal<void, Queries> queries_updated;
119
120private:
121 HudImpl *pimpl_;
122};
123
124}
125}
126
127#endif /* UNITY_HUD_H */
0128
=== added file 'manual-tests/Hud.txt'
--- manual-tests/Hud.txt 1970-01-01 00:00:00 +0000
+++ manual-tests/Hud.txt 2012-02-06 11:00:29 +0000
@@ -0,0 +1,57 @@
1For reference, the term Tap means to press the indicated key and release it, within a timeframe of 50ms
2
3Hud Invocate
4-----------
5This test makes sure that the hud presents itself, the launcher hides
6and the panel changes
7
8#. Tap Alt
9
10Outcome
11 The hud interface presents itself with no other interface such as the dash present.
12 The Launcher hides, the panel becomes transparent with a colour tint matching the hud
13
14Hud Search
15-----------
16This test makes sure that the hud will search and activate items.
17
18#. Ensure the devices indicator is present
19#. Tap Alt
20#. Type "system" to search for the "System settings..." item in the devices indicator
21#. Press return to activate the search query.
22
23Outcome
24 The system settings interface presents itself, the hud disappears.
25 If the hud does not disappear, this test failed. If the system settings interface
26 did not present itself, this test did *not* fail.
27
28
29Hud Key-Navigation
30-----------
31This test ensures the hud key navigation is intact
32
33#. Ensure the messaging indicator is present
34#. Tap Alt
35#. Type "Message" to search for items from the messaging indicator
36#. Press down twice
37#. Press return
38
39Outcome
40 The item selected will activate and the hud with disappear.
41 If the hud does not disappear, this test failed.
42 If the buttons under the search box do not highlight, this test failed.
43
44
45Hud Dismiss
46----------
47This test ensures that the hud is dismissable
48
49#. Tap Alt
50#. Type "test"
51#. Press escape
52#. Click anywhere on the screen that is not the hud interface
53
54Outcome
55 After pressing escape in step three, the text "test" should be removed from the hud search
56 After step four, the hud should dismiss itself and not be present.
57
058
=== modified file 'plugins/unityshell/src/DashController.cpp'
--- plugins/unityshell/src/DashController.cpp 2012-02-04 01:55:49 +0000
+++ plugins/unityshell/src/DashController.cpp 2012-02-06 11:00:29 +0000
@@ -118,6 +118,18 @@
118 sigc::mem_fun(this, &Controller::OnActivateRequest));118 sigc::mem_fun(this, &Controller::OnActivateRequest));
119 ubus_manager_.RegisterInterest(UBUS_DASH_ABOUT_TO_SHOW,119 ubus_manager_.RegisterInterest(UBUS_DASH_ABOUT_TO_SHOW,
120 [&] (GVariant*) { EnsureDash(); });120 [&] (GVariant*) { EnsureDash(); });
121 ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, [&] (GVariant *data) {
122 unity::glib::String overlay_identity;
123 gboolean can_maximise = FALSE;
124 gint32 overlay_monitor = 0;
125 g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, &overlay_identity, &can_maximise, &overlay_monitor);
126
127 // hide if something else is coming up
128 if (g_strcmp0(overlay_identity, "dash"))
129 {
130 HideDash(true);
131 }
132 });
121}133}
122134
123void Controller::EnsureDash()135void Controller::EnsureDash()
124136
=== modified file 'plugins/unityshell/src/DashStyle.cpp'
--- plugins/unityshell/src/DashStyle.cpp 2012-01-19 11:57:37 +0000
+++ plugins/unityshell/src/DashStyle.cpp 2012-02-06 11:00:29 +0000
@@ -119,6 +119,7 @@
119 void Text(cairo_t* cr,119 void Text(cairo_t* cr,
120 nux::Color const& color,120 nux::Color const& color,
121 std::string const& label,121 std::string const& label,
122 int font_size = -1,
122 double horizMargin = 10.0,123 double horizMargin = 10.0,
123 Alignment alignment = Alignment::CENTER);124 Alignment alignment = Alignment::CENTER);
124125
@@ -1325,6 +1326,7 @@
1325void Style::Impl::Text(cairo_t* cr,1326void Style::Impl::Text(cairo_t* cr,
1326 nux::Color const& color,1327 nux::Color const& color,
1327 std::string const& label,1328 std::string const& label,
1329 int text_size,
1328 double horizMargin,1330 double horizMargin,
1329 Alignment alignment)1331 Alignment alignment)
1330{1332{
@@ -1358,6 +1360,11 @@
1358 else1360 else
1359 desc = pango_font_description_from_string(fontName);1361 desc = pango_font_description_from_string(fontName);
13601362
1363 if (text_size > 0)
1364 {
1365 pango_font_description_set_absolute_size(desc, text_size * PANGO_SCALE);
1366 }
1367
1361 PangoWeight weight;1368 PangoWeight weight;
1362 switch (regular_text_weight_)1369 switch (regular_text_weight_)
1363 {1370 {
@@ -1428,6 +1435,7 @@
1428 pango_layout_get_extents(layout, &ink, &log);1435 pango_layout_get_extents(layout, &ink, &log);
1429 x = horizMargin; // let pango alignment handle the x position1436 x = horizMargin; // let pango alignment handle the x position
1430 y = ((double) h - pango_units_to_double(log.height)) / 2.0;1437 y = ((double) h - pango_units_to_double(log.height)) / 2.0;
1438
1431 cairo_move_to(cr, x, y);1439 cairo_move_to(cr, x, y);
1432 pango_cairo_show_layout(cr, layout);1440 pango_cairo_show_layout(cr, layout);
14331441
@@ -1530,7 +1538,9 @@
1530 cairo_set_operator(cr, old);1538 cairo_set_operator(cr, old);
1531}1539}
15321540
1533bool Style::Button(cairo_t* cr, nux::ButtonVisualState state, std::string const& label, Alignment alignment)1541bool Style::Button(cairo_t* cr, nux::ButtonVisualState state,
1542 std::string const& label, int font_size,
1543 Alignment alignment, bool zeromargin)
1534{1544{
1535 // sanity checks1545 // sanity checks
1536 if (cairo_status(cr) != CAIRO_STATUS_SUCCESS)1546 if (cairo_status(cr) != CAIRO_STATUS_SUCCESS)
@@ -1539,8 +1549,10 @@
1539 if (cairo_surface_get_type(cairo_get_target(cr)) != CAIRO_SURFACE_TYPE_IMAGE)1549 if (cairo_surface_get_type(cairo_get_target(cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1540 return false;1550 return false;
15411551
1542 unsigned int garnish = GetButtonGarnishSize();1552 unsigned int garnish = 0;
15431553 if (zeromargin == false)
1554 garnish = GetButtonGarnishSize();
1555
1544 //ButtonOutlinePath(cr, true);1556 //ButtonOutlinePath(cr, true);
1545 double w = cairo_image_surface_get_width(cairo_get_target(cr));1557 double w = cairo_image_surface_get_width(cairo_get_target(cr));
1546 double h = cairo_image_surface_get_height(cairo_get_target(cr));1558 double h = cairo_image_surface_get_height(cairo_get_target(cr));
@@ -1571,7 +1583,6 @@
1571 cairo_fill_preserve(cr);1583 cairo_fill_preserve(cr);
1572 }1584 }
1573 cairo_set_source_rgba(cr, pimpl->button_label_border_color_[state]);1585 cairo_set_source_rgba(cr, pimpl->button_label_border_color_[state]);
1574 //cairo_set_line_width(cr, pimpl->button_label_border_size_[state]);
1575 cairo_stroke(cr);1586 cairo_stroke(cr);
15761587
1577 pimpl->DrawOverlay(cr,1588 pimpl->DrawOverlay(cr,
@@ -1582,12 +1593,133 @@
1582 pimpl->Text(cr,1593 pimpl->Text(cr,
1583 pimpl->button_label_text_color_[state],1594 pimpl->button_label_text_color_[state],
1584 label,1595 label,
1596 font_size,
1585 10.0,1597 10.0,
1586 alignment);1598 alignment);
15871599
1588 return true;1600 return true;
1589}1601}
15901602
1603bool Style::SquareButton(cairo_t* cr, nux::ButtonVisualState state,
1604 std::string const& label, bool curve_bottom,
1605 int font_size, Alignment alignment,
1606 bool zeromargin)
1607{
1608 // sanity checks
1609 if (cairo_status(cr) != CAIRO_STATUS_SUCCESS)
1610 return false;
1611
1612 if (cairo_surface_get_type(cairo_get_target(cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1613 return false;
1614
1615 unsigned int garnish = 0;
1616 if (zeromargin == false)
1617 garnish = GetButtonGarnishSize();
1618
1619 double w = cairo_image_surface_get_width(cairo_get_target(cr));
1620 double h = cairo_image_surface_get_height(cairo_get_target(cr));
1621
1622 double x = garnish;
1623 double y = garnish;
1624
1625 double width = w - (2.0 * garnish) - 1.0;
1626 double height = h - (2.0 * garnish) - 1.0;
1627
1628 bool odd = true;
1629 double radius = 7.0;
1630
1631 // draw the grid background
1632 {
1633 cairo_set_line_width(cr, 1);
1634 cairo_move_to(cr, _align(x + width, odd), _align(y, odd));
1635 if (curve_bottom)
1636 {
1637 LOG_DEBUG(logger) << "curve: " << _align(x + width, odd) << " - " << _align(y + height - radius, odd);
1638 // line to bottom-right corner
1639 cairo_line_to(cr, _align(x + width, odd), _align(y + height - radius, odd));
1640
1641 // line to bottom-right, left of the corner
1642 cairo_arc(cr,
1643 _align(x + width - radius, odd),
1644 _align(y + height - radius, odd),
1645 radius,
1646 0.0f * G_PI / 180.0f,
1647 90.0f * G_PI / 180.0f);
1648
1649 // line to bottom-left, right of the corner
1650 cairo_line_to(cr, _align(x + radius, odd), _align(y + height, odd));
1651
1652 // line to bottom-left, above the corner
1653 cairo_arc(cr,
1654 _align(x + radius, odd),
1655 _align(y + height - radius, odd),
1656 radius,
1657 90.0f * G_PI / 180.0f,
1658 180.0f * G_PI / 180.0f);
1659
1660 // line to top
1661 cairo_line_to(cr, _align(x, odd), _align(y, odd));
1662 }
1663 else
1664 {
1665 cairo_line_to(cr, _align(x + width, odd), _align(y + height, odd));
1666 cairo_line_to(cr, _align(x, odd), _align(x + height, odd));
1667 cairo_line_to(cr, _align(x, odd), _align(y, odd));
1668 }
1669
1670 cairo_set_source_rgba(cr, pimpl->button_label_border_color_[nux::ButtonVisualState::VISUAL_STATE_NORMAL]);
1671 cairo_stroke(cr);
1672 }
1673
1674 cairo_set_line_width(cr, pimpl->button_label_border_size_[state]);
1675 odd = cairo_get_line_width(cr) == 2.0 ? false : true;
1676
1677
1678 if (pimpl->button_label_border_size_[state] == 2.0)
1679 {
1680 x += 1;
1681 y += 1;
1682 width -= 1.0;
1683 height -= 1.0;
1684 }
1685
1686 if (state == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
1687 {
1688 RoundedRect(cr,
1689 1.0,
1690 _align(x, odd), _align(y, odd),
1691 5.0,
1692 _align(width, odd), _align(height, odd));
1693
1694 if (pimpl->button_label_fill_color_[state].alpha != 0.0)
1695 {
1696 cairo_set_source_rgba(cr, pimpl->button_label_fill_color_[state]);
1697 cairo_fill_preserve(cr);
1698 }
1699 cairo_set_source_rgba(cr, pimpl->button_label_border_color_[state]);
1700 cairo_stroke(cr);
1701 }
1702
1703 pimpl->DrawOverlay(cr,
1704 pimpl->button_label_overlay_opacity_[state],
1705 pimpl->button_label_overlay_mode_[state],
1706 pimpl->button_label_blur_size_[state] * 0.75);
1707
1708 // FIXME - magic value of 42 here for the offset in the HUD,
1709 // replace with a nicer style system that lets hud override
1710 // default values when it needs to
1711 pimpl->Text(cr,
1712 pimpl->button_label_text_color_[state],
1713 label,
1714 font_size,
1715 42.0 + 10.0,
1716 alignment);
1717
1718 cairo_surface_write_to_png(cairo_get_target(cr), "/tmp/wut.png");
1719
1720 return true;
1721}
1722
1591bool Style::StarEmpty(cairo_t* cr, nux::ButtonVisualState state)1723bool Style::StarEmpty(cairo_t* cr, nux::ButtonVisualState state)
1592{1724{
1593 // sanity checks1725 // sanity checks
15941726
=== modified file 'plugins/unityshell/src/DashStyle.h'
--- plugins/unityshell/src/DashStyle.h 2012-01-19 11:51:57 +0000
+++ plugins/unityshell/src/DashStyle.h 2012-02-06 11:00:29 +0000
@@ -87,8 +87,15 @@
87 static Style& Instance();87 static Style& Instance();
8888
89 virtual bool Button(cairo_t* cr, nux::ButtonVisualState state,89 virtual bool Button(cairo_t* cr, nux::ButtonVisualState state,
90 std::string const& label,90 std::string const& label, int font_size=-1,
91 Alignment alignment = Alignment::CENTER); 91 Alignment alignment = Alignment::CENTER,
92 bool zeromargin=false);
93
94 virtual bool SquareButton(cairo_t* cr, nux::ButtonVisualState state,
95 std::string const& label, bool curve_bottom,
96 int font_size=-1,
97 Alignment alignment = Alignment::CENTER,
98 bool zeromargin=false);
9299
93 virtual bool StarEmpty(cairo_t* cr, nux::ButtonVisualState state);100 virtual bool StarEmpty(cairo_t* cr, nux::ButtonVisualState state);
94101
95102
=== modified file 'plugins/unityshell/src/DashView.h'
--- plugins/unityshell/src/DashView.h 2012-01-27 06:58:20 +0000
+++ plugins/unityshell/src/DashView.h 2012-02-06 11:00:29 +0000
@@ -30,7 +30,7 @@
30#include <UnityCore/HomeLens.h>30#include <UnityCore/HomeLens.h>
3131
32#include "BackgroundEffectHelper.h"32#include "BackgroundEffectHelper.h"
33#include "DashSearchBar.h"33#include "SearchBar.h"
34#include "Introspectable.h"34#include "Introspectable.h"
35#include "LensBar.h"35#include "LensBar.h"
36#include "LensView.h"36#include "LensView.h"
3737
=== modified file 'plugins/unityshell/src/FilterAllButton.cpp'
--- plugins/unityshell/src/FilterAllButton.cpp 2012-01-10 14:09:12 +0000
+++ plugins/unityshell/src/FilterAllButton.cpp 2012-02-06 11:00:29 +0000
@@ -59,6 +59,7 @@
59{59{
60 if (filter_ and Active())60 if (filter_ and Active())
61 filter_->Clear();61 filter_->Clear();
62 QueueDraw();
62}63}
6364
64void FilterAllButton::OnFilteringChanged(bool filtering)65void FilterAllButton::OnFilteringChanged(bool filtering)
6566
=== added file 'plugins/unityshell/src/HudButton.cpp'
--- plugins/unityshell/src/HudButton.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudButton.cpp 2012-02-06 11:00:29 +0000
@@ -0,0 +1,208 @@
1/*
2 * Copyright 2011 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser 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, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the applicable version of the GNU Lesser General Public
12 * License for more details.
13 *
14 * You should have received a copy of both the GNU Lesser General Public
15 * License version 3 along with this program. If not, see
16 * <http://www.gnu.org/licenses/>
17 *
18 * Authored by: Gordon Allott <gord.allott@canonical.com>
19 *
20 */
21#include "config.h"
22
23#include <pango/pango.h>
24#include <pango/pangocairo.h>
25#include <gdk/gdk.h>
26#include <gtk/gtk.h>
27
28#include <Nux/Nux.h>
29#include <NuxCore/Logger.h>
30#include <NuxImage/CairoGraphics.h>
31#include <NuxGraphics/NuxGraphics.h>
32#include <UnityCore/GLibWrapper.h>
33#include "DashStyle.h"
34
35#include "HudButton.h"
36
37namespace
38{
39nux::logging::Logger logger("unity.hud.HudButton");
40}
41
42namespace unity
43{
44namespace hud
45{
46
47
48HudButton::HudButton (nux::TextureArea *image, NUX_FILE_LINE_DECL)
49 : nux::Button (image, NUX_FILE_LINE_PARAM)
50 , is_rounded(false)
51 , is_focused_(false)
52{
53 InitTheme();
54 key_nav_focus_change.connect([this](nux::Area *area, bool recieving, nux::KeyNavDirection direction){ QueueDraw(); });
55}
56
57HudButton::HudButton (const std::string label_, NUX_FILE_LINE_DECL)
58 : nux::Button (NUX_FILE_LINE_PARAM)
59 , is_rounded(false)
60 , is_focused_(false)
61{
62 InitTheme();
63}
64
65HudButton::HudButton (const std::string label_, nux::TextureArea *image, NUX_FILE_LINE_DECL)
66 : nux::Button (image, NUX_FILE_LINE_PARAM)
67 , is_rounded(false)
68 , is_focused_(false)
69{
70 InitTheme();
71}
72
73HudButton::HudButton (NUX_FILE_LINE_DECL)
74 : nux::Button (NUX_FILE_LINE_PARAM)
75 , is_rounded(false)
76 , is_focused_(false)
77{
78 InitTheme();
79}
80
81HudButton::~HudButton() {
82}
83
84void HudButton::InitTheme()
85{
86 is_rounded.changed.connect([&] (bool rounded)
87 {
88 nux::Geometry geo = GetGeometry();
89 prelight_->Invalidate(geo);
90 active_->Invalidate(geo);
91 normal_->Invalidate(geo);
92 });
93
94 SetMinimumHeight(42);
95 if (!active_)
96 {
97 nux::Geometry const& geo = GetGeometry();
98
99 prelight_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
100 active_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
101 normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
102 }
103}
104
105void HudButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
106{
107 dash::Style::Instance().SquareButton(cr, faked_state, label_,
108 is_rounded, 17,
109 dash::Alignment::LEFT, true);
110}
111
112bool HudButton::AcceptKeyNavFocus()
113{
114 return true;
115}
116
117
118long HudButton::ComputeContentSize ()
119{
120 long ret = nux::Button::ComputeContentSize();
121 nux::Geometry const& geo = GetGeometry();
122
123 if (cached_geometry_ != geo)
124 {
125 prelight_->Invalidate(geo);
126 active_->Invalidate(geo);
127 normal_->Invalidate(geo);
128
129 cached_geometry_ = geo;
130 }
131
132 return ret;
133}
134
135void HudButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
136{
137 nux::Geometry const& geo = GetGeometry();
138 gPainter.PaintBackground(GfxContext, geo);
139 // set up our texture mode
140 nux::TexCoordXForm texxform;
141 texxform.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP);
142 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
143
144 // clear what is behind us
145 unsigned int alpha = 0, src = 0, dest = 0;
146 GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
147 GfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
148 GfxContext.GetRenderStates().SetBlend(true);
149
150 nux::Color col = nux::color::Black;
151 col.alpha = 0;
152 GfxContext.QRP_Color(geo.x,
153 geo.y,
154 geo.width,
155 geo.height,
156 col);
157
158 nux::BaseTexture* texture = normal_->GetTexture();
159 if (HasKeyFocus())
160 texture = active_->GetTexture();
161 else if (HasKeyFocus())
162 texture = prelight_->GetTexture();
163 else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
164 texture = active_->GetTexture();
165
166 GfxContext.QRP_1Tex(geo.x,
167 geo.y,
168 texture->GetWidth() + 1, // FIXME !! - jay, nux has gone crazy, unless i specify +1 here, it won't render the entire texture
169 texture->GetHeight(),
170 texture->GetDeviceTexture(),
171 texxform,
172 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
173
174 GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
175}
176
177void HudButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
178}
179
180void HudButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
181 nux::Button::PostDraw(GfxContext, force_draw);
182}
183
184void HudButton::SetQuery(Query::Ptr query)
185{
186 query_ = query;
187 label_ = query->formatted_text;
188 label = query->formatted_text;
189}
190
191Query::Ptr HudButton::GetQuery()
192{
193 return query_;
194}
195
196// Introspectable
197std::string HudButton::GetName() const
198{
199 return "HudButton";
200}
201
202void HudButton::AddProperties(GVariantBuilder* builder)
203{
204 g_variant_builder_add(builder, "{sv}", "label", g_variant_new_string(label_.c_str()));
205}
206
207}
208}
0209
=== added file 'plugins/unityshell/src/HudButton.h'
--- plugins/unityshell/src/HudButton.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudButton.h 2012-02-06 11:00:29 +0000
@@ -0,0 +1,81 @@
1/*
2 * Copyright 2011 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser 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, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the applicable version of the GNU Lesser General Public
12 * License for more details.
13 *
14 * You should have received a copy of both the GNU Lesser General Public
15 * License version 3 along with this program. If not, see
16 * <http://www.gnu.org/licenses/>
17 *
18 * Authored by: Gordon Allott <gord.allott@canonical.com>
19 *
20 */
21
22
23
24#ifndef FILTERBASICBUTTON_H
25#define FILTERBASICBUTTON_H
26
27#include <Nux/Nux.h>
28#include <Nux/CairoWrapper.h>
29#include <Nux/Button.h>
30#include <Nux/TextureArea.h>
31#include <UnityCore/Hud.h>
32#include "Introspectable.h"
33
34namespace unity {
35namespace hud {
36class HudButton : public nux::Button, public unity::debug::Introspectable
37{
38 typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
39public:
40 typedef nux::ObjectPtr<HudButton> Ptr;
41 HudButton (nux::TextureArea *image, NUX_FILE_LINE_PROTO);
42 HudButton (const std::string label, NUX_FILE_LINE_PROTO);
43 HudButton (const std::string label, nux::TextureArea *image, NUX_FILE_LINE_PROTO);
44 HudButton (NUX_FILE_LINE_PROTO);
45 virtual ~HudButton();
46
47 void SetQuery(Query::Ptr query);
48 std::shared_ptr<Query> GetQuery();
49
50 nux::Property<std::string> label;
51 nux::Property<std::string> hint;
52 nux::Property<bool> is_rounded;
53protected:
54
55 virtual bool AcceptKeyNavFocus();
56 virtual long ComputeContentSize();
57 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
58 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
59 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
60
61 std::string GetName() const;
62 void AddProperties(GVariantBuilder* builder);
63
64 void InitTheme ();
65 void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state);
66 typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr;
67
68 NuxCairoPtr prelight_;
69 NuxCairoPtr active_;
70 NuxCairoPtr normal_;
71
72private:
73 std::string label_;
74
75 Query::Ptr query_;
76 nux::Geometry cached_geometry_;
77 bool is_focused_;
78};
79}
80}
81#endif // FILTERBASICBUTTON_H
082
=== added file 'plugins/unityshell/src/HudController.cpp'
--- plugins/unityshell/src/HudController.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudController.cpp 2012-02-06 11:00:29 +0000
@@ -0,0 +1,385 @@
1/*
2 * Copyright (C) 2010 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: Gord Allott <gord.allott@canonical.com>
17 */
18
19#include "HudController.h"
20
21#include <NuxCore/Logger.h>
22#include <Nux/HLayout.h>
23#include "PluginAdapter.h"
24#include "UBusMessages.h"
25#include "UScreen.h"
26namespace unity
27{
28namespace hud
29{
30
31namespace
32{
33nux::logging::Logger logger("unity.hud.controller");
34}
35
36Controller::Controller()
37 : launcher_width(66)
38 , panel_height(24)
39 , hud_service_("com.canonical.hud", "/com/canonical/hud")
40 , window_(0)
41 , visible_(false)
42 , need_show_(false)
43 , timeline_id_(0)
44 , last_opacity_(0.0f)
45 , start_time_(0)
46{
47 LOG_DEBUG(logger) << "hud startup";
48 SetupRelayoutCallbacks();
49
50 ubus.RegisterInterest(UBUS_HUD_CLOSE_REQUEST, sigc::mem_fun(this, &Controller::OnExternalHideHud));
51
52 //!!FIXME!! - just hijacks the dash close request so we get some more requests than normal,
53 ubus.RegisterInterest(UBUS_PLACE_VIEW_CLOSE_REQUEST, sigc::mem_fun(this, &Controller::OnExternalHideHud));
54
55 ubus.RegisterInterest(UBUS_OVERLAY_SHOWN, [&] (GVariant *data) {
56 unity::glib::String overlay_identity;
57 gboolean can_maximise = FALSE;
58 gint32 overlay_monitor = 0;
59 g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, &overlay_identity, &can_maximise, &overlay_monitor);
60
61 if (g_strcmp0(overlay_identity, "hud"))
62 {
63 HideHud(true);
64 }
65 });
66
67 PluginAdapter::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &Controller::OnScreenUngrabbed));
68
69 hud_service_.queries_updated.connect(sigc::mem_fun(this, &Controller::OnQueriesFinished));
70 EnsureHud();
71}
72
73Controller::~Controller()
74{
75 if (window_)
76 window_->UnReference();
77 window_ = 0;
78
79 g_source_remove(timeline_id_);
80 g_source_remove(ensure_id_);
81}
82
83void Controller::SetupWindow()
84{
85 window_ = new nux::BaseWindow("Hud");
86 window_->SinkReference();
87 window_->SetBackgroundColor(nux::Color(0.0f, 0.0f, 0.0f, 0.0f));
88 window_->SetConfigureNotifyCallback(&Controller::OnWindowConfigure, this);
89 window_->ShowWindow(false);
90 window_->SetOpacity(0.0f);
91 window_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow));
92}
93
94void Controller::SetupHudView()
95{
96 LOG_DEBUG(logger) << "SetupHudView called";
97 view_ = new View();
98
99 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
100 layout_->AddView(view_, 1);
101 window_->SetLayout(layout_);
102
103 view_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow));
104
105 LOG_DEBUG(logger) << "connecting to signals";
106 view_->search_changed.connect(sigc::mem_fun(this, &Controller::OnSearchChanged));
107 view_->search_activated.connect(sigc::mem_fun(this, &Controller::OnSearchActivated));
108 view_->query_activated.connect(sigc::mem_fun(this, &Controller::OnQueryActivated));
109 view_->query_selected.connect(sigc::mem_fun(this, &Controller::OnQuerySelected));
110}
111
112void Controller::SetupRelayoutCallbacks()
113{
114 GdkScreen* screen = gdk_screen_get_default();
115
116 sig_manager_.Add(new glib::Signal<void, GdkScreen*>(screen,
117 "monitors-changed", sigc::mem_fun(this, &Controller::Relayout)));
118 sig_manager_.Add(new glib::Signal<void, GdkScreen*>(screen,
119 "size-changed", sigc::mem_fun(this, &Controller::Relayout)));
120}
121
122void Controller::EnsureHud()
123{
124 if (window_)
125 return;
126
127 LOG_DEBUG(logger) << "Initializing Hud";
128
129 SetupWindow();
130 SetupHudView();
131 Relayout();
132 ensure_id_ = 0;
133}
134
135nux::BaseWindow* Controller::window() const
136{
137 return window_;
138}
139
140// We update the @geo that's sent in with our desired width and height
141void Controller::OnWindowConfigure(int window_width, int window_height,
142 nux::Geometry& geo, void* data)
143{
144 Controller* self = static_cast<Controller*>(data);
145 geo = self->GetIdealWindowGeometry();
146}
147
148nux::Geometry Controller::GetIdealWindowGeometry()
149{
150 UScreen *uscreen = UScreen::GetDefault();
151 int primary_monitor = uscreen->GetPrimaryMonitor();
152 auto monitor_geo = uscreen->GetMonitorGeometry(primary_monitor);
153
154 // We want to cover as much of the screen as possible to grab any mouse events outside
155 // of our window
156 return nux::Geometry (monitor_geo.x,
157 monitor_geo.y + panel_height,
158 monitor_geo.width,
159 monitor_geo.height - panel_height);
160}
161
162void Controller::Relayout(GdkScreen*screen)
163{
164 EnsureHud();
165 nux::Geometry content_geo = view_->GetGeometry();
166 nux::Geometry geo = GetIdealWindowGeometry();
167
168 window_->SetGeometry(geo);
169 layout_->SetMinMaxSize(content_geo.width, content_geo.height);
170 view_->SetWindowGeometry(window_->GetAbsoluteGeometry(), window_->GetGeometry());
171 view_->Relayout();
172}
173
174void Controller::OnMouseDownOutsideWindow(int x, int y,
175 unsigned long bflags, unsigned long kflags)
176{
177 LOG_DEBUG(logger) << "OnMouseDownOutsideWindow called";
178 HideHud();
179}
180
181void Controller::OnScreenUngrabbed()
182{
183 LOG_DEBUG(logger) << "OnScreenUngrabbed called";
184 if (need_show_)
185 {
186 EnsureHud();
187 ShowHud();
188 }
189}
190
191void Controller::OnExternalShowHud(GVariant* variant)
192{
193 EnsureHud();
194 visible_ ? HideHud() : ShowHud();
195}
196
197void Controller::OnExternalHideHud(GVariant* variant)
198{
199 LOG_DEBUG(logger) << "External Hiding the hud";
200 EnsureHud();
201 HideHud();
202}
203
204void Controller::ShowHideHud()
205{
206 EnsureHud();
207 visible_ ? HideHud(true) : ShowHud();
208}
209
210bool Controller::IsVisible()
211{
212 return visible_;
213}
214
215void Controller::ShowHud()
216{
217 LOG_DEBUG(logger) << "Showing the hud";
218 EnsureHud();
219 view_->AboutToShow();
220
221 window_->ShowWindow(true);
222 window_->PushToFront();
223 window_->EnableInputWindow(true, "Hud", true, false);
224 window_->SetInputFocus();
225 nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus());
226 window_->CaptureMouseDownAnyWhereElse(true);
227 view_->CaptureMouseDownAnyWhereElse(true);
228 window_->QueueDraw();
229
230 view_->ResetToDefault();
231
232 view_->SetIcon("");
233 hud_service_.RequestQuery("");
234 need_show_ = false;
235 visible_ = true;
236
237 StartShowHideTimeline();
238 view_->SetWindowGeometry(window_->GetAbsoluteGeometry(), window_->GetGeometry());
239
240 // hide the launcher
241 GVariant* message_data = g_variant_new("(b)", TRUE);
242 ubus.SendMessage(UBUS_LAUNCHER_LOCK_HIDE, message_data);
243
244 GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "hud", FALSE, 0);
245 ubus.SendMessage(UBUS_OVERLAY_SHOWN, info);
246}
247void Controller::HideHud(bool restore)
248{
249 LOG_DEBUG (logger) << "hiding the hud";
250 if (visible_ == false)
251 return;
252
253 EnsureHud();
254 view_->AboutToHide();
255 window_->CaptureMouseDownAnyWhereElse(false);
256 window_->EnableInputWindow(false, "Hud", true, false);
257 visible_ = false;
258
259 StartShowHideTimeline();
260
261 restore = true;
262 if (restore)
263 PluginAdapter::Default ()->restoreInputFocus ();
264
265 hud_service_.CloseQuery();
266
267 //unhide the launcher
268 GVariant* message_data = g_variant_new("(b)", FALSE);
269 ubus.SendMessage(UBUS_LAUNCHER_LOCK_HIDE, message_data);
270
271 GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "hud", FALSE, 0);
272 ubus.SendMessage(UBUS_OVERLAY_HIDDEN, info);
273}
274
275void Controller::StartShowHideTimeline()
276{
277 EnsureHud();
278
279 if (timeline_id_)
280 g_source_remove(timeline_id_);
281
282 timeline_id_ = g_timeout_add(15, (GSourceFunc)Controller::OnViewShowHideFrame, this);
283 last_opacity_ = window_->GetOpacity();
284 start_time_ = g_get_monotonic_time();
285
286}
287
288gboolean Controller::OnViewShowHideFrame(Controller* self)
289{
290#define _LENGTH_ 90000
291 float diff = g_get_monotonic_time() - self->start_time_;
292 float progress = diff / (float)_LENGTH_;
293 float last_opacity = self->last_opacity_;
294
295 if (self->visible_)
296 {
297 self->window_->SetOpacity(last_opacity + ((1.0f - last_opacity) * progress));
298 }
299 else
300 {
301 self->window_->SetOpacity(last_opacity - (last_opacity * progress));
302 }
303
304 if (diff > _LENGTH_)
305 {
306 self->timeline_id_ = 0;
307
308 // Make sure the state is right
309 self->window_->SetOpacity(self->visible_ ? 1.0f : 0.0f);
310 if (!self->visible_)
311 {
312 self->window_->ShowWindow(false);
313 }
314
315 return FALSE;
316 }
317
318 return TRUE;
319}
320
321void Controller::OnActivateRequest(GVariant* variant)
322{
323 EnsureHud();
324 ShowHud();
325}
326
327void Controller::OnSearchChanged(std::string search_string)
328{
329 LOG_DEBUG(logger) << "Search Changed";
330 hud_service_.RequestQuery(search_string);
331}
332
333void Controller::OnSearchActivated(std::string search_string)
334{
335 unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp;
336 hud_service_.ExecuteQueryBySearch(search_string, timestamp);
337 HideHud();
338}
339
340void Controller::OnQueryActivated(Query::Ptr query)
341{
342 LOG_DEBUG(logger) << "Activating query, " << query->formatted_text;
343 unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp;
344 hud_service_.ExecuteQuery(query, timestamp);
345 HideHud();
346}
347
348void Controller::OnQuerySelected(Query::Ptr query)
349{
350 LOG_DEBUG(logger) << "Selected query, " << query->formatted_text;
351 view_->SetIcon(query->icon_name);
352}
353
354
355void Controller::OnQueriesFinished(Hud::Queries queries)
356{
357 view_->SetQueries(queries);
358 std::string icon_name = "";
359 for (auto query = queries.begin(); query != queries.end(); query++)
360 {
361 if (!(*query)->icon_name.empty())
362 {
363 icon_name = (*query)->icon_name;
364 break;
365 }
366 }
367
368 LOG_DEBUG(logger) << "setting icon to - " << icon_name;
369 view_->SetIcon(icon_name);
370}
371
372// Introspectable
373std::string Controller::GetName() const
374{
375 return "HudController";
376}
377
378void Controller::AddProperties(GVariantBuilder* builder)
379{
380 g_variant_builder_add(builder, "{sv}", "visible", g_variant_new_boolean (visible_));
381}
382
383
384}
385}
0386
=== added file 'plugins/unityshell/src/HudController.h'
--- plugins/unityshell/src/HudController.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudController.h 2012-02-06 11:00:29 +0000
@@ -0,0 +1,113 @@
1/*
2 * Copyright (C) 2010 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: Neil Jagdish Patel <neil.patel@canonical.com>
17 */
18
19#ifndef UNITY_HUD_CONTROLLER_H_
20#define UNITY_HUD_CONTROLLER_H_
21
22#include <memory>
23
24#include <gdk/gdk.h>
25#include <UnityCore/GLibSignal.h>
26#include <UnityCore/Hud.h>
27
28#include <NuxCore/Property.h>
29#include <NuxGraphics/GraphicsEngine.h>
30#include <Nux/Nux.h>
31#include <Nux/BaseWindow.h>
32
33#include "HudView.h"
34#include "UBusWrapper.h"
35
36namespace unity
37{
38namespace hud
39{
40
41class Controller : public unity::debug::Introspectable
42{
43public:
44 typedef std::shared_ptr<Controller> Ptr;
45
46 Controller();
47 ~Controller();
48
49 nux::BaseWindow* window() const;
50
51 nux::Property<int> launcher_width;
52 nux::Property<int> panel_height;
53
54 void ShowHideHud();
55 void ShowHud();
56 void HideHud(bool restore_focus = true);
57 bool IsVisible();
58protected:
59 std::string GetName() const;
60 void AddProperties(GVariantBuilder* builder);
61
62private:
63 void EnsureHud();
64 void SetupWindow();
65 void SetupHudView();
66 void SetupRelayoutCallbacks();
67 void RegisterUBusInterests();
68
69 nux::Geometry GetIdealWindowGeometry();
70 void Relayout(GdkScreen*screen=NULL);
71
72 void OnMouseDownOutsideWindow(int x, int y, unsigned long bflags, unsigned long kflags);
73 void OnScreenUngrabbed();
74 void OnExternalShowHud(GVariant* variant);
75 void OnExternalHideHud(GVariant* variant);
76 void OnActivateRequest(GVariant* variant);
77
78 void OnSearchChanged(std::string search_string);
79 void OnSearchActivated(std::string search_string);
80 void OnQueryActivated(Query::Ptr query);
81 void OnQuerySelected(Query::Ptr query);
82
83
84private:
85 void StartShowHideTimeline();
86 static gboolean OnViewShowHideFrame(Controller* self);
87
88 static void OnWindowConfigure(int width, int height, nux::Geometry& geo, void* data);
89
90 void OnQueriesFinished(Hud::Queries queries);
91
92private:
93 UBusManager ubus;
94 Hud hud_service_;
95 glib::SignalManager sig_manager_;
96 nux::BaseWindow* window_;
97 bool visible_;
98 bool need_show_;
99
100 guint timeline_id_;
101 float last_opacity_;
102 gint64 start_time_;
103
104 View* view_;
105 guint ensure_id_;
106
107 nux::Layout* layout_;
108};
109
110
111}
112}
113#endif
0114
=== added file 'plugins/unityshell/src/HudIcon.cpp'
--- plugins/unityshell/src/HudIcon.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudIcon.cpp 2012-02-06 11:00:29 +0000
@@ -0,0 +1,95 @@
1/*
2 * Copyright (C) 2010 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: Gord Allott <gord.allott@canonical.com>
17 */
18
19
20#include "HudIcon.h"
21#include "NuxCore/Logger.h"
22namespace
23{
24 nux::logging::Logger logger("unity.hud.icon");
25}
26
27namespace unity
28{
29namespace hud
30{
31
32Icon::Icon(nux::BaseTexture* texture, guint width, guint height)
33 : unity::IconTexture(texture, width, height)
34{
35 Init();
36 icon_renderer_.SetTargetSize(54, 46, 0);
37}
38
39Icon::Icon(const char* icon_name, unsigned int size, bool defer_icon_loading)
40 : unity::IconTexture(icon_name, size, defer_icon_loading)
41{
42 Init();
43}
44
45Icon::~Icon()
46{
47}
48
49void Icon::Init()
50{
51 SetMinimumWidth(66);
52 SetMinimumHeight(66);
53 background_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_back_54.png", -1, true);
54 gloss_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_shine_54.png", -1, true);
55 edge_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_edge_54.png", -1, true);
56
57 texture_updated.connect([&] (nux::BaseTexture* texture)
58 {
59 icon_texture_source_ = new HudIconTextureSource(nux::ObjectPtr<nux::BaseTexture>(texture));
60 icon_texture_source_->ColorForIcon(_pixbuf_cached);
61 QueueDraw();
62 LOG_DEBUG(logger) << "got our texture";
63 });
64}
65
66void Icon::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
67{
68 if (texture() == nullptr)
69 return;
70
71 unity::ui::RenderArg arg;
72 arg.icon = icon_texture_source_.GetPointer();
73 arg.colorify = nux::color::White;
74 arg.running_arrow = true;
75 arg.running_on_viewport = true;
76 arg.render_center = nux::Point3(32, 32, 0);
77 arg.logical_center = nux::Point3(52, 50, 0);
78 arg.window_indicators = true;
79 arg.backlight_intensity = 1.0f;
80 arg.alpha = 1.0f;
81
82 std::list<unity::ui::RenderArg> args;
83 args.push_front(arg);
84
85
86 auto toplevel = GetToplevel();
87 icon_renderer_.SetTargetSize(54, 46, 0);
88 icon_renderer_.PreprocessIcons(args, toplevel->GetGeometry());
89 icon_renderer_.RenderIcon(GfxContext, arg, toplevel->GetGeometry(), toplevel->GetGeometry());
90}
91
92
93}
94}
95
096
=== added file 'plugins/unityshell/src/HudIcon.h'
--- plugins/unityshell/src/HudIcon.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudIcon.h 2012-02-06 11:00:29 +0000
@@ -0,0 +1,73 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2010 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Gord Allott <gord.allott@canonical.com>
18 *
19 */
20
21#ifndef HUDICON_H
22#define HUDICON_H
23
24#include <set>
25#include <string>
26
27#include "config.h"
28
29#include <Nux/Nux.h>
30#include <Nux/BaseWindow.h>
31#include <NuxCore/Math/MathInc.h>
32
33#include <sigc++/trackable.h>
34#include <sigc++/signal.h>
35#include <sigc++/functors/ptr_fun.h>
36#include <sigc++/functors/mem_fun.h>
37
38#include <gtk/gtk.h>
39
40#include "IconTexture.h"
41#include "HudIconTextureSource.h"
42#include "IconRenderer.h"
43#include "Introspectable.h"
44
45namespace unity
46{
47namespace hud
48{
49
50class Icon : public unity::IconTexture
51{
52public:
53 typedef nux::ObjectPtr<IconTexture> Ptr;
54 Icon(nux::BaseTexture* texture, guint width, guint height);
55 Icon(const char* icon_name, unsigned int size, bool defer_icon_loading = false);
56 ~Icon();
57
58protected:
59 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
60 void Init();
61
62 nux::ObjectPtr<nux::BaseTexture> background_;
63 nux::ObjectPtr<nux::BaseTexture> gloss_;
64 nux::ObjectPtr<nux::BaseTexture> edge_;
65 nux::ObjectPtr<HudIconTextureSource> icon_texture_source_;
66 unity::ui::IconRenderer icon_renderer_;
67};
68
69}
70
71}
72
73#endif /* HUDICON_H */
074
=== added file 'plugins/unityshell/src/HudIconTextureSource.cpp'
--- plugins/unityshell/src/HudIconTextureSource.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudIconTextureSource.cpp 2012-02-06 11:00:29 +0000
@@ -0,0 +1,110 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Gordon Allott <gord.allott@canonical.com>
18 */
19
20
21#include "HudIconTextureSource.h"
22#include "config.h"
23
24#include <glib.h>
25
26#include <Nux/Nux.h>
27#include <NuxCore/Logger.h>
28
29
30namespace unity
31{
32namespace hud
33{
34
35HudIconTextureSource::HudIconTextureSource(nux::ObjectPtr<nux::BaseTexture> texture)
36 : unity::ui::IconTextureSource()
37 , icon_texture_(texture)
38{
39}
40
41HudIconTextureSource::~HudIconTextureSource()
42{
43}
44
45void HudIconTextureSource::ColorForIcon(GdkPixbuf* pixbuf)
46{
47 unsigned int width = gdk_pixbuf_get_width(pixbuf);
48 unsigned int height = gdk_pixbuf_get_height(pixbuf);
49 unsigned int row_bytes = gdk_pixbuf_get_rowstride(pixbuf);
50
51 long int rtotal = 0, gtotal = 0, btotal = 0;
52 float total = 0.0f;
53
54 guchar* img = gdk_pixbuf_get_pixels(pixbuf);
55
56 for (unsigned int i = 0; i < width; i++)
57 {
58 for (unsigned int j = 0; j < height; j++)
59 {
60 guchar* pixels = img + (j * row_bytes + i * 4);
61 guchar r = *(pixels + 0);
62 guchar g = *(pixels + 1);
63 guchar b = *(pixels + 2);
64 guchar a = *(pixels + 3);
65
66 float saturation = (MAX(r, MAX(g, b)) - MIN(r, MIN(g, b))) / 255.0f;
67 float relevance = .1 + .9 * (a / 255.0f) * saturation;
68
69 rtotal += (guchar)(r * relevance);
70 gtotal += (guchar)(g * relevance);
71 btotal += (guchar)(b * relevance);
72
73 total += relevance * 255;
74 }
75 }
76
77 nux::color::RedGreenBlue rgb(rtotal / total,
78 gtotal / total,
79 btotal / total);
80 nux::color::HueSaturationValue hsv(rgb);
81
82 if (hsv.saturation > 0.15f)
83 hsv.saturation = 0.65f;
84
85 hsv.value = 0.90f;
86 bg_color = nux::Color(nux::color::RedGreenBlue(hsv));
87}
88
89nux::Color HudIconTextureSource::BackgroundColor()
90{
91 return bg_color;
92}
93
94nux::BaseTexture* HudIconTextureSource::TextureForSize(int size)
95{
96 return icon_texture_.GetPointer();
97}
98
99nux::Color HudIconTextureSource::GlowColor()
100{
101 return nux::Color(0.0f, 0.0f, 0.0f, 0.0f);
102}
103
104nux::BaseTexture* HudIconTextureSource::Emblem()
105{
106 return nullptr;
107}
108
109}
110}
0\ No newline at end of file111\ No newline at end of file
1112
=== added file 'plugins/unityshell/src/HudIconTextureSource.h'
--- plugins/unityshell/src/HudIconTextureSource.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudIconTextureSource.h 2012-02-06 11:00:29 +0000
@@ -0,0 +1,51 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Gordon Allott <gord.allott@canonical.com>
18 */
19
20
21#ifndef HUDICONTEXTURESOURCE_H
22#define HUDICONTEXTURESOURCE_H
23
24#include "IconTextureSource.h"
25
26namespace unity
27{
28namespace hud
29{
30
31class HudIconTextureSource : public unity::ui::IconTextureSource
32{
33public:
34 HudIconTextureSource(nux::ObjectPtr<nux::BaseTexture> texture);
35 ~HudIconTextureSource();
36
37 virtual nux::Color BackgroundColor();
38 virtual nux::BaseTexture* TextureForSize(int size);
39 virtual nux::Color GlowColor();
40 virtual nux::BaseTexture* Emblem();
41 void ColorForIcon(GdkPixbuf* pixbuf);
42
43private:
44 nux::Color bg_color;
45 nux::ObjectPtr<nux::BaseTexture> icon_texture_;
46};
47
48}
49}
50
51#endif // HUDICONTEXTURESOURCE_H
052
=== added file 'plugins/unityshell/src/HudView.cpp'
--- plugins/unityshell/src/HudView.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudView.cpp 2012-02-06 11:00:29 +0000
@@ -0,0 +1,398 @@
1/*
2 * Copyright (C) 2010 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: Gord Allott <gord.allott@canonical.com>
17 */
18
19#include "HudView.h"
20
21#include <math.h>
22
23#include <gio/gdesktopappinfo.h>
24#include <glib/gi18n-lib.h>
25#include <gtk/gtk.h>
26#include <Nux/Button.h>
27#include <iostream>
28#include <sstream>
29
30#include <NuxCore/Logger.h>
31#include <UnityCore/GLibWrapper.h>
32#include <UnityCore/RadioOptionFilter.h>
33#include <Nux/HLayout.h>
34#include <Nux/LayeredLayout.h>
35
36#include <NuxCore/Logger.h>
37#include "HudButton.h"
38#include "UBusMessages.h"
39#include "DashStyle.h"
40
41namespace unity
42{
43namespace hud
44{
45
46namespace
47{
48nux::logging::Logger logger("unity.hud.view");
49int icon_size = 42;
50const std::string default_text = _("Type your command");
51}
52
53NUX_IMPLEMENT_OBJECT_TYPE(View);
54
55View::View()
56 : nux::View(NUX_TRACKER_LOCATION)
57 , button_views_(NULL)
58{
59 renderer_.SetOwner(this);
60 renderer_.need_redraw.connect([this] () {
61 QueueDraw();
62 });
63
64 nux::ROPConfig rop;
65 rop.Blend = true;
66 rop.SrcBlend = GL_ONE;
67 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
68
69 SetupViews();
70 search_bar_->key_down.connect (sigc::mem_fun (this, &View::OnKeyDown));
71
72 search_bar_->activated.connect ([&]() {
73 search_activated.emit(search_bar_->search_string);
74 });
75
76 mouse_down.connect(sigc::mem_fun(this, &View::OnMouseButtonDown));
77
78 Relayout();
79
80}
81
82View::~View()
83{
84 RemoveChild(search_bar_.GetPointer());
85 for (auto button = buttons_.begin(); button != buttons_.end(); button++)
86 {
87 RemoveChild((*button).GetPointer());
88 }
89}
90
91void View::ResetToDefault()
92{
93 search_bar_->search_string = "";
94 search_bar_->search_hint = default_text;
95}
96
97void View::Relayout()
98{
99 nux::Geometry geo = GetGeometry();
100 content_geo_ = GetBestFitGeometry(geo);
101 LOG_DEBUG(logger) << "content_geo: " << content_geo_.width << "x" << content_geo_.height;
102
103 layout_->SetMinMaxSize(content_geo_.width, content_geo_.height);
104
105 QueueDraw();
106}
107
108long View::PostLayoutManagement(long LayoutResult)
109{
110 Relayout();
111 return LayoutResult;
112}
113
114
115nux::View* View::default_focus() const
116{
117 return search_bar_->text_entry();
118}
119
120void View::SetQueries(Hud::Queries queries)
121{
122 // remove the previous children
123 for (auto button = buttons_.begin(); button != buttons_.end(); button++)
124 {
125 RemoveChild((*button).GetPointer());
126 }
127
128 queries_ = queries_;
129 buttons_.clear();
130 button_views_->Clear();
131 int found_items = 0;
132 for (auto query = queries.begin(); query != queries.end(); query++)
133 {
134 if (found_items > 5)
135 break;
136
137 HudButton::Ptr button = HudButton::Ptr(new HudButton());
138 buttons_.push_front(button);
139 button->SetQuery(*query);
140 button_views_->AddView(button.GetPointer(), 0, nux::MINOR_POSITION_LEFT);
141
142 button->click.connect([&](nux::View* view) {
143 query_activated.emit(dynamic_cast<HudButton*>(view)->GetQuery());
144 });
145
146 button->key_nav_focus_activate.connect([&](nux::Area *area) {
147 query_activated.emit(dynamic_cast<HudButton*>(area)->GetQuery());
148 });
149
150 button->key_nav_focus_change.connect([&](nux::Area *area, bool recieving, KeyNavDirection direction){
151 if (recieving)
152 query_selected.emit(dynamic_cast<HudButton*>(area)->GetQuery());
153 });
154
155 button->is_rounded = (query == --(queries.end())) ? true : false;
156 button->SetMinimumWidth(941);
157 found_items++;
158 }
159
160 QueueRelayout();
161 QueueDraw();
162}
163
164void View::SetIcon(std::string icon_name)
165{
166 LOG_DEBUG(logger) << "Setting icon to " << icon_name;
167 icon_->SetByIconName(icon_name.c_str(), icon_size);
168 QueueDraw();
169}
170
171// Gives us the width and height of the contents that will give us the best "fit",
172// which means that the icons/views will not have uneccessary padding, everything will
173// look tight
174nux::Geometry View::GetBestFitGeometry(nux::Geometry const& for_geo)
175{
176 //FIXME - remove magic values, replace with scalable text depending on DPI
177 // requires smarter font settings really...
178 int width, height = 0;
179 width = 1024;
180 height = 276;
181
182 LOG_DEBUG (logger) << "best fit is, " << width << ", " << height;
183
184 return nux::Geometry(0, 0, width, height);
185}
186
187void View::AboutToShow()
188{
189 renderer_.AboutToShow();
190}
191
192void View::AboutToHide()
193{
194 renderer_.AboutToHide();
195}
196
197void View::SetWindowGeometry(nux::Geometry const& absolute_geo, nux::Geometry const& geo)
198{
199 window_geometry_ = geo;
200 window_geometry_.x = 0;
201 window_geometry_.y = 0;
202 absolute_window_geometry_ = absolute_geo;
203}
204
205namespace
206{
207 const int top_spacing = 9;
208 const int content_width = 941;
209 const int icon_vertical_margin = 5;
210 const int spacing_between_icon_and_content = 8;
211}
212
213void View::SetupViews()
214{
215 layout_ = new nux::HLayout();
216
217 icon_ = new Icon("", icon_size, true);
218 nux::Layout* icon_layout = new nux::VLayout();
219 icon_layout->SetVerticalExternalMargin(icon_vertical_margin);
220 icon_layout->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
221 layout_->AddLayout(icon_layout, 0, nux::MINOR_POSITION_TOP, nux::MINOR_SIZE_MATCHCONTENT);
222 layout_->AddLayout(new nux::SpaceLayout(spacing_between_icon_and_content,
223 spacing_between_icon_and_content,
224 spacing_between_icon_and_content,
225 spacing_between_icon_and_content), 0);
226
227
228 content_layout_ = new nux::VLayout();
229 layout_->AddLayout(content_layout_.GetPointer(), 1, nux::MINOR_POSITION_TOP);
230 SetLayout(layout_.GetPointer());
231
232 // add the top spacing
233 content_layout_->AddLayout(new nux::SpaceLayout(top_spacing,top_spacing,top_spacing,top_spacing), 0);
234
235 // add the search bar to the composite
236 search_bar_ = new unity::SearchBar(content_width, true);
237 search_bar_->disable_glow = true;
238 search_bar_->search_hint = default_text;
239 search_bar_->search_changed.connect(sigc::mem_fun(this, &View::OnSearchChanged));
240 AddChild(search_bar_.GetPointer());
241 content_layout_->AddView(search_bar_.GetPointer(), 0, nux::MINOR_POSITION_LEFT);
242
243 button_views_ = new nux::VLayout();
244 button_views_->SetMaximumWidth(content_width);
245
246 content_layout_->AddLayout(button_views_.GetPointer(), 1, nux::MINOR_POSITION_LEFT);
247}
248
249void View::OnSearchChanged(std::string const& search_string)
250{
251 LOG_DEBUG(logger) << "got search change";
252 search_changed.emit(search_string);
253 if (search_string.empty())
254 {
255 search_bar_->search_hint = default_text;
256 }
257 else
258 {
259 search_bar_->search_hint = "";
260 }
261}
262
263
264void View::OnKeyDown (unsigned long event_type, unsigned long keysym,
265 unsigned long event_state, const TCHAR* character,
266 unsigned short key_repeat_count)
267{
268 if (keysym == NUX_VK_ESCAPE)
269 {
270 LOG_DEBUG(logger) << "got escape key";
271 ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST);
272 }
273}
274
275void View::OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key)
276{
277 if (!content_geo_.IsPointInside(x, y))
278 {
279 ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST);
280 }
281}
282
283void View::Draw(nux::GraphicsEngine& gfx_context, bool force_draw)
284{
285 renderer_.DrawFull(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_, true);
286}
287
288void View::DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw)
289{
290 renderer_.DrawInner(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_);
291
292 if (IsFullRedraw())
293 {
294 nux::GetPainter().PushBackgroundStack();
295 layout_->ProcessDraw(gfx_context, force_draw);
296 nux::GetPainter().PopBackgroundStack();
297 }
298 else
299 {
300 layout_->ProcessDraw(gfx_context, force_draw);
301 }
302
303 renderer_.DrawInnerCleanup(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_);
304}
305
306// Keyboard navigation
307bool View::AcceptKeyNavFocus()
308{
309 return false;
310}
311
312// Introspectable
313std::string View::GetName() const
314{
315 return "HudView";
316}
317
318void View::AddProperties(GVariantBuilder* builder)
319{
320
321}
322
323bool View::InspectKeyEvent(unsigned int eventType,
324 unsigned int key_sym,
325 const char* character)
326{
327 if ((eventType == nux::NUX_KEYDOWN) && (key_sym == NUX_VK_ESCAPE))
328 {
329 if (search_bar_->search_string == "")
330 {
331 ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST);
332 }
333 else
334 {
335 search_bar_->search_string = "";
336 search_bar_->search_hint = default_text;
337 }
338 return true;
339 }
340 return false;
341}
342
343nux::Area* View::FindKeyFocusArea(unsigned int key_symbol,
344 unsigned long x11_key_code,
345 unsigned long special_keys_state)
346{
347 // Do what nux::View does, but if the event isn't a key navigation,
348 // designate the text entry to process it.
349
350 nux::KeyNavDirection direction = nux::KEY_NAV_NONE;
351 switch (x11_key_code)
352 {
353 case NUX_VK_UP:
354 direction = nux::KEY_NAV_UP;
355 break;
356 case NUX_VK_DOWN:
357 direction = nux::KEY_NAV_DOWN;
358 break;
359 case NUX_VK_LEFT:
360 direction = nux::KEY_NAV_LEFT;
361 break;
362 case NUX_VK_RIGHT:
363 direction = nux::KEY_NAV_RIGHT;
364 break;
365 case NUX_VK_LEFT_TAB:
366 direction = nux::KEY_NAV_TAB_PREVIOUS;
367 break;
368 case NUX_VK_TAB:
369 direction = nux::KEY_NAV_TAB_NEXT;
370 break;
371 case NUX_VK_ENTER:
372 case NUX_KP_ENTER:
373 // Not sure if Enter should be a navigation key
374 direction = nux::KEY_NAV_ENTER;
375 break;
376 default:
377 direction = nux::KEY_NAV_NONE;
378 break;
379 }
380
381 if (has_key_focus_)
382 {
383 return this;
384 }
385 else if (direction == nux::KEY_NAV_NONE)
386 {
387 // then send the event to the search entry
388 return search_bar_->text_entry();
389 }
390 else if (next_object_to_key_focus_area_)
391 {
392 return next_object_to_key_focus_area_->FindKeyFocusArea(key_symbol, x11_key_code, special_keys_state);
393 }
394 return NULL;
395}
396
397}
398}
0399
=== added file 'plugins/unityshell/src/HudView.h'
--- plugins/unityshell/src/HudView.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudView.h 2012-02-06 11:00:29 +0000
@@ -0,0 +1,118 @@
1/*
2 * Copyright (C) 2010 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: Gordon Allott <gord.allott@canonical.com>
17 */
18
19#ifndef UNITY_HUD_VIEW_H_
20#define UNITY_HUD_VIEW_H_
21
22#include <string>
23
24#include <NuxGraphics/GraphicsEngine.h>
25#include <Nux/Nux.h>
26#include <Nux/PaintLayer.h>
27#include <Nux/View.h>
28#include <Nux/VLayout.h>
29#include <StaticCairoText.h>
30
31#include <glib.h>
32
33#include <UnityCore/Hud.h>
34#include "Introspectable.h"
35
36#include "UBusWrapper.h"
37#include "HudIcon.h"
38#include "HudButton.h"
39#include "SearchBar.h"
40#include "OverlayRenderer.h"
41
42namespace unity
43{
44namespace hud
45{
46
47class View : public nux::View, public unity::debug::Introspectable
48{
49 NUX_DECLARE_OBJECT_TYPE(HudView, nux::View);
50 typedef nux::ObjectPtr<View> Ptr;
51public:
52 View();
53 ~View();
54
55 void ResetToDefault();
56
57 void Relayout();
58 nux::View* default_focus() const;
59
60 void SetQueries(Hud::Queries queries);
61 void SetIcon(std::string icon_name);
62
63 void AboutToShow();
64 void AboutToHide();
65
66 void SetWindowGeometry(nux::Geometry const& absolute_geo, nux::Geometry const& geo);
67
68 sigc::signal<void, std::string> search_changed;
69 sigc::signal<void, std::string> search_activated;
70 sigc::signal<void, Query::Ptr> query_activated;
71 sigc::signal<void, Query::Ptr> query_selected;
72
73protected:
74 virtual Area* FindKeyFocusArea(unsigned int key_symbol,
75 unsigned long x11_key_code,
76 unsigned long special_keys_state);
77
78 void SetupViews();
79 void OnSearchChanged(std::string const& search_string);
80 virtual long PostLayoutManagement(long LayoutResult);
81private:
82 void OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key);
83 void OnKeyDown (unsigned long event_type, unsigned long event_keysym,
84 unsigned long event_state, const TCHAR* character,
85 unsigned short key_repeat_count);
86 void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);
87 void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw);
88 bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character);
89 bool AcceptKeyNavFocus();
90 nux::Geometry GetBestFitGeometry(nux::Geometry const& for_geo);
91
92 std::string GetName() const;
93 void AddProperties(GVariantBuilder* builder);
94
95private:
96 UBusManager ubus;
97 nux::ObjectPtr<nux::Layout> layout_;
98 nux::ObjectPtr<nux::Layout> content_layout_;
99 nux::ObjectPtr<nux::VLayout> button_views_;
100 std::list<HudButton::Ptr> buttons_;
101
102 //FIXME - replace with dash search bar once modifications to dash search bar land
103 SearchBar::Ptr search_bar_;
104 Icon::Ptr icon_;
105 bool visible_;
106
107 Hud::Queries queries_;
108 nux::Geometry content_geo_;
109 OverlayRenderer renderer_;
110 nux::Geometry window_geometry_;
111 nux::Geometry absolute_window_geometry_;
112};
113
114
115}
116}
117#endif
118
0119
=== modified file 'plugins/unityshell/src/IMTextEntry.cpp'
--- plugins/unityshell/src/IMTextEntry.cpp 2012-01-26 12:59:18 +0000
+++ plugins/unityshell/src/IMTextEntry.cpp 2012-02-06 11:00:29 +0000
@@ -27,12 +27,10 @@
2727
28namespace unity28namespace unity
29{29{
30namespace dash
31{
3230
33namespace31namespace
34{32{
35nux::logging::Logger logger("unity.dash.imtextentry");33nux::logging::Logger logger("unity.imtextentry");
36}34}
3735
38NUX_IMPLEMENT_OBJECT_TYPE(IMTextEntry);36NUX_IMPLEMENT_OBJECT_TYPE(IMTextEntry);
@@ -338,4 +336,3 @@
338}336}
339337
340}338}
341}
342339
=== modified file 'plugins/unityshell/src/IMTextEntry.h'
--- plugins/unityshell/src/IMTextEntry.h 2012-01-03 00:51:51 +0000
+++ plugins/unityshell/src/IMTextEntry.h 2012-02-06 11:00:29 +0000
@@ -30,8 +30,6 @@
3030
31namespace unity31namespace unity
32{32{
33namespace dash
34{
3533
36using namespace unity::glib;34using namespace unity::glib;
37using namespace nux;35using namespace nux;
@@ -80,6 +78,5 @@
80};78};
8179
82}80}
83}
8481
85#endif82#endif
8683
=== modified file 'plugins/unityshell/src/IconTexture.cpp'
--- plugins/unityshell/src/IconTexture.cpp 2011-11-08 18:21:44 +0000
+++ plugins/unityshell/src/IconTexture.cpp 2012-02-06 11:00:29 +0000
@@ -24,6 +24,7 @@
24#include <pango/pangocairo.h>24#include <pango/pangocairo.h>
2525
26#include <Nux/Nux.h>26#include <Nux/Nux.h>
27#include <NuxCore/Logger.h>
27#include <NuxGraphics/GLThread.h>28#include <NuxGraphics/GLThread.h>
28#include <UnityCore/GLibWrapper.h>29#include <UnityCore/GLibWrapper.h>
29#include <UnityCore/Variant.h>30#include <UnityCore/Variant.h>
@@ -37,6 +38,7 @@
37namespace38namespace
38{39{
39const char* const DEFAULT_ICON = "text-x-preview";40const char* const DEFAULT_ICON = "text-x-preview";
41nux::logging::Logger logger("unity.icontexture");
40}42}
4143
42using namespace unity;44using namespace unity;
@@ -67,7 +69,7 @@
67{69{
68 _icon_name = g_strdup(icon_name ? icon_name : DEFAULT_ICON);70 _icon_name = g_strdup(icon_name ? icon_name : DEFAULT_ICON);
6971
70 if (!g_strcmp0(_icon_name, "") == 0 && !defer_icon_loading)72 if (g_strcmp0(_icon_name, "") != 0 && !defer_icon_loading)
71 LoadIcon();73 LoadIcon();
72}74}
7375
@@ -95,8 +97,11 @@
9597
96void IconTexture::LoadIcon()98void IconTexture::LoadIcon()
97{99{
98 static const char* const DEFAULT_GICON = ". GThemedIcon text-x-preview";100 LOG_DEBUG(logger) << "LoadIcon called (" << _icon_name << ") - loading: " << _loading;
99101static const char* const DEFAULT_GICON = ". GThemedIcon text-x-preview";
102 if (!g_strcmp0(_icon_name, ""))
103 return;
104
100 if (_loading)105 if (_loading)
101 return;106 return;
102 _loading = true;107 _loading = true;
@@ -144,6 +149,7 @@
144 _texture_height,149 _texture_height,
145 sigc::mem_fun(this, &IconTexture::CreateTextureCallback));150 sigc::mem_fun(this, &IconTexture::CreateTextureCallback));
146 QueueDraw();151 QueueDraw();
152 _loading = false;
147}153}
148154
149void IconTexture::IconLoaded(std::string const& icon_name, unsigned size,155void IconTexture::IconLoaded(std::string const& icon_name, unsigned size,
@@ -162,6 +168,9 @@
162 if (icon_name != DEFAULT_ICON)168 if (icon_name != DEFAULT_ICON)
163 SetByIconName(DEFAULT_ICON, _size);169 SetByIconName(DEFAULT_ICON, _size);
164 }170 }
171
172 texture_updated.emit(_texture_cached.GetPointer());
173 QueueDraw();
165}174}
166175
167void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)176void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
168177
=== modified file 'plugins/unityshell/src/IconTexture.h'
--- plugins/unityshell/src/IconTexture.h 2011-12-08 01:23:11 +0000
+++ plugins/unityshell/src/IconTexture.h 2012-02-06 11:00:29 +0000
@@ -53,6 +53,8 @@
5353
54 nux::BaseTexture* texture();54 nux::BaseTexture* texture();
5555
56 sigc::signal<void, nux::BaseTexture*> texture_updated;
57
56protected:58protected:
57 // Key navigation59 // Key navigation
58 virtual bool AcceptKeyNavFocus();60 virtual bool AcceptKeyNavFocus();
@@ -61,7 +63,8 @@
61 std::string GetName() const;63 std::string GetName() const;
62 void AddProperties(GVariantBuilder* builder);64 void AddProperties(GVariantBuilder* builder);
63 virtual bool DoCanFocus();65 virtual bool DoCanFocus();
6466 GdkPixbuf* _pixbuf_cached;
67
65protected:68protected:
66 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);69 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
6770
@@ -74,7 +77,7 @@
74 char* _icon_name;77 char* _icon_name;
75 unsigned int _size;78 unsigned int _size;
7679
77 GdkPixbuf* _pixbuf_cached;80
78 nux::ObjectPtr<nux::BaseTexture> _texture_cached;81 nux::ObjectPtr<nux::BaseTexture> _texture_cached;
79 // FIXME: make these two a nux::Size.82 // FIXME: make these two a nux::Size.
80 int _texture_width;83 int _texture_width;
8184
=== modified file 'plugins/unityshell/src/OverlayRenderer.cpp'
--- plugins/unityshell/src/OverlayRenderer.cpp 2012-02-03 21:56:04 +0000
+++ plugins/unityshell/src/OverlayRenderer.cpp 2012-02-06 11:00:29 +0000
@@ -50,7 +50,7 @@
50 void Init();50 void Init();
51 void OnBackgroundColorChanged(GVariant* args);51 void OnBackgroundColorChanged(GVariant* args);
52 52
53 void Draw(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry);53 void Draw(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry, bool force_draw);
54 void DrawContent(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry);54 void DrawContent(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry);
55 void DrawContentCleanup(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry);55 void DrawContentCleanup(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry);
56 56
@@ -118,12 +118,12 @@
118 parent->need_redraw.emit();118 parent->need_redraw.emit();
119}119}
120120
121void OverlayRendererImpl::Draw(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry)121void OverlayRendererImpl::Draw(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geometry, bool force_edges)
122{122{
123 bool paint_blur = BackgroundEffectHelper::blur_type != BLUR_NONE;123 bool paint_blur = BackgroundEffectHelper::blur_type != BLUR_NONE;
124 nux::Geometry geo = content_geo;124 nux::Geometry geo = content_geo;
125125
126 if (dash::Settings::Instance().GetFormFactor() != dash::FormFactor::NETBOOK)126 if (dash::Settings::Instance().GetFormFactor() != dash::FormFactor::NETBOOK || force_edges)
127 {127 {
128 // Paint the edges128 // Paint the edges
129 {129 {
@@ -475,9 +475,9 @@
475 pimpl_->bg_effect_helper_.blur_type = BLUR_NONE;475 pimpl_->bg_effect_helper_.blur_type = BLUR_NONE;
476}476}
477477
478void OverlayRenderer::DrawFull(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo)478void OverlayRenderer::DrawFull(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo, bool force_edges)
479{479{
480 pimpl_->Draw(gfx_context, content_geo, absolute_geo, geo);480 pimpl_->Draw(gfx_context, content_geo, absolute_geo, geo, force_edges);
481}481}
482482
483void OverlayRenderer::DrawInner(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo)483void OverlayRenderer::DrawInner(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo)
484484
=== modified file 'plugins/unityshell/src/OverlayRenderer.h'
--- plugins/unityshell/src/OverlayRenderer.h 2012-01-27 06:58:20 +0000
+++ plugins/unityshell/src/OverlayRenderer.h 2012-02-06 11:00:29 +0000
@@ -70,7 +70,7 @@
70 * absolute_geo: your views GetAbsoluteGeometry()70 * absolute_geo: your views GetAbsoluteGeometry()
71 * geo: your views GetGeometry()71 * geo: your views GetGeometry()
72 */72 */
73 void DrawFull(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo);73 void DrawFull(nux::GraphicsEngine& gfx_context, nux::Geometry content_geo, nux::Geometry absolute_geo, nux::Geometry geo, bool force_edges=false);
74 74
75 /*75 /*
76 * Draws just the stack that is overlay behind the inner_geometry using push/pop layers, call in DrawContent() before drawing your content76 * Draws just the stack that is overlay behind the inner_geometry using push/pop layers, call in DrawContent() before drawing your content
7777
=== renamed file 'plugins/unityshell/src/DashSearchBar.cpp' => 'plugins/unityshell/src/SearchBar.cpp'
--- plugins/unityshell/src/DashSearchBar.cpp 2012-01-26 22:17:41 +0000
+++ plugins/unityshell/src/SearchBar.cpp 2012-02-06 11:00:29 +0000
@@ -25,6 +25,7 @@
25#include <Nux/VLayout.h>25#include <Nux/VLayout.h>
26#include <Nux/Layout.h>26#include <Nux/Layout.h>
27#include <Nux/WindowCompositor.h>27#include <Nux/WindowCompositor.h>
28#include <NuxCore/Logger.h>
2829
29#include <NuxImage/CairoGraphics.h>30#include <NuxImage/CairoGraphics.h>
30#include <NuxImage/ImageSurface.h>31#include <NuxImage/ImageSurface.h>
@@ -36,7 +37,7 @@
36#include <glib.h>37#include <glib.h>
37#include <glib/gi18n-lib.h>38#include <glib/gi18n-lib.h>
3839
39#include "DashSearchBar.h"40#include "SearchBar.h"
40#include <UnityCore/Variant.h>41#include <UnityCore/Variant.h>
4142
42#include "CairoTexture.h"43#include "CairoTexture.h"
@@ -48,12 +49,17 @@
48namespace49namespace
49{50{
50const float kExpandDefaultIconOpacity = 1.0f;51const float kExpandDefaultIconOpacity = 1.0f;
52const int external_margin_vertical = 8;
53const int external_margin_horizontal = 7;
54}
55
56namespace
57{
58 nux::logging::Logger logger("unity");
51}59}
5260
53namespace unity61namespace unity
54{62{
55namespace dash
56{
5763
58NUX_IMPLEMENT_OBJECT_TYPE(SearchBar);64NUX_IMPLEMENT_OBJECT_TYPE(SearchBar);
5965
@@ -62,18 +68,53 @@
62 , search_hint("")68 , search_hint("")
63 , showing_filters(false)69 , showing_filters(false)
64 , can_refine_search(false)70 , can_refine_search(false)
71 , disable_glow(false)
72 , show_filter_hint_(true)
65 , search_bar_width_(642)73 , search_bar_width_(642)
66 , live_search_timeout_(0)74 , live_search_timeout_(0)
67 , start_spinner_timeout_(0)75 , start_spinner_timeout_(0)
68{76{
77 Init();
78}
79
80SearchBar::SearchBar(int search_bar_width, bool show_filter_hint_, NUX_FILE_LINE_DECL)
81 : View(NUX_FILE_LINE_PARAM)
82 , search_hint("")
83 , showing_filters(false)
84 , can_refine_search(false)
85 , disable_glow(false)
86 , show_filter_hint_(show_filter_hint_)
87 , search_bar_width_(search_bar_width)
88 , live_search_timeout_(0)
89 , start_spinner_timeout_(0)
90{
91 Init();
92}
93
94SearchBar::SearchBar(int search_bar_width, NUX_FILE_LINE_DECL)
95 : View(NUX_FILE_LINE_PARAM)
96 , search_hint("")
97 , showing_filters(false)
98 , can_refine_search(false)
99 , disable_glow(false)
100 , show_filter_hint_(true)
101 , search_bar_width_(search_bar_width)
102 , live_search_timeout_(0)
103 , start_spinner_timeout_(0)
104{
105 Init();
106}
107
108void SearchBar::Init()
109{
69 nux::BaseTexture* icon = dash::Style::Instance().GetSearchMagnifyIcon();110 nux::BaseTexture* icon = dash::Style::Instance().GetSearchMagnifyIcon();
70111
71 bg_layer_ = new nux::ColorLayer(nux::Color(0xff595853), true);112 bg_layer_ = new nux::ColorLayer(nux::Color(0xff595853), true);
72113
73 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);114 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
74 layout_->SetHorizontalInternalMargin(0);115 layout_->SetHorizontalInternalMargin(0);
75 layout_->SetVerticalExternalMargin(8);116 layout_->SetVerticalExternalMargin(external_margin_vertical);
76 layout_->SetHorizontalExternalMargin(7);117 layout_->SetHorizontalExternalMargin(external_margin_horizontal);
77 SetLayout(layout_);118 SetLayout(layout_);
78119
79 spinner_ = new SearchBarSpinner();120 spinner_ = new SearchBarSpinner();
@@ -102,42 +143,44 @@
102 layered_layout_->SetMaximumWidth(search_bar_width_);143 layered_layout_->SetMaximumWidth(search_bar_width_);
103 layout_->AddView(layered_layout_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);144 layout_->AddView(layered_layout_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);
104145
105 std::string filter_str = _("<small><b>Filter results</b></small>");146 if (show_filter_hint_)
106 show_filters_ = new nux::StaticCairoText(filter_str.c_str());147 {
107 show_filters_->SetVisible(false);148 std::string filter_str = _("<small><b>Filter results</b></small>");
108 show_filters_->SetFont("Ubuntu 10");149 show_filters_ = new nux::StaticCairoText(filter_str.c_str());
109 show_filters_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 1.0f));150 show_filters_->SetVisible(false);
110 show_filters_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT);151 show_filters_->SetFont("Ubuntu 10");
111 show_filters_->mouse_click.connect([&] (int x, int y, unsigned long b, unsigned long k) { showing_filters = !showing_filters; });152 show_filters_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
112153 show_filters_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT);
113 nux::BaseTexture* arrow;154 show_filters_->mouse_click.connect([&] (int x, int y, unsigned long b, unsigned long k) { showing_filters = !showing_filters; });
114 arrow = dash::Style::Instance().GetGroupExpandIcon();155
115 expand_icon_ = new IconTexture(arrow,156 nux::BaseTexture* arrow;
116 arrow->GetWidth(),157 arrow = dash::Style::Instance().GetGroupExpandIcon();
117 arrow->GetHeight());158 expand_icon_ = new IconTexture(arrow,
118 expand_icon_->SetOpacity(kExpandDefaultIconOpacity);159 arrow->GetWidth(),
119 expand_icon_->SetMinimumSize(arrow->GetWidth(), arrow->GetHeight());160 arrow->GetHeight());
120 expand_icon_->SetVisible(false);161 expand_icon_->SetOpacity(kExpandDefaultIconOpacity);
121 expand_icon_->mouse_click.connect([&] (int x, int y, unsigned long b, unsigned long k) { showing_filters = !showing_filters; });162 expand_icon_->SetMinimumSize(arrow->GetWidth(), arrow->GetHeight());
122163 expand_icon_->SetVisible(false);
123 filter_layout_ = new nux::HLayout();164 expand_icon_->mouse_click.connect([&] (int x, int y, unsigned long b, unsigned long k) { showing_filters = !showing_filters; });
124 filter_layout_->SetHorizontalInternalMargin(8);165
125 filter_layout_->SetHorizontalExternalMargin(6);166 filter_layout_ = new nux::HLayout();
126 filter_space_ = new nux::SpaceLayout(100, 10000, 0, 1);167 filter_layout_->SetHorizontalInternalMargin(8);
127 filter_layout_->AddLayout(filter_space_, 1);168 filter_layout_->SetHorizontalExternalMargin(6);
128 filter_layout_->AddView(show_filters_, 0, nux::MINOR_POSITION_CENTER);169 filter_space_ = new nux::SpaceLayout(100, 10000, 0, 1);
129170 filter_layout_->AddLayout(filter_space_, 1);
130 arrow_layout_ = new nux::VLayout();171 filter_layout_->AddView(show_filters_, 0, nux::MINOR_POSITION_CENTER);
131 arrow_top_space_ = new nux::SpaceLayout(2, 2, 12, 12);172
132 arrow_bottom_space_ = new nux::SpaceLayout(2, 2, 8, 8);173 arrow_layout_ = new nux::VLayout();
133 arrow_layout_->AddView(arrow_top_space_, 0, nux::MINOR_POSITION_CENTER);174 arrow_top_space_ = new nux::SpaceLayout(2, 2, 12, 12);
134 arrow_layout_->AddView(expand_icon_, 0, nux::MINOR_POSITION_CENTER);175 arrow_bottom_space_ = new nux::SpaceLayout(2, 2, 8, 8);
135 arrow_layout_->AddView(arrow_bottom_space_, 0, nux::MINOR_POSITION_CENTER);176 arrow_layout_->AddView(arrow_top_space_, 0, nux::MINOR_POSITION_CENTER);
136177 arrow_layout_->AddView(expand_icon_, 0, nux::MINOR_POSITION_CENTER);
137 filter_layout_->AddView(arrow_layout_, 0, nux::MINOR_POSITION_CENTER);178 arrow_layout_->AddView(arrow_bottom_space_, 0, nux::MINOR_POSITION_CENTER);
138179
139 layout_->AddView(filter_layout_, 1, nux::MINOR_POSITION_RIGHT, nux::MINOR_SIZE_FULL);180 filter_layout_->AddView(arrow_layout_, 0, nux::MINOR_POSITION_CENTER);
140181
182 layout_->AddView(filter_layout_, 1, nux::MINOR_POSITION_RIGHT, nux::MINOR_SIZE_FULL);
183 }
141 sig_manager_.Add(new Signal<void, GtkSettings*, GParamSpec*>184 sig_manager_.Add(new Signal<void, GtkSettings*, GParamSpec*>
142 (gtk_settings_get_default(),185 (gtk_settings_get_default(),
143 "notify::gtk-font-name",186 "notify::gtk-font-name",
@@ -151,9 +194,21 @@
151 showing_filters.changed.connect(sigc::mem_fun(this, &SearchBar::OnShowingFiltersChanged));194 showing_filters.changed.connect(sigc::mem_fun(this, &SearchBar::OnShowingFiltersChanged));
152 can_refine_search.changed.connect([&] (bool can_refine)195 can_refine_search.changed.connect([&] (bool can_refine)
153 {196 {
154 show_filters_->SetVisible(can_refine);197 if (show_filter_hint_)
155 expand_icon_->SetVisible(can_refine);198 {
156 });199 show_filters_->SetVisible(can_refine);
200 expand_icon_->SetVisible(can_refine);
201 }
202 });
203
204 disable_glow.changed.connect([&](bool disabled)
205 {
206 layout_->SetVerticalExternalMargin(0);
207 layout_->SetHorizontalExternalMargin(0);
208 UpdateBackground(true);
209 QueueDraw();
210 });
211
157}212}
158213
159SearchBar::~SearchBar()214SearchBar::~SearchBar()
@@ -259,18 +314,21 @@
259314
260void SearchBar::OnShowingFiltersChanged(bool is_showing)315void SearchBar::OnShowingFiltersChanged(bool is_showing)
261{316{
262 dash::Style& style = dash::Style::Instance();317 if (show_filter_hint_)
263 if (is_showing)318 {
264 expand_icon_->SetTexture(style.GetGroupUnexpandIcon());319 dash::Style& style = dash::Style::Instance();
265 else320 if (is_showing)
266 expand_icon_->SetTexture(style.GetGroupExpandIcon());321 expand_icon_->SetTexture(style.GetGroupUnexpandIcon());
322 else
323 expand_icon_->SetTexture(style.GetGroupExpandIcon());
324 }
267}325}
268326
269void SearchBar::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)327void SearchBar::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
270{328{
271 nux::Geometry geo = GetGeometry();329 nux::Geometry geo = GetGeometry();
272330
273 UpdateBackground();331 UpdateBackground(false);
274332
275 GfxContext.PushClippingRectangle(geo);333 GfxContext.PushClippingRectangle(geo);
276334
@@ -344,21 +402,33 @@
344 spinner_->SetState(is_empty ? STATE_READY : STATE_CLEAR);402 spinner_->SetState(is_empty ? STATE_READY : STATE_CLEAR);
345}403}
346404
347void SearchBar::UpdateBackground()405void SearchBar::UpdateBackground(bool force)
348{406{
349#define PADDING 12407 int PADDING = 12;
350#define RADIUS 5408 int RADIUS = 5;
351 int x, y, width, height;409 int x, y, width, height;
352 nux::Geometry geo = GetGeometry();410 nux::Geometry geo = GetGeometry();
353 geo.width = layered_layout_->GetGeometry().width;411 geo.width = layered_layout_->GetGeometry().width;
354412
355 if (geo.width == last_width_ && geo.height == last_height_)413 LOG_DEBUG(logger) << "height: "
414 << geo.height << " - "
415 << layered_layout_->GetGeometry().height << " - "
416 << pango_entry_->GetGeometry().height;
417
418 if (geo.width == last_width_
419 && geo.height == last_height_
420 && force == false)
356 return;421 return;
357422
358 last_width_ = geo.width;423 last_width_ = geo.width;
359 last_height_ = geo.height;424 last_height_ = geo.height;
360425
426 if (disable_glow)
427 PADDING = 2;
428
429
361 x = y = PADDING - 1;430 x = y = PADDING - 1;
431
362 width = last_width_ - (2 * PADDING);432 width = last_width_ - (2 * PADDING);
363 height = last_height_ - (2 * PADDING) + 1;433 height = last_height_ - (2 * PADDING) + 1;
364434
@@ -473,5 +543,4 @@
473 g_variant_builder_add (builder, "{sv}", "search_string", g_variant_new_string (pango_entry_->GetText().c_str()) );543 g_variant_builder_add (builder, "{sv}", "search_string", g_variant_new_string (pango_entry_->GetText().c_str()) );
474}544}
475545
476} // namespace dash
477} // namespace unity546} // namespace unity
478547
=== renamed file 'plugins/unityshell/src/DashSearchBar.h' => 'plugins/unityshell/src/SearchBar.h'
--- plugins/unityshell/src/DashSearchBar.h 2012-01-17 15:39:16 +0000
+++ plugins/unityshell/src/SearchBar.h 2012-02-06 11:00:29 +0000
@@ -17,8 +17,8 @@
17 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>17 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18 */18 */
1919
20#ifndef DASH_SEARCH_BAR_H20#ifndef SEARCH_BAR_H
21#define DASH_SEARCH_BAR_H21#define SEARCH_BAR_H
2222
23#include <gtk/gtk.h>23#include <gtk/gtk.h>
2424
@@ -32,7 +32,7 @@
32#include <Nux/TextEntry.h>32#include <Nux/TextEntry.h>
33#include <UnityCore/GLibSignal.h>33#include <UnityCore/GLibSignal.h>
3434
35#include "DashSearchBarSpinner.h"35#include "SearchBarSpinner.h"
36#include "IconTexture.h"36#include "IconTexture.h"
37#include "IMTextEntry.h"37#include "IMTextEntry.h"
38#include "Introspectable.h"38#include "Introspectable.h"
@@ -40,8 +40,6 @@
4040
41namespace unity41namespace unity
42{42{
43namespace dash
44{
4543
46using namespace unity::glib;44using namespace unity::glib;
4745
@@ -49,7 +47,10 @@
49{47{
50 NUX_DECLARE_OBJECT_TYPE(SearchBar, nux::View);48 NUX_DECLARE_OBJECT_TYPE(SearchBar, nux::View);
51public:49public:
50 typedef nux::ObjectPtr<SearchBar> Ptr;
52 SearchBar(NUX_FILE_LINE_PROTO);51 SearchBar(NUX_FILE_LINE_PROTO);
52 SearchBar(int search_width, bool show_filter_hint, NUX_FILE_LINE_PROTO);
53 SearchBar(int search_width, NUX_FILE_LINE_PROTO);
53 ~SearchBar();54 ~SearchBar();
5455
55 void SearchFinished();56 void SearchFinished();
@@ -59,6 +60,7 @@
59 nux::Property<std::string> search_hint;60 nux::Property<std::string> search_hint;
60 nux::Property<bool> showing_filters;61 nux::Property<bool> showing_filters;
61 nux::Property<bool> can_refine_search;62 nux::Property<bool> can_refine_search;
63 nux::Property<bool> disable_glow;
62 nux::ROProperty<bool> im_active;64 nux::ROProperty<bool> im_active;
6365
64 sigc::signal<void> activated;66 sigc::signal<void> activated;
@@ -67,6 +69,8 @@
6769
68private:70private:
6971
72 void Init();
73
70 void OnFontChanged(GtkSettings* settings, GParamSpec* pspec=NULL);74 void OnFontChanged(GtkSettings* settings, GParamSpec* pspec=NULL);
71 void OnSearchHintChanged();75 void OnSearchHintChanged();
7276
@@ -76,7 +80,7 @@
76 void OnMouseButtonDown(int x, int y, unsigned long button_flags, unsigned long key_flags);80 void OnMouseButtonDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
77 void OnEndKeyFocus();81 void OnEndKeyFocus();
7882
79 void UpdateBackground();83 void UpdateBackground(bool force);
80 void OnSearchChanged(nux::TextEntry* text_entry);84 void OnSearchChanged(nux::TextEntry* text_entry);
81 void OnClearClicked(int x, int y, unsigned long button_flags, unsigned long key_flags);85 void OnClearClicked(int x, int y, unsigned long button_flags, unsigned long key_flags);
82 void OnEntryActivated();86 void OnEntryActivated();
@@ -85,6 +89,7 @@
85 std::string get_search_string() const;89 std::string get_search_string() const;
86 bool set_search_string(std::string const& string);90 bool set_search_string(std::string const& string);
87 bool get_im_active() const;91 bool get_im_active() const;
92 bool show_filter_hint_;
8893
89 static gboolean OnLiveSearchTimeout(SearchBar* self);94 static gboolean OnLiveSearchTimeout(SearchBar* self);
90 static gboolean OnSpinnerStartCb(SearchBar* self);95 static gboolean OnSpinnerStartCb(SearchBar* self);
@@ -110,7 +115,6 @@
110 IconTexture* expand_icon_;115 IconTexture* expand_icon_;
111 int search_bar_width_;116 int search_bar_width_;
112117
113
114 int last_width_;118 int last_width_;
115 int last_height_;119 int last_height_;
116 120
@@ -121,6 +125,5 @@
121};125};
122126
123}127}
124}
125128
126#endif129#endif
127130
=== renamed file 'plugins/unityshell/src/DashSearchBarSpinner.cpp' => 'plugins/unityshell/src/SearchBarSpinner.cpp'
--- plugins/unityshell/src/DashSearchBarSpinner.cpp 2011-12-16 22:10:23 +0000
+++ plugins/unityshell/src/SearchBarSpinner.cpp 2012-02-06 11:00:29 +0000
@@ -17,7 +17,7 @@
17 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>17 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18 */18 */
1919
20#include "DashSearchBarSpinner.h"20#include "SearchBarSpinner.h"
2121
22#include <Nux/VLayout.h>22#include <Nux/VLayout.h>
2323
@@ -25,8 +25,6 @@
2525
26namespace unity26namespace unity
27{27{
28namespace dash
29{
3028
31NUX_IMPLEMENT_OBJECT_TYPE(SearchBarSpinner);29NUX_IMPLEMENT_OBJECT_TYPE(SearchBarSpinner);
3230
@@ -236,4 +234,3 @@
236}234}
237235
238}236}
239}
240237
=== renamed file 'plugins/unityshell/src/DashSearchBarSpinner.h' => 'plugins/unityshell/src/SearchBarSpinner.h'
--- plugins/unityshell/src/DashSearchBarSpinner.h 2011-12-08 01:23:11 +0000
+++ plugins/unityshell/src/SearchBarSpinner.h 2012-02-06 11:00:29 +0000
@@ -17,8 +17,8 @@
17 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>17 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18 */18 */
1919
20#ifndef DASH_SEARCH_BAR_SPINNER_H20#ifndef SEARCH_BAR_SPINNER_H
21#define DASH_SEARCH_BAR_SPINNER_H21#define SEARCH_BAR_SPINNER_H
2222
23#include <Nux/Nux.h>23#include <Nux/Nux.h>
24#include <Nux/View.h>24#include <Nux/View.h>
@@ -29,8 +29,6 @@
2929
30namespace unity30namespace unity
31{31{
32namespace dash
33{
3432
35enum SpinnerState33enum SpinnerState
36{34{
@@ -80,6 +78,5 @@
80};78};
8179
82}80}
83}
8481
85#endif82#endif
8683
=== modified file 'plugins/unityshell/src/UBusMessages.h'
--- plugins/unityshell/src/UBusMessages.h 2012-01-31 10:59:11 +0000
+++ plugins/unityshell/src/UBusMessages.h 2012-02-06 11:00:29 +0000
@@ -78,6 +78,8 @@
78// FIXME - fix the nux focus api so we don't need this78// FIXME - fix the nux focus api so we don't need this
79#define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED"79#define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED"
8080
81#define UBUS_HUD_CLOSE_REQUEST "HUD_CLOSE_REQUEST"
82
81// Signals sent when the switcher is shown, hidden or changes selection83// Signals sent when the switcher is shown, hidden or changes selection
82#define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN"84#define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN"
83#define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED"85#define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED"
8486
=== modified file 'plugins/unityshell/src/unity-search-bar-accessible.cpp'
--- plugins/unityshell/src/unity-search-bar-accessible.cpp 2011-09-15 13:58:42 +0000
+++ plugins/unityshell/src/unity-search-bar-accessible.cpp 2012-02-06 11:00:29 +0000
@@ -20,7 +20,7 @@
20 * SECTION:unity-search_bar-accessible20 * SECTION:unity-search_bar-accessible
21 * @Title: UnitySearchBarAccessible21 * @Title: UnitySearchBarAccessible
22 * @short_description: Implementation of the ATK interfaces for #SearchBar22 * @short_description: Implementation of the ATK interfaces for #SearchBar
23 * @see_also: SearchBar at DashSearchBar.h23 * @see_also: SearchBar at SearchBar.h
24 *24 *
25 * #UnitySearchBarAccessible implements the required ATK interfaces for25 * #UnitySearchBarAccessible implements the required ATK interfaces for
26 * #SearchBar, ie: exposing the different SearchBarIcon on the model as26 * #SearchBar, ie: exposing the different SearchBarIcon on the model as
@@ -33,9 +33,9 @@
33#include "unity-search-bar-accessible.h"33#include "unity-search-bar-accessible.h"
3434
35#include "unitya11y.h"35#include "unitya11y.h"
36#include "DashSearchBar.h"36#include "SearchBar.h"
3737
38using namespace unity::dash;38using namespace unity;
3939
40/* GObject */40/* GObject */
41static void unity_search_bar_accessible_class_init(UnitySearchBarAccessibleClass* klass);41static void unity_search_bar_accessible_class_init(UnitySearchBarAccessibleClass* klass);
4242
=== modified file 'plugins/unityshell/src/unitya11y.cpp'
--- plugins/unityshell/src/unitya11y.cpp 2011-11-07 22:28:01 +0000
+++ plugins/unityshell/src/unitya11y.cpp 2012-02-06 11:00:29 +0000
@@ -299,7 +299,7 @@
299 if (object->Type().IsDerivedFromType(unity::dash::ResultViewGrid::StaticObjectType))299 if (object->Type().IsDerivedFromType(unity::dash::ResultViewGrid::StaticObjectType))
300 return unity_rvgrid_accessible_new(object);300 return unity_rvgrid_accessible_new(object);
301301
302 if (object->Type().IsDerivedFromType(unity::dash::SearchBar::StaticObjectType))302 if (object->Type().IsDerivedFromType(unity::SearchBar::StaticObjectType))
303 return unity_search_bar_accessible_new(object);303 return unity_search_bar_accessible_new(object);
304304
305 if (object->Type().IsDerivedFromType(unity::switcher::SwitcherView::StaticObjectType))305 if (object->Type().IsDerivedFromType(unity::switcher::SwitcherView::StaticObjectType))
306306
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2012-02-04 01:55:49 +0000
+++ plugins/unityshell/src/unityshell.cpp 2012-02-06 11:00:29 +0000
@@ -52,7 +52,6 @@
5252
53#include "unitya11y.h"53#include "unitya11y.h"
5454
55#include "ubus-server.h"
56#include "UBusMessages.h"55#include "UBusMessages.h"
57#include "UScreen.h"56#include "UScreen.h"
5857
@@ -119,6 +118,7 @@
119 , dash_is_open_ (false)118 , dash_is_open_ (false)
120 , grab_index_ (0)119 , grab_index_ (0)
121 , painting_tray_ (false)120 , painting_tray_ (false)
121 , last_hud_show_time_(0)
122{122{
123 Timer timer;123 Timer timer;
124 gfloat version;124 gfloat version;
@@ -258,6 +258,8 @@
258 }258 }
259#endif259#endif
260260
261 optionSetShowHudInitiate(boost::bind(&UnityScreen::ShowHudInitiate, this, _1, _2, _3));
262 optionSetShowHudTerminate(boost::bind(&UnityScreen::ShowHudTerminate, this, _1, _2, _3));
261 optionSetBackgroundColorNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));263 optionSetBackgroundColorNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
262 optionSetLauncherHideModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));264 optionSetLauncherHideModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
263 optionSetBacklightModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));265 optionSetBacklightModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
@@ -371,7 +373,7 @@
371 sout << "<Alt>" << XKeysymToString(above_tab_keysym);373 sout << "<Alt>" << XKeysymToString(above_tab_keysym);
372374
373 screen->removeAction(&optionGetAltTabNextWindow());375 screen->removeAction(&optionGetAltTabNextWindow());
374 376
375 CompAction action = CompAction();377 CompAction action = CompAction();
376 action.keyFromString(sout.str());378 action.keyFromString(sout.str());
377 action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab);379 action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab);
@@ -386,7 +388,7 @@
386 sout << "<Alt><Shift>" << XKeysymToString(above_tab_keysym);388 sout << "<Alt><Shift>" << XKeysymToString(above_tab_keysym);
387389
388 screen->removeAction(&optionGetAltTabPrevWindow());390 screen->removeAction(&optionGetAltTabPrevWindow());
389 391
390 CompAction action = CompAction();392 CompAction action = CompAction();
391 action.keyFromString(sout.str());393 action.keyFromString(sout.str());
392 action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab);394 action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab);
@@ -820,8 +822,8 @@
820bool UnityScreen::forcePaintOnTop ()822bool UnityScreen::forcePaintOnTop ()
821{823{
822 return !allowWindowPaint ||824 return !allowWindowPaint ||
823 ((switcher_controller_->Visible() ||825 ((switcher_controller_->Visible() ||
824 dash_is_open_) && !fullscreen_windows_.empty () && (!(screen->grabbed () && !screen->otherGrabExist (NULL))));826 dash_is_open_) && !fullscreen_windows_.empty () && (!(screen->grabbed () && !screen->otherGrabExist (NULL))));
825}827}
826828
827void UnityWindow::paintThumbnail (nux::Geometry const& bounding, float alpha)829void UnityWindow::paintThumbnail (nux::Geometry const& bounding, float alpha)
@@ -967,7 +969,7 @@
967{969{
968 if (mShowdesktopHandler)970 if (mShowdesktopHandler)
969 if (mShowdesktopHandler->animate (ms))971 if (mShowdesktopHandler->animate (ms))
970 { 972 {
971 delete mShowdesktopHandler;973 delete mShowdesktopHandler;
972 mShowdesktopHandler = NULL;974 mShowdesktopHandler = NULL;
973 return true;975 return true;
@@ -996,7 +998,7 @@
996 return false;998 return false;
997999
998 if (w->state () & (CompWindowStateSkipPagerMask |1000 if (w->state () & (CompWindowStateSkipPagerMask |
999 CompWindowStateSkipTaskbarMask))1001 CompWindowStateSkipTaskbarMask))
1000 return false;1002 return false;
10011003
1002 if ((w->state () & CompWindowStateHiddenMask))1004 if ((w->state () & CompWindowStateHiddenMask))
@@ -1669,7 +1671,7 @@
1669 altTabInitiateCommon(action, state, options);1671 altTabInitiateCommon(action, state, options);
1670 switcher_controller_->Select(1); // always select the current application1672 switcher_controller_->Select(1); // always select the current application
1671 }1673 }
1672 1674
1673 switcher_controller_->NextDetail();1675 switcher_controller_->NextDetail();
16741676
1675 action->setState(action->state() | CompAction::StateTermKey);1677 action->setState(action->state() | CompAction::StateTermKey);
@@ -1680,7 +1682,7 @@
1680{1682{
1681 if (switcher_controller_->Visible())1683 if (switcher_controller_->Visible())
1682 switcher_controller_->PrevDetail();1684 switcher_controller_->PrevDetail();
1683 1685
1684 return false;1686 return false;
1685}1687}
16861688
@@ -1735,6 +1737,44 @@
1735 PluginAdapter::Default ()->restoreInputFocus ();1737 PluginAdapter::Default ()->restoreInputFocus ();
1736}1738}
17371739
1740bool UnityScreen::ShowHudInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1741{
1742 // to receive the Terminate event
1743 if (state & CompAction::StateInitKey)
1744 action->setState(action->state() | CompAction::StateTermKey);
1745
1746 last_hud_show_time_ = g_get_monotonic_time();
1747
1748 return false;
1749}
1750
1751bool UnityScreen::ShowHudTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1752{
1753 if (optionGetShowHud().key().toString() == action->key().toString())
1754 {
1755 if (switcher_controller_->Visible())
1756 return false; // early exit if the switcher is open
1757
1758 gint64 current_time = g_get_monotonic_time();
1759 if (current_time - last_hud_show_time_ < 150 * 1000)
1760 {
1761 if (hud_controller_->IsVisible())
1762 {
1763 ubus_manager_.SendMessage(UBUS_HUD_CLOSE_REQUEST);
1764 }
1765 else
1766 {
1767 hud_controller_->ShowHud();
1768 }
1769 last_hud_show_time_ = 0;
1770 }
1771 }
1772
1773 action->setState(action->state() & ~CompAction::StateTermKey);
1774
1775 return false;
1776}
1777
1738gboolean UnityScreen::initPluginActions(gpointer data)1778gboolean UnityScreen::initPluginActions(gpointer data)
1739{1779{
1740 CompPlugin* p = CompPlugin::find("expo");1780 CompPlugin* p = CompPlugin::find("expo");
@@ -1821,7 +1861,7 @@
1821 bool result = screen->initPluginForScreen(p);1861 bool result = screen->initPluginForScreen(p);
1822 if (p->vTable->name() == "unityshell")1862 if (p->vTable->name() == "unityshell")
1823 initAltTabNextWindow();1863 initAltTabNextWindow();
1824 1864
1825 return result;1865 return result;
1826}1866}
18271867
@@ -1834,8 +1874,8 @@
1834 return "Unity";1874 return "Unity";
1835}1875}
18361876
1837bool isNuxWindow (CompWindow* value) 1877bool isNuxWindow (CompWindow* value)
1838{ 1878{
1839 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();1879 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();
1840 auto id = value->id();1880 auto id = value->id();
18411881
@@ -1862,7 +1902,7 @@
1862void UnityScreen::RaiseInputWindows()1902void UnityScreen::RaiseInputWindows()
1863{1903{
1864 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();1904 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();
1865 1905
1866 for (auto window : xwns)1906 for (auto window : xwns)
1867 {1907 {
1868 CompWindow* cwin = screen->findWindow(window);1908 CompWindow* cwin = screen->findWindow(window);
@@ -1995,7 +2035,7 @@
1995 if (!window->onCurrentDesktop ())2035 if (!window->onCurrentDesktop ())
1996 return false;2036 return false;
19972037
1998 /* Only withdrawn windows 2038 /* Only withdrawn windows
1999 * which are marked hidden2039 * which are marked hidden
2000 * are excluded */2040 * are excluded */
2001 if (!window->shaded () &&2041 if (!window->shaded () &&
@@ -2003,8 +2043,8 @@
2003 (window->state () & CompWindowStateHiddenMask))2043 (window->state () & CompWindowStateHiddenMask))
2004 return false;2044 return false;
20052045
2006 if (window->geometry ().x () + window->geometry ().width () <= 0 ||2046 if (window->geometry ().x () + window->geometry ().width () <= 0 ||
2007 window->geometry ().y () + window->geometry ().height () <= 0 ||2047 window->geometry ().y () + window->geometry ().height () <= 0 ||
2008 window->geometry ().x () >= (int) screen->width ()||2048 window->geometry ().x () >= (int) screen->width ()||
2009 window->geometry ().y () >= (int) screen->height ())2049 window->geometry ().y () >= (int) screen->height ())
2010 return false;2050 return false;
@@ -2110,7 +2150,7 @@
2110 !(lastState & CompWindowStateFullscreenMask))2150 !(lastState & CompWindowStateFullscreenMask))
2111 UnityScreen::get (screen)->fullscreen_windows_.push_back(window);2151 UnityScreen::get (screen)->fullscreen_windows_.push_back(window);
2112 else if (lastState & CompWindowStateFullscreenMask &&2152 else if (lastState & CompWindowStateFullscreenMask &&
2113 !(window->state () & CompWindowStateFullscreenMask))2153 !(window->state () & CompWindowStateFullscreenMask))
2114 UnityScreen::get (screen)->fullscreen_windows_.remove(window);2154 UnityScreen::get (screen)->fullscreen_windows_.remove(window);
21152155
2116 PluginAdapter::Default()->NotifyStateChange(window, window->state(), lastState);2156 PluginAdapter::Default()->NotifyStateChange(window, window->state(), lastState);
@@ -2259,9 +2299,9 @@
2259 {2299 {
2260 case UnityshellOptions::BackgroundColor:2300 case UnityshellOptions::BackgroundColor:
2261 {2301 {
2262 nux::Color override_color (optionGetBackgroundColorRed() / 65535.0f, 2302 nux::Color override_color (optionGetBackgroundColorRed() / 65535.0f,
2263 optionGetBackgroundColorGreen() / 65535.0f, 2303 optionGetBackgroundColorGreen() / 65535.0f,
2264 optionGetBackgroundColorBlue() / 65535.0f, 2304 optionGetBackgroundColorBlue() / 65535.0f,
2265 optionGetBackgroundColorAlpha() / 65535.0f);2305 optionGetBackgroundColorAlpha() / 65535.0f);
22662306
2267 override_color.red = override_color.red / override_color.alpha;2307 override_color.red = override_color.red / override_color.alpha;
@@ -2309,6 +2349,7 @@
2309 launcher_options->icon_size = optionGetIconSize();2349 launcher_options->icon_size = optionGetIconSize();
2310 launcher_options->tile_size = optionGetIconSize() + 6;2350 launcher_options->tile_size = optionGetIconSize() + 6;
23112351
2352 hud_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;
2312 /* The launcher geometry includes 1px used to draw the right margin2353 /* The launcher geometry includes 1px used to draw the right margin
2313 * that must not be considered when drawing the dash */2354 * that must not be considered when drawing the dash */
2314 dash_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;2355 dash_controller_->launcher_width = launcher_controller_->launcher().GetAbsoluteWidth() - 1;
@@ -2497,6 +2538,11 @@
2497 /* Setup Places */2538 /* Setup Places */
2498 dash_controller_.reset(new dash::Controller());2539 dash_controller_.reset(new dash::Controller());
2499 dash_controller_->on_realize.connect(sigc::mem_fun(this, &UnityScreen::OnDashRealized));2540 dash_controller_->on_realize.connect(sigc::mem_fun(this, &UnityScreen::OnDashRealized));
2541
2542 /* Setup Hud */
2543 hud_controller_.reset(new hud::Controller());
2544 AddChild(hud_controller_.get());
2545 LOG_INFO(logger) << "initLauncher-hud " << timer.ElapsedSeconds() << "s";
2500 2546
2501 // Setup Shortcut Hint2547 // Setup Shortcut Hint
2502 InitHints();2548 InitHints();
@@ -2646,7 +2692,7 @@
26462692
2647 if (mShowdesktopHandler)2693 if (mShowdesktopHandler)
2648 delete mShowdesktopHandler;2694 delete mShowdesktopHandler;
2649 2695
2650 if (focusdesktop_handle_)2696 if (focusdesktop_handle_)
2651 g_source_remove(focusdesktop_handle_);2697 g_source_remove(focusdesktop_handle_);
26522698
26532699
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2012-01-29 06:08:20 +0000
+++ plugins/unityshell/src/unityshell.h 2012-02-06 11:00:29 +0000
@@ -58,6 +58,8 @@
58#include <compiztoolbox/compiztoolbox.h>58#include <compiztoolbox/compiztoolbox.h>
59#include <dlfcn.h>59#include <dlfcn.h>
6060
61#include "HudController.h"
62
61namespace unity63namespace unity
62{64{
6365
@@ -202,6 +204,9 @@
202 bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);204 bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
203 bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);205 bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
204206
207 /* handle hud key activations */
208 bool ShowHudInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
209 bool ShowHudTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
205 bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);210 bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
206 bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);211 bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
207 bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);212 bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
@@ -268,6 +273,7 @@
268 dash::Controller::Ptr dash_controller_;273 dash::Controller::Ptr dash_controller_;
269 panel::Controller::Ptr panel_controller_;274 panel::Controller::Ptr panel_controller_;
270 switcher::Controller::Ptr switcher_controller_;275 switcher::Controller::Ptr switcher_controller_;
276 hud::Controller::Ptr hud_controller_;
271277
272 shortcut::Controller::Ptr shortcut_controller_;278 shortcut::Controller::Ptr shortcut_controller_;
273 std::list<shortcut::AbstractHint*> hints_;279 std::list<shortcut::AbstractHint*> hints_;
@@ -322,6 +328,7 @@
322 CompWindowList fullscreen_windows_;328 CompWindowList fullscreen_windows_;
323 bool painting_tray_;329 bool painting_tray_;
324 unsigned int tray_paint_mask_;330 unsigned int tray_paint_mask_;
331 gint64 last_hud_show_time_;
325332
326#ifndef USE_GLES333#ifndef USE_GLES
327 ScreenEffectFramebufferObject::GLXGetProcAddressProc glXGetProcAddressP;334 ScreenEffectFramebufferObject::GLXGetProcAddressProc glXGetProcAddressP;
@@ -396,7 +403,7 @@
396 UnityMinimizedHandler *mMinimizeHandler;403 UnityMinimizedHandler *mMinimizeHandler;
397404
398 UnityShowdesktopHandler *mShowdesktopHandler;405 UnityShowdesktopHandler *mShowdesktopHandler;
399 406
400private:407private:
401408
402 guint focusdesktop_handle_;409 guint focusdesktop_handle_;
403410
=== modified file 'plugins/unityshell/unityshell.xml.in'
--- plugins/unityshell/unityshell.xml.in 2012-02-01 00:06:29 +0000
+++ plugins/unityshell/unityshell.xml.in 2012-02-06 11:00:29 +0000
@@ -40,9 +40,14 @@
40 </requirement>40 </requirement>
41 </deps>41 </deps>
42 <options>42 <options>
43 <group>43 <group>
44 <_short>Behaviour</_short>44 <_short>Behaviour</_short>
45 <option name="launcher_hide_mode" type="int">45 <option name="show_hud" type="key">
46 <_short>Key to show the HUD</_short>
47 <_long>Make the HUD appear with this key</_long>
48 <default>&lt;Alt&gt;</default>
49 </option>
50 <option name="launcher_hide_mode" type="int">
46 <_short>Hide Launcher</_short>51 <_short>Hide Launcher</_short>
47 <_long>Make the launcher hide automatically after some time of inactivity: always or just when the focussed window is not over the launcher</_long>52 <_long>Make the launcher hide automatically after some time of inactivity: always or just when the focussed window is not over the launcher</_long>
48 <min>0</min>53 <min>0</min>
@@ -64,16 +69,16 @@
64 <value>3</value>69 <value>3</value>
65 <_name>Dodge Active Window</_name>70 <_name>Dodge Active Window</_name>
66 </desc>71 </desc>
67 </option>72 </option>
68 <option name="show_launcher" type="key">73 <option name="show_launcher" type="key">
69 <_short>Key to show the launcher</_short>74 <_short>Key to show the launcher</_short>
70 <_long>Make the launcher appear with that key</_long>75 <_long>Make the launcher appear with that key</_long>
71 <default>&lt;Super&gt;</default>76 <default>&lt;Super&gt;</default>
72 </option>77 </option>
73 <option name="keyboard_focus" type="key">78 <option name="keyboard_focus" type="key">
74 <_short>Key to put keyboard-focus on launcher</_short>79 <_short>Key to put keyboard-focus on launcher</_short>
75 <_long>Set the keyboard-focus on the launcher so it can be navigated with the cursor-keys</_long>80 <_long>Set the keyboard-focus on the launcher so it can be navigated with the cursor-keys</_long>
76 <default>&lt;Alt&gt;F1</default>81 <default>&lt;Alt&gt;F1</default>
77 </option>82 </option>
78 <option name="execute_command" type="key">83 <option name="execute_command" type="key">
79 <_short>Key to execute a command</_short>84 <_short>Key to execute a command</_short>
@@ -118,37 +123,37 @@
118 <_long>fixme</_long>123 <_long>fixme</_long>
119 <default>&lt;Alt&gt;&lt;Shift&gt;Tab</default>124 <default>&lt;Alt&gt;&lt;Shift&gt;Tab</default>
120 </option>125 </option>
121 <option name="alt_tab_right" type="key">126 <option name="alt_tab_right" type="key">
122 <_short>Go right in the switcher</_short>127 <_short>Go right in the switcher</_short>
123 <_long>fixme</_long>128 <_long>fixme</_long>
124 <default>&lt;Alt&gt;Right</default>129 <default>&lt;Alt&gt;Right</default>
125 <passive_grab>false</passive_grab>130 <passive_grab>false</passive_grab>
126 <internal/>131 <internal/>
127 </option>132 </option>
128 <option name="alt_tab_left" type="key">133 <option name="alt_tab_left" type="key">
129 <_short>Go left in the switcher</_short>134 <_short>Go left in the switcher</_short>
130 <_long>fixme</_long>135 <_long>fixme</_long>
131 <default>&lt;Alt&gt;Left</default>136 <default>&lt;Alt&gt;Left</default>
132 <passive_grab>false</passive_grab>137 <passive_grab>false</passive_grab>
133 <internal/>138 <internal/>
134 </option>139 </option>
135 <option name="alt_tab_detail_start" type="key">140 <option name="alt_tab_detail_start" type="key">
136 <_short>Key to expose the windows in the switcher</_short>141 <_short>Key to expose the windows in the switcher</_short>
137 <_long>fixme</_long>142 <_long>fixme</_long>
138 <default>&lt;Alt&gt;Down</default>143 <default>&lt;Alt&gt;Down</default>
139 <passive_grab>false</passive_grab>144 <passive_grab>false</passive_grab>
140 <internal/>145 <internal/>
141 </option>146 </option>
142 <option name="alt_tab_detail_stop" type="key">147 <option name="alt_tab_detail_stop" type="key">
143 <_short>Key to collapse windows in the switcher</_short>148 <_short>Key to collapse windows in the switcher</_short>
144 <_long>fixme</_long>149 <_long>fixme</_long>
145 <default>&lt;Alt&gt;Up</default>150 <default>&lt;Alt&gt;Up</default>
146 <passive_grab>false</passive_grab>151 <passive_grab>false</passive_grab>
147 <internal/>152 <internal/>
148 </option>153 </option>
149 <option name="alt_tab_next_window" type="key">154 <option name="alt_tab_next_window" type="key">
150 <_short>Key to flip through windows in the switcher</_short>155 <_short>Key to flip through windows in the switcher</_short>
151 <_long>fixme</_long>156 <_long>fixme</_long>
152 <passive_grab>false</passive_grab>157 <passive_grab>false</passive_grab>
153 </option>158 </option>
154 <option name="alt_tab_prev_window" type="key">159 <option name="alt_tab_prev_window" type="key">
@@ -156,11 +161,11 @@
156 <_long>fixme</_long>161 <_long>fixme</_long>
157 <passive_grab>false</passive_grab>162 <passive_grab>false</passive_grab>
158 </option>163 </option>
159 <option name="show_minimized_windows" type="bool">164 <option name="show_minimized_windows" type="bool">
160 <_short>Show minimized windows in switcher</_short>165 <_short>Show minimized windows in switcher</_short>
161 <_long>Hack to enable minimized windows in switcher. Disable and report bugs if problems are caused</_long>166 <_long>Hack to enable minimized windows in switcher. Disable and report bugs if problems are caused</_long>
162 <default>true</default>167 <default>true</default>
163 </option>168 </option>
164 </group>169 </group>
165 <group>170 <group>
166 <_short>Experimental</_short>171 <_short>Experimental</_short>
@@ -359,7 +364,7 @@
359 <max>100</max>364 <max>100</max>
360 <default>75</default>365 <default>75</default>
361 </option>366 </option>
362 367
363 <option name="devices_option" type="int">368 <option name="devices_option" type="int">
364 <_short>Show Devices</_short>369 <_short>Show Devices</_short>
365 <_long>Show devices in the launcher</_long>370 <_long>Show devices in the launcher</_long>
366371
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2012-01-24 09:02:23 +0000
+++ po/POTFILES.in 2012-02-06 11:00:29 +0000
@@ -6,7 +6,7 @@
6plugins/unityshell/src/SpacerLauncherIcon.cpp6plugins/unityshell/src/SpacerLauncherIcon.cpp
7plugins/unityshell/src/TrashLauncherIcon.cpp7plugins/unityshell/src/TrashLauncherIcon.cpp
8plugins/unityshell/src/BFBLauncherIcon.cpp8plugins/unityshell/src/BFBLauncherIcon.cpp
9plugins/unityshell/src/DashSearchBar.cpp9plugins/unityshell/src/SearchBar.cpp
10plugins/unityshell/src/DashView.cpp10plugins/unityshell/src/DashView.cpp
11plugins/unityshell/src/DesktopLauncherIcon.cpp11plugins/unityshell/src/DesktopLauncherIcon.cpp
12plugins/unityshell/src/FilterExpanderLabel.cpp12plugins/unityshell/src/FilterExpanderLabel.cpp
1313
=== modified file 'standalone-clients/CMakeLists.txt'
--- standalone-clients/CMakeLists.txt 2012-01-24 08:53:48 +0000
+++ standalone-clients/CMakeLists.txt 2012-02-06 11:00:29 +0000
@@ -47,10 +47,10 @@
47 ${UNITY_SRC}/BackgroundEffectHelper.h47 ${UNITY_SRC}/BackgroundEffectHelper.h
48 ${UNITY_SRC}/BGHash.cpp48 ${UNITY_SRC}/BGHash.cpp
49 ${UNITY_SRC}/BGHash.h49 ${UNITY_SRC}/BGHash.h
50 ${UNITY_SRC}/DashSearchBar.cpp50 ${UNITY_SRC}/SearchBar.cpp
51 ${UNITY_SRC}/DashSearchBar.h51 ${UNITY_SRC}/SearchBar.h
52 ${UNITY_SRC}/DashSearchBarSpinner.cpp52 ${UNITY_SRC}/SearchBarSpinner.cpp
53 ${UNITY_SRC}/DashSearchBarSpinner.h53 ${UNITY_SRC}/SearchBarSpinner.h
54 ${UNITY_SRC}/DashView.cpp54 ${UNITY_SRC}/DashView.cpp
55 ${UNITY_SRC}/DashView.h55 ${UNITY_SRC}/DashView.h
56 ${UNITY_SRC}/DashViewPrivate.cpp56 ${UNITY_SRC}/DashViewPrivate.cpp
@@ -84,6 +84,10 @@
84 ${UNITY_SRC}/PlacesSimpleTile.h84 ${UNITY_SRC}/PlacesSimpleTile.h
85 ${UNITY_SRC}/PlacesVScrollBar.cpp85 ${UNITY_SRC}/PlacesVScrollBar.cpp
86 ${UNITY_SRC}/PlacesVScrollBar.h86 ${UNITY_SRC}/PlacesVScrollBar.h
87 ${UNITY_SRC}/DashView.cpp
88 ${UNITY_SRC}/DashView.h
89 ${UNITY_SRC}/DashViewPrivate.cpp
90 ${UNITY_SRC}/DashViewPrivate.h
87 ${UNITY_SRC}/DashStyle.cpp91 ${UNITY_SRC}/DashStyle.cpp
88 ${UNITY_SRC}/IconLoader.cpp92 ${UNITY_SRC}/IconLoader.cpp
89 ${UNITY_SRC}/IconLoader.h93 ${UNITY_SRC}/IconLoader.h
@@ -456,6 +460,39 @@
456 )460 )
457add_dependencies (bg-hash unity-core-${UNITY_API_VERSION})461add_dependencies (bg-hash unity-core-${UNITY_API_VERSION})
458462
463add_executable (hud
464 StandaloneHud.cpp
465 ${UNITY_SRC}/BackgroundEffectHelper.cpp
466 ${UNITY_SRC}/BackgroundEffectHelper.h
467 ${UNITY_SRC}/DashSettings.cpp
468 ${UNITY_SRC}/DashSettings.h
469 ${UNITY_SRC}/DashStyle.cpp
470 ${UNITY_SRC}/HudButton.cpp
471 ${UNITY_SRC}/HudIcon.cpp
472 ${UNITY_SRC}/HudIcon.h
473 ${UNITY_SRC}/HudIconTextureSource.cpp
474 ${UNITY_SRC}/HudIconTextureSource.h
475 ${UNITY_SRC}/HudView.cpp
476 ${UNITY_SRC}/IMTextEntry.cpp
477 ${UNITY_SRC}/Introspectable.cpp
478 ${UNITY_SRC}/IconTexture.cpp
479 ${UNITY_SRC}/IconLoader.cpp
480 ${UNITY_SRC}/IconRenderer.cpp
481 ${UNITY_SRC}/IconTextureSource.cpp
482 ${UNITY_SRC}/JSONParser.cpp
483 ${UNITY_SRC}/OverlayRenderer.cpp
484 ${UNITY_SRC}/SearchBar.cpp
485 ${UNITY_SRC}/SearchBarSpinner.cpp
486 ${UNITY_SRC}/StaticCairoText.cpp
487 ${UNITY_SRC}/TextureCache.cpp
488 ${UNITY_SRC}/Timer.cpp
489 ${UNITY_SRC}/UBusWrapper.cpp
490 ${UNITY_SRC}/ubus-server.cpp
491 ${UNITY_SRC}/UScreen.cpp
492 ${UNITY_SRC}/UScreen.h
493 )
494add_dependencies (hud unity-core-${UNITY_API_VERSION})
495
459add_executable (test-shortcut496add_executable (test-shortcut
460 TestShortcut.cpp497 TestShortcut.cpp
461 ${UNITY_SRC}/AbstractSeparator.cpp498 ${UNITY_SRC}/AbstractSeparator.cpp
462499
=== added file 'standalone-clients/StandaloneHud.cpp'
--- standalone-clients/StandaloneHud.cpp 1970-01-01 00:00:00 +0000
+++ standalone-clients/StandaloneHud.cpp 2012-02-06 11:00:29 +0000
@@ -0,0 +1,171 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Gordon Allott <gord.allott@canonical.com>
18 *
19 */
20
21#include <sstream>
22#include "Nux/Nux.h"
23#include "Nux/VLayout.h"
24#include "Nux/Button.h"
25#include "Nux/TextureArea.h"
26#include "Nux/WindowThread.h"
27#include "NuxGraphics/GraphicsEngine.h"
28#include <gtk/gtk.h>
29
30#include "HudView.h"
31#include "DashStyle.h"
32#include "DashSettings.h"
33#include <NuxCore/Logger.h>
34
35namespace
36{
37 nux::logging::Logger logger("unity.tests.Hud");
38}
39
40class TestRunner
41{
42public:
43 TestRunner ();
44 ~TestRunner ();
45
46 static void InitWindowThread (nux::NThread* thread, void* InitData);
47 void Init ();
48 nux::Layout *layout;
49 unity::hud::View* hud_view_;
50 unity::dash::Settings dash_settings_;
51
52private:
53 unity::hud::Hud hud_service_;
54};
55
56TestRunner::TestRunner ()
57 : hud_service_("com.canonical.hud", "/com/canonical/hud")
58{
59}
60
61TestRunner::~TestRunner ()
62{
63}
64
65void TestRunner::Init ()
66{
67 LOG_WARNING(logger) << "test init";
68 layout = new nux::VLayout();
69
70 hud_view_ = new unity::hud::View();
71
72 layout->AddView (hud_view_, 1, nux::MINOR_POSITION_TOP, nux::MINOR_SIZE_FULL);
73 nux::GetWindowCompositor().SetKeyFocusArea(hud_view_->default_focus());
74
75 nux::GetWindowThread()->SetLayout (layout);
76
77 // things the controller normally does
78 hud_service_.queries_updated.connect([&] (unity::hud::Hud::Queries queries) {
79 hud_view_->SetQueries(queries);
80 std::string icon_name = "";
81 for (auto query = queries.begin(); query != queries.end(); query++)
82 {
83 if (!(*query)->icon_name.empty())
84 {
85 LOG_DEBUG(logger) << "Setting icon name to: " << (*query)->icon_name;
86 icon_name = (*query)->icon_name;
87 break;
88 }
89 }
90
91 hud_view_->SetIcon(icon_name);
92
93 });
94
95 hud_view_->query_activated.connect([&] (unity::hud::Query::Ptr query) {
96 hud_service_.ExecuteQuery(query, 0);
97 });
98
99 hud_view_->query_selected.connect([&] (unity::hud::Query::Ptr query) {
100 hud_view_->SetIcon(query->icon_name);
101 });
102
103 hud_view_->search_changed.connect([&] (std::string search_string) {
104 hud_service_.RequestQuery(search_string);
105 });
106
107 hud_view_->search_activated.connect([&] (std::string search_string) {
108 hud_service_.ExecuteQueryBySearch(search_string, 0);
109 });
110
111 hud_service_.RequestQuery("");
112
113 hud_view_->SetWindowGeometry(layout->GetAbsoluteGeometry(), layout->GetGeometry());
114
115}
116
117void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
118{
119 TestRunner *self = (TestRunner *) InitData;
120 self->Init ();
121}
122
123void
124ControlThread (nux::NThread* thread,
125 void* data)
126{
127 // sleep for 3 seconds
128 nux::SleepForMilliseconds (3000);
129 printf ("ControlThread successfully started\n");
130}
131
132
133int main(int argc, char **argv)
134{
135 nux::SystemThread* st = NULL;
136 nux::WindowThread* wt = NULL;
137
138 // no real tests right now, just make sure we don't get any criticals and such
139 // waiting on nice perceptual diff support before we can build real tests
140 // for views
141
142 g_type_init ();
143 gtk_init (&argc, &argv);
144
145 nux::NuxInitialize(0);
146
147 // Slightly higher as we're more likely to test things we know will fail
148 nux::logging::configure_logging("unity.hud=debug");
149
150 nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
151 LOG_DEBUG(logger) << "starting the standalone hud";
152 // The instances for the pseudo-singletons.
153 unity::dash::Style dash_style;
154
155 TestRunner *test_runner = new TestRunner ();
156 wt = nux::CreateGUIThread(TEXT("Hud Prototype Test"),
157 1200, 768,
158 0,
159 &TestRunner::InitWindowThread,
160 test_runner);
161
162 st = nux::CreateSystemThread (NULL, ControlThread, wt);
163
164 if (st)
165 st->Start (NULL);
166
167 wt->Run (NULL);
168 delete st;
169 delete wt;
170 return 0;
171}
0172
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-02-01 03:39:14 +0000
+++ tests/CMakeLists.txt 2012-02-06 11:00:29 +0000
@@ -99,6 +99,8 @@
9999
100# The service that provides DBus services to test against100# The service that provides DBus services to test against
101 add_executable(test-gtest-service101 add_executable(test-gtest-service
102 test_service_hud.c
103 test_service_hud.h
102 test_service_lens.c104 test_service_lens.c
103 test_service_lens.h105 test_service_lens.h
104 test_service_main.c106 test_service_main.c
@@ -183,7 +185,8 @@
183 test_utils.h185 test_utils.h
184 test_ratings_filter.cpp186 test_ratings_filter.cpp
185 test_results.cpp187 test_results.cpp
186 )188 test_hud.cpp
189 )
187 target_link_libraries(test-gtest-dbus ${GTEST_BOTH_LIBRARIES})190 target_link_libraries(test-gtest-dbus ${GTEST_BOTH_LIBRARIES})
188 add_test(UnityGTestDBus test-gtest-dbus)191 add_test(UnityGTestDBus test-gtest-dbus)
189 add_dependencies(test-gtest-dbus unity-core-${UNITY_API_VERSION} test-gtest-service)192 add_dependencies(test-gtest-dbus unity-core-${UNITY_API_VERSION} test-gtest-service)
190193
=== added file 'tests/test_hud.cpp'
--- tests/test_hud.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_hud.cpp 2012-02-06 11:00:29 +0000
@@ -0,0 +1,104 @@
1#include <gtest/gtest.h>
2#include <glib-object.h>
3#include <UnityCore/GLibWrapper.h>
4#include <UnityCore/Hud.h>
5
6using namespace std;
7
8namespace
9{
10
11GMainLoop* loop_ = NULL;
12unity::hud::Hud *hud;
13
14class TestHud : public ::testing::Test
15{
16public:
17 TestHud()
18 : query_return_result(false)
19 , connected_result(false)
20 {
21 }
22 unity::hud::Hud::Queries queries;
23 bool query_return_result;
24 bool connected_result;
25};
26
27TEST_F(TestHud, TestConstruction)
28{
29 loop_ = g_main_loop_new(NULL, FALSE);
30 hud = new unity::hud::Hud("com.canonical.Unity.Test", "/com/canonical/hud");
31
32 // performs a check on the hud, if the hud is connected, report a sucess
33 auto timeout_check = [] (gpointer data) -> gboolean
34 {
35 TestHud* self = static_cast<TestHud*>(data);
36 if (hud->connected)
37 {
38 self->connected_result = true;
39 g_main_loop_quit(loop_);
40 return FALSE;
41 }
42 else
43 {
44 self->connected_result = false;
45 return TRUE;
46 }
47 };
48
49
50 // if the hud is not connected when this lambda runs, fail.
51 auto timeout_bailout = [] (gpointer data) -> gboolean
52 {
53 TestHud* self = static_cast<TestHud*>(data);
54 // reached timeout, failed testing
55 self->connected_result = false;
56 g_main_loop_quit(loop_);
57 return FALSE;
58 };
59
60 g_timeout_add_seconds(1, timeout_check, this);
61 g_timeout_add_seconds(10, timeout_bailout, this);
62
63 g_main_loop_run(loop_);
64
65 EXPECT_EQ(connected_result, true);
66}
67
68TEST_F(TestHud, TestQueryReturn)
69{
70 query_return_result = false;
71
72 // make sure we receive the queries
73 auto query_connection = [this](unity::hud::Hud::Queries queries_)
74 {
75 query_return_result = true;
76 g_main_loop_quit(loop_);
77 queries = queries_;
78 };
79
80 auto timeout_bailout = [] (gpointer data) -> gboolean
81 {
82 TestHud* self = static_cast<TestHud*>(data);
83 self->query_return_result = false;
84 g_main_loop_quit(loop_);
85 return FALSE;
86 };
87
88 hud->queries_updated.connect(query_connection);
89
90 guint source_id = g_timeout_add_seconds(10, timeout_bailout, this);
91
92 // next check we get 30 entries from this specific known callback
93 hud->RequestQuery("Request30Queries");
94 g_main_loop_run(loop_);
95 EXPECT_EQ(query_return_result, true);
96 EXPECT_NE(queries.size(), 0);
97 g_source_remove(source_id);
98
99 // finally close the connection - Nothing to check for here
100 hud->CloseQuery();
101}
102
103
104}
0105
=== added file 'tests/test_service_hud.c'
--- tests/test_service_hud.c 1970-01-01 00:00:00 +0000
+++ tests/test_service_hud.c 2012-02-06 11:00:29 +0000
@@ -0,0 +1,268 @@
1#include "test_service_hud.h"
2#include <unity.h>
3#include <gio/gio.h>
4
5const char * hud_interface =
6"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
7"<node name=\"/\">\n"
8" <interface name=\"com.canonical.hud\">\n"
9"<!-- Properties -->\n"
10" <!-- None -->\n"
11"\n"
12"<!-- Functions -->\n"
13" <method name=\"StartQuery\">\n"
14" <!-- in -->\n"
15" <arg type=\"s\" name=\"query\" direction=\"in\" />\n"
16" <arg type=\"i\" name=\"entries\" direction=\"in\" />\n"
17" <!-- out -->\n"
18" <arg type=\"s\" name=\"target\" direction=\"out\" />\n"
19" <arg type=\"a(sssssv)\" name=\"suggestions\" direction=\"out\" />\n"
20" <arg type=\"v\" name=\"querykey\" direction=\"out\" />\n"
21" </method>\n"
22"\n"
23" <method name=\"ExecuteQuery\">\n"
24" <arg type=\"v\" name=\"key\" direction=\"in\" />\n"
25" <arg type=\"u\" name=\"timestamp\" direction=\"in\" />\n"
26" </method>\n"
27"\n"
28" <method name=\"CloseQuery\">\n"
29" <arg type=\"v\" name=\"querykey\" direction=\"in\" />\n"
30" </method>\n"
31"\n"
32"<!-- Signals -->\n"
33" <signal name=\"UpdatedQuery\">\n"
34" <arg type=\"s\" name=\"target\" direction=\"out\" />\n"
35" <arg type=\"a(sssssv)\" name=\"suggestions\" direction=\"out\" />\n"
36" <arg type=\"v\" name=\"querykey\" direction=\"out\" />\n"
37" </signal>\n"
38"\n"
39"<!-- End of interesting stuff -->\n"
40"\n"
41" </interface>\n"
42"</node>\n"
43;
44static void bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data);
45static void bus_method (GDBusConnection *connection,
46 const gchar *sender,
47 const gchar *object_path,
48 const gchar *interface_name,
49 const gchar *method_name,
50 GVariant *parameters,
51 GDBusMethodInvocation *invocation,
52 gpointer user_data);
53
54G_DEFINE_TYPE(ServiceHud, service_hud, G_TYPE_OBJECT);
55static GDBusNodeInfo * node_info = NULL;
56static GDBusInterfaceInfo * iface_info = NULL;
57static GDBusInterfaceVTable bus_vtable = {
58 method_call: bus_method,
59 get_property: NULL,
60 set_property: NULL,
61};
62
63
64struct _ServiceHudPrivate
65{
66 GDBusConnection * bus;
67 GCancellable * bus_lookup;
68 guint bus_registration;
69};
70
71static void
72service_hud_dispose(GObject* object)
73{
74 ServiceHud* self = SERVICE_HUD(object);
75 if (self->priv->bus_lookup != NULL) {
76 g_cancellable_cancel(self->priv->bus_lookup);
77 g_object_unref(self->priv->bus_lookup);
78 self->priv->bus_lookup = NULL;
79 }
80
81 if (self->priv->bus_registration != 0) {
82 g_dbus_connection_unregister_object(self->priv->bus, self->priv->bus_registration);
83 self->priv->bus_registration = 0;
84 }
85
86 if (self->priv->bus != NULL) {
87 g_object_unref(self->priv->bus);
88 self->priv->bus = NULL;
89 }
90
91}
92
93static void
94service_hud_class_init(ServiceHudClass* klass)
95{
96 G_OBJECT_CLASS(klass)->dispose = service_hud_dispose;
97 g_type_class_add_private (klass, sizeof (ServiceHudPrivate));
98
99 if (node_info == NULL)
100 {
101 GError * error = NULL;
102
103 node_info = g_dbus_node_info_new_for_xml(hud_interface, &error);
104 if (error != NULL)
105 {
106 g_error("Unable to parse HUD interface: %s", error->message);
107 g_error_free(error);
108 }
109 }
110
111 if (node_info != NULL && iface_info == NULL)
112 {
113 iface_info = g_dbus_node_info_lookup_interface(node_info,"com.canonical.hud");
114 if (iface_info == NULL)
115 {
116 g_error("Unable to find interface 'com.canonical.hud'");
117 }
118 }
119
120}
121
122static void
123service_hud_init(ServiceHud* self)
124{
125 self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SERVICE_TYPE_HUD, ServiceHudPrivate);
126 self->priv->bus = NULL;
127 self->priv->bus_lookup = NULL;
128 self->priv->bus_registration = 0;
129
130 self->priv->bus_lookup = g_cancellable_new();
131 g_bus_get(G_BUS_TYPE_SESSION, self->priv->bus_lookup, bus_got_cb, self);
132
133}
134
135ServiceHud*
136service_hud_new()
137{
138 return g_object_new(SERVICE_TYPE_HUD, NULL);
139}
140
141static void
142bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data)
143{
144 GError * error = NULL;
145 ServiceHud * self = SERVICE_HUD(user_data);
146 GDBusConnection * bus;
147
148 bus = g_bus_get_finish(res, &error);
149 if (error != NULL) {
150 g_critical("Unable to get bus: %s", error->message);
151 g_error_free(error);
152 return;
153 }
154
155 self->priv->bus = bus;
156
157 /* Register object */
158 self->priv->bus_registration = g_dbus_connection_register_object(bus,
159 /* path */ "/com/canonical/hud",
160 /* interface */ iface_info,
161 /* vtable */ &bus_vtable,
162 /* userdata */ self,
163 /* destroy */ NULL,
164 /* error */ &error);
165
166 if (error != NULL) {
167 g_critical ("Unable to create bus connection object, %s", error->message);
168 g_error_free(error);
169 return;
170 }
171
172 return;
173}
174
175static void
176bus_method (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data)
177{
178 if (g_strcmp0(method_name, "StartQuery") == 0)
179 {
180 GVariant * ret = NULL;
181 gchar * query = NULL;
182 int num_entries = 0;
183
184 g_variant_get(parameters, "(si)", &query, &num_entries);
185
186 /* Build into into a variant */
187 GVariantBuilder ret_builder;
188 g_variant_builder_init(&ret_builder, G_VARIANT_TYPE_TUPLE);
189 g_variant_builder_add_value(&ret_builder, g_variant_new_string("target"));
190 GVariantBuilder builder;
191
192 g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
193
194 int i = 0;
195 for (i = 0; i < num_entries; i++)
196 {
197 gchar* target = g_strdup_printf("test-%i", i);
198 gchar* icon = g_strdup_printf("icon-%i", i);
199 gchar* future_icon = g_strdup(icon);
200 gchar* completion_text = g_strdup_printf("completion-%i", i);
201 gchar* accelerator = g_strdup_printf("<alt>+whatever");
202
203 GVariantBuilder tuple;
204 g_variant_builder_init(&tuple, G_VARIANT_TYPE_TUPLE);
205 g_variant_builder_add_value(&tuple, g_variant_new_string(target));
206 g_variant_builder_add_value(&tuple, g_variant_new_string(icon));
207 g_variant_builder_add_value(&tuple, g_variant_new_string(future_icon));
208 g_variant_builder_add_value(&tuple, g_variant_new_string(completion_text));
209 g_variant_builder_add_value(&tuple, g_variant_new_string(accelerator));
210 // build a fake key
211 GVariant* key;
212 {
213 GVariantBuilder keybuilder;
214 g_variant_builder_init(&keybuilder, G_VARIANT_TYPE_TUPLE);
215 g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string"));
216 g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string"));
217 g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string"));
218 g_variant_builder_add_value(&keybuilder, g_variant_new_int32(1986));
219
220 key = g_variant_new_variant(g_variant_builder_end(&keybuilder));
221 }
222 g_variant_ref_sink(key);
223 g_variant_builder_add_value(&tuple, key);
224 g_variant_builder_add_value(&builder, g_variant_builder_end(&tuple));
225 g_free(target);
226 g_free(icon);
227 g_free(future_icon);
228 g_free(completion_text);
229 }
230 g_variant_builder_add_value(&ret_builder, g_variant_builder_end(&builder));
231
232 GVariant* query_key;
233 {
234 GVariantBuilder keybuilder;
235 g_variant_builder_init(&keybuilder, G_VARIANT_TYPE_TUPLE);
236 g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string"));
237 g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string"));
238 g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string"));
239 g_variant_builder_add_value(&keybuilder, g_variant_new_int32(1986));
240
241 query_key = g_variant_new_variant(g_variant_builder_end(&keybuilder));
242 }
243 g_variant_ref_sink(query_key);
244 g_variant_builder_add_value(&ret_builder, query_key);
245
246 ret = g_variant_builder_end(&ret_builder);
247
248 g_dbus_method_invocation_return_value(invocation, ret);
249 g_free(query);
250 }
251 else if (g_strcmp0(method_name, "ExecuteQuery") == 0)
252 {
253 GVariant * key = NULL;
254 key = g_variant_get_child_value(parameters, 0);
255 g_dbus_method_invocation_return_value(invocation, NULL);
256 g_variant_unref(key);
257 }
258 else if (g_strcmp0(method_name, "CloseQuery") == 0)
259 {
260 GVariant * key = NULL;
261 key = g_variant_get_child_value(parameters, 0);
262 g_dbus_method_invocation_return_value(invocation, NULL);
263 g_variant_unref(key);
264 }
265
266 return;
267}
268
0269
=== added file 'tests/test_service_hud.h'
--- tests/test_service_hud.h 1970-01-01 00:00:00 +0000
+++ tests/test_service_hud.h 2012-02-06 11:00:29 +0000
@@ -0,0 +1,46 @@
1#ifndef _SERVICE_HUD_H_
2#define _SERVICE_HUD_H_
3
4#include <glib-object.h>
5G_BEGIN_DECLS
6
7#define SERVICE_TYPE_HUD (service_hud_get_type ())
8
9#define SERVICE_HUD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\
10 SERVICE_TYPE_HUD, ServiceHud))
11
12#define SERVICE_HUD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\
13 SERVICE_TYPE_HUD, ServiceHudClass))
14
15#define SERVICE_IS_HUD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
16 SERVICE_TYPE_HUD))
17
18#define SERVICE_IS_HUD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\
19 SERVICE_TYPE_HUD))
20
21#define ServiceHud_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\
22 SERVICE_TYPE_HUD, ServiceHudClass))
23
24typedef struct _ServiceHud ServiceHud;
25typedef struct _ServiceHudClass ServiceHudClass;
26typedef struct _ServiceHudPrivate ServiceHudPrivate;
27
28struct _ServiceHud
29{
30 GObject parent;
31
32 ServiceHudPrivate *priv;
33};
34
35struct _ServiceHudClass
36{
37 GObjectClass parent_class;
38};
39
40GType service_hud_get_type(void) G_GNUC_CONST;
41
42ServiceHud* service_hud_new(void);
43
44G_END_DECLS
45
46#endif /* _SERVICE_HUD_H_ */
047
=== modified file 'tests/test_service_main.c'
--- tests/test_service_main.c 2011-07-26 09:08:42 +0000
+++ tests/test_service_main.c 2012-02-06 11:00:29 +0000
@@ -2,6 +2,7 @@
22
3#include "test_service_lens.h"3#include "test_service_lens.h"
4#include "test_service_model.h"4#include "test_service_model.h"
5#include "test_service_hud.h"
56
6static void on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null);7static void on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null);
7static void handle_method_call(GDBusConnection *connection,8static void handle_method_call(GDBusConnection *connection,
@@ -34,6 +35,7 @@
34static GMainLoop* loop_ = NULL;35static GMainLoop* loop_ = NULL;
35static ServiceLens* lens_ = NULL;36static ServiceLens* lens_ = NULL;
36static ServiceModel* model_ = NULL;37static ServiceModel* model_ = NULL;
38static ServiceHud* hud_ = NULL;
3739
38gint40gint
39main(gint argc, gchar** argv)41main(gint argc, gchar** argv)
@@ -44,6 +46,7 @@
4446
45 lens_ = service_lens_new();47 lens_ = service_lens_new();
46 model_ = service_model_new();48 model_ = service_model_new();
49 hud_ = service_hud_new();
4750
48 g_bus_own_name(G_BUS_TYPE_SESSION,51 g_bus_own_name(G_BUS_TYPE_SESSION,
49 "com.canonical.Unity.Test",52 "com.canonical.Unity.Test",
@@ -57,8 +60,9 @@
57 g_main_loop_run(loop_);60 g_main_loop_run(loop_);
58 g_main_loop_unref(loop_);61 g_main_loop_unref(loop_);
5962
60 g_object_unref(lens_);63 //g_object_unref(lens_);
61 g_object_unref(model_);64 //g_object_unref(model_);
65 g_object_unref(hud_);
62 g_dbus_node_info_unref(introspection_data);66 g_dbus_node_info_unref(introspection_data);
6367
64 return 0;68 return 0;