summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Young <rcxdude@gmail.com>2008-05-04 12:25:14 +0100
committerDouglas Young <rcxdude@gmail.com>2008-05-04 12:25:14 +0100
commitc17bd4f68a1de33de52782d5cb8aed6bc86b2a2e (patch)
tree7315b10c9d4bbf28dd683f2f8e9b0eb82e86456a
parent239aa158bf9452d932e6914833972a7a50ead590 (diff)
downloaddodge-c17bd4f68a1de33de52782d5cb8aed6bc86b2a2e.tar.gz
dodge-c17bd4f68a1de33de52782d5cb8aed6bc86b2a2e.tar.bz2
added handling of changing options while dodge is active
-rw-r--r--dodge.c268
1 files changed, 184 insertions, 84 deletions
diff --git a/dodge.c b/dodge.c
index 049845b..6e6f828 100644
--- a/dodge.c
+++ b/dodge.c
@@ -60,8 +60,10 @@ typedef struct _DodgeWindow
typedef struct _DodgeScreen
{
- PaintOutputProc paintOutput;
- PreparePaintScreenProc preparePaintScreen;
+ PaintOutputProc paintOutput;
+ PreparePaintScreenProc preparePaintScreen;
+ WindowStateChangeNotifyProc windowStateChangeNotify;
+
PositionPollingHandle pollHandle;
int windowPrivateIndex;
@@ -103,15 +105,9 @@ typedef struct _DodgeScreen
DodgeWindow *dw = GET_DODGE_WINDOW (w, \
GET_DODGE_SCREEN (w->screen, \
GET_DODGE_DISPLAY (w->screen->display)))
+
#define POSITIVE(x) ((x)>0?(x):0)
-static void
-positionUpdate (CompScreen *s, int x, int y)
-{
- DODGE_SCREEN (s);
- ds->px = x;
- ds->py = y;
-}
#define PI 3.1415926
#define FRICTION (0.005f * ds->friction)
@@ -274,60 +270,7 @@ dodgestep (CompWindow *w, int ms, int away)
}
-static void
-dodgeMarkDodgeWindows (CompScreen *s)
-{
- DODGE_SCREEN (s);
- CompWindow *w;
- for (w = s->windows; w; w = w->next)
- {
- DODGE_WINDOW (w);
- if((matchEval(dodgeGetWindowTypes (s->display),w) || dw->selected) &&
- !(w->invisible || w->destroyed || w->hidden || w->minimized))
- {
- if (dw)
- {
- dw->isdodge = TRUE;
- dw->vx = 0;
- dw->vy = 0;
- dw->ox = WIN_CX(w);
- dw->oy = WIN_CY(w);
- if (ds->model == ModelOffScreen)
- {
- if (WIN_CX(w) > WIN_CY(w) &&
- WIN_CX(w) * w->screen->height +
- WIN_CY(w) * w->screen->width >
- (w->screen->width * w->screen->height))
- dw->pos = WEST;
- if (WIN_CX(w) < WIN_CY(w) &&
- WIN_CX(w) * w->screen->height +
- WIN_CY(w) * w->screen->width >
- (w->screen->width * w->screen->height))
- dw->pos = SOUTH;
- if (WIN_CX(w) > WIN_CY(w) &&
- WIN_CX(w) * w->screen->height +
- WIN_CY(w) * w->screen->width <
- (w->screen->width * w->screen->height))
- dw->pos = NORTH;
- if (WIN_CX(w) < WIN_CY(w) &&
- WIN_CX(w) * w->screen->height +
- WIN_CY(w) * w->screen->width <
- (w->screen->width * w->screen->height))
- dw->pos = EAST;
- }
- }
- }
- else
- {
- if (dw->isdodge)
- {
- dw->isdodge = FALSE;
- dw->ox = 0;
- dw->oy = 0;
- }
- }
- }
-}
+
static void
dodgePreparePaintScreen (CompScreen *s,
int ms)
@@ -383,8 +326,62 @@ dodgePreparePaintScreen (CompScreen *s,
WRAP (ds, s, preparePaintScreen, dodgePreparePaintScreen);
}
+static void
+dodgeUpdateDodgeWindow (CompWindow *w)
+{
+ DODGE_WINDOW (w);
+ DODGE_SCREEN (w->screen);
+ if((matchEval(dodgeGetWindowTypes (w->screen->display),w) || dw->selected) &&
+ !(w->invisible || w->destroyed || w->hidden || w->minimized))
+ {
+ if (dw)
+ {
+ dw->isdodge = TRUE;
+ dw->vx = 0;
+ dw->vy = 0;
+ /* don't change original position if dodge is active */
+ if (!ds->active || !(dw->ox || dw->oy))
+ {
+ dw->ox = WIN_CX(w);
+ dw->oy = WIN_CY(w);
+ }
+ if (WIN_CX(w) > WIN_CY(w) &&
+ WIN_CX(w) * w->screen->height +
+ WIN_CY(w) * w->screen->width >
+ (w->screen->width * w->screen->height))
+ dw->pos = WEST;
+ if (WIN_CX(w) < WIN_CY(w) &&
+ WIN_CX(w) * w->screen->height +
+ WIN_CY(w) * w->screen->width >
+ (w->screen->width * w->screen->height))
+ dw->pos = SOUTH;
+ if (WIN_CX(w) > WIN_CY(w) &&
+ WIN_CX(w) * w->screen->height +
+ WIN_CY(w) * w->screen->width <
+ (w->screen->width * w->screen->height))
+ dw->pos = NORTH;
+ if (WIN_CX(w) < WIN_CY(w) &&
+ WIN_CX(w) * w->screen->height +
+ WIN_CY(w) * w->screen->width <
+ (w->screen->width * w->screen->height))
+ dw->pos = EAST;
+
+ }
+ }
+ else
+ {
+ if (dw->isdodge)
+ {
+ dw->isdodge = FALSE;
+ dw->ox = 0;
+ dw->oy = 0;
+ }
+ }
+
+}
+
static Bool
-dodgeMark (CompDisplay *d,
+dodgeSelect (CompDisplay *d,
CompAction *action,
CompActionState state,
CompOption *option,
@@ -396,9 +393,14 @@ dodgeMark (CompDisplay *d,
xid = getIntOptionNamed (option, nOption, "window", 0);
w = findWindowAtDisplay (d, xid);
DODGE_WINDOW(w);
+ DODGE_SCREEN(w->screen);
dw->selected = !dw->selected;
+ if (ds->active)
+ dodgeUpdateDodgeWindow (w);
+
return TRUE;
}
+
static Bool
dodgeToggle (CompDisplay *d,
CompAction *action,
@@ -407,28 +409,31 @@ dodgeToggle (CompDisplay *d,
int nOption)
{
CompScreen *s;
- Window xid;
- xid = getIntOptionNamed (option, nOption, "root", 0);
- s = findScreenAtDisplay (d, xid);
- if (s)
+ for (s = d->screens; s; s = s->next)
{
- DODGE_SCREEN(s);
- if (ds->active)
- ds->exiting = TRUE;
- else
+ if (s)
{
- ds->model = dodgeGetModel (d);
- ds->springk = dodgeGetSpringK (d);
- ds->friction = dodgeGetFriction (d);
- ds->padding = dodgeGetPadding (d);
- ds->ox = s->x;
- ds->oy = s->y;
- dodgeMarkDodgeWindows (s);
- ds->active = TRUE;
+ DODGE_SCREEN(s);
+ if (ds->active)
+ ds->exiting = TRUE;
+ else
+ {
+ ds->model = dodgeGetModel (d);
+ ds->springk = dodgeGetSpringK (d);
+ ds->friction = dodgeGetFriction (d);
+ ds->padding = dodgeGetPadding (d);
+ ds->ox = s->x;
+ ds->oy = s->y;
+ CompWindow *w;
+ for (w = s->windows; w; w = w->next)
+ {
+ dodgeUpdateDodgeWindow (w);
+ }
+ ds->active = TRUE;
+ }
}
- return TRUE;
}
- return FALSE;
+ return TRUE;
}
@@ -467,9 +472,94 @@ dodgePaintOutput (CompScreen *s,
}
+static void
+positionUpdate (CompScreen *s, int x, int y)
+{
+ DODGE_SCREEN (s);
+ ds->px = x;
+ ds->py = y;
+}
+
+static void
+dodgeStateChange (CompWindow *w,
+ unsigned int last)
+{
+ DODGE_SCREEN (w->screen);
+ if(ds->active)
+ dodgeUpdateDodgeWindow (w);
+}
+
+static void
+dodgeModelChange (CompDisplay *d,
+ CompOption *opt,
+ DodgeDisplayOptions num)
+{
+ CompScreen *s;
+ for (s = d->screens; s; s = s->next)
+ {
+ DODGE_SCREEN (s);
+ ds->model = dodgeGetModel (d);
+ }
+}
+
+static void
+dodgeFrictionChange (CompDisplay *d,
+ CompOption *opt,
+ DodgeDisplayOptions num)
+{
+ CompScreen *s;
+ for (s = d->screens; s; s = s->next)
+ {
+ DODGE_SCREEN (s);
+ ds->friction = dodgeGetFriction (d);
+ }
+}
+
+static void
+dodgePaddingChange (CompDisplay *d,
+ CompOption *opt,
+ DodgeDisplayOptions num)
+{
+ CompScreen *s;
+ for (s = d->screens; s; s = s->next)
+ {
+ DODGE_SCREEN (s);
+ ds->padding = dodgeGetPadding (d);
+ }
+}
+
+static void
+dodgeKChange (CompDisplay *d,
+ CompOption *opt,
+ DodgeDisplayOptions num)
+{
+ CompScreen *s;
+ for (s = d->screens; s; s = s->next)
+ {
+ DODGE_SCREEN (s);
+ ds->springk = dodgeGetSpringK (d);
+ }
+}
+
+static void
+dodgeTypeChange (CompDisplay *d,
+ CompOption *opt,
+ DodgeDisplayOptions num)
+{
+ CompScreen *s;
+ for (s = d->screens; s; s = s->next)
+ {
+ CompWindow *w;
+ for (w = s->windows; w; w = w->next)
+ {
+ dodgeUpdateDodgeWindow (w);
+ }
+ }
+}
+
static Bool
dodgeInitDisplay (CompPlugin *p,
- CompDisplay *d)
+ CompDisplay *d)
{
DodgeDisplay *dd;
int mousepollindex;
@@ -494,8 +584,14 @@ dodgeInitDisplay (CompPlugin *p,
dodgeSetDodgeToggleKeyInitiate (d, dodgeToggle);
dodgeSetDodgeToggleButtonInitiate (d, dodgeToggle);
dodgeSetDodgeToggleEdgeInitiate (d, dodgeToggle);
- dodgeSetDodgeSelectKeyInitiate (d, dodgeMark);
+ dodgeSetDodgeSelectKeyInitiate (d, dodgeSelect);
+ dodgeSetModelNotify (d, dodgeModelChange);
+ dodgeSetFrictionNotify (d, dodgeFrictionChange);
+ dodgeSetPaddingNotify (d, dodgePaddingChange);
+ dodgeSetSpringKNotify (d, dodgeKChange);
+ dodgeSetWindowTypesNotify (d, dodgeTypeChange);
+
dd->mpFunc = d->base.privates[mousepollindex].ptr;
return TRUE;
}
@@ -526,6 +622,8 @@ dodgeInitScreen (CompPlugin *p,
WRAP (ds, s, preparePaintScreen, dodgePreparePaintScreen);
WRAP (ds, s, paintOutput, dodgePaintOutput);
+ WRAP (ds, s, windowStateChangeNotify, dodgeStateChange);
+
ds->windowPrivateIndex = allocateWindowPrivateIndex (s);
s->base.privates[dd->screenPrivateIndex].ptr = ds;
@@ -562,6 +660,8 @@ dodgeInitWindow (CompPlugin *p,
dw->isdodge = FALSE;
dw->selected = FALSE;
w->base.privates[ds->windowPrivateIndex].ptr = dw;
+ if (ds->active)
+ dodgeUpdateDodgeWindow (w);
return TRUE;
}