~ubuntu-branches/ubuntu/wily/lxappearance-obconf/wily-proposed

« back to all changes in this revision

Viewing changes to src/appearance.c

  • Committer: Package Import Robot
  • Author(s): Daniel Baumann
  • Date: 2012-04-16 21:39:22 UTC
  • Revision ID: package-import@ubuntu.com-20120416213922-fcf49q5qsm9tv5ms
Tags: upstream-0.2.0
ImportĀ upstreamĀ versionĀ 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
 
2
 
 
3
   appearance.c for ObConf, the configuration tool for Openbox
 
4
   Copyright (c) 2003-2007   Dana Jansens
 
5
   Copyright (c) 2003        Tim Riley
 
6
 
 
7
   Copyright (C) 2010        Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
 
8
 
 
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.
 
13
 
 
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.
 
18
 
 
19
   See the COPYING file for a copy of the GNU General Public License.
 
20
*/
 
21
 
 
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. */
 
25
 
 
26
#include "main.h"
 
27
#include "tree.h"
 
28
#include "preview_update.h"
 
29
#include "appearance.h"
 
30
#include <ctype.h> /* toupper */
 
31
 
 
32
static gboolean mapping = FALSE;
 
33
 
 
34
static RrFont *read_font(GtkFontButton *w, const gchar *place);
 
35
static RrFont *write_font(GtkFontButton *w, const gchar *place);
 
36
 
 
37
/* Forwarded */
 
38
 
 
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);
 
46
 
 
47
/* End of forwarded */
 
48
 
 
49
void appearance_setup_tab()
 
50
{
 
51
    GtkWidget *w;
 
52
    gchar *layout;
 
53
    RrFont *f;
 
54
 
 
55
    mapping = TRUE;
 
56
/*
 
57
    w = get_widget("window_border");
 
58
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
 
59
                                 tree_get_bool("theme/keepBorder", TRUE));
 
60
 
 
61
    w = get_widget("animate_iconify");
 
62
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
 
63
                                 tree_get_bool("theme/animateIconify", TRUE));
 
64
*/
 
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);
 
69
    g_free(layout);
 
70
 
 
71
    w = get_widget("font_active");
 
72
    f = read_font(GTK_FONT_BUTTON(w), "ActiveWindow");
 
73
    preview_update_set_active_font(f);
 
74
 
 
75
    w = get_widget("font_inactive");
 
76
    f = read_font(GTK_FONT_BUTTON(w), "InactiveWindow");
 
77
    preview_update_set_inactive_font(f);
 
78
 
 
79
    w = get_widget("font_menu_header");
 
80
    f = read_font(GTK_FONT_BUTTON(w), "MenuHeader");
 
81
    preview_update_set_menu_header_font(f);
 
82
 
 
83
    w = get_widget("font_menu_item");
 
84
    f = read_font(GTK_FONT_BUTTON(w), "MenuItem");
 
85
    preview_update_set_menu_item_font(f);
 
86
 
 
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");
 
91
    }
 
92
    preview_update_set_osd_active_font(f);
 
93
 
 
94
    w = get_widget("font_inactive_display");
 
95
    f = read_font(GTK_FONT_BUTTON(w), "InactiveOnScreenDisplay");
 
96
    preview_update_set_osd_inactive_font(f);
 
97
 
 
98
    mapping = FALSE;
 
99
}
 
100
 
 
101
void on_title_layout_changed(GtkEntry *w, gpointer data)
 
102
{
 
103
    gchar *layout;
 
104
    gchar *it, *it2;
 
105
    gboolean n, d, s, l, i, m, c;
 
106
 
 
107
    if (mapping) return;
 
108
 
 
109
    layout = g_strdup(gtk_entry_get_text(w));
 
110
 
 
111
    n = d = s = l = i = m = c = FALSE;
 
112
 
 
113
    for (it = layout; *it; ++it) {
 
114
        gboolean *b;
 
115
 
 
116
        switch (*it) {
 
117
        case 'N':
 
118
        case 'n':
 
119
            b = &n;
 
120
            break;
 
121
        case 'd':
 
122
        case 'D':
 
123
            b = &d;
 
124
            break;
 
125
        case 's':
 
126
        case 'S':
 
127
            b = &s;
 
128
            break;
 
129
        case 'l':
 
130
        case 'L':
 
131
            b = &l;
 
132
            break;
 
133
        case 'i':
 
134
        case 'I':
 
135
            b = &i;
 
136
            break;
 
137
        case 'm':
 
138
        case 'M':
 
139
            b = &m;
 
140
            break;
 
141
        case 'c':
 
142
        case 'C':
 
143
            b = &c;
 
144
            break;
 
145
        default:
 
146
            b = NULL;
 
147
            break;
 
148
        }
 
149
 
 
150
        if (!b || *b) {
 
151
            /* drop the letter */
 
152
            for (it2 = it; *it2; ++it2)
 
153
                *it2 = *(it2+1);
 
154
        } else {
 
155
            *it = toupper(*it);
 
156
            *b = TRUE;
 
157
        }
 
158
    }
 
159
 
 
160
    gtk_entry_set_text(w, layout);
 
161
    tree_set_string("theme/titleLayout", layout);
 
162
    preview_update_set_title_layout(layout);
 
163
 
 
164
    g_free(layout);
 
165
}
 
166
 
 
167
void on_font_active_font_set(GtkFontButton *w, gpointer data)
 
168
{
 
169
    if (mapping) return;
 
170
 
 
171
    preview_update_set_active_font(write_font(w, "ActiveWindow"));
 
172
}
 
173
 
 
174
void on_font_inactive_font_set(GtkFontButton *w, gpointer data)
 
