summaryrefslogtreecommitdiff
path: root/beryl-plugins/src/miniview.c
diff options
context:
space:
mode:
authorracarr <racarr@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2007-02-09 00:14:55 +0000
committerracarr <racarr@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2007-02-09 00:14:55 +0000
commit40f0ba59d6d9100e945f158a52d9fbddce3cc69f (patch)
tree3a5072daedfd592d9c3e90d5728a64d03afaee55 /beryl-plugins/src/miniview.c
parentc5c8de6394ef3f03cf14a3ef8feba1cc41f3d593 (diff)
downloadmarex-dev-40f0ba59d6d9100e945f158a52d9fbddce3cc69f.tar.gz
marex-dev-40f0ba59d6d9100e945f158a52d9fbddce3cc69f.tar.bz2
Readd miniview plugin, this has a few fixes from the last version in repos notably it works on multihead
git-svn-id: file:///beryl/trunk@3829 d7aaf104-2d23-0410-ae22-9d23157bf5a3
Diffstat (limited to 'beryl-plugins/src/miniview.c')
-rw-r--r--beryl-plugins/src/miniview.c518
1 files changed, 518 insertions, 0 deletions
diff --git a/beryl-plugins/src/miniview.c b/beryl-plugins/src/miniview.c
new file mode 100644
index 0000000..6342b95
--- /dev/null
+++ b/beryl-plugins/src/miniview.c
@@ -0,0 +1,518 @@
+ /**
+ *
+ * Beryl miniview plugin
+ *
+ * miniview.c
+ *
+ * Copyright (c) 2006 Robert Carr <racarr@beryl-project.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ **/
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <sys/time.h>
+
+#include <beryl.h>
+
+#define MINIVIEW_CREATE_KEY_DEFAULT "Tab"
+#define MINIVIEW_CREATE_MODIFIERS_DEFAULT (ShiftMask)
+
+#define MINIVIEW_MOVE_KEY_DEFAULT Button1
+#define MINIVIEW_MOVE_MODIFIERS_DEFAULT ( ShiftMask )
+
+#define MINIVIEW_INCREASE_KEY_DEFAULT "i"
+#define MINIVIEW_INCREASE_MODIFIERS_DEFAULT (CompSuperMask | CompAltMask)
+
+#define MINIVIEW_DECREASE_KEY_DEFAULT "d"
+#define MINIVIEW_DECREASE_MODIFIERS_DEFAULT (CompSuperMask | CompAltMask)
+
+
+#define MINIVIEW_HIDE_KEY_DEFAULT "h"
+#define MINIVIEW_HIDE_MODIFIERS_DEFAULT (ShiftMask | CompSuperMask)
+
+/* Unimplemented increase/decrease */
+
+static int displayPrivateIndex;
+
+#define MINIVIEW_DISPLAY_OPTION_CREATE 0
+#define MINIVIEW_DISPLAY_OPTION_MOVE 1
+#define MINIVIEW_DISPLAY_OPTION_HIDE 2
+#define MINIVIEW_DISPLAY_OPTION_NUM 3
+
+typedef struct _MiniviewDisplay
+{
+ int screenPrivateIndex;
+ HandleEventProc handleEvent;
+
+ CompOption opt[MINIVIEW_DISPLAY_OPTION_NUM];
+} MiniviewDisplay;
+
+typedef struct _MiniviewScreen
+{
+ DonePaintScreenProc donePaintScreen;
+ PaintScreenProc paintScreen;
+ PreparePaintScreenProc preparePaintScreen;
+ PaintTransformedScreenProc paintTransformedScreen;
+
+ Bool showing;
+ int miniX;
+ int miniY;
+ int miniViewport;
+ int miniViewportY;
+ int moveStep;
+ float zCam;
+
+
+ float size;
+
+ Bool moving;
+
+
+ int grabIndex;
+
+} MiniviewScreen;
+
+#define GET_MINIVIEW_DISPLAY(d) \
+ ((MiniviewDisplay *) (d)->privates[displayPrivateIndex].ptr)
+#define MINIVIEW_DISPLAY(d) \
+ MiniviewDisplay *md = GET_MINIVIEW_DISPLAY(d);
+
+#define GET_MINIVIEW_SCREEN(s,md) \
+ ((MiniviewScreen *) (s)->privates[(md)->screenPrivateIndex].ptr)
+#define MINIVIEW_SCREEN(s) \
+ MiniviewScreen *ms = GET_MINIVIEW_SCREEN(s, GET_MINIVIEW_DISPLAY(s->display))
+
+#define NUM_OPTIONS(d) (sizeof ((d->opt)) / sizeof (CompOption))
+
+
+static void miniviewHandleEvent(CompDisplay * d, XEvent * event)
+{
+ MINIVIEW_DISPLAY(d);
+
+ CompScreen *s;
+ switch (event->type)
+ {
+ default:
+ break;
+ }
+ UNWRAP(md,d,handleEvent);
+ (*d->handleEvent)(d,event);
+ WRAP(md,d,handleEvent,miniviewHandleEvent);
+}
+
+static Bool miniviewCreate(CompDisplay * d, CompAction * action,
+ CompActionState state, CompOption * option,
+ int nOption)
+{
+ CompScreen *s;
+ Window xid;
+
+ xid = getIntOptionNamed(option, nOption, "root", 0);
+ s = findScreenAtDisplay(d, xid);
+ MINIVIEW_SCREEN(s);
+ ms->showing = !ms->showing;
+ ms->miniViewport = s->x;
+ ms->miniViewportY = s->y;
+ ms->miniX = d->pointerX;
+ ms->miniY = d->pointerY;
+ ms->zCam = 0;
+ ms->moveStep = 1;
+ damageScreen(s);
+ return FALSE;
+}
+
+static Bool miniviewMove(CompDisplay * d, CompAction * action,
+ CompActionState state, CompOption * option,
+ int nOption)
+{
+ CompScreen *s;
+ Window xid;
+
+ xid = getIntOptionNamed(option, nOption, "root", 0);
+ s = findScreenAtDisplay(d, xid);
+ MINIVIEW_SCREEN(s);
+ ms->moving = !ms->moving;
+ damageScreen(s);
+
+
+ return FALSE;
+}
+
+static Bool miniviewHide(CompDisplay * d, CompAction * action,
+ CompActionState state, CompOption * option,
+ int nOption)
+{
+ CompScreen *s;
+ Window xid;
+
+ xid = getIntOptionNamed(option, nOption, "root", 0);
+ s = findScreenAtDisplay(d, xid);
+ MINIVIEW_SCREEN(s);
+ ms->showing = !ms->showing;
+ damageScreen(s);
+
+
+ return FALSE;
+}
+
+
+static Bool miniviewPaintScreen(CompScreen * s,
+ const ScreenPaintAttrib * sAttrib,
+ Region region, int output, unsigned int mask)
+{
+ Bool status;
+
+ MINIVIEW_SCREEN(s);
+ if (ms->showing)
+ {
+ mask |= PAINT_SCREEN_TRANSFORMED_MASK;
+ }
+ UNWRAP(ms, s, paintScreen);
+ status = (*s->paintScreen) (s, sAttrib, region, output, mask);
+ WRAP(ms, s, paintScreen, miniviewPaintScreen);
+
+ return status;
+}
+
+static void miniviewPreparePaintScreen(CompScreen *s, int ICouldCareLess)
+{
+ MINIVIEW_SCREEN(s);
+ if ((ms->moving && ms->showing))
+ {
+ int winX, winY;
+ int rootX, rootY;
+ unsigned int mask_return;
+ Window root_return;
+ Window child_return;
+
+ XQueryPointer(s->display->display, s->root,
+ &root_return, &child_return,
+ &rootX, &rootY, &winX, &winY, &mask_return);
+
+ ms->miniX = rootX;
+ ms->miniY = rootY;
+
+ }
+ UNWRAP(ms,s,preparePaintScreen);
+ (*s->preparePaintScreen) (s,ICouldCareLess);
+ WRAP(ms,s,preparePaintScreen,miniviewPreparePaintScreen);
+}
+
+static void miniviewPaintTransformedScreen(CompScreen * s,
+ const ScreenPaintAttrib * sAttrib,
+ Region region, int output,
+ unsigned int mask)
+{
+ MINIVIEW_SCREEN(s);
+
+ UNWRAP(ms, s, paintTransformedScreen);
+ (*s->paintTransformedScreen) (s, sAttrib, region, output, mask);
+ if (ms->showing )
+ {
+ //mask &= PAINT_SCREEN_TRANSFORMED_MASK;
+ int oldFilter = s->display->textureFilter;
+ s->display->textureFilter = GL_LINEAR_MIPMAP_LINEAR;
+
+ glPushMatrix();
+ if (ms->zCam > -ms->size)
+ ms->zCam -= .075;
+
+
+ ScreenPaintAttrib * sa = sAttrib;
+
+ glScalef(1.0f,1.0f,1.0f*-ms->zCam);
+ glTranslatef(-1.0,1.0,0);
+
+ float compensation;
+ compensation = ms->size - 2.0f;
+ compensation /= 2;
+ glTranslatef(-compensation,compensation,0);
+
+ if (ms->moveStep <= 0.95)
+ ms->moveStep += 0.05;
+
+ glTranslatef((1/((float)s->width/(float)ms->miniX)*-ms->zCam),
+ (-1/((float)s->height/(float)ms->miniY)*-ms->zCam),
+ 0);
+ int move = 0;
+ int ymove = 0;
+
+ while (s->x != ms->miniViewport)
+ {
+ moveScreenViewport(s, 1, 0, FALSE);
+ move++;
+ }
+ while (s->y != ms->miniViewport)
+ {
+ moveScreenViewport(s,0,1,FALSE);
+ ymove++;
+ }
+ (*s->paintTransformedScreen) (s, sa, &s->region, output, mask);
+ s->display->textureFilter = oldFilter;
+
+ moveScreenViewport(s,-move,-ymove,FALSE);
+
+ glPopMatrix();
+ }
+
+
+ WRAP(ms, s, paintTransformedScreen, miniviewPaintTransformedScreen);
+
+}
+
+static void miniviewDonePaintScreen(CompScreen * s)
+{
+ MINIVIEW_SCREEN(s);
+
+ if (ms->showing)
+ damageScreen(s);
+
+
+
+ UNWRAP(ms, s, donePaintScreen);
+ (*s->donePaintScreen) (s);
+ WRAP(ms, s, donePaintScreen, miniviewDonePaintScreen);
+}
+
+static void miniviewDisplayInitOptions(MiniviewDisplay * md)
+{
+ CompOption *o;
+
+ o = &md->opt[MINIVIEW_DISPLAY_OPTION_CREATE];
+ o->advanced = False;
+ o->name = "create";
+ o->group = N_("Misc. Settings");
+ o->subGroup = N_("");
+ o->displayHints = "";
+ o->shortDesc = N_("Create");
+ o->longDesc = N_("Create thumbnail of current viewport");
+ o->type = CompOptionTypeAction;
+ o->value.action.initiate = miniviewCreate;
+ o->value.action.terminate = 0;
+ o->value.action.bell = 0;
+ o->value.action.edgeMask = 0;
+ o->value.action.state = CompActionStateInitKey;
+ o->value.action.type = CompBindingTypeKey;
+ o->value.action.key.modifiers = MINIVIEW_CREATE_MODIFIERS_DEFAULT;
+ o->value.action.key.keysym = XStringToKeysym(MINIVIEW_CREATE_KEY_DEFAULT);
+
+ o = &md->opt[MINIVIEW_DISPLAY_OPTION_HIDE];
+ o->advanced = False;
+ o->name = "Hide";
+ o->group = N_("Misc. Settings");
+ o->subGroup = N_("");
+ o->displayHints = "";
+ o->shortDesc = N_("Hide");
+ o->longDesc = N_("Engage miniview hide mode.");
+ o->type = CompOptionTypeAction;
+ o->value.action.initiate = miniviewHide;
+ o->value.action.terminate = 0;
+ o->value.action.bell = 0;
+ o->value.action.edgeMask = 0;
+ o->value.action.state = CompActionStateInitKey;
+ o->value.action.type = CompBindingTypeKey;
+ o->value.action.key.modifiers = MINIVIEW_HIDE_MODIFIERS_DEFAULT;
+ o->value.action.key.keysym = XStringToKeysym(MINIVIEW_HIDE_KEY_DEFAULT);
+
+ o = &md->opt[MINIVIEW_DISPLAY_OPTION_MOVE];
+ o->advanced = False;
+ o->name = "move";
+ o->group = N_("Misc. Settings");
+ o->subGroup = N_("");
+ o->displayHints = "";
+ o->shortDesc = N_("Move preview");
+ o->longDesc = N_("Move current preview to mouse location");
+ o->type = CompOptionTypeAction;
+ o->value.action.initiate = miniviewMove;
+ o->value.action.terminate = 0;
+ o->value.action.bell = 0;
+ o->value.action.edgeMask = 0;
+ o->value.action.state =
+ CompActionStateInitButton;
+ o->value.action.type = CompBindingTypeButton;
+ //o->value.action.key.modifiers = MINIVIEW_MOVE_MODIFIERS_DEFAULT;
+ //o->value.action.key.keysym = XStringToKeysym(MINIVIEW_MOVE_KEY_DEFAULT);
+ o->value.action.button.modifiers = MINIVIEW_MOVE_MODIFIERS_DEFAULT;
+ o->value.action.button.button = MINIVIEW_MOVE_KEY_DEFAULT;
+
+}
+
+static CompOption *miniviewGetDisplayOptions(CompDisplay * d, int *count)
+{
+ if (d)
+ {
+ MINIVIEW_DISPLAY(d);
+ *count = NUM_OPTIONS(md);
+ return md->opt;
+ }
+ else
+ {
+ MiniviewDisplay *md = malloc(sizeof(MiniviewDisplay));
+
+ miniviewDisplayInitOptions(md);
+ *count = NUM_OPTIONS(md);
+ return md->opt;
+ }
+}
+
+static Bool
+miniviewSetDisplayOption(CompDisplay * d, char *name, CompOptionValue * value)
+{
+ CompOption *o;
+ int index;
+
+ MINIVIEW_DISPLAY(d);
+
+ o = compFindOption(md->opt, NUM_OPTIONS(md), name, &index);
+
+ if (!o)
+ return FALSE;
+
+ switch (index)
+ {
+ case MINIVIEW_DISPLAY_OPTION_CREATE:
+ case MINIVIEW_DISPLAY_OPTION_MOVE:
+ case MINIVIEW_DISPLAY_OPTION_HIDE:
+ if (setDisplayAction(d, o, value))
+ return TRUE;
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+static Bool miniviewInitDisplay(CompPlugin * p, CompDisplay * d)
+{
+ MiniviewDisplay *md;
+
+ md = malloc(sizeof(MiniviewDisplay));
+ if (!md)
+ return FALSE;
+
+ md->screenPrivateIndex = allocateScreenPrivateIndex(d);
+
+ if (md->screenPrivateIndex < 0)
+ {
+ free(md);
+ return FALSE;
+ }
+
+ miniviewDisplayInitOptions(md);
+
+ WRAP(md,d,handleEvent,miniviewHandleEvent);
+ d->privates[displayPrivateIndex].ptr = md;
+
+ return TRUE;
+}
+
+static void miniviewFiniDisplay(CompPlugin * p, CompDisplay * d)
+{
+ MINIVIEW_DISPLAY(d);
+
+
+ UNWRAP(md,d,handleEvent);
+ freeScreenPrivateIndex(d, md->screenPrivateIndex);
+ free(md);
+}
+
+static Bool miniviewInitScreen(CompPlugin * p, CompScreen * s)
+{
+ MiniviewScreen *ms;
+
+ MINIVIEW_DISPLAY(s->display);
+
+ ms = malloc(sizeof(MiniviewScreen));
+
+ if (!ms)
+ return FALSE;
+
+ ms->grabIndex = ms->moving = ms->miniX = ms->miniY = ms->miniViewport = ms->showing = ms->zCam =
+ ms->moveStep = 0;
+ ms->size = 3.0;
+ addScreenAction(s, &md->opt[MINIVIEW_DISPLAY_OPTION_CREATE].value.action);
+ addScreenAction(s, &md->opt[MINIVIEW_DISPLAY_OPTION_MOVE].value.action);
+ addScreenAction(s, &md->opt[MINIVIEW_DISPLAY_OPTION_HIDE].value.action);
+
+ WRAP(ms, s, paintScreen, miniviewPaintScreen);
+ WRAP(ms, s, donePaintScreen, miniviewDonePaintScreen);
+ WRAP(ms, s, paintTransformedScreen, miniviewPaintTransformedScreen);
+ WRAP(ms, s, preparePaintScreen, miniviewPreparePaintScreen);
+
+ s->privates[md->screenPrivateIndex].ptr = ms;
+
+ return TRUE;
+}
+
+static void miniviewFiniScreen(CompPlugin * p, CompScreen * s)
+{
+ MINIVIEW_SCREEN(s);
+ MINIVIEW_DISPLAY(s->display);
+
+ removeScreenAction(s, &md->opt[MINIVIEW_DISPLAY_OPTION_CREATE].value.action);
+ removeScreenAction(s, &md->opt[MINIVIEW_DISPLAY_OPTION_MOVE].value.action);
+ removeScreenAction(s, &md->opt[MINIVIEW_DISPLAY_OPTION_HIDE].value.action);
+ UNWRAP(ms, s, paintScreen);
+ UNWRAP(ms, s, donePaintScreen);
+ UNWRAP(ms, s, paintTransformedScreen);
+ UNWRAP(ms, s, preparePaintScreen);
+ free(ms);
+}
+
+static Bool miniviewInit(CompPlugin * p)
+{
+ displayPrivateIndex = allocateDisplayPrivateIndex();
+ if (displayPrivateIndex < 0)
+ return FALSE;
+ return TRUE;
+}
+
+static void miniviewFini(CompPlugin * p)
+{
+ if (displayPrivateIndex >= 0)
+ freeDisplayPrivateIndex(displayPrivateIndex);
+}
+
+
+
+CompPluginVTable miniviewVTable = {
+ "miniview",
+ N_("Mini-viewport"),
+ N_("Viewport preview plugin"),
+ miniviewInit,
+ miniviewFini,
+ miniviewInitDisplay,
+ miniviewFiniDisplay,
+ miniviewInitScreen,
+ miniviewFiniScreen,
+ 0,
+ 0,
+ miniviewGetDisplayOptions,
+ miniviewSetDisplayOption,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ BERYL_ABI_INFO,
+ "beryl-plugins",
+ "misc",
+ 0,
+ 0,
+ TRUE,
+};
+
+CompPluginVTable *getCompPluginInfo(void)
+{
+ return &miniviewVTable;
+}