Move/rename some functions.

SVN revision: 28558
This commit is contained in:
Kim Woelders 2007-03-04 23:25:11 +00:00
parent 1a0917f4c2
commit 0ea436497d
4 changed files with 237 additions and 233 deletions

View File

@ -1900,6 +1900,101 @@ EwinChangesProcess(EWin * ewin)
EWinChanges.flags = 0;
}
EWin **
EwinListTransients(const EWin * ewin, int *num, int group)
{
EWin *const *ewins, **lst, *ew;
int i, j, n;
j = 0;
lst = NULL;
if (EwinGetTransientCount(ewin) <= 0)
goto done;
ewins = EwinListGetAll(&n);
/* Find regular transients */
for (i = 0; i < n; i++)
{
ew = ewins[i];
/* Skip self-reference */
if (ew == ewin)
continue;
if (EwinGetTransientFor(ew) == EwinGetClientXwin(ewin))
{
lst = EREALLOC(EWin *, lst, j + 1);
lst[j++] = ew;
}
}
if (!group)
goto done;
/* Group transients (if ewin is not a transient) */
if (EwinIsTransient(ewin))
goto done;
for (i = 0; i < n; i++)
{
ew = ewins[i];
/* Skip self-reference */
if (ew == ewin)
continue;
if (EwinGetTransientFor(ew) == VRoot.xwin &&
EwinGetWindowGroup(ew) == EwinGetWindowGroup(ewin))
{
lst = EREALLOC(EWin *, lst, j + 1);
lst[j++] = ew;
}
}
done:
*num = j;
return lst;
}
EWin **
EwinListTransientFor(const EWin * ewin, int *num)
{
EWin *const *ewins, **lst, *ew;
int i, j, n;
j = 0;
lst = NULL;
if (!EwinIsTransient(ewin))
goto done;
ewins = EwinListGetAll(&n);
for (i = 0; i < n; i++)
{
ew = ewins[i];
/* Skip self-reference */
if (ew == ewin)
continue;
/* Regular parent or if root trans, top level group members */
if ((EwinGetTransientFor(ewin) == EwinGetClientXwin(ew)) ||
(!EwinIsTransient(ew) &&
EwinGetTransientFor(ewin) == VRoot.xwin &&
EwinGetWindowGroup(ew) == EwinGetWindowGroup(ewin)))
{
lst = EREALLOC(EWin *, lst, j + 1);
lst[j++] = ew;
}
}
done:
*num = j;
return lst;
}
void
EwinsEventsConfigure(int mode)
{

View File

@ -376,6 +376,9 @@ void EwinUpdateOpacity(EWin * ewin);
void EwinChange(EWin * ewin, unsigned int flag);
EWin **EwinListTransients(const EWin * ewin, int *num, int group);
EWin **EwinListTransientFor(const EWin * ewin, int *num);
void EwinsEventsConfigure(int mode);
void EwinsSetFree(void);
void EwinsShowDesktop(int on);
@ -436,8 +439,8 @@ EWin *EwinFindByPtr(const EWin * ewin);
EWin *EwinFindByFrame(Window win);
EWin *EwinFindByClient(Window win);
EWin *EwinFindByChildren(Window win);
EWin **EwinListTransients(const EWin * ewin, int *num, int group);
EWin **EwinListTransientFor(const EWin * ewin, int *num);
EWin **EwinsFindByExpr(const char *match, int *pnum, int *pflags);
EWin *EwinFindByExpr(const char *match);
/* icccm.c (for now) */
#if USE_XSYNC

View File

@ -24,6 +24,8 @@
#include "borders.h"
#include "ewins.h"
#include "groups.h"
#include <ctype.h>
#include <string.h>
EWin *
EwinFindByPtr(const EWin * ewin)
@ -96,6 +98,136 @@ EwinFindByChildren(Window win)
return NULL;
}
EWin **
EwinsFindByExpr(const char *match, int *pnum, int *pflags)
{
EWin *ewin, **lst;
EWin *const *ewins;
int type;
int i, num, len, nfound, match_one, flags;
if (pnum)
*pnum = 0;
if (!match || !match[0])
return NULL;
ewin = NULL;
flags = 0;
if (!strcmp(match, "*") || !strcmp(match, "=") || !strcmp(match, "current"))
{
ewin = GetContextEwin();
if (!ewin)
ewin = GetFocusEwin();
if (match[0] == '=')
flags = 1; /* Nogroup */
goto do_one;
}
if (isdigit(match[0]))
{
unsigned int win;
sscanf(match, "%x", &win);
ewin = EwinFindByChildren(win);
goto do_one;
}
match_one = 1;
if (!strcmp(match, "all"))
{
type = 'a';
match_one = 0;
flags = 1; /* Nogroup */
}
else if (match[0] == '=')
{
type = 's';
match++;
flags = 1; /* Nogroup */
}
else if (strchr(match, '*'))
{
type = 'w';
match_one = 0;
flags = 1; /* Nogroup */
}
else
{
type = 's';
}
len = strlen(match);
if (len <= 0)
return NULL;
ewins = EwinListGetAll(&num);
if (!ewins)
return NULL;
nfound = 0;
lst = NULL;
for (i = 0; i < num; i++)
{
ewin = ewins[i];
if (type == 'a') /* All */
{
}
else if (type == 'w') /* Wildcard */
{
if (!matchregexp(match, EwinGetIcccmName(ewin)))
continue;
}
else /* Match name (substring) */
{
const char *name;
name = EwinGetIcccmName(ewin);
if (!name)
continue;
if (!strcasestr(name, match))
continue;
}
nfound++;
lst = EREALLOC(EWin *, lst, nfound);
lst[nfound - 1] = ewin;
if (match_one)
break;
}
goto done;
do_one:
if (!ewin)
return NULL;
nfound = 1;
lst = EMALLOC(EWin *, 1);
if (!lst)
return NULL;
lst[0] = ewin;
done:
if (pnum)
*pnum = nfound;
if (pflags)
*pflags = flags;
return lst;
}
EWin *
EwinFindByExpr(const char *match)
{
EWin *ewin, **lst;
lst = EwinsFindByExpr(match, NULL, NULL);
if (!lst)
return NULL;
ewin = lst[0];
Efree(lst);
return ewin;
}
EWin **
ListWinGroupMembersForEwin(const EWin * ewin, int action, char nogroup,
int *pnum)
@ -190,98 +322,3 @@ ListWinGroupMembersForEwin(const EWin * ewin, int action, char nogroup,
*pnum = gwcnt;
return gwins;
}
EWin **
EwinListTransients(const EWin * ewin, int *num, int group)
{
EWin *const *ewins, **lst, *ew;
int i, j, n;
j = 0;
lst = NULL;
if (EwinGetTransientCount(ewin) <= 0)
goto done;
ewins = EwinListGetAll(&n);
/* Find regular transients */
for (i = 0; i < n; i++)
{
ew = ewins[i];
/* Skip self-reference */
if (ew == ewin)
continue;
if (EwinGetTransientFor(ew) == EwinGetClientXwin(ewin))
{
lst = EREALLOC(EWin *, lst, j + 1);
lst[j++] = ew;
}
}
if (!group)
goto done;
/* Group transients (if ewin is not a transient) */
if (EwinIsTransient(ewin))
goto done;
for (i = 0; i < n; i++)
{
ew = ewins[i];
/* Skip self-reference */
if (ew == ewin)
continue;
if (EwinGetTransientFor(ew) == VRoot.xwin &&
EwinGetWindowGroup(ew) == EwinGetWindowGroup(ewin))
{
lst = EREALLOC(EWin *, lst, j + 1);
lst[j++] = ew;
}
}
done:
*num = j;
return lst;
}
EWin **
EwinListTransientFor(const EWin * ewin, int *num)
{
EWin *const *ewins, **lst, *ew;
int i, j, n;
j = 0;
lst = NULL;
if (!EwinIsTransient(ewin))
goto done;
ewins = EwinListGetAll(&n);
for (i = 0; i < n; i++)
{
ew = ewins[i];
/* Skip self-reference */
if (ew == ewin)
continue;
/* Regular parent or if root trans, top level group members */
if ((EwinGetTransientFor(ewin) == EwinGetClientXwin(ew)) ||
(!EwinIsTransient(ew) &&
EwinGetTransientFor(ewin) == VRoot.xwin &&
EwinGetWindowGroup(ew) == EwinGetWindowGroup(ewin)))
{
lst = EREALLOC(EWin *, lst, j + 1);
lst[j++] = ew;
}
}
done:
*num = j;
return lst;
}

