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

Proposed by Gord Allott
Status: Superseded
Proposed branch: lp:~gordallott/unity/hud
Merge into: lp:unity
Diff against target: 4111 lines (+3217/-162)
36 files modified
CMakeLists.txt (+2/-2)
UnityCore/CMakeLists.txt (+2/-0)
UnityCore/GLibDBusProxy.cpp (+0/-1)
UnityCore/Hud.cpp (+239/-0)
UnityCore/Hud.h (+127/-0)
manual-tests/Hud.txt (+57/-0)
plugins/unityshell/src/DashController.cpp (+5/-3)
plugins/unityshell/src/DashStyle.cpp (+1/-0)
plugins/unityshell/src/HudButton.cpp (+182/-0)
plugins/unityshell/src/HudButton.h (+76/-0)
plugins/unityshell/src/HudController.cpp (+364/-0)
plugins/unityshell/src/HudController.h (+113/-0)
plugins/unityshell/src/HudIcon.cpp (+91/-0)
plugins/unityshell/src/HudIcon.h (+69/-0)
plugins/unityshell/src/HudSearchBar.cpp (+404/-0)
plugins/unityshell/src/HudSearchBar.h (+116/-0)
plugins/unityshell/src/HudView.cpp (+377/-0)
plugins/unityshell/src/HudView.h (+115/-0)
plugins/unityshell/src/IconTexture.cpp (+23/-10)
plugins/unityshell/src/Launcher.cpp (+44/-26)
plugins/unityshell/src/Launcher.h (+2/-2)
plugins/unityshell/src/PanelMenuView.cpp (+2/-2)
plugins/unityshell/src/PanelView.cpp (+2/-2)
plugins/unityshell/src/PlacesHomeView.cpp (+1/-1)
plugins/unityshell/src/UBusMessages.h (+7/-3)
plugins/unityshell/src/WindowButtons.cpp (+21/-13)
plugins/unityshell/src/unityshell.cpp (+77/-39)
plugins/unityshell/src/unityshell.h (+8/-1)
plugins/unityshell/unityshell.xml.in (+46/-41)
standalone-clients/CMakeLists.txt (+33/-0)
standalone-clients/StandaloneHud.cpp (+170/-0)
tests/CMakeLists.txt (+13/-10)
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 (+10/-6)
To merge this branch: bzr merge lp:~gordallott/unity/hud
Reviewer Review Type Date Requested Status
Michal Hruby (community) Needs Information
Review via email: mp+90082@code.launchpad.net

This proposal has been superseded by a proposal from 2012-01-25.

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

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

Why is this needed?

