Hi,
Thanks for your comments. I've finally getting around to implementing
the changes that you requested.
Kristian Lyngstøl wrote:
Hi,
Thanks for the patches and sorry for the late reply. I'm cc'ing the dev list.
On Mon, Feb 18, 2008 at 8:24 AM, Thomas Jaeger <[EMAIL PROTECTED]> wrote:
I've split the changes into two patches: the first, maximumize-overlap
adds an option to ignore windows that are already overlapping with the
current window, so that, for example, if there is a maximized (without
the 'um') window in the background, this won't prevent "maximumization".
In its current form, this doesn't quite work: If an overlapping window
is followed by a dock, its region is subtracted in the next iteration of
the loop. This looks like a copy-and-paste related editing error;
maximumize-remove-spurious-union.patch takes the offending line out.
This was applied. There are currently two bits of code dealing with
partial overlapping which should share variables (your code and the
existing "shrink" code), but that could be an other task.
I don't really see any possibility of sensible code sharing here.
The second one restores the original size of the window if
maximumization would otherwise be a no-op, which effectively allows
toggling of maximumization.
This one is not committed for a few reasons.
Okay, I've redone the private_index stuff, basically copying the code
from shelf and renaming variables. I also added a description of
maximumizeGetMask.
Thanks,
Tom
diff --git a/maximumize.c b/maximumize.c
index 0f11aa4..8b20364 100644
--- a/maximumize.c
+++ b/maximumize.c
@@ -97,7 +97,6 @@ maximumizeEmptyRegion (CompWindow *window,
XUnionRectWithRegion (&w->struts->right, tmpRegion, tmpRegion);
XUnionRectWithRegion (&w->struts->top, tmpRegion, tmpRegion);
XUnionRectWithRegion (&w->struts->bottom, tmpRegion, tmpRegion);
- XUnionRectWithRegion (&tmpRect, tmpRegion, tmpRegion);
XSubtractRegion (newRegion, tmpRegion, newRegion);
}
continue;
diff --git a/maximumize.c b/maximumize.c
index 8b20364..f3f5e31 100644
--- a/maximumize.c
+++ b/maximumize.c
@@ -29,10 +29,40 @@
#include <compiz-core.h>
#include "maximumize_options.h"
+
+typedef struct {
+ XWindowChanges *origSize;
+} MaximumizeWindow;
+
+typedef struct {
+ int windowPrivateIndex;
+} MaximumizeScreen;
+
+typedef struct {
+ int screenPrivateIndex;
+} MaximumizeDisplay;
+
+static int displayPrivateIndex;
+
+#define GET_MAXIMUMIZE_DISPLAY(d) \
+ ((MaximumizeDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
+#define MAXIMUMIZE_DISPLAY(d) \
+ MaximumizeDisplay *md = GET_MAXIMUMIZE_DISPLAY (d)
+#define GET_MAXIMUMIZE_SCREEN(s, md) \
+ ((MaximumizeScreen *) (s)->base.privates[(md)->screenPrivateIndex].ptr)
+#define MAXIMUMIZE_SCREEN(s) \
+ MaximumizeScreen *ms = GET_MAXIMUMIZE_SCREEN (s, GET_MAXIMUMIZE_DISPLAY (s->display))
+#define GET_MAXIMUMIZE_WINDOW(w, ms) \
+ ((MaximumizeWindow *) (w)->base.privates[(ms)->windowPrivateIndex].ptr)
+#define MAXIMUMIZE_WINDOW(w) \
+ MaximumizeWindow *mw = GET_MAXIMUMIZE_WINDOW (w, \
+ GET_MAXIMUMIZE_SCREEN (w->screen, \
+ GET_MAXIMUMIZE_DISPLAY (w->screen->display)))
+
/* Returns true if rectangles a and b intersect by at least 40 in both directions
*/
static Bool
-maximumizeSubstantialOverlap(XRectangle a, XRectangle b)
+maximumizeSubstantialOverlap (XRectangle a, XRectangle b)
{
if (a.x + a.width <= b.x + 40) return False;
if (b.x + b.width <= a.x + 40) return False;
@@ -68,7 +98,7 @@ maximumizeEmptyRegion (CompWindow *window,
XUnionRegion (region, newRegion, newRegion);
- if (maximumizeGetIgnoreOverlapping(s->display)) {
+ if (maximumizeGetIgnoreOverlapping (s->display)) {
windowRect.x = window->serverX - window->input.left;
windowRect.y = window->serverY - window->input.top;
windowRect.width = window->serverWidth + window->input.right +
@@ -113,15 +143,15 @@ maximumizeEmptyRegion (CompWindow *window,
tmpRect.height = w->serverHeight + w->input.top +
w->input.bottom;
- if (maximumizeGetIgnoreOverlapping(s->display) &&
- maximumizeSubstantialOverlap(tmpRect, windowRect))
+ if (maximumizeGetIgnoreOverlapping (s->display) &&
+ maximumizeSubstantialOverlap (tmpRect, windowRect))
continue;
XUnionRectWithRegion (&tmpRect, tmpRegion, tmpRegion);
XSubtractRegion (newRegion, tmpRegion, newRegion);
}
XDestroyRegion (tmpRegion);
-
+
return newRegion;
}
@@ -249,7 +279,28 @@ maximumizeFindRect (CompWindow *w,
}
-/* Calls out to compute the resize */
+/* Checks whether we are trying to change the window's position and/or size */
+static unsigned int
+maximumizeGetMask (CompWindow *w, XWindowChanges *xwc)
+{
+ unsigned int mask = 0;
+
+ if (xwc->x != w->serverX)
+ mask |= CWX;
+
+ if (xwc->y != w->serverY)
+ mask |= CWY;
+
+ if (xwc->width != w->serverWidth)
+ mask |= CWWidth;
+
+ if (xwc->height != w->serverHeight)
+ mask |= CWHeight;
+
+ return mask;
+}
+
+/* Calls out to compute the resize and constrains the window */
static unsigned int
maximumizeComputeResize(CompWindow *w,
XWindowChanges *xwc)
@@ -259,6 +310,8 @@ maximumizeComputeResize(CompWindow *w,
unsigned int mask = 0;
BOX box;
+ MAXIMUMIZE_WINDOW (w);
+
output = &w->screen->outputDev[outputDeviceForWindow (w)];
region = maximumizeEmptyRegion (w, &output->region);
if (!region)
@@ -267,30 +320,44 @@ maximumizeComputeResize(CompWindow *w,
box = maximumizeFindRect (w, region);
XDestroyRegion (region);
- if (box.x1 != w->serverX)
- mask |= CWX;
-
- if (box.y1 != w->serverY)
- mask |= CWY;
-
- if ((box.x2 - box.x1) != w->serverWidth)
- mask |= CWWidth;
-
- if ((box.y2 - box.y1) != w->serverHeight)
- mask |= CWHeight;
-
xwc->x = box.x1;
xwc->y = box.y1;
- xwc->width = box.x2 - box.x1;
+ xwc->width = box.x2 - box.x1;
xwc->height = box.y2 - box.y1;
+ mask = maximumizeGetMask (w, xwc);
+ if (mask)
+ {
+ constrainNewWindowSize (w, xwc->width, xwc->height, &xwc->width, &xwc->height);
+ mask = maximumizeGetMask (w, xwc);
+ }
+
+ if (mask) {
+ if (!mw->origSize) {
+ mw->origSize = malloc (sizeof (XWindowChanges));
+ if (mw->origSize) {
+ mw->origSize->x = w->serverX;
+ mw->origSize->y = w->serverY;
+ mw->origSize->width = w->serverWidth;
+ mw->origSize->height = w->serverHeight;
+ }
+ }
+ } else {
+ /* If there are no changes to be made, restore the original size */
+ if (mw->origSize) {
+ *xwc = *mw->origSize;
+ mask = maximumizeGetMask (w, xwc);
+ free (mw->origSize);
+ mw->origSize = 0;
+ }
+ }
+
return mask;
}
/*
* Initially triggered keybinding.
- * Fetch the window, fetch the resize, constrain it.
- *
+ * Fetch the window, fetch the resize.
*/
static Bool
maximumizeTrigger(CompDisplay *d,
@@ -306,21 +373,12 @@ maximumizeTrigger(CompDisplay *d,
w = findWindowAtDisplay (d, xid);
if (w)
{
- int width, height;
unsigned int mask;
XWindowChanges xwc;
mask = maximumizeComputeResize (w, &xwc);
if (mask)
{
- if (constrainNewWindowSize (w, xwc.width, xwc.height,
- &width, &height))
- {
- mask |= CWWidth | CWHeight;
- xwc.width = width;
- xwc.height = height;
- }
-
if (w->mapNum && (mask & (CWWidth | CWHeight)))
sendSyncRequest (w);
@@ -331,19 +389,128 @@ maximumizeTrigger(CompDisplay *d,
return TRUE;
}
+
/* Configuration, initialization, boring stuff. --------------------- */
static Bool
+maximumizeInitScreen (CompPlugin *p,
+ CompScreen *s)
+{
+ MaximumizeScreen *ms;
+
+ MAXIMUMIZE_DISPLAY (s->display);
+
+ ms = malloc (sizeof (MaximumizeScreen));
+ if (!ms)
+ return FALSE; // fixme: error message.
+
+ ms->windowPrivateIndex = allocateWindowPrivateIndex (s);
+ if (ms->windowPrivateIndex < 0)
+ {
+ free (ms);
+ return FALSE;
+ }
+
+ s->base.privates[md->screenPrivateIndex].ptr = ms;
+
+ return TRUE;
+}
+
+static void
+maximumizeFiniScreen (CompPlugin *p,
+ CompScreen *s)
+{
+ MAXIMUMIZE_SCREEN (s);
+
+ freeWindowPrivateIndex (s, ms->windowPrivateIndex);
+
+ free (ms);
+}
+
+static Bool
maximumizeInitDisplay (CompPlugin *p,
CompDisplay *d)
{
+ MaximumizeDisplay *md;
+
if (!checkPluginABI ("core", CORE_ABIVERSION))
return FALSE;
+ md = malloc (sizeof (MaximumizeDisplay));
+ if (!md)
+ return FALSE;
+
+ md->screenPrivateIndex = allocateScreenPrivateIndex (d);
+ if (md->screenPrivateIndex < 0)
+ {
+ free (md);
+ return FALSE;
+ }
+
maximumizeSetTriggerKeyInitiate (d, maximumizeTrigger);
+ d->base.privates[displayPrivateIndex].ptr = md;
+
return TRUE;
}
+static void
+maximumizeFiniDisplay (CompPlugin *p,
+ CompDisplay *d)
+{
+ MAXIMUMIZE_DISPLAY (d);
+
+ freeScreenPrivateIndex (d, md->screenPrivateIndex);
+
+ free (md);
+}
+
+static void
+maximumizeFini (CompPlugin *p)
+{
+ freeDisplayPrivateIndex (displayPrivateIndex);
+}
+
+static Bool
+maximumizeInit (CompPlugin *p)
+{
+ displayPrivateIndex = allocateDisplayPrivateIndex ();
+ if (displayPrivateIndex < 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static Bool
+maximumizeInitWindow (CompPlugin *p,
+ CompWindow *w)
+{
+ MaximumizeWindow *mw;
+
+ MAXIMUMIZE_SCREEN (w->screen);
+
+ mw = malloc (sizeof (MaximumizeWindow));
+ if (!mw)
+ return FALSE;
+
+ mw->origSize = 0;
+
+ w->base.privates[ms->windowPrivateIndex].ptr = mw;
+
+ return TRUE;
+}
+
+static void
+maximumizeFiniWindow (CompPlugin *p,
+ CompWindow *w)
+{
+ MAXIMUMIZE_WINDOW (w);
+
+ if (mw->origSize)
+ free (mw->origSize);
+
+ free (mw);
+}
+
static CompBool
maximumizeInitObject (CompPlugin *p,
CompObject *o)
@@ -351,8 +518,8 @@ maximumizeInitObject (CompPlugin *p,
static InitPluginObjectProc dispTab[] = {
(InitPluginObjectProc) 0, /* InitCore */
(InitPluginObjectProc) maximumizeInitDisplay,
- 0,
- 0
+ (InitPluginObjectProc) maximumizeInitScreen,
+ (InitPluginObjectProc) maximumizeInitWindow
};
RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
@@ -364,9 +531,9 @@ maximumizeFiniObject (CompPlugin *p,
{
static FiniPluginObjectProc dispTab[] = {
(FiniPluginObjectProc) 0, /* FiniCore */
- 0,
- 0,
- 0
+ (FiniPluginObjectProc) maximumizeFiniDisplay,
+ (FiniPluginObjectProc) maximumizeFiniScreen,
+ (FiniPluginObjectProc) maximumizeFiniWindow
};
DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
@@ -375,8 +542,8 @@ maximumizeFiniObject (CompPlugin *p,
CompPluginVTable maximumizeVTable = {
"maximumize",
0,
- 0,
- 0,
+ maximumizeInit,
+ maximumizeFini,
maximumizeInitObject,
maximumizeFiniObject,
0,
_______________________________________________
Dev mailing list
[email protected]
http://lists.compiz-fusion.org/mailman/listinfo/dev