chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / src / mod-trans.c
1 /*
2  * Copyright (C) 2004-2007 Jaron Omega
3  * Copyright (C) 2004-2009 Kim Woelders
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies of the Software, its documentation and marketing & publicity
14  * materials, and acknowledgment shall be given in the documentation, materials
15  * and software packages that this Software was used.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #include "E.h"
25 #include "dialog.h"
26 #include "emodule.h"
27 #include "iclass.h"
28 #include "settings.h"
29 #include "timers.h"
30
31 #ifdef ENABLE_THEME_TRANSPARENCY
32 /*
33  * Theme transparency settings
34  */
35
36 #if ENABLE_DIALOGS
37 static Timer       *st_timer = NULL;
38
39 static int
40 TransparencyChangeTimeout(void *data)
41 {
42    TransparencySet(PTR2INT(data));
43
44    st_timer = NULL;
45    return 0;
46 }
47
48 static void
49 TransparencyChange(int val)
50 {
51    TIMER_DEL(st_timer);
52    TIMER_ADD(st_timer, .01, TransparencyChangeTimeout, INT2PTR(val));
53 }
54
55 /*
56  * Configuration dialog
57  */
58 static int          tmp_theme_transparency;
59
60 static int          tmp_st_border;
61 static int          tmp_st_widget;
62 static int          tmp_st_dialog;
63 static int          tmp_st_menu;
64 static int          tmp_st_tooltip;
65 static int          tmp_st_hilight;
66
67 static void
68 CB_ConfigureTrans(Dialog * d __UNUSED__, int val, void *data __UNUSED__)
69 {
70    if (val < 2)
71      {
72         Conf.trans.border = tmp_st_border;
73         Conf.trans.widget = tmp_st_widget;
74         Conf.trans.dialog = tmp_st_dialog;
75         Conf.trans.menu = tmp_st_menu;
76         Conf.trans.tooltip = tmp_st_tooltip;
77
78         if (tmp_st_hilight == ICLASS_ATTR_GLASS)
79           {
80              Conf.trans.hilight = tmp_st_hilight;
81              Conf.trans.menu_item = ICLASS_ATTR_GLASS;
82
83           }
84         else if (tmp_st_hilight == ICLASS_ATTR_BG)
85           {
86              Conf.trans.hilight = tmp_st_hilight;
87              Conf.trans.menu_item = ICLASS_ATTR_BG;
88
89           }
90         else if (tmp_st_hilight == ICLASS_ATTR_OPAQUE)
91           {
92              Conf.trans.hilight = tmp_st_hilight;
93              Conf.trans.menu_item = ICLASS_ATTR_OPAQUE;
94
95           }
96
97         Conf.trans.pager = ICLASS_ATTR_BG;
98         Conf.trans.iconbox = ICLASS_ATTR_BG;
99         Conf.trans.warplist = ICLASS_ATTR_BG;
100 #if 0                           /* Should not be necessary */
101         TransparencyChange(tmp_theme_transparency);
102 #endif
103      }
104    autosave();
105 }
106
107 static void
108 CB_ThemeTransparency(Dialog * d __UNUSED__, int val __UNUSED__, void *data)
109 {
110    DItem              *di;
111    char                s[256];
112
113    di = (DItem *) data;
114    Esnprintf(s, sizeof(s), _("Theme transparency: %2d"),
115              tmp_theme_transparency);
116    DialogItemSetText(di, s);
117
118    TransparencyChange(tmp_theme_transparency);
119 }
120
121 static void
122 _DlgFillThemeTrans(Dialog * d __UNUSED__, DItem * table, void *data __UNUSED__)
123 {
124    DItem              *di, *label;
125    DItem              *radio_border, *radio_widget, *radio_menu,
126       *radio_dialog, *radio_tooltip, *radio_hilight;
127    char                s[256];
128
129    tmp_st_border = Conf.trans.border;
130    tmp_st_widget = Conf.trans.widget;
131    tmp_st_dialog = Conf.trans.dialog;
132    tmp_st_menu = Conf.trans.menu;
133    tmp_st_tooltip = Conf.trans.tooltip;
134    tmp_st_hilight = Conf.trans.hilight;
135
136    tmp_theme_transparency = Conf.trans.alpha;
137
138    DialogItemTableSetOptions(table, 7, 0, 0, 0);
139
140    di = DialogAddItem(table, DITEM_TEXT);
141    DialogItemSetColSpan(di, 7);
142    DialogItemSetAlign(di, 0, 512);
143    DialogItemSetText(di, _("Changes Might Require Restart:"));
144
145    di = DialogAddItem(table, DITEM_SEPARATOR);
146    DialogItemSetColSpan(di, 7);
147
148    di = DialogAddItem(table, DITEM_NONE);
149
150    di = DialogAddItem(table, DITEM_TEXT);
151    DialogItemSetAlign(di, 0, 512);
152    DialogItemSetText(di, _("Borders:"));
153
154    di = DialogAddItem(table, DITEM_TEXT);
155    DialogItemSetAlign(di, 0, 512);
156    DialogItemSetText(di, _("Menus:"));
157
158    di = DialogAddItem(table, DITEM_TEXT);
159    DialogItemSetAlign(di, 0, 512);
160    DialogItemSetText(di, _("Hilights:"));
161
162    di = DialogAddItem(table, DITEM_TEXT);
163    DialogItemSetAlign(di, 0, 512);
164    DialogItemSetText(di, _("E Widgets:"));
165
166    di = DialogAddItem(table, DITEM_TEXT);
167    DialogItemSetAlign(di, 0, 512);
168    DialogItemSetText(di, _("E Dialogs:"));
169
170    di = DialogAddItem(table, DITEM_TEXT);
171    DialogItemSetAlign(di, 0, 512);
172    DialogItemSetText(di, _("Tooltips:"));
173
174    di = DialogAddItem(table, DITEM_TEXT);
175    DialogItemSetAlign(di, 0, 1024);
176    DialogItemSetText(di, _("Opaque"));
177
178    radio_border = di = DialogAddItem(table, DITEM_RADIOBUTTON);
179    DialogItemRadioButtonSetFirst(di, radio_border);
180    DialogItemRadioButtonGroupSetVal(di, 0);
181
182    radio_menu = di = DialogAddItem(table, DITEM_RADIOBUTTON);
183    DialogItemRadioButtonSetFirst(di, radio_menu);
184    DialogItemRadioButtonGroupSetVal(di, 0);
185
186    radio_hilight = di = DialogAddItem(table, DITEM_RADIOBUTTON);
187    DialogItemRadioButtonSetFirst(di, radio_hilight);
188    DialogItemRadioButtonGroupSetVal(di, 0);
189
190    radio_widget = di = DialogAddItem(table, DITEM_RADIOBUTTON);
191    DialogItemRadioButtonSetFirst(di, radio_widget);
192    DialogItemRadioButtonGroupSetVal(di, 0);
193
194    radio_dialog = di = DialogAddItem(table, DITEM_RADIOBUTTON);
195    DialogItemRadioButtonSetFirst(di, radio_dialog);
196    DialogItemRadioButtonGroupSetVal(di, 0);
197
198    radio_tooltip = di = DialogAddItem(table, DITEM_RADIOBUTTON);
199    DialogItemRadioButtonSetFirst(di, radio_tooltip);
200    DialogItemRadioButtonGroupSetVal(di, 0);
201
202    di = DialogAddItem(table, DITEM_TEXT);
203    DialogItemSetAlign(di, 0, 1024);
204    DialogItemSetText(di, _("Background"));
205
206    di = DialogAddItem(table, DITEM_RADIOBUTTON);
207    DialogItemRadioButtonSetFirst(di, radio_border);
208    DialogItemRadioButtonGroupSetVal(di, 1);
209    DialogItemRadioButtonGroupSetValPtr(radio_border, &tmp_st_border);
210
211    di = DialogAddItem(table, DITEM_RADIOBUTTON);
212    DialogItemRadioButtonSetFirst(di, radio_menu);
213    DialogItemRadioButtonGroupSetVal(di, 1);
214
215    di = DialogAddItem(table, DITEM_RADIOBUTTON);
216    DialogItemRadioButtonSetFirst(di, radio_hilight);
217    DialogItemRadioButtonGroupSetVal(di, 1);
218
219    di = DialogAddItem(table, DITEM_RADIOBUTTON);
220    DialogItemRadioButtonSetFirst(di, radio_widget);
221    DialogItemRadioButtonGroupSetVal(di, 1);
222    DialogItemRadioButtonGroupSetValPtr(radio_widget, &tmp_st_widget);
223
224    di = DialogAddItem(table, DITEM_RADIOBUTTON);
225    DialogItemRadioButtonSetFirst(di, radio_dialog);
226    DialogItemRadioButtonGroupSetVal(di, 1);
227    DialogItemRadioButtonGroupSetValPtr(radio_dialog, &tmp_st_dialog);
228
229    di = DialogAddItem(table, DITEM_RADIOBUTTON);
230    DialogItemRadioButtonSetFirst(di, radio_tooltip);
231    DialogItemRadioButtonGroupSetVal(di, 1);
232
233    di = DialogAddItem(table, DITEM_TEXT);
234    DialogItemSetAlign(di, 0, 1024);
235    DialogItemSetText(di, _("Glass"));
236
237    di = DialogAddItem(table, DITEM_NONE);
238
239    di = DialogAddItem(table, DITEM_RADIOBUTTON);
240    DialogItemRadioButtonSetFirst(di, radio_menu);
241    DialogItemRadioButtonGroupSetVal(di, 2);
242    DialogItemRadioButtonGroupSetValPtr(radio_menu, &tmp_st_menu);
243
244    di = DialogAddItem(table, DITEM_RADIOBUTTON);
245    DialogItemRadioButtonSetFirst(di, radio_hilight);
246    DialogItemRadioButtonGroupSetVal(di, 2);
247    DialogItemRadioButtonGroupSetValPtr(radio_hilight, &tmp_st_hilight);
248
249    di = DialogAddItem(table, DITEM_NONE);
250
251    di = DialogAddItem(table, DITEM_NONE);
252
253    di = DialogAddItem(table, DITEM_RADIOBUTTON);
254    DialogItemRadioButtonSetFirst(di, radio_tooltip);
255    DialogItemRadioButtonGroupSetVal(di, 2);
256    DialogItemRadioButtonGroupSetValPtr(radio_tooltip, &tmp_st_tooltip);
257
258    di = DialogAddItem(table, DITEM_SEPARATOR);
259    DialogItemSetColSpan(di, 7);
260
261    di = label = DialogAddItem(table, DITEM_TEXT);
262    DialogItemSetColSpan(di, 7);
263    DialogItemSetAlign(di, 512, 512);
264    Esnprintf(s, sizeof(s), _("Theme transparency: %2d"),
265              tmp_theme_transparency);
266    DialogItemSetText(di, s);
267
268    di = DialogAddItem(table, DITEM_SLIDER);
269    DialogItemSetColSpan(di, 7);
270    DialogItemSliderSetMinLength(di, 10);
271    DialogItemSliderSetBounds(di, 0, 255);
272    DialogItemSliderSetUnits(di, 1);
273    DialogItemSliderSetJump(di, 16);
274    DialogItemSliderSetValPtr(di, &tmp_theme_transparency);
275    DialogItemSetCallback(di, CB_ThemeTransparency, 0, (void *)label);
276 }
277
278 const DialogDef     DlgThemeTrans = {
279    "CONFIGURE_TRANS",
280    N_("Transparency"),
281    N_("Selective Transparency Settings"),
282    SOUND_SETTINGS_TRANS,
283    "pix/tips.png",
284    N_("Enlightenment Selective Transparency\n" "Settings Dialog\n"),
285    _DlgFillThemeTrans,
286    DLG_OAC, CB_ConfigureTrans,
287 };
288 #endif /* ENABLE_DIALOGS */
289
290 static void
291 TransparencySighan(int sig, void *prm __UNUSED__)
292 {
293    switch (sig)
294      {
295      case ESIGNAL_CONFIGURE:
296         TransparencySet(Conf.trans.alpha);
297         break;
298      }
299 }
300
301 static const CfgItem TransCfgItems[] = {
302    CFG_ITEM_INT(Conf.trans, alpha, 0),
303    CFG_ITEM_INT(Conf.trans, menu, ICLASS_ATTR_BG),
304    CFG_ITEM_INT(Conf.trans, menu_item, ICLASS_ATTR_BG),
305    CFG_ITEM_INT(Conf.trans, tooltip, ICLASS_ATTR_GLASS),
306    CFG_ITEM_INT(Conf.trans, widget, ICLASS_ATTR_BG),
307    CFG_ITEM_INT(Conf.trans, hilight, ICLASS_ATTR_OPAQUE),
308    CFG_ITEM_INT(Conf.trans, border, ICLASS_ATTR_BG),
309    CFG_ITEM_INT(Conf.trans, iconbox, ICLASS_ATTR_BG),
310    CFG_ITEM_INT(Conf.trans, dialog, ICLASS_ATTR_BG),
311    CFG_ITEM_INT(Conf.trans, pager, ICLASS_ATTR_BG),
312    CFG_ITEM_INT(Conf.trans, warplist, ICLASS_ATTR_BG),
313 };
314 #define N_CFG_ITEMS (sizeof(TransCfgItems)/sizeof(CfgItem))
315
316 /*
317  * Module descriptor
318  */
319 extern const EModule ModTransparency;
320 const EModule       ModTransparency = {
321    "transparency", "tr",
322    TransparencySighan,
323    {0, NULL},
324    {N_CFG_ITEMS, TransCfgItems}
325 };
326
327 #endif /* ENABLE_THEME_TRANSPARENCY */