[Galago-commits] r2539 - in trunk/notification-daemon: . src themes/standard

galago-commits at freedesktop.org galago-commits at freedesktop.org
Sat Feb 4 12:26:01 PST 2006


Author: chipx86
Date: 2006-02-04 12:25:57 -0800 (Sat, 04 Feb 2006)
New Revision: 2539

Modified:
   trunk/notification-daemon/ChangeLog
   trunk/notification-daemon/src/daemon.c
   trunk/notification-daemon/src/engines.c
   trunk/notification-daemon/src/engines.h
   trunk/notification-daemon/themes/standard/theme.c
Log:
Add a pie-based countdown timer to notifications containing actions, so that the user knows how long they have until the notification simply expires.


Modified: trunk/notification-daemon/ChangeLog
===================================================================
--- trunk/notification-daemon/ChangeLog	2006-02-04 10:04:49 UTC (rev 2538)
+++ trunk/notification-daemon/ChangeLog	2006-02-04 20:25:57 UTC (rev 2539)
@@ -1,3 +1,13 @@
+Sat Feb 04 12:24:32 PST 2006  Christian Hammond <chipx86 at chipx86.com>
+
+	* src/daemon.c:
+	* src/engines.c:
+	* src/engines.h:
+	* themes/standard/theme.c:
+	  - Add a pie-based countdown timer to notifications containing actions,
+	    so that the user knows how long they have until the notification
+	    simply expires.
+
 Sat Feb 04 02:04:35 PST 2006  Christian Hammond <chipx86 at chipx86.com>
 
 	* themes/standard/theme.c:

Modified: trunk/notification-daemon/src/daemon.c
===================================================================
--- trunk/notification-daemon/src/daemon.c	2006-02-04 10:04:49 UTC (rev 2538)
+++ trunk/notification-daemon/src/daemon.c	2006-02-04 20:25:57 UTC (rev 2539)
@@ -269,6 +269,9 @@
 
 	g_get_current_time(&now);
 
+	theme_notification_tick(nt->nw,
+							(nt->expiration.tv_sec - now.tv_sec) * 1000);
+
 	if (now.tv_sec > nt->expiration.tv_sec ||
 		(now.tv_sec == nt->expiration.tv_sec &&
 		 now.tv_usec >= nt->expiration.tv_usec))
@@ -311,6 +314,8 @@
 		if (timeout == -1)
 			timeout = NOTIFY_DAEMON_DEFAULT_TIMEOUT;
 
+		theme_set_notification_timeout(nt->nw, timeout);
+
 		usec = timeout * 1000;	/* convert from msec to usec */
 		g_get_current_time(&nt->expiration);
 		g_time_val_add(&nt->expiration, usec);

Modified: trunk/notification-daemon/src/engines.c
===================================================================
--- trunk/notification-daemon/src/engines.c	2006-02-04 10:04:49 UTC (rev 2538)
+++ trunk/notification-daemon/src/engines.c	2006-02-04 20:25:57 UTC (rev 2539)
@@ -22,6 +22,8 @@
 	void (*add_notification_action)(GtkWindow *nw, const char *label,
 									const char *key, GCallback cb);
 	void (*move_notification)(GtkWindow *nw, int x, int y);
+	void (*set_notification_timeout)(GtkWindow *nw, guint timeout);
+	void (*notification_tick)(GtkWindow *nw, guint timeout);
 
 } ThemeEngine;
 
@@ -62,6 +64,9 @@
 		g_free(engine); \
 	}
 
+#define BIND_OPTIONAL_FUNC(name) \
+	g_module_symbol(engine->module, #name, (gpointer *)&engine->name);
+
 	BIND_REQUIRED_FUNC(create_notification);
 	BIND_REQUIRED_FUNC(destroy_notification);
 	BIND_REQUIRED_FUNC(show_notification);
@@ -72,6 +77,8 @@
 	BIND_REQUIRED_FUNC(set_notification_arrow);
 	BIND_REQUIRED_FUNC(add_notification_action);
 	BIND_REQUIRED_FUNC(move_notification);
+	BIND_OPTIONAL_FUNC(set_notification_timeout);
+	BIND_OPTIONAL_FUNC(notification_tick);
 
 	return engine;
 }
@@ -193,6 +200,24 @@
 }
 
 void
