summaryrefslogtreecommitdiff
path: root/src/bin/e_win.c
blob: 2d609608a590c38fe07a291293bd9a8f79ed59f3 (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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
#include "e.h"

/* local subsystem functions */
static void _e_win_free(E_Win *win);
static void _e_win_del(void *obj);
static void _e_win_prop_update(E_Win *win);
static void _e_win_state_update(E_Win *win);
static void _e_win_cb_move(Ecore_Evas *ee);
static void _e_win_cb_resize(Ecore_Evas *ee);
static void _e_win_cb_delete(Ecore_Evas *ee);

/* local subsystem globals */
static Eina_List *wins = NULL;

/* externally accessible functions */
EINTERN int
e_win_init(void)
{
   return 1;
}

EINTERN int
e_win_shutdown(void)
{
/*   
   while (wins)
     {
	e_object_del(E_OBJECT(wins->data));
     }
*/
   return 1;
}

EAPI E_Win *
e_win_new(E_Container *con)
{
   E_Win *win;
   Evas_Object *obj;
   
   win = E_OBJECT_ALLOC(E_Win, E_WIN_TYPE, _e_win_free);
   if (!win) return NULL;
   e_object_del_func_set(E_OBJECT(win), _e_win_del);
   win->container = con;
   win->ecore_evas = e_canvas_new(con->manager->root,
				  0, 0, 1, 1, 1, 0,
				  &(win->evas_win));
   e_canvas_add(win->ecore_evas);
   ecore_evas_data_set(win->ecore_evas, "E_Win", win);
   ecore_evas_callback_move_set(win->ecore_evas, _e_win_cb_move);
   ecore_evas_callback_resize_set(win->ecore_evas, _e_win_cb_resize);
   ecore_evas_callback_delete_request_set(win->ecore_evas, _e_win_cb_delete);
   win->evas = ecore_evas_get(win->ecore_evas);
   ecore_evas_name_class_set(win->ecore_evas, "E", "_e_internal_window");
   ecore_evas_title_set(win->ecore_evas, "E");
   obj = evas_object_rectangle_add(win->evas);
   evas_object_name_set(obj, "E_Win");
   evas_object_data_set(obj, "E_Win", win);
   win->x = 0;
   win->y = 0;
   win->w = 1;
   win->h = 1;
   win->placed = 0;
   win->min_w = 0;
   win->min_h = 0;
   win->max_w = 9999;
   win->max_h = 9999;
   win->base_w = 0;
   win->base_h = 0;
   win->step_x = 1;
   win->step_y = 1;
   win->min_aspect = 0.0;
   win->max_aspect = 0.0;
   wins = eina_list_append(wins, win);
   
   win->pointer = e_pointer_window_new(win->evas_win, 0);
   return win;
}

EAPI void
e_win_show(E_Win *win)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if (!win->border)
     {
	_e_win_prop_update(win);
	ecore_evas_lower(win->ecore_evas);
	win->border = e_border_new(win->container, win->evas_win, 1, 1);
// dont need this - special stuff        
//        win->border->ignore_first_unmap = 1;
	if (!win->placed)
	  win->border->re_manage = 0;
	win->border->internal = 1;
	win->border->internal_ecore_evas = win->ecore_evas;
	if (win->state.no_remember) win->border->internal_no_remember = 1;
     }
   _e_win_prop_update(win);
   e_border_show(win->border);
// done now by e_border specially   
//   ecore_evas_show(win->ecore_evas);
}

EAPI void
e_win_hide(E_Win *win)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if (win->border) e_border_hide(win->border, 1);
}

/**
 * This will move window to position, automatically accounts border decorations.
 *
 * Don't need to account win->border->client_inset, it's done
 * automatically, so it will work fine with new windows that still
 * don't have the border.
 *
 * @parm x horizontal position to place window.
 * @parm y vertical position to place window.
 */
EAPI void
e_win_move(E_Win *win, int x, int y)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if (win->border)
     e_border_move_without_border(win->border, x, y);
   else
     ecore_evas_move(win->ecore_evas, x, y);
}

/**
 * This will resize window, automatically accounts border decorations.
 *
 * Don't need to account win->border->client_inset, it's done
 * automatically, so it will work fine with new windows that still
 * don't have the border.
 *
 * @parm w horizontal window size.
 * @parm h vertical window size.
 */
