1
1
/*
2
2
* $Id: ede-panel.cpp 3330 2012-05-28 10:57:50Z karijes $
3
3
*
4
- * Copyright (C) 2012 Sanel Zukan
4
+ * Copyright (C) 2012-2014 Sanel Zukan
5
5
*
6
6
* This program is free software; you can redistribute it and/or
7
7
* modify it under the terms of the GNU General Public License
@@ -83,7 +83,8 @@ static bool server_running;
83
83
* list of server capabilities
84
84
* check all available on: http://people.gnome.org/~mccann/docs/notification-spec/notification-spec-latest.html
85
85
*/
86
- static const char *server_caps[] = {" actions" , " body" , " icon-static" , 0 };
86
+ // static const char *server_caps[] = {"actions", "body", "icon-static", 0};
87
+ static const char *server_caps[] = {" body" , " icon-static" , 0 };
87
88
88
89
/* increased every time new notification window is shown; must be less than UINT_MAX */
89
90
static unsigned int notify_id;
@@ -128,22 +129,40 @@ static bool get_int_coordinate(const char *n, EdbusDict &hints, int &c) {
128
129
return true ;
129
130
}
130
131
131
- static void show_window (unsigned int id,
132
- const char *app_name,
133
- const char *app_icon,
134
- const char *summary,
135
- const char *body,
136
- int expire_timeout,
137
- EdbusDict &hints)
132
+ static void show_or_update_window (bool update_only,
133
+ unsigned int id,
134
+ const char *app_name,
135
+ const char *app_icon,
136
+ const char *summary,
137
+ const char *body,
138
+ int expire_timeout,
139
+ EdbusDict &hints)
138
140
{
139
141
byte_t u = get_urgency_level (hints);
142
+ NotifyWindow *win = NULL ;
140
143
141
- NotifyWindow *win = new NotifyWindow ();
144
+ if (update_only) {
145
+ E_DEBUG (E_STRLOC " : Requesting update\n " );
146
+ /* try to find existing window with given id */
147
+ Fl_Window *wi;
148
+ NotifyWindow *tmp;
149
+
150
+ for (wi = Fl::first_window (); wi; wi = Fl::next_window (wi)) {
151
+ if (wi->type () != NOTIFYWINDOW_TYPE) continue ;
152
+ tmp = (NotifyWindow*)wi;
153
+ if (tmp->get_id () == id) {
154
+ E_DEBUG (E_STRLOC " : Requesting update - win found\n " );
155
+ win = tmp;
156
+ break ;
157
+ }
158
+ }
159
+ }
160
+
161
+ /* window not found or new window requested */
162
+ if (!win) win = new NotifyWindow ();
142
163
143
- if (!empty_str (summary))
144
- win->set_summary (summary);
145
- if (!empty_str (body))
146
- win->set_body (body);
164
+ if (!empty_str (summary)) win->set_summary (summary);
165
+ if (!empty_str (body)) win->set_body (body);
147
166
if (empty_str (app_icon)) {
148
167
switch (u) {
149
168
case URGENCY_CRITICAL:
@@ -158,7 +177,7 @@ static void show_window(unsigned int id,
158
177
159
178
win->set_icon (app_icon);
160
179
win->set_id (id);
161
- win->set_expire (expire_timeout);
180
+ win->set_expire (expire_timeout, update_only );
162
181
163
182
/* according to spec, both coordinates must exist so window can be positioned as desired */
164
183
int X, Y;
@@ -198,7 +217,8 @@ static void show_window(unsigned int id,
198
217
}
199
218
200
219
/* we are already running loop, so window will handle events */
201
- win->show ();
220
+ if (!win->shown ())
221
+ win->show ();
202
222
}
203
223
204
224
static int handle_notify (EdbusConnection *dbus, const EdbusMessage *m) {
@@ -209,7 +229,7 @@ static int handle_notify(EdbusConnection *dbus, const EdbusMessage *m) {
209
229
210
230
const char *app_name, *app_icon, *summary, *body;
211
231
app_name = app_icon = summary = body = NULL ;
212
- unsigned int replaces_id;
232
+ unsigned int replaces_id, id ;
213
233
int expire_timeout;
214
234
215
235
EdbusMessage::const_iterator it = m->begin ();
@@ -246,19 +266,33 @@ static int handle_notify(EdbusConnection *dbus, const EdbusMessage *m) {
246
266
E_RETURN_VAL_IF_FAIL (it->is_int32 (), 0 );
247
267
expire_timeout = it->to_int32 ();
248
268
249
- /* specification dumb stuff: what if we got UINT_MAX?? here we will reverse to first ID */
250
- if (++notify_id == UINT_MAX) notify_id = 1 ;
269
+ if (replaces_id > 0 ) {
270
+ id = replaces_id;
271
+ } else {
272
+ /* by the spec, if we got MAX, reversing will be just fine */
273
+ if (++notify_id == UINT_MAX) notify_id = 1 ;
274
+ id = notify_id;
275
+ }
251
276
277
+ /* this should never happen */
278
+ E_RETURN_VAL_IF_FAIL (id != 0 , 0 );
279
+
280
+ show_or_update_window (replaces_id > 0 , id,
281
+ app_name, app_icon, summary, body, expire_timeout, hints);
282
+ #if 0
252
283
if(replaces_id) {
253
- // replaces_id == notify_id;
284
+ update_window(replaces_id, app_name, app_icon, summary, body, expire_timeout, hints);
285
+ sent_id = replaces_id;
254
286
} else {
255
287
show_window(notify_id, app_name, app_icon, summary, body, expire_timeout, hints);
288
+ sent_id = notify_id;
256
289
}
290
+ #endif
257
291
258
- /* reply sent to client */
292
+ /* reply sent to client, with used window id */
259
293
EdbusMessage reply;
260
294
reply.create_reply (*m);
261
- reply << EdbusData::from_uint32 (replaces_id );
295
+ reply << EdbusData::from_uint32 (id );
262
296
dbus->send (reply);
263
297
264
298
return 1 ;
@@ -357,7 +391,6 @@ int main(int argc, char **argv) {
357
391
358
392
dbus.register_object (NOTIFICATIONS_DBUS_PATH);
359
393
dbus.method_callback (notifications_dbus_method_cb, &dbus);
360
- // dbus.signal_callback(notifications_dbus_signal_cb, &dbus);
361
394
dbus.setup_listener_with_fltk ();
362
395
server_running = true ;
363
396
0 commit comments