+theme_set_notification_timeout(GtkWindow *nw, guint timeout)
+{
+	ThemeEngine *engine = g_object_get_data(G_OBJECT(nw), "_theme_engine");
+
+	if (engine->set_notification_timeout != NULL)
+		engine->set_notification_timeout(nw, timeout);
+}
+
+void
+theme_notification_tick(GtkWindow *nw, guint remaining)
+{
+	ThemeEngine *engine = g_object_get_data(G_OBJECT(nw), "_theme_engine");
+
+	if (engine->notification_tick != NULL)
+		engine->notification_tick(nw, remaining);
+}
+
+void
 theme_set_notification_text(GtkWindow *nw, const char *summary,
 							const char *body)
 {

Modified: trunk/notification-daemon/src/engines.h
===================================================================
--- trunk/notification-daemon/src/engines.h	2006-02-04 10:04:49 UTC (rev 2538)
+++ trunk/notification-daemon/src/engines.h	2006-02-04 20:25:57 UTC (rev 2539)
@@ -10,6 +10,8 @@
 void theme_show_notification(GtkWindow *nw);
 void theme_hide_notification(GtkWindow *nw);
 void theme_set_notification_hints(GtkWindow *nw, GHashTable *hints);
+void theme_set_notification_timeout(GtkWindow *nw, guint timeout);
+void theme_notification_tick(GtkWindow *nw, guint remaining);
 void theme_set_notification_text(GtkWindow *nw, const char *summary,
 								 const char *body);
 void theme_set_notification_icon(GtkWindow *nw, GdkPixbuf *pixbuf);

Modified: trunk/notification-daemon/themes/standard/theme.c
===================================================================
--- trunk/notification-daemon/themes/standard/theme.c	2006-02-04 10:04:49 UTC (rev 2538)
+++ trunk/notification-daemon/themes/standard/theme.c	2006-02-04 20:25:57 UTC (rev 2539)
@@ -7,6 +7,7 @@
 
 typedef struct
 {
+	GtkWidget *win;
 	GtkWidget *top_spacer;
 	GtkWidget *bottom_spacer;
 	GtkWidget *main_hbox;
@@ -18,6 +19,7 @@
 	GtkWidget *actions_box;
 	GtkWidget *last_sep;
 	GtkWidget *stripe_spacer;
+	GtkWidget *pie_countdown;
 
 	gboolean has_arrow;
 
@@ -37,6 +39,8 @@
 	GdkRegion *window_region;
 
 	guchar urgency;
+	guint timeout;
+	guint remaining;
 
 	UrlClickedCb url_clicked;
 
@@ -53,6 +57,8 @@
 #define IMAGE_SIZE    32
 #define IMAGE_PADDING 10
 #define STRIPE_WIDTH  25
+#define PIE_WIDTH     24
+#define PIE_HEIGHT    24
 #define BODY_X_OFFSET (IMAGE_SIZE + 8)
 #define DEFAULT_ARROW_OFFSET  (STRIPE_WIDTH + 2)
 #define DEFAULT_ARROW_HEIGHT  14
@@ -191,6 +197,7 @@
 	windata->url_clicked = url_clicked;
 
 	win = gtk_window_new(GTK_WINDOW_POPUP);
+	windata->win = win;
 	gtk_widget_add_events(win, GDK_BUTTON_RELEASE_MASK);
 	gtk_widget_realize(win);
 	g_object_set_data_full(G_OBJECT(win), "windata", windata,
@@ -323,6 +330,28 @@
 }
 
 void
+set_notification_timeout(GtkWindow *nw, guint timeout)
+{
+	WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata");
+	g_assert(windata != NULL);
+
+	windata->timeout = timeout;
+}
+
+void
+notification_tick(GtkWindow *nw, guint remaining)
+{
+	WindowData *windata = g_object_get_data(G_OBJECT(nw), "windata");
+	windata->remaining = remaining;
+
+	if (windata->pie_countdown != NULL)
+	{
+		gtk_widget_queue_draw_area(windata->pie_countdown, 0, 0,
+								   PIE_WIDTH, PIE_HEIGHT);
+	}
+}
+
+void
 set_notification_text(GtkWindow *nw, const char *summary, const char *body)
 {
 	char *str;
@@ -391,6 +420,30 @@
 	}
 }
 
+static gboolean
+countdown_expose_cb(GtkWidget *pie, GdkEventExpose *event,
+					WindowData *windata)
+{
+	GtkStyle *style = gtk_widget_get_style(windata->win);
+	GdkGC *bg_gc = style->base_gc[GTK_STATE_NORMAL];
+
+	gdk_draw_rectangle(GDK_DRAWABLE(pie->window), bg_gc, TRUE,
+					   0, 0, pie->allocation.width, pie->allocation.height);
+
+	if (windata->timeout > 0)
+	{
+		GdkGC *pie_gc = style->bg_gc[GTK_STATE_NORMAL];
+		gdouble pct = (gdouble)windata->remaining / (gdouble)windata->timeout;
+
+		gdk_draw_arc(GDK_DRAWABLE(windata->pie_countdown->window),
+					 pie_gc, TRUE,
+					 0, 0, PIE_WIDTH, PIE_HEIGHT,
+					 90 * 64, pct * 360.0 * 64.0);
+	}
+
+	return TRUE;
+}
+
 static void
 action_clicked_cb(GtkWidget *w, GdkEventButton *event,
 				  ActionInvokedCb action_cb)
@@ -418,6 +471,15 @@
 	{
 		gtk_widget_show(windata->actions_box);
 		update_content_hbox_visibility(windata);
+
+		windata->pie_countdown = gtk_drawing_area_new();
+		gtk_widget_show(windata->pie_countdown);
+		gtk_box_pack_end(GTK_BOX(windata->actions_box), windata->pie_countdown,
+						 FALSE, FALSE, 0);
+		gtk_widget_set_size_request(windata->pie_countdown,
+									PIE_WIDTH, PIE_HEIGHT);
+		g_signal_connect(G_OBJECT(windata->pie_countdown), "expose_event",
+						 G_CALLBACK(countdown_expose_cb), windata);
 	}
 
 	button = gtk_button_new();



More information about the galago-commits mailing list