From dca8f6d8b87d6f92ff21344ec80b64c7a3b7de7f Mon Sep 17 00:00:00 2001 From: Alan Fitton Date: Sat, 3 Sep 2011 09:38:07 +0000 Subject: issue 76 - as stated in the documentation gtk_window_get_size() isn't always up to date. I'm sure it worked when I implemented this on GNOME, so as the docs suggest I think behavior could vary on other window managers. I'm on XFCE now and it doesn't work. use the configure-event to save the size instead. --- config.h.in | 3 +++ configure.ac | 2 +- src/trg-client.c | 6 +++++- src/trg-main-window.c | 21 ++++++++++++++++----- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/config.h.in b/config.h.in index 05d248e..a3a9510 100644 --- a/config.h.in +++ b/config.h.in @@ -21,6 +21,9 @@ /* Define if libproxy is available */ #undef HAVE_LIBPROXY +/* Define if libunique is available */ +#undef HAVE_LIBUNIQUE + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H diff --git a/configure.ac b/configure.ac index 7731f87..8cc214b 100644 --- a/configure.ac +++ b/configure.ac @@ -38,7 +38,7 @@ PKG_CHECK_MODULES([jsonglib], [json-glib-1.0 >= 0.8]) PKG_CHECK_MODULES([gthread], [gthread-2.0]) PKG_CHECK_MODULES([gtk], [gtk+-2.0 >= 2.16]) PKG_CHECK_MODULES([gio], [gio-2.0 >= 2.22]) -PKG_CHECK_MODULES([unique], [unique-1.0]) +PKG_CHECK_MODULES([unique], [unique-1.0], AC_DEFINE(HAVE_LIBUNIQUE, 1, [Define if libunique is available])) PKG_CHECK_MODULES([notify], [libnotify]) PKG_CHECK_MODULES([libproxy], [libproxy-1.0], AC_DEFINE(HAVE_LIBPROXY, 1, [Define if libproxy is available]), AC_MSG_WARN([libproxy is required for HTTP proxy support])) LIBCURL_CHECK_CONFIG([yes], [7.0], [], [AC_MSG_ERROR(["libcurl not found"])]) diff --git a/src/trg-client.c b/src/trg-client.c index 244361e..fb57a93 100644 --- a/src/trg-client.c +++ b/src/trg-client.c @@ -176,8 +176,12 @@ int trg_client_populate_with_settings(TrgClient * tc) trg_prefs_get_int(prefs, TRG_PREFS_KEY_PORT, TRG_PREFS_PROFILE); host = trg_prefs_get_string(prefs, TRG_PREFS_KEY_HOSTNAME, TRG_PREFS_PROFILE); - if (!host || strlen(host) < 1) + if (!host) { return TRG_NO_HOSTNAME_SET; + } else if (strlen(host) < 1) { + free(host); + return TRG_NO_HOSTNAME_SET; + } priv->ssl = trg_prefs_get_bool(prefs, TRG_PREFS_KEY_SSL, TRG_PREFS_PROFILE); diff --git a/src/trg-main-window.c b/src/trg-main-window.c index bf9d3f5..2b85339 100644 --- a/src/trg-main-window.c +++ b/src/trg-main-window.c @@ -208,6 +208,8 @@ struct _TrgMainWindowPrivate { GtkWidget *hpaned, *vpaned; GtkWidget *filterEntry, *filterEntryClearButton; + + gint width, height; }; enum { @@ -316,12 +318,10 @@ static gboolean delete_event(GtkWidget * w, GdkEvent * event G_GNUC_UNUSED, gpoi static void destroy_window(GtkWidget * w, gpointer data G_GNUC_UNUSED) { TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(w); TrgPrefs *prefs = trg_client_get_prefs(priv->client); - int width, height; - gtk_window_get_size(GTK_WINDOW(w), &width, &height); - trg_prefs_set_int(prefs, TRG_PREFS_KEY_WINDOW_HEIGHT, height, + trg_prefs_set_int(prefs, TRG_PREFS_KEY_WINDOW_HEIGHT, priv->height, TRG_PREFS_GLOBAL); - trg_prefs_set_int(prefs, TRG_PREFS_KEY_WINDOW_WIDTH, width, + trg_prefs_set_int(prefs, TRG_PREFS_KEY_WINDOW_WIDTH, priv->width, TRG_PREFS_GLOBAL); trg_tree_view_persist(TRG_TREE_VIEW(priv->peersTreeView)); trg_tree_view_persist(TRG_TREE_VIEW(priv->filesTreeView)); @@ -1553,6 +1553,16 @@ TrgStateSelector *trg_main_window_get_state_selector(TrgMainWindow * win) { return priv->stateSelector; } +static gboolean trg_main_window_config_event(GtkWidget *widget, + GdkEvent *event, + gpointer user_data G_GNUC_UNUSED) +{ + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(widget); + priv->width = event->configure.width; + priv->height = event->configure.height; + return FALSE; +} + static GObject *trg_main_window_constructor(GType type, guint n_construct_properties, GObjectConstructParam * construct_params) { TrgMainWindow *self; @@ -1581,7 +1591,6 @@ static GObject *trg_main_window_constructor(GType type, if (priv->icon) gtk_window_set_default_icon(priv->icon); - notify_init(PACKAGE_NAME); gtk_window_set_title(GTK_WINDOW(self), PACKAGE_NAME); gtk_window_set_default_size(GTK_WINDOW(self), 1000, 600); g_signal_connect(G_OBJECT(self), "delete-event", @@ -1590,6 +1599,8 @@ static GObject *trg_main_window_constructor(GType type, NULL); g_signal_connect(G_OBJECT(self), "window-state-event", G_CALLBACK(window_state_event), NULL); + g_signal_connect(G_OBJECT(self), "configure-event", + G_CALLBACK(trg_main_window_config_event), NULL); priv->torrentModel = trg_torrent_model_new(); trg_client_set_torrent_table(priv->client, -- cgit v1.2.3