Search code examples
colorsgtkgnomepalettedia

Permanently change the color palette in the GTK color picker


When using the color picker widget GTK applications I often use a different color Palette to the one given by default, as shown in the picture below. While the program is running I can change the defaults colors and they stay changed, however, when I close the program those modifications disappear.

Color picker in DIA

I wonder how I can make those modifications to persistent in disk.


Solution

  • From the tags you chose, the application name seems to be Dia. In the application, nothing lets you set this option. So the short answer is: no.

    The issue is that Dia uses the now deprecated GtkColorSelectionDialog (in favor of GtkColorChooserDialog). In the deprecated version, there is a flag to tell the widget to show/hide the color palette, but that's pretty much the only control you have (see gtk_color_selection_set_has_palette).

    In the new widget version (which, by the way, looks totally different), you have direct access to a gtk_color_chooser_add_palette:

    void
    gtk_color_chooser_add_palette (GtkColorChooser *chooser,
                                   GtkOrientation orientation,
                                   gint colors_per_line,
                                   gint n_colors,
                                   GdkRGBA *colors);
    

    You can see you have much more options as far as customizing the palette is concerned. You even have the ability to decide the colors. This means you could save your current selection in the palette. Then, at application quit, you could save all the palette's colors in some sort of settings, and load them back at application start.

    As a final note, I looked at the Dia source code and found that they seem to be looking to make the move to the new widget. Here is an excerpt:

    // ...
    
    window = self->color_select = 
       /*gtk_color_chooser_dialog_new (self->edit_color == FOREGROUND ? 
                                       _("Select foreground color") : _("Select background color"), 
                                       GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));*/ 
       gtk_color_selection_dialog_new (self->edit_color == FOREGROUND ? 
                                       _("Select foreground color") : _("Select background color")); 
      
     selection = gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (self->color_select)); 
      
     self->color_select_active = 1; 
     //gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (window), TRUE); 
     gtk_color_selection_set_has_opacity_control (GTK_COLOR_SELECTION (selection), TRUE);
    
    // ...
    

    From the commented code, it seems they are trying to make the move...