add opaque move/resize to the rc3
[mikachu/openbox.git] / openbox / config.c
1 #include "config.h"
2 #include "parse.h"
3
4 gboolean config_focus_new;
5 gboolean config_focus_follow;
6 gboolean config_focus_last;
7 gboolean config_focus_last_on_desktop;
8 gboolean config_focus_popup;
9
10 char *config_theme;
11
12 int config_desktops_num;
13 GSList *config_desktops_names;
14
15 gboolean config_opaque_move;
16 gboolean config_opaque_resize;
17
18 static void parse_focus(char *name, ParseToken *value)
19 {
20     if (!g_ascii_strcasecmp(name, "focusnew")) {
21         if (value->type != TOKEN_BOOL)
22             yyerror("invalid value");
23         else {
24             config_focus_new = value->data.bool;
25         }
26     } else if (!g_ascii_strcasecmp(name, "followmouse")) {
27         if (value->type != TOKEN_BOOL)
28             yyerror("invalid value");
29         else {
30             config_focus_follow = value->data.bool;
31         }
32     } else if (!g_ascii_strcasecmp(name, "focuslast")) {
33         if (value->type != TOKEN_BOOL)
34             yyerror("invalid value");
35         else {
36             config_focus_last = value->data.bool;
37         }
38     } else if (!g_ascii_strcasecmp(name, "focuslastondesktop")) {
39         if (value->type != TOKEN_BOOL)
40             yyerror("invalid value");
41         else {
42             config_focus_last_on_desktop = value->data.bool;
43         }
44     } else if (!g_ascii_strcasecmp(name, "cyclingdialog")) {
45         if (value->type != TOKEN_BOOL)
46             yyerror("invalid value");
47         else {
48             config_focus_popup = value->data.bool;
49         }
50     } else
51         yyerror("invalid option");
52     parse_free_token(value);
53 }
54
55 static void parse_theme(char *name, ParseToken *value)
56 {
57     if (!g_ascii_strcasecmp(name, "theme")) {
58         if (value->type != TOKEN_STRING)
59             yyerror("invalid value");
60         else {
61             g_free(config_theme);
62             config_theme = g_strdup(value->data.string);
63         }
64     } else
65         yyerror("invalid option");
66     parse_free_token(value);
67 }
68
69 static void parse_desktops(char *name, ParseToken *value)
70 {
71     GList *it;
72
73     if (!g_ascii_strcasecmp(name, "number")) {
74         if (value->type != TOKEN_INTEGER)
75             yyerror("invalid value");
76         else {
77             config_desktops_num = value->data.integer;
78         }
79     } else if (!g_ascii_strcasecmp(name, "names")) {
80         if (value->type == TOKEN_LIST) {
81             for (it = value->data.list; it; it = it->next)
82                 if (((ParseToken*)it->data)->type != TOKEN_STRING) break;
83             if (it == NULL) {
84                 /* build a string list */
85                 g_free(config_desktops_names);
86                 for (it = value->data.list; it; it = it->next)
87                     config_desktops_names =
88                         g_slist_append(config_desktops_names,
89                                        g_strdup
90                                        (((ParseToken*)it->data)->data.string));
91             } else {
92                 yyerror("invalid string in names list");
93             }
94         } else {
95             yyerror("syntax error (expected list of strings)");
96         }
97     } else
98         yyerror("invalid option");
99     parse_free_token(value);
100 }
101
102 static void parse_moveresize(char *name, ParseToken *value)
103 {
104     if (!g_ascii_strcasecmp(name, "opaque_move")) {
105         if (value->type != TOKEN_BOOL)
106             yyerror("invalid value");
107         else {
108             config_opaque_move = value->data.integer;
109         }
110     } else if (!g_ascii_strcasecmp(name, "opaque_resize")) {
111         if (value->type != TOKEN_BOOL)
112             yyerror("invalid value");
113         else {
114             config_opaque_resize = value->data.integer;
115         }
116     } else
117         yyerror("invalid option");
118     parse_free_token(value);
119 }
120
121 void config_startup()
122 {
123     config_focus_new = TRUE;
124     config_focus_follow = FALSE;
125     config_focus_last = TRUE;
126     config_focus_last_on_desktop = TRUE;
127     config_focus_popup = TRUE;
128
129     parse_reg_section("focus", NULL, parse_focus);
130
131     config_theme = NULL;
132
133     parse_reg_section("theme", NULL, parse_theme);
134
135     config_desktops_num = 4;
136     config_desktops_names = NULL;
137
138     parse_reg_section("desktops", NULL, parse_desktops);
139
140     config_opaque_move = TRUE;
141     config_opaque_resize = TRUE;
142
143     parse_reg_section("moveresize", NULL, parse_moveresize);
144 }
145
146 void config_shutdown()
147 {
148     GSList *it;
149
150     g_free(config_theme);
151
152     for (it = config_desktops_names; it; it = it->next)
153         g_free(it->data);
154     g_slist_free(config_desktops_names);
155 }