EAPI void
e_win_resize(E_Win *win, int w, int h)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if (win->border)
     e_border_resize_without_border(win->border, w, h);
   else
     ecore_evas_resize(win->ecore_evas, w, h);
}

/**
 * This will move and resize window to position, automatically
 * accounts border decorations.
 *
 * Don't need to account win->border->client_inset, it's done
 * automatically, so it will work fine with new windows that still
 * don't have the border.
 *
 * @parm x horizontal position to place window.
 * @parm y vertical position to place window.
 * @parm w horizontal window size.
 * @parm h vertical window size.
 */
EAPI void
e_win_move_resize(E_Win *win, int x, int y, int w, int h)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if (win->border)
     e_border_move_resize_without_border(win->border, x, y, w, h);
   else
     ecore_evas_move_resize(win->ecore_evas, x, y, w, h);
}

EAPI void
e_win_raise(E_Win *win)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if (win->border)
     e_border_raise(win->border);
}

EAPI void
e_win_lower(E_Win *win)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if (win->border)
     e_border_lower(win->border);
}

EAPI void
e_win_placed_set(E_Win *win, int placed)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->placed = placed;
   if (win->border)
     _e_win_prop_update(win);
}

EAPI Evas *
e_win_evas_get(E_Win *win)
{
   E_OBJECT_CHECK_RETURN(win, NULL);
   E_OBJECT_TYPE_CHECK_RETURN(win, E_WIN_TYPE, NULL);
   return win->evas;
}

EAPI void
e_win_move_callback_set(E_Win *win, void (*func) (E_Win *win))
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->cb_move = func;
}

EAPI void
e_win_resize_callback_set(E_Win *win, void (*func) (E_Win *win))
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->cb_resize = func;
}

EAPI void
e_win_delete_callback_set(E_Win *win, void (*func) (E_Win *win))
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->cb_delete = func;
}

EAPI void
e_win_shaped_set(E_Win *win, int shaped)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   ecore_evas_shaped_set(win->ecore_evas, shaped);
}

EAPI void
e_win_avoid_damage_set(E_Win *win, int avoid)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   ecore_evas_avoid_damage_set(win->ecore_evas, avoid);
}

EAPI void
e_win_borderless_set(E_Win *win, int borderless)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   ecore_evas_borderless_set(win->ecore_evas, borderless);
}

EAPI void
e_win_layer_set(E_Win *win, int layer)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   ecore_evas_layer_set(win->ecore_evas, layer);
}

EAPI void
e_win_sticky_set(E_Win *win, int sticky)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   ecore_evas_sticky_set(win->ecore_evas, sticky);
}

EAPI void
e_win_size_min_set(E_Win *win, int w, int h)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->min_w = w;
   win->min_h = h;   
   if (win->border)
     _e_win_prop_update(win);
}

EAPI void
e_win_size_max_set(E_Win *win, int w, int h)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->max_w = w;
   win->max_h = h;   
   if (win->border)
     _e_win_prop_update(win);
}

EAPI void
e_win_size_base_set(E_Win *win, int w, int h)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->base_w = w;
   win->base_h = h;   
   if (win->border)
     _e_win_prop_update(win);
}

EAPI void
e_win_step_set(E_Win *win, int x, int y)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->step_x = x;
   win->step_y = y;
   if (win->border)
     _e_win_prop_update(win);
}

EAPI void
e_win_name_class_set(E_Win *win, const char *name, const char *class)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   ecore_evas_name_class_set(win->ecore_evas, name, class);
}

EAPI void
e_win_title_set(E_Win *win, const char *title)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   ecore_evas_title_set(win->ecore_evas, title);
}

EAPI void
e_win_centered_set(E_Win *win, int centered)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if ((win->state.centered) && (!centered))
     {
	win->state.centered = 0;
	_e_win_state_update(win);
     }
   else if ((!win->state.centered) && (centered))
     {
	win->state.centered = 1;
	_e_win_state_update(win);
     }
   if ((win->border) && (centered))
     e_border_center(win->border);
}

EAPI void
e_win_dialog_set(E_Win *win, int dialog)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   if ((win->state.dialog) && (!dialog))
     {
	win->state.dialog = 0;
	_e_win_prop_update(win);
     }
   else if ((!win->state.dialog) && (dialog))
     {
	win->state.dialog = 1;
	_e_win_prop_update(win);
     }
}

