Changeset View
Changeset View
Standalone View
Standalone View
color-reload-module/reloader.c
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2020 Carson Black <uhhadd@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include <gtk/gtk.h> | ||||
22 | #include <glib.h> | ||||
23 | #include <gio/gio.h> | ||||
24 | #include <gdk/gdk.h> | ||||
25 | | ||||
26 | gchar *path; | ||||
27 | GFile *file; | ||||
28 | GFileMonitor *mon; | ||||
29 | GtkCssProvider *provider; | ||||
30 | | ||||
31 | void reload_colours() { | ||||
32 | if (provider == NULL) { | ||||
33 | provider = gtk_css_provider_new(); | ||||
34 | } else { | ||||
35 | gtk_style_context_remove_provider_for_screen( | ||||
36 | gdk_screen_get_default(), | ||||
37 | GTK_STYLE_PROVIDER(provider) | ||||
38 | ); | ||||
39 | g_clear_object(&provider); | ||||
40 | provider = gtk_css_provider_new(); | ||||
41 | } | ||||
42 | gtk_style_context_add_provider_for_screen( | ||||
43 | gdk_screen_get_default(), | ||||
44 | GTK_STYLE_PROVIDER (provider), | ||||
45 | GTK_STYLE_PROVIDER_PRIORITY_USER+1 | ||||
46 | ); | ||||
47 | gtk_css_provider_load_from_file( | ||||
48 | provider, | ||||
49 | file, | ||||
50 | NULL | ||||
51 | ); | ||||
52 | } | ||||
53 | | ||||
54 | void gtk_module_init(gint *argc, gchar ***argv[]) { | ||||
55 | path = g_strconcat(g_get_home_dir(), "/.config/gtk-3.0/colors.css", NULL); | ||||
56 | file = g_file_new_for_path(path); | ||||
57 | | ||||
58 | mon = g_file_monitor_file( | ||||
59 | file, | ||||
60 | G_FILE_MONITOR_NONE, | ||||
61 | NULL, | ||||
62 | NULL | ||||
63 | ); | ||||
64 | | ||||
65 | g_signal_connect(mon, "changed", G_CALLBACK(reload_colours), NULL); | ||||
66 | } | ||||
67 | |