aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/elementary/src/lib/elm_win.c
blob: bbabccdfb623b23d5fcf1cdf5e2b2d1b53d020e7 (plain) (blame)
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
523
524
525
526
527
528
529
530
531
#include <Elementary.h>
#include "elm_priv.h"

typedef struct _Elm_Win Elm_Win;

struct _Elm_Win
{
   Ecore_Evas     *ee;
   Evas           *evas;
   Evas_Object    *parent;
   Evas_Object    *win_obj;
   Eina_List      *subobjs;
   Ecore_X_Window  xwin;
   Ecore_Job      *deferred_resize_job;
   Ecore_Job      *deferred_child_eval_job;
   Elm_Win_Type    type;
   Evas_Bool       autodel : 1;
};

static void _elm_win_resize(Ecore_Evas *ee);
static void _elm_win_obj_intercept_show(void *data, Evas_Object *obj);
static void _elm_win_obj_intercept_hide(void *data, Evas_Object *obj);
static void _elm_win_obj_intercept_move(void *data, Evas_Object *obj, Evas_Coord x, Evas_Coord y);
static void _elm_win_obj_intercept_resize(void *data, Evas_Object *obj, Evas_Coord w, Evas_Coord h);
static void _elm_win_obj_intercept_raise(void *data, Evas_Object *obj);
static void _elm_win_obj_intercept_lower(void *data, Evas_Object *obj);
static void _elm_win_obj_intercept_stack_above(void *data, Evas_Object *obj, Evas_Object *above);
static void _elm_win_obj_intercept_stack_below(void *data, Evas_Object *obj, Evas_Object *below);
static void _elm_win_obj_intercept_layer_set(void *data, Evas_Object *obj, int l);
static void _elm_win_obj_intercept_color_set(void *data, Evas_Object *obj, int r, int g, int b, int a);
static void _elm_win_obj_callback_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _elm_win_obj_callback_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _elm_win_delete_request(Ecore_Evas *ee);
static void _elm_win_resize_job(void *data);
static void _elm_win_xwin_update(Elm_Win *win);
static void _elm_win_eval_subobjs(Evas_Object *obj);
static void _elm_win_subobj_callback_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _elm_win_subobj_callback_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);

static Eina_List *_elm_win_list = NULL;

static void
_elm_win_resize(Ecore_Evas *ee)
{
   Elm_Win *win = ecore_evas_data_get(ee, "__Elm");
   if (!win) return;
   if (win->deferred_resize_job) ecore_job_del(win->deferred_resize_job);
   win->deferred_resize_job = ecore_job_add(_elm_win_resize_job, win);
}

static void
_elm_win_obj_intercept_show(void *data, Evas_Object *obj)
{
   Elm_Win *win = data;
   ecore_evas_show(win->ee);
   evas_object_show(obj);
}

static void
_elm_win_obj_intercept_hide(void *data, Evas_Object *obj)
{
   Elm_Win *win = data;
   ecore_evas_hide(win->ee);
   evas_object_hide(obj);
}

static void
_elm_win_obj_intercept_move(void *data, Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
   Elm_Win *win = data;
   // FIXME: account for frame
   ecore_evas_move(win->ee, x, y);
}

