stacking: Cosmetics, preparing for other changes

This commit is contained in:
Kim Woelders 2022-04-04 11:06:28 +02:00
parent a67b247ff2
commit f171611d89
1 changed files with 104 additions and 100 deletions

View File

@ -30,23 +30,22 @@
#define EobjGetCwin(p) \ #define EobjGetCwin(p) \
((p->type == EOBJ_TYPE_EWIN) ? EwinGetClientXwin(((EWin*)(p))) : NoXID) ((p->type == EOBJ_TYPE_EWIN) ? EwinGetClientXwin(((EWin*)(p))) : NoXID)
typedef struct _eobjlist EobjList; typedef struct {
struct _eobjlist {
const char *name; const char *name;
int nalloc; struct {
int nwins; int nalloc;
EObj **list; int nobjs;
EObj **list;
} o;
char layered; char layered;
char type; } EobjList;
};
static int EobjListRaise(EobjList * ewl, EObj * eo, int test); static int EobjListRaise(EobjList * eol, EObj * eo, int test);
static int EobjListLower(EobjList * ewl, EObj * eo, int test); static int EobjListLower(EobjList * eol, EObj * eo, int test);
#if ENABLE_DEBUG_STACKING #if ENABLE_DEBUG_STACKING
static void static void
EobjListShow(const char *txt, EobjList * ewl) EobjListShow(const char *txt, EobjList * eol)
{ {
int i; int i;
EObj *eo; EObj *eo;
@ -54,61 +53,62 @@ EobjListShow(const char *txt, EobjList * ewl)
if (!EDebug(EDBUG_TYPE_STACKING)) if (!EDebug(EDBUG_TYPE_STACKING))
return; return;
Eprintf("%s-%s:\n", ewl->name, txt); Eprintf("%s-%s:\n", eol->name, txt);
for (i = 0; i < ewl->nwins; i++) for (i = 0; i < eol->o.nobjs; i++)
{ {
eo = ewl->list[i]; eo = eol->o.list[i];
Eprintf(" %2d: %#10x %#10x %d %d %s\n", i, EobjGetXwin(eo), Eprintf(" %2d: %#10x %#10x %d %d %s\n", i, EobjGetXwin(eo),
EobjGetCwin(eo), eo->desk->num, eo->ilayer, EobjGetName(eo)); EobjGetCwin(eo), eo->desk->num, eo->ilayer, EobjGetName(eo));
} }
} }
#else #else
#define EobjListShow(txt, ewl) #define EobjListShow(txt, eol)
#endif #endif
static int static int
EobjListGetIndex(EobjList * ewl, EObj * eo) EobjListGetIndex(EobjList * eol, EObj * eo)
{ {
int i; int i;
for (i = 0; i < ewl->nwins; i++) for (i = 0; i < eol->o.nobjs; i++)
if (ewl->list[i] == eo) if (eol->o.list[i] == eo)
return i; return i;
return -1; return -1;
} }
static void static void
EobjListAdd(EobjList * ewl, EObj * eo, int ontop) EobjListAdd(EobjList * eol, EObj * eo, int ontop)
{ {
int i; int i;
/* Quit if already in list */ /* Quit if already in list */
i = EobjListGetIndex(ewl, eo); i = EobjListGetIndex(eol, eo);
if (i >= 0) if (i >= 0)
return; return;
if (ewl->nwins >= ewl->nalloc) if (eol->o.nobjs >= eol->o.nalloc)
{ {
ewl->nalloc += 16; eol->o.nalloc += 16;
ewl->list = EREALLOC(EObj *, ewl->list, ewl->nalloc); eol->o.list = EREALLOC(EObj *, eol->o.list, eol->o.nalloc);
} }
if (ewl->layered) if (eol->layered)
{ {
/* The simple way for now (add, raise/lower) */ /* The simple way for now (add, raise/lower) */
if (ontop) if (ontop)
{ {
ewl->list[ewl->nwins] = eo; eol->o.list[eol->o.nobjs] = eo;
ewl->nwins++; eol->o.nobjs++;
EobjListRaise(ewl, eo, 0); EobjListRaise(eol, eo, 0);
} }
else else
{ {
memmove(ewl->list + 1, ewl->list, ewl->nwins * sizeof(EObj *)); memmove(eol->o.list + 1, eol->o.list,
ewl->list[0] = eo; eol->o.nobjs * sizeof(EObj *));
ewl->nwins++; eol->o.list[0] = eo;
EobjListLower(ewl, eo, 0); eol->o.nobjs++;
EobjListLower(eol, eo, 0);
} }
if (eo->stacked == 0) if (eo->stacked == 0)
DeskSetDirtyStack(eo->desk, eo); DeskSetDirtyStack(eo->desk, eo);
@ -117,61 +117,62 @@ EobjListAdd(EobjList * ewl, EObj * eo, int ontop)
{ {
if (ontop) if (ontop)
{ {
memmove(ewl->list + 1, ewl->list, ewl->nwins * sizeof(EObj *)); memmove(eol->o.list + 1, eol->o.list,
ewl->list[0] = eo; eol->o.nobjs * sizeof(EObj *));
eol->o.list[0] = eo;
} }
else else
{ {
ewl->list[ewl->nwins] = eo; eol->o.list[eol->o.nobjs] = eo;
} }
ewl->nwins++; eol->o.nobjs++;
} }
EobjListShow("EobjListAdd", ewl); EobjListShow("EobjListAdd", eol);
} }
static void static void
EobjListDel(EobjList * ewl, EObj * eo) EobjListDel(EobjList * eol, EObj * eo)
{ {
int i, n; int i, n;
/* Quit if not in list */ /* Quit if not in list */
i = EobjListGetIndex(ewl, eo); i = EobjListGetIndex(eol, eo);
if (i < 0) if (i < 0)
return; return;
ewl->nwins--; eol->o.nobjs--;
n = ewl->nwins - i; n = eol->o.nobjs - i;
if (n > 0) if (n > 0)
{ {
memmove(ewl->list + i, ewl->list + i + 1, n * sizeof(EObj *)); memmove(eol->o.list + i, eol->o.list + i + 1, n * sizeof(EObj *));
} }
else if (ewl->nwins <= 0) else if (eol->o.nobjs <= 0)
{ {
/* Enables autocleanup at shutdown, if ever implemented */ /* Enables autocleanup at shutdown, if ever implemented */
EFREE_NULL(ewl->list); EFREE_NULL(eol->o.list);
ewl->nalloc = 0; eol->o.nalloc = 0;
} }
EobjListShow("EobjListDel", ewl); EobjListShow("EobjListDel", eol);
} }
static int static int
EobjListLower(EobjList * ewl, EObj * eo, int test) EobjListLower(EobjList * eol, EObj * eo, int test)
{ {
int i, j, n; int i, j, n;
/* Quit if not in list */ /* Quit if not in list */
i = EobjListGetIndex(ewl, eo); i = EobjListGetIndex(eol, eo);
if (i < 0) if (i < 0)
return 0; return 0;
j = ewl->nwins - 1; j = eol->o.nobjs - 1;
if (ewl->layered) if (eol->layered)
{ {
/* Take the layer into account */ /* Take the layer into account */
for (; j >= 0; j--) for (; j >= 0; j--)
if (i != j && eo->ilayer <= ewl->list[j]->ilayer) if (i != j && eo->ilayer <= eol->o.list[j]->ilayer)
break; break;
if (j < i) if (j < i)
j++; j++;
@ -183,39 +184,39 @@ EobjListLower(EobjList * ewl, EObj * eo, int test)
if (n > 0) if (n > 0)
{ {
memmove(ewl->list + i, ewl->list + i + 1, n * sizeof(EObj *)); memmove(eol->o.list + i, eol->o.list + i + 1, n * sizeof(EObj *));
ewl->list[j] = eo; eol->o.list[j] = eo;
if (ewl->layered && eo->stacked > 0) if (eol->layered && eo->stacked > 0)
DeskSetDirtyStack(eo->desk, eo); DeskSetDirtyStack(eo->desk, eo);
} }
else if (n < 0) else if (n < 0)
{ {
memmove(ewl->list + j + 1, ewl->list + j, -n * sizeof(EObj *)); memmove(eol->o.list + j + 1, eol->o.list + j, -n * sizeof(EObj *));
ewl->list[j] = eo; eol->o.list[j] = eo;
if (ewl->layered && eo->stacked > 0) if (eol->layered && eo->stacked > 0)
DeskSetDirtyStack(eo->desk, eo); DeskSetDirtyStack(eo->desk, eo);
} }
EobjListShow("EobjListLower", ewl); EobjListShow("EobjListLower", eol);
return n; return n;
} }
static int static int
EobjListRaise(EobjList * ewl, EObj * eo, int test) EobjListRaise(EobjList * eol, EObj * eo, int test)
{ {
int i, j, n; int i, j, n;
/* Quit if not in list */ /* Quit if not in list */
i = EobjListGetIndex(ewl, eo); i = EobjListGetIndex(eol, eo);
if (i < 0) if (i < 0)
return 0; return 0;
j = 0; j = 0;
if (ewl->layered) if (eol->layered)
{ {
/* Take the layer into account */ /* Take the layer into account */
for (; j < ewl->nwins; j++) for (; j < eol->o.nobjs; j++)
if (j != i && eo->ilayer >= ewl->list[j]->ilayer) if (j != i && eo->ilayer >= eol->o.list[j]->ilayer)
break; break;
if (j > i) if (j > i)
j--; j--;
@ -227,43 +228,43 @@ EobjListRaise(EobjList * ewl, EObj * eo, int test)
if (n > 0) if (n > 0)
{ {
memmove(ewl->list + i, ewl->list + i + 1, n * sizeof(EObj *)); memmove(eol->o.list + i, eol->o.list + i + 1, n * sizeof(EObj *));
ewl->list[j] = eo; eol->o.list[j] = eo;
if (ewl->layered && eo->stacked > 0) if (eol->layered && eo->stacked > 0)
DeskSetDirtyStack(eo->desk, eo); DeskSetDirtyStack(eo->desk, eo);
} }
else if (n < 0) else if (n < 0)
{ {
memmove(ewl->list + j + 1, ewl->list + j, -n * sizeof(EObj *)); memmove(eol->o.list + j + 1, eol->o.list + j, -n * sizeof(EObj *));
ewl->list[j] = eo; eol->o.list[j] = eo;
if (ewl->layered && eo->stacked > 0) if (eol->layered && eo->stacked > 0)
DeskSetDirtyStack(eo->desk, eo); DeskSetDirtyStack(eo->desk, eo);
} }
EobjListShow("EobjListRaise", ewl); EobjListShow("EobjListRaise", eol);
return n; return n;
} }
static EObj * static EObj *
EobjListFind(const EobjList * ewl, EX_Window win) EobjListFind(const EobjList * eol, EX_Window win)
{ {
int i; int i;
for (i = 0; i < ewl->nwins; i++) for (i = 0; i < eol->o.nobjs; i++)
if (EobjGetXwin(ewl->list[i]) == win) if (EobjGetXwin(eol->o.list[i]) == win)
return ewl->list[i]; return eol->o.list[i];
return NULL; return NULL;
} }
#if 0 #if 0
static int static int
EobjListTypeCount(const EobjList * ewl, int type) EobjListTypeCount(const EobjList * eol, int type)
{ {
int i, n; int i, n;
for (i = n = 0; i < ewl->nwins; i++) for (i = n = 0; i < eol->o.nobjs; i++)
if (ewl->list[i]->type == type) if (eol->o.list[i]->type == type)
n++; n++;
return n; return n;
@ -273,15 +274,18 @@ EobjListTypeCount(const EobjList * ewl, int type)
/* /*
* The global object/client lists * The global object/client lists
*/ */
static EobjList EobjListStack = { "Stack", 0, 0, NULL, 1, 0 }; #define EOBJ_LIST(_name, _layered) \
static EobjList EwinListFocus = { "Focus", 0, 0, NULL, 0, 1 }; { .name = _name, .layered = _layered }
static EobjList EwinListOrder = { "Order", 0, 0, NULL, 0, 2 };
static EobjList EobjListStack = EOBJ_LIST("Stack", 1);
static EobjList EwinListFocus = EOBJ_LIST("Focus", 0);
static EobjList EwinListOrder = EOBJ_LIST("Order", 0);
static EObj *const * static EObj *const *
EobjListGet(EobjList * ewl, int *num) EobjListGet(EobjList * eol, int *num)
{ {
*num = ewl->nwins; *num = eol->o.nobjs;
return ewl->list; return eol->o.list;
} }
int int
@ -349,15 +353,15 @@ EwinListStackGet(int *num)
{ {
static EWin **lst = NULL; static EWin **lst = NULL;
static int nalloc = 0; static int nalloc = 0;
const EobjList *ewl; const EobjList *eol;
int i, j; int i, j;
EObj *eo; EObj *eo;
ewl = &EobjListStack; eol = &EobjListStack;
for (i = j = 0; i < ewl->nwins; i++) for (i = j = 0; i < eol->o.nobjs; i++)
{ {
eo = ewl->list[i]; eo = eol->o.list[i];
if (eo->type != EOBJ_TYPE_EWIN) if (eo->type != EOBJ_TYPE_EWIN)
continue; continue;
@ -385,15 +389,15 @@ EwinListGetForDesk(int *num, Desk * dsk)
{ {
static EWin **lst = NULL; static EWin **lst = NULL;
static int nalloc = 0; static int nalloc = 0;
const EobjList *ewl; const EobjList *eol;
int i, j; int i, j;
EObj *eo; EObj *eo;
ewl = &EobjListStack; eol = &EobjListStack;
for (i = j = 0; i < ewl->nwins; i++) for (i = j = 0; i < eol->o.nobjs; i++)
{ {
eo = ewl->list[i]; eo = eol->o.list[i];
if (eo->type != EOBJ_TYPE_EWIN || eo->desk != dsk) if (eo->type != EOBJ_TYPE_EWIN || eo->desk != dsk)
continue; continue;
@ -415,22 +419,22 @@ EobjListStackGetForDesk(int *num, Desk * dsk)
{ {
static EObj **lst = NULL; static EObj **lst = NULL;
static int nalloc = 0; static int nalloc = 0;
const EobjList *ewl; const EobjList *eol;
int i, j; int i, j;
EObj *eo; EObj *eo;
ewl = &EobjListStack; eol = &EobjListStack;
/* Too many - who cares. */ /* Too many - who cares. */
if (nalloc < ewl->nwins) if (nalloc < eol->o.nobjs)
{ {
nalloc = (ewl->nwins + 16) & ~0xf; /* 16 at the time */ nalloc = (eol->o.nobjs + 16) & ~0xf; /* 16 at the time */
lst = EREALLOC(EObj *, lst, nalloc); lst = EREALLOC(EObj *, lst, nalloc);
} }
for (i = j = 0; i < ewl->nwins; i++) for (i = j = 0; i < eol->o.nobjs; i++)
{ {
eo = ewl->list[i]; eo = eol->o.list[i];
if (eo->desk != dsk) if (eo->desk != dsk)
continue; continue;
@ -444,16 +448,16 @@ EobjListStackGetForDesk(int *num, Desk * dsk)
int int
EwinListStackIsRaised(const EWin * ewin) EwinListStackIsRaised(const EWin * ewin)
{ {
const EobjList *ewl; const EobjList *eol;
int i; int i;
const EObj *eo, *eox; const EObj *eo, *eox;
ewl = &EobjListStack; eol = &EobjListStack;
eox = EoObj(ewin); eox = EoObj(ewin);
for (i = 0; i < ewl->nwins; i++) for (i = 0; i < eol->o.nobjs; i++)
{ {
eo = ewl->list[i]; eo = eol->o.list[i];
if (eo->type != EOBJ_TYPE_EWIN) if (eo->type != EOBJ_TYPE_EWIN)
continue; continue;
if (eo->desk != eox->desk) if (eo->desk != eox->desk)