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

static Ecore_Event_Handler *eh = NULL;

static Eina_Bool
_ds_unmaximize_render(void *d EINA_UNUSED)
{
   e_comp_render_queue(e_comp_get(NULL));
   return EINA_FALSE;
}

static void
_ds_unmaximize_post(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   E_Client *ec = data;
   Eina_Rectangle *rect;
   int x, y, w, h;
   double time = 0.15;

   if (e_comp_config_get()->match.disable_borders) return;
   if (e_comp_config_get()->fast_borders)
     time /= 2;
   w = ec->w, h = ec->h;
   evas_object_geometry_get(ec->frame, &x, &y, NULL, NULL);

   rect = evas_object_data_del(obj, "__DSUMAX");
   if (!rect) return;
   evas_object_geometry_set(obj, rect->x, rect->y, rect->w, rect->h);
   free(rect);
   efx_resize(ec->frame, EFX_EFFECT_SPEED_SINUSOIDAL, EFX_POINT(x, y), w, h, time, NULL, NULL);
   ecore_timer_add(0.1, _ds_unmaximize_render, NULL);
}

static void
_ds_unmaximize(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   E_Client *ec = data;
   Eina_Rectangle *rect;

   if (e_comp_config_get()->match.disable_borders) return;

   rect = malloc(sizeof(Eina_Rectangle));
   rect->x = ec->x, rect->y = ec->y;
   rect->w = ec->w, rect->h = ec->h;
   evas_object_data_set(ec->frame, "__DSUMAX", rect);
}

static void
_ds_unmaximize_pre(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   E_Client *ec = data;
   Eina_Bool max;

   max = !!evas_object_data_del(ec->frame, "__DSMAX");
   if (max)
     efx_resize_stop(ec->frame);
   ec->maximize_override = 0;
}

static void
_ds_maximize_done(void *data, Efx_Map_Data *emd EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
   E_Client *ec = data;

   ec->maximize_override = 0;
   evas_object_data_del(ec->frame, "__DSMAX");
}

static void
_ds_maximize(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   E_Client *ec = data;
   int x, y, w, h;
   int ecx, ecy, ecw, ech;
   double time = 0.2;

   if (e_comp_config_get()->match.disable_borders) return;
   if (e_comp_config_get()->fast_borders)
     time /= 2;
   ecx = ec->x, ecy = ec->y, ecw = ec->w, ech = ec->h;
   e_comp_object_frame_xy_adjust(ec->frame, ec->saved.x + ec->zone->x, ec->saved.y + ec->zone->y, &x, &y);
   evas_object_geometry_get(ec->frame, NULL, NULL, &w, &h);
   if ((!w) || (!h)) return; //new client, don't break the universe
   ec->maximize_override = 1;
   evas_object_geometry_set(ec->frame, x, y, w, h);
   efx_resize(ec->frame, EFX_EFFECT_SPEED_SINUSOIDAL, EFX_POINT(ecx, ecy), ecw, ech, time, _ds_maximize_done, ec);
   evas_object_data_set(ec->frame, "__DSMAX", (void*)1);
}

static void
_ds_fullscreen(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   E_Client *ec = data;

   evas_object_data_del(ec->frame, "__DSMAX");
   free(evas_object_data_del(ec->frame, "__DSUMAX"));
   ec->maximize_override = 0;
   efx_resize_stop(ec->frame);
}

static void
_ds_maximize_check(E_Client *ec)
{
   if (e_client_util_ignored_get(ec)) return;
   evas_object_smart_callback_add(ec->frame, "maximize_done", _ds_maximize, ec);
   evas_object_smart_callback_add(ec->frame, "unmaximize_pre", _ds_unmaximize_pre, ec);
   evas_object_smart_callback_add(ec->frame, "unmaximize", _ds_unmaximize, ec);
   evas_object_smart_callback_add(ec->frame, "unmaximize_done", _ds_unmaximize_post, ec);
   evas_object_smart_callback_add(ec->frame, "fullscreen", _ds_fullscreen, ec);
}

static Eina_Bool
_ds_maximize_add(void *d EINA_UNUSED, int t EINA_UNUSED, E_Event_Client *ev)
{
   _ds_maximize_check(ev->ec);
   return ECORE_CALLBACK_RENEW;
}

EINTERN void
maximize_init(void)
{
   E_Client *ec;

   E_CLIENT_FOREACH(e_comp_get(NULL), ec)
     _ds_maximize_check(ec);
   eh = ecore_event_handler_add(E_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_ds_maximize_add, NULL);
}

EINTERN void
maximize_shutdown(void)
{
   E_Client *ec;

   E_CLIENT_FOREACH(e_comp_get(NULL), ec)
     {
        if (e_client_util_ignored_get(ec)) continue;
        evas_object_smart_callback_del(ec->frame, "maximize_done", _ds_maximize);
        evas_object_smart_callback_del(ec->frame, "unmaximize_pre", _ds_unmaximize_pre);
        evas_object_smart_callback_del(ec->frame, "unmaximize", _ds_unmaximize);
        evas_object_smart_callback_del(ec->frame, "unmaximize_done", _ds_unmaximize_post);
        evas_object_smart_callback_del(ec->frame, "fullscreen", _ds_fullscreen);
     }
   E_FREE_FUNC(eh, ecore_event_handler_del);
}