looper/backends/ui/gtk/main.cpp
2024-04-09 10:15:05 -07:00

59 lines
No EOL
2.1 KiB
C++

#include "main.h"
#include "main_window.hpp"
#include <assets/assets.h>
#include <license.hpp>
std::string GtkBackend::get_id() {
return "gtk";
}
std::string GtkBackend::get_name() {
return "GTK frontend";
}
int GtkBackend::run(std::vector<std::string> realArgs, int argc, char **argv) {
int ret = UIBackend::run(realArgs, argc, argv);
if (ret != 0) {
return ret;
}
Glib::set_application_name("Looper");
auto app = Gtk::Application::create("com.complecwaft.Looper.GTK", Gio::Application::Flags::NON_UNIQUE);
char *gtk_frontend_css = (char*)malloc(gtk_frontend_css_size + 1);
memcpy(gtk_frontend_css, gtk_frontend_css_data, gtk_frontend_css_size);
gtk_frontend_css[gtk_frontend_css_size] = '\0';
std::string gtk_frontend_css_str = std::string(gtk_frontend_css);
free(gtk_frontend_css);
auto provider = Gtk::CssProvider::create();
provider->load_from_string(gtk_frontend_css_str);
app->signal_startup().connect([=,this]() {
app->add_action("quit", [app]() {
app->quit();
});
Gtk::StyleContext::add_provider_for_display(Gdk::Display::get_default(), provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
});
app->signal_activate().connect([=,this] {
auto *win = new MainWindow(playback, app);
win->present();
});
app_ptr = app.get();
ret = app->run(argc, argv);
app_ptr = nullptr;
return ret;
}
void GtkBackend::QuitHandler() {
if (app_ptr != nullptr) {
((Gtk::Application*)app_ptr)->quit();
}
}
void GtkBackend::add_licenses() {
auto &license_data = get_license_data();
auto gtkmm = LicenseData("GtkMM", "lgpl-2.1");
auto glibmm = LicenseData("GlibMM", "lgpl-2.1");
auto glib = LicenseData("Glib", "lgpl-2.1-or-later");
auto gtk = LicenseData("GTK", "lgpl-2.0");
LOAD_LICENSE(gtkmm, lgpl_2_1);
LOAD_LICENSE(glibmm, lgpl_2_1);
LOAD_LICENSE(glib, lgpl_2_1);
LOAD_LICENSE(gtk, lgpl_2_0);
license_data.insert(gtkmm);
license_data.insert(glibmm);
license_data.insert(glib);
license_data.insert(gtk);
}