summaryrefslogtreecommitdiff
path: root/src/bin/e_manager.c
blob: be3d52908871846a413e1c796855a93ae7f1f772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

/* local subsystem functions */
static void _e_manager_free(E_Manager *man);

static int _e_manager_cb_window_show_request(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_configure(void *data, int ev_type, void *ev);
#if 0 /* use later - maybe */
static int _e_manager_cb_window_destroy(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_hide(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_reparent(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_create(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_configure_request(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_gravity(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_stack(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_stack_request(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_property(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_colormap(void *data, int ev_type, void *ev);
static int _e_manager_cb_window_shape(void *data, int ev_type, void *ev);
static int _e_manager_cb_client_message(void *data, int ev_type, void *ev);
#endif

/* local subsystem globals */
static Evas_List *managers = NULL;
    
/* externally accessible functions */
int
e_manager_init(void)
{
   return 1;
}

int
e_manager_shutdown(void)
{
   while (managers)
     e_object_del(E_OBJECT(managers->data));
   return 1;
}

Evas_List *
e_manager_list(void)
{
   return managers;
}

E_Manager *
e_manager_new(Ecore_X_Window root)
{
   E_Manager *man;
   Ecore_Event_Handler *h;

   if (!ecore_x_window_manage(root)) return NULL;
   man = E_OBJECT_ALLOC(E_Manager, E_MANAGER_TYPE, _e_manager_free);
   if (!man) return NULL;
   managers = evas_list_append(managers, man);
   man->root = root;
   ecore_x_window_size_get(man->root, &(man->w), &(man->h));
   man->win = ecore_x_window_override_new(man->root, man->x, man->y, man->w, man->h);
   ecore_x_icccm_title_set(man->win, "Enlightenment Manager");
   h = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_SHOW_REQUEST, _e_manager_cb_window_show_request, man);
   if (h) man->handlers = evas_list_append(man->handlers, h);
   h = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_CONFIGURE, _e_manager_cb_window_configure, man);
   if (h) man->handlers = evas_list_append(man->handlers, h);
   return man;
}

void
e_manager_manage_windows(E_Manager *man)
{
   /* FIXME: move this to an actual function to start managing */
   Ecore_X_Window *windows;
   int wnum;

   windows = ecore_x_window_children_get(man->root, &wnum);
   if (windows)
     {
	int i;

	for (i = 0; i < wnum; i++)
	  {
	     Ecore_X_Window_Attributes att;
	     unsigned int ret_val, deskxy[2];
	     int ret;

	     ecore_x_window_attributes_get(windows[i], &att);
	     ret = ecore_x_window_prop_card32_get(windows[i],
						  E_ATOM_MANAGED,
						  &ret_val, 1);

	     /* we have seen this window before */
	     if ((ret > -1) && (ret_val == 1))
	       {
		  E_Container *con = NULL;
		  E_Zone      *zone = NULL;
		  E_Desk      *desk = NULL;
		  E_Border    *bd = NULL;
		  int          id;

		  /* get all information from window before it is 
		   * reset by e_border_new */
		  ret = ecore_x_window_prop_card32_get(windows[i],
						       E_ATOM_CONTAINER,
						       &id, 1);
		  if (ret == 1)
		    con = e_manager_container_number_get(man, id);
		  else
		    con = e_manager_container_current_get(man);

		  ret = ecore_x_window_prop_card32_get(windows[i],
						       E_ATOM_ZONE,
						       &id, 1);
		  if (ret == 1)
		    zone = e_container_zone_number_get(con, id);
		  else
		    zone = e_zone_current_get(con);

		  ret = ecore_x_window_prop_card32_get(windows[i],
						       E_ATOM_DESK,
						       deskxy, 2);
		  if (ret == 2)
		    desk = e_desk_at_xy_get(zone,
					    deskxy[0],
					    deskxy[1]);

		  bd = e_border_new(con, windows[i], 1);
		  if (bd)
		    {
		       /* FIXME:
			* It's enough to set the desk, the zone will
			* be set according to the desk */
		       if (zone)
			 e_border_zone_set(bd, zone);

		       if (desk)
			 e_border_desk_set(bd, desk);
		    }
	       }
	     else if ((att.visible) && (!att.override) &&
		      (!att.input_only))
	       {
		  /* We have not seen this window, and X tells us it
		   * should be seen */
		  E_Container *con;
		  E_Border *bd;
		  con = e_manager_container_current_get(man);
		  bd = e_border_new(con, windows[i], 1);
		  if (bd)
		    e_border_show(bd);
	       }
	  }
     }
}

void
e_manager_show(E_Manager *man)
{
   E_OBJECT_CHECK(man);
   E_OBJECT_TYPE_CHECK(man, E_MANAGER_TYPE);
   if (man->visible) return;
   ecore_x_window_show(man->win);
   ecore_x_window_focus(man->win);
   e_init_show();
   man->visible = 1;
}

void
e_manager_hide(E_Manager *man)
{
   E_OBJECT_CHECK(man);
   E_OBJECT_TYPE_CHECK(man, E_MANAGER_TYPE);
   if (!man->visible) return;
   ecore_x_window_hide(man->win);
   man->visible = 0; 
}

void
e_manager_move(E_Manager *man, int x, int y)
{
   E_OBJECT_CHECK(man);
   E_OBJECT_TYPE_CHECK(man, E_MANAGER_TYPE);
   if ((x == man->x) && (y == man->y)) return;
   man->x = x;
   man->y = y;
   ecore_x_window_move(man->win, man->x, man->y);
}

void
e_manager_resize(E_Manager *man, int w, int h)
{
   Evas_List *l;
   
   E_OBJECT_CHECK(man);
   E_OBJECT_TYPE_CHECK(man, E_MANAGER_TYPE);
   if ((w == man->w) && (h == man->h)) return;
   man->w = w;
   man->h = h;
   ecore_x_window_resize(man->win, man->w, man->h);
	
   for (l = man->containers; l; l = l->next)
     {
	E_Container *con;
	
	con = l->data;
	e_container_resize(con, man->w, man->h);
     }
}

void
e_manager_move_resize(E_Manager *man, int x, int y, int w, int h)
{
   Evas_List *l;
   
   E_OBJECT_CHECK(man);
   E_OBJECT_TYPE_CHECK(man, E_MANAGER_TYPE);
   if ((x == man->x) && (y == man->y) && (w == man->w) && (h == man->h)) return;
   man->x = x;
   man->y = y;
   man->w = w;
   man->h = h;
   ecore_x_window_move_resize(man->win, man->x, man->y, man->w, man->h);

   for (l = man->containers; l; l = l->next)
     {
	E_Container *con;
	
	con = l->data;
	e_container_resize(con, man->w, man->h);
     }
}

void
e_manager_raise(E_Manager *man)
{
   E_OBJECT_CHECK(man);
   E_OBJECT_TYPE_CHECK(man, E_MANAGER_TYPE);
   ecore_x_window_raise(man->win);
   e_init_show();
}

void
e_manager_lower(E_Manager *man)
{
   E_OBJECT_CHECK(man);
   E_OBJECT_TYPE_CHECK(man, E_MANAGER_TYPE);
   ecore_x_window_lower(man->win);
}

E_Container *
e_manager_container_current_get(E_Manager *man)
{
   /* FIXME
    * Currently only one container, but...
    */
   E_OBJECT_CHECK_RETURN(man, NULL);
   E_OBJECT_TYPE_CHECK_RETURN(man, E_MANAGER_TYPE, NULL);

   return (E_Container *)man->containers->data;
}

E_Container *
e_manager_container_number_get(E_Manager *man, int num)
{
   Evas_List *l;

   E_OBJECT_CHECK_RETURN(man, NULL);
   E_OBJECT_TYPE_CHECK_RETURN(man, E_MANAGER_TYPE, NULL);
   for (l = man->containers; l; l = l->next)
     {
	E_Container *con;
	
	con = l->data;
	if (con->num == num)
	  return con;
     }
   return NULL;
}

/* local subsystem functions */
static void
_e_manager_free(E_Manager *man)
{
   while (man->handlers)
     {
	Ecore_Event_Handler *h;
   
	h = man->handlers->data;
	man->handlers = evas_list_remove_list(man->handlers, man->handlers);
	ecore_event_handler_del(h);
     }
   while (man->containers)
     e_object_del(E_OBJECT(man->containers->data));
   ecore_x_window_del(man->win);
   managers = evas_list_remove(managers, man);   
   free(man);
}

static int
_e_manager_cb_window_show_request(void *data, int ev_type, void *ev)
{
   E_Manager *man;
   Ecore_X_Event_Window_Show_Request *e;
   
   man = data;
   e = ev;
   if (e->parent != man->root) return 1; /* try other handlers for this */
   
     {
	E_Container *con;
	E_Border *bd;
	
	con = e_container_current_get(man);
	if (!e_border_find_by_client_window(e->win))
	  {
	     bd = e_border_new(con, e->win, 0);
	     if (bd)
	       {
		  e_border_raise(bd);
		  e_border_show(bd);
	       }
	     else ecore_x_window_show(e->win);
	  }
     }
   return 1;
}

static int
_e_manager_cb_window_configure(void *data, int ev_type, void *ev)
{
   E_Manager *man;
   Ecore_X_Event_Window_Configure *e;
   
   man = data;
   e = ev;
   if (e->win != man->root) return 1;
   e_manager_resize(man, e->w, e->h);
   return 1;
}

#if 0 /* use later - maybe */
static int _e_manager_cb_window_destroy(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_hide(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_reparent(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_create(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_configure_request(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_configure(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_gravity(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_stack(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_stack_request(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_property(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_colormap(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_window_shape(void *data, int ev_type, void *ev){return 1;}
static int _e_manager_cb_client_message(void *data, int ev_type, void *ev){return 1;}
#endif