static void
_elm_win_obj_intercept_resize(void *data, Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{
   Elm_Win *win = data;
   ecore_evas_resize(win->ee, w, h);
}

static void
_elm_win_obj_intercept_raise(void *data, Evas_Object *obj)
{
   Elm_Win *win = data;
   ecore_evas_raise(win->ee);
}

static void
_elm_win_obj_intercept_lower(void *data, Evas_Object *obj)
{
   Elm_Win *win = data;
   ecore_evas_lower(win->ee);
}

static void
_elm_win_obj_intercept_stack_above(void *data, Evas_Object *obj, Evas_Object *above)
{
   if (above)
     {
	Elm_Win *win = evas_object_data_get(above, "__Elm");
	if (!win) evas_object_raise(obj);
	// FIXME: find window id of win and stack abive
	return;
     }
   evas_object_raise(obj);
   return;
}

static void
_elm_win_obj_intercept_stack_below(void *data, Evas_Object *obj, Evas_Object *below)
{
   if (below)
     {
	Elm_Win *win = evas_object_data_get(below, "__Elm");
	if (!win) evas_object_raise(obj);
	// FIXME: find window id of win and stack below
	return;
     }
   evas_object_lower(obj);
   return;
}

static void
_elm_win_obj_intercept_layer_set(void *data, Evas_Object *obj, int l)
{
   Elm_Win *win = data;
   // FIXME: use netwm above/below hints
   ecore_evas_layer_set(win->ee, l);
}

static void
_elm_win_obj_intercept_color_set(void *data, Evas_Object *obj, int r, int g, int b, int a)
{
   return;
}

static void
_deferred_ecore_evas_free(void *data)
{
   ecore_evas_free(data);
}

static void
_elm_win_obj_callback_del(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
   Elm_Win *win = data;

   _elm_win_list = eina_list_remove(_elm_win_list, win->win_obj);
   while (win->subobjs) elm_win_resize_object_del(obj, win->subobjs->data);
   evas_object_intercept_show_callback_del(win->win_obj, _elm_win_obj_intercept_show);
   evas_object_intercept_hide_callback_del(win->win_obj, _elm_win_obj_intercept_hide);
   evas_object_intercept_move_callback_del(win->win_obj, _elm_win_obj_intercept_move);
   evas_object_intercept_resize_callback_del(win->win_obj, _elm_win_obj_intercept_resize);
   evas_object_intercept_raise_callback_del(win->win_obj, _elm_win_obj_intercept_raise);
   evas_object_intercept_lower_callback_del(win->win_obj, _elm_win_obj_intercept_lower);
   evas_object_intercept_stack_above_callback_del(win->win_obj, _elm_win_obj_intercept_stack_above);
   evas_object_intercept_stack_below_callback_del(win->win_obj, _elm_win_obj_intercept_stack_below);
   evas_object_intercept_layer_set_callback_del(win->win_obj, _elm_win_obj_intercept_layer_set);
   evas_object_intercept_color_set_callback_del(win->win_obj, _elm_win_obj_intercept_color_set);
   evas_object_event_callback_del(win->win_obj, EVAS_CALLBACK_DEL, _elm_win_obj_callback_del);
   evas_object_event_callback_del(win->win_obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _elm_win_obj_callback_changed_size_hints);
   ecore_evas_callback_delete_request_set(win->ee, NULL);
   ecore_evas_callback_resize_set(win->ee, NULL);
   if (win->deferred_resize_job) ecore_job_del(win->deferred_resize_job);
   if (win->deferred_child_eval_job) ecore_job_del(win->deferred_child_eval_job);
   while (evas_object_bottom_get(win->evas) &&
	  (evas_object_bottom_get(win->evas) != obj))
     evas_object_del(evas_object_bottom_get(win->evas));
   while (evas_object_top_get(win->evas) &&
	  (evas_object_top_get(win->evas) != obj))
     evas_object_del(evas_object_top_get(win->evas));
// fixme - we are in the del handler for the object and delete the canvas
// that lives under it from the handler... nasty. deferring doesnt help either
   ecore_job_add(_deferred_ecore_evas_free, win->ee);
//   ecore_evas_free(win->ee);
   free(win);
}

static void
_elm_win_obj_callback_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
   Elm_Win *win = data;
   Evas_Coord w, h;
   
   evas_object_size_hint_min_get(obj, &w, &h);
   ecore_evas_size_min_set(win->ee, w, h);
   evas_object_size_hint_max_get(obj, &w, &h);
   if (w < 1) w = -1;
   if (h < 1) h = -1;
   ecore_evas_size_max_set(win->ee, w, h);
}

static void
_elm_win_delete_request(Ecore_Evas *ee)
{
   Elm_Win *win = ecore_evas_data_get(ee, "__Elm");
   if (!win) return;
   evas_object_smart_callback_call(win->win_obj, "delete-request", NULL);
   if (win->autodel) evas_object_del(win->win_obj);
}

