summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2007-04-02 14:50:27 +0200
committerDanny Baumann <dannybaumann@web.de>2007-04-02 14:50:27 +0200
commit4792c1eb025b3fa9780e2d63dd1d9c6f7cd1e5fc (patch)
tree7ae9737be55bfcc1b6ff2a193fb273278698a372
parenta4be9cdcca1016b1daf61ed4d1014d57712f9d12 (diff)
downloadberyl-plugins-4792c1eb025b3fa9780e2d63dd1d9c6f7cd1e5fc.tar.gz
beryl-plugins-4792c1eb025b3fa9780e2d63dd1d9c6f7cd1e5fc.tar.bz2
resize plugin: some code cleanup in preparation for merge into Compiz
-rw-r--r--src/resize.c267
1 files changed, 81 insertions, 186 deletions
diff --git a/src/resize.c b/src/resize.c
index fb0c68a..175668d 100644
--- a/src/resize.c
+++ b/src/resize.c
@@ -55,11 +55,6 @@
#define RESIZE_OPACITY_MIN 1
#define RESIZE_OPACITY_MAX 100
-#define RESIZE_OPACIFY_MIN_OPACITY_DEFAULT 80
-#define RESIZE_OPACIFY_MIN_OPACITY_MIN 1
-#define RESIZE_OPACIFY_MIN_OPACITY_MAX 100
-
-#define RESIZE_SYNC_WINDOW_DEFAULT FALSE
#define RESIZE_WARP_POINTER_DEFAULT FALSE
#define RESIZE_INITIATE_KEY_DEFAULT "F8"
@@ -87,13 +82,11 @@ struct _ResizeKeys
#define RESIZE_DISPLAY_OPTION_INITIATE 0
#define RESIZE_DISPLAY_OPTION_OPACITY 1
-#define RESIZE_DISPLAY_OPTION_OPACIFY_MIN_OPACITY 2
-#define RESIZE_DISPLAY_OPTION_SYNC_WINDOW 3
-#define RESIZE_DISPLAY_OPTION_WARP_POINTER 4
-#define RESIZE_DISPLAY_OPTION_MODE 5
-#define RESIZE_DISPLAY_OPTION_BORDER_COLOR 6
-#define RESIZE_DISPLAY_OPTION_FILL_COLOR 7
-#define RESIZE_DISPLAY_OPTION_NUM 8
+#define RESIZE_DISPLAY_OPTION_WARP_POINTER 2
+#define RESIZE_DISPLAY_OPTION_MODE 3
+#define RESIZE_DISPLAY_OPTION_BORDER_COLOR 4
+#define RESIZE_DISPLAY_OPTION_FILL_COLOR 5
+#define RESIZE_DISPLAY_OPTION_NUM 6
static int displayPrivateIndex;
@@ -147,7 +140,6 @@ typedef struct _ResizeDisplay
int right_edge, bottom_edge;
GLushort resizeOpacity;
- GLushort opacifyMinOpacity;
int resizeMode;
Bool ungrabPending;
@@ -163,10 +155,8 @@ typedef struct _ResizeScreen
int x, y;
PaintWindowProc paintWindow;
- PreparePaintScreenProc preparePaintScreen;
PaintScreenProc paintScreen;
PaintTransformedScreenProc paintTransformedScreen;
- DonePaintScreenProc donePaintScreen;
Cursor leftCursor;
Cursor rightCursor;
@@ -193,43 +183,22 @@ typedef struct _ResizeScreen
#define NUM_OPTIONS(d) (sizeof ((d)->opt) / sizeof (CompOption))
-static void resizeUpdateWindowRealSize(CompDisplay * d, int move_only)
+static void resizeUpdateRealWindowSize(CompDisplay * d)
{
RESIZE_DISPLAY(d);
XWindowChanges xwc;
- unsigned int xwcm = 0;
if (!rd->w || rd->w->syncWait)
return;
- if (move_only)
- {
- moveWindow(rd->w, rd->currentX - rd->w->attrib.x,
- rd->currentY - rd->w->attrib.y, TRUE, TRUE);
- syncWindowPosition(rd->w);
- }
- else
- {
- if (rd->currentX != rd->w->serverX)
- xwcm |= CWX;
- if (rd->currentY != rd->w->serverY)
- xwcm |= CWY;
- if (rd->currentWidth != rd->w->serverWidth)
- xwcm |= CWWidth;
- if (rd->currentHeight != rd->w->serverHeight)
- xwcm |= CWHeight;
-
- xwc.x = rd->currentX;
- xwc.y = rd->currentY;
- xwc.width = rd->currentWidth;
- xwc.height = rd->currentHeight;
-
- if (rd->resizeMode == ResizeModeNormal
- && rd->opt[RESIZE_DISPLAY_OPTION_SYNC_WINDOW].value.b)
- sendSyncRequest(rd->w);
-
- configureXWindow(rd->w, xwcm, &xwc);
- }
+ xwc.x = rd->currentX;
+ xwc.y = rd->currentY;
+ xwc.width = rd->currentWidth;
+ xwc.height = rd->currentHeight;
+
+ sendSyncRequest(rd->w);
+
+ configureXWindow(rd->w, CWX | CWY | CWWidth | CWHeight, &xwc);
}
#define CLAMP(v, min, max) ((v) <= (min) ? (min) : (v) >= (max) ? (max) : (v))
@@ -357,7 +326,6 @@ resizeFindLinePointClosestToPoint (double x1, double y1,
static Bool
resizeConstrainAspectRatio(CompWindow * w, int width, int height, int *retWidth, int *retHeight)
{
- RESIZE_DISPLAY(w->screen->display);
const XSizeHints *hints = &w->sizeHints;
double minRatio, maxRatio;
int newWidth, newHeight;
@@ -367,6 +335,8 @@ resizeConstrainAspectRatio(CompWindow * w, int width, int height, int *retWidth,
Bool resizeLeftRight = FALSE;
Bool resizeUpDown = FALSE;
+ RESIZE_DISPLAY(w->screen->display);
+
newWidth = width;
newHeight = height;
@@ -418,7 +388,7 @@ resizeConstrainAspectRatio(CompWindow * w, int width, int height, int *retWidth,
static void resizeApply(CompDisplay * d)
{
- int move_only = 0, cw, ch;
+ int cw, ch;
RESIZE_DISPLAY(d);
@@ -449,12 +419,17 @@ static void resizeApply(CompDisplay * d)
rd->currentWidth = cw;
rd->currentHeight = ch;
- switch (rd->resizeMode)
+ if (rd->resizeMode == ResizeModeNormal)
{
- case ResizeModeStretch:
- move_only = 1;
- case ResizeModeNormal:
- resizeUpdateWindowRealSize(d, move_only);
+ resizeUpdateRealWindowSize(d);
+ }
+ else if (rd->resizeMode == ResizeModeStretch)
+ {
+ moveWindow(rd->w,
+ rd->currentX - rd->w->attrib.x,
+ rd->currentY - rd->w->attrib.y,
+ TRUE, TRUE);
+ syncWindowPosition(rd->w);
}
if (rd->resizeMode != ResizeModeNormal)
@@ -562,7 +537,6 @@ resizeInitiate(CompDisplay * d,
CompActionState state, CompOption * option, int nOption)
{
CompWindow *w;
- ResizeScreen *rs;
Window xid;
unsigned int mods;
@@ -581,7 +555,7 @@ resizeInitiate(CompDisplay * d,
if (!(w->actions & CompWindowActionResizeMask))
return FALSE;
- rs = GET_RESIZE_SCREEN(w->screen);
+ RESIZE_SCREEN(w->screen);
rd->dx_to_apply = rd->dy_to_apply = 0;
@@ -683,14 +657,11 @@ resizeInitiate(CompDisplay * d,
if (rs->grabIndex)
{
- int mods_sought = virtualToRealModMask(d,
- rd->
- opt
+ int mods_sought = virtualToRealModMask(d,rd->opt
[RESIZE_DISPLAY_OPTION_INITIATE].
value.action.button.modifiers);
int button_sought =
- rd->opt[RESIZE_DISPLAY_OPTION_INITIATE].value.action.
- button.button;
+ rd->opt[RESIZE_DISPLAY_OPTION_INITIATE].value.action.button.button;
rd->releaseButton = button;
@@ -773,18 +744,22 @@ resizeTerminate(CompDisplay * d,
(xwc.width != rd->w->serverWidth) || (xwc.height != rd->w->serverHeight))
{
rd->ungrabPending = TRUE;
- } else {
+ } else
+ {
(rd->w->screen->windowUngrabNotify) (rd->w);
}
configureXWindow(rd->w, CWX | CWY | CWWidth | CWHeight, &xwc);
- } else if (rd->resizeMode != ResizeModeNormal
- && (rd->currentX != rd->w->serverX
- || rd->currentY != rd->w->serverY
- || rd->currentWidth != rd->w->serverWidth
- || rd->currentHeight != rd->w->serverHeight)) {
+ }
+ else if (rd->resizeMode != ResizeModeNormal &&
+ ((rd->currentX != rd->w->serverX) ||
+ (rd->currentY != rd->w->serverY) ||
+ (rd->currentWidth != rd->w->serverWidth) ||
+ (rd->currentHeight != rd->w->serverHeight)))
+ {
rd->ungrabPending = TRUE;
- resizeUpdateWindowRealSize(d, 0);
- } else {
+ resizeUpdateRealWindowSize(d);
+ } else
+ {
syncWindowPosition(rd->w);
(rd->w->screen->windowUngrabNotify) (rd->w);
}
@@ -1024,9 +999,7 @@ static void resizeHandleEvent(CompDisplay * d, XEvent * event)
if (rs->grabIndex)
{
- resizeTerminate(d,
- &rd->
- opt
+ resizeTerminate(d, &rd->opt
[RESIZE_DISPLAY_OPTION_INITIATE].
value.action, 0, NULL, 0);
}
@@ -1034,21 +1007,19 @@ static void resizeHandleEvent(CompDisplay * d, XEvent * event)
break;
case ButtonRelease:
- {
- CompAction *action =
+ {
+ CompAction *action =
&rd->opt[RESIZE_DISPLAY_OPTION_INITIATE].value.action;
- if (action->state & CompActionStateTermButton &&
- (rd->releaseButton == -1 ||
- event->xbutton.button == rd->releaseButton))
- resizeTerminate(d, action, CompActionStateTermButton, NULL, 0);
- }
+ if (action->state & CompActionStateTermButton &&
+ (rd->releaseButton == -1 ||
+ event->xbutton.button == rd->releaseButton))
+ {
+ resizeTerminate(d, action, CompActionStateTermButton, NULL, 0);
+ }
+ }
break;
case MotionNotify:
- s = findScreenAtDisplay(d, event->xmotion.root);
- if (s)
- resizeHandleMotionEvent(s, d->pointerX, d->pointerY);
- break;
case EnterNotify:
case LeaveNotify:
s = findScreenAtDisplay(d, event->xcrossing.root);
@@ -1092,10 +1063,13 @@ static void resizeHandleEvent(CompDisplay * d, XEvent * event)
(*d->handleEvent) (d, event);
WRAP(rd, d, handleEvent, resizeHandleEvent);
- switch (event->type) {
+ switch (event->type)
+ {
case ConfigureNotify:
- if (rd->ungrabPending) {
- if (rd->w && (rd->w->id == event->xconfigure.window)) {
+ if (rd->ungrabPending)
+ {
+ if (rd->w && (rd->w->id == event->xconfigure.window))
+ {
(rd->w->screen->windowUngrabNotify) (rd->w);
syncWindowPosition(rd->w);
rd->w = NULL;
@@ -1103,39 +1077,17 @@ static void resizeHandleEvent(CompDisplay * d, XEvent * event)
rd->ungrabPending = FALSE;
}
break;
-
default:
break;
}
}
-static void resizePreparePaintScreen(CompScreen * s, int msSinceLastPaint)
-{
-
- RESIZE_SCREEN(s);
- RESIZE_DISPLAY(s->display);
-
- if (rd->w && rd->resizeMode > ResizeModeNormal &&
- rs->grabIndex &&
- (rd->lastWidth != rd->currentWidth ||
- rd->lastHeight != rd->currentHeight))
- {
- damageScreen(s);
- }
-
- UNWRAP(rs, s, preparePaintScreen);
- (*s->preparePaintScreen) (s, msSinceLastPaint);
- WRAP(rs, s, preparePaintScreen, resizePreparePaintScreen);
-}
-
static Bool
resizePaintWindow(CompWindow * w,
const WindowPaintAttrib * attrib,
const CompTransform *transform,
Region region, unsigned int mask)
{
- WindowPaintAttrib sAttrib = *attrib;
- CompTransform sTransform = *transform;
CompScreen *s = w->screen;
Bool status;
@@ -1144,34 +1096,38 @@ resizePaintWindow(CompWindow * w,
if ((rs->grabIndex || rd->ungrabPending) && (rd->w == w))
{
- sAttrib = *attrib;
-
- if (rd->resizeMode != ResizeModeNormal)
- mask |= PAINT_WINDOW_TRANSFORMED_MASK;
+ WindowPaintAttrib sAttrib = *attrib;
+ CompTransform sTransform = *transform;
if (rd->resizeMode == ResizeModeStretch)
{
- float xScale =
- (float)(rd->currentWidth) /
- (float)(rd->w->attrib.width);
- float yScale =
- (float)(rd->currentHeight) /
- (float)(rd->w->attrib.height);
+ float xScale = (float)(rd->currentWidth) /
+ (float)(rd->w->attrib.width);
+ float yScale = (float)(rd->currentHeight) /
+ (float)(rd->w->attrib.height);
+
matrixTranslate (&sTransform, w->attrib.x, w->attrib.y, 0.0f);
matrixScale (&sTransform, xScale, yScale, 0.0f);
matrixTranslate (&sTransform, -w->attrib.x, -w->attrib.y, 0.0f);
+
+ mask |= PAINT_WINDOW_TRANSFORMED_MASK;
}
- if (rd->resizeOpacity != OPAQUE
- && sAttrib.opacity >= rd->opacifyMinOpacity)
+ if (rd->resizeOpacity != OPAQUE)
{
sAttrib.opacity = (sAttrib.opacity * rd->resizeOpacity) >> 16;
}
- }
- UNWRAP(rs, s, paintWindow);
- status = (*s->paintWindow) (w, &sAttrib, &sTransform, region, mask);
- WRAP(rs, s, paintWindow, resizePaintWindow);
+ UNWRAP(rs, s, paintWindow);
+ status = (*s->paintWindow) (w, &sAttrib, &sTransform, region, mask);
+ WRAP(rs, s, paintWindow, resizePaintWindow);
+ }
+ else
+ {
+ UNWRAP(rs, s, paintWindow);
+ status = (*s->paintWindow) (w, attrib, transform, region, mask);
+ WRAP(rs, s, paintWindow, resizePaintWindow);
+ }
return status;
}
@@ -1196,7 +1152,7 @@ resizePaintOutline(CompScreen * s, const ScreenPaintAttrib * sa,
(rd->w->shaded ? rd->w->height : rd->currentHeight) +
rd->w->input.bottom;
- CompTransform sTransform = *transform;
+ CompTransform sTransform = *transform;
if (transformed)
{
@@ -1206,8 +1162,6 @@ resizePaintOutline(CompScreen * s, const ScreenPaintAttrib * sa,
else
transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform);
-
-
glPushMatrix ();
glLoadMatrixf (sTransform.m);
@@ -1277,28 +1231,13 @@ resizePaintTransformedScreen(CompScreen * s, const ScreenPaintAttrib * sa,
(*s->paintTransformedScreen) (s, sa, transform, region, output, mask);
WRAP(rs, s, paintTransformedScreen, resizePaintTransformedScreen);
- if ((rs->x == s->x) && (rs->y == s->y)) {
+ if ((rs->x == s->x) && (rs->y == s->y))
+ {
rs->painted = TRUE;
resizePaintOutline(s, sa, transform, output, TRUE);
}
}
-static void resizeDonePaintScreen(CompScreen * s)
-{
- RESIZE_SCREEN(s);
- RESIZE_DISPLAY(s->display);
-
- if (rd->resizeMode != ResizeModeNormal && rd->w && rs->grabIndex)
- {
- rd->lastWidth = rd->currentWidth;
- rd->lastHeight = rd->currentHeight;
- }
-
- UNWRAP(rs, s, donePaintScreen);
- (*s->donePaintScreen) (s);
- WRAP(rs, s, donePaintScreen, resizeDonePaintScreen);
-}
-
static Bool
resizeSetDisplayOption(CompDisplay * display,
char *name, CompOptionValue * value)
@@ -1314,7 +1253,6 @@ resizeSetDisplayOption(CompDisplay * display,
switch (index)
{
-
case RESIZE_DISPLAY_OPTION_INITIATE:
if (setDisplayAction(display, o, value))
return TRUE;
@@ -1328,15 +1266,6 @@ resizeSetDisplayOption(CompDisplay * display,
}
break;
- case RESIZE_DISPLAY_OPTION_OPACIFY_MIN_OPACITY:
- if (compSetIntOption(o, value))
- {
- rd->opacifyMinOpacity = (o->value.i * OPAQUE) / 100;
- return TRUE;
- }
- break;
-
- case RESIZE_DISPLAY_OPTION_SYNC_WINDOW:
case RESIZE_DISPLAY_OPTION_WARP_POINTER:
if (compSetBoolOption(o, value))
return TRUE;
@@ -1421,34 +1350,6 @@ static void resizeDisplayInitOptions(ResizeDisplay * rd)
o->rest.i.min = RESIZE_OPACITY_MIN;
o->rest.i.max = RESIZE_OPACITY_MAX;
- o = &rd->opt[RESIZE_DISPLAY_OPTION_OPACIFY_MIN_OPACITY];
- o->advanced = False;
- o->name = "opacify_min_opacity";
- o->group = N_("Appearance");
- o->subGroup = N_("Opacity");
- o->displayHints = "";
- o->shortDesc = N_("Minimum Opacity for Opacify");
- o->longDesc =
- N_
- ("Opacify only Windows whose Opacity is higher than this value.");
- o->type = CompOptionTypeInt;
- o->value.i = RESIZE_OPACIFY_MIN_OPACITY_DEFAULT;
- o->rest.i.min = RESIZE_OPACIFY_MIN_OPACITY_MIN;
- o->rest.i.max = RESIZE_OPACIFY_MIN_OPACITY_MAX;
-
- o = &rd->opt[RESIZE_DISPLAY_OPTION_SYNC_WINDOW];
- o->advanced = False;
- o->name = "sync_window";
- o->group = N_("Behaviour");
- o->subGroup = N_("");
- o->displayHints = "";
- o->shortDesc = N_("Repaints the Window on Each Resize Step");
- o->longDesc =
- N_("If this is set to true the Window will Repaint itself "
- "during Resize, which may cause some lag.");
- o->type = CompOptionTypeBool;
- o->value.b = RESIZE_SYNC_WINDOW_DEFAULT;
-
o = &rd->opt[RESIZE_DISPLAY_OPTION_MODE];
o->advanced = False;
o->name = "resize_mode";
@@ -1531,8 +1432,6 @@ static Bool resizeInitDisplay(CompPlugin * p, CompDisplay * d)
rd->resizeMode = ResizeModeNormal;
rd->resizeOpacity = (RESIZE_OPACITY_DEFAULT * OPAQUE) / 100;
- rd->opacifyMinOpacity =
- (RESIZE_OPACIFY_MIN_OPACITY_DEFAULT * OPAQUE) / 100;
resizeDisplayInitOptions(rd);
@@ -1597,10 +1496,8 @@ static Bool resizeInitScreen(CompPlugin * p, CompScreen * s)
addScreenAction(s, &rd->opt[RESIZE_DISPLAY_OPTION_INITIATE].value.action);
WRAP(rs, s, paintWindow, resizePaintWindow);
- WRAP(rs, s, preparePaintScreen, resizePreparePaintScreen);
WRAP(rs, s, paintScreen, resizePaintScreen);
WRAP(rs, s, paintTransformedScreen, resizePaintTransformedScreen);
- WRAP(rs, s, donePaintScreen, resizeDonePaintScreen);
s->privates[rd->screenPrivateIndex].ptr = rs;
@@ -1613,10 +1510,8 @@ static void resizeFiniScreen(CompPlugin * p, CompScreen * s)
RESIZE_DISPLAY(s->display);
UNWRAP(rs, s, paintWindow);
- UNWRAP(rs, s, preparePaintScreen);
UNWRAP(rs, s, paintScreen);
UNWRAP(rs, s, paintTransformedScreen);
- UNWRAP(rs, s, donePaintScreen);
removeScreenAction(s,
&rd->opt[RESIZE_DISPLAY_OPTION_INITIATE].value.action);