diff finch/libgnt/gntwm.c @ 18235:d359e5f3ee87

Plucked revision from finchfeat to allow partial matching for window-titles and/or window-names to determine the target workspace for a new window. Adds g_hash_table_find for glib < 2.4. applied changes from 498ca4dd71cf163d032b2e43fa329ce0cb4e3491 through bc87d18d218432986c9436e902d8d6922ce54b90
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 23 Jun 2007 03:20:02 +0000
parents af7b944374ba
children 1648cd94dddf b25cb0775be3
line wrap: on
line diff
--- a/finch/libgnt/gntwm.c	Sat Jun 23 03:08:06 2007 +0000
+++ b/finch/libgnt/gntwm.c	Sat Jun 23 03:20:02 2007 +0000
@@ -1458,50 +1458,50 @@
 static gboolean
 match_title(gpointer title, gpointer n, gpointer wid_title)
 {
-	/* maybe check for regex.h? */
+	/* XXX: do any regex magic here. */
 	if (g_strrstr((gchar *)wid_title, (gchar *)title))
 		return TRUE;
 	return FALSE;
 }
 
 #if !GLIB_CHECK_VERSION(2,4,0)
-typedef struct
+struct
 {
-	GntWM *wm;
-	GntWS *ret;
-	gchar *title;
-} title_search;
+	gpointer data;
+	gpointer value;
+} table_find_data;
 
-static void match_title_search(gpointer key, gpointer value, gpointer search)
+static void
+table_find_helper(gpointer key, gpointer value, gpointer data)
 {
-	title_search *s = search;
-	if (s->ret)
-		return;
-	if (match_title(key, NULL, s->title))
-		s->ret = g_hash_table_lookup(s->wm->title_places, key);
+	GHRFunc func = data;
+	if (func(key, value, table_find_data.data))
+		table_find_data.value = value;
+}
+
+static gpointer
+g_hash_table_find(GHashTable * table, GHRFunc func, gpointer data)
+{
+	table_find_data.data = data;
+	table_find_data.value = NULL;
+	g_hash_table_foreach(table, table_find_helper, func);
+	return table_find_data.value;
 }
 #endif
 
 static GntWS *
-new_widget_find_workspace(GntWM *wm, GntWidget *widget, gchar *wid_title)
+new_widget_find_workspace(GntWM *wm, GntWidget *widget)
 {
-	GntWS *ret;
-	const gchar *name;
-#if GLIB_CHECK_VERSION(2,4,0)
-	ret = g_hash_table_find(wm->title_places, match_title, wid_title);
-#else
-	title_search *s = NULL;
-	s = g_new0(title_search, 1);
-	s->wm = wm;
-	s->title = wid_title;
-	g_hash_table_foreach(wm->title_places, match_title_search, s);
-	ret = s->ret;
-#endif
+	GntWS *ret = NULL;
+	const gchar *name, *title;
+	title = GNT_BOX(widget)->title;
+	if (title)
+		ret = g_hash_table_find(wm->title_places, match_title, (gpointer)title);
 	if (ret)
 		return ret;
 	name = gnt_widget_get_name(widget);
 	if (name)
-		ret = g_hash_table_lookup(wm->name_places, name);
+		ret = g_hash_table_find(wm->name_places, match_title, (gpointer)name);
 	return ret ? ret : wm->cws;
 }
 
@@ -1564,8 +1564,7 @@
 			GntWidget *w = NULL;
 
 			if (GNT_IS_BOX(widget)) {
-				char *title = GNT_BOX(widget)->title;
-				ws = new_widget_find_workspace(wm, widget, title);
+				ws = new_widget_find_workspace(wm, widget);
 			}
 
 			if (ws->ordered)