summaryrefslogtreecommitdiff
path: root/libmatekbd/matekbd-keyboard-drawing.h
blob: e481947ada29777b0185f684c52ce2ce21fe6b92 (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * Copyright (C) 2006 Sergey V. Udaltsov <svu@gnome.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef MATEKBD_KEYBOARD_DRAWING_H
#define MATEKBD_KEYBOARD_DRAWING_H 1

#include <gtk/gtk.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBgeom.h>

#ifdef __cplusplus
extern "C" {
#endif
#define MATEKBD_KEYBOARD_DRAWING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), matekbd_keyboard_drawing_get_type (), \
                               MatekbdKeyboardDrawing))
#define MATEKBD_KEYBOARD_DRAWING_CLASS(clazz) (G_TYPE_CHECK_CLASS_CAST ((clazz), matekbd_keyboard_drawing_get_type () \
                                       MatekbdKeyboardDrawingClass))
#define MATEKBD_IS_KEYBOARD_DRAWING(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), matekbd_keyboard_drawing_get_type ())
typedef struct _MatekbdKeyboardDrawing MatekbdKeyboardDrawing;
typedef struct _MatekbdKeyboardDrawingClass MatekbdKeyboardDrawingClass;

typedef struct _MatekbdKeyboardDrawingItem MatekbdKeyboardDrawingItem;
typedef struct _MatekbdKeyboardDrawingKey MatekbdKeyboardDrawingKey;
typedef struct _MatekbdKeyboardDrawingDoodad MatekbdKeyboardDrawingDoodad;
typedef struct _MatekbdKeyboardDrawingGroupLevel
 MatekbdKeyboardDrawingGroupLevel;
typedef struct _MatekbdKeyboardDrawingRenderContext
 MatekbdKeyboardDrawingRenderContext;

typedef enum {
	MATEKBD_KEYBOARD_DRAWING_ITEM_TYPE_INVALID = 0,
	MATEKBD_KEYBOARD_DRAWING_ITEM_TYPE_KEY,
	MATEKBD_KEYBOARD_DRAWING_ITEM_TYPE_KEY_EXTRA,
	MATEKBD_KEYBOARD_DRAWING_ITEM_TYPE_DOODAD
} MatekbdKeyboardDrawingItemType;

typedef enum {
	MATEKBD_KEYBOARD_DRAWING_POS_TOPLEFT,
	MATEKBD_KEYBOARD_DRAWING_POS_TOPRIGHT,
	MATEKBD_KEYBOARD_DRAWING_POS_BOTTOMLEFT,
	MATEKBD_KEYBOARD_DRAWING_POS_BOTTOMRIGHT,
	MATEKBD_KEYBOARD_DRAWING_POS_TOTAL,
	MATEKBD_KEYBOARD_DRAWING_POS_FIRST =
	    MATEKBD_KEYBOARD_DRAWING_POS_TOPLEFT,
	MATEKBD_KEYBOARD_DRAWING_POS_LAST =
	    MATEKBD_KEYBOARD_DRAWING_POS_BOTTOMRIGHT
} MatekbdKeyboardDrawingGroupLevelPosition;

/* units are in xkb form */
struct _MatekbdKeyboardDrawingItem {
	/*< private > */

	MatekbdKeyboardDrawingItemType type;
	gint origin_x;
	gint origin_y;
	gint angle;
	guint priority;
};

/* units are in xkb form */
struct _MatekbdKeyboardDrawingKey {
	/*< private > */

	MatekbdKeyboardDrawingItemType type;
	gint origin_x;
	gint origin_y;
	gint angle;
	guint priority;

	XkbKeyRec *xkbkey;
	gboolean pressed;
	guint keycode;
};

/* units are in xkb form */
struct _MatekbdKeyboardDrawingDoodad {
	/*< private > */

	MatekbdKeyboardDrawingItemType type;
	gint origin_x;
	gint origin_y;
	gint angle;
	guint priority;

	XkbDoodadRec *doodad;
	gboolean on;		/* for indicator doodads */
};

struct _MatekbdKeyboardDrawingGroupLevel {
	gint group;
	gint level;
};

struct _MatekbdKeyboardDrawingRenderContext {
	cairo_t *cr;

	gint angle;		/* current angle pango is set to draw at, in tenths of a degree */
	PangoLayout *layout;
	PangoFontDescription *font_desc;

	gint scale_numerator;
	gint scale_denominator;

	GdkColor *dark_color;
};

struct _MatekbdKeyboardDrawing {
	/*< private > */

	GtkDrawingArea parent;

	cairo_surface_t *surface;
	XkbDescRec *xkb;
	gboolean xkbOnDisplay;
	guint l3mod;

	MatekbdKeyboardDrawingRenderContext *renderContext;

	/* Indexed by keycode */
	MatekbdKeyboardDrawingKey *keys;

	/* list of stuff to draw in priority order */
	GList *keyboard_items;

	GdkColor *colors;

	guint timeout;
	guint idle_redraw;

	MatekbdKeyboardDrawingGroupLevel **groupLevels;

	guint mods;

	Display *display;
	gint screen_num;

	gint xkb_event_type;

	MatekbdKeyboardDrawingDoodad **physical_indicators;
	gint physical_indicators_size;

	guint track_config:1;
	guint track_modifiers:1;
};

struct _MatekbdKeyboardDrawingClass {
	GtkDrawingAreaClass parent_class;

	/* we send this signal when the user presses a key that "doesn't exist"
	 * according to the keyboard geometry; it probably means their xkb
	 * configuration is incorrect */
	void (*bad_keycode) (MatekbdKeyboardDrawing * drawing, guint keycode);
};

GType matekbd_keyboard_drawing_get_type (void);
GtkWidget *matekbd_keyboard_drawing_new (void);

gboolean matekbd_keyboard_drawing_render (MatekbdKeyboardDrawing * kbdrawing,
				       cairo_t * cr,
				       PangoLayout * layout,
				       double x, double y,
				       double width, double height,
				       gdouble dpi_x, gdouble dpi_y);
gboolean matekbd_keyboard_drawing_set_keyboard (MatekbdKeyboardDrawing *
					     kbdrawing,
					     XkbComponentNamesRec * names);

const gchar* matekbd_keyboard_drawing_get_keycodes(MatekbdKeyboardDrawing* kbdrawing);
const gchar* matekbd_keyboard_drawing_get_geometry(MatekbdKeyboardDrawing* kbdrawing);
const gchar* matekbd_keyboard_drawing_get_symbols(MatekbdKeyboardDrawing* kbdrawing);
const gchar* matekbd_keyboard_drawing_get_types(MatekbdKeyboardDrawing* kbdrawing);
const gchar* matekbd_keyboard_drawing_get_compat(MatekbdKeyboardDrawing* kbdrawing);

void matekbd_keyboard_drawing_set_track_modifiers (MatekbdKeyboardDrawing *
						kbdrawing,
						gboolean enable);
void matekbd_keyboard_drawing_set_track_config (MatekbdKeyboardDrawing *
					     kbdrawing, gboolean enable);

void matekbd_keyboard_drawing_set_groups_levels (MatekbdKeyboardDrawing *
					      kbdrawing,
					      MatekbdKeyboardDrawingGroupLevel
					      * groupLevels[]);


void matekbd_keyboard_drawing_print (MatekbdKeyboardDrawing * drawing,
				  GtkWindow * parent_window,
				  const gchar * description);


GtkWidget* matekbd_keyboard_drawing_new_dialog (gint group, gchar* group_name);

#ifdef __cplusplus
}
#endif
#endif				/* #ifndef MATEKBD_KEYBOARD_DRAWING_H */