Skip to content

Commit

Permalink
Use Gtk.ColorDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Aug 29, 2024
1 parent 7153354 commit ee05d2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ executable(
dependencies: [
dependency('glib-2.0'),
dependency('gobject-2.0'),
dependency('gtk4'),
dependency('gtk4', version: '>= 4.10.0'),
dependency('granite-7', version: '>= 7.0.0'),
meson.get_compiler('c').find_library('m', required : false)
],
Expand Down
48 changes: 12 additions & 36 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public class MainWindow : Gtk.Window {

private GLib.Settings settings;

private string? prev_foreground_entry = null;
private string? prev_background_entry = null;

public MainWindow (Gtk.Application application) {
Object (application: application);
}
Expand Down Expand Up @@ -126,7 +123,7 @@ public class MainWindow : Gtk.Window {

fg_entry.icon_press.connect ((pos) => {
if (pos == Gtk.EntryIconPosition.SECONDARY) {
on_entry_icon_press (fg_entry);
on_entry_icon_press.begin (fg_entry);
}
});

Expand All @@ -136,7 +133,7 @@ public class MainWindow : Gtk.Window {

bg_entry.icon_press.connect ((pos) => {
if (pos == Gtk.EntryIconPosition.SECONDARY) {
on_entry_icon_press (bg_entry);
on_entry_icon_press.begin (bg_entry);
}
});

Expand All @@ -147,41 +144,20 @@ public class MainWindow : Gtk.Window {
style_results_pane (fg_entry.text, bg_entry.text);
}

private void on_entry_icon_press (Gtk.Entry entry) {
private async void on_entry_icon_press (Gtk.Entry entry) {
gdk_color.parse (entry.text);

var dialog = new Gtk.ColorChooserDialog ("", this) {
deletable = false,
rgba = gdk_color,
show_editor = true
var dialog = new Gtk.ColorDialog () {
modal = true,
with_alpha = false
};
dialog.present ();


dialog.color_activated.connect (() => {
if (entry == fg_entry && prev_foreground_entry == null) {
prev_foreground_entry = entry.text;
} else if (entry == bg_entry && prev_background_entry == null) {
prev_background_entry = entry.text;
}

entry.text = dialog.rgba.to_string ();
});

// if (dialog.run () == Gtk.ResponseType.OK) {
// entry.text = widget.current_rgba.to_string ();
// } else {
// if (prev_foreground_entry != null) {
// fg_entry.text = prev_foreground_entry;
// }

// if (prev_background_entry != null) {
// bg_entry.text = prev_background_entry;
// }
// }

prev_foreground_entry = null;
prev_background_entry = null;
try {
var rgba = yield dialog.choose_rgba (this, gdk_color, null);
entry.text = rgba.to_string ();
} catch (Error e) {
critical ("failed to get color");
}
}

private void on_entry_changed () {
Expand Down

0 comments on commit ee05d2c

Please # to comment.