summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--adw/CMakeLists.txt2
-rw-r--r--adw/include/adwaitamm/enums.hpp51
-rw-r--r--adw/include/adwaitamm/stylemanager.hpp81
-rw-r--r--adw/src/enums.cpp49
-rw-r--r--adw/src/stylemanager.cpp106
-rw-r--r--adw/src/wrap_init.cpp3
-rw-r--r--app/src/main.cpp7
7 files changed, 296 insertions, 3 deletions
diff --git a/adw/CMakeLists.txt b/adw/CMakeLists.txt
index ad979ea..6ca4ad0 100644
--- a/adw/CMakeLists.txt
+++ b/adw/CMakeLists.txt
@@ -22,9 +22,11 @@ add_library("adwaitamm"
"src/applicationwindow.cpp"
"src/breakpoint.cpp"
"src/dialog.cpp"
+ "src/enums.cpp"
"src/preferencesdialog.cpp"
"src/preferencespage.cpp"
"src/preferencesrow.cpp"
+ "src/stylemanager.cpp"
"src/switchrow.cpp"
"src/toast.cpp"
"src/toastoverlay.cpp"
diff --git a/adw/include/adwaitamm/enums.hpp b/adw/include/adwaitamm/enums.hpp
new file mode 100644
index 0000000..d19ebc7
--- /dev/null
+++ b/adw/include/adwaitamm/enums.hpp
@@ -0,0 +1,51 @@
+#ifndef LIBADWAITAMM_ENUMS_HPP
+#define LIBADWAITAMM_ENUMS_HPP
+
+#include <glibmm/value.h>
+
+#include <glib-object.h>
+
+namespace Adwaita
+{
+ enum struct AccentColor
+ {
+ Blue,
+ Teal,
+ Green,
+ Yellow,
+ Orange,
+ Red,
+ Pink,
+ Purple,
+ Slate,
+ };
+
+ enum struct ColorScheme
+ {
+ Default,
+ ForceLight,
+ PreferLight,
+ PreferDark,
+ ForceDark,
+ };
+} // namespace Adwaita
+
+namespace Glib
+{
+
+#define VALUE_SPECIALIZATION(Enum) \
+ template<> \
+ class Value<Adwaita::Enum> : public Glib::Value_Enum<Adwaita::Enum> \
+ { \
+ public: \
+ auto static value_type() -> GType; \
+ }
+
+ VALUE_SPECIALIZATION(AccentColor);
+ VALUE_SPECIALIZATION(ColorScheme);
+
+#undef VALUE_SPECIALIZATION
+
+} // namespace Glib
+
+#endif \ No newline at end of file
diff --git a/adw/include/adwaitamm/stylemanager.hpp b/adw/include/adwaitamm/stylemanager.hpp
new file mode 100644
index 0000000..8c6fd85
--- /dev/null
+++ b/adw/include/adwaitamm/stylemanager.hpp
@@ -0,0 +1,81 @@
+#ifndef LIBADWAITAMM_STYLE_MANAGER_HPP
+#define LIBADWAITAMM_STYLE_MANAGER_HPP
+
+#include "adwaitamm/helpers/gobj_mixin.hpp"
+
+#include <glibmm/class.h>
+#include <glibmm/object.h>
+#include <glibmm/objectbase.h>
+#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+
+#include <giomm/application.h>
+
+#include <gtkmm/application.h>
+
+#include <gdkmm/display.h>
+#include <glib-object.h>
+
+#define _ADWAITA_INSIDE
+#include <adw-style-manager.h>
+#undef _ADWAITA_INSIDE
+
+using AdwStyleManager = struct _AdwStyleManager;
+
+namespace Adwaita
+{
+ enum struct AccentColor;
+ enum struct ColorScheme;
+
+ struct StyleManager : Glib::Object,
+ helpers::gobj_mixin<StyleManager, AdwStyleManager>
+ {
+ struct Class : Glib::Class
+ {
+ using BaseClassParent = GObjectClass;
+ using BaseClassType = AdwStyleManagerClass;
+ using BaseObjectType = AdwStyleManager;
+ using CppClassParent = struct Glib::Object_Class;
+ using CppObjectType = StyleManager;
+
+ auto init() -> Glib::Class const &;
+ auto static class_init_function(void * gclass, void * data) -> void;
+ auto static wrap_new(GObject * object) -> Glib::ObjectBase *;
+ };
+
+ using BaseObjectType = Class::BaseObjectType;
+ using BaseClassType = Class::BaseClassType;
+ using CppObjectType = Class::CppObjectType;
+ using CppClassType = Class;
+
+ using helpers::gobj_mixin<CppObjectType, BaseObjectType>::gobj;
+ using helpers::gobj_mixin<CppObjectType, BaseObjectType>::gobj_copy;
+
+ StyleManager(StyleManager const & other) = delete;
+ StyleManager(StyleManager && other) noexcept = delete;
+
+ auto operator=(StyleManager const & other) noexcept -> StyleManager & = delete;
+ auto operator=(StyleManager && other) noexcept -> StyleManager & = delete;
+
+ auto static get_default() -> StyleManager *;
+ auto static for_display(Gdk::Display & display) -> StyleManager *;
+
+ auto static get_type() -> GType;
+ auto static get_base_type() -> GType;
+
+ auto get_accent_color() const -> AccentColor;
+ auto set_color_scheme(ColorScheme value) -> void;
+
+ protected:
+ explicit StyleManager(Glib::ConstructParams const & params);
+ explicit StyleManager(BaseObjectType * gobj);
+ explicit StyleManager();
+ };
+} // namespace Adwaita
+
+namespace Glib
+{
+ auto wrap(AdwStyleManager * object) -> Adwaita::StyleManager *;
+} // namespace Glib
+
+#endif \ No newline at end of file
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);
diff --git a/app/src/main.cpp b/app/src/main.cpp
index f86eee3..7595dc3 100644
--- a/app/src/main.cpp
+++ b/app/src/main.cpp
@@ -13,8 +13,9 @@
#include <gtkmm/builder.h>
#include <adwaitamm/application.hpp>
+#include <adwaitamm/enums.hpp>
+#include <adwaitamm/stylemanager.hpp>
-#include <adwaita.h>
#include <libintl.h>
#include <clocale>
@@ -45,8 +46,8 @@ auto main(int argc, char * argv[]) -> int
turns::core::register_types();
turns::ui::register_types();
- auto style_manager = adw_style_manager_get_default();
- adw_style_manager_set_color_scheme(style_manager, ADW_COLOR_SCHEME_PREFER_LIGHT);
+ auto style_manager = Adwaita::StyleManager::get_default();
+ style_manager->set_color_scheme(Adwaita::ColorScheme::PreferLight);
app->add_action("quit", sigc::mem_fun(*app, &Adwaita::Application::quit));
app->set_accel_for_action("app.quit", "<Primary>q");