Changeset 5662


Ignore:
Timestamp:
Apr 21, 2008, 8:58:39 PM (14 years ago)
Author:
charles
Message:

(gtk) remember window size & location between sessions

Location:
trunk/gtk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r5646 r5662  
    223223
    224224static void
     225onMainWindowSizeAllocated( GtkWidget      * window,
     226                           GtkAllocation  * alloc UNUSED,
     227                           gpointer         gdata UNUSED )
     228{
     229    const gboolean isMaximized = window->window
     230        && ( gdk_window_get_state( window->window ) & GDK_WINDOW_STATE_MAXIMIZED );
     231
     232    if( !isMaximized )
     233    {
     234        int x, y, w, h;
     235        gtk_window_get_position( GTK_WINDOW( window ), &x, &y );
     236        gtk_window_get_size( GTK_WINDOW( window ), &w, &h );
     237        pref_int_set( PREF_KEY_MAIN_WINDOW_X, x );
     238        pref_int_set( PREF_KEY_MAIN_WINDOW_Y, y );
     239        pref_int_set( PREF_KEY_MAIN_WINDOW_WIDTH, w );
     240        pref_int_set( PREF_KEY_MAIN_WINDOW_HEIGHT, h );
     241    }
     242}
     243
     244static void
    225245windowStateChanged( GtkWidget * widget UNUSED, GdkEventWindowState * event, gpointer gdata )
    226246{
     
    350370
    351371        /* create main window now to be a parent to any error dialogs */
    352         GtkWindow * mainwind = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) );
    353         g_signal_connect( mainwind, "window-state-event", G_CALLBACK(windowStateChanged), cbdata );
    354 
    355         appsetup( mainwind, argfiles, cbdata, startpaused, startminimized );
     372        GtkWindow * win = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) );
     373        g_signal_connect( win, "window-state-event", G_CALLBACK(windowStateChanged), cbdata );
     374        g_signal_connect( win, "size-allocate", G_CALLBACK(onMainWindowSizeAllocated), cbdata );
     375
     376        appsetup( win, argfiles, cbdata, startpaused, startminimized );
    356377    }
    357378    else
  • trunk/gtk/tr-prefs.c

    r5605 r5662  
    6262    pref_int_set_default    ( PREF_KEY_UL_LIMIT, 50 );
    6363    pref_flag_set_default   ( PREF_KEY_OPTIONS_PROMPT, TRUE );
     64
     65    pref_int_set_default    ( PREF_KEY_MAIN_WINDOW_HEIGHT, 500 );
     66    pref_int_set_default    ( PREF_KEY_MAIN_WINDOW_WIDTH, 300 );
     67    pref_int_set_default    ( PREF_KEY_MAIN_WINDOW_X, 50 );
     68    pref_int_set_default    ( PREF_KEY_MAIN_WINDOW_Y, 50 );
    6469
    6570    str = NULL;
  • trunk/gtk/tr-prefs.h

    r5605 r5662  
    5050#define PREF_KEY_MAX_PEERS_PER_TORRENT  "max-peers-per-torrent"
    5151#define PREF_KEY_BLOCKLIST_ENABLED      "blocklist-enabled"
     52#define PREF_KEY_MAIN_WINDOW_HEIGHT     "main-window-height"
     53#define PREF_KEY_MAIN_WINDOW_WIDTH      "main-window-width"
     54#define PREF_KEY_MAIN_WINDOW_X          "main-window-x"
     55#define PREF_KEY_MAIN_WINDOW_Y          "main-window-y"
    5256
    5357
  • trunk/gtk/tr-window.c

    r5478 r5662  
    181181
    182182static void
    183 realized_cb ( GtkWidget * wind, gpointer unused UNUSED )
    184 {
    185     PrivateData * p = get_private_data( GTK_WINDOW( wind ) );
    186     sizingmagic( GTK_WINDOW(wind),
    187                  GTK_SCROLLED_WINDOW( p->scroll ),
    188                  GTK_POLICY_NEVER,
    189                  GTK_POLICY_AUTOMATIC );
    190 }
    191 
    192 static void
    193183prefsChanged( TrCore * core UNUSED, const char * key, gpointer wind )
    194184{
     
    427417    PrivateData * p;
    428418    GtkWidget *vbox, *w, *self, *h, *c, *s, *image, *menu;
     419    GtkWindow *win;
    429420    GSList * l;
    430421    GSList * toggles;
     
    453444    self = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    454445    g_object_set_data_full(G_OBJECT(self), PRIVATE_DATA_KEY, p, privateFree );
    455     gtk_window_set_title( GTK_WINDOW( self ), g_get_application_name());
    456     gtk_window_set_role( GTK_WINDOW( self ), "tr-main" );
    457     gtk_window_add_accel_group (GTK_WINDOW(self),
    458                                 gtk_ui_manager_get_accel_group (ui_manager));
    459     g_signal_connect( self, "realize", G_CALLBACK(realized_cb), NULL);
     446    win = GTK_WINDOW( self );
     447    gtk_window_set_title( win, g_get_application_name());
     448    gtk_window_set_role( win, "tr-main" );
     449    gtk_window_set_default_size( win, pref_int_get( PREF_KEY_MAIN_WINDOW_WIDTH ),
     450                                      pref_int_get( PREF_KEY_MAIN_WINDOW_HEIGHT ) );
     451    gtk_window_move( win, pref_int_get( PREF_KEY_MAIN_WINDOW_X ),
     452                          pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) );
     453    gtk_window_add_accel_group( win, gtk_ui_manager_get_accel_group( ui_manager ) );
    460454
    461455    /* window's main container */
     
    565559    p->view = makeview( p, core );
    566560    w = p->scroll = gtk_scrolled_window_new( NULL, NULL );
     561    gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(w), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
    567562    gtk_container_add( GTK_CONTAINER(w), p->view );
    568563    gtk_box_pack_start_defaults( GTK_BOX(vbox), w );
  • trunk/gtk/util.c

    r5658 r5662  
    266266}
    267267
    268 /**
    269  * don't use more than 50% the height of the screen, nor 80% the width.
    270  * but don't be too small, either -- set the minimums to 500 x 300
    271  */
    272 void
    273 sizingmagic( GtkWindow         * wind,
    274              GtkScrolledWindow * scroll,
    275              GtkPolicyType       hscroll,
    276              GtkPolicyType       vscroll )
    277 {
    278     int width;
    279     int height;
    280     GtkRequisition req;
    281 
    282     GdkScreen * screen = gtk_widget_get_screen( GTK_WIDGET( wind ) );
    283 
    284     gtk_scrolled_window_set_policy( scroll, GTK_POLICY_NEVER,
    285                                             GTK_POLICY_NEVER );
    286 
    287     gtk_widget_size_request( GTK_WIDGET( wind ), &req );
    288     req.height = MAX( req.height, 300 );
    289     height = MIN( req.height, gdk_screen_get_height( screen ) / 5 * 4 );
    290 
    291     gtk_scrolled_window_set_policy( scroll, GTK_POLICY_NEVER, vscroll );
    292     gtk_widget_size_request( GTK_WIDGET( wind ), &req );
    293     req.width = MAX( req.width, 500 );
    294     width = MIN( req.width, gdk_screen_get_width( screen ) / 2 );
    295 
    296     gtk_window_set_default_size( wind, width, height );
    297     gtk_scrolled_window_set_policy( scroll, hscroll, vscroll );
    298 }
    299 
    300268static void
    301269onErrorResponse(GtkWidget * dialog, int resp UNUSED, gpointer glist)
  • trunk/gtk/util.h

    r5605 r5662  
    9292#ifdef GTK_MAJOR_VERSION
    9393
    94 /* here there be dragons */
    95 void
    96 sizingmagic( GtkWindow * wind, GtkScrolledWindow * scroll,
    97              GtkPolicyType hscroll, GtkPolicyType vscroll );
    98 
    9994/* create an error dialog, if wind is NULL or mapped then show dialog now,
    10095   otherwise show it when wind becomes mapped */
Note: See TracChangeset for help on using the changeset viewer.