[Goodies-commits] r4656 - in xfce4-dict/trunk: lib panel-plugin src

Enrico Troeger enrico at xfce.org
Tue Apr 22 21:11:14 CEST 2008


Author: enrico
Date: 2008-04-22 19:11:14 +0000 (Tue, 22 Apr 2008)
New Revision: 4656

Modified:
   xfce4-dict/trunk/lib/common.c
   xfce4-dict/trunk/lib/common.h
   xfce4-dict/trunk/lib/gui.c
   xfce4-dict/trunk/lib/gui.h
   xfce4-dict/trunk/panel-plugin/xfce4-dict-plugin.c
   xfce4-dict/trunk/src/xfce4-dict.c
Log:
Implement saving and restoring window geometry.


Modified: xfce4-dict/trunk/lib/common.c
===================================================================
--- xfce4-dict/trunk/lib/common.c	2008-04-22 19:11:08 UTC (rev 4655)
+++ xfce4-dict/trunk/lib/common.c	2008-04-22 19:11:14 UTC (rev 4656)
@@ -255,6 +255,29 @@
 }
 
 
+static void parse_geometry(DictData *dd, const gchar *str)
+{
+	gint i;
+
+	/* first init first element with -1 */
+	dd->geometry[0] = -1;
+
+	sscanf(str, "%d;%d;%d;%d;%d;",
+		&dd->geometry[0], &dd->geometry[1], &dd->geometry[2], &dd->geometry[3], &dd->geometry[4]);
+
+	/* don't use insane values but when main windows was maximized last time, pos might be
+	 * negative at least on Windows for some reason */
+	if (dd->geometry[4] != 1)
+	{
+		for (i = 0; i < 4; i++)
+		{
+			if (dd->geometry[i] < -1)
+				dd->geometry[i] = -1;
+		}
+	}
+}
+
+
 void dict_read_rc_file(DictData *dd)
 {
 	XfceRc *rc;
@@ -268,6 +291,7 @@
 	const gchar *weburl = NULL;
 	const gchar *spell_bin = "aspell";
 	const gchar *spell_dictionary = "en";
+	const gchar *geo = "-1;0;0;0;0;";
 
 	if ((rc = xfce_rc_config_open(XFCE_RESOURCE_CONFIG, "xfce4-dict/xfce4-dict.rc", TRUE)) != NULL)
 	{
@@ -282,6 +306,9 @@
 		spell_bin = xfce_rc_read_entry(rc, "spell_bin", spell_bin);
 		spell_dictionary = xfce_rc_read_entry(rc, "spell_dictionary", spell_dictionary);
 
+		geo = xfce_rc_read_entry(rc, "geometry", geo);
+		parse_geometry(dd, geo);
+
 		xfce_rc_close(rc);
 	}
 
@@ -308,6 +335,8 @@
 
 	if ((rc = xfce_rc_config_open(XFCE_RESOURCE_CONFIG, "xfce4-dict/xfce4-dict.rc", FALSE)) != NULL)
 	{
+		gchar geometry_string[128];
+
 		xfce_rc_write_int_entry(rc, "mode_in_use", dd->mode_in_use);
 		xfce_rc_write_int_entry(rc, "mode_default", dd->mode_default);
 		if (dd->web_url != NULL)
@@ -320,6 +349,10 @@
 		xfce_rc_write_entry(rc, "spell_bin", dd->spell_bin);
 		xfce_rc_write_entry(rc, "spell_dictionary", dd->spell_dictionary);
 
+		g_snprintf(geometry_string, sizeof(geometry_string), "%d;%d;%d;%d;%d;",
+			dd->geometry[0], dd->geometry[1], dd->geometry[2], dd->geometry[3], dd->geometry[4]);
+		xfce_rc_write_entry(rc, "geometry", geometry_string);
+
 		xfce_rc_close(rc);
 	}
 }
