1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 11 сент. 2017 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef UI_TK_UTIL_LSPKEYBOARDHANDLER_H_ 23 #define UI_TK_UTIL_LSPKEYBOARDHANDLER_H_ 24 25 namespace lsp 26 { 27 namespace tk 28 { 29 class LSPKeyboardHandler: public ws::IEventHandler 30 { 31 protected: 32 enum constants_t 33 { 34 RPT_BUF_SIZE = 64 35 }; 36 37 protected: 38 size_t nPause; // Pause before repeat 39 size_t nRepeat; // Repeat 40 size_t nRepeatSize; // Number of elements in repeat buffer 41 ws_event_t sLast; // Last received event 42 ws_code_t vRepeat[RPT_BUF_SIZE]; // Repeat buffer 43 LSPTimer sTimer; // Timer to simulate character repeat 44 45 protected: 46 status_t process_key_down(const ws_event_t *e); 47 status_t process_key_up(const ws_event_t *e); 48 static status_t simulate_repeat(timestamp_t ts, void *arg); 49 void simulate_repeat(timestamp_t ts); 50 51 public: 52 LSPKeyboardHandler(); 53 virtual ~LSPKeyboardHandler(); 54 55 status_t init(LSPDisplay *dpy); 56 57 public: pause_time()58 size_t pause_time() const { return nPause; }; repeat_time()59 size_t repeat_time() const { return nRepeat; }; 60 61 public: 62 void set_pause_time(size_t value); 63 void set_repeat_time(size_t value); 64 65 public: 66 static ws_code_t translate_keypad(ws_code_t code); 67 68 public: 69 // Event handling callbacks 70 virtual status_t handle_event(const ws_event_t *e); 71 72 // Event handling callbacks 73 virtual status_t on_key_down(const ws_event_t *e); 74 75 virtual status_t on_key_press(const ws_event_t *e); 76 77 virtual status_t on_key_up(const ws_event_t *e); 78 }; 79 80 } /* namespace tk */ 81 } /* namespace lsp */ 82 83 #endif /* UI_TK_UTIL_LSPKEYBOARDHANDLER_H_ */ 84