From c61998283c8436dd4360e35ce10c309e7d3ee723 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 25 Jul 2024 13:05:02 +0200 Subject: adw: add bare bones wrapper for AdwApplication --- adw/CMakeLists.txt | 22 ++++++++ adw/include/turns/adw/application.hpp | 55 ++++++++++++++++++ adw/include/turns/adw/wrap_init.hpp | 9 +++ adw/src/application.cpp | 102 ++++++++++++++++++++++++++++++++++ adw/src/wrap_init.cpp | 21 +++++++ 5 files changed, 209 insertions(+) create mode 100644 adw/CMakeLists.txt create mode 100644 adw/include/turns/adw/application.hpp create mode 100644 adw/include/turns/adw/wrap_init.hpp create mode 100644 adw/src/application.cpp create mode 100644 adw/src/wrap_init.cpp (limited to 'adw') diff --git a/adw/CMakeLists.txt b/adw/CMakeLists.txt new file mode 100644 index 0000000..9ac563a --- /dev/null +++ b/adw/CMakeLists.txt @@ -0,0 +1,22 @@ +add_library("adw" + "src/application.cpp" + "src/wrap_init.cpp" +) + +add_library("turns::adw" ALIAS "adw") + +target_include_directories("adw" PUBLIC + "include" +) + +target_compile_options("adw" PUBLIC + "$<$:-Wall>" + "$<$:-Wextra>" + "$<$:-Werror>" + "$<$:-pedantic-errors>" +) + +target_link_libraries("adw" PUBLIC + "PkgConfig::adwaita" + "PkgConfig::gtkmm" +) diff --git a/adw/include/turns/adw/application.hpp b/adw/include/turns/adw/application.hpp new file mode 100644 index 0000000..26bec41 --- /dev/null +++ b/adw/include/turns/adw/application.hpp @@ -0,0 +1,55 @@ +#ifndef TURNS_ADW_APPLICATION_HPP +#define TURNS_ADW_APPLICATION_HPP + +#include +#include + +#include + +#include + +using AdwApplication = struct _AdwApplication; + +namespace turns::adw +{ + struct Application_Class; + + struct Application : Gtk::Application + { + Application(Application && other) noexcept = default; + auto operator=(Application && other) noexcept -> Application & = default; + + Application(Application const & other) = delete; + auto operator=(Application const & other) noexcept -> Application & = delete; + + auto static get_type() -> GType; + auto static get_base_type() -> GType; + + template + auto gobj(this Self && self) noexcept + { + return reinterpret_cast(self.gobject_); + } + + auto gobj_copy() -> AdwApplication *; + + auto static create(Glib::ustring const & id = {}, + Gio::Application::Flags flags = Gio::Application::Flags::NONE) -> Glib::RefPtr; + + protected: + explicit Application(Glib::ConstructParams const & params); + explicit Application(AdwApplication * gobj); + explicit Application(Glib::ustring const & id = {}, Gio::Application::Flags flags = Gio::Application::Flags::NONE); + + private: + friend Application_Class; + static Application_Class s_class; + }; +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwApplication * object, bool copy = false) -> Glib::RefPtr; +} // namespace Glib + +#endif \ No newline at end of file diff --git a/adw/include/turns/adw/wrap_init.hpp b/adw/include/turns/adw/wrap_init.hpp new file mode 100644 index 0000000..5096736 --- /dev/null +++ b/adw/include/turns/adw/wrap_init.hpp @@ -0,0 +1,9 @@ +#ifndef TURNS_ADW_WRAP_INIT_HPP +#define TURNS_ADW_WRAP_INIT_HPP + +namespace turns::adw +{ + auto wrap_init() -> void; +} // namespace turns::adw + +#endif \ No newline at end of file diff --git a/adw/src/application.cpp b/adw/src/application.cpp new file mode 100644 index 0000000..539f7bc --- /dev/null +++ b/adw/src/application.cpp @@ -0,0 +1,102 @@ +#include "turns/adw/application.hpp" + +#include "turns/adw/wrap_init.hpp" + +#include +#include + +#include + +#include + +#include + +namespace turns::adw +{ + struct Application_Class : Glib::Class + { + auto init() -> Glib::Class const &; + auto static class_init_function(void * gclass, void * data) -> void; + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; + + auto Application_Class::init() -> Glib::Class const & + { + if (!gtype_) + { + class_init_func_ = &Application_Class::class_init_function; + register_derived_type(adw_application_get_type()); + } + return *this; + } + + auto Application_Class::class_init_function(void * gclass, void * data) -> void + { + auto const klass = static_cast(gclass); + Gtk::Application_Class::class_init_function(klass, data); + } + + auto Application_Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return new Application(ADW_APPLICATION(object)); + } + + Application_Class Application::s_class{}; + + auto Application::get_type() -> GType + { + return s_class.init().get_type(); + } + + auto Application::get_base_type() -> GType + { + return adw_application_get_type(); + } + + auto Application::gobj_copy() -> AdwApplication * + { + reference(); + return gobj(); + } + + auto Application::create(Glib::ustring const & id, Gio::Application::Flags flags) -> Glib::RefPtr + { + auto static did_init = false; + + if (!did_init) + { + Gtk::init_gtkmm_internals(); + turns::adw::wrap_init(); + did_init = true; + } + + return Glib::RefPtr(new Application(id, flags)); + } + + Application::Application(Glib::ConstructParams const & params) + : Gtk::Application{params} + { + } + + Application::Application(AdwApplication * gobj) + : Glib::ObjectBase{nullptr} + , Gtk::Application((GtkApplication *)gobj) + { + } + + Application::Application(Glib::ustring const & id, Gio::Application::Flags flags) + : Glib::ObjectBase{nullptr} + , Gtk::Application{Glib::ConstructParams{s_class.init(), "application_id", Glib::c_str_or_nullptr(id), "flags", static_cast(flags), nullptr}} + { + } + +} // namespace turns::adw + +namespace Glib +{ + auto wrap(AdwApplication * object, bool copy) -> Glib::RefPtr + { + return Glib::make_refptr_for_instance( + dynamic_cast(Glib::wrap_auto(G_OBJECT(object), copy))); + } +} // namespace Glib \ No newline at end of file diff --git a/adw/src/wrap_init.cpp b/adw/src/wrap_init.cpp new file mode 100644 index 0000000..42ff1cf --- /dev/null +++ b/adw/src/wrap_init.cpp @@ -0,0 +1,21 @@ +#include "turns/adw/wrap_init.hpp" + +#include "turns/adw/application.hpp" + +#include + +namespace turns::adw +{ + struct Application_Class + { + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; + + auto wrap_init() -> void + { + adw_init(); + + Glib::wrap_register(adw_application_get_type(), &Application_Class::wrap_new); + g_type_ensure(Application::get_type()); + } +} // namespace turns::adw \ No newline at end of file -- cgit v1.2.3