static void
_elm_win_resize_job(void *data)
{
   Elm_Win *win = data;
   Eina_List *l;
   int w, h;
   
   win->deferred_resize_job = NULL;
   ecore_evas_geometry_get(win->ee, NULL, NULL, &w, &h);
   evas_object_intercept_resize_callback_del(win->win_obj, _elm_win_obj_intercept_resize);
   evas_object_resize(win->win_obj, w, h);
   evas_object_intercept_resize_callback_add(win->win_obj, _elm_win_obj_intercept_resize, win);
   for (l = win->subobjs; l; l = l->next)
     {
	evas_object_move(l->data, 0, 0);
	evas_object_resize(l->data, w, h);
     }
}

static void
_elm_win_xwin_update(Elm_Win *win)
{
   win->xwin = 0;
   switch (_elm_config->engine)
     {
      case ELM_SOFTWARE_X11:
	if (win->ee) win->xwin = ecore_evas_software_x11_window_get(win->ee);
	break;
      case ELM_SOFTWARE_FB:
	break;
      case ELM_SOFTWARE_16_X11:
	if (win->ee) win->xwin = ecore_evas_software_x11_16_window_get(win->ee);
	break;
      case ELM_XRENDER_X11:
	if (win->ee) win->xwin = ecore_evas_xrender_x11_window_get(win->ee);
	break;
      case ELM_OPENGL_X11:
	if (win->ee) win->xwin = ecore_evas_gl_x11_window_get(win->ee);
	break;
      default:
	break;
     }
   if (win->parent)
     {
	Elm_Win *win2;
	
	win2 = evas_object_data_get(win->parent, "__Elm");
	if (win2)
	  {
	     if (win->xwin)
	       ecore_x_icccm_transient_for_set(win->xwin, win2->xwin);
	  }
     }
   
   if (win->type == ELM_WIN_BASIC)
     {
	switch (win->type)
          {
	   case ELM_WIN_BASIC:
	     if (win->xwin) 
	       ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_NORMAL);
	     break;
	   case ELM_WIN_DIALOG_BASIC:
	     if (win->xwin) 
	       ecore_x_netwm_window_type_set(win->xwin, ECORE_X_WINDOW_TYPE_DIALOG);
	     break;
	   default:
	     break;
	  }
     }

}

static void
_elm_win_eval_subobjs(Evas_Object *obj)
{
   Eina_List *l;
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   Evas_Coord w, h, minw = -1, minh = -1, maxw = -1, maxh = -1;
   int xx = 1, xy = 1;
   double wx, wy;

   for (l = win->subobjs; l; l = l->next)
     {
	evas_object_size_hint_weight_get(l->data, &wx, &wy);
	if (wx == 0.0) xx = 0;
	if (wy == 0.0) xy = 0;
	
	evas_object_size_hint_min_get(l->data, &w, &h);
	if (w < 1) w = -1;
	if (h < 1) h = -1;
	if (w > minw) minw = w;
	if (h > minh) minh = h;
	
	evas_object_size_hint_max_get(l->data, &w, &h);
	if (w < 1) w = -1;
	if (h < 1) h = -1;
	if (maxw == -1) maxw = w;
	else if (w < maxw) maxw = w;
	if (maxh == -1) maxh = h;
	else if (h < maxh) maxh = h;
     }
   if ((maxw >= 0) && (maxw < minw)) maxw = minw;
   if ((maxh >= 0) && (maxh < minh)) maxh = minh;
   if (!xx) maxw = minw;
   else maxw = 32767;
   if (!xy) maxh = minh;
   else maxh = 32767;
   evas_object_size_hint_min_set(obj, minw, minh);
   evas_object_size_hint_max_set(obj, maxw, maxh);
   evas_object_geometry_get(obj, NULL, NULL, &w, &h);
   if (w < minw) w = minw;
   if (h < minh) h = minh;
   if ((maxw >= 0) && (w > maxw)) w = maxw;
   if ((maxh >= 0) && (h > maxh)) h = maxh;
   evas_object_resize(obj, w, h);
}

