Back to index

nux  3.0.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
nux::XInputWindow Class Reference

#include <XInputWindow.h>

Collaboration diagram for nux::XInputWindow:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 XInputWindow (const char *title, bool take_focus=False, int override_redirect=0)
 ~XInputWindow ()
void EnableStruts (bool enable)
bool StrutsEnabled ()
void EnableOverlayStruts (bool enable)
bool OverlayStrutsEnabled ()
void EnsureInputs ()
void EnableTakeFocus ()
void SetGeometry (const Rect &geo)
 Set the position and size of the window.
void SetGeometry (int x, int y, int width, int height)
 Set the position and size of the window.
Rect const & GetGeometry () const
 Get the window geometry.
Window GetWindow ()
 Get X11 the Window.
void SetInputFocus ()
void Hide ()
void Show ()

Static Public Member Functions

static std::vector< Window >
const & 
NativeHandleList ()

Private Member Functions

std::vector< long int > GetStrutsData ()
void SetStruts ()
void UnsetStruts ()
void SetOverlayStruts ()
void UnsetOverlayStruts ()
void EnableDnd ()
void DisableDnd ()

Private Attributes

bool strutsEnabled_
bool overlayStrutsEnabled_
Window window_
Display * display_
Rect geometry_
bool shown_
bool mapped_
Atom overlay_strut_atom_

Static Private Attributes

static std::vector< Window > native_windows_

Detailed Description

Definition at line 41 of file XInputWindow.h.


Constructor & Destructor Documentation

nux::XInputWindow::XInputWindow ( const char *  title,
bool  take_focus = False,
int  override_redirect = 0 
)

Definition at line 33 of file XInputWindow.cpp.

    : strutsEnabled_(false)
    , overlayStrutsEnabled_(false)
    , display_(GetGraphicsDisplay()->GetX11Display())
    , geometry_(0, 0, 1, 1)
    , shown_(false)
    , mapped_(false)
    , overlay_strut_atom_(0)
  {
    XSetWindowAttributes attrib;

    attrib.override_redirect = override_redirect;
    attrib.event_mask = KeyPressMask        |
                        KeyReleaseMask      |
                        ButtonPressMask     |
                        ButtonReleaseMask   |
                        EnterWindowMask     |
                        LeaveWindowMask     |
                        PointerMotionMask   |
                        ButtonMotionMask    |
                        PropertyChangeMask  |
                        StructureNotifyMask |
                        FocusChangeMask;

    window_ = XCreateWindow(display_, XDefaultRootWindow(display_),
                            geometry_.x, geometry_.y,
                            geometry_.width, geometry_.height, 0,
                            CopyFromParent, InputOutput, CopyFromParent,
                            CWOverrideRedirect | CWEventMask, &attrib);

    native_windows_.push_back(window_);

    Atom data[32];
    int     i = 0;
    data[i++] = XInternAtom(display_, "_NET_WM_STATE_STICKY", 0);
    data[i++] = XInternAtom(display_, "_NET_WM_STATE_SKIP_TASKBAR", 0);
    data[i++] = XInternAtom(display_, "_NET_WM_STATE_SKIP_PAGER", 0);

    XChangeProperty(display_, window_,
                    XInternAtom(display_, "_NET_WM_STATE", 0),
                    XA_ATOM, 32, PropModeReplace,
                    (unsigned char *) data, i);

    Atom type[1];
    type[0] = XInternAtom(display_, "_NET_WM_WINDOW_TYPE_DOCK", 0);
    XChangeProperty(display_, window_,
                    XInternAtom(display_, "_NET_WM_WINDOW_TYPE", 0),
                    XA_ATOM, 32, PropModeReplace,
                    (unsigned char *) type, 1);

    XStoreName(display_, window_, title);
    EnsureInputs();

    if (take_focus)
      EnableTakeFocus();

    EnableDnd();
  }

Here is the call graph for this function:

Definition at line 94 of file XInputWindow.cpp.

  {
    native_windows_.erase(std::find(native_windows_.begin(), native_windows_.end(), window_));
    XDestroyWindow(display_, window_);
  }

Member Function Documentation

void nux::XInputWindow::DisableDnd ( ) [private]

Definition at line 321 of file XInputWindow.cpp.

  {
    XDeleteProperty(display_, window_,
                    XInternAtom(display_, "XdndAware", false));
  }
void nux::XInputWindow::EnableDnd ( ) [private]

Definition at line 312 of file XInputWindow.cpp.

  {
    int version = 5;
    XChangeProperty(display_, window_,
                    XInternAtom(display_, "XdndAware", false),
                    XA_ATOM, 32, PropModeReplace,
                    (unsigned char *) &version, 1);
  }

Here is the caller graph for this function:

