From d5170b0025a8f090a21c8e5f0c12aaeffeea8a65 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 29 Aug 2025 03:54:31 +0200 Subject: [PATCH] Use non-modal color dialog for Trigger UI --- gtk2_ardour/slot_properties_box.cc | 2 +- gtk2_ardour/trigger_ui.cc | 43 +++++++++++++----------------- gtk2_ardour/trigger_ui.h | 7 ++--- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/gtk2_ardour/slot_properties_box.cc b/gtk2_ardour/slot_properties_box.cc index fa262926dd..cbea197e92 100644 --- a/gtk2_ardour/slot_properties_box.cc +++ b/gtk2_ardour/slot_properties_box.cc @@ -236,7 +236,7 @@ SlotPropertyTable::SlotPropertyTable () _load_button.signal_clicked.connect (sigc::bind((sigc::mem_fun (*this, (&TriggerUI::choose_sample))), false)); _color_button.set_name("FollowAction"); - _color_button.signal_clicked.connect (sigc::mem_fun (*this, (&TriggerUI::choose_color))); + _color_button.signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, (&TriggerUI::choose_color)), dynamic_cast (get_toplevel()))); _follow_size_group = Gtk::SizeGroup::create (Gtk::SIZE_GROUP_VERTICAL); _follow_size_group->add_widget(_name_frame); diff --git a/gtk2_ardour/trigger_ui.cc b/gtk2_ardour/trigger_ui.cc index 4dbd6f21f4..0488272840 100644 --- a/gtk2_ardour/trigger_ui.cc +++ b/gtk2_ardour/trigger_ui.cc @@ -49,6 +49,7 @@ #include "keyboard.h" #include "public_editor.h" #include "region_view.h" +#include "stripable_colorpicker.h" #include "trigger_jump_dialog.h" #include "ui_config.h" @@ -143,34 +144,17 @@ TriggerUI::trigger_swap (uint32_t n) } void -TriggerUI::choose_color () +TriggerUI::choose_color (Gtk::Window* parent) { - // TODO use StripableColorDialog and see note there regarding eyedropper.. if (!_color_dialog) { - _color_dialog = new Gtk::ColorSelectionDialog; + _color_dialog = new StripableColorDialog; + color_connection.disconnect (); } - _color_dialog->get_color_selection()->set_has_opacity_control (false); - _color_dialog->get_color_selection()->set_has_palette (true); - _color_dialog->get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (_color_dialog, &Gtk::Dialog::response), Gtk::RESPONSE_ACCEPT)); - _color_dialog->get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (_color_dialog, &Gtk::Dialog::response), Gtk::RESPONSE_CANCEL)); + tref.box()->DropReferences.connect (trigger_connections,invalidator (*this), [this]() { _color_dialog->reset (); color_connection.disconnect (); }, gui_context()); + color_connection = _color_dialog->ColorChanged.connect ([this](uint32_t color) { if (trigger ()) { trigger()->set_color(color); }}); - Gdk::Color c = Gtkmm2ext::gdk_color_from_rgba(trigger()->color()); - - _color_dialog->get_color_selection()->set_previous_color (c); - _color_dialog->get_color_selection()->set_current_color (c); - - switch (_color_dialog->run()) { - case Gtk::RESPONSE_ACCEPT: { - c = _color_dialog->get_color_selection()->get_current_color(); - color_t ct = Gtkmm2ext::gdk_color_to_rgba(c); - trigger()->set_color(ct); - } break; - default: - break; - } - - _color_dialog->hide (); + _color_dialog->popup (_("Set Trigger Color"), trigger()->color(), parent); } void @@ -406,7 +390,7 @@ TriggerUI::context_menu () items.push_back (MenuElem (_("Load..."), sigc::bind(sigc::mem_fun (*this, (&TriggerUI::choose_sample)), true))); items.push_back (SeparatorElem()); - items.push_back (MenuElem (_("Color..."), sigc::mem_fun (*this, &TriggerUI::choose_color))); + items.push_back (MenuElem (_("Color..."), sigc::bind (sigc::mem_fun (*this, &TriggerUI::choose_color), (Gtk::Window*)NULL))); items.push_back (MenuElem (_("Clear"), sigc::mem_fun (*this, &TriggerUI::clear_trigger))); items.push_back (SeparatorElem()); items.push_back (MenuElem (_("MIDI Learn"), sigc::mem_fun (*this, &TriggerUI::trigger_midi_learn))); @@ -805,5 +789,16 @@ TriggerUI::set_trigger (ARDOUR::TriggerReference tr) tref.box()->TriggerSwapped.connect (trigger_swap_connection, invalidator (*this), std::bind (&TriggerUI::trigger_swap, this, _1), gui_context ()); + if (_color_dialog) { + if (trigger()) { + Gdk::Color c = Gtkmm2ext::gdk_color_from_rgba(trigger()->color()); + _color_dialog->get_color_selection()->set_previous_color (c); + _color_dialog->get_color_selection()->set_current_color (c); + } else { + color_connection.disconnect (); + _color_dialog->reset (); + } + } + on_trigger_set(); //derived classes can do initialization here } diff --git a/gtk2_ardour/trigger_ui.h b/gtk2_ardour/trigger_ui.h index 0e480f51ff..ca47252583 100644 --- a/gtk2_ardour/trigger_ui.h +++ b/gtk2_ardour/trigger_ui.h @@ -18,7 +18,6 @@ #pragma once -#include "ytkmm/colorselection.h" #include "ytkmm/entry.h" #include "gtkmm2ext/actions.h" @@ -35,6 +34,7 @@ namespace Gtk } class TriggerJumpDialog; +class StripableColorDialog; class TriggerUI : virtual public sigc::trackable { @@ -67,7 +67,7 @@ public: ARDOUR::TriggerPtr trigger() const; ARDOUR::TriggerBox& triggerbox() const { return trigger()->box(); } - void choose_color (); + void choose_color (Gtk::Window*); void choose_sample (bool allow_multiple_select); void sample_chosen (int r); @@ -121,12 +121,13 @@ protected: Gtk::Menu* _context_menu; bool _ignore_menu_action; - Gtk::ColorSelectionDialog* _color_dialog; + StripableColorDialog* _color_dialog; void trigger_swap (uint32_t); PBD::ScopedConnection trigger_swap_connection; ARDOUR::TriggerReference tref; + sigc::connection color_connection; PBD::ScopedConnectionList trigger_connections; };