changeset 15347:03edbb70210f

[gaim-migrate @ 18140] Update gaim_gtk_set_urgent to work on WIN32. I also changed the function signature to take a GtkWindow instead of a GdkWindow so that we can use gtk_window_set_urgency_hint (only available on GTK >= 2.8.0). committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 16 Jan 2007 22:20:26 +0000
parents 467244cc4ff2
children 804e69c8ce23
files gtk/gtkblist.c gtk/gtkutils.c gtk/gtkutils.h gtk/win32/gtkwin32dep.c gtk/win32/gtkwin32dep.h
diffstat 5 files changed, 81 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/gtk/gtkblist.c	Tue Jan 16 19:45:24 2007 +0000
+++ b/gtk/gtkblist.c	Tue Jan 16 22:20:26 2007 +0000
@@ -778,15 +778,15 @@
 
 	if (GAIM_BLIST_NODE_IS_GROUP(node)) {
 		char *title;
-		
+
 		title = gaim_get_group_title(node, TRUE);
-		
+
 		gtk_tree_store_set(gtkblist->treemodel, iter,
 		   NAME_COLUMN, title,
 		   -1);
 
 		g_free(title);
-		
+
 		gaim_blist_node_set_bool(node, "collapsed", FALSE);
 	}
 }
@@ -802,15 +802,15 @@
 
 	if (GAIM_BLIST_NODE_IS_GROUP(node)) {
 		char *title;
-		
+
 		title = gaim_get_group_title(node, FALSE);
-		
+
 		gtk_tree_store_set(gtkblist->treemodel, iter,
 		   NAME_COLUMN, title,
 		   -1);
-		
+
 		g_free(title);
-		
+
 		gaim_blist_node_set_bool(node, "collapsed", TRUE);
 	} else if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
 		gaim_gtk_blist_collapse_contact_cb(NULL, node);
@@ -3807,7 +3807,7 @@
 	gtkblist->headline_callback = NULL;
 	gtkblist->headline_data = NULL;
 	gtkblist->headline_destroy = NULL;
-	gaim_gtk_set_urgent(gtkblist->window->window, FALSE);
+	gaim_gtk_set_urgent(GTK_WINDOW(gtkblist->window), FALSE);
 }
 
 static gboolean
@@ -5708,7 +5708,7 @@
 	gtkblist->headline_callback = callback;
 	gtkblist->headline_data = user_data;
 	gtkblist->headline_destroy = destroy;
-	gaim_gtk_set_urgent(gtkblist->window->window, TRUE);
+	gaim_gtk_set_urgent(GTK_WINDOW(gtkblist->window), TRUE);
 	gtk_widget_show_all(gtkblist->headline_hbox);
 }
 
--- a/gtk/gtkutils.c	Tue Jan 16 19:45:24 2007 +0000
+++ b/gtk/gtkutils.c	Tue Jan 16 22:20:26 2007 +0000
@@ -2220,7 +2220,7 @@
 	GtkWidget *icon_filesel;
 	GtkWidget *icon_preview;
 	GtkWidget *icon_text;
-	
+
 	void (*callback)(const char*,gpointer);
 	gpointer data;
 };
@@ -2678,7 +2678,7 @@
 
 #if !GTK_CHECK_VERSION(2,6,0)
 static void
