1 /* 2 * Copyright (c) 2012, Thomas Jaeger <ThJaeger@gmail.com> 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 #ifndef __HANDLER_H__ 17 #define __HANDLER_H__ 18 #include "gesture.h" 19 #include "grabber.h" 20 #include "actiondb.h" 21 22 class Handler; 23 24 class XState { 25 friend class Handler; 26 public: 27 XState(); 28 29 bool handle(Glib::IOCondition); 30 void handle_enter_leave(XEvent &ev); 31 void handle_event(XEvent &ev); 32 void handle_xi2_event(XIDeviceEvent *event); 33 void handle_raw_motion(XIRawEvent *event); 34 void report_xi2_event(XIDeviceEvent *event, const char *type); 35 36 void fake_core_button(guint b, bool press); 37 void fake_click(guint b); 38 void update_core_mapping(); 39 40 void remove_device(int deviceid); 41 void ungrab(int deviceid); 42 43 bool idle(); 44 void ping(); 45 void bail_out(); 46 void select(); 47 void run_action(RAction act); 48 void queue(sigc::slot<void> f); 49 std::string select_window(); 50 51 static void activate_window(Window w, Time t); 52 static Window get_window(Window w, Atom prop); 53 static Atom get_atom(Window w, Atom prop); 54 static bool has_atom(Window w, Atom prop, Atom value); 55 static void icccm_client_message(Window w, Atom a, Time t); 56 57 Grabber::XiDevice *current_dev; 58 bool in_proximity; 59 bool accepted; 60 std::set<guint> xinput_pressed; 61 guint modifiers; 62 std::map<guint, guint> core_inv_map; 63 private: 64 Window ping_window; 65 Handler *handler; 66 67 static int xErrorHandler(Display *dpy2, XErrorEvent *e); 68 static int xIOErrorHandler(Display *dpy2); 69 int (*oldHandler)(Display *, XErrorEvent *); 70 int (*oldIOHandler)(Display *); 71 std::list<sigc::slot<void> > queued; 72 std::map<int, std::string> opcodes; 73 }; 74 75 class Handler { 76 public: 77 Handler *child; 78 Handler *parent; Handler()79 Handler() : child(NULL), parent(NULL) {} top()80 Handler *top() { 81 if (child) 82 return child->top(); 83 else 84 return this; 85 } 86 motion(RTriple e)87 virtual void motion(RTriple e) {} raw_motion(RTriple e,bool,bool)88 virtual void raw_motion(RTriple e, bool, bool) {} press(guint b,RTriple e)89 virtual void press(guint b, RTriple e) {} release(guint b,RTriple e)90 virtual void release(guint b, RTriple e) {} press_master(guint b,Time t)91 virtual void press_master(guint b, Time t) {} pong()92 virtual void pong() {} 93 void replace_child(Handler *c); init()94 virtual void init() {} ~Handler()95 virtual ~Handler() { 96 if (child) 97 delete child; 98 } 99 virtual std::string name() = 0; 100 virtual Grabber::State grab_mode() = 0; 101 }; 102 103 extern XState *xstate; 104 105 #endif 106