1

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.

Vicente Bolea
  • 1,409
  • 16
  • 39
  • It seems like you want to know how to do this while running a program, not how to do it in code, am I right? – BobMorane Mar 04 '22 at 13:40
  • 1
    @BobMorane Yes, this question is as an user of this application not as an developer, however, it does not mean that I wouldnt accept an answer that involves a patch to their source code for instance. – Vicente Bolea Mar 04 '22 at 16:17

1 Answers1

1

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...

BobMorane
  • 3,870
  • 3
  • 20
  • 42
  • 1
    Great answer, I can see that this is not possible at the moment but there are attempts to make the move to the new API in their developing branch. I will take this as the accepted answer. Thanks! – Vicente Bolea Mar 07 '22 at 18:18