175
{
 
176
    if (mapping) return;
 
177
 
 
178
    preview_update_set_inactive_font(write_font(w, "InactiveWindow"));
 
179
}
 
180
 
 
181
void on_font_menu_header_font_set(GtkFontButton *w, gpointer data)
 
182
{
 
183
    if (mapping) return;
 
184
 
 
185
    preview_update_set_menu_header_font(write_font(w, "MenuHeader"));
 
186
}
 
187
 
 
188
void on_font_menu_item_font_set(GtkFontButton *w, gpointer data)
 
189
{
 
190
    if (mapping) return;
 
191
 
 
192
    preview_update_set_menu_item_font(write_font(w, "MenuItem"));
 
193
}
 
194
 
 
195
void on_font_active_display_font_set(GtkFontButton *w, gpointer data)
 
196
{
 
197
    if (mapping) return;
 
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"));
 
202
#endif
 
203
}
 
204
 
 
205
void on_font_inactive_display_font_set(GtkFontButton *w, gpointer data)
 
206
{
 
207
    if (mapping) return;
 
208
 
 
209
    preview_update_set_osd_inactive_font(write_font(w, "InactiveOnScreenDisplay"));
 
210
}
 
211
 
 
212
static RrFont *read_font(GtkFontButton *w, const gchar *place)
 
213
{
 
214
    RrFont *font;
 
215
    gchar *fontstring, *node;
 
216
    gchar *name, **names;
 
217
    gchar *size;
 
218
    gchar *weight;
 
219
    gchar *slant;
 
220
 
 
221
    RrFontWeight rr_weight = RR_FONTWEIGHT_NORMAL;
 
222
    RrFontSlant rr_slant = RR_FONTSLANT_NORMAL;
 
223
 
 
224
    mapping = TRUE;
 
225
 
 
226
    node = g_strdup_printf("theme/font:place=%s/name", place);
 
227
    name = tree_get_string(node, "Sans");
 
228
    g_free(node);
 
229
 
 
230
    node = g_strdup_printf("theme/font:place=%s/size", place);
 
231
    size = tree_get_string(node, "8");
 
232
    g_free(node);
 
233
 
 
234
    node = g_strdup_printf("theme/font:place=%s/weight", place);
 
235
    weight = tree_get_string(node, "");
 
236
    g_free(node);
 
237
 
 
238
    node = g_strdup_printf("theme/font:place=%s/slant", place);
 
239
    slant = tree_get_string(node, "");
 
240
    g_free(node);
 
241
 
 
242
    /* get only the first font in the string */
 
243
    names = g_strsplit(name, ",", 0);
 
244
    g_free(name);
 
245
    name = g_strdup(names[0]);
 
246
    g_strfreev(names);
 
247
 
 
248
    /* don't use "normal" in the gtk string */
 
249
    if (!g_ascii_strcasecmp(weight, "normal")) {
 
250
        g_free(weight); weight = g_strdup("");
 
251
    }
 
252
    if (!g_ascii_strcasecmp(slant, "normal")) {
 
253
        g_free(slant); slant = g_strdup("");
 
254
    }
 
255
 
 
256
    fontstring = g_strdup_printf("%s %s %s %s", name, weight, slant, size);
 
257
    gtk_font_button_set_font_name(w, fontstring);
 
258
 
 
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;
 
262
 
 
263
    font = RrFontOpen(rrinst, name, atoi(size), rr_weight, rr_slant);
 
264
    g_free(fontstring);
 
265
    g_free(slant);
 
266
    g_free(weight);
 
267
    g_free(size);
 
268
    g_free(name);
 
269
 
 
270
    mapping = FALSE;
 
271
 
 
272
    return font;
 
273
}
 
274
 
 
275
static RrFont *write_font(GtkFontButton *w, const gchar *place)
 
276
{
 
277
    gchar *c;
 
278
    gchar *font, *node;
 
279
    const gchar *size = NULL;
 
280
    const gchar *bold = NULL;
 
281
    const gchar *italic = NULL;
 
282
 
 
283
    RrFontWeight weight = RR_FONTWEIGHT_NORMAL;
 
284
    RrFontSlant slant = RR_FONTSLANT_NORMAL;
 
285
 
 
286
    if (mapping) return NULL;
 
287
 
 
288
    font = g_strdup(gtk_font_button_get_font_name(w));
 
289
    while ((c = strrchr(font, ' '))) {
 
290
        if (!bold && !italic && !size && atoi(c+1))
 
291
            size = c+1;
 
292
        else if (!bold && !italic && !g_ascii_strcasecmp(c+1, "italic"))
 
293
            italic = c+1;
 
294
        else if (!bold && !g_ascii_strcasecmp(c+1, "bold"))
 
295
            bold = c+1;
 
296
        else
 
297
            break;
 
298
        *c = '\0';
 
299
    }
 
300
    if (!bold) bold = "Normal";
 
301
    if (!italic) italic = "Normal";
 
302
 
 
303
    node = g_strdup_printf("theme/font:place=%s/name", place);
 
304
    tree_set_string(node, font);
 
305
    g_free(node);
 
306
 
 
307
    node = g_strdup_printf("theme/font:place=%s/size", place);
 
308
    tree_set_string(node, size);
 
309
    g_free(node);
 
310
 
 
311
    node = g_strdup_printf("theme/font:place=%s/weight", place);
 
312
    tree_set_string(node, bold);
 
313
    g_free(node);
 
314
 
 
315
    node = g_strdup_printf("theme/font:place=%s/slant", place);
 
316
    tree_set_string(node, italic);
 
317
    g_free(node);
 
318
 
 
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;
 
322
 
 
323
    return RrFontOpen(rrinst, font, atoi(size), weight, slant);
 
324
 
 
325
    g_free(font);
 
326
 
 
327
}