Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <geis/geis.h>
- #include <iostream>
- #include <stdexcept>
- #include <X11/Xutil.h>
- using namespace std;
- class GeisTest
- {
- public:
- // Sets up a GEIS instance
- GeisTest()
- {
- GeisXcbWinInfo xcbWinInfo;
- xcbWinInfo.display_name = NULL;
- xcbWinInfo.screenp = NULL;
- xcbWinInfo.window_id = XRootWindow(XOpenDisplay(NULL), 0);
- GeisWinInfo winInfo;
- winInfo.win_type = GEIS_XCB_FULL_WINDOW;
- winInfo.win_info = &xcbWinInfo;
- if (geis_init(&winInfo, &geisInstance) != GEIS_STATUS_SUCCESS)
- {
- throw runtime_error("error initializing geis");
- }
- gestureFuncs.added = GeisTest::gestureAdded;
- gestureFuncs.removed = GeisTest::gestureRemoved;
- gestureFuncs.start = GeisTest::gestureStart;
- gestureFuncs.update = GeisTest::gestureUpdate;
- gestureFuncs.finish = GeisTest::gestureFinish;
- if (geis_subscribe(geisInstance,
- GEIS_ALL_INPUT_DEVICES,
- GEIS_ALL_GESTURES,
- &gestureFuncs,
- this) != GEIS_STATUS_SUCCESS)
- {
- throw runtime_error("error creating geis subscription");
- }
- }
- // Tears down a GEIS instance
- ~GeisTest()
- {
- geis_finish(geisInstance);
- }
- // an example of how to integrate GEIS into an event loop
- int
- run()
- {
- int fd = -1;
- geis_configuration_get_value(geisInstance, GEIS_CONFIG_UNIX_FD, &fd);
- for(;;)
- {
- fd_set read_fds;
- FD_ZERO(&read_fds);
- FD_SET(0, &read_fds);
- FD_SET(fd, &read_fds);
- int sstat = select(fd+1, &read_fds, NULL, NULL, NULL);
- if (sstat < 0)
- throw runtime_error("error in select");
- if (FD_ISSET(0, &read_fds))
- break;
- if (FD_ISSET(fd, &read_fds))
- geis_event_dispatch(geisInstance);
- }
- return 0;
- }
- static void
- gestureAdded(void* cookie, GeisGestureType type,
- GeisGestureId id, GeisSize numAttrs, GeisGestureAttr* attrs)
- {
- cout << "Gesture added\n";
- }
- static void
- gestureRemoved(void* cookie, GeisGestureType type,
- GeisGestureId id, GeisSize numAttrs, GeisGestureAttr* attrs)
- {
- cout << "Gesture removed\n";
- }
- static void
- gestureStart(void* cookie, GeisGestureType type,
- GeisGestureId id, GeisSize numAttrs, GeisGestureAttr* attrs)
- {
- cout << "Gesture start\n";
- }
- static void
- gestureUpdate(void* cookie, GeisGestureType type,
- GeisGestureId id, GeisSize numAttrs, GeisGestureAttr* attrs)
- {
- cout << "Gesture update\n";
- }
- static void
- gestureFinish(void* cookie, GeisGestureType type,
- GeisGestureId id, GeisSize numAttrs, GeisGestureAttr* attrs)
- {
- cout << "Gesture finish\n";
- }
- private:
- GeisInstance geisInstance;
- GeisGestureFuncs gestureFuncs;
- };
- int
- main(int, char*[])
- {
- try
- {
- return GeisTest().run();
- }
- catch (exception& ex)
- {
- cerr << ex.what() << "\n";
- return 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement