summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <wjt@endlessos.org>2023-02-23 15:50:19 +0000
committerWill Thompson <wjt@endlessos.org>2023-02-23 15:50:19 +0000
commit73bb669091c7089e225ed8e894ff4b4015fdd293 (patch)
tree734a5c8af5bd921342e686cc10549e70c3e6a810
parent793eb3426c8a9a72fed935eeec56e1c352de1537 (diff)
downloadgnome-initial-setup-73bb669091c7089e225ed8e894ff4b4015fdd293.tar.gz
Add helper function to add CSS from a resource
This project keeps a number of CSS files next to the widgets they apply to. (You might expect from the current layout that they apply only to the page at hand, but in fact they are global.) Libadwaita can automatically load certain resources, but not when arranged in this way. It may in future be desirable to centralize all CSS rules in one file, and namespace them better. https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/styles-and-appearance.html#custom-styles In the meantime, add a helper function to load CSS from a resource and install it for the default display.
-rw-r--r--gnome-initial-setup/gis-util.c33
-rw-r--r--gnome-initial-setup/gis-util.h19
-rw-r--r--gnome-initial-setup/gnome-initial-setup.h1
-rw-r--r--gnome-initial-setup/meson.build1
4 files changed, 54 insertions, 0 deletions
diff --git a/gnome-initial-setup/gis-util.c b/gnome-initial-setup/gis-util.c
new file mode 100644
index 0000000..ac153fc
--- /dev/null
+++ b/gnome-initial-setup/gis-util.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2023 Endless OS Foundation LLC
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "gis-util.h"
+
+void
+gis_add_style_from_resource (const char *resource_path)
+{
+ g_autoptr(GtkCssProvider) provider = gtk_css_provider_new ();
+
+ gtk_css_provider_load_from_resource (provider, resource_path);
+ gtk_style_context_add_provider_for_display (gdk_display_get_default (),
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
diff --git a/gnome-initial-setup/gis-util.h b/gnome-initial-setup/gis-util.h
new file mode 100644
index 0000000..5041bdd
--- /dev/null
+++ b/gnome-initial-setup/gis-util.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2023 Endless OS Foundation LLC
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#pragma once
+
+void gis_add_style_from_resource (const char *path);
diff --git a/gnome-initial-setup/gnome-initial-setup.h b/gnome-initial-setup/gnome-initial-setup.h
index 8880634..2865867 100644
--- a/gnome-initial-setup/gnome-initial-setup.h
+++ b/gnome-initial-setup/gnome-initial-setup.h
@@ -35,6 +35,7 @@ typedef struct _GisPage GisPage;
#include "gis-page.h"
#include "gis-pkexec.h"
#include "gis-keyring.h"
+#include "gis-util.h"
void gis_ensure_stamp_files (GisDriver *driver);
gboolean gis_get_mock_mode (void);
diff --git a/gnome-initial-setup/meson.build b/gnome-initial-setup/meson.build
index a3dd513..a6a014d 100644
--- a/gnome-initial-setup/meson.build
+++ b/gnome-initial-setup/meson.build
@@ -16,6 +16,7 @@ sources += [
'gis-pkexec.c',
'gis-driver.c',
'gis-keyring.c',
+ 'gis-util.c',
'gnome-initial-setup.h',
'gis-assistant.h',
'gis-page.h',