Disable setting of custom colors if run without lxsession.
[lxde/lxappearance.git] / src / lxappearance.c
CommitLineData
0cd84ed6 1/*
3a7d812e 2 * lxappearance.c
0cd84ed6
HJYP
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
3a7d812e 26#include "lxappearance.h"
15c155a6 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>
ae63f687 35#include <string.h>
15c155a6 36
c847cfdc 37#if ENABLE_DBUS
924e9daf 38#include <dbus/dbus.h>
c847cfdc 39#endif
924e9daf 40
0cd84ed6 41#include "widget-theme.h"
71ce58a7 42#include "color-scheme.h"
0cd84ed6
HJYP
43#include "icon-theme.h"
44#include "cursor-theme.h"
2d9128f0 45#include "font.h"
e597424e 46#include "other.h"
756f0a66 47#include "plugin.h"
0cd84ed6 48
15c155a6
HJYP
49LXAppearance app = {0};
50
51Atom lxsession_atom = 0;
ae63f687 52static const char* lxsession_name = NULL;
15c155a6 53
924e9daf
JL
54/* Dbus functions Copy from lxsession-logout
55 TODO Create a library fro this ?
56*/
57
58static gboolean check_lxde_dbus()
59{
c847cfdc 60#if ENABLE_DBUS
924e9daf
JL
61 DBusError error;
62 dbus_error_init(&error);
63 DBusConnection * connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
64 if (connection == NULL)
65 {
66 g_warning(G_STRLOC ": Failed to connect to the session message bus: %s", error.message);
67 dbus_error_free(&error);
68 return FALSE;
69 }
70
a50b8ed7 71 dbus_bool_t ret = dbus_bus_name_has_owner(connection,"org.lxde.SessionManager",NULL);
924e9daf 72
a50b8ed7 73 if (ret == TRUE)
924e9daf
JL
74 {
75 return TRUE;
76 }
77 else
78 {
79 return FALSE;
80 }
c847cfdc
JL
81#else
82 return FALSE;
83#endif
924e9daf
JL
84}
85
15c155a6
HJYP
86static void check_lxsession()
87{
073c0729 88 lxsession_atom = XInternAtom( GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "_LXSESSION", True );
15c155a6
HJYP
89 if( lxsession_atom != None )
90 {
073c0729
JL
91 XGrabServer( GDK_DISPLAY_XDISPLAY(gdk_display_get_default()) );
92 if( XGetSelectionOwner( GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), lxsession_atom ) )
ae63f687 93 {
15c155a6 94 app.use_lxsession = TRUE;
ae63f687
HJYP
95 lxsession_name = g_getenv("DESKTOP_SESSION");
96 }
073c0729 97 XUngrabServer( GDK_DISPLAY_XDISPLAY(gdk_display_get_default()) );
15c155a6 98 }
924e9daf
JL
99
100 /* Check Lxsession also with dbus */
101 if (check_lxde_dbus())
102 {
103 app.use_lxsession = TRUE;
104 lxsession_name = g_getenv("DESKTOP_SESSION");
105 }
106
15c155a6
HJYP
107}
108
0cd84ed6
HJYP
109static GOptionEntry option_entries[] =
110{
111 { NULL }
112};
113
ae63f687
HJYP
114static void save_cursor_theme_name()
115{
116 char* dir_path;
117 if(!app.cursor_theme || !g_strcmp0(app.cursor_theme, "default"))
118 return;
119
120 dir_path = g_build_filename(g_get_home_dir(), ".icons/default", NULL);
121 if(0 == g_mkdir_with_parents(dir_path, 0700))
122 {
123 char* index_theme = g_build_filename(dir_path, "index.theme", NULL);
124 char* content = g_strdup_printf(
f63c8576 125 "# This file is written by LXAppearance. Do not edit.\n"
ae63f687
HJYP
126 "[Icon Theme]\n"
127 "Name=Default\n"
128 "Comment=Default Cursor Theme\n"
79ec4790 129 "Inherits=%s\n", app.cursor_theme ? app.cursor_theme : "");
ae63f687
HJYP
130 g_file_set_contents(index_theme, content, -1, NULL);
131 g_free(content);
132 g_free(index_theme);
133 }
134 g_free(dir_path);
135
136 /*
137 dir_path = g_build_filename(g_get_home_dir(), ".Xdefaults", NULL);
138 Xcursor.theme: name
139 Xcursor.size: [size]
140 g_file_set_contents(dir_path, "", -1, NULL);
141 g_free(dir_path);
142 */
143}
144
145static void reload_all_programs()
15c155a6 146{
b4438824
JL
147#if GTK_CHECK_VERSION(3, 0, 0)
148
149/* TODO Port this to something else than gdk_event_send_clientmessage_toall */
150
151#else
ae63f687
HJYP
152 GdkEventClient event;
153 event.type = GDK_CLIENT_EVENT;
154 event.send_event = TRUE;
155 event.window = NULL;
15c155a6 156
ae63f687
HJYP
157 if( app.use_lxsession )
158 {
159 event.message_type = gdk_atom_intern_static_string("_LXSESSION");
160 event.data.b[0] = 0; /* LXS_RELOAD */
161 }
162 else
163 {
164 /* if( icon_only )
165 event.message_type = gdk_atom_intern("_GTK_LOAD_ICONTHEMES", FALSE);
166 */
167 event.message_type = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
168 }
169 event.data_format = 8;
170 gdk_event_send_clientmessage_toall((GdkEvent *)&event);
b4438824 171#endif
ae63f687
HJYP
172}
173
9bb12c12
HJYP
174static const char* bool2str(gboolean val)
175{
176 return val ? "TRUE" : "FALSE";
177}
b8648654 178
9bb12c12 179
ae63f687
HJYP
180static void lxappearance_save_gtkrc()
181{
182 static const char* tb_styles[]={
183 "GTK_TOOLBAR_ICONS",
184 "GTK_TOOLBAR_TEXT",
185 "GTK_TOOLBAR_BOTH",
186 "GTK_TOOLBAR_BOTH_HORIZ"
187 };
188 static const char* tb_icon_sizes[]={
189 "GTK_ICON_SIZE_INVALID",
190 "GTK_ICON_SIZE_MENU",
191 "GTK_ICON_SIZE_SMALL_TOOLBAR",
192 "GTK_ICON_SIZE_LARGE_TOOLBAR",
193 "GTK_ICON_SIZE_BUTTON",
194 "GTK_ICON_SIZE_DND",
195 "GTK_ICON_SIZE_DIALOG"
196 };
197
3518acea 198 char* file_path = g_build_filename(g_get_home_dir(), ".gtkrc-2.0", NULL);
c92e9c11 199 GString* content = g_string_sized_new(512);
79ec4790 200 g_string_append(content,
ae63f687 201 "# DO NOT EDIT! This file will be overwritten by LXAppearance.\n"
79ec4790
HJYP
202 "# Any customization should be done in ~/.gtkrc-2.0.mine instead.\n\n");
203 if(app.widget_theme)
204 g_string_append_printf(content,
205 "gtk-theme-name=\"%s\"\n", app.widget_theme);
206 if(app.icon_theme)
207 g_string_append_printf(content,
208 "gtk-icon-theme-name=\"%s\"\n", app.icon_theme);
209 if(app.default_font)
210 g_string_append_printf(content,
211 "gtk-font-name=\"%s\"\n", app.default_font);
212 if(app.cursor_theme)
213 g_string_append_printf(content,
214 "gtk-cursor-theme-name=\"%s\"\n", app.cursor_theme);
215 save_cursor_theme_name();
216
217 g_string_append_printf(content,
218 "gtk-cursor-theme-size=%d\n"
ae63f687
HJYP
219 "gtk-toolbar-style=%s\n"
220 "gtk-toolbar-icon-size=%s\n"
36827f45
HJYP
221 "gtk-button-images=%d\n"
222 "gtk-menu-images=%d\n"
9bb12c12 223#if GTK_CHECK_VERSION(2, 14, 0)
36827f45 224 "gtk-enable-event-sounds=%d\n"
79ec4790 225 "gtk-enable-input-feedback-sounds=%d\n"
9bb12c12 226#endif
2d9128f0
JL
227 "gtk-xft-antialias=%d\n"
228 "gtk-xft-hinting=%d\n"
229
79ec4790 230 , app.cursor_theme_size,
ae63f687
HJYP
231 tb_styles[app.toolbar_style],
232 tb_icon_sizes[app.toolbar_icon_size],
36827f45
HJYP
233 app.button_images ? 1 : 0,
234 app.menu_images ? 1 : 0,
9bb12c12 235#if GTK_CHECK_VERSION(2, 14, 0)
36827f45 236 app.enable_event_sound ? 1 : 0,
2d9128f0 237 app.enable_input_feedback ? 1 : 0,
9bb12c12 238#endif
2d9128f0
JL
239 app.enable_antialising ? 1 : 0,
240 app.enable_hinting ? 1 : 0
c92e9c11
HJYP
241 );
242
2d9128f0
JL
243 if(app.hinting_style)
244 g_string_append_printf(content,
b8648654 245 "gtk-xft-hintstyle=\"%s\"\n", app.hinting_style);
2d9128f0
JL
246
247 if(app.font_rgba)
248 g_string_append_printf(content,
b8648654 249 "gtk-xft-rgba=\"%s\"\n", app.font_rgba);
2d9128f0 250
eee70cc4
AG
251#if 0
252 /* unfortunately we cannot set colors without XSETTINGS daemon,
253 themes will override any custom settings in .gtkrc-2.0 file */
254 /* FIXME: we should support other xsettings daemons too */
c92e9c11
HJYP
255 if(app.color_scheme)
256 {
257 char* escaped = g_strescape(app.color_scheme, NULL);
258 g_string_append_printf(content,
203587a3 259 "gtk-color-scheme=\"%s\"\n",
c92e9c11
HJYP
260 escaped);
261 g_free(escaped);
262 }
eee70cc4 263#endif
c92e9c11
HJYP
264
265 g_string_append_printf(content,
266 "include \"%s/.gtkrc-2.0.mine\"\n",
ae63f687
HJYP
267 g_get_home_dir());
268
c92e9c11 269 g_file_set_contents(file_path, content->str, content->len, NULL);
c26fee92 270
924e9daf
JL
271 /* Save also in GTK3 folder
272 Content shold be different from the gtk2 one
273 */
274 GString* content_gtk3 = g_string_sized_new(512);
275 char* file_path_gtk3 = g_build_filename(g_get_user_config_dir(), "gtk-3.0", NULL);
276 char* file_path_settings = g_build_filename(g_get_user_config_dir(), "gtk-3.0", "settings.ini", NULL);
c26fee92
JL
277
278 if (!g_file_test(file_path_gtk3, G_FILE_TEST_IS_DIR))
279 {
280 g_mkdir_with_parents(file_path_gtk3, 0755);
281 }
282
924e9daf
JL
283
284 g_string_append(content_gtk3, "[Settings] \n");
285
286 if(app.widget_theme)
287 g_string_append_printf(content_gtk3,
288 "gtk-theme-name=%s\n", app.widget_theme);
289 if(app.icon_theme)
290 g_string_append_printf(content_gtk3,
291 "gtk-icon-theme-name=%s\n", app.icon_theme);
292 if(app.default_font)
293 g_string_append_printf(content_gtk3,
294 "gtk-font-name=%s\n", app.default_font);
295 if(app.cursor_theme)
296 g_string_append_printf(content_gtk3,
297 "gtk-cursor-theme-name=%s\n", app.cursor_theme);
298 save_cursor_theme_name();
299
300 g_string_append_printf(content_gtk3,
301 "gtk-cursor-theme-size=%d\n"
302 "gtk-toolbar-style=%s\n"
303 "gtk-toolbar-icon-size=%s\n"
304 "gtk-button-images=%d\n"
305 "gtk-menu-images=%d\n"
306#if GTK_CHECK_VERSION(2, 14, 0)
307 "gtk-enable-event-sounds=%d\n"
308 "gtk-enable-input-feedback-sounds=%d\n"
309#endif
310 "gtk-xft-antialias=%d\n"
311 "gtk-xft-hinting=%d\n"
312
313 , app.cursor_theme_size,
314 tb_styles[app.toolbar_style],
315 tb_icon_sizes[app.toolbar_icon_size],
316 app.button_images ? 1 : 0,
317 app.menu_images ? 1 : 0,
318#if GTK_CHECK_VERSION(2, 14, 0)
319 app.enable_event_sound ? 1 : 0,
320 app.enable_input_feedback ? 1 : 0,
321#endif
322 app.enable_antialising ? 1 : 0,
323 app.enable_hinting ? 1 : 0
324 );
325
326 if(app.hinting_style)
327 g_string_append_printf(content_gtk3,
328 "gtk-xft-hintstyle=%s\n", app.hinting_style);
329
330 if(app.font_rgba)
331 g_string_append_printf(content_gtk3,
332 "gtk-xft-rgba=%s\n", app.font_rgba);
333
eee70cc4
AG
334#if 0
335 /* unfortunately we cannot set colors without XSETTINGS daemon,
336 themes will override any custom settings in .gtkrc-2.0 file */
337 /* FIXME: we should support other xsettings daemons too */
924e9daf
JL
338 if(app.color_scheme)
339 {
340 char* escaped = g_strescape(app.color_scheme, NULL);
341 g_string_append_printf(content_gtk3,
342 "gtk-color-scheme=%s\n",
343 escaped);
344 g_free(escaped);
345 }
eee70cc4 346#endif
924e9daf
JL
347
348 g_file_set_contents(file_path_settings, content_gtk3->str, content_gtk3->len, NULL);
c26fee92 349
c92e9c11 350 g_string_free(content, TRUE);
924e9daf 351 g_string_free(content_gtk3, TRUE);
ae63f687 352 g_free(file_path);
15c155a6
HJYP
353}
354
355static void lxappearance_save_lxsession()
356{
ae63f687
HJYP
357 char* rel_path = g_strconcat("lxsession/", lxsession_name, "/desktop.conf", NULL);
358 char* user_config_file = g_build_filename(g_get_user_config_dir(), rel_path, NULL);
359 char* buf;
b8648654 360 int len;
ae63f687
HJYP
361 GKeyFile* kf = g_key_file_new();
362
363 if(!g_key_file_load_from_file(kf, user_config_file, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL))
364 {
365 /* the user config file doesn't exist, create its parent dir */
366 len = strlen(user_config_file) - strlen("/desktop.conf");
367 user_config_file[len] = '\0';
368 g_debug("user_config_file = %s", user_config_file);
369 g_mkdir_with_parents(user_config_file, 0700);
370 user_config_file[len] = '/';
371
df6716ee
HJYP
372 g_key_file_load_from_dirs(kf, rel_path, (const char**)g_get_system_config_dirs(), NULL,
373 G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL);
ae63f687
HJYP
374 }
375
376 g_free(rel_path);
15c155a6 377
ae63f687
HJYP
378 g_key_file_set_string( kf, "GTK", "sNet/ThemeName", app.widget_theme );
379 g_key_file_set_string( kf, "GTK", "sGtk/FontName", app.default_font );
380
c92e9c11 381 g_key_file_set_string( kf, "GTK", "sGtk/ColorScheme", app.color_scheme ? app.color_scheme : "" );
71ce58a7 382
ae63f687
HJYP
383 g_key_file_set_string( kf, "GTK", "sNet/IconThemeName", app.icon_theme );
384
385 g_key_file_set_string( kf, "GTK", "sGtk/CursorThemeName", app.cursor_theme );
386 g_key_file_set_integer( kf, "GTK", "iGtk/CursorThemeSize", app.cursor_theme_size );
387 save_cursor_theme_name();
388
389 g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarStyle", app.toolbar_style );
390 g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarIconSize", app.toolbar_icon_size );
391
9bb12c12
HJYP
392 g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarStyle", app.toolbar_style );
393 g_key_file_set_integer( kf, "GTK", "iGtk/ToolbarIconSize", app.toolbar_icon_size );
394
6b54b65a
HJYP
395 g_key_file_set_integer( kf, "GTK", "iGtk/ButtonImages", app.button_images );
396 g_key_file_set_integer( kf, "GTK", "iGtk/MenuImages", app.menu_images );
397
398#if GTK_CHECK_VERSION(2, 14, 0)
9bb12c12
HJYP
399 /* "Net/SoundThemeName\0" "gtk-sound-theme-name\0" */
400 g_key_file_set_integer( kf, "GTK", "iNet/EnableEventSounds", app.enable_event_sound);
401 g_key_file_set_integer( kf, "GTK", "iNet/EnableInputFeedbackSounds", app.enable_input_feedback);
402#endif
2d9128f0
JL
403 g_key_file_set_integer( kf, "GTK", "iXft/Antialias", app.enable_antialising);
404 g_key_file_set_integer( kf, "GTK", "iXft/Hinting", app.enable_hinting);
b8648654
JL
405 g_key_file_set_string( kf, "GTK", "sXft/HintStyle", app.hinting_style);
406 g_key_file_set_string( kf, "GTK", "sXft/RGBA", app.font_rgba);
9bb12c12 407
ae63f687
HJYP
408 buf = g_key_file_to_data( kf, &len, NULL );
409 g_key_file_free(kf);
410
411 g_file_set_contents(user_config_file, buf, len, NULL);
412 g_free(buf);
413 g_free(user_config_file);
15c155a6
HJYP
414}
415
416static void on_dlg_response(GtkDialog* dlg, int res, gpointer user_data)
417{
418 switch(res)
419 {
420 case GTK_RESPONSE_APPLY:
421
422 if(app.use_lxsession)
423 lxappearance_save_lxsession();
424 else
425 lxappearance_save_gtkrc();
426
ae63f687
HJYP
427 reload_all_programs();
428
15c155a6 429 app.changed = FALSE;
df6716ee 430 gtk_dialog_set_response_sensitive(GTK_DIALOG(app.dlg), GTK_RESPONSE_APPLY, FALSE);
15c155a6
HJYP
431 break;
432 case 1: /* about dialog */
433 {
434 GtkBuilder* b = gtk_builder_new();
435 if(gtk_builder_add_from_file(b, PACKAGE_UI_DIR "/about.ui", NULL))
436 {
437 GtkWidget* dlg = GTK_WIDGET(gtk_builder_get_object(b, "dlg"));
df6716ee 438 gtk_dialog_run(GTK_DIALOG(dlg));
15c155a6
HJYP
439 gtk_widget_destroy(dlg);
440 }
441 g_object_unref(b);
442 }
443 break;
444 default:
445 gtk_main_quit();
446 }
447}
448
449static void settings_init()
450{
e597424e
HJYP
451 GtkSettings* settings = gtk_settings_get_default();
452 g_object_get(settings,
453 "gtk-theme-name", &app.widget_theme,
ae63f687 454 "gtk-font-name", &app.default_font,
e597424e
HJYP
455 "gtk-icon-theme-name", &app.icon_theme,
456 "gtk-cursor-theme-name", &app.cursor_theme,
4e409096 457 "gtk-cursor-theme-size", &app.cursor_theme_size,
e597424e
HJYP
458 "gtk-toolbar-style", &app.toolbar_style,
459 "gtk-toolbar-icon-size", &app.toolbar_icon_size,
6b54b65a
HJYP
460 "gtk-button-images", &app.button_images,
461 "gtk-menu-images", &app.menu_images,
9bb12c12
HJYP
462#if GTK_CHECK_VERSION(2, 14, 0)
463 "gtk-enable-event-sounds", &app.enable_event_sound,
464 "gtk-enable-input-feedback-sounds", &app.enable_input_feedback,
465#endif
2d9128f0
JL
466 "gtk-xft-antialias", &app.enable_antialising,
467 "gtk-xft-hinting", &app.enable_hinting,
468 "gtk-xft-hintstyle", &app.hinting_style,
469 "gtk-xft-rgba", &app.font_rgba,
e597424e 470 NULL);
15c155a6 471 /* try to figure out cursor theme used. */
15c155a6
HJYP
472 if(!app.cursor_theme || g_strcmp0(app.cursor_theme, "default") == 0)
473 {
474 /* get the real theme name from default. */
475 GKeyFile* kf = g_key_file_new();
476 char* fpath = g_build_filename(g_get_home_dir(), ".icons/default/index.theme", NULL);
477 gboolean ret = g_key_file_load_from_file(kf, fpath, 0, NULL);
478 g_free(fpath);
479
480 if(!ret)
481 ret = g_key_file_load_from_data_dirs(kf, "icons/default/index.theme", NULL, 0, NULL);
482
483 if(ret)
484 {
e597424e 485 g_free(app.cursor_theme);
15c155a6
HJYP
486 app.cursor_theme = g_key_file_get_string(kf, "Icon Theme", "Inherits", NULL);
487 g_debug("cursor theme name: %s", app.cursor_theme);
488 }
489 g_key_file_free(kf);
490 }
c92e9c11
HJYP
491
492 app.color_scheme_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
493 /* try to load custom color scheme if available */
494 if(app.use_lxsession)
495 {
496 char* rel_path = g_strconcat("lxsession/", lxsession_name, "/desktop.conf", NULL);
497 char* user_config_file = g_build_filename(g_get_user_config_dir(), rel_path, NULL);
498 GKeyFile* kf = g_key_file_new();
499 if(g_key_file_load_from_file(kf, user_config_file, 0, NULL))
500 app.color_scheme = g_key_file_get_string(kf, "GTK", "sGtk/ColorScheme", NULL);
df6716ee 501 else if(g_key_file_load_from_dirs(kf, rel_path, (const char**)g_get_system_config_dirs(), NULL, 0, NULL))
c92e9c11
HJYP
502 app.color_scheme = g_key_file_get_string(kf, "GTK", "sGtk/ColorScheme", NULL);
503 g_key_file_free(kf);
504 g_free(rel_path);
505 g_free(user_config_file);
506
507 if(app.color_scheme)
508 {
509 if(*app.color_scheme)
510 color_scheme_str_to_hash(app.color_scheme_hash, app.color_scheme);
511 else
512 {
513 g_free(app.color_scheme);
514 app.color_scheme = NULL;
515 }
516 }
517 }
eee70cc4
AG
518#if 0
519 /* unfortunately we cannot set colors without XSETTINGS daemon,
520 themes will override any custom settings in .gtkrc-2.0 file */
521 /* FIXME: we should support other xsettings daemons too */
c92e9c11
HJYP
522 else
523 {
524 char* gtkrc_file = g_build_filename(g_get_home_dir(), ".gtkrc-2.0", NULL);
525 gtkrc_file_get_color_scheme(gtkrc_file, app.color_scheme_hash);
526 g_free(gtkrc_file);
527 if(g_hash_table_size(app.color_scheme_hash) > 0)
528 app.color_scheme = color_scheme_hash_to_str(app.color_scheme_hash);
529 }
eee70cc4 530#endif
15c155a6
HJYP
531}
532
0cd84ed6
HJYP
533int main(int argc, char** argv)
534{
535 GError* err = NULL;
536 GtkBuilder* b;
0cd84ed6
HJYP
537
538 /* gettext support */
539#ifdef ENABLE_NLS
540 bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR );
541 bind_textdomain_codeset ( GETTEXT_PACKAGE, "UTF-8" );
542 textdomain ( GETTEXT_PACKAGE );
543#endif
544
ff19d42c 545 g_thread_init(NULL);
0cd84ed6
HJYP
546 /* initialize GTK+ and parse the command line arguments */
547 if( G_UNLIKELY( ! gtk_init_with_args( &argc, &argv, "", option_entries, GETTEXT_PACKAGE, &err ) ) )
548 {
549 g_print( "Error: %s\n", err->message );
550 return 1;
551 }
552
1123e741
HJYP
553 app.abi_version = LXAPPEARANCE_ABI_VERSION;
554
15c155a6
HJYP
555 /* check if we're under LXSession */
556 check_lxsession();
557
0cd84ed6
HJYP
558 /* create GUI here */
559 b = gtk_builder_new();
560 if(!gtk_builder_add_from_file(b, PACKAGE_UI_DIR "/lxappearance.ui", NULL))
561 return 1;
562
6b54b65a
HJYP
563 /* NOTE: GUI must be created prior to loading settings from GtkSettings object.
564 * Some properties of GtkSettings class are installed by some other gtk classes.
565 * For example, "gtk-menu-images" property is actually installed by initialization
566 * of GtkImageMenuItem class. If we load the GUI first, then when the menu items
567 * are created, this property gets correctly registered. So later it can be read. */
568
569 /* load config values */
570 settings_init();
571
e597424e
HJYP
572 app.dlg = GTK_WIDGET(gtk_builder_get_object(b, "dlg"));
573
0cd84ed6 574 widget_theme_init(b);
71ce58a7 575 color_scheme_init(b);
0cd84ed6
HJYP
576 icon_theme_init(b);
577 cursor_theme_init(b);
2d9128f0 578 font_init(b);
e597424e 579 other_init(b);
756f0a66
HJYP
580 /* the page for window manager plugins */
581 app.wm_page = GTK_WIDGET(gtk_builder_get_object(b, "wm_page"));
582
ff19d42c
HJYP
583 plugins_init(b);
584
15c155a6 585 g_signal_connect(app.dlg, "response", G_CALLBACK(on_dlg_response), NULL);
0cd84ed6 586
15c155a6 587 gtk_window_present(GTK_WINDOW(app.dlg));
0cd84ed6
HJYP
588 g_object_unref(b);
589
590 gtk_main();
591
756f0a66
HJYP
592 plugins_finalize();
593
0cd84ed6
HJYP
594 return 0;
595}
15c155a6
HJYP
596
597void lxappearance_changed()
598{
599 if(!app.changed)
600 {
601 app.changed = TRUE;
df6716ee 602 gtk_dialog_set_response_sensitive(GTK_DIALOG(app.dlg), GTK_RESPONSE_APPLY, TRUE);
15c155a6
HJYP
603 }
604}
2d9128f0
JL
605
606void on_check_button_toggled(GtkToggleButton* btn, gpointer user_data)
607{
608 gboolean* val = (gboolean*)user_data;
609 gboolean new_val = gtk_toggle_button_get_active(btn);
610 if(new_val != *val)
611 {
612 *val = new_val;
613 lxappearance_changed();
614 }
615}