@@ -327,9 +360,10 @@
 
 void dict_free_data(DictData *dd)
 {
+	dict_write_rc_file(dd);
+
 	gtk_widget_destroy(dd->window);
 
-	dict_write_rc_file(dd);
 	g_free(dd->searched_word);
 	g_free(dd->dictionary);
 	g_free(dd->server);

Modified: xfce4-dict/trunk/lib/common.h
===================================================================
--- xfce4-dict/trunk/lib/common.h	2008-04-22 19:11:08 UTC (rev 4655)
+++ xfce4-dict/trunk/lib/common.h	2008-04-22 19:11:14 UTC (rev 4656)
@@ -75,6 +75,9 @@
 	gint query_status;
 	gchar *query_buffer;
 
+	/* main window's geometry */
+	gint geometry[5];
+
 	/* widgets */
 	GtkWidget *window;
 	GtkWidget *statusbar;
@@ -102,5 +105,4 @@
 
 DictData *dict_create_dictdata();
 
-
 #endif

Modified: xfce4-dict/trunk/lib/gui.c
===================================================================
--- xfce4-dict/trunk/lib/gui.c	2008-04-22 19:11:08 UTC (rev 4655)
+++ xfce4-dict/trunk/lib/gui.c	2008-04-22 19:11:14 UTC (rev 4656)
@@ -310,6 +310,15 @@
 	/* TODO: find a way to get this working, the treeview doesn't receive anything as long as it isn't
 	 * editable. scrolledwindow_results and a surrounding event box as receivers also don't work. */
 	g_signal_connect(dd->main_textview, "drag-data-received", G_CALLBACK(dict_drag_data_received), dd);
+
+	/* use the saved window geometry */
+	if (dd->geometry[0] != -1)
+	{
+		gtk_window_move(GTK_WINDOW(dd->window), dd->geometry[0], dd->geometry[1]);
+		gtk_window_set_default_size(GTK_WINDOW(dd->window), dd->geometry[2], dd->geometry[3]);
+		if (dd->geometry[4] == 1)
+			gtk_window_maximize(GTK_WINDOW(dd->window));
+	}
 }
 
 
@@ -342,3 +351,15 @@
 
 	xfce_about_info_free(info);
 }
+
+
+void dict_gui_query_geometry(DictData *dd)
+{
+	gtk_window_get_position(GTK_WINDOW(dd->window),	&dd->geometry[0], &dd->geometry[1]);
+	gtk_window_get_size(GTK_WINDOW(dd->window),	&dd->geometry[2], &dd->geometry[3]);
+
+	if (gdk_window_get_state(dd->window->window) & GDK_WINDOW_STATE_MAXIMIZED)
+		dd->geometry[4] = 1;
+	else
+		dd->geometry[4] = 0;
+}

Modified: xfce4-dict/trunk/lib/gui.h
===================================================================
--- xfce4-dict/trunk/lib/gui.h	2008-04-22 19:11:08 UTC (rev 4655)
+++ xfce4-dict/trunk/lib/gui.h	2008-04-22 19:11:14 UTC (rev 4656)
@@ -28,6 +28,7 @@
 void dict_gui_clear_text_buffer(DictData *dd);
 void dict_gui_set_panel_entry_text(DictData *dd, const gchar *text);
 void dict_gui_show_main_window(DictData *dd);
+void dict_gui_query_geometry(DictData *dd);
 const guint8 *dict_gui_get_icon_data(void);
 
 

Modified: xfce4-dict/trunk/panel-plugin/xfce4-dict-plugin.c
===================================================================
--- xfce4-dict/trunk/panel-plugin/xfce4-dict-plugin.c	2008-04-22 19:11:08 UTC (rev 4655)
+++ xfce4-dict/trunk/panel-plugin/xfce4-dict-plugin.c	2008-04-22 19:11:14 UTC (rev 4656)
@@ -132,7 +132,13 @@
 static void dict_plugin_panel_button_clicked(GtkWidget *button, DictPanelData *dpd)
 {
 	if (GTK_WIDGET_VISIBLE(dpd->dd->window))
+	{
+		/* we must query geometry settings here because position and maximized state
+		 * doesn't work when the window is hidden */
+		dict_gui_query_geometry(dpd->dd);
+
 		gtk_widget_hide(dpd->dd->window);
+	}
 	else
 	{
 		const gchar *panel_text = gtk_entry_get_text(GTK_ENTRY(dpd->dd->panel_entry));
@@ -222,6 +228,13 @@
 	/* Destroy the setting dialog, if this open */
 	GtkWidget *dialog = g_object_get_data(G_OBJECT(dpd->plugin), "dialog");
 
+	/* if the main window is visible, query geometry as usual, if it is hidden the geometry
+	 * was queried when it was hidden */
+	if (GTK_WIDGET_VISIBLE(dpd->dd->window))
+	{
+		dict_gui_query_geometry(dpd->dd);
+	}
+
 	if (dialog != NULL)
 		gtk_widget_destroy(dialog);
 

Modified: xfce4-dict/trunk/src/xfce4-dict.c
===================================================================
--- xfce4-dict/trunk/src/xfce4-dict.c	2008-04-22 19:11:08 UTC (rev 4655)
+++ xfce4-dict/trunk/src/xfce4-dict.c	2008-04-22 19:11:14 UTC (rev 4656)
@@ -65,6 +65,7 @@
 
 static gboolean main_quit(GtkWidget *widget, GdkEvent *event, DictData *dd)
 {
+	dict_gui_query_geometry(dd);
 	dict_free_data(dd);
     gtk_main_quit();
 




More information about the Goodies-commits mailing list