forked from bfabiszewski/kterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.h
107 lines (95 loc) · 3.29 KB
/
keyboard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* keyboard.c
*
* This file is part of kterm
*
* Copyright(C) 2016 Bartek Fabiszewski (www.fabiszewski.net)
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef keyboard_h
#define keyboard_h
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
/**
* Keyboard layout variants
*/
typedef enum {
KBT_DEFAULT = 0,
KBT_SHIFT,
KBT_MOD1,
KBT_MOD2,
KBT_MOD3,
KBT_COUNT
} KBtype;
/**
* Lookup table name to keyval
*/
struct kbsymlookup {
const guint keyval;
const gchar *name;
};
/**
* Lookup table name to gdk modifier type
*/
struct kbmodlookup {
const GdkModifierType modifier;
const gchar *name;
const gchar *gdk_name;
};
/** Mask of all kterm supported modifiers set */
#define KB_MODIFIERS_SET_MASK (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | GDK_MOD4_MASK)
/** Mask of basic kterm supported modifiers set (shift, control, alt) */
#define KB_MODIFIERS_BASIC_MASK (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK)
/** Max count of key buttons */
#define KEYS_MAX 500
/** Max count of keyboard rows */
#define ROWS_MAX 10
/** Basic size of key button in internal units */
#define KEY_UNIT 1000
struct Keyboard;
/**
* Single keyboard key structure
*/
typedef struct Key {
GtkWidget *button; /** Button widget */
gchar *label[KBT_COUNT]; /** Labels array for each layout variant */
GtkWidget *image[KBT_COUNT]; /** Image widgets array for each layout variant */
guint keyval[KBT_COUNT]; /** Keyvals array for each layout variant */
GdkModifierType modifier; /** Modifier type for modifier button */
guint width; /** Forced button width */
gboolean obey_caps; /** Button should react to caps lock */
gboolean fill; /** Button may expand to fill free space */
gboolean extended; /** Button only present in landscape view */
struct Keyboard *keyboard; /** Pointer to keyboard structure */
} Key;
/**
* Keyboard structure
*/
typedef struct Keyboard {
Key **keys; /** Array of keys */
guint32 modifier_mask; /** Current state of modifiers */
guint key_count; /** Keys count */
guint row_count; /** Rows count */
guint key_per_row[ROWS_MAX]; /** Keys count in each row */
guint unit_width; /** Precalculated minimum width of a button */
guint unit_height; /** Precalculated minimum height of a button */
GtkWidget *container; /** Keyboard container */
} Keyboard;
Keyboard * build_layout(GtkWidget *parent, GError **error);
gboolean keyboard_event(GtkWidget *button, GdkEvent *ev, Key *key);
gboolean keyboard_set_size(gpointer data);
void keyboard_free(Keyboard **keyboard);
void keyboard_key_free(Key *key);
#endif /* keyboard_h */