summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Gurgel Pinho <eduardo@mad4.Chagas>2008-11-19 22:03:17 -0300
committerEduardo Gurgel Pinho <eduardo@mad4.Chagas>2008-11-19 22:03:17 -0300
commit4e851d82c2408e5023ee1361a0e6a248cd918ac6 (patch)
tree3274582daa2bea57907f516b6f18f401b06a4a8b
parent5032a41755435523d66aa1e1d019f3c625f49123 (diff)
downloadsmartput-4e851d82c2408e5023ee1361a0e6a248cd918ac6.tar.gz
smartput-4e851d82c2408e5023ee1361a0e6a248cd918ac6.tar.bz2
Undo implemented.
-rw-r--r--smartput.c128
-rw-r--r--smartput.xml.in5
2 files changed, 122 insertions, 11 deletions
diff --git a/smartput.c b/smartput.c
index bc6c3e2..db1ee1b 100644
--- a/smartput.c
+++ b/smartput.c
@@ -49,6 +49,15 @@
#include <compiz-core.h>
#include "smartput_options.h"
+typedef struct _SmartputUndoInfo {
+ Window window;
+
+ int x, y;
+ int width, height;
+
+ unsigned int state;
+} SmartputUndoInfo;
+
static int SmartputDisplayPrivateIndex;
typedef struct _SmartputDisplay
@@ -75,6 +84,9 @@ typedef struct _SmartputScreen
int animation; /* animation flag */
int grabIndex; /* screen grab index */
+
+ SmartputUndoInfo undoInfo;
+
} SmartputScreen;
typedef struct _SmartputWindow
@@ -427,19 +439,70 @@ smartputSameViewport(CompWindow* w1,
return ((x1 == x2) && (y1 == y2));
}
+/*
+ * Update undo information.
+ */
+static void
+smartputUpdateUndoInfo (CompScreen *s,
+ CompWindow *w,
+ Bool reset)
+{
+ SMARTPUT_SCREEN (s);
+ if(reset)
+ {
+ sps->undoInfo.window = None;
+ sps->undoInfo.x = 0;
+ sps->undoInfo.y = 0;
+ sps->undoInfo.height = 0;
+ sps->undoInfo.width = 0;
+ sps->undoInfo.state = 0;
+ }
+ else
+ {
+ sps->undoInfo.window = w->id;
+ sps->undoInfo.x = w->serverX;
+ sps->undoInfo.y = w->serverY;
+ sps->undoInfo.width = w->serverWidth;
+ sps->undoInfo.height = w->serverHeight;
+ sps->undoInfo.state = w->state;
+ }
+}
+
+/*
+ * Compute size based on undo information.
+ */
+
+static unsigned int
+smartputUndoResize (CompScreen *s,
+ XWindowChanges *xwc)
+{
+ unsigned int mask;
+
+ SMARTPUT_SCREEN (s);
+
+ mask |= CWWidth | CWHeight | CWX | CWY;
+ xwc->x = sps->undoInfo.x;
+ xwc->y = sps->undoInfo.y;
+ xwc->width = sps->undoInfo.width;
+ xwc->height = sps->undoInfo.height;
+
+ return mask;
+}
+
static Bool
smartputInitiate(CompWindow *w,
CompAction *action,
CompActionState state,
CompOption *option,
- int nOption)
+ int nOption,
+ Bool undo)
{
CompDisplay *d;
if (w)
{
CompScreen* s = w->screen;
- SMARTPUT_SCREEN(s);
+ SMARTPUT_SCREEN (s);
if(otherScreenGrabExist (s, "smartput", 0))
return FALSE;
@@ -453,12 +516,23 @@ smartputInitiate(CompWindow *w,
int width, height;
unsigned int mask;
- XWindowChanges *xwc = malloc(sizeof(XWindowChanges));
-
+ XWindowChanges *xwc;
+
d = s->display;
SMARTPUT_WINDOW (w);
- mask = smartputComputeResize (w, xwc);
+ free(spw->xwc);
+ xwc = malloc(sizeof(XWindowChanges));
+
+ if(undo)
+ {
+ if(!(w->id == sps->undoInfo.window) || sps->undoInfo.window == None) return FALSE;
+ mask = smartputUndoResize (s,xwc);
+ }
+ else
+ {
+ mask = smartputComputeResize (w, xwc);
+ }
if (mask)
{
if (constrainNewWindowSize (w, xwc->width, xwc->height,
@@ -471,12 +545,14 @@ smartputInitiate(CompWindow *w,
spw->lastX = w->serverX;
spw->lastX = w->serverY;
- spw->targetX = xwc->x;
- spw->targetY = xwc->y;
- spw->xwc = xwc;
- spw->mask = mask;
+ spw->targetX = xwc->x;
+ spw->targetY = xwc->y;
+ spw->xwc = xwc;
+ spw->mask = mask;
sps->lastWindow = w->id;
+ smartputUpdateUndoInfo (s, w, undo);
+
spw->animation = TRUE;
sps->animation = TRUE;
@@ -488,6 +564,34 @@ smartputInitiate(CompWindow *w,
}
/*
+ * Tries to undo Smart Put last action
+ */
+static Bool
+smartputUndo(CompDisplay *d,
+ CompAction *action,
+ CompActionState state,
+ CompOption *option,
+ int nOption)
+{
+ Window xid;
+ CompWindow *w;
+
+ xid = getIntOptionNamed (option, nOption, "window", 0);
+ if(!xid)
+ xid = d->activeWindow;
+
+ w = findWindowAtDisplay (d, xid);
+
+ if (w)
+ {
+ return smartputInitiate(w, action, state,
+ option, nOption,TRUE);
+
+ }
+ return FALSE;
+}
+
+/*
* Initially triggered keybinding.
* Fetch the window, fetch the resize, constrain it.
*
@@ -519,7 +623,7 @@ smartputTrigger(CompDisplay *d,
if (w->wmType & CompWindowTypeDockMask)
return FALSE;
return smartputInitiate(w, action, state,
- option, nOption);
+ option, nOption,FALSE);
}
return FALSE;
@@ -731,6 +835,7 @@ smartputDonePaintScreen (CompScreen *s)
if(spw->mask && spw->xwc)
configureXWindow (w, spw->mask, spw->xwc);
spw->mask = 0;
+ free(spw->xwc);
spw->xwc = NULL;
}
if (sps->grabIndex)
@@ -923,6 +1028,7 @@ smartputInitDisplay (CompPlugin *p,
smartputSetTriggerKeyInitiate (d, smartputTrigger);
smartputSetTriggerAllKeyInitiate (d, smartputAllTrigger);
+ smartputSetUndoKeyInitiate (d, smartputUndo);
WRAP (spd, d, handleEvent, smartputHandleEvent);
d->base.privates[SmartputDisplayPrivateIndex].ptr = spd;
@@ -1027,7 +1133,7 @@ smartputFiniWindow (CompPlugin *p,
CompWindow *w)
{
SMARTPUT_WINDOW (w);
-
+ if(spw->xwc) free(spw->xwc);
free (spw);
}
diff --git a/smartput.xml.in b/smartput.xml.in
index 11df9c1..4552ea7 100644
--- a/smartput.xml.in
+++ b/smartput.xml.in
@@ -12,6 +12,11 @@
<_long>Smart Put!!!</_long>
<default>&lt;Super&gt;&lt;Shift&gt;KP_Multiply</default>
</option>
+ <option name="undo_key" type="key">
+ <_short>Undo Smart Put on last "smartputed" window</_short>
+ <_long>Undo!!!</_long>
+ <default>&lt;Super&gt;&lt;Control&gt;KP_Multiply</default>
+ </option>
<option name="trigger_all_key" type="key">
<_short>Apply Smart Put on current viewport</_short>
<_long>Smart Put!!!</_long>