EAPI void
e_win_no_remember_set(E_Win *win, int no_remember)
{
   E_OBJECT_CHECK(win);
   E_OBJECT_TYPE_CHECK(win, E_WIN_TYPE);
   win->state.no_remember = no_remember;
}

EAPI E_Win *
e_win_evas_object_win_get(Evas_Object *obj)
{
   Evas *evas;
   Evas_Object *wobj;
   E_Win *win;
   
   if (!obj) return NULL;
   evas = evas_object_evas_get(obj);
   wobj = evas_object_name_find(evas, "E_Win");
   if (!wobj) return NULL;
   win = evas_object_data_get(wobj, "E_Win");
   return win;
}

EAPI void 
e_win_border_icon_set(E_Win *win, const char *icon) 
{
   E_Border *border;
   
   border = win->border;
   if (!border) return;
   if (border->internal_icon)
     {
	eina_stringshare_del(border->internal_icon);
	border->internal_icon = NULL;
     }
   if (icon)
     border->internal_icon = eina_stringshare_add(icon);
}

EAPI void 
e_win_border_icon_key_set(E_Win *win, const char *key) 
{
   E_Border *border;
   
   border = win->border;
   if (!border) return;
   if (border->internal_icon_key) 
     {
	eina_stringshare_del(border->internal_icon_key);
	border->internal_icon_key = NULL;
     }
   if (key)
     border->internal_icon_key = eina_stringshare_add(key);
}

/* local subsystem functions */
static void
_e_win_free(E_Win *win)
{
   if (win->pointer)
     e_object_del(E_OBJECT(win->pointer));

   e_canvas_del(win->ecore_evas);
   ecore_evas_free(win->ecore_evas);
   if (win->border)
     {
	e_border_hide(win->border, 1);
	e_object_del(E_OBJECT(win->border));
     }
   wins = eina_list_remove(wins, win);
   free(win);
}

static void
_e_win_del(void *obj)
{
   E_Win *win;
   
   win = obj;
   if (win->border) e_border_hide(win->border, 1);
}

static void
_e_win_prop_update(E_Win *win)
{
   ecore_x_icccm_size_pos_hints_set(win->evas_win,
				    win->placed, ECORE_X_GRAVITY_NW,
				    win->min_w, win->min_h,
				    win->max_w, win->max_h,
				    win->base_w, win->base_h,
				    win->step_x, win->step_y,
				    win->min_aspect, win->max_aspect);
   if (win->state.dialog)
     {
	ecore_x_icccm_transient_for_set(win->evas_win, win->container->manager->root);
	ecore_x_netwm_window_type_set(win->evas_win, ECORE_X_WINDOW_TYPE_DIALOG);
     }
   else
     {
	ecore_x_icccm_transient_for_unset(win->evas_win);
	ecore_x_netwm_window_type_set(win->evas_win, ECORE_X_WINDOW_TYPE_NORMAL);
     }
}

static void
_e_win_state_update(E_Win *win)
{
   Ecore_X_Atom state[1];
   int num = 0;

   if (win->state.centered)
     state[num++] = E_ATOM_WINDOW_STATE_CENTERED;

   if (num)
     ecore_x_window_prop_card32_set(win->evas_win, E_ATOM_WINDOW_STATE, state, num);
   else
     ecore_x_window_prop_property_del(win->evas_win, E_ATOM_WINDOW_STATE);
}

static void
_e_win_cb_move(Ecore_Evas *ee)
{
   E_Win *win;
   
   win = ecore_evas_data_get(ee, "E_Win");
   if (!win) return;
   ecore_evas_geometry_get(win->ecore_evas, &win->x, &win->y, &win->w, &win->h);   
   if (win->cb_move) win->cb_move(win);
}

static void
_e_win_cb_resize(Ecore_Evas *ee)
{
   E_Win *win;
   
   win = ecore_evas_data_get(ee, "E_Win");
   if (!win) return;
   ecore_evas_geometry_get(win->ecore_evas, &win->x, &win->y, &win->w, &win->h);
   if (win->cb_resize) win->cb_resize(win);
}

static void
_e_win_cb_delete(Ecore_Evas *ee)
{
   E_Win *win;
   
   win = ecore_evas_data_get(ee, "E_Win");
   if (!win) return;
   if (win->cb_delete) win->cb_delete(win);
}