Commit 306e01d8 authored by Carson Black's avatar Carson Black 🍿

[GTK3] Add module to reload colorscheme in GTK3 apps without restarting them

Summary: The title is somewhat self explanatory.

Test Plan: `gtk-app-here --gtk-module colorreload-gtk-module`

Reviewers: #plasma, gikari

Reviewed By: gikari

Subscribers: gikari, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28076
parent 8a53a970
......@@ -36,6 +36,7 @@ add_subdirectory(gtkproxies)
add_subdirectory(gtk3proxies)
add_subdirectory(kded)
add_subdirectory(kconf_update)
add_subdirectory(color-reload-module)
# add clang-format target for all our real source files
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
......
include(GNUInstallDirs)
add_library(colorreload-gtk-module SHARED
reloader.c
)
target_link_libraries(colorreload-gtk-module
PRIVATE
${GLIB_LIBRARIES}
${GTK_LIBRARIES}
)
target_include_directories(
colorreload-gtk-module PRIVATE
${GLIB_INCLUDE_DIRS} ${GTK_INCLUDE_DIRS}
)
install(
TARGETS colorreload-gtk-module
DESTINATION ${CMAKE_INSTALL_LIBDIR}/gtk-3.0/modules
)
#include <gtk/gtk.h>
#include <glib.h>
#include <gio/gio.h>
#include <gdk/gdk.h>
gchar *path;
GFile *file;
GFileMonitor *mon;
GtkCssProvider *provider;
void reload_colours() {
if (provider == NULL) {
provider = gtk_css_provider_new();
} else {
gtk_style_context_remove_provider_for_screen(
gdk_screen_get_default(),
GTK_STYLE_PROVIDER(provider)
);
g_clear_object(&provider);
provider = gtk_css_provider_new();
}
gtk_style_context_add_provider_for_screen(
gdk_screen_get_default(),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_USER+1
);
gtk_css_provider_load_from_file(
provider,
file,
NULL
);
}
void gtk_module_init(gint *argc, gchar ***argv[]) {
path = g_strconcat(g_get_home_dir(), "/.config/gtk-3.0/colors.css", NULL);
file = g_file_new_for_path(path);
mon = g_file_monitor_file(
file,
G_FILE_MONITOR_NONE,
NULL,
NULL
);
g_signal_connect(mon, "changed", G_CALLBACK(reload_colours), NULL);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment