Merge lp:~dbarth/compiz/reworked-fix-744104 into lp:~unity-team/compiz/trunk
- reworked-fix-744104
- Merge into 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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity Team | Pending | ||
Review via email: mp+56583@code.launchpad.net |
Commit message
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
1 | === modified file 'plugins/grid/grid.xml.in' |
2 | --- plugins/grid/grid.xml.in 2011-04-05 13:32:45 +0000 |
3 | +++ plugins/grid/grid.xml.in 2011-04-06 14:53:28 +0000 |
4 | @@ -556,6 +556,37 @@ |
5 | <alpha>0x4f4f</alpha> |
6 | </default> |
7 | </option> |
8 | + <option name="indicator_direction" type="int"> |
9 | + <_short>Indicator direction</_short> |
10 | + <_long>Where the indicator should come from on-screen</_long> |
11 | + <default>0</default> |
12 | + <min>0</min> |
13 | + <max>1</max> |
14 | + <desc> |
15 | + <value>0</value> |
16 | + <_name>From Window</_name> |
17 | + </desc> |
18 | + <desc> |
19 | + <value>1</value> |
20 | + <_name>From Edge</_name> |
21 | + </desc> |
22 | + </option> |
23 | + <option name="indicator_type" type="int"> |
24 | + <_short>Indicator type</_short> |
25 | + <_long>Appearance of the indicator</_long> |
26 | + <default>0</default> |
27 | + <min>0</min> |
28 | + <max>0</max> |
29 | + <desc> |
30 | + <value>0</value> |
31 | + <_name>Outline</_name> |
32 | + </desc> |
33 | + </option> |
34 | + <option name="behind_window" type="bool"> |
35 | + <_short>Behind window</_short> |
36 | + <_long>Draw indicator behind window</_long> |
37 | + <default>true</default> |
38 | + </option> |
39 | </group> |
40 | </options> |
41 | </plugin> |
42 | |
43 | === modified file 'plugins/grid/src/grid.cpp' |
44 | --- plugins/grid/src/grid.cpp 2011-04-05 13:32:45 +0000 |
45 | +++ plugins/grid/src/grid.cpp 2011-04-06 14:53:28 +0000 |
46 | @@ -127,7 +127,7 @@ |
47 | if (edgeToGridType () != GridUnknown && optionGetDrawIndicator () && |
48 | gw->allowGrid (edgeToGridType ())) |
49 | { |
50 | - cRect = gw->constrainSize (desiredSlot); |
51 | + cRect = gw->constrainSize (*desiredSlot); |
52 | } |
53 | else |
54 | cRect.setGeometry (0, 0, 0, 0); |
55 | @@ -146,7 +146,17 @@ |
56 | xid = CompOption::getIntOptionNamed (option, "window"); |
57 | cw = screen->findWindow (xid); |
58 | |
59 | - if (where == GridUnknown || screen->otherGrabExist ("move", NULL)) |
60 | + if (where == GridUnknown) |
61 | + { |
62 | + if (desiredSlot) |
63 | + { |
64 | + delete desiredSlot; |
65 | + desiredSlot = NULL; |
66 | + } |
67 | + |
68 | + return false; |
69 | + } |
70 | + else if (screen->otherGrabExist ("move", NULL)) |
71 | return false; |
72 | |
73 | if (cw) |
74 | @@ -155,6 +165,9 @@ |
75 | |
76 | GRID_WINDOW (cw); |
77 | |
78 | + if (!gw->allowGrid (where)) |
79 | + return false; |
80 | + |
81 | if (gw->lastTarget != where) |
82 | gw->resizeCount = 0; |
83 | |
84 | @@ -199,6 +212,41 @@ |
85 | return true; |
86 | } |
87 | |
88 | + /* Should really be three different types here, but not enough time |
89 | + * to implement that one FIXME */ |
90 | + if (!desiredSlot) |
91 | + { |
92 | + if (resize) |
93 | + { |
94 | + desiredSlot = new PaintableAnimatedGridRectangle (); |
95 | + |
96 | + if (!desiredSlot) |
97 | + return false; |
98 | + } |
99 | + else |
100 | + { |
101 | + CompRect sbr = cw->serverBorderRect (); |
102 | + if (compositingActive) |
103 | + { |
104 | + CompRect sbr = cw->serverBorderRect (); |
105 | + desiredSlot = new PaintableAnimatedGridRectangle (); |
106 | + |
107 | + if (!desiredSlot) |
108 | + return false; |
109 | + } |
110 | + else |
111 | + { |
112 | + desiredSlot = new PaintableAnimatedGridRectangle (); |
113 | + |
114 | + if (!desiredSlot) |
115 | + return false; |
116 | + } |
117 | + |
118 | + ((AnimatedGridRectangle *) desiredSlot)->setFrom (sbr); |
119 | + } |
120 | + } |
121 | + |
122 | + |
123 | /* Convention: |
124 | * xxxSlot include decorations (it's the screen area occupied) |
125 | * xxxRect are undecorated (it's the constrained position |
126 | @@ -206,15 +254,15 @@ |
127 | */ |
128 | |
129 | /* slice and dice to get desired slot - including decorations */ |
130 | - desiredSlot.setY (workarea.y () + props.gravityDown * |
131 | + desiredSlot->setY (workarea.y () + props.gravityDown * |
132 | (workarea.height () / props.numCellsY)); |
133 | - desiredSlot.setHeight (workarea.height () / props.numCellsY); |
134 | - desiredSlot.setX (workarea.x () + props.gravityRight * |
135 | + desiredSlot->setHeight (workarea.height () / props.numCellsY); |
136 | + desiredSlot->setX (workarea.x () + props.gravityRight * |
137 | (workarea.width () / props.numCellsX)); |
138 | - desiredSlot.setWidth (workarea.width () / props.numCellsX); |
139 | + desiredSlot->setWidth (workarea.width () / props.numCellsX); |
140 | |
141 | /* Adjust for constraints and decorations */ |
142 | - desiredRect = gw->constrainSize (desiredSlot).subtractBorders (cw); |
143 | + desiredRect = gw->constrainSize (*desiredSlot).subtractBorders (cw); |
144 | /* Get current rect not including decorations */ |
145 | currentRect.setGeometry (cw->serverX (), cw->serverY (), |
146 | cw->serverWidth (), |
147 | @@ -243,8 +291,8 @@ |
148 | switch (gw->resizeCount) |
149 | { |
150 | case 1: |
151 | - desiredSlot.setWidth (slotWidth66); |
152 | - desiredSlot.setX (workarea.x () + |
153 | + desiredSlot->setWidth (slotWidth66); |
154 | + desiredSlot->setX (workarea.x () + |
155 | props.gravityRight * slotWidth33); |
156 | gw->resizeCount++; |
157 | break; |
158 | @@ -252,20 +300,20 @@ |
159 | gw->resizeCount++; |
160 | break; |
161 | case 3: |
162 | - desiredSlot.setWidth (slotWidth33); |
163 | - desiredSlot.setX (workarea.x () + |
164 | + desiredSlot->setWidth (slotWidth33); |
165 | + desiredSlot->setX (workarea.x () + |
166 | props.gravityRight * slotWidth66); |
167 | gw->resizeCount++; |
168 | break; |
169 | case 4: |
170 | - desiredSlot.setWidth (slotWidth25); |
171 | - desiredSlot.setX (workarea.x () + |
172 | + desiredSlot->setWidth (slotWidth25); |
173 | + desiredSlot->setX (workarea.x () + |
174 | props.gravityRight * slotWidth75); |
175 | gw->resizeCount++; |
176 | break; |
177 | case 5: |
178 | - desiredSlot.setWidth (slotWidth75); |
179 | - desiredSlot.setX (workarea.x () + |
180 | + desiredSlot->setWidth (slotWidth75); |
181 | + desiredSlot->setX (workarea.x () + |
182 | props.gravityRight * slotWidth25); |
183 | gw->resizeCount++; |
184 | break; |
185 | @@ -284,27 +332,27 @@ |
186 | switch (gw->resizeCount) |
187 | { |
188 | case 1: |
189 | - desiredSlot.setWidth (workarea.width () - |
190 | + desiredSlot->setWidth (workarea.width () - |
191 | (slotWidth17 * 2)); |
192 | - desiredSlot.setX (workarea.x () + slotWidth17); |
193 | + desiredSlot->setX (workarea.x () + slotWidth17); |
194 | gw->resizeCount++; |
195 | break; |
196 | case 2: |
197 | - desiredSlot.setWidth ((slotWidth25 * 2) + |
198 | + desiredSlot->setWidth ((slotWidth25 * 2) + |
199 | (slotWidth17 * 2)); |
200 | - desiredSlot.setX (workarea.x () + |
201 | + desiredSlot->setX (workarea.x () + |
202 | (slotWidth25 - slotWidth17)); |
203 | gw->resizeCount++; |
204 | break; |
205 | case 3: |
206 | - desiredSlot.setWidth ((slotWidth25 * 2)); |
207 | - desiredSlot.setX (workarea.x () + slotWidth25); |
208 | + desiredSlot->setWidth ((slotWidth25 * 2)); |
209 | + desiredSlot->setX (workarea.x () + slotWidth25); |
210 | gw->resizeCount++; |
211 | break; |
212 | case 4: |
213 | - desiredSlot.setWidth (slotWidth33 - |
214 | + desiredSlot->setWidth (slotWidth33 - |
215 | (cw->border ().left + cw->border ().right)); |
216 | - desiredSlot.setX (workarea.x () + slotWidth33); |
217 | + desiredSlot->setX (workarea.x () + slotWidth33); |
218 | gw->resizeCount++; |
219 | break; |
220 | case 5: |
221 | @@ -318,7 +366,7 @@ |
222 | if (gw->resizeCount == 6) |
223 | gw->resizeCount = 1; |
224 | |
225 | - desiredRect = gw->constrainSize (desiredSlot).subtractBorders (cw); |
226 | + desiredRect = gw->constrainSize (*desiredSlot).subtractBorders (cw); |
227 | } |
228 | |
229 | /* TODO: animate move+resize */ |
230 | @@ -336,6 +384,9 @@ |
231 | if (cw->mapNum ()) |
232 | cw->sendSyncRequest (); |
233 | |
234 | + delete desiredSlot; |
235 | + desiredSlot = NULL; |
236 | + |
237 | cw->configureXWindow (flags, &xwc); |
238 | gw->isGridResized = true; |
239 | gw->isGridMaximized = false; |
240 | @@ -347,48 +398,102 @@ |
241 | return true; |
242 | } |
243 | |
244 | -void |
245 | -GridScreen::glPaintRectangle (const GLScreenPaintAttrib &sAttrib, |
246 | - const GLMatrix &transform, |
247 | - CompOutput *output) |
248 | -{ |
249 | - CompRect rect; |
250 | - GLMatrix sTransform (transform); |
251 | - |
252 | - getPaintRectangle (rect); |
253 | - |
254 | - glPushMatrix (); |
255 | - |
256 | - sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA); |
257 | - |
258 | - glLoadMatrixf (sTransform.getMatrix ()); |
259 | - |
260 | - glDisableClientState (GL_TEXTURE_COORD_ARRAY); |
261 | - glEnable (GL_BLEND); |
262 | - |
263 | - /* fill rectangle */ |
264 | - glColor4usv (optionGetFillColor ()); |
265 | - glRecti (rect.x1 (), rect.y2 (), rect.x2 (), rect.y1 ()); |
266 | - |
267 | - /* Set outline rect smaller to avoid damage issues */ |
268 | - rect.setGeometry (rect.x () + 1, rect.y () + 1, |
269 | - rect.width () - 2, rect.height () - 2); |
270 | - |
271 | - /* draw outline */ |
272 | - glColor4usv (optionGetOutlineColor ()); |
273 | - glLineWidth (2.0); |
274 | - glBegin (GL_LINE_LOOP); |
275 | - glVertex2i (rect.x1 (), rect.y1 ()); |
276 | - glVertex2i (rect.x2 (), rect.y1 ()); |
277 | - glVertex2i (rect.x2 (), rect.y2 ()); |
278 | - glVertex2i (rect.x1 (), rect.y2 ()); |
279 | - glEnd (); |
280 | - |
281 | - /* clean up */ |
282 | - glColor4usv (defaultColor); |
283 | - glDisable (GL_BLEND); |
284 | - glEnableClientState (GL_TEXTURE_COORD_ARRAY); |
285 | - glPopMatrix (); |
286 | +CompRect |
287 | +AnimatedGridRectangle::current () |
288 | +{ |
289 | + /* Expand edges out to destination rect based on progress */ |
290 | + |
291 | + CompRect ret = mFrom; |
292 | + |
293 | + ret.setTop (floor (mFrom.top () + (top () - mFrom.top ()) * mProgress)); |
294 | + ret.setLeft (floor (mFrom.left () + (left () - mFrom.left ()) * mProgress)); |
295 | + ret.setRight (floor (mFrom.right () + (right () - mFrom.right ()) * mProgress)); |
296 | + ret.setBottom (floor (mFrom.bottom () + (bottom () - mFrom.bottom ()) * mProgress)); |
297 | + |
298 | + return ret; |
299 | +} |
300 | + |
301 | +float |
302 | +AnimatedGridRectangle::progress () |
303 | +{ |
304 | + return mProgress; |
305 | +} |
306 | + |
307 | +void |
308 | +AnimatedGridRectangle::setTime (unsigned int t) |
309 | +{ |
310 | + mTime = t; |
311 | +} |
312 | + |
313 | +void |
314 | +AnimatedGridRectangle::setFrom (CompRect &f) |
315 | +{ |
316 | + mFrom = f; |
317 | +} |
318 | + |
319 | +void |
320 | +AnimatedGridRectangle::setProgress (float p) |
321 | +{ |
322 | + mProgress = p; |
323 | + |
324 | + if (mProgress >= 1.0f) |
325 | + mProgress = 1.0f; |
326 | + else if (mProgress <= 0.0f) |
327 | + mProgress = 0.0f; |
328 | +} |
329 | + |
330 | +void |
331 | +AnimatedGridRectangle::reset () |
332 | +{ |
333 | + mProgress = 0.0f; |
334 | +} |
335 | + |
336 | +void |
337 | +PaintableAnimatedGridRectangle::paint (const GLMatrix &mat) |
338 | +{ |
339 | + CompRect outline; |
340 | + CompRect fill = current (); |
341 | + GridScreen *gScreen = GridScreen::get (screen); |
342 | + |
343 | + if (gScreen->optionGetIndicatorType () == GridOptions::IndicatorTypeOutline) |
344 | + { |
345 | + glPushMatrix (); |
346 | + |
347 | + glLoadMatrixf (mat.getMatrix ()); |
348 | + |
349 | + glDisableClientState (GL_TEXTURE_COORD_ARRAY); |
350 | + glEnable (GL_BLEND); |
351 | + |
352 | + /* fill rectangle */ |
353 | + glColor4f ((float) gScreen->optionGetFillColorRed () / 65535.0f, |
354 | + (float) gScreen->optionGetFillColorGreen () / 65535.0f, |
355 | + (float) gScreen->optionGetFillColorBlue () / 65535.0f, |
356 | + ((float) gScreen->optionGetFillColorAlpha () / 65535.0f) * progress ()); |
357 | + glRecti (fill.x1 (), fill.y2 (), fill.x2 (), fill.y1 ()); |
358 | + |
359 | + /* Set outline rect smaller to avoid damage issues */ |
360 | + outline.setGeometry (fill.x () + 1, fill.y () + 1, |
361 | + fill.width () - 2,fill. height () - 2); |
362 | + |
363 | + /* draw outline */ |
364 | + glColor4f ((float) gScreen->optionGetOutlineColorRed () / 65535.0f, |
365 | + (float) gScreen->optionGetOutlineColorGreen () / 65535.0f, |
366 | + (float) gScreen->optionGetOutlineColorBlue () / 65535.0f, |
367 | + ((float) gScreen->optionGetOutlineColorAlpha () / 65535.0f) * progress ()); |
368 | + glLineWidth (2.0); |
369 | + glBegin (GL_LINE_LOOP); |
370 | + glVertex2i (outline.x1 (), outline.y1 ()); |
371 | + glVertex2i (outline.x2 (), outline.y1 ()); |
372 | + glVertex2i (outline.x2 (), outline.y2 ()); |
373 | + glVertex2i (outline.x1 (), outline.y2 ()); |
374 | + glEnd (); |
375 | + |
376 | + /* clean up */ |
377 | + glColor4usv (defaultColor); |
378 | + glDisable (GL_BLEND); |
379 | + glEnableClientState (GL_TEXTURE_COORD_ARRAY); |
380 | + glPopMatrix (); |
381 | + } |
382 | } |
383 | |
384 | bool |
385 | @@ -398,11 +503,18 @@ |
386 | CompOutput *output, |
387 | unsigned int mask) |
388 | { |
389 | - bool status; |
390 | - |
391 | - status = glScreen->glPaintOutput (attrib, matrix, region, output, mask); |
392 | - |
393 | - glPaintRectangle (attrib, matrix, output); |
394 | + bool status; |
395 | + |
396 | + if (desiredSlot && optionGetDrawIndicator ()) |
397 | + { |
398 | + GLMatrix sTransform (matrix); |
399 | + status = glScreen->glPaintOutput (attrib, matrix, region, output, mask); |
400 | + |
401 | + sTransform.toScreenSpace (output, -DEFAULT_Z_CAMERA); |
402 | + ((PaintableAnimatedGridRectangle *) desiredSlot)->paint (sTransform); |
403 | + } |
404 | + else |
405 | + status = glScreen->glPaintOutput (attrib, matrix, region, output, mask); |
406 | |
407 | return status; |
408 | } |
409 | @@ -452,6 +564,8 @@ |
410 | CompOutput out; |
411 | CompOption::Vector opts; |
412 | CompOption::Value v = CompOption::Value ((int) mGrabWindow->id ()); |
413 | + CompRect *edgeBox = NULL; |
414 | + float edgeDist; /* interpolated 0.0f -> 1.0f based on distance */ |
415 | |
416 | screen->handleEvent (event); |
417 | |
418 | @@ -469,31 +583,182 @@ |
419 | /* Bottom Left */ |
420 | if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold()) && |
421 | pointerX < out.x () + optionGetLeftEdgeThreshold()) |
422 | + { |
423 | + float xd, yd; |
424 | + unsigned int xptr = (out.x ()) + pointerX; |
425 | + unsigned int yptr = (out.y () + out.height ()) - pointerY; |
426 | + |
427 | + if (xptr) |
428 | + xd = MIN (((float) xptr / (float) optionGetLeftEdgeThreshold ()), 1.0f); |
429 | + else |
430 | + xd = 0.0f; |
431 | + |
432 | + if (yptr) |
433 | + yd = MIN (((float) yptr / (float) optionGetBottomEdgeThreshold ()), 1.0f); |
434 | + else |
435 | + yd = 0.0f; |
436 | + |
437 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge) |
438 | + edgeBox = new CompRect (out.x (), out.y () + (out.height () - mGrabWindow->height ()), |
439 | + mGrabWindow->width (), mGrabWindow->height ()); |
440 | + |
441 | + edgeDist = (xd + yd) / 2.0f; |
442 | edge = BottomLeft; |
443 | + } |
444 | /* Bottom Right */ |
445 | else if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold()) && |
446 | pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold())) |
447 | + { |
448 | + float xd, yd; |
449 | + unsigned int xptr = (out.x () + out.width ()) - pointerX; |
450 | + unsigned int yptr = (out.y () + out.height ()) - pointerY; |
451 | + |
452 | + if (xptr) |
453 | + xd = MIN (((float) xptr / (float) optionGetRightEdgeThreshold ()), 1.0f); |
454 | + else |
455 | + xd = 0.0f; |
456 | + |
457 | + if (yptr) |
458 | + yd = MIN (((float) yptr / (float) optionGetBottomEdgeThreshold ()), 1.0f); |
459 | + else |
460 | + yd = 0.0f; |
461 | + |
462 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge) |
463 | + edgeBox = new CompRect (out.x () + (out.width () - mGrabWindow->width ()), |
464 | + out.y () + (out.height () - mGrabWindow->height ()), |
465 | + mGrabWindow->width (), mGrabWindow->height ()); |
466 | + |
467 | + edgeDist = (xd + yd) / 2.0f; |
468 | edge = BottomRight; |
469 | + } |
470 | /* Top Left */ |
471 | else if (pointerY < optionGetTopEdgeThreshold() && |
472 | pointerX < optionGetLeftEdgeThreshold()) |
473 | + { |
474 | + float xd, yd; |
475 | + unsigned int xptr = (out.x ()) + pointerX; |
476 | + unsigned int yptr = (out.y ()) + pointerY; |
477 | + |
478 | + if (xptr) |
479 | + xd = MIN (((float) xptr / (float) optionGetLeftEdgeThreshold ()), 1.0f); |
480 | + else |
481 | + xd = 0.0f; |
482 | + |
483 | + if (yptr) |
484 | + yd = MIN (((float) yptr / (float) optionGetTopEdgeThreshold ()), 1.0f); |
485 | + else |
486 | + yd = 0.0f; |
487 | + |
488 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge) |
489 | + edgeBox = new CompRect (out.x (), |
490 | + out.y (), |
491 | + mGrabWindow->width (), mGrabWindow->height ()); |
492 | + |
493 | + edgeDist = (xd + yd) / 2.0f; |
494 | edge = TopLeft; |
495 | + } |
496 | /* Top Right */ |
497 | else if (pointerY < out.y () + optionGetTopEdgeThreshold() && |
498 | pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold())) |
499 | + { |
500 | + float xd, yd; |
501 | + unsigned int xptr = (out.x () + out.width ()) - pointerX; |
502 | + unsigned int yptr = (out.y ()) + pointerY; |
503 | + |
504 | + if (xptr) |
505 | + xd = MIN (((float) xptr / (float) optionGetRightEdgeThreshold ()), 1.0f); |
506 | + else |
507 | + xd = 0.0f; |
508 | + |
509 | + if (yptr) |
510 | + yd = MIN (((float) yptr / (float) optionGetTopEdgeThreshold ()), 1.0f); |
511 | + else |
512 | + yd = 0.0f; |
513 | + |
514 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge) |
515 | + edgeBox = new CompRect (out.x () + (out.width () - mGrabWindow->width ()), |
516 | + out.y (), |
517 | + mGrabWindow->width (), mGrabWindow->height ()); |
518 | + |
519 | + edgeDist = (xd + yd) / 2.0f; |
520 | edge = TopRight; |
521 | + } |
522 | /* Left */ |
523 | else if (pointerX < out.x () + optionGetLeftEdgeThreshold()) |
524 | + { |
525 | + float xd; |
526 | + unsigned int xptr = (out.x ()) + pointerX; |
527 | + |
528 | + if (xptr) |
529 | + xd = MIN (((float) xptr / (float) optionGetLeftEdgeThreshold ()), 1.0f); |
530 | + else |
531 | + xd = 0.0f; |
532 | + |
533 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge) |
534 | + edgeBox = new CompRect (out.x (), |
535 | + out.y () + (out.height () / 2.0f) - mGrabWindow->height () / 2.0f, |
536 | + mGrabWindow->width (), mGrabWindow->height ()); |
537 | + |
538 | + edgeDist = xd; |
539 | edge = Left; |
540 | + } |
541 | /* Right */ |
542 | else if (pointerX > (out.x () + out.width () - optionGetRightEdgeThreshold())) |
543 | + { |
544 | + float xd; |
545 | + unsigned int xptr = (out.x () + out.width ()) - pointerX; |
546 | + |
547 | + if (xptr) |
548 | + xd = MIN (((float) xptr / (float) optionGetRightEdgeThreshold ()), 1.0f); |
549 | + else |
550 | + xd = 0.0f; |
551 | + |
552 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge) |
553 | + edgeBox = new CompRect (out.x () + (out.width () - mGrabWindow->width ()), |
554 | + out.y () + (out.height () / 2.0f) - mGrabWindow->height () / 2.0f, |
555 | + mGrabWindow->width (), mGrabWindow->height ()); |
556 | + |
557 | + edgeDist = xd; |
558 | edge = Right; |
559 | + } |
560 | /* Top */ |
561 | else if (pointerY < out.y () + optionGetTopEdgeThreshold()) |
562 | + { |
563 | + float yd; |
564 | + unsigned int yptr = (out.y ()) + pointerY; |
565 | + |
566 | + if (yptr) |
567 | + yd = MIN (((float) yptr / (float) optionGetTopEdgeThreshold ()), 1.0f); |
568 | + else |
569 | + yd = 0.0f; |
570 | + |
571 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge) |
572 | + edgeBox = new CompRect (out.x () + (out.width () / 2.0f) - mGrabWindow->width () / 2.0f, |
573 | + out.y (), |
574 | + mGrabWindow->width (), mGrabWindow->height ()); |
575 | + |
576 | + edgeDist = yd; |
577 | edge = Top; |
578 | + } |
579 | /* Bottom */ |
580 | else if (pointerY > (out.y () + out.height () - optionGetBottomEdgeThreshold())) |
581 | + { |
582 | + float yd; |
583 | + unsigned int yptr = (out.y () + out.width ()) - pointerY; |
584 | + |
585 | + if (yptr) |
586 | + yd = MIN (((float) yptr / (float) optionGetBottomEdgeThreshold ()), 1.0f); |
587 | + else |
588 | + yd = 0.0f; |
589 | + |
590 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromEdge) |
591 | + edgeBox = new CompRect (out.x () + (out.width () / 2.0f) - mGrabWindow->width () / 2.0f, |
592 | + out.y () + (out.height () - mGrabWindow->height ()), |
593 | + mGrabWindow->width (), mGrabWindow->height ()); |
594 | + |
595 | + edgeDist = yd; |
596 | edge = Bottom; |
597 | + } |
598 | /* No Edge */ |
599 | else |
600 | edge = NoEdge; |
601 | @@ -504,29 +769,71 @@ |
602 | (screen->outputDeviceForPoint (pointerX, pointerY)); |
603 | if (lastWorkarea != currentWorkarea) |
604 | { |
605 | + CompRect old; |
606 | + |
607 | + if (desiredSlot) |
608 | + old = *desiredSlot; |
609 | + |
610 | lastWorkarea = currentWorkarea; |
611 | |
612 | if (compositingActive && cScreen) |
613 | - cScreen->damageRegion (desiredSlot); |
614 | + cScreen->damageRegion (old); |
615 | |
616 | initiateCommon (0, 0, opts, edgeToGridType (), false); |
617 | |
618 | + if (edgeBox && desiredSlot) |
619 | + { |
620 | + desiredSlot->setFrom (*edgeBox); |
621 | + delete edgeBox; |
622 | + } |
623 | + |
624 | if (compositingActive && cScreen) |
625 | - cScreen->damageRegion (desiredSlot); |
626 | + cScreen->damageRegion (desiredSlot ? *desiredSlot : old); |
627 | } |
628 | |
629 | /* Detect edge region change */ |
630 | if (lastEdge != edge) |
631 | { |
632 | + CompRect old; |
633 | + |
634 | + if (desiredSlot) |
635 | + { |
636 | + ((AnimatedGridRectangle *) desiredSlot)->reset (); |
637 | + old = *desiredSlot; |
638 | + } |
639 | + |
640 | lastEdge = edge; |
641 | |
642 | if (compositingActive && cScreen) |
643 | - cScreen->damageRegion (desiredSlot); |
644 | + cScreen->damageRegion (old); |
645 | |
646 | initiateCommon (0, 0, opts, edgeToGridType (), false); |
647 | |
648 | + if (edgeBox && desiredSlot) |
649 | + { |
650 | + desiredSlot->setFrom (*edgeBox); |
651 | + delete edgeBox; |
652 | + } |
653 | + |
654 | if (compositingActive && cScreen) |
655 | - cScreen->damageRegion (desiredSlot); |
656 | + cScreen->damageRegion (desiredSlot ? *desiredSlot : old); |
657 | + } |
658 | + |
659 | + /* The closer the user gets to the edge, the more progress should go up */ |
660 | + if (desiredSlot) |
661 | + { |
662 | + CompRect damage; |
663 | + CompRect sbr = mGrabWindow->serverBorderRect (); |
664 | + |
665 | + damage = ((AnimatedGridRectangle *) desiredSlot)->current (); |
666 | + cScreen->damageRegion (damage); |
667 | + |
668 | + if (optionGetIndicatorDirection () == GridOptions::IndicatorDirectionFromWindow) |
669 | + ((AnimatedGridRectangle *) desiredSlot)->setFrom (sbr); |
670 | + ((AnimatedGridRectangle *) desiredSlot)->setProgress (1.0f - edgeDist); |
671 | + |
672 | + damage = ((AnimatedGridRectangle *) desiredSlot)->current (); |
673 | + cScreen->damageRegion (damage); |
674 | } |
675 | |
676 | GRID_WINDOW (mGrabWindow); |
677 | @@ -540,6 +847,24 @@ |
678 | restoreWindow (0, 0, opts); |
679 | } |
680 | |
681 | +bool |
682 | +GridWindow::glDraw (const GLMatrix &transform, |
683 | + GLFragment::Attrib &fragment, |
684 | + const CompRegion ®ion, |
685 | + unsigned int mask) |
686 | +{ |
687 | + CompRegion nRegion = region; |
688 | + |
689 | + if (gScreen->desiredSlot) |
690 | + { |
691 | + nRegion = nRegion.united (gScreen->desiredSlot->current ()); |
692 | + |
693 | + gScreen->desiredSlot->paint (transform); |
694 | + } |
695 | + |
696 | + return glWindow->glDraw (transform, fragment, nRegion, mask); |
697 | + } |
698 | + |
699 | void |
700 | GridWindow::grabNotify (int x, |
701 | int y, |
702 | @@ -550,7 +875,12 @@ |
703 | { |
704 | screen->handleEventSetEnabled (gScreen, true); |
705 | if (compositingActive) |
706 | - gScreen->glScreen->glPaintOutputSetEnabled (gScreen, true); |
707 | + { |
708 | + if (gScreen->optionGetBehindWindow ()) |
709 | + glWindow->glDrawSetEnabled (this, true); |
710 | + else |
711 | + gScreen->glScreen->glPaintOutputSetEnabled (gScreen, true); |
712 | + } |
713 | gScreen->mGrabWindow = window; |
714 | pointerBufDx = pointerBufDy = 0; |
715 | |
716 | @@ -574,6 +904,7 @@ |
717 | if (window == gScreen->mGrabWindow) |
718 | { |
719 | CompOption::Vector opts; |
720 | + CompRect damage = gScreen->desiredSlot ? *gScreen->desiredSlot : CompRect (0, 0, 0, 0); |
721 | CompOption::Value v = CompOption::Value ((int) gScreen->mGrabWindow->id ()); |
722 | |
723 | opts.resize (1); |
724 | @@ -587,8 +918,11 @@ |
725 | |
726 | if (compositingActive) |
727 | { |
728 | - gScreen->glScreen->glPaintOutputSetEnabled (gScreen, false); |
729 | - gScreen->cScreen->damageRegion (gScreen->desiredSlot); |
730 | + if (gScreen->optionGetBehindWindow ()) |
731 | + glWindow->glDrawSetEnabled (this, false); |
732 | + else |
733 | + gScreen->glScreen->glPaintOutputSetEnabled (gScreen, false); |
734 | + gScreen->cScreen->damageRegion (damage); |
735 | } |
736 | |
737 | gScreen->mGrabWindow = NULL; |
738 | @@ -654,6 +988,7 @@ |
739 | |
740 | GridScreen::GridScreen (CompScreen *screen) : |
741 | PluginClassHandler<GridScreen, CompScreen> (screen), |
742 | + desiredSlot (NULL), |
743 | mGrabWindow (NULL) |
744 | { |
745 | if (compositingActive) |
746 | @@ -661,8 +996,7 @@ |
747 | cScreen = CompositeScreen::get (screen); |
748 | glScreen = GLScreen::get (screen); |
749 | |
750 | - CompositeScreenInterface::setHandler (cScreen, false); |
751 | - GLScreenInterface::setHandler (glScreen, false); |
752 | + ScreenInterface::setHandler (screen, false); |
753 | } |
754 | |
755 | ScreenInterface::setHandler (screen, false); |
756 | @@ -696,6 +1030,7 @@ |
757 | GridWindow::GridWindow (CompWindow *window) : |
758 | PluginClassHandler <GridWindow, CompWindow> (window), |
759 | window (window), |
760 | + glWindow (GLWindow::get (window)), |
761 | gScreen (GridScreen::get (screen)), |
762 | isGridResized (false), |
763 | isGridMaximized (false), |
764 | @@ -705,6 +1040,7 @@ |
765 | lastTarget (GridUnknown) |
766 | { |
767 | WindowInterface::setHandler (window); |
768 | + GLWindowInterface::setHandler (glWindow, false); |
769 | } |
770 | |
771 | /* Initial plugin init function called. Checks to see if we are ABI |
772 | |
773 | === modified file 'plugins/grid/src/grid.h' |
774 | --- plugins/grid/src/grid.h 2011-04-05 13:32:45 +0000 |
775 | +++ plugins/grid/src/grid.h 2011-04-06 14:53:28 +0000 |
776 | @@ -28,6 +28,8 @@ |
777 | #include <composite/composite.h> |
778 | #include <opengl/opengl.h> |
779 | |
780 | +#include <cmath> |
781 | + |
782 | #include "grid_options.h" |
783 | |
784 | #define SNAPOFF_THRESHOLD 50 |
785 | @@ -85,6 +87,89 @@ |
786 | GridRectangle addBorders (CompWindow *w) const; |
787 | }; |
788 | |
789 | +class Paintable |
790 | +{ |
791 | + public: |
792 | + |
793 | + Paintable () |
794 | + { |
795 | + }; |
796 | + |
797 | + virtual void paint (const GLMatrix &mat) = 0; |
798 | +}; |
799 | + |
800 | +class AnimatedGridRectangle : |
801 | + public GridRectangle |
802 | +{ |
803 | + public: |
804 | + |
805 | + AnimatedGridRectangle () : |
806 | + GridRectangle::GridRectangle (), |
807 | + mFrom (CompRect (0, 0, 0, 0)), |
808 | + mProgress (0.0f), |
809 | + mTime (300) |
810 | + { |
811 | + }; |
812 | + |
813 | + AnimatedGridRectangle (const GridRectangle &r) : |
814 | + GridRectangle::GridRectangle (r), |
815 | + mFrom (CompRect (0, 0, 0, 0)), |
816 | + mProgress (0.0f), |
817 | + mTime (300) |
818 | + { |
819 | + }; |
820 | + |
821 | + AnimatedGridRectangle (const CompRect &r) : |
822 | + GridRectangle::GridRectangle (r), |
823 | + mFrom (CompRect (0, 0, 0, 0)), |
824 | + mProgress (0.0f), |
825 | + mTime (300) |
826 | + { |
827 | + }; |
828 | + |
829 | + CompRect current (); |
830 | + float progress (); |
831 | + |
832 | + void setFrom (CompRect &); |
833 | + void setProgress (float); |
834 | + void reset (); |
835 | + void setTime (unsigned int); |
836 | + |
837 | + private: |
838 | + |
839 | + CompRect mFrom; |
840 | + float mProgress; |
841 | + |
842 | + unsigned int mTime; |
843 | +}; |
844 | + |
845 | +class PaintableAnimatedGridRectangle : |
846 | + public Paintable, |
847 | + public AnimatedGridRectangle |
848 | +{ |
849 | + public: |
850 | + |
851 | + PaintableAnimatedGridRectangle () : |
852 | + Paintable::Paintable (), |
853 | + AnimatedGridRectangle::AnimatedGridRectangle () |
854 | + { |
855 | + }; |
856 | + |
857 | + PaintableAnimatedGridRectangle (const GridRectangle &r) : |
858 | + Paintable::Paintable (), |
859 | + AnimatedGridRectangle::AnimatedGridRectangle (r) |
860 | + { |
861 | + }; |
862 | + |
863 | + PaintableAnimatedGridRectangle (const CompRect &r) : |
864 | + Paintable::Paintable (), |
865 | + AnimatedGridRectangle::AnimatedGridRectangle (r) |
866 | + { |
867 | + }; |
868 | + |
869 | + virtual void paint (const GLMatrix &mat); |
870 | +}; |
871 | + |
872 | class GridScreen : |
873 | public ScreenInterface, |
874 | public CompositeScreenInterface, |
875 | @@ -98,7 +183,7 @@ |
876 | CompositeScreen *cScreen; |
877 | GLScreen *glScreen; |
878 | |
879 | - GridRectangle desiredSlot; |
880 | + PaintableAnimatedGridRectangle *desiredSlot; |
881 | CompRect workarea, currentRect, |
882 | desiredRect, lastWorkarea, currentWorkarea; |
883 | GridProps props; |
884 | @@ -110,9 +195,6 @@ |
885 | bool initiateCommon (CompAction*, CompAction::State, |
886 | CompOption::Vector&, GridType, bool); |
887 | |
888 | - void glPaintRectangle (const GLScreenPaintAttrib&, |
889 | - const GLMatrix&, CompOutput *); |
890 | - |
891 | bool glPaintOutput (const GLScreenPaintAttrib &, |
892 | const GLMatrix &, const CompRegion &, |
893 | CompOutput *, unsigned int); |
894 | @@ -132,12 +214,14 @@ |
895 | |
896 | class GridWindow : |
897 | public WindowInterface, |
898 | + public GLWindowInterface, |
899 | public PluginClassHandler <GridWindow, CompWindow> |
900 | { |
901 | public: |
902 | |
903 | GridWindow (CompWindow *); |
904 | CompWindow *window; |
905 | + GLWindow *glWindow; |
906 | GridScreen *gScreen; |
907 | |
908 | bool isGridResized; |
909 | @@ -154,6 +238,12 @@ |
910 | GridRectangle |
911 | constrainSize (const GridRectangle & slot); |
912 | |
913 | + bool |
914 | + glDraw (const GLMatrix &transform, |
915 | + GLFragment::Attrib &fragment, |
916 | + const CompRegion ®ion, |
917 | + unsigned int mask); |
918 | + |
919 | void grabNotify (int, int, unsigned int, unsigned int); |
920 | |
921 | void ungrabNotify (); |