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) 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -259,39 +259,8 @@ ListWinGroupMembersForEwin(const EWin * ewin, int action, char nogroup,
if (!grp) if (!grp)
continue; continue;
switch (action) if (!GroupMatchAction(grp, action))
{ continue;
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;
}
do_add: do_add:
gwins = EREALLOC(EWin *, gwins, gwcnt + 1); 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) 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -40,10 +40,33 @@
#define USE_GROUP_SHOWHIDE 1 /* Enable group borders */ #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_OFF 0
#define SET_ON 1 #define SET_ON 1
#define SET_TOGGLE 2 #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 LIST_HEAD(group_list);
static struct { static struct {
@ -126,8 +149,22 @@ GroupFind(int gid)
return LIST_FIND(Group, &group_list, GroupMatchId, INT2PTR(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 void
GroupRemember(int gid) GroupRememberByGid(int gid)
{ {
Group *g; Group *g;
@ -138,6 +175,42 @@ GroupRemember(int gid)
g->save = 1; 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 * static Group *
GroupFind2(const char *groupid) GroupFind2(const char *groupid)
{ {

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -23,12 +23,8 @@
*/ */
#ifndef _GROUPS_H_ #ifndef _GROUPS_H_
#define _GROUPS_H_ #define _GROUPS_H_
#include "ewins.h"
#include "list.h"
#define GROUP_SELECT_ALL 0 #include "etypes.h"
#define GROUP_SELECT_EWIN_ONLY 1
#define GROUP_SELECT_ALL_EXCEPT_EWIN 2
/* For window group listing */ /* For window group listing */
#define GROUP_ACTION_ANY 0 #define GROUP_ACTION_ANY 0
@ -40,30 +36,15 @@
#define GROUP_ACTION_SHADE 6 #define GROUP_ACTION_SHADE 6
#define GROUP_ACTION_SET_WINDOW_BORDER 7 #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 */ /* finders.c */
EWin **ListWinGroupMembersForEwin(const EWin * ewin, int action, EWin **ListWinGroupMembersForEwin(const EWin * ewin, int action,
char nogroup, int *num); char nogroup, int *num);
/* groups.c */ /* 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 *const *EwinGetGroups(const EWin * ewin, int *num);
Group *EwinsInGroup(const EWin * ewin1, const EWin * ewin2); Group *EwinsInGroup(const EWin * ewin1, const EWin * ewin2);
void GroupsEwinAdd(EWin * ewin, const int *pgid, int ngid); void GroupsEwinAdd(EWin * ewin, const int *pgid, int ngid);
@ -72,6 +53,5 @@ void GroupsLoad(void);
void GroupsSave(void); void GroupsSave(void);
Group **GroupsGetList(int *pnum); Group **GroupsGetList(int *pnum);
int GroupsGetSwapmove(void); int GroupsGetSwapmove(void);
void GroupRemember(int gid);
#endif /* _GROUPS_H_ */ #endif /* _GROUPS_H_ */

View File

@ -1,6 +1,6 @@
/* /*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors * 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
@ -574,7 +574,8 @@ MenuLoadFromGroups(Menu * m)
{ {
Menu *mm; Menu *mm;
Group **lst; Group **lst;
int i, j, num; EWin *const *ewlst;
int i, j, num, ewnum;
char s[256]; char s[256];
MenuItem *mi; MenuItem *mi;
@ -586,24 +587,23 @@ MenuLoadFromGroups(Menu * m)
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
ewlst = GroupGetMembers(lst[i], &ewnum);
mm = MenuCreate("__SUBMENUGROUP_E", NULL, m, NULL); mm = MenuCreate("__SUBMENUGROUP_E", NULL, m, NULL);
Esnprintf(s, sizeof(s), "gop %i showhide", Esnprintf(s, sizeof(s), "gop %i showhide", EwinGetClientXwin(ewlst[0]));
EwinGetClientXwin(lst[i]->members[0]));
mi = MenuItemCreate(_("Show/Hide this group"), NULL, s, NULL); mi = MenuItemCreate(_("Show/Hide this group"), NULL, s, NULL);
Esnprintf(s, sizeof(s), "wop %#x ic", Esnprintf(s, sizeof(s), "wop %#x ic", EwinGetClientXwin(ewlst[0]));
EwinGetClientXwin(lst[i]->members[0]));
MenuAddItem(mm, mi); MenuAddItem(mm, mi);
mi = MenuItemCreate(_("Iconify this group"), NULL, s, NULL); mi = MenuItemCreate(_("Iconify this group"), NULL, s, NULL);
MenuAddItem(mm, mi); 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", Esnprintf(s, sizeof(s), "wop %#x focus",
EwinGetClientXwin(lst[i]->members[j])); EwinGetClientXwin(ewlst[j]));
mi = MenuItemCreate(EwinGetTitle(lst[i]->members[j]), NULL, mi = MenuItemCreate(EwinGetTitle(ewlst[j]), NULL, s, NULL);
s, NULL);
MenuAddItem(mm, mi); MenuAddItem(mm, mi);
} }
Esnprintf(s, sizeof(s), _("Group %i"), i); 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) 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 * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * 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)); EFREE_SET(sn->groups, EMALLOC(int, num_groups));
for (j = 0; j < num_groups; j++) for (j = 0; j < num_groups; j++)
{ sn->groups[j] = GroupRemember(groups[j]);
sn->groups[j] = groups[j]->index;
groups[j]->save = 1;
}
} }
else else
{ {
@ -1355,7 +1352,7 @@ _SnapshotsLoad(FILE * fs)
sn->groups = EREALLOC(int, sn->groups, sn->num_groups); sn->groups = EREALLOC(int, sn->groups, sn->num_groups);
sn->groups[sn->num_groups - 1] = atoi(s); 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 #if USE_COMPOSITE
else if (!strcmp(buf, "OPACITY")) else if (!strcmp(buf, "OPACITY"))