comparison 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
comparison
equal deleted inserted replaced
18233:98c1375232e2 18235:d359e5f3ee87
1456 } 1456 }
1457 1457
1458 static gboolean 1458 static gboolean
1459 match_title(gpointer title, gpointer n, gpointer wid_title) 1459 match_title(gpointer title, gpointer n, gpointer wid_title)
1460 { 1460 {
1461 /* maybe check for regex.h? */ 1461 /* XXX: do any regex magic here. */
1462 if (g_strrstr((gchar *)wid_title, (gchar *)title)) 1462 if (g_strrstr((gchar *)wid_title, (gchar *)title))
1463 return TRUE; 1463 return TRUE;
1464 return FALSE; 1464 return FALSE;
1465 } 1465 }
1466 1466
1467 #if !GLIB_CHECK_VERSION(2,4,0) 1467 #if !GLIB_CHECK_VERSION(2,4,0)
1468 typedef struct 1468 struct
1469 { 1469 {
1470 GntWM *wm; 1470 gpointer data;
1471 GntWS *ret; 1471 gpointer value;
1472 gchar *title; 1472 } table_find_data;
1473 } title_search; 1473
1474 1474 static void
1475 static void match_title_search(gpointer key, gpointer value, gpointer search) 1475 table_find_helper(gpointer key, gpointer value, gpointer data)
1476 { 1476 {
1477 title_search *s = search; 1477 GHRFunc func = data;
1478 if (s->ret) 1478 if (func(key, value, table_find_data.data))
1479 return; 1479 table_find_data.value = value;
1480 if (match_title(key, NULL, s->title)) 1480 }
1481 s->ret = g_hash_table_lookup(s->wm->title_places, key); 1481
1482 static gpointer
1483 g_hash_table_find(GHashTable * table, GHRFunc func, gpointer data)
1484 {
1485 table_find_data.data = data;
1486 table_find_data.value = NULL;
1487 g_hash_table_foreach(table, table_find_helper, func);
1488 return table_find_data.value;
1482 } 1489 }
1483 #endif 1490 #endif
1484 1491
1485 static GntWS * 1492 static GntWS *
1486 new_widget_find_workspace(GntWM *wm, GntWidget *widget, gchar *wid_title) 1493 new_widget_find_workspace(GntWM *wm, GntWidget *widget)
1487 { 1494 {
1488 GntWS *ret; 1495 GntWS *ret = NULL;
1489 const gchar *name; 1496 const gchar *name, *title;
1490 #if GLIB_CHECK_VERSION(2,4,0) 1497 title = GNT_BOX(widget)->title;
1491 ret = g_hash_table_find(wm->title_places, match_title, wid_title); 1498 if (title)
1492 #else 1499 ret = g_hash_table_find(wm->title_places, match_title, (gpointer)title);
1493 title_search *s = NULL;
1494 s = g_new0(title_search, 1);
1495 s->wm = wm;
1496 s->title = wid_title;
1497 g_hash_table_foreach(wm->title_places, match_title_search, s);
1498 ret = s->ret;
1499 #endif
1500 if (ret) 1500 if (ret)
1501 return ret; 1501 return ret;
1502 name = gnt_widget_get_name(widget); 1502 name = gnt_widget_get_name(widget);
1503 if (name) 1503 if (name)
1504 ret = g_hash_table_lookup(wm->name_places, name); 1504 ret = g_hash_table_find(wm->name_places, match_title, (gpointer)name);
1505 return ret ? ret : wm->cws; 1505 return ret ? ret : wm->cws;
1506 } 1506 }
1507 1507
1508 static void 1508 static void
1509 gnt_wm_new_window_real(GntWM *wm, GntWidget *widget) 1509 gnt_wm_new_window_real(GntWM *wm, GntWidget *widget)
1562 GntWS *ws = wm->cws; 1562 GntWS *ws = wm->cws;
1563 if (node->me != wm->_list.window) { 1563 if (node->me != wm->_list.window) {
1564 GntWidget *w = NULL; 1564 GntWidget *w = NULL;
1565 1565
1566 if (GNT_IS_BOX(widget)) { 1566 if (GNT_IS_BOX(widget)) {
1567 char *title = GNT_BOX(widget)->title; 1567 ws = new_widget_find_workspace(wm, widget);
1568 ws = new_widget_find_workspace(wm, widget, title);
1569 } 1568 }
1570 1569
1571 if (ws->ordered) 1570 if (ws->ordered)
1572 w = ws->ordered->data; 1571 w = ws->ordered->data;
1573 1572