Definition at line 263 of file XInputWindow.cpp.

  {
    if (overlayStrutsEnabled_ == enable)
      return;

    if (!overlay_strut_atom_)
      overlay_strut_atom_ = XInternAtom(display_, "_COMPIZ_NET_OVERLAY_STRUT", 0);

    overlayStrutsEnabled_ = enable;
    if (enable)
      SetOverlayStruts();
    else
      UnsetOverlayStruts();
  }

Here is the call graph for this function:

void nux::XInputWindow::EnableStruts ( bool  enable)

Definition at line 246 of file XInputWindow.cpp.

  {
    if (strutsEnabled_ == enable)
      return;

    strutsEnabled_ = enable;
    if (enable)
      SetStruts();
    else
      UnsetStruts();
  }

Here is the call graph for this function:

Definition at line 299 of file XInputWindow.cpp.

  {
    Atom wmTakeFocus = XInternAtom(display_, "WM_TAKE_FOCUS", False);
    XWMHints* wmHints = NULL;

    wmHints = (XWMHints*) calloc(1, sizeof(XWMHints));
    wmHints->flags |= InputHint;
    wmHints->input = False;
    XSetWMHints(display_, window_, wmHints);
    free(wmHints);
    XSetWMProtocols(display_, window_, &wmTakeFocus, 1);
  }

Here is the caller graph for this function:

Definition at line 283 of file XInputWindow.cpp.

  {
    XSelectInput(display_, window_,
                  KeyPressMask        |
                  KeyReleaseMask      |
                  ButtonPressMask     |
                  ButtonReleaseMask   |
                  EnterWindowMask     |
                  LeaveWindowMask     |
                  PointerMotionMask   |
                  ButtonMotionMask    |
                  PropertyChangeMask  |
                  StructureNotifyMask |
                  FocusChangeMask);
  }

Here is the caller graph for this function:

Get the window geometry.

Definition at line 350 of file XInputWindow.cpp.

  {
    return geometry_;
  }
std::vector< long int > nux::XInputWindow::GetStrutsData ( ) [private]

Definition at line 106 of file XInputWindow.cpp.

  {
    int n_info;
    XineramaScreenInfo *info = XineramaQueryScreens(display_, &n_info);
    Region             screen_region;
    Region             total_screen_region = XCreateRegion();
    Region             input_window_region = XCreateRegion();
    Region             intersection = XCreateRegion();
    XRectangle         monitor;
    XRectangle         tmp_rect;
    int largestWidth = 0, largestHeight = 0;
    int screenWidth, screenHeight;
    std::vector<long int> data(12, 0);

    /* Find the screen that this region intersects */
    tmp_rect.x = geometry_.x;
    tmp_rect.y = geometry_.y;
    tmp_rect.width = geometry_.width;
    tmp_rect.height = geometry_.height;

    XUnionRectWithRegion(&tmp_rect, input_window_region, input_window_region);

    /* If there is no Xinerama data available just use the geometry we have */
    if (!info)
    {
      monitor = tmp_rect;
      n_info = 0;
    }

    for (int i = 0; i < n_info; i++)
    {
      tmp_rect.x = info[i].x_org;
      tmp_rect.y = info[i].y_org;
      tmp_rect.width = info[i].width;
      tmp_rect.height = info[i].height;

      screen_region = XCreateRegion();

      XUnionRectWithRegion(&tmp_rect, screen_region, screen_region);
      XUnionRegion(screen_region, total_screen_region, total_screen_region);
      XIntersectRegion(screen_region, input_window_region, intersection);

      if (!XEmptyRegion(intersection))
      {
        int width = intersection->extents.x2 - intersection->extents.x1;
        int height = intersection->extents.y2 - intersection->extents.y1;

        if ((width * height) > (largestWidth * largestHeight))
        {
          largestWidth = width;
          largestHeight = height;

          monitor.x      = info[i].x_org;
          monitor.y      = info[i].y_org;
          monitor.width  = info[i].width;
          monitor.height = info[i].height;
        }
      }

      XDestroyRegion(screen_region);
    }

    screenWidth = total_screen_region->extents.x2 - total_screen_region->extents.x1;
    screenHeight = total_screen_region->extents.y2 - total_screen_region->extents.y1;

    XDestroyRegion(input_window_region);
    XDestroyRegion(intersection);
    XDestroyRegion(total_screen_region);

    if (info)
      XFree(info);

    if (geometry_.width > geometry_.height)
    {
      if (geometry_.y - monitor.y < monitor.height / 2)
      {
        /* top */
        data[2] = geometry_.y + geometry_.height;
        data[8] = geometry_.x;
        data[9] = geometry_.x + geometry_.width - 1;
      }
      else
      {
        /* bottom */
        data[3] = (screenHeight - 1) - geometry_.y;
        data[10] = geometry_.x;
        data[11] = geometry_.x + geometry_.width - 1;
      }
    }
    else
    {
      if (geometry_.x - monitor.x < monitor.width / 2)
      {
        /* left */
        data[0] = geometry_.x + geometry_.width;
        data[4] = geometry_.y;
        data[5] = geometry_.y + geometry_.height - 1;
      }
      else
      {
        /* right */
        data[1] = (screenWidth - 1) - geometry_.y;
        data[6] = geometry_.y;
        data[7] = geometry_.y + geometry_.height - 1;
      }
    }

    return data;
  }

