summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Lyngstol <kristian@bohemians.org>2008-01-18 16:41:09 +0100
committerKristian Lyngstol <kristian@bohemians.org>2008-01-18 16:41:09 +0100
commite595578f2be2f4f9e5f8d78130adc8eb5257b1ff (patch)
treecb28902c84512e4693d1198e241ea4065ff62872
parentfade28c36e1fa26ee9be8a0b8de10b6557ecb33c (diff)
downloadshelf-e595578f2be2f4f9e5f8d78130adc8eb5257b1ff.tar.gz
shelf-e595578f2be2f4f9e5f8d78130adc8eb5257b1ff.tar.bz2
Binding to scale to a 1/2, 1/3 or a 1/6th of the screen.
-rw-r--r--shelf.c46
-rw-r--r--shelf.xml.in7
2 files changed, 52 insertions, 1 deletions
diff --git a/shelf.c b/shelf.c
index ba2ef2c..825da91 100644
--- a/shelf.c
+++ b/shelf.c
@@ -238,6 +238,50 @@ shelfTrigger (CompDisplay *d,
return TRUE;
}
+/* Returns the ratio to multiply by to get a window that's 1/ration the
+ * size of the screen.
+ */
+static inline float
+shelfRat (CompWindow *w,
+ float ratio)
+{
+ float winHeight = (float) w->height;
+ float winWidth = (float) w->width;
+ float scrHeight = (float) w->screen->height;
+ float scrWidth = (float) w->screen->width;
+ float ret;
+ if (winHeight/scrHeight < winWidth/scrWidth)
+ ret = scrWidth/winWidth;
+ else
+ ret = scrHeight/winHeight;
+ return ret/ratio;
+}
+
+static Bool
+shelfTriggerScreen (CompDisplay *d,
+ CompAction *action,
+ CompActionState state,
+ CompOption *option,
+ int nOption)
+{
+ CompWindow *w = findWindowAtDisplay (d, d->activeWindow);
+ if (!w)
+ return TRUE;
+ SHELF_SCREEN (w->screen);
+ SHELF_WINDOW (w);
+ if (sw->targetScale > shelfRat(w,2.0f))
+ shelfScaleWindow (w, shelfRat(w,2.0f));
+ else if (sw->targetScale <= shelfRat(w,2.0f) &&
+ sw->targetScale > shelfRat(w,3.0f))
+ shelfScaleWindow (w, shelfRat(w,3.0f));
+ else if (sw->targetScale <= shelfRat(w,3.0f) &&
+ sw->targetScale > shelfRat(w,6.0f))
+ shelfScaleWindow (w, shelfRat(w,6.0f));
+ else
+ shelfScaleWindow (w, 1.0f);
+ return TRUE;
+}
+
/* shelfInc and shelfDec are matcing functions and bindings;
* They increase and decrease the scale factor by 'interval'.
*/
@@ -532,7 +576,9 @@ shelfInitDisplay (CompPlugin *p,
freeScreenPrivateIndex (d, screenPrivateIndex);
return FALSE;
}
+
shelfSetTriggerKeyInitiate (d, shelfTrigger);
+ shelfSetTriggerscreenKeyInitiate (d, shelfTriggerScreen);
shelfSetIncButtonInitiate (d, shelfInc);
shelfSetDecButtonInitiate (d, shelfDec);
WRAP (sd, d, handleEvent, shelfHandleEvent);
diff --git a/shelf.xml.in b/shelf.xml.in
index 130beeb..7eed12a 100644
--- a/shelf.xml.in
+++ b/shelf.xml.in
@@ -9,9 +9,14 @@
<_short>Bindings</_short>
<option name="trigger_key" type="key">
<_short>Trigger scale down</_short>
- <_long> Scale a window down to half size. </_long>
+ <_long> Scale a window down to a portion of it's size. </_long>
<default>&lt;Super&gt;l</default>
</option>
+ <option name="triggerscreen_key" type="key">
+ <_short>Trigger scale down to screen</_short>
+ <_long> Scale a window down to a ration of the screen size. Respectively half, a third or a sixth of the screen.</_long>
+ <default>&lt;Super&gt;p</default>
+ </option>
<option name="dec_button" type="button">
<_short>Make the window smaller</_short>
<_long> Reduces the scale factor making the window smaller. </_long>