135
135
if (zs->zooms.at (out).currentZoom != 1.0f ||
136
zs->zooms.at (out).newZoom != 1.0f ||
137
zs->zooms.at (out).zVelocity != 0.0f)
136
zs->zooms.at (out).newZoom != 1.0f ||
137
zs->zooms.at (out).zVelocity != 0.0f)
143
143
/* Returns the distance to the defined edge in zoomed pixels. */
145
EZoomScreen::distanceToEdge (int out, EZoomScreen::ZoomEdge edge)
145
EZoomScreen::distanceToEdge (int out,
146
EZoomScreen::ZoomEdge edge)
147
148
CompOutput *o = &screen->outputDevs ().at (out);
157
158
o->region ()->extents.y1, &x1, &y1);
161
case WEST: return o->region ()->extents.x1 - x1;
160
162
case NORTH: return o->region ()->extents.y1 - y1;
163
case EAST: return x2 - o->region ()->extents.x2;
161
164
case SOUTH: return y2 - o->region ()->extents.y2;
162
case EAST: return x2 - o->region ()->extents.x2;
163
case WEST: return o->region ()->extents.x1 - x1;
165
167
return 0; // Never reached.
170
172
EZoomScreen::ZoomArea::updateActualTranslates ()
172
174
xtrans = -realXTranslate * (1.0f - currentZoom);
173
ytrans = realYTranslate * (1.0f - currentZoom);
175
ytrans = realYTranslate * (1.0f - currentZoom);
176
178
/* Returns true if the head in question is currently moving.
182
184
EZoomScreen::isInMovement (int out)
184
186
if (zooms.at (out).currentZoom == 1.0f &&
185
zooms.at (out).newZoom == 1.0f &&
186
zooms.at (out).zVelocity == 0.0f)
187
zooms.at (out).newZoom == 1.0f &&
188
zooms.at (out).zVelocity == 0.0f)
189
191
if (zooms.at (out).currentZoom != zooms.at (out).newZoom ||
227
231
yTranslate (0.0f),
228
232
realXTranslate (0.0f),
229
233
realYTranslate (0.0f),
233
240
/* Adjust the velocity in the z-direction. */
235
EZoomScreen::adjustZoomVelocity (int out, float chunk)
242
EZoomScreen::adjustZoomVelocity (int out,
237
float d = (zooms.at (out).newZoom - zooms.at (out).currentZoom) * 75.0f;
245
float d = (zooms.at (out).newZoom - zooms.at (out).currentZoom) * 75.0f;
239
246
float adjust = d * 0.002f;
240
247
float amount = fabs (d);
244
251
else if (amount > 5.0f)
247
zooms.at (out).zVelocity =
248
(amount * zooms.at (out).zVelocity + adjust) / (amount + 1.0f);
254
zooms.at (out).zVelocity = (amount * zooms.at (out).zVelocity + adjust) /
250
257
if (fabs (d) < 0.1f && fabs (zooms.at (out).zVelocity) < 0.005f)
252
259
zooms.at (out).currentZoom = zooms.at (out).newZoom;
253
zooms.at (out).zVelocity = 0.0f;
260
zooms.at (out).zVelocity = 0.0f;
256
263
zooms.at (out).currentZoom += (zooms.at (out).zVelocity * chunk) /
260
267
/* Adjust the X/Y velocity based on target translation and real
261
268
* translation. */
263
EZoomScreen::adjustXYVelocity (int out, float chunk)
270
EZoomScreen::adjustXYVelocity (int out,
265
273
zooms.at (out).xVelocity /= 1.25f;
266
274
zooms.at (out).yVelocity /= 1.25f;
296
304
zooms.at (out).realXTranslate = zooms.at (out).xTranslate;
297
305
zooms.at (out).realYTranslate = zooms.at (out).yTranslate;
298
zooms.at (out).xVelocity = 0.0f;
299
zooms.at (out).yVelocity = 0.0f;
306
zooms.at (out).xVelocity = 0.0f;
307
zooms.at (out).yVelocity = 0.0f;
402
410
const float MaxUShortFloat = std::numeric_limits <unsigned short>::max ();
412
GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
414
/* just enable blending if it is disabled */
406
418
/* Draw filled rectangle */
407
float alpha = optionGetZoomBoxFillColorAlpha () / MaxUShortFloat;
408
color = optionGetZoomBoxFillColor ();
419
float alpha = optionGetZoomBoxFillColorAlpha () / MaxUShortFloat;
420
GLushort *color = optionGetZoomBoxFillColor ();
410
422
colorData[0] = alpha * color[0];
411
423
colorData[1] = alpha * color[1];
466
478
streamingBuffer->end ();
467
479
streamingBuffer->render (zTransform);
469
glDisable (GL_BLEND);
481
/* just disable blending if it was disabled before */
483
glDisable (GL_BLEND);
471
485
/* Damage the zoom selection box region during draw. */
472
486
cScreen->damageRegion (CompRegion (x1 - 1,
508
522
status = gScreen->glPaintOutput (sa, zTransform, region, output, mask);
510
524
drawCursor (output, transform);
514
status = gScreen->glPaintOutput (attrib, transform, region, output,
527
status = gScreen->glPaintOutput (attrib, transform, region, output, mask);
518
530
drawBox (transform, output, box);
557
569
* that is, it's the point that's the same regardless of zoom level.
560
EZoomScreen::setCenter (int x, int y, bool instant)
572
EZoomScreen::setCenter (int x,
562
576
int out = screen->outputDeviceForPoint (x, y);
563
577
CompOutput *o = &screen->outputDevs ().at (out);
627
641
EZoomScreen::areaToWindow (CompWindow *w)
629
643
int left = w->serverX () - w->border ().left;
630
int width = w->width () + w->border ().left + w->border ().right;
631
644
int top = w->serverY () - w->border ().top;
632
int height = w->height () + w->border ().top + w->border ().bottom;
645
int width = w->width () + w->border ().left + w->border ().right;
646
int height = w->height () + w->border ().top + w->border ().bottom;
634
648
setZoomArea (left, top, width, height, false);
637
651
/* Pans the zoomed area vertically/horizontally by * value * zs->panFactor
638
652
* TODO: Fix output. */
640
EZoomScreen::panZoom (int xvalue, int yvalue)
654
EZoomScreen::panZoom (int xvalue,
657
float panFactor = optionGetPanFactor ();
642
659
for (unsigned int out = 0; out < zooms.size (); ++out)
644
zooms.at (out).xTranslate +=
645
optionGetPanFactor () * xvalue *
646
zooms.at (out).currentZoom;
647
zooms.at (out).yTranslate +=
648
optionGetPanFactor () * yvalue *
649
zooms.at (out).currentZoom;
661
zooms.at (out).xTranslate += panFactor * xvalue * zooms.at (out).currentZoom;
662
zooms.at (out).yTranslate += panFactor * yvalue * zooms.at (out).currentZoom;
652
665
constrainZoomTranslate ();
661
674
pollHandle.start ();
662
675
lastChange = time(NULL);
663
mouse = MousePoller::getCurrentPosition ();
676
mouse = MousePoller::getCurrentPosition ();
666
679
/* Sets the zoom (or scale) level.
667
680
* Cleans up if we are suddenly zoomed out.
670
EZoomScreen::setScale (int out, float value)
683
EZoomScreen::setScale (int out,
672
686
if (zooms.at (out).locked)
761
CompOutput *o = &screen->outputDevs ()[out];
762
ZoomArea &za = zooms.at (out);
775
CompOutput *o = &screen->outputDevs ()[out];
776
ZoomArea &za = zooms.at (out);
777
int oWidth = o->width ();
778
int oHeight = o->height ();
779
int halfOWidth = oWidth / 2;
780
int halfOHeight = oHeight / 2;
767
785
*resultX = x - (za.realXTranslate *
768
(1.0f - za.currentZoom) * o->width ()) - o->width () / 2;
786
(1.0f - za.currentZoom) * oWidth) - halfOWidth;
769
787
*resultX /= za.currentZoom;
770
*resultX += o->width () / 2;
788
*resultX += halfOWidth;
771
789
*resultX += o->x1 ();
772
790
*resultY = y - (za.realYTranslate *
773
(1.0f - za.currentZoom) * o->height ()) - o->height () / 2;
791
(1.0f - za.currentZoom) * oHeight) - halfOHeight;
774
792
*resultY /= za.currentZoom;
775
*resultY += o->height () / 2;
793
*resultY += halfOHeight;
776
794
*resultY += o->y1 ();
787
CompOutput *o = &screen->outputDevs ().at (out);
789
805
if (!outputIsZoomArea (out))
795
ZoomArea &za = zooms.at (out);
811
CompOutput *o = &screen->outputDevs ().at (out);
812
ZoomArea &za = zooms.at (out);
813
int oWidth = o->width ();
814
int oHeight = o->height ();
815
int halfOWidth = oWidth / 2;
816
int halfOHeight = oHeight / 2;
800
*resultX = x - (za.xTranslate *
801
(1.0f - za.newZoom) * o->width ()) - o->width () / 2;
821
*resultX = x - (za.xTranslate * (1.0f - za.newZoom) * oWidth) - halfOWidth;
802
822
*resultX /= za.newZoom;
803
*resultX += o->width () / 2;
823
*resultX += halfOWidth;
804
824
*resultX += o->x1 ();
805
*resultY = y - (za.yTranslate *
806
(1.0f - za.newZoom) * o->height ()) - o->height () / 2;
825
*resultY = y - (za.yTranslate * (1.0f - za.newZoom) * oHeight) - halfOHeight;
807
826
*resultY /= za.newZoom;
808
*resultY += o->height () / 2;
827
*resultY += halfOHeight;
809
828
*resultY += o->y1 ();
814
833
* Returns false if the point isn't on a actively zoomed head
815
834
* or the area is locked. */
817
EZoomScreen::ensureVisibility (int x, int y, int margin)
836
EZoomScreen::ensureVisibility (int x,
819
840
int out = screen->outputDeviceForPoint (x, y);
873
894
int out = screen->outputDeviceForPoint (x1 + (x2 - x1 / 2), y1 + (y2 - y1 / 2));
874
895
CompOutput *o = &screen->outputDevs ().at (out);
876
bool widthOkay = (float)(x2-x1) / (float)o->width () < zooms.at (out).newZoom;
897
bool widthOkay = (float)(x2-x1) / (float)o->width () < zooms.at (out).newZoom;
877
898
bool heightOkay = (float)(y2-y1) / (float)o->height () < zooms.at (out).newZoom;
1240
1266
for (i = 0; i < ci->width * ci->height; ++i)
1242
unsigned long pix = ci->pixels[i];
1243
pixels[i * 4] = pix & 0xff;
1268
pix = ci->pixels[i];
1269
pixels[i * 4] = pix & 0xff;
1244
1270
pixels[(i * 4) + 1] = (pix >> 8) & 0xff;
1245
1271
pixels[(i * 4) + 2] = (pix >> 16) & 0xff;
1246
1272
pixels[(i * 4) + 3] = (pix >> 24) & 0xff;
1265
1291
for (i = 0; i < cursor->width * cursor->height; ++i)
1267
unsigned long pix = 0x00ffffff;
1268
pixels[i * 4] = pix & 0xff;
1294
pixels[i * 4] = pix & 0xff;
1269
1295
pixels[(i * 4) + 1] = (pix >> 8) & 0xff;
1270
1296
pixels[(i * 4) + 2] = (pix >> 16) & 0xff;
1271
1297
pixels[(i * 4) + 3] = (pix >> 24) & 0xff;
1319
1345
/* Force cursor hiding and mouse panning if this output is locked
1320
1346
* and cursor hiding is not enabled and we are syncing the mouse
1322
if (!optionGetScaleMouse () &&
1323
(optionGetZoomMode () == EzoomOptions::ZoomModeSyncMouse &&
1324
optionGetHideOriginalMouse () &&
1325
!zooms.at (out).locked))
1348
if (!optionGetScaleMouse () &&
1349
optionGetZoomMode () == EzoomOptions::ZoomModeSyncMouse &&
1350
optionGetHideOriginalMouse () &&
1351
!zooms.at (out).locked)
1328
1354
if (!cursorInfoSelected)
1330
1356
cursorInfoSelected = true;
1331
XFixesSelectCursorInput (screen->dpy (), screen->root (),
1357
XFixesSelectCursorInput (screen->dpy (), screen->root (),
1332
1358
XFixesDisplayCursorNotifyMask);
1333
1359
updateCursor (&cursor);
1361
1387
int x1 = CompOption::getIntOptionNamed (options, "x1", -1);
1362
1388
int y1 = CompOption::getIntOptionNamed (options, "y1", -1);
1390
if (x1 < 0 || y1 < 0)
1363
1393
int x2 = CompOption::getIntOptionNamed (options, "x2", -1);
1364
1394
int y2 = CompOption::getIntOptionNamed (options, "y2", -1);
1366
bool scale = CompOption::getBoolOptionNamed (options, "scale", false);
1367
bool restrain = CompOption::getBoolOptionNamed (options, "restrain", false);
1369
if (x1 < 0 || y1 < 0)
1378
int out = screen->outputDeviceForPoint (x1, y1);
1380
int width = x2 - x1;
1381
int height = y2 - y1;
1402
bool scale = CompOption::getBoolOptionNamed (options, "scale", false);
1403
bool restrain = CompOption::getBoolOptionNamed (options, "restrain", false);
1404
int out = screen->outputDeviceForPoint (x1, y1);
1405
int width = x2 - x1;
1406
int height = y2 - y1;
1383
1408
setZoomArea (x1, y1, width, height, false);
1384
1409
CompOutput *o = &screen->outputDevs (). at(out);
1386
1411
if (scale && width && height)
1387
setScaleBigger (out, width / static_cast <float> (o->width ()),
1388
height / static_cast <float> (o->height ()));
1412
setScaleBigger (out, width / static_cast <float> (o->width ()),
1413
height / static_cast <float> (o->height ()));
1391
restrainCursor (out);
1416
restrainCursor (out);
1393
1418
toggleFunctions (true);
1437
1462
int height = y2 - y1;
1439
1464
if (scale && width && height)
1440
setScaleBigger (out, width / static_cast <float> (o->width ()),
1441
height / static_cast <float> (o->height ()));
1465
setScaleBigger (out, width / static_cast <float> (o->width ()),
1466
height / static_cast <float> (o->height ()));
1444
1469
restrainCursor (out);
1504
1529
int out = screen->outputDeviceForGeometry (outGeometry);
1505
1530
CompOutput *o = &screen->outputDevs (). at (out);
1506
setScaleBigger (out, width / static_cast <float> (o->width ()),
1507
height / static_cast <float> (o->height ()));
1531
setScaleBigger (out, width / static_cast <float> (o->width ()),
1532
height / static_cast <float> (o->height ()));
1508
1533
setZoomArea (x, y, width, height, false);
1623
int width = w->width () + w->border ().left + w->border ().right;
1624
int height = w->height () + w->border ().top + w->border ().bottom;
1646
int width = w->width () + w->border ().left + w->border ().right;
1647
int height = w->height () + w->border ().top + w->border ().bottom;
1625
1648
int out = screen->outputDeviceForGeometry (w->geometry ());
1626
1649
CompOutput *o = &screen->outputDevs ().at (out);
1628
setScaleBigger (out, width / static_cast <float> (o->width ()),
1629
height / static_cast <float> (o->height ()));
1651
setScaleBigger (out, width / static_cast <float> (o->width ()),
1652
height / static_cast <float> (o->height ()));
1630
1653
areaToWindow (w);
1631
1654
toggleFunctions (true);
1637
1660
EZoomScreen::zoomPan (CompAction *action,
1638
1661
CompAction::State state,
1639
1662
CompOption::Vector options,
1643
1666
panZoom (horizAmount, vertAmount);
1651
1674
EZoomScreen::zoomCenterMouse (CompAction *action,
1652
CompAction::State state,
1653
CompOption::Vector options)
1675
CompAction::State state,
1676
CompOption::Vector options)
1655
1678
int out = screen->outputDeviceForPoint (pointerX, pointerY);
1684
1707
XWindowChanges xwc;
1686
1709
int out = screen->outputDeviceForGeometry (w->geometry ());
1687
xwc.x = w->serverX ();
1688
xwc.y = w->serverY ();
1689
xwc.width = (int) (screen->outputDevs ().at (out).width () *
1690
zooms.at (out).currentZoom -
1691
(int) ((w->border ().left + w->border ().right)));
1710
xwc.x = w->serverX ();
1711
xwc.y = w->serverY ();
1713
xwc.width = (int) (screen->outputDevs ().at (out).width () *
1714
zooms.at (out).currentZoom -
1715
(int) ((w->border ().left + w->border ().right)));
1692
1716
xwc.height = (int) (screen->outputDevs ().at (out).height () *
1693
1717
zooms.at (out).currentZoom -
1694
1718
(int) ((w->border ().top + w->border ().bottom)));
1752
1776
EZoomScreen::terminate (CompAction *action,
1753
CompAction::State state,
1754
CompOption::Vector options)
1777
CompAction::State state,
1778
CompOption::Vector options)
1756
1780
int out = screen->outputDeviceForPoint (pointerX, pointerY);
1813
1837
if (optionGetFocusFitWindow ())
1815
int width = w->width () + w->border ().left + w->border ().right;
1816
int height = w->height () + w->border ().top + w->border ().bottom;
1817
float scale = MAX (width / static_cast <float> (screen->outputDevs ().at(out).width ()),
1839
int width = w->width () + w->border ().left + w->border ().right;
1840
int height = w->height () + w->border ().top + w->border ().bottom;
1841
float scale = MAX (width / static_cast <float> (screen->outputDevs ().at (out).width ()),
1818
1842
height / static_cast <float> (screen->outputDevs ().at (out).height ()));
1820
1844
if (scale > optionGetAutoscaleMin ())