4 e_place_zone_region_smart_cleanup(E_Zone *zone)
7 Eina_List *clients = NULL;
11 desk = e_desk_current_get(zone);
14 /* Build a list of windows on this desktop and not iconified. */
15 if ((ec->desk == desk) && (!ec->iconic) &&
16 (!ec->lock_user_location) && (!e_client_util_ignored_get(ec)))
22 /* Ordering windows largest to smallest gives better results */
24 EINA_LIST_FOREACH(clients, ll, ec2)
28 testarea = ec2->w * ec2->h;
29 /* Insert the ec if larger than the current ec */
32 clients = eina_list_prepend_relative(clients, ec2, ec);
36 /* Looped over all clients without placing, so place at end */
37 if (!ll) clients = eina_list_append(clients, ec);
41 /* Loop over the clients moving each one using the smart placement */
42 EINA_LIST_FREE(clients, ec)
46 e_place_zone_region_smart(zone, clients, ec->x, ec->y,
47 ec->w, ec->h, &new_x, &new_y);
48 evas_object_move(ec->frame, new_x, new_y);
53 _e_place_cb_sort_cmp(const void *v1, const void *v2)
55 return (*((int *)v1)) - (*((int *)v2));
59 _e_place_coverage_client_add(E_Desk *desk, Eina_List *skiplist, int ar, int x, int y, int w, int h)
64 int x0, x00, yy0, y00;
68 if (eina_list_data_find(skiplist, ec)) continue;
69 if (e_client_util_ignored_get(ec)) continue;
70 x2 = (ec->x - desk->zone->x); y2 = (ec->y - desk->zone->y); w2 = ec->w; h2 = ec->h;
71 if (E_INTERSECTS(x, y, w, h, x2, y2, w2, h2) &&
72 ((ec->sticky) || (ec->desk == desk)) &&
73 (!ec->iconic) && (ec->visible))
78 if ((x2 + w2) < (x + w)) x00 = (x2 + w2);
82 if ((y2 + h2) < (y + h)) y00 = (y2 + h2);
91 /* TODO: remove this function */
93 _e_place_coverage_shelf_add(E_Desk *desk, int ar, int x, int y, int w, int h)
99 e_place_desk_region_smart(E_Desk *desk, Eina_List *skiplist, int x, int y, int w, int h, int *rx, int *ry)
101 int a_w = 0, a_h = 0, a_alloc_w = 0, a_alloc_h = 0;
102 int *a_x = NULL, *a_y = NULL;
104 char *u_x = NULL, *u_y = NULL;
110 /* DISABLE placement entirely for speed testing */
114 if ((w <= 0) || (h <= 0))
116 printf("EEEK! trying to place 0x0 window!!!!\n");
120 /* FIXME: this NEEDS optimizing */
125 if (!a_x || !a_y) goto error;
133 u_x = calloc(zw + 1, sizeof(char));
134 u_y = calloc(zh + 1, sizeof(char));
135 if (!u_x || !u_y) goto error;
151 if (e_client_util_ignored_get(ec)) continue;
153 if (eina_list_data_find(skiplist, ec)) continue;
155 if (!((ec->sticky) || (ec->desk == desk))) continue;
157 bx = ec->x - desk->zone->x;
158 by = ec->y - desk->zone->y;
162 if (E_INTERSECTS(bx, by, bw, bh, 0, 0, zw, zh))
169 if ((bx + bw) > zw) bw = zw - bx;
170 if (bx >= zw) continue;
176 if ((by + bh) > zh) bh = zh - by;
177 if (by >= zh) continue;
184 E_REALLOC(a_x, int, a_alloc_w);
185 if (!a_x) goto error;
196 E_REALLOC(a_x, int, a_alloc_w);
197 if (!a_x) goto error;
199 a_x[a_w - 1] = bx + bw;
208 E_REALLOC(a_y, int, a_alloc_h);
209 if (!a_y) goto error;
220 E_REALLOC(a_y, int, a_alloc_h);
221 if (!a_y) goto error;
223 a_y[a_h - 1] = by + bh;
228 qsort(a_x, a_w, sizeof(int), _e_place_cb_sort_cmp);
229 qsort(a_y, a_h, sizeof(int), _e_place_cb_sort_cmp);
235 int area = 0x7fffffff;
237 for (j = 0; j < a_h - 1; j++)
239 for (i = 0; i < a_w - 1; i++)
241 if ((a_x[i] <= (zw - w)) &&
242 (a_y[j] <= (zh - h)))
246 ar = _e_place_coverage_client_add(desk, skiplist, ar,
249 if (e_config->window_placement_policy == E_WINDOW_PLACEMENT_SMART)
250 ar = _e_place_coverage_shelf_add(desk, ar,
258 if (ar == 0) goto done;
261 if ((a_x[i + 1] - w > 0) && (a_y[j] <= (zh - h)))
265 ar = _e_place_coverage_client_add(desk, skiplist, ar,
266 a_x[i + 1] - w, a_y[j],
268 if (e_config->window_placement_policy == E_WINDOW_PLACEMENT_SMART)
269 ar = _e_place_coverage_shelf_add(desk, ar,
270 a_x[i + 1] - w, a_y[j],
275 *rx = a_x[i + 1] - w;
277 if (ar == 0) goto done;
280 if ((a_x[i + 1] - w > 0) && (a_y[j + 1] - h > 0))
284 ar = _e_place_coverage_client_add(desk, skiplist, ar,
285 a_x[i + 1] - w, a_y[j + 1] - h,
287 if (e_config->window_placement_policy == E_WINDOW_PLACEMENT_SMART)
288 ar = _e_place_coverage_shelf_add(desk, ar,
289 a_x[i + 1] - w, a_y[j + 1] - h,
294 *rx = a_x[i + 1] - w;
295 *ry = a_y[j + 1] - h;
296 if (ar == 0) goto done;
299 if ((a_x[i] <= (zw - w)) && (a_y[j + 1] - h > 0))
303 ar = _e_place_coverage_client_add(desk, skiplist, ar,
304 a_x[i], a_y[j + 1] - h,
306 if (e_config->window_placement_policy == E_WINDOW_PLACEMENT_SMART)
307 ar = _e_place_coverage_shelf_add(desk, ar,
308 a_x[i], a_y[j + 1] - h,
314 *ry = a_y[j + 1] - h;
315 if (ar == 0) goto done;
325 if ((*rx + w) > desk->zone->w) *rx = desk->zone->w - w;
326 if (*rx < 0) *rx = 0;
327 if ((*ry + h) > desk->zone->h) *ry = desk->zone->h - h;
328 if (*ry < 0) *ry = 0;
330 // printf("0 - PLACE %i %i | %ix%i\n", *rx, *ry, w, h);
332 *rx += desk->zone->x;
333 *ry += desk->zone->y;
346 e_place_zone_region_smart(E_Zone *zone, Eina_List *skiplist, int x, int y, int w, int h, int *rx, int *ry)
348 return e_place_desk_region_smart(e_desk_current_get(zone), skiplist,
353 e_place_zone_cursor(E_Zone *zone, int x EINA_UNUSED, int y EINA_UNUSED, int w, int h, int it, int *rx, int *ry)
355 int cursor_x = 0, cursor_y = 0;
356 int zone_right, zone_bottom;
358 E_OBJECT_CHECK_RETURN(zone, 0);
360 e_input_device_pointer_xy_get(NULL, &cursor_x, &cursor_y);
361 *rx = cursor_x - (w >> 1);
362 *ry = cursor_y - (it >> 1);
370 zone_right = zone->x + zone->w;
371 zone_bottom = zone->y + zone->h;
373 if ((*rx + w) > zone_right)
374 *rx = zone_right - w;
376 if ((*ry + h) > zone_bottom)
377 *ry = zone_bottom - h;
383 e_place_zone_manual(E_Zone *zone, int w, int h, int *rx, int *ry)
385 int cursor_x = 0, cursor_y = 0;
387 E_OBJECT_CHECK_RETURN(zone, 0);
389 e_input_device_pointer_xy_get(NULL, &cursor_x, &cursor_y);
390 if (rx) *rx = cursor_x - (w >> 1);
391 if (ry) *ry = cursor_y - (h >> 1);