1999-10-04 15:06:00 -07:00
|
|
|
/*
|
2007-01-13 11:14:29 -08:00
|
|
|
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
|
2000-04-05 16:22:56 -07: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-04-05 16:22:56 -07: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-04-05 16:22:56 -07: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-12-22 10:43:15 -08:00
|
|
|
#include "borders.h"
|
2005-07-16 09:57:45 -07:00
|
|
|
#include "ewins.h"
|
2005-11-19 07:47:10 -08:00
|
|
|
#include "groups.h"
|
1999-08-17 15:56:46 -07:00
|
|
|
|
|
|
|
EWin *
|
2005-06-30 05:50:47 -07:00
|
|
|
EwinFindByPtr(const EWin * ewin)
|
|
|
|
{
|
|
|
|
EWin *const *ewins;
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
ewins = EwinListGetAll(&num);
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if (ewin == ewins[i])
|
|
|
|
return ewins[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EWin *
|
|
|
|
EwinFindByFrame(Window win)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-03-26 13:21:47 -08:00
|
|
|
EWin *const *ewins;
|
1999-08-17 15:56:46 -07:00
|
|
|
int i, num;
|
|
|
|
|
2004-04-01 14:41:22 -08:00
|
|
|
ewins = EwinListGetAll(&num);
|
1999-08-17 15:56:46 -07:00
|
|
|
for (i = 0; i < num; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2006-04-18 09:26:51 -07:00
|
|
|
if (win == EoGetXwin(ewins[i]))
|
2004-03-26 13:21:47 -08:00
|
|
|
return ewins[i];
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2005-01-25 13:58:28 -08:00
|
|
|
return NULL;
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EWin *
|
2005-06-30 05:50:47 -07:00
|
|
|
EwinFindByClient(Window win)
|
|
|
|
{
|
|
|
|
EWin *const *ewins;
|
|
|
|
int i, num;
|
|
|
|
|
|
|
|
ewins = EwinListGetAll(&num);
|
|
|
|
for (i = 0; i < num; i++)
|
|
|
|
{
|
2006-08-07 13:20:16 -07:00
|
|
|
if (win == EwinGetClientXwin(ewins[i]))
|
2005-06-30 05:50:47 -07:00
|
|
|
return ewins[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EWin *
|
|
|
|
EwinFindByChildren(Window win)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-03-26 13:21:47 -08:00
|
|
|
EWin *const *ewins;
|
1999-08-17 15:56:46 -07:00
|
|
|
int i, j, num;
|
|
|
|
|
2004-04-01 14:41:22 -08:00
|
|
|
ewins = EwinListGetAll(&num);
|
1999-08-17 15:56:46 -07:00
|
|
|
for (i = 0; i < num; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2006-08-07 13:20:16 -07:00
|
|
|
if ((win == EwinGetClientXwin(ewins[i])) ||
|
|
|
|
(win == EwinGetContainerXwin(ewins[i])))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-03-26 13:21:47 -08:00
|
|
|
return ewins[i];
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j = 0; j < ewins[i]->border->num_winparts; j++)
|
2006-08-07 13:47:12 -07:00
|
|
|
if (win == WinGetXwin(ewins[i]->bits[j].win))
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2004-03-26 13:21:47 -08:00
|
|
|
return ewins[i];
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
|
|
|
}
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2005-01-25 13:58:28 -08:00
|
|
|
return NULL;
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EWin **
|
2005-10-29 06:09:31 -07:00
|
|
|
ListWinGroupMembersForEwin(const EWin * ewin, int action, char nogroup,
|
2005-11-05 09:12:53 -08:00
|
|
|
int *pnum)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
|
|
|
|
2005-11-05 09:12:53 -08:00
|
|
|
EWin **gwins, *ew;
|
|
|
|
EWin *const *ewins;
|
|
|
|
Group *grp;
|
|
|
|
int i, num, gwcnt;
|
1999-08-17 15:56:46 -07:00
|
|
|
|
2005-11-05 09:12:53 -08:00
|
|
|
if (!ewin)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2005-11-05 09:12:53 -08:00
|
|
|
*pnum = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-05-22 12:15:03 -07:00
|
|
|
|
2005-11-05 09:12:53 -08:00
|
|
|
gwcnt = 0;
|
|
|
|
gwins = NULL;
|
2003-05-22 12:15:03 -07:00
|
|
|
|
2005-11-05 09:12:53 -08:00
|
|
|
if (nogroup || ewin->num_groups <= 0)
|
|
|
|
goto done;
|
2003-05-22 12:15:03 -07:00
|
|
|
|
2005-11-05 09:12:53 -08:00
|
|
|
ewins = EwinListGetAll(&num);
|
|
|
|
if (ewins == NULL) /* Should not be possible */
|
|
|
|
goto done;
|
2003-05-22 12:15:03 -07:00
|
|
|
|
2005-11-05 09:12:53 -08:00
|
|
|
/* Loop through window stack, bottom up */
|
|
|
|
for (i = num - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
ew = ewins[i];
|
|
|
|
|
|
|
|
if (ew == ewin)
|
|
|
|
goto do_add;
|
|
|
|
|
|
|
|
/* To get consistent behaviour, limit groups to a single desktop for now: */
|
|
|
|
if (EoGetDesk(ew) != EoGetDesk(ewin))
|
|
|
|
continue;
|
2003-05-22 12:15:03 -07:00
|
|
|
|
2005-11-05 09:12:53 -08:00
|
|
|
grp = EwinsInGroup(ewin, ew);
|
|
|
|
if (!grp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (action)
|
2003-05-22 12:15:03 -07:00
|
|
|
{
|
2005-11-05 09:12:53 -08:00
|
|
|
case GROUP_ACTION_SET_WINDOW_BORDER:
|
|
|
|
if (!grp->cfg.set_border)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case GROUP_ACTION_ICONIFY:
|
|
|
|
if (!grp->cfg.iconify)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case GROUP_ACTION_MOVE:
|
|
|
|
if (!grp->cfg.move)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case GROUP_ACTION_RAISE:
|
|
|
|
case GROUP_ACTION_LOWER:
|
|
|
|
case GROUP_ACTION_RAISE_LOWER:
|
|
|
|
if (!grp->cfg.raise)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case GROUP_ACTION_STICK:
|
|
|
|
if (!grp->cfg.stick)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case GROUP_ACTION_SHADE:
|
|
|
|
if (!grp->cfg.shade)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case GROUP_ACTION_KILL:
|
|
|
|
if (!grp->cfg.kill)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2003-05-22 12:15:03 -07:00
|
|
|
}
|
2005-11-05 09:12:53 -08:00
|
|
|
|
|
|
|
do_add:
|
|
|
|
gwins = Erealloc(gwins, (gwcnt + 1) * sizeof(EWin *));
|
|
|
|
gwins[gwcnt] = ew;
|
|
|
|
gwcnt++;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2005-11-05 09:12:53 -08:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (gwins == NULL)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2005-11-05 09:12:53 -08:00
|
|
|
gwins = Emalloc(sizeof(EWin *));
|
|
|
|
gwins[0] = (EWin *) ewin;
|
|
|
|
gwcnt = 1;
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2005-11-05 09:12:53 -08:00
|
|
|
*pnum = gwcnt;
|
|
|
|
return gwins;
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EWin **
|
2005-10-29 06:09:31 -07:00
|
|
|
EwinListTransients(const EWin * ewin, int *num, int group)
|
1999-08-17 15:56:46 -07:00
|
|
|
{
|
2004-06-18 18:31:21 -07:00
|
|
|
EWin *const *ewins, **lst, *ew;
|
1999-08-17 15:56:46 -07:00
|
|
|
int i, j, n;
|
|
|
|
|
|
|
|
j = 0;
|
2004-06-18 18:31:21 -07:00
|
|
|
lst = NULL;
|
|
|
|
|
2005-08-01 10:34:53 -07:00
|
|
|
if (EwinGetTransientCount(ewin) <= 0)
|
2004-06-18 18:31:21 -07:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
ewins = EwinListGetAll(&n);
|
|
|
|
|
|
|
|
/* Find regular transients */
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
ew = ewins[i];
|
|
|
|
|
|
|
|
/* Skip self-reference */
|
|
|
|
if (ew == ewin)
|
|
|
|
continue;
|
|
|
|
|
2006-08-07 13:20:16 -07:00
|
|
|
if (EwinGetTransientFor(ew) == EwinGetClientXwin(ewin))
|
2004-06-18 18:31:21 -07:00
|
|
|
{
|
|
|
|
lst = Erealloc(lst, (j + 1) * sizeof(EWin *));
|
|
|
|
lst[j++] = ew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!group)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Group transients (if ewin is not a transient) */
|
2005-08-01 10:34:53 -07:00
|
|
|
if (EwinIsTransient(ewin))
|
2004-06-18 18:31:21 -07:00
|
|
|
goto done;
|
|
|
|
|
1999-08-17 15:56:46 -07:00
|
|
|
for (i = 0; i < n; i++)
|
2000-07-26 11:00:47 -07:00
|
|
|
{
|
2004-06-18 18:31:21 -07:00
|
|
|
ew = ewins[i];
|
|
|
|
|
|
|
|
/* Skip self-reference */
|
|
|
|
if (ew == ewin)
|
2004-05-29 13:42:06 -07:00
|
|
|
continue;
|
2004-06-18 18:31:21 -07:00
|
|
|
|
2006-04-29 12:39:21 -07:00
|
|
|
if (EwinGetTransientFor(ew) == VRoot.xwin &&
|
2005-08-01 10:34:53 -07:00
|
|
|
EwinGetWindowGroup(ew) == EwinGetWindowGroup(ewin))
|
2004-06-18 18:31:21 -07:00
|
|
|
{
|
|
|
|
lst = Erealloc(lst, (j + 1) * sizeof(EWin *));
|
|
|
|
lst[j++] = ew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
*num = j;
|
2005-01-25 13:58:28 -08:00
|
|
|
return lst;
|
2004-06-18 18:31:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EWin **
|
2005-10-29 06:09:31 -07:00
|
|
|
EwinListTransientFor(const EWin * ewin, int *num)
|
2004-06-18 18:31:21 -07:00
|
|
|
{
|
|
|
|
EWin *const *ewins, **lst, *ew;
|
|
|
|
int i, j, n;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
lst = NULL;
|
|
|
|
|
2005-08-01 10:34:53 -07:00
|
|
|
if (!EwinIsTransient(ewin))
|
2004-06-18 18:31:21 -07:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
ewins = EwinListGetAll(&n);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
ew = ewins[i];
|
|
|
|
|
|
|
|
/* Skip self-reference */
|
|
|
|
if (ew == ewin)
|
2004-05-29 13:42:06 -07:00
|
|
|
continue;
|
|
|
|
|
2004-06-18 18:31:21 -07:00
|
|
|
/* Regular parent or if root trans, top level group members */
|
2006-08-07 13:20:16 -07:00
|
|
|
if ((EwinGetTransientFor(ewin) == EwinGetClientXwin(ew)) ||
|
2005-08-01 10:34:53 -07:00
|
|
|
(!EwinIsTransient(ew) &&
|
2006-04-29 12:39:21 -07:00
|
|
|
EwinGetTransientFor(ewin) == VRoot.xwin &&
|
2005-08-01 10:34:53 -07:00
|
|
|
EwinGetWindowGroup(ew) == EwinGetWindowGroup(ewin)))
|
2004-06-18 18:31:21 -07:00
|
|
|
{
|
|
|
|
lst = Erealloc(lst, (j + 1) * sizeof(EWin *));
|
|
|
|
lst[j++] = ew;
|
|
|
|
}
|
2000-07-26 11:00:47 -07:00
|
|
|
}
|
2004-06-18 18:31:21 -07:00
|
|
|
|
|
|
|
done:
|
1999-08-17 15:56:46 -07:00
|
|
|
*num = j;
|
2005-01-25 13:58:28 -08:00
|
|
|
return lst;
|
1999-08-17 15:56:46 -07:00
|
|
|
}
|