Back to index

unity  6.0.0
Classes | Defines | Functions
test-minimize-handler.cpp File Reference
#include <minimizedwindowhandler.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <unistd.h>
#include <sstream>
#include <poll.h>
#include <cstring>
#include <x11-window-read-transients.h>

Go to the source code of this file.

Classes

class  X11WindowFakeMinimizable

Defines

#define _GNU_SOURCE

Functions

void usage ()
int main (int argc, char **argv)

Define Documentation

#define _GNU_SOURCE

Definition at line 22 of file test-minimize-handler.cpp.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 115 of file test-minimize-handler.cpp.

{
  Display                    *dpy;
  Window                     xid = 0;
  X11WindowFakeMinimizable                  *window;
  X11WindowFakeMinimizable                  *transient = NULL;
  X11WindowFakeMinimizable                  *hasClientLeader = NULL;
  std::string                option = "";
  bool                       shapeExt;
  int                        shapeEvent;
  int                        shapeError;
  bool                       terminate = false;

  if ((argc == 2 && std::string (argv[1]) == "--help") || argc > 3)
  {
    usage ();
    return 1;
  }

  dpy = XOpenDisplay (NULL);

  if (!dpy)
  {
    std::cerr << "Failed to open display ... setting test to passed" << std::endl;
    return 0;
  }

  shapeExt = XShapeQueryExtension (dpy, &shapeEvent, &shapeError);

  if (!shapeExt)
  {
    std::cerr << "No shape extension .. setting test to passed" << std::endl;
    XCloseDisplay (dpy);
    return 0;
  }

  if (argc > 1)
    std::stringstream (argv[1]) >> std::hex >> xid;

  window = new X11WindowFakeMinimizable (dpy, xid);

  if (!xid)
  {
    transient = new X11WindowFakeMinimizable (dpy, 0);
    hasClientLeader = new X11WindowFakeMinimizable (dpy, 0);

    transient->makeTransientFor (window);
    window->setClientLeader (window);
    hasClientLeader->setClientLeader (window);
  }

  std::cout << "[m]inimize [u]nminimize [q]uit?" << std::endl;

  do
  {
    struct pollfd pfd[2];

    pfd[0].fd = ConnectionNumber (dpy);
    pfd[0].events = POLLIN;
    pfd[0].revents = 0;
    pfd[1].fd = STDIN_FILENO;
    pfd[1].events = POLLIN;
    pfd[1].revents = 0;

    poll (pfd, 2, -1);

    while (XPending (dpy))
    {
      XEvent ev;
      XNextEvent (dpy, &ev);
    }

    if (pfd[1].revents == POLLIN)
    {
      char buf[2];

      int ret = read (STDIN_FILENO, buf, 1);

      if (ret != EAGAIN || ret != EWOULDBLOCK)
      {
        buf[1] = '\0';
        if (strncmp (buf, "m", 1) == 0)
        {
          window->minimize ();
          std::cout << "[m]inimize [u]nminimize [q]uit?" << std::endl;
        }
        else if (strncmp (buf, "u", 1) == 0)
        {
          window->unminimize ();
          std::cout << "[m]inimize [u]nminimize [q]uit?" << std::endl;
        }
        else if (strncmp (buf, "q", 1) == 0)
        {
          terminate = true;
          std::cout << "[m]inimize [u]nminimize [q]uit?" << std::endl;
        }
      }
    }

  } while (!terminate);

  delete window;

  XCloseDisplay (dpy);

  return 0;
}

Here is the call graph for this function:

void usage ( )

Definition at line 108 of file test-minimize-handler.cpp.

{
  std::cout << "test-minimize-handler [WINDOW]" << std::endl;
  std::cout << "prompt will be for op, where op is one of " << std::endl;
  std::cout << "[m] minimize, [u] unminimize [q] to quit" << std::endl;
}