Merge lp:~dbarth/compiz/reworked-fix-744104 into lp:~unity-team/compiz/trunk

Proposed by David Barth
Status: Merged
Merged at revision: 2736
Proposed branch: lp:~dbarth/compiz/reworked-fix-744104
Merge into: lp:~unity-team/compiz/trunk
Diff against target: 921 lines (+541/-84)
3 files modified
plugins/grid/grid.xml.in (+31/-0)
plugins/grid/src/grid.cpp (+416/-80)
plugins/grid/src/grid.h (+94/-4)
To merge this branch: bzr merge lp:~dbarth/compiz/reworked-fix-744104
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+56583@code.launchpad.net

Description of the change

Re-worked version of sam's original patch, to make it apply to the current trunk

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/grid/grid.xml.in'
--- plugins/grid/grid.xml.in 2011-04-05 13:32:45 +0000
+++ plugins/grid/grid.xml.in 2011-04-06 14:53:28 +0000
@@ -556,6 +556,37 @@
556 <alpha>0x4f4f</alpha>556 <alpha>0x4f4f</alpha>
557 </default>557 </default>
558 </option>558 </option>
559 <option name="indicator_direction" type="int">
560 <_short>Indicator direction</_short>
561 <_long>Where the indicator should come from on-screen</_long>
562 <default>0</default>
563 <min>0</min>
564 <max>1</max>
565 <desc>
566 <value>0</value>
567 <_name>From Window</_name>
568 </desc>
569 <desc>
570 <value>1</value>
571 <_name>From Edge</_name>
572 </desc>
573 </option>
574 <option name="indicator_type" type="int">
575 <_short>Indicator type</_short>
576 <_long>Appearance of the indicator</_long>
577 <default>0</default>
578 <min>0</min>
579 <max>0</max>
580 <desc>
581 <value>0</value>
582 <_name>Outline</_name>
583 </desc>
584 </option>
585 <option name="behind_window" type="bool">
586 <_short>Behind window</_short>
587 <_long>Draw indicator behind window</_long>
588 <default>true</default>
589 </option>
559 </group>590 </group>
560 </options>591 </options>
561 </plugin>592 </plugin>
562593
=== modified file 'plugins/grid/src/grid.cpp'
--- plugins/grid/src/grid.cpp 2011-04-05 13:32:45 +0000
+++ plugins/grid/src/grid.cpp 2011-04-06 14:53:28 +0000
@@ -127,7 +127,7 @@
127 if (edgeToGridType () != GridUnknown && optionGetDrawIndicator () &&127 if (edgeToGridType () != GridUnknown && optionGetDrawIndicator () &&
128 gw->allowGrid (edgeToGridType ()))128 gw->allowGrid (edgeToGridType ()))
129 {129 {
130 cRect = gw->constrainSize (desiredSlot);130 cRect = gw->constrainSize (*desiredSlot);
131 }131 }
132 else132 else
133 cRect.setGeometry (0, 0, 0, 0);133 cRect.setGeometry (0, 0, 0, 0);
@@ -146,7 +146,17 @@
146 xid = CompOption::getIntOptionNamed (option, "window");146 xid = CompOption::getIntOptionNamed (option, "window");
147 cw = screen->findWindow (xid);147 cw = screen->findWindow (xid);
148148
149 if (where == GridUnknown || screen->otherGrabExist ("move", NULL))149 if (where == GridUnknown)
150 {
151 if (desiredSlot)
152 {
153 delete desiredSlot;
154 desiredSlot = NULL;
155 }
156
157 return false;
158 }
159 else if (screen->otherGrabExist ("move", NULL))
150 return false;160 return false;
151161
152 if (cw)162 if (cw)
@@ -155,6 +165,9 @@
155165
156 GRID_WINDOW (cw);166 GRID_WINDOW (cw);
157167
168 if (!gw->allowGrid (where))
169 return false;
170
158 if (gw->lastTarget != where)171 if (gw->lastTarget != where)
159 gw->resizeCount = 0;172 gw->resizeCount = 0;
160173
@@ -199,6 +212,41 @@
199 return true;212 return true;
200 }213 }
201214
215 /* Should really be three different types here, but not enough time
216 * to implement that one FIXME */
217 if (!desiredSlot)
218 {
219 if (resize)
220 {
221 desiredSlot = new PaintableAnimatedGridRectangle ();
222
223 if (!desiredSlot)
224 return false;
225 }
226 else
227 {
228 CompRect sbr = cw->serverBorderRect ();
229 if (compositingActive)
230 {
231 CompRect sbr = cw->serverBorderRect ();
232 desiredSlot = new PaintableAnimatedGridRectangle ();
233
234 if (!desiredSlot)
235 return false;
236 }
237 else
238 {
239 desiredSlot = new PaintableAnimatedGridRectangle ();
240
241 if (!desiredSlot)
242 return false;
243 }
244
245 ((AnimatedGridRectangle *) desiredSlot)->setFrom (sbr);
246 }
247 }
248
249
202 /* Convention:250 /* Convention:
203 * xxxSlot include decorations (it's the screen area occupied)251 * xxxSlot include decorations (it's the screen area occupied)
204 * xxxRect are undecorated (it's the constrained position252 * xxxRect are undecorated (it's the constrained position
@@ -206,15 +254,15 @@
206 */254 */
207255
208 /* slice and dice to get desired slot - including decorations */256 /* slice and dice to get desired slot - including decorations */
209 desiredSlot.setY (workarea.y () + props.gravityDown *257 desiredSlot->setY (workarea.y () + props.gravityDown *
210 (workarea.height () / props.numCellsY));258 (workarea.height () / props.numCellsY));
211 desiredSlot.setHeight (workarea.height () / props.numCellsY);259 desiredSlot->setHeight (workarea.height () / props.numCellsY);
212 desiredSlot.setX (workarea.x () + props.gravityRight *260 desiredSlot->setX (workarea.x () + props.gravityRight *
213 (workarea.width () / props.numCellsX));261 (workarea.width () / props.numCellsX));
214 desiredSlot.setWidth (workarea.width () / props.numCellsX);262 desiredSlot->setWidth (workarea.width () / props.numCellsX);
215263
216 /* Adjust for constraints and decorations */264 /* Adjust for constraints and decorations */
217 desiredRect = gw->constrainSize (desiredSlot).subtractBorders (cw);265 desiredRect = gw->constrainSize (*desiredSlot).subtractBorders (cw);
218 /* Get current rect not including decorations */266 /* Get current rect not including decorations */
219 currentRect.setGeometry (cw->serverX (), cw->serverY (),267 currentRect.setGeometry (cw->serverX (), cw->serverY (),
220 cw->serverWidth (),268 cw->serverWidth (),
@@ -243,8 +291,8 @@
243 switch (gw->resizeCount)291 switch (gw->resizeCount)
244 {292 {
245 case 1:293 case 1:
246 desiredSlot.setWidth (slotWidth66);294 desiredSlot->setWidth (slotWidth66);
247 desiredSlot.setX (workarea.x () +295 desiredSlot->setX (workarea.x () +
248 props.gravityRight * slotWidth33);296 props.gravityRight * slotWidth33);
249 gw->resizeCount++;297 gw->resizeCount++;
250 break;298 break;
@@ -252,20 +300,20 @@
252 gw->resizeCount++;300 gw->resizeCount++;
253 break;301 break;
254 case 3:302 case 3:
255 desiredSlot.setWidth (slotWidth33);303 desiredSlot->setWidth (slotWidth33);
256 desiredSlot.setX (workarea.x () +304 desiredSlot->setX (workarea.x () +
257 props.gravityRight * slotWidth66);305 props.gravityRight * slotWidth66);
258 gw->resizeCount++;306 gw->resizeCount++;
259 break;307 break;
260 case 4:308 case 4:
261 desiredSlot.setWidth (slotWidth25);309 desiredSlot->setWidth (slotWidth25);
262 desiredSlot.setX (workarea.x () +310 desiredSlot->setX (workarea.x () +
263 props.gravityRight * slotWidth75);311 props.gravityRight * slotWidth75);
264 gw->resizeCount++;312 gw->resizeCount++;
265 break;313 break;
266 case 5:314 case 5:
267 desiredSlot.setWidth (slotWidth75);315 desiredSlot->setWidth (slotWidth75);
268 desiredSlot.setX (workarea.x () +316 desiredSlot->setX (workarea.x () +
269 props.gravityRight * slotWidth25);317 props.gravityRight * slotWidth25);
270 gw->resizeCount++;318 gw->resizeCount++;
271 break;319 break;
@@ -284,27 +332,27 @@
284 switch (gw->resizeCount)332 switch (gw->resizeCount)
285 {333 {
286 case 1:334 case 1:
287 desiredSlot.setWidth (workarea.width () -335 desiredSlot->setWidth (workarea.width () -
288 (slotWidth17 * 2));336 (slotWidth17 * 2));
289 desiredSlot.setX (workarea.x () + slotWidth17);337 desiredSlot->setX (workarea.x () + slotWidth17);
290 gw->resizeCount++;338 gw->resizeCount++;
291 break;339 break;
292 case 2:340 case 2:
293 desiredSlot.setWidth ((slotWidth25 * 2) +341 desiredSlot->setWidth ((slotWidth25 * 2) +
294 (slotWidth17 * 2));342 (slotWidth17 * 2));
295 desiredSlot.setX (workarea.x () +343 desiredSlot->setX (workarea.x () +
296 (slotWidth25 - slotWidth17));344 (slotWidth25 - slotWidth17));
297 gw->resizeCount++;345 gw->resizeCount++;
298 break;346 break;
299 case 3:347 case 3:
300 desiredSlot.setWidth ((slotWidth25 * 2));348 desiredSlot->setWidth ((slotWidth25 * 2));
301 desiredSlot.setX (workarea.x () + slotWidth25);349 desiredSlot->setX (workarea.x () + slotWidth25);
302 gw->resizeCount++;350 gw->resizeCount++;
303 break;351 break;
304 case 4:352 case 4:
305 desiredSlot.setWidth (slotWidth33 -353 desiredSlot->setWidth (slotWidth33 -
306 (cw->border ().left + cw->border ().right));354 (cw->border ().left + cw->border ().right));
307 desiredSlot.setX (workarea.x () + slotWidth33);355 desiredSlot->setX (workarea.x () + slotWidth33);
308 gw->resizeCount++;356 gw->resizeCount++;
309 break;357 break;
310 case 5:358 case 5:
@@ -318,7 +366,7 @@
318 if (gw->resizeCount == 6)366 if (gw->resizeCount == 6)
319 gw->resizeCount = 1;367 gw->resizeCount = 1;
320368
321 desiredRect = gw->constrainSize (desiredSlot).subtractBorders (cw);369 desiredRect = gw->constrainSize (*desiredSlot).subtractBorders (cw);
322 }370 }
323371
324 /* TODO: animate move+resize */372 /* TODO: animate move+resize */
@@ -336,6 +384,9 @@
336 if (cw->mapNum ())384 if (cw->mapNum ())
337 cw->sendSyncRequest ();385 cw->sendSyncRequest ();
338386
387 delete desiredSlot;
388 desiredSlot = NULL;
389
339 cw->configureXWindow (flags, &xwc);390 cw->configureXWindow (flags, &xwc);
340 gw->isGridResized = true;391 gw->isGridResized = true;
341 gw->isGridMaximized = false;392 gw->isGridMaximized = false;
@@ -347,48 +398,102 @@
347 return true;398 return true;
348}399}
349400
350void401CompRect
351GridScreen::glPaintRectangle (const GLScreenPaintAttrib &sAttrib,402AnimatedGridRectangle::current ()
352 const GLMatrix &transform,403{
353 CompOutput *output)404 /* Expand edges out to destination rect based on progress */
354{405
355 CompRect rect;406 CompRect ret = mFrom;
356 GLMatrix sTransform (transform);407
357408 ret.setTop (floor (mFrom.top () + (top () - mFrom.top ()) * mProgress));
358 getPaintRectangle (rect);409 ret.setLeft (floor (mFrom.left () + (left () - mFrom.left ()) * mProgress));
359410 ret.setRight (floor (mFrom.right () + (right () - mFrom.right ()) * mProgress));
360 glPushMatrix ();411 ret.setBottom (floor (mFrom.bottom () + (bottom () - mFrom.bottom ()) * mProgress));
361412
362 sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);413 return ret;
363414}
364 glLoadMatrixf (sTransform.getMatrix ());415
365416float
366 glDisableClientState (GL_TEXTURE_COORD_ARRAY);417AnimatedGridRectangle::progress ()
367 glEnable (GL_BLEND);418{
368419 return mProgress;
369 /* fill rectangle */420}
370 glColor4usv (optionGetFillColor ());421
371 glRecti (rect.x1 (), rect.y2 (), rect.x2 (), rect.y1 ());422void
372423AnimatedGridRectangle::setTime (unsigned int t)
373 /* Set outline rect smaller to avoid damage issues */424{
374 rect.setGeometry (rect.x () + 1, rect.y () + 1,425 mTime = t;
375 rect.width () - 2, rect.height () - 2);426}
376427
377 /* draw outline */428void
378 glColor4usv (optionGetOutlineColor ());429AnimatedGridRectangle::setFrom (CompRect &f)
379 glLineWidth (2.0);430{
380 glBegin (GL_LINE_LOOP);431 mFrom = f;
381 glVertex2i (rect.x1 (), rect.y1 ());432}
382 glVertex2i (rect.x2 (), rect.y1 ());433
383 glVertex2i (rect.x2 (), rect.y2 ());434void
384 glVertex2i (rect.x1 (), rect.y2 ());435AnimatedGridRectangle::setProgress (float p)
385 glEnd ();436{
386437 mProgress = p;
387 /* clean up */438
388 glColor4usv (defaultColor);439 if (mProgress >= 1.0f)
389 glDisable (GL_BLEND);440 mProgress = 1.0f;
390 glEnableClientState (GL_TEXTURE_COORD_ARRAY);441 else if (mProgress <= 0.0f)
391 glPopMatrix ();442 mProgress = 0.0f;
443}
444
445void
446AnimatedGridRectangle::reset ()
447{
448 mProgress = 0.0f;
449}
450
451void
452PaintableAnimatedGridRectangle::paint (const GLMatrix &mat)
453{
454 CompRect outline;
455 CompRect fill = current ();
456 GridScreen *gScreen = GridScreen::get (screen);
457
458 if (gScreen->optionGetIndicatorType () == GridOptions::IndicatorTypeOutline)
459 {
460 glPushMatrix ();
461
462 glLoadMatrixf (mat.getMatrix ());
463
464 glDisableClientState (GL_TEXTURE_COORD_ARRAY);
465 glEnable (GL_BLEND);
466
467 /* fill rectangle */
468 glColor4f ((float) gScreen->optionGetFillColorRed () / 65535.0f,
469 (float) gScreen->optionGetFillColorGreen () / 65535.0f,
470 (float) gScreen->optionGetFillColorBlue () / 65535.0f,
471 ((float) gScreen->optionGetFillColorAlpha () / 65535.0f) * progress ());
472 glRecti (fill.x1 (), fill.y2 (), fill.x2 (), fill.y1 ());
473
474 /* Set outline rect smaller to avoid damage issues */
475 outline.setGeometry (fill.x () + 1, fill.y () + 1,
476 fill.width () - 2,fill. height () - 2);
477
478 /* draw outline */
479 glColor4f ((float) gScreen->optionGetOutlineColorRed () / 65535.0f,
480 (float) gScreen->optionGetOutlineColorGreen () / 65535.0f,
481 (float) gScreen->optionGetOutlineColorBlue () / 65535.0f,
482 ((float) gScreen->optionGetOutlineColorAlpha () / 65535.0f) * progress ());
483 glLineWidth (2.0);
484 glBegin (GL_LINE_LOOP);
485 glVertex2i (outline.x1 (), outline.y1 ());
486 glVertex2i (outline.x2 (), outline.y1 ());
487 glVertex2i (outline.x2 (), outline.y2 ());
488 glVertex2i (outline.x1 (), outline.y2 ());
489 glEnd ();
490
491 /* clean up */
492 glColor4usv (defaultColor);
493 glDisable (GL_BLEND);
494 glEnableClientState (GL_TEXTURE_COORD_ARRAY);
495 glPopMatrix ();
496 }
392}497}
393498
394bool499bool
@@ -398,11 +503,18 @@
398 CompOutput *output,503 CompOutput *output,
399 unsigned int mask)504 unsigned int mask)
400{505{
401 bool status;506 bool status;
402507
403 status = glScreen->glPaintOutput (attrib, matrix, region, output, mask);508 if (desiredSlot && optionGetDrawIndicator ())
404509 {
405 glPaintRectangle (attrib, matrix, output);510 GLMatrix sTransform (matrix);
511 status = glScreen->glPaintOutput (attrib, matrix, region, output, mask);
512
513 sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA);
514 ((PaintableAnimatedGridRectangle *) desiredSlot)->paint (sTransform);
515 }
516 else
517 status = glScreen->glPaintOutput (attrib, matrix, region, output, mask);
406518
407 return status;519 return status;
408}520}
@@ -452,6 +564,8 @@
452 CompOutput out;564 CompOutput out;
453 CompOption::Vector opts;565 CompOption::Vector opts;
454 CompOption::Value v = CompOption::Value ((int) mGrabWindow->id ());566 CompOption::Value v = CompOption::Value ((int) mGrabWindow->id ());
567 CompRect *edgeBox = NULL;
568 float edgeDist; /* interpolated 0.0f -> 1.0f based on distance */
455569
456 screen->handleEvent (event);570 screen->handleEvent (event);
457571
@@ -469,31 +583,182 @@
469 /* Bottom Left */583 /* Bottom Left */
470 if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold()) &&584 if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold()) &&
471 pointerX < out.x () + optionGetLeftEdgeThreshold())585 pointerX < out.x () + optionGetLeftEdgeThreshold())
586 {
587 float xd, yd;
588 unsigned int xptr = (out.x ()) + pointerX;
589 unsigned int yptr = (out.y () + out.height ()) - pointerY;
590
591 if (xptr)
592 xd = MIN (((float) xptr / (float) optionGetLeftEdgeThreshold ()), 1.0f);
593 else
594 xd = 0.0f;
595
596 if (yptr)
597 yd = MIN (((float) yptr / (float) optionGetBottomEdgeThreshold ()), 1.0f);
598 else
599 yd = 0.0f;
600
601 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge)
602 edgeBox = new CompRect (out.x (), out.y () + (out.height () - mGrabWindow->height ()),
603 mGrabWindow->width (), mGrabWindow->height ());
604
605 edgeDist = (xd + yd) / 2.0f;
472 edge = BottomLeft;606 edge = BottomLeft;
607 }
473 /* Bottom Right */608 /* Bottom Right */
474 else if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold()) &&609 else if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold()) &&
475 pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold()))610 pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold()))
611 {
612 float xd, yd;
613 unsigned int xptr = (out.x () + out.width ()) - pointerX;
614 unsigned int yptr = (out.y () + out.height ()) - pointerY;
615
616 if (xptr)
617 xd = MIN (((float) xptr / (float) optionGetRightEdgeThreshold ()), 1.0f);
618 else
619 xd = 0.0f;
620
621 if (yptr)
622 yd = MIN (((float) yptr / (float) optionGetBottomEdgeThreshold ()), 1.0f);
623 else
624 yd = 0.0f;
625
626 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge)
627 edgeBox = new CompRect (out.x () + (out.width () - mGrabWindow->width ()),
628 out.y () + (out.height () - mGrabWindow->height ()),
629 mGrabWindow->width (), mGrabWindow->height ());
630
631 edgeDist = (xd + yd) / 2.0f;
476 edge = BottomRight;632 edge = BottomRight;
633 }
477 /* Top Left */634 /* Top Left */
478 else if (pointerY < optionGetTopEdgeThreshold() &&635 else if (pointerY < optionGetTopEdgeThreshold() &&
479 pointerX < optionGetLeftEdgeThreshold())636 pointerX < optionGetLeftEdgeThreshold())
637 {
638 float xd, yd;
639 unsigned int xptr = (out.x ()) + pointerX;
640 unsigned int yptr = (out.y ()) + pointerY;
641
642 if (xptr)
643 xd = MIN (((float) xptr / (float) optionGetLeftEdgeThreshold ()), 1.0f);
644 else
645 xd = 0.0f;
646
647 if (yptr)
648 yd = MIN (((float) yptr / (float) optionGetTopEdgeThreshold ()), 1.0f);
649 else
650 yd = 0.0f;
651
652 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge)
653 edgeBox = new CompRect (out.x (),
654 out.y (),
655 mGrabWindow->width (), mGrabWindow->height ());
656
657 edgeDist = (xd + yd) / 2.0f;
480 edge = TopLeft;658 edge = TopLeft;
659 }
481 /* Top Right */660 /* Top Right */
482 else if (pointerY < out.y () + optionGetTopEdgeThreshold() &&661 else if (pointerY < out.y () + optionGetTopEdgeThreshold() &&
483 pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold()))662 pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold()))
663 {
664 float xd, yd;
665 unsigned int xptr = (out.x () + out.width ()) - pointerX;
666 unsigned int yptr = (out.y ()) + pointerY;
667
668 if (xptr)
669 xd = MIN (((float) xptr / (float) optionGetRightEdgeThreshold ()), 1.0f);
670 else
671 xd = 0.0f;
672
673 if (yptr)
674 yd = MIN (((float) yptr / (float) optionGetTopEdgeThreshold ()), 1.0f);
675 else
676 yd = 0.0f;
677
678 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge)
679 edgeBox = new CompRect (out.x () + (out.width () - mGrabWindow->width ()),
680 out.y (),
681 mGrabWindow->width (), mGrabWindow->height ());
682
683 edgeDist = (xd + yd) / 2.0f;
484 edge = TopRight;684 edge = TopRight;
685 }
485 /* Left */686 /* Left */
486 else if (pointerX < out.x () + optionGetLeftEdgeThreshold())687 else if (pointerX < out.x () + optionGetLeftEdgeThreshold())
688 {
689 float xd;
690 unsigned int xptr = (out.x ()) + pointerX;
691
692 if (xptr)
693 xd = MIN (((float) xptr / (float) optionGetLeftEdgeThreshold ()), 1.0f);
694 else
695 xd = 0.0f;
696
697 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge)
698 edgeBox = new CompRect (out.x (),
699 out.y () + (out.height () / 2.0f) - mGrabWindow->height () / 2.0f,
700 mGrabWindow->width (), mGrabWindow->height ());
701
702 edgeDist = xd;
487 edge = Left;703 edge = Left;
704 }
488 /* Right */705 /* Right */
489 else if (pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold()))706 else if (pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold()))
707 {
708 float xd;
709 unsigned int xptr = (out.x () + out.width ()) - pointerX;
710
711 if (xptr)
712 xd = MIN (((float) xptr / (float) optionGetRightEdgeThreshold ()), 1.0f);
713 else
714 xd = 0.0f;
715
716 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge)
717 edgeBox = new CompRect (out.x () + (out.width () - mGrabWindow->width ()),
718 out.y () + (out.height () / 2.0f) - mGrabWindow->height () / 2.0f,
719 mGrabWindow->width (), mGrabWindow->height ());
720
721 edgeDist = xd;
490 edge = Right;722 edge = Right;
723 }
491 /* Top */724 /* Top */
492 else if (pointerY < out.y () + optionGetTopEdgeThreshold())725 else if (pointerY < out.y () + optionGetTopEdgeThreshold())
726 {
727 float yd;
728 unsigned int yptr = (out.y ()) + pointerY;
729
730 if (yptr)
731 yd = MIN (((float) yptr / (float) optionGetTopEdgeThreshold ()), 1.0f);
732 else
733 yd = 0.0f;
734
735 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge)
736 edgeBox = new CompRect (out.x () + (out.width () / 2.0f) - mGrabWindow->width () / 2.0f,
737 out.y (),
738 mGrabWindow->width (), mGrabWindow->height ());
739
740 edgeDist = yd;
493 edge = Top;741 edge = Top;
742 }
494 /* Bottom */743 /* Bottom */
495 else if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold()))744 else if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold()))
745 {
746 float yd;
747 unsigned int yptr = (out.y () + out.width ()) - pointerY;
748
749 if (yptr)
750 yd = MIN (((float) yptr / (float) optionGetBottomEdgeThreshold ()), 1.0f);
751 else
752 yd = 0.0f;
753
754 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge)
755 edgeBox = new CompRect (out.x () + (out.width () / 2.0f) - mGrabWindow->width () / 2.0f,
756 out.y () + (out.height () - mGrabWindow->height ()),
757 mGrabWindow->width (), mGrabWindow->height ());
758
759 edgeDist = yd;
496 edge = Bottom;760 edge = Bottom;
761 }
497 /* No Edge */762 /* No Edge */
498 else763 else
499 edge = NoEdge;764 edge = NoEdge;
@@ -504,29 +769,71 @@
504 (screen->outputDeviceForPoint (pointerX, pointerY));769 (screen->outputDeviceForPoint (pointerX, pointerY));
505 if (lastWorkarea != currentWorkarea)770 if (lastWorkarea != currentWorkarea)
506 {771 {
772 CompRect old;
773
774 if (desiredSlot)
775 old = *desiredSlot;
776
507 lastWorkarea = currentWorkarea;777 lastWorkarea = currentWorkarea;
508778
509 if (compositingActive && cScreen)779 if (compositingActive && cScreen)
510 cScreen->damageRegion (desiredSlot);780 cScreen->damageRegion (old);
511781
512 initiateCommon (0, 0, opts, edgeToGridType (), false);782 initiateCommon (0, 0, opts, edgeToGridType (), false);
513783
784 if (edgeBox && desiredSlot)
785 {
786 desiredSlot->setFrom (*edgeBox);
787 delete edgeBox;
788 }
789
514 if (compositingActive && cScreen)790 if (compositingActive && cScreen)
515 cScreen->damageRegion (desiredSlot);791 cScreen->damageRegion (desiredSlot ? *desiredSlot : old);
516 }792 }
517793
518 /* Detect edge region change */794 /* Detect edge region change */
519 if (lastEdge != edge)795 if (lastEdge != edge)
520 {796 {
797 CompRect old;
798
799 if (desiredSlot)
800 {
801 ((AnimatedGridRectangle *) desiredSlot)->reset ();
802 old = *desiredSlot;
803 }
804
521 lastEdge = edge;805 lastEdge = edge;
522806
523 if (compositingActive && cScreen)807 if (compositingActive && cScreen)
524 cScreen->damageRegion (desiredSlot);808 cScreen->damageRegion (old);
525809
526 initiateCommon (0, 0, opts, edgeToGridType (), false);810 initiateCommon (0, 0, opts, edgeToGridType (), false);
527811
812 if (edgeBox && desiredSlot)
813 {
814 desiredSlot->setFrom (*edgeBox);
815 delete edgeBox;
816 }
817
528 if (compositingActive && cScreen)818 if (compositingActive && cScreen)
529 cScreen->damageRegion (desiredSlot);819 cScreen->damageRegion (desiredSlot ? *desiredSlot : old);
820 }
821
822 /* The closer the user gets to the edge, the more progress should go up */
823 if (desiredSlot)
824 {
825 CompRect damage;
826 CompRect sbr = mGrabWindow->serverBorderRect ();
827
828 damage = ((AnimatedGridRectangle *) desiredSlot)->current ();
829 cScreen->damageRegion (damage);
830
831 if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromWindow)
832 ((AnimatedGridRectangle *) desiredSlot)->setFrom (sbr);
833 ((AnimatedGridRectangle *) desiredSlot)->setProgress (1.0f - edgeDist);
834
835 damage = ((AnimatedGridRectangle *) desiredSlot)->current ();
836 cScreen->damageRegion (damage);
530 }837 }
531838
532 GRID_WINDOW (mGrabWindow);839 GRID_WINDOW (mGrabWindow);
@@ -540,6 +847,24 @@
540 restoreWindow (0, 0, opts);847 restoreWindow (0, 0, opts);
541}848}
542849
850bool
851GridWindow::glDraw (const GLMatrix &transform,
852 GLFragment::Attrib &fragment,
853 const CompRegion &region,
854 unsigned int mask)
855{
856 CompRegion nRegion = region;
857
858 if (gScreen->desiredSlot)
859 {
860 nRegion = nRegion.united (gScreen->desiredSlot->current ());
861
862 gScreen->desiredSlot->paint (transform);
863 }
864
865 return glWindow->glDraw (transform, fragment, nRegion, mask);
866 }
867
543void868void
544GridWindow::grabNotify (int x,869GridWindow::grabNotify (int x,
545 int y,870 int y,
@@ -550,7 +875,12 @@
550 {875 {
551 screen->handleEventSetEnabled (gScreen, true);876 screen->handleEventSetEnabled (gScreen, true);
552 if (compositingActive)877 if (compositingActive)
553 gScreen->glScreen->glPaintOutputSetEnabled (gScreen, true);878 {
879 if (gScreen->optionGetBehindWindow ())
880 glWindow->glDrawSetEnabled (this, true);
881 else
882 gScreen->glScreen->glPaintOutputSetEnabled (gScreen, true);
883 }
554 gScreen->mGrabWindow = window;884 gScreen->mGrabWindow = window;
555 pointerBufDx = pointerBufDy = 0;885 pointerBufDx = pointerBufDy = 0;
556886
@@ -574,6 +904,7 @@
574 if (window == gScreen->mGrabWindow)904 if (window == gScreen->mGrabWindow)
575 {905 {
576 CompOption::Vector opts;906 CompOption::Vector opts;
907 CompRect damage = gScreen->desiredSlot ? *gScreen->desiredSlot : CompRect (0, 0, 0, 0);
577 CompOption::Value v = CompOption::Value ((int) gScreen->mGrabWindow->id ());908 CompOption::Value v = CompOption::Value ((int) gScreen->mGrabWindow->id ());
578909
579 opts.resize (1);910 opts.resize (1);
@@ -587,8 +918,11 @@
587918
588 if (compositingActive)919 if (compositingActive)
589 {920 {
590 gScreen->glScreen->glPaintOutputSetEnabled (gScreen, false);921 if (gScreen->optionGetBehindWindow ())
591 gScreen->cScreen->damageRegion (gScreen->desiredSlot);922 glWindow->glDrawSetEnabled (this, false);
923 else
924 gScreen->glScreen->glPaintOutputSetEnabled (gScreen, false);
925 gScreen->cScreen->damageRegion (damage);
592 }926 }
593927
594 gScreen->mGrabWindow = NULL;928 gScreen->mGrabWindow = NULL;
@@ -654,6 +988,7 @@
654988
655GridScreen::GridScreen (CompScreen *screen) :989GridScreen::GridScreen (CompScreen *screen) :
656 PluginClassHandler<GridScreen, CompScreen> (screen),990 PluginClassHandler<GridScreen, CompScreen> (screen),
991 desiredSlot (NULL),
657 mGrabWindow (NULL)992 mGrabWindow (NULL)
658{993{
659 if (compositingActive)994 if (compositingActive)
@@ -661,8 +996,7 @@
661 cScreen = CompositeScreen::get (screen);996 cScreen = CompositeScreen::get (screen);
662 glScreen = GLScreen::get (screen);997 glScreen = GLScreen::get (screen);
663998
664 CompositeScreenInterface::setHandler (cScreen, false);999 ScreenInterface::setHandler (screen, false);
665 GLScreenInterface::setHandler (glScreen, false);
666 }1000 }
6671001
668 ScreenInterface::setHandler (screen, false);1002 ScreenInterface::setHandler (screen, false);
@@ -696,6 +1030,7 @@
696GridWindow::GridWindow (CompWindow *window) :1030GridWindow::GridWindow (CompWindow *window) :
697 PluginClassHandler <GridWindow, CompWindow> (window),1031 PluginClassHandler <GridWindow, CompWindow> (window),
698 window (window),1032 window (window),
1033 glWindow (GLWindow::get (window)),
699 gScreen (GridScreen::get (screen)),1034 gScreen (GridScreen::get (screen)),
700 isGridResized (false),1035 isGridResized (false),
701 isGridMaximized (false),1036 isGridMaximized (false),
@@ -705,6 +1040,7 @@
705 lastTarget (GridUnknown)1040 lastTarget (GridUnknown)
706{1041{
707 WindowInterface::setHandler (window);1042 WindowInterface::setHandler (window);
1043 GLWindowInterface::setHandler (glWindow, false);
708}1044}
7091045
710/* Initial plugin init function called. Checks to see if we are ABI1046/* Initial plugin init function called. Checks to see if we are ABI
7111047
=== modified file 'plugins/grid/src/grid.h'
--- plugins/grid/src/grid.h 2011-04-05 13:32:45 +0000
+++ plugins/grid/src/grid.h 2011-04-06 14:53:28 +0000
@@ -28,6 +28,8 @@
28#include <composite/composite.h>28#include <composite/composite.h>
29#include <opengl/opengl.h>29#include <opengl/opengl.h>
3030
31#include <cmath>
32
31#include "grid_options.h"33#include "grid_options.h"
3234
33#define SNAPOFF_THRESHOLD 5035#define SNAPOFF_THRESHOLD 50
@@ -85,6 +87,89 @@
85 GridRectangle addBorders (CompWindow *w) const;87 GridRectangle addBorders (CompWindow *w) const;
86};88};
8789
90class Paintable
91{
92 public:
93
94 Paintable ()
95 {
96 };
97
98 virtual void paint (const GLMatrix &mat) = 0;
99};
100
101class AnimatedGridRectangle :
102 public GridRectangle
103{
104 public:
105
106 AnimatedGridRectangle () :
107 GridRectangle::GridRectangle (),
108 mFrom (CompRect (0, 0, 0, 0)),
109 mProgress (0.0f),
110 mTime (300)
111 {
112 };
113
114 AnimatedGridRectangle (const GridRectangle &r) :
115 GridRectangle::GridRectangle (r),
116 mFrom (CompRect (0, 0, 0, 0)),
117 mProgress (0.0f),
118 mTime (300)
119 {
120 };
121
122 AnimatedGridRectangle (const CompRect &r) :
123 GridRectangle::GridRectangle (r),
124 mFrom (CompRect (0, 0, 0, 0)),
125 mProgress (0.0f),
126 mTime (300)
127 {
128 };
129
130 CompRect current ();
131 float progress ();
132
133 void setFrom (CompRect &);
134 void setProgress (float);
135 void reset ();
136 void setTime (unsigned int);
137
138 private:
139
140 CompRect mFrom;
141 float mProgress;
142
143 unsigned int mTime;
144};
145
146class PaintableAnimatedGridRectangle :
147 public Paintable,
148 public AnimatedGridRectangle
149{
150 public:
151
152 PaintableAnimatedGridRectangle () :
153 Paintable::Paintable (),
154 AnimatedGridRectangle::AnimatedGridRectangle ()
155 {
156 };
157
158 PaintableAnimatedGridRectangle (const GridRectangle &r) :
159 Paintable::Paintable (),
160 AnimatedGridRectangle::AnimatedGridRectangle (r)
161 {
162 };
163
164 PaintableAnimatedGridRectangle (const CompRect &r) :
165 Paintable::Paintable (),
166 AnimatedGridRectangle::AnimatedGridRectangle (r)
167 {
168 };
169
170 virtual void paint (const GLMatrix &mat);
171};
172
88class GridScreen :173class GridScreen :
89 public ScreenInterface,174 public ScreenInterface,
90 public CompositeScreenInterface,175 public CompositeScreenInterface,
@@ -98,7 +183,7 @@
98 CompositeScreen *cScreen;183 CompositeScreen *cScreen;
99 GLScreen *glScreen;184 GLScreen *glScreen;
100185
101 GridRectangle desiredSlot;186 PaintableAnimatedGridRectangle *desiredSlot;
102 CompRect workarea, currentRect,187 CompRect workarea, currentRect,
103 desiredRect, lastWorkarea, currentWorkarea;188 desiredRect, lastWorkarea, currentWorkarea;
104 GridProps props;189 GridProps props;
@@ -110,9 +195,6 @@
110 bool initiateCommon (CompAction*, CompAction::State,195 bool initiateCommon (CompAction*, CompAction::State,
111 CompOption::Vector&, GridType, bool);196 CompOption::Vector&, GridType, bool);
112197
113 void glPaintRectangle (const GLScreenPaintAttrib&,
114 const GLMatrix&, CompOutput *);
115
116 bool glPaintOutput (const GLScreenPaintAttrib &,198 bool glPaintOutput (const GLScreenPaintAttrib &,
117 const GLMatrix &, const CompRegion &,199 const GLMatrix &, const CompRegion &,
118 CompOutput *, unsigned int);200 CompOutput *, unsigned int);
@@ -132,12 +214,14 @@
132214
133class GridWindow :215class GridWindow :
134 public WindowInterface,216 public WindowInterface,
217 public GLWindowInterface,
135 public PluginClassHandler <GridWindow, CompWindow>218 public PluginClassHandler <GridWindow, CompWindow>
136{219{
137 public:220 public:
138221
139 GridWindow (CompWindow *);222 GridWindow (CompWindow *);
140 CompWindow *window;223 CompWindow *window;
224 GLWindow *glWindow;
141 GridScreen *gScreen;225 GridScreen *gScreen;
142226
143 bool isGridResized;227 bool isGridResized;
@@ -154,6 +238,12 @@
154 GridRectangle238 GridRectangle
155 constrainSize (const GridRectangle & slot);239 constrainSize (const GridRectangle & slot);
156240
241 bool
242 glDraw (const GLMatrix &transform,
243 GLFragment::Attrib &fragment,
244 const CompRegion &region,
245 unsigned int mask);
246
157 void grabNotify (int, int, unsigned int, unsigned int);247 void grabNotify (int, int, unsigned int, unsigned int);
158248
159 void ungrabNotify ();249 void ungrabNotify ();

Subscribers

People subscribed via source and target branches