141
src/ipc.c
View File

@ -36,7 +36,6 @@
#include "snaps.h"
#include "timers.h"
#include "xwin.h"
#include <ctype.h>
#define SS(s) ((s) ? (s) : NoText)
static const char NoText[] = "-NONE-";
@ -92,136 +91,6 @@ IpcPrintf(const char *fmt, ...)
bufsiz += len;
}
static EWin **
IpcFindEwins(const char *match, int *pnum, int *pflags)
{
EWin *ewin, **lst;
EWin *const *ewins;
int type;
int i, num, len, nfound, match_one, flags;
if (pnum)
*pnum = 0;
if (!match || !match[0])
return NULL;
ewin = NULL;
flags = 0;
if (!strcmp(match, "*") || !strcmp(match, "=") || !strcmp(match, "current"))
{
ewin = GetContextEwin();
if (!ewin)
ewin = GetFocusEwin();
if (match[0] == '=')
flags = 1; /* Nogroup */
goto do_one;
}
if (isdigit(match[0]))
{
unsigned int win;
sscanf(match, "%x", &win);
ewin = EwinFindByChildren(win);
goto do_one;
}
match_one = 1;
if (!strcmp(match, "all"))
{
type = 'a';
match_one = 0;
flags = 1; /* Nogroup */
}
else if (match[0] == '=')
{
type = 's';
match++;
flags = 1; /* Nogroup */
}
else if (strchr(match, '*'))
{
type = 'w';
match_one = 0;
flags = 1; /* Nogroup */
}
else
{
type = 's';
}
len = strlen(match);
if (len <= 0)
return NULL;
ewins = EwinListGetAll(&num);
if (!ewins)
return NULL;
nfound = 0;
lst = NULL;
for (i = 0; i < num; i++)
{
ewin = ewins[i];
if (type == 'a') /* All */
{
}
else if (type == 'w') /* Wildcard */
{
if (!matchregexp(match, EwinGetIcccmName(ewin)))
continue;
}
else /* Match name (substring) */
{
const char *name;
name = EwinGetIcccmName(ewin);
if (!name)
continue;
if (!strcasestr(name, match))
continue;
}
nfound++;
lst = EREALLOC(EWin *, lst, nfound);
lst[nfound - 1] = ewin;
if (match_one)
break;
}
goto done;
do_one:
if (!ewin)
return NULL;
nfound = 1;
lst = EMALLOC(EWin *, 1);
if (!lst)
return NULL;
lst[0] = ewin;
done:
if (pnum)
*pnum = nfound;
if (pflags)
*pflags = flags;
return lst;
}
static EWin *
IpcFindEwin(const char *match)
{
EWin *ewin, **lst;
lst = IpcFindEwins(match, NULL, NULL);
if (!lst)
return NULL;
ewin = lst[0];
Efree(lst);
return ewin;
}
static int
SetEwinBoolean(const char *txt, char *item, const char *value, int set)
{
@ -454,7 +323,7 @@ IPC_WinList(const char *params, Client * c __UNUSED__)
if (!match || !match[0])
match = "all";
lst = IpcFindEwins(match, &num, NULL);
lst = EwinsFindByExpr(match, &num, NULL);
if (!lst)
{
IpcPrintf("No windows matching %s\n", match);
@ -972,7 +841,7 @@ IPC_WinOps(const char *params, Client * c __UNUSED__)
return;
}
lst = IpcFindEwins(match, &num, &flags);
lst = EwinsFindByExpr(match, &num, &flags);
if (!lst)
{
IpcPrintf("No windows matching %s\n", match);
@ -1245,7 +1114,7 @@ IPC_EwinInfo(const char *params, Client * c __UNUSED__)
sscanf(params, "%1000s", match);
lst = IpcFindEwins(match, &num, NULL);
lst = EwinsFindByExpr(match, &num, NULL);
if (!lst)
{
IpcPrintf("No windows matching %s\n", match);
@ -1302,8 +1171,8 @@ IPC_Reparent(const char *params, Client * c __UNUSED__)
sscanf(params, "%100s %100s", param1, param2);
ewin = IpcFindEwin(param1);
enew = IpcFindEwin(param2);
ewin = EwinFindByExpr(param1);
enew = EwinFindByExpr(param2);
if (!ewin || !enew)
IpcPrintf("No matching client or target EWin found\n");
else