static void
_elm_win_subobj_callback_del(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
   elm_win_resize_object_del(data, obj);
}

static void
_elm_win_subobj_callback_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
   _elm_win_eval_subobjs(data);
}

void
_elm_win_shutdown(void)
{
   while (_elm_win_list) evas_object_del(_elm_win_list->data);
}

void
_elm_win_rescale(void)
{
   Eina_List *l;
   
   for (l = _elm_win_list; l; l = l->next) elm_widget_theme(l->data);
}

EAPI Evas_Object *
elm_win_add(Evas_Object *parent, const char *name, Elm_Win_Type type)
{
   Elm_Win *win;
   
   win = ELM_NEW(Elm_Win);
   switch (_elm_config->engine)
     {
      case ELM_SOFTWARE_X11:
	win->ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 1, 1);
	if (win->ee) win->xwin = ecore_evas_software_x11_window_get(win->ee);
	break;
      case ELM_SOFTWARE_FB:
	win->ee = ecore_evas_fb_new(NULL, 0, 1, 1);
        ecore_evas_fullscreen_set(win->ee, 1);
	break;
      case ELM_SOFTWARE_16_X11:
	win->ee = ecore_evas_software_x11_16_new(NULL, 0, 0, 0, 1, 1);
	if (win->ee) win->xwin = ecore_evas_software_x11_16_window_get(win->ee);
	break;
      case ELM_XRENDER_X11:
	win->ee = ecore_evas_xrender_x11_new(NULL, 0, 0, 0, 1, 1);
	if (win->ee) win->xwin = ecore_evas_xrender_x11_window_get(win->ee);
	break;
      case ELM_OPENGL_X11:
	win->ee = ecore_evas_gl_x11_new(NULL, 0, 0, 0, 1, 1);
	if (win->ee) win->xwin = ecore_evas_gl_x11_window_get(win->ee);
	break;
      default:
	break;
     }
   if (!win->ee)
     {
	printf("ELEMENTARY: Error. Cannot create window.\n");
	free(win);
	return NULL;
     }
   if (_elm_config->bgpixmap && !_elm_config->compositing)
     ecore_evas_avoid_damage_set(win->ee, ECORE_EVAS_AVOID_DAMAGE_EXPOSE);
// bg pixmap done by x - has other issues like can be redrawn by x before it
// is filled/ready by app   
//     ecore_evas_avoid_damage_set(win->ee, ECORE_EVAS_AVOID_DAMAGE_BUILT_IN);
   
   win->type = type;
   win->parent = parent;
   
   win->evas = ecore_evas_get(win->ee);
   win->win_obj = elm_widget_add(win->evas);
   evas_object_color_set(win->win_obj, 0, 0, 0, 0);
   evas_object_move(win->win_obj, 0, 0);
   evas_object_resize(win->win_obj, 1, 1);
   evas_object_layer_set(win->win_obj, 50);
   evas_object_pass_events_set(win->win_obj, 1);
   evas_object_data_set(win->win_obj, "__Elm", win);

   evas_object_intercept_show_callback_add(win->win_obj, _elm_win_obj_intercept_show, win);
   evas_object_intercept_hide_callback_add(win->win_obj, _elm_win_obj_intercept_hide, win);
   evas_object_intercept_move_callback_add(win->win_obj, _elm_win_obj_intercept_move, win);
   evas_object_intercept_resize_callback_add(win->win_obj, _elm_win_obj_intercept_resize, win);
   evas_object_intercept_raise_callback_add(win->win_obj, _elm_win_obj_intercept_raise, win);
   evas_object_intercept_lower_callback_add(win->win_obj, _elm_win_obj_intercept_lower, win);
   evas_object_intercept_stack_above_callback_add(win->win_obj, _elm_win_obj_intercept_stack_above, win);
   evas_object_intercept_stack_below_callback_add(win->win_obj, _elm_win_obj_intercept_stack_below, win);
   evas_object_intercept_layer_set_callback_add(win->win_obj, _elm_win_obj_intercept_layer_set, win);
   evas_object_intercept_color_set_callback_add(win->win_obj, _elm_win_obj_intercept_color_set, win);
   evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_DEL, _elm_win_obj_callback_del, win);
   evas_object_event_callback_add(win->win_obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _elm_win_obj_callback_changed_size_hints, win);
   
   ecore_evas_name_class_set(win->ee, name, _elm_appname);
   ecore_evas_data_set(win->ee, "__Elm", win);
   ecore_evas_callback_delete_request_set(win->ee, _elm_win_delete_request);
   ecore_evas_callback_resize_set(win->ee, _elm_win_resize);
   // FIXME: use elm config for this
   evas_image_cache_set(win->evas, 4096 * 1024);
   evas_font_cache_set(win->evas, 512 * 1024);
   evas_font_path_append(win->evas, "fonts");
