changeset 21976:a86c035be695

New actions: window-next-urgent (alt+tab), and window-prev-urgent (alt+shift+tab).
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 03 Jan 2008 11:12:36 +0000
parents c7c5e2ff2b04
children 05c2ef19e2fa cacc01b50a23
files doc/finch.1.in finch/libgnt/gntwm.c
diffstat 2 files changed, 48 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/doc/finch.1.in	Wed Jan 02 22:15:06 2008 +0000
+++ b/doc/finch.1.in	Thu Jan 03 11:12:36 2008 +0000
@@ -105,6 +105,12 @@
 .B Alt \+ 1 2 ... 0
 Jump to the 1st, 2nd ... 10th window.
 .TP
+.B Alt \+ Tab
+Jump to the next URGENT (highlighted) window.
+.TP
+.B Alt \+ Shift \+ Tab
+Jump to the previous URGENT (highlighted) window.
+.TP
 .B Ctrl \+ o
 Bring up the menu (if there is one) for a window.
 .TP
@@ -460,6 +466,7 @@
 .br
 # switch-window-n
 .br
+# Other actions: window-next-urgent, window-prev-urgent
 
 # For the sample custom window manager
 .br
--- a/finch/libgnt/gntwm.c	Wed Jan 02 22:15:06 2008 +0000
+++ b/finch/libgnt/gntwm.c	Thu Jan 03 11:12:36 2008 +0000
@@ -388,10 +388,10 @@
 }
 
 static void
-switch_window(GntWM *wm, int direction)
+switch_window(GntWM *wm, int direction, gboolean urgent)
 {
 	GntWidget *w = NULL, *wid = NULL;
-	int pos;
+	int pos, orgpos;
 
 	if (wm->_list.window || wm->menu)
 		return;
@@ -404,15 +404,20 @@
 	}
 
 	w = wm->cws->ordered->data;
-	pos = g_list_index(wm->cws->list, w);
-	pos += direction;
+	orgpos = pos = g_list_index(wm->cws->list, w);
+
+	do {
+		pos += direction;
 
-	if (pos < 0)
-		wid = g_list_last(wm->cws->list)->data;
-	else if (pos >= g_list_length(wm->cws->list))
-		wid = wm->cws->list->data;
-	else if (pos >= 0)
-		wid = g_list_nth_data(wm->cws->list, pos);
+		if (pos < 0) {
+			wid = g_list_last(wm->cws->list)->data;
+			pos = g_list_length(wm->cws->list) - 1;
+		} else if (pos >= g_list_length(wm->cws->list)) {
+			wid = wm->cws->list->data;
+			pos = 0;
+		} else
+			wid = g_list_nth_data(wm->cws->list, pos);
+	} while (urgent && !GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT) && pos != orgpos);
 
 	gnt_wm_raise_window(wm, wid);
 }
@@ -421,7 +426,7 @@
 window_next(GntBindable *bindable, GList *null)
 {
 	GntWM *wm = GNT_WM(bindable);
-	switch_window(wm, 1);
+	switch_window(wm, 1, FALSE);
 	return TRUE;
 }
 
@@ -429,7 +434,7 @@
 window_prev(GntBindable *bindable, GList *null)
 {
 	GntWM *wm = GNT_WM(bindable);
-	switch_window(wm, -1);
+	switch_window(wm, -1, FALSE);
 	return TRUE;
 }
 
@@ -1202,6 +1207,22 @@
 	return ignore_keys ? !(ignore_keys = FALSE) : FALSE;
 }
 
+static gboolean
+window_next_urgent(GntBindable *bindable, GList *n)
+{
+	GntWM *wm = GNT_WM(bindable);
+	switch_window(wm, 1, TRUE);
+	return TRUE;
+}
+
+static gboolean
+window_prev_urgent(GntBindable *bindable, GList *n)
+{
+	GntWM *wm = GNT_WM(bindable);
+	switch_window(wm, -1, TRUE);
+	return TRUE;
+}
+
 #ifdef USE_PYTHON
 static void
 python_script_selected(GntFileSel *fs, const char *path, const char *f, gpointer n)
@@ -1323,6 +1344,7 @@
 {
 	int i;
 	GObjectClass *gclass = G_OBJECT_CLASS(klass);
+	char key[32];
 
 	gclass->dispose = gnt_wm_destroy;
 
@@ -1482,10 +1504,15 @@
 				"\033" "\\", NULL);
 	gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "help-for-window", help_for_window,
 				"\033" "|", NULL);
-	gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-start", ignore_keys_start, 
+	gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-start", ignore_keys_start,
 				GNT_KEY_CTRL_G, NULL);
-	gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-end", ignore_keys_end, 
+	gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-end", ignore_keys_end,
 				"\033" GNT_KEY_CTRL_G, NULL);
+	gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-next-urgent", window_next_urgent,
+				"\033" "\t", NULL);
+	snprintf(key, sizeof(key), "\033%s", GNT_KEY_BACK_TAB);
+	gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-prev-urgent", window_prev_urgent,
+				key[1] ? key : NULL, NULL);
 #ifdef USE_PYTHON
 	gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "run-python", run_python,
 				GNT_KEY_F3, NULL);