changeset 1473:01693e68707b

layout id "_current_" matches the currently active layout window
author nadvornik
date Sat, 21 Mar 2009 19:51:07 +0000
parents b4001cb9fbc4
children aec6992e5116
files src/layout.c src/layout.h
diffstat 2 files changed, 34 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/layout.c	Sat Mar 21 18:22:04 2009 +0000
+++ b/src/layout.c	Sat Mar 21 19:51:07 2009 +0000
@@ -59,7 +59,7 @@
 
 
 GList *layout_window_list = NULL;
-
+LayoutWindow *current_lw = NULL;
 
 static void layout_list_scroll_to_subpart(LayoutWindow *lw, const gchar *needle);
 
@@ -74,10 +74,10 @@
 {
 	if (*lw == NULL)
 		{
-		if (layout_window_list) *lw = layout_window_list->data;
+		if (current_lw) *lw = current_lw;
+		else if (layout_window_list) *lw = layout_window_list->data;
 		return (*lw != NULL);
 		}
-
 	return (g_list_find(layout_window_list, *lw) != NULL);
 }
 
@@ -119,6 +119,14 @@
 	GList *work;
 
 	if (!id || !id[0]) return NULL;
+	
+	if (strcmp(id, LAYOUT_ID_CURRENT) == 0)
+		{
+		if (current_lw) return current_lw;
+		if (layout_window_list) return layout_window_list->data;
+		return NULL;
+		}
+
 	work = layout_window_list;
 	while (work)
 		{
@@ -160,6 +168,13 @@
 		}
 }
 
+static gboolean layout_set_current_cb(GtkWidget *widget, GdkEventFocus *event, gpointer data)
+{
+	LayoutWindow *lw = data;
+	current_lw = lw;
+	return FALSE;
+}
+
 /*
  *-----------------------------------------------------------------------------
  * menu, toolbar, and dir view
@@ -2203,6 +2218,7 @@
 	if (!lw) return;
 
 	layout_window_list = g_list_remove(layout_window_list, lw);
+	if (current_lw == lw) current_lw = NULL;
 
 	if (lw->exif_window) g_signal_handlers_disconnect_matched(G_OBJECT(lw->exif_window), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, lw);
 		
@@ -2321,6 +2337,9 @@
 	g_signal_connect(G_OBJECT(lw->window), "delete_event",
 			 G_CALLBACK(layout_delete_cb), lw);
 
+	g_signal_connect(G_OBJECT(lw->window), "focus-in-event",
+			 G_CALLBACK(layout_set_current_cb), lw);
+
 	layout_keyboard_init(lw, lw->window);
 
 #ifdef HAVE_LIRC
@@ -2441,6 +2460,7 @@
 
 void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names, const gchar **attribute_values)
 {
+	gchar *id = NULL;
 	
 	while (*attribute_names)
 		{
@@ -2448,7 +2468,7 @@
 		const gchar *value = *attribute_values++;
 
 		/* layout options */
-		if (READ_CHAR(*layout, id)) continue;
+		if (READ_CHAR_FULL("id", id)) continue;
 
 		if (READ_INT(*layout, style)) continue;
 		if (READ_CHAR(*layout, order)) continue;
@@ -2490,7 +2510,15 @@
 
 		log_printf("unknown attribute %s = %s\n", option, value);
 		}
-
+	if (id && strcmp(id, LAYOUT_ID_CURRENT) != 0)
+		{
+		g_free(layout->id);
+		layout->id = id;
+		}
+	else
+		{
+		g_free(id);
+		}
 }
 
 static void layout_config_commandline(LayoutOptions *lop, gchar **path)
--- a/src/layout.h	Sat Mar 21 18:22:04 2009 +0000
+++ b/src/layout.h	Sat Mar 21 19:51:07 2009 +0000
@@ -13,6 +13,7 @@
 #ifndef LAYOUT_H
 #define LAYOUT_H
 
+#define LAYOUT_ID_CURRENT "_current_"
 
 extern GList *layout_window_list;