1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */ 2 /* 3 * nimf-events.h 4 * This file is part of Nimf. 5 * 6 * Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com> 7 * 8 * Nimf is free software: you can redistribute it and/or modify it 9 * under the terms of the GNU Lesser General Public License as published 10 * by the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * Nimf is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 * See the 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 this program; If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef __NIMF_EVENTS_H__ 23 #define __NIMF_EVENTS_H__ 24 25 #include <glib-object.h> 26 #include "nimf-types.h" 27 28 G_BEGIN_DECLS 29 30 typedef struct _NimfEventKey NimfEventKey; 31 typedef union _NimfEvent NimfEvent; 32 33 /** 34 * NimfEventType: 35 * @NIMF_EVENT_NOTHING: a special code to indicate a null event. 36 * @NIMF_EVENT_KEY_PRESS: a key has been pressed. 37 * @NIMF_EVENT_KEY_RELEASE: a key has been released. 38 */ 39 typedef enum 40 { 41 NIMF_EVENT_NOTHING = -1, 42 NIMF_EVENT_KEY_PRESS = 0, 43 NIMF_EVENT_KEY_RELEASE = 1, 44 } NimfEventType; 45 46 /** 47 * NimfEventKey: 48 * @type: the type of the event (%NIMF_EVENT_KEY_PRESS or 49 * %NIMF_EVENT_KEY_RELEASE). 50 * @state: (type NimfModifierType): a bit-mask representing the state of 51 * the modifier keys (e.g. Control, Shift and Alt) and the pointer 52 * buttons. See #NimfModifierType. 53 * @keyval: the key that was pressed or released. See the 54 * `nimf-key-syms.h` header file for a complete list of Nimf key codes. 55 * @hardware_keycode: the raw code of the key that was pressed or released. 56 * 57 * Describes a key press or key release event. 58 */ 59 struct _NimfEventKey 60 { 61 NimfEventType type; 62 guint32 state; 63 guint32 keyval; 64 guint32 hardware_keycode; 65 }; 66 67 /** 68 * NimfEvent: 69 * @type: a #NimfEventType 70 * @key: a #NimfEventKey 71 * 72 * A #NimfEvent contains a union. 73 */ 74 union _NimfEvent 75 { 76 NimfEventType type; 77 NimfEventKey key; 78 }; 79 80 NimfEvent *nimf_event_new (NimfEventType type); 81 void nimf_event_free (NimfEvent *event); 82 gboolean nimf_event_matches (NimfEvent *event, 83 const NimfKey **keys); 84 guint nimf_event_keycode_to_qwerty_keyval (const NimfEvent *event); 85 86 G_END_DECLS 87 88 #endif /* __NIMF_EVENTS_H__ */ 89