//   evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_NONE);
//   evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_AUTO);
//   evas_font_hinting_set(win->evas, EVAS_FONT_HINTING_BYTECODE);
   edje_frametime_set(1.0 / 30.0);
   edje_scale_set(_elm_config->scale);

   _elm_win_xwin_update(win);

   _elm_win_list = eina_list_append(_elm_win_list, win->win_obj);
   
   return win->win_obj;
}

EAPI void
elm_win_resize_object_add(Evas_Object *obj, Evas_Object *subobj)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   win->subobjs = eina_list_append(win->subobjs, subobj);
   elm_widget_sub_object_add(obj, subobj);
   evas_object_event_callback_add(subobj, EVAS_CALLBACK_DEL, _elm_win_subobj_callback_del, obj);
   evas_object_event_callback_add(subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _elm_win_subobj_callback_changed_size_hints, obj);
   _elm_win_eval_subobjs(obj);
}

EAPI void
elm_win_resize_object_del(Evas_Object *obj, Evas_Object *subobj)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   evas_object_event_callback_del(subobj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _elm_win_subobj_callback_changed_size_hints);
   evas_object_event_callback_del(subobj, EVAS_CALLBACK_DEL, _elm_win_subobj_callback_del);
   win->subobjs = eina_list_remove(win->subobjs, subobj);
   elm_widget_sub_object_del(obj, subobj);
   _elm_win_eval_subobjs(obj);
}

EAPI void
elm_win_title_set(Evas_Object *obj, const char *title)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   ecore_evas_title_set(win->ee, title);
}
  
EAPI void
elm_win_autodel_set(Evas_Object *obj, Evas_Bool autodel)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   win->autodel = autodel;
}

EAPI void
elm_win_activate(Evas_Object *obj)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   ecore_evas_activate(win->ee);
}

EAPI void
elm_win_borderless_set(Evas_Object *obj, Evas_Bool borderless)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   ecore_evas_borderless_set(win->ee, borderless);
   _elm_win_xwin_update(win);
}

EAPI void
elm_win_shaped_set(Evas_Object *obj, Evas_Bool shaped)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   ecore_evas_shaped_set(win->ee, shaped);
   _elm_win_xwin_update(win);
}

EAPI void
elm_win_alpha_set(Evas_Object *obj, Evas_Bool alpha)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   if (win->xwin)
     {
	if (alpha)
	  {
	     if (!_elm_config->compositing)
	       elm_win_shaped_set(obj, alpha);
	     else
	       ecore_evas_alpha_set(win->ee, alpha);
	  }
	else
	  ecore_evas_alpha_set(win->ee, alpha);
	_elm_win_xwin_update(win);
     }
   else
     ecore_evas_alpha_set(win->ee, alpha);
}

EAPI void
elm_win_override_set(Evas_Object *obj, Evas_Bool override)
{
   Elm_Win *win = evas_object_data_get(obj, "__Elm");
   if (!win) return;
   ecore_evas_override_set(win->ee, override);
   _elm_win_xwin_update(win);
}