[compiz] Accessibility: mouse guides for Compiz, and forthcoming contributions

MC Return mc.return at gmx.net
Mon Apr 13 10:10:50 PDT 2015


Hey Luca,

I forgot one important thing in my review:
When you manipulate global OpenGL states you need to set them back to 
what they were before after painting - in the ruler-drawing-case you 
change the glBlendFunc, but also glLineWidth without restoring them - 
drawGuides () could look something like this (with added only on output 
with pointer option):

void
ShowmouseScreen::drawGuides (const GLMatrix &transform)
{
     unsigned short       *color       = optionGetGuideColor ();
     const int            x            = mMousePos.x ();
     const int            y            = mMousePos.y ();
     const float          xf           = (float)x;
     const float          yf           = (float)y;
     const int            thickness    = optionGetGuideThickness ();
     const float          r            = 
(float)optionGetGuideEmptyRadius ();

     CompRect workArea;
     const bool restrictGuidesToOutputWithPointer = 
optionGetRestrictGuidesToOutputWithPointer ();

     if (restrictGuidesToOutputWithPointer)
     workArea = screen->getWorkareaForOutput 
(screen->outputDeviceForPoint (x, y));
     else
     workArea = CompRect (0, 0, screen->width (), screen->height ());

     const int workAreaX           = workArea.x ();
     const int workAreaY           = workArea.y ();
     const int workAreaWidth       = workArea.width ();
     const int workAreaHeight      = workArea.height ();
     const int workAreaXPlusWidth  = workAreaX + workAreaWidth;
     const int workAreaYPlusHeight = workAreaY + workAreaHeight;

     /* If the thickness is zero we don't have to draw, but we should
      * still mark the region where the guides should be as damaged --
      * this is useful when thickness has just been changed.
      */
     if (thickness > 0)
     {
     glLineWidth ((GLfloat)thickness);

     GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);

     /* we push in any case as we are going to change the blend function */
     #ifndef USE_GLES
     glPushAttrib (GL_COLOR_BUFFER_BIT | GL_LINE_BIT);
     #endif

     if (!glBlendEnabled)
         glEnable (GL_BLEND);

     glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

     if (restrictGuidesToOutputWithPointer)
     {
         if (yf - r >= (GLfloat)workAreaY)
         drawLine (transform, xf, (GLfloat)workAreaY, xf, yf - r, color);

         if (yf + r <= (GLfloat)workAreaYPlusHeight)
         drawLine (transform, xf, yf + r, xf, 
(GLfloat)workAreaYPlusHeight, color);

         if (xf - r >= (GLfloat)workAreaX)
         drawLine (transform, (GLfloat)workAreaX, yf, xf - r, yf, color);

         if (xf + r <= (GLfloat)workAreaXPlusWidth)
         drawLine (transform, xf + r, yf, (GLfloat)workAreaXPlusWidth, 
yf, color);
     }
     else
     {
         drawLine (transform, xf, (GLfloat)workAreaY, xf, yf - r, color);
         drawLine (transform, xf, yf + r, xf, 
(GLfloat)workAreaYPlusHeight, color);
         drawLine (transform, (GLfloat)workAreaX, yf, xf - r, yf, color);
         drawLine (transform, xf + r, yf, (GLfloat)workAreaXPlusWidth, 
yf, color);
     }

     /* we changed the blend function in any way here */
     #ifndef USE_GLES
     glPopAttrib ();    // restore line width and glBlendFunc/GL_BLEND
     #else
     if (!glBlendEnabled)
         glDisable (GL_BLEND);

     glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
     glLineWidth (1.0f);
     #endif
     }

     cScreen->damageRegion (CompRegion (workAreaX, y - thickness / 2 - 1,
                        workAreaXPlusWidth, thickness + 1));
     cScreen->damageRegion (CompRegion (x - thickness / 2 - 1, workAreaY,
                        thickness + 1, workAreaYPlusHeight));
}

Maybe this saves you some work.

Greetinx,
MC Return
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/compiz/attachments/20150413/5c78c2e1/attachment.html>


More information about the compiz mailing list