From 19fe7868fe82cf0e2fb2264f4e893f6158f373ea Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 23 Aug 2011 23:48:11 +0800 Subject: Added input remover test (bzr r1410.5.6) --- tests/test-input-remover/CMakeLists.txt | 20 +++ tests/test-input-remover/test-input-remover.cpp | 184 ++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 tests/test-input-remover/CMakeLists.txt create mode 100644 tests/test-input-remover/test-input-remover.cpp (limited to 'tests/test-input-remover') diff --git a/tests/test-input-remover/CMakeLists.txt b/tests/test-input-remover/CMakeLists.txt new file mode 100644 index 000000000..b05e7991a --- /dev/null +++ b/tests/test-input-remover/CMakeLists.txt @@ -0,0 +1,20 @@ +project (test-input-remover) + +include (FindPkgConfig) + +pkg_check_modules (COMPIZ_TEST_INPUT_REMOVER REQUIRED x11 xext) + +if (COMPIZ_TEST_INPUT_REMOVER_FOUND) + include_directories (${COMPIZ_TEST_INPUT_REMOVER_INCLUDE_DIRS} + ../../src) + + link_directories (${COMPIZ_TEST_INPUT_REMOVER_LINK_DIRS}) + + add_executable (test-input-remover + test-input-remover.cpp + ../../plugins/unityshell/src/inputremover.cpp) + + target_link_libraries (test-input-remover + ${COMPIZ_TEST_INPUT_REMOVER_LIBRARIES}) + +endif (COMPIZ_TEST_INPUT_REMOVER_FOUND) diff --git a/tests/test-input-remover/test-input-remover.cpp b/tests/test-input-remover/test-input-remover.cpp new file mode 100644 index 000000000..db72c25c1 --- /dev/null +++ b/tests/test-input-remover/test-input-remover.cpp @@ -0,0 +1,184 @@ +/* + * Copyright (C) 2011 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authored By: + * Sam Spilsbury + */ + +#include +#include +#include +#include +#include +#include +#include + +void usage () +{ + std::cout << "test-input-remover [WINDOW] [TIME]" << std::endl; +} + +bool +print_rects (Display *dpy, Window xid) +{ + XRectangle *rects; + int count = 0, ordering; + int x, y; + unsigned int width, height, border, depth; + Window root; + + XGetGeometry (dpy, xid, &root, &x, &y, &width, &height, &border, &depth); + + rects = XShapeGetRectangles (dpy, xid, ShapeInput, + &count, &ordering); + + if (count == 0) + std::cout << "No Input Shape Set" << std::endl; + + /* 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))) + { + std::cout << "No Input Shape Defined" << std::endl; + } + + for (int i = 0; i < count; i++) + { + std::cout << "Rect - " << rects[i].x << ", " << rects[i].y << ", " << rects[i].width << ", " << rects[i].height << std::endl; + } + + if (rects) + XFree (rects); + + return count > 0; +} + +int main (int argc, char **argv) +{ + Display *dpy; + Window xid; + int time = 0; + compiz::WindowInputRemover *remover; + bool shapeExt; + int shapeEvent; + int shapeError; + + 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; + else + { + XSetWindowAttributes attrib; + XEvent e; + + xid = XCreateWindow (dpy, DefaultRootWindow (dpy), 0, 0, 100, 100, 0, + DefaultDepth (dpy, DefaultScreen (dpy)), InputOutput, + DefaultVisual (dpy, DefaultScreen (dpy)), 0, &attrib); + + XSelectInput (dpy, xid, ExposureMask | StructureNotifyMask); + XMapRaised (dpy, xid); + while (1) + { + XNextEvent (dpy, &e); + bool exposed = false; + + switch (e.type) + { + case Expose: + std::cout << "Exposure event" << std::endl; + if (e.xexpose.window == xid) + exposed = true; + break; + default: + break; + } + + if (exposed) + break; + } + } + + if (argc == 3) + std::stringstream (argv[2]) >> std::dec >> time; + + remover = new compiz::WindowInputRemover (dpy, xid); + if (!remover) + return 1; + + print_rects (dpy, xid); + + std::cout << "Saving input shape of 0x" << std::hex << xid << std::dec << std::endl; + remover->save (); + std::cout << "Removing input shape of 0x" << std::hex << xid << std::dec << std::endl; + remover->remove (); + XSync (dpy, false); + + std::cout << "Getting input rects for 0x" << std::hex << xid << std::dec << std::endl; + if (print_rects (dpy, xid)) + { + std::cout << "Error! Window still has rects after shape was removed!" << std::endl; + delete remover; + XCloseDisplay (dpy); + return 1; + } + + std::cout << "Waiting " << std::dec << time << " seconds" << std::endl; + sleep (time); + std::cout << "Restoring input shape of 0x" << std::hex << xid << std::dec << std::endl; + remover->restore (); + XSync (dpy, false); + + if (!print_rects (dpy, xid)) + { + std::cout << "Error! Failed to restore input shape for 0x" << std::hex << xid << std::dec << std::endl; + delete remover; + XCloseDisplay (dpy); + return 1; + } + + delete remover; + + XCloseDisplay (dpy); + + return 0; +} -- cgit v1.2.3