Back to index

unity  6.0.0
Public Types | Public Member Functions | Private Member Functions | Private Attributes
compiz::WindowInputRemover Class Reference

#include <inputremover.h>

Inheritance diagram for compiz::WindowInputRemover:
Inheritance graph
[legend]
Collaboration diagram for compiz::WindowInputRemover:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::shared_ptr
< WindowInputRemoverInterface
Ptr

Public Member Functions

 WindowInputRemover (Display *, Window xid)
 ~WindowInputRemover ()
bool save ()
bool remove ()
bool restore ()

Private Member Functions

bool saveInput ()
bool removeInput ()
bool restoreInput ()
void sendShapeNotify ()

Private Attributes

Display * mDpy
Window mShapeWindow
unsigned long mShapeMask
XRectangle * mInputRects
int mNInputRects
int mInputRectOrdering
XRectangle * mBoundingRects
int mNBoundingRects
int mBoundingRectOrdering
bool mRemoved
int mShapeEvent
int mShapeError

Detailed Description

Definition at line 52 of file inputremover.h.


Member Typedef Documentation

Definition at line 37 of file inputremover.h.


Constructor & Destructor Documentation

compiz::WindowInputRemover::WindowInputRemover ( Display *  dpy,
Window  xid 
)

Definition at line 31 of file inputremover.cpp.

                                                            :
  mDpy (dpy),
  mShapeWindow (xid),
  mShapeMask (0),
  mInputRects (NULL),
  mNInputRects (0),
  mInputRectOrdering (0),
  mBoundingRects (NULL),
  mNBoundingRects (0),
  mBoundingRectOrdering (0),
  mRemoved (false)
{
  /* FIXME: roundtrip */
  XShapeQueryExtension (mDpy, &mShapeEvent, &mShapeError);
}

Definition at line 48 of file inputremover.cpp.

{
  if (mRemoved)
    restore ();
}

Member Function Documentation

bool compiz::WindowInputRemoverInterface::remove ( ) [inline, inherited]

Definition at line 40 of file inputremover.h.

