Handle gtk-cursor-theme-size.
[lxde/lxappearance.git] / src / lxappearance2.c
CommitLineData
0cd84ed6
HJYP
1/*
2 * lxappearance2.c
3 *
4 * Copyright 2010 PCMan <pcman.tw@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
15c155a6
HJYP
26#include "lxappearance2.h"
27
0cd84ed6
HJYP
28#include <gtk/gtk.h>
29#include <glib/gi18n.h>
15c155a6
HJYP
30
31#include <X11/X.h>
32#include <X11/Xatom.h>
33#include <X11/Xlib.h>
34#include <gdk/gdkx.h>
35
0cd84ed6
HJYP
36#include "widget-theme.h"
37#include "icon-theme.h"
38#include "cursor-theme.h"
e597424e 39#include "other.h"
0cd84ed6 40
15c155a6
HJYP
41LXAppearance app = {0};
42
43Atom lxsession_atom = 0;
44
45static void check_lxsession()
46{
47 lxsession_atom = XInternAtom( GDK_DISPLAY(), "_LXSESSION", True );
48 if( lxsession_atom != None )
49 {
50 XGrabServer( GDK_DISPLAY() );
51 if( XGetSelectionOwner( GDK_DISPLAY(), lxsession_atom ) )
52 app.use_lxsession = TRUE;
53 XUngrabServer( GDK_DISPLAY() );
54 }
55}
56
0cd84ed6
HJYP
57static GOptionEntry option_entries[] =
58{
59 { NULL }
60};
61
15c155a6
HJYP
62static void lxappearance_save_gtkrc()
63{
64
65}
66
67static void lxappearance_save_lxsession()
68{
69
70}
71
72static void on_dlg_response(GtkDialog* dlg, int res, gpointer user_data)
73{
74 switch(res)
75 {
76 case GTK_RESPONSE_APPLY:
77
78 if(app.use_lxsession)
79 lxappearance_save_lxsession();
80 else
81 lxappearance_save_gtkrc();
82
83 app.changed = FALSE;
84 gtk_dialog_set_response_sensitive(app.dlg, GTK_RESPONSE_APPLY, FALSE);
85 break;
86 case 1: /* about dialog */
87 {
88 GtkBuilder* b = gtk_builder_new();
89 if(gtk_builder_add_from_file(b, PACKAGE_UI_DIR "/about.ui", NULL))
90 {
91 GtkWidget* dlg = GTK_WIDGET(gtk_builder_get_object(b, "dlg"));
92 gtk_dialog_run(dlg);
93 gtk_widget_destroy(dlg);
94 }
95 g_object_unref(b);
96 }
97 break;
98 default:
99 gtk_main_quit();
100 }
101}
102
103static void settings_init()
104{
e597424e
HJYP
105 GtkSettings* settings = gtk_settings_get_default();
106 g_object_get(settings,
107 "gtk-theme-name", &app.widget_theme,
108 "gtk-icon-theme-name", &app.icon_theme,
109 "gtk-cursor-theme-name", &app.cursor_theme,
4e409096 110 "gtk-cursor-theme-size", &app.cursor_theme_size,
e597424e
HJYP
111 "gtk-toolbar-style", &app.toolbar_style,
112 "gtk-toolbar-icon-size", &app.toolbar_icon_size,
113 NULL);
15c155a6 114 /* try to figure out cursor theme used. */
15c155a6
HJYP
115 if(!app.cursor_theme || g_strcmp0(app.cursor_theme, "default") == 0)
116 {
117 /* get the real theme name from default. */
118 GKeyFile* kf = g_key_file_new();
119 char* fpath = g_build_filename(g_get_home_dir(), ".icons/default/index.theme", NULL);
120 gboolean ret = g_key_file_load_from_file(kf, fpath, 0, NULL);
121 g_free(fpath);
122
123 if(!ret)
124 ret = g_key_file_load_from_data_dirs(kf, "icons/default/index.theme", NULL, 0, NULL);
125
126 if(ret)
127 {
e597424e 128 g_free(app.cursor_theme);
15c155a6
HJYP
129 app.cursor_theme = g_key_file_get_string(kf, "Icon Theme", "Inherits", NULL);
130 g_debug("cursor theme name: %s", app.cursor_theme);
131 }
132 g_key_file_free(kf);
133 }
134}
135
0cd84ed6
HJYP
136int main(int argc, char** argv)
137{
138 GError* err = NULL;
139 GtkBuilder* b;
0cd84ed6
HJYP
140
141 /* gettext support */
142#ifdef ENABLE_NLS
143 bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR );
144 bind_textdomain_codeset ( GETTEXT_PACKAGE, "UTF-8" );
145 textdomain ( GETTEXT_PACKAGE );
146#endif
147
0cd84ed6
HJYP
148 /* initialize GTK+ and parse the command line arguments */
149 if( G_UNLIKELY( ! gtk_init_with_args( &argc, &argv, "", option_entries, GETTEXT_PACKAGE, &err ) ) )
150 {
151 g_print( "Error: %s\n", err->message );
152 return 1;
153 }
154
15c155a6
HJYP
155 /* check if we're under LXSession */
156 check_lxsession();
157
158 /* load config values */
159 settings_init();
160
0cd84ed6
HJYP
161 /* create GUI here */
162 b = gtk_builder_new();
163 if(!gtk_builder_add_from_file(b, PACKAGE_UI_DIR "/lxappearance.ui", NULL))
164 return 1;
165
e597424e
HJYP
166 app.dlg = GTK_WIDGET(gtk_builder_get_object(b, "dlg"));
167
0cd84ed6
HJYP
168 widget_theme_init(b);
169 icon_theme_init(b);
170 cursor_theme_init(b);
e597424e 171 other_init(b);
0cd84ed6 172
15c155a6 173 g_signal_connect(app.dlg, "response", G_CALLBACK(on_dlg_response), NULL);
0cd84ed6 174
15c155a6 175 gtk_window_present(GTK_WINDOW(app.dlg));
0cd84ed6
HJYP
176 g_object_unref(b);
177
178 gtk_main();
179
180 return 0;
181}
15c155a6
HJYP
182
183void lxappearance_changed()
184{
185 if(!app.changed)
186 {
187 app.changed = TRUE;
188 gtk_dialog_set_response_sensitive(app.dlg, GTK_RESPONSE_APPLY, TRUE);
189 }
190}