Added support for geometry option (not fully tested). geometry
authorHugo Villeneuve <hugo@hugovil.com>
Tue, 25 Mar 2014 02:01:41 +0000 (22:01 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Wed, 26 Mar 2014 22:56:17 +0000 (18:56 -0400)
src/cdplay.c
src/discedit.c
src/grip.c
src/grip.h

index 5a30509..f26ff35 100644 (file)
@@ -326,7 +326,7 @@ void MakeTrackPage(GripInfo *ginfo)
 
   gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_FIXED);
   gtk_tree_view_column_set_fixed_width(column,
-                                       uinfo->win_width-
+                                       uinfo->size_hints.base_width-
                                        (GetLengthRipWidth(ginfo)+15));
 
   gtk_tree_view_append_column(GTK_TREE_VIEW(uinfo->track_list),column);
@@ -1056,8 +1056,8 @@ void MinMax(GtkWidget *widget,gpointer data)
                                 WINWIDTH,WINHEIGHT);
 
     gtk_window_resize(GTK_WINDOW(uinfo->app),
-                      uinfo->win_width,
-                      uinfo->win_height);
+                      uinfo->size_hints.base_width,
+                      uinfo->size_hints.base_height);
   }
   else {
     gtk_container_border_width(GTK_CONTAINER(uinfo->winbox),0);
@@ -1077,8 +1077,8 @@ void MinMax(GtkWidget *widget,gpointer data)
                                 MIN_WINWIDTH,MIN_WINHEIGHT);
 
     gtk_window_resize(GTK_WINDOW(uinfo->app),
-                      uinfo->win_width_min,
-                      uinfo->win_height_min);
+                      uinfo->size_hints.min_width,
+                      uinfo->size_hints.min_height);
 
     UpdateGTK();
   }
