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 | ||||||||||||||||
Related bugs: |
|
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.
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2011-12-19 22:18:53 +0000 | |||
3 | +++ CMakeLists.txt 2012-01-25 11:34:37 +0000 | |||
4 | @@ -8,7 +8,7 @@ | |||
5 | 8 | # | 8 | # |
6 | 9 | set (PROJECT_NAME "unity") | 9 | set (PROJECT_NAME "unity") |
7 | 10 | set (UNITY_MAJOR 5) | 10 | set (UNITY_MAJOR 5) |
9 | 11 | set (UNITY_MINOR 0) | 11 | set (UNITY_MINOR 1) |
10 | 12 | set (UNITY_MICRO 0) | 12 | set (UNITY_MICRO 0) |
11 | 13 | set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}") | 13 | set (UNITY_VERSION "${UNITY_MAJOR}.${UNITY_MINOR}.${UNITY_MICRO}") |
12 | 14 | set (UNITY_API_VERSION "5.0") | 14 | set (UNITY_API_VERSION "5.0") |
13 | @@ -110,7 +110,7 @@ | |||
14 | 110 | SET (BOOT_LOGGER_FLAG "-DENABLE_LOGGER") | 110 | SET (BOOT_LOGGER_FLAG "-DENABLE_LOGGER") |
15 | 111 | endif (BOOT_LOGGER) | 111 | endif (BOOT_LOGGER) |
16 | 112 | 112 | ||
18 | 113 | SET (MAINTAINER_CFLAGS "-Werror -Wall -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self -Warray-bounds") | 113 | SET (MAINTAINER_CFLAGS "-Wall -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self -Warray-bounds") |
19 | 114 | option (DISABLE_MAINTAINER_CFLAGS "Disable maintainer CFlags" OFF) | 114 | option (DISABLE_MAINTAINER_CFLAGS "Disable maintainer CFlags" OFF) |
20 | 115 | if (DISABLE_MAINTAINER_CFLAGS) | 115 | if (DISABLE_MAINTAINER_CFLAGS) |
21 | 116 | SET (MAINTAINER_CFLAGS "") | 116 | SET (MAINTAINER_CFLAGS "") |
22 | 117 | 117 | ||
23 | === modified file 'UnityCore/CMakeLists.txt' | |||
24 | --- UnityCore/CMakeLists.txt 2012-01-17 16:02:39 +0000 | |||
25 | +++ UnityCore/CMakeLists.txt 2012-01-25 11:34:37 +0000 | |||
26 | @@ -21,6 +21,7 @@ | |||
27 | 21 | GLibSignal-inl.h | 21 | GLibSignal-inl.h |
28 | 22 | GLibWrapper.h | 22 | GLibWrapper.h |
29 | 23 | GLibWrapper-inl.h | 23 | GLibWrapper-inl.h |
30 | 24 | Hud.h | ||
31 | 24 | IndicatorEntry.h | 25 | IndicatorEntry.h |
32 | 25 | Indicator.h | 26 | Indicator.h |
33 | 26 | Indicators.h | 27 | Indicators.h |
34 | @@ -53,6 +54,7 @@ | |||
35 | 53 | GLibDBusProxy.cpp | 54 | GLibDBusProxy.cpp |
36 | 54 | GLibSignal.cpp | 55 | GLibSignal.cpp |
37 | 55 | GLibWrapper.cpp | 56 | GLibWrapper.cpp |
38 | 57 | Hud.cpp | ||
39 | 56 | Indicator.cpp | 58 | Indicator.cpp |
40 | 57 | IndicatorEntry.cpp | 59 | IndicatorEntry.cpp |
41 | 58 | Indicators.cpp | 60 | Indicators.cpp |
42 | 59 | 61 | ||
43 | === modified file 'UnityCore/GLibDBusProxy.cpp' | |||
44 | --- UnityCore/GLibDBusProxy.cpp 2012-01-16 15:19:47 +0000 | |||
45 | +++ UnityCore/GLibDBusProxy.cpp 2012-01-25 11:34:37 +0000 | |||
46 | @@ -144,7 +144,6 @@ | |||
47 | 144 | LOG_DEBUG(logger) << self->name_ << " appeared"; | 144 | LOG_DEBUG(logger) << self->name_ << " appeared"; |
48 | 145 | 145 | ||
49 | 146 | self->connected_ = true; | 146 | self->connected_ = true; |
50 | 147 | self->owner_->connected.emit(); | ||
51 | 148 | } | 147 | } |
52 | 149 | 148 | ||
53 | 150 | void DBusProxy::Impl::OnNameVanished(GDBusConnection* connection, | 149 | void DBusProxy::Impl::OnNameVanished(GDBusConnection* connection, |
54 | 151 | 150 | ||
55 | === added file 'UnityCore/Hud.cpp' | |||
56 | --- UnityCore/Hud.cpp 1970-01-01 00:00:00 +0000 | |||
57 | +++ UnityCore/Hud.cpp 2012-01-25 11:34:37 +0000 | |||
58 | @@ -0,0 +1,239 @@ | |||
59 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
60 | 2 | /* | ||
61 | 3 | * Copyright (C) 2011 Canonical Ltd | ||
62 | 4 | * | ||
63 | 5 | * This program is free software: you can redistribute it and/or modify | ||
64 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
65 | 7 | * published by the Free Software Foundation. | ||
66 | 8 | * | ||
67 | 9 | * This program is distributed in the hope that it will be useful, | ||
68 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
69 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
70 | 12 | * GNU General Public License for more details. | ||
71 | 13 | * | ||
72 | 14 | * You should have received a copy of the GNU General Public License | ||
73 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
74 | 16 | * | ||
75 | 17 | * Authored by: Gordon Allott <gord.allott@canonical.com> | ||
76 | 18 | */ | ||
77 | 19 | // | ||
78 | 20 | #include "Hud.h" | ||
79 | 21 | |||
80 | 22 | #include <gio/gio.h> | ||
81 | 23 | #include <glib.h> | ||
82 | 24 | #include <NuxCore/Logger.h> | ||
83 | 25 | #include "GLibWrapper.h" | ||
84 | 26 | #include "GLibDBusProxy.h" | ||
85 | 27 | |||
86 | 28 | #include "config.h" | ||
87 | 29 | |||
88 | 30 | #include <sigc++/bind.h> | ||
89 | 31 | |||
90 | 32 | namespace unity | ||
91 | 33 | { | ||
92 | 34 | namespace hud | ||
93 | 35 | { | ||
94 | 36 | |||
95 | 37 | namespace | ||
96 | 38 | { | ||
97 | 39 | nux::logging::Logger logger("unity.hud.hud"); | ||
98 | 40 | const int request_number_of_results = 6; | ||
99 | 41 | } | ||
100 | 42 | |||
101 | 43 | // Impl classes | ||
102 | 44 | class HudImpl | ||
103 | 45 | { | ||
104 | 46 | public: | ||
105 | 47 | HudImpl(std::string const& dbus_name, | ||
106 | 48 | std::string const& dbus_path, | ||
107 | 49 | Hud *parent) | ||
108 | 50 | : query_key_(NULL) | ||
109 | 51 | , proxy_(dbus_name, dbus_path, "com.canonical.hud") | ||
110 | 52 | , parent_(parent) | ||
111 | 53 | { | ||
112 | 54 | LOG_DEBUG(logger) << "Hud init with name: " << dbus_name << "and path: " << dbus_path; | ||
113 | 55 | proxy_.connected.connect([&]() { | ||
114 | 56 | LOG_DEBUG(logger) << "Hud Connected"; | ||
115 | 57 | parent_->connected = true; | ||
116 | 58 | }); | ||
117 | 59 | |||
118 | 60 | proxy_.Connect("UpdatedQuery", sigc::mem_fun(this, &HudImpl::UpdateQueryCallback)); | ||
119 | 61 | } | ||
120 | 62 | |||
121 | 63 | void QueryCallback(GVariant* data); | ||
122 | 64 | void UpdateQueryCallback(GVariant* data); | ||
123 | 65 | void BuildQueries(GVariant* query_array); | ||
124 | 66 | void ExecuteByKey(GVariant* key, unsigned int timestamp); | ||
125 | 67 | void ExecuteQueryByStringCallback(GVariant* query, unsigned int timestamp); | ||
126 | 68 | void CloseQuery(); | ||
127 | 69 | |||
128 | 70 | GVariant* query_key_; | ||
129 | 71 | Hud::Queries queries_; | ||
130 | 72 | glib::DBusProxy proxy_; | ||
131 | 73 | Hud* parent_; | ||
132 | 74 | }; | ||
133 | 75 | |||
134 | 76 | void HudImpl::ExecuteByKey(GVariant* key, unsigned int timestamp) | ||
135 | 77 | { | ||
136 | 78 | LOG_DEBUG(logger) << "Executing by Key"; | ||
137 | 79 | |||
138 | 80 | GVariantBuilder tuple; | ||
139 | 81 | g_variant_builder_init(&tuple, G_VARIANT_TYPE_TUPLE); | ||
140 | 82 | g_variant_builder_add_value(&tuple, g_variant_new_variant(key)); | ||
141 | 83 | g_variant_builder_add_value(&tuple, g_variant_new_uint32(timestamp)); | ||
142 | 84 | |||
143 | 85 | proxy_.Call("ExecuteQuery", g_variant_builder_end(&tuple)); | ||
144 | 86 | } | ||
145 | 87 | |||
146 | 88 | void HudImpl::ExecuteQueryByStringCallback(GVariant* query, unsigned int timestamp) | ||
147 | 89 | { | ||
148 | 90 | queries_.clear(); | ||
149 | 91 | |||
150 | 92 | GVariant* query_key = g_variant_get_child_value(query, 2); | ||
151 | 93 | query_key_ = query_key; | ||
152 | 94 | |||
153 | 95 | GVariant* queries = g_variant_get_child_value(query, 1); | ||
154 | 96 | BuildQueries(queries); | ||
155 | 97 | g_variant_unref(queries); | ||
156 | 98 | |||
157 | 99 | if (queries_.empty() == false) | ||
158 | 100 | { | ||
159 | 101 | // we now execute based off the first result | ||
160 | 102 | ExecuteByKey(queries_.front()->key, timestamp); | ||
161 | 103 | CloseQuery(); | ||
162 | 104 | } | ||
163 | 105 | } | ||
164 | 106 | |||
165 | 107 | void HudImpl::QueryCallback(GVariant* query) | ||
166 | 108 | { | ||
167 | 109 | queries_.clear(); | ||
168 | 110 | |||
169 | 111 | // extract the information from the GVariants | ||
170 | 112 | GVariant* target = g_variant_get_child_value(query, 0); | ||
171 | 113 | g_variant_unref(target); | ||
172 | 114 | |||
173 | 115 | GVariant* query_key = g_variant_get_child_value(query, 2); | ||
174 | 116 | query_key_ = query_key; | ||
175 | 117 | |||
176 | 118 | GVariant* queries = g_variant_get_child_value(query, 1); | ||
177 | 119 | BuildQueries(queries); | ||
178 | 120 | g_variant_unref(queries); | ||
179 | 121 | |||
180 | 122 | parent_->queries_updated.emit(queries_); | ||
181 | 123 | } | ||
182 | 124 | |||
183 | 125 | void HudImpl::UpdateQueryCallback(GVariant* query) | ||
184 | 126 | { | ||
185 | 127 | // as we are expecting an update, we want to check | ||
186 | 128 | // and make sure that we are the actual recievers of | ||
187 | 129 | // the signal | ||
188 | 130 | |||
189 | 131 | GVariant* query_key = g_variant_get_child_value(query, 2); | ||
190 | 132 | if (g_variant_equal(query_key_, query_key)) | ||
191 | 133 | { | ||
192 | 134 | GVariant* queries = g_variant_get_child_value(query, 1); | ||
193 | 135 | BuildQueries(queries); | ||
194 | 136 | g_variant_unref(queries); | ||
195 | 137 | } | ||
196 | 138 | } | ||
197 | 139 | |||
198 | 140 | void HudImpl::BuildQueries(GVariant* query_array) | ||
199 | 141 | { | ||
200 | 142 | GVariantIter iter; | ||
201 | 143 | g_variant_iter_init(&iter, query_array); | ||
202 | 144 | glib::String formatted_text; | ||
203 | 145 | glib::String icon; | ||
204 | 146 | glib::String item_icon; | ||
205 | 147 | glib::String completion_text; | ||
206 | 148 | glib::String shortcut; | ||
207 | 149 | GVariant* key = NULL; | ||
208 | 150 | |||
209 | 151 | while (g_variant_iter_loop(&iter, "(sssssv)", | ||
210 | 152 | &formatted_text, &icon, &item_icon, &completion_text, &shortcut, &key)) | ||
211 | 153 | { | ||
212 | 154 | queries_.push_back(Query::Ptr(new Query(std::string(formatted_text), | ||
213 | 155 | std::string(icon), | ||
214 | 156 | std::string(item_icon), | ||
215 | 157 | std::string(completion_text), | ||
216 | 158 | std::string(shortcut), | ||
217 | 159 | key))); | ||
218 | 160 | } | ||
219 | 161 | } | ||
220 | 162 | |||
221 | 163 | void HudImpl::CloseQuery() | ||
222 | 164 | { | ||
223 | 165 | if (query_key_ == NULL) | ||
224 | 166 | { | ||
225 | 167 | LOG_WARN(logger) << "Attempted to close the hud connection without starting it"; | ||
226 | 168 | } | ||
227 | 169 | else | ||
228 | 170 | { | ||
229 | 171 | GVariant* paramaters = g_variant_new("(v)", query_key_); | ||
230 | 172 | proxy_.Call("CloseQuery", paramaters); | ||
231 | 173 | g_variant_unref(query_key_); | ||
232 | 174 | query_key_ = NULL; | ||
233 | 175 | queries_.clear(); | ||
234 | 176 | } | ||
235 | 177 | } | ||
236 | 178 | |||
237 | 179 | |||
238 | 180 | Hud::Hud(std::string const& dbus_name, | ||
239 | 181 | std::string const& dbus_path) | ||
240 | 182 | : connected(false) | ||
241 | 183 | , pimpl_(new HudImpl(dbus_name, dbus_path, this)) | ||
242 | 184 | { | ||
243 | 185 | pimpl_->parent_ = this; | ||
244 | 186 | } | ||
245 | 187 | |||
246 | 188 | Hud::~Hud() | ||
247 | 189 | { | ||
248 | 190 | delete pimpl_; | ||
249 | 191 | } | ||
250 | 192 | |||
251 | 193 | void Hud::RequestQuery(std::string const& search_string) | ||
252 | 194 | { | ||
253 | 195 | LOG_DEBUG(logger) << "Getting Query: " << search_string; | ||
254 | 196 | if (pimpl_->query_key_ != NULL) | ||
255 | 197 | { | ||
256 | 198 | CloseQuery(); | ||
257 | 199 | } | ||
258 | 200 | |||
259 | 201 | GVariant* paramaters = g_variant_new("(si)", | ||
260 | 202 | search_string.c_str(), | ||
261 | 203 | request_number_of_results); | ||
262 | 204 | pimpl_->proxy_.Call("StartQuery", paramaters, sigc::mem_fun(this->pimpl_, &HudImpl::QueryCallback)); | ||
263 | 205 | } | ||
264 | 206 | |||
265 | 207 | |||
266 | 208 | void Hud::ExecuteQuery(Query::Ptr query, unsigned int timestamp) | ||
267 | 209 | { | ||
268 | 210 | LOG_DEBUG(logger) << "Executing query: " << query->formatted_text; | ||
269 | 211 | pimpl_->ExecuteByKey(query->key, timestamp); | ||
270 | 212 | } | ||
271 | 213 | |||
272 | 214 | void Hud::ExecuteQueryBySearch(std::string execute_string, unsigned int timestamp) | ||
273 | 215 | { | ||
274 | 216 | //Does a search then executes the result based on that search | ||
275 | 217 | LOG_DEBUG(logger) << "Executing by string" << execute_string; | ||
276 | 218 | if (pimpl_->query_key_ != NULL) | ||
277 | 219 | { | ||
278 | 220 | CloseQuery(); | ||
279 | 221 | } | ||
280 | 222 | |||
281 | 223 | GVariant* paramaters = g_variant_new("(si)", | ||
282 | 224 | execute_string.c_str(), | ||
283 | 225 | 1); | ||
284 | 226 | |||
285 | 227 | auto functor = sigc::mem_fun(this->pimpl_, &HudImpl::ExecuteQueryByStringCallback); | ||
286 | 228 | |||
287 | 229 | pimpl_->proxy_.Call("StartQuery", paramaters, sigc::bind(functor, timestamp)); | ||
288 | 230 | } | ||
289 | 231 | |||
290 | 232 | void Hud::CloseQuery() | ||
291 | 233 | { | ||
292 | 234 | //Send close hint to the hud | ||
293 | 235 | pimpl_->CloseQuery(); | ||
294 | 236 | } | ||
295 | 237 | |||
296 | 238 | } | ||
297 | 239 | } | ||
298 | 0 | 240 | ||
299 | === added file 'UnityCore/Hud.h' | |||
300 | --- UnityCore/Hud.h 1970-01-01 00:00:00 +0000 | |||
301 | +++ UnityCore/Hud.h 2012-01-25 11:34:37 +0000 | |||
302 | @@ -0,0 +1,127 @@ | |||
303 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
304 | 2 | /* | ||
305 | 3 | * Copyright (C) 2011 Canonical Ltd | ||
306 | 4 | * | ||
307 | 5 | * This program is free software: you can redistribute it and/or modify | ||
308 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
309 | 7 | * published by the Free Software Foundation. | ||
310 | 8 | * | ||
311 | 9 | * This program is distributed in the hope that it will be useful, | ||
312 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
313 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
314 | 12 | * GNU General Public License for more details. | ||
315 | 13 | * | ||
316 | 14 | * You should have received a copy of the GNU General Public License | ||
317 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
318 | 16 | * | ||
319 | 17 | * Authored by: Gordon Allott <gord.allott@canonical.com> | ||
320 | 18 | */ | ||
321 | 19 | |||
322 | 20 | #ifndef UNITY_HUD_H | ||
323 | 21 | #define UNITY_HUD_H | ||
324 | 22 | |||
325 | 23 | #include <deque> | ||
326 | 24 | #include <string> | ||
327 | 25 | #include <memory> | ||
328 | 26 | #include <NuxCore/Property.h> | ||
329 | 27 | #include <glib/gvariant.h> | ||
330 | 28 | |||
331 | 29 | namespace unity | ||
332 | 30 | { | ||
333 | 31 | namespace hud | ||
334 | 32 | { | ||
335 | 33 | |||
336 | 34 | |||
337 | 35 | class Query | ||
338 | 36 | { | ||
339 | 37 | public: | ||
340 | 38 | typedef std::shared_ptr<Query> Ptr; | ||
341 | 39 | |||
342 | 40 | Query(std::string const& formatted_text_, std::string const& icon_name_, | ||
343 | 41 | std::string const& item_icon_, std::string const& completion_text_, | ||
344 | 42 | std::string const& shortcut_, GVariant* key_) | ||
345 | 43 | : formatted_text(formatted_text_) | ||
346 | 44 | , icon_name(icon_name_) | ||
347 | 45 | , item_icon(item_icon_) | ||
348 | 46 | , completion_text(completion_text_) | ||
349 | 47 | , shortcut(shortcut_) | ||
350 | 48 | , key(key_) | ||
351 | 49 | { | ||
352 | 50 | g_variant_ref(key); | ||
353 | 51 | } | ||
354 | 52 | |||
355 | 53 | ~Query() | ||
356 | 54 | { | ||
357 | 55 | g_variant_unref(key); | ||
358 | 56 | } | ||
359 | 57 | |||
360 | 58 | Query(const Query &rhs); | ||
361 | 59 | Query& operator=(Query); | ||
362 | 60 | |||
363 | 61 | std::string formatted_text; // Pango formatted text | ||
364 | 62 | std::string icon_name; // icon name using standard lookups | ||
365 | 63 | std::string item_icon; // Future API | ||
366 | 64 | std::string completion_text; // Non formatted text f or completion | ||
367 | 65 | std::string shortcut; // Shortcut key | ||
368 | 66 | GVariant *key; | ||
369 | 67 | }; | ||
370 | 68 | |||
371 | 69 | |||
372 | 70 | class HudImpl; | ||
373 | 71 | class Hud | ||
374 | 72 | { | ||
375 | 73 | public: | ||
376 | 74 | typedef std::shared_ptr<Hud> Ptr; | ||
377 | 75 | typedef std::deque<Query::Ptr> Queries; | ||
378 | 76 | |||
379 | 77 | /* | ||
380 | 78 | * Constructor for the hud | ||
381 | 79 | * \param dbus_name string that specifies the name of the hud service | ||
382 | 80 | * \param dbus_path string that specifies the path of the hud service | ||
383 | 81 | */ | ||
384 | 82 | Hud(std::string const& dbus_name, | ||
385 | 83 | std::string const& dbus_path); | ||
386 | 84 | |||
387 | 85 | ~Hud(); | ||
388 | 86 | |||
389 | 87 | Hud(const Hud &rhs); | ||
390 | 88 | Hud& operator=(Hud); | ||
391 | 89 | |||
392 | 90 | nux::Property<std::string> target; | ||
393 | 91 | nux::Property<bool> connected; | ||
394 | 92 | |||
395 | 93 | /* | ||
396 | 94 | * Queries the service for new suggestions, will fire off the | ||
397 | 95 | * suggestion_search_finished signal when the suggestions are returned | ||
398 | 96 | */ | ||
399 | 97 | void RequestQuery(std::string const& search_string); | ||
400 | 98 | |||
401 | 99 | /* | ||
402 | 100 | * Executes a Query | ||
403 | 101 | */ | ||
404 | 102 | void ExecuteQuery(Query::Ptr query, unsigned int timestamp); | ||
405 | 103 | |||
406 | 104 | /* | ||
407 | 105 | * Executes a query that returns from a search, | ||
408 | 106 | * Implicitly calls CloseQuery(); | ||
409 | 107 | */ | ||
410 | 108 | void ExecuteQueryBySearch(std::string execute_string, unsigned int timestamp); | ||
411 | 109 | |||
412 | 110 | /* | ||
413 | 111 | * Closes the query connection, call when the hud closes | ||
414 | 112 | */ | ||
415 | 113 | void CloseQuery(); | ||
416 | 114 | |||
417 | 115 | /* | ||
418 | 116 | * Returns a deque of Query types when the service provides them | ||
419 | 117 | */ | ||
420 | 118 | sigc::signal<void, Queries> queries_updated; | ||
421 | 119 | |||
422 | 120 | private: | ||
423 | 121 | HudImpl *pimpl_; | ||
424 | 122 | }; | ||
425 | 123 | |||
426 | 124 | } | ||
427 | 125 | } | ||
428 | 126 | |||
429 | 127 | #endif /* UNITY_HUD_H */ | ||
430 | 0 | 128 | ||
431 | === added file 'manual-tests/Hud.txt' | |||
432 | --- manual-tests/Hud.txt 1970-01-01 00:00:00 +0000 | |||
433 | +++ manual-tests/Hud.txt 2012-01-25 11:34:37 +0000 | |||
434 | @@ -0,0 +1,57 @@ | |||
435 | 1 | For reference, the term Tap means to press the indicated key and release it, within a timeframe of 50ms | ||
436 | 2 | |||
437 | 3 | Hud Invocate | ||
438 | 4 | ----------- | ||
439 | 5 | This test makes sure that the hud presents itself, the launcher hides | ||
440 | 6 | and the panel changes | ||
441 | 7 | |||
442 | 8 | #. Tap Alt | ||
443 | 9 | |||
444 | 10 | Outcome | ||
445 | 11 | The hud interface presents itself with no other interface such as the dash present. | ||
446 | 12 | The Launcher hides, the panel becomes transparent with a colour tint matching the hud | ||
447 | 13 | |||
448 | 14 | Hud Search | ||
449 | 15 | ----------- | ||
450 | 16 | This test makes sure that the hud will search and activate items. | ||
451 | 17 | |||
452 | 18 | #. Ensure the devices indicator is present | ||
453 | 19 | #. Tap Alt | ||
454 | 20 | #. Type "system" to search for the "System settings..." item in the devices indicator | ||
455 | 21 | #. Press return to activate the search query. | ||
456 | 22 | |||
457 | 23 | Outcome | ||
458 | 24 | The system settings interface presents itself, the hud disappears. | ||
459 | 25 | If the hud does not disappear, this test failed. If the system settings interface | ||
460 | 26 | did not present itself, this test did *not* fail. | ||
461 | 27 | |||
462 | 28 | |||
463 | 29 | Hud Key-Navigation | ||
464 | 30 | ----------- | ||
465 | 31 | This test ensures the hud key navigation is intact | ||
466 | 32 | |||
467 | 33 | #. Ensure the messaging indicator is present | ||
468 | 34 | #. Tap Alt | ||
469 | 35 | #. Type "Message" to search for items from the messaging indicator | ||
470 | 36 | #. Press down twice | ||
471 | 37 | #. Press return | ||
472 | 38 | |||
473 | 39 | Outcome | ||
474 | 40 | The item selected will activate and the hud with disappear. | ||
475 | 41 | If the hud does not disappear, this test failed. | ||
476 | 42 | If the buttons under the search box do not highlight, this test failed. | ||
477 | 43 | |||
478 | 44 | |||
479 | 45 | Hud Dismiss | ||
480 | 46 | ---------- | ||
481 | 47 | This test ensures that the hud is dismissable | ||
482 | 48 | |||
483 | 49 | #. Tap Alt | ||
484 | 50 | #. Type "test" | ||
485 | 51 | #. Press escape | ||
486 | 52 | #. Click anywhere on the screen that is not the hud interface | ||
487 | 53 | |||
488 | 54 | Outcome | ||
489 | 55 | After pressing escape in step three, the text "test" should be removed from the hud search | ||
490 | 56 | After step four, the hud should dismiss itself and not be present. | ||
491 | 57 | |||
492 | 0 | 58 | ||
493 | === modified file 'plugins/unityshell/src/DashController.cpp' | |||
494 | --- plugins/unityshell/src/DashController.cpp 2011-12-08 01:23:11 +0000 | |||
495 | +++ plugins/unityshell/src/DashController.cpp 2012-01-25 11:34:37 +0000 | |||
496 | @@ -242,7 +242,8 @@ | |||
497 | 242 | 242 | ||
498 | 243 | StartShowHideTimeline(); | 243 | StartShowHideTimeline(); |
499 | 244 | 244 | ||
501 | 245 | ubus_manager_.SendMessage(UBUS_PLACE_VIEW_SHOWN); | 245 | GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE); |
502 | 246 | ubus_manager_.SendMessage(UBUS_OVERLAY_SHOWN, info); | ||
503 | 246 | } | 247 | } |
504 | 247 | 248 | ||
505 | 248 | void Controller::HideDash(bool restore) | 249 | void Controller::HideDash(bool restore) |
506 | @@ -262,8 +263,9 @@ | |||
507 | 262 | PluginAdapter::Default ()->restoreInputFocus (); | 263 | PluginAdapter::Default ()->restoreInputFocus (); |
508 | 263 | 264 | ||
509 | 264 | StartShowHideTimeline(); | 265 | StartShowHideTimeline(); |
512 | 265 | 266 | ||
513 | 266 | ubus_manager_.SendMessage(UBUS_PLACE_VIEW_HIDDEN); | 267 | GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "dash", TRUE); |
514 | 268 | ubus_manager_.SendMessage(UBUS_OVERLAY_HIDDEN, info); | ||
515 | 267 | } | 269 | } |
516 | 268 | 270 | ||
517 | 269 | void Controller::StartShowHideTimeline() | 271 | void Controller::StartShowHideTimeline() |
518 | 270 | 272 | ||
519 | === modified file 'plugins/unityshell/src/DashStyle.cpp' | |||
520 | --- plugins/unityshell/src/DashStyle.cpp 2012-01-19 11:57:37 +0000 | |||
521 | +++ plugins/unityshell/src/DashStyle.cpp 2012-01-25 11:34:37 +0000 | |||
522 | @@ -1428,6 +1428,7 @@ | |||
523 | 1428 | pango_layout_get_extents(layout, &ink, &log); | 1428 | pango_layout_get_extents(layout, &ink, &log); |
524 | 1429 | x = horizMargin; // let pango alignment handle the x position | 1429 | x = horizMargin; // let pango alignment handle the x position |
525 | 1430 | y = ((double) h - pango_units_to_double(log.height)) / 2.0; | 1430 | y = ((double) h - pango_units_to_double(log.height)) / 2.0; |
526 | 1431 | |||
527 | 1431 | cairo_move_to(cr, x, y); | 1432 | cairo_move_to(cr, x, y); |
528 | 1432 | pango_cairo_show_layout(cr, layout); | 1433 | pango_cairo_show_layout(cr, layout); |
529 | 1433 | 1434 | ||
530 | 1434 | 1435 | ||
531 | === added file 'plugins/unityshell/src/HudButton.cpp' | |||
532 | --- plugins/unityshell/src/HudButton.cpp 1970-01-01 00:00:00 +0000 | |||
533 | +++ plugins/unityshell/src/HudButton.cpp 2012-01-25 11:34:37 +0000 | |||
534 | @@ -0,0 +1,182 @@ | |||
535 | 1 | /* | ||
536 | 2 | * Copyright 2011 Canonical Ltd. | ||
537 | 3 | * | ||
538 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
539 | 5 | * under the terms of the GNU Lesser General Public License version 3, as | ||
540 | 6 | * published by the Free Software Foundation. | ||
541 | 7 | * | ||
542 | 8 | * This program is distributed in the hope that it will be useful, but | ||
543 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
544 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR | ||
545 | 11 | * PURPOSE. See the applicable version of the GNU Lesser General Public | ||
546 | 12 | * License for more details. | ||
547 | 13 | * | ||
548 | 14 | * You should have received a copy of both the GNU Lesser General Public | ||
549 | 15 | * License version 3 along with this program. If not, see | ||
550 | 16 | * <http://www.gnu.org/licenses/> | ||
551 | 17 | * | ||
552 | 18 | * Authored by: Gordon Allott <gord.allott@canonical.com> | ||
553 | 19 | * | ||
554 | 20 | */ | ||
555 | 21 | #include "config.h" | ||
556 | 22 | |||
557 | 23 | #include <pango/pango.h> | ||
558 | 24 | #include <pango/pangocairo.h> | ||
559 | 25 | #include <gdk/gdk.h> | ||
560 | 26 | #include <gtk/gtk.h> | ||
561 | 27 | |||
562 | 28 | #include <Nux/Nux.h> | ||
563 | 29 | #include <NuxCore/Logger.h> | ||
564 | 30 | #include <NuxImage/CairoGraphics.h> | ||
565 | 31 | #include <NuxGraphics/NuxGraphics.h> | ||
566 | 32 | #include <UnityCore/GLibWrapper.h> | ||
567 | 33 | #include "DashStyle.h" | ||
568 | 34 | |||
569 | 35 | #include "HudButton.h" | ||
570 | 36 | |||
571 | 37 | namespace | ||
572 | 38 | { | ||
573 | 39 | nux::logging::Logger logger("unity.hud.HudButton"); | ||
574 | 40 | } | ||
575 | 41 | |||
576 | 42 | namespace unity | ||
577 | 43 | { | ||
578 | 44 | namespace hud | ||
579 | 45 | { | ||
580 | 46 | |||
581 | 47 | |||
582 | 48 | HudButton::HudButton (nux::TextureArea *image, NUX_FILE_LINE_DECL) | ||
583 | 49 | : nux::Button (image, NUX_FILE_LINE_PARAM) | ||
584 | 50 | , is_focused_(false) | ||
585 | 51 | { | ||
586 | 52 | InitTheme(); | ||
587 | 53 | OnKeyNavFocusChange.connect([this](nux::Area *area){ QueueDraw(); }); | ||
588 | 54 | } | ||
589 | 55 | |||
590 | 56 | HudButton::HudButton (const std::string label_, NUX_FILE_LINE_DECL) | ||
591 | 57 | : nux::Button (NUX_FILE_LINE_PARAM) | ||
592 | 58 | , is_focused_(false) | ||
593 | 59 | { | ||
594 | 60 | InitTheme(); | ||
595 | 61 | } | ||
596 | 62 | |||
597 | 63 | HudButton::HudButton (const std::string label_, nux::TextureArea *image, NUX_FILE_LINE_DECL) | ||
598 | 64 | : nux::Button (image, NUX_FILE_LINE_PARAM) | ||
599 | 65 | , is_focused_(false) | ||
600 | 66 | { | ||
601 | 67 | InitTheme(); | ||
602 | 68 | } | ||
603 | 69 | |||
604 | 70 | HudButton::HudButton (NUX_FILE_LINE_DECL) | ||
605 | 71 | : nux::Button (NUX_FILE_LINE_PARAM) | ||
606 | 72 | , is_focused_(false) | ||
607 | 73 | { | ||
608 | 74 | InitTheme(); | ||
609 | 75 | } | ||
610 | 76 | |||
611 | 77 | HudButton::~HudButton() { | ||
612 | 78 | } | ||
613 | 79 | |||
614 | 80 | void HudButton::InitTheme() | ||
615 | 81 | { | ||
616 | 82 | SetMinimumHeight(42); | ||
617 | 83 | if (!active_) | ||
618 | 84 | { | ||
619 | 85 | nux::Geometry const& geo = GetGeometry(); | ||
620 | 86 | |||
621 | 87 | prelight_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT))); | ||
622 | 88 | active_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_PRESSED))); | ||
623 | 89 | normal_.reset(new nux::CairoWrapper(geo, sigc::bind(sigc::mem_fun(this, &HudButton::RedrawTheme), nux::ButtonVisualState::VISUAL_STATE_NORMAL))); | ||
624 | 90 | } | ||
625 | 91 | } | ||
626 | 92 | |||
627 | 93 | void HudButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state) | ||
628 | 94 | { | ||
629 | 95 | dash::Style::Instance().Button(cr, faked_state, label_, dash::Alignment::LEFT); | ||
630 | 96 | } | ||
631 | 97 | |||
632 | 98 | bool HudButton::AcceptKeyNavFocus() | ||
633 | 99 | { | ||
634 | 100 | return true; | ||
635 | 101 | } | ||
636 | 102 | |||
637 | 103 | |||
638 | 104 | long HudButton::ComputeContentSize () | ||
639 | 105 | { | ||
640 | 106 | long ret = nux::Button::ComputeContentSize(); | ||
641 | 107 | nux::Geometry const& geo = GetGeometry(); | ||
642 | 108 | |||
643 | 109 | if (cached_geometry_ != geo) | ||
644 | 110 | { | ||
645 | 111 | prelight_->Invalidate(geo); | ||
646 | 112 | active_->Invalidate(geo); | ||
647 | 113 | normal_->Invalidate(geo); | ||
648 | 114 | |||
649 | 115 | cached_geometry_ = geo; | ||
650 | 116 | } | ||
651 | 117 | |||
652 | 118 | return ret; | ||
653 | 119 | } | ||
654 | 120 | |||
655 | 121 | void HudButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) | ||
656 | 122 | { | ||
657 | 123 | nux::Geometry const& geo = GetGeometry(); | ||
658 | 124 | |||
659 | 125 | gPainter.PaintBackground(GfxContext, geo); | ||
660 | 126 | // set up our texture mode | ||
661 | 127 | nux::TexCoordXForm texxform; | ||
662 | 128 | texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); | ||
663 | 129 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); | ||
664 | 130 | |||
665 | 131 | // clear what is behind us | ||
666 | 132 | unsigned int alpha = 0, src = 0, dest = 0; | ||
667 | 133 | GfxContext.GetRenderStates().GetBlend(alpha, src, dest); | ||
668 | 134 | GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | ||
669 | 135 | |||
670 | 136 | nux::Color col = nux::color::Black; | ||
671 | 137 | col.alpha = 0; | ||
672 | 138 | GfxContext.QRP_Color(geo.x, | ||
673 | 139 | geo.y, | ||
674 | 140 | geo.width, | ||
675 | 141 | geo.height, | ||
676 | 142 | col); | ||
677 | 143 | |||
678 | 144 | nux::BaseTexture* texture = normal_->GetTexture(); | ||
679 | 145 | if (HasKeyFocus()) | ||
680 | 146 | texture = active_->GetTexture(); | ||
681 | 147 | else if (HasKeyFocus()) | ||
682 | 148 | texture = prelight_->GetTexture(); | ||
683 | 149 | else if (GetVisualState() == nux::ButtonVisualState::VISUAL_STATE_PRESSED) | ||
684 | 150 | texture = active_->GetTexture(); | ||
685 | 151 | |||
686 | 152 | GfxContext.QRP_1Tex(geo.x, | ||
687 | 153 | geo.y, | ||
688 | 154 | geo.width, | ||
689 | 155 | geo.height, | ||
690 | 156 | texture->GetDeviceTexture(), | ||
691 | 157 | texxform, | ||
692 | 158 | nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); | ||
693 | 159 | |||
694 | 160 | GfxContext.GetRenderStates().SetBlend(alpha, src, dest); | ||
695 | 161 | } | ||
696 | 162 | |||
697 | 163 | void HudButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) { | ||
698 | 164 | } | ||
699 | 165 | |||
700 | 166 | void HudButton::PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) { | ||
701 | 167 | nux::Button::PostDraw(GfxContext, force_draw); | ||
702 | 168 | } | ||
703 | 169 | |||
704 | 170 | void HudButton::SetQuery(Query::Ptr query) | ||
705 | 171 | { | ||
706 | 172 | query_ = query; | ||
707 | 173 | label_ = query->formatted_text; | ||
708 | 174 | label = query->formatted_text; | ||
709 | 175 | } | ||
710 | 176 | |||
711 | 177 | Query::Ptr HudButton::GetQuery() | ||
712 | 178 | { | ||
713 | 179 | return query_; | ||
714 | 180 | } | ||
715 | 181 | } | ||
716 | 182 | } | ||
717 | 0 | 183 | ||
718 | === added file 'plugins/unityshell/src/HudButton.h' | |||
719 | --- plugins/unityshell/src/HudButton.h 1970-01-01 00:00:00 +0000 | |||
720 | +++ plugins/unityshell/src/HudButton.h 2012-01-25 11:34:37 +0000 | |||
721 | @@ -0,0 +1,76 @@ | |||
722 | 1 | /* | ||
723 | 2 | * Copyright 2011 Canonical Ltd. | ||
724 | 3 | * | ||
725 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
726 | 5 | * under the terms of the GNU Lesser General Public License version 3, as | ||
727 | 6 | * published by the Free Software Foundation. | ||
728 | 7 | * | ||
729 | 8 | * This program is distributed in the hope that it will be useful, but | ||
730 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
731 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR | ||
732 | 11 | * PURPOSE. See the applicable version of the GNU Lesser General Public | ||
733 | 12 | * License for more details. | ||
734 | 13 | * | ||
735 | 14 | * You should have received a copy of both the GNU Lesser General Public | ||
736 | 15 | * License version 3 along with this program. If not, see | ||
737 | 16 | * <http://www.gnu.org/licenses/> | ||
738 | 17 | * | ||
739 | 18 | * Authored by: Gordon Allott <gord.allott@canonical.com> | ||
740 | 19 | * | ||
741 | 20 | */ | ||
742 | 21 | |||
743 | 22 | |||
744 | 23 | |||
745 | 24 | #ifndef FILTERBASICBUTTON_H | ||
746 | 25 | #define FILTERBASICBUTTON_H | ||
747 | 26 | |||
748 | 27 | #include <Nux/Nux.h> | ||
749 | 28 | #include <Nux/CairoWrapper.h> | ||
750 | 29 | #include <Nux/Button.h> | ||
751 | 30 | #include <Nux/TextureArea.h> | ||
752 | 31 | #include <UnityCore/Hud.h> | ||
753 | 32 | |||
754 | 33 | namespace unity { | ||
755 | 34 | |||
756 | 35 | namespace hud { | ||
757 | 36 | class HudButton : public nux::Button { | ||
758 | 37 | typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr; | ||
759 | 38 | typedef nux::ObjectPtr<HudButton> Ptr; | ||
760 | 39 | public: | ||
761 | 40 | HudButton (nux::TextureArea *image, NUX_FILE_LINE_PROTO); | ||
762 | 41 | HudButton (const std::string label, NUX_FILE_LINE_PROTO); | ||
763 | 42 | HudButton (const std::string label, nux::TextureArea *image, NUX_FILE_LINE_PROTO); | ||
764 | 43 | HudButton (NUX_FILE_LINE_PROTO); | ||
765 | 44 | virtual ~HudButton(); | ||
766 | 45 | |||
767 | 46 | void SetQuery(Query::Ptr query); | ||
768 | 47 | std::shared_ptr<Query> GetQuery(); | ||
769 | 48 | |||
770 | 49 | nux::Property<std::string> label; | ||
771 | 50 | nux::Property<std::string> hint; | ||
772 | 51 | |||
773 | 52 | protected: | ||
774 | 53 | virtual bool AcceptKeyNavFocus(); | ||
775 | 54 | virtual long ComputeContentSize(); | ||
776 | 55 | virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); | ||
777 | 56 | virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); | ||
778 | 57 | virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw); | ||
779 | 58 | |||
780 | 59 | void InitTheme (); | ||
781 | 60 | void RedrawTheme(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state); | ||
782 | 61 | typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr; | ||
783 | 62 | |||
784 | 63 | NuxCairoPtr prelight_; | ||
785 | 64 | NuxCairoPtr active_; | ||
786 | 65 | NuxCairoPtr normal_; | ||
787 | 66 | |||
788 | 67 | private: | ||
789 | 68 | std::string label_; | ||
790 | 69 | |||
791 | 70 | Query::Ptr query_; | ||
792 | 71 | nux::Geometry cached_geometry_; | ||
793 | 72 | bool is_focused_; | ||
794 | 73 | }; | ||
795 | 74 | } | ||
796 | 75 | } | ||
797 | 76 | #endif // FILTERBASICBUTTON_H | ||
798 | 0 | 77 | ||
799 | === added file 'plugins/unityshell/src/HudController.cpp' | |||
800 | --- plugins/unityshell/src/HudController.cpp 1970-01-01 00:00:00 +0000 | |||
801 | +++ plugins/unityshell/src/HudController.cpp 2012-01-25 11:34:37 +0000 | |||
802 | @@ -0,0 +1,364 @@ | |||
803 | 1 | /* | ||
804 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
805 | 3 | * | ||
806 | 4 | * This program is free software: you can redistribute it and/or modify | ||
807 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
808 | 6 | * published by the Free Software Foundation. | ||
809 | 7 | * | ||
810 | 8 | * This program is distributed in the hope that it will be useful, | ||
811 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
812 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
813 | 11 | * GNU General Public License for more details. | ||
814 | 12 | * | ||
815 | 13 | * You should have received a copy of the GNU General Public License | ||
816 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
817 | 15 | * | ||
818 | 16 | * Authored by: Gord Allott <gord.allott@canonical.com> | ||
819 | 17 | */ | ||
820 | 18 | |||
821 | 19 | #include "HudController.h" | ||
822 | 20 | |||
823 | 21 | #include <NuxCore/Logger.h> | ||
824 | 22 | #include <Nux/HLayout.h> | ||
825 | 23 | #include "PluginAdapter.h" | ||
826 | 24 | #include "UBusMessages.h" | ||
827 | 25 | #include "UScreen.h" | ||
828 | 26 | namespace unity | ||
829 | 27 | { | ||
830 | 28 | namespace hud | ||
831 | 29 | { | ||
832 | 30 | |||
833 | 31 | namespace | ||
834 | 32 | { | ||
835 | 33 | nux::logging::Logger logger("unity.hud.controller"); | ||
836 | 34 | } | ||
837 | 35 | |||
838 | 36 | Controller::Controller() | ||
839 | 37 | : launcher_width(66) | ||
840 | 38 | , panel_height(24) | ||
841 | 39 | , hud_service_("com.canonical.hud", "/com/canonical/hud") | ||
842 | 40 | , window_(0) | ||
843 | 41 | , visible_(false) | ||
844 | 42 | , need_show_(false) | ||
845 | 43 | , timeline_id_(0) | ||
846 | 44 | , last_opacity_(0.0f) | ||
847 | 45 | , start_time_(0) | ||
848 | 46 | { | ||
849 | 47 | LOG_DEBUG(logger) << "hud startup"; | ||
850 | 48 | SetupRelayoutCallbacks(); | ||
851 | 49 | |||
852 | 50 | ubus.RegisterInterest(UBUS_HUD_CLOSE_REQUEST, sigc::mem_fun(this, &Controller::OnExternalHideHud)); | ||
853 | 51 | |||
854 | 52 | //!!FIXME!! - just hijacks the dash close request so we get some more requests than normal, | ||
855 | 53 | ubus.RegisterInterest(UBUS_PLACE_VIEW_CLOSE_REQUEST, sigc::mem_fun(this, &Controller::OnExternalHideHud)); | ||
856 | 54 | |||
857 | 55 | PluginAdapter::Default()->compiz_screen_ungrabbed.connect(sigc::mem_fun(this, &Controller::OnScreenUngrabbed)); | ||
858 | 56 | |||
859 | 57 | hud_service_.queries_updated.connect(sigc::mem_fun(this, &Controller::OnQueriesFinished)); | ||
860 | 58 | EnsureHud(); | ||
861 | 59 | } | ||
862 | 60 | |||
863 | 61 | Controller::~Controller() | ||
864 | 62 | { | ||
865 | 63 | if (window_) | ||
866 | 64 | window_->UnReference(); | ||
867 | 65 | window_ = 0; | ||
868 | 66 | |||
869 | 67 | g_source_remove(timeline_id_); | ||
870 | 68 | g_source_remove(ensure_id_); | ||
871 | 69 | } | ||
872 | 70 | |||
873 | 71 | void Controller::SetupWindow() | ||
874 | 72 | { | ||
875 | 73 | window_ = new nux::BaseWindow("Hud"); | ||
876 | 74 | window_->SinkReference(); | ||
877 | 75 | window_->SetBackgroundColor(nux::Color(0.0f, 0.0f, 0.0f, 0.0f)); | ||
878 | 76 | window_->SetConfigureNotifyCallback(&Controller::OnWindowConfigure, this); | ||
879 | 77 | window_->ShowWindow(false); | ||
880 | 78 | window_->SetOpacity(0.0f); | ||
881 | 79 | window_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow)); | ||
882 | 80 | } | ||
883 | 81 | |||
884 | 82 | void Controller::SetupHudView() | ||
885 | 83 | { | ||
886 | 84 | LOG_DEBUG(logger) << "SetupHudView called"; | ||
887 | 85 | view_ = new View(); | ||
888 | 86 | |||
889 | 87 | layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); | ||
890 | 88 | layout_->AddView(view_, 1); | ||
891 | 89 | window_->SetLayout(layout_); | ||
892 | 90 | |||
893 | 91 | view_->mouse_down_outside_pointer_grab_area.connect(sigc::mem_fun(this, &Controller::OnMouseDownOutsideWindow)); | ||
894 | 92 | |||
895 | 93 | LOG_DEBUG(logger) << "connecting to signals"; | ||
896 | 94 | view_->search_changed.connect(sigc::mem_fun(this, &Controller::OnSearchChanged)); | ||
897 | 95 | view_->search_activated.connect(sigc::mem_fun(this, &Controller::OnSearchActivated)); | ||
898 | 96 | view_->query_activated.connect(sigc::mem_fun(this, &Controller::OnQueryActivated)); | ||
899 | 97 | view_->query_selected.connect(sigc::mem_fun(this, &Controller::OnQuerySelected)); | ||
900 | 98 | } | ||
901 | 99 | |||
902 | 100 | void Controller::SetupRelayoutCallbacks() | ||
903 | 101 | { | ||
904 | 102 | GdkScreen* screen = gdk_screen_get_default(); | ||
905 | 103 | |||
906 | 104 | sig_manager_.Add(new glib::Signal<void, GdkScreen*>(screen, | ||
907 | 105 | "monitors-changed", sigc::mem_fun(this, &Controller::Relayout))); | ||
908 | 106 | sig_manager_.Add(new glib::Signal<void, GdkScreen*>(screen, | ||
909 | 107 | "size-changed", sigc::mem_fun(this, &Controller::Relayout))); | ||
910 | 108 | } | ||
911 | 109 | |||
912 | 110 | void Controller::EnsureHud() | ||
913 | 111 | { | ||
914 | 112 | if (window_) | ||
915 | 113 | return; | ||
916 | 114 | |||
917 | 115 | LOG_DEBUG(logger) << "Initializing Hud"; | ||
918 | 116 | |||
919 | 117 | SetupWindow(); | ||
920 | 118 | SetupHudView(); | ||
921 | 119 | Relayout(); | ||
922 | 120 | ensure_id_ = 0; | ||
923 | 121 | } | ||
924 | 122 | |||
925 | 123 | nux::BaseWindow* Controller::window() const | ||
926 | 124 | { | ||
927 | 125 | return window_; | ||
928 | 126 | } | ||
929 | 127 | |||
930 | 128 | // We update the @geo that's sent in with our desired width and height | ||
931 | 129 | void Controller::OnWindowConfigure(int window_width, int window_height, | ||
932 | 130 | nux::Geometry& geo, void* data) | ||
933 | 131 | { | ||
934 | 132 | Controller* self = static_cast<Controller*>(data); | ||
935 | 133 | geo = self->GetIdealWindowGeometry(); | ||
936 | 134 | } | ||
937 | 135 | |||
938 | 136 | nux::Geometry Controller::GetIdealWindowGeometry() | ||
939 | 137 | { | ||
940 | 138 | UScreen *uscreen = UScreen::GetDefault(); | ||
941 | 139 | int primary_monitor = uscreen->GetPrimaryMonitor(); | ||
942 | 140 | auto monitor_geo = uscreen->GetMonitorGeometry(primary_monitor); | ||
943 | 141 | |||
944 | 142 | // We want to cover as much of the screen as possible to grab any mouse events outside | ||
945 | 143 | // of our window | ||
946 | 144 | return nux::Geometry (monitor_geo.x, | ||
947 | 145 | monitor_geo.y + panel_height, | ||
948 | 146 | monitor_geo.width, | ||
949 | 147 | monitor_geo.height - panel_height); | ||
950 | 148 | } | ||
951 | 149 | |||
952 | 150 | void Controller::Relayout(GdkScreen*screen) | ||
953 | 151 | { | ||
954 | 152 | EnsureHud(); | ||
955 | 153 | nux::Geometry content_geo = view_->GetGeometry(); | ||
956 | 154 | nux::Geometry geo = GetIdealWindowGeometry(); | ||
957 | 155 | |||
958 | 156 | window_->SetGeometry(geo); | ||
959 | 157 | layout_->SetMinMaxSize(content_geo.width, content_geo.height); | ||
960 | 158 | view_->SetWindowGeometry(window_->GetAbsoluteGeometry(), window_->GetGeometry()); | ||
961 | 159 | view_->Relayout(); | ||
962 | 160 | } | ||
963 | 161 | |||
964 | 162 | void Controller::OnMouseDownOutsideWindow(int x, int y, | ||
965 | 163 | unsigned long bflags, unsigned long kflags) | ||
966 | 164 | { | ||
967 | 165 | LOG_DEBUG(logger) << "OnMouseDownOutsideWindow called"; | ||
968 | 166 | HideHud(); | ||
969 | 167 | } | ||
970 | 168 | |||
971 | 169 | void Controller::OnScreenUngrabbed() | ||
972 | 170 | { | ||
973 | 171 | LOG_DEBUG(logger) << "OnScreenUngrabbed called"; | ||
974 | 172 | if (need_show_) | ||
975 | 173 | { | ||
976 | 174 | EnsureHud(); | ||
977 | 175 | ShowHud(); | ||
978 | 176 | } | ||
979 | 177 | } | ||
980 | 178 | |||
981 | 179 | void Controller::OnExternalShowHud(GVariant* variant) | ||
982 | 180 | { | ||
983 | 181 | EnsureHud(); | ||
984 | 182 | visible_ ? HideHud() : ShowHud(); | ||
985 | 183 | } | ||
986 | 184 | |||
987 | 185 | void Controller::OnExternalHideHud(GVariant* variant) | ||
988 | 186 | { | ||
989 | 187 | LOG_DEBUG(logger) << "External Hiding the hud"; | ||
990 | 188 | EnsureHud(); | ||
991 | 189 | HideHud(); | ||
992 | 190 | } | ||
993 | 191 | |||
994 | 192 | void Controller::ShowHideHud() | ||
995 | 193 | { | ||
996 | 194 | EnsureHud(); | ||
997 | 195 | visible_ ? HideHud() : ShowHud(); | ||
998 | 196 | } | ||
999 | 197 | |||
1000 | 198 | void Controller::ShowHud() | ||
1001 | 199 | { | ||
1002 | 200 | LOG_DEBUG(logger) << "Showing the hud"; | ||
1003 | 201 | EnsureHud(); | ||
1004 | 202 | view_->AboutToShow(); | ||
1005 | 203 | |||
1006 | 204 | window_->ShowWindow(true); | ||
1007 | 205 | window_->PushToFront(); | ||
1008 | 206 | window_->EnableInputWindow(true, "Hud", true, false); | ||
1009 | 207 | window_->SetInputFocus(); | ||
1010 | 208 | nux::GetWindowCompositor().SetKeyFocusArea(view_->default_focus()); | ||
1011 | 209 | window_->CaptureMouseDownAnyWhereElse(true); | ||
1012 | 210 | view_->CaptureMouseDownAnyWhereElse(true); | ||
1013 | 211 | window_->QueueDraw(); | ||
1014 | 212 | |||
1015 | 213 | view_->ResetToDefault(); | ||
1016 | 214 | hud_service_.RequestQuery(""); | ||
1017 | 215 | |||
1018 | 216 | need_show_ = false; | ||
1019 | 217 | visible_ = true; | ||
1020 | 218 | |||
1021 | 219 | StartShowHideTimeline(); | ||
1022 | 220 | view_->SetWindowGeometry(window_->GetAbsoluteGeometry(), window_->GetGeometry()); | ||
1023 | 221 | |||
1024 | 222 | // hide the launcher | ||
1025 | 223 | GVariant* message_data = g_variant_new("(b)", TRUE); | ||
1026 | 224 | ubus.SendMessage(UBUS_LAUNCHER_LOCK_HIDE, message_data); | ||
1027 | 225 | |||
1028 | 226 | GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "hud", FALSE); | ||
1029 | 227 | ubus.SendMessage(UBUS_OVERLAY_SHOWN, info); | ||
1030 | 228 | } | ||
1031 | 229 | void Controller::HideHud(bool restore) | ||
1032 | 230 | { | ||
1033 | 231 | LOG_DEBUG (logger) << "hiding the hud"; | ||
1034 | 232 | if (visible_ == false) | ||
1035 | 233 | return; | ||
1036 | 234 | |||
1037 | 235 | EnsureHud(); | ||
1038 | 236 | view_->AboutToHide(); | ||
1039 | 237 | window_->CaptureMouseDownAnyWhereElse(false); | ||
1040 | 238 | window_->EnableInputWindow(false, "Hud", true, false); | ||
1041 | 239 | visible_ = false; | ||
1042 | 240 | |||
1043 | 241 | StartShowHideTimeline(); | ||
1044 | 242 | |||
1045 | 243 | restore = true; | ||
1046 | 244 | if (restore) | ||
1047 | 245 | PluginAdapter::Default ()->restoreInputFocus (); | ||
1048 | 246 | |||
1049 | 247 | hud_service_.CloseQuery(); | ||
1050 | 248 | |||
1051 | 249 | //unhide the launcher | ||
1052 | 250 | GVariant* message_data = g_variant_new("(b)", FALSE); | ||
1053 | 251 | ubus.SendMessage(UBUS_LAUNCHER_LOCK_HIDE, message_data); | ||
1054 | 252 | |||
1055 | 253 | GVariant* info = g_variant_new(UBUS_OVERLAY_FORMAT_STRING, "hud", FALSE); | ||
1056 | 254 | ubus.SendMessage(UBUS_OVERLAY_HIDDEN, info); | ||
1057 | 255 | } | ||
1058 | 256 | |||
1059 | 257 | void Controller::StartShowHideTimeline() | ||
1060 | 258 | { | ||
1061 | 259 | EnsureHud(); | ||
1062 | 260 | |||
1063 | 261 | if (timeline_id_) | ||
1064 | 262 | g_source_remove(timeline_id_); | ||
1065 | 263 | |||
1066 | 264 | timeline_id_ = g_timeout_add(15, (GSourceFunc)Controller::OnViewShowHideFrame, this); | ||
1067 | 265 | last_opacity_ = window_->GetOpacity(); | ||
1068 | 266 | start_time_ = g_get_monotonic_time(); | ||
1069 | 267 | |||
1070 | 268 | } | ||
1071 | 269 | |||
1072 | 270 | gboolean Controller::OnViewShowHideFrame(Controller* self) | ||
1073 | 271 | { | ||
1074 | 272 | #define _LENGTH_ 90000 | ||
1075 | 273 | float diff = g_get_monotonic_time() - self->start_time_; | ||
1076 | 274 | float progress = diff / (float)_LENGTH_; | ||
1077 | 275 | float last_opacity = self->last_opacity_; | ||
1078 | 276 | |||
1079 | 277 | if (self->visible_) | ||
1080 | 278 | { | ||
1081 | 279 | self->window_->SetOpacity(last_opacity + ((1.0f - last_opacity) * progress)); | ||
1082 | 280 | } | ||
1083 | 281 | else | ||
1084 | 282 | { | ||
1085 | 283 | self->window_->SetOpacity(last_opacity - (last_opacity * progress)); | ||
1086 | 284 | } | ||
1087 | 285 | |||
1088 | 286 | if (diff > _LENGTH_) | ||
1089 | 287 | { | ||
1090 | 288 | self->timeline_id_ = 0; | ||
1091 | 289 | |||
1092 | 290 | // Make sure the state is right | ||
1093 | 291 | self->window_->SetOpacity(self->visible_ ? 1.0f : 0.0f); | ||
1094 | 292 | if (!self->visible_) | ||
1095 | 293 | { | ||
1096 | 294 | self->window_->ShowWindow(false); | ||
1097 | 295 | } | ||
1098 | 296 | |||
1099 | 297 | return FALSE; | ||
1100 | 298 | } | ||
1101 | 299 | |||
1102 | 300 | return TRUE; | ||
1103 | 301 | } | ||
1104 | 302 | |||
1105 | 303 | void Controller::OnActivateRequest(GVariant* variant) | ||
1106 | 304 | { | ||
1107 | 305 | EnsureHud(); | ||
1108 | 306 | ShowHud(); | ||
1109 | 307 | } | ||
1110 | 308 | |||
1111 | 309 | void Controller::OnSearchChanged(std::string search_string) | ||
1112 | 310 | { | ||
1113 | 311 | LOG_DEBUG(logger) << "Search Changed"; | ||
1114 | 312 | hud_service_.RequestQuery(search_string); | ||
1115 | 313 | } | ||
1116 | 314 | |||
1117 | 315 | void Controller::OnSearchActivated(std::string search_string) | ||
1118 | 316 | { | ||
1119 | 317 | unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; | ||
1120 | 318 | hud_service_.ExecuteQueryBySearch(search_string, timestamp); | ||
1121 | 319 | HideHud(); | ||
1122 | 320 | } | ||
1123 | 321 | |||
1124 | 322 | void Controller::OnQueryActivated(Query::Ptr query) | ||
1125 | 323 | { | ||
1126 | 324 | LOG_DEBUG(logger) << "Activating query, " << query->formatted_text; | ||
1127 | 325 | unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; | ||
1128 | 326 | hud_service_.ExecuteQuery(query, timestamp); | ||
1129 | 327 | HideHud(); | ||
1130 | 328 | } | ||
1131 | 329 | |||
1132 | 330 | void Controller::OnQuerySelected(Query::Ptr query) | ||
1133 | 331 | { | ||
1134 | 332 | LOG_DEBUG(logger) << "Selected query, " << query->formatted_text; | ||
1135 | 333 | view_->SetIcon(query->icon_name); | ||
1136 | 334 | } | ||
1137 | 335 | |||
1138 | 336 | |||
1139 | 337 | void Controller::OnQueriesFinished(Hud::Queries queries) | ||
1140 | 338 | { | ||
1141 | 339 | view_->SetQueries(queries); | ||
1142 | 340 | std::string icon_name = ""; | ||
1143 | 341 | for (auto query = queries.begin(); query != queries.end(); query++) | ||
1144 | 342 | { | ||
1145 | 343 | if (!(*query)->icon_name.empty()) | ||
1146 | 344 | { | ||
1147 | 345 | icon_name = (*query)->icon_name; | ||
1148 | 346 | break; | ||
1149 | 347 | } | ||
1150 | 348 | } | ||
1151 | 349 | |||
1152 | 350 | view_->SetIcon(icon_name); | ||
1153 | 351 | } | ||
1154 | 352 | |||
1155 | 353 | // Introspectable | ||
1156 | 354 | const gchar* Controller::GetName() | ||
1157 | 355 | { | ||
1158 | 356 | return "unity.hud.Controller"; | ||
1159 | 357 | } | ||
1160 | 358 | |||
1161 | 359 | void Controller::AddProperties(GVariantBuilder* builder) | ||
1162 | 360 | {} | ||
1163 | 361 | |||
1164 | 362 | |||
1165 | 363 | } | ||
1166 | 364 | } | ||
1167 | 0 | 365 | ||
1168 | === added file 'plugins/unityshell/src/HudController.h' | |||
1169 | --- plugins/unityshell/src/HudController.h 1970-01-01 00:00:00 +0000 | |||
1170 | +++ plugins/unityshell/src/HudController.h 2012-01-25 11:34:37 +0000 | |||
1171 | @@ -0,0 +1,113 @@ | |||
1172 | 1 | /* | ||
1173 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
1174 | 3 | * | ||
1175 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1176 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1177 | 6 | * published by the Free Software Foundation. | ||
1178 | 7 | * | ||
1179 | 8 | * This program is distributed in the hope that it will be useful, | ||
1180 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1181 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1182 | 11 | * GNU General Public License for more details. | ||
1183 | 12 | * | ||
1184 | 13 | * You should have received a copy of the GNU General Public License | ||
1185 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1186 | 15 | * | ||
1187 | 16 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
1188 | 17 | */ | ||
1189 | 18 | |||
1190 | 19 | #ifndef UNITY_HUD_CONTROLLER_H_ | ||
1191 | 20 | #define UNITY_HUD_CONTROLLER_H_ | ||
1192 | 21 | |||
1193 | 22 | #include <memory> | ||
1194 | 23 | |||
1195 | 24 | #include <gdk/gdk.h> | ||
1196 | 25 | #include <UnityCore/GLibSignal.h> | ||
1197 | 26 | #include <UnityCore/Hud.h> | ||
1198 | 27 | |||
1199 | 28 | #include <NuxCore/Property.h> | ||
1200 | 29 | #include <NuxGraphics/GraphicsEngine.h> | ||
1201 | 30 | #include <Nux/Nux.h> | ||
1202 | 31 | #include <Nux/BaseWindow.h> | ||
1203 | 32 | |||
1204 | 33 | #include "HudView.h" | ||
1205 | 34 | #include "UBusWrapper.h" | ||
1206 | 35 | |||
1207 | 36 | namespace unity | ||
1208 | 37 | { | ||
1209 | 38 | namespace hud | ||
1210 | 39 | { | ||
1211 | 40 | |||
1212 | 41 | class Controller | ||
1213 | 42 | { | ||
1214 | 43 | public: | ||
1215 | 44 | typedef std::shared_ptr<Controller> Ptr; | ||
1216 | 45 | |||
1217 | 46 | Controller(); | ||
1218 | 47 | ~Controller(); | ||
1219 | 48 | |||
1220 | 49 | nux::BaseWindow* window() const; | ||
1221 | 50 | |||
1222 | 51 | nux::Property<int> launcher_width; | ||
1223 | 52 | nux::Property<int> panel_height; | ||
1224 | 53 | |||
1225 | 54 | void ShowHideHud(); | ||
1226 | 55 | void ShowHud(); | ||
1227 | 56 | void HideHud(bool restore_focus = true); | ||
1228 | 57 | |||
1229 | 58 | protected: | ||
1230 | 59 | const gchar* GetName(); | ||
1231 | 60 | void AddProperties(GVariantBuilder* builder); | ||
1232 | 61 | |||
1233 | 62 | private: | ||
1234 | 63 | void EnsureHud(); | ||
1235 | 64 | void SetupWindow(); | ||
1236 | 65 | void SetupHudView(); | ||
1237 | 66 | void SetupRelayoutCallbacks(); | ||
1238 | 67 | void RegisterUBusInterests(); | ||
1239 | 68 | |||
1240 | 69 | nux::Geometry GetIdealWindowGeometry(); | ||
1241 | 70 | void Relayout(GdkScreen*screen=NULL); | ||
1242 | 71 | |||
1243 | 72 | void OnMouseDownOutsideWindow(int x, int y, unsigned long bflags, unsigned long kflags); | ||
1244 | 73 | void OnScreenUngrabbed(); | ||
1245 | 74 | void OnExternalShowHud(GVariant* variant); | ||
1246 | 75 | void OnExternalHideHud(GVariant* variant); | ||
1247 | 76 | void OnActivateRequest(GVariant* variant); | ||
1248 | 77 | |||
1249 | 78 | void OnSearchChanged(std::string search_string); | ||
1250 | 79 | void OnSearchActivated(std::string search_string); | ||
1251 | 80 | void OnQueryActivated(Query::Ptr query); | ||
1252 | 81 | void OnQuerySelected(Query::Ptr query); | ||
1253 | 82 | |||
1254 | 83 | |||
1255 | 84 | private: | ||
1256 | 85 | void StartShowHideTimeline(); | ||
1257 | 86 | static gboolean OnViewShowHideFrame(Controller* self); | ||
1258 | 87 | |||
1259 | 88 | static void OnWindowConfigure(int width, int height, nux::Geometry& geo, void* data); | ||
1260 | 89 | |||
1261 | 90 | void OnQueriesFinished(Hud::Queries queries); | ||
1262 | 91 | |||
1263 | 92 | private: | ||
1264 | 93 | UBusManager ubus; | ||
1265 | 94 | Hud hud_service_; | ||
1266 | 95 | glib::SignalManager sig_manager_; | ||
1267 | 96 | nux::BaseWindow* window_; | ||
1268 | 97 | bool visible_; | ||
1269 | 98 | bool need_show_; | ||
1270 | 99 | |||
1271 | 100 | guint timeline_id_; | ||
1272 | 101 | float last_opacity_; | ||
1273 | 102 | gint64 start_time_; | ||
1274 | 103 | |||
1275 | 104 | View* view_; | ||
1276 | 105 | guint ensure_id_; | ||
1277 | 106 | |||
1278 | 107 | nux::Layout* layout_; | ||
1279 | 108 | }; | ||
1280 | 109 | |||
1281 | 110 | |||
1282 | 111 | } | ||
1283 | 112 | } | ||
1284 | 113 | #endif | ||
1285 | 0 | 114 | ||
1286 | === added file 'plugins/unityshell/src/HudIcon.cpp' | |||
1287 | --- plugins/unityshell/src/HudIcon.cpp 1970-01-01 00:00:00 +0000 | |||
1288 | +++ plugins/unityshell/src/HudIcon.cpp 2012-01-25 11:34:37 +0000 | |||
1289 | @@ -0,0 +1,91 @@ | |||
1290 | 1 | /* | ||
1291 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
1292 | 3 | * | ||
1293 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1294 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1295 | 6 | * published by the Free Software Foundation. | ||
1296 | 7 | * | ||
1297 | 8 | * This program is distributed in the hope that it will be useful, | ||
1298 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1299 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1300 | 11 | * GNU General Public License for more details. | ||
1301 | 12 | * | ||
1302 | 13 | * You should have received a copy of the GNU General Public License | ||
1303 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1304 | 15 | * | ||
1305 | 16 | * Authored by: Gord Allott <gord.allott@canonical.com> | ||
1306 | 17 | */ | ||
1307 | 18 | |||
1308 | 19 | |||
1309 | 20 | #include "HudIcon.h" | ||
1310 | 21 | |||
1311 | 22 | //FIXME - we should be using the LauncherRenderer method of rendering icons here instead of compositing ourself | ||
1312 | 23 | // to make sure we get the correct average background colour and running indicator | ||
1313 | 24 | |||
1314 | 25 | namespace unity | ||
1315 | 26 | { | ||
1316 | 27 | namespace hud | ||
1317 | 28 | { | ||
1318 | 29 | |||
1319 | 30 | Icon::Icon(nux::BaseTexture* texture, guint width, guint height) | ||
1320 | 31 | : unity::IconTexture(texture, width, height) | ||
1321 | 32 | { | ||
1322 | 33 | Init(); | ||
1323 | 34 | } | ||
1324 | 35 | |||
1325 | 36 | Icon::Icon(const char* icon_name, unsigned int size, bool defer_icon_loading) | ||
1326 | 37 | : unity::IconTexture(icon_name, size, defer_icon_loading) | ||
1327 | 38 | { | ||
1328 | 39 | Init(); | ||
1329 | 40 | } | ||
1330 | 41 | |||
1331 | 42 | Icon::~Icon() | ||
1332 | 43 | { | ||
1333 | 44 | } | ||
1334 | 45 | |||
1335 | 46 | void Icon::Init() | ||
1336 | 47 | { | ||
1337 | 48 | SetMinimumWidth(54); | ||
1338 | 49 | SetMinimumHeight(54); | ||
1339 | 50 | background_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_back_54.png", -1, true); | ||
1340 | 51 | gloss_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_shine_54.png", -1, true); | ||
1341 | 52 | edge_ = nux::CreateTexture2DFromFile(PKGDATADIR"/launcher_icon_edge_54.png", -1, true); | ||
1342 | 53 | } | ||
1343 | 54 | |||
1344 | 55 | void Icon::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) | ||
1345 | 56 | { | ||
1346 | 57 | nux::Geometry geo = GetGeometry(); | ||
1347 | 58 | // set up our texture mode | ||
1348 | 59 | nux::TexCoordXForm texxform; | ||
1349 | 60 | |||
1350 | 61 | GfxContext.QRP_1Tex(geo.x, | ||
1351 | 62 | geo.y, | ||
1352 | 63 | background_->GetWidth(), | ||
1353 | 64 | background_->GetHeight(), | ||
1354 | 65 | background_->GetDeviceTexture(), | ||
1355 | 66 | texxform, | ||
1356 | 67 | nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); | ||
1357 | 68 | |||
1358 | 69 | GfxContext.QRP_1Tex(geo.x, | ||
1359 | 70 | geo.y, | ||
1360 | 71 | gloss_->GetWidth(), | ||
1361 | 72 | gloss_->GetHeight(), | ||
1362 | 73 | gloss_->GetDeviceTexture(), | ||
1363 | 74 | texxform, | ||
1364 | 75 | nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); | ||
1365 | 76 | |||
1366 | 77 | GfxContext.QRP_1Tex(geo.x, | ||
1367 | 78 | geo.y, | ||
1368 | 79 | edge_->GetWidth(), | ||
1369 | 80 | edge_->GetHeight(), | ||
1370 | 81 | edge_->GetDeviceTexture(), | ||
1371 | 82 | texxform, | ||
1372 | 83 | nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); | ||
1373 | 84 | |||
1374 | 85 | unity::IconTexture::Draw(GfxContext, force_draw); | ||
1375 | 86 | } | ||
1376 | 87 | |||
1377 | 88 | |||
1378 | 89 | } | ||
1379 | 90 | } | ||
1380 | 91 | |||
1381 | 0 | 92 | ||
1382 | === added file 'plugins/unityshell/src/HudIcon.h' | |||
1383 | --- plugins/unityshell/src/HudIcon.h 1970-01-01 00:00:00 +0000 | |||
1384 | +++ plugins/unityshell/src/HudIcon.h 2012-01-25 11:34:37 +0000 | |||
1385 | @@ -0,0 +1,69 @@ | |||
1386 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1387 | 2 | /* | ||
1388 | 3 | * Copyright (C) 2010 Canonical Ltd | ||
1389 | 4 | * | ||
1390 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1391 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1392 | 7 | * published by the Free Software Foundation. | ||
1393 | 8 | * | ||
1394 | 9 | * This program is distributed in the hope that it will be useful, | ||
1395 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1396 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1397 | 12 | * GNU General Public License for more details. | ||
1398 | 13 | * | ||
1399 | 14 | * You should have received a copy of the GNU General Public License | ||
1400 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1401 | 16 | * | ||
1402 | 17 | * Authored by: Gord Allott <gord.allott@canonical.com> | ||
1403 | 18 | * | ||
1404 | 19 | */ | ||
1405 | 20 | |||
1406 | 21 | #ifndef HUDICON_H | ||
1407 | 22 | #define HUDICON_H | ||
1408 | 23 | |||
1409 | 24 | #include <set> | ||
1410 | 25 | #include <string> | ||
1411 | 26 | |||
1412 | 27 | #include "config.h" | ||
1413 | 28 | |||
1414 | 29 | #include <Nux/Nux.h> | ||
1415 | 30 | #include <Nux/BaseWindow.h> | ||
1416 | 31 | #include <NuxCore/Math/MathInc.h> | ||
1417 | 32 | |||
1418 | 33 | #include <sigc++/trackable.h> | ||
1419 | 34 | #include <sigc++/signal.h> | ||
1420 | 35 | #include <sigc++/functors/ptr_fun.h> | ||
1421 | 36 | #include <sigc++/functors/mem_fun.h> | ||
1422 | 37 | |||
1423 | 38 | #include <gtk/gtk.h> | ||
1424 | 39 | |||
1425 | 40 | #include "IconTexture.h" | ||
1426 | 41 | #include "Introspectable.h" | ||
1427 | 42 | |||
1428 | 43 | namespace unity | ||
1429 | 44 | { | ||
1430 | 45 | namespace hud | ||
1431 | 46 | { | ||
1432 | 47 | |||
1433 | 48 | class Icon : public unity::IconTexture | ||
1434 | 49 | { | ||
1435 | 50 | public: | ||
1436 | 51 | typedef nux::ObjectPtr<IconTexture> Ptr; | ||
1437 | 52 | Icon(nux::BaseTexture* texture, guint width, guint height); | ||
1438 | 53 | Icon(const char* icon_name, unsigned int size, bool defer_icon_loading = false); | ||
1439 | 54 | ~Icon(); | ||
1440 | 55 | |||
1441 | 56 | protected: | ||
1442 | 57 | void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); | ||
1443 | 58 | void Init(); | ||
1444 | 59 | |||
1445 | 60 | nux::ObjectPtr<nux::BaseTexture> background_; | ||
1446 | 61 | nux::ObjectPtr<nux::BaseTexture> gloss_; | ||
1447 | 62 | nux::ObjectPtr<nux::BaseTexture> edge_; | ||
1448 | 63 | }; | ||
1449 | 64 | |||
1450 | 65 | } | ||
1451 | 66 | |||
1452 | 67 | } | ||
1453 | 68 | |||
1454 | 69 | #endif /* HUDICON_H */ | ||
1455 | 0 | 70 | ||
1456 | === added file 'plugins/unityshell/src/HudSearchBar.cpp' | |||
1457 | --- plugins/unityshell/src/HudSearchBar.cpp 1970-01-01 00:00:00 +0000 | |||
1458 | +++ plugins/unityshell/src/HudSearchBar.cpp 2012-01-25 11:34:37 +0000 | |||
1459 | @@ -0,0 +1,404 @@ | |||
1460 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1461 | 2 | /* | ||
1462 | 3 | * Copyright (C) 2010-2011 Canonical Ltd | ||
1463 | 4 | * | ||
1464 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1465 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1466 | 7 | * published by the Free Software Foundation. | ||
1467 | 8 | * | ||
1468 | 9 | * This program is distributed in the hope that it will be useful, | ||
1469 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1470 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1471 | 12 | * GNU General Public License for more detais. | ||
1472 | 13 | * | ||
1473 | 14 | * You shoud have received a copy of the GNU General Public License | ||
1474 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1475 | 16 | * | ||
1476 | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
1477 | 18 | */ | ||
1478 | 19 | |||
1479 | 20 | /* FIXME!! - port this to the DashSearchBar and rename both to SearchBar */ | ||
1480 | 21 | |||
1481 | 22 | #include "config.h" | ||
1482 | 23 | |||
1483 | 24 | #include <Nux/Nux.h> | ||
1484 | 25 | #include <Nux/BaseWindow.h> | ||
1485 | 26 | #include <Nux/HLayout.h> | ||
1486 | 27 | #include <Nux/Layout.h> | ||
1487 | 28 | #include <Nux/WindowCompositor.h> | ||
1488 | 29 | |||
1489 | 30 | #include <NuxImage/CairoGraphics.h> | ||
1490 | 31 | #include <NuxImage/ImageSurface.h> | ||
1491 | 32 | #include <Nux/StaticText.h> | ||
1492 | 33 | |||
1493 | 34 | #include <NuxGraphics/GLThread.h> | ||
1494 | 35 | #include <NuxGraphics/RenderingPipe.h> | ||
1495 | 36 | |||
1496 | 37 | #include <glib.h> | ||
1497 | 38 | #include <glib/gi18n-lib.h> | ||
1498 | 39 | |||
1499 | 40 | #include "HudSearchBar.h" | ||
1500 | 41 | #include <UnityCore/Variant.h> | ||
1501 | 42 | |||
1502 | 43 | #include "DashStyle.h" | ||
1503 | 44 | |||
1504 | 45 | #define LIVE_SEARCH_TIMEOUT 250 | ||
1505 | 46 | // Create a texture from the CairoGraphics object. | ||
1506 | 47 | // | ||
1507 | 48 | // Returns a new BaseTexture that has a ref count of 1. | ||
1508 | 49 | static nux::BaseTexture* texture_from_cairo_graphics(nux::CairoGraphics& cg) | ||
1509 | 50 | { | ||
1510 | 51 | nux::NBitmapData* bitmap = cg.GetBitmap(); | ||
1511 | 52 | nux::BaseTexture* tex = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture(); | ||
1512 | 53 | tex->Update(bitmap); | ||
1513 | 54 | delete bitmap; | ||
1514 | 55 | return tex; | ||
1515 | 56 | } | ||
1516 | 57 | |||
1517 | 58 | namespace unity | ||
1518 | 59 | { | ||
1519 | 60 | namespace hud | ||
1520 | 61 | { | ||
1521 | 62 | |||
1522 | 63 | NUX_IMPLEMENT_OBJECT_TYPE(SearchBar); | ||
1523 | 64 | |||
1524 | 65 | SearchBar::SearchBar(NUX_FILE_LINE_DECL) | ||
1525 | 66 | : View(NUX_FILE_LINE_PARAM) | ||
1526 | 67 | , search_hint("") | ||
1527 | 68 | , showing_filters(false) | ||
1528 | 69 | , can_refine_search(false) | ||
1529 | 70 | , live_search_timeout_(0) | ||
1530 | 71 | { | ||
1531 | 72 | nux::BaseTexture* icon = dash::Style::Instance().GetSearchMagnifyIcon(); | ||
1532 | 73 | |||
1533 | 74 | bg_layer_ = new nux::ColorLayer(nux::Color(0xff595853), true); | ||
1534 | 75 | |||
1535 | 76 | layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); | ||
1536 | 77 | layout_->SetHorizontalInternalMargin(0); | ||
1537 | 78 | layout_->SetVerticalExternalMargin(8); | ||
1538 | 79 | layout_->SetHorizontalExternalMargin(10); | ||
1539 | 80 | SetLayout(layout_); | ||
1540 | 81 | |||
1541 | 82 | spinner_ = new dash::SearchBarSpinner(); | ||
1542 | 83 | spinner_->SetMinMaxSize(icon->GetWidth(), icon->GetHeight()); | ||
1543 | 84 | spinner_->mouse_click.connect(sigc::mem_fun(this, &SearchBar::OnClearClicked)); | ||
1544 | 85 | layout_->AddView(spinner_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); | ||
1545 | 86 | |||
1546 | 87 | hint_ = new nux::StaticCairoText(" "); | ||
1547 | 88 | hint_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 0.5f)); | ||
1548 | 89 | hint_->SetMaximumWidth(570); | ||
1549 | 90 | |||
1550 | 91 | pango_entry_ = new dash::IMTextEntry(); | ||
1551 | 92 | pango_entry_->sigTextChanged.connect(sigc::mem_fun(this, &SearchBar::OnSearchChanged)); | ||
1552 | 93 | pango_entry_->activated.connect([&]() { activated.emit(); }); | ||
1553 | 94 | pango_entry_->cursor_moved.connect([&](int i) { QueueDraw(); }); | ||
1554 | 95 | pango_entry_->mouse_down.connect(sigc::mem_fun(this, &SearchBar::OnMouseButtonDown)); | ||
1555 | 96 | pango_entry_->end_key_focus.connect(sigc::mem_fun(this, &SearchBar::OnEndKeyFocus)); | ||
1556 | 97 | pango_entry_->SetMaximumWidth(570); | ||
1557 | 98 | |||
1558 | 99 | layered_layout_ = new nux::LayeredLayout(); | ||
1559 | 100 | layered_layout_->AddLayer(hint_); | ||
1560 | 101 | layered_layout_->AddLayer(pango_entry_); | ||
1561 | 102 | layered_layout_->SetPaintAll(true); | ||
1562 | 103 | layered_layout_->SetActiveLayerN(1); | ||
1563 | 104 | layered_layout_->SetMinimumWidth(420); | ||
1564 | 105 | layered_layout_->SetMaximumWidth(645); | ||
1565 | 106 | layout_->AddView(layered_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX); | ||
1566 | 107 | |||
1567 | 108 | std::string filter_str = _("Filter results"); | ||
1568 | 109 | filter_str+= " ▸"; | ||
1569 | 110 | show_filters_ = new nux::StaticCairoText(filter_str.c_str()); | ||
1570 | 111 | show_filters_->SetVisible(false); | ||
1571 | 112 | show_filters_->SetTextColor(nux::Color(1.0f, 1.0f, 1.0f, 1.0f)); | ||
1572 | 113 | show_filters_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT); | ||
1573 | 114 | show_filters_->mouse_click.connect([&] (int x, int y, unsigned long b, unsigned long k) { showing_filters = !showing_filters; }); | ||
1574 | 115 | |||
1575 | 116 | nux::Layout *filter_layout = new nux::HLayout(); | ||
1576 | 117 | filter_layout->SetHorizontalExternalMargin(12); | ||
1577 | 118 | filter_layout->AddLayout(new nux::SpaceLayout(0, 10000, 0, 1), 1); | ||
1578 | 119 | filter_layout->AddView(show_filters_, 0, nux::MINOR_POSITION_RIGHT); | ||
1579 | 120 | |||
1580 | 121 | layout_->AddView(filter_layout, 1, nux::MINOR_POSITION_RIGHT, nux::MINOR_SIZE_FIX); | ||
1581 | 122 | |||
1582 | 123 | sig_manager_.Add(new Signal<void, GtkSettings*, GParamSpec*> | ||
1583 | 124 | (gtk_settings_get_default(), | ||
1584 | 125 | "notify::gtk-font-name", | ||
1585 | 126 | sigc::mem_fun(this, &SearchBar::OnFontChanged))); | ||
1586 | 127 | OnFontChanged(gtk_settings_get_default()); | ||
1587 | 128 | |||
1588 | 129 | search_hint.changed.connect([&](std::string const& s) { OnSearchHintChanged(); }); | ||
1589 | 130 | search_string.SetGetterFunction(sigc::mem_fun(this, &SearchBar::get_search_string)); | ||
1590 | 131 | search_string.SetSetterFunction(sigc::mem_fun(this, &SearchBar::set_search_string)); | ||
1591 | 132 | im_active.SetGetterFunction(sigc::mem_fun(this, &SearchBar::get_im_active)); | ||
1592 | 133 | showing_filters.changed.connect(sigc::mem_fun(this, &SearchBar::OnShowingFiltersChanged)); | ||
1593 | 134 | can_refine_search.changed.connect([&] (bool can_refine) { show_filters_->SetVisible(can_refine); }); | ||
1594 | 135 | } | ||
1595 | 136 | |||
1596 | 137 | SearchBar::~SearchBar() | ||
1597 | 138 | { | ||
1598 | 139 | delete bg_layer_; | ||
1599 | 140 | |||
1600 | 141 | if (live_search_timeout_) | ||
1601 | 142 | g_source_remove(live_search_timeout_); | ||
1602 | 143 | } | ||
1603 | 144 | |||
1604 | 145 | void SearchBar::OnFontChanged(GtkSettings* settings, GParamSpec* pspec) | ||
1605 | 146 | { | ||
1606 | 147 | static const int HOW_LARGE = 8; | ||
1607 | 148 | gchar* font_name = NULL; | ||
1608 | 149 | PangoFontDescription* desc; | ||
1609 | 150 | gint size; | ||
1610 | 151 | gchar* font_desc; | ||
1611 | 152 | |||
1612 | 153 | g_object_get(settings, "gtk-font-name", &font_name, NULL); | ||
1613 | 154 | |||
1614 | 155 | desc = pango_font_description_from_string(font_name); | ||
1615 | 156 | pango_entry_->SetFontFamily(pango_font_description_get_family(desc)); | ||
1616 | 157 | |||
1617 | 158 | size = pango_font_description_get_size(desc); | ||
1618 | 159 | size /= pango_font_description_get_size_is_absolute(desc) ? 1 : PANGO_SCALE; | ||
1619 | 160 | pango_entry_->SetFontSize(size + HOW_LARGE); | ||
1620 | 161 | |||
1621 | 162 | pango_entry_->SetFontOptions(gdk_screen_get_font_options(gdk_screen_get_default())); | ||
1622 | 163 | |||
1623 | 164 | font_desc = g_strdup_printf("%s %d", pango_font_description_get_family(desc), size + HOW_LARGE); | ||
1624 | 165 | hint_->SetFont(font_desc); | ||
1625 | 166 | |||
1626 | 167 | g_free(font_desc); | ||
1627 | 168 | font_desc = g_strdup_printf("%s %d", pango_font_description_get_family(desc), size + HOW_LARGE/2); | ||
1628 | 169 | show_filters_->SetFont(font_desc); | ||
1629 | 170 | |||
1630 | 171 | pango_font_description_free(desc); | ||
1631 | 172 | g_free(font_name); | ||
1632 | 173 | g_free(font_desc); | ||
1633 | 174 | } | ||
1634 | 175 | |||
1635 | 176 | void SearchBar::OnSearchHintChanged() | ||
1636 | 177 | { | ||
1637 | 178 | std::string hint = search_hint; | ||
1638 | 179 | gchar* tmp = g_markup_escape_text(hint.c_str(), -1); | ||
1639 | 180 | |||
1640 | 181 | gchar* markup = g_strdup_printf("%s", tmp); | ||
1641 | 182 | hint_->SetText(markup); | ||
1642 | 183 | |||
1643 | 184 | g_free(markup); | ||
1644 | 185 | g_free(tmp); | ||
1645 | 186 | } | ||
1646 | 187 | |||
1647 | 188 | void SearchBar::OnSearchChanged(nux::TextEntry* text_entry) | ||
1648 | 189 | { | ||
1649 | 190 | // We don't want to set a new search string on every new character, so we add a sma | ||
1650 | 191 | // timeout to see if the user is typing a sentence. If more characters are added, we | ||
1651 | 192 | // keep restarting the timeout unti the user has actuay paused. | ||
1652 | 193 | if (live_search_timeout_) | ||
1653 | 194 | g_source_remove(live_search_timeout_); | ||
1654 | 195 | |||
1655 | 196 | live_search_timeout_ = g_timeout_add(LIVE_SEARCH_TIMEOUT, | ||
1656 | 197 | (GSourceFunc)&OnLiveSearchTimeout, | ||
1657 | 198 | this); | ||
1658 | 199 | |||
1659 | 200 | //spinner_->SetState(is_empty ? unity::dash::STATE_READY : unity::dash::STATE_SEARCHING); | ||
1660 | 201 | |||
1661 | 202 | pango_entry_->QueueDraw(); | ||
1662 | 203 | hint_->QueueDraw(); | ||
1663 | 204 | QueueDraw(); | ||
1664 | 205 | |||
1665 | 206 | search_changed.emit(pango_entry_->GetText()); | ||
1666 | 207 | } | ||
1667 | 208 | |||
1668 | 209 | gboolean SearchBar::OnLiveSearchTimeout(SearchBar* sef) | ||
1669 | 210 | { | ||
1670 | 211 | sef->live_search_reached.emit(sef->pango_entry_->GetText()); | ||
1671 | 212 | sef->live_search_timeout_ = 0; | ||
1672 | 213 | return FALSE; | ||
1673 | 214 | } | ||
1674 | 215 | |||
1675 | 216 | void SearchBar::OnShowingFiltersChanged(bool is_showing) | ||
1676 | 217 | { | ||
1677 | 218 | std::string filter_str = _("Filter results"); | ||
1678 | 219 | filter_str += " <small>"; | ||
1679 | 220 | filter_str += is_showing ? "▾" : "▸"; | ||
1680 | 221 | filter_str += "</small>"; | ||
1681 | 222 | show_filters_->SetText(filter_str.c_str()); | ||
1682 | 223 | } | ||
1683 | 224 | |||
1684 | 225 | void SearchBar::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) | ||
1685 | 226 | { | ||
1686 | 227 | nux::Geometry geo = GetGeometry(); | ||
1687 | 228 | |||
1688 | 229 | UpdateBackground(); | ||
1689 | 230 | GfxContext.PushClippingRectangle(geo); | ||
1690 | 231 | |||
1691 | 232 | nux::GetPainter().PaintBackground(GfxContext, geo); | ||
1692 | 233 | |||
1693 | 234 | bg_layer_->SetGeometry(nux::Geometry(geo.x, geo.y, last_width_, geo.height)); | ||
1694 | 235 | nux::GetPainter().RenderSinglePaintLayer(GfxContext, | ||
1695 | 236 | bg_layer_->GetGeometry(), | ||
1696 | 237 | bg_layer_); | ||
1697 | 238 | |||
1698 | 239 | GfxContext.PopClippingRectangle(); | ||
1699 | 240 | } | ||
1700 | 241 | |||
1701 | 242 | void SearchBar::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) | ||
1702 | 243 | { | ||
1703 | 244 | nux::Geometry geo = GetGeometry(); | ||
1704 | 245 | |||
1705 | 246 | GfxContext.PushClippingRectangle(geo); | ||
1706 | 247 | |||
1707 | 248 | if (!IsFullRedraw()) | ||
1708 | 249 | gPainter.PushLayer(GfxContext, bg_layer_->GetGeometry(), bg_layer_); | ||
1709 | 250 | |||
1710 | 251 | layout_->ProcessDraw(GfxContext, force_draw); | ||
1711 | 252 | |||
1712 | 253 | if (!IsFullRedraw()) | ||
1713 | 254 | gPainter.PopBackground(); | ||
1714 | 255 | GfxContext.PopClippingRectangle(); | ||
1715 | 256 | } | ||
1716 | 257 | |||
1717 | 258 | void SearchBar::OnClearClicked(int x, int y, unsigned long button_fags, | ||
1718 | 259 | unsigned long key_fags) | ||
1719 | 260 | { | ||
1720 | 261 | pango_entry_->SetText(""); | ||
1721 | 262 | spinner_->SetState(unity::dash::STATE_READY); | ||
1722 | 263 | live_search_reached.emit(""); | ||
1723 | 264 | } | ||
1724 | 265 | |||
1725 | 266 | void SearchBar::OnEntryActivated() | ||
1726 | 267 | { | ||
1727 | 268 | activated.emit(); | ||
1728 | 269 | } | ||
1729 | 270 | |||
1730 | 271 | void | ||
1731 | 272 | SearchBar::SearchFinished() | ||
1732 | 273 | { | ||
1733 | 274 | spinner_->SetState(unity::dash::STATE_CLEAR); | ||
1734 | 275 | } | ||
1735 | 276 | |||
1736 | 277 | void SearchBar::UpdateBackground() | ||
1737 | 278 | { | ||
1738 | 279 | #define PADDING 12 | ||
1739 | 280 | #define RADIUS 5 | ||
1740 | 281 | int x, y, width, height; | ||
1741 | 282 | nux::Geometry geo = GetGeometry(); | ||
1742 | 283 | geo.width = layered_layout_->GetGeometry().width; | ||
1743 | 284 | |||
1744 | 285 | if (geo.width == last_width_ && geo.height == last_height_) | ||
1745 | 286 | return; | ||
1746 | 287 | |||
1747 | 288 | last_width_ = geo.width; | ||
1748 | 289 | last_height_ = geo.height; | ||
1749 | 290 | |||
1750 | 291 | x = y = PADDING; | ||
1751 | 292 | width = last_width_ - (2 * PADDING); | ||
1752 | 293 | height = last_height_ - (2 * PADDING); | ||
1753 | 294 | |||
1754 | 295 | nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, last_width_, last_height_); | ||
1755 | 296 | cairo_t* cr = cairo_graphics.GetContext(); | ||
1756 | 297 | |||
1757 | 298 | cairo_graphics.DrawRoundedRectangle(cr, | ||
1758 | 299 | 1.0f, | ||
1759 | 300 | x, | ||
1760 | 301 | y, | ||
1761 | 302 | RADIUS, | ||
1762 | 303 | width, | ||
1763 | 304 | height, | ||
1764 | 305 | true); | ||
1765 | 306 | |||
1766 | 307 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); | ||
1767 | 308 | cairo_set_line_width(cr, 1.0); | ||
1768 | 309 | cairo_stroke_preserve(cr); | ||
1769 | 310 | cairo_graphics.BlurSurface (3, cairo_get_target (cr)); | ||
1770 | 311 | |||
1771 | 312 | cairo_operator_t op = CAIRO_OPERATOR_OVER; | ||
1772 | 313 | op = cairo_get_operator (cr); | ||
1773 | 314 | cairo_set_operator (cr, CAIRO_OPERATOR_OVER); | ||
1774 | 315 | cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.5f); | ||
1775 | 316 | cairo_fill_preserve(cr); | ||
1776 | 317 | cairo_set_operator (cr, op); | ||
1777 | 318 | cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.5f); | ||
1778 | 319 | cairo_fill_preserve(cr); | ||
1779 | 320 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 0.8f); | ||
1780 | 321 | //cairo_set_line_width(cr, 1.0); | ||
1781 | 322 | cairo_stroke(cr); | ||
1782 | 323 | |||
1783 | 324 | cairo_destroy(cr); | ||
1784 | 325 | nux::BaseTexture* texture2D = texture_from_cairo_graphics(cairo_graphics); | ||
1785 | 326 | |||
1786 | 327 | nux::TexCoordXForm texxform; | ||
1787 | 328 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); | ||
1788 | 329 | texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT); | ||
1789 | 330 | if (bg_layer_) | ||
1790 | 331 | delete bg_layer_; | ||
1791 | 332 | |||
1792 | 333 | nux::ROPConfig rop; | ||
1793 | 334 | rop.Blend = true; | ||
1794 | 335 | rop.SrcBlend = GL_ONE; | ||
1795 | 336 | rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; | ||
1796 | 337 | |||
1797 | 338 | bg_layer_ = new nux::TextureLayer(texture2D->GetDeviceTexture(), | ||
1798 | 339 | texxform, | ||
1799 | 340 | nux::color::White, | ||
1800 | 341 | true, | ||
1801 | 342 | rop); | ||
1802 | 343 | |||
1803 | 344 | texture2D->UnReference(); | ||
1804 | 345 | } | ||
1805 | 346 | |||
1806 | 347 | void SearchBar::OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key) | ||
1807 | 348 | { | ||
1808 | 349 | search_hint = ""; | ||
1809 | 350 | } | ||
1810 | 351 | |||
1811 | 352 | void SearchBar::OnEndKeyFocus() | ||
1812 | 353 | { | ||
1813 | 354 | //search_hint = _("Search"); | ||
1814 | 355 | } | ||
1815 | 356 | |||
1816 | 357 | nux::TextEntry* SearchBar::text_entry() const | ||
1817 | 358 | { | ||
1818 | 359 | return pango_entry_; | ||
1819 | 360 | } | ||
1820 | 361 | |||
1821 | 362 | std::string SearchBar::get_search_string() const | ||
1822 | 363 | { | ||
1823 | 364 | return pango_entry_->GetText(); | ||
1824 | 365 | } | ||
1825 | 366 | |||
1826 | 367 | bool SearchBar::set_search_string(std::string const& string) | ||
1827 | 368 | { | ||
1828 | 369 | pango_entry_->SetText(string.c_str()); | ||
1829 | 370 | spinner_->SetState(string == "" ? unity::dash::STATE_READY : unity::dash::STATE_CLEAR); | ||
1830 | 371 | return true; | ||
1831 | 372 | } | ||
1832 | 373 | |||
1833 | 374 | bool SearchBar::get_im_active() const | ||
1834 | 375 | { | ||
1835 | 376 | return pango_entry_->im_active(); | ||
1836 | 377 | } | ||
1837 | 378 | |||
1838 | 379 | // | ||
1839 | 380 | // Key navigation | ||
1840 | 381 | // | ||
1841 | 382 | bool | ||
1842 | 383 | SearchBar::AcceptKeyNavFocus() | ||
1843 | 384 | { | ||
1844 | 385 | return false; | ||
1845 | 386 | } | ||
1846 | 387 | |||
1847 | 388 | const gchar* SearchBar::GetName() | ||
1848 | 389 | { | ||
1849 | 390 | return "SearchBar"; | ||
1850 | 391 | } | ||
1851 | 392 | |||
1852 | 393 | const gchar* SearchBar::GetChildsName() | ||
1853 | 394 | { | ||
1854 | 395 | return ""; | ||
1855 | 396 | } | ||
1856 | 397 | |||
1857 | 398 | void SearchBar::AddProperties(GVariantBuilder* builder) | ||
1858 | 399 | { | ||
1859 | 400 | unity::variant::BuilderWrapper(builder).add(GetGeometry()); | ||
1860 | 401 | } | ||
1861 | 402 | |||
1862 | 403 | } | ||
1863 | 404 | } | ||
1864 | 0 | 405 | ||
1865 | === added file 'plugins/unityshell/src/HudSearchBar.h' | |||
1866 | --- plugins/unityshell/src/HudSearchBar.h 1970-01-01 00:00:00 +0000 | |||
1867 | +++ plugins/unityshell/src/HudSearchBar.h 2012-01-25 11:34:37 +0000 | |||
1868 | @@ -0,0 +1,116 @@ | |||
1869 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
1870 | 2 | /* | ||
1871 | 3 | * Copyright (C) 2010 Canonical Ltd | ||
1872 | 4 | * | ||
1873 | 5 | * This program is free software: you can redistribute it and/or modify | ||
1874 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
1875 | 7 | * published by the Free Software Foundation. | ||
1876 | 8 | * | ||
1877 | 9 | * This program is distributed in the hope that it will be useful, | ||
1878 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1879 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1880 | 12 | * GNU General Public License for more details. | ||
1881 | 13 | * | ||
1882 | 14 | * You should have received a copy of the GNU General Public License | ||
1883 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1884 | 16 | * | ||
1885 | 17 | * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> | ||
1886 | 18 | */ | ||
1887 | 19 | |||
1888 | 20 | #ifndef HUD_SEARCH_BAR_H | ||
1889 | 21 | #define HUD_SEARCH_BAR_H | ||
1890 | 22 | |||
1891 | 23 | #include <gtk/gtk.h> | ||
1892 | 24 | |||
1893 | 25 | #include <NuxCore/Property.h> | ||
1894 | 26 | #include <Nux/LayeredLayout.h> | ||
1895 | 27 | #include <Nux/TextureArea.h> | ||
1896 | 28 | #include <Nux/View.h> | ||
1897 | 29 | #include <Nux/TextureArea.h> | ||
1898 | 30 | #include <NuxGraphics/GraphicsEngine.h> | ||
1899 | 31 | #include <Nux/EditTextBox.h> | ||
1900 | 32 | #include <Nux/TextEntry.h> | ||
1901 | 33 | #include <UnityCore/GLibSignal.h> | ||
1902 | 34 | |||
1903 | 35 | #include "DashSearchBarSpinner.h" | ||
1904 | 36 | #include "IMTextEntry.h" | ||
1905 | 37 | #include "StaticCairoText.h" | ||
1906 | 38 | |||
1907 | 39 | namespace unity | ||
1908 | 40 | { | ||
1909 | 41 | namespace hud | ||
1910 | 42 | { | ||
1911 | 43 | |||
1912 | 44 | using namespace unity::glib; | ||
1913 | 45 | |||
1914 | 46 | class SearchBar : public nux::View | ||
1915 | 47 | { | ||
1916 | 48 | NUX_DECLARE_OBJECT_TYPE(SearchBar, nux::View); | ||
1917 | 49 | typedef nux::ObjectPtr<SearchBar> Ptr; | ||
1918 | 50 | public: | ||
1919 | 51 | SearchBar(NUX_FILE_LINE_PROTO); | ||
1920 | 52 | ~SearchBar(); | ||
1921 | 53 | |||
1922 | 54 | void SearchFinished(); | ||
1923 | 55 | nux::TextEntry* text_entry() const; | ||
1924 | 56 | |||
1925 | 57 | nux::RWProperty<std::string> search_string; | ||
1926 | 58 | nux::Property<std::string> search_hint; | ||
1927 | 59 | nux::Property<bool> showing_filters; | ||
1928 | 60 | nux::Property<bool> can_refine_search; | ||
1929 | 61 | nux::ROProperty<bool> im_active; | ||
1930 | 62 | |||
1931 | 63 | sigc::signal<void> activated; | ||
1932 | 64 | sigc::signal<void, std::string const&> search_changed; | ||
1933 | 65 | sigc::signal<void, std::string const&> live_search_reached; | ||
1934 | 66 | |||
1935 | 67 | private: | ||
1936 | 68 | |||
1937 | 69 | void OnFontChanged(GtkSettings* settings, GParamSpec* pspec=NULL); | ||
1938 | 70 | void OnSearchHintChanged(); | ||
1939 | 71 | |||
1940 | 72 | void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); | ||
1941 | 73 | void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); | ||
1942 | 74 | |||
1943 | 75 | void OnMouseButtonDown(int x, int y, unsigned long button_flags, unsigned long key_flags); | ||
1944 | 76 | void OnEndKeyFocus(); | ||
1945 | 77 | |||
1946 | 78 | void UpdateBackground(); | ||
1947 | 79 | void OnSearchChanged(nux::TextEntry* text_entry); | ||
1948 | 80 | void OnClearClicked(int x, int y, unsigned long button_flags, unsigned long key_flags); | ||
1949 | 81 | void OnEntryActivated(); | ||
1950 | 82 | void OnShowingFiltersChanged(bool is_showing); | ||
1951 | 83 | |||
1952 | 84 | std::string get_search_string() const; | ||
1953 | 85 | bool set_search_string(std::string const& string); | ||
1954 | 86 | bool get_im_active() const; | ||
1955 | 87 | |||
1956 | 88 | static gboolean OnLiveSearchTimeout(SearchBar* self); | ||
1957 | 89 | |||
1958 | 90 | const gchar* GetName(); | ||
1959 | 91 | const gchar* GetChildsName(); | ||
1960 | 92 | void AddProperties(GVariantBuilder* builder); | ||
1961 | 93 | bool AcceptKeyNavFocus(); | ||
1962 | 94 | |||
1963 | 95 | private: | ||
1964 | 96 | glib::SignalManager sig_manager_; | ||
1965 | 97 | |||
1966 | 98 | nux::AbstractPaintLayer* bg_layer_; | ||
1967 | 99 | nux::HLayout* layout_; | ||
1968 | 100 | nux::LayeredLayout* layered_layout_; | ||
1969 | 101 | nux::StaticCairoText* hint_; | ||
1970 | 102 | unity::dash::IMTextEntry* pango_entry_; | ||
1971 | 103 | nux::StaticCairoText* show_filters_; | ||
1972 | 104 | |||
1973 | 105 | int last_width_; | ||
1974 | 106 | int last_height_; | ||
1975 | 107 | |||
1976 | 108 | guint live_search_timeout_; | ||
1977 | 109 | |||
1978 | 110 | unity::dash::SearchBarSpinner* spinner_; | ||
1979 | 111 | }; | ||
1980 | 112 | |||
1981 | 113 | } | ||
1982 | 114 | } | ||
1983 | 115 | |||
1984 | 116 | #endif | ||
1985 | 0 | 117 | ||
1986 | === added file 'plugins/unityshell/src/HudView.cpp' | |||
1987 | --- plugins/unityshell/src/HudView.cpp 1970-01-01 00:00:00 +0000 | |||
1988 | +++ plugins/unityshell/src/HudView.cpp 2012-01-25 11:34:37 +0000 | |||
1989 | @@ -0,0 +1,377 @@ | |||
1990 | 1 | /* | ||
1991 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
1992 | 3 | * | ||
1993 | 4 | * This program is free software: you can redistribute it and/or modify | ||
1994 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
1995 | 6 | * published by the Free Software Foundation. | ||
1996 | 7 | * | ||
1997 | 8 | * This program is distributed in the hope that it will be useful, | ||
1998 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1999 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2000 | 11 | * GNU General Public License for more details. | ||
2001 | 12 | * | ||
2002 | 13 | * You should have received a copy of the GNU General Public License | ||
2003 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2004 | 15 | * | ||
2005 | 16 | * Authored by: Gord Allott <gord.allott@canonical.com> | ||
2006 | 17 | */ | ||
2007 | 18 | |||
2008 | 19 | #include "HudView.h" | ||
2009 | 20 | |||
2010 | 21 | #include <math.h> | ||
2011 | 22 | |||
2012 | 23 | #include <gio/gdesktopappinfo.h> | ||
2013 | 24 | #include <glib/gi18n-lib.h> | ||
2014 | 25 | #include <gtk/gtk.h> | ||
2015 | 26 | #include <Nux/Button.h> | ||
2016 | 27 | #include <iostream> | ||
2017 | 28 | #include <sstream> | ||
2018 | 29 | |||
2019 | 30 | #include <NuxCore/Logger.h> | ||
2020 | 31 | #include <UnityCore/GLibWrapper.h> | ||
2021 | 32 | #include <UnityCore/RadioOptionFilter.h> | ||
2022 | 33 | #include <Nux/HLayout.h> | ||
2023 | 34 | #include <Nux/LayeredLayout.h> | ||
2024 | 35 | |||
2025 | 36 | #include <NuxCore/Logger.h> | ||
2026 | 37 | #include "HudButton.h" | ||
2027 | 38 | #include "UBusMessages.h" | ||
2028 | 39 | #include "DashStyle.h" | ||
2029 | 40 | |||
2030 | 41 | namespace unity | ||
2031 | 42 | { | ||
2032 | 43 | namespace hud | ||
2033 | 44 | { | ||
2034 | 45 | |||
2035 | 46 | namespace | ||
2036 | 47 | { | ||
2037 | 48 | nux::logging::Logger logger("unity.hud.view"); | ||
2038 | 49 | int icon_size = 42; | ||
2039 | 50 | const std::string default_text = _("Type your command"); | ||
2040 | 51 | } | ||
2041 | 52 | |||
2042 | 53 | NUX_IMPLEMENT_OBJECT_TYPE(View); | ||
2043 | 54 | |||
2044 | 55 | View::View() | ||
2045 | 56 | : nux::View(NUX_TRACKER_LOCATION) | ||
2046 | 57 | , button_views_(NULL) | ||
2047 | 58 | { | ||
2048 | 59 | renderer_.SetOwner(this); | ||
2049 | 60 | renderer_.need_redraw.connect([this] () { | ||
2050 | 61 | QueueDraw(); | ||
2051 | 62 | }); | ||
2052 | 63 | |||
2053 | 64 | nux::ROPConfig rop; | ||
2054 | 65 | rop.Blend = true; | ||
2055 | 66 | rop.SrcBlend = GL_ONE; | ||
2056 | 67 | rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; | ||
2057 | 68 | |||
2058 | 69 | SetupViews(); | ||
2059 | 70 | search_bar_->key_down.connect (sigc::mem_fun (this, &View::OnKeyDown)); | ||
2060 | 71 | |||
2061 | 72 | search_bar_->activated.connect ([&]() { | ||
2062 | 73 | search_activated.emit(search_bar_->search_string); | ||
2063 | 74 | }); | ||
2064 | 75 | |||
2065 | 76 | mouse_down.connect(sigc::mem_fun(this, &View::OnMouseButtonDown)); | ||
2066 | 77 | |||
2067 | 78 | Relayout(); | ||
2068 | 79 | |||
2069 | 80 | } | ||
2070 | 81 | |||
2071 | 82 | View::~View() | ||
2072 | 83 | { | ||
2073 | 84 | } | ||
2074 | 85 | |||
2075 | 86 | void View::ResetToDefault() | ||
2076 | 87 | { | ||
2077 | 88 | search_bar_->search_string = ""; | ||
2078 | 89 | search_bar_->search_hint = default_text; | ||
2079 | 90 | } | ||
2080 | 91 | |||
2081 | 92 | void View::Relayout() | ||
2082 | 93 | { | ||
2083 | 94 | nux::Geometry geo = GetGeometry(); | ||
2084 | 95 | content_geo_ = GetBestFitGeometry(geo); | ||
2085 | 96 | LOG_DEBUG(logger) << "content_geo: " << content_geo_.width << "x" << content_geo_.height; | ||
2086 | 97 | |||
2087 | 98 | layout_->SetMinMaxSize(content_geo_.width, content_geo_.height); | ||
2088 | 99 | |||
2089 | 100 | QueueDraw(); | ||
2090 | 101 | } | ||
2091 | 102 | |||
2092 | 103 | long View::PostLayoutManagement(long LayoutResult) | ||
2093 | 104 | { | ||
2094 | 105 | Relayout(); | ||
2095 | 106 | return LayoutResult; | ||
2096 | 107 | } | ||
2097 | 108 | |||
2098 | 109 | |||
2099 | 110 | nux::View* View::default_focus() const | ||
2100 | 111 | { | ||
2101 | 112 | return search_bar_->text_entry(); | ||
2102 | 113 | } | ||
2103 | 114 | |||
2104 | 115 | void View::SetQueries(Hud::Queries queries) | ||
2105 | 116 | { | ||
2106 | 117 | queries_ = queries_; | ||
2107 | 118 | button_views_->Clear(); | ||
2108 | 119 | int found_items = 0; | ||
2109 | 120 | for (auto query = queries.begin(); query != queries.end(); query++) | ||
2110 | 121 | { | ||
2111 | 122 | if (found_items > 5) | ||
2112 | 123 | break; | ||
2113 | 124 | |||
2114 | 125 | HudButton *button = new HudButton(); | ||
2115 | 126 | button->SetQuery(*query); | ||
2116 | 127 | button_views_->AddView(button, 0, nux::MINOR_POSITION_LEFT); | ||
2117 | 128 | |||
2118 | 129 | button->click.connect([&](nux::View* view) { | ||
2119 | 130 | query_activated.emit(dynamic_cast<HudButton*>(view)->GetQuery()); | ||
2120 | 131 | }); | ||
2121 | 132 | |||
2122 | 133 | button->OnKeyNavFocusActivate.connect([&](nux::Area *area) { | ||
2123 | 134 | query_activated.emit(dynamic_cast<HudButton*>(area)->GetQuery()); | ||
2124 | 135 | }); | ||
2125 | 136 | |||
2126 | 137 | button->OnKeyNavFocusChange.connect([&](nux::Area *area){ | ||
2127 | 138 | query_selected.emit(dynamic_cast<HudButton*>(area)->GetQuery()); | ||
2128 | 139 | }); | ||
2129 | 140 | |||
2130 | 141 | found_items++; | ||
2131 | 142 | } | ||
2132 | 143 | |||
2133 | 144 | QueueRelayout(); | ||
2134 | 145 | QueueDraw(); | ||
2135 | 146 | } | ||
2136 | 147 | |||
2137 | 148 | void View::SetIcon(std::string icon_name) | ||
2138 | 149 | { | ||
2139 | 150 | LOG_DEBUG(logger) << "Setting icon to " << icon_name; | ||
2140 | 151 | icon_->SetByIconName(icon_name.c_str(), icon_size); | ||
2141 | 152 | QueueDraw(); | ||
2142 | 153 | } | ||
2143 | 154 | |||
2144 | 155 | // Gives us the width and height of the contents that will give us the best "fit", | ||
2145 | 156 | // which means that the icons/views will not have uneccessary padding, everything will | ||
2146 | 157 | // look tight | ||
2147 | 158 | nux::Geometry View::GetBestFitGeometry(nux::Geometry const& for_geo) | ||
2148 | 159 | { | ||
2149 | 160 | dash::Style& style = dash::Style::Instance(); | ||
2150 | 161 | int width = 0, height = 0; | ||
2151 | 162 | int tile_width = style.GetTileWidth(); | ||
2152 | 163 | int half = for_geo.width / 2; | ||
2153 | 164 | |||
2154 | 165 | while ((width += tile_width) + (19 * 2) < half) | ||
2155 | 166 | ; | ||
2156 | 167 | |||
2157 | 168 | width = MAX(width, tile_width * 6); | ||
2158 | 169 | |||
2159 | 170 | width += 19 + 32; | ||
2160 | 171 | |||
2161 | 172 | height = search_bar_->GetGeometry().height; | ||
2162 | 173 | height += 6; | ||
2163 | 174 | height += (style.GetTextLineHeight() + (12*2)) * 6; | ||
2164 | 175 | height += 6; | ||
2165 | 176 | |||
2166 | 177 | LOG_DEBUG (logger) << "best fit is, " << width << ", " << height; | ||
2167 | 178 | |||
2168 | 179 | return nux::Geometry(0, 0, width, height); | ||
2169 | 180 | } | ||
2170 | 181 | |||
2171 | 182 | void View::AboutToShow() | ||
2172 | 183 | { | ||
2173 | 184 | renderer_.AboutToShow(); | ||
2174 | 185 | } | ||
2175 | 186 | |||
2176 | 187 | void View::AboutToHide() | ||
2177 | 188 | { | ||
2178 | 189 | renderer_.AboutToHide(); | ||
2179 | 190 | } | ||
2180 | 191 | |||
2181 | 192 | void View::SetWindowGeometry(nux::Geometry const& absolute_geo, nux::Geometry const& geo) | ||
2182 | 193 | { | ||
2183 | 194 | window_geometry_ = geo; | ||
2184 | 195 | window_geometry_.x = 0; | ||
2185 | 196 | window_geometry_.y = 0; | ||
2186 | 197 | absolute_window_geometry_ = absolute_geo; | ||
2187 | 198 | } | ||
2188 | 199 | |||
2189 | 200 | void View::SetupViews() | ||
2190 | 201 | { | ||
2191 | 202 | layout_ = new nux::HLayout(); | ||
2192 | 203 | layout_->AddLayout(new nux::SpaceLayout(8,8,8,8), 0); | ||
2193 | 204 | |||
2194 | 205 | icon_ = new Icon("", icon_size, true); | ||
2195 | 206 | //icon_->SetBaseSize(icon_size, icon_size); | ||
2196 | 207 | //icon_->SetMinMaxSize(icon_size, icon_size); | ||
2197 | 208 | |||
2198 | 209 | nux::Layout* icon_layout = new nux::VLayout(); | ||
2199 | 210 | icon_layout->SetVerticalExternalMargin(12); | ||
2200 | 211 | icon_layout->AddView(icon_.GetPointer(), 0, nux::MINOR_POSITION_LEFT, nux::MINOR_SIZE_FULL); | ||
2201 | 212 | layout_->AddLayout(icon_layout, 0, nux::MINOR_POSITION_TOP, nux::MINOR_SIZE_MATCHCONTENT); | ||
2202 | 213 | |||
2203 | 214 | |||
2204 | 215 | content_layout_ = new nux::VLayout(); | ||
2205 | 216 | layout_->AddLayout(content_layout_.GetPointer(), 1, nux::MINOR_POSITION_TOP); | ||
2206 | 217 | SetLayout(layout_.GetPointer()); | ||
2207 | 218 | |||
2208 | 219 | // add the search bar to the composite | ||
2209 | 220 | search_bar_ = new unity::hud::SearchBar(); | ||
2210 | 221 | search_bar_->search_hint = default_text; | ||
2211 | 222 | search_bar_->search_changed.connect(sigc::mem_fun(this, &View::OnSearchChanged)); | ||
2212 | 223 | content_layout_->AddView(search_bar_.GetPointer(), 0, nux::MINOR_POSITION_LEFT); | ||
2213 | 224 | |||
2214 | 225 | button_views_ = new nux::VLayout(); | ||
2215 | 226 | button_views_->SetHorizontalExternalMargin(12); | ||
2216 | 227 | content_layout_->AddLayout(button_views_.GetPointer(), 1, nux::MINOR_POSITION_LEFT); | ||
2217 | 228 | } | ||
2218 | 229 | |||
2219 | 230 | void View::OnSearchChanged(std::string const& search_string) | ||
2220 | 231 | { | ||
2221 | 232 | LOG_DEBUG(logger) << "got search change"; | ||
2222 | 233 | search_changed.emit(search_string); | ||
2223 | 234 | if (search_string.empty()) | ||
2224 | 235 | { | ||
2225 | 236 | search_bar_->search_hint = default_text; | ||
2226 | 237 | } | ||
2227 | 238 | else | ||
2228 | 239 | { | ||
2229 | 240 | search_bar_->search_hint = ""; | ||
2230 | 241 | } | ||
2231 | 242 | } | ||
2232 | 243 | |||
2233 | 244 | |||
2234 | 245 | void View::OnKeyDown (unsigned long event_type, unsigned long keysym, | ||
2235 | 246 | unsigned long event_state, const TCHAR* character, | ||
2236 | 247 | unsigned short key_repeat_count) | ||
2237 | 248 | { | ||
2238 | 249 | if (keysym == NUX_VK_ESCAPE) | ||
2239 | 250 | { | ||
2240 | 251 | LOG_DEBUG(logger) << "got escape key"; | ||
2241 | 252 | ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST); | ||
2242 | 253 | } | ||
2243 | 254 | } | ||
2244 | 255 | |||
2245 | 256 | void View::OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key) | ||
2246 | 257 | { | ||
2247 | 258 | if (!content_geo_.IsPointInside(x, y)) | ||
2248 | 259 | { | ||
2249 | 260 | ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST); | ||
2250 | 261 | } | ||
2251 | 262 | } | ||
2252 | 263 | |||
2253 | 264 | void View::Draw(nux::GraphicsEngine& gfx_context, bool force_draw) | ||
2254 | 265 | { | ||
2255 | 266 | renderer_.DrawFull(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_); | ||
2256 | 267 | } | ||
2257 | 268 | |||
2258 | 269 | void View::DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw) | ||
2259 | 270 | { | ||
2260 | 271 | renderer_.DrawInner(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_); | ||
2261 | 272 | |||
2262 | 273 | if (IsFullRedraw()) | ||
2263 | 274 | { | ||
2264 | 275 | nux::GetPainter().PushBackgroundStack(); | ||
2265 | 276 | layout_->ProcessDraw(gfx_context, force_draw); | ||
2266 | 277 | nux::GetPainter().PopBackgroundStack(); | ||
2267 | 278 | } | ||
2268 | 279 | else | ||
2269 | 280 | { | ||
2270 | 281 | layout_->ProcessDraw(gfx_context, force_draw); | ||
2271 | 282 | } | ||
2272 | 283 | |||
2273 | 284 | renderer_.DrawInnerCleanup(gfx_context, layout_->GetGeometry(), absolute_window_geometry_, window_geometry_); | ||
2274 | 285 | } | ||
2275 | 286 | |||
2276 | 287 | // Keyboard navigation | ||
2277 | 288 | bool View::AcceptKeyNavFocus() | ||
2278 | 289 | { | ||
2279 | 290 | return false; | ||
2280 | 291 | } | ||
2281 | 292 | |||
2282 | 293 | // Introspectable | ||
2283 | 294 | const gchar* View::GetName() | ||
2284 | 295 | { | ||
2285 | 296 | return "unity.hud.View"; | ||
2286 | 297 | } | ||
2287 | 298 | |||
2288 | 299 | void View::AddProperties(GVariantBuilder* builder) | ||
2289 | 300 | {} | ||
2290 | 301 | |||
2291 | 302 | bool View::InspectKeyEvent(unsigned int eventType, | ||
2292 | 303 | unsigned int key_sym, | ||
2293 | 304 | const char* character) | ||
2294 | 305 | { | ||
2295 | 306 | if ((eventType == nux::NUX_KEYDOWN) && (key_sym == NUX_VK_ESCAPE)) | ||
2296 | 307 | { | ||
2297 | 308 | if (search_bar_->search_string == "") | ||
2298 | 309 | { | ||
2299 | 310 | ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST); | ||
2300 | 311 | } | ||
2301 | 312 | else | ||
2302 | 313 | { | ||
2303 | 314 | search_bar_->search_string = ""; | ||
2304 | 315 | search_bar_->search_hint = default_text; | ||
2305 | 316 | } | ||
2306 | 317 | return true; | ||
2307 | 318 | } | ||
2308 | 319 | return false; | ||
2309 | 320 | } | ||
2310 | 321 | |||
2311 | 322 | nux::Area* View::FindKeyFocusArea(unsigned int key_symbol, | ||
2312 | 323 | unsigned long x11_key_code, | ||
2313 | 324 | unsigned long special_keys_state) | ||
2314 | 325 | { | ||
2315 | 326 | // Do what nux::View does, but if the event isn't a key navigation, | ||
2316 | 327 | // designate the text entry to process it. | ||
2317 | 328 | |||
2318 | 329 | nux::KeyNavDirection direction = nux::KEY_NAV_NONE; | ||
2319 | 330 | switch (x11_key_code) | ||
2320 | 331 | { | ||
2321 | 332 | case NUX_VK_UP: | ||
2322 | 333 | direction = nux::KEY_NAV_UP; | ||
2323 | 334 | break; | ||
2324 | 335 | case NUX_VK_DOWN: | ||
2325 | 336 | direction = nux::KEY_NAV_DOWN; | ||
2326 | 337 | break; | ||
2327 | 338 | case NUX_VK_LEFT: | ||
2328 | 339 | direction = nux::KEY_NAV_LEFT; | ||
2329 | 340 | break; | ||
2330 | 341 | case NUX_VK_RIGHT: | ||
2331 | 342 | direction = nux::KEY_NAV_RIGHT; | ||
2332 | 343 | break; | ||
2333 | 344 | case NUX_VK_LEFT_TAB: | ||
2334 | 345 | direction = nux::KEY_NAV_TAB_PREVIOUS; | ||
2335 | 346 | break; | ||
2336 | 347 | case NUX_VK_TAB: | ||
2337 | 348 | direction = nux::KEY_NAV_TAB_NEXT; | ||
2338 | 349 | break; | ||
2339 | 350 | case NUX_VK_ENTER: | ||
2340 | 351 | case NUX_KP_ENTER: | ||
2341 | 352 | // Not sure if Enter should be a navigation key | ||
2342 | 353 | direction = nux::KEY_NAV_ENTER; | ||
2343 | 354 | break; | ||
2344 | 355 | default: | ||
2345 | 356 | direction = nux::KEY_NAV_NONE; | ||
2346 | 357 | break; | ||
2347 | 358 | } | ||
2348 | 359 | |||
2349 | 360 | if (has_key_focus_) | ||
2350 | 361 | { | ||
2351 | 362 | return this; | ||
2352 | 363 | } | ||
2353 | 364 | else if (direction == nux::KEY_NAV_NONE) | ||
2354 | 365 | { | ||
2355 | 366 | // then send the event to the search entry | ||
2356 | 367 | return search_bar_->text_entry(); | ||
2357 | 368 | } | ||
2358 | 369 | else if (next_object_to_key_focus_area_) | ||
2359 | 370 | { | ||
2360 | 371 | return next_object_to_key_focus_area_->FindKeyFocusArea(key_symbol, x11_key_code, special_keys_state); | ||
2361 | 372 | } | ||
2362 | 373 | return NULL; | ||
2363 | 374 | } | ||
2364 | 375 | |||
2365 | 376 | } | ||
2366 | 377 | } | ||
2367 | 0 | 378 | ||
2368 | === added file 'plugins/unityshell/src/HudView.h' | |||
2369 | --- plugins/unityshell/src/HudView.h 1970-01-01 00:00:00 +0000 | |||
2370 | +++ plugins/unityshell/src/HudView.h 2012-01-25 11:34:37 +0000 | |||
2371 | @@ -0,0 +1,115 @@ | |||
2372 | 1 | /* | ||
2373 | 2 | * Copyright (C) 2010 Canonical Ltd | ||
2374 | 3 | * | ||
2375 | 4 | * This program is free software: you can redistribute it and/or modify | ||
2376 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
2377 | 6 | * published by the Free Software Foundation. | ||
2378 | 7 | * | ||
2379 | 8 | * This program is distributed in the hope that it will be useful, | ||
2380 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2381 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2382 | 11 | * GNU General Public License for more details. | ||
2383 | 12 | * | ||
2384 | 13 | * You should have received a copy of the GNU General Public License | ||
2385 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2386 | 15 | * | ||
2387 | 16 | * Authored by: Gordon Allott <gord.allott@canonical.com> | ||
2388 | 17 | */ | ||
2389 | 18 | |||
2390 | 19 | #ifndef UNITY_HUD_VIEW_H_ | ||
2391 | 20 | #define UNITY_HUD_VIEW_H_ | ||
2392 | 21 | |||
2393 | 22 | #include <string> | ||
2394 | 23 | |||
2395 | 24 | #include <NuxGraphics/GraphicsEngine.h> | ||
2396 | 25 | #include <Nux/Nux.h> | ||
2397 | 26 | #include <Nux/PaintLayer.h> | ||
2398 | 27 | #include <Nux/View.h> | ||
2399 | 28 | #include <Nux/VLayout.h> | ||
2400 | 29 | #include <StaticCairoText.h> | ||
2401 | 30 | |||
2402 | 31 | #include <glib.h> | ||
2403 | 32 | |||
2404 | 33 | #include <UnityCore/Hud.h> | ||
2405 | 34 | |||
2406 | 35 | #include "UBusWrapper.h" | ||
2407 | 36 | #include "HudIcon.h" | ||
2408 | 37 | #include "HudSearchBar.h" | ||
2409 | 38 | #include "OverlayRenderer.h" | ||
2410 | 39 | |||
2411 | 40 | namespace unity | ||
2412 | 41 | { | ||
2413 | 42 | namespace hud | ||
2414 | 43 | { | ||
2415 | 44 | |||
2416 | 45 | class View : public nux::View | ||
2417 | 46 | { | ||
2418 | 47 | NUX_DECLARE_OBJECT_TYPE(HudView, nux::View); | ||
2419 | 48 | typedef nux::ObjectPtr<View> Ptr; | ||
2420 | 49 | public: | ||
2421 | 50 | View(); | ||
2422 | 51 | ~View(); | ||
2423 | 52 | |||
2424 | 53 | void ResetToDefault(); | ||
2425 | 54 | |||
2426 | 55 | void Relayout(); | ||
2427 | 56 | nux::View* default_focus() const; | ||
2428 | 57 | |||
2429 | 58 | void SetQueries(Hud::Queries queries); | ||
2430 | 59 | void SetIcon(std::string icon_name); | ||
2431 | 60 | |||
2432 | 61 | void AboutToShow(); | ||
2433 | 62 | void AboutToHide(); | ||
2434 | 63 | |||
2435 | 64 | void SetWindowGeometry(nux::Geometry const& absolute_geo, nux::Geometry const& geo); | ||
2436 | 65 | |||
2437 | 66 | sigc::signal<void, std::string> search_changed; | ||
2438 | 67 | sigc::signal<void, std::string> search_activated; | ||
2439 | 68 | sigc::signal<void, Query::Ptr> query_activated; | ||
2440 | 69 | sigc::signal<void, Query::Ptr> query_selected; | ||
2441 | 70 | |||
2442 | 71 | protected: | ||
2443 | 72 | virtual Area* FindKeyFocusArea(unsigned int key_symbol, | ||
2444 | 73 | unsigned long x11_key_code, | ||
2445 | 74 | unsigned long special_keys_state); | ||
2446 | 75 | |||
2447 | 76 | void SetupViews(); | ||
2448 | 77 | void OnSearchChanged(std::string const& search_string); | ||
2449 | 78 | virtual long PostLayoutManagement(long LayoutResult); | ||
2450 | 79 | private: | ||
2451 | 80 | void OnMouseButtonDown(int x, int y, unsigned long button, unsigned long key); | ||
2452 | 81 | void OnKeyDown (unsigned long event_type, unsigned long event_keysym, | ||
2453 | 82 | unsigned long event_state, const TCHAR* character, | ||
2454 | 83 | unsigned short key_repeat_count); | ||
2455 | 84 | void Draw(nux::GraphicsEngine& gfx_context, bool force_draw); | ||
2456 | 85 | void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw); | ||
2457 | 86 | bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character); | ||
2458 | 87 | bool AcceptKeyNavFocus(); | ||
2459 | 88 | nux::Geometry GetBestFitGeometry(nux::Geometry const& for_geo); | ||
2460 | 89 | |||
2461 | 90 | const gchar* GetName(); | ||
2462 | 91 | void AddProperties(GVariantBuilder* builder); | ||
2463 | 92 | |||
2464 | 93 | private: | ||
2465 | 94 | UBusManager ubus; | ||
2466 | 95 | nux::ObjectPtr<nux::Layout> layout_; | ||
2467 | 96 | nux::ObjectPtr<nux::Layout> content_layout_; | ||
2468 | 97 | nux::ObjectPtr<nux::VLayout> button_views_; | ||
2469 | 98 | |||
2470 | 99 | //FIXME - replace with dash search bar once modifications to dash search bar land | ||
2471 | 100 | SearchBar::Ptr search_bar_; | ||
2472 | 101 | Icon::Ptr icon_; | ||
2473 | 102 | bool visible_; | ||
2474 | 103 | |||
2475 | 104 | Hud::Queries queries_; | ||
2476 | 105 | nux::Geometry content_geo_; | ||
2477 | 106 | OverlayRenderer renderer_; | ||
2478 | 107 | nux::Geometry window_geometry_; | ||
2479 | 108 | nux::Geometry absolute_window_geometry_; | ||
2480 | 109 | }; | ||
2481 | 110 | |||
2482 | 111 | |||
2483 | 112 | } | ||
2484 | 113 | } | ||
2485 | 114 | #endif | ||
2486 | 115 | |||
2487 | 0 | 116 | ||
2488 | === modified file 'plugins/unityshell/src/IconTexture.cpp' | |||
2489 | --- plugins/unityshell/src/IconTexture.cpp 2011-11-08 18:21:44 +0000 | |||
2490 | +++ plugins/unityshell/src/IconTexture.cpp 2012-01-25 11:34:37 +0000 | |||
2491 | @@ -24,6 +24,7 @@ | |||
2492 | 24 | #include <pango/pangocairo.h> | 24 | #include <pango/pangocairo.h> |
2493 | 25 | 25 | ||
2494 | 26 | #include <Nux/Nux.h> | 26 | #include <Nux/Nux.h> |
2495 | 27 | #include <NuxCore/Logger.h> | ||
2496 | 27 | #include <NuxGraphics/GLThread.h> | 28 | #include <NuxGraphics/GLThread.h> |
2497 | 28 | #include <UnityCore/GLibWrapper.h> | 29 | #include <UnityCore/GLibWrapper.h> |
2498 | 29 | #include <UnityCore/Variant.h> | 30 | #include <UnityCore/Variant.h> |
2499 | @@ -37,6 +38,7 @@ | |||
2500 | 37 | namespace | 38 | namespace |
2501 | 38 | { | 39 | { |
2502 | 39 | const char* const DEFAULT_ICON = "text-x-preview"; | 40 | const char* const DEFAULT_ICON = "text-x-preview"; |
2503 | 41 | nux::logging::Logger logger("unity.icontexture"); | ||
2504 | 40 | } | 42 | } |
2505 | 41 | 43 | ||
2506 | 42 | using namespace unity; | 44 | using namespace unity; |
2507 | @@ -67,7 +69,7 @@ | |||
2508 | 67 | { | 69 | { |
2509 | 68 | _icon_name = g_strdup(icon_name ? icon_name : DEFAULT_ICON); | 70 | _icon_name = g_strdup(icon_name ? icon_name : DEFAULT_ICON); |
2510 | 69 | 71 | ||
2512 | 70 | if (!g_strcmp0(_icon_name, "") == 0 && !defer_icon_loading) | 72 | if (g_strcmp0(_icon_name, "") != 0 && !defer_icon_loading) |
2513 | 71 | LoadIcon(); | 73 | LoadIcon(); |
2514 | 72 | } | 74 | } |
2515 | 73 | 75 | ||
2516 | @@ -78,25 +80,33 @@ | |||
2517 | 78 | 80 | ||
2518 | 79 | void IconTexture::SetByIconName(const char* icon_name, unsigned int size) | 81 | void IconTexture::SetByIconName(const char* icon_name, unsigned int size) |
2519 | 80 | { | 82 | { |
2524 | 81 | g_free(_icon_name); | 83 | if (g_strcmp0(icon_name, "") != 0) |
2525 | 82 | _icon_name = g_strdup(icon_name); | 84 | { |
2526 | 83 | _size = size; | 85 | g_free(_icon_name); |
2527 | 84 | LoadIcon(); | 86 | _icon_name = g_strdup(icon_name); |
2528 | 87 | _size = size; | ||
2529 | 88 | LoadIcon(); | ||
2530 | 89 | } | ||
2531 | 85 | } | 90 | } |
2532 | 86 | 91 | ||
2533 | 87 | void IconTexture::SetByFilePath(const char* file_path, unsigned int size) | 92 | void IconTexture::SetByFilePath(const char* file_path, unsigned int size) |
2534 | 88 | { | 93 | { |
2538 | 89 | g_free(_icon_name); | 94 | if (g_strcmp0(file_path, "") != 0) |
2539 | 90 | _icon_name = g_strdup(file_path); | 95 | { |
2540 | 91 | _size = size; | 96 | g_free(_icon_name); |
2541 | 97 | _icon_name = g_strdup(file_path); | ||
2542 | 98 | _size = size; | ||
2543 | 92 | 99 | ||
2545 | 93 | LoadIcon(); | 100 | LoadIcon(); |
2546 | 101 | } | ||
2547 | 94 | } | 102 | } |
2548 | 95 | 103 | ||
2549 | 96 | void IconTexture::LoadIcon() | 104 | void IconTexture::LoadIcon() |
2550 | 97 | { | 105 | { |
2551 | 98 | static const char* const DEFAULT_GICON = ". GThemedIcon text-x-preview"; | 106 | static const char* const DEFAULT_GICON = ". GThemedIcon text-x-preview"; |
2553 | 99 | 107 | if (_icon_name == NULL) | |
2554 | 108 | return; | ||
2555 | 109 | |||
2556 | 100 | if (_loading) | 110 | if (_loading) |
2557 | 101 | return; | 111 | return; |
2558 | 102 | _loading = true; | 112 | _loading = true; |
2559 | @@ -144,6 +154,7 @@ | |||
2560 | 144 | _texture_height, | 154 | _texture_height, |
2561 | 145 | sigc::mem_fun(this, &IconTexture::CreateTextureCallback)); | 155 | sigc::mem_fun(this, &IconTexture::CreateTextureCallback)); |
2562 | 146 | QueueDraw(); | 156 | QueueDraw(); |
2563 | 157 | _loading = false; | ||
2564 | 147 | } | 158 | } |
2565 | 148 | 159 | ||
2566 | 149 | void IconTexture::IconLoaded(std::string const& icon_name, unsigned size, | 160 | void IconTexture::IconLoaded(std::string const& icon_name, unsigned size, |
2567 | @@ -162,6 +173,8 @@ | |||
2568 | 162 | if (icon_name != DEFAULT_ICON) | 173 | if (icon_name != DEFAULT_ICON) |
2569 | 163 | SetByIconName(DEFAULT_ICON, _size); | 174 | SetByIconName(DEFAULT_ICON, _size); |
2570 | 164 | } | 175 | } |
2571 | 176 | |||
2572 | 177 | QueueDraw(); | ||
2573 | 165 | } | 178 | } |
2574 | 166 | 179 | ||
2575 | 167 | void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) | 180 | void IconTexture::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) |
2576 | 168 | 181 | ||
2577 | === modified file 'plugins/unityshell/src/Launcher.cpp' | |||
2578 | --- plugins/unityshell/src/Launcher.cpp 2012-01-23 13:07:40 +0000 | |||
2579 | +++ plugins/unityshell/src/Launcher.cpp 2012-01-25 11:34:37 +0000 | |||
2580 | @@ -282,8 +282,8 @@ | |||
2581 | 282 | _drag_window = NULL; | 282 | _drag_window = NULL; |
2582 | 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); |
2583 | 284 | 284 | ||
2586 | 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)); |
2587 | 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)); |
2588 | 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)); |
2589 | 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)); |
2590 | 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)); |
2591 | @@ -1490,34 +1490,52 @@ | |||
2592 | 1490 | } | 1490 | } |
2593 | 1491 | } | 1491 | } |
2594 | 1492 | 1492 | ||
2596 | 1493 | void Launcher::OnPlaceViewShown(GVariant* data) | 1493 | void Launcher::OnOverlayShown(GVariant* data) |
2597 | 1494 | { | 1494 | { |
2606 | 1495 | LauncherModel::iterator it; | 1495 | // check the type of overlay |
2607 | 1496 | 1496 | gchar* overlay_identity = NULL; | |
2608 | 1497 | _dash_is_open = true; | 1497 | gboolean can_maximise = FALSE; |
2609 | 1498 | bg_effect_helper_.enabled = true; | 1498 | g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, |
2610 | 1499 | _hide_machine->SetQuirk(LauncherHideMachine::PLACES_VISIBLE, true); | 1499 | &overlay_identity, &can_maximise); |
2611 | 1500 | _hover_machine->SetQuirk(LauncherHoverMachine::PLACES_VISIBLE, true); | 1500 | |
2612 | 1501 | 1501 | if (!g_strcmp0(overlay_identity, "dash")) | |
2613 | 1502 | DesaturateIcons(); | 1502 | { |
2614 | 1503 | LauncherModel::iterator it; | ||
2615 | 1504 | |||
2616 | 1505 | _dash_is_open = true; | ||
2617 | 1506 | bg_effect_helper_.enabled = true; | ||
2618 | 1507 | _hide_machine->SetQuirk(LauncherHideMachine::PLACES_VISIBLE, true); | ||
2619 | 1508 | _hover_machine->SetQuirk(LauncherHoverMachine::PLACES_VISIBLE, true); | ||
2620 | 1509 | |||
2621 | 1510 | DesaturateIcons(); | ||
2622 | 1511 | } | ||
2623 | 1503 | } | 1512 | } |
2624 | 1504 | 1513 | ||
2626 | 1505 | void Launcher::OnPlaceViewHidden(GVariant* data) | 1514 | void Launcher::OnOverlayHidden(GVariant* data) |
2627 | 1506 | { | 1515 | { |
2642 | 1507 | LauncherModel::iterator it; | 1516 | // check the type of overlay |
2643 | 1508 | 1517 | gchar* overlay_identity = NULL; | |
2644 | 1509 | _dash_is_open = false; | 1518 | gboolean can_maximise = FALSE; |
2645 | 1510 | bg_effect_helper_.enabled = false; | 1519 | g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, |
2646 | 1511 | _hide_machine->SetQuirk(LauncherHideMachine::PLACES_VISIBLE, false); | 1520 | &overlay_identity, &can_maximise); |
2647 | 1512 | _hover_machine->SetQuirk(LauncherHoverMachine::PLACES_VISIBLE, false); | 1521 | |
2648 | 1513 | 1522 | if (!g_strcmp0(overlay_identity, "dash")) | |
2649 | 1514 | // as the leave event is no more received when the place is opened | 1523 | { |
2650 | 1515 | // FIXME: remove when we change the mouse grab strategy in nux | 1524 | LauncherModel::iterator it; |
2651 | 1516 | nux::Point pt = nux::GetWindowCompositor().GetMousePosition(); | 1525 | |
2652 | 1517 | 1526 | _dash_is_open = false; | |
2653 | 1518 | SetStateMouseOverLauncher(GetAbsoluteGeometry().IsInside(pt)); | 1527 | bg_effect_helper_.enabled = false; |
2654 | 1519 | 1528 | _hide_machine->SetQuirk(LauncherHideMachine::PLACES_VISIBLE, false); | |
2655 | 1520 | SaturateIcons(); | 1529 | _hover_machine->SetQuirk(LauncherHoverMachine::PLACES_VISIBLE, false); |
2656 | 1530 | |||
2657 | 1531 | // as the leave event is no more received when the place is opened | ||
2658 | 1532 | // FIXME: remove when we change the mouse grab strategy in nux | ||
2659 | 1533 | nux::Point pt = nux::GetWindowCompositor().GetMousePosition(); | ||
2660 | 1534 | |||
2661 | 1535 | SetStateMouseOverLauncher(GetAbsoluteGeometry().IsInside(pt)); | ||
2662 | 1536 | |||
2663 | 1537 | SaturateIcons(); | ||
2664 | 1538 | } | ||
2665 | 1521 | } | 1539 | } |
2666 | 1522 | 1540 | ||
2667 | 1523 | void Launcher::OnActionDone(GVariant* data) | 1541 | void Launcher::OnActionDone(GVariant* data) |
2668 | 1524 | 1542 | ||
2669 | === modified file 'plugins/unityshell/src/Launcher.h' | |||
2670 | --- plugins/unityshell/src/Launcher.h 2012-01-23 13:07:40 +0000 | |||
2671 | +++ plugins/unityshell/src/Launcher.h 2012-01-25 11:34:37 +0000 | |||
2672 | @@ -350,8 +350,8 @@ | |||
2673 | 350 | 350 | ||
2674 | 351 | void OnIconNeedsRedraw(AbstractLauncherIcon* icon); | 351 | void OnIconNeedsRedraw(AbstractLauncherIcon* icon); |
2675 | 352 | 352 | ||
2678 | 353 | void OnPlaceViewHidden(GVariant* data); | 353 | void OnOverlayHidden(GVariant* data); |
2679 | 354 | void OnPlaceViewShown(GVariant* data); | 354 | void OnOverlayShown(GVariant* data); |
2680 | 355 | 355 | ||
2681 | 356 | void DesaturateIcons(); | 356 | void DesaturateIcons(); |
2682 | 357 | void SaturateIcons(); | 357 | void SaturateIcons(); |
2683 | 358 | 358 | ||
2684 | === modified file 'plugins/unityshell/src/PanelMenuView.cpp' | |||
2685 | --- plugins/unityshell/src/PanelMenuView.cpp 2012-01-12 13:36:44 +0000 | |||
2686 | +++ plugins/unityshell/src/PanelMenuView.cpp 2012-01-25 11:34:37 +0000 | |||
2687 | @@ -155,10 +155,10 @@ | |||
2688 | 155 | 155 | ||
2689 | 156 | // Register for all the interesting events | 156 | // Register for all the interesting events |
2690 | 157 | UBusServer* ubus = ubus_server_get_default(); | 157 | UBusServer* ubus = ubus_server_get_default(); |
2692 | 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, |
2693 | 159 | (UBusCallback)PanelMenuView::OnPlaceViewShown, | 159 | (UBusCallback)PanelMenuView::OnPlaceViewShown, |
2694 | 160 | this)); | 160 | this)); |
2696 | 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, |
2697 | 162 | (UBusCallback)PanelMenuView::OnPlaceViewHidden, | 162 | (UBusCallback)PanelMenuView::OnPlaceViewHidden, |
2698 | 163 | this)); | 163 | this)); |
2699 | 164 | 164 | ||
2700 | 165 | 165 | ||
2701 | === modified file 'plugins/unityshell/src/PanelView.cpp' | |||
2702 | --- plugins/unityshell/src/PanelView.cpp 2012-01-16 07:34:25 +0000 | |||
2703 | +++ plugins/unityshell/src/PanelView.cpp 2012-01-25 11:34:37 +0000 | |||
2704 | @@ -103,11 +103,11 @@ | |||
2705 | 103 | (UBusCallback)&PanelView::OnBackgroundUpdate, | 103 | (UBusCallback)&PanelView::OnBackgroundUpdate, |
2706 | 104 | this); | 104 | this); |
2707 | 105 | 105 | ||
2709 | 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, |
2710 | 107 | (UBusCallback)&PanelView::OnDashHidden, | 107 | (UBusCallback)&PanelView::OnDashHidden, |
2711 | 108 | this); | 108 | this); |
2712 | 109 | 109 | ||
2714 | 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, |
2715 | 111 | (UBusCallback)&PanelView::OnDashShown, | 111 | (UBusCallback)&PanelView::OnDashShown, |
2716 | 112 | this); | 112 | this); |
2717 | 113 | // request the latest colour from bghash | 113 | // request the latest colour from bghash |
2718 | 114 | 114 | ||
2719 | === modified file 'plugins/unityshell/src/PlacesHomeView.cpp' | |||
2720 | --- plugins/unityshell/src/PlacesHomeView.cpp 2011-12-14 20:04:23 +0000 | |||
2721 | +++ plugins/unityshell/src/PlacesHomeView.cpp 2012-01-25 11:34:37 +0000 | |||
2722 | @@ -106,7 +106,7 @@ | |||
2723 | 106 | (style.GetHomeTileHeight() * 2) + 32); | 106 | (style.GetHomeTileHeight() * 2) + 32); |
2724 | 107 | 107 | ||
2725 | 108 | _ubus_handle = ubus_server_register_interest(ubus_server_get_default(), | 108 | _ubus_handle = ubus_server_register_interest(ubus_server_get_default(), |
2727 | 109 | UBUS_PLACE_VIEW_SHOWN, | 109 | UBUS_OVERLAY_SHOWN, |
2728 | 110 | (UBusCallback) &PlacesHomeView::DashVisible, | 110 | (UBusCallback) &PlacesHomeView::DashVisible, |
2729 | 111 | this); | 111 | this); |
2730 | 112 | 112 | ||
2731 | 113 | 113 | ||
2732 | === modified file 'plugins/unityshell/src/UBusMessages.h' | |||
2733 | --- plugins/unityshell/src/UBusMessages.h 2012-01-17 15:41:30 +0000 | |||
2734 | +++ plugins/unityshell/src/UBusMessages.h 2012-01-25 11:34:37 +0000 | |||
2735 | @@ -34,9 +34,11 @@ | |||
2736 | 34 | #define UBUS_PLACE_ENTRY_ACTIVATE_REQUEST "PLACE_ENTRY_ACTIVATE_REQUEST" | 34 | #define UBUS_PLACE_ENTRY_ACTIVATE_REQUEST "PLACE_ENTRY_ACTIVATE_REQUEST" |
2737 | 35 | #define UBUS_DASH_ABOUT_TO_SHOW "DASH_ABOUT_TO_SHOW" | 35 | #define UBUS_DASH_ABOUT_TO_SHOW "DASH_ABOUT_TO_SHOW" |
2738 | 36 | 36 | ||
2742 | 37 | // Signal send when places are shown or hidden | 37 | // Signal sent when an overlay interface is shown, includes a gvariant |
2743 | 38 | #define UBUS_PLACE_VIEW_HIDDEN "PLACE_VIEW_HIDDEN" | 38 | // gvariant format is (sb), (interface-name, can_maximize?) |
2744 | 39 | #define UBUS_PLACE_VIEW_SHOWN "PLACE_VIEW_SHOWN" | 39 | #define UBUS_OVERLAY_FORMAT_STRING "(sb)" |
2745 | 40 | #define UBUS_OVERLAY_HIDDEN "OVERLAY_HIDDEN" | ||
2746 | 41 | #define UBUS_OVERLAY_SHOWN "OVERLAY_SHOWN" | ||
2747 | 40 | 42 | ||
2748 | 41 | #define UBUS_PLACE_VIEW_QUEUE_DRAW "PLACE_VIEW_QUEUE_DRAW" | 43 | #define UBUS_PLACE_VIEW_QUEUE_DRAW "PLACE_VIEW_QUEUE_DRAW" |
2749 | 42 | 44 | ||
2750 | @@ -76,6 +78,8 @@ | |||
2751 | 76 | // FIXME - fix the nux focus api so we don't need this | 78 | // FIXME - fix the nux focus api so we don't need this |
2752 | 77 | #define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED" | 79 | #define UBUS_RESULT_VIEW_KEYNAV_CHANGED "RESULT_VIEW_KEYNAV_CHANGED" |
2753 | 78 | 80 | ||
2754 | 81 | #define UBUS_HUD_CLOSE_REQUEST "HUD_CLOSE_REQUEST" | ||
2755 | 82 | |||
2756 | 79 | // Signals sent when the switcher is shown, hidden or changes selection | 83 | // Signals sent when the switcher is shown, hidden or changes selection |
2757 | 80 | #define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN" | 84 | #define UBUS_SWITCHER_SHOWN "SWITCHER_SHOWN" |
2758 | 81 | #define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED" | 85 | #define UBUS_SWITCHER_SELECTION_CHANGED "SWITCHER_SELECTION_CHANGED" |
2759 | 82 | 86 | ||
2760 | === modified file 'plugins/unityshell/src/WindowButtons.cpp' | |||
2761 | --- plugins/unityshell/src/WindowButtons.cpp 2011-12-14 20:04:23 +0000 | |||
2762 | +++ plugins/unityshell/src/WindowButtons.cpp 2012-01-25 11:34:37 +0000 | |||
2763 | @@ -54,7 +54,7 @@ | |||
2764 | 54 | _normal_dash_tex(NULL), | 54 | _normal_dash_tex(NULL), |
2765 | 55 | _prelight_dash_tex(NULL), | 55 | _prelight_dash_tex(NULL), |
2766 | 56 | _pressed_dash_tex(NULL), | 56 | _pressed_dash_tex(NULL), |
2768 | 57 | _dash_is_open(false), | 57 | _overlay_is_open(false), |
2769 | 58 | _mouse_is_down(false), | 58 | _mouse_is_down(false), |
2770 | 59 | _place_shown_interest(0), | 59 | _place_shown_interest(0), |
2771 | 60 | _place_hidden_interest(0), | 60 | _place_hidden_interest(0), |
2772 | @@ -66,11 +66,11 @@ | |||
2773 | 66 | dash::Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::UpdateDashUnmaximize)); | 66 | dash::Settings::Instance().changed.connect(sigc::mem_fun(this, &WindowButton::UpdateDashUnmaximize)); |
2774 | 67 | 67 | ||
2775 | 68 | UBusServer* ubus = ubus_server_get_default(); | 68 | UBusServer* ubus = ubus_server_get_default(); |
2778 | 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, |
2779 | 70 | (UBusCallback)&WindowButton::OnPlaceViewShown, | 70 | (UBusCallback)&WindowButton::OnOverlayShown, |
2780 | 71 | this); | 71 | this); |
2783 | 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, |
2784 | 73 | (UBusCallback)&WindowButton::OnPlaceViewHidden, | 73 | (UBusCallback)&WindowButton::OnOverlayHidden, |
2785 | 74 | this); | 74 | this); |
2786 | 75 | 75 | ||
2787 | 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 */ |
2788 | @@ -106,7 +106,7 @@ | |||
2789 | 106 | 106 | ||
2790 | 107 | GfxContext.PushClippingRectangle(geo); | 107 | GfxContext.PushClippingRectangle(geo); |
2791 | 108 | 108 | ||
2793 | 109 | if (_dash_is_open) | 109 | if (_overlay_is_open) |
2794 | 110 | { | 110 | { |
2795 | 111 | //FIXME should use HasMouseFocus() | 111 | //FIXME should use HasMouseFocus() |
2796 | 112 | if (_mouse_is_down && IsMouseInside()) | 112 | if (_mouse_is_down && IsMouseInside()) |
2797 | @@ -163,7 +163,7 @@ | |||
2798 | 163 | _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT); | 163 | _prelight_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRELIGHT); |
2799 | 164 | _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED); | 164 | _pressed_dash_tex = GetDashWindowButton(_type, panel::WindowState::PRESSED); |
2800 | 165 | 165 | ||
2802 | 166 | if (_dash_is_open) | 166 | if (_overlay_is_open) |
2803 | 167 | { | 167 | { |
2804 | 168 | if (_normal_dash_tex) | 168 | if (_normal_dash_tex) |
2805 | 169 | SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight()); | 169 | SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight()); |
2806 | @@ -190,6 +190,7 @@ | |||
2807 | 190 | if (_pressed_dash_tex) | 190 | if (_pressed_dash_tex) |
2808 | 191 | _pressed_dash_tex->UnReference(); | 191 | _pressed_dash_tex->UnReference(); |
2809 | 192 | 192 | ||
2810 | 193 | //!!FIXME!! - don't have disabled instances of the (un)maximize buttons | ||
2811 | 193 | if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP) | 194 | if (dash::Settings::Instance().GetFormFactor() == dash::FormFactor::DESKTOP) |
2812 | 194 | { | 195 | { |
2813 | 195 | // get maximize buttons | 196 | // get maximize buttons |
2814 | @@ -208,7 +209,7 @@ | |||
2815 | 208 | // still check if the dash is really opened, | 209 | // still check if the dash is really opened, |
2816 | 209 | // someone could change the form factor through dconf | 210 | // someone could change the form factor through dconf |
2817 | 210 | // when the dash is closed | 211 | // when the dash is closed |
2819 | 211 | if (_dash_is_open) | 212 | if (_overlay_is_open) |
2820 | 212 | { | 213 | { |
2821 | 213 | if (_normal_dash_tex) | 214 | if (_normal_dash_tex) |
2822 | 214 | SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight()); | 215 | SetMinMaxSize(_normal_dash_tex->GetWidth(), _normal_dash_tex->GetHeight()); |
2823 | @@ -239,28 +240,35 @@ | |||
2824 | 239 | nux::BaseTexture* _normal_dash_tex; | 240 | nux::BaseTexture* _normal_dash_tex; |
2825 | 240 | nux::BaseTexture* _prelight_dash_tex; | 241 | nux::BaseTexture* _prelight_dash_tex; |
2826 | 241 | nux::BaseTexture* _pressed_dash_tex; | 242 | nux::BaseTexture* _pressed_dash_tex; |
2828 | 242 | bool _dash_is_open; | 243 | bool _overlay_is_open; |
2829 | 244 | bool _overlay_can_maximize; | ||
2830 | 243 | bool _mouse_is_down; | 245 | bool _mouse_is_down; |
2831 | 244 | guint32 _place_shown_interest; | 246 | guint32 _place_shown_interest; |
2832 | 245 | guint32 _place_hidden_interest; | 247 | guint32 _place_hidden_interest; |
2833 | 246 | double _opacity; | 248 | double _opacity; |
2834 | 247 | 249 | ||
2836 | 248 | static void OnPlaceViewShown(GVariant* data, void* val) | 250 | static void OnOverlayShown(GVariant* data, void* val) |
2837 | 249 | { | 251 | { |
2838 | 252 | gchar* overlay_identity = NULL; | ||
2839 | 253 | gboolean can_maximise = FALSE; | ||
2840 | 254 | g_variant_get(data, UBUS_OVERLAY_FORMAT_STRING, | ||
2841 | 255 | &overlay_identity, &can_maximise); | ||
2842 | 250 | WindowButton* self = (WindowButton*)val; | 256 | WindowButton* self = (WindowButton*)val; |
2843 | 251 | 257 | ||
2845 | 252 | self->_dash_is_open = true; | 258 | self->_overlay_is_open = true; |
2846 | 253 | if (self->_normal_dash_tex) | 259 | if (self->_normal_dash_tex) |
2847 | 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()); |
2848 | 255 | 261 | ||
2849 | 262 | self->_overlay_can_maximize = (can_maximise) ? true : false; | ||
2850 | 263 | |||
2851 | 256 | self->QueueDraw(); | 264 | self->QueueDraw(); |
2852 | 257 | } | 265 | } |
2853 | 258 | 266 | ||
2855 | 259 | static void OnPlaceViewHidden(GVariant* data, void* val) | 267 | static void OnOverlayHidden(GVariant* data, void* val) |
2856 | 260 | { | 268 | { |
2857 | 261 | WindowButton* self = (WindowButton*)val; | 269 | WindowButton* self = (WindowButton*)val; |
2858 | 262 | 270 | ||
2860 | 263 | self->_dash_is_open = false; | 271 | self->_overlay_is_open = false; |
2861 | 264 | if (self->_normal_tex) | 272 | if (self->_normal_tex) |
2862 | 265 | self->SetMinMaxSize(self->_normal_tex->GetWidth(), self->_normal_tex->GetHeight()); | 273 | self->SetMinMaxSize(self->_normal_tex->GetWidth(), self->_normal_tex->GetHeight()); |
2863 | 266 | 274 | ||
2864 | 267 | 275 | ||
2865 | === modified file 'plugins/unityshell/src/unityshell.cpp' | |||
2866 | --- plugins/unityshell/src/unityshell.cpp 2012-01-20 06:47:42 +0000 | |||
2867 | +++ plugins/unityshell/src/unityshell.cpp 2012-01-25 11:34:37 +0000 | |||
2868 | @@ -118,6 +118,7 @@ | |||
2869 | 118 | , dash_is_open_ (false) | 118 | , dash_is_open_ (false) |
2870 | 119 | , grab_index_ (0) | 119 | , grab_index_ (0) |
2871 | 120 | , painting_tray_ (false) | 120 | , painting_tray_ (false) |
2872 | 121 | , last_hud_show_time_(0) | ||
2873 | 121 | { | 122 | { |
2874 | 122 | Timer timer; | 123 | Timer timer; |
2875 | 123 | gfloat version; | 124 | gfloat version; |
2876 | @@ -206,9 +207,9 @@ | |||
2877 | 206 | 207 | ||
2878 | 207 | nux::NuxInitialize(0); | 208 | nux::NuxInitialize(0); |
2879 | 208 | wt = nux::CreateFromForeignWindow(cScreen->output(), | 209 | wt = nux::CreateFromForeignWindow(cScreen->output(), |
2883 | 209 | glXGetCurrentContext(), | 210 | glXGetCurrentContext(), |
2884 | 210 | &UnityScreen::initUnity, | 211 | &UnityScreen::initUnity, |
2885 | 211 | this); | 212 | this); |
2886 | 212 | 213 | ||
2887 | 213 | wt->RedrawRequested.connect(sigc::mem_fun(this, &UnityScreen::onRedrawRequested)); | 214 | wt->RedrawRequested.connect(sigc::mem_fun(this, &UnityScreen::onRedrawRequested)); |
2888 | 214 | 215 | ||
2889 | @@ -243,6 +244,9 @@ | |||
2890 | 243 | uScreen->_fbo->onScreenSizeChanged (geometry); | 244 | uScreen->_fbo->onScreenSizeChanged (geometry); |
2891 | 244 | } | 245 | } |
2892 | 245 | 246 | ||
2893 | 247 | optionSetShowHudInitiate(boost::bind(&UnityScreen::ShowHudInitiate, this, _1, _2, _3)); | ||
2894 | 248 | optionSetShowHudTerminate(boost::bind(&UnityScreen::ShowHudTerminate, this, _1, _2, _3)); | ||
2895 | 249 | |||
2896 | 246 | optionSetBackgroundColorNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); | 250 | optionSetBackgroundColorNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); |
2897 | 247 | optionSetLauncherHideModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); | 251 | optionSetLauncherHideModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); |
2898 | 248 | optionSetBacklightModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); | 252 | optionSetBacklightModeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); |
2899 | @@ -301,19 +305,19 @@ | |||
2900 | 301 | 305 | ||
2901 | 302 | UBusServer* ubus = ubus_server_get_default(); | 306 | UBusServer* ubus = ubus_server_get_default(); |
2902 | 303 | _ubus_handles[0] = ubus_server_register_interest(ubus, | 307 | _ubus_handles[0] = ubus_server_register_interest(ubus, |
2906 | 304 | UBUS_LAUNCHER_START_KEY_NAV, | 308 | UBUS_LAUNCHER_START_KEY_NAV, |
2907 | 305 | (UBusCallback)&UnityScreen::OnLauncherStartKeyNav, | 309 | (UBusCallback)&UnityScreen::OnLauncherStartKeyNav, |
2908 | 306 | this); | 310 | this); |
2909 | 307 | 311 | ||
2910 | 308 | _ubus_handles[1] = ubus_server_register_interest(ubus, | 312 | _ubus_handles[1] = ubus_server_register_interest(ubus, |
2914 | 309 | UBUS_LAUNCHER_END_KEY_NAV, | 313 | UBUS_LAUNCHER_END_KEY_NAV, |
2915 | 310 | (UBusCallback)&UnityScreen::OnLauncherEndKeyNav, | 314 | (UBusCallback)&UnityScreen::OnLauncherEndKeyNav, |
2916 | 311 | this); | 315 | this); |
2917 | 312 | 316 | ||
2918 | 313 | _ubus_handles[2] = ubus_server_register_interest(ubus, | 317 | _ubus_handles[2] = ubus_server_register_interest(ubus, |
2922 | 314 | UBUS_QUICKLIST_END_KEY_NAV, | 318 | UBUS_QUICKLIST_END_KEY_NAV, |
2923 | 315 | (UBusCallback)&UnityScreen::OnQuicklistEndKeyNav, | 319 | (UBusCallback)&UnityScreen::OnQuicklistEndKeyNav, |
2924 | 316 | this); | 320 | this); |
2925 | 317 | 321 | ||
2926 | 318 | g_idle_add_full (G_PRIORITY_DEFAULT, &UnityScreen::initPluginActions, this, NULL); | 322 | g_idle_add_full (G_PRIORITY_DEFAULT, &UnityScreen::initPluginActions, this, NULL); |
2927 | 319 | super_keypressed_ = false; | 323 | super_keypressed_ = false; |
2928 | @@ -328,11 +332,11 @@ | |||
2929 | 328 | 332 | ||
2930 | 329 | BackgroundEffectHelper::updates_enabled = true; | 333 | BackgroundEffectHelper::updates_enabled = true; |
2931 | 330 | 334 | ||
2933 | 331 | ubus_manager_.RegisterInterest(UBUS_PLACE_VIEW_SHOWN, [&](GVariant * args) { | 335 | ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, [&](GVariant * args) { |
2934 | 332 | dash_is_open_ = true; | 336 | dash_is_open_ = true; |
2935 | 333 | RaiseInputWindows(); | 337 | RaiseInputWindows(); |
2936 | 334 | }); | 338 | }); |
2938 | 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; }); |
2939 | 336 | LOG_INFO(logger) << "UnityScreen constructed: " << timer.ElapsedSeconds() << "s"; | 340 | LOG_INFO(logger) << "UnityScreen constructed: " << timer.ElapsedSeconds() << "s"; |
2940 | 337 | } | 341 | } |
2941 | 338 | } | 342 | } |
2942 | @@ -372,7 +376,7 @@ | |||
2943 | 372 | sout << "<Alt>" << XKeysymToString(above_tab_keysym); | 376 | sout << "<Alt>" << XKeysymToString(above_tab_keysym); |
2944 | 373 | 377 | ||
2945 | 374 | screen->removeAction(&optionGetAltTabNextWindow()); | 378 | screen->removeAction(&optionGetAltTabNextWindow()); |
2947 | 375 | 379 | ||
2948 | 376 | CompAction action = CompAction(); | 380 | CompAction action = CompAction(); |
2949 | 377 | action.keyFromString(sout.str()); | 381 | action.keyFromString(sout.str()); |
2950 | 378 | action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab); | 382 | action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab); |
2951 | @@ -387,7 +391,7 @@ | |||
2952 | 387 | sout << "<Alt><Shift>" << XKeysymToString(above_tab_keysym); | 391 | sout << "<Alt><Shift>" << XKeysymToString(above_tab_keysym); |
2953 | 388 | 392 | ||
2954 | 389 | screen->removeAction(&optionGetAltTabPrevWindow()); | 393 | screen->removeAction(&optionGetAltTabPrevWindow()); |
2956 | 390 | 394 | ||
2957 | 391 | CompAction action = CompAction(); | 395 | CompAction action = CompAction(); |
2958 | 392 | action.keyFromString(sout.str()); | 396 | action.keyFromString(sout.str()); |
2959 | 393 | action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab); | 397 | action.setState (CompAction::StateInitKey | CompAction::StateAutoGrab); |
2960 | @@ -638,9 +642,9 @@ | |||
2961 | 638 | uTrayWindow->gWindow->glAddGeometrySetCurrentIndex ( MAXSHORT); | 642 | uTrayWindow->gWindow->glAddGeometrySetCurrentIndex ( MAXSHORT); |
2962 | 639 | uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (MAXSHORT); | 643 | uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (MAXSHORT); |
2963 | 640 | uTrayWindow->gWindow->glDraw (oTransform, attrib, infiniteRegion, | 644 | uTrayWindow->gWindow->glDraw (oTransform, attrib, infiniteRegion, |
2967 | 641 | PAINT_WINDOW_TRANSFORMED_MASK | | 645 | PAINT_WINDOW_TRANSFORMED_MASK | |
2968 | 642 | PAINT_WINDOW_BLEND_MASK | | 646 | PAINT_WINDOW_BLEND_MASK | |
2969 | 643 | PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK); | 647 | PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK); |
2970 | 644 | uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (oldGlDrawGeometryIndex); | 648 | uTrayWindow->gWindow->glDrawGeometrySetCurrentIndex (oldGlDrawGeometryIndex); |
2971 | 645 | uTrayWindow->gWindow->glAddGeometrySetCurrentIndex (oldGlAddGeometryIndex); | 649 | uTrayWindow->gWindow->glAddGeometrySetCurrentIndex (oldGlAddGeometryIndex); |
2972 | 646 | uTrayWindow->gWindow->glDrawSetCurrentIndex (oldGlDrawIndex); | 650 | uTrayWindow->gWindow->glDrawSetCurrentIndex (oldGlDrawIndex); |
2973 | @@ -673,8 +677,8 @@ | |||
2974 | 673 | bool UnityScreen::forcePaintOnTop () | 677 | bool UnityScreen::forcePaintOnTop () |
2975 | 674 | { | 678 | { |
2976 | 675 | return !allowWindowPaint || | 679 | return !allowWindowPaint || |
2979 | 676 | ((switcher_controller_->Visible() || | 680 | ((switcher_controller_->Visible() || |
2980 | 677 | dash_is_open_) && !fullscreen_windows_.empty () && (!(screen->grabbed () && !screen->otherGrabExist (NULL)))); | 681 | dash_is_open_) && !fullscreen_windows_.empty () && (!(screen->grabbed () && !screen->otherGrabExist (NULL)))); |
2981 | 678 | } | 682 | } |
2982 | 679 | 683 | ||
2983 | 680 | void UnityWindow::paintThumbnail (nux::Geometry const& bounding, float alpha) | 684 | void UnityWindow::paintThumbnail (nux::Geometry const& bounding, float alpha) |
2984 | @@ -801,7 +805,7 @@ | |||
2985 | 801 | { | 805 | { |
2986 | 802 | if (mShowdesktopHandler) | 806 | if (mShowdesktopHandler) |
2987 | 803 | if (mShowdesktopHandler->animate (ms)) | 807 | if (mShowdesktopHandler->animate (ms)) |
2989 | 804 | { | 808 | { |
2990 | 805 | delete mShowdesktopHandler; | 809 | delete mShowdesktopHandler; |
2991 | 806 | mShowdesktopHandler = NULL; | 810 | mShowdesktopHandler = NULL; |
2992 | 807 | return true; | 811 | return true; |
2993 | @@ -830,7 +834,7 @@ | |||
2994 | 830 | return false; | 834 | return false; |
2995 | 831 | 835 | ||
2996 | 832 | if (w->state () & (CompWindowStateSkipPagerMask | | 836 | if (w->state () & (CompWindowStateSkipPagerMask | |
2998 | 833 | CompWindowStateSkipTaskbarMask)) | 837 | CompWindowStateSkipTaskbarMask)) |
2999 | 834 | return false; | 838 | return false; |
3000 | 835 | 839 | ||
3001 | 836 | if ((w->state () & CompWindowStateHiddenMask)) | 840 | if ((w->state () & CompWindowStateHiddenMask)) |
3002 | @@ -1225,7 +1229,7 @@ | |||
3003 | 1225 | PluginAdapter::Default()->NotifyCompizEvent(plugin, event, option); | 1229 | PluginAdapter::Default()->NotifyCompizEvent(plugin, event, option); |
3004 | 1226 | compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow>::handleCompizEvent (plugin, event, option); | 1230 | compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow>::handleCompizEvent (plugin, event, option); |
3005 | 1227 | 1231 | ||
3007 | 1228 | if (dash_is_open_ && | 1232 | if (dash_is_open_ && |
3008 | 1229 | strcmp(event, "start_viewport_switch") == 0) | 1233 | strcmp(event, "start_viewport_switch") == 0) |
3009 | 1230 | { | 1234 | { |
3010 | 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); |
3011 | @@ -1433,7 +1437,7 @@ | |||
3012 | 1433 | grab_index_ = screen->pushGrab (screen->invisibleCursor(), "unity-switcher"); | 1437 | grab_index_ = screen->pushGrab (screen->invisibleCursor(), "unity-switcher"); |
3013 | 1434 | if (!grab_index_) | 1438 | if (!grab_index_) |
3014 | 1435 | return false; | 1439 | return false; |
3016 | 1436 | 1440 | ||
3017 | 1437 | std::vector<unity::launcher::AbstractLauncherIcon*> results = launcher_controller_->GetAltTabIcons(); | 1441 | std::vector<unity::launcher::AbstractLauncherIcon*> results = launcher_controller_->GetAltTabIcons(); |
3018 | 1438 | 1442 | ||
3019 | 1439 | screen->addAction(&optionGetAltTabRight()); | 1443 | screen->addAction(&optionGetAltTabRight()); |
3020 | @@ -1524,7 +1528,7 @@ | |||
3021 | 1524 | altTabInitiateCommon(action, state, options); | 1528 | altTabInitiateCommon(action, state, options); |
3022 | 1525 | switcher_controller_->Select(1); // always select the current application | 1529 | switcher_controller_->Select(1); // always select the current application |
3023 | 1526 | } | 1530 | } |
3025 | 1527 | 1531 | ||
3026 | 1528 | switcher_controller_->NextDetail(); | 1532 | switcher_controller_->NextDetail(); |
3027 | 1529 | 1533 | ||
3028 | 1530 | action->setState(action->state() | CompAction::StateTermKey); | 1534 | action->setState(action->state() | CompAction::StateTermKey); |
3029 | @@ -1535,7 +1539,7 @@ | |||
3030 | 1535 | { | 1539 | { |
3031 | 1536 | if (switcher_controller_->Visible()) | 1540 | if (switcher_controller_->Visible()) |
3032 | 1537 | switcher_controller_->PrevDetail(); | 1541 | switcher_controller_->PrevDetail(); |
3034 | 1538 | 1542 | ||
3035 | 1539 | return false; | 1543 | return false; |
3036 | 1540 | } | 1544 | } |
3037 | 1541 | 1545 | ||
3038 | @@ -1584,6 +1588,35 @@ | |||
3039 | 1584 | PluginAdapter::Default ()->restoreInputFocus (); | 1588 | PluginAdapter::Default ()->restoreInputFocus (); |
3040 | 1585 | } | 1589 | } |
3041 | 1586 | 1590 | ||
3042 | 1591 | bool UnityScreen::ShowHudInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options) | ||
3043 | 1592 | { | ||
3044 | 1593 | // to receive the Terminate event | ||
3045 | 1594 | if (state & CompAction::StateInitKey) | ||
3046 | 1595 | action->setState(action->state() | CompAction::StateTermKey); | ||
3047 | 1596 | |||
3048 | 1597 | last_hud_show_time_ = g_get_monotonic_time(); | ||
3049 | 1598 | |||
3050 | 1599 | return false; | ||
3051 | 1600 | } | ||
3052 | 1601 | |||
3053 | 1602 | bool UnityScreen::ShowHudTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options) | ||
3054 | 1603 | { | ||
3055 | 1604 | if (optionGetShowHud().key().toString() == action->key().toString()) | ||
3056 | 1605 | { | ||
3057 | 1606 | if (switcher_controller_->Visible()) | ||
3058 | 1607 | return false; // early exit if the switcher is open | ||
3059 | 1608 | |||
3060 | 1609 | gint64 current_time = g_get_monotonic_time(); | ||
3061 | 1610 | if (current_time - last_hud_show_time_ < 150 * 1000) | ||
3062 | 1611 | { | ||
3063 | 1612 | // less than 50 ms have passed, thats a tap | ||
3064 | 1613 | hud_controller_->ShowHideHud(); | ||
3065 | 1614 | last_hud_show_time_ = 0; | ||
3066 | 1615 | } | ||
3067 | 1616 | } | ||
3068 | 1617 | return false; | ||
3069 | 1618 | } | ||
3070 | 1619 | |||
3071 | 1587 | void UnityScreen::OnQuicklistEndKeyNav(GVariant* data, void* value) | 1620 | void UnityScreen::OnQuicklistEndKeyNav(GVariant* data, void* value) |
3072 | 1588 | { | 1621 | { |
3073 | 1589 | UnityScreen* self = reinterpret_cast<UnityScreen*>(value); | 1622 | UnityScreen* self = reinterpret_cast<UnityScreen*>(value); |
3074 | @@ -1676,7 +1709,7 @@ | |||
3075 | 1676 | bool result = screen->initPluginForScreen(p); | 1709 | bool result = screen->initPluginForScreen(p); |
3076 | 1677 | if (p->vTable->name() == "unityshell") | 1710 | if (p->vTable->name() == "unityshell") |
3077 | 1678 | initAltTabNextWindow(); | 1711 | initAltTabNextWindow(); |
3079 | 1679 | 1712 | ||
3080 | 1680 | return result; | 1713 | return result; |
3081 | 1681 | } | 1714 | } |
3082 | 1682 | 1715 | ||
3083 | @@ -1689,8 +1722,8 @@ | |||
3084 | 1689 | return "Unity"; | 1722 | return "Unity"; |
3085 | 1690 | } | 1723 | } |
3086 | 1691 | 1724 | ||
3089 | 1692 | bool isNuxWindow (CompWindow* value) | 1725 | bool isNuxWindow (CompWindow* value) |
3090 | 1693 | { | 1726 | { |
3091 | 1694 | std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList(); | 1727 | std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList(); |
3092 | 1695 | auto id = value->id(); | 1728 | auto id = value->id(); |
3093 | 1696 | 1729 | ||
3094 | @@ -1717,7 +1750,7 @@ | |||
3095 | 1717 | void UnityScreen::RaiseInputWindows() | 1750 | void UnityScreen::RaiseInputWindows() |
3096 | 1718 | { | 1751 | { |
3097 | 1719 | std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList(); | 1752 | std::vector<Window> const& xwns = nux::XInputWindow::NativeHandleList(); |
3099 | 1720 | 1753 | ||
3100 | 1721 | for (auto window : xwns) | 1754 | for (auto window : xwns) |
3101 | 1722 | { | 1755 | { |
3102 | 1723 | CompWindow* cwin = screen->findWindow(window); | 1756 | CompWindow* cwin = screen->findWindow(window); |
3103 | @@ -1842,7 +1875,7 @@ | |||
3104 | 1842 | if (!window->onCurrentDesktop ()) | 1875 | if (!window->onCurrentDesktop ()) |
3105 | 1843 | return false; | 1876 | return false; |
3106 | 1844 | 1877 | ||
3108 | 1845 | /* Only withdrawn windows | 1878 | /* Only withdrawn windows |
3109 | 1846 | * which are marked hidden | 1879 | * which are marked hidden |
3110 | 1847 | * are excluded */ | 1880 | * are excluded */ |
3111 | 1848 | if (!window->shaded () && | 1881 | if (!window->shaded () && |
3112 | @@ -1850,8 +1883,8 @@ | |||
3113 | 1850 | (window->state () & CompWindowStateHiddenMask)) | 1883 | (window->state () & CompWindowStateHiddenMask)) |
3114 | 1851 | return false; | 1884 | return false; |
3115 | 1852 | 1885 | ||
3118 | 1853 | if (window->geometry ().x () + window->geometry ().width () <= 0 || | 1886 | if (window->geometry ().x () + window->geometry ().width () <= 0 || |
3119 | 1854 | window->geometry ().y () + window->geometry ().height () <= 0 || | 1887 | window->geometry ().y () + window->geometry ().height () <= 0 || |
3120 | 1855 | window->geometry ().x () >= (int) screen->width ()|| | 1888 | window->geometry ().x () >= (int) screen->width ()|| |
3121 | 1856 | window->geometry ().y () >= (int) screen->height ()) | 1889 | window->geometry ().y () >= (int) screen->height ()) |
3122 | 1857 | return false; | 1890 | return false; |
3123 | @@ -1957,7 +1990,7 @@ | |||
3124 | 1957 | !(lastState & CompWindowStateFullscreenMask)) | 1990 | !(lastState & CompWindowStateFullscreenMask)) |
3125 | 1958 | UnityScreen::get (screen)->fullscreen_windows_.push_back(window); | 1991 | UnityScreen::get (screen)->fullscreen_windows_.push_back(window); |
3126 | 1959 | else if (lastState & CompWindowStateFullscreenMask && | 1992 | else if (lastState & CompWindowStateFullscreenMask && |
3128 | 1960 | !(window->state () & CompWindowStateFullscreenMask)) | 1993 | !(window->state () & CompWindowStateFullscreenMask)) |
3129 | 1961 | UnityScreen::get (screen)->fullscreen_windows_.remove(window); | 1994 | UnityScreen::get (screen)->fullscreen_windows_.remove(window); |
3130 | 1962 | 1995 | ||
3131 | 1963 | PluginAdapter::Default()->NotifyStateChange(window, window->state(), lastState); | 1996 | PluginAdapter::Default()->NotifyStateChange(window, window->state(), lastState); |
3132 | @@ -2136,9 +2169,9 @@ | |||
3133 | 2136 | { | 2169 | { |
3134 | 2137 | case UnityshellOptions::BackgroundColor: | 2170 | case UnityshellOptions::BackgroundColor: |
3135 | 2138 | { | 2171 | { |
3139 | 2139 | nux::Color override_color (optionGetBackgroundColorRed() / 65535.0f, | 2172 | nux::Color override_color (optionGetBackgroundColorRed() / 65535.0f, |
3140 | 2140 | optionGetBackgroundColorGreen() / 65535.0f, | 2173 | optionGetBackgroundColorGreen() / 65535.0f, |
3141 | 2141 | optionGetBackgroundColorBlue() / 65535.0f, | 2174 | optionGetBackgroundColorBlue() / 65535.0f, |
3142 | 2142 | optionGetBackgroundColorAlpha() / 65535.0f); | 2175 | optionGetBackgroundColorAlpha() / 65535.0f); |
3143 | 2143 | 2176 | ||
3144 | 2144 | override_color.red = override_color.red / override_color.alpha; | 2177 | override_color.red = override_color.red / override_color.alpha; |
3145 | @@ -2185,6 +2218,7 @@ | |||
3146 | 2185 | 2218 | ||
3147 | 2186 | launcher.SetIconSize(optionGetIconSize() + 6, optionGetIconSize()); | 2219 | launcher.SetIconSize(optionGetIconSize() + 6, optionGetIconSize()); |
3148 | 2187 | dash_controller_->launcher_width = optionGetIconSize() + 18; | 2220 | dash_controller_->launcher_width = optionGetIconSize() + 18; |
3149 | 2221 | hud_controller_->launcher_width = optionGetIconSize() + 18; | ||
3150 | 2188 | 2222 | ||
3151 | 2189 | if (p) | 2223 | if (p) |
3152 | 2190 | { | 2224 | { |
3153 | @@ -2360,6 +2394,10 @@ | |||
3154 | 2360 | /* Setup Places */ | 2394 | /* Setup Places */ |
3155 | 2361 | dash_controller_.reset(new dash::Controller()); | 2395 | dash_controller_.reset(new dash::Controller()); |
3156 | 2362 | dash_controller_->on_realize.connect(sigc::mem_fun(this, &UnityScreen::OnDashRealized)); | 2396 | dash_controller_->on_realize.connect(sigc::mem_fun(this, &UnityScreen::OnDashRealized)); |
3157 | 2397 | |||
3158 | 2398 | /* Setup Hud */ | ||
3159 | 2399 | hud_controller_.reset(new hud::Controller()); | ||
3160 | 2400 | LOG_INFO(logger) << "initLauncher-hud " << timer.ElapsedSeconds() << "s"; | ||
3161 | 2363 | 2401 | ||
3162 | 2364 | // Setup Shortcut Hint | 2402 | // Setup Shortcut Hint |
3163 | 2365 | InitHints(); | 2403 | InitHints(); |
3164 | @@ -2515,7 +2553,7 @@ | |||
3165 | 2515 | 2553 | ||
3166 | 2516 | if (mShowdesktopHandler) | 2554 | if (mShowdesktopHandler) |
3167 | 2517 | delete mShowdesktopHandler; | 2555 | delete mShowdesktopHandler; |
3169 | 2518 | 2556 | ||
3170 | 2519 | if (focusdesktop_handle_) | 2557 | if (focusdesktop_handle_) |
3171 | 2520 | g_source_remove(focusdesktop_handle_); | 2558 | g_source_remove(focusdesktop_handle_); |
3172 | 2521 | 2559 | ||
3173 | 2522 | 2560 | ||
3174 | === modified file 'plugins/unityshell/src/unityshell.h' | |||
3175 | --- plugins/unityshell/src/unityshell.h 2012-01-20 06:47:42 +0000 | |||
3176 | +++ plugins/unityshell/src/unityshell.h 2012-01-25 11:34:37 +0000 | |||
3177 | @@ -56,6 +56,8 @@ | |||
3178 | 56 | #include <compiztoolbox/compiztoolbox.h> | 56 | #include <compiztoolbox/compiztoolbox.h> |
3179 | 57 | #include <dlfcn.h> | 57 | #include <dlfcn.h> |
3180 | 58 | 58 | ||
3181 | 59 | #include "HudController.h" | ||
3182 | 60 | |||
3183 | 59 | namespace unity | 61 | namespace unity |
3184 | 60 | { | 62 | { |
3185 | 61 | 63 | ||
3186 | @@ -192,6 +194,9 @@ | |||
3187 | 192 | bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); | 194 | bool altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); |
3188 | 193 | bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); | 195 | bool altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); |
3189 | 194 | 196 | ||
3190 | 197 | /* handle hud key activations */ | ||
3191 | 198 | bool ShowHudInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); | ||
3192 | 199 | bool ShowHudTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options); | ||
3193 | 195 | bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); | 200 | bool launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); |
3194 | 196 | bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); | 201 | bool launcherSwitcherPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options); |
3195 | 197 | bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options); | 202 | bool launcherSwitcherTerminate(CompAction* action, CompAction::State state, CompOption::Vector& options); |
3196 | @@ -260,6 +265,7 @@ | |||
3197 | 260 | dash::Controller::Ptr dash_controller_; | 265 | dash::Controller::Ptr dash_controller_; |
3198 | 261 | panel::Controller::Ptr panel_controller_; | 266 | panel::Controller::Ptr panel_controller_; |
3199 | 262 | switcher::Controller::Ptr switcher_controller_; | 267 | switcher::Controller::Ptr switcher_controller_; |
3200 | 268 | hud::Controller::Ptr hud_controller_; | ||
3201 | 263 | 269 | ||
3202 | 264 | shortcut::Controller::Ptr shortcut_controller_; | 270 | shortcut::Controller::Ptr shortcut_controller_; |
3203 | 265 | std::list<shortcut::AbstractHint*> hints_; | 271 | std::list<shortcut::AbstractHint*> hints_; |
3204 | @@ -313,6 +319,7 @@ | |||
3205 | 313 | CompWindowList fullscreen_windows_; | 319 | CompWindowList fullscreen_windows_; |
3206 | 314 | bool painting_tray_; | 320 | bool painting_tray_; |
3207 | 315 | unsigned int tray_paint_mask_; | 321 | unsigned int tray_paint_mask_; |
3208 | 322 | gint64 last_hud_show_time_; | ||
3209 | 316 | 323 | ||
3210 | 317 | ScreenEffectFramebufferObject::GLXGetProcAddressProc glXGetProcAddressP; | 324 | ScreenEffectFramebufferObject::GLXGetProcAddressProc glXGetProcAddressP; |
3211 | 318 | 325 | ||
3212 | @@ -381,7 +388,7 @@ | |||
3213 | 381 | UnityMinimizedHandler *mMinimizeHandler; | 388 | UnityMinimizedHandler *mMinimizeHandler; |
3214 | 382 | 389 | ||
3215 | 383 | UnityShowdesktopHandler *mShowdesktopHandler; | 390 | UnityShowdesktopHandler *mShowdesktopHandler; |
3217 | 384 | 391 | ||
3218 | 385 | private: | 392 | private: |
3219 | 386 | 393 | ||
3220 | 387 | guint focusdesktop_handle_; | 394 | guint focusdesktop_handle_; |
3221 | 388 | 395 | ||
3222 | === modified file 'plugins/unityshell/unityshell.xml.in' | |||
3223 | --- plugins/unityshell/unityshell.xml.in 2012-01-19 16:21:14 +0000 | |||
3224 | +++ plugins/unityshell/unityshell.xml.in 2012-01-25 11:34:37 +0000 | |||
3225 | @@ -40,8 +40,13 @@ | |||
3226 | 40 | </requirement> | 40 | </requirement> |
3227 | 41 | </deps> | 41 | </deps> |
3228 | 42 | <options> | 42 | <options> |
3230 | 43 | <group> | 43 | <group> |
3231 | 44 | <_short>Behaviour</_short> | 44 | <_short>Behaviour</_short> |
3232 | 45 | <option name="show_hud" type="key"> | ||
3233 | 46 | <_short>Key to show the HUD</_short> | ||
3234 | 47 | <_long>Make the HUD appear with this key</_long> | ||
3235 | 48 | <default><Alt></default> | ||
3236 | 49 | </option> | ||
3237 | 45 | <option name="launcher_reveal_edge" type="edge"> | 50 | <option name="launcher_reveal_edge" type="edge"> |
3238 | 46 | <_short>Reveal Mode</_short> | 51 | <_short>Reveal Mode</_short> |
3239 | 47 | <_long>From which edge should the launcher reveal.</_long> | 52 | <_long>From which edge should the launcher reveal.</_long> |
3240 | @@ -56,7 +61,7 @@ | |||
3241 | 56 | <max>1000</max> | 61 | <max>1000</max> |
3242 | 57 | <default>150</default> | 62 | <default>150</default> |
3243 | 58 | </option> | 63 | </option> |
3245 | 59 | <option name="launcher_hide_mode" type="int"> | 64 | <option name="launcher_hide_mode" type="int"> |
3246 | 60 | <_short>Hide Launcher</_short> | 65 | <_short>Hide Launcher</_short> |
3247 | 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> |
3248 | 62 | <min>0</min> | 67 | <min>0</min> |
3249 | @@ -78,16 +83,16 @@ | |||
3250 | 78 | <value>3</value> | 83 | <value>3</value> |
3251 | 79 | <_name>Dodge Active Window</_name> | 84 | <_name>Dodge Active Window</_name> |
3252 | 80 | </desc> | 85 | </desc> |
3255 | 81 | </option> | 86 | </option> |
3256 | 82 | <option name="show_launcher" type="key"> | 87 | <option name="show_launcher" type="key"> |
3257 | 83 | <_short>Key to show the launcher</_short> | 88 | <_short>Key to show the launcher</_short> |
3258 | 84 | <_long>Make the launcher appear with that key</_long> | 89 | <_long>Make the launcher appear with that key</_long> |
3259 | 85 | <default><Super></default> | 90 | <default><Super></default> |
3260 | 86 | </option> | 91 | </option> |
3261 | 87 | <option name="keyboard_focus" type="key"> | 92 | <option name="keyboard_focus" type="key"> |
3265 | 88 | <_short>Key to put keyboard-focus on launcher</_short> | 93 | <_short>Key to put keyboard-focus on launcher</_short> |
3266 | 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> |
3267 | 90 | <default><Alt>F1</default> | 95 | <default><Alt>F1</default> |
3268 | 91 | </option> | 96 | </option> |
3269 | 92 | <option name="execute_command" type="key"> | 97 | <option name="execute_command" type="key"> |
3270 | 93 | <_short>Key to execute a command</_short> | 98 | <_short>Key to execute a command</_short> |
3271 | @@ -132,37 +137,37 @@ | |||
3272 | 132 | <_long>fixme</_long> | 137 | <_long>fixme</_long> |
3273 | 133 | <default><Alt><Shift>Tab</default> | 138 | <default><Alt><Shift>Tab</default> |
3274 | 134 | </option> | 139 | </option> |
3289 | 135 | <option name="alt_tab_right" type="key"> | 140 | <option name="alt_tab_right" type="key"> |
3290 | 136 | <_short>Go right in the switcher</_short> | 141 | <_short>Go right in the switcher</_short> |
3291 | 137 | <_long>fixme</_long> | 142 | <_long>fixme</_long> |
3292 | 138 | <default><Alt>Right</default> | 143 | <default><Alt>Right</default> |
3293 | 139 | <passive_grab>false</passive_grab> | 144 | <passive_grab>false</passive_grab> |
3294 | 140 | <internal/> | 145 | <internal/> |
3295 | 141 | </option> | 146 | </option> |
3296 | 142 | <option name="alt_tab_left" type="key"> | 147 | <option name="alt_tab_left" type="key"> |
3297 | 143 | <_short>Go left in the switcher</_short> | 148 | <_short>Go left in the switcher</_short> |
3298 | 144 | <_long>fixme</_long> | 149 | <_long>fixme</_long> |
3299 | 145 | <default><Alt>Left</default> | 150 | <default><Alt>Left</default> |
3300 | 146 | <passive_grab>false</passive_grab> | 151 | <passive_grab>false</passive_grab> |
3301 | 147 | <internal/> | 152 | <internal/> |
3302 | 148 | </option> | 153 | </option> |
3303 | 149 | <option name="alt_tab_detail_start" type="key"> | 154 | <option name="alt_tab_detail_start" type="key"> |
3309 | 150 | <_short>Key to expose the windows in the switcher</_short> | 155 | <_short>Key to expose the windows in the switcher</_short> |
3310 | 151 | <_long>fixme</_long> | 156 | <_long>fixme</_long> |
3311 | 152 | <default><Alt>Down</default> | 157 | <default><Alt>Down</default> |
3312 | 153 | <passive_grab>false</passive_grab> | 158 | <passive_grab>false</passive_grab> |
3313 | 154 | <internal/> | 159 | <internal/> |
3314 | 155 | </option> | 160 | </option> |
3322 | 156 | <option name="alt_tab_detail_stop" type="key"> | 161 | <option name="alt_tab_detail_stop" type="key"> |
3323 | 157 | <_short>Key to collapse windows in the switcher</_short> | 162 | <_short>Key to collapse windows in the switcher</_short> |
3324 | 158 | <_long>fixme</_long> | 163 | <_long>fixme</_long> |
3325 | 159 | <default><Alt>Up</default> | 164 | <default><Alt>Up</default> |
3326 | 160 | <passive_grab>false</passive_grab> | 165 | <passive_grab>false</passive_grab> |
3327 | 161 | <internal/> | 166 | <internal/> |
3328 | 162 | </option> | 167 | </option> |
3329 | 163 | <option name="alt_tab_next_window" type="key"> | 168 | <option name="alt_tab_next_window" type="key"> |
3332 | 164 | <_short>Key to flip through windows in the switcher</_short> | 169 | <_short>Key to flip through windows in the switcher</_short> |
3333 | 165 | <_long>fixme</_long> | 170 | <_long>fixme</_long> |
3334 | 166 | <passive_grab>false</passive_grab> | 171 | <passive_grab>false</passive_grab> |
3335 | 167 | </option> | 172 | </option> |
3336 | 168 | <option name="alt_tab_prev_window" type="key"> | 173 | <option name="alt_tab_prev_window" type="key"> |
3337 | @@ -170,11 +175,11 @@ | |||
3338 | 170 | <_long>fixme</_long> | 175 | <_long>fixme</_long> |
3339 | 171 | <passive_grab>false</passive_grab> | 176 | <passive_grab>false</passive_grab> |
3340 | 172 | </option> | 177 | </option> |
3346 | 173 | <option name="show_minimized_windows" type="bool"> | 178 | <option name="show_minimized_windows" type="bool"> |
3347 | 174 | <_short>Show minimized windows in switcher</_short> | 179 | <_short>Show minimized windows in switcher</_short> |
3348 | 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> |
3349 | 176 | <default>true</default> | 181 | <default>true</default> |
3350 | 177 | </option> | 182 | </option> |
3351 | 178 | </group> | 183 | </group> |
3352 | 179 | <group> | 184 | <group> |
3353 | 180 | <_short>Experimental</_short> | 185 | <_short>Experimental</_short> |
3354 | @@ -333,7 +338,7 @@ | |||
3355 | 333 | <max>100</max> | 338 | <max>100</max> |
3356 | 334 | <default>75</default> | 339 | <default>75</default> |
3357 | 335 | </option> | 340 | </option> |
3359 | 336 | 341 | ||
3360 | 337 | <option name="devices_option" type="int"> | 342 | <option name="devices_option" type="int"> |
3361 | 338 | <_short>Show Devices</_short> | 343 | <_short>Show Devices</_short> |
3362 | 339 | <_long>Show devices in the launcher</_long> | 344 | <_long>Show devices in the launcher</_long> |
3363 | 340 | 345 | ||
3364 | === modified file 'standalone-clients/CMakeLists.txt' | |||
3365 | --- standalone-clients/CMakeLists.txt 2012-01-17 11:30:30 +0000 | |||
3366 | +++ standalone-clients/CMakeLists.txt 2012-01-25 11:34:37 +0000 | |||
3367 | @@ -86,6 +86,10 @@ | |||
3368 | 86 | ${UNITY_SRC}/PlacesSimpleTile.h | 86 | ${UNITY_SRC}/PlacesSimpleTile.h |
3369 | 87 | ${UNITY_SRC}/PlacesVScrollBar.cpp | 87 | ${UNITY_SRC}/PlacesVScrollBar.cpp |
3370 | 88 | ${UNITY_SRC}/PlacesVScrollBar.h | 88 | ${UNITY_SRC}/PlacesVScrollBar.h |
3371 | 89 | ${UNITY_SRC}/DashView.cpp | ||
3372 | 90 | ${UNITY_SRC}/DashView.h | ||
3373 | 91 | ${UNITY_SRC}/DashViewPrivate.cpp | ||
3374 | 92 | ${UNITY_SRC}/DashViewPrivate.h | ||
3375 | 89 | ${UNITY_SRC}/HomeView.cpp | 93 | ${UNITY_SRC}/HomeView.cpp |
3376 | 90 | ${UNITY_SRC}/HomeView.h | 94 | ${UNITY_SRC}/HomeView.h |
3377 | 91 | ${UNITY_SRC}/DashStyle.cpp | 95 | ${UNITY_SRC}/DashStyle.cpp |
3378 | @@ -460,6 +464,35 @@ | |||
3379 | 460 | ) | 464 | ) |
3380 | 461 | add_dependencies (bg-hash unity-core-${UNITY_API_VERSION}) | 465 | add_dependencies (bg-hash unity-core-${UNITY_API_VERSION}) |
3381 | 462 | 466 | ||
3382 | 467 | add_executable (hud | ||
3383 | 468 | StandaloneHud.cpp | ||
3384 | 469 | ${UNITY_SRC}/BackgroundEffectHelper.cpp | ||
3385 | 470 | ${UNITY_SRC}/BackgroundEffectHelper.h | ||
3386 | 471 | ${UNITY_SRC}/DashSettings.cpp | ||
3387 | 472 | ${UNITY_SRC}/DashSettings.h | ||
3388 | 473 | ${UNITY_SRC}/DashStyle.cpp | ||
3389 | 474 | ${UNITY_SRC}/DashSearchBarSpinner.cpp | ||
3390 | 475 | ${UNITY_SRC}/HudSearchBar.cpp | ||
3391 | 476 | ${UNITY_SRC}/HudButton.cpp | ||
3392 | 477 | ${UNITY_SRC}/HudIcon.cpp | ||
3393 | 478 | ${UNITY_SRC}/HudIcon.h | ||
3394 | 479 | ${UNITY_SRC}/HudView.cpp | ||
3395 | 480 | ${UNITY_SRC}/IMTextEntry.cpp | ||
3396 | 481 | ${UNITY_SRC}/Introspectable.cpp | ||
3397 | 482 | ${UNITY_SRC}/IconTexture.cpp | ||
3398 | 483 | ${UNITY_SRC}/IconLoader.cpp | ||
3399 | 484 | ${UNITY_SRC}/JSONParser.cpp | ||
3400 | 485 | ${UNITY_SRC}/OverlayRenderer.cpp | ||
3401 | 486 | ${UNITY_SRC}/StaticCairoText.cpp | ||
3402 | 487 | ${UNITY_SRC}/TextureCache.cpp | ||
3403 | 488 | ${UNITY_SRC}/Timer.cpp | ||
3404 | 489 | ${UNITY_SRC}/UBusWrapper.cpp | ||
3405 | 490 | ${UNITY_SRC}/ubus-server.cpp | ||
3406 | 491 | ${UNITY_SRC}/UScreen.cpp | ||
3407 | 492 | ${UNITY_SRC}/UScreen.h | ||
3408 | 493 | ) | ||
3409 | 494 | add_dependencies (hud unity-core-${UNITY_API_VERSION}) | ||
3410 | 495 | |||
3411 | 463 | add_executable (test-shortcut | 496 | add_executable (test-shortcut |
3412 | 464 | TestShortcut.cpp | 497 | TestShortcut.cpp |
3413 | 465 | ${UNITY_SRC}/AbstractSeparator.cpp | 498 | ${UNITY_SRC}/AbstractSeparator.cpp |
3414 | 466 | 499 | ||
3415 | === added file 'standalone-clients/StandaloneHud.cpp' | |||
3416 | --- standalone-clients/StandaloneHud.cpp 1970-01-01 00:00:00 +0000 | |||
3417 | +++ standalone-clients/StandaloneHud.cpp 2012-01-25 11:34:37 +0000 | |||
3418 | @@ -0,0 +1,170 @@ | |||
3419 | 1 | /* | ||
3420 | 2 | * Copyright 2010 Canonical Ltd. | ||
3421 | 3 | * | ||
3422 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
3423 | 5 | * under the terms of the GNU General Public License version 3, as published | ||
3424 | 6 | * by the Free Software Foundation. | ||
3425 | 7 | * | ||
3426 | 8 | * This program is distributed in the hope that it will be useful, but | ||
3427 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
3428 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR | ||
3429 | 11 | * PURPOSE. See the GNU General Public License for more details. | ||
3430 | 12 | * | ||
3431 | 13 | * You should have received a copy of the GNU General Public License | ||
3432 | 14 | * version 3 along with this program. If not, see | ||
3433 | 15 | * <http://www.gnu.org/licenses/> | ||
3434 | 16 | * | ||
3435 | 17 | * Authored by: Gordon Allott <gord.allott@canonical.com> | ||
3436 | 18 | * | ||
3437 | 19 | */ | ||
3438 | 20 | |||
3439 | 21 | #include <sstream> | ||
3440 | 22 | #include "Nux/Nux.h" | ||
3441 | 23 | #include "Nux/VLayout.h" | ||
3442 | 24 | #include "Nux/Button.h" | ||
3443 | 25 | #include "Nux/TextureArea.h" | ||
3444 | 26 | #include "Nux/WindowThread.h" | ||
3445 | 27 | #include "NuxGraphics/GraphicsEngine.h" | ||
3446 | 28 | #include <gtk/gtk.h> | ||
3447 | 29 | |||
3448 | 30 | #include "HudView.h" | ||
3449 | 31 | #include "DashStyle.h" | ||
3450 | 32 | #include "DashSettings.h" | ||
3451 | 33 | #include <NuxCore/Logger.h> | ||
3452 | 34 | |||
3453 | 35 | namespace | ||
3454 | 36 | { | ||
3455 | 37 | nux::logging::Logger logger("unity.tests.Hud"); | ||
3456 | 38 | } | ||
3457 | 39 | |||
3458 | 40 | class TestRunner | ||
3459 | 41 | { | ||
3460 | 42 | public: | ||
3461 | 43 | TestRunner (); | ||
3462 | 44 | ~TestRunner (); | ||
3463 | 45 | |||
3464 | 46 | static void InitWindowThread (nux::NThread* thread, void* InitData); | ||
3465 | 47 | void Init (); | ||
3466 | 48 | nux::Layout *layout; | ||
3467 | 49 | unity::hud::View* hud_view_; | ||
3468 | 50 | unity::dash::Settings dash_settings_; | ||
3469 | 51 | |||
3470 | 52 | private: | ||
3471 | 53 | unity::hud::Hud hud_service_; | ||
3472 | 54 | }; | ||
3473 | 55 | |||
3474 | 56 | TestRunner::TestRunner () | ||
3475 | 57 | : hud_service_("com.canonical.hud", "/com/canonical/hud") | ||
3476 | 58 | { | ||
3477 | 59 | } | ||
3478 | 60 | |||
3479 | 61 | TestRunner::~TestRunner () | ||
3480 | 62 | { | ||
3481 | 63 | } | ||
3482 | 64 | |||
3483 | 65 | void TestRunner::Init () | ||
3484 | 66 | { | ||
3485 | 67 | LOG_WARNING(logger) << "test init"; | ||
3486 | 68 | layout = new nux::VLayout(); | ||
3487 | 69 | |||
3488 | 70 | hud_view_ = new unity::hud::View(); | ||
3489 | 71 | |||
3490 | 72 | layout->AddView (hud_view_, 1, nux::MINOR_POSITION_TOP, nux::MINOR_SIZE_FULL); | ||
3491 | 73 | nux::GetWindowCompositor().SetKeyFocusArea(hud_view_->default_focus()); | ||
3492 | 74 | |||
3493 | 75 | nux::GetWindowThread()->SetLayout (layout); | ||
3494 | 76 | |||
3495 | 77 | // things the controller normally does | ||
3496 | 78 | hud_service_.queries_updated.connect([&] (unity::hud::Hud::Queries queries) { | ||
3497 | 79 | hud_view_->SetQueries(queries); | ||
3498 | 80 | std::string icon_name = ""; | ||
3499 | 81 | for (auto query = queries.begin(); query != queries.end(); query++) | ||
3500 | 82 | { | ||
3501 | 83 | if (!(*query)->icon_name.empty()) | ||
3502 | 84 | { | ||
3503 | 85 | icon_name = (*query)->icon_name; | ||
3504 | 86 | break; | ||
3505 | 87 | } | ||
3506 | 88 | } | ||
3507 | 89 | |||
3508 | 90 | hud_view_->SetIcon(icon_name); | ||
3509 | 91 | |||
3510 | 92 | }); | ||
3511 | 93 | |||
3512 | 94 | hud_view_->query_activated.connect([&] (unity::hud::Query::Ptr query) { | ||
3513 | 95 | hud_service_.ExecuteQuery(query, 0); | ||
3514 | 96 | }); | ||
3515 | 97 | |||
3516 | 98 | hud_view_->query_selected.connect([&] (unity::hud::Query::Ptr query) { | ||
3517 | 99 | hud_view_->SetIcon(query->icon_name); | ||
3518 | 100 | }); | ||
3519 | 101 | |||
3520 | 102 | hud_view_->search_changed.connect([&] (std::string search_string) { | ||
3521 | 103 | hud_service_.RequestQuery(search_string); | ||
3522 | 104 | }); | ||
3523 | 105 | |||
3524 | 106 | hud_view_->search_activated.connect([&] (std::string search_string) { | ||
3525 | 107 | hud_service_.ExecuteQueryBySearch(search_string, 0); | ||
3526 | 108 | }); | ||
3527 | 109 | |||
3528 | 110 | hud_service_.RequestQuery(""); | ||
3529 | 111 | |||
3530 | 112 | hud_view_->SetWindowGeometry(layout->GetAbsoluteGeometry(), layout->GetGeometry()); | ||
3531 | 113 | |||
3532 | 114 | } | ||
3533 | 115 | |||
3534 | 116 | void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData) | ||
3535 | 117 | { | ||
3536 | 118 | TestRunner *self = (TestRunner *) InitData; | ||
3537 | 119 | self->Init (); | ||
3538 | 120 | } | ||
3539 | 121 | |||
3540 | 122 | void | ||
3541 | 123 | ControlThread (nux::NThread* thread, | ||
3542 | 124 | void* data) | ||
3543 | 125 | { | ||
3544 | 126 | // sleep for 3 seconds | ||
3545 | 127 | nux::SleepForMilliseconds (3000); | ||
3546 | 128 | printf ("ControlThread successfully started\n"); | ||
3547 | 129 | } | ||
3548 | 130 | |||
3549 | 131 | |||
3550 | 132 | int main(int argc, char **argv) | ||
3551 | 133 | { | ||
3552 | 134 | nux::SystemThread* st = NULL; | ||
3553 | 135 | nux::WindowThread* wt = NULL; | ||
3554 | 136 | |||
3555 | 137 | // no real tests right now, just make sure we don't get any criticals and such | ||
3556 | 138 | // waiting on nice perceptual diff support before we can build real tests | ||
3557 | 139 | // for views | ||
3558 | 140 | |||
3559 | 141 | g_type_init (); | ||
3560 | 142 | gtk_init (&argc, &argv); | ||
3561 | 143 | |||
3562 | 144 | nux::NuxInitialize(0); | ||
3563 | 145 | |||
3564 | 146 | // Slightly higher as we're more likely to test things we know will fail | ||
3565 | 147 | nux::logging::configure_logging("unity.hud=debug"); | ||
3566 | 148 | |||
3567 | 149 | nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY")); | ||
3568 | 150 | LOG_DEBUG(logger) << "starting the standalone hud"; | ||
3569 | 151 | // The instances for the pseudo-singletons. | ||
3570 | 152 | unity::dash::Style dash_style; | ||
3571 | 153 | |||
3572 | 154 | TestRunner *test_runner = new TestRunner (); | ||
3573 | 155 | wt = nux::CreateGUIThread(TEXT("Hud Prototype Test"), | ||
3574 | 156 | 1024, 768, | ||
3575 | 157 | 0, | ||
3576 | 158 | &TestRunner::InitWindowThread, | ||
3577 | 159 | test_runner); | ||
3578 | 160 | |||
3579 | 161 | st = nux::CreateSystemThread (NULL, ControlThread, wt); | ||
3580 | 162 | |||
3581 | 163 | if (st) | ||
3582 | 164 | st->Start (NULL); | ||
3583 | 165 | |||
3584 | 166 | wt->Run (NULL); | ||
3585 | 167 | delete st; | ||
3586 | 168 | delete wt; | ||
3587 | 169 | return 0; | ||
3588 | 170 | } | ||
3589 | 0 | 171 | ||
3590 | === modified file 'tests/CMakeLists.txt' | |||
3591 | --- tests/CMakeLists.txt 2012-01-23 13:07:40 +0000 | |||
3592 | +++ tests/CMakeLists.txt 2012-01-25 11:34:37 +0000 | |||
3593 | @@ -99,6 +99,8 @@ | |||
3594 | 99 | 99 | ||
3595 | 100 | # The service that provides DBus services to test against | 100 | # The service that provides DBus services to test against |
3596 | 101 | add_executable(test-gtest-service | 101 | add_executable(test-gtest-service |
3597 | 102 | test_service_hud.c | ||
3598 | 103 | test_service_hud.h | ||
3599 | 102 | test_service_lens.c | 104 | test_service_lens.c |
3600 | 103 | test_service_lens.h | 105 | test_service_lens.h |
3601 | 104 | test_service_main.c | 106 | test_service_main.c |
3602 | @@ -164,17 +166,18 @@ | |||
3603 | 164 | 166 | ||
3604 | 165 | # tests that require dbus, must not require X | 167 | # tests that require dbus, must not require X |
3605 | 166 | add_executable(test-gtest-dbus | 168 | add_executable(test-gtest-dbus |
3611 | 167 | test_categories.cpp | 169 | # test_categories.cpp |
3612 | 168 | test_filesystem_lenses.cpp | 170 | # test_filesystem_lenses.cpp |
3613 | 169 | test_filter.cpp | 171 | # test_filter.cpp |
3614 | 170 | test_indicator_entry.cpp | 172 | # test_indicator_entry.cpp |
3615 | 171 | test_lens.cpp | 173 | # test_lens.cpp |
3616 | 172 | test_main_dbus.cpp | 174 | test_main_dbus.cpp |
3622 | 173 | test_model.cpp | 175 | # test_model.cpp |
3623 | 174 | test_utils.h | 176 | # test_utils.h |
3624 | 175 | test_ratings_filter.cpp | 177 | # test_ratings_filter.cpp |
3625 | 176 | test_results.cpp | 178 | # test_results.cpp |
3626 | 177 | ) | 179 | test_hud.cpp |
3627 | 180 | ) | ||
3628 | 178 | target_link_libraries(test-gtest-dbus ${GTEST_BOTH_LIBRARIES}) | 181 | target_link_libraries(test-gtest-dbus ${GTEST_BOTH_LIBRARIES}) |
3629 | 179 | add_test(UnityGTestDBus test-gtest-dbus) | 182 | add_test(UnityGTestDBus test-gtest-dbus) |
3630 | 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) |
3631 | 181 | 184 | ||
3632 | === added file 'tests/test_hud.cpp' | |||
3633 | --- tests/test_hud.cpp 1970-01-01 00:00:00 +0000 | |||
3634 | +++ tests/test_hud.cpp 2012-01-25 11:34:37 +0000 | |||
3635 | @@ -0,0 +1,104 @@ | |||
3636 | 1 | #include <gtest/gtest.h> | ||
3637 | 2 | #include <glib-object.h> | ||
3638 | 3 | #include <UnityCore/GLibWrapper.h> | ||
3639 | 4 | #include <UnityCore/Hud.h> | ||
3640 | 5 | |||
3641 | 6 | using namespace std; | ||
3642 | 7 | |||
3643 | 8 | namespace | ||
3644 | 9 | { | ||
3645 | 10 | |||
3646 | 11 | GMainLoop* loop_ = NULL; | ||
3647 | 12 | unity::hud::Hud *hud; | ||
3648 | 13 | |||
3649 | 14 | class TestHud : public ::testing::Test | ||
3650 | 15 | { | ||
3651 | 16 | public: | ||
3652 | 17 | TestHud() | ||
3653 | 18 | : query_return_result(false) | ||
3654 | 19 | , connected_result(false) | ||
3655 | 20 | { | ||
3656 | 21 | } | ||
3657 | 22 | unity::hud::Hud::Queries queries; | ||
3658 | 23 | bool query_return_result; | ||
3659 | 24 | bool connected_result; | ||
3660 | 25 | }; | ||
3661 | 26 | |||
3662 | 27 | TEST_F(TestHud, TestConstruction) | ||
3663 | 28 | { | ||
3664 | 29 | loop_ = g_main_loop_new(NULL, FALSE); | ||
3665 | 30 | hud = new unity::hud::Hud("com.canonical.Unity.Test", "/com/canonical/hud"); | ||
3666 | 31 | |||
3667 | 32 | // performs a check on the hud, if the hud is connected, report a sucess | ||
3668 | 33 | auto timeout_check = [] (gpointer data) -> gboolean | ||
3669 | 34 | { | ||
3670 | 35 | TestHud* self = static_cast<TestHud*>(data); | ||
3671 | 36 | if (hud->connected) | ||
3672 | 37 | { | ||
3673 | 38 | self->connected_result = true; | ||
3674 | 39 | g_main_loop_quit(loop_); | ||
3675 | 40 | return FALSE; | ||
3676 | 41 | } | ||
3677 | 42 | else | ||
3678 | 43 | { | ||
3679 | 44 | self->connected_result = false; | ||
3680 | 45 | return TRUE; | ||
3681 | 46 | } | ||
3682 | 47 | }; | ||
3683 | 48 | |||
3684 | 49 | |||
3685 | 50 | // if the hud is not connected when this lambda runs, fail. | ||
3686 | 51 | auto timeout_bailout = [] (gpointer data) -> gboolean | ||
3687 | 52 | { | ||
3688 | 53 | TestHud* self = static_cast<TestHud*>(data); | ||
3689 | 54 | // reached timeout, failed testing | ||
3690 | 55 | self->connected_result = false; | ||
3691 | 56 | g_main_loop_quit(loop_); | ||
3692 | 57 | return FALSE; | ||
3693 | 58 | }; | ||
3694 | 59 | |||
3695 | 60 | g_timeout_add_seconds(1, timeout_check, this); | ||
3696 | 61 | g_timeout_add_seconds(10, timeout_bailout, this); | ||
3697 | 62 | |||
3698 | 63 | g_main_loop_run(loop_); | ||
3699 | 64 | |||
3700 | 65 | EXPECT_EQ(connected_result, true); | ||
3701 | 66 | } | ||
3702 | 67 | |||
3703 | 68 | TEST_F(TestHud, TestQueryReturn) | ||
3704 | 69 | { | ||
3705 | 70 | query_return_result = false; | ||
3706 | 71 | |||
3707 | 72 | // make sure we receive the queries | ||
3708 | 73 | auto query_connection = [this](unity::hud::Hud::Queries queries_) | ||
3709 | 74 | { | ||
3710 | 75 | query_return_result = true; | ||
3711 | 76 | g_main_loop_quit(loop_); | ||
3712 | 77 | queries = queries_; | ||
3713 | 78 | }; | ||
3714 | 79 | |||
3715 | 80 | auto timeout_bailout = [] (gpointer data) -> gboolean | ||
3716 | 81 | { | ||
3717 | 82 | TestHud* self = static_cast<TestHud*>(data); | ||
3718 | 83 | self->query_return_result = false; | ||
3719 | 84 | g_main_loop_quit(loop_); | ||
3720 | 85 | return FALSE; | ||
3721 | 86 | }; | ||
3722 | 87 | |||
3723 | 88 | hud->queries_updated.connect(query_connection); | ||
3724 | 89 | |||
3725 | 90 | guint source_id = g_timeout_add_seconds(10, timeout_bailout, this); | ||
3726 | 91 | |||
3727 | 92 | // next check we get 30 entries from this specific known callback | ||
3728 | 93 | hud->RequestQuery("Request30Queries"); | ||
3729 | 94 | g_main_loop_run(loop_); | ||
3730 | 95 | EXPECT_EQ(query_return_result, true); | ||
3731 | 96 | EXPECT_NE(queries.size(), 0); | ||
3732 | 97 | g_source_remove(source_id); | ||
3733 | 98 | |||
3734 | 99 | // finally close the connection - Nothing to check for here | ||
3735 | 100 | hud->CloseQuery(); | ||
3736 | 101 | } | ||
3737 | 102 | |||
3738 | 103 | |||
3739 | 104 | } | ||
3740 | 0 | 105 | ||
3741 | === added file 'tests/test_service_hud.c' | |||
3742 | --- tests/test_service_hud.c 1970-01-01 00:00:00 +0000 | |||
3743 | +++ tests/test_service_hud.c 2012-01-25 11:34:37 +0000 | |||
3744 | @@ -0,0 +1,268 @@ | |||
3745 | 1 | #include "test_service_hud.h" | ||
3746 | 2 | #include <unity.h> | ||
3747 | 3 | #include <gio/gio.h> | ||
3748 | 4 | |||
3749 | 5 | const char * hud_interface = | ||
3750 | 6 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | ||
3751 | 7 | "<node name=\"/\">\n" | ||
3752 | 8 | " <interface name=\"com.canonical.hud\">\n" | ||
3753 | 9 | "<!-- Properties -->\n" | ||
3754 | 10 | " <!-- None -->\n" | ||
3755 | 11 | "\n" | ||
3756 | 12 | "<!-- Functions -->\n" | ||
3757 | 13 | " <method name=\"StartQuery\">\n" | ||
3758 | 14 | " <!-- in -->\n" | ||
3759 | 15 | " <arg type=\"s\" name=\"query\" direction=\"in\" />\n" | ||
3760 | 16 | " <arg type=\"i\" name=\"entries\" direction=\"in\" />\n" | ||
3761 | 17 | " <!-- out -->\n" | ||
3762 | 18 | " <arg type=\"s\" name=\"target\" direction=\"out\" />\n" | ||
3763 | 19 | " <arg type=\"a(sssssv)\" name=\"suggestions\" direction=\"out\" />\n" | ||
3764 | 20 | " <arg type=\"v\" name=\"querykey\" direction=\"out\" />\n" | ||
3765 | 21 | " </method>\n" | ||
3766 | 22 | "\n" | ||
3767 | 23 | " <method name=\"ExecuteQuery\">\n" | ||
3768 | 24 | " <arg type=\"v\" name=\"key\" direction=\"in\" />\n" | ||
3769 | 25 | " <arg type=\"u\" name=\"timestamp\" direction=\"in\" />\n" | ||
3770 | 26 | " </method>\n" | ||
3771 | 27 | "\n" | ||
3772 | 28 | " <method name=\"CloseQuery\">\n" | ||
3773 | 29 | " <arg type=\"v\" name=\"querykey\" direction=\"in\" />\n" | ||
3774 | 30 | " </method>\n" | ||
3775 | 31 | "\n" | ||
3776 | 32 | "<!-- Signals -->\n" | ||
3777 | 33 | " <signal name=\"UpdatedQuery\">\n" | ||
3778 | 34 | " <arg type=\"s\" name=\"target\" direction=\"out\" />\n" | ||
3779 | 35 | " <arg type=\"a(sssssv)\" name=\"suggestions\" direction=\"out\" />\n" | ||
3780 | 36 | " <arg type=\"v\" name=\"querykey\" direction=\"out\" />\n" | ||
3781 | 37 | " </signal>\n" | ||
3782 | 38 | "\n" | ||
3783 | 39 | "<!-- End of interesting stuff -->\n" | ||
3784 | 40 | "\n" | ||
3785 | 41 | " </interface>\n" | ||
3786 | 42 | "</node>\n" | ||
3787 | 43 | ; | ||
3788 | 44 | static void bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data); | ||
3789 | 45 | static void bus_method (GDBusConnection *connection, | ||
3790 | 46 | const gchar *sender, | ||
3791 | 47 | const gchar *object_path, | ||
3792 | 48 | const gchar *interface_name, | ||
3793 | 49 | const gchar *method_name, | ||
3794 | 50 | GVariant *parameters, | ||
3795 | 51 | GDBusMethodInvocation *invocation, | ||
3796 | 52 | gpointer user_data); | ||
3797 | 53 | |||
3798 | 54 | G_DEFINE_TYPE(ServiceHud, service_hud, G_TYPE_OBJECT); | ||
3799 | 55 | static GDBusNodeInfo * node_info = NULL; | ||
3800 | 56 | static GDBusInterfaceInfo * iface_info = NULL; | ||
3801 | 57 | static GDBusInterfaceVTable bus_vtable = { | ||
3802 | 58 | method_call: bus_method, | ||
3803 | 59 | get_property: NULL, | ||
3804 | 60 | set_property: NULL, | ||
3805 | 61 | }; | ||
3806 | 62 | |||
3807 | 63 | |||
3808 | 64 | struct _ServiceHudPrivate | ||
3809 | 65 | { | ||
3810 | 66 | GDBusConnection * bus; | ||
3811 | 67 | GCancellable * bus_lookup; | ||
3812 | 68 | guint bus_registration; | ||
3813 | 69 | }; | ||
3814 | 70 | |||
3815 | 71 | static void | ||
3816 | 72 | service_hud_dispose(GObject* object) | ||
3817 | 73 | { | ||
3818 | 74 | ServiceHud* self = SERVICE_HUD(object); | ||
3819 | 75 | if (self->priv->bus_lookup != NULL) { | ||
3820 | 76 | g_cancellable_cancel(self->priv->bus_lookup); | ||
3821 | 77 | g_object_unref(self->priv->bus_lookup); | ||
3822 | 78 | self->priv->bus_lookup = NULL; | ||
3823 | 79 | } | ||
3824 | 80 | |||
3825 | 81 | if (self->priv->bus_registration != 0) { | ||
3826 | 82 | g_dbus_connection_unregister_object(self->priv->bus, self->priv->bus_registration); | ||
3827 | 83 | self->priv->bus_registration = 0; | ||
3828 | 84 | } | ||
3829 | 85 | |||
3830 | 86 | if (self->priv->bus != NULL) { | ||
3831 | 87 | g_object_unref(self->priv->bus); | ||
3832 | 88 | self->priv->bus = NULL; | ||
3833 | 89 | } | ||
3834 | 90 | |||
3835 | 91 | } | ||
3836 | 92 | |||
3837 | 93 | static void | ||
3838 | 94 | service_hud_class_init(ServiceHudClass* klass) | ||
3839 | 95 | { | ||
3840 | 96 | G_OBJECT_CLASS(klass)->dispose = service_hud_dispose; | ||
3841 | 97 | g_type_class_add_private (klass, sizeof (ServiceHudPrivate)); | ||
3842 | 98 | |||
3843 | 99 | if (node_info == NULL) | ||
3844 | 100 | { | ||
3845 | 101 | GError * error = NULL; | ||
3846 | 102 | |||
3847 | 103 | node_info = g_dbus_node_info_new_for_xml(hud_interface, &error); | ||
3848 | 104 | if (error != NULL) | ||
3849 | 105 | { | ||
3850 | 106 | g_error("Unable to parse HUD interface: %s", error->message); | ||
3851 | 107 | g_error_free(error); | ||
3852 | 108 | } | ||
3853 | 109 | } | ||
3854 | 110 | |||
3855 | 111 | if (node_info != NULL && iface_info == NULL) | ||
3856 | 112 | { | ||
3857 | 113 | iface_info = g_dbus_node_info_lookup_interface(node_info,"com.canonical.hud"); | ||
3858 | 114 | if (iface_info == NULL) | ||
3859 | 115 | { | ||
3860 | 116 | g_error("Unable to find interface 'com.canonical.hud'"); | ||
3861 | 117 | } | ||
3862 | 118 | } | ||
3863 | 119 | |||
3864 | 120 | } | ||
3865 | 121 | |||
3866 | 122 | static void | ||
3867 | 123 | service_hud_init(ServiceHud* self) | ||
3868 | 124 | { | ||
3869 | 125 | self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SERVICE_TYPE_HUD, ServiceHudPrivate); | ||
3870 | 126 | self->priv->bus = NULL; | ||
3871 | 127 | self->priv->bus_lookup = NULL; | ||
3872 | 128 | self->priv->bus_registration = 0; | ||
3873 | 129 | |||
3874 | 130 | self->priv->bus_lookup = g_cancellable_new(); | ||
3875 | 131 | g_bus_get(G_BUS_TYPE_SESSION, self->priv->bus_lookup, bus_got_cb, self); | ||
3876 | 132 | |||
3877 | 133 | } | ||
3878 | 134 | |||
3879 | 135 | ServiceHud* | ||
3880 | 136 | service_hud_new() | ||
3881 | 137 | { | ||
3882 | 138 | return g_object_new(SERVICE_TYPE_HUD, NULL); | ||
3883 | 139 | } | ||
3884 | 140 | |||
3885 | 141 | static void | ||
3886 | 142 | bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data) | ||
3887 | 143 | { | ||
3888 | 144 | GError * error = NULL; | ||
3889 | 145 | ServiceHud * self = SERVICE_HUD(user_data); | ||
3890 | 146 | GDBusConnection * bus; | ||
3891 | 147 | |||
3892 | 148 | bus = g_bus_get_finish(res, &error); | ||
3893 | 149 | if (error != NULL) { | ||
3894 | 150 | g_critical("Unable to get bus: %s", error->message); | ||
3895 | 151 | g_error_free(error); | ||
3896 | 152 | return; | ||
3897 | 153 | } | ||
3898 | 154 | |||
3899 | 155 | self->priv->bus = bus; | ||
3900 | 156 | |||
3901 | 157 | /* Register object */ | ||
3902 | 158 | self->priv->bus_registration = g_dbus_connection_register_object(bus, | ||
3903 | 159 | /* path */ "/com/canonical/hud", | ||
3904 | 160 | /* interface */ iface_info, | ||
3905 | 161 | /* vtable */ &bus_vtable, | ||
3906 | 162 | /* userdata */ self, | ||
3907 | 163 | /* destroy */ NULL, | ||
3908 | 164 | /* error */ &error); | ||
3909 | 165 | |||
3910 | 166 | if (error != NULL) { | ||
3911 | 167 | g_critical ("Unable to create bus connection object, %s", error->message); | ||
3912 | 168 | g_error_free(error); | ||
3913 | 169 | return; | ||
3914 | 170 | } | ||
3915 | 171 | |||
3916 | 172 | return; | ||
3917 | 173 | } | ||
3918 | 174 | |||
3919 | 175 | static void | ||
3920 | 176 | bus_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) | ||
3921 | 177 | { | ||
3922 | 178 | if (g_strcmp0(method_name, "StartQuery") == 0) | ||
3923 | 179 | { | ||
3924 | 180 | GVariant * ret = NULL; | ||
3925 | 181 | gchar * query = NULL; | ||
3926 | 182 | int num_entries = 0; | ||
3927 | 183 | |||
3928 | 184 | g_variant_get(parameters, "(si)", &query, &num_entries); | ||
3929 | 185 | |||
3930 | 186 | /* Build into into a variant */ | ||
3931 | 187 | GVariantBuilder ret_builder; | ||
3932 | 188 | g_variant_builder_init(&ret_builder, G_VARIANT_TYPE_TUPLE); | ||
3933 | 189 | g_variant_builder_add_value(&ret_builder, g_variant_new_string("target")); | ||
3934 | 190 | GVariantBuilder builder; | ||
3935 | 191 | |||
3936 | 192 | g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); | ||
3937 | 193 | |||
3938 | 194 | int i = 0; | ||
3939 | 195 | for (i = 0; i < num_entries; i++) | ||
3940 | 196 | { | ||
3941 | 197 | gchar* target = g_strdup_printf("test-%i", i); | ||
3942 | 198 | gchar* icon = g_strdup_printf("icon-%i", i); | ||
3943 | 199 | gchar* future_icon = g_strdup(icon); | ||
3944 | 200 | gchar* completion_text = g_strdup_printf("completion-%i", i); | ||
3945 | 201 | gchar* accelerator = g_strdup_printf("<alt>+whatever"); | ||
3946 | 202 | |||
3947 | 203 | GVariantBuilder tuple; | ||
3948 | 204 | g_variant_builder_init(&tuple, G_VARIANT_TYPE_TUPLE); | ||
3949 | 205 | g_variant_builder_add_value(&tuple, g_variant_new_string(target)); | ||
3950 | 206 | g_variant_builder_add_value(&tuple, g_variant_new_string(icon)); | ||
3951 | 207 | g_variant_builder_add_value(&tuple, g_variant_new_string(future_icon)); | ||
3952 | 208 | g_variant_builder_add_value(&tuple, g_variant_new_string(completion_text)); | ||
3953 | 209 | g_variant_builder_add_value(&tuple, g_variant_new_string(accelerator)); | ||
3954 | 210 | // build a fake key | ||
3955 | 211 | GVariant* key; | ||
3956 | 212 | { | ||
3957 | 213 | GVariantBuilder keybuilder; | ||
3958 | 214 | g_variant_builder_init(&keybuilder, G_VARIANT_TYPE_TUPLE); | ||
3959 | 215 | g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string")); | ||
3960 | 216 | g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string")); | ||
3961 | 217 | g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string")); | ||
3962 | 218 | g_variant_builder_add_value(&keybuilder, g_variant_new_int32(1986)); | ||
3963 | 219 | |||
3964 | 220 | key = g_variant_new_variant(g_variant_builder_end(&keybuilder)); | ||
3965 | 221 | } | ||
3966 | 222 | g_variant_ref_sink(key); | ||
3967 | 223 | g_variant_builder_add_value(&tuple, key); | ||
3968 | 224 | g_variant_builder_add_value(&builder, g_variant_builder_end(&tuple)); | ||
3969 | 225 | g_free(target); | ||
3970 | 226 | g_free(icon); | ||
3971 | 227 | g_free(future_icon); | ||
3972 | 228 | g_free(completion_text); | ||
3973 | 229 | } | ||
3974 | 230 | g_variant_builder_add_value(&ret_builder, g_variant_builder_end(&builder)); | ||
3975 | 231 | |||
3976 | 232 | GVariant* query_key; | ||
3977 | 233 | { | ||
3978 | 234 | GVariantBuilder keybuilder; | ||
3979 | 235 | g_variant_builder_init(&keybuilder, G_VARIANT_TYPE_TUPLE); | ||
3980 | 236 | g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string")); | ||
3981 | 237 | g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string")); | ||
3982 | 238 | g_variant_builder_add_value(&keybuilder, g_variant_new_string("dummy string")); | ||
3983 | 239 | g_variant_builder_add_value(&keybuilder, g_variant_new_int32(1986)); | ||
3984 | 240 | |||
3985 | 241 | query_key = g_variant_new_variant(g_variant_builder_end(&keybuilder)); | ||
3986 | 242 | } | ||
3987 | 243 | g_variant_ref_sink(query_key); | ||
3988 | 244 | g_variant_builder_add_value(&ret_builder, query_key); | ||
3989 | 245 | |||
3990 | 246 | ret = g_variant_builder_end(&ret_builder); | ||
3991 | 247 | |||
3992 | 248 | g_dbus_method_invocation_return_value(invocation, ret); | ||
3993 | 249 | g_free(query); | ||
3994 | 250 | } | ||
3995 | 251 | else if (g_strcmp0(method_name, "ExecuteQuery") == 0) | ||
3996 | 252 | { | ||
3997 | 253 | GVariant * key = NULL; | ||
3998 | 254 | key = g_variant_get_child_value(parameters, 0); | ||
3999 | 255 | g_dbus_method_invocation_return_value(invocation, NULL); | ||
4000 | 256 | g_variant_unref(key); | ||
4001 | 257 | } | ||
4002 | 258 | else if (g_strcmp0(method_name, "CloseQuery") == 0) | ||
4003 | 259 | { | ||
4004 | 260 | GVariant * key = NULL; | ||
4005 | 261 | key = g_variant_get_child_value(parameters, 0); | ||
4006 | 262 | g_dbus_method_invocation_return_value(invocation, NULL); | ||
4007 | 263 | g_variant_unref(key); | ||
4008 | 264 | } | ||
4009 | 265 | |||
4010 | 266 | return; | ||
4011 | 267 | } | ||
4012 | 268 | |||
4013 | 0 | 269 | ||
4014 | === added file 'tests/test_service_hud.h' | |||
4015 | --- tests/test_service_hud.h 1970-01-01 00:00:00 +0000 | |||
4016 | +++ tests/test_service_hud.h 2012-01-25 11:34:37 +0000 | |||
4017 | @@ -0,0 +1,46 @@ | |||
4018 | 1 | #ifndef _SERVICE_HUD_H_ | ||
4019 | 2 | #define _SERVICE_HUD_H_ | ||
4020 | 3 | |||
4021 | 4 | #include <glib-object.h> | ||
4022 | 5 | G_BEGIN_DECLS | ||
4023 | 6 | |||
4024 | 7 | #define SERVICE_TYPE_HUD (service_hud_get_type ()) | ||
4025 | 8 | |||
4026 | 9 | #define SERVICE_HUD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ | ||
4027 | 10 | SERVICE_TYPE_HUD, ServiceHud)) | ||
4028 | 11 | |||
4029 | 12 | #define SERVICE_HUD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),\ | ||
4030 | 13 | SERVICE_TYPE_HUD, ServiceHudClass)) | ||
4031 | 14 | |||
4032 | 15 | #define SERVICE_IS_HUD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),\ | ||
4033 | 16 | SERVICE_TYPE_HUD)) | ||
4034 | 17 | |||
4035 | 18 | #define SERVICE_IS_HUD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),\ | ||
4036 | 19 | SERVICE_TYPE_HUD)) | ||
4037 | 20 | |||
4038 | 21 | #define ServiceHud_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),\ | ||
4039 | 22 | SERVICE_TYPE_HUD, ServiceHudClass)) | ||
4040 | 23 | |||
4041 | 24 | typedef struct _ServiceHud ServiceHud; | ||
4042 | 25 | typedef struct _ServiceHudClass ServiceHudClass; | ||
4043 | 26 | typedef struct _ServiceHudPrivate ServiceHudPrivate; | ||
4044 | 27 | |||
4045 | 28 | struct _ServiceHud | ||
4046 | 29 | { | ||
4047 | 30 | GObject parent; | ||
4048 | 31 | |||
4049 | 32 | ServiceHudPrivate *priv; | ||
4050 | 33 | }; | ||
4051 | 34 | |||
4052 | 35 | struct _ServiceHudClass | ||
4053 | 36 | { | ||
4054 | 37 | GObjectClass parent_class; | ||
4055 | 38 | }; | ||
4056 | 39 | |||
4057 | 40 | GType service_hud_get_type(void) G_GNUC_CONST; | ||
4058 | 41 | |||
4059 | 42 | ServiceHud* service_hud_new(void); | ||
4060 | 43 | |||
4061 | 44 | G_END_DECLS | ||
4062 | 45 | |||
4063 | 46 | #endif /* _SERVICE_HUD_H_ */ | ||
4064 | 0 | 47 | ||
4065 | === modified file 'tests/test_service_main.c' | |||
4066 | --- tests/test_service_main.c 2011-07-26 09:08:42 +0000 | |||
4067 | +++ tests/test_service_main.c 2012-01-25 11:34:37 +0000 | |||
4068 | @@ -2,6 +2,7 @@ | |||
4069 | 2 | 2 | ||
4070 | 3 | #include "test_service_lens.h" | 3 | #include "test_service_lens.h" |
4071 | 4 | #include "test_service_model.h" | 4 | #include "test_service_model.h" |
4072 | 5 | #include "test_service_hud.h" | ||
4073 | 5 | 6 | ||
4074 | 6 | static void on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null); | 7 | static void on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null); |
4075 | 7 | static void handle_method_call(GDBusConnection *connection, | 8 | static void handle_method_call(GDBusConnection *connection, |
4076 | @@ -32,8 +33,9 @@ | |||
4077 | 32 | }; | 33 | }; |
4078 | 33 | 34 | ||
4079 | 34 | static GMainLoop* loop_ = NULL; | 35 | static GMainLoop* loop_ = NULL; |
4082 | 35 | static ServiceLens* lens_ = NULL; | 36 | //static ServiceLens* lens_ = NULL; |
4083 | 36 | static ServiceModel* model_ = NULL; | 37 | //static ServiceModel* model_ = NULL; |
4084 | 38 | static ServiceHud* hud_ = NULL; | ||
4085 | 37 | 39 | ||
4086 | 38 | gint | 40 | gint |
4087 | 39 | main(gint argc, gchar** argv) | 41 | main(gint argc, gchar** argv) |
4088 | @@ -42,8 +44,9 @@ | |||
4089 | 42 | 44 | ||
4090 | 43 | loop_ = g_main_loop_new(NULL, FALSE); | 45 | loop_ = g_main_loop_new(NULL, FALSE); |
4091 | 44 | 46 | ||
4094 | 45 | lens_ = service_lens_new(); | 47 | //lens_ = service_lens_new(); |
4095 | 46 | model_ = service_model_new(); | 48 | //model_ = service_model_new(); |
4096 | 49 | hud_ = service_hud_new(); | ||
4097 | 47 | 50 | ||
4098 | 48 | g_bus_own_name(G_BUS_TYPE_SESSION, | 51 | g_bus_own_name(G_BUS_TYPE_SESSION, |
4099 | 49 | "com.canonical.Unity.Test", | 52 | "com.canonical.Unity.Test", |
4100 | @@ -57,8 +60,9 @@ | |||
4101 | 57 | g_main_loop_run(loop_); | 60 | g_main_loop_run(loop_); |
4102 | 58 | g_main_loop_unref(loop_); | 61 | g_main_loop_unref(loop_); |
4103 | 59 | 62 | ||
4106 | 60 | g_object_unref(lens_); | 63 | //g_object_unref(lens_); |
4107 | 61 | g_object_unref(model_); | 64 | //g_object_unref(model_); |
4108 | 65 | g_object_unref(hud_); | ||
4109 | 62 | g_dbus_node_info_unref(introspection_data); | 66 | g_dbus_node_info_unref(introspection_data); |
4110 | 63 | 67 | ||
4111 | 64 | return 0; | 68 | return 0; |
50 - self->owner_ ->connected. emit();
Why is this needed?