9958953b14aafd18824b6b8cf8433f7a3ed442a1
[framework/uifw/e17.git] / src / modules / illume2 / e_mod_select_window.c
1 #include "e_illume_private.h"
2 #include "e_mod_select_window.h"
3
4 /* local function prototypes */
5 static void *_e_mod_illume_config_select_window_create_data(E_Config_Dialog *cfd);
6 static void _e_mod_illume_config_select_window_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
7 static Evas_Object *_e_mod_illume_config_select_window_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
8 static void _e_mod_illume_config_select_window_list_changed(void *data);
9 static Eina_Bool _e_mod_illume_config_select_window_change_timeout(void *data);
10 static int _e_mod_illume_config_select_window_match(E_Border *bd);
11
12 /* local variables */
13 E_Illume_Select_Window_Type stype;
14 Ecore_Timer *_sw_change_timer = NULL;
15
16 /* public functions */
17 void 
18 e_mod_illume_config_select_window(E_Illume_Select_Window_Type type) 
19 {
20    E_Config_Dialog *cfd;
21    E_Config_Dialog_View *v;
22
23    if (e_config_dialog_find("E", "_config_illume_select_window")) return;
24
25    v = E_NEW(E_Config_Dialog_View, 1);
26    if (!v) return;
27
28    stype = type;
29    v->create_cfdata = _e_mod_illume_config_select_window_create_data;
30    v->free_cfdata = _e_mod_illume_config_select_window_free_data;
31    v->basic.create_widgets = _e_mod_illume_config_select_window_create;
32    v->basic_only = 1;
33    v->normal_win = 1;
34    v->scroll = 1;
35    cfd = e_config_dialog_new(e_container_current_get(e_manager_current_get()), 
36                              _("Select Home Window"), "E", 
37                              "_config_illume_select_window", 
38                              "enlightenment/windows", 0, v, NULL);
39    if (!cfd) return;
40    e_dialog_resizable_set(cfd->dia, 1);
41 }
42
43 static void *
44 _e_mod_illume_config_select_window_create_data(E_Config_Dialog *cfd __UNUSED__) 
45 {
46    return NULL;
47 }
48
49 static void 
50 _e_mod_illume_config_select_window_free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata __UNUSED__) 
51 {
52    if (_sw_change_timer) ecore_timer_del(_sw_change_timer);
53    _sw_change_timer = NULL;
54 }
55
56 static Evas_Object *
57 _e_mod_illume_config_select_window_create(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata __UNUSED__) 
58 {
59    Evas_Object *list, *ow;
60    Eina_List *bds, *l;
61    E_Zone *zone;
62    int i, sel = -1;
63
64    zone = e_util_zone_current_get(e_manager_current_get());
65    list = e_widget_list_add(evas, 0, 0);
66    ow = e_widget_ilist_add(evas, 24, 24, NULL);
67    e_widget_ilist_selector_set(ow, 1);
68    evas_event_freeze(evas);
69    edje_freeze();
70    e_widget_ilist_freeze(ow);
71    e_widget_ilist_clear(ow);
72    e_widget_ilist_go(ow);
73
74    if ((bds = e_border_client_list()))
75      {
76         for (i = 0, l = bds; l; l = l->next, i++) 
77           {
78              E_Border *bd;
79              const char *name;
80
81              if (!(bd = l->data)) continue;
82              if (bd->zone != zone) continue;
83              if (e_object_is_del(E_OBJECT(bd))) continue;
84              if (!(name = e_border_name_get(bd))) continue;
85              if (_e_mod_illume_config_select_window_match(bd)) sel = i;
86              e_widget_ilist_append(ow, NULL, name, 
87                                    _e_mod_illume_config_select_window_list_changed, 
88                                    bd, name);
89           }
90      }
91
92    e_widget_size_min_set(ow, 100, 200);
93    e_widget_ilist_go(ow);
94    if (sel >= 0) e_widget_ilist_selected_set(ow, sel);
95    e_widget_ilist_thaw(ow);
96    edje_thaw();
97    evas_event_thaw(evas);
98    e_widget_list_object_append(list, ow, 1, 0, 0.0);
99    return list;
100 }
101
102 static void 
103 _e_mod_illume_config_select_window_list_changed(void *data) 
104 {
105    E_Border *bd;
106    Ecore_X_Window_Type wtype;
107    char *title, *name, *class;
108
109    if (!(bd = data)) return;
110    title = ecore_x_icccm_title_get(bd->client.win);
111    ecore_x_icccm_name_class_get(bd->client.win, &name, &class);
112    ecore_x_netwm_window_type_get(bd->client.win, &wtype);
113
114    switch (stype) 
115      {
116       case E_ILLUME_SELECT_WINDOW_TYPE_HOME:
117         eina_stringshare_replace(&_e_illume_cfg->policy.home.title, title);
118         eina_stringshare_replace(&_e_illume_cfg->policy.home.class, class);
119         eina_stringshare_replace(&_e_illume_cfg->policy.home.name, name);
120         break;
121       case E_ILLUME_SELECT_WINDOW_TYPE_VKBD:
122         eina_stringshare_replace(&_e_illume_cfg->policy.vkbd.title, title);
123         eina_stringshare_replace(&_e_illume_cfg->policy.vkbd.class, class);
124         eina_stringshare_replace(&_e_illume_cfg->policy.vkbd.name, name);
125         break;
126       case E_ILLUME_SELECT_WINDOW_TYPE_SOFTKEY:
127         eina_stringshare_replace(&_e_illume_cfg->policy.softkey.title, title);
128         eina_stringshare_replace(&_e_illume_cfg->policy.softkey.class, class);
129         eina_stringshare_replace(&_e_illume_cfg->policy.softkey.name, name);
130         break;
131       case E_ILLUME_SELECT_WINDOW_TYPE_INDICATOR:
132         eina_stringshare_replace(&_e_illume_cfg->policy.indicator.title, title);
133         eina_stringshare_replace(&_e_illume_cfg->policy.indicator.class, class);
134         eina_stringshare_replace(&_e_illume_cfg->policy.indicator.name, name);
135         break;
136      }
137
138    if (title) free(title);
139    if (name) free(name);
140    if (class) free(class);
141
142    if (_sw_change_timer) ecore_timer_del(_sw_change_timer);
143    _sw_change_timer = 
144      ecore_timer_add(0.5, _e_mod_illume_config_select_window_change_timeout, data);
145 }
146
147 static Eina_Bool
148 _e_mod_illume_config_select_window_change_timeout(__UNUSED__ void *data)
149 {
150    e_config_save_queue();
151    _sw_change_timer = NULL;
152    return ECORE_CALLBACK_CANCEL;
153 }
154
155 static int 
156 _e_mod_illume_config_select_window_match(E_Border *bd) 
157 {
158    Ecore_X_Window_Type wtype;
159    char *title, *name, *class;
160    int match = 0;
161
162    if (!bd) return 0;
163    title = ecore_x_icccm_title_get(bd->client.win);
164    ecore_x_icccm_name_class_get(bd->client.win, &name, &class);
165    ecore_x_netwm_window_type_get(bd->client.win, &wtype);
166
167    switch (stype) 
168      {
169       case E_ILLUME_SELECT_WINDOW_TYPE_HOME:
170         if (_e_illume_cfg->policy.home.match.title) 
171           {
172              if ((title) && (!strcmp(title, _e_illume_cfg->policy.home.title)))
173                match = 1;
174           }
175         if (_e_illume_cfg->policy.home.match.name) 
176           {
177              if ((name) && (!strcmp(name, _e_illume_cfg->policy.home.name)))
178                match = 1;
179           }
180         if (_e_illume_cfg->policy.home.match.class) 
181           {
182              if ((class) && (!strcmp(class, _e_illume_cfg->policy.home.class)))
183                match = 1;
184           }
185         break;
186       case E_ILLUME_SELECT_WINDOW_TYPE_VKBD:
187         if (_e_illume_cfg->policy.vkbd.match.title) 
188           {
189              if ((title) && (!strcmp(title, _e_illume_cfg->policy.vkbd.title)))
190                match = 1;
191           }
192         if (_e_illume_cfg->policy.vkbd.match.name) 
193           {
194              if ((name) && (!strcmp(name, _e_illume_cfg->policy.vkbd.name)))
195                match = 1;
196           }
197         if (_e_illume_cfg->policy.vkbd.match.class) 
198           {
199              if ((class) && (!strcmp(class, _e_illume_cfg->policy.vkbd.class)))
200                match = 1;
201           }
202         break;
203       case E_ILLUME_SELECT_WINDOW_TYPE_SOFTKEY:
204         if (_e_illume_cfg->policy.softkey.match.title) 
205           {
206              if ((title) && (!strcmp(title, _e_illume_cfg->policy.softkey.title)))
207                match = 1;
208           }
209         if (_e_illume_cfg->policy.softkey.match.name) 
210           {
211              if ((name) && (!strcmp(name, _e_illume_cfg->policy.softkey.name)))
212                match = 1;
213           }
214         if (_e_illume_cfg->policy.softkey.match.class) 
215           {
216              if ((class) && (!strcmp(class, _e_illume_cfg->policy.softkey.class)))
217                match = 1;
218           }
219         break;
220       case E_ILLUME_SELECT_WINDOW_TYPE_INDICATOR:
221         if (_e_illume_cfg->policy.indicator.match.title) 
222           {
223              if ((title) && (!strcmp(title, _e_illume_cfg->policy.indicator.title)))
224                match = 1;
225           }
226         if (_e_illume_cfg->policy.indicator.match.name) 
227           {
228              if ((name) && (!strcmp(name, _e_illume_cfg->policy.indicator.name)))
229                match = 1;
230           }
231         if (_e_illume_cfg->policy.indicator.match.class) 
232           {
233              if ((class) && (!strcmp(class, _e_illume_cfg->policy.indicator.class)))
234                match = 1;
235           }
236         break;
237      }
238
239    if (title) free(title);
240    if (name) free(name);
241    if (class) free(class);
242
243    return match;
244 }