summaryrefslogtreecommitdiff
path: root/src/desksanity.c
blob: ae181f3812d3e26a1f89cea65c24b9d578ece09a (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
#include "e_mod_main.h"

static E_Desk *desk_show = NULL;
static Evas_Object *dm_show = NULL;
static E_Desk *desk_hide = NULL;
static Evas_Object *dm_hide = NULL;

typedef enum
{
   DS_PAN,
   DS_FADE_OUT,
   DS_FADE_IN,
   DS_BATMAN,
   DS_ZOOM_IN,
   DS_ZOOM_OUT,
   DS_GROW,
   DS_ROTATE_OUT,
   DS_ROTATE_IN,
   DS_SLIDE_SPLIT,
   DS_QUAD_SPLIT,
   DS_QUAD_MERGE,
   DS_BLINK,
   DS_VIEWPORT,
   DS_LAST,
} DS_Type;

static DS_Type cur_type = DS_PAN;

static void
_ds_end(void *data EINA_UNUSED, Efx_Map_Data *emd EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
   /* hide/delete previous desk's mirror */
   evas_object_hide(dm_hide);
   E_FREE_FUNC(dm_hide, evas_object_del);
   desk_hide = NULL;

   /* trigger desk flip end if there's a current desk set */
   if (desk_show)
     {
        e_desk_flip_end(desk_show);
        e_comp_shape_queue_block(e_comp_get(desk_show), 0);
     }

   /* hide/delete current desk's mirror */
   evas_object_hide(dm_show);
   E_FREE_FUNC(dm_show, evas_object_del);
   desk_show = NULL;
}

static Evas_Object *
dm_add(E_Desk *desk)
{
   Evas_Object *o;

   /* add new mirror: not a pager or taskbar */
   o = e_deskmirror_add(desk, 0, 0);
   /* cover desk */
   evas_object_geometry_set(o, desk->zone->x, desk->zone->y, desk->zone->w, desk->zone->h);
   /* don't receive events */
   evas_object_pass_events_set(o, 1);
   /* clip to current screen */
   evas_object_clip_set(o, desk->zone->bg_clip_object);
   /* above all menus/popups/clients */
   evas_object_layer_set(o, E_LAYER_MENU + 100);
   evas_object_show(o);
   return o;
}

static void
_ds_show(E_Desk *desk, int dx, int dy)
{
   E_Client *ec;
   DS_Type use_type;

   /* free existing mirror */
   E_FREE_FUNC(dm_show, evas_object_del);

   /* iterate all clients */
   E_CLIENT_FOREACH(desk->zone->comp, ec)
     {
        /* skip clients from other screens, iconic clients, and ignorable clients */
        if ((ec->desk->zone != desk->zone) || (ec->iconic) || e_client_util_ignored_get(ec)) continue;
        /* always keep user-moving clients visible */
        if (ec->moving)
          {
             e_client_desk_set(ec, desk);
             evas_object_show(ec->frame);
             continue;
          }
        /* skip clients from other desks and clients visible on all desks */
        if ((ec->desk != desk) || (ec->sticky)) continue;
        e_comp_object_effect_unclip(ec->frame);
        e_comp_object_effect_set(ec->frame, NULL);
        /* comp unignore the client */
        e_client_comp_hidden_set(ec, EINA_FALSE);
        ec->hidden = 0;
        evas_object_show(ec->frame);
     }
   desk_show = desk;
   /* create mirror for current desk */
   dm_show = dm_add(desk);
   evas_object_name_set(dm_show, "dm_show");
   e_comp_shape_queue_block(e_comp_get(desk), 1);
   /* guarantee that the user gets to see each flip
    * at least once
    */
   if (cur_type < DS_LAST)
     use_type = cur_type++;
   else
     use_type = rand() % DS_LAST;
   /* pick a random flip */
   switch (use_type)
     {
      int x, y, hx, hy, w, h;
      Evas_Object *o;

      case DS_PAN:
        switch (dx)
          {
           case -1: // left -> right
             x = desk->zone->x - desk->zone->w;
             hx = desk->zone->x + desk->zone->w;
             break;
           case 0: // X
             x = desk->zone->x;
             hx = desk->zone->x;
             break;
           case 1: // left <- right
             x = desk->zone->x + desk->zone->w;
             hx = desk->zone->x - desk->zone->w;
             break;
          }
        switch (dy)
          {
           case -1: // up -> down
             y = desk->zone->y - desk->zone->h;
             hy = desk->zone->y + desk->zone->h;
             break;
           case 0: // X
             y = desk->zone->y;
             hy = desk->zone->y;
             break;
           case 1: // up <- down
             y = desk->zone->y + desk->zone->h;
             hy = desk->zone->y - desk->zone->h;
             break;
          }
        evas_object_move(dm_show, x, y);
        efx_move(dm_hide, EFX_EFFECT_SPEED_DECELERATE, EFX_POINT(hx, hy), 0.2, NULL, NULL);
        efx_move(dm_show, EFX_EFFECT_SPEED_DECELERATE, EFX_POINT(desk->zone->x, desk->zone->y), 0.2, _ds_end, NULL);
        break;
      case DS_FADE_OUT:
        E_FREE_FUNC(dm_show, evas_object_del);
        efx_fade(dm_hide, EFX_EFFECT_SPEED_LINEAR, EFX_COLOR(0, 0, 0), 0, 0.25, _ds_end, NULL);
        break;
      case DS_FADE_IN:
        E_FREE_FUNC(dm_hide, evas_object_del);
        efx_fade(dm_show, EFX_EFFECT_SPEED_LINEAR, EFX_COLOR(0, 0, 0), 0, 0.0, NULL, NULL);
        efx_fade(dm_show, EFX_EFFECT_SPEED_LINEAR, EFX_COLOR(255, 255, 255), 255, 0.25, _ds_end, NULL);
        break;
      case DS_BATMAN:
        E_FREE_FUNC(dm_show, evas_object_del);
        evas_object_raise(dm_hide);
        efx_spin_start(dm_hide, 1080.0, NULL);
        efx_zoom(dm_hide, EFX_EFFECT_SPEED_LINEAR, 1.0, 0.00001, NULL, 0.4, _ds_end, NULL);
        break;
      case DS_ZOOM_IN:
        efx_zoom(dm_show, EFX_EFFECT_SPEED_LINEAR, 0.000001, 1.0, NULL, 0.4, _ds_end, NULL);
        break;
      case DS_ZOOM_OUT:
        E_FREE_FUNC(dm_show, evas_object_del);
        evas_object_raise(dm_hide);
        efx_zoom(dm_hide, EFX_EFFECT_SPEED_LINEAR, 1.0, 0.0000001, NULL, 0.4, _ds_end, NULL);
        break;
      case DS_GROW:
        x = hx = desk->zone->x;
        w = 1;
        if (dx == 1) // grow right to left
          x = desk->zone->x + desk->zone->w;
        else if (!dx)
          w = desk->zone->w;
        y = hy = desk->zone->y;
        h = 1;
        if (dy == 1) // grow bottom to top
          y = desk->zone->y + desk->zone->h;
        else if (!dy)
          h = desk->zone->h;
        o = evas_object_rectangle_add(e_comp_get(desk)->evas);
        evas_object_geometry_set(o, x, y, w, h);
        evas_object_clip_set(dm_show, o);
        evas_object_show(o);
        e_comp_object_util_del_list_append(dm_show, o);
        efx_resize(o, EFX_EFFECT_SPEED_LINEAR, EFX_POINT(hx, hy), desk->zone->w, desk->zone->h, 0.4, _ds_end, NULL);
        break;
      case DS_ROTATE_OUT:
        E_FREE_FUNC(dm_show, evas_object_del);
        efx_move_circle(dm_hide, EFX_EFFECT_SPEED_LINEAR, EFX_POINT(desk->zone->x + (desk->zone->w / 2), desk->zone->y + (desk->zone->h / 2)),
          720, 0.4, NULL, NULL);
        efx_resize(dm_hide, EFX_EFFECT_SPEED_LINEAR, NULL, 1, 1, 0.4, _ds_end, NULL);
        break;
      case DS_ROTATE_IN:
        evas_object_resize(dm_show, 1, 1);
        efx_move_circle(dm_show, EFX_EFFECT_SPEED_LINEAR, EFX_POINT(desk->zone->x + (desk->zone->w / 2), desk->zone->y + (desk->zone->h / 2)),
          720, 0.4, NULL, NULL);
        efx_resize(dm_show, EFX_EFFECT_SPEED_LINEAR, NULL, desk->zone->w, desk->zone->h, 0.4, _ds_end, NULL);
        break;
      case DS_SLIDE_SPLIT:
      {
         Evas_Object *dm_hide2, *clip1, *clip2;
         //int x, y, w, h; //clip1
         int xx, yy, ww, hh; //clip2
         int ex, ey, exx, eyy; //move coords

         dm_hide2 = dm_add(desk_hide);
         e_comp_object_util_del_list_append(dm_hide, dm_hide2);

         clip1 = evas_object_rectangle_add(e_comp_get(desk_show)->evas);
         x = desk_show->zone->x;
         y = desk_show->zone->y;
         w = desk_show->zone->w;
         h = desk_show->zone->h;
         if (dy)
           w /= 2;
         else
           h /= 2;
         evas_object_geometry_set(clip1, x, y, w, h);
         e_comp_object_util_del_list_append(dm_hide, clip1);
         evas_object_clip_set(dm_hide, clip1);
         evas_object_show(clip1);

         clip2 = evas_object_rectangle_add(e_comp_get(desk_show)->evas);
         xx = desk_show->zone->x;
         yy = desk_show->zone->y;
         ww = w;
         hh = h;
         if (dx)
           yy += h;
         else
           xx += w;
         evas_object_geometry_set(clip2, xx, yy, ww, hh);
         e_comp_object_util_del_list_append(dm_hide, clip2);
         evas_object_clip_set(dm_hide2, clip2);
         evas_object_show(clip2);

         E_FREE_FUNC(dm_show, evas_object_del);

         if (dx)
           {
              ex = desk_show->zone->x - (dx * desk_show->zone->w);
              exx = desk_show->zone->x + (dx * desk_show->zone->w);
           }
         else
           ex = exx = desk_show->zone->x;
         if (dy)
           {
              ey = desk_show->zone->y - (dy * desk_show->zone->h);
              eyy = desk_show->zone->y + (dy * desk_show->zone->h);
           }
         else
           ey = eyy = desk_show->zone->y;
         efx_move(dm_hide, EFX_EFFECT_SPEED_ACCELERATE,
           EFX_POINT(ex, ey),
           0.5, NULL, NULL);
         efx_move(dm_hide2, EFX_EFFECT_SPEED_ACCELERATE,
           EFX_POINT(exx, eyy),
           0.5, _ds_end, NULL);
      }
        break;
      case DS_QUAD_SPLIT:
      {
         int i;
         Evas_Object *dmh[4] = {NULL};
         Evas_Object *clip[4];
         Evas_Point cxy[4] = {{desk->zone->x, desk->zone->y},
                              {desk->zone->x + (desk->zone->w / 2), desk->zone->y},
                              {desk->zone->x, desk->zone->y + (desk->zone->h / 2)},
                              {desk->zone->x + (desk->zone->w / 2), desk->zone->y + (desk->zone->h / 2)}
                             };
         Evas_Point exy[4] = {{desk->zone->x - desk->zone->w, desk->zone->y - desk->zone->h},
                              {desk->zone->x + (desk->zone->w * 2), desk->zone->y - desk->zone->h},
                              {desk->zone->x - desk->zone->w, desk->zone->y + (desk->zone->h / 2)},
                              {desk->zone->x + (desk->zone->w * 2), desk->zone->y + (desk->zone->h * 2)}
                             };

         E_FREE_FUNC(dm_show, evas_object_del);
         dmh[0] = dm_hide;
         for (i = 0; i < 4; i++)
           {
              if (!dmh[i])
                {
                   dmh[i] = dm_add(desk_hide);
                   e_comp_object_util_del_list_append(dm_hide, dmh[i]);
                }
              clip[i] = evas_object_rectangle_add(e_comp_get(desk)->evas);
              e_comp_object_util_del_list_append(dm_hide, clip[i]);
              evas_object_geometry_set(clip[i], cxy[i].x, cxy[i].y, desk->zone->w / 2, desk->zone->h / 2);
              evas_object_clip_set(dmh[i], clip[i]);
              evas_object_show(clip[i]);
              efx_move(clip[i], EFX_EFFECT_SPEED_ACCELERATE,
                &exy[i], 0.8, (i == 3) ? _ds_end : NULL, NULL);
           }
      }
        break;
      case DS_QUAD_MERGE:
      {
         int i;
         Evas_Object *dmh[4] = {NULL};
         Evas_Object *clip[4];
         Evas_Point cxy[4] = {{desk->zone->x, desk->zone->y},
                              {desk->zone->x + (desk->zone->w / 2), desk->zone->y},
                              {desk->zone->x, desk->zone->y + (desk->zone->h / 2)},
                              {desk->zone->x + (desk->zone->w / 2), desk->zone->y + (desk->zone->h / 2)}
                             };

         E_FREE_FUNC(dm_show, evas_object_del);
         dmh[0] = dm_hide;
         for (i = 0; i < 4; i++)
           {
              if (!dmh[i])
                {
                   dmh[i] = dm_add(desk_hide);
                   e_comp_object_util_del_list_append(dm_hide, dmh[i]);
                }
              clip[i] = evas_object_rectangle_add(e_comp_get(desk)->evas);
              e_comp_object_util_del_list_append(dm_hide, clip[i]);
              evas_object_geometry_set(clip[i], cxy[i].x, cxy[i].y, desk->zone->w / 2, desk->zone->h / 2);
              evas_object_clip_set(dmh[i], clip[i]);
              evas_object_show(clip[i]);
              efx_resize(clip[i], EFX_EFFECT_SPEED_ACCELERATE,
                EFX_POINT(desk->zone->x + (desk->zone->w / 2), desk->zone->y + (desk->zone->h / 2)),
                1, 1 ,0.8, (i == 3) ? _ds_end : NULL, NULL);
           }
      }
        break;
      case DS_BLINK:
      {
         Evas_Object *clip;

         E_FREE_FUNC(dm_show, evas_object_del);
         clip = evas_object_rectangle_add(e_comp_get(desk)->evas);
         evas_object_geometry_set(clip, desk->zone->x, desk->zone->y, desk->zone->w, desk->zone->h);
         evas_object_clip_set(dm_hide, clip);
         e_comp_object_util_del_list_append(dm_hide, clip);
         evas_object_show(clip);
         efx_resize(clip, EFX_EFFECT_SPEED_DECELERATE,
           EFX_POINT(desk->zone->x, desk->zone->y + (desk->zone->h / 2)),
           desk->zone->w, 1, 0.45, _ds_end, NULL);
      }
      case DS_VIEWPORT:
      {
         Evas_Object *clip;

         E_FREE_FUNC(dm_show, evas_object_del);
         clip = evas_object_rectangle_add(e_comp_get(desk)->evas);
         evas_object_geometry_set(clip, desk->zone->x, desk->zone->y, desk->zone->w, desk->zone->h);
         evas_object_clip_set(dm_hide, clip);
         e_comp_object_util_del_list_append(dm_hide, clip);
         evas_object_show(clip);
         efx_resize(clip, EFX_EFFECT_SPEED_DECELERATE,
           EFX_POINT(desk->zone->x + (desk->zone->w / 2), desk->zone->y + (desk->zone->h / 2)),
           1, 1, 0.6, _ds_end, NULL);
      }
        break;
      default: break;
     }
}

static void
_ds_hide(E_Desk *desk)
{
   E_Client *ec;

   E_FREE_FUNC(dm_hide, evas_object_del);
   E_CLIENT_FOREACH(desk->zone->comp, ec)
     {
        /* same as above */
        if ((ec->desk->zone != desk->zone) || (ec->iconic) || e_client_util_ignored_get(ec)) continue;
        if (ec->moving) continue;
        if ((ec->desk != desk) || (ec->sticky)) continue;
        /* comp hide clients */
        e_client_comp_hidden_set(ec, EINA_TRUE);
        ec->hidden = 1;
        evas_object_hide(ec->frame);
     }
   desk_hide = desk;
   /* create mirror for previous desk */
   dm_hide = dm_add(desk);
   evas_object_name_set(dm_hide, "dm_hide");
}


static void
_ds_flip(void *data EINA_UNUSED, E_Desk *desk, int dx, int dy, Eina_Bool show)
{
   /* this is called for desk hide, then for desk show. always in that order. always. */
   if (show)
     _ds_show(desk, dx, dy);
   else
     _ds_hide(desk);
}

EINTERN void
ds_init(void)
{
   /* set a desk flip replacement callback */
   e_desk_flip_cb_set(_ds_flip, NULL);
}

EINTERN void
ds_shutdown(void)
{
   e_desk_flip_cb_set(NULL, NULL);
   _ds_end(NULL, NULL, NULL);
   cur_type = DS_PAN;
}