1 /* 2 * Copyright 2011 kubtek <kubtek@mail.com> 3 * 4 * This file is part of StarDict. 5 * 6 * StarDict is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * StarDict is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with StarDict. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef _X11_ISKEYSPRESSED_HPP_ 21 #define _X11_ISKEYSPRESSED_HPP_ 22 23 #include <gdk/gdkx.h> 24 #include <X11/keysym.h> 25 #include <gtk/gtk.h> 26 #include <memory> 27 #include "iskeyspressed.h" 28 29 typedef enum { SYM, CODE, BUTTON } KeyType_t; 30 typedef enum { PRESS, RELEASE } EventType_t; 31 32 struct Keys_t { 33 34 KeyType_t type; 35 36 EventType_t event_type; 37 38 union { 39 KeySym sym; 40 KeyCode code; 41 unsigned int button; 42 } key; 43 44 unsigned int modifier; 45 46 Keys_t(KeyType_t t=SYM, EventType_t et=PRESS, KeySym s=0, unsigned int m=0) : typeKeys_t47 type(t), event_type(et), modifier(m) 48 { 49 key.sym=s; 50 } 51 }; 52 53 class x11_hotkeys : public hotkeys { 54 public: 55 x11_hotkeys(GtkWindow *win_); 56 ~x11_hotkeys(); 57 const std::list<std::string>& possible_combs(); 58 void set_comb(const std::string& comb); 59 bool is_pressed(); 60 private: 61 std::string comb; 62 GtkWindow *win; 63 bool pressed; 64 Keys_t grab_key; 65 std::list<std::string> possb_combs; 66 std::auto_ptr<hotkeys> def_hot_keys;/*I don't want to duplicate work, 67 so hold here pointer to default 68 object of this class*/ 69 Display *display; 70 static unsigned int numlock_mask, scrolllock_mask, capslock_mask; 71 72 static GdkFilterReturn key_filter(GdkXEvent *gdk_xevent, 73 GdkEvent *event, x11_hotkeys *th); 74 void ungrabkeys(void); 75 static void get_offending_modifiers(Display * dpy); 76 static void my_grab_key(Display * dpy, KeyCode keycode, 77 unsigned int modifier, Window win); 78 static void my_grab_button(Display * dpy, unsigned int button, 79 unsigned int modifier, Window win); 80 static bool grab_keys(Display *dpy, Keys_t keys[], int nb_keys); 81 }; 82 83 #endif//!_X11_ISKEYSPRESSED_HPP_ 84