Skip to content

Commit aa56a7f

Browse files
authored
Port glight to Gtkmm-4 (#499)
1 parent 293a08d commit aa56a7f

File tree

118 files changed

+2498
-2460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+2498
-2460
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v2
1717
- name: Build the Docker image
18-
run: docker build . --file scripts/docker/Ubuntu22
18+
run: docker build . --file scripts/docker/Ubuntu24

CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5)
33
project(glight)
44

55
find_package(PkgConfig)
6-
pkg_check_modules(GTKMM gtkmm-3.0>=3.0.0 REQUIRED)
6+
pkg_check_modules(GTKMM gtkmm-4.0>=4.0.0 REQUIRED)
77
pkg_check_modules(SIGCXX2 sigc++-2.0 REQUIRED)
88
pkg_check_modules(FLACPP flac++ REQUIRED)
99
pkg_check_modules(ALSA alsa REQUIRED)
@@ -33,10 +33,10 @@ set(CMAKE_CXX_CLANG_TIDY "clang-tidy;--fix-errors;-checks=*,-llvmlibc*,\
3333
endif()
3434

3535
add_compile_options(
36-
-DGTKMM_DISABLE_DEPRECATED
37-
-DGDKMM_DISABLE_DEPRECATED
38-
-DGLIBMM_DISABLE_DEPRECATED
39-
-DGIOMM_DISABLE_DEPRECATED
36+
# -DGTKMM_DISABLE_DEPRECATED
37+
# -DGDKMM_DISABLE_DEPRECATED
38+
# -DGLIBMM_DISABLE_DEPRECATED
39+
# -DGIOMM_DISABLE_DEPRECATED
4040
-O3
4141
-Wall
4242
-Wvla
@@ -73,18 +73,19 @@ include_directories(SYSTEM ${AUBIO_INCLUDE_DIR})
7373

7474
set(GUIFILES
7575
gui/application.cpp
76-
gui/components/nameframe.cpp
7776
gui/functions.cpp
7877
gui/instance.cpp
7978
gui/renderengine.cpp
8079
gui/components/audiowidget.cpp
8180
gui/components/beatinput.cpp
8281
gui/components/colorselectwidget.cpp
8382
gui/components/colorsequencewidget.cpp
83+
gui/components/controlbutton.cpp
8484
gui/components/durationinput.cpp
8585
gui/components/fixturelist.cpp
8686
gui/components/foldercombo.cpp
8787
gui/components/iconbutton.cpp
88+
gui/components/nameframe.cpp
8889
gui/components/objectlist.cpp
8990
gui/components/powermonitor.cpp
9091
gui/components/propertiesbox.cpp

gui/application.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ void Application::Run(int argc, char *argv[]) {
1313
if (argc > 1) {
1414
window.OpenFile(argv[1]);
1515
}
16-
run(window, 1, argv);
16+
signal_activate().connect([&window, this]() {
17+
add_window(window);
18+
window.present();
19+
});
20+
run();
1721
snd_config_update_free_global();
1822
}
1923

gui/application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace glight::gui {
88
class Application : public Gtk::Application {
99
public:
1010
Application()
11-
: Gtk::Application("org.glight", Gio::APPLICATION_HANDLES_OPEN) {}
11+
: Gtk::Application("org.glight", Gio::Application::Flags::HANDLES_OPEN) {}
1212
void Run(int argc, char *argv[]);
1313
};
1414

gui/components/audiowidget.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <cairomm/context.h>
99

1010
#include <gdkmm/general.h> // set_source_pixbuf()
11+
#include <gtkmm/gestureclick.h>
1112

1213
namespace {
1314

@@ -67,12 +68,15 @@ AudioWidget::AudioWidget()
6768
_chunkBuffer(kChunkSize) {
6869
set_size_request(50, 50);
6970

70-
add_events(Gdk::BUTTON_PRESS_MASK);
71-
72-
signal_button_press_event().connect(
71+
auto gesture = Gtk::GestureClick::create();
72+
gesture->set_button(1);
73+
gesture->signal_pressed().connect(
7374
sigc::mem_fun(*this, &AudioWidget::onButtonPressed));
75+
add_controller(gesture);
7476

75-
signal_draw().connect(sigc::mem_fun(*this, &AudioWidget::onExpose));
77+
set_draw_func([&](const Cairo::RefPtr<Cairo::Context> &cairo, int, int) {
78+
AudioWidget::onExpose(cairo);
79+
});
7680
}
7781

7882
AudioWidget::~AudioWidget() = default;
@@ -124,7 +128,7 @@ void AudioWidget::ResizeBuffer() {
124128
_height = get_height();
125129
if (_width > 0) {
126130
_buffer =
127-
Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, false, 8, _width, _height);
131+
Gdk::Pixbuf::create(Gdk::Colorspace::RGB, false, 8, _width, _height);
128132
} else {
129133
_buffer.reset();
130134
}
@@ -209,12 +213,11 @@ void AudioWidget::bufferToScreen(const Cairo::RefPtr<Cairo::Context> &context) {
209213
context->fill();
210214
}
211215

212-
bool AudioWidget::onButtonPressed(GdkEventButton *event) {
216+
void AudioWidget::onButtonPressed(int, double x, double y) {
213217
const int position = std::clamp<int>(
214-
static_cast<int>(event->x) + _renderStartPosition, 0, DataSize() - 1);
218+
static_cast<int>(x) + _renderStartPosition, 0, DataSize() - 1);
215219
_signalClicked.emit(static_cast<double>(position) * kChunkSize /
216220
(44.100 * 4.0));
217-
return true;
218221
}
219222

220223
void AudioWidget::SetScene(theatre::Scene &scene) {

gui/components/audiowidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class AudioWidget : public Gtk::DrawingArea {
6060
if (_buffer) bufferToScreen(context);
6161
return true;
6262
}
63-
bool onButtonPressed(GdkEventButton *event);
63+
void onButtonPressed(int, double, double);
6464
void verticalLine(guint8 *dataPtr, size_t rowStride, int x, unsigned char r,
6565
unsigned char g, unsigned char b) {
6666
if (x >= 0 && x < _width) {

gui/components/beatinput.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <sstream>
44

5+
#include <gtkmm/adjustment.h>
6+
57
namespace glight::gui {
68
namespace {
79
inline constexpr size_t kNValues = 10;
@@ -14,17 +16,17 @@ inline const std::string kStringValues[kNValues]{
1416
BeatInput::BeatInput(double value)
1517
: scale_(Gtk::Adjustment::create(
1618
0, 0, static_cast<double>(kNValues - 1) + 0.1, 1),
17-
Gtk::ORIENTATION_HORIZONTAL) {
19+
Gtk::Orientation::HORIZONTAL) {
1820
Initialize(value);
1921
}
2022

2123
BeatInput::BeatInput(const std::string &label, double value)
2224
: caption_label_(label),
2325
scale_(Gtk::Adjustment::create(
2426
0, 0, static_cast<double>(kNValues - 1) + 0.1, 1),
25-
Gtk::ORIENTATION_HORIZONTAL) {
26-
caption_label_.set_halign(Gtk::ALIGN_END);
27-
pack_start(caption_label_, false, false);
27+
Gtk::Orientation::HORIZONTAL) {
28+
caption_label_.set_halign(Gtk::Align::END);
29+
append(caption_label_);
2830

2931
Initialize(value);
3032
}
@@ -36,13 +38,11 @@ void BeatInput::Initialize(double value) {
3638
scale_.set_round_digits(0);
3739
scale_.set_draw_value(false);
3840
scale_.signal_value_changed().connect([&]() { OnScaleChanged(); });
39-
pack_start(scale_, true, true);
41+
append(scale_);
4042

4143
SetValueLabel(index);
4244
value_label_.set_width_chars(3);
43-
pack_end(value_label_, false, false);
44-
45-
show_all_children();
45+
append(value_label_);
4646
}
4747

4848
double BeatInput::ValueToScale(double value) {

gui/components/beatinput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace glight::gui {
1212

13-
class BeatInput : public Gtk::HBox {
13+
class BeatInput : public Gtk::Box {
1414
public:
1515
BeatInput(double value);
1616

gui/components/colorbutton.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define GLIGHT_GUI_COMPONENTS_DISPLAY_COLOR_H_
33

44
#include <gtkmm/drawingarea.h>
5+
#include <gtkmm/gestureclick.h>
56

67
#include "theatre/color.h"
78

@@ -11,15 +12,15 @@ class ColorButton : public Gtk::DrawingArea {
1112
public:
1213
ColorButton(const theatre::Color& color = theatre::Color::White())
1314
: color_(color) {
14-
signal_draw().connect([&](const Cairo::RefPtr<Cairo::Context>& cr) {
15-
DrawColor(cr);
16-
return true;
17-
});
18-
set_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
19-
signal_button_release_event().connect([&](GdkEventButton*) {
20-
signal_clicked_();
21-
return false;
15+
set_draw_func([&](const Cairo::RefPtr<Cairo::Context>& cairo, int, int) {
16+
DrawColor(cairo);
2217
});
18+
19+
auto gesture = Gtk::GestureClick::create();
20+
gesture->set_button(1);
21+
gesture->signal_released().connect(
22+
[this](int, double, double) { signal_clicked_(); });
23+
add_controller(gesture);
2324
}
2425

2526
void SetColor(const theatre::Color& color) {

gui/components/colorselectwidget.cpp

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,29 @@ ColorSelectWidget::ColorSelectWidget(Gtk::Window *parent, bool allow_variable)
1616
static_button_("Static"),
1717
variable_button_("Variable"),
1818
set_button_("Set...") {
19-
Gtk::RadioButton::Group group;
20-
static_button_.set_group(group);
21-
static_button_.signal_clicked().connect([&]() {
19+
static_button_.signal_toggled().connect([&]() {
2220
if (variable_label_.get_parent()) {
2321
remove(set_button_);
2422
remove(variable_label_);
25-
pack_end(color_button_, true, true, 5);
23+
append(color_button_);
2624
color_button_.show();
2725
signal_color_changed_();
2826
}
2927
});
30-
pack_start(static_button_, false, false, 0);
31-
static_button_.show();
28+
append(static_button_);
3229

33-
variable_button_.set_group(group);
34-
variable_button_.signal_clicked().connect([&]() {
30+
variable_button_.set_group(static_button_);
31+
variable_button_.signal_toggled().connect([&]() {
3532
if (color_button_.get_parent()) {
3633
remove(color_button_);
37-
pack_end(variable_label_);
34+
append(variable_label_);
3835
variable_label_.show();
39-
pack_end(set_button_);
36+
append(set_button_);
4037
set_button_.show();
4138
signal_color_changed_();
4239
}
4340
});
44-
pack_start(variable_button_, true, true, 0);
45-
variable_button_.show();
41+
append(variable_button_);
4642

4743
set_button_.signal_clicked().connect([&]() {
4844
if (static_button_.get_active())
@@ -52,20 +48,18 @@ ColorSelectWidget::ColorSelectWidget(Gtk::Window *parent, bool allow_variable)
5248
});
5349

5450
color_button_.set_size_request(35, 35);
55-
pack_end(color_button_, true, true, 5);
51+
append(color_button_);
5652
color_button_.SignalClicked().connect([&]() { OpenColorSelection(); });
57-
color_button_.show();
5853

5954
SetAllowVariables(allow_variable);
6055
}
6156

6257
void ColorSelectWidget::OpenColorSelection() {
63-
const std::optional<theatre::Color> color =
64-
OpenColorDialog(*parent_, color_button_.GetColor());
65-
if (color) {
66-
color_button_.SetColor(*color);
67-
signal_color_changed_();
68-
}
58+
OpenColorDialog(dialog_, *parent_, color_button_.GetColor(),
59+
[this](theatre::Color color) {
60+
color_button_.SetColor(color);
61+
signal_color_changed_();
62+
});
6963
}
7064

7165
void ColorSelectWidget::OpenVariableSelection() {
@@ -75,29 +69,33 @@ void ColorSelectWidget::OpenVariableSelection() {
7569
dialog.SignalNewClicked().connect([&]() {
7670
StringInputDialog string_dialog("New variable",
7771
"Name of new variable:", "");
78-
if (string_dialog.run() == Gtk::RESPONSE_OK) {
79-
std::unique_ptr<theatre::Effect> effect =
80-
std::make_unique<theatre::VariableEffect>();
81-
theatre::Folder &parent = dialog.SelectedFolder();
82-
effect->SetName(string_dialog.Value());
83-
theatre::Management &management = Instance::Management();
84-
system::ObservingPtr<theatre::Effect> added =
85-
management.AddEffectPtr(std::move(effect), parent);
86-
for (size_t i = 0; i != added->NInputs(); ++i)
87-
management.AddSourceValue(*added, i);
88-
Instance::Events().EmitUpdate();
89-
dialog.SelectObject(*added);
90-
}
72+
string_dialog.signal_response().connect([&](int response) {
73+
if (response == Gtk::ResponseType::OK) {
74+
std::unique_ptr<theatre::Effect> effect =
75+
std::make_unique<theatre::VariableEffect>();
76+
theatre::Folder &parent = dialog.SelectedFolder();
77+
effect->SetName(string_dialog.Value());
78+
theatre::Management &management = Instance::Management();
79+
system::ObservingPtr<theatre::Effect> added =
80+
management.AddEffectPtr(std::move(effect), parent);
81+
for (size_t i = 0; i != added->NInputs(); ++i)
82+
management.AddSourceValue(*added, i);
83+
Instance::Events().EmitUpdate();
84+
dialog.SelectObject(*added);
85+
}
86+
});
87+
string_dialog.show();
9188
});
92-
if (dialog.run() == Gtk::RESPONSE_OK) {
89+
dialog.signal_response().connect([&](int response) {
9390
theatre::VariableEffect *v =
9491
dynamic_cast<theatre::VariableEffect *>(dialog.SelectedObject().Get());
9592
if (v && v != variable_) {
9693
variable_ = v;
9794
SetVariableLabel();
9895
signal_color_changed_();
9996
}
100-
}
97+
});
98+
dialog.show();
10199
}
102100

103101
void ColorSelectWidget::SetVariableLabel() {

0 commit comments

Comments
 (0)