Hide Group struct internals

This commit is contained in:
Kim Woelders 2020-02-08 06:36:03 +01:00
parent 36b4eff7cc
commit 7011dc150d
5 changed files with 97 additions and 78 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2008-2019 Kim Woelders
* Copyright (C) 2008-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -259,39 +259,8 @@ ListWinGroupMembersForEwin(const EWin * ewin, int action, char nogroup,
if (!grp)
continue;
switch (action)
{
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_STACKING:
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;
}
if (!GroupMatchAction(grp, action))
continue;
do_add:
gwins = EREALLOC(EWin *, gwins, gwcnt + 1);

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2018 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -40,10 +40,33 @@
#define USE_GROUP_SHOWHIDE 1 /* Enable group borders */
#define GROUP_SELECT_ALL 0
#define GROUP_SELECT_EWIN_ONLY 1
#define GROUP_SELECT_ALL_EXCEPT_EWIN 2
#define SET_OFF 0
#define SET_ON 1
#define SET_TOGGLE 2
typedef struct _groupconfig {
char iconify;
char kill;
char move;
char raise;
char set_border;
char shade;
char stick;
} GroupConfig;
struct _group {
dlist_t list;
int index;
EWin **members;
int num_members;
GroupConfig cfg;
char save; /* Used in snapshot - must save */
};
static LIST_HEAD(group_list);
static struct {
@ -126,8 +149,22 @@ GroupFind(int gid)
return LIST_FIND(Group, &group_list, GroupMatchId, INT2PTR(gid));
}
EWin *const *
GroupGetMembers(const Group * g, int *num)
{
*num = g->num_members;
return g->members;
}
int
GroupRemember(Group * g)
{
g->save = 1;
return g->index;
}
void
GroupRemember(int gid)
GroupRememberByGid(int gid)
{
Group *g;
@ -138,6 +175,42 @@ GroupRemember(int gid)
g->save = 1;
}
int
GroupMatchAction(const Group * g, int action)
{
int match;
switch (action)
{
default:
match = 0;
break;
case GROUP_ACTION_SET_WINDOW_BORDER:
match = g->cfg.set_border;
break;
case GROUP_ACTION_ICONIFY:
match = g->cfg.iconify;
break;
case GROUP_ACTION_MOVE:
match = g->cfg.move;
break;
case GROUP_ACTION_STACKING:
match = g->cfg.raise;
break;
case GROUP_ACTION_STICK:
match = g->cfg.stick;
break;
case GROUP_ACTION_SHADE:
match = g->cfg.shade;
break;
case GROUP_ACTION_KILL:
match = g->cfg.kill;
break;
}
return match;
}
static Group *
GroupFind2(const char *groupid)
{

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2013 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -23,12 +23,8 @@
*/
#ifndef _GROUPS_H_
#define _GROUPS_H_
#include "ewins.h"
#include "list.h"
#define GROUP_SELECT_ALL 0
#define GROUP_SELECT_EWIN_ONLY 1
#define GROUP_SELECT_ALL_EXCEPT_EWIN 2
#include "etypes.h"
/* For window group listing */
#define GROUP_ACTION_ANY 0
@ -40,30 +36,15 @@
#define GROUP_ACTION_SHADE 6
#define GROUP_ACTION_SET_WINDOW_BORDER 7
typedef struct _groupconfig {
char iconify;
char kill;
char move;
char raise;
char set_border;
char shade;
char stick;
} GroupConfig;
struct _group {
dlist_t list;
int index;
EWin **members;
int num_members;
GroupConfig cfg;
char save; /* Used in snapshot - must save */
};
/* finders.c */
EWin **ListWinGroupMembersForEwin(const EWin * ewin, int action,
char nogroup, int *num);
/* groups.c */
int GroupMatchAction(const Group * g, int action);
int GroupRemember(Group * g);
void GroupRememberByGid(int gid);
EWin *const *GroupGetMembers(const Group * g, int *num);
Group *const *EwinGetGroups(const EWin * ewin, int *num);
Group *EwinsInGroup(const EWin * ewin1, const EWin * ewin2);
void GroupsEwinAdd(EWin * ewin, const int *pgid, int ngid);
@ -72,6 +53,5 @@ void GroupsLoad(void);
void GroupsSave(void);
Group **GroupsGetList(int *pnum);
int GroupsGetSwapmove(void);
void GroupRemember(int gid);
#endif /* _GROUPS_H_ */

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2018 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -574,7 +574,8 @@ MenuLoadFromGroups(Menu * m)
{
Menu *mm;
Group **lst;
int i, j, num;
EWin *const *ewlst;
int i, j, num, ewnum;
char s[256];
MenuItem *mi;
@ -586,24 +587,23 @@ MenuLoadFromGroups(Menu * m)
for (i = 0; i < num; i++)
{
ewlst = GroupGetMembers(lst[i], &ewnum);
mm = MenuCreate("__SUBMENUGROUP_E", NULL, m, NULL);
Esnprintf(s, sizeof(s), "gop %i showhide",
EwinGetClientXwin(lst[i]->members[0]));
Esnprintf(s, sizeof(s), "gop %i showhide", EwinGetClientXwin(ewlst[0]));
mi = MenuItemCreate(_("Show/Hide this group"), NULL, s, NULL);
Esnprintf(s, sizeof(s), "wop %#x ic",
EwinGetClientXwin(lst[i]->members[0]));
Esnprintf(s, sizeof(s), "wop %#x ic", EwinGetClientXwin(ewlst[0]));
MenuAddItem(mm, mi);
mi = MenuItemCreate(_("Iconify this group"), NULL, s, NULL);
MenuAddItem(mm, mi);
for (j = 0; j < lst[i]->num_members; j++)
for (j = 0; j < ewnum; j++)
{
Esnprintf(s, sizeof(s), "wop %#x focus",
EwinGetClientXwin(lst[i]->members[j]));
mi = MenuItemCreate(EwinGetTitle(lst[i]->members[j]), NULL,
s, NULL);
EwinGetClientXwin(ewlst[j]));
mi = MenuItemCreate(EwinGetTitle(ewlst[j]), NULL, s, NULL);
MenuAddItem(mm, mi);
}
Esnprintf(s, sizeof(s), _("Group %i"), i);

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2004-2018 Kim Woelders
* Copyright (C) 2004-2020 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -418,10 +418,7 @@ _SnapUpdateEwinGroups(Snapshot * sn, const EWin * ewin, char onoff)
EFREE_SET(sn->groups, EMALLOC(int, num_groups));
for (j = 0; j < num_groups; j++)
{
sn->groups[j] = groups[j]->index;
groups[j]->save = 1;
}
sn->groups[j] = GroupRemember(groups[j]);
}
else
{
@ -1355,7 +1352,7 @@ _SnapshotsLoad(FILE * fs)
sn->groups = EREALLOC(int, sn->groups, sn->num_groups);
sn->groups[sn->num_groups - 1] = atoi(s);
GroupRemember(sn->groups[sn->num_groups - 1]);
GroupRememberByGid(sn->groups[sn->num_groups - 1]);
}
#if USE_COMPOSITE
else if (!strcmp(buf, "OPACITY"))