diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-04-04 19:56:43 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-04-04 19:56:43 +0200 |
| commit | fe21003777718efac8743bf99c5388b3d6477be2 (patch) | |
| tree | affc835c977b2703ceefd0b8db9109050433c5a6 /adw/src | |
| parent | 61eb53baaa69bdd860c26a79ddf1e53592a6d149 (diff) | |
| download | turns-fe21003777718efac8743bf99c5388b3d6477be2.tar.xz turns-fe21003777718efac8743bf99c5388b3d6477be2.zip | |
adw: implement basic StyleManager
Diffstat (limited to 'adw/src')
| -rw-r--r-- | adw/src/enums.cpp | 49 | ||||
| -rw-r--r-- | adw/src/stylemanager.cpp | 106 | ||||
| -rw-r--r-- | adw/src/wrap_init.cpp | 3 |
3 files changed, 158 insertions, 0 deletions
diff --git a/adw/src/enums.cpp b/adw/src/enums.cpp new file mode 100644 index 0000000..02dd74a --- /dev/null +++ b/adw/src/enums.cpp @@ -0,0 +1,49 @@ +#include "adwaitamm/enums.hpp" + +#include <adwaitamm/stylemanager.hpp> + +#include <glib-object.h> + +#include <type_traits> + +namespace +{ + template<auto Wrapped, auto Unwrapped> + auto constexpr matches = + static_cast<std::underlying_type_t<decltype(Wrapped)>>(Wrapped) == static_cast<std::underlying_type_t<decltype(Unwrapped)>>(Unwrapped); +} // namespace + +namespace Adwaita +{ + + static_assert(matches<AccentColor::Blue, ADW_ACCENT_COLOR_BLUE>); + static_assert(matches<AccentColor::Teal, ADW_ACCENT_COLOR_TEAL>); + static_assert(matches<AccentColor::Green, ADW_ACCENT_COLOR_GREEN>); + static_assert(matches<AccentColor::Yellow, ADW_ACCENT_COLOR_YELLOW>); + static_assert(matches<AccentColor::Orange, ADW_ACCENT_COLOR_ORANGE>); + static_assert(matches<AccentColor::Red, ADW_ACCENT_COLOR_RED>); + static_assert(matches<AccentColor::Pink, ADW_ACCENT_COLOR_PINK>); + static_assert(matches<AccentColor::Purple, ADW_ACCENT_COLOR_PURPLE>); + static_assert(matches<AccentColor::Slate, ADW_ACCENT_COLOR_SLATE>); + + static_assert(matches<ColorScheme::Default, ADW_COLOR_SCHEME_DEFAULT>); + static_assert(matches<ColorScheme::ForceLight, ADW_COLOR_SCHEME_FORCE_LIGHT>); + static_assert(matches<ColorScheme::PreferLight, ADW_COLOR_SCHEME_PREFER_LIGHT>); + static_assert(matches<ColorScheme::PreferDark, ADW_COLOR_SCHEME_PREFER_DARK>); + static_assert(matches<ColorScheme::ForceDark, ADW_COLOR_SCHEME_FORCE_DARK>); + +} // namespace Adwaita + +namespace Glib +{ +#define VALUE_SPECIALIZATION(Enum, AdwEnumName) \ + auto Value<Adwaita::Enum>::value_type() -> GType \ + { \ + return adw_##AdwEnumName##_get_type(); \ + } + + VALUE_SPECIALIZATION(AccentColor, accent_color) + VALUE_SPECIALIZATION(ColorScheme, color_scheme) + +#undef VALUE_SPECIALIZATION +} // namespace Glib
\ No newline at end of file diff --git a/adw/src/stylemanager.cpp b/adw/src/stylemanager.cpp new file mode 100644 index 0000000..74fe40a --- /dev/null +++ b/adw/src/stylemanager.cpp @@ -0,0 +1,106 @@ +#include "adwaitamm/stylemanager.hpp" + +#include "adwaitamm/enums.hpp" + +#include <glibmm/class.h> +#include <glibmm/object.h> +#include <glibmm/objectbase.h> +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> +#include <glibmm/wrap.h> + +#include <giomm/application.h> + +#include <gtkmm/application.h> +#include <gtkmm/init.h> +#include <gtkmm/private/application_p.h> + +#include <adwaita.h> +#include <gdkmm/display.h> +#include <gio/gio.h> +#include <glib-object.h> + +namespace Adwaita +{ + namespace + { + auto constinit _class = StyleManager::Class{}; + } // namespace + + auto StyleManager::Class::init() -> Glib::Class const & + { + if (!gtype_) + { + class_init_func_ = &StyleManager::Class::class_init_function; + register_derived_type(adw_style_manager_get_type()); + } + return *this; + } + + auto StyleManager::Class::class_init_function(void * gclass, void * data) -> void + { + auto const klass = static_cast<AdwStyleManagerClass *>(gclass); + Glib::Object_Class::class_init_function(klass, data); + } + + auto StyleManager::Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return new StyleManager(ADW_STYLE_MANAGER(object)); + } + + auto StyleManager::get_default() -> StyleManager * + { + return Glib::wrap(adw_style_manager_get_default()); + } + + auto StyleManager::for_display(Gdk::Display & display) -> StyleManager * + { + return Glib::wrap(adw_style_manager_get_for_display(Glib::unwrap(&display))); + } + + auto StyleManager::get_type() -> GType + { + return _class.init().get_type(); + } + + auto StyleManager::get_base_type() -> GType + { + return adw_style_manager_get_type(); + } + + StyleManager::StyleManager(Glib::ConstructParams const & params) + : Glib::Object{params} + { + } + + StyleManager::StyleManager(BaseObjectType * gobj) + : Glib::Object(G_OBJECT(gobj)) + { + } + + StyleManager::StyleManager() + : Glib::ObjectBase{nullptr} + , Glib::Object{Glib::ConstructParams{_class.init()}} + { + adw_init(); + } + + auto StyleManager::get_accent_color() const -> AccentColor + { + return static_cast<AccentColor>(adw_style_manager_get_accent_color(const_cast<BaseObjectType *>(unwrap(this)))); + } + + auto StyleManager::set_color_scheme(ColorScheme value) -> void + { + adw_style_manager_set_color_scheme(unwrap(this), static_cast<AdwColorScheme>(value)); + } + +} // namespace Adwaita + +namespace Glib +{ + auto wrap(AdwStyleManager * object) -> Adwaita::StyleManager * + { + return dynamic_cast<Adwaita::StyleManager *>(Glib::wrap_auto(G_OBJECT(object))); + } +} // namespace Glib
\ No newline at end of file diff --git a/adw/src/wrap_init.cpp b/adw/src/wrap_init.cpp index 8cad77d..f048633 100644 --- a/adw/src/wrap_init.cpp +++ b/adw/src/wrap_init.cpp @@ -9,6 +9,7 @@ #include "adwaitamm/preferencesdialog.hpp" #include "adwaitamm/preferencespage.hpp" #include "adwaitamm/preferencesrow.hpp" +#include "adwaitamm/stylemanager.hpp" #include "adwaitamm/switchrow.hpp" #include "adwaitamm/toast.hpp" #include "adwaitamm/toastoverlay.hpp" @@ -34,6 +35,7 @@ namespace Adwaita WRAP_CLASS(PreferencesDialog, preferences_dialog); WRAP_CLASS(PreferencesPage, preferences_page); WRAP_CLASS(PreferencesRow, preferences_row); + WRAP_CLASS(StyleManager, style_manager); WRAP_CLASS(SwitchRow, switch_row); WRAP_CLASS(Toast, toast); WRAP_CLASS(ToastOverlay, toast_overlay); @@ -47,6 +49,7 @@ namespace Adwaita ENSURE_TYPE(PreferencesDialog); ENSURE_TYPE(PreferencesPage); ENSURE_TYPE(PreferencesRow); + ENSURE_TYPE(StyleManager); ENSURE_TYPE(SwitchRow); ENSURE_TYPE(Toast); ENSURE_TYPE(ToastOverlay); |
