[Galago-commits] r2495 - in trunk/notification-daemon: . src

galago-commits at freedesktop.org galago-commits at freedesktop.org
Wed Jan 25 00:07:56 PST 2006


Author: chipx86
Date: 2006-01-25 00:07:54 -0800 (Wed, 25 Jan 2006)
New Revision: 2495

Modified:
   trunk/notification-daemon/ChangeLog
   trunk/notification-daemon/configure.ac
   trunk/notification-daemon/src/daemon.c
Log:
Don't pop up a notification if a window is full screen or if the screensaver is active. This closes bug #4.


Modified: trunk/notification-daemon/ChangeLog
===================================================================
--- trunk/notification-daemon/ChangeLog	2006-01-25 06:57:00 UTC (rev 2494)
+++ trunk/notification-daemon/ChangeLog	2006-01-25 08:07:54 UTC (rev 2495)
@@ -1,3 +1,10 @@
+Wed Jan 25 00:01:56 PST 2006  Christian Hammond <chipx86 at chipx86.com>
+
+	* src/daemon.c:
+	* configure.ac:
+	  - Don't pop up a notification if a window is full screen or if the
+	    screensaver is active. This closes bug #4.
+
 Tue Jan 24 00:18:18 PST 2006  Christian Hammond <chipx86 at chipx86.com>
 
 	* src/Makefile.am:

Modified: trunk/notification-daemon/configure.ac
===================================================================
--- trunk/notification-daemon/configure.ac	2006-01-25 06:57:00 UTC (rev 2494)
+++ trunk/notification-daemon/configure.ac	2006-01-25 08:07:54 UTC (rev 2495)
@@ -76,7 +76,7 @@
 AC_CHECK_LIB([popt], [poptGetArg], , AC_MSG_ERROR([Popt is required]))
 
 REQ_DBUS_VERSION=0.36
-pkg_modules="gtk+-2.0 >= 2.2.2 glib-2.0 >= 2.2.2, dbus-1 >= $REQ_DBUS_VERSION, dbus-glib-1 >= $REQ_DBUS_VERSION libsexy >= 0.1.3 gconf-2.0"
+pkg_modules="gtk+-2.0 >= 2.2.2 glib-2.0 >= 2.2.2, dbus-1 >= $REQ_DBUS_VERSION, dbus-glib-1 >= $REQ_DBUS_VERSION libsexy >= 0.1.3 gconf-2.0 libwnck-1.0"
 PKG_CHECK_MODULES(NOTIFICATION_DAEMON, [$pkg_modules])
 AC_SUBST(NOTIFICATION_DAEMON_CFLAGS)
 AC_SUBST(NOTIFICATION_DAEMON_LIBS)

Modified: trunk/notification-daemon/src/daemon.c
===================================================================
--- trunk/notification-daemon/src/daemon.c	2006-01-25 06:57:00 UTC (rev 2494)
+++ trunk/notification-daemon/src/daemon.c	2006-01-25 08:07:54 UTC (rev 2495)
@@ -32,11 +32,16 @@
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
+#include <X11/Xproto.h>
+
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
 #include <gdk/gdkx.h>
 
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+
 #include "daemon.h"
 #include "engines.h"
 #include "notificationdaemon-dbus-glue.h"
@@ -525,7 +530,7 @@
 }
 
 static gboolean
-get_work_area(GdkRectangle *rect)
+get_work_area(GtkWidget *nw, GdkRectangle *rect)
 {
 	Atom workarea = XInternAtom(GDK_DISPLAY(), "_NET_WORKAREA", True);
 	Atom type;
@@ -536,13 +541,18 @@
 	guchar *ret_workarea;
 	long *workareas;
 	int result;
-	int disp_screen = 0; /* XXX */
+	GdkScreen *screen;
+	int disp_screen;
 
+	gtk_widget_realize(nw);
+	screen = gdk_drawable_get_screen(GDK_DRAWABLE(nw->window));
+	disp_screen = GDK_SCREEN_XNUMBER(screen);
+
 	/* Defaults in case of error */
 	rect->x = 0;
 	rect->y = 0;
-	rect->width = gdk_screen_width();
-	rect->height = gdk_screen_height();
+	rect->width = gdk_screen_get_width(screen);
+	rect->height = gdk_screen_get_height(screen);
 
 	if (workarea == None)
 		return FALSE;
@@ -579,7 +589,7 @@
 	GSList *link;
 	gint x, y;
 
-	get_work_area(&workarea);
+	get_work_area(GTK_WIDGET(nw), &workarea);
 
 	y = workarea.y + workarea.height;
 	x = 0;
@@ -624,7 +634,7 @@
 
 	gtk_widget_size_request(GTK_WIDGET(nw), &req);
 
-	get_work_area(&workarea);
+	get_work_area(GTK_WIDGET(nw), &workarea);
 
 	x = workarea.x + workarea.width - req.width;
 	y = workarea.y + workarea.height - req.height;
@@ -700,6 +710,77 @@
 	}
 }
 