-_gdk_file_scale_size_prepared_cb (GdkPixbufLoader *loader, 
+_gdk_file_scale_size_prepared_cb (GdkPixbufLoader *loader,
 		  int              width,
 		  int              height,
 		  gpointer         data)
@@ -2691,7 +2691,7 @@
 
 	g_return_if_fail (width > 0 && height > 0);
 
-	if (info->preserve_aspect_ratio && 
+	if (info->preserve_aspect_ratio &&
 		(info->width > 0 || info->height > 0)) {
 		if (info->width < 0)
 		{
@@ -2841,7 +2841,7 @@
 
 	if (filename) {
 		char *newfile;
-		
+
 		newfile = gaim_gtk_convert_buddy_icon(gaim_find_prpl(gaim_account_get_protocol_id(account)),
 						filename);
 		path = gaim_buddy_icons_get_full_path(newfile);
@@ -2876,17 +2876,24 @@
 	return ret;
 }
 
-void gaim_gtk_set_urgent(GdkWindow *window, gboolean urgent)
+void gaim_gtk_set_urgent(GtkWindow *window, gboolean urgent)
 {
-#ifdef _WIN32
-#error Hey, Daniel! Make this work!
+#if GTK_CHECK_VERSION(2,8,0)
+	gtk_window_set_urgency_hint(window, urgent)
+#elif defined _WIN32
+	gtkwgaim_window_flash(window, urgent);
 #else
+	GdkWindow *gdkwin;
 	XWMHints *hints;
 
 	g_return_if_fail(window != NULL);
 
-	hints = XGetWMHints(GDK_WINDOW_XDISPLAY(window),
-	                    GDK_WINDOW_XWINDOW(window));
+	gdkwin = GTK_WIDGET(window)->window;
+
+	g_return_if_fail(gdkwin != NULL);
+
+	hints = XGetWMHints(GDK_WINDOW_XDISPLAY(gdkwin),
+	                    GDK_WINDOW_XWINDOW(gdkwin));
 	if(!hints)
 		hints = XAllocWMHints();
 
@@ -2894,8 +2901,8 @@
 		hints->flags |= XUrgencyHint;
 	else
 		hints->flags &= ~XUrgencyHint;
-	XSetWMHints(GDK_WINDOW_XDISPLAY(window),
-	            GDK_WINDOW_XWINDOW(window), hints);
+	XSetWMHints(GDK_WINDOW_XDISPLAY(gdkwin),
+	            GDK_WINDOW_XWINDOW(gdkwin), hints);
 	XFree(hints);
 #endif
 }
@@ -2910,7 +2917,7 @@
 	return &handle;
 }
 
-static void connection_signed_off_cb(GaimConnection *gc) 
+static void connection_signed_off_cb(GaimConnection *gc)
 {
 	GSList *list;
 	for (list = minidialogs; list; list = list->next) {
@@ -2955,17 +2962,17 @@
 
 	if (first_call) {
 		first_call = FALSE;
-		gaim_signal_connect(gaim_connections_get_handle(), "signed-off", 
+		gaim_signal_connect(gaim_connections_get_handle(), "signed-off",
 				    gaim_gtk_utils_get_handle(),
 				    GAIM_CALLBACK(connection_signed_off_cb), NULL);
 	}
-	
+
       	hbox = gtk_hbox_new(FALSE, 0);
         gtk_container_add(GTK_CONTAINER(vbox), hbox);
-	
+
         if (img != NULL)
 		gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0);
-	
+
 	primary_esc = g_markup_escape_text(primary, -1);
 
 	if (secondary)
@@ -2980,15 +2987,15 @@
         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
         gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
         gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
-	
+
 	hbox2 = gtk_hbox_new(FALSE, 6);
 	gtk_box_pack_start(GTK_BOX(vbox), hbox2, FALSE, FALSE, 0);
-	
+
 	va_start(args, user_data);
 	while ((button_text = va_arg(args, char*))) {
 		callback = va_arg(args, GCallback);
 		button = gtk_button_new();
-	
+
 		if (callback)
 			g_signal_connect_swapped(G_OBJECT(button), "clicked", callback, user_data);
 		g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK(gtk_widget_destroy), vbox);
--- a/gtk/gtkutils.h	Tue Jan 16 19:45:24 2007 +0000
+++ b/gtk/gtkutils.h	Tue Jan 16 22:20:26 2007 +0000
@@ -540,7 +540,7 @@
  * @param window  The window to draw attention to
  * @param urgent  Whether to set the urgent hint or not
  */
-void gaim_gtk_set_urgent(GdkWindow *window, gboolean urgent);
+void gaim_gtk_set_urgent(GtkWindow *window, gboolean urgent);
 
 #if !GTK_CHECK_VERSION(2,2,0)
 /**
--- a/gtk/win32/gtkwin32dep.c	Tue Jan 16 19:45:24 2007 +0000
+++ b/gtk/win32/gtkwin32dep.c	Tue Jan 16 22:20:26 2007 +0000
@@ -239,10 +239,48 @@
 	return win_hwnd;
 }
 
+static gboolean stop_flashing(GtkWidget *widget, GdkEventFocus *event, gpointer data) {
+	GtkWindow *window = data;
+	gtkwgaim_window_flash(window, FALSE);
+	return FALSE;
+}
+
+void
+gtkwgaim_window_flash(GtkWindow *window, gboolean flash) {
+	GdkWindow * gdkwin;
+
+	g_return_if_fail(window != NULL);
+
+	gdkwin = GTK_WIDGET(window)->window;
+
+	g_return_if_fail(GDK_IS_WINDOW(gdkwin));
+	g_return_if_fail(GDK_WINDOW_TYPE(gdkwin) != GDK_WINDOW_CHILD);
+
+	if(GDK_WINDOW_DESTROYED(gdkwin))
+	    return;
+
+	if(MyFlashWindowEx) {
+		FLASHWINFO info;
+
+		memset(&info, 0, sizeof(FLASHWINFO));
+		info.cbSize = sizeof(FLASHWINFO);
+		info.hwnd = GDK_WINDOW_HWND(gdkwin);
+		if (flash)
+			info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
+		else
+			info.dwFlags = FLASHW_STOP;
+		info.dwTimeout = 0;
+		info.dwTimeout = 0;
+
+		MyFlashWindowEx(&info);
+	} else
+		FlashWindow(GDK_WINDOW_HWND(gdkwin), flash);
+}
+
 void
 gtkwgaim_conv_blink(GaimConversation *conv, GaimMessageFlags flags) {
 	GaimGtkWindow *win;
-	GtkWidget *window;
+	GtkWindow *window;
 
 	/* Don't flash for our own messages or system messages */
 	if(flags & GAIM_MESSAGE_SEND || flags & GAIM_MESSAGE_SYSTEM)
@@ -258,23 +296,12 @@
 		gaim_debug_info("gtkwgaim", "No conversation windows found to blink.\n");
 		return;
 	}
-
-	window = win->window;
-
-	/* Don't flash if we have the window focused */
-	if(GetForegroundWindow() == GDK_WINDOW_HWND(window->window))
-		return;
+	window = GTK_WINDOW(win->window);
 
-	if(MyFlashWindowEx) {
-		FLASHWINFO info;
-
-		memset(&info, 0, sizeof(FLASHWINFO));
-		info.cbSize = sizeof(FLASHWINFO);
-		info.hwnd = GDK_WINDOW_HWND(window->window);
-		info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
-		info.dwTimeout = 0;
-		MyFlashWindowEx(&info);
-	}
+	gtkwgaim_window_flash(window, TRUE);
+	/* Stop flashing when window receives focus */
+	g_signal_connect(G_OBJECT(window), "focus-in-event",
+					 G_CALLBACK(stop_flashing), window);
 }
 
 static gboolean
--- a/gtk/win32/gtkwin32dep.h	Tue Jan 16 19:45:24 2007 +0000
+++ b/gtk/win32/gtkwin32dep.h	Tue Jan 16 22:20:26 2007 +0000
@@ -37,6 +37,7 @@
 void gtkwgaim_shell_execute(const char *target, const char *verb, const char *clazz);
 void gtkwgaim_ensure_onscreen(GtkWidget *win);
 void gtkwgaim_conv_blink(GaimConversation *conv, GaimMessageFlags flags);
+void gtkwgaim_window_flash(GtkWindow *window, gboolean flash);
 
 /* init / cleanup */
 void gtkwgaim_init(HINSTANCE);