1
/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3
appearance.c for ObConf, the configuration tool for Openbox
4
Copyright (c) 2003-2007 Dana Jansens
5
Copyright (c) 2003 Tim Riley
7
Copyright (C) 2010 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
See the COPYING file for a copy of the GNU General Public License.
22
/* This file is part of ObConf. It's taken by Hong Jen Yee on
23
* 2010-08-07 and some modifications were done to make it a loadable
24
* module of LXAppearance. */
28
#include "preview_update.h"
29
#include "appearance.h"
30
#include <ctype.h> /* toupper */
32
static gboolean mapping = FALSE;
34
static RrFont *read_font(GtkFontButton *w, const gchar *place);
35
static RrFont *write_font(GtkFontButton *w, const gchar *place);
39
void on_title_layout_changed(GtkEntry *w, gpointer data);
40
void on_font_active_font_set(GtkFontButton *w, gpointer data);
41
void on_font_inactive_font_set(GtkFontButton *w, gpointer data);
42
void on_font_menu_header_font_set(GtkFontButton *w, gpointer data);
43
void on_font_menu_item_font_set(GtkFontButton *w, gpointer data);
44
void on_font_active_display_font_set(GtkFontButton *w, gpointer data);
45
void on_font_inactive_display_font_set(GtkFontButton *w, gpointer data);
47
/* End of forwarded */
49
void appearance_setup_tab()
57
w = get_widget("window_border");
58
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
59
tree_get_bool("theme/keepBorder", TRUE));
61
w = get_widget("animate_iconify");
62
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
63
tree_get_bool("theme/animateIconify", TRUE));
65
w = get_widget("title_layout");
66
layout = tree_get_string("theme/titleLayout", "NLIMC");
67
gtk_entry_set_text(GTK_ENTRY(w), layout);
68
preview_update_set_title_layout(layout);
71
w = get_widget("font_active");
72
f = read_font(GTK_FONT_BUTTON(w), "ActiveWindow");
73
preview_update_set_active_font(f);
75
w = get_widget("font_inactive");
76
f = read_font(GTK_FONT_BUTTON(w), "InactiveWindow");
77
preview_update_set_inactive_font(f);
79
w = get_widget("font_menu_header");
80
f = read_font(GTK_FONT_BUTTON(w), "MenuHeader");
81
preview_update_set_menu_header_font(f);
83
w = get_widget("font_menu_item");
84
f = read_font(GTK_FONT_BUTTON(w), "MenuItem");
85
preview_update_set_menu_item_font(f);
87
w = get_widget("font_active_display");
88
if (!(f = read_font(GTK_FONT_BUTTON(w), "ActiveOnScreenDisplay"))) {
89
f = read_font(GTK_FONT_BUTTON(w), "OnScreenDisplay");
90
tree_delete_node("theme/font:place=OnScreenDisplay");
92
preview_update_set_osd_active_font(f);
94
w = get_widget("font_inactive_display");
95
f = read_font(GTK_FONT_BUTTON(w), "InactiveOnScreenDisplay");
96
preview_update_set_osd_inactive_font(f);
101
void on_title_layout_changed(GtkEntry *w, gpointer data)
105
gboolean n, d, s, l, i, m, c;
109
layout = g_strdup(gtk_entry_get_text(w));
111
n = d = s = l = i = m = c = FALSE;
113
for (it = layout; *it; ++it) {
151
/* drop the letter */
152
for (it2 = it; *it2; ++it2)
160
gtk_entry_set_text(w, layout);
161
tree_set_string("theme/titleLayout", layout);
162
preview_update_set_title_layout(layout);
167
void on_font_active_font_set(GtkFontButton *w, gpointer data)
171
preview_update_set_active_font(write_font(w, "ActiveWindow"));
174
void on_font_inactive_font_set(GtkFontButton *w, gpointer data)
178
preview_update_set_inactive_font(write_font(w, "InactiveWindow"));
181
void on_font_menu_header_font_set(GtkFontButton *w, gpointer data)
185
preview_update_set_menu_header_font(write_font(w, "MenuHeader"));
188
void on_font_menu_item_font_set(GtkFontButton *w, gpointer data)
192
preview_update_set_menu_item_font(write_font(w, "MenuItem"));
195
void on_font_active_display_font_set(GtkFontButton *w, gpointer data)
198
#if RR_CHECK_VERSION(3, 5, 0)
199
preview_update_set_osd_active_font(write_font(w, "ActiveOnScreenDisplay"));
200
#else /* for older versions of openbox */
201
preview_update_set_osd_active_font(write_font(w, "OnScreenDisplay"));
205
void on_font_inactive_display_font_set(GtkFontButton *w, gpointer data)
209
preview_update_set_osd_inactive_font(write_font(w, "InactiveOnScreenDisplay"));
212
static RrFont *read_font(GtkFontButton *w, const gchar *place)
215
gchar *fontstring, *node;
216
gchar *name, **names;
221
RrFontWeight rr_weight = RR_FONTWEIGHT_NORMAL;
222
RrFontSlant rr_slant = RR_FONTSLANT_NORMAL;
226
node = g_strdup_printf("theme/font:place=%s/name", place);
227
name = tree_get_string(node, "Sans");
230
node = g_strdup_printf("theme/font:place=%s/size", place);
231
size = tree_get_string(node, "8");
234
node = g_strdup_printf("theme/font:place=%s/weight", place);
235
weight = tree_get_string(node, "");
238
node = g_strdup_printf("theme/font:place=%s/slant", place);
239
slant = tree_get_string(node, "");
242
/* get only the first font in the string */
243
names = g_strsplit(name, ",", 0);
245
name = g_strdup(names[0]);
248
/* don't use "normal" in the gtk string */
249
if (!g_ascii_strcasecmp(weight, "normal")) {
250
g_free(weight); weight = g_strdup("");
252
if (!g_ascii_strcasecmp(slant, "normal")) {
253
g_free(slant); slant = g_strdup("");
256
fontstring = g_strdup_printf("%s %s %s %s", name, weight, slant, size);
257
gtk_font_button_set_font_name(w, fontstring);
259
if (!g_ascii_strcasecmp(weight, "Bold")) rr_weight = RR_FONTWEIGHT_BOLD;
260
if (!g_ascii_strcasecmp(slant, "Italic")) rr_slant = RR_FONTSLANT_ITALIC;
261
if (!g_ascii_strcasecmp(slant, "Oblique")) rr_slant = RR_FONTSLANT_OBLIQUE;
263
font = RrFontOpen(rrinst, name, atoi(size), rr_weight, rr_slant);
275
static RrFont *write_font(GtkFontButton *w, const gchar *place)
279
const gchar *size = NULL;
280
const gchar *bold = NULL;
281
const gchar *italic = NULL;
283
RrFontWeight weight = RR_FONTWEIGHT_NORMAL;
284
RrFontSlant slant = RR_FONTSLANT_NORMAL;
286
if (mapping) return NULL;
288
font = g_strdup(gtk_font_button_get_font_name(w));
289
while ((c = strrchr(font, ' '))) {
290
if (!bold && !italic && !size && atoi(c+1))
292
else if (!bold && !italic && !g_ascii_strcasecmp(c+1, "italic"))
294
else if (!bold && !g_ascii_strcasecmp(c+1, "bold"))
300
if (!bold) bold = "Normal";
301
if (!italic) italic = "Normal";
303
node = g_strdup_printf("theme/font:place=%s/name", place);
304
tree_set_string(node, font);
307
node = g_strdup_printf("theme/font:place=%s/size", place);
308
tree_set_string(node, size);
311
node = g_strdup_printf("theme/font:place=%s/weight", place);
312
tree_set_string(node, bold);
315
node = g_strdup_printf("theme/font:place=%s/slant", place);
316
tree_set_string(node, italic);
319
if (!g_ascii_strcasecmp(bold, "Bold")) weight = RR_FONTWEIGHT_BOLD;
320
if (!g_ascii_strcasecmp(italic, "Italic")) slant = RR_FONTSLANT_ITALIC;
321
if (!g_ascii_strcasecmp(italic, "Oblique")) slant = RR_FONTSLANT_OBLIQUE;
323
return RrFontOpen(rrinst, font, atoi(size), weight, slant);