From 727c0f18f96c0a1966db2768d505c0dd9ad62662 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Thu, 25 Apr 2024 21:44:50 +0100 Subject: [PATCH] Remove Gtk code A separate repo has been created for the Gtk fork. --- .github/workflows/build.yml | 15 +----- meson.build | 31 ------------ src/main.c | 85 -------------------------------- src/stack-appearance.c | 97 ------------------------------------- src/stack-appearance.h | 10 ---- src/stack-lang.c | 55 --------------------- src/stack-lang.h | 10 ---- src/stack-mouse.c | 64 ------------------------ src/stack-mouse.h | 10 ---- src/state.h | 21 -------- src/update.c | 81 ------------------------------- src/update.h | 8 --- 12 files changed, 1 insertion(+), 486 deletions(-) delete mode 100644 meson.build delete mode 100644 src/main.c delete mode 100644 src/stack-appearance.c delete mode 100644 src/stack-appearance.h delete mode 100644 src/stack-lang.c delete mode 100644 src/stack-lang.h delete mode 100644 src/stack-mouse.c delete mode 100644 src/stack-mouse.h delete mode 100644 src/state.h delete mode 100644 src/update.c delete mode 100644 src/update.h diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 27c6004..764886b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,7 +47,6 @@ jobs: cmake git libxml2 - meson qt6-base qt6-tools gtk3 @@ -59,7 +58,7 @@ jobs: run: | apt-get update apt-get upgrade -y - apt-get install -y cmake clang g++ gcc git meson \ + apt-get install -y cmake clang g++ gcc git \ libglib2.0 libgl1-mesa-dev libxml2-dev pkg-config \ qt6-base-dev qt6-l10n-tools \ qt6-tools-dev qt6-tools-dev-tools \ @@ -86,15 +85,3 @@ jobs: -S . cmake --build build-clang --verbose - - name: Meson build with gcc - run: | - export CC=gcc - export CXX=g++ - meson setup build-meson-gcc --werror - meson compile -C build-meson-gcc - - - name: Run tests - run: | - build-meson-gcc/tests/t1000_add_xpath_node - build-meson-gcc/tests/t1001_nodenames - diff --git a/meson.build b/meson.build deleted file mode 100644 index 7bfa05f..0000000 --- a/meson.build +++ /dev/null @@ -1,31 +0,0 @@ -project( - 'labwc-tweaks', - 'c', - version: '0.1.0', - license: 'GPL-2.0-only', - default_options: ['c_std=c11', 'warning_level=3'], -) - -add_project_arguments(['-Wno-unused-parameter'], language: 'c',) - -gtkdeps = [dependency('gtk+-3.0'), dependency('libxml-2.0'), dependency('gio-2.0')] - -executable( - meson.project_name(), - files( - 'src/main.c', - 'src/xml.c', - 'src/environment.c', - 'src/theme.c', - 'src/keyboard-layouts.c', - 'src/stack-appearance.c', - 'src/stack-lang.c', - 'src/stack-mouse.c', - 'src/update.c', - ), - dependencies: gtkdeps, - install : true, -) - -subdir('tests') -subdir('data') diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 13c46ef..0000000 --- a/src/main.c +++ /dev/null @@ -1,85 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -#define _POSIX_C_SOURCE 200809L -#include -#include -#include -#include -#include -#include -#include "state.h" -#include "stack-appearance.h" -#include "stack-lang.h" -#include "stack-mouse.h" -#include "update.h" -#include "xml.h" - -static void -activate(GtkApplication *app, gpointer user_data) -{ - struct state *state = (struct state *)user_data; - - /* window */ - state->window = gtk_application_window_new(app); - gtk_window_set_title(GTK_WINDOW(state->window), "Tweaks"); - - /* grid */ - GtkWidget *grid = gtk_grid_new(); - gtk_container_add(GTK_CONTAINER(state->window), grid); - GtkWidget *sidebar = gtk_stack_sidebar_new(); - GtkWidget *separator = gtk_separator_new(GTK_ORIENTATION_VERTICAL); - GtkWidget *stack = gtk_stack_new(); - GtkWidget *bottom_buttons = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); - gtk_grid_set_row_spacing(GTK_GRID(grid), 10); - gtk_grid_attach(GTK_GRID(grid), sidebar, 0, 0, 1, 2); - gtk_grid_attach(GTK_GRID(grid), separator, 1, 0, 1, 2); - gtk_grid_attach(GTK_GRID(grid), stack, 2, 0, 1, 1); - gtk_grid_attach(GTK_GRID(grid), bottom_buttons, 0, 1, 3, 1); - - /* sidebar + stack */ - gtk_stack_sidebar_set_stack(GTK_STACK_SIDEBAR(sidebar), GTK_STACK(stack)); - stack_appearance_init(state, stack); - stack_mouse_init(state, stack); - stack_lang_init(state, stack); - - /* bottom buttons */ - GtkWidget *button = gtk_button_new_with_label("Update"); - g_signal_connect(button, "clicked", G_CALLBACK(update), state); - gtk_container_add(GTK_CONTAINER(bottom_buttons), button); - button = gtk_button_new_with_label("Quit"); - g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_widget_destroy), state->window); - gtk_container_add(GTK_CONTAINER(bottom_buttons), button); - gtk_button_box_set_layout(GTK_BUTTON_BOX(bottom_buttons), GTK_BUTTONBOX_END); - - /* show */ - gtk_widget_show_all(state->window); -} - -int -main(int argc, char **argv) -{ - struct state state = { 0 }; - - /* read/create config file */ - char filename[4096]; - char *home = getenv("HOME"); - snprintf(filename, sizeof(filename), "%s/%s", home, ".config/labwc/rc.xml"); - xml_init(filename); - xml_setup_nodes(); - - /* connect to gsettings */ - state.settings = g_settings_new("org.gnome.desktop.interface"); - - /* start ui */ - GtkApplication *app; - int status; - app = gtk_application_new(NULL, G_APPLICATION_DEFAULT_FLAGS); - g_signal_connect(app, "activate", G_CALLBACK(activate), &state); - status = g_application_run(G_APPLICATION(app), argc, argv); - g_object_unref(app); - - /* clean up */ - xml_finish(); - pango_cairo_font_map_set_default(NULL); - - return status; -} diff --git a/src/stack-appearance.c b/src/stack-appearance.c deleted file mode 100644 index e6cc8fa..0000000 --- a/src/stack-appearance.c +++ /dev/null @@ -1,97 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -#include "keyboard-layouts.h" -#include "state.h" -#include "stack-appearance.h" -#include "theme.h" -#include "xml.h" - -void -stack_appearance_init(struct state *state, GtkWidget *stack) -{ - GtkWidget *widget; - - GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_stack_add_named(GTK_STACK(stack), vbox, "appearance"); - gtk_container_child_set(GTK_CONTAINER(stack), vbox, "title", "Appearance", NULL); - - /* the grid with settings */ - int row = 0; - GtkWidget *grid = gtk_grid_new(); - g_object_set(grid, "margin", 20, "row-spacing", 10, "column-spacing", 10, NULL); - gtk_box_pack_start(GTK_BOX(vbox), grid, TRUE, TRUE, 5); - - /* openbox theme combobox */ - struct themes openbox_themes = { 0 }; - theme_find(&openbox_themes, "themes", "openbox-3/themerc"); - widget = gtk_label_new("openbox theme"); - gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, row, 1, 1); - state->widgets.openbox_theme_name = gtk_combo_box_text_new(); - int active = -1; - char *active_id = xml_get("/labwc_config/theme/name"); - struct theme *theme; - for (int i = 0; i < openbox_themes.nr; ++i) { - theme = openbox_themes.data + i; - if (active_id && !strcmp(theme->name, active_id)) { - active = i; - } - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(state->widgets.openbox_theme_name), theme->name); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(state->widgets.openbox_theme_name), active); - gtk_grid_attach(GTK_GRID(grid), state->widgets.openbox_theme_name, 1, row++, 1, 1); - theme_free_vector(&openbox_themes); - - /* corner radius spinbutton */ - widget = gtk_label_new("corner radius"); - gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, row, 1, 1); - GtkAdjustment *adjustment = gtk_adjustment_new(0, 0, 10, 1, 2, 0); - state->widgets.corner_radius = gtk_spin_button_new(GTK_ADJUSTMENT(adjustment), 1, 0); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(state->widgets.corner_radius), xml_get_int("/labwc_config/theme/cornerradius")); - gtk_grid_attach(GTK_GRID(grid), state->widgets.corner_radius, 1, row++, 1, 1); - - /* gtk theme combobox */ - struct themes gtk_themes = { 0 }; - theme_find(>k_themes, "themes", "gtk-3.0/gtk.css"); - - widget = gtk_label_new("gtk theme"); - gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, row, 1, 1); - state->widgets.gtk_theme_name = gtk_combo_box_text_new(); - - active_id = g_settings_get_string(state->settings, "gtk-theme"); - active = -1; - for (int i = 0; i < gtk_themes.nr; ++i) { - theme = gtk_themes.data + i; - if (!strcmp(theme->name, active_id)) { - active = i; - } - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(state->widgets.gtk_theme_name), theme->name); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(state->widgets.gtk_theme_name), active); - gtk_grid_attach(GTK_GRID(grid), state->widgets.gtk_theme_name, 1, row++, 1, 1); - theme_free_vector(>k_themes); - - /* icon theme combobox */ - struct themes icon_themes = { 0 }; - theme_find(&icon_themes, "icons", NULL); - - widget = gtk_label_new("icon theme"); - gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, row, 1, 1); - state->widgets.icon_theme_name = gtk_combo_box_text_new(); - - active_id = g_settings_get_string(state->settings, "icon-theme"); - active = -1; - for (int i = 0; i < icon_themes.nr; ++i) { - theme = icon_themes.data + i; - if (!strcmp(theme->name, active_id)) { - active = i; - } - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(state->widgets.icon_theme_name), theme->name); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(state->widgets.icon_theme_name), active); - gtk_grid_attach(GTK_GRID(grid), state->widgets.icon_theme_name, 1, row++, 1, 1); - theme_free_vector(&icon_themes); -} - diff --git a/src/stack-appearance.h b/src/stack-appearance.h deleted file mode 100644 index 8ae9f2d..0000000 --- a/src/stack-appearance.h +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef STACK_APPEARANCE_H -#define STACK_APPEARANCE_H -#include - -struct state; - -void stack_appearance_init(struct state *state, GtkWidget *stack); - -#endif /* STACK_APPEARANCE_H */ diff --git a/src/stack-lang.c b/src/stack-lang.c deleted file mode 100644 index f1296a0..0000000 --- a/src/stack-lang.c +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -#define _POSIX_C_SOURCE 200809L -#include -#include "environment.h" -#include "keyboard-layouts.h" -#include "state.h" -#include "stack-lang.h" -#include "theme.h" -#include "xml.h" - -void -stack_lang_init(struct state *state, GtkWidget *stack) -{ - GtkWidget *widget; - - GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_stack_add_named(GTK_STACK(stack), vbox, "lang"); - gtk_container_child_set(GTK_CONTAINER(stack), vbox, "title", "Language & Region", NULL); - - /* the grid with settings */ - int row = 0; - GtkWidget *grid = gtk_grid_new(); - g_object_set(grid, "margin", 20, "row-spacing", 10, "column-spacing", 10, NULL); - gtk_box_pack_start(GTK_BOX(vbox), grid, TRUE, TRUE, 5); - - /* keyboard layout */ - GList *keyboard_layouts = NULL; - keyboard_layouts_init(&keyboard_layouts, "/usr/share/X11/xkb/rules/evdev.lst"); - - widget = gtk_label_new("keyboard layout"); - gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, row, 1, 1); - state->widgets.keyboard_layout = gtk_combo_box_text_new(); - - char xkb_default_layout[1024]; - environment_get(xkb_default_layout, sizeof(xkb_default_layout), "XKB_DEFAULT_LAYOUT"); - int active = -1; - - GList *iter; - int i = 0; - for (iter = keyboard_layouts; iter; iter = iter->next) { - struct layout *layout = (struct layout *)iter->data; - if (!strcmp(layout->lang, xkb_default_layout)) { - active = i; - } - char buf[256]; - snprintf(buf, sizeof(buf), "%s %s", layout->lang, layout->description); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(state->widgets.keyboard_layout), buf); - ++i; - } - gtk_combo_box_set_active(GTK_COMBO_BOX(state->widgets.keyboard_layout), active); - gtk_grid_attach(GTK_GRID(grid), state->widgets.keyboard_layout, 1, row++, 1, 1); - keyboard_layouts_finish(keyboard_layouts); -} - diff --git a/src/stack-lang.h b/src/stack-lang.h deleted file mode 100644 index 80b74a7..0000000 --- a/src/stack-lang.h +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef STACK_LANG_H -#define STACK_LANG_H -#include - -struct state; - -void stack_lang_init(struct state *state, GtkWidget *stack); - -#endif /* STACK_LANG_H */ diff --git a/src/stack-mouse.c b/src/stack-mouse.c deleted file mode 100644 index 6437b08..0000000 --- a/src/stack-mouse.c +++ /dev/null @@ -1,64 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -#include "keyboard-layouts.h" -#include "state.h" -#include "stack-mouse.h" -#include "theme.h" -#include "xml.h" - -void -stack_mouse_init(struct state *state, GtkWidget *stack) -{ - GtkWidget *widget; - - GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_stack_add_named(GTK_STACK(stack), vbox, "mouse"); - gtk_container_child_set(GTK_CONTAINER(stack), vbox, "title", "Mouse & Touchpad", NULL); - - /* the grid with settings */ - int row = 0; - GtkWidget *grid = gtk_grid_new(); - g_object_set(grid, "margin", 20, "row-spacing", 10, "column-spacing", 10, NULL); - gtk_box_pack_start(GTK_BOX(vbox), grid, TRUE, TRUE, 5); - - /* cursor theme combobox */ - struct themes cursor_themes = { 0 }; - theme_find(&cursor_themes, "icons", "cursors"); - - widget = gtk_label_new("cursor theme"); - gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, row, 1, 1); - state->widgets.cursor_theme_name = gtk_combo_box_text_new(); - - char *active_id = g_settings_get_string(state->settings, "cursor-theme"); - int active = -1; - for (int i = 0; i < cursor_themes.nr; ++i) { - struct theme *theme = cursor_themes.data + i; - if (!strcmp(theme->name, active_id)) { - active = i; - } - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(state->widgets.cursor_theme_name), theme->name); - } - gtk_combo_box_set_active(GTK_COMBO_BOX(state->widgets.cursor_theme_name), active); - gtk_grid_attach(GTK_GRID(grid), state->widgets.cursor_theme_name, 1, row++, 1, 1); - theme_free_vector(&cursor_themes); - - /* cursor size spinbutton */ - widget = gtk_label_new("cursor size"); - gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, row, 1, 1); - GtkAdjustment *cursor_adjustment = gtk_adjustment_new(0, 0, 512, 1, 2, 0); - state->widgets.cursor_size = gtk_spin_button_new(GTK_ADJUSTMENT(cursor_adjustment), 1, 0); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(state->widgets.cursor_size), g_settings_get_int(state->settings, "cursor-size")); - gtk_grid_attach(GTK_GRID(grid), state->widgets.cursor_size, 1, row++, 1, 1); - - /* natural scroll combobox */ - widget = gtk_label_new("natural scroll"); - gtk_widget_set_halign(widget, GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grid), widget, 0, row, 1, 1); - state->widgets.natural_scroll = gtk_combo_box_text_new(); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(state->widgets.natural_scroll), "no"); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(state->widgets.natural_scroll), "yes"); - gtk_combo_box_set_active(GTK_COMBO_BOX(state->widgets.natural_scroll), xml_get_bool_text("/labwc_config/libinput/device/naturalscroll")); - gtk_grid_attach(GTK_GRID(grid), state->widgets.natural_scroll, 1, row++, 1, 1); -} - diff --git a/src/stack-mouse.h b/src/stack-mouse.h deleted file mode 100644 index 240846b..0000000 --- a/src/stack-mouse.h +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef STACK_MOUSE_H -#define STACK_MOUSE_H -#include - -struct state; - -void stack_mouse_init(struct state *state, GtkWidget *stack); - -#endif /* STACK_MOUSE_H */ diff --git a/src/state.h b/src/state.h deleted file mode 100644 index bc4646f..0000000 --- a/src/state.h +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef STATE_H -#define STATE_H -#include - -struct state { - GtkWidget *window; - struct { - GtkWidget *corner_radius; - GtkWidget *openbox_theme_name; - GtkWidget *gtk_theme_name; - GtkWidget *icon_theme_name; - GtkWidget *cursor_theme_name; - GtkWidget *cursor_size; - GtkWidget *natural_scroll; - GtkWidget *keyboard_layout; - } widgets; - GSettings *settings; -}; - -#endif /* STATE_H */ diff --git a/src/update.c b/src/update.c deleted file mode 100644 index 8172139..0000000 --- a/src/update.c +++ /dev/null @@ -1,81 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -#include -#include "environment.h" -#include "state.h" -#include "update.h" -#include "xml.h" - -static void -spawn_sync(char const *command) -{ - GError *err = NULL; - assert(command); - g_spawn_command_line_sync(command, NULL, NULL, NULL, &err); - if (err) { - fprintf(stderr, "warn: could not find %s\n", command); - g_error_free(err); - } -} - -static const char -*first_field(const char *s, char delim) -{ - char *p = strchr(s, delim); - if (p) { - *p = '\0'; - } - return s; -} - -static void -set_value_num(GSettings *settings, const char *key, int value) -{ - g_settings_set_value(settings, key, g_variant_new("i", value)); -} - -static void -set_value(GSettings *settings, const char *key, const char *value) -{ - if (!value) { - fprintf(stderr, "warn: cannot set '%s' - no value specified\n", key); - return; - } - g_settings_set_value(settings, key, g_variant_new("s", value)); -} - -#define COMBO_TEXT(w) gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(w)) -#define SPIN_BUTTON_VAL(w) gtk_spin_button_get_value(GTK_SPIN_BUTTON(w)) -#define SPIN_BUTTON_VAL_INT(w) (int)SPIN_BUTTON_VAL(w) - -void -update(GtkWidget *widget, gpointer data) -{ - struct state *state = (struct state *)data; - - /* ~/.config/labwc/rc.xml */ - xml_set_num("/labwc_config/theme/cornerradius", SPIN_BUTTON_VAL(state->widgets.corner_radius)); - xml_set("/labwc_config/theme/name", COMBO_TEXT(state->widgets.openbox_theme_name)); - xml_set("/labwc_config/libinput/device/naturalscroll", COMBO_TEXT(state->widgets.natural_scroll)); - xml_save(); - - /* gsettings */ - set_value(state->settings, "cursor-theme", COMBO_TEXT(state->widgets.cursor_theme_name)); - set_value_num(state->settings, "cursor-size", SPIN_BUTTON_VAL_INT(state->widgets.cursor_size)); - set_value(state->settings, "gtk-theme", COMBO_TEXT(state->widgets.gtk_theme_name)); - set_value(state->settings, "icon-theme", COMBO_TEXT(state->widgets.icon_theme_name)); - - /* ~/.config/labwc/environment */ - environment_set("XCURSOR_THEME", COMBO_TEXT(state->widgets.cursor_theme_name)); - environment_set_num("XCURSOR_SIZE", SPIN_BUTTON_VAL_INT(state->widgets.cursor_size)); - environment_set("XKB_DEFAULT_LAYOUT", first_field(COMBO_TEXT(state->widgets.keyboard_layout), ' ')); - - if (!g_strcmp0(COMBO_TEXT(state->widgets.openbox_theme_name), "GTK")) { - spawn_sync("labwc-gtktheme.py"); - } - - /* reconfigure labwc */ - if (!fork()) { - execl("/bin/sh", "/bin/sh", "-c", "killall -s SIGHUP labwc", (void *)NULL); - } -} - diff --git a/src/update.h b/src/update.h deleted file mode 100644 index 5913ebc..0000000 --- a/src/update.h +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef UPDATE_H -#define UPDATE_H -#include - -void update(GtkWidget *widget, gpointer data); - -#endif /* UPDATE_H */