[gnome-latex: 61/205] Unmaximization: best method



commit 504bd1b27f2c94e56a05f3064d3042f46fbd9185
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Sun Sep 13 01:57:22 2009 +0200

    Unmaximization: best method
    
    When saving preferences, if the window is maximized, the sizes of the
    window are reduced by 100, else making window non-maximized the next
    time will have no effect.
    
    There was previously a problem with this method because the left/top
    widgets was packed into the panes with "gtk_paned_pack1 (paned, widget,
    TRUE, TRUE)", so the position of the panes increased... Now the widgets
    are packed into the panes with the gtk_paned_add* functions.
    
    If needed, the previous method is in the previous commit ;)

 src/callbacks.c | 35 -----------------------------------
 src/callbacks.h |  2 --
 src/main.c      | 20 +++++++-------------
 src/prefs.c     | 12 ++++++++++++
 4 files changed, 19 insertions(+), 50 deletions(-)
---
diff --git a/src/callbacks.c b/src/callbacks.c
index 02328b4..25f845a 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -859,41 +859,6 @@ cb_show_symbol_tables (GtkToggleAction *toggle_action, gpointer user_data)
                gtk_widget_hide (latexila.symbols->vbox);
 }
 
-gboolean
-cb_window_unmaximized (GtkWidget *widget, GdkEventWindowState *event,
-               gpointer user_data)
-{
-       // TODO is there an easier way to do that?
-       // TODO disconnect the signal instead of using a static bool?
-
-       static gboolean first_time = TRUE;
-
-       if (! first_time)
-               return FALSE;
-
-       if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED)
-       {
-               if (! (event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED)
-                               && first_time)
-               {
-                       // For the first unmaximisation, decrease a little the size of the
-                       // window. Without that, the window would keep the same size.
-
-                       gint width = latexila.prefs->window_width;
-                       gint height = latexila.prefs->window_height;
-                       width -= width / 10;
-                       height -= height / 10;
-                       gtk_window_resize (latexila.main_window, width, height);
-
-                       first_time = FALSE;
-                       return TRUE;
-               }
-       }
-
-       // let the event propagate further
-       return FALSE;
-}
-
 void
 open_new_document (const gchar *filename, const gchar *uri)
 {
diff --git a/src/callbacks.h b/src/callbacks.h
index a5f1e10..c86b99e 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -66,8 +66,6 @@ void cb_font_set (GtkFontButton *font_button, gpointer user_data);
 void cb_category_symbols_selected (GtkIconView *icon_view, gpointer user_data);
 void cb_symbol_selected (GtkIconView *icon_view, gpointer user_data);
 void cb_show_symbol_tables (GtkToggleAction *toggle_action, gpointer user_data);
-gboolean cb_window_unmaximized (GtkWidget *widget, GdkEventWindowState *event,
-               gpointer user_data);
 
 void open_new_document (const gchar *filename, const gchar *uri);
 
diff --git a/src/main.c b/src/main.c
index 2df05f0..d947e5d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -149,16 +149,10 @@ main (int argc, char *argv[])
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
        gtk_window_set_default_size (GTK_WINDOW (window),
                        latexila.prefs->window_width, latexila.prefs->window_height);
+
        if (latexila.prefs->window_maximised)
-       {
                gtk_window_maximize (GTK_WINDOW (window));
 
-               // For the first unmaximisation, decrease a little the size of the
-               // window. Without that, the window would keep the same size.
-               g_signal_connect (G_OBJECT (window), "window-state-event",
-                               G_CALLBACK (cb_window_unmaximized), NULL);
-       }
-
 
        /* menubar and toolbar */
        GtkWidget *main_vbox = gtk_vbox_new (FALSE, 0);
@@ -180,7 +174,7 @@ main (int argc, char *argv[])
        latexila.symbols = g_malloc (sizeof (symbols_t));
        GtkWidget *vbox_symbols = gtk_vbox_new (FALSE, 0);
        latexila.symbols->vbox = vbox_symbols;
-       gtk_paned_pack1 (GTK_PANED (main_hpaned), vbox_symbols, TRUE, TRUE);
+       gtk_paned_add1 (GTK_PANED (main_hpaned), vbox_symbols);
 
        init_symbols ();
 
@@ -191,7 +185,7 @@ main (int argc, char *argv[])
        GtkWidget *vpaned = gtk_vpaned_new ();
        latexila.vpaned = GTK_PANED (vpaned);
        gtk_paned_set_position (GTK_PANED (vpaned), latexila.prefs->vpaned_pos);
-       gtk_paned_pack2 (GTK_PANED (main_hpaned), vpaned, TRUE, TRUE);
+       gtk_paned_add2 (GTK_PANED (main_hpaned), vpaned);
 
        /* source view with tabs */
        GtkWidget *notebook = gtk_notebook_new ();
@@ -199,7 +193,7 @@ main (int argc, char *argv[])
        gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
        g_signal_connect (G_OBJECT (notebook), "switch-page",
                        G_CALLBACK (cb_page_change), NULL);
-       gtk_paned_pack1 (GTK_PANED (vpaned), notebook, TRUE, TRUE);
+       gtk_paned_add1 (GTK_PANED (vpaned), notebook);
 
        /* log zone */
        latexila.action_log = g_malloc (sizeof (action_log_t));
@@ -210,7 +204,7 @@ main (int argc, char *argv[])
        GtkWidget *hpaned = gtk_hpaned_new ();
        latexila.log_hpaned = GTK_PANED (hpaned);
        gtk_paned_set_position (GTK_PANED (hpaned), latexila.prefs->log_hpaned_pos);
-       gtk_paned_pack2 (GTK_PANED (vpaned), hpaned, TRUE, TRUE);
+       gtk_paned_add2 (GTK_PANED (vpaned), hpaned);
 
        // action history
        GtkListStore *list_store = gtk_list_store_new (N_COLUMNS_ACTION,
@@ -239,7 +233,7 @@ main (int argc, char *argv[])
        scrollbar = gtk_scrolled_window_new (NULL, NULL);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollbar),
                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-       gtk_paned_pack1 (GTK_PANED (hpaned), scrollbar, TRUE, TRUE);
+       gtk_paned_add1 (GTK_PANED (hpaned), scrollbar);
        gtk_container_add (GTK_CONTAINER (scrollbar), list_view);
        
        // log details
@@ -257,7 +251,7 @@ main (int argc, char *argv[])
        scrollbar = gtk_scrolled_window_new (NULL, NULL);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollbar),
                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-       gtk_paned_pack2 (GTK_PANED (hpaned), scrollbar, TRUE, TRUE);
+       gtk_paned_add2 (GTK_PANED (hpaned), scrollbar);
        gtk_container_add (GTK_CONTAINER (scrollbar), log_view);
 
        // tags
diff --git a/src/prefs.c b/src/prefs.c
index 3fac2b1..61ded6a 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -208,6 +208,18 @@ save_preferences (preferences_t *prefs)
 
        gint window_width, window_height;
        gtk_window_get_size (latexila.main_window, &window_width, &window_height);
+
+       // If window is maximized, store sizes that are a bit smaller than full
+       // screen, else making window non-fullscreen will have no effect.
+       // Attention, the left/top widgets must be packed in paned with
+       // gtk_paned_add1 () and not "gtk_paned_pack1 (paned, widget, TRUE, TRUE)",
+       // else the positions panes will inexplicably increase...
+       if (window_maximised)
+       {
+               window_width -= 100;
+               window_height -= 100;
+       }
+
        g_key_file_set_integer (key_file, PROGRAM_NAME, "window_width",
                        window_width);
        g_key_file_set_integer (key_file, PROGRAM_NAME, "window_height",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]