(gtk) remember window size & location between sessions
This commit is contained in:
parent
b34e0efecb
commit
29b0b33663
27
gtk/main.c
27
gtk/main.c
|
@ -221,6 +221,26 @@ selectionChangedCB( GtkTreeSelection * s, gpointer unused UNUSED )
|
||||||
refreshTorrentActions( s );
|
refreshTorrentActions( s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
onMainWindowSizeAllocated( GtkWidget * window,
|
||||||
|
GtkAllocation * alloc UNUSED,
|
||||||
|
gpointer gdata UNUSED )
|
||||||
|
{
|
||||||
|
const gboolean isMaximized = window->window
|
||||||
|
&& ( gdk_window_get_state( window->window ) & GDK_WINDOW_STATE_MAXIMIZED );
|
||||||
|
|
||||||
|
if( !isMaximized )
|
||||||
|
{
|
||||||
|
int x, y, w, h;
|
||||||
|
gtk_window_get_position( GTK_WINDOW( window ), &x, &y );
|
||||||
|
gtk_window_get_size( GTK_WINDOW( window ), &w, &h );
|
||||||
|
pref_int_set( PREF_KEY_MAIN_WINDOW_X, x );
|
||||||
|
pref_int_set( PREF_KEY_MAIN_WINDOW_Y, y );
|
||||||
|
pref_int_set( PREF_KEY_MAIN_WINDOW_WIDTH, w );
|
||||||
|
pref_int_set( PREF_KEY_MAIN_WINDOW_HEIGHT, h );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
windowStateChanged( GtkWidget * widget UNUSED, GdkEventWindowState * event, gpointer gdata )
|
windowStateChanged( GtkWidget * widget UNUSED, GdkEventWindowState * event, gpointer gdata )
|
||||||
{
|
{
|
||||||
|
@ -349,10 +369,11 @@ main( int argc, char ** argv )
|
||||||
cbdata->core = tr_core_new( h );
|
cbdata->core = tr_core_new( h );
|
||||||
|
|
||||||
/* create main window now to be a parent to any error dialogs */
|
/* create main window now to be a parent to any error dialogs */
|
||||||
GtkWindow * mainwind = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) );
|
GtkWindow * win = GTK_WINDOW( tr_window_new( myUIManager, cbdata->core ) );
|
||||||
g_signal_connect( mainwind, "window-state-event", G_CALLBACK(windowStateChanged), cbdata );
|
g_signal_connect( win, "window-state-event", G_CALLBACK(windowStateChanged), cbdata );
|
||||||
|
g_signal_connect( win, "size-allocate", G_CALLBACK(onMainWindowSizeAllocated), cbdata );
|
||||||
|
|
||||||
appsetup( mainwind, argfiles, cbdata, startpaused, startminimized );
|
appsetup( win, argfiles, cbdata, startpaused, startminimized );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,6 +62,11 @@ tr_prefs_init_global( void )
|
||||||
pref_int_set_default ( PREF_KEY_UL_LIMIT, 50 );
|
pref_int_set_default ( PREF_KEY_UL_LIMIT, 50 );
|
||||||
pref_flag_set_default ( PREF_KEY_OPTIONS_PROMPT, TRUE );
|
pref_flag_set_default ( PREF_KEY_OPTIONS_PROMPT, TRUE );
|
||||||
|
|
||||||
|
pref_int_set_default ( PREF_KEY_MAIN_WINDOW_HEIGHT, 500 );
|
||||||
|
pref_int_set_default ( PREF_KEY_MAIN_WINDOW_WIDTH, 300 );
|
||||||
|
pref_int_set_default ( PREF_KEY_MAIN_WINDOW_X, 50 );
|
||||||
|
pref_int_set_default ( PREF_KEY_MAIN_WINDOW_Y, 50 );
|
||||||
|
|
||||||
str = NULL;
|
str = NULL;
|
||||||
#if GLIB_CHECK_VERSION(2,14,0)
|
#if GLIB_CHECK_VERSION(2,14,0)
|
||||||
if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DOWNLOAD );
|
if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DOWNLOAD );
|
||||||
|
|
|
@ -49,6 +49,10 @@ GtkWidget * tr_prefs_dialog_new( GObject * core, GtkWindow * parent );
|
||||||
#define PREF_KEY_MAX_PEERS_GLOBAL "max-peers-global"
|
#define PREF_KEY_MAX_PEERS_GLOBAL "max-peers-global"
|
||||||
#define PREF_KEY_MAX_PEERS_PER_TORRENT "max-peers-per-torrent"
|
#define PREF_KEY_MAX_PEERS_PER_TORRENT "max-peers-per-torrent"
|
||||||
#define PREF_KEY_BLOCKLIST_ENABLED "blocklist-enabled"
|
#define PREF_KEY_BLOCKLIST_ENABLED "blocklist-enabled"
|
||||||
|
#define PREF_KEY_MAIN_WINDOW_HEIGHT "main-window-height"
|
||||||
|
#define PREF_KEY_MAIN_WINDOW_WIDTH "main-window-width"
|
||||||
|
#define PREF_KEY_MAIN_WINDOW_X "main-window-x"
|
||||||
|
#define PREF_KEY_MAIN_WINDOW_Y "main-window-y"
|
||||||
|
|
||||||
|
|
||||||
void tr_prefs_init_global( void );
|
void tr_prefs_init_global( void );
|
||||||
|
|
|
@ -179,16 +179,6 @@ makeview( PrivateData * p, TrCore * core )
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
realized_cb ( GtkWidget * wind, gpointer unused UNUSED )
|
|
||||||
{
|
|
||||||
PrivateData * p = get_private_data( GTK_WINDOW( wind ) );
|
|
||||||
sizingmagic( GTK_WINDOW(wind),
|
|
||||||
GTK_SCROLLED_WINDOW( p->scroll ),
|
|
||||||
GTK_POLICY_NEVER,
|
|
||||||
GTK_POLICY_AUTOMATIC );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
prefsChanged( TrCore * core UNUSED, const char * key, gpointer wind )
|
prefsChanged( TrCore * core UNUSED, const char * key, gpointer wind )
|
||||||
{
|
{
|
||||||
|
@ -426,6 +416,7 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core )
|
||||||
char * pch;
|
char * pch;
|
||||||
PrivateData * p;
|
PrivateData * p;
|
||||||
GtkWidget *vbox, *w, *self, *h, *c, *s, *image, *menu;
|
GtkWidget *vbox, *w, *self, *h, *c, *s, *image, *menu;
|
||||||
|
GtkWindow *win;
|
||||||
GSList * l;
|
GSList * l;
|
||||||
GSList * toggles;
|
GSList * toggles;
|
||||||
const char * filter_names[FILTER_MODE_QTY] = {
|
const char * filter_names[FILTER_MODE_QTY] = {
|
||||||
|
@ -452,11 +443,14 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core )
|
||||||
/* make the window */
|
/* make the window */
|
||||||
self = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
self = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
g_object_set_data_full(G_OBJECT(self), PRIVATE_DATA_KEY, p, privateFree );
|
g_object_set_data_full(G_OBJECT(self), PRIVATE_DATA_KEY, p, privateFree );
|
||||||
gtk_window_set_title( GTK_WINDOW( self ), g_get_application_name());
|
win = GTK_WINDOW( self );
|
||||||
gtk_window_set_role( GTK_WINDOW( self ), "tr-main" );
|
gtk_window_set_title( win, g_get_application_name());
|
||||||
gtk_window_add_accel_group (GTK_WINDOW(self),
|
gtk_window_set_role( win, "tr-main" );
|
||||||
gtk_ui_manager_get_accel_group (ui_manager));
|
gtk_window_set_default_size( win, pref_int_get( PREF_KEY_MAIN_WINDOW_WIDTH ),
|
||||||
g_signal_connect( self, "realize", G_CALLBACK(realized_cb), NULL);
|
pref_int_get( PREF_KEY_MAIN_WINDOW_HEIGHT ) );
|
||||||
|
gtk_window_move( win, pref_int_get( PREF_KEY_MAIN_WINDOW_X ),
|
||||||
|
pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) );
|
||||||
|
gtk_window_add_accel_group( win, gtk_ui_manager_get_accel_group( ui_manager ) );
|
||||||
|
|
||||||
/* window's main container */
|
/* window's main container */
|
||||||
vbox = gtk_vbox_new (FALSE, 0);
|
vbox = gtk_vbox_new (FALSE, 0);
|
||||||
|
@ -564,6 +558,7 @@ tr_window_new( GtkUIManager * ui_manager, TrCore * core )
|
||||||
/* workarea */
|
/* workarea */
|
||||||
p->view = makeview( p, core );
|
p->view = makeview( p, core );
|
||||||
w = p->scroll = gtk_scrolled_window_new( NULL, NULL );
|
w = p->scroll = gtk_scrolled_window_new( NULL, NULL );
|
||||||
|
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(w), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC );
|
||||||
gtk_container_add( GTK_CONTAINER(w), p->view );
|
gtk_container_add( GTK_CONTAINER(w), p->view );
|
||||||
gtk_box_pack_start_defaults( GTK_BOX(vbox), w );
|
gtk_box_pack_start_defaults( GTK_BOX(vbox), w );
|
||||||
gtk_container_set_focus_child( GTK_CONTAINER( vbox ), w );
|
gtk_container_set_focus_child( GTK_CONTAINER( vbox ), w );
|
||||||
|
|
32
gtk/util.c
32
gtk/util.c
|
@ -265,38 +265,6 @@ getdownloaddir( void )
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* don't use more than 50% the height of the screen, nor 80% the width.
|
|
||||||
* but don't be too small, either -- set the minimums to 500 x 300
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
sizingmagic( GtkWindow * wind,
|
|
||||||
GtkScrolledWindow * scroll,
|
|
||||||
GtkPolicyType hscroll,
|
|
||||||
GtkPolicyType vscroll )
|
|
||||||
{
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
GtkRequisition req;
|
|
||||||
|
|
||||||
GdkScreen * screen = gtk_widget_get_screen( GTK_WIDGET( wind ) );
|
|
||||||
|
|
||||||
gtk_scrolled_window_set_policy( scroll, GTK_POLICY_NEVER,
|
|
||||||
GTK_POLICY_NEVER );
|
|
||||||
|
|
||||||
gtk_widget_size_request( GTK_WIDGET( wind ), &req );
|
|
||||||
req.height = MAX( req.height, 300 );
|
|
||||||
height = MIN( req.height, gdk_screen_get_height( screen ) / 5 * 4 );
|
|
||||||
|
|
||||||
gtk_scrolled_window_set_policy( scroll, GTK_POLICY_NEVER, vscroll );
|
|
||||||
gtk_widget_size_request( GTK_WIDGET( wind ), &req );
|
|
||||||
req.width = MAX( req.width, 500 );
|
|
||||||
width = MIN( req.width, gdk_screen_get_width( screen ) / 2 );
|
|
||||||
|
|
||||||
gtk_window_set_default_size( wind, width, height );
|
|
||||||
gtk_scrolled_window_set_policy( scroll, hscroll, vscroll );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
onErrorResponse(GtkWidget * dialog, int resp UNUSED, gpointer glist)
|
onErrorResponse(GtkWidget * dialog, int resp UNUSED, gpointer glist)
|
||||||
{
|
{
|
||||||
|
|
|
@ -91,11 +91,6 @@ void gtr_uninhibit_hibernation( guint );
|
||||||
|
|
||||||
#ifdef GTK_MAJOR_VERSION
|
#ifdef GTK_MAJOR_VERSION
|
||||||
|
|
||||||
/* here there be dragons */
|
|
||||||
void
|
|
||||||
sizingmagic( GtkWindow * wind, GtkScrolledWindow * scroll,
|
|
||||||
GtkPolicyType hscroll, GtkPolicyType vscroll );
|
|
||||||
|
|
||||||
/* create an error dialog, if wind is NULL or mapped then show dialog now,
|
/* create an error dialog, if wind is NULL or mapped then show dialog now,
|
||||||
otherwise show it when wind becomes mapped */
|
otherwise show it when wind becomes mapped */
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue