-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.c
90 lines (78 loc) · 2.7 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// SPDX-License-Identifier: GPL-2.0-only
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#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 GTK");
/* 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)
{
#if HAVE_NLS
setlocale(LC_ALL, "");
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
textdomain(GETTEXT_PACKAGE);
#endif
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;
}