@@ -1617,12 +1617,12 @@ void UpdateDisplay(GripInfo *ginfo)
   
   if(!uinfo->minimized) {
     if(uinfo->track_edit_visible) {
-      gtk_window_get_size(GTK_WINDOW(uinfo->app),&uinfo->win_width,
+      gtk_window_get_size(GTK_WINDOW(uinfo->app),&uinfo->size_hints.base_width,
                           &uinfo->win_height_edit);
     }
     else
-      gtk_window_get_size(GTK_WINDOW(uinfo->app),&uinfo->win_width,
-                          &uinfo->win_height);
+      gtk_window_get_size(GTK_WINDOW(uinfo->app),&uinfo->size_hints.base_width,
+                          &uinfo->size_hints.base_height);
     
     if(old_width &&
        (old_width != uinfo->track_list->allocation.width)) {
@@ -1632,8 +1632,8 @@ void UpdateDisplay(GripInfo *ginfo)
     old_width=uinfo->track_list->allocation.width;
   }
   else {
-    gtk_window_get_size(GTK_WINDOW(uinfo->app),&uinfo->win_width_min,
-                        &uinfo->win_height_min);
+    gtk_window_get_size(GTK_WINDOW(uinfo->app),&uinfo->size_hints.min_width,
+                        &uinfo->size_hints.min_height);
   }
 
   if(!ginfo->looking_up) {
index 9b37586..4a0a41b 100644 (file)
@@ -311,8 +311,8 @@ void ToggleTrackEdit(GtkWidget *widget,gpointer data)
 
   if(uinfo->track_edit_visible) {
     gtk_window_resize(GTK_WINDOW(uinfo->app),
-                      uinfo->win_width,
-                      uinfo->win_height);
+                      uinfo->size_hints.base_width,
+                      uinfo->size_hints.base_height);
 
     gtk_widget_hide(uinfo->track_edit_box);
     UpdateGTK();
@@ -323,7 +323,7 @@ void ToggleTrackEdit(GtkWidget *widget,gpointer data)
     gtk_widget_show(uinfo->track_edit_box);
 
     gtk_window_resize(GTK_WINDOW(uinfo->app),
-                      uinfo->win_width,
+                      uinfo->size_hints.base_width,
                       uinfo->win_height_edit);
   }
 
index 1183d87..8d65a3e 100644 (file)
@@ -126,11 +126,11 @@ void DoSaveConfig(GripInfo *ginfo);
 {"selected_ripper",CFG_ENTRY_INT,0,&ginfo->selected_ripper},\
 {"play_mode",CFG_ENTRY_INT,0,&ginfo->play_mode},\
 {"playloop",CFG_ENTRY_BOOL,0,&ginfo->playloop},\
-{"win_width",CFG_ENTRY_INT,0,&uinfo->win_width},\
-{"win_height",CFG_ENTRY_INT,0,&uinfo->win_height},\
+{"win_width",CFG_ENTRY_INT,0,&uinfo->size_hints.base_width},\
+{"win_height",CFG_ENTRY_INT,0,&uinfo->size_hints.base_height},\
 {"win_height_edit",CFG_ENTRY_INT,0,&uinfo->win_height_edit},\
-{"win_width_min",CFG_ENTRY_INT,0,&uinfo->win_width_min},\
-{"win_height_min",CFG_ENTRY_INT,0,&uinfo->win_height_min},\
+{"win_width_min",CFG_ENTRY_INT,0,&uinfo->size_hints.min_width},\
+{"win_height_min",CFG_ENTRY_INT,0,&uinfo->size_hints.min_height},\
 {"win_pos_x",CFG_ENTRY_INT,0,&uinfo->x},\
 {"win_pos_y",CFG_ENTRY_INT,0,&uinfo->y},\
 {"vol_vis",CFG_ENTRY_BOOL,0,&uinfo->volvis},\
@@ -156,7 +156,7 @@ gboolean AppWindowStateCB(GtkWidget *widget, GdkEventWindowState *event, gpointe
   GripInfo *ginfo = (GripInfo*)data;
   GripGUI *uinfo = &(ginfo->gui_info);
   GdkWindowState state = event->new_window_state;
-       
+
   if ((state & GDK_WINDOW_STATE_WITHDRAWN) || (state & GDK_WINDOW_STATE_ICONIFIED)) {
     ginfo->app_visible = FALSE;
     return TRUE;
@@ -193,31 +193,39 @@ GtkWidget *GripNew(const gchar* geometry,char *device,char *scsi_device,
   uinfo->encode_status_window=NULL;
   uinfo->track_list=NULL;
 
-  uinfo->win_width=WINWIDTH;
-  uinfo->win_height=WINHEIGHT;
+  /* Size hints */
+  uinfo->size_hints.min_width = MIN_WINWIDTH;
+  uinfo->size_hints.min_height = MIN_WINHEIGHT;
+  uinfo->size_hints.base_width = WINWIDTH;
+  uinfo->size_hints.base_height = WINHEIGHT;
+  uinfo->size_hints.width_inc = 10;
+  uinfo->size_hints.height_inc = 10;
+
   uinfo->win_height_edit=WINHEIGHTEDIT;
-  uinfo->win_width_min=MIN_WINWIDTH;
-  uinfo->win_height_min=MIN_WINHEIGHT;
-
-  /*  if(geometry != NULL) {
-    gint x,y,w,h;
-    
-    if(gnome_parse_geometry(geometry, 
-                           &x,&y,&w,&h)) {
-      if(x != -1) {
-       gtk_widget_set_uposition(app,x,y);
-      }
-      
-      if(w != -1) {
-        uinfo->win_width=w;
-        uinfo->win_height=h;
-      }
-    }
-    else {
-      g_error(_("Could not parse geometry string `%s'"), geometry);
+
+  gtk_window_set_geometry_hints(GTK_WINDOW(app), app,
+                               &uinfo->size_hints,
+                               GDK_HINT_MIN_SIZE |
+                               GDK_HINT_BASE_SIZE |
+                               GDK_HINT_RESIZE_INC);
+
+  if(geometry != NULL) {
+    /*
+      If either a size or a position can be extracted from the geometry string,
+      gtk-window-parse-geometry returns â€˜#t’ and calls
+      gtk-window-set-default-size and/or gtk-window-move to resize/move the
+      window.
+    */
+    if (!gtk_window_parse_geometry(GTK_WINDOW(app), geometry)) {
+      fprintf (stderr, "Failed to parse geometry string '%s'\n", geometry);
+    } else {
+      /* For saving the position */
+      gtk_window_get_position(GTK_WINDOW(uinfo->app), &uinfo->x, &uinfo->y);
     }
   }
-  */
+
+  Debug("X = %d\n", uinfo->x);
+  Debug("Y = %d\n", uinfo->y);
 
   if(config_filename && *config_filename)
     g_snprintf(ginfo->config_filename,256,"%s",config_filename);
@@ -253,23 +261,27 @@ GtkWidget *GripNew(const gchar* geometry,char *device,char *scsi_device,
     gtk_widget_set_size_request(GTK_WIDGET(app),MIN_WINWIDTH,
                                 MIN_WINHEIGHT);
 
-    gtk_window_resize(GTK_WINDOW(app),uinfo->win_width_min,
-                                uinfo->win_height_min);
+    gtk_window_resize(GTK_WINDOW(app),uinfo->size_hints.min_width,
+                                uinfo->size_hints.min_height);
   }
   else {
     gtk_widget_set_size_request(GTK_WIDGET(app),WINWIDTH,
                                 WINHEIGHT);
 
     if(uinfo->track_edit_visible) {
-      gtk_window_resize(GTK_WINDOW(app),uinfo->win_width,
+      gtk_window_resize(GTK_WINDOW(app),uinfo->size_hints.base_width,
                         uinfo->win_height_edit);
     }
     else {
-      gtk_window_resize(GTK_WINDOW(app),uinfo->win_width,
-                        uinfo->win_height);
+      gtk_window_resize(GTK_WINDOW(app),uinfo->size_hints.base_width,
+                        uinfo->size_hints.base_height);
     }
   }
 
+  Debug("X = %d\n", uinfo->x);
+  Debug("Y = %d\n", uinfo->y);
+  gtk_window_move(GTK_WINDOW(app), uinfo->x, uinfo->y);
+
   /* Position window from values in config file. */
   gtk_window_move(GTK_WINDOW(app),uinfo->x, uinfo->y);
 
index 396ffa1..0e88fb0 100644 (file)
@@ -63,11 +63,8 @@ typedef struct _grip_gui {
   GtkWidget *winbox;
   GtkWidget *notebook;
   gboolean minimized;
-  int win_width;
-  int win_height;
+  GdkGeometry size_hints;
   int win_height_edit;
-  int win_width_min;
-  int win_height_min;
   int x;
   int y;
   GtkStyle *style_wb;