1999-10-04 15:06:00 -07:00
|
|
|
/*
|
2005-03-19 08:40:18 -08:00
|
|
|
* Copyright (C) 2000-2005 Carsten Haitzler, Geoff Harrison and various contributors
|
|
|
|
* Copyright (C) 2004-2005 Kim Woelders
|
2000-03-25 17:22:00 -08:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2000-03-25 17:22:00 -08:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies of the Software, its documentation and marketing & publicity
|
|
|
|
* materials, and acknowledgment shall be given in the documentation, materials
|
|
|
|
* and software packages that this Software was used.
|
2000-03-25 17:22:00 -08:00
|
|
|
*
|
1999-10-04 15:06:00 -07:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
1999-08-17 15:56:46 -07:00
|
|
|
#include "E.h"
|
2005-08-21 06:21:48 -07:00
|
|
|
#include "buttons.h"
|
2005-09-04 00:27:20 -07:00
|
|
|
#include "desktops.h"
|
2005-07-16 09:57:45 -07:00
|
|
|
#include "ewins.h"
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2004-02-08 08:17:58 -08:00
|
|
|
static int
|
1999-08-17 15:56:46 -07:00
|
|
|
ArrangeAddToList(int **array, int current_size, int value)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < current_size; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
if (value < (*array)[i])
|
|
|
|
{
|
|
|
|
for (j = current_size; j > i; j--)
|
|
|
|
(*array)[j] = (*array)[j - 1];
|
|
|
|
(*array)[i] = value;
|
2005-01-25 13:58:28 -08:00
|
|
|
return current_size + 1;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
else if (value == (*array)[i])
|
2005-01-25 13:58:28 -08:00
|
|
|
return current_size;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
(*array)[current_size] = value;
|
2005-01-25 13:58:28 -08:00
|
|
|
return current_size + 1;
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
2004-02-08 08:17:58 -08:00
|
|
|
static void
|
1999-08-17 15:56:46 -07:00
|
|
|
ArrangeSwapList(RectBox * list, int a, int b)
|
|
|
|
{
|
|
|
|
RectBox bb;
|
|
|
|
|
|
|
|
bb.data = list[a].data;
|
|
|
|
bb.x = list[a].x;
|
|
|
|
bb.y = list[a].y;
|
|
|
|
bb.w = list[a].w;
|
|
|
|
bb.h = list[a].h;
|
|
|
|
list[a].data = list[b].data;
|
|
|
|
list[a].x = list[b].x;
|
|
|
|
list[a].y = list[b].y;
|
|
|
|
list[a].w = list[b].w;
|
|
|
|
list[a].h = list[b].h;
|
|
|
|
list[b].data = bb.data;
|
|
|
|
list[b].x = bb.x;
|
|
|
|
list[b].y = bb.y;
|
|
|
|
list[b].w = bb.w;
|
|
|
|
list[b].h = bb.h;
|
|
|
|
}
|
|
|
|
|
1999-10-08 19:01:06 -07:00
|
|
|
void
|
1999-08-17 15:56:46 -07:00
|
|
|
ArrangeRects(RectBox * fixed, int fixed_count, RectBox * floating,
|
2003-05-22 12:15:03 -07:00
|
|
|
int floating_count, RectBox * sorted, int startx, int starty,
|
|
|
|
int width, int height, int policy, char initial_window)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
int num_sorted = 0;
|
|
|
|
int xsize = 0, ysize = 0;
|
|
|
|
int *xarray = NULL, *yarray = NULL;
|
|
|
|
int *leftover = NULL;
|
1999-10-26 06:38:33 -07:00
|
|
|
int i, j, k, x, y, x1, x2, y1, y2;
|
1999-08-17 15:56:46 -07:00
|
|
|
unsigned char *filled = NULL;
|
|
|
|
RectBox *spaces = NULL;
|
1999-10-26 06:38:33 -07:00
|
|
|
int num_spaces = 0;
|
1999-08-17 15:56:46 -07:00
|
|
|
int sort;
|
1999-10-26 06:38:33 -07:00
|
|
|
int a1, a2;
|
|
|
|
int num_leftover = 0;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2003-06-15 14:43:06 -07:00
|
|
|
#define Filled(x,y) (filled[(y * (xsize - 1)) + x])
|
|
|
|
|
2000-03-25 17:22:00 -08:00
|
|
|
if (initial_window)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-07-20 11:02:16 -07:00
|
|
|
int xx1, yy1, xx2, yy2;
|
|
|
|
|
2004-07-02 17:58:19 -07:00
|
|
|
GetPointerScreenAvailableArea(&xx1, &yy1, &xx2, &yy2);
|
2003-07-20 11:02:16 -07:00
|
|
|
xx2 += xx1;
|
|
|
|
yy2 += yy1;
|
|
|
|
if (startx < xx1)
|
|
|
|
startx = xx1;
|
|
|
|
if (width > xx2)
|
|
|
|
width = xx2;
|
|
|
|
if (starty < yy1)
|
|
|
|
starty = yy1;
|
|
|
|
if (height > yy2)
|
|
|
|
height = yy2;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2000-03-25 17:22:00 -08:00
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
switch (policy)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
case ARRANGE_VERBATIM:
|
|
|
|
break;
|
|
|
|
case ARRANGE_BY_SIZE:
|
|
|
|
sort = 0;
|
|
|
|
while (!sort)
|
|
|
|
{
|
|
|
|
sort = 1;
|
|
|
|
for (i = 0; i < floating_count - 1; i++)
|
|
|
|
{
|
|
|
|
a1 = floating[i].w * floating[i].h;
|
|
|
|
a2 = floating[i + 1].w * floating[i + 1].h;
|
|
|
|
if (a2 > a1)
|
|
|
|
{
|
|
|
|
sort = 0;
|
|
|
|
ArrangeSwapList(floating, i, i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ARRANGE_BY_POSITION:
|
|
|
|
sort = 0;
|
|
|
|
while (!sort)
|
|
|
|
{
|
|
|
|
sort = 1;
|
|
|
|
for (i = 0; i < floating_count - 1; i++)
|
|
|
|
{
|
|
|
|
a1 = floating[i].x + floating[i].y;
|
|
|
|
a2 = (floating[i + 1].x + (floating[i + 1].w >> 1)) +
|
|
|
|
(floating[i + 1].y + (floating[i + 1].h >> 1));
|
|
|
|
if (a2 < a1)
|
|
|
|
{
|
|
|
|
sort = 0;
|
|
|
|
ArrangeSwapList(floating, i, i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
/* for every floating rect in order, "fit" it into the sorted list */
|
1999-10-26 06:38:33 -07:00
|
|
|
i = ((fixed_count + floating_count) * 2) + 2;
|
|
|
|
xarray = Emalloc(i * sizeof(int));
|
|
|
|
yarray = Emalloc(i * sizeof(int));
|
|
|
|
filled = Emalloc(i * i * sizeof(char));
|
1999-08-17 15:56:46 -07:00
|
|
|
|
1999-10-26 06:38:33 -07:00
|
|
|
spaces = Emalloc(i * i * sizeof(RectBox));
|
1999-08-17 15:56:46 -07:00
|
|
|
if (floating_count)
|
|
|
|
leftover = Emalloc(floating_count * sizeof(int));
|
|
|
|
|
2003-06-15 14:43:06 -07:00
|
|
|
if (!xarray || !yarray || !filled || !spaces)
|
2004-03-20 07:49:05 -08:00
|
|
|
goto done;
|
2003-06-15 14:43:06 -07:00
|
|
|
|
1999-10-26 06:38:33 -07:00
|
|
|
/* copy "fixed" rects into the sorted list */
|
1999-08-17 15:56:46 -07:00
|
|
|
for (i = 0; i < fixed_count; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
sorted[num_sorted].data = fixed[i].data;
|
|
|
|
sorted[num_sorted].x = fixed[i].x;
|
|
|
|
sorted[num_sorted].y = fixed[i].y;
|
|
|
|
sorted[num_sorted].w = fixed[i].w;
|
|
|
|
sorted[num_sorted].h = fixed[i].h;
|
|
|
|
sorted[num_sorted].p = fixed[i].p;
|
|
|
|
num_sorted++;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-10-26 06:38:33 -07:00
|
|
|
/* go through each floating rect in order and "fit" it in */
|
1999-08-17 15:56:46 -07:00
|
|
|
for (i = 0; i < floating_count; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
xsize = 0;
|
|
|
|
ysize = 0;
|
1999-10-26 06:38:33 -07:00
|
|
|
/* put all the sorted rects into the xy arrays */
|
2003-05-22 12:15:03 -07:00
|
|
|
xsize = ArrangeAddToList(&xarray, xsize, startx);
|
|
|
|
xsize = ArrangeAddToList(&xarray, xsize, width);
|
|
|
|
ysize = ArrangeAddToList(&yarray, ysize, starty);
|
|
|
|
ysize = ArrangeAddToList(&yarray, ysize, height);
|
|
|
|
for (j = 0; j < num_sorted; j++)
|
|
|
|
{
|
|
|
|
if (sorted[j].x < width)
|
|
|
|
xsize = ArrangeAddToList(&xarray, xsize, sorted[j].x);
|
|
|
|
if ((sorted[j].x + sorted[j].w) < width)
|
|
|
|
xsize =
|
|
|
|
ArrangeAddToList(&xarray, xsize, sorted[j].x + sorted[j].w);
|
|
|
|
if (sorted[j].y < height)
|
|
|
|
ysize = ArrangeAddToList(&yarray, ysize, sorted[j].y);
|
|
|
|
if ((sorted[j].y + sorted[j].h) < height)
|
|
|
|
ysize =
|
|
|
|
ArrangeAddToList(&yarray, ysize, sorted[j].y + sorted[j].h);
|
|
|
|
}
|
1999-10-26 06:38:33 -07:00
|
|
|
/* fill the allocation array */
|
2005-10-30 11:40:49 -08:00
|
|
|
for (j = 0; j < (xsize - 1) * (ysize - 1); filled[j++] = 0)
|
|
|
|
;
|
2003-05-22 12:15:03 -07:00
|
|
|
for (j = 0; j < num_sorted; j++)
|
|
|
|
{
|
|
|
|
x1 = -1;
|
|
|
|
x2 = -1;
|
|
|
|
y1 = -1;
|
|
|
|
y2 = -1;
|
|
|
|
for (k = 0; k < xsize - 1; k++)
|
|
|
|
{
|
|
|
|
if (sorted[j].x == xarray[k])
|
|
|
|
{
|
|
|
|
x1 = k;
|
|
|
|
x2 = k;
|
|
|
|
}
|
|
|
|
if (sorted[j].x + sorted[j].w == xarray[k + 1])
|
|
|
|
x2 = k;
|
|
|
|
}
|
|
|
|
for (k = 0; k < ysize - 1; k++)
|
|
|
|
{
|
|
|
|
if (sorted[j].y == yarray[k])
|
|
|
|
{
|
|
|
|
y1 = k;
|
|
|
|
y2 = k;
|
|
|
|
}
|
|
|
|
if (sorted[j].y + sorted[j].h == yarray[k + 1])
|
|
|
|
y2 = k;
|
|
|
|
}
|
|
|
|
if ((x1 >= 0) && (x2 >= 0) && (y1 >= 0) && (y2 >= 0))
|
|
|
|
{
|
|
|
|
for (y = y1; y <= y2; y++)
|
|
|
|
{
|
|
|
|
for (x = x1; x <= x2; x++)
|
|
|
|
{
|
2003-06-15 14:43:06 -07:00
|
|
|
if (Filled(x, y) <= sorted[j].p)
|
|
|
|
Filled(x, y) = sorted[j].p + 1;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
num_spaces = 0;
|
1999-10-26 06:38:33 -07:00
|
|
|
/* create list of all "spaces" */
|
2003-05-22 12:15:03 -07:00
|
|
|
for (y = 0; y < ysize - 1; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < xsize - 1; x++)
|
|
|
|
{
|
1999-10-26 06:38:33 -07:00
|
|
|
/* if the square is empty (lowe prioiryt suares filled) "grow" the space */
|
2003-06-15 14:43:06 -07:00
|
|
|
if (Filled(x, y) <= floating[i].p)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
|
|
|
int can_expand_x = 1;
|
|
|
|
int can_expand_y = 1;
|
1999-10-26 06:38:33 -07:00
|
|
|
|
2003-05-22 12:15:03 -07:00
|
|
|
x1 = x + 1;
|
|
|
|
y1 = y + 1;
|
2003-06-15 14:43:06 -07:00
|
|
|
Filled(x, y) = 100;
|
2003-05-22 12:15:03 -07:00
|
|
|
if (x >= xsize - 2)
|
|
|
|
can_expand_x = 0;
|
|
|
|
if (y >= ysize - 2)
|
|
|
|
can_expand_y = 0;
|
|
|
|
while ((can_expand_x) || (can_expand_y))
|
|
|
|
{
|
|
|
|
if (x1 >= xsize - 1)
|
|
|
|
can_expand_x = 0;
|
|
|
|
if (y1 >= ysize - 1)
|
|
|
|
can_expand_y = 0;
|
|
|
|
if (can_expand_x)
|
|
|
|
{
|
|
|
|
for (j = y; j < y1; j++)
|
|
|
|
{
|
2003-06-15 14:43:06 -07:00
|
|
|
if (Filled(x1, j) >= floating[i].p + 1)
|
2003-05-22 12:15:03 -07:00
|
|
|
can_expand_x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (can_expand_x)
|
|
|
|
x1++;
|
|
|
|
if (can_expand_y)
|
|
|
|
{
|
|
|
|
for (j = x; j < x1; j++)
|
|
|
|
{
|
2003-06-15 14:43:06 -07:00
|
|
|
if (Filled(j, y1) >= floating[i].p + 1)
|
2003-05-22 12:15:03 -07:00
|
|
|
can_expand_y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (can_expand_y)
|
|
|
|
y1++;
|
|
|
|
}
|
|
|
|
spaces[num_spaces].x = xarray[x];
|
|
|
|
spaces[num_spaces].y = yarray[y];
|
|
|
|
spaces[num_spaces].w = xarray[x1] - xarray[x];
|
|
|
|
spaces[num_spaces].h = yarray[y1] - yarray[y];
|
|
|
|
spaces[num_spaces].p = 0;
|
|
|
|
num_spaces++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-26 06:38:33 -07:00
|
|
|
/* find the first space that fits */
|
2003-05-22 12:15:03 -07:00
|
|
|
k = -1;
|
|
|
|
sort = 0x7fffffff;
|
|
|
|
for (j = 0; j < num_spaces; j++)
|
|
|
|
{
|
|
|
|
if ((spaces[j].w >= floating[i].w)
|
|
|
|
&& (spaces[j].h >= floating[i].h))
|
|
|
|
{
|
|
|
|
if (spaces[j].x >= startx)
|
|
|
|
{
|
|
|
|
if ((spaces[j].x + spaces[j].w) <= width)
|
|
|
|
{
|
|
|
|
if (spaces[j].y >= starty)
|
|
|
|
{
|
|
|
|
if ((spaces[j].y + spaces[j].h) <= height)
|
|
|
|
{
|
|
|
|
if (policy == ARRANGE_BY_POSITION)
|
|
|
|
{
|
|
|
|
a1 = (spaces[j].x +
|
|
|
|
(spaces[j].w >> 1)) -
|
|
|
|
(floating[i].x +
|
|
|
|
(floating[i].w >> 1));
|
|
|
|
a2 = (spaces[j].y +
|
|
|
|
(spaces[j].h >> 1)) -
|
|
|
|
(floating[i].y +
|
|
|
|
(floating[i].h >> 1));
|
|
|
|
if (a1 < 0)
|
|
|
|
a1 = -a1;
|
|
|
|
if (a2 < 0)
|
|
|
|
a2 = -a2;
|
|
|
|
if ((a1 + a2) < sort)
|
|
|
|
{
|
|
|
|
sort = a1 + a2;
|
|
|
|
k = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
k = j;
|
|
|
|
j = num_spaces;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (k >= 0)
|
|
|
|
{
|
|
|
|
if (policy == ARRANGE_BY_POSITION)
|
|
|
|
{
|
|
|
|
a1 = (spaces[k].x + (spaces[k].w >> 1)) - (floating[i].x +
|
|
|
|
(floating[i].w >>
|
|
|
|
1));
|
|
|
|
a2 = (spaces[k].y + (spaces[k].h >> 1)) - (floating[i].y +
|
|
|
|
(floating[i].h >>
|
|
|
|
1));
|
|
|
|
if (a1 >= 0)
|
|
|
|
{
|
|
|
|
sorted[num_sorted].x = spaces[k].x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sorted[num_sorted].x =
|
|
|
|
spaces[k].x + spaces[k].w - floating[i].w;
|
|
|
|
}
|
|
|
|
if (a2 >= 0)
|
|
|
|
{
|
|
|
|
sorted[num_sorted].y = spaces[k].y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sorted[num_sorted].y =
|
|
|
|
spaces[k].y + spaces[k].h - floating[i].h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sorted[num_sorted].x = spaces[k].x;
|
|
|
|
sorted[num_sorted].y = spaces[k].y;
|
|
|
|
}
|
|
|
|
sorted[num_sorted].data = floating[i].data;
|
|
|
|
sorted[num_sorted].w = floating[i].w;
|
|
|
|
sorted[num_sorted].h = floating[i].h;
|
|
|
|
sorted[num_sorted].p = floating[i].p;
|
|
|
|
num_sorted++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
leftover[num_leftover++] = i;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2000-03-25 17:22:00 -08:00
|
|
|
|
2003-06-15 14:43:06 -07:00
|
|
|
/* ok we cant fit everything in this baby.... time to fit */
|
|
|
|
/* the leftovers into the leftover space */
|
1999-10-26 06:38:33 -07:00
|
|
|
for (i = 0; i < num_leftover; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
xsize = 0;
|
|
|
|
ysize = 0;
|
|
|
|
/* put all the sorted rects into the xy arrays */
|
|
|
|
xsize = ArrangeAddToList(&xarray, xsize, 0);
|
|
|
|
xsize = ArrangeAddToList(&xarray, xsize, width);
|
|
|
|
ysize = ArrangeAddToList(&yarray, ysize, 0);
|
|
|
|
ysize = ArrangeAddToList(&yarray, ysize, height);
|
|
|
|
for (j = 0; j < num_sorted; j++)
|
|
|
|
{
|
|
|
|
if (sorted[j].x < width)
|
|
|
|
xsize = ArrangeAddToList(&xarray, xsize, sorted[j].x);
|
|
|
|
if ((sorted[j].x + sorted[j].w) < width)
|
|
|
|
xsize =
|
|
|
|
ArrangeAddToList(&xarray, xsize, sorted[j].x + sorted[j].w);
|
|
|
|
if (sorted[j].y < height)
|
|
|
|
ysize = ArrangeAddToList(&yarray, ysize, sorted[j].y);
|
|
|
|
if ((sorted[j].y + sorted[j].h) < height)
|
|
|
|
ysize =
|
|
|
|
ArrangeAddToList(&yarray, ysize, sorted[j].y + sorted[j].h);
|
|
|
|
}
|
|
|
|
/* fill the allocation array */
|
2005-10-30 11:40:49 -08:00
|
|
|
for (j = 0; j < (xsize - 1) * (ysize - 1); filled[j++] = 0)
|
|
|
|
;
|
2003-05-22 12:15:03 -07:00
|
|
|
for (j = 0; j < num_sorted; j++)
|
|
|
|
{
|
|
|
|
x1 = -1;
|
|
|
|
x2 = -1;
|
|
|
|
y1 = -1;
|
|
|
|
y2 = -1;
|
|
|
|
for (k = 0; k < xsize - 1; k++)
|
|
|
|
{
|
|
|
|
if (sorted[j].x == xarray[k])
|
|
|
|
{
|
|
|
|
x1 = k;
|
|
|
|
x2 = k;
|
|
|
|
}
|
|
|
|
if (sorted[j].x + sorted[j].w == xarray[k + 1])
|
|
|
|
x2 = k;
|
|
|
|
}
|
|
|
|
for (k = 0; k < ysize - 1; k++)
|
|
|
|
{
|
|
|
|
if (sorted[j].y == yarray[k])
|
|
|
|
{
|
|
|
|
y1 = k;
|
|
|
|
y2 = k;
|
|
|
|
}
|
|
|
|
if (sorted[j].y + sorted[j].h == yarray[k + 1])
|
|
|
|
y2 = k;
|
|
|
|
}
|
|
|
|
if ((x1 >= 0) && (x2 >= 0) && (y1 >= 0) && (y2 >= 0))
|
|
|
|
{
|
|
|
|
for (y = y1; y <= y2; y++)
|
|
|
|
{
|
|
|
|
for (x = x1; x <= x2; x++)
|
|
|
|
{
|
2003-06-15 14:43:06 -07:00
|
|
|
if (Filled(x, y) <= sorted[j].p)
|
|
|
|
Filled(x, y) = sorted[j].p + 1;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
num_spaces = 0;
|
|
|
|
/* create list of all "spaces" */
|
|
|
|
for (y = 0; y < ysize - 1; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < xsize - 1; x++)
|
|
|
|
{
|
|
|
|
/* if the square is empty "grow" the space */
|
2003-06-15 14:43:06 -07:00
|
|
|
if (Filled(x, y) <= floating[leftover[i]].p)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
|
|
|
int can_expand_x = 1;
|
|
|
|
int can_expand_y = 1;
|
|
|
|
char fitswin = 1;
|
1999-10-26 06:38:33 -07:00
|
|
|
|
2003-05-22 12:15:03 -07:00
|
|
|
x1 = x + 1;
|
|
|
|
y1 = y + 1;
|
|
|
|
if (x >= xsize - 2)
|
|
|
|
can_expand_x = 0;
|
|
|
|
if (y >= ysize - 2)
|
|
|
|
can_expand_y = 0;
|
|
|
|
while ((can_expand_x) || (can_expand_y))
|
|
|
|
{
|
|
|
|
if (x1 >= xsize - 1)
|
|
|
|
can_expand_x = 0;
|
|
|
|
if (y1 >= ysize - 1)
|
|
|
|
can_expand_y = 0;
|
|
|
|
if (can_expand_x)
|
|
|
|
{
|
|
|
|
for (j = y; j < y1; j++)
|
|
|
|
{
|
2003-06-15 14:43:06 -07:00
|
|
|
if (Filled(x1, j) >
|
|
|
|
floating[leftover[i]].p + 1)
|
|
|
|
can_expand_x = 0;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (can_expand_x)
|
|
|
|
x1++;
|
|
|
|
if (can_expand_y)
|
|
|
|
{
|
|
|
|
for (j = x; j < x1; j++)
|
|
|
|
{
|
2003-06-15 14:43:06 -07:00
|
|
|
if (Filled(j, y1) >
|
|
|
|
floating[leftover[i]].p + 1)
|
|
|
|
can_expand_y = 0;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (can_expand_y)
|
|
|
|
y1++;
|
|
|
|
}
|
|
|
|
spaces[num_spaces].x = xarray[x];
|
|
|
|
spaces[num_spaces].y = yarray[y];
|
|
|
|
spaces[num_spaces].w = xarray[x1] - xarray[x];
|
|
|
|
spaces[num_spaces].h = yarray[y1] - yarray[y];
|
|
|
|
spaces[num_spaces].p = fitswin;
|
|
|
|
num_spaces++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* find the first space that fits */
|
|
|
|
k = -1;
|
|
|
|
sort = 0x7fffffff;
|
|
|
|
a1 = floating[leftover[i]].w * floating[leftover[i]].h;
|
|
|
|
k = -1;
|
|
|
|
for (j = 0; j < num_spaces; j++)
|
|
|
|
{
|
|
|
|
a2 = spaces[j].w * spaces[j].h;
|
|
|
|
if ((a2 != 0) && ((a1 - a2) < sort) && (spaces[j].p))
|
|
|
|
{
|
|
|
|
k = j;
|
|
|
|
sort = a1 - a2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if there's a small space ... */
|
|
|
|
if (k >= 0)
|
|
|
|
{
|
|
|
|
sorted[num_sorted].x = spaces[k].x;
|
|
|
|
sorted[num_sorted].y = spaces[k].y;
|
|
|
|
sorted[num_sorted].data = floating[leftover[i]].data;
|
|
|
|
sorted[num_sorted].w = floating[leftover[i]].w;
|
|
|
|
sorted[num_sorted].h = floating[leftover[i]].h;
|
|
|
|
if ((sorted[num_sorted].x + sorted[num_sorted].w) > width)
|
|
|
|
sorted[num_sorted].x = width - sorted[num_sorted].w;
|
|
|
|
if ((sorted[num_sorted].y + sorted[num_sorted].h) > height)
|
|
|
|
sorted[num_sorted].y = height - sorted[num_sorted].h;
|
|
|
|
if (sorted[num_sorted].x < startx)
|
|
|
|
sorted[num_sorted].x = startx;
|
|
|
|
if (sorted[num_sorted].y < starty)
|
|
|
|
sorted[num_sorted].y = starty;
|
|
|
|
num_sorted++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* there is no room - put it centered */
|
|
|
|
/* (but dont put top left off screen) */
|
|
|
|
sorted[num_sorted].data = floating[leftover[i]].data;
|
|
|
|
sorted[num_sorted].x = (width - floating[leftover[i]].w) / 2;
|
|
|
|
sorted[num_sorted].y = (height - floating[leftover[i]].h) / 2;
|
|
|
|
sorted[num_sorted].w = floating[leftover[i]].w;
|
|
|
|
sorted[num_sorted].h = floating[leftover[i]].h;
|
|
|
|
if (sorted[num_sorted].x < startx)
|
|
|
|
sorted[num_sorted].x = startx;
|
|
|
|
if (sorted[num_sorted].y < starty)
|
|
|
|
sorted[num_sorted].y = starty;
|
|
|
|
num_sorted++;
|
|
|
|
}
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-10-26 06:38:33 -07:00
|
|
|
for (i = 0; i < num_sorted; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
if ((sorted[i].x + sorted[i].w) > width)
|
2004-05-04 12:04:42 -07:00
|
|
|
sorted[i].x = VRoot.w - sorted[i].w;
|
2003-05-22 12:15:03 -07:00
|
|
|
if ((sorted[i].y + sorted[i].h) > height)
|
2004-05-04 12:04:42 -07:00
|
|
|
sorted[i].y = VRoot.h - sorted[i].h;
|
2003-05-22 12:15:03 -07:00
|
|
|
if (sorted[i].x < startx)
|
|
|
|
sorted[i].x = startx;
|
|
|
|
if (sorted[i].y < starty)
|
|
|
|
sorted[i].y = starty;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2003-06-15 14:43:06 -07:00
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
done:
|
2003-06-15 14:43:06 -07:00
|
|
|
/* free up memory */
|
|
|
|
if (xarray)
|
|
|
|
Efree(xarray);
|
|
|
|
if (yarray)
|
|
|
|
Efree(yarray);
|
|
|
|
if (filled)
|
|
|
|
Efree(filled);
|
|
|
|
if (spaces)
|
|
|
|
Efree(spaces);
|
|
|
|
if (leftover)
|
|
|
|
Efree(leftover);
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
1999-10-08 19:01:06 -07:00
|
|
|
void
|
1999-08-17 15:56:46 -07:00
|
|
|
SnapEwin(EWin * ewin, int dx, int dy, int *new_dx, int *new_dy)
|
|
|
|
{
|
2005-08-07 07:06:52 -07:00
|
|
|
EWin *const *lst1;
|
1999-08-17 15:56:46 -07:00
|
|
|
EWin **lst, **gwins;
|
|
|
|
int gnum, num, i, j, screen_snap_dist, odx, ody;
|
1999-09-08 19:25:18 -07:00
|
|
|
static char last_res = 0;
|
2003-07-20 11:02:16 -07:00
|
|
|
int top_bound, bottom_bound, left_bound, right_bound, w, h;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
1999-09-08 17:39:43 -07:00
|
|
|
if (!ewin)
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
1999-09-08 17:39:43 -07:00
|
|
|
|
2004-03-20 07:49:05 -08:00
|
|
|
if (!Conf.snap.enable)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
*new_dx = dx;
|
|
|
|
*new_dy = dy;
|
2005-01-25 13:58:28 -08:00
|
|
|
return;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2000-03-26 13:30:58 -08:00
|
|
|
|
2004-07-02 17:58:19 -07:00
|
|
|
ScreenGetAvailableArea(ewin->shape_x, ewin->shape_y,
|
|
|
|
&left_bound, &top_bound, &w, &h);
|
2003-07-20 11:02:16 -07:00
|
|
|
right_bound = left_bound + w;
|
|
|
|
bottom_bound = top_bound + h;
|
2004-03-20 07:49:05 -08:00
|
|
|
screen_snap_dist = Mode.constrained ? (w + h) : Conf.snap.screen_snap_dist;
|
2000-03-26 13:30:58 -08:00
|
|
|
|
2005-08-07 07:06:52 -07:00
|
|
|
lst = NULL;
|
|
|
|
lst1 = EwinListOrderGet(&num);
|
|
|
|
if (lst1)
|
|
|
|
{
|
|
|
|
lst = malloc(num * sizeof(EWin *));
|
2005-10-30 11:40:49 -08:00
|
|
|
if (!lst)
|
|
|
|
return;
|
2005-08-07 07:06:52 -07:00
|
|
|
memcpy(lst, lst1, num * sizeof(EWin *));
|
|
|
|
}
|
2004-12-28 15:46:49 -08:00
|
|
|
gwins = ListWinGroupMembersForEwin(ewin, GROUP_ACTION_MOVE, Mode.nogroup
|
2004-05-19 14:41:03 -07:00
|
|
|
|| Mode.move.swap, &gnum);
|
1999-08-17 15:56:46 -07:00
|
|
|
if (gwins)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
for (i = 0; i < gnum; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < num; j++)
|
|
|
|
{
|
|
|
|
if ((lst[j] == gwins[i]) || (lst[j] == ewin))
|
|
|
|
lst[j] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Efree(gwins);
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-05-18 16:31:07 -07:00
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
odx = dx;
|
|
|
|
ody = dy;
|
|
|
|
if (dx < 0)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (IN_BELOW(ewin->shape_x + dx, left_bound, screen_snap_dist)
|
|
|
|
&& (ewin->shape_x >= left_bound))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
dx = left_bound - ewin->shape_x;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
else if (lst)
|
|
|
|
{
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (lst[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if ((EoGetDesk(ewin) == EoGetDesk(lst[i]) ||
|
|
|
|
EoIsSticky(lst[i])) && !(EoIsFloating(lst[i])) &&
|
2005-07-08 09:48:19 -07:00
|
|
|
!lst[i]->state.iconified && !lst[i]->props.ignorearrange)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (IN_BELOW
|
2004-12-28 15:46:49 -08:00
|
|
|
(ewin->shape_x + dx,
|
|
|
|
EoGetX(lst[i]) + EoGetW(lst[i]) - 1,
|
2004-05-18 16:31:07 -07:00
|
|
|
Conf.snap.edge_snap_dist)
|
2004-12-28 15:46:49 -08:00
|
|
|
&& SPANS_COMMON(ewin->shape_y, EoGetH(ewin),
|
|
|
|
EoGetY(lst[i]), EoGetH(lst[i]))
|
|
|
|
&& (ewin->shape_x >=
|
|
|
|
(EoGetX(lst[i]) + EoGetW(lst[i]))))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
dx =
|
|
|
|
(EoGetX(lst[i]) + EoGetW(lst[i])) -
|
|
|
|
ewin->shape_x;
|
2004-05-18 16:31:07 -07:00
|
|
|
break;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-18 16:31:07 -07:00
|
|
|
if ((ewin->req_x - ewin->shape_x) > 0)
|
2003-05-22 12:15:03 -07:00
|
|
|
dx = 0;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
else if (dx > 0)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (IN_ABOVE
|
2004-12-28 15:46:49 -08:00
|
|
|
(ewin->shape_x + EoGetW(ewin) + dx, right_bound, screen_snap_dist)
|
|
|
|
&& ((ewin->shape_x + EoGetW(ewin)) <= right_bound))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
dx = right_bound - (ewin->shape_x + EoGetW(ewin));
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
else if (lst)
|
|
|
|
{
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (lst[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if ((EoGetDesk(ewin) == EoGetDesk(lst[i]) ||
|
|
|
|
EoIsSticky(lst[i])) && !(EoIsFloating(lst[i])) &&
|
2005-07-08 09:48:19 -07:00
|
|
|
!lst[i]->state.iconified && !lst[i]->props.ignorearrange)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
if (IN_ABOVE
|
|
|
|
(ewin->shape_x + EoGetW(ewin) + dx - 1,
|
|
|
|
EoGetX(lst[i]), Conf.snap.edge_snap_dist)
|
|
|
|
&& SPANS_COMMON(ewin->shape_y, EoGetH(ewin),
|
|
|
|
EoGetY(lst[i]), EoGetH(lst[i]))
|
|
|
|
&& ((ewin->shape_x + EoGetW(ewin)) <=
|
|
|
|
EoGetX(lst[i])))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
dx =
|
|
|
|
EoGetX(lst[i]) - (ewin->shape_x + EoGetW(ewin));
|
2004-05-18 16:31:07 -07:00
|
|
|
break;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-18 16:31:07 -07:00
|
|
|
if ((ewin->req_x - ewin->shape_x) < 0)
|
2003-05-22 12:15:03 -07:00
|
|
|
dx = 0;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-05-18 16:31:07 -07:00
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
if (dy < 0)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (IN_BELOW(ewin->shape_y + dy, top_bound, screen_snap_dist)
|
|
|
|
&& (ewin->shape_y >= top_bound))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
dy = top_bound - ewin->shape_y;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
else if (lst)
|
|
|
|
{
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (lst[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if ((EoGetDesk(ewin) == EoGetDesk(lst[i]) ||
|
|
|
|
EoIsSticky(lst[i])) && !(EoIsFloating(lst[i])) &&
|
2005-07-08 09:48:19 -07:00
|
|
|
!lst[i]->state.iconified && !lst[i]->props.ignorearrange)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (IN_BELOW
|
2004-12-28 15:46:49 -08:00
|
|
|
(ewin->shape_y + dy,
|
|
|
|
EoGetY(lst[i]) + EoGetH(lst[i]) - 1,
|
2004-05-18 16:31:07 -07:00
|
|
|
Conf.snap.edge_snap_dist)
|
2004-12-28 15:46:49 -08:00
|
|
|
&& SPANS_COMMON(ewin->shape_x, EoGetW(ewin),
|
|
|
|
EoGetX(lst[i]), EoGetW(lst[i]))
|
|
|
|
&& (ewin->shape_y >=
|
|
|
|
(EoGetY(lst[i]) + EoGetH(lst[i]))))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
dy =
|
|
|
|
(EoGetY(lst[i]) + EoGetH(lst[i])) -
|
|
|
|
ewin->shape_y;
|
2004-05-18 16:31:07 -07:00
|
|
|
break;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-18 16:31:07 -07:00
|
|
|
if ((ewin->req_y - ewin->shape_y) > 0)
|
2003-05-22 12:15:03 -07:00
|
|
|
dy = 0;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
else if (dy > 0)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (IN_ABOVE
|
2004-12-28 15:46:49 -08:00
|
|
|
(ewin->shape_y + EoGetH(ewin) + dy, bottom_bound,
|
|
|
|
screen_snap_dist)
|
|
|
|
&& ((ewin->shape_y + EoGetH(ewin)) <= bottom_bound))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
dy = bottom_bound - (ewin->shape_y + EoGetH(ewin));
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
else if (lst)
|
|
|
|
{
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2004-05-18 16:31:07 -07:00
|
|
|
if (lst[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
2004-12-28 15:46:49 -08:00
|
|
|
if ((EoGetDesk(ewin) == EoGetDesk(lst[i]) ||
|
|
|
|
EoIsSticky(lst[i])) && !(EoIsFloating(lst[i])) &&
|
2005-07-08 09:48:19 -07:00
|
|
|
!lst[i]->state.iconified && !lst[i]->props.ignorearrange)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
if (IN_ABOVE
|
|
|
|
(ewin->shape_y + EoGetH(ewin) + dy - 1,
|
|
|
|
EoGetY(lst[i]), Conf.snap.edge_snap_dist)
|
|
|
|
&& SPANS_COMMON(ewin->shape_x, EoGetW(ewin),
|
|
|
|
EoGetX(lst[i]), EoGetW(lst[i]))
|
|
|
|
&& ((ewin->shape_y + EoGetH(ewin)) <=
|
|
|
|
EoGetY(lst[i])))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
dy =
|
|
|
|
EoGetY(lst[i]) - (ewin->shape_y + EoGetH(ewin));
|
2004-05-18 16:31:07 -07:00
|
|
|
break;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-18 16:31:07 -07:00
|
|
|
if ((ewin->req_y - ewin->shape_y) < 0)
|
2003-05-22 12:15:03 -07:00
|
|
|
dy = 0;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-05-18 16:31:07 -07:00
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
if (lst)
|
|
|
|
Efree(lst);
|
2004-05-18 16:31:07 -07:00
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
if ((odx != dx) || (ody != dy))
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
if (!last_res)
|
|
|
|
{
|
2004-01-03 04:29:58 -08:00
|
|
|
/* SoundPlay("SOUND_MOVE_RESIST"); */
|
2003-05-22 12:15:03 -07:00
|
|
|
last_res = 1;
|
|
|
|
}
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-09-08 19:25:18 -07:00
|
|
|
else
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
last_res = 0;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-08-17 15:56:46 -07:00
|
|
|
*new_dx = dx;
|
|
|
|
*new_dy = dy;
|
|
|
|
}
|
1999-10-01 14:38:22 -07:00
|
|
|
|
1999-10-08 19:01:06 -07:00
|
|
|
void
|
1999-10-01 14:38:22 -07:00
|
|
|
ArrangeEwin(EWin * ewin)
|
2003-05-16 11:06:14 -07:00
|
|
|
{
|
2005-04-28 15:01:53 -07:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
ArrangeEwinXY(ewin, &x, &y);
|
2005-07-10 01:31:15 -07:00
|
|
|
EwinMove(ewin, x, y);
|
2003-05-16 11:06:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-11-13 04:40:13 -08:00
|
|
|
ArrangeEwinCentered(EWin * ewin)
|
2003-05-16 11:06:14 -07:00
|
|
|
{
|
2005-04-28 15:01:53 -07:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
ArrangeEwinCenteredXY(ewin, &x, &y);
|
2005-07-10 01:31:15 -07:00
|
|
|
EwinMove(ewin, x, y);
|
2003-05-16 11:06:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-09-04 00:27:20 -07:00
|
|
|
EWinIsOnViewport(EWin * ewin, Desk * dsk)
|
2003-05-16 11:06:14 -07:00
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
int ax, ay;
|
|
|
|
|
|
|
|
if (EoIsSticky(ewin))
|
2003-05-16 11:06:14 -07:00
|
|
|
return 1;
|
|
|
|
|
2005-09-04 00:27:20 -07:00
|
|
|
DeskGetArea(dsk, &ax, &ay);
|
|
|
|
if (EoGetDesk(ewin) == dsk && ewin->area_x == ax && ewin->area_y == ay)
|
2003-05-16 11:06:14 -07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ArrangeEwinXY(EWin * ewin, int *px, int *py)
|
1999-10-01 14:38:22 -07:00
|
|
|
{
|
2004-03-26 13:21:47 -08:00
|
|
|
EWin *const *lst;
|
1999-10-01 14:38:22 -07:00
|
|
|
Button **blst;
|
|
|
|
int i, j, num;
|
|
|
|
RectBox *fixed, *ret, newrect;
|
|
|
|
|
1999-10-07 12:28:53 -07:00
|
|
|
fixed = NULL;
|
|
|
|
ret = NULL;
|
2003-05-16 11:06:14 -07:00
|
|
|
|
2004-04-01 14:41:22 -08:00
|
|
|
lst = EwinListGetAll(&num);
|
1999-10-01 14:38:22 -07:00
|
|
|
if ((lst) && (num > 0))
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
fixed = Emalloc(sizeof(RectBox) * num);
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
EWin *e = lst[i];
|
2003-05-16 11:06:14 -07:00
|
|
|
|
2003-05-22 12:15:03 -07:00
|
|
|
if (e == ewin ||
|
2005-07-08 09:48:19 -07:00
|
|
|
e->state.iconified || e->props.ignorearrange ||
|
|
|
|
EoGetLayer(e) == 0 || !EWinIsOnViewport(e, EoGetDesk(ewin)))
|
2003-05-22 12:15:03 -07:00
|
|
|
continue;
|
2003-05-16 11:06:14 -07:00
|
|
|
|
2003-05-22 12:15:03 -07:00
|
|
|
fixed[j].data = e;
|
2004-12-28 15:46:49 -08:00
|
|
|
fixed[j].x = EoGetX(e);
|
|
|
|
fixed[j].y = EoGetY(e);
|
|
|
|
fixed[j].w = EoGetW(e);
|
|
|
|
fixed[j].h = EoGetH(e);
|
2003-05-22 12:15:03 -07:00
|
|
|
if (fixed[j].x < 0)
|
|
|
|
{
|
|
|
|
fixed[j].w += fixed[j].x;
|
|
|
|
fixed[j].x = 0;
|
|
|
|
}
|
2004-05-04 12:04:42 -07:00
|
|
|
if ((fixed[j].x + fixed[j].w) > VRoot.w)
|
|
|
|
fixed[j].w = VRoot.w - fixed[j].x;
|
2003-05-22 12:15:03 -07:00
|
|
|
if (fixed[j].y < 0)
|
|
|
|
{
|
|
|
|
fixed[j].h += fixed[j].y;
|
|
|
|
fixed[j].y = 0;
|
|
|
|
}
|
2004-05-04 12:04:42 -07:00
|
|
|
if ((fixed[j].y + fixed[j].h) > VRoot.h)
|
|
|
|
fixed[j].h = VRoot.h - fixed[j].y;
|
2003-05-22 12:15:03 -07:00
|
|
|
if ((fixed[j].w <= 0) || (fixed[j].h <= 0))
|
|
|
|
continue;
|
2003-05-16 11:06:14 -07:00
|
|
|
|
2005-07-08 09:48:19 -07:00
|
|
|
if (e->props.never_use_area)
|
2003-05-22 12:15:03 -07:00
|
|
|
fixed[j].p = 50;
|
|
|
|
else
|
2004-12-28 15:46:49 -08:00
|
|
|
fixed[j].p = EoGetLayer(e);
|
2003-05-22 12:15:03 -07:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
blst = (Button **) ListItemType(&num, LIST_TYPE_BUTTON);
|
|
|
|
if (blst)
|
|
|
|
{
|
|
|
|
fixed = Erealloc(fixed, sizeof(RectBox) * (num + j));
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2004-12-28 15:46:49 -08:00
|
|
|
if (ButtonGetInfo(blst[i], &fixed[j], EoGetDesk(ewin)))
|
2003-05-22 12:15:03 -07:00
|
|
|
continue;
|
2003-05-16 11:06:14 -07:00
|
|
|
|
2003-05-22 12:15:03 -07:00
|
|
|
if (fixed[j].x < 0)
|
|
|
|
{
|
|
|
|
fixed[j].w += fixed[j].x;
|
|
|
|
fixed[j].x = 0;
|
|
|
|
}
|
2004-05-04 12:04:42 -07:00
|
|
|
if ((fixed[j].x + fixed[j].w) > VRoot.w)
|
|
|
|
fixed[j].w = VRoot.w - fixed[j].x;
|
2003-05-22 12:15:03 -07:00
|
|
|
if (fixed[j].y < 0)
|
|
|
|
{
|
|
|
|
fixed[j].h += fixed[j].y;
|
|
|
|
fixed[j].y = 0;
|
|
|
|
}
|
2004-05-04 12:04:42 -07:00
|
|
|
if ((fixed[j].y + fixed[j].h) > VRoot.h)
|
|
|
|
fixed[j].h = VRoot.h - fixed[j].y;
|
2003-05-22 12:15:03 -07:00
|
|
|
if ((fixed[j].w <= 0) || (fixed[j].h <= 0))
|
|
|
|
continue;
|
2003-05-16 11:06:14 -07:00
|
|
|
|
2003-12-07 01:18:55 -08:00
|
|
|
if (fixed[j].p) /* Sticky */
|
2003-06-15 14:43:06 -07:00
|
|
|
fixed[j].p = 1;
|
2003-05-22 12:15:03 -07:00
|
|
|
else
|
|
|
|
fixed[j].p = 0;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
Efree(blst);
|
|
|
|
}
|
|
|
|
ret = Emalloc(sizeof(RectBox) * (j + 1));
|
|
|
|
newrect.data = ewin;
|
|
|
|
newrect.x = 0;
|
|
|
|
newrect.y = 0;
|
2004-12-28 15:46:49 -08:00
|
|
|
newrect.w = EoGetW(ewin);
|
|
|
|
newrect.h = EoGetH(ewin);
|
|
|
|
newrect.p = EoGetLayer(ewin);
|
2003-11-08 02:56:25 -08:00
|
|
|
ArrangeRects(fixed, j, &newrect, 1, ret,
|
2004-05-04 12:04:42 -07:00
|
|
|
0, 0, VRoot.w, VRoot.h, ARRANGE_BY_SIZE, 1);
|
2003-05-16 11:06:14 -07:00
|
|
|
|
2003-05-22 12:15:03 -07:00
|
|
|
for (i = 0; i < j + 1; i++)
|
|
|
|
{
|
|
|
|
if (ret[i].data == ewin)
|
|
|
|
{
|
|
|
|
*px = ret[i].x;
|
|
|
|
*py = ret[i].y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
Efree(ret);
|
|
|
|
if (fixed)
|
|
|
|
Efree(fixed);
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
1999-10-01 14:38:22 -07:00
|
|
|
else
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2003-05-22 12:15:03 -07:00
|
|
|
ArrangeEwinCenteredXY(ewin, px, py);
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2003-05-16 11:06:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ArrangeEwinCenteredXY(EWin * ewin, int *px, int *py)
|
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
|
2004-07-02 17:58:19 -07:00
|
|
|
GetPointerScreenAvailableArea(&x, &y, &w, &h);
|
2004-12-28 15:46:49 -08:00
|
|
|
*px = (w - EoGetW(ewin)) / 2 + x;
|
|
|
|
*py = (h - EoGetH(ewin)) / 2 + y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ArrangeEwins(const char *params)
|
|
|
|
{
|
|
|
|
const char *type;
|
|
|
|
int method;
|
|
|
|
int i, j, k, num, speed, ax, ay;
|
|
|
|
RectBox *fixed, *ret, *floating;
|
|
|
|
char doslide;
|
|
|
|
EWin *const *lst, *ewin;
|
|
|
|
Button **blst;
|
|
|
|
|
|
|
|
type = params;
|
|
|
|
method = ARRANGE_BY_SIZE;
|
2005-10-09 11:01:30 -07:00
|
|
|
speed = Conf.place.slidespeedcleanup;
|
|
|
|
doslide = Conf.place.cleanupslide;
|
2004-12-28 15:46:49 -08:00
|
|
|
|
|
|
|
if (params)
|
|
|
|
{
|
|
|
|
if (!strcmp("order", type))
|
|
|
|
{
|
|
|
|
method = ARRANGE_VERBATIM;
|
|
|
|
}
|
|
|
|
else if (!strcmp("place", type))
|
|
|
|
{
|
|
|
|
method = ARRANGE_BY_POSITION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lst = EwinListGetAll(&num);
|
|
|
|
if (!lst)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
fixed = NULL;
|
|
|
|
floating = Emalloc(sizeof(RectBox) * num);
|
|
|
|
ret = Emalloc(sizeof(RectBox) * (num));
|
|
|
|
j = 0;
|
|
|
|
k = 0;
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
ewin = lst[i];
|
|
|
|
|
|
|
|
DeskGetArea(EoGetDesk(ewin), &ax, &ay);
|
|
|
|
|
|
|
|
if ((EoGetDesk(ewin) == DesksGetCurrent()) &&
|
2005-07-08 09:48:19 -07:00
|
|
|
(!EoIsSticky(ewin)) && (!EoIsFloating(ewin)) &&
|
|
|
|
(!ewin->state.iconified) && (!ewin->props.ignorearrange) &&
|
|
|
|
(ewin->type != EWIN_TYPE_MENU) &&
|
|
|
|
(ewin->area_x == ax) && (ewin->area_y == ay))
|
2004-12-28 15:46:49 -08:00
|
|
|
{
|
|
|
|
floating[j].data = lst[i];
|
|
|
|
floating[j].x = EoGetX(ewin);
|
|
|
|
floating[j].y = EoGetY(ewin);
|
|
|
|
floating[j].w = EoGetW(ewin);
|
|
|
|
floating[j].p = EoGetLayer(ewin);
|
|
|
|
floating[j++].h = EoGetH(ewin);
|
|
|
|
}
|
|
|
|
else if ((EoGetDesk(ewin) == DesksGetCurrent()) &&
|
|
|
|
(EoGetLayer(ewin) != 4) && (EoGetLayer(ewin) != 0) &&
|
|
|
|
(ewin->type != EWIN_TYPE_MENU))
|
|
|
|
{
|
|
|
|
fixed = Erealloc(fixed, sizeof(RectBox) * (k + 1));
|
|
|
|
fixed[k].data = lst[i];
|
|
|
|
fixed[k].x = EoGetX(ewin);
|
|
|
|
fixed[k].y = EoGetY(ewin);
|
|
|
|
fixed[k].w = EoGetW(ewin);
|
|
|
|
fixed[k].h = EoGetH(ewin);
|
|
|
|
if (fixed[k].x < 0)
|
|
|
|
{
|
|
|
|
fixed[k].x += fixed[k].w;
|
|
|
|
fixed[k].x = 0;
|
|
|
|
}
|
|
|
|
if ((fixed[k].x + fixed[k].w) > VRoot.w)
|
|
|
|
fixed[k].w = VRoot.w - fixed[k].x;
|
|
|
|
if (fixed[k].y < 0)
|
|
|
|
{
|
|
|
|
fixed[k].y += fixed[k].h;
|
|
|
|
fixed[k].y = 0;
|
|
|
|
}
|
|
|
|
if ((fixed[k].y + fixed[k].h) > VRoot.h)
|
|
|
|
fixed[k].h = VRoot.h - fixed[k].y;
|
|
|
|
if ((fixed[k].w > 0) && (fixed[k].h > 0))
|
|
|
|
{
|
2005-07-08 09:48:19 -07:00
|
|
|
if (!ewin->props.never_use_area)
|
2004-12-28 15:46:49 -08:00
|
|
|
fixed[k].p = EoGetLayer(ewin);
|
|
|
|
else
|
|
|
|
fixed[k].p = 99;
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
blst = (Button **) ListItemType(&num, LIST_TYPE_BUTTON);
|
|
|
|
if (blst)
|
|
|
|
{
|
|
|
|
fixed = Erealloc(fixed, sizeof(RectBox) * (num + k));
|
|
|
|
ret = Erealloc(ret, sizeof(RectBox) * ((num + j) + 1 + k));
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if (ButtonGetInfo(blst[i], &fixed[k], DesksGetCurrent()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fixed[k].x < 0)
|
|
|
|
{
|
|
|
|
fixed[k].x += fixed[k].w;
|
|
|
|
fixed[k].x = 0;
|
|
|
|
}
|
|
|
|
if ((fixed[k].x + fixed[k].w) > VRoot.w)
|
|
|
|
fixed[k].w = VRoot.w - fixed[k].x;
|
|
|
|
if (fixed[k].y < 0)
|
|
|
|
{
|
|
|
|
fixed[k].y += fixed[k].h;
|
|
|
|
fixed[k].y = 0;
|
|
|
|
}
|
|
|
|
if ((fixed[k].y + fixed[k].h) > VRoot.h)
|
|
|
|
fixed[k].h = VRoot.h - fixed[k].y;
|
|
|
|
if ((fixed[k].w <= 0) || (fixed[k].h <= 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (fixed[k].p) /* Sticky */
|
|
|
|
fixed[k].p = 50;
|
|
|
|
else
|
|
|
|
fixed[k].p = 0;
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
Efree(blst);
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrangeRects(fixed, k, floating, j, ret, 0, 0, VRoot.w, VRoot.h, method, 0);
|
|
|
|
|
|
|
|
for (i = 0; i < (j + k); i++)
|
|
|
|
{
|
|
|
|
if (ret[i].data)
|
|
|
|
{
|
|
|
|
if (doslide)
|
|
|
|
{
|
|
|
|
ewin = (EWin *) ret[i].data;
|
|
|
|
if (ewin)
|
|
|
|
{
|
|
|
|
if ((EoGetX(ewin) != ret[i].x)
|
|
|
|
|| (EoGetY(ewin) != ret[i].y))
|
|
|
|
{
|
|
|
|
SlideEwinTo(ewin, EoGetX(ewin), EoGetY(ewin),
|
|
|
|
ret[i].x, ret[i].y, speed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ewin = (EWin *) ret[i].data;
|
|
|
|
if (ewin)
|
|
|
|
{
|
|
|
|
if ((EoGetX(ewin) != ret[i].x)
|
|
|
|
|| (EoGetY(ewin) != ret[i].y))
|
2005-07-10 01:31:15 -07:00
|
|
|
EwinMove((EWin *) ret[i].data, ret[i].x, ret[i].y);
|
2004-12-28 15:46:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fixed)
|
|
|
|
Efree(fixed);
|
|
|
|
if (ret)
|
|
|
|
Efree(ret);
|
|
|
|
if (floating)
|
|
|
|
Efree(floating);
|
|
|
|
|
|
|
|
done:
|
|
|
|
return;
|
1999-10-01 14:38:22 -07:00
|
|
|
}
|