702.3.1
by Michael Terry
add modelines and fix up some inconsistent tabbings |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
2 |
/*
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
3 |
* Copyright (C) 2010-2012 Canonical Ltd
|
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
4 |
*
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
|
|
1527.5.3
by Marco Trevisan (Treviño)
DBusIndicators: don't spam the service, just send really changed geometries |
18 |
* Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
|
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
19 |
*/
|
20 |
||
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
21 |
#include "config.h" |
1185.6.8
by Tim Penhey
Middle of hacking, need some wrapers. |
22 |
#include "DBusIndicators.h" |
23 |
||
1208.2.6
by Tim Penhey
Remove the AddProperties on the DBusIndicators object. |
24 |
#include "GLibWrapper.h" |
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
25 |
#include "GLibDBusProxy.h" |
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
26 |
#include "Variant.h" |
1185.6.2
by Tim Penhey
Remove old header and rename new. |
27 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
28 |
namespace unity |
29 |
{
|
|
30 |
namespace indicator |
|
31 |
{
|
|
1185.6.8
by Tim Penhey
Middle of hacking, need some wrapers. |
32 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
33 |
namespace
|
34 |
{
|
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
35 |
const std::string SERVICE_NAME("com.canonical.Unity.Panel.Service"); |
36 |
const std::string SERVICE_PATH("/com/canonical/Unity/Panel/Service"); |
|
37 |
const std::string SERVICE_IFACE("com.canonical.Unity.Panel.Service"); |
|
1185.6.12
by Tim Penhey
Fixing the compile time errors... |
38 |
} // anonymous namespace |
1185.6.8
by Tim Penhey
Middle of hacking, need some wrapers. |
39 |
|
40 |
||
1858.12.3
by Marco Trevisan (Treviño)
DBusIndicators: cleaning up |
41 |
/* Connects to the remote panel service (unity-panel-service) and translates
|
42 |
* that into something that the panel can show */
|
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
43 |
class DBusIndicators::Impl |
44 |
{
|
|
45 |
public: |
|
46 |
Impl(DBusIndicators* owner); |
|
1858.13.2
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
47 |
~Impl(); |
1208.2.9
by Tim Penhey
Start a compiler firewall. |
48 |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
49 |
void CheckLocalService(); |
1208.2.9
by Tim Penhey
Start a compiler firewall. |
50 |
void RequestSyncAll(); |
51 |
void RequestSyncIndicator(std::string const& name); |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
52 |
void Sync(GVariant* args); |
53 |
void SyncGeometries(std::string const& name, EntryLocationMap const& locations); |
|
54 |
||
55 |
void OnConnected(); |
|
56 |
void OnDisconnected(); |
|
57 |
||
58 |
void OnReSync(GVariant* parameters); |
|
59 |
void OnEntryActivated(GVariant* parameters); |
|
60 |
void OnEntryActivatedRequest(GVariant* parameters); |
|
61 |
void OnEntryShowNowChanged(GVariant* parameters); |
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
62 |
|
1270.2.18
by Neil Jagdish Patel
Some cleanups |
63 |
virtual void OnEntryScroll(std::string const& entry_id, int delta); |
1858.9.10
by Marco Trevisan (Treviño)
UnityCore: update Entry ShowMenu related methods against the services changes. |
64 |
virtual void OnEntryShowMenu(std::string const& entry_id, unsigned int xid, |
65 |
int x, int y, unsigned int button, |
|
66 |
unsigned int timestamp); |
|
1265.2.6
by Marco Trevisan (Treviño)
Support for seconday activate |
67 |
virtual void OnEntrySecondaryActivate(std::string const& entry_id, |
1265.2.9
by Marco Trevisan (Treviño)
Indicator: Don't use anymore the x,y position on secondary-activation |
68 |
unsigned int timestamp); |
1858.10.1
by Marco Trevisan (Treviño)
UnityCore: Implement OnShowAppMenu on DBusIndicators |
69 |
virtual void OnShowAppMenu(unsigned int xid, int x, int y, |
70 |
unsigned int timestamp); |
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
71 |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
72 |
struct CallData |
73 |
{
|
|
74 |
Impl* self; |
|
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
75 |
glib::Variant parameters; |
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
76 |
};
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
77 |
|
78 |
DBusIndicators* owner_; |
|
1858.13.2
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
79 |
guint reconnect_timeout_id_; |
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
80 |
guint show_entry_idle_id_; |
81 |
guint show_appmenu_idle_id_; |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
82 |
glib::DBusProxy gproxy_; |
1527.5.4
by Marco Trevisan (Treviño)
DBusIndicators: cache locations per each different caller |
83 |
std::map<std::string, EntryLocationMap> cached_locations_; |
1208.2.9
by Tim Penhey
Start a compiler firewall. |
84 |
};
|
85 |
||
86 |
||
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
87 |
// Public Methods
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
88 |
DBusIndicators::Impl::Impl(DBusIndicators* owner) |
89 |
: owner_(owner) |
|
1858.13.2
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
90 |
, reconnect_timeout_id_(0) |
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
91 |
, show_entry_idle_id_(0) |
92 |
, show_appmenu_idle_id_(0) |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
93 |
, gproxy_(SERVICE_NAME, SERVICE_PATH, SERVICE_IFACE, |
1858.13.2
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
94 |
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES) |
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
95 |
{
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
96 |
gproxy_.Connect("ReSync", sigc::mem_fun(this, &DBusIndicators::Impl::OnReSync)); |
97 |
gproxy_.Connect("EntryActivated", sigc::mem_fun(this, &DBusIndicators::Impl::OnEntryActivated)); |
|
98 |
gproxy_.Connect("EntryActivateRequest", sigc::mem_fun(this, &DBusIndicators::Impl::OnEntryActivatedRequest)); |
|
99 |
gproxy_.Connect("EntryShowNowChanged", sigc::mem_fun(this, &DBusIndicators::Impl::OnEntryShowNowChanged)); |
|
100 |
||
101 |
gproxy_.connected.connect(sigc::mem_fun(this, &DBusIndicators::Impl::OnConnected)); |
|
102 |
gproxy_.disconnected.connect(sigc::mem_fun(this, &DBusIndicators::Impl::OnDisconnected)); |
|
103 |
||
104 |
CheckLocalService(); |
|
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
105 |
}
|
106 |
||
1858.13.2
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
107 |
DBusIndicators::Impl::~Impl() |
108 |
{
|
|
109 |
if (reconnect_timeout_id_) |
|
110 |
g_source_remove(reconnect_timeout_id_); |
|
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
111 |
|
112 |
if (show_entry_idle_id_) |
|
113 |
g_source_remove(show_entry_idle_id_); |
|
114 |
||
115 |
if (show_appmenu_idle_id_) |
|
116 |
g_source_remove(show_appmenu_idle_id_); |
|
1858.13.2
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
117 |
}
|
118 |
||
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
119 |
void DBusIndicators::Impl::CheckLocalService() |
1185.6.8
by Tim Penhey
Middle of hacking, need some wrapers. |
120 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
121 |
if (g_getenv("PANEL_USE_LOCAL_SERVICE")) |
702.2.1
by Michael Terry
when the panel-service dies, restart it |
122 |
{
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
123 |
glib::Error error; |
124 |
||
125 |
g_spawn_command_line_sync("killall -9 unity-panel-service", |
|
126 |
nullptr, nullptr, nullptr, nullptr); |
|
127 |
||
128 |
// This is obviously hackish, but this part of the code is mostly hackish...
|
|
129 |
// Let's attempt to run it from where we expect it to be
|
|
130 |
std::string cmd = PREFIXDIR + std::string("/lib/unity/unity-panel-service"); |
|
131 |
std::cerr << "\nWARNING: Couldn't load panel from installed services, " |
|
132 |
<< "so trying to load panel from known location: " |
|
133 |
<< cmd << "\n"; |
|
134 |
||
135 |
g_spawn_command_line_async(cmd.c_str(), &error); |
|
136 |
||
137 |
if (error) |
|
138 |
{
|
|
139 |
std::cerr << "\nWARNING: Unable to launch remote service manually: " |
|
140 |
<< error.Message() << "\n"; |
|
141 |
}
|
|
702.2.1
by Michael Terry
when the panel-service dies, restart it |
142 |
}
|
143 |
}
|
|
144 |
||
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
145 |
void DBusIndicators::Impl::OnConnected() |
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
146 |
{
|
1185.6.10
by Tim Penhey
Almost done... I think. |
147 |
RequestSyncAll(); |
148 |
}
|
|
149 |
||
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
150 |
void DBusIndicators::Impl::OnDisconnected() |
151 |
{
|
|
152 |
for (auto indicator : owner_->GetIndicators()) |
|
153 |
{
|
|
154 |
owner_->RemoveIndicator(indicator->name()); |
|
155 |
}
|
|
156 |
||
1858.12.5
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
157 |
cached_locations_.clear(); |
158 |
||
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
159 |
CheckLocalService(); |
1858.13.2
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
160 |
RequestSyncAll(); |
161 |
||
1858.12.8
by Marco Trevisan (Treviño)
DBusIndicators: avoid to run the reconnect timeout twice. |
162 |
if (reconnect_timeout_id_) |
163 |
g_source_remove(reconnect_timeout_id_); |
|
164 |
||
1858.13.2
by Marco Trevisan (Treviño)
DBusIndicators: sync against DBusProxy changes, add reconnection support here |
165 |
reconnect_timeout_id_ = g_timeout_add_seconds(1, [](gpointer data) -> gboolean { |
166 |
auto self = static_cast<DBusIndicators::Impl*>(data); |
|
167 |
||
168 |
if (!self->gproxy_.IsConnected()) |
|
169 |
{
|
|
170 |
self->RequestSyncAll(); |
|
171 |
return TRUE; |
|
172 |
}
|
|
173 |
||
174 |
self->reconnect_timeout_id_ = 0; |
|
175 |
return FALSE; |
|
176 |
}, this); |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
177 |
}
|
178 |
||
179 |
void DBusIndicators::Impl::OnReSync(GVariant* parameters) |
|
180 |
{
|
|
181 |
glib::String indicator_name; |
|
182 |
g_variant_get(parameters, "(s)", &indicator_name); |
|
183 |
||
184 |
if (indicator_name && !indicator_name.Str().empty()) |
|
185 |
{
|
|
186 |
RequestSyncIndicator(indicator_name); |
|
187 |
}
|
|
188 |
else
|
|
189 |
{
|
|
190 |
RequestSyncAll(); |
|
191 |
}
|
|
192 |
}
|
|
193 |
||
194 |
void DBusIndicators::Impl::OnEntryActivated(GVariant* parameters) |
|
195 |
{
|
|
196 |
glib::String entry_name; |
|
197 |
nux::Rect geo; |
|
198 |
g_variant_get(parameters, "(s(iiuu))", &entry_name, &geo.x, &geo.y, &geo.width, &geo.height); |
|
199 |
||
200 |
if (entry_name) |
|
201 |
owner_->ActivateEntry(entry_name, geo); |
|
202 |
}
|
|
203 |
||
204 |
void DBusIndicators::Impl::OnEntryActivatedRequest(GVariant* parameters) |
|
205 |
{
|
|
206 |
glib::String entry_name; |
|
207 |
g_variant_get(parameters, "(s)", &entry_name); |
|
208 |
||
209 |
if (entry_name) |
|
210 |
owner_->on_entry_activate_request.emit(entry_name); |
|
211 |
}
|
|
212 |
||
213 |
void DBusIndicators::Impl::OnEntryShowNowChanged(GVariant* parameters) |
|
214 |
{
|
|
215 |
glib::String entry_name; |
|
216 |
gboolean show_now; |
|
217 |
g_variant_get(parameters, "(sb)", &entry_name, &show_now); |
|
218 |
||
219 |
if (entry_name) |
|
220 |
owner_->SetEntryShowNow(entry_name, show_now); |
|
221 |
}
|
|
222 |
||
1208.2.9
by Tim Penhey
Start a compiler firewall. |
223 |
void DBusIndicators::Impl::RequestSyncAll() |
1185.6.10
by Tim Penhey
Almost done... I think. |
224 |
{
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
225 |
gproxy_.Call("Sync", nullptr, sigc::mem_fun(this, &DBusIndicators::Impl::Sync)); |
1185.6.10
by Tim Penhey
Almost done... I think. |
226 |
}
|
227 |
||
1208.2.9
by Tim Penhey
Start a compiler firewall. |
228 |
void DBusIndicators::Impl::RequestSyncIndicator(std::string const& name) |
1185.6.10
by Tim Penhey
Almost done... I think. |
229 |
{
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
230 |
GVariant* parameter = g_variant_new("(s)", name.c_str()); |
231 |
||
232 |
gproxy_.Call("SyncOne", parameter, sigc::mem_fun(this, &DBusIndicators::Impl::Sync)); |
|
1185.6.10
by Tim Penhey
Almost done... I think. |
233 |
}
|
234 |
||
235 |
||
1208.2.9
by Tim Penhey
Start a compiler firewall. |
236 |
void DBusIndicators::Impl::OnEntryShowMenu(std::string const& entry_id, |
1858.9.10
by Marco Trevisan (Treviño)
UnityCore: update Entry ShowMenu related methods against the services changes. |
237 |
unsigned int xid, int x, int y, |
238 |
unsigned int button, |
|
239 |
unsigned int timestamp) |
|
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
240 |
{
|
1858.9.13
by Marco Trevisan (Treviño)
DBusIndicators: updated also the on_entry_show_menu signal. |
241 |
owner_->on_entry_show_menu.emit(entry_id, xid, x, y, button, timestamp); |
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
242 |
|
1185.6.10
by Tim Penhey
Almost done... I think. |
243 |
// We have to do this because on certain systems X won't have time to
|
628.2.1
by Neil Jagdish Patel
- Move out asking for the menu to be shown until after the current mainloop run |
244 |
// respond to our request for XUngrabPointer and this will cause the
|
245 |
// menu not to show
|
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
246 |
auto data = new CallData(); |
247 |
data->self = this; |
|
248 |
data->parameters = g_variant_new("(suiiuu)", entry_id.c_str(), xid, x, y, |
|
249 |
button, timestamp); |
|
250 |
||
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
251 |
if (show_entry_idle_id_) |
252 |
g_source_remove(show_entry_idle_id_); |
|
253 |
||
254 |
show_entry_idle_id_ = g_idle_add_full (G_PRIORITY_DEFAULT, [] (gpointer data) -> gboolean { |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
255 |
auto call_data = static_cast<CallData*>(data); |
256 |
call_data->self->gproxy_.Call("ShowEntry", call_data->parameters); |
|
257 |
||
258 |
return FALSE; |
|
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
259 |
}, data, [] (gpointer data) { delete static_cast<CallData*>(data); }); |
1858.10.1
by Marco Trevisan (Treviño)
UnityCore: Implement OnShowAppMenu on DBusIndicators |
260 |
}
|
261 |
||
262 |
void DBusIndicators::Impl::OnShowAppMenu(unsigned int xid, int x, int y, |
|
263 |
unsigned int timestamp) |
|
264 |
{
|
|
265 |
owner_->on_show_appmenu.emit(xid, x, y, timestamp); |
|
266 |
||
267 |
// We have to do this because on certain systems X won't have time to
|
|
268 |
// respond to our request for XUngrabPointer and this will cause the
|
|
269 |
// menu not to show
|
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
270 |
auto data = new CallData(); |
271 |
data->self = this; |
|
272 |
data->parameters = g_variant_new("(uiiu)", xid, x, y, timestamp); |
|
273 |
||
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
274 |
if (show_appmenu_idle_id_) |
275 |
g_source_remove(show_appmenu_idle_id_); |
|
276 |
||
277 |
show_appmenu_idle_id_ = g_idle_add_full (G_PRIORITY_DEFAULT, [] (gpointer data) -> gboolean { |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
278 |
auto call_data = static_cast<CallData*>(data); |
279 |
call_data->self->gproxy_.Call("ShowAppMenu", call_data->parameters); |
|
280 |
||
281 |
return FALSE; |
|
1858.12.9
by Marco Trevisan (Treviño)
DBusIndicators: Use safer idle and move to glib::Variant in CallData |
282 |
}, data, [] (gpointer data) { delete static_cast<CallData*>(data); }); |
572.7.30
by Neil Jagdish Patel
Work around mouse down/up pairing |
283 |
}
|
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
284 |
|
1265.2.6
by Marco Trevisan (Treviño)
Support for seconday activate |
285 |
void DBusIndicators::Impl::OnEntrySecondaryActivate(std::string const& entry_id, |
1265.2.9
by Marco Trevisan (Treviño)
Indicator: Don't use anymore the x,y position on secondary-activation |
286 |
unsigned int timestamp) |
1265.2.6
by Marco Trevisan (Treviño)
Support for seconday activate |
287 |
{
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
288 |
gproxy_.Call("SecondaryActivateEntry", g_variant_new("(su)", entry_id.c_str(), timestamp)); |
1265.2.6
by Marco Trevisan (Treviño)
Support for seconday activate |
289 |
}
|
290 |
||
1208.2.9
by Tim Penhey
Start a compiler firewall. |
291 |
void DBusIndicators::Impl::OnEntryScroll(std::string const& entry_id, int delta) |
1185.6.9
by Tim Penhey
Time to commit. |
292 |
{
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
293 |
gproxy_.Call("ScrollEntry", g_variant_new("(si)", entry_id.c_str(), delta)); |
669.2.3
by Neil Jagdish Patel
Add support for actually showing the menus when requested. Still doesn't work with anything apart from the first menu |
294 |
}
|
295 |
||
1858.12.3
by Marco Trevisan (Treviño)
DBusIndicators: cleaning up |
296 |
void DBusIndicators::Impl::Sync(GVariant* args) |
1185.6.10
by Tim Penhey
Almost done... I think. |
297 |
{
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
298 |
GVariantIter* iter = nullptr; |
299 |
gchar* name_hint = nullptr; |
|
300 |
gchar* indicator_id = nullptr; |
|
301 |
gchar* entry_id = nullptr; |
|
302 |
gchar* label = nullptr; |
|
1088.2.1
by Mirco Müller
initialize values, check for NULL before trying to duplicate, should fix LP: #752293 |
303 |
gboolean label_sensitive = false; |
304 |
gboolean label_visible = false; |
|
305 |
guint32 image_type = 0; |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
306 |
gchar* image_data = nullptr; |
1088.2.1
by Mirco Müller
initialize values, check for NULL before trying to duplicate, should fix LP: #752293 |
307 |
gboolean image_sensitive = false; |
308 |
gboolean image_visible = false; |
|
1351.2.3
by Marco Trevisan (Treviño)
UnityCore: Support for prioritized indicator entries |
309 |
gint32 priority = -1; |
572.7.17
by Neil Jagdish Patel
Some more cleanup |
310 |
|
1088.2.1
by Mirco Müller
initialize values, check for NULL before trying to duplicate, should fix LP: #752293 |
311 |
// sanity check
|
312 |
if (!args) |
|
313 |
return; |
|
314 |
||
1351.2.19
by Marco Trevisan (Treviño)
Better Indicator and Indicators APIs |
315 |
std::map<Indicator::Ptr, Indicator::Entries> indicators; |
1185.6.10
by Tim Penhey
Almost done... I think. |
316 |
|
1351.2.5
by Marco Trevisan (Treviño)
Including name_hint parameter in the IndicatorEntry. |
317 |
g_variant_get(args, "(a(ssssbbusbbi))", &iter); |
318 |
while (g_variant_iter_loop(iter, "(ssssbbusbbi)", |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
319 |
&indicator_id, |
320 |
&entry_id, |
|
1351.2.5
by Marco Trevisan (Treviño)
Including name_hint parameter in the IndicatorEntry. |
321 |
&name_hint, |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
322 |
&label, |
323 |
&label_sensitive, |
|
324 |
&label_visible, |
|
325 |
&image_type, |
|
326 |
&image_data, |
|
327 |
&image_sensitive, |
|
1351.2.3
by Marco Trevisan (Treviño)
UnityCore: Support for prioritized indicator entries |
328 |
&image_visible, |
329 |
&priority)) |
|
1185.6.10
by Tim Penhey
Almost done... I think. |
330 |
{
|
1351.2.19
by Marco Trevisan (Treviño)
Better Indicator and Indicators APIs |
331 |
std::string entry(entry_id); |
332 |
std::string indicator_name(indicator_id); |
|
333 |
||
334 |
Indicator::Ptr indicator = owner_->GetIndicator(indicator_name); |
|
335 |
if (!indicator) |
|
336 |
{
|
|
337 |
indicator = owner_->AddIndicator(indicator_name); |
|
338 |
}
|
|
339 |
||
340 |
Indicator::Entries& entries = indicators[indicator]; |
|
341 |
||
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
342 |
// Null entries (entry_id == "") are empty indicators.
|
1185.6.10
by Tim Penhey
Almost done... I think. |
343 |
if (entry != "") |
344 |
{
|
|
1351.2.19
by Marco Trevisan (Treviño)
Better Indicator and Indicators APIs |
345 |
Entry::Ptr e = indicator->GetEntry(entry_id); |
1351.2.3
by Marco Trevisan (Treviño)
UnityCore: Support for prioritized indicator entries |
346 |
|
347 |
if (!e) |
|
348 |
{
|
|
349 |
e = Entry::Ptr(new Entry(entry, |
|
1351.2.5
by Marco Trevisan (Treviño)
Including name_hint parameter in the IndicatorEntry. |
350 |
name_hint, |
1351.2.3
by Marco Trevisan (Treviño)
UnityCore: Support for prioritized indicator entries |
351 |
label, |
352 |
label_sensitive, |
|
353 |
label_visible, |
|
354 |
image_type, |
|
355 |
image_data, |
|
356 |
image_sensitive, |
|
357 |
image_visible, |
|
358 |
priority)); |
|
359 |
}
|
|
360 |
else
|
|
361 |
{
|
|
362 |
e->setLabel(label, label_sensitive, label_visible); |
|
363 |
e->setImage(image_type, image_data, image_sensitive, image_visible); |
|
364 |
e->setPriority(priority); |
|
365 |
}
|
|
366 |
||
1185.6.10
by Tim Penhey
Almost done... I think. |
367 |
entries.push_back(e); |
368 |
}
|
|
369 |
}
|
|
370 |
g_variant_iter_free(iter); |
|
371 |
||
1351.2.3
by Marco Trevisan (Treviño)
UnityCore: Support for prioritized indicator entries |
372 |
for (auto i = indicators.begin(), end = indicators.end(); i != end; ++i) |
1185.6.10
by Tim Penhey
Almost done... I think. |
373 |
{
|
1351.2.19
by Marco Trevisan (Treviño)
Better Indicator and Indicators APIs |
374 |
i->first->Sync(indicators[i->first]); |
1185.6.10
by Tim Penhey
Almost done... I think. |
375 |
}
|
376 |
||
377 |
// Notify listeners we have new data
|
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
378 |
owner_->on_synced.emit(); |
572.1.11
by Neil Jagdish Patel
Import the work done so far with Compiz |
379 |
}
|
380 |
||
1208.2.11
by Tim Penhey
Move the variant creation into the bowels of the DBusIndicator. |
381 |
void DBusIndicators::Impl::SyncGeometries(std::string const& name, |
382 |
EntryLocationMap const& locations) |
|
1185.6.15
by Tim Penhey
More refactoring of the PanelView. |
383 |
{
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
384 |
if (!gproxy_.IsConnected()) |
1208.2.11
by Tim Penhey
Move the variant creation into the bowels of the DBusIndicator. |
385 |
return; |
386 |
||
387 |
GVariantBuilder b; |
|
1527.5.4
by Marco Trevisan (Treviño)
DBusIndicators: cache locations per each different caller |
388 |
bool found_changed_locations = false; |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
389 |
g_variant_builder_init(&b, G_VARIANT_TYPE("(a(ssiiii))")); |
390 |
g_variant_builder_open(&b, G_VARIANT_TYPE("a(ssiiii)")); |
|
1527.5.4
by Marco Trevisan (Treviño)
DBusIndicators: cache locations per each different caller |
391 |
EntryLocationMap& cached_loc = cached_locations_[name]; |
1208.2.11
by Tim Penhey
Move the variant creation into the bowels of the DBusIndicator. |
392 |
|
1527.5.3
by Marco Trevisan (Treviño)
DBusIndicators: don't spam the service, just send really changed geometries |
393 |
// Only send to panel service the geometries of items that have changed
|
394 |
for (auto i = locations.begin(), end = locations.end(); i != end; ++i) |
|
395 |
{
|
|
396 |
auto rect = i->second; |
|
397 |
||
1527.5.5
by Marco Trevisan (Treviño)
DBusIndicators: re-use computed rect value. |
398 |
if (cached_loc[i->first] != rect) |
1527.5.3
by Marco Trevisan (Treviño)
DBusIndicators: don't spam the service, just send really changed geometries |
399 |
{
|
400 |
g_variant_builder_add(&b, "(ssiiii)", |
|
401 |
name.c_str(), |
|
402 |
i->first.c_str(), |
|
403 |
rect.x, |
|
404 |
rect.y, |
|
405 |
rect.width, |
|
406 |
rect.height); |
|
407 |
found_changed_locations = true; |
|
408 |
}
|
|
409 |
}
|
|
410 |
||
411 |
// Inform panel service of the entries that have been removed sending invalid values
|
|
1527.5.4
by Marco Trevisan (Treviño)
DBusIndicators: cache locations per each different caller |
412 |
for (auto i = cached_loc.begin(), end = cached_loc.end(); i != end; ++i) |
1527.5.3
by Marco Trevisan (Treviño)
DBusIndicators: don't spam the service, just send really changed geometries |
413 |
{
|
414 |
if (locations.find(i->first) == locations.end()) |
|
415 |
{
|
|
416 |
g_variant_builder_add(&b, "(ssiiii)", |
|
417 |
name.c_str(), |
|
418 |
i->first.c_str(), |
|
419 |
0, |
|
420 |
0, |
|
421 |
-1, |
|
422 |
-1); |
|
423 |
found_changed_locations = true; |
|
424 |
}
|
|
425 |
}
|
|
426 |
||
427 |
if (!found_changed_locations) |
|
1938.1.1
by Sven Baars
Always free the created GVariantBuilder before return |
428 |
{
|
429 |
g_variant_builder_clear(&b); |
|
1527.5.3
by Marco Trevisan (Treviño)
DBusIndicators: don't spam the service, just send really changed geometries |
430 |
return; |
1938.1.1
by Sven Baars
Always free the created GVariantBuilder before return |
431 |
}
|
1208.2.11
by Tim Penhey
Move the variant creation into the bowels of the DBusIndicator. |
432 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
433 |
g_variant_builder_close(&b); |
1527.5.3
by Marco Trevisan (Treviño)
DBusIndicators: don't spam the service, just send really changed geometries |
434 |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
435 |
gproxy_.Call("SyncGeometries", g_variant_builder_end(&b)); |
1527.5.4
by Marco Trevisan (Treviño)
DBusIndicators: cache locations per each different caller |
436 |
cached_loc = locations; |
1185.6.15
by Tim Penhey
More refactoring of the PanelView. |
437 |
}
|
438 |
||
1208.2.9
by Tim Penhey
Start a compiler firewall. |
439 |
DBusIndicators::DBusIndicators() |
440 |
: pimpl(new Impl(this)) |
|
1858.9.184
by Marco Trevisan (Treviño)
DBusIndicators: use glib::Object to handle the dbus proxy, so we have ref-counting for free |
441 |
{}
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
442 |
|
443 |
DBusIndicators::~DBusIndicators() |
|
1858.12.2
by Marco Trevisan (Treviño)
DBusIndicators: code rewritten to make it use glib::DBusProxy |
444 |
{}
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
445 |
|
1208.2.11
by Tim Penhey
Move the variant creation into the bowels of the DBusIndicator. |
446 |
void DBusIndicators::SyncGeometries(std::string const& name, |
447 |
EntryLocationMap const& locations) |
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
448 |
{
|
1208.2.11
by Tim Penhey
Move the variant creation into the bowels of the DBusIndicator. |
449 |
pimpl->SyncGeometries(name, locations); |
1208.2.9
by Tim Penhey
Start a compiler firewall. |
450 |
}
|
451 |
||
452 |
void DBusIndicators::OnEntryScroll(std::string const& entry_id, int delta) |
|
453 |
{
|
|
454 |
pimpl->OnEntryScroll(entry_id, delta); |
|
455 |
}
|
|
456 |
||
457 |
void DBusIndicators::OnEntryShowMenu(std::string const& entry_id, |
|
1858.9.10
by Marco Trevisan (Treviño)
UnityCore: update Entry ShowMenu related methods against the services changes. |
458 |
unsigned int xid, int x, int y, |
459 |
unsigned int button, unsigned int timestamp) |
|
1208.2.9
by Tim Penhey
Start a compiler firewall. |
460 |
{
|
1858.9.10
by Marco Trevisan (Treviño)
UnityCore: update Entry ShowMenu related methods against the services changes. |
461 |
pimpl->OnEntryShowMenu(entry_id, xid, x, y, button, timestamp); |
1208.2.9
by Tim Penhey
Start a compiler firewall. |
462 |
}
|
463 |
||
1265.2.6
by Marco Trevisan (Treviño)
Support for seconday activate |
464 |
void DBusIndicators::OnEntrySecondaryActivate(std::string const& entry_id, |
1265.2.9
by Marco Trevisan (Treviño)
Indicator: Don't use anymore the x,y position on secondary-activation |
465 |
unsigned int timestamp) |
1265.2.6
by Marco Trevisan (Treviño)
Support for seconday activate |
466 |
{
|
1265.2.9
by Marco Trevisan (Treviño)
Indicator: Don't use anymore the x,y position on secondary-activation |
467 |
pimpl->OnEntrySecondaryActivate(entry_id, timestamp); |
1265.2.6
by Marco Trevisan (Treviño)
Support for seconday activate |
468 |
}
|
469 |
||
1858.9.19
by Marco Trevisan (Treviño)
UnityCore: Implement OnShowAppMenu on DBusIndicators |
470 |
void DBusIndicators::OnShowAppMenu(unsigned int xid, int x, int y, |
471 |
unsigned int timestamp) |
|
472 |
{
|
|
473 |
pimpl->OnShowAppMenu(xid, x, y, timestamp); |
|
474 |
}
|
|
475 |
||
1185.6.8
by Tim Penhey
Middle of hacking, need some wrapers. |
476 |
} // namespace indicator |
477 |
} // namespace unity |