review: Needs Information

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2011-12-19 22:18:53 +0000
+++ CMakeLists.txt 2012-01-25 11:34:37 +0000
@@ -8,7 +8,7 @@
8#8#
9set (PROJECT_NAME "unity")9set (PROJECT_NAME "unity")
10set (UNITY_MAJOR 5)10set (UNITY_MAJOR 5)
11set (UNITY_MINOR 0)11set (UNITY_MINOR 1)
12set (UNITY_MICRO 0)12set (UNITY_MICRO 0)
13set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}")13set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}")
14set (UNITY_API_VERSION "5.0")14set (UNITY_API_VERSION "5.0")
@@ -110,7 +110,7 @@
110 SET (BOOT_LOGGER_FLAG "-DENABLE_LOGGER")110 SET (BOOT_LOGGER_FLAG "-DENABLE_LOGGER")
111endif (BOOT_LOGGER)111endif (BOOT_LOGGER)
112112
113SET (MAINTAINER_CFLAGS "-Werror -Wall -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self -Warray-bounds")113SET (MAINTAINER_CFLAGS "-Wall -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self -Warray-bounds")
114option (DISABLE_MAINTAINER_CFLAGS "Disable maintainer CFlags" OFF)114option (DISABLE_MAINTAINER_CFLAGS "Disable maintainer CFlags" OFF)
115if (DISABLE_MAINTAINER_CFLAGS)115if (DISABLE_MAINTAINER_CFLAGS)
116 SET (MAINTAINER_CFLAGS "")116 SET (MAINTAINER_CFLAGS "")
117117
=== modified file 'UnityCore/CMakeLists.txt'
--- UnityCore/CMakeLists.txt 2012-01-17 16:02:39 +0000
+++ UnityCore/CMakeLists.txt 2012-01-25 11:34:37 +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 IndicatorEntry.h25 IndicatorEntry.h
25 Indicator.h26 Indicator.h
26 Indicators.h27 Indicators.h
@@ -53,6 +54,7 @@
53 GLibDBusProxy.cpp54 GLibDBusProxy.cpp
54 GLibSignal.cpp55 GLibSignal.cpp
55 GLibWrapper.cpp56 GLibWrapper.cpp
57 Hud.cpp
56 Indicator.cpp58 Indicator.cpp
57 IndicatorEntry.cpp59 IndicatorEntry.cpp
58 Indicators.cpp60 Indicators.cpp
5961
=== modified file 'UnityCore/GLibDBusProxy.cpp'
--- UnityCore/GLibDBusProxy.cpp 2012-01-16 15:19:47 +0000
+++ UnityCore/GLibDBusProxy.cpp 2012-01-25 11:34:37 +0000
@@ -144,7 +144,6 @@
144 LOG_DEBUG(logger) << self->name_ << " appeared";144 LOG_DEBUG(logger) << self->name_ << " appeared";
145145
146 self->connected_ = true;146 self->connected_ = true;
147 self->owner_->connected.emit();
148}147}
149148
150void DBusProxy::Impl::OnNameVanished(GDBusConnection* connection,149void DBusProxy::Impl::OnNameVanished(GDBusConnection* connection,
151150
=== added file 'UnityCore/Hud.cpp'
--- UnityCore/Hud.cpp 1970-01-01 00:00:00 +0000
+++ UnityCore/Hud.cpp 2012-01-25 11:34:37 +0000
@@ -0,0 +1,239 @@
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 queries_.clear();
91
92 GVariant* query_key = g_variant_get_child_value(query, 2);
93 query_key_ = query_key;
94
95 GVariant* queries = g_variant_get_child_value(query, 1);
96 BuildQueries(queries);
97 g_variant_unref(queries);
98
99 if (queries_.empty() == false)
100 {
101 // we now execute based off the first result
102 ExecuteByKey(queries_.front()->key, timestamp);
103 CloseQuery();
104 }
105}
106
107void HudImpl::QueryCallback(GVariant* query)
108{
109 queries_.clear();
110
111 // extract the information from the GVariants
112 GVariant* target = g_variant_get_child_value(query, 0);
113 g_variant_unref(target);
114
115 GVariant* query_key = g_variant_get_child_value(query, 2);
116 query_key_ = query_key;
117
118 GVariant* queries = g_variant_get_child_value(query, 1);
119 BuildQueries(queries);
120 g_variant_unref(queries);
121
122 parent_->queries_updated.emit(queries_);
123}
124
125void HudImpl::UpdateQueryCallback(GVariant* query)
126{
127 // as we are expecting an update, we want to check
128 // and make sure that we are the actual recievers of
129 // the signal
130
131 GVariant* query_key = g_variant_get_child_value(query, 2);
132 if (g_variant_equal(query_key_, query_key))
133 {
134 GVariant* queries = g_variant_get_child_value(query, 1);
135 BuildQueries(queries);
136 g_variant_unref(queries);
137 }
138}
139
140void HudImpl::BuildQueries(GVariant* query_array)
141{
142 GVariantIter iter;
143 g_variant_iter_init(&iter, query_array);
144 glib::String formatted_text;
145 glib::String icon;
146 glib::String item_icon;
147 glib::String completion_text;
148 glib::String shortcut;
149 GVariant* key = NULL;
150
151 while (g_variant_iter_loop(&iter, "(sssssv)",
152 &formatted_text, &icon, &item_icon, &completion_text, &shortcut, &key))
153 {
154 queries_.push_back(Query::Ptr(new Query(std::string(formatted_text),
155 std::string(icon),
156 std::string(item_icon),
157 std::string(completion_text),
158 std::string(shortcut),
159 key)));
160 }
161}
162
163void HudImpl::CloseQuery()
164{
165 if (query_key_ == NULL)
166 {
167 LOG_WARN(logger) << "Attempted to close the hud connection without starting it";
168 }
169 else
170 {
171 GVariant* paramaters = g_variant_new("(v)", query_key_);
172 proxy_.Call("CloseQuery", paramaters);
173 g_variant_unref(query_key_);
174 query_key_ = NULL;
175 queries_.clear();
176 }
177}
178
179
180Hud::Hud(std::string const& dbus_name,
181 std::string const& dbus_path)
182 : connected(false)
183 , pimpl_(new HudImpl(dbus_name, dbus_path, this))
184{
185 pimpl_->parent_ = this;
186}
187
188Hud::~Hud()
189{
190 delete pimpl_;
191}
192
193void Hud::RequestQuery(std::string const& search_string)
194{
195 LOG_DEBUG(logger) << "Getting Query: " << search_string;
196 if (pimpl_->query_key_ != NULL)
197 {
198 CloseQuery();
199 }
200
201 GVariant* paramaters = g_variant_new("(si)",
202 search_string.c_str(),
203 request_number_of_results);
204 pimpl_->proxy_.Call("StartQuery", paramaters, sigc::mem_fun(this->pimpl_, &HudImpl::QueryCallback));
205}
206
207
208void Hud::ExecuteQuery(Query::Ptr query, unsigned int timestamp)
209{
210 LOG_DEBUG(logger) << "Executing query: " << query->formatted_text;
211 pimpl_->ExecuteByKey(query->key, timestamp);
212}
213
214void Hud::ExecuteQueryBySearch(std::string execute_string, unsigned int timestamp)
215{
216 //Does a search then executes the result based on that search
217 LOG_DEBUG(logger) << "Executing by string" << execute_string;
218 if (pimpl_->query_key_ != NULL)
219 {
220 CloseQuery();
221 }
222
223 GVariant* paramaters = g_variant_new("(si)",
224 execute_string.c_str(),
225 1);
226
227 auto functor = sigc::mem_fun(this->pimpl_, &HudImpl::ExecuteQueryByStringCallback);
228
229 pimpl_->proxy_.Call("StartQuery", paramaters, sigc::bind(functor, timestamp));
230}
231
232void Hud::CloseQuery()
233{
234 //Send close hint to the hud
235 pimpl_->CloseQuery();
236}
237
238}
239}
0240
=== added file 'UnityCore/Hud.h'
--- UnityCore/Hud.h 1970-01-01 00:00:00 +0000
+++ UnityCore/Hud.h 2012-01-25 11:34:37 +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-01-25 11:34:37 +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 2011-12-08 01:23:11 +0000
+++ plugins/unityshell/src/DashController.cpp 2012-01-25 11:34:37 +0000
@@ -242,7 +242,8 @@
242242
243 StartShowHideTimeline();243 StartShowHideTimeline();
244244
245 ubus_manager_.SendMessage(UBUS_PLACE_VIEW_SHOWN);245 GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE);
246 ubus_manager_.SendMessage(UBUS_OVERLAY_SHOWN, info);
246}247}
247248
248void Controller::HideDash(bool restore)249void Controller::HideDash(bool restore)
@@ -262,8 +263,9 @@
262 PluginAdapter::Default ()->restoreInputFocus ();263 PluginAdapter::Default ()->restoreInputFocus ();
263264
264 StartShowHideTimeline();265 StartShowHideTimeline();
265266
266 ubus_manager_.SendMessage(UBUS_PLACE_VIEW_HIDDEN);267 GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE);
268 ubus_manager_.SendMessage(UBUS_OVERLAY_HIDDEN, info);
267}269}
268270
269void Controller::StartShowHideTimeline()271void Controller::StartShowHideTimeline()
270272
=== 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-01-25 11:34:37 +0000
@@ -1428,6 +1428,7 @@
1428 pango_layout_get_extents(layout, &ink, &log);1428 pango_layout_get_extents(layout, &ink, &log);
1429 x = horizMargin; // let pango alignment handle the x position1429 x = horizMargin; // let pango alignment handle the x position
1430 y = ((double) h - pango_units_to_double(log.height)) / 2.0;1430 y = ((double) h - pango_units_to_double(log.height)) / 2.0;
1431
1431 cairo_move_to(cr, x, y);1432 cairo_move_to(cr, x, y);
1432 pango_cairo_show_layout(cr, layout);1433 pango_cairo_show_layout(cr, layout);
14331434
14341435
=== 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-01-25 11:34:37 +0000
@@ -0,0 +1,182 @@
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_focused_(false)
51{
52 InitTheme();
53 OnKeyNavFocusChange.connect([this](nux::Area *area){ QueueDraw(); });
54}
55
56HudButton::HudButton (const std::string label_, NUX_FILE_LINE_DECL)
57 : nux::Button (NUX_FILE_LINE_PARAM)
58 , is_focused_(false)
59{
60 InitTheme();
61}
62
63HudButton::HudButton (const std::string label_, nux::TextureArea *image, NUX_FILE_LINE_DECL)
64 : nux::Button (image, NUX_FILE_LINE_PARAM)
65 , is_focused_(false)
66{
67 InitTheme();
68}
69
70HudButton::HudButton (NUX_FILE_LINE_DECL)
71 : nux::Button (NUX_FILE_LINE_PARAM)
72 , is_focused_(false)
73{
74 InitTheme();
75}
76
77HudButton::~HudButton() {
78}
79
80void HudButton::InitTheme()
81{
82 SetMinimumHeight(42);
83 if (!active_)
84 {
85 nux::Geometry const& geo = GetGeometry();
86
87 prelight_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
88 active_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED)));
89 normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL)));
90 }
91}
92
93void HudButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
94{
95 dash::Style::Instance().Button(cr, faked_state, label_, dash::Alignment::LEFT);
96}
97
98bool HudButton::AcceptKeyNavFocus()
99{
100 return true;
101}
102
103
104long HudButton::ComputeContentSize ()
105{
106 long ret = nux::Button::ComputeContentSize();
107 nux::Geometry const& geo = GetGeometry();
108
109 if (cached_geometry_ != geo)
110 {
111 prelight_->Invalidate(geo);
112 active_->Invalidate(geo);
113 normal_->Invalidate(geo);
114
115 cached_geometry_ = geo;
116 }
117
118 return ret;
119}
120
121void HudButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
122{
123 nux::Geometry const& geo = GetGeometry();
124
125 gPainter.PaintBackground(GfxContext, geo);
126 // set up our texture mode
127 nux::TexCoordXForm texxform;
128 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
129 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
130
131 // clear what is behind us
132 unsigned int alpha = 0, src = 0, dest = 0;
133 GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
134 GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
135
136 nux::Color col = nux::color::Black;
137 col.alpha = 0;
138 GfxContext.QRP_Color(geo.x,
139 geo.y,
140 geo.width,
141 geo.height,
142 col);
143
144 nux::BaseTexture* texture = normal_->GetTexture();
145 if (HasKeyFocus())
146 texture = active_->GetTexture();
147 else if (HasKeyFocus())
148 texture = prelight_->GetTexture();
149 else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED)
150 texture = active_->GetTexture();
151
152 GfxContext.QRP_1Tex(geo.x,
153 geo.y,
154 geo.width,
155 geo.height,
156 texture->GetDeviceTexture(),
157 texxform,
158 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
159
160 GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
161}
162
163void HudButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {
164}
165
166void HudButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {
167 nux::Button::PostDraw(GfxContext, force_draw);
168}
169
170void HudButton::SetQuery(Query::Ptr query)
171{
172 query_ = query;
173 label_ = query->formatted_text;
174 label = query->formatted_text;
175}
176
177Query::Ptr HudButton::GetQuery()
178{
179 return query_;
180}
181}
182}
0183
=== 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-01-25 11:34:37 +0000
@@ -0,0 +1,76 @@
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
33namespace unity {
34
35namespace hud {
36class HudButton : public nux::Button {
37 typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr;
38 typedef nux::ObjectPtr<HudButton> Ptr;
39public:
40 HudButton (nux::TextureArea *image, NUX_FILE_LINE_PROTO);
41 HudButton (const std::string label, NUX_FILE_LINE_PROTO);
42 HudButton (const std::string label, nux::TextureArea *image, NUX_FILE_LINE_PROTO);
43 HudButton (NUX_FILE_LINE_PROTO);
44 virtual ~HudButton();
45
46 void SetQuery(Query::Ptr query);
47 std::shared_ptr<Query> GetQuery();
48
49 nux::Property<std::string> label;
50 nux::Property<std::string> hint;
51
52protected:
53 virtual bool AcceptKeyNavFocus();
54 virtual long ComputeContentSize();
55 virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
56 virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
57 virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw);
58
59 void InitTheme ();
60 void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state);
61 typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr;
62
63 NuxCairoPtr prelight_;
64 NuxCairoPtr active_;
65 NuxCairoPtr normal_;
66
67private:
68 std::string label_;
69
70 Query::Ptr query_;
71 nux::Geometry cached_geometry_;
72 bool is_focused_;
73};
74}
75}
76#endif // FILTERBASICBUTTON_H
077
=== 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-01-25 11:34:37 +0000
@@ -0,0 +1,364 @@
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 PluginAdapter::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &Controller::OnScreenUngrabbed));
56
57 hud_service_.queries_updated.connect(sigc::mem_fun(this, &Controller::OnQueriesFinished));
58 EnsureHud();
59}
60
61Controller::~Controller()
62{
63 if (window_)
64 window_->UnReference();
65 window_ = 0;
66
67 g_source_remove(timeline_id_);
68 g_source_remove(ensure_id_);
69}
70
71void Controller::SetupWindow()
72{
73 window_ = new nux::BaseWindow("Hud");
74 window_->SinkReference();
75 window_->SetBackgroundColor(nux::Color(0.0f, 0.0f, 0.0f, 0.0f));
76 window_->SetConfigureNotifyCallback(&Controller::OnWindowConfigure, this);
77 window_->ShowWindow(false);
78 window_->SetOpacity(0.0f);
79 window_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow));
80}
81
82void Controller::SetupHudView()
83{
84 LOG_DEBUG(logger) << "SetupHudView called";
85 view_ = new View();
86
87 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
88 layout_->AddView(view_, 1);
89 window_->SetLayout(layout_);
90
91 view_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow));
92
93 LOG_DEBUG(logger) << "connecting to signals";
94 view_->search_changed.connect(sigc::mem_fun(this, &Controller::OnSearchChanged));
95 view_->search_activated.connect(sigc::mem_fun(this, &Controller::OnSearchActivated));
96 view_->query_activated.connect(sigc::mem_fun(this, &Controller::OnQueryActivated));
97 view_->query_selected.connect(sigc::mem_fun(this, &Controller::OnQuerySelected));
98}
99
100void Controller::SetupRelayoutCallbacks()
101{
102 GdkScreen* screen = gdk_screen_get_default();
103
104 sig_manager_.Add(new glib::Signal<void, GdkScreen*>(screen,
105 "monitors-changed", sigc::mem_fun(this, &Controller::Relayout)));
106 sig_manager_.Add(new glib::Signal<void, GdkScreen*>(screen,
107 "size-changed", sigc::mem_fun(this, &Controller::Relayout)));
108}
109
110void Controller::EnsureHud()
111{
112 if (window_)
113 return;
114
115 LOG_DEBUG(logger) << "Initializing Hud";
116
117 SetupWindow();
118 SetupHudView();
119 Relayout();
120 ensure_id_ = 0;
121}
122
123nux::BaseWindow* Controller::window() const
124{
125 return window_;
126}
127
128// We update the @geo that's sent in with our desired width and height
129void Controller::OnWindowConfigure(int window_width, int window_height,
130 nux::Geometry& geo, void* data)
131{
132 Controller* self = static_cast<Controller*>(data);
133 geo = self->GetIdealWindowGeometry();
134}
135
136nux::Geometry Controller::GetIdealWindowGeometry()
137{
138 UScreen *uscreen = UScreen::GetDefault();
139 int primary_monitor = uscreen->GetPrimaryMonitor();
140 auto monitor_geo = uscreen->GetMonitorGeometry(primary_monitor);
141
142 // We want to cover as much of the screen as possible to grab any mouse events outside
143 // of our window
144 return nux::Geometry (monitor_geo.x,
145 monitor_geo.y + panel_height,
146 monitor_geo.width,
147 monitor_geo.height - panel_height);
148}
149
150void Controller::Relayout(GdkScreen*screen)
151{
152 EnsureHud();
153 nux::Geometry content_geo = view_->GetGeometry();
154 nux::Geometry geo = GetIdealWindowGeometry();
155
156 window_->SetGeometry(geo);
157 layout_->SetMinMaxSize(content_geo.width, content_geo.height);
158 view_->SetWindowGeometry(window_->GetAbsoluteGeometry(), window_->GetGeometry());
159 view_->Relayout();
160}
161
162void Controller::OnMouseDownOutsideWindow(int x, int y,
163 unsigned long bflags, unsigned long kflags)
164{
165 LOG_DEBUG(logger) << "OnMouseDownOutsideWindow called";
166 HideHud();
167}
168
169void Controller::OnScreenUngrabbed()
170{
171 LOG_DEBUG(logger) << "OnScreenUngrabbed called";
172 if (need_show_)
173 {
174 EnsureHud();
175 ShowHud();
176 }
177}
178
179void Controller::OnExternalShowHud(GVariant* variant)
180{
181 EnsureHud();
182 visible_ ? HideHud() : ShowHud();
183}
184
185void Controller::OnExternalHideHud(GVariant* variant)
186{
187 LOG_DEBUG(logger) << "External Hiding the hud";
188 EnsureHud();
189 HideHud();
190}
191
192void Controller::ShowHideHud()
193{
194 EnsureHud();
195 visible_ ? HideHud() : ShowHud();
196}
197
198void Controller::ShowHud()
199{
200 LOG_DEBUG(logger) << "Showing the hud";
201 EnsureHud();
202 view_->AboutToShow();
203
204 window_->ShowWindow(true);
205 window_->PushToFront();
206 window_->EnableInputWindow(true, "Hud", true, false);
207 window_->SetInputFocus();
208 nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus());
209 window_->CaptureMouseDownAnyWhereElse(true);
210 view_->CaptureMouseDownAnyWhereElse(true);
211 window_->QueueDraw();
212
213 view_->ResetToDefault();
214 hud_service_.RequestQuery("");
215
216 need_show_ = false;
217 visible_ = true;
218
219 StartShowHideTimeline();
220 view_->SetWindowGeometry(window_->GetAbsoluteGeometry(), window_->GetGeometry());
221
222 // hide the launcher
223 GVariant* message_data = g_variant_new("(b)", TRUE);
224 ubus.SendMessage(UBUS_LAUNCHER_LOCK_HIDE, message_data);
225
226 GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "hud", FALSE);
227 ubus.SendMessage(UBUS_OVERLAY_SHOWN, info);
228}
229void Controller::HideHud(bool restore)
230{
231 LOG_DEBUG (logger) << "hiding the hud";
232 if (visible_ == false)
233 return;
234
235 EnsureHud();
236 view_->AboutToHide();
237 window_->CaptureMouseDownAnyWhereElse(false);
238 window_->EnableInputWindow(false, "Hud", true, false);
239 visible_ = false;
240
241 StartShowHideTimeline();
242
243 restore = true;
244 if (restore)
245 PluginAdapter::Default ()->restoreInputFocus ();
246
247 hud_service_.CloseQuery();
248
249 //unhide the launcher
250 GVariant* message_data = g_variant_new("(b)", FALSE);
251 ubus.SendMessage(UBUS_LAUNCHER_LOCK_HIDE, message_data);
252
253 GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "hud", FALSE);
254 ubus.SendMessage(UBUS_OVERLAY_HIDDEN, info);
255}
256
257void Controller::StartShowHideTimeline()
258{
259 EnsureHud();
260
261 if (timeline_id_)
262 g_source_remove(timeline_id_);
263
264 timeline_id_ = g_timeout_add(15, (GSourceFunc)Controller::OnViewShowHideFrame, this);
265 last_opacity_ = window_->GetOpacity();
266 start_time_ = g_get_monotonic_time();
267
268}
269
270gboolean Controller::OnViewShowHideFrame(Controller* self)
271{
272#define _LENGTH_ 90000
273 float diff = g_get_monotonic_time() - self->start_time_;
274 float progress = diff / (float)_LENGTH_;
275 float last_opacity = self->last_opacity_;
276
277 if (self->visible_)
278 {
279 self->window_->SetOpacity(last_opacity + ((1.0f - last_opacity) * progress));
280 }
281 else
282 {
283 self->window_->SetOpacity(last_opacity - (last_opacity * progress));
284 }
285
286 if (diff > _LENGTH_)
287 {
288 self->timeline_id_ = 0;
289
290 // Make sure the state is right
291 self->window_->SetOpacity(self->visible_ ? 1.0f : 0.0f);
292 if (!self->visible_)
293 {
294 self->window_->ShowWindow(false);
295 }
296
297 return FALSE;
298 }
299
300 return TRUE;
301}
302
303void Controller::OnActivateRequest(GVariant* variant)
304{
305 EnsureHud();
306 ShowHud();
307}
308
309void Controller::OnSearchChanged(std::string search_string)
310{
311 LOG_DEBUG(logger) << "Search Changed";
312 hud_service_.RequestQuery(search_string);
313}
314
315void Controller::OnSearchActivated(std::string search_string)
316{
317 unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp;
318 hud_service_.ExecuteQueryBySearch(search_string, timestamp);
319 HideHud();
320}
321
322void Controller::OnQueryActivated(Query::Ptr query)
323{
324 LOG_DEBUG(logger) << "Activating query, " << query->formatted_text;
325 unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp;
326 hud_service_.ExecuteQuery(query, timestamp);
327 HideHud();
328}
329
330void Controller::OnQuerySelected(Query::Ptr query)
331{
332 LOG_DEBUG(logger) << "Selected query, " << query->formatted_text;
333 view_->SetIcon(query->icon_name);
334}
335
336
337void Controller::OnQueriesFinished(Hud::Queries queries)
338{
339 view_->SetQueries(queries);
340 std::string icon_name = "";
341 for (auto query = queries.begin(); query != queries.end(); query++)
342 {
343 if (!(*query)->icon_name.empty())
344 {
345 icon_name = (*query)->icon_name;
346 break;
347 }
348 }
349
350 view_->SetIcon(icon_name);
351}
352
353// Introspectable
354const gchar* Controller::GetName()
355{
356 return "unity.hud.Controller";
357}
358
359void Controller::AddProperties(GVariantBuilder* builder)
360{}
361
362
363}
364}
0365
=== 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-01-25 11:34:37 +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
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
58protected:
59 const gchar* GetName();
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-01-25 11:34:37 +0000
@@ -0,0 +1,91 @@
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
22//FIXME - we should be using the LauncherRenderer method of rendering icons here instead of compositing ourself
23// to make sure we get the correct average background colour and running indicator
24
25namespace unity
26{
27namespace hud
28{
29
30Icon::Icon(nux::BaseTexture* texture, guint width, guint height)
31 : unity::IconTexture(texture, width, height)
32{
33 Init();
34}
35
36Icon::Icon(const char* icon_name, unsigned int size, bool defer_icon_loading)
37 : unity::IconTexture(icon_name, size, defer_icon_loading)
38{
39 Init();
40}
41
42Icon::~Icon()
43{
44}
45
46void Icon::Init()
47{
48 SetMinimumWidth(54);
49 SetMinimumHeight(54);
50 background_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_back_54.png", -1, true);
51 gloss_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_shine_54.png", -1, true);
52 edge_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_edge_54.png", -1, true);
53}
54
55void Icon::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
56{
57 nux::Geometry geo = GetGeometry();
58 // set up our texture mode
59 nux::TexCoordXForm texxform;
60
61 GfxContext.QRP_1Tex(geo.x,
62 geo.y,
63 background_->GetWidth(),
64 background_->GetHeight(),
65 background_->GetDeviceTexture(),
66 texxform,
67 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
68
69 GfxContext.QRP_1Tex(geo.x,
70 geo.y,
71 gloss_->GetWidth(),
72 gloss_->GetHeight(),
73 gloss_->GetDeviceTexture(),
74 texxform,
75 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
76
77 GfxContext.QRP_1Tex(geo.x,
78 geo.y,
79 edge_->GetWidth(),
80 edge_->GetHeight(),
81 edge_->GetDeviceTexture(),
82 texxform,
83 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
84
85 unity::IconTexture::Draw(GfxContext, force_draw);
86}
87
88
89}
90}
91
092
=== 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-01-25 11:34:37 +0000
@@ -0,0 +1,69 @@
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 "Introspectable.h"
42
43namespace unity
44{
45namespace hud
46{
47
48class Icon : public unity::IconTexture
49{
50public:
51 typedef nux::ObjectPtr<IconTexture> Ptr;
52 Icon(nux::BaseTexture* texture, guint width, guint height);
53 Icon(const char* icon_name, unsigned int size, bool defer_icon_loading = false);
54 ~Icon();
55
56protected:
57 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
58 void Init();
59
60 nux::ObjectPtr<nux::BaseTexture> background_;
61 nux::ObjectPtr<nux::BaseTexture> gloss_;
62 nux::ObjectPtr<nux::BaseTexture> edge_;
63};
64
65}
66
67}
68
69#endif /* HUDICON_H */
070
=== added file 'plugins/unityshell/src/HudSearchBar.cpp'
--- plugins/unityshell/src/HudSearchBar.cpp 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudSearchBar.cpp 2012-01-25 11:34:37 +0000
@@ -0,0 +1,404 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2010-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 detais.
13 *
14 * You shoud 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: Neil Jagdish Patel <neil.patel@canonical.com>
18 */
19
20/* FIXME!! - port this to the DashSearchBar and rename both to SearchBar */
21
22#include "config.h"
23
24#include <Nux/Nux.h>
25#include <Nux/BaseWindow.h>
26#include <Nux/HLayout.h>
27#include <Nux/Layout.h>
28#include <Nux/WindowCompositor.h>
29
30#include <NuxImage/CairoGraphics.h>
31#include <NuxImage/ImageSurface.h>
32#include <Nux/StaticText.h>
33
34#include <NuxGraphics/GLThread.h>
35#include <NuxGraphics/RenderingPipe.h>
36
37#include <glib.h>
38#include <glib/gi18n-lib.h>
39
40#include "HudSearchBar.h"
41#include <UnityCore/Variant.h>
42
43#include "DashStyle.h"
44
45#define LIVE_SEARCH_TIMEOUT 250
46// Create a texture from the CairoGraphics object.
47//
48// Returns a new BaseTexture that has a ref count of 1.
49static nux::BaseTexture* texture_from_cairo_graphics(nux::CairoGraphics& cg)
50{
51 nux::NBitmapData* bitmap = cg.GetBitmap();
52 nux::BaseTexture* tex = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
53 tex->Update(bitmap);
54 delete bitmap;
55 return tex;
56}
57
58namespace unity
59{
60namespace hud
61{
62
63NUX_IMPLEMENT_OBJECT_TYPE(SearchBar);
64
65SearchBar::SearchBar(NUX_FILE_LINE_DECL)
66 : View(NUX_FILE_LINE_PARAM)
67 , search_hint("")
68 , showing_filters(false)
69 , can_refine_search(false)
70 , live_search_timeout_(0)
71{
72nux::BaseTexture* icon = dash::Style::Instance().GetSearchMagnifyIcon();
73
74 bg_layer_ = new nux::ColorLayer(nux::Color(0xff595853), true);
75
76 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
77 layout_->SetHorizontalInternalMargin(0);
78 layout_->SetVerticalExternalMargin(8);
79 layout_->SetHorizontalExternalMargin(10);
80 SetLayout(layout_);
81
82 spinner_ = new dash::SearchBarSpinner();
83 spinner_->SetMinMaxSize(icon->GetWidth(), icon->GetHeight());
84 spinner_->mouse_click.connect(sigc::mem_fun(this, &SearchBar::OnClearClicked));
85 layout_->AddView(spinner_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
86
87 hint_ = new nux::StaticCairoText(" ");
88 hint_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 0.5f));
89 hint_->SetMaximumWidth(570);
90
91 pango_entry_ = new dash::IMTextEntry();
92 pango_entry_->sigTextChanged.connect(sigc::mem_fun(this, &SearchBar::OnSearchChanged));
93 pango_entry_->activated.connect([&]() { activated.emit(); });
94 pango_entry_->cursor_moved.connect([&](int i) { QueueDraw(); });
95 pango_entry_->mouse_down.connect(sigc::mem_fun(this, &SearchBar::OnMouseButtonDown));
96 pango_entry_->end_key_focus.connect(sigc::mem_fun(this, &SearchBar::OnEndKeyFocus));
97 pango_entry_->SetMaximumWidth(570);
98
99 layered_layout_ = new nux::LayeredLayout();
100 layered_layout_->AddLayer(hint_);
101 layered_layout_->AddLayer(pango_entry_);
102 layered_layout_->SetPaintAll(true);
103 layered_layout_->SetActiveLayerN(1);
104 layered_layout_->SetMinimumWidth(420);
105 layered_layout_->SetMaximumWidth(645);
106 layout_->AddView(layered_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);
107
108 std::string filter_str = _("Filter results");
109 filter_str+= " ▸";
110 show_filters_ = new nux::StaticCairoText(filter_str.c_str());
111 show_filters_->SetVisible(false);
112 show_filters_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
113 show_filters_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT);
114 show_filters_->mouse_click.connect([&] (int x, int y, unsigned long b, unsigned long k) { showing_filters = !showing_filters; });
115
116 nux::Layout *filter_layout = new nux::HLayout();
117 filter_layout->SetHorizontalExternalMargin(12);
118 filter_layout->AddLayout(new nux::SpaceLayout(0, 10000, 0, 1), 1);
119 filter_layout->AddView(show_filters_, 0, nux::MINOR_POSITION_RIGHT);
120
121 layout_->AddView(filter_layout, 1, nux::MINOR_POSITION_RIGHT, nux::MINOR_SIZE_FIX);
122
123 sig_manager_.Add(new Signal<void, GtkSettings*, GParamSpec*>
124 (gtk_settings_get_default(),
125 "notify::gtk-font-name",
126 sigc::mem_fun(this, &SearchBar::OnFontChanged)));
127 OnFontChanged(gtk_settings_get_default());
128
129 search_hint.changed.connect([&](std::string const& s) { OnSearchHintChanged(); });
130 search_string.SetGetterFunction(sigc::mem_fun(this, &SearchBar::get_search_string));
131 search_string.SetSetterFunction(sigc::mem_fun(this, &SearchBar::set_search_string));
132 im_active.SetGetterFunction(sigc::mem_fun(this, &SearchBar::get_im_active));
133 showing_filters.changed.connect(sigc::mem_fun(this, &SearchBar::OnShowingFiltersChanged));
134 can_refine_search.changed.connect([&] (bool can_refine) { show_filters_->SetVisible(can_refine); });
135}
136
137SearchBar::~SearchBar()
138{
139 delete bg_layer_;
140
141 if (live_search_timeout_)
142 g_source_remove(live_search_timeout_);
143}
144
145void SearchBar::OnFontChanged(GtkSettings* settings, GParamSpec* pspec)
146{
147 static const int HOW_LARGE = 8;
148 gchar* font_name = NULL;
149 PangoFontDescription* desc;
150 gint size;
151 gchar* font_desc;
152
153 g_object_get(settings, "gtk-font-name", &font_name, NULL);
154
155 desc = pango_font_description_from_string(font_name);
156 pango_entry_->SetFontFamily(pango_font_description_get_family(desc));
157
158 size = pango_font_description_get_size(desc);
159 size /= pango_font_description_get_size_is_absolute(desc) ? 1 : PANGO_SCALE;
160 pango_entry_->SetFontSize(size + HOW_LARGE);
161
162 pango_entry_->SetFontOptions(gdk_screen_get_font_options(gdk_screen_get_default()));
163
164 font_desc = g_strdup_printf("%s %d", pango_font_description_get_family(desc), size + HOW_LARGE);
165 hint_->SetFont(font_desc);
166
167 g_free(font_desc);
168 font_desc = g_strdup_printf("%s %d", pango_font_description_get_family(desc), size + HOW_LARGE/2);
169 show_filters_->SetFont(font_desc);
170
171 pango_font_description_free(desc);
172 g_free(font_name);
173 g_free(font_desc);
174}
175
176void SearchBar::OnSearchHintChanged()
177{
178 std::string hint = search_hint;
179 gchar* tmp = g_markup_escape_text(hint.c_str(), -1);
180
181 gchar* markup = g_strdup_printf("%s", tmp);
182 hint_->SetText(markup);
183
184 g_free(markup);
185 g_free(tmp);
186}
187
188void SearchBar::OnSearchChanged(nux::TextEntry* text_entry)
189{
190 // We don't want to set a new search string on every new character, so we add a sma
191 // timeout to see if the user is typing a sentence. If more characters are added, we
192 // keep restarting the timeout unti the user has actuay paused.
193 if (live_search_timeout_)
194 g_source_remove(live_search_timeout_);
195
196 live_search_timeout_ = g_timeout_add(LIVE_SEARCH_TIMEOUT,
197 (GSourceFunc)&OnLiveSearchTimeout,
198 this);
199
200 //spinner_->SetState(is_empty ? unity::dash::STATE_READY : unity::dash::STATE_SEARCHING);
201
202 pango_entry_->QueueDraw();
203 hint_->QueueDraw();
204 QueueDraw();
205
206 search_changed.emit(pango_entry_->GetText());
207}
208
209gboolean SearchBar::OnLiveSearchTimeout(SearchBar* sef)
210{
211 sef->live_search_reached.emit(sef->pango_entry_->GetText());
212 sef->live_search_timeout_ = 0;
213 return FALSE;
214}
215
216void SearchBar::OnShowingFiltersChanged(bool is_showing)
217{
218 std::string filter_str = _("Filter results");
219 filter_str += " <small>";
220 filter_str += is_showing ? "▾" : "▸";
221 filter_str += "</small>";
222 show_filters_->SetText(filter_str.c_str());
223}
224
225void SearchBar::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
226{
227 nux::Geometry geo = GetGeometry();
228
229 UpdateBackground();
230 GfxContext.PushClippingRectangle(geo);
231
232 nux::GetPainter().PaintBackground(GfxContext, geo);
233
234 bg_layer_->SetGeometry(nux::Geometry(geo.x, geo.y, last_width_, geo.height));
235 nux::GetPainter().RenderSinglePaintLayer(GfxContext,
236 bg_layer_->GetGeometry(),
237 bg_layer_);
238
239 GfxContext.PopClippingRectangle();
240}
241
242void SearchBar::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
243{
244 nux::Geometry geo = GetGeometry();
245
246 GfxContext.PushClippingRectangle(geo);
247
248 if (!IsFullRedraw())
249 gPainter.PushLayer(GfxContext, bg_layer_->GetGeometry(), bg_layer_);
250
251 layout_->ProcessDraw(GfxContext, force_draw);
252
253 if (!IsFullRedraw())
254 gPainter.PopBackground();
255 GfxContext.PopClippingRectangle();
256}
257
258void SearchBar::OnClearClicked(int x, int y, unsigned long button_fags,
259 unsigned long key_fags)
260{
261 pango_entry_->SetText("");
262 spinner_->SetState(unity::dash::STATE_READY);
263 live_search_reached.emit("");
264}
265
266void SearchBar::OnEntryActivated()
267{
268 activated.emit();
269}
270
271void
272SearchBar::SearchFinished()
273{
274 spinner_->SetState(unity::dash::STATE_CLEAR);
275}
276
277void SearchBar::UpdateBackground()
278{
279#define PADDING 12
280#define RADIUS 5
281 int x, y, width, height;
282 nux::Geometry geo = GetGeometry();
283 geo.width = layered_layout_->GetGeometry().width;
284
285 if (geo.width == last_width_ && geo.height == last_height_)
286 return;
287
288 last_width_ = geo.width;
289 last_height_ = geo.height;
290
291 x = y = PADDING;
292 width = last_width_ - (2 * PADDING);
293 height = last_height_ - (2 * PADDING);
294
295 nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, last_width_, last_height_);
296 cairo_t* cr = cairo_graphics.GetContext();
297
298 cairo_graphics.DrawRoundedRectangle(cr,
299 1.0f,
300 x,
301 y,
302 RADIUS,
303 width,
304 height,
305 true);
306
307 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
308 cairo_set_line_width(cr, 1.0);
309 cairo_stroke_preserve(cr);
310 cairo_graphics.BlurSurface (3, cairo_get_target (cr));
311
312 cairo_operator_t op = CAIRO_OPERATOR_OVER;
313 op = cairo_get_operator (cr);
314 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
315 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.5f);
316 cairo_fill_preserve(cr);
317 cairo_set_operator (cr, op);
318 cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.5f);
319 cairo_fill_preserve(cr);
320 cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 0.8f);
321 //cairo_set_line_width(cr, 1.0);
322 cairo_stroke(cr);
323
324 cairo_destroy(cr);
325 nux::BaseTexture* texture2D = texture_from_cairo_graphics(cairo_graphics);
326
327 nux::TexCoordXForm texxform;
328 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
329 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
330 if (bg_layer_)
331 delete bg_layer_;
332
333 nux::ROPConfig rop;
334 rop.Blend = true;
335 rop.SrcBlend = GL_ONE;
336 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
337
338 bg_layer_ = new nux::TextureLayer(texture2D->GetDeviceTexture(),
339 texxform,
340 nux::color::White,
341 true,
342 rop);
343
344 texture2D->UnReference();
345}
346
347void SearchBar::OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key)
348{
349 search_hint = "";
350}
351
352void SearchBar::OnEndKeyFocus()
353{
354 //search_hint = _("Search");
355}
356
357nux::TextEntry* SearchBar::text_entry() const
358{
359 return pango_entry_;
360}
361
362std::string SearchBar::get_search_string() const
363{
364 return pango_entry_->GetText();
365}
366
367bool SearchBar::set_search_string(std::string const& string)
368{
369 pango_entry_->SetText(string.c_str());
370 spinner_->SetState(string == "" ? unity::dash::STATE_READY : unity::dash::STATE_CLEAR);
371 return true;
372}
373
374bool SearchBar::get_im_active() const
375{
376 return pango_entry_->im_active();
377}
378
379//
380// Key navigation
381//
382bool
383SearchBar::AcceptKeyNavFocus()
384{
385 return false;
386}
387
388const gchar* SearchBar::GetName()
389{
390 return "SearchBar";
391}
392
393const gchar* SearchBar::GetChildsName()
394{
395 return "";
396}
397
398void SearchBar::AddProperties(GVariantBuilder* builder)
399{
400 unity::variant::BuilderWrapper(builder).add(GetGeometry());
401}
402
403}
404}
0405
=== added file 'plugins/unityshell/src/HudSearchBar.h'
--- plugins/unityshell/src/HudSearchBar.h 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/src/HudSearchBar.h 2012-01-25 11:34:37 +0000
@@ -0,0 +1,116 @@
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: Neil Jagdish Patel <neil.patel@canonical.com>
18 */
19
20#ifndef HUD_SEARCH_BAR_H
21#define HUD_SEARCH_BAR_H
22
23#include <gtk/gtk.h>
24
25#include <NuxCore/Property.h>
26#include <Nux/LayeredLayout.h>
27#include <Nux/TextureArea.h>
28#include <Nux/View.h>
29#include <Nux/TextureArea.h>
30#include <NuxGraphics/GraphicsEngine.h>
31#include <Nux/EditTextBox.h>
32#include <Nux/TextEntry.h>
33#include <UnityCore/GLibSignal.h>
34
35#include "DashSearchBarSpinner.h"
36#include "IMTextEntry.h"
37#include "StaticCairoText.h"
38
39namespace unity
40{
41namespace hud
42{
43
44using namespace unity::glib;
45
46class SearchBar : public nux::View
47{
48 NUX_DECLARE_OBJECT_TYPE(SearchBar, nux::View);
49 typedef nux::ObjectPtr<SearchBar> Ptr;
50public:
51 SearchBar(NUX_FILE_LINE_PROTO);
52 ~SearchBar();
53
54 void SearchFinished();
55 nux::TextEntry* text_entry() const;
56
57 nux::RWProperty<std::string> search_string;
58 nux::Property<std::string> search_hint;
59 nux::Property<bool> showing_filters;
60 nux::Property<bool> can_refine_search;
61 nux::ROProperty<bool> im_active;
62
63 sigc::signal<void> activated;
64 sigc::signal<void, std::string const&> search_changed;
65 sigc::signal<void, std::string const&> live_search_reached;
66
67private:
68
69 void OnFontChanged(GtkSettings* settings, GParamSpec* pspec=NULL);
70 void OnSearchHintChanged();
71
72 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
73 void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
74
75 void OnMouseButtonDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
76 void OnEndKeyFocus();
77
78 void UpdateBackground();
79 void OnSearchChanged(nux::TextEntry* text_entry);
80 void OnClearClicked(int x, int y, unsigned long button_flags, unsigned long key_flags);
81 void OnEntryActivated();
82 void OnShowingFiltersChanged(bool is_showing);
83
84 std::string get_search_string() const;
85 bool set_search_string(std::string const& string);
86 bool get_im_active() const;
87
88 static gboolean OnLiveSearchTimeout(SearchBar* self);
89
90 const gchar* GetName();
91 const gchar* GetChildsName();
92 void AddProperties(GVariantBuilder* builder);
93 bool AcceptKeyNavFocus();
94
95private:
96 glib::SignalManager sig_manager_;
97
98 nux::AbstractPaintLayer* bg_layer_;
99 nux::HLayout* layout_;
100 nux::LayeredLayout* layered_layout_;
101 nux::StaticCairoText* hint_;
102 unity::dash::IMTextEntry* pango_entry_;
103 nux::StaticCairoText* show_filters_;
104
105 int last_width_;
106 int last_height_;
107
108 guint live_search_timeout_;
109
110 unity::dash::SearchBarSpinner* spinner_;
111};
112
113}
114}
115
116#endif
0117
=== 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-01-25 11:34:37 +0000
@@ -0,0 +1,377 @@
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}
85
86void View::ResetToDefault()
87{
88 search_bar_->search_string = "";
89 search_bar_->search_hint = default_text;
90}
91
92void View::Relayout()
93{
94 nux::Geometry geo = GetGeometry();
95 content_geo_ = GetBestFitGeometry(geo);
96 LOG_DEBUG(logger) << "content_geo: " << content_geo_.width << "x" << content_geo_.height;
97
98 layout_->SetMinMaxSize(content_geo_.width, content_geo_.height);
99
100 QueueDraw();
101}
102
103long View::PostLayoutManagement(long LayoutResult)
104{
105 Relayout();
106 return LayoutResult;
107}
108
109
110nux::View* View::default_focus() const
111{
112 return search_bar_->text_entry();
113}
114
115void View::SetQueries(Hud::Queries queries)
116{
117 queries_ = queries_;
118 button_views_->Clear();
119 int found_items = 0;
120 for (auto query = queries.begin(); query != queries.end(); query++)
121 {
122 if (found_items > 5)
123 break;
124
125 HudButton *button = new HudButton();
126 button->SetQuery(*query);
127 button_views_->AddView(button, 0, nux::MINOR_POSITION_LEFT);
128
129 button->click.connect([&](nux::View* view) {
130 query_activated.emit(dynamic_cast<HudButton*>(view)->GetQuery());
131 });
132
133 button->OnKeyNavFocusActivate.connect([&](nux::Area *area) {
134 query_activated.emit(dynamic_cast<HudButton*>(area)->GetQuery());
135 });
136
137 button->OnKeyNavFocusChange.connect([&](nux::Area *area){
138 query_selected.emit(dynamic_cast<HudButton*>(area)->GetQuery());
139 });
140
141 found_items++;
142 }
143
144 QueueRelayout();
145 QueueDraw();
146}
147
148void View::SetIcon(std::string icon_name)
149{
150 LOG_DEBUG(logger) << "Setting icon to " << icon_name;
151 icon_->SetByIconName(icon_name.c_str(), icon_size);
152 QueueDraw();
153}
154
155// Gives us the width and height of the contents that will give us the best "fit",
156// which means that the icons/views will not have uneccessary padding, everything will
157// look tight
158nux::Geometry View::GetBestFitGeometry(nux::Geometry const& for_geo)
159{
160 dash::Style& style = dash::Style::Instance();
161 int width = 0, height = 0;
162 int tile_width = style.GetTileWidth();
163 int half = for_geo.width / 2;
164
165 while ((width += tile_width) + (19 * 2) < half)
166 ;
167
168 width = MAX(width, tile_width * 6);
169
170 width += 19 + 32;
171
172 height = search_bar_->GetGeometry().height;
173 height += 6;
174 height += (style.GetTextLineHeight() + (12*2)) * 6;
175 height += 6;
176
177 LOG_DEBUG (logger) << "best fit is, " << width << ", " << height;
178
179 return nux::Geometry(0, 0, width, height);
180}
181
182void View::AboutToShow()
183{
184 renderer_.AboutToShow();
185}
186
187void View::AboutToHide()
188{
189 renderer_.AboutToHide();
190}
191
192void View::SetWindowGeometry(nux::Geometry const& absolute_geo, nux::Geometry const& geo)
193{
194 window_geometry_ = geo;
195 window_geometry_.x = 0;
196 window_geometry_.y = 0;
197 absolute_window_geometry_ = absolute_geo;
198}
199
200void View::SetupViews()
201{
202 layout_ = new nux::HLayout();
203 layout_->AddLayout(new nux::SpaceLayout(8,8,8,8), 0);
204
205 icon_ = new Icon("", icon_size, true);
206 //icon_->SetBaseSize(icon_size, icon_size);
207 //icon_->SetMinMaxSize(icon_size, icon_size);
208
209 nux::Layout* icon_layout = new nux::VLayout();
210 icon_layout->SetVerticalExternalMargin(12);
211 icon_layout->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL);
212 layout_->AddLayout(icon_layout, 0, nux::MINOR_POSITION_TOP, nux::MINOR_SIZE_MATCHCONTENT);
213
214
215 content_layout_ = new nux::VLayout();
216 layout_->AddLayout(content_layout_.GetPointer(), 1, nux::MINOR_POSITION_TOP);
217 SetLayout(layout_.GetPointer());
218
219 // add the search bar to the composite
220 search_bar_ = new unity::hud::SearchBar();
221 search_bar_->search_hint = default_text;
222 search_bar_->search_changed.connect(sigc::mem_fun(this, &View::OnSearchChanged));
223 content_layout_->AddView(search_bar_.GetPointer(), 0, nux::MINOR_POSITION_LEFT);
224
225 button_views_ = new nux::VLayout();
226 button_views_->SetHorizontalExternalMargin(12);
227 content_layout_->AddLayout(button_views_.GetPointer(), 1, nux::MINOR_POSITION_LEFT);
228}
229
230void View::OnSearchChanged(std::string const& search_string)
231{
232 LOG_DEBUG(logger) << "got search change";
233 search_changed.emit(search_string);
234 if (search_string.empty())
235 {
236 search_bar_->search_hint = default_text;
237 }
238 else
239 {
240 search_bar_->search_hint = "";
241 }
242}
243
244
245void View::OnKeyDown (unsigned long event_type, unsigned long keysym,
246 unsigned long event_state, const TCHAR* character,
247 unsigned short key_repeat_count)
248{
249 if (keysym == NUX_VK_ESCAPE)
250 {
251 LOG_DEBUG(logger) << "got escape key";
252 ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST);
253 }
254}
255
256void View::OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key)
257{
258 if (!content_geo_.IsPointInside(x, y))
259 {
260 ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST);
261 }
262}
263
264void View::Draw(nux::GraphicsEngine& gfx_context, bool force_draw)
265{
266 renderer_.DrawFull(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_);
267}
268
269void View::DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw)
270{
271 renderer_.DrawInner(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_);
272
273 if (IsFullRedraw())
274 {
275 nux::GetPainter().PushBackgroundStack();
276 layout_->ProcessDraw(gfx_context, force_draw);
277 nux::GetPainter().PopBackgroundStack();
278 }
279 else
280 {
281 layout_->ProcessDraw(gfx_context, force_draw);
282 }
283
284 renderer_.DrawInnerCleanup(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_);
285}
286
287// Keyboard navigation
288bool View::AcceptKeyNavFocus()
289{
290 return false;
291}
292
293// Introspectable
294const gchar* View::GetName()
295{
296 return "unity.hud.View";
297}
298
299void View::AddProperties(GVariantBuilder* builder)
300{}
301
302bool View::InspectKeyEvent(unsigned int eventType,
303 unsigned int key_sym,
304 const char* character)
305{
306 if ((eventType == nux::NUX_KEYDOWN) && (key_sym == NUX_VK_ESCAPE))
307 {
308 if (search_bar_->search_string == "")
309 {
310 ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST);
311 }
312 else
313 {
314 search_bar_->search_string = "";
315 search_bar_->search_hint = default_text;
316 }
317 return true;
318 }
319 return false;
320}
321
322nux::Area* View::FindKeyFocusArea(unsigned int key_symbol,
323 unsigned long x11_key_code,
324 unsigned long special_keys_state)
325{
326 // Do what nux::View does, but if the event isn't a key navigation,
327 // designate the text entry to process it.
328
329 nux::KeyNavDirection direction = nux::KEY_NAV_NONE;
330 switch (x11_key_code)
331 {
332 case NUX_VK_UP:
333 direction = nux::KEY_NAV_UP;
334 break;
335 case NUX_VK_DOWN:
336 direction = nux::KEY_NAV_DOWN;
337 break;
338 case NUX_VK_LEFT:
339 direction = nux::KEY_NAV_LEFT;
340 break;
341 case NUX_VK_RIGHT:
342 direction = nux::KEY_NAV_RIGHT;
343 break;
344 case NUX_VK_LEFT_TAB:
345 direction = nux::KEY_NAV_TAB_PREVIOUS;
346 break;
347 case NUX_VK_TAB:
348 direction = nux::KEY_NAV_TAB_NEXT;
349 break;
350 case NUX_VK_ENTER:
351 case NUX_KP_ENTER:
352 // Not sure if Enter should be a navigation key
353 direction = nux::KEY_NAV_ENTER;
354 break;
355 default:
356 direction = nux::KEY_NAV_NONE;
357 break;
358 }
359
360 if (has_key_focus_)
361 {
362 return this;
363 }
364 else if (direction == nux::KEY_NAV_NONE)
365 {
366 // then send the event to the search entry
367 return search_bar_->text_entry();
368 }
369 else if (next_object_to_key_focus_area_)
370 {
371 return next_object_to_key_focus_area_->FindKeyFocusArea(key_symbol, x11_key_code, special_keys_state);
372 }
373 return NULL;
374}
375
376}
377}
0378
=== 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-01-25 11:34:37 +0000
@@ -0,0 +1,115 @@
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
35#include "UBusWrapper.h"
36#include "HudIcon.h"
37#include "HudSearchBar.h"
38#include "OverlayRenderer.h"
39
40namespace unity
41{
42namespace hud
43{
44
45class View : public nux::View
46{
47 NUX_DECLARE_OBJECT_TYPE(HudView, nux::View);
48 typedef nux::ObjectPtr<View> Ptr;
49public:
50 View();
51 ~View();
52
53 void ResetToDefault();
54
55 void Relayout();
56 nux::View* default_focus() const;
57
58 void SetQueries(Hud::Queries queries);
59 void SetIcon(std::string icon_name);
60
61 void AboutToShow();
62 void AboutToHide();
63
64 void SetWindowGeometry(nux::Geometry const& absolute_geo, nux::Geometry const& geo);
65
66 sigc::signal<void, std::string> search_changed;
67 sigc::signal<void, std::string> search_activated;
68 sigc::signal<void, Query::Ptr> query_activated;
69 sigc::signal<void, Query::Ptr> query_selected;
70
71protected:
72 virtual Area* FindKeyFocusArea(unsigned int key_symbol,
73 unsigned long x11_key_code,
74 unsigned long special_keys_state);
75
76 void SetupViews();
77 void OnSearchChanged(std::string const& search_string);
78 virtual long PostLayoutManagement(long LayoutResult);
79private:
80 void OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key);
81 void OnKeyDown (unsigned long event_type, unsigned long event_keysym,
82 unsigned long event_state, const TCHAR* character,
83 unsigned short key_repeat_count);
84 void Draw(nux::GraphicsEngine& gfx_context, bool force_draw);
85 void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw);
86 bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character);
87 bool AcceptKeyNavFocus();
88 nux::Geometry GetBestFitGeometry(nux::Geometry const& for_geo);
89
90 const gchar* GetName();
91 void AddProperties(GVariantBuilder* builder);
92
93private:
94 UBusManager ubus;
95 nux::ObjectPtr<nux::Layout> layout_;
96 nux::ObjectPtr<nux::Layout> content_layout_;
97 nux::ObjectPtr<nux::VLayout> button_views_;
98
99 //FIXME - replace with dash search bar once modifications to dash search bar land
100 SearchBar::Ptr search_bar_;
101 Icon::Ptr icon_;
102 bool visible_;
103
104 Hud::Queries queries_;
105 nux::Geometry content_geo_;
106 OverlayRenderer renderer_;
107 nux::Geometry window_geometry_;
108 nux::Geometry absolute_window_geometry_;
109};
110
111
112}
113}
114#endif
115
0116
=== 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-01-25 11:34:37 +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
@@ -78,25 +80,33 @@
7880
79void IconTexture::SetByIconName(const char* icon_name, unsigned int size)81void IconTexture::SetByIconName(const char* icon_name, unsigned int size)
80{82{
81 g_free(_icon_name);83 if (g_strcmp0(icon_name, "") != 0)
82 _icon_name = g_strdup(icon_name);84 {
83 _size = size;85 g_free(_icon_name);
84 LoadIcon();86 _icon_name = g_strdup(icon_name);
87 _size = size;
88 LoadIcon();
89 }
85}90}
8691
87void IconTexture::SetByFilePath(const char* file_path, unsigned int size)92void IconTexture::SetByFilePath(const char* file_path, unsigned int size)
88{93{
89 g_free(_icon_name);94 if (g_strcmp0(file_path, "") != 0)
90 _icon_name = g_strdup(file_path);95 {
91 _size = size;96 g_free(_icon_name);
97 _icon_name = g_strdup(file_path);
98 _size = size;
9299
93 LoadIcon();100 LoadIcon();
101 }
94}102}
95103
96void IconTexture::LoadIcon()104void IconTexture::LoadIcon()
97{105{
98 static const char* const DEFAULT_GICON = ". GThemedIcon text-x-preview";106 static const char* const DEFAULT_GICON = ". GThemedIcon text-x-preview";
99107 if (_icon_name == NULL)
108 return;
109
100 if (_loading)110 if (_loading)
101 return;111 return;
102 _loading = true;112 _loading = true;
@@ -144,6 +154,7 @@
144 _texture_height,154 _texture_height,
145 sigc::mem_fun(this, &IconTexture::CreateTextureCallback));155 sigc::mem_fun(this, &IconTexture::CreateTextureCallback));
146 QueueDraw();156 QueueDraw();
157 _loading = false;
147}158}
148159
149void IconTexture::IconLoaded(std::string const& icon_name, unsigned size,160void IconTexture::IconLoaded(std::string const& icon_name, unsigned size,
@@ -162,6 +173,8 @@
162 if (icon_name != DEFAULT_ICON)173 if (icon_name != DEFAULT_ICON)
163 SetByIconName(DEFAULT_ICON, _size);174 SetByIconName(DEFAULT_ICON, _size);
164 }175 }
176
177 QueueDraw();
165}178}
166179
167void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)180void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
168181
=== modified file 'plugins/unityshell/src/Launcher.cpp'
--- plugins/unityshell/src/Launcher.cpp 2012-01-23 13:07:40 +0000
+++ plugins/unityshell/src/Launcher.cpp 2012-01-25 11:34:37 +0000
@@ -282,8 +282,8 @@
282 _drag_window = NULL;282 _drag_window = NULL;
283 _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(2, 2, 1, nux::BITFMT_R8G8B8A8);283 _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(2, 2, 1, nux::BITFMT_R8G8B8A8);
284284
285 ubus.RegisterInterest(UBUS_PLACE_VIEW_SHOWN, sigc::mem_fun(this, &Launcher::OnPlaceViewShown));285 ubus.RegisterInterest(UBUS_OVERLAY_SHOWN, sigc::mem_fun(this, &Launcher::OnOverlayShown));
286 ubus.RegisterInterest(UBUS_PLACE_VIEW_HIDDEN, sigc::mem_fun(this, &Launcher::OnPlaceViewHidden));286 ubus.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::mem_fun(this, &Launcher::OnOverlayHidden));
287 ubus.RegisterInterest(UBUS_LAUNCHER_ACTION_DONE, sigc::mem_fun(this, &Launcher::OnActionDone));287 ubus.RegisterInterest(UBUS_LAUNCHER_ACTION_DONE, sigc::mem_fun(this, &Launcher::OnActionDone));
288 ubus.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &Launcher::OnBGColorChanged));288 ubus.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, sigc::mem_fun(this, &Launcher::OnBGColorChanged));
289 ubus.RegisterInterest(UBUS_LAUNCHER_LOCK_HIDE, sigc::mem_fun(this, &Launcher::OnLockHideChanged));289 ubus.RegisterInterest(UBUS_LAUNCHER_LOCK_HIDE, sigc::mem_fun(this, &Launcher::OnLockHideChanged));
@@ -1490,34 +1490,52 @@
1490 }1490 }
1491}1491}
14921492
1493void Launcher::OnPlaceViewShown(GVariant* data)1493void Launcher::OnOverlayShown(GVariant* data)
1494{1494{
1495 LauncherModel::iterator it;1495 // check the type of overlay
14961496 gchar* overlay_identity = NULL;
1497 _dash_is_open = true;1497 gboolean can_maximise = FALSE;
1498 bg_effect_helper_.enabled = true;1498 g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING,
1499 _hide_machine->SetQuirk(LauncherHideMachine::PLACES_VISIBLE, true);1499 &overlay_identity, &can_maximise);
1500 _hover_machine->SetQuirk(LauncherHoverMachine::PLACES_VISIBLE, true);1500
15011501 if (!g_strcmp0(overlay_identity, "dash"))
1502 DesaturateIcons();1502 {
1503 LauncherModel::iterator it;
1504
1505 _dash_is_open = true;
1506 bg_effect_helper_.enabled = true;
1507 _hide_machine->SetQuirk(LauncherHideMachine::PLACES_VISIBLE, true);
1508 _hover_machine->SetQuirk(LauncherHoverMachine::PLACES_VISIBLE, true);
1509
1510 DesaturateIcons();
1511 }
1503}1512}
15041513
1505void Launcher::OnPlaceViewHidden(GVariant* data)1514void Launcher::OnOverlayHidden(GVariant* data)
1506{1515{
1507 LauncherModel::iterator it;1516 // check the type of overlay
15081517 gchar* overlay_identity = NULL;
1509 _dash_is_open = false;1518 gboolean can_maximise = FALSE;
1510 bg_effect_helper_.enabled = false;1519 g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING,
1511 _hide_machine->SetQuirk(LauncherHideMachine::PLACES_VISIBLE, false);1520 &overlay_identity, &can_maximise);
1512 _hover_machine->SetQuirk(LauncherHoverMachine::PLACES_VISIBLE, false);1521
15131522 if (!g_strcmp0(overlay_identity, "dash"))
1514 // as the leave event is no more received when the place is opened1523 {
1515 // FIXME: remove when we change the mouse grab strategy in nux1524 LauncherModel::iterator it;
1516 nux::Point pt = nux::GetWindowCompositor().GetMousePosition();1525
15171526 _dash_is_open = false;
1518 SetStateMouseOverLauncher(GetAbsoluteGeometry().IsInside(pt));1527 bg_effect_helper_.enabled = false;
15191528 _hide_machine->SetQuirk(LauncherHideMachine::PLACES_VISIBLE, false);
1520 SaturateIcons();1529 _hover_machine->SetQuirk(LauncherHoverMachine::PLACES_VISIBLE, false);
1530
1531 // as the leave event is no more received when the place is opened
1532 // FIXME: remove when we change the mouse grab strategy in nux
1533 nux::Point pt = nux::GetWindowCompositor().GetMousePosition();
1534
1535 SetStateMouseOverLauncher(GetAbsoluteGeometry().IsInside(pt));
1536
1537 SaturateIcons();
1538 }
1521}1539}
15221540
1523void Launcher::OnActionDone(GVariant* data)1541void Launcher::OnActionDone(GVariant* data)
15241542
=== modified file 'plugins/unityshell/src/Launcher.h'
--- plugins/unityshell/src/Launcher.h 2012-01-23 13:07:40 +0000
+++ plugins/unityshell/src/Launcher.h 2012-01-25 11:34:37 +0000
@@ -350,8 +350,8 @@
350350
351 void OnIconNeedsRedraw(AbstractLauncherIcon* icon);351 void OnIconNeedsRedraw(AbstractLauncherIcon* icon);
352352
353 void OnPlaceViewHidden(GVariant* data);353 void OnOverlayHidden(GVariant* data);
354 void OnPlaceViewShown(GVariant* data);354 void OnOverlayShown(GVariant* data);
355355
356 void DesaturateIcons();356 void DesaturateIcons();
357 void SaturateIcons();357 void SaturateIcons();
358358
=== modified file 'plugins/unityshell/src/PanelMenuView.cpp'
--- plugins/unityshell/src/PanelMenuView.cpp 2012-01-12 13:36:44 +0000
+++ plugins/unityshell/src/PanelMenuView.cpp 2012-01-25 11:34:37 +0000
@@ -155,10 +155,10 @@
155155
156 // Register for all the interesting events156 // Register for all the interesting events
157 UBusServer* ubus = ubus_server_get_default();157 UBusServer* ubus = ubus_server_get_default();
158 _ubus_interests.push_back(ubus_server_register_interest(ubus, UBUS_PLACE_VIEW_SHOWN,158 _ubus_interests.push_back(ubus_server_register_interest(ubus, UBUS_OVERLAY_SHOWN,
159 (UBusCallback)PanelMenuView::OnPlaceViewShown,159 (UBusCallback)PanelMenuView::OnPlaceViewShown,
160 this));160 this));
161 _ubus_interests.push_back(ubus_server_register_interest(ubus, UBUS_PLACE_VIEW_HIDDEN,161 _ubus_interests.push_back(ubus_server_register_interest(ubus, UBUS_OVERLAY_HIDDEN,
162 (UBusCallback)PanelMenuView::OnPlaceViewHidden,162 (UBusCallback)PanelMenuView::OnPlaceViewHidden,
163 this));163 this));
164164
165165
=== modified file 'plugins/unityshell/src/PanelView.cpp'
--- plugins/unityshell/src/PanelView.cpp 2012-01-16 07:34:25 +0000
+++ plugins/unityshell/src/PanelView.cpp 2012-01-25 11:34:37 +0000
@@ -103,11 +103,11 @@
103 (UBusCallback)&PanelView::OnBackgroundUpdate,103 (UBusCallback)&PanelView::OnBackgroundUpdate,
104 this);104 this);
105105
106 _handle_dash_hidden = ubus_server_register_interest(ubus, UBUS_PLACE_VIEW_HIDDEN,106 _handle_dash_hidden = ubus_server_register_interest(ubus, UBUS_OVERLAY_HIDDEN,
107 (UBusCallback)&PanelView::OnDashHidden,107 (UBusCallback)&PanelView::OnDashHidden,
108 this);108 this);
109109
110 _handle_dash_shown = ubus_server_register_interest(ubus, UBUS_PLACE_VIEW_SHOWN,110 _handle_dash_shown = ubus_server_register_interest(ubus, UBUS_OVERLAY_SHOWN,
111 (UBusCallback)&PanelView::OnDashShown,111 (UBusCallback)&PanelView::OnDashShown,
112 this);112 this);
113 // request the latest colour from bghash113 // request the latest colour from bghash
114114
=== modified file 'plugins/unityshell/src/PlacesHomeView.cpp'
--- plugins/unityshell/src/PlacesHomeView.cpp 2011-12-14 20:04:23 +0000
+++ plugins/unityshell/src/PlacesHomeView.cpp 2012-01-25 11:34:37 +0000
@@ -106,7 +106,7 @@
106 (style.GetHomeTileHeight() * 2) + 32);106 (style.GetHomeTileHeight() * 2) + 32);
107107
108 _ubus_handle = ubus_server_register_interest(ubus_server_get_default(),108 _ubus_handle = ubus_server_register_interest(ubus_server_get_default(),
109 UBUS_PLACE_VIEW_SHOWN,109 UBUS_OVERLAY_SHOWN,
110 (UBusCallback) &PlacesHomeView::DashVisible,110 (UBusCallback) &PlacesHomeView::DashVisible,
111 this);111 this);
112112
113113
=== modified file 'plugins/unityshell/src/UBusMessages.h'
--- plugins/unityshell/src/UBusMessages.h 2012-01-17 15:41:30 +0000
+++ plugins/unityshell/src/UBusMessages.h 2012-01-25 11:34:37 +0000
@@ -34,9 +34,11 @@
34#define UBUS_PLACE_ENTRY_ACTIVATE_REQUEST "PLACE_ENTRY_ACTIVATE_REQUEST"34#define UBUS_PLACE_ENTRY_ACTIVATE_REQUEST "PLACE_ENTRY_ACTIVATE_REQUEST"
35#define UBUS_DASH_ABOUT_TO_SHOW "DASH_ABOUT_TO_SHOW"35#define UBUS_DASH_ABOUT_TO_SHOW "DASH_ABOUT_TO_SHOW"
3636
37// Signal send when places are shown or hidden37// Signal sent when an overlay interface is shown, includes a gvariant
38#define UBUS_PLACE_VIEW_HIDDEN "PLACE_VIEW_HIDDEN"38// gvariant format is (sb), (interface-name, can_maximize?)
39#define UBUS_PLACE_VIEW_SHOWN "PLACE_VIEW_SHOWN"39#define UBUS_OVERLAY_FORMAT_STRING "(sb)"
40#define UBUS_OVERLAY_HIDDEN "OVERLAY_HIDDEN"
41#define UBUS_OVERLAY_SHOWN "OVERLAY_SHOWN"
4042
41#define UBUS_PLACE_VIEW_QUEUE_DRAW "PLACE_VIEW_QUEUE_DRAW"43#define UBUS_PLACE_VIEW_QUEUE_DRAW "PLACE_VIEW_QUEUE_DRAW"
4244
@@ -76,6 +78,8 @@
76// FIXME - fix the nux focus api so we don't need this78// FIXME - fix the nux focus api so we don't need this
77#define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED"79#define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED"
7880
81#define UBUS_HUD_CLOSE_REQUEST "HUD_CLOSE_REQUEST"
82
79// Signals sent when the switcher is shown, hidden or changes selection83// Signals sent when the switcher is shown, hidden or changes selection
80#define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN"84#define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN"
81#define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED"85#define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED"
8286
=== modified file 'plugins/unityshell/src/WindowButtons.cpp'
--- plugins/unityshell/src/WindowButtons.cpp 2011-12-14 20:04:23 +0000
+++ plugins/unityshell/src/WindowButtons.cpp 2012-01-25 11:34:37 +0000
@@ -54,7 +54,7 @@
54 _normal_dash_tex(NULL),54 _normal_dash_tex(NULL),
55 _prelight_dash_tex(NULL),55 _prelight_dash_tex(NULL),
56 _pressed_dash_tex(NULL),56 _pressed_dash_tex(NULL),
57 _dash_is_open(false),57 _overlay_is_open(false),
58 _mouse_is_down(false),58 _mouse_is_down(false),
59 _place_shown_interest(0),59 _place_shown_interest(0),
60 _place_hidden_interest(0),60 _place_hidden_interest(0),
@@ -66,11 +66,11 @@
66 dash::Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::UpdateDashUnmaximize));66 dash::Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::UpdateDashUnmaximize));
6767
68 UBusServer* ubus = ubus_server_get_default();68 UBusServer* ubus = ubus_server_get_default();
69 _place_shown_interest = ubus_server_register_interest(ubus, UBUS_PLACE_VIEW_SHOWN,69 _place_shown_interest = ubus_server_register_interest(ubus, UBUS_OVERLAY_SHOWN,
70 (UBusCallback)&WindowButton::OnPlaceViewShown,70 (UBusCallback)&WindowButton::OnOverlayShown,
71 this);71 this);
72 _place_hidden_interest = ubus_server_register_interest(ubus, UBUS_PLACE_VIEW_HIDDEN,72 _place_hidden_interest = ubus_server_register_interest(ubus, UBUS_OVERLAY_HIDDEN,
73 (UBusCallback)&WindowButton::OnPlaceViewHidden,73 (UBusCallback)&WindowButton::OnOverlayHidden,
74 this);74 this);
7575
76 /* FIXME HasMouseFocus() doesn't seem to work correctly, so we use this workaround */76 /* FIXME HasMouseFocus() doesn't seem to work correctly, so we use this workaround */
@@ -106,7 +106,7 @@
106106
107 GfxContext.PushClippingRectangle(geo);107 GfxContext.PushClippingRectangle(geo);
108108
109 if (_dash_is_open)109 if (_overlay_is_open)
110 {110 {
111 //FIXME should use HasMouseFocus()111 //FIXME should use HasMouseFocus()
112 if (_mouse_is_down && IsMouseInside())112 if (_mouse_is_down && IsMouseInside())
@@ -163,7 +163,7 @@
163 _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT);163 _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT);
164 _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED);164 _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED);
165165
166 if (_dash_is_open)166 if (_overlay_is_open)
167 {167 {
168 if (_normal_dash_tex)168 if (_normal_dash_tex)
169 SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight());169 SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight());
@@ -190,6 +190,7 @@
190 if (_pressed_dash_tex)190 if (_pressed_dash_tex)
191 _pressed_dash_tex->UnReference();191 _pressed_dash_tex->UnReference();
192192
193 //!!FIXME!! - don't have disabled instances of the (un)maximize buttons
193 if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)194 if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP)
194 {195 {
195 // get maximize buttons196 // get maximize buttons
@@ -208,7 +209,7 @@
208 // still check if the dash is really opened,209 // still check if the dash is really opened,
209 // someone could change the form factor through dconf210 // someone could change the form factor through dconf
210 // when the dash is closed211 // when the dash is closed
211 if (_dash_is_open)212 if (_overlay_is_open)
212 {213 {
213 if (_normal_dash_tex)214 if (_normal_dash_tex)
214 SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight());215 SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight());
@@ -239,28 +240,35 @@
239 nux::BaseTexture* _normal_dash_tex;240 nux::BaseTexture* _normal_dash_tex;
240 nux::BaseTexture* _prelight_dash_tex;241 nux::BaseTexture* _prelight_dash_tex;
241 nux::BaseTexture* _pressed_dash_tex;242 nux::BaseTexture* _pressed_dash_tex;
242 bool _dash_is_open;243 bool _overlay_is_open;
244 bool _overlay_can_maximize;
243 bool _mouse_is_down;245 bool _mouse_is_down;
244 guint32 _place_shown_interest;246 guint32 _place_shown_interest;
245 guint32 _place_hidden_interest;247 guint32 _place_hidden_interest;
246 double _opacity;248 double _opacity;
247249
248 static void OnPlaceViewShown(GVariant* data, void* val)250 static void OnOverlayShown(GVariant* data, void* val)
249 {251 {
252 gchar* overlay_identity = NULL;
253 gboolean can_maximise = FALSE;
254 g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING,
255 &overlay_identity, &can_maximise);
250 WindowButton* self = (WindowButton*)val;256 WindowButton* self = (WindowButton*)val;
251257
252 self->_dash_is_open = true;258 self->_overlay_is_open = true;
253 if (self->_normal_dash_tex)259 if (self->_normal_dash_tex)
254 self->SetMinMaxSize(self->_normal_dash_tex->GetWidth(), self->_normal_dash_tex->GetHeight());260 self->SetMinMaxSize(self->_normal_dash_tex->GetWidth(), self->_normal_dash_tex->GetHeight());
255261
262 self->_overlay_can_maximize = (can_maximise) ? true : false;
263
256 self->QueueDraw();264 self->QueueDraw();
257 }265 }
258266
259 static void OnPlaceViewHidden(GVariant* data, void* val)267 static void OnOverlayHidden(GVariant* data, void* val)
260 {268 {
261 WindowButton* self = (WindowButton*)val;269 WindowButton* self = (WindowButton*)val;
262270
263 self->_dash_is_open = false;271 self->_overlay_is_open = false;
264 if (self->_normal_tex)272 if (self->_normal_tex)
265 self->SetMinMaxSize(self->_normal_tex->GetWidth(), self->_normal_tex->GetHeight());273 self->SetMinMaxSize(self->_normal_tex->GetWidth(), self->_normal_tex->GetHeight());
266274
267275
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2012-01-20 06:47:42 +0000
+++ plugins/unityshell/src/unityshell.cpp 2012-01-25 11:34:37 +0000
@@ -118,6 +118,7 @@
118 , dash_is_open_ (false)118 , dash_is_open_ (false)
119 , grab_index_ (0)119 , grab_index_ (0)
120 , painting_tray_ (false)120 , painting_tray_ (false)
121 , last_hud_show_time_(0)
121{122{
122 Timer timer;123 Timer timer;
123 gfloat version;124 gfloat version;
@@ -206,9 +207,9 @@
206207
207 nux::NuxInitialize(0);208 nux::NuxInitialize(0);
208 wt = nux::CreateFromForeignWindow(cScreen->output(),209 wt = nux::CreateFromForeignWindow(cScreen->output(),
209 glXGetCurrentContext(),210 glXGetCurrentContext(),
210 &UnityScreen::initUnity,211 &UnityScreen::initUnity,
211 this);212 this);
212213
213 wt->RedrawRequested.connect(sigc::mem_fun(this, &UnityScreen::onRedrawRequested));214 wt->RedrawRequested.connect(sigc::mem_fun(this, &UnityScreen::onRedrawRequested));
214215
@@ -243,6 +244,9 @@
243 uScreen->_fbo->onScreenSizeChanged (geometry);244 uScreen->_fbo->onScreenSizeChanged (geometry);
244 }245 }
245246
247 optionSetShowHudInitiate(boost::bind(&UnityScreen::ShowHudInitiate, this, _1, _2, _3));
248 optionSetShowHudTerminate(boost::bind(&UnityScreen::ShowHudTerminate, this, _1, _2, _3));
249
246 optionSetBackgroundColorNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));250 optionSetBackgroundColorNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
247 optionSetLauncherHideModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));251 optionSetLauncherHideModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
248 optionSetBacklightModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));252 optionSetBacklightModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2));
@@ -301,19 +305,19 @@
301305
302 UBusServer* ubus = ubus_server_get_default();306 UBusServer* ubus = ubus_server_get_default();
303 _ubus_handles[0] = ubus_server_register_interest(ubus,307 _ubus_handles[0] = ubus_server_register_interest(ubus,
304 UBUS_LAUNCHER_START_KEY_NAV,308 UBUS_LAUNCHER_START_KEY_NAV,
305 (UBusCallback)&UnityScreen::OnLauncherStartKeyNav,309 (UBusCallback)&UnityScreen::OnLauncherStartKeyNav,
306 this);310 this);
307311
308 _ubus_handles[1] = ubus_server_register_interest(ubus,312 _ubus_handles[1] = ubus_server_register_interest(ubus,
309 UBUS_LAUNCHER_END_KEY_NAV,313 UBUS_LAUNCHER_END_KEY_NAV,
310 (UBusCallback)&UnityScreen::OnLauncherEndKeyNav,314 (UBusCallback)&UnityScreen::OnLauncherEndKeyNav,
311 this);315 this);
312316
313 _ubus_handles[2] = ubus_server_register_interest(ubus,317 _ubus_handles[2] = ubus_server_register_interest(ubus,
314 UBUS_QUICKLIST_END_KEY_NAV,318 UBUS_QUICKLIST_END_KEY_NAV,
315 (UBusCallback)&UnityScreen::OnQuicklistEndKeyNav,319 (UBusCallback)&UnityScreen::OnQuicklistEndKeyNav,
316 this);320 this);
317321
318 g_idle_add_full (G_PRIORITY_DEFAULT, &UnityScreen::initPluginActions, this, NULL);322 g_idle_add_full (G_PRIORITY_DEFAULT, &UnityScreen::initPluginActions, this, NULL);
319 super_keypressed_ = false;323 super_keypressed_ = false;
@@ -328,11 +332,11 @@
328332
329 BackgroundEffectHelper::updates_enabled = true;333 BackgroundEffectHelper::updates_enabled = true;
330334
331 ubus_manager_.RegisterInterest(UBUS_PLACE_VIEW_SHOWN, [&](GVariant * args) { 335 ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, [&](GVariant * args) {
332 dash_is_open_ = true; 336 dash_is_open_ = true;
333 RaiseInputWindows(); 337 RaiseInputWindows();
334 });338 });
335 ubus_manager_.RegisterInterest(UBUS_PLACE_VIEW_HIDDEN, [&](GVariant * args) { dash_is_open_ = false; });339 ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, [&](GVariant * args) { dash_is_open_ = false; });
336 LOG_INFO(logger) << "UnityScreen constructed: " << timer.ElapsedSeconds() << "s";340 LOG_INFO(logger) << "UnityScreen constructed: " << timer.ElapsedSeconds() << "s";
337 }341 }
338}342}
@@ -372,7 +376,7 @@
372 sout << "<Alt>" << XKeysymToString(above_tab_keysym);376 sout << "<Alt>" << XKeysymToString(above_tab_keysym);
373377
374 screen->removeAction(&optionGetAltTabNextWindow());378 screen->removeAction(&optionGetAltTabNextWindow());
375 379
376 CompAction action = CompAction();380 CompAction action = CompAction();
377 action.keyFromString(sout.str());381 action.keyFromString(sout.str());
378 action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab);382 action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab);
@@ -387,7 +391,7 @@
387 sout << "<Alt><Shift>" << XKeysymToString(above_tab_keysym);391 sout << "<Alt><Shift>" << XKeysymToString(above_tab_keysym);
388392
389 screen->removeAction(&optionGetAltTabPrevWindow());393 screen->removeAction(&optionGetAltTabPrevWindow());
390 394
391 CompAction action = CompAction();395 CompAction action = CompAction();
392 action.keyFromString(sout.str());396 action.keyFromString(sout.str());
393 action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab);397 action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab);
@@ -638,9 +642,9 @@
638 uTrayWindow->gWindow->glAddGeometrySetCurrentIndex ( MAXSHORT);642 uTrayWindow->gWindow->glAddGeometrySetCurrentIndex ( MAXSHORT);
639 uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (MAXSHORT);643 uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (MAXSHORT);
640 uTrayWindow->gWindow->glDraw (oTransform, attrib, infiniteRegion,644 uTrayWindow->gWindow->glDraw (oTransform, attrib, infiniteRegion,
641 PAINT_WINDOW_TRANSFORMED_MASK |645 PAINT_WINDOW_TRANSFORMED_MASK |
642 PAINT_WINDOW_BLEND_MASK |646 PAINT_WINDOW_BLEND_MASK |
643 PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK);647 PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK);
644 uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (oldGlDrawGeometryIndex);648 uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (oldGlDrawGeometryIndex);
645 uTrayWindow->gWindow->glAddGeometrySetCurrentIndex (oldGlAddGeometryIndex);649 uTrayWindow->gWindow->glAddGeometrySetCurrentIndex (oldGlAddGeometryIndex);
646 uTrayWindow->gWindow->glDrawSetCurrentIndex (oldGlDrawIndex);650 uTrayWindow->gWindow->glDrawSetCurrentIndex (oldGlDrawIndex);
@@ -673,8 +677,8 @@
673bool UnityScreen::forcePaintOnTop ()677bool UnityScreen::forcePaintOnTop ()
674{678{
675 return !allowWindowPaint ||679 return !allowWindowPaint ||
676 ((switcher_controller_->Visible() ||680 ((switcher_controller_->Visible() ||
677 dash_is_open_) && !fullscreen_windows_.empty () && (!(screen->grabbed () && !screen->otherGrabExist (NULL))));681 dash_is_open_) && !fullscreen_windows_.empty () && (!(screen->grabbed () && !screen->otherGrabExist (NULL))));
678}682}
679683
680void UnityWindow::paintThumbnail (nux::Geometry const& bounding, float alpha)684void UnityWindow::paintThumbnail (nux::Geometry const& bounding, float alpha)
@@ -801,7 +805,7 @@
801{805{
802 if (mShowdesktopHandler)806 if (mShowdesktopHandler)
803 if (mShowdesktopHandler->animate (ms))807 if (mShowdesktopHandler->animate (ms))
804 { 808 {
805 delete mShowdesktopHandler;809 delete mShowdesktopHandler;
806 mShowdesktopHandler = NULL;810 mShowdesktopHandler = NULL;
807 return true;811 return true;
@@ -830,7 +834,7 @@
830 return false;834 return false;
831835
832 if (w->state () & (CompWindowStateSkipPagerMask |836 if (w->state () & (CompWindowStateSkipPagerMask |
833 CompWindowStateSkipTaskbarMask))837 CompWindowStateSkipTaskbarMask))
834 return false;838 return false;
835839
836 if ((w->state () & CompWindowStateHiddenMask))840 if ((w->state () & CompWindowStateHiddenMask))
@@ -1225,7 +1229,7 @@
1225 PluginAdapter::Default()->NotifyCompizEvent(plugin, event, option);1229 PluginAdapter::Default()->NotifyCompizEvent(plugin, event, option);
1226 compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow>::handleCompizEvent (plugin, event, option);1230 compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow>::handleCompizEvent (plugin, event, option);
12271231
1228 if (dash_is_open_ && 1232 if (dash_is_open_ &&
1229 strcmp(event, "start_viewport_switch") == 0)1233 strcmp(event, "start_viewport_switch") == 0)
1230 {1234 {
1231 ubus_server_send_message(ubus_server_get_default(), UBUS_PLACE_VIEW_CLOSE_REQUEST, NULL);1235 ubus_server_send_message(ubus_server_get_default(), UBUS_PLACE_VIEW_CLOSE_REQUEST, NULL);
@@ -1433,7 +1437,7 @@
1433 grab_index_ = screen->pushGrab (screen->invisibleCursor(), "unity-switcher");1437 grab_index_ = screen->pushGrab (screen->invisibleCursor(), "unity-switcher");
1434 if (!grab_index_)1438 if (!grab_index_)
1435 return false;1439 return false;
1436 1440
1437 std::vector<unity::launcher::AbstractLauncherIcon*> results = launcher_controller_->GetAltTabIcons();1441 std::vector<unity::launcher::AbstractLauncherIcon*> results = launcher_controller_->GetAltTabIcons();
14381442
1439 screen->addAction(&optionGetAltTabRight());1443 screen->addAction(&optionGetAltTabRight());
@@ -1524,7 +1528,7 @@
1524 altTabInitiateCommon(action, state, options);1528 altTabInitiateCommon(action, state, options);
1525 switcher_controller_->Select(1); // always select the current application1529 switcher_controller_->Select(1); // always select the current application
1526 }1530 }
1527 1531
1528 switcher_controller_->NextDetail();1532 switcher_controller_->NextDetail();
15291533
1530 action->setState(action->state() | CompAction::StateTermKey);1534 action->setState(action->state() | CompAction::StateTermKey);
@@ -1535,7 +1539,7 @@
1535{1539{
1536 if (switcher_controller_->Visible())1540 if (switcher_controller_->Visible())
1537 switcher_controller_->PrevDetail();1541 switcher_controller_->PrevDetail();
1538 1542
1539 return false;1543 return false;
1540}1544}
15411545
@@ -1584,6 +1588,35 @@
1584 PluginAdapter::Default ()->restoreInputFocus ();1588 PluginAdapter::Default ()->restoreInputFocus ();
1585}1589}
15861590
1591bool UnityScreen::ShowHudInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1592{
1593 // to receive the Terminate event
1594 if (state & CompAction::StateInitKey)
1595 action->setState(action->state() | CompAction::StateTermKey);
1596
1597 last_hud_show_time_ = g_get_monotonic_time();
1598
1599 return false;
1600}
1601
1602bool UnityScreen::ShowHudTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1603{
1604 if (optionGetShowHud().key().toString() == action->key().toString())
1605 {
1606 if (switcher_controller_->Visible())
1607 return false; // early exit if the switcher is open
1608
1609 gint64 current_time = g_get_monotonic_time();
1610 if (current_time - last_hud_show_time_ < 150 * 1000)
1611 {
1612 // less than 50 ms have passed, thats a tap
1613 hud_controller_->ShowHideHud();
1614 last_hud_show_time_ = 0;
1615 }
1616 }
1617 return false;
1618}
1619
1587void UnityScreen::OnQuicklistEndKeyNav(GVariant* data, void* value)1620void UnityScreen::OnQuicklistEndKeyNav(GVariant* data, void* value)
1588{1621{
1589 UnityScreen* self = reinterpret_cast<UnityScreen*>(value);1622 UnityScreen* self = reinterpret_cast<UnityScreen*>(value);
@@ -1676,7 +1709,7 @@
1676 bool result = screen->initPluginForScreen(p);1709 bool result = screen->initPluginForScreen(p);
1677 if (p->vTable->name() == "unityshell")1710 if (p->vTable->name() == "unityshell")
1678 initAltTabNextWindow();1711 initAltTabNextWindow();
1679 1712
1680 return result;1713 return result;
1681}1714}
16821715
@@ -1689,8 +1722,8 @@
1689 return "Unity";1722 return "Unity";
1690}1723}
16911724
1692bool isNuxWindow (CompWindow* value) 1725bool isNuxWindow (CompWindow* value)
1693{ 1726{
1694 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();1727 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();
1695 auto id = value->id();1728 auto id = value->id();
16961729
@@ -1717,7 +1750,7 @@
1717void UnityScreen::RaiseInputWindows()1750void UnityScreen::RaiseInputWindows()
1718{1751{
1719 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();1752 std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList();
1720 1753
1721 for (auto window : xwns)1754 for (auto window : xwns)
1722 {1755 {
1723 CompWindow* cwin = screen->findWindow(window);1756 CompWindow* cwin = screen->findWindow(window);
@@ -1842,7 +1875,7 @@
1842 if (!window->onCurrentDesktop ())1875 if (!window->onCurrentDesktop ())
1843 return false;1876 return false;
18441877
1845 /* Only withdrawn windows 1878 /* Only withdrawn windows
1846 * which are marked hidden1879 * which are marked hidden
1847 * are excluded */1880 * are excluded */
1848 if (!window->shaded () &&1881 if (!window->shaded () &&
@@ -1850,8 +1883,8 @@
1850 (window->state () & CompWindowStateHiddenMask))1883 (window->state () & CompWindowStateHiddenMask))
1851 return false;1884 return false;
18521885
1853 if (window->geometry ().x () + window->geometry ().width () <= 0 ||1886 if (window->geometry ().x () + window->geometry ().width () <= 0 ||
1854 window->geometry ().y () + window->geometry ().height () <= 0 ||1887 window->geometry ().y () + window->geometry ().height () <= 0 ||
1855 window->geometry ().x () >= (int) screen->width ()||1888 window->geometry ().x () >= (int) screen->width ()||
1856 window->geometry ().y () >= (int) screen->height ())1889 window->geometry ().y () >= (int) screen->height ())
1857 return false;1890 return false;
@@ -1957,7 +1990,7 @@
1957 !(lastState & CompWindowStateFullscreenMask))1990 !(lastState & CompWindowStateFullscreenMask))
1958 UnityScreen::get (screen)->fullscreen_windows_.push_back(window);1991 UnityScreen::get (screen)->fullscreen_windows_.push_back(window);
1959 else if (lastState & CompWindowStateFullscreenMask &&1992 else if (lastState & CompWindowStateFullscreenMask &&
1960 !(window->state () & CompWindowStateFullscreenMask))1993 !(window->state () & CompWindowStateFullscreenMask))
1961 UnityScreen::get (screen)->fullscreen_windows_.remove(window);1994 UnityScreen::get (screen)->fullscreen_windows_.remove(window);
19621995
1963 PluginAdapter::Default()->NotifyStateChange(window, window->state(), lastState);1996 PluginAdapter::Default()->NotifyStateChange(window, window->state(), lastState);
@@ -2136,9 +2169,9 @@
2136 {2169 {
2137 case UnityshellOptions::BackgroundColor:2170 case UnityshellOptions::BackgroundColor:
2138 {2171 {
2139 nux::Color override_color (optionGetBackgroundColorRed() / 65535.0f, 2172 nux::Color override_color (optionGetBackgroundColorRed() / 65535.0f,
2140 optionGetBackgroundColorGreen() / 65535.0f, 2173 optionGetBackgroundColorGreen() / 65535.0f,
2141 optionGetBackgroundColorBlue() / 65535.0f, 2174 optionGetBackgroundColorBlue() / 65535.0f,
2142 optionGetBackgroundColorAlpha() / 65535.0f);2175 optionGetBackgroundColorAlpha() / 65535.0f);
21432176
2144 override_color.red = override_color.red / override_color.alpha;2177 override_color.red = override_color.red / override_color.alpha;
@@ -2185,6 +2218,7 @@
21852218
2186 launcher.SetIconSize(optionGetIconSize() + 6, optionGetIconSize());2219 launcher.SetIconSize(optionGetIconSize() + 6, optionGetIconSize());
2187 dash_controller_->launcher_width = optionGetIconSize() + 18;2220 dash_controller_->launcher_width = optionGetIconSize() + 18;
2221 hud_controller_->launcher_width = optionGetIconSize() + 18;
21882222
2189 if (p)2223 if (p)
2190 {2224 {
@@ -2360,6 +2394,10 @@
2360 /* Setup Places */2394 /* Setup Places */
2361 dash_controller_.reset(new dash::Controller());2395 dash_controller_.reset(new dash::Controller());
2362 dash_controller_->on_realize.connect(sigc::mem_fun(this, &UnityScreen::OnDashRealized));2396 dash_controller_->on_realize.connect(sigc::mem_fun(this, &UnityScreen::OnDashRealized));
2397
2398 /* Setup Hud */
2399 hud_controller_.reset(new hud::Controller());
2400 LOG_INFO(logger) << "initLauncher-hud " << timer.ElapsedSeconds() << "s";
2363 2401
2364 // Setup Shortcut Hint2402 // Setup Shortcut Hint
2365 InitHints();2403 InitHints();
@@ -2515,7 +2553,7 @@
25152553
2516 if (mShowdesktopHandler)2554 if (mShowdesktopHandler)
2517 delete mShowdesktopHandler;2555 delete mShowdesktopHandler;
2518 2556
2519 if (focusdesktop_handle_)2557 if (focusdesktop_handle_)
2520 g_source_remove(focusdesktop_handle_);2558 g_source_remove(focusdesktop_handle_);
25212559
25222560
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2012-01-20 06:47:42 +0000
+++ plugins/unityshell/src/unityshell.h 2012-01-25 11:34:37 +0000
@@ -56,6 +56,8 @@
56#include <compiztoolbox/compiztoolbox.h>56#include <compiztoolbox/compiztoolbox.h>
57#include <dlfcn.h>57#include <dlfcn.h>
5858
59#include "HudController.h"
60
59namespace unity61namespace unity
60{62{
6163
@@ -192,6 +194,9 @@
192 bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);194 bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
193 bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);195 bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
194196
197 /* handle hud key activations */
198 bool ShowHudInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
199 bool ShowHudTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
195 bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);200 bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
196 bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);201 bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options);
197 bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);202 bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options);
@@ -260,6 +265,7 @@
260 dash::Controller::Ptr dash_controller_;265 dash::Controller::Ptr dash_controller_;
261 panel::Controller::Ptr panel_controller_;266 panel::Controller::Ptr panel_controller_;
262 switcher::Controller::Ptr switcher_controller_;267 switcher::Controller::Ptr switcher_controller_;
268 hud::Controller::Ptr hud_controller_;
263269
264 shortcut::Controller::Ptr shortcut_controller_;270 shortcut::Controller::Ptr shortcut_controller_;
265 std::list<shortcut::AbstractHint*> hints_;271 std::list<shortcut::AbstractHint*> hints_;
@@ -313,6 +319,7 @@
313 CompWindowList fullscreen_windows_;319 CompWindowList fullscreen_windows_;
314 bool painting_tray_;320 bool painting_tray_;
315 unsigned int tray_paint_mask_;321 unsigned int tray_paint_mask_;
322 gint64 last_hud_show_time_;
316323
317 ScreenEffectFramebufferObject::GLXGetProcAddressProc glXGetProcAddressP;324 ScreenEffectFramebufferObject::GLXGetProcAddressProc glXGetProcAddressP;
318325
@@ -381,7 +388,7 @@
381 UnityMinimizedHandler *mMinimizeHandler;388 UnityMinimizedHandler *mMinimizeHandler;
382389
383 UnityShowdesktopHandler *mShowdesktopHandler;390 UnityShowdesktopHandler *mShowdesktopHandler;
384 391
385private:392private:
386393
387 guint focusdesktop_handle_;394 guint focusdesktop_handle_;
388395
=== modified file 'plugins/unityshell/unityshell.xml.in'
--- plugins/unityshell/unityshell.xml.in 2012-01-19 16:21:14 +0000
+++ plugins/unityshell/unityshell.xml.in 2012-01-25 11:34:37 +0000
@@ -40,8 +40,13 @@
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="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>
45 <option name="launcher_reveal_edge" type="edge">50 <option name="launcher_reveal_edge" type="edge">
46 <_short>Reveal Mode</_short>51 <_short>Reveal Mode</_short>
47 <_long>From which edge should the launcher reveal.</_long>52 <_long>From which edge should the launcher reveal.</_long>
@@ -56,7 +61,7 @@
56 <max>1000</max>61 <max>1000</max>
57 <default>150</default>62 <default>150</default>
58 </option>63 </option>
59 <option name="launcher_hide_mode" type="int">64 <option name="launcher_hide_mode" type="int">
60 <_short>Hide Launcher</_short>65 <_short>Hide Launcher</_short>
61 <_long>Make the launcher hide automatically after some time of inactivity: always or just when the focussed window is not over the launcher</_long>66 <_long>Make the launcher hide automatically after some time of inactivity: always or just when the focussed window is not over the launcher</_long>
62 <min>0</min>67 <min>0</min>
@@ -78,16 +83,16 @@
78 <value>3</value>83 <value>3</value>
79 <_name>Dodge Active Window</_name>84 <_name>Dodge Active Window</_name>
80 </desc>85 </desc>
81 </option>86 </option>
82 <option name="show_launcher" type="key">87 <option name="show_launcher" type="key">
83 <_short>Key to show the launcher</_short>88 <_short>Key to show the launcher</_short>
84 <_long>Make the launcher appear with that key</_long>89 <_long>Make the launcher appear with that key</_long>
85 <default>&lt;Super&gt;</default>90 <default>&lt;Super&gt;</default>
86 </option>91 </option>
87 <option name="keyboard_focus" type="key">92 <option name="keyboard_focus" type="key">
88 <_short>Key to put keyboard-focus on launcher</_short>93 <_short>Key to put keyboard-focus on launcher</_short>
89 <_long>Set the keyboard-focus on the launcher so it can be navigated with the cursor-keys</_long>94 <_long>Set the keyboard-focus on the launcher so it can be navigated with the cursor-keys</_long>
90 <default>&lt;Alt&gt;F1</default>95 <default>&lt;Alt&gt;F1</default>
91 </option>96 </option>
92 <option name="execute_command" type="key">97 <option name="execute_command" type="key">
93 <_short>Key to execute a command</_short>98 <_short>Key to execute a command</_short>
@@ -132,37 +137,37 @@
132 <_long>fixme</_long>137 <_long>fixme</_long>
133 <default>&lt;Alt&gt;&lt;Shift&gt;Tab</default>138 <default>&lt;Alt&gt;&lt;Shift&gt;Tab</default>
134 </option>139 </option>
135 <option name="alt_tab_right" type="key">140 <option name="alt_tab_right" type="key">
136 <_short>Go right in the switcher</_short>141 <_short>Go right in the switcher</_short>
137 <_long>fixme</_long>142 <_long>fixme</_long>
138 <default>&lt;Alt&gt;Right</default>143 <default>&lt;Alt&gt;Right</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_left" type="key">147 <option name="alt_tab_left" type="key">
143 <_short>Go left in the switcher</_short>148 <_short>Go left in the switcher</_short>
144 <_long>fixme</_long>149 <_long>fixme</_long>
145 <default>&lt;Alt&gt;Left</default>150 <default>&lt;Alt&gt;Left</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_detail_start" type="key">154 <option name="alt_tab_detail_start" type="key">
150 <_short>Key to expose the windows in the switcher</_short>155 <_short>Key to expose the windows in the switcher</_short>
151 <_long>fixme</_long>156 <_long>fixme</_long>
152 <default>&lt;Alt&gt;Down</default>157 <default>&lt;Alt&gt;Down</default>
153 <passive_grab>false</passive_grab>158 <passive_grab>false</passive_grab>
154 <internal/>159 <internal/>
155 </option>160 </option>
156 <option name="alt_tab_detail_stop" type="key">161 <option name="alt_tab_detail_stop" type="key">
157 <_short>Key to collapse windows in the switcher</_short>162 <_short>Key to collapse windows in the switcher</_short>
158 <_long>fixme</_long>163 <_long>fixme</_long>
159 <default>&lt;Alt&gt;Up</default>164 <default>&lt;Alt&gt;Up</default>
160 <passive_grab>false</passive_grab>165 <passive_grab>false</passive_grab>
161 <internal/>166 <internal/>
162 </option>167 </option>
163 <option name="alt_tab_next_window" type="key">168 <option name="alt_tab_next_window" type="key">
164 <_short>Key to flip through windows in the switcher</_short>169 <_short>Key to flip through windows in the switcher</_short>
165 <_long>fixme</_long>170 <_long>fixme</_long>
166 <passive_grab>false</passive_grab>171 <passive_grab>false</passive_grab>
167 </option>172 </option>
168 <option name="alt_tab_prev_window" type="key">173 <option name="alt_tab_prev_window" type="key">
@@ -170,11 +175,11 @@
170 <_long>fixme</_long>175 <_long>fixme</_long>
171 <passive_grab>false</passive_grab>176 <passive_grab>false</passive_grab>
172 </option>177 </option>
173 <option name="show_minimized_windows" type="bool">178 <option name="show_minimized_windows" type="bool">
174 <_short>Show minimized windows in switcher</_short>179 <_short>Show minimized windows in switcher</_short>
175 <_long>Hack to enable minimized windows in switcher. Disable and report bugs if problems are caused</_long>180 <_long>Hack to enable minimized windows in switcher. Disable and report bugs if problems are caused</_long>
176 <default>true</default>181 <default>true</default>
177 </option>182 </option>
178 </group>183 </group>
179 <group>184 <group>
180 <_short>Experimental</_short>185 <_short>Experimental</_short>
@@ -333,7 +338,7 @@
333 <max>100</max>338 <max>100</max>
334 <default>75</default>339 <default>75</default>
335 </option>340 </option>
336 341
337 <option name="devices_option" type="int">342 <option name="devices_option" type="int">
338 <_short>Show Devices</_short>343 <_short>Show Devices</_short>
339 <_long>Show devices in the launcher</_long>344 <_long>Show devices in the launcher</_long>
340345
=== modified file 'standalone-clients/CMakeLists.txt'
--- standalone-clients/CMakeLists.txt 2012-01-17 11:30:30 +0000
+++ standalone-clients/CMakeLists.txt 2012-01-25 11:34:37 +0000
@@ -86,6 +86,10 @@
86 ${UNITY_SRC}/PlacesSimpleTile.h86 ${UNITY_SRC}/PlacesSimpleTile.h
87 ${UNITY_SRC}/PlacesVScrollBar.cpp87 ${UNITY_SRC}/PlacesVScrollBar.cpp
88 ${UNITY_SRC}/PlacesVScrollBar.h88 ${UNITY_SRC}/PlacesVScrollBar.h
89 ${UNITY_SRC}/DashView.cpp
90 ${UNITY_SRC}/DashView.h
91 ${UNITY_SRC}/DashViewPrivate.cpp
92 ${UNITY_SRC}/DashViewPrivate.h
89 ${UNITY_SRC}/HomeView.cpp93 ${UNITY_SRC}/HomeView.cpp
90 ${UNITY_SRC}/HomeView.h94 ${UNITY_SRC}/HomeView.h
91 ${UNITY_SRC}/DashStyle.cpp95 ${UNITY_SRC}/DashStyle.cpp
@@ -460,6 +464,35 @@
460 )464 )
461add_dependencies (bg-hash unity-core-${UNITY_API_VERSION})465add_dependencies (bg-hash unity-core-${UNITY_API_VERSION})
462466
467add_executable (hud
468 StandaloneHud.cpp
469 ${UNITY_SRC}/BackgroundEffectHelper.cpp
470 ${UNITY_SRC}/BackgroundEffectHelper.h
471 ${UNITY_SRC}/DashSettings.cpp
472 ${UNITY_SRC}/DashSettings.h
473 ${UNITY_SRC}/DashStyle.cpp
474 ${UNITY_SRC}/DashSearchBarSpinner.cpp
475 ${UNITY_SRC}/HudSearchBar.cpp
476 ${UNITY_SRC}/HudButton.cpp
477 ${UNITY_SRC}/HudIcon.cpp
478 ${UNITY_SRC}/HudIcon.h
479 ${UNITY_SRC}/HudView.cpp
480 ${UNITY_SRC}/IMTextEntry.cpp
481 ${UNITY_SRC}/Introspectable.cpp
482 ${UNITY_SRC}/IconTexture.cpp
483 ${UNITY_SRC}/IconLoader.cpp
484 ${UNITY_SRC}/JSONParser.cpp
485 ${UNITY_SRC}/OverlayRenderer.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
463add_executable (test-shortcut496add_executable (test-shortcut
464 TestShortcut.cpp497 TestShortcut.cpp
465 ${UNITY_SRC}/AbstractSeparator.cpp498 ${UNITY_SRC}/AbstractSeparator.cpp
466499
=== added file 'standalone-clients/StandaloneHud.cpp'
--- standalone-clients/StandaloneHud.cpp 1970-01-01 00:00:00 +0000
+++ standalone-clients/StandaloneHud.cpp 2012-01-25 11:34:37 +0000
@@ -0,0 +1,170 @@
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 icon_name = (*query)->icon_name;
86 break;
87 }
88 }
89
90 hud_view_->SetIcon(icon_name);
91
92 });
93
94 hud_view_->query_activated.connect([&] (unity::hud::Query::Ptr query) {
95 hud_service_.ExecuteQuery(query, 0);
96 });
97
98 hud_view_->query_selected.connect([&] (unity::hud::Query::Ptr query) {
99 hud_view_->SetIcon(query->icon_name);
100 });
101
102 hud_view_->search_changed.connect([&] (std::string search_string) {
103 hud_service_.RequestQuery(search_string);
104 });
105
106 hud_view_->search_activated.connect([&] (std::string search_string) {
107 hud_service_.ExecuteQueryBySearch(search_string, 0);
108 });
109
110 hud_service_.RequestQuery("");
111
112 hud_view_->SetWindowGeometry(layout->GetAbsoluteGeometry(), layout->GetGeometry());
113
114}
115
116void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
117{
118 TestRunner *self = (TestRunner *) InitData;
119 self->Init ();
120}
121
122void
123ControlThread (nux::NThread* thread,
124 void* data)
125{
126 // sleep for 3 seconds
127 nux::SleepForMilliseconds (3000);
128 printf ("ControlThread successfully started\n");
129}
130
131
132int main(int argc, char **argv)
133{
134 nux::SystemThread* st = NULL;
135 nux::WindowThread* wt = NULL;
136
137 // no real tests right now, just make sure we don't get any criticals and such
138 // waiting on nice perceptual diff support before we can build real tests
139 // for views
140
141 g_type_init ();
142 gtk_init (&argc, &argv);
143
144 nux::NuxInitialize(0);
145
146 // Slightly higher as we're more likely to test things we know will fail
147 nux::logging::configure_logging("unity.hud=debug");
148
149 nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
150 LOG_DEBUG(logger) << "starting the standalone hud";
151 // The instances for the pseudo-singletons.
152 unity::dash::Style dash_style;
153
154 TestRunner *test_runner = new TestRunner ();
155 wt = nux::CreateGUIThread(TEXT("Hud Prototype Test"),
156 1024, 768,
157 0,
158 &TestRunner::InitWindowThread,
159 test_runner);
160
161 st = nux::CreateSystemThread (NULL, ControlThread, wt);
162
163 if (st)
164 st->Start (NULL);
165
166 wt->Run (NULL);
167 delete st;
168 delete wt;
169 return 0;
170}
0171
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-01-23 13:07:40 +0000
+++ tests/CMakeLists.txt 2012-01-25 11:34:37 +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
@@ -164,17 +166,18 @@
164166
165# tests that require dbus, must not require X167# tests that require dbus, must not require X
166 add_executable(test-gtest-dbus168 add_executable(test-gtest-dbus
167 test_categories.cpp169# test_categories.cpp
168 test_filesystem_lenses.cpp170# test_filesystem_lenses.cpp
169 test_filter.cpp171# test_filter.cpp
170 test_indicator_entry.cpp172# test_indicator_entry.cpp
171 test_lens.cpp173# test_lens.cpp
172 test_main_dbus.cpp174 test_main_dbus.cpp
173 test_model.cpp175# test_model.cpp
174 test_utils.h176# test_utils.h
175 test_ratings_filter.cpp177# test_ratings_filter.cpp
176 test_results.cpp178# test_results.cpp
177 )179 test_hud.cpp
180 )
178 target_link_libraries(test-gtest-dbus ${GTEST_BOTH_LIBRARIES})181 target_link_libraries(test-gtest-dbus ${GTEST_BOTH_LIBRARIES})
179 add_test(UnityGTestDBus test-gtest-dbus)182 add_test(UnityGTestDBus test-gtest-dbus)
180 add_dependencies(test-gtest-dbus unity-core-${UNITY_API_VERSION} test-gtest-service)183 add_dependencies(test-gtest-dbus unity-core-${UNITY_API_VERSION} test-gtest-service)
181184
=== added file 'tests/test_hud.cpp'
--- tests/test_hud.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_hud.cpp 2012-01-25 11:34:37 +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-01-25 11:34:37 +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-01-25 11:34:37 +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-01-25 11:34:37 +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,
@@ -32,8 +33,9 @@
32};33};
3334
34static GMainLoop* loop_ = NULL;35static GMainLoop* loop_ = NULL;
35static ServiceLens* lens_ = NULL;36//static ServiceLens* lens_ = NULL;
36static ServiceModel* model_ = NULL;37//static ServiceModel* model_ = NULL;
38static ServiceHud* hud_ = NULL;
3739
38gint40gint
39main(gint argc, gchar** argv)41main(gint argc, gchar** argv)
@@ -42,8 +44,9 @@
4244
43 loop_ = g_main_loop_new(NULL, FALSE);45 loop_ = g_main_loop_new(NULL, FALSE);
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;