1 /* 2 * Copyright (C) 2006 Sergey V. Udaltsov <svu@gnome.org> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the 16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 * Boston, MA 02111-1307, USA. 18 */ 19 20 #ifndef GKBD_KEYBOARD_DRAWING_H 21 #define GKBD_KEYBOARD_DRAWING_H 1 22 23 #include <gtk/gtk.h> 24 #include <X11/XKBlib.h> 25 #include <X11/extensions/XKBgeom.h> 26 #include <libxklavier/xklavier.h> 27 28 G_BEGIN_DECLS 29 #define GKBD_KEYBOARD_DRAWING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), gkbd_keyboard_drawing_get_type (), \ 30 GkbdKeyboardDrawing)) 31 #define GKBD_KEYBOARD_DRAWING_CLASS(clazz) (G_TYPE_CHECK_CLASS_CAST ((clazz), gkbd_keyboard_drawing_get_type () \ 32 GkbdKeyboardDrawingClass)) 33 #define GKBD_IS_KEYBOARD_DRAWING(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), gkbd_keyboard_drawing_get_type ()) 34 typedef struct _GkbdKeyboardDrawing GkbdKeyboardDrawing; 35 typedef struct _GkbdKeyboardDrawingClass GkbdKeyboardDrawingClass; 36 37 typedef struct _GkbdKeyboardDrawingItem GkbdKeyboardDrawingItem; 38 typedef struct _GkbdKeyboardDrawingKey GkbdKeyboardDrawingKey; 39 typedef struct _GkbdKeyboardDrawingDoodad GkbdKeyboardDrawingDoodad; 40 typedef struct _GkbdKeyboardDrawingGroupLevel 41 GkbdKeyboardDrawingGroupLevel; 42 typedef struct _GkbdKeyboardDrawingRenderContext 43 GkbdKeyboardDrawingRenderContext; 44 45 typedef enum { 46 GKBD_KEYBOARD_DRAWING_ITEM_TYPE_INVALID = 0, 47 GKBD_KEYBOARD_DRAWING_ITEM_TYPE_KEY, 48 GKBD_KEYBOARD_DRAWING_ITEM_TYPE_KEY_EXTRA, 49 GKBD_KEYBOARD_DRAWING_ITEM_TYPE_DOODAD 50 } GkbdKeyboardDrawingItemType; 51 52 typedef enum { 53 GKBD_KEYBOARD_DRAWING_POS_TOPLEFT, 54 GKBD_KEYBOARD_DRAWING_POS_TOPRIGHT, 55 GKBD_KEYBOARD_DRAWING_POS_BOTTOMLEFT, 56 GKBD_KEYBOARD_DRAWING_POS_BOTTOMRIGHT, 57 GKBD_KEYBOARD_DRAWING_POS_TOTAL, 58 GKBD_KEYBOARD_DRAWING_POS_FIRST = 59 GKBD_KEYBOARD_DRAWING_POS_TOPLEFT, 60 GKBD_KEYBOARD_DRAWING_POS_LAST = 61 GKBD_KEYBOARD_DRAWING_POS_BOTTOMRIGHT 62 } GkbdKeyboardDrawingGroupLevelPosition; 63 64 /* units are in xkb form */ 65 struct _GkbdKeyboardDrawingItem { 66 /*< private > */ 67 68 GkbdKeyboardDrawingItemType type; 69 gint origin_x; 70 gint origin_y; 71 gint angle; 72 guint priority; 73 }; 74 75 /* units are in xkb form */ 76 struct _GkbdKeyboardDrawingKey { 77 /*< private > */ 78 79 GkbdKeyboardDrawingItemType type; 80 gint origin_x; 81 gint origin_y; 82 gint angle; 83 guint priority; 84 85 XkbKeyRec *xkbkey; 86 gboolean pressed; 87 guint keycode; 88 }; 89 90 /* units are in xkb form */ 91 struct _GkbdKeyboardDrawingDoodad { 92 /*< private > */ 93 94 GkbdKeyboardDrawingItemType type; 95 gint origin_x; 96 gint origin_y; 97 gint angle; 98 guint priority; 99 100 XkbDoodadRec *doodad; 101 gboolean on; /* for indicator doodads */ 102 }; 103 104 struct _GkbdKeyboardDrawingGroupLevel { 105 gint group; 106 gint level; 107 }; 108 109 struct _GkbdKeyboardDrawingRenderContext { 110 cairo_t *cr; 111 112 gint angle; /* current angle pango is set to draw at, in tenths of a degree */ 113 PangoLayout *layout; 114 PangoFontDescription *font_desc; 115 116 gint scale_numerator; 117 gint scale_denominator; 118 119 GdkRGBA dark_color; 120 }; 121 122 struct _GkbdKeyboardDrawing { 123 /*< private > */ 124 125 GtkDrawingArea parent; 126 127 XkbDescRec *xkb; 128 gboolean xkbOnDisplay; 129 guint l3mod; 130 131 GkbdKeyboardDrawingRenderContext *renderContext; 132 133 /* Indexed by keycode */ 134 GkbdKeyboardDrawingKey *keys; 135 136 /* list of stuff to draw in priority order */ 137 GList *keyboard_items; 138 139 GdkRGBA *colors; 140 141 guint timeout; 142 143 GkbdKeyboardDrawingGroupLevel **groupLevels; 144 145 guint mods; 146 147 Display *display; 148 gint screen_num; 149 150 gint xkb_event_type; 151 152 GkbdKeyboardDrawingDoodad **physical_indicators; 153 gint physical_indicators_size; 154 155 guint track_config:1; 156 guint track_modifiers:1; 157 }; 158 159 struct _GkbdKeyboardDrawingClass { 160 GtkDrawingAreaClass parent_class; 161 162 /* we send this signal when the user presses a key that "doesn't exist" 163 * according to the keyboard geometry; it probably means their xkb 164 * configuration is incorrect */ 165 void (*bad_keycode) (GkbdKeyboardDrawing * drawing, guint keycode); 166 }; 167 168 GType gkbd_keyboard_drawing_get_type (void); 169 GtkWidget *gkbd_keyboard_drawing_new (void); 170 171 gboolean gkbd_keyboard_drawing_render (GkbdKeyboardDrawing * kbdrawing, 172 cairo_t * cr, 173 PangoLayout * layout, 174 double x, double y, 175 double width, double height, 176 gdouble dpi_x, gdouble dpi_y); 177 gboolean gkbd_keyboard_drawing_set_keyboard (GkbdKeyboardDrawing * 178 kbdrawing, 179 XkbComponentNamesRec * names); 180 181 void gkbd_keyboard_drawing_set_layout (GkbdKeyboardDrawing * kbdrawing, 182 const gchar * id); 183 184 G_CONST_RETURN gchar 185 * gkbd_keyboard_drawing_get_keycodes (GkbdKeyboardDrawing * kbdrawing); 186 G_CONST_RETURN gchar 187 * gkbd_keyboard_drawing_get_geometry (GkbdKeyboardDrawing * kbdrawing); 188 G_CONST_RETURN gchar 189 * gkbd_keyboard_drawing_get_symbols (GkbdKeyboardDrawing * kbdrawing); 190 G_CONST_RETURN gchar *gkbd_keyboard_drawing_get_types (GkbdKeyboardDrawing 191 * kbdrawing); 192 G_CONST_RETURN gchar *gkbd_keyboard_drawing_get_compat (GkbdKeyboardDrawing 193 * kbdrawing); 194 195 void gkbd_keyboard_drawing_set_track_modifiers (GkbdKeyboardDrawing * 196 kbdrawing, 197 gboolean enable); 198 void gkbd_keyboard_drawing_set_track_config (GkbdKeyboardDrawing * 199 kbdrawing, gboolean enable); 200 201 void gkbd_keyboard_drawing_set_groups_levels (GkbdKeyboardDrawing * 202 kbdrawing, 203 GkbdKeyboardDrawingGroupLevel 204 * groupLevels[]); 205 206 207 void gkbd_keyboard_drawing_print (GkbdKeyboardDrawing * drawing, 208 GtkWindow * parent_window, 209 const gchar * description); 210 211 GtkWidget *gkbd_keyboard_drawing_dialog_new (void); 212 213 void gkbd_keyboard_drawing_dialog_set_group (GtkWidget * dialog, 214 XklConfigRegistry * registry, 215 gint group); 216 217 void gkbd_keyboard_drawing_dialog_set_layout (GtkWidget * dialog, 218 XklConfigRegistry * registry, 219 const gchar * layout); 220 221 G_END_DECLS 222 #endif /* #ifndef GKBD_KEYBOARD_DRAWING_H */ 223