+static gboolean
+screensaver_active(GtkWidget *nw)
+{
+	GdkDisplay *display = gdk_drawable_get_display(GDK_DRAWABLE(nw->window));
+	Atom type;
+	int format;
+	unsigned long nitems, bytes_after;
+	unsigned char *temp_data;
+	gboolean active = FALSE;
+	Atom XA_BLANK = gdk_x11_get_xatom_by_name_for_display(display, "BLANK");
+	Atom XA_LOCK = gdk_x11_get_xatom_by_name_for_display(display, "LOCK");
+
+	/* Check for a screensaver first. */
+	if (XGetWindowProperty(
+		GDK_DISPLAY_XDISPLAY(display),
+		GDK_ROOT_WINDOW(),
+		gdk_x11_get_xatom_by_name_for_display(display, "_SCREENSAVER_STATUS"),
+		0, G_MAXLONG, False, XA_INTEGER, &type, &format, &nitems,
+		&bytes_after, &temp_data) == Success &&
+		type && temp_data != NULL)
+	{
+		CARD32 *data = (CARD32 *)temp_data;
+
+		active = (type == XA_INTEGER && nitems >= 3 &&
+				  (time_t)data[1] > (time_t)666000000L &&
+				  (data[0] == XA_BLANK || data[0] == XA_LOCK));
+	}
+
+	if (temp_data != NULL)
+		free(temp_data);
+
+	return active;
+}
+
+static gboolean
+fullscreen_window_exists(GtkWidget *nw)
+{
+	WnckScreen *wnck_screen;
+	GList *l;
+
+	wnck_screen = wnck_screen_get(GDK_SCREEN_XNUMBER(
+		gdk_drawable_get_screen(GDK_DRAWABLE(GTK_WIDGET(nw)->window))));
+	wnck_screen_force_update(wnck_screen);
+
+	for (l = wnck_screen_get_windows_stacked(wnck_screen);
+		 l != NULL;
+		 l = l->next)
+	{
+		WnckWindow *wnck_win = (WnckWindow *)l->data;
+
+		if (wnck_window_is_fullscreen(wnck_win))
+		{
+			/*
+			 * Sanity check if the window is _really_ fullscreen to
+			 * work around a bug in libwnck that doesn't get all
+			 * unfullscreen events.
+			 */
+			int sw = wnck_screen_get_width(wnck_screen);
+			int sh = wnck_screen_get_height(wnck_screen);
+			int x, y, w, h;
+
+			wnck_window_get_geometry(wnck_win, &x, &y, &w, &h);
+
+			if (sw == w && sh == h)
+				return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
 gboolean
 notify_daemon_notify_handler(NotifyDaemon *daemon,
 							 const gchar *app_name,
@@ -842,8 +923,13 @@
 	g_signal_connect(G_OBJECT(nw), "button-release-event",
 					 G_CALLBACK(window_clicked_cb), daemon);
 
-	theme_show_notification(nw);
 
+	if (!screensaver_active(GTK_WIDGET(nw)) &&
+		!fullscreen_window_exists(GTK_WIDGET(nw)))
+	{
+		theme_show_notification(nw);
+	}
+
 	return_id = (id == 0 ? _store_notification(daemon, nw, timeout) : id);
 
 #if CHECK_DBUS_VERSION(0, 60)



More information about the galago-commits mailing list