This commit is contained in:
Tracker-Friendly 2023-07-25 00:50:55 +01:00
parent 22444c27c8
commit 382e2448cd
3 changed files with 109 additions and 0 deletions

30
Makefile Normal file
View File

@ -0,0 +1,30 @@
# Makefile for Mode Switcher GTK application
# Compiler
CC = gcc
# Compiler flags
CFLAGS = `pkg-config --cflags gtk+-3.0`
# Linker flags
LDFLAGS = `pkg-config --libs gtk+-3.0`
# Source files
SRC = mode_switcher.c
# Object files
OBJ = $(SRC:.c=.o)
# Executable name
EXECUTABLE = themeswitcher
all: $(EXECUTABLE)
$(EXECUTABLE): $(OBJ)
$(CC) $(OBJ) -o $(EXECUTABLE) $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJ) $(EXECUTABLE)

View File

@ -0,0 +1,12 @@
[Desktop Entry]
Type=Application
TryExec=themeswitcher
Exec=themeswitcher
Icon=weather-clear-symbloic
Terminal=false
Categories=System;
Name=Theme Switcher
GenericName=Theme Switcher
Comment=Simple switcher between a light and dark theme
StartupWMClass=themeswitcher

67
themeswitcher.c Normal file
View File

@ -0,0 +1,67 @@
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <stdlib.h> // For system() function
static void light_mode_clicked(GtkWidget *widget, gpointer data)
{
GSettings *settings = g_settings_new("org.gnome.desktop.interface");
g_settings_set_string(settings, "gtk-theme", "Adwaita");
g_settings_set_string(settings, "color-scheme", "prefer-light");
g_object_unref(settings);
settings = g_settings_new("org.gnome.desktop.wm.preferences");
g_settings_set_string(settings, "theme", "Adwaita");
g_object_unref(settings);
// Restart and fork wf-panel into the background
system("pkill wf-panel");
system("wf-panel &");
}
static void dark_mode_clicked(GtkWidget *widget, gpointer data)
{
GSettings *settings = g_settings_new("org.gnome.desktop.interface");
g_settings_set_string(settings, "gtk-theme", "Adwaita-dark");
g_settings_set_string(settings, "color-scheme", "prefer-dark");
g_object_unref(settings);
settings = g_settings_new("org.gnome.desktop.wm.preferences");
g_settings_set_string(settings, "theme", "Adwaita-dark");
g_object_unref(settings);
// Restart and fork wf-panel into the background
system("pkill wf-panel");
system("wf-panel &");
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window;
GtkWidget *box;
GtkWidget *light_button;
GtkWidget *dark_button;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Mode Switcher");
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
gtk_container_add(GTK_CONTAINER(window), box);
light_button = gtk_button_new_with_label("Light Mode");
g_signal_connect(light_button, "clicked", G_CALLBACK(light_mode_clicked), NULL);
gtk_box_pack_start(GTK_BOX(box), light_button, TRUE, TRUE, 0);
dark_button = gtk_button_new_with_label("Dark Mode");
g_signal_connect(dark_button, "clicked", G_CALLBACK(dark_mode_clicked), NULL);
gtk_box_pack_start(GTK_BOX(box), dark_button, TRUE, TRUE, 0);
gtk_widget_show_all(window);
gtk_main();
return 0;
}