Here is the caller graph for this function:

Get X11 the Window.

Definition at line 355 of file XInputWindow.cpp.

  {
    return window_;
  }

Definition at line 365 of file XInputWindow.cpp.

  {
    XMoveResizeWindow(display_, window_,
                      -100 - geometry_.width,
                      -100 - geometry_.height,
                      geometry_.width,
                      geometry_.height);
    shown_ = false;
  }
std::vector< Window > const & nux::XInputWindow::NativeHandleList ( ) [static]

Definition at line 101 of file XInputWindow.cpp.

  {
    return native_windows_;
  }

Definition at line 278 of file XInputWindow.cpp.

  {
    return overlayStrutsEnabled_;
  }
void nux::XInputWindow::SetGeometry ( const Rect geo)

Set the position and size of the window.

Definition at line 328 of file XInputWindow.cpp.

  {
    geometry_ = geo;

    if (shown_)
      XMoveResizeWindow(display_, window_,
                        geo.x, geo.y, geo.width, geo.height);
    EnsureInputs();

    if (strutsEnabled_)
      SetStruts();
    if (overlayStrutsEnabled_)
      SetOverlayStruts();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::XInputWindow::SetGeometry ( int  x,
int  y,
int  width,
int  height 
)

Set the position and size of the window.

Definition at line 344 of file XInputWindow.cpp.

  {
    SetGeometry(Rect(x, y, width, height));
  }

Here is the call graph for this function:

Definition at line 360 of file XInputWindow.cpp.

  {
    XSetInputFocus(display_, window_, RevertToParent, CurrentTime);
  }

Definition at line 232 of file XInputWindow.cpp.

  {
    std::vector<long int> data(GetStrutsData());

    XChangeProperty(display_, window_, overlay_strut_atom_,
                    XA_CARDINAL, 32, PropModeReplace,
                    (unsigned char*) &data[0], 12);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::XInputWindow::SetStruts ( ) [private]

Definition at line 216 of file XInputWindow.cpp.

  {
    std::vector<long int> data(GetStrutsData());

    XChangeProperty(display_, window_,
                    XInternAtom(display_, "_NET_WM_STRUT_PARTIAL", 0),
                    XA_CARDINAL, 32, PropModeReplace,
                    (unsigned char*) &data[0], 12);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 375 of file XInputWindow.cpp.

  {
    shown_ = true;

    if (!mapped_)
    {
      XMapRaised(display_, window_);
      mapped_ = true;

      XEvent xevent;
      while (XCheckTypedWindowEvent(display_, window_, MapNotify, &xevent));
      XSetInputFocus(display_, window_, RevertToParent, CurrentTime);

    }
    XMoveResizeWindow(display_, window_,
                      geometry_.x, geometry_.y,
                      geometry_.width, geometry_.height);
  }

Definition at line 258 of file XInputWindow.cpp.

  {
    return strutsEnabled_;
  }

Definition at line 241 of file XInputWindow.cpp.

  {
    XDeleteProperty(display_, window_, overlay_strut_atom_);
  }

Here is the caller graph for this function:

void nux::XInputWindow::UnsetStruts ( ) [private]

Definition at line 226 of file XInputWindow.cpp.

  {
    XDeleteProperty(display_, window_,
                    XInternAtom(display_, "_NET_WM_STRUT_PARTIAL", 0));
  }

Here is the caller graph for this function:


Member Data Documentation

Display* nux::XInputWindow::display_ [private]

Definition at line 96 of file XInputWindow.h.

Definition at line 97 of file XInputWindow.h.

Definition at line 99 of file XInputWindow.h.

std::vector< Window > nux::XInputWindow::native_windows_ [static, private]

Definition at line 91 of file XInputWindow.h.

Definition at line 100 of file XInputWindow.h.

Definition at line 94 of file XInputWindow.h.

bool nux::XInputWindow::shown_ [private]

Definition at line 98 of file XInputWindow.h.

Definition at line 93 of file XInputWindow.h.

Window nux::XInputWindow::window_ [private]

Definition at line 95 of file XInputWindow.h.


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