{ return removeInput (); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool compiz::WindowInputRemover::removeInput ( ) [private, virtual]

Implements compiz::WindowInputRemoverInterface.

Definition at line 274 of file inputremover.cpp.

{
  if (!mNInputRects)
    if (!save ())
      return false;

  XShapeSelectInput (mDpy, mShapeWindow, NoEventMask);

  XShapeCombineRectangles (mDpy, mShapeWindow, ShapeInput, 0, 0,
                           NULL, 0, ShapeSet, 0);
  XShapeCombineRectangles (mDpy, mShapeWindow, ShapeBounding, 0, 0,
                           NULL, 0, ShapeSet, 0);

  XShapeSelectInput (mDpy, mShapeWindow, mShapeMask);

  mRemoved = true;

  sendShapeNotify ();

  return true;
}
bool compiz::WindowInputRemoverInterface::restore ( ) [inline, inherited]

Definition at line 41 of file inputremover.h.

{ return restoreInput (); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool compiz::WindowInputRemover::restoreInput ( ) [private, virtual]

Implements compiz::WindowInputRemoverInterface.

Definition at line 297 of file inputremover.cpp.

{
  XShapeSelectInput (mDpy, mShapeWindow, NoEventMask);

  if (mRemoved)
  {
    if (mNInputRects)
    {
      XShapeCombineRectangles (mDpy, mShapeWindow, ShapeInput, 0, 0,
                              mInputRects, mNInputRects,
                              ShapeSet, mInputRectOrdering);

    }
    else
    {
      XShapeCombineMask (mDpy, mShapeWindow, ShapeInput,
                      0, 0, None, ShapeSet);
    }

    if (mInputRects)
    {
      XFree (mInputRects);
      mInputRects = NULL;
      mNInputRects = 0;
    }

    if (mNBoundingRects)
    {
      XShapeCombineRectangles (mDpy, mShapeWindow, ShapeBounding, 0, 0,
                         mBoundingRects, mNBoundingRects,
                         ShapeSet, mBoundingRectOrdering);
    }
    else
    {
      XShapeCombineMask (mDpy, mShapeWindow, ShapeBounding,
                   0, 0, None, ShapeSet);
    }

    if (mBoundingRects)
    {
      XFree (mBoundingRects);
      mBoundingRects = NULL;
      mNBoundingRects = 0;
    }
  }

  XShapeSelectInput (mDpy, mShapeWindow, mShapeMask);

  mRemoved = false;

  sendShapeNotify ();

  return true;
}
bool compiz::WindowInputRemoverInterface::save ( ) [inline, inherited]

Definition at line 39 of file inputremover.h.

{ return saveInput (); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool compiz::WindowInputRemover::saveInput ( ) [private, virtual]

Implements compiz::WindowInputRemoverInterface.

Definition at line 210 of file inputremover.cpp.

{
  XRectangle   *rects;
  int          count = 0, ordering;
  Window       root;
  int          x, y;
  unsigned int width, height, border, depth;

  /* FIXME: There should be a generic GetGeometry request we can
     * use here in order to avoid a round-trip */
  if (!XGetGeometry (mDpy, mShapeWindow, &root, &x, &y, &width, &height,
                     &border, &depth))
  {
    return false;
  }

  rects = XShapeGetRectangles (mDpy, mShapeWindow, ShapeInput,
                               &count, &ordering);

  /* check if the returned shape exactly matches the window shape -
   * if that is true, the window currently has no set input shape */
  if ((count == 1) &&
      (rects[0].x == -((int) border)) &&
      (rects[0].y == -((int) border)) &&
      (rects[0].width == (width + border)) &&
      (rects[0].height == (height + border)))
  {
    count = 0;
  }

  if (mInputRects)
    XFree (mInputRects);

  mInputRects = rects;
  mNInputRects = count;
  mInputRectOrdering = ordering;

  rects = XShapeGetRectangles (mDpy, mShapeWindow, ShapeBounding,
                               &count, &ordering);

  /* check if the returned shape exactly matches the window shape -
   * if that is true, the window currently has no set bounding shape */
  if ((count == 1) &&
      (rects[0].x == -((int) border)) &&
      (rects[0].y == -((int) border)) &&
      (rects[0].width == (width + border)) &&
      (rects[0].height == (height + border)))
  {
    count = 0;
  }

  if (mBoundingRects)
    XFree (mBoundingRects);

  mBoundingRects = rects;
  mNBoundingRects = count;
  mBoundingRectOrdering = ordering;

  mShapeMask = XShapeInputSelected (mDpy, mShapeWindow);

  return true;
}

Definition at line 55 of file inputremover.cpp.

{
  /* Send a synthetic ShapeNotify event to the client and parent window
   * since we ignored shape events when setting visibility
   * in order to avoid cycling in the shape handling code -
   * ignore the sent shape notify event since that will
   * be send_event = true
   *
   * NB: We must send ShapeNotify events to both the client
   * window and to the root window with SubstructureRedirectMask
   * since NoEventMask will only deliver the event to the client
   * (see xserver/dix/events.c on the handling of CantBeFiltered
   *  messages)
   *
   * NB: This code will break if you don't have this patch on the
   * X Server since XSendEvent for non-core events are broken.
   *
   * http://lists.x.org/archives/xorg-devel/2011-September/024996.html
   */

  XShapeEvent  xsev;
  XEvent       *xev = (XEvent *) &xsev;
  Window       rootReturn, parentReturn;
  Window       childReturn;
  Window       *children;
  int          x, y, xOffset, yOffset;
  unsigned int width, height, depth, border, nchildren;

  memset (&xsev, 0, sizeof (XShapeEvent));

  /* XXX: libXShape is weird and range checks the event
   * type on event_to_wire so ensure that we are setting
   * the event type on the right range */
  xsev.type = (mShapeEvent - ShapeNotify) & 0x7f;
  /* We must explicitly fill in these values to avoid padding errors */
  xsev.serial = 0L;
  xsev.send_event = TRUE;
  xsev.display = mDpy;
  xsev.window = mShapeWindow;

  if (!mRemoved)
  {
    /* FIXME: these roundtrips suck */
    if (!XGetGeometry (mDpy, mShapeWindow, &rootReturn, &x, &y, &width, &height, &depth, &border))
      return;
    if (!XQueryTree (mDpy, mShapeWindow, &rootReturn, &parentReturn, &children, &nchildren))
      return;

    /* We need to translate the co-ordinates of the origin to the
     * client window to its parent to find out the offset of its
     * position so that we can subtract that from the final bounding
     * rect of the window shape according to the Shape extension
     * specification */

    XTranslateCoordinates (mDpy, mShapeWindow, parentReturn, 0, 0,
                        &xOffset, &yOffset, &childReturn);

    xsev.kind = ShapeBounding;

    /* Calculate extents of the bounding shape */
    if (!mNBoundingRects)
    {
      /* No set input shape, we must use the client geometry */
      xsev.x = x - xOffset;
      xsev.y = y - yOffset;
      xsev.width = width; 
      xsev.height = height;
      xsev.shaped = false;
    }
    else
    {
      Region      boundingRegion = XCreateRegion ();

      for (int i = 0; i < mNBoundingRects; i++)
        XUnionRectWithRegion (&(mBoundingRects[i]), boundingRegion, boundingRegion);

      xsev.x = boundingRegion->extents.x1 - xOffset;
      xsev.y = boundingRegion->extents.y1 - yOffset;
      xsev.width = boundingRegion->extents.x2 - boundingRegion->extents.x1;
      xsev.height = boundingRegion->extents.y2 - boundingRegion->extents.y1;
      xsev.shaped = true;

      XDestroyRegion (boundingRegion);
    }

    xsev.time = CurrentTime;

    XSendEvent (mDpy, mShapeWindow, FALSE, NoEventMask, xev);
    XSendEvent (mDpy, parentReturn, FALSE, NoEventMask, xev);
    xsev.kind = ShapeInput;

    /* Calculate extents of the bounding shape */
    if (!mNInputRects)
    {
      /* No set input shape, we must use the client geometry */
      xsev.x = x - xOffset;
      xsev.y = y - yOffset;
      xsev.width = width; 
      xsev.height = height;
      xsev.shaped = false;
    }
    else
    {
      Region      inputRegion = XCreateRegion ();

      for (int i = 0; i < mNInputRects; i++)
        XUnionRectWithRegion (&(mInputRects[i]), inputRegion, inputRegion);

      xsev.x = inputRegion->extents.x1 - xOffset;
      xsev.y = inputRegion->extents.y1 - yOffset;
      xsev.width = inputRegion->extents.x2 - inputRegion->extents.x1;
      xsev.height = inputRegion->extents.y2 - inputRegion->extents.y1;
      xsev.shaped = true;

      XDestroyRegion (inputRegion);
    }

    xsev.time = CurrentTime;

    XSendEvent (mDpy, mShapeWindow, FALSE, NoEventMask, xev);
    XSendEvent (mDpy, parentReturn, FALSE, NoEventMask, xev);

    if (children)
      XFree (children);
  }
  else
  {
    XQueryTree (mDpy, mShapeWindow, &rootReturn, &parentReturn, &children, &nchildren);

    xsev.kind = ShapeBounding;

    xsev.x = 0;
    xsev.y = 0;
    xsev.width = 0;
    xsev.height = 0;
    xsev.shaped = true;

    xsev.time = CurrentTime;
    XSendEvent (mDpy, mShapeWindow, FALSE, NoEventMask, xev);
    XSendEvent (mDpy, parentReturn, FALSE, NoEventMask, xev);

    xsev.kind = ShapeInput;

    /* Both ShapeBounding and ShapeInput are null */

    xsev.time = CurrentTime;

    XSendEvent (mDpy, mShapeWindow, FALSE, NoEventMask, xev);
    XSendEvent (mDpy, parentReturn, FALSE, NoEventMask, xev);

  }

}

Member Data Documentation

Definition at line 78 of file inputremover.h.

Definition at line 76 of file inputremover.h.

Definition at line 68 of file inputremover.h.

Definition at line 74 of file inputremover.h.

Definition at line 72 of file inputremover.h.

Definition at line 77 of file inputremover.h.

Definition at line 73 of file inputremover.h.

Definition at line 79 of file inputremover.h.

Definition at line 82 of file inputremover.h.

Definition at line 81 of file inputremover.h.

unsigned long compiz::WindowInputRemover::mShapeMask [private]

Definition at line 70 of file inputremover.h.

Definition at line 69 of file inputremover.h.


The documentation for this class was generated from the following files: