summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-09-08 00:44:32 +0200
committerLennart Poettering <lennart@poettering.net>2007-09-08 00:44:32 +0200
commitbb6f4086df4ede00ba2048be08ac08cbbcf90649 (patch)
treeef238174c288a381bf45f5264cd292577950defa
parent7e2e7661c325718982387c3355d4f929e4025ec7 (diff)
Show a status icon in the tray and show notifications on it whenever a node connects
-rw-r--r--Makefile6
-rw-r--r--lassi-server.c47
-rw-r--r--lassi-server.h3
-rw-r--r--lassi-tray.c73
-rw-r--r--lassi-tray.h31
5 files changed, 156 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index d4f9749..fba1929 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
-CFLAGS=-Wall -Wextra -W -O0 -g -pipe -Wno-unused-parameter `pkg-config --cflags dbus-glib-1 glib-2.0 gtk+-2.0 xtst avahi-glib avahi-client avahi-ui`
-LIBS=`pkg-config --libs dbus-glib-1 glib-2.0 gtk+-2.0 xtst avahi-glib avahi-client avahi-ui`
+CFLAGS=-Wall -Wextra -W -O0 -g -pipe -Wno-unused-parameter `pkg-config --cflags dbus-glib-1 glib-2.0 gtk+-2.0 xtst avahi-glib avahi-client avahi-ui libnotify`
+LIBS=`pkg-config --libs dbus-glib-1 glib-2.0 gtk+-2.0 xtst avahi-glib avahi-client avahi-ui libnotify`
-mango-lassi: lassi-server.o lassi-grab.o lassi-osd.o lassi-order.o lassi-clipboard.o lassi-avahi.o *.h
+mango-lassi: lassi-server.o lassi-grab.o lassi-osd.o lassi-order.o lassi-clipboard.o lassi-avahi.o lassi-tray.o *.h
$(CC) $^ -o $@ $(LIBS) $(CFLAGS)
clean:
diff --git a/lassi-server.c b/lassi-server.c
index 7584d95..77a76da 100644
--- a/lassi-server.c
+++ b/lassi-server.c
@@ -17,6 +17,7 @@
#include "lassi-order.h"
#include "lassi-clipboard.h"
#include "lassi-avahi.h"
+#include "lassi-tray.h"
#define LASSI_INTERFACE "org.gnome.MangoLassi"
@@ -356,6 +357,30 @@ int lassi_server_key_event(LassiServer *ls, unsigned key, gboolean is_press) {
return 0;
}
+static void show_welcome(LassiConnection *lc, gboolean connect) {
+ gboolean to_left;
+ LassiServer *ls;
+ char *summary, *body;
+
+ g_assert(lc);
+
+ ls = lc->server;
+ to_left = !!g_list_find(ls->connections_left, lc);
+
+ if (connect) {
+ summary = g_strdup_printf("%s now shares input with this desktop", lc->id);
+ body = g_strdup_printf("You're now sharing keyboard and mouse with <b>%s</b> which is located to the <b>%s</b>.", lc->id, to_left ? "left" : "right");
+ } else {
+ summary = g_strdup_printf("%s no longer shares input with this desktop", lc->id);
+ body = g_strdup_printf("You're no longer sharing keyboard and mouse with <b>%s</b> which was located to the <b>%s</b>.", lc->id, to_left ? "left" : "right");
+ }
+
+ lassi_tray_show_notification(&ls->tray_info, summary, body, to_left ? LASSI_TRAY_NOTIFICATION_LEFT : LASSI_TRAY_NOTIFICATION_RIGHT);
+
+ g_free(summary);
+ g_free(body);
+}
+
static void connection_unlink(LassiConnection *lc) {
DBusMessage *n;
dbus_bool_t b;
@@ -370,6 +395,8 @@ static void connection_unlink(LassiConnection *lc) {
ls->n_connections --;
if (lc->id) {
+ show_welcome(lc, FALSE);
+
g_hash_table_remove(ls->connections_by_id, lc->id);
ls->connections_left = g_list_remove(ls->connections_left, lc);
ls->connections_right = g_list_remove(ls->connections_right, lc);
@@ -402,6 +429,8 @@ static void connection_unlink(LassiConnection *lc) {
server_layout_changed(ls, -1);
server_dump(ls);
}
+
+ lassi_tray_update(&ls->tray_info, ls->n_connections);
connection_destroy(lc);
}
@@ -693,7 +722,11 @@ static int signal_hello(LassiConnection *lc, DBusMessage *m) {
if (lc->we_are_client) {
server_send_update_grab(lc->server, -1);
server_send_update_order(lc->server, NULL);
- }
+
+ lc->delayed_welcome = FALSE;
+ show_welcome(lc, TRUE);
+ } else
+ lc->delayed_welcome = TRUE;
server_layout_changed(lc->server, -1);
@@ -899,6 +932,11 @@ finish:
lassi_list_free(new_order);
lassi_list_free(merged_order);
+
+ if (lc->delayed_welcome) {
+ lc->delayed_welcome = FALSE;
+ show_welcome(lc, TRUE);
+ }
return r;
}
@@ -1237,6 +1275,7 @@ static LassiConnection* connection_add(LassiServer *ls, DBusConnection *c, gbool
lc->server = ls;
lc->id = lc->address = NULL;
lc->we_are_client = we_are_client;
+ lc->delayed_welcome = FALSE;
ls->connections = g_list_prepend(ls->connections, lc);
ls->n_connections++;
@@ -1274,6 +1313,7 @@ static LassiConnection* connection_add(LassiServer *ls, DBusConnection *c, gbool
dbus_message_unref(m);
+ lassi_tray_update(&ls->tray_info, ls->n_connections);
return lc;
}
@@ -1349,6 +1389,9 @@ static int server_init(LassiServer *ls) {
if (lassi_avahi_init(&ls->avahi_info, ls) < 0)
goto finish;
+ if (lassi_tray_init(&ls->tray_info, ls) < 0)
+ goto finish;
+
r = 0;
finish:
@@ -1384,6 +1427,8 @@ static void server_done(LassiServer *ls) {
lassi_grab_done(&ls->grab_info);
lassi_osd_done(&ls->osd_info);
lassi_clipboard_done(&ls->clipboard_info);
+ lassi_avahi_done(&ls->avahi_info);
+ lassi_tray_done(&ls->tray_info);
memset(ls, 0, sizeof(*ls));
}
diff --git a/lassi-server.h b/lassi-server.h
index b6117ae..411c06f 100644
--- a/lassi-server.h
+++ b/lassi-server.h
@@ -11,6 +11,7 @@ typedef struct LassiConnection LassiConnection;
#include "lassi-osd.h"
#include "lassi-clipboard.h"
#include "lassi-avahi.h"
+#include "lassi-tray.h"
struct LassiServer {
DBusServer *dbus_server;
@@ -48,6 +49,7 @@ struct LassiServer {
LassiOsdInfo osd_info;
LassiClipboardInfo clipboard_info;
LassiAvahiInfo avahi_info;
+ LassiTrayInfo tray_info;
};
struct LassiConnection {
@@ -57,6 +59,7 @@ struct LassiConnection {
char *id, *address;
gboolean we_are_client;
+ gboolean delayed_welcome;
};
int lassi_server_change_grab(LassiServer *s, gboolean to_left, int y);
diff --git a/lassi-tray.c b/lassi-tray.c
new file mode 100644
index 0000000..8ab8afb
--- /dev/null
+++ b/lassi-tray.c
@@ -0,0 +1,73 @@
+#include <gtk/gtk.h>
+
+#include <libnotify/notify.h>
+
+#include <string.h>
+
+#include "lassi-tray.h"
+#include "lassi-server.h"
+
+#define ICON_IDLE "network-wired"
+#define ICON_BUSY "network-workgroup"
+
+int lassi_tray_init(LassiTrayInfo *i, LassiServer *server) {
+ g_assert(i);
+ g_assert(server);
+
+ memset(i, 0, sizeof(*i));
+ i->server = server;
+
+ notify_init("Mango Lassi");
+
+ i->status_icon = gtk_status_icon_new_from_icon_name(ICON_IDLE);
+
+ lassi_tray_update(i, 0);
+
+ return 0;
+}
+
+void lassi_tray_update(LassiTrayInfo *i, int n_connected) {
+ char *t;
+ g_assert(i);
+
+ gtk_status_icon_set_from_icon_name(i->status_icon, n_connected > 0 ? ICON_BUSY : ICON_IDLE);
+
+ if (n_connected == 0)
+ t = g_strdup("No desktops connected.");
+ else if (n_connected == 1)
+ t = g_strdup("1 desktop connected.");
+ else
+ t = g_strdup_printf("%i desktops connected.", n_connected);
+
+ gtk_status_icon_set_tooltip(i->status_icon, t);
+
+ g_free(t);
+}
+
+void lassi_tray_show_notification(LassiTrayInfo *i, char *summary, char *body, LassiTrayNotificationIcon icon) {
+
+ static const char * const icon_name[] = {
+ [LASSI_TRAY_NOTIFICATION_WELCOME] = "user-desktop",
+ [LASSI_TRAY_NOTIFICATION_LEFT] = "go-previous",
+ [LASSI_TRAY_NOTIFICATION_RIGHT] = "go-next"
+ };
+
+ NotifyNotification *n;
+
+ n = notify_notification_new_with_status_icon(summary, body, icon_name[icon], i->status_icon);
+ notify_notification_set_timeout(n, 10000);
+ notify_notification_set_urgency(n, NOTIFY_URGENCY_LOW);
+ notify_notification_set_category(n, "network");
+ notify_notification_show(n, NULL);
+
+}
+
+void lassi_tray_done(LassiTrayInfo *i) {
+ g_assert(i);
+
+ g_object_unref(G_OBJECT(i->status_icon));
+
+ notify_uninit();
+
+ memset(i, 0, sizeof(*i));
+}
diff --git a/lassi-tray.h b/lassi-tray.h
new file mode 100644
index 0000000..9d056bc
--- /dev/null
+++ b/lassi-tray.h
@@ -0,0 +1,31 @@
+#ifndef foolassitrayhfoo
+#define foolassitrayhfoo
+
+#include <gtk/gtk.h>
+#include <libnotify/notification.h>
+
+typedef struct LassiTrayInfo LassiTrayInfo;
+struct LassiServer;
+
+typedef enum LassiTrayNotificationIcon {
+ LASSI_TRAY_NOTIFICATION_WELCOME,
+ LASSI_TRAY_NOTIFICATION_LEFT,
+ LASSI_TRAY_NOTIFICATION_RIGHT
+} LassiTrayNotificationIcon;
+
+struct LassiTrayInfo {
+ struct LassiServer *server;
+
+ GtkStatusIcon *status_icon;
+};
+
+#include "lassi-server.h"
+
+int lassi_tray_init(LassiTrayInfo *i, LassiServer *server);
+void lassi_tray_done(LassiTrayInfo *i);
+void lassi_tray_update(LassiTrayInfo *i, int n_connected);
+
+void lassi_tray_show_notification(LassiTrayInfo *i, char *summary, char *body, LassiTrayNotificationIcon icon);
+
+
+#endif