summaryrefslogtreecommitdiff
path: root/beryl-plugins/src/group
diff options
context:
space:
mode:
authormaniac <maniac@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2007-02-14 14:51:57 +0000
committermaniac <maniac@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2007-02-14 14:51:57 +0000
commitbd7758006a76da32c6efc4420ed48e545a03650e (patch)
treec22cdd7cddb3b92418794805c5548fb4f8cf2357 /beryl-plugins/src/group
parent8ed1ef61f82b7ef866d0c81e77383b8b499ed968 (diff)
downloadmarex-dev-bd7758006a76da32c6efc4420ed48e545a03650e.tar.gz
marex-dev-bd7758006a76da32c6efc4420ed48e545a03650e.tar.bz2
group plugin: added initial framework for preserving grouping state after WM changes / restarts
git-svn-id: file:///beryl/trunk@4061 d7aaf104-2d23-0410-ae22-9d23157bf5a3
Diffstat (limited to 'beryl-plugins/src/group')
-rw-r--r--beryl-plugins/src/group/group.c117
-rw-r--r--beryl-plugins/src/group/group.h8
-rw-r--r--beryl-plugins/src/group/init.c2
-rw-r--r--beryl-plugins/src/group/tab.c4
4 files changed, 120 insertions, 11 deletions
diff --git a/beryl-plugins/src/group/group.c b/beryl-plugins/src/group/group.c
index e45779d..0118268 100644
--- a/beryl-plugins/src/group/group.c
+++ b/beryl-plugins/src/group/group.c
@@ -61,6 +61,85 @@ groupFindWindowIndex(CompWindow *w, GroupSelection *g)
}
/*
+ * groupFindGroupByID
+ *
+ */
+static GroupSelection*
+groupFindGroupByID(CompScreen *s, long int id)
+{
+ GroupSelection *group;
+ GROUP_SCREEN(s);
+
+ for (group = gs->groups; group; group = group->next) {
+ if (group->identifier == id)
+ break;
+ }
+
+ return group;
+}
+
+/*
+ * groupCheckWindowProperty
+ *
+ */
+static Bool
+groupCheckWindowProperty(CompWindow *w, long int *id, Bool *tabbed)
+{
+ Atom type;
+ int fmt;
+ unsigned long nitems, exbyte;
+ long int *data;
+
+ GROUP_DISPLAY(w->screen->display);
+
+ if (XGetWindowProperty(w->screen->display->display, w->id,
+ gd->groupWinPropertyAtom, 0, 2,
+ False, XA_CARDINAL, &type, &fmt,
+ &nitems, &exbyte,
+ (unsigned char **)&data) == Success)
+ {
+ if (type == XA_CARDINAL && fmt == 32 && nitems == 2)
+ {
+ if (id)
+ *id = data[0];
+ if (tabbed)
+ *tabbed = (Bool)data[1];
+
+ XFree(data);
+ return TRUE;
+ }
+ else if (fmt != 0)
+ XFree(data);
+ }
+ return FALSE;
+}
+
+/*
+ * groupUpdateWindowProperty
+ *
+ */
+void groupUpdateWindowProperty(CompWindow *w)
+{
+ GROUP_WINDOW(w);
+ GROUP_DISPLAY(w->screen->display);
+
+ if (gw->group) {
+ long int buffer[2];
+
+ buffer[0] = gw->group->identifier;
+ buffer[1] = (gw->slot) ? TRUE : FALSE;
+
+ XChangeProperty(w->screen->display->display,
+ w->id, gd->groupWinPropertyAtom, XA_CARDINAL,
+ 32, PropModeReplace, (unsigned char *) buffer, 2);
+ } else {
+ XDeleteProperty(w->screen->display->display,
+ w->id, gd->groupWinPropertyAtom);
+ }
+
+}
+
+/*
* groupGrabScreen
*
*/
@@ -263,9 +342,10 @@ void groupDeleteGroupWindow(CompWindow * w, Bool allowRegroup)
damageWindowOutputExtents(w);
gw->group = NULL;
updateWindowOutputExtents(w);
+ groupUpdateWindowProperty(w);
if (allowRegroup && gs->opt[GROUP_SCREEN_OPTION_AUTOTAB].value.b && (w->type & gs->wMask)) {
- groupAddWindowToGroup(w, NULL);
+ groupAddWindowToGroup(w, NULL, 0);
groupTabGroup(w);
}
}
@@ -295,9 +375,10 @@ void groupDeleteGroup(GroupSelection *group)
damageWindowOutputExtents(cw);
gw->group = NULL;
updateWindowOutputExtents(cw);
+ groupUpdateWindowProperty(cw);
if (gs->opt[GROUP_SCREEN_OPTION_AUTOTAB].value.b && (cw->type & gs->wMask)) {
- groupAddWindowToGroup(cw, NULL);
+ groupAddWindowToGroup(cw, NULL, 0);
groupTabGroup(cw);
}
}
@@ -337,7 +418,7 @@ void groupDeleteGroup(GroupSelection *group)
*
*/
void
-groupAddWindowToGroup(CompWindow * w, GroupSelection *group)
+groupAddWindowToGroup(CompWindow * w, GroupSelection *group, long int initialIdent)
{
GROUP_SCREEN(w->screen);
GROUP_WINDOW(w);
@@ -359,6 +440,8 @@ groupAddWindowToGroup(CompWindow * w, GroupSelection *group)
gw->group = group;
updateWindowOutputExtents(w);
+
+ groupUpdateWindowProperty(w);
if(group->nWins == 2)
updateWindowOutputExtents(group->windows[0]); // First window in the group got its glow too...
@@ -405,6 +488,11 @@ groupAddWindowToGroup(CompWindow * w, GroupSelection *group)
g->ungroupState = UngroupNone;
g->tabBar = NULL;
+ if (initialIdent)
+ g->identifier = (long int) w->id;
+ else
+ g->identifier = initialIdent;
+
g->grabWindow = None;
g->grabMask = 0;
@@ -433,6 +521,8 @@ groupAddWindowToGroup(CompWindow * w, GroupSelection *group)
}
gw->group = g;
+
+ groupUpdateWindowProperty(w);
}
}
@@ -469,7 +559,7 @@ groupGroupWindows(CompDisplay * d, CompAction * action,
// we need to do one first to get the pointer of a new group
cw = gd->tmpSel.windows[0];
- groupAddWindowToGroup(cw, group);
+ groupAddWindowToGroup(cw, group, 0);
GROUP_WINDOW (cw);
gw->inSelection = FALSE;
@@ -480,7 +570,7 @@ groupGroupWindows(CompDisplay * d, CompAction * action,
cw = gd->tmpSel.windows[i];
GROUP_WINDOW(cw);
- groupAddWindowToGroup(cw, group);
+ groupAddWindowToGroup(cw, group, 0);
gw->inSelection = FALSE;
damageScreen(cw->screen);
@@ -836,7 +926,7 @@ groupHandleButtonReleaseEvent(CompDisplay *d, XEvent *event)
}
// Change the group.
- groupAddWindowToGroup(gs->draggedSlot->window, group);
+ groupAddWindowToGroup(gs->draggedSlot->window, group, 0);
} else
groupUnhookTabBarSlot(group->tabBar, gs->draggedSlot, TRUE);
@@ -1422,10 +1512,19 @@ Bool groupDamageWindowRect(CompWindow * w, Bool initial, BoxPtr rect)
if (initial) {
GROUP_WINDOW(w);
-
- if (gs->opt[GROUP_SCREEN_OPTION_AUTOTAB].value.b && (w->type & gs->wMask)) {
+ Bool tabbed;
+ long int id;
+
+ /* read window property to see if window was grouped
+ before - if it was, regroup */
+ if (groupCheckWindowProperty(w, &id, &tabbed)) {
+ GroupSelection *group = groupFindGroupByID(w->screen, id);
+ groupAddWindowToGroup(w, group, id);
+ if (tabbed)
+ groupTabGroup(w);
+ } else if (gs->opt[GROUP_SCREEN_OPTION_AUTOTAB].value.b && (w->type & gs->wMask)) {
if (!gw->group && (gw->windowState == WindowNormal)) {
- groupAddWindowToGroup(w, NULL);
+ groupAddWindowToGroup(w, NULL, 0);
groupTabGroup(w);
}
}
diff --git a/beryl-plugins/src/group/group.h b/beryl-plugins/src/group/group.h
index 0e13e62..e313701 100644
--- a/beryl-plugins/src/group/group.h
+++ b/beryl-plugins/src/group/group.h
@@ -373,6 +373,9 @@ struct _GroupSelection {
CompWindow **windows;
int nWins;
+ // unique identifier for this group
+ long int identifier;
+
GroupTabBarSlot* topTab;
GroupTabBarSlot* prevTopTab;
@@ -416,6 +419,8 @@ typedef struct _GroupDisplay {
GroupSelection tmpSel;
Bool ignoreMode;
+
+ Atom groupWinPropertyAtom;
CompTimeoutHandle timeoutHandle;
} GroupDisplay;
@@ -521,6 +526,7 @@ Bool groupSetScreenOption(CompScreen * s, char *name, CompOptionValue * value);
/*
* group.c
*/
+void groupUpdateWindowProperty(CompWindow *w);
void groupGrabScreen(CompScreen * s, GroupScreenGrabState newState);
void groupHandleEvent(CompDisplay * d, XEvent * event);
Bool groupGroupWindows(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);
@@ -528,7 +534,7 @@ Bool groupUnGroupWindows(CompDisplay * d, CompAction * action, CompActionState s
int groupFindWindowIndex(CompWindow *w, GroupSelection *g);
void groupDeleteGroupWindow(CompWindow * w, Bool allowRegroup);
void groupDeleteGroup(GroupSelection *group);
-void groupAddWindowToGroup(CompWindow * w, GroupSelection *group);
+void groupAddWindowToGroup(CompWindow * w, GroupSelection *group, long int initialIdent);
void groupSyncWindows(GroupSelection *group);
void groupRaiseWindows(CompWindow * top, GroupSelection *group);
Bool groupRemoveWindow(CompDisplay * d, CompAction * action, CompActionState state, CompOption * option, int nOption);
diff --git a/beryl-plugins/src/group/init.c b/beryl-plugins/src/group/init.c
index 152c93a..4b29f7c 100644
--- a/beryl-plugins/src/group/init.c
+++ b/beryl-plugins/src/group/init.c
@@ -52,6 +52,8 @@ Bool groupInitDisplay(CompPlugin * p, CompDisplay * d)
gd->ignoreMode = FALSE;
+ gd->groupWinPropertyAtom = XInternAtom(d->display, "_BERYL_GROUP", 0);
+
groupDisplayInitOptions(gd);
WRAP(gd, d, handleEvent, groupHandleEvent);
diff --git a/beryl-plugins/src/group/tab.c b/beryl-plugins/src/group/tab.c
index 76e3cb2..93eb9b4 100644
--- a/beryl-plugins/src/group/tab.c
+++ b/beryl-plugins/src/group/tab.c
@@ -1369,7 +1369,7 @@ void groupTabGroup(CompWindow *main)
GROUP_WINDOW(cw);
int x = WIN_X(cw), y = WIN_Y(cw);
-
+
if(gw->animateState & IS_ANIMATED)
{
x = gw->destination.x;
@@ -1955,6 +1955,7 @@ void groupDeleteTabBarSlot(GroupTabBar *bar, GroupTabBarSlot *slot)
}
gw->slot = NULL;
+ groupUpdateWindowProperty(w);
free(slot);
}
@@ -1977,6 +1978,7 @@ void groupCreateSlot(GroupSelection *group, CompWindow *w)
groupInsertTabBarSlot(group->tabBar, slot);
gw->slot = slot;
+ groupUpdateWindowProperty(w);
}
#define SPRING_K gs->opt[GROUP_SCREEN_OPTION_TAB_DRAG_SPRING_K].value.f