summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMassimo Mund <massimo.mund@stud.uni-duisburg-essen.de>2008-11-23 21:05:28 +0100
committerMassimo Mund <massimo.mund@stud.uni-duisburg-essen.de>2008-11-23 21:05:28 +0100
commit1c5750dcd5f7a2943692300b9e7572397c2c7550 (patch)
treef8dbeceaed857f2c8b9f9d1001e2defcc8f36ed6
parent1171d5480cdba4d374f6d12191b0914c57656039 (diff)
downloadsmartput-1c5750dcd5f7a2943692300b9e7572397c2c7550.tar.gz
smartput-1c5750dcd5f7a2943692300b9e7572397c2c7550.tar.bz2
Added window stacking, allow windows shrink, Mousetriggers, window margin
-rw-r--r--smartput.c159
-rw-r--r--smartput.xml.in30
2 files changed, 177 insertions, 12 deletions
diff --git a/smartput.c b/smartput.c
index 4da90eb..6241877 100644
--- a/smartput.c
+++ b/smartput.c
@@ -9,6 +9,9 @@
* Copyright : (C) 2008 by Marco Diego Aurelio Mesquita
* E-mail : marcodiegomesquita@gmail.com
*
+ * Copyright : (C) 2008 by Massimo Mund
+ * E-mail : mo@lancode.de
+ *
* Based on put.c
* Copyright : (C) 2006 by Darryll Truchan
* E-mail : <moppsy@comcast.net>
@@ -36,8 +39,6 @@
* - Animation configuration.
* - Smart Put All animation.
* - Undo
- * - Mouse triggers
- * - Padding
*
* More:
* This plugin is based on Maximumize Plugin (Author: Kristian LyngstĂžl <kristian@bohemians.org>)
@@ -353,10 +354,13 @@ smartputFindRect (CompWindow *w,
int currentArea = tmpRect.width*tmpRect.height;
- CompScreen *s = w->screen;
- CompWindow *window;
+ CompScreen *s = w->screen;
+ CompDisplay *d = s->display;
+ CompWindow *window;
+
int maxArea = -1;
- int area = 0;
+ int area = 0;
+
for (window = s->windows; window; window = window->next)
{
BOX testBoxes[16];
@@ -379,8 +383,110 @@ smartputFindRect (CompWindow *w,
}
}
}
- if(maxArea >= currentArea) return maxBox;
- else return windowBox;
+
+ /* Check if the user has choosen that windows also may shrink
+ * And if so, windows may just shrink to a minimal size of 50x50
+ */
+ if(smartputGetAllowWindowsShrink (d) &&
+ (maxBox.x2 - maxBox.x1) > 50 &&
+ (maxBox.y2 - maxBox.y1) > 50)
+ return maxBox;
+
+ if(maxArea >= currentArea)
+ return maxBox;
+ else
+ return windowBox;
+}
+
+/*
+ * Finding the best window to stack the current window on.
+ */
+
+static BOX
+smartputFindStapleRect (CompWindow *w,
+ Region r)
+{
+ BOX windowBox, maxBox;
+ CompWindow *window;
+ int maxArea, maxRate;
+
+ windowBox.x1 = w->serverX;
+ windowBox.y1 = w->serverY;
+ windowBox.x2 = w->serverX + w->serverWidth ;
+ windowBox.y2 = w->serverY + w->serverHeight;
+
+ maxArea = -1;
+ maxRate = 0;
+ maxBox = windowBox;
+ for (window = w->screen->windows; window; window = window->next) {
+
+ BOX current;
+ current.x1 = window->serverX;
+ current.y1 = window->serverY;
+ current.x2 = window->serverX + window->serverWidth;
+ current.y2 = window->serverY + window->serverHeight;
+
+ if (window->invisible || window->hidden || window->minimized)
+ continue;
+
+ if (current.x1 == windowBox.x1 &&
+ current.x2 == windowBox.x2 &&
+ current.y1 == windowBox.y1 &&
+ current.y2 == windowBox.y2)
+ continue;
+
+ if (current.x1 == 0 &&
+ current.x2 == w->screen->width &&
+ current.y1 == 0 &&
+ current.y2 == w->screen->height)
+ continue;
+
+ int rXpos, rYpos = 0;
+ int rWidth, rHeight = 0;
+ if (current.x1 > windowBox.x1)
+ rXpos = current.x1;
+ else
+ rXpos = windowBox.x1;
+
+ if (current.x2 < windowBox.x2)
+ rWidth = current.x2 - rXpos;
+ else
+ rWidth = windowBox.x2 - rXpos;
+
+ if (current.y1 > windowBox.y1)
+ rYpos = current.y1;
+ else
+ rYpos = windowBox.y1;
+
+ if (current.y2 < windowBox.y2)
+ rHeight = current.y2 - rYpos;
+ else
+ rHeight = windowBox.y2 - rYpos;
+
+ int cover_area = 0;
+ int cover_rate = 0;
+ if (rWidth < 0 || rHeight < 0)
+ {
+ cover_area = 0;
+ cover_rate = 0;
+ }
+ else
+ {
+ cover_area = rHeight * rWidth;
+ cover_rate = ((cover_area*100)/((current.x2-current.x1)*(current.y2-current.y1)));
+ }
+
+ if ((cover_rate >= 98 && cover_area > maxArea) ||
+ cover_rate > maxRate)
+ {
+ maxArea = cover_area;
+ maxRate = cover_rate;
+ maxBox = current;
+ }
+ }
+
+ return maxBox;
+
}
/*
@@ -391,16 +497,44 @@ smartputComputeResize(CompWindow *w,
XWindowChanges *xwc)
{
CompOutput *output;
+ CompDisplay *d;
Region region;
unsigned int mask = 0;
BOX box;
output = &w->screen->outputDev[outputDeviceForWindow (w)];
region = smartputEmptyRegion (w, &output->region);
+ d = w->screen->display;
+
if (!region)
- return mask;
+ return mask;
box = smartputFindRect (w, region);
+
+ /* Find out if the box which is given back by smartputFindRect
+ * has other dimensions than the current window
+ * If it has not, the window will not move and if the users
+ * set it in the options we will try to stack it onto an
+ * underlying window
+ */
+ if (box.x1 == w->serverX &&
+ box.y1 == w->serverY &&
+ (box.x2 - box.x1) == w->serverWidth &&
+ (box.y2 - box.y1) == w->serverHeight &&
+ smartputGetAllowWindowsStack (d))
+ {
+ box = smartputFindStapleRect(w, region);
+ }
+ else
+ {
+ /* The margin stuff which is set up in the options */
+ int margin = smartputGetWindowMargin (d);
+ box.x1 = box.x1 + margin;
+ box.x2 = box.x2 - margin;
+ box.y1 = box.y1 + margin;
+ box.y2 = box.y2 - margin;
+ }
+
XDestroyRegion (region);
if (box.x1 != w->serverX)
@@ -509,7 +643,6 @@ smartputInitiate(CompWindow *w,
/*
* Grab the screen
*/
-
if(!sps->grabIndex)
sps->grabIndex = pushScreenGrab (s, s->invisibleCursor, "smartput");
if(!sps->grabIndex)
@@ -534,6 +667,7 @@ smartputInitiate(CompWindow *w,
{
mask = smartputComputeResize (w, xwc);
}
+
if (mask)
{
if (constrainNewWindowSize (w, xwc->width, xwc->height,
@@ -833,13 +967,12 @@ smartputDonePaintScreen (CompScreen *s)
if(w)
{
SMARTPUT_WINDOW (w);
-
if(spw->mask && spw->xwc)
{
if (w->mapNum && (spw->mask & (CWWidth | CWHeight)))
{
- sendSyncRequest (w);
- configureXWindow (w, spw->mask, spw->xwc);
+ sendSyncRequest (w);
+ configureXWindow (w, spw->mask, spw->xwc);
}
spw->mask = 0;
free(spw->xwc);
@@ -1034,6 +1167,8 @@ smartputInitDisplay (CompPlugin *p,
spd->lastWindow = None;
+ smartputSetTriggerButtonInitiate(d, smartputTrigger);
+ smartputSetTriggerAllButtonInitiate (d, smartputAllTrigger);
smartputSetTriggerKeyInitiate (d, smartputTrigger);
smartputSetTriggerAllKeyInitiate (d, smartputAllTrigger);
smartputSetUndoKeyInitiate (d, smartputUndo);
diff --git a/smartput.xml.in b/smartput.xml.in
index 4552ea7..abcbabe 100644
--- a/smartput.xml.in
+++ b/smartput.xml.in
@@ -22,6 +22,36 @@
<_long>Smart Put!!!</_long>
<default>&lt;Super&gt;&lt;Control&gt;&lt;Shift&gt;KP_Multiply</default>
</option>
+ <option name="trigger_button" type="button">
+ <_short>Initiate Smartput on current window</_short>
+ <_long>Smart Put!!!</_long>
+ <default>Button8</default>
+ </option>
+ <option name="trigger_all_button" type="button">
+ <_short>Initiate Smartput on current viewport</_short>
+ <_long>Smart Put!!!</_long>
+ <default>Button9</default>
+ </option>
+ </group>
+ <group>
+ <_short>Options</_short>
+ <option name="allow_windows_stack" type="bool">
+ <_short>Allow stack windows</_short>
+ <_long>Stack windows on each other if there is no place left to place them</_long>
+ <default>false</default>
+ </option>
+ <option name="allow_windows_shrink" type="bool">
+ <_short>Allow windows shrink</_short>
+ <_long>Just place the window when the new size is larger than the old one</_long>
+ <default>false</default>
+ </option>
+ <option name="window_margin" type="int">
+ <_short>Window margin</_short>
+ <_long>The distance windows hold between each other</_long>
+ <default>0</default>
+ <min>0</min>
+ <max>500</max>
+ </option>
</group>
</display>
</plugin>