RE: Window size and position



Good morning,

Am Freitag, den 22.04.2005, 11:39 -0400 schrieb Freddie Unpenstein:
I'm currently coding a small application. I want the main window to
remember its size and position every time it is started.

I believe that's the job of the window manager...
That's why you can set a couple different names for your window.

I believed this, too. But it isn't done by the window-manager.

In my applications I use this code:

void save_main_window(GConfClient *conf, GtkWidget *app_main_wnd) {
 GError *error = NULL;
 gint  x, y;
 
 if (conf != NULL) {
  gtk_window_get_position(GTK_WINDOW(app_main_wnd), &x, &y);
  gconf_client_set_pair(conf, "/apps/application/pos",
   GCONF_VALUE_INT, GCONF_VALUE_INT, &x, &y, &error);
  if (error != NULL) {
   g_print("gconf_client_set_pair (pos): %s\n", error->message);
   g_error_free(error);
   error = NULL;
  }
   
  gtk_window_get_size(GTK_WINDOW(app_main_wnd), &x, &y);
  gconf_client_set_pair(conf, "/apps/application/size", 
   GCONF_VALUE_INT, GCONF_VALUE_INT, &x, &y, &error);
  if (error != NULL) {
   g_print("gconf_client_set_pair (size): %s\n", error->message);
   g_error_free(error);
   error = NULL;
  }
  /* IMPORTANT!!! */
  gconf_client_suggest_sync(conf, &error);
  if (error != NULL) {
   g_print("gconf_client_sync (): %s\n", error->message);
   g_error_free(error);
   error = NULL;
  }
 }
}

void load_main_window() {
 GError *error = NULL;
 gint  x, y;
 
 if (conf != NULL) {
  x = 0; y = 0;
  if (!gconf_client_get_pair(conf, "/apps/application/pos", 
    GCONF_VALUE_INT, GCONF_VALUE_INT, &x, &y, &error)) {
   if (error != NULL) {
    g_print("gconf_client_get_pair (pos): %s\n", error->message);
    g_error_free(error);
   }
  }
  gtk_window_move(GTK_WINDOW(app_main_wnd), x, y);

  error = NULL;
  x = 800; y = 600;
  if (!gconf_client_get_pair(conf, "/apps/application/size", 
    GCONF_VALUE_INT, GCONF_VALUE_INT, &x, &y, &error)) {
   if (error != NULL) {
    g_print("gconf_client_get_pair (size): %s\n", error->message);
    g_error_free(error);
   }
  }
  gtk_window_resize(GTK_WINDOW(app_main_wnd), x, y);
 }
}

I hope this will help you.

The line marked "IMPORTANT" is really important.
The function "gconf_client_suggest_sync" will write all data to the
configuration file!
Also you must replace "application" by your application-name.
Best regards

JÃrgen



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