~ubuntu-branches/ubuntu/precise/gnome-control-center/precise-updates

« back to all changes in this revision

Viewing changes to panels/common/eggaccelerators.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher, Jeremy Bicha, Ken VanDine
  • Date: 2012-02-15 23:16:31 UTC
  • mfrom: (1.1.56)
  • Revision ID: package-import@ubuntu.com-20120215231631-vk7me0mhofpsq0hp
Tags: 1:3.3.5-0ubuntu1
* Upload the new serie, that will bring in quite some fixes, we revert
  some problematic or risky changes as well
* The new version includes those fixes:
  - "Change Password in User Accounts panel focuses "New password" field, 
     skipping "Current password"" (lp: #821759)
  - The dialog to add online accounts should have a title 
    (lp: #822380)
  - "Remove Profile" button clickable in Color panel when 
     no profile selected (lp: #869603)
  - Move Removable Media into System Info (lp: #835880)
  - Sound preferences: mouse scrolling balance only works for right.
    (lp: #918017)
  - gnome-control-center SIGSEGV in actualize_printers_list() 
    (lp: #903009)
  - selecting preffered applications is not an info (lp: #890143)
  - Add a keyboard shortcut by default for take screenshot of a selection"
    (lp: #625518)
* debian/patches/revert_git_datetime_port.patch:
  - revert use of datetimed, we don't use systemd and ubuntu-system-service 
    doesn't support it yet
* debian/patches/revert_git_drop_library.patch:
  - consolidate "01_allow_external_panels.patch", don't drop the library
    we use it from other components on ubuntu, the patch will be improved
    later to not use a copy of files like it does in that version
* debian/patches/revert_git_stop_using_gconf.patch,
  debian/patches/revert_ua_gsettings.patch,
  debian/patches/revert_git_keyboard_gsettings.patch:
  - revert keyboard porting to gsettings, compiz still use gconf and we
    didn't update gnome-shell to the new serie (yet)

[ Jeremy Bicha ]
* New upstream release (Thanks Rico Tzchichholz!)
* debian/control.in:
  - Bump minimum dependency versions and add libwacom dependency
* debian/rules: Build without -Wl,-z,defs
* debian/watch: Watch for unstable releases
* Refreshed patches:
  - 01_allow_external_panels.patch
  - 04_add_theme_selection.patch
  - 50_ubuntu_systemwide_prefs.patch
  - 58_ubuntu_icon_views_redesign.patch
  - 59_install_gcm_components_on_demand.patch
  - 91_configure_cheese.patch
* Dropped upstream patches:
  - 00git_handle_media_dialog_close.patch
  - 03_show_wacom_under_unity.patch
  - 90_git_sound_tab_order.patch
  - 91_git_build_use_fontconfig.patch
  - 92_git_minimal_output_height.patch
  - 93_change_window_role_on_panel_change.patch
  - 94_git_adding_shortcuts.patch
  - 95_git_ctrlw_shortcut.patch
  - git_extra_keywords.patch

[ Ken VanDine ]
* debian/patches/96_sound_nua_panel.patch
  - refreshed with latest changes from ronoc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* eggaccelerators.c
2
 
 * Copyright (C) 2002  Red Hat, Inc.; Copyright 1998, 2001 Tim Janik
3
 
 * Developed by Havoc Pennington, Tim Janik
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Library General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Library General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Library General Public
16
 
 * License along with this library; if not, write to the
17
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
 
 * Boston, MA 02111-1307, USA.
19
 
 */
20
 
 
21
 
#include "eggaccelerators.h"
22
 
 
23
 
#include <stdlib.h>
24
 
#include <string.h>
25
 
#include <gdk/gdkx.h>
26
 
#include <gdk/gdkkeysyms.h>
27
 
#include <gtk/gtk.h>
28
 
 
29
 
enum
30
 
{
31
 
  EGG_MODMAP_ENTRY_SHIFT   = 0,
32
 
  EGG_MODMAP_ENTRY_LOCK    = 1,
33
 
  EGG_MODMAP_ENTRY_CONTROL = 2,
34
 
  EGG_MODMAP_ENTRY_MOD1    = 3,
35
 
  EGG_MODMAP_ENTRY_MOD2    = 4,
36
 
  EGG_MODMAP_ENTRY_MOD3    = 5,
37
 
  EGG_MODMAP_ENTRY_MOD4    = 6,
38
 
  EGG_MODMAP_ENTRY_MOD5    = 7,
39
 
  EGG_MODMAP_ENTRY_LAST    = 8
40
 
};
41
 
 
42
 
#define MODMAP_ENTRY_TO_MODIFIER(x) (1 << (x))
43
 
 
44
 
typedef struct
45
 
{
46
 
  EggVirtualModifierType mapping[EGG_MODMAP_ENTRY_LAST];
47
 
 
48
 
} EggModmap;
49
 
 
50
 
const EggModmap* egg_keymap_get_modmap (GdkKeymap *keymap);
51
 
 
52
 
static inline gboolean
53
 
is_alt (const gchar *string)
54
 
{
55
 
  return ((string[0] == '<') &&
56
 
          (string[1] == 'a' || string[1] == 'A') &&
57
 
          (string[2] == 'l' || string[2] == 'L') &&
58
 
          (string[3] == 't' || string[3] == 'T') &&
59
 
          (string[4] == '>'));
60
 
}
61
 
 
62
 
static inline gboolean
63
 
is_ctl (const gchar *string)
64
 
{
65
 
  return ((string[0] == '<') &&
66
 
          (string[1] == 'c' || string[1] == 'C') &&
67
 
          (string[2] == 't' || string[2] == 'T') &&
68
 
          (string[3] == 'l' || string[3] == 'L') &&
69
 
          (string[4] == '>'));
70
 
}
71
 
 
72
 
static inline gboolean
73
 
is_modx (const gchar *string)
74
 
{
75
 
  return ((string[0] == '<') &&
76
 
          (string[1] == 'm' || string[1] == 'M') &&
77
 
          (string[2] == 'o' || string[2] == 'O') &&
78
 
          (string[3] == 'd' || string[3] == 'D') &&
79
 
          (string[4] >= '1' && string[4] <= '5') &&
80
 
          (string[5] == '>'));
81
 
}
82
 
 
83
 
static inline gboolean
84
 
is_ctrl (const gchar *string)
85
 
{
86
 
  return ((string[0] == '<') &&
87
 
          (string[1] == 'c' || string[1] == 'C') &&
88
 
          (string[2] == 't' || string[2] == 'T') &&
89
 
          (string[3] == 'r' || string[3] == 'R') &&
90
 
          (string[4] == 'l' || string[4] == 'L') &&
91
 
          (string[5] == '>'));
92
 
}
93
 
 
94
 
static inline gboolean
95
 
is_shft (const gchar *string)
96
 
{
97
 
  return ((string[0] == '<') &&
98
 
          (string[1] == 's' || string[1] == 'S') &&
99
 
          (string[2] == 'h' || string[2] == 'H') &&
100
 
          (string[3] == 'f' || string[3] == 'F') &&
101
 
          (string[4] == 't' || string[4] == 'T') &&
102
 
          (string[5] == '>'));
103
 
}
104
 
 
105
 
static inline gboolean
106
 
is_shift (const gchar *string)
107
 
{
108
 
  return ((string[0] == '<') &&
109
 
          (string[1] == 's' || string[1] == 'S') &&
110
 
          (string[2] == 'h' || string[2] == 'H') &&
111
 
          (string[3] == 'i' || string[3] == 'I') &&
112
 
          (string[4] == 'f' || string[4] == 'F') &&
113
 
          (string[5] == 't' || string[5] == 'T') &&
114
 
          (string[6] == '>'));
115
 
}
116
 
 
117
 
static inline gboolean
118
 
is_control (const gchar *string)
119
 
{
120
 
  return ((string[0] == '<') &&
121
 
          (string[1] == 'c' || string[1] == 'C') &&
122
 
          (string[2] == 'o' || string[2] == 'O') &&
123
 
          (string[3] == 'n' || string[3] == 'N') &&
124
 
          (string[4] == 't' || string[4] == 'T') &&
125
 
          (string[5] == 'r' || string[5] == 'R') &&
126
 
          (string[6] == 'o' || string[6] == 'O') &&
127
 
          (string[7] == 'l' || string[7] == 'L') &&
128
 
          (string[8] == '>'));
129
 
}
130
 
 
131
 
static inline gboolean
132
 
is_release (const gchar *string)
133
 
{
134
 
  return ((string[0] == '<') &&
135
 
          (string[1] == 'r' || string[1] == 'R') &&
136
 
          (string[2] == 'e' || string[2] == 'E') &&
137
 
          (string[3] == 'l' || string[3] == 'L') &&
138
 
          (string[4] == 'e' || string[4] == 'E') &&
139
 
          (string[5] == 'a' || string[5] == 'A') &&
140
 
          (string[6] == 's' || string[6] == 'S') &&
141
 
          (string[7] == 'e' || string[7] == 'E') &&
142
 
          (string[8] == '>'));
143
 
}
144
 
 
145
 
static inline gboolean
146
 
is_meta (const gchar *string)
147
 
{
148
 
  return ((string[0] == '<') &&
149
 
          (string[1] == 'm' || string[1] == 'M') &&
150
 
          (string[2] == 'e' || string[2] == 'E') &&
151
 
          (string[3] == 't' || string[3] == 'T') &&
152
 
          (string[4] == 'a' || string[4] == 'A') &&
153
 
          (string[5] == '>'));
154
 
}
155
 
 
156
 
static inline gboolean
157
 
is_super (const gchar *string)
158
 
{
159
 
  return ((string[0] == '<') &&
160
 
          (string[1] == 's' || string[1] == 'S') &&
161
 
          (string[2] == 'u' || string[2] == 'U') &&
162
 
          (string[3] == 'p' || string[3] == 'P') &&
163
 
          (string[4] == 'e' || string[4] == 'E') &&
164
 
          (string[5] == 'r' || string[5] == 'R') &&
165
 
          (string[6] == '>'));
166
 
}
167
 
 
168
 
static inline gboolean
169
 
is_hyper (const gchar *string)
170
 
{
171
 
  return ((string[0] == '<') &&
172
 
          (string[1] == 'h' || string[1] == 'H') &&
173
 
          (string[2] == 'y' || string[2] == 'Y') &&
174
 
          (string[3] == 'p' || string[3] == 'P') &&
175
 
          (string[4] == 'e' || string[4] == 'E') &&
176
 
          (string[5] == 'r' || string[5] == 'R') &&
177
 
          (string[6] == '>'));
178
 
}
179
 
 
180
 
static inline gboolean
181
 
is_primary (const gchar *string)
182
 
{
183
 
        return ((string[0] == '<') &&
184
 
                (string[1] == 'p' || string[1] == 'P') &&
185
 
                (string[2] == 'r' || string[2] == 'R') &&
186
 
                (string[3] == 'i' || string[3] == 'I') &&
187
 
                (string[4] == 'm' || string[4] == 'M') &&
188
 
                (string[5] == 'a' || string[5] == 'A') &&
189
 
                (string[6] == 'r' || string[6] == 'R') &&
190
 
                (string[7] == 'y' || string[7] == 'Y') &&
191
 
                (string[8] == '>'));
192
 
}
193
 
 
194
 
static inline gboolean
195
 
is_keycode (const gchar *string)
196
 
{
197
 
  return ((string[0] == '0') &&
198
 
          (string[1] == 'x'));
199
 
}
200
 
 
201
 
/**
202
 
 * egg_accelerator_parse_virtual:
203
 
 * @accelerator:      string representing an accelerator
204
 
 * @accelerator_key:  return location for accelerator keyval
205
 
 * @accelerator_mods: return location for accelerator modifier mask
206
 
 *
207
 
 * Parses a string representing a virtual accelerator. The format
208
 
 * looks like "&lt;Control&gt;a" or "&lt;Shift&gt;&lt;Alt&gt;F1" or
209
 
 * "&lt;Release&gt;z" (the last one is for key release).  The parser
210
 
 * is fairly liberal and allows lower or upper case, and also
211
 
 * abbreviations such as "&lt;Ctl&gt;" and "&lt;Ctrl&gt;".
212
 
 *
213
 
 * If the parse fails, @accelerator_key and @accelerator_mods will
214
 
 * be set to 0 (zero) and %FALSE will be returned. If the string contains
215
 
 * only modifiers, @accelerator_key will be set to 0 but %TRUE will be
216
 
 * returned.
217
 
 *
218
 
 * The virtual vs. concrete accelerator distinction is a relic of
219
 
 * how the X Window System works; there are modifiers Mod2-Mod5 that
220
 
 * can represent various keyboard keys (numlock, meta, hyper, etc.),
221
 
 * the virtual modifier represents the keyboard key, the concrete
222
 
 * modifier the actual Mod2-Mod5 bits in the key press event.
223
 
 *
224
 
 * Returns: %TRUE on success.
225
 
 */
226
 
gboolean
227
 
egg_accelerator_parse_virtual (const gchar            *accelerator,
228
 
                               guint                  *accelerator_key,
229
 
                               guint                  *keycode,
230
 
                               EggVirtualModifierType *accelerator_mods)
231
 
{
232
 
  guint keyval;
233
 
  GdkModifierType mods;
234
 
  gint len;
235
 
  gboolean bad_keyval;
236
 
 
237
 
  if (accelerator_key)
238
 
    *accelerator_key = 0;
239
 
  if (accelerator_mods)
240
 
    *accelerator_mods = 0;
241
 
  if (keycode)
242
 
    *keycode = 0;
243
 
 
244
 
  g_return_val_if_fail (accelerator != NULL, FALSE);
245
 
 
246
 
  bad_keyval = FALSE;
247
 
 
248
 
  keyval = 0;
249
 
  mods = 0;
250
 
  len = strlen (accelerator);
251
 
  while (len)
252
 
    {
253
 
      if (*accelerator == '<')
254
 
        {
255
 
          if (len >= 9 && is_release (accelerator))
256
 
            {
257
 
              accelerator += 9;
258
 
              len -= 9;
259
 
              mods |= EGG_VIRTUAL_RELEASE_MASK;
260
 
            }
261
 
          else if (len >= 9 && is_control (accelerator))
262
 
            {
263
 
              accelerator += 9;
264
 
              len -= 9;
265
 
              mods |= EGG_VIRTUAL_CONTROL_MASK;
266
 
            }
267
 
          else if (len >= 7 && is_shift (accelerator))
268
 
            {
269
 
              accelerator += 7;
270
 
              len -= 7;
271
 
              mods |= EGG_VIRTUAL_SHIFT_MASK;
272
 
            }
273
 
          else if (len >= 6 && is_shft (accelerator))
274
 
            {
275
 
              accelerator += 6;
276
 
              len -= 6;
277
 
              mods |= EGG_VIRTUAL_SHIFT_MASK;
278
 
            }
279
 
          else if (len >= 6 && is_ctrl (accelerator))
280
 
            {
281
 
              accelerator += 6;
282
 
              len -= 6;
283
 
              mods |= EGG_VIRTUAL_CONTROL_MASK;
284
 
            }
285
 
          else if (len >= 6 && is_modx (accelerator))
286
 
            {
287
 
              static const guint mod_vals[] = {
288
 
                EGG_VIRTUAL_ALT_MASK, EGG_VIRTUAL_MOD2_MASK, EGG_VIRTUAL_MOD3_MASK,
289
 
                EGG_VIRTUAL_MOD4_MASK, EGG_VIRTUAL_MOD5_MASK
290
 
              };
291
 
 
292
 
              len -= 6;
293
 
              accelerator += 4;
294
 
              mods |= mod_vals[*accelerator - '1'];
295
 
              accelerator += 2;
296
 
            }
297
 
          else if (len >= 5 && is_ctl (accelerator))
298
 
            {
299
 
              accelerator += 5;
300
 
              len -= 5;
301
 
              mods |= EGG_VIRTUAL_CONTROL_MASK;
302
 
            }
303
 
          else if (len >= 5 && is_alt (accelerator))
304
 
            {
305
 
              accelerator += 5;
306
 
              len -= 5;
307
 
              mods |= EGG_VIRTUAL_ALT_MASK;
308
 
            }
309
 
          else if (len >= 6 && is_meta (accelerator))
310
 
            {
311
 
              accelerator += 6;
312
 
              len -= 6;
313
 
              mods |= EGG_VIRTUAL_META_MASK;
314
 
            }
315
 
          else if (len >= 7 && is_hyper (accelerator))
316
 
            {
317
 
              accelerator += 7;
318
 
              len -= 7;
319
 
              mods |= EGG_VIRTUAL_HYPER_MASK;
320
 
            }
321
 
          else if (len >= 7 && is_super (accelerator))
322
 
            {
323
 
              accelerator += 7;
324
 
              len -= 7;
325
 
              mods |= EGG_VIRTUAL_SUPER_MASK;
326
 
            }
327
 
          else if (len >= 9 && is_primary (accelerator))
328
 
            {
329
 
              accelerator += 9;
330
 
              len -= 9;
331
 
              mods |= EGG_VIRTUAL_CONTROL_MASK;
332
 
            }
333
 
          else
334
 
            {
335
 
              gchar last_ch;
336
 
 
337
 
              last_ch = *accelerator;
338
 
              while (last_ch && last_ch != '>')
339
 
                {
340
 
                  last_ch = *accelerator;
341
 
                  accelerator += 1;
342
 
                  len -= 1;
343
 
                }
344
 
            }
345
 
        }
346
 
      else
347
 
        {
348
 
          keyval = gdk_keyval_from_name (accelerator);
349
 
 
350
 
          if (keyval == 0)
351
 
            {
352
 
              /* If keyval is 0, then maybe it's a keycode.  Check for 0x## */
353
 
              if (len >= 4 && is_keycode (accelerator))
354
 
                {
355
 
                  char keystring[5];
356
 
                  gchar *endptr;
357
 
                  gint tmp_keycode;
358
 
 
359
 
                  memcpy (keystring, accelerator, 4);
360
 
                  keystring [4] = '\000';
361
 
 
362
 
                  tmp_keycode = strtol (keystring, &endptr, 16);
363
 
 
364
 
                  if (endptr == NULL || *endptr != '\000')
365
 
                    {
366
 
                      bad_keyval = TRUE;
367
 
                    }
368
 
                  else if (keycode != NULL)
369
 
                    {
370
 
                      *keycode = tmp_keycode;
371
 
                      /* 0x00 is an invalid keycode too. */
372
 
                      if (*keycode == 0)
373
 
                        bad_keyval = TRUE;
374
 
                    }
375
 
                }
376
 
            }
377
 
          else if (keycode != NULL)
378
 
            {
379
 
              *keycode = XKeysymToKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), keyval);
380
 
              if (*keycode == 0)
381
 
                bad_keyval = TRUE;
382
 
            }
383
 
 
384
 
          accelerator += len;
385
 
          len -= len;
386
 
        }
387
 
    }
388
 
 
389
 
  if (accelerator_key)
390
 
    *accelerator_key = gdk_keyval_to_lower (keyval);
391
 
  if (accelerator_mods)
392
 
    *accelerator_mods = mods;
393
 
 
394
 
  return !bad_keyval;
395
 
}
396
 
 
397
 
/**
398
 
 * egg_virtual_accelerator_name:
399
 
 * @accelerator_key:  accelerator keyval
400
 
 * @accelerator_mods: accelerator modifier mask
401
 
 * @returns:          a newly-allocated accelerator name
402
 
 *
403
 
 * Converts an accelerator keyval and modifier mask
404
 
 * into a string parseable by egg_accelerator_parse_virtual().
405
 
 * For example, if you pass in #GDK_q and #EGG_VIRTUAL_CONTROL_MASK,
406
 
 * this function returns "&lt;Control&gt;q".
407
 
 *
408
 
 * The caller of this function must free the returned string.
409
 
 */
410
 
gchar*
411
 
egg_virtual_accelerator_name (guint                  accelerator_key,
412
 
                              guint                  keycode,
413
 
                              EggVirtualModifierType accelerator_mods)
414
 
{
415
 
  gchar *gtk_name;
416
 
  GdkModifierType gdkmods = 0;
417
 
 
418
 
  egg_keymap_resolve_virtual_modifiers (NULL, accelerator_mods, &gdkmods);
419
 
  gtk_name = gtk_accelerator_name (accelerator_key, gdkmods);
420
 
 
421
 
  if (!accelerator_key)
422
 
    {
423
 
        gchar *name;
424
 
        name = g_strdup_printf ("%s0x%02x", gtk_name, keycode);
425
 
        g_free (gtk_name);
426
 
        return name;
427
 
    }
428
 
 
429
 
  return gtk_name;
430
 
}
431
 
 
432
 
/**
433
 
 * egg_virtual_accelerator_label:
434
 
 * @accelerator_key:  accelerator keyval
435
 
 * @accelerator_mods: accelerator modifier mask
436
 
 * @returns:          a newly-allocated accelerator label
437
 
 *
438
 
 * Converts an accelerator keyval and modifier mask
439
 
 * into a (possibly translated) string that can be displayed to
440
 
 * a user.
441
 
 * For example, if you pass in #GDK_q and #EGG_VIRTUAL_CONTROL_MASK,
442
 
 * and you use a German locale, this function returns "Strg+Q".
443
 
 *
444
 
 * The caller of this function must free the returned string.
445
 
 */
446
 
gchar*
447
 
egg_virtual_accelerator_label (guint                  accelerator_key,
448
 
                               guint                  keycode,
449
 
                               EggVirtualModifierType accelerator_mods)
450
 
{
451
 
  gchar *gtk_label;
452
 
  GdkModifierType gdkmods = 0;
453
 
 
454
 
  egg_keymap_resolve_virtual_modifiers (NULL, accelerator_mods, &gdkmods);
455
 
  gtk_label = gtk_accelerator_get_label (accelerator_key, gdkmods);
456
 
 
457
 
  if (!accelerator_key)
458
 
    {
459
 
        gchar *label;
460
 
        label = g_strdup_printf ("%s0x%02x", gtk_label, keycode);
461
 
        g_free (gtk_label);
462
 
        return label;
463
 
    }
464
 
 
465
 
  return gtk_label;
466
 
}
467
 
 
468
 
void
469
 
egg_keymap_resolve_virtual_modifiers (GdkKeymap              *keymap,
470
 
                                      EggVirtualModifierType  virtual_mods,
471
 
                                      GdkModifierType        *concrete_mods)
472
 
{
473
 
  GdkModifierType concrete;
474
 
  int i;
475
 
  const EggModmap *modmap;
476
 
 
477
 
  g_return_if_fail (concrete_mods != NULL);
478
 
  g_return_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap));
479
 
 
480
 
  modmap = egg_keymap_get_modmap (keymap);
481
 
 
482
 
  /* Not so sure about this algorithm. */
483
 
 
484
 
  concrete = 0;
485
 
  for (i = 0; i < EGG_MODMAP_ENTRY_LAST; ++i)
486
 
    {
487
 
      if (modmap->mapping[i] & virtual_mods)
488
 
        concrete |= MODMAP_ENTRY_TO_MODIFIER (i);
489
 
    }
490
 
 
491
 
  *concrete_mods = concrete;
492
 
}
493
 
 
494
 
void
495
 
egg_keymap_virtualize_modifiers (GdkKeymap              *keymap,
496
 
                                 GdkModifierType         concrete_mods,
497
 
                                 EggVirtualModifierType *virtual_mods)
498
 
{
499
 
  GdkModifierType virtual;
500
 
  int i;
501
 
  const EggModmap *modmap;
502
 
 
503
 
  g_return_if_fail (virtual_mods != NULL);
504
 
  g_return_if_fail (keymap == NULL || GDK_IS_KEYMAP (keymap));
505
 
 
506
 
  modmap = egg_keymap_get_modmap (keymap);
507
 
 
508
 
  /* Not so sure about this algorithm. */
509
 
 
510
 
  virtual = 0;
511
 
  for (i = 0; i < EGG_MODMAP_ENTRY_LAST; ++i)
512
 
    {
513
 
      if (MODMAP_ENTRY_TO_MODIFIER (i) & concrete_mods)
514
 
        {
515
 
          EggVirtualModifierType cleaned;
516
 
 
517
 
          cleaned = modmap->mapping[i] & ~(EGG_VIRTUAL_MOD2_MASK |
518
 
                                           EGG_VIRTUAL_MOD3_MASK |
519
 
                                           EGG_VIRTUAL_MOD4_MASK |
520
 
                                           EGG_VIRTUAL_MOD5_MASK);
521
 
 
522
 
          if (cleaned != 0)
523
 
            {
524
 
              virtual |= cleaned;
525
 
            }
526
 
          else
527
 
            {
528
 
              /* Rather than dropping mod2->mod5 if not bound,
529
 
               * go ahead and use the concrete names
530
 
               */
531
 
              virtual |= modmap->mapping[i];
532
 
            }
533
 
        }
534
 
    }
535
 
 
536
 
  *virtual_mods = virtual;
537
 
}
538
 
 
539
 
static void
540
 
reload_modmap (GdkKeymap *keymap,
541
 
               EggModmap *modmap)
542
 
{
543
 
  XModifierKeymap *xmodmap;
544
 
  int map_size;
545
 
  int i;
546
 
 
547
 
  /* FIXME multihead */
548
 
  xmodmap = XGetModifierMapping (gdk_x11_get_default_xdisplay ());
549
 
 
550
 
  memset (modmap->mapping, 0, sizeof (modmap->mapping));
551
 
 
552
 
  /* there are 8 modifiers in the order shift, shift lock,
553
 
   * control, mod1-5 with up to max_keypermod bindings each
554
 
   */
555
 
  map_size = 8 * xmodmap->max_keypermod;
556
 
  for (i = 3 * xmodmap->max_keypermod; i < map_size; ++i)
557
 
    {
558
 
      /* get the key code at this point in the map,
559
 
       * see if its keysym is one we're interested in
560
 
       */
561
 
      int keycode = xmodmap->modifiermap[i];
562
 
      GdkKeymapKey *keys;
563
 
      guint *keyvals;
564
 
      int n_entries;
565
 
      int j;
566
 
      EggVirtualModifierType mask;
567
 
 
568
 
      keys = NULL;
569
 
      keyvals = NULL;
570
 
      n_entries = 0;
571
 
 
572
 
      gdk_keymap_get_entries_for_keycode (keymap,
573
 
                                          keycode,
574
 
                                          &keys, &keyvals, &n_entries);
575
 
 
576
 
      mask = 0;
577
 
      for (j = 0; j < n_entries; ++j)
578
 
        {
579
 
          if (keyvals[j] == GDK_KEY_Num_Lock)
580
 
            mask |= EGG_VIRTUAL_NUM_LOCK_MASK;
581
 
          else if (keyvals[j] == GDK_KEY_Scroll_Lock)
582
 
            mask |= EGG_VIRTUAL_SCROLL_LOCK_MASK;
583
 
          else if (keyvals[j] == GDK_KEY_Meta_L ||
584
 
                   keyvals[j] == GDK_KEY_Meta_R)
585
 
            mask |= EGG_VIRTUAL_META_MASK;
586
 
          else if (keyvals[j] == GDK_KEY_Hyper_L ||
587
 
                   keyvals[j] == GDK_KEY_Hyper_R)
588
 
            mask |= EGG_VIRTUAL_HYPER_MASK;
589
 
          else if (keyvals[j] == GDK_KEY_Super_L ||
590
 
                   keyvals[j] == GDK_KEY_Super_R)
591
 
            mask |= EGG_VIRTUAL_SUPER_MASK;
592
 
          else if (keyvals[j] == GDK_KEY_Mode_switch)
593
 
            mask |= EGG_VIRTUAL_MODE_SWITCH_MASK;
594
 
        }
595
 
 
596
 
      /* Mod1Mask is 1 << 3 for example, i.e. the
597
 
       * fourth modifier, i / keyspermod is the modifier
598
 
       * index
599
 
       */
600
 
      modmap->mapping[i/xmodmap->max_keypermod] |= mask;
601
 
 
602
 
      g_free (keyvals);
603
 
      g_free (keys);
604
 
    }
605
 
 
606
 
  /* Add in the not-really-virtual fixed entries */
607
 
  modmap->mapping[EGG_MODMAP_ENTRY_SHIFT] |= EGG_VIRTUAL_SHIFT_MASK;
608
 
  modmap->mapping[EGG_MODMAP_ENTRY_CONTROL] |= EGG_VIRTUAL_CONTROL_MASK;
609
 
  modmap->mapping[EGG_MODMAP_ENTRY_LOCK] |= EGG_VIRTUAL_LOCK_MASK;
610
 
  modmap->mapping[EGG_MODMAP_ENTRY_MOD1] |= EGG_VIRTUAL_ALT_MASK;
611
 
  modmap->mapping[EGG_MODMAP_ENTRY_MOD2] |= EGG_VIRTUAL_MOD2_MASK;
612
 
  modmap->mapping[EGG_MODMAP_ENTRY_MOD3] |= EGG_VIRTUAL_MOD3_MASK;
613
 
  modmap->mapping[EGG_MODMAP_ENTRY_MOD4] |= EGG_VIRTUAL_MOD4_MASK;
614
 
  modmap->mapping[EGG_MODMAP_ENTRY_MOD5] |= EGG_VIRTUAL_MOD5_MASK;
615
 
 
616
 
  XFreeModifiermap (xmodmap);
617
 
}
618
 
 
619
 
const EggModmap*
620
 
egg_keymap_get_modmap (GdkKeymap *keymap)
621
 
{
622
 
  EggModmap *modmap;
623
 
 
624
 
  if (keymap == NULL)
625
 
    keymap = gdk_keymap_get_default ();
626
 
 
627
 
  /* This is all a hack, much simpler when we can just
628
 
   * modify GDK directly.
629
 
   */
630
 
 
631
 
  modmap = g_object_get_data (G_OBJECT (keymap), "egg-modmap");
632
 
 
633
 
  if (modmap == NULL)
634
 
    {
635
 
      modmap = g_new0 (EggModmap, 1);
636
 
 
637
 
      /* FIXME modify keymap change events with an event filter
638
 
       * and force a reload if we get one
639
 
       */
640
 
 
641
 
      reload_modmap (keymap, modmap);
642
 
 
643
 
      g_object_set_data_full (G_OBJECT (keymap),
644
 
                              "egg-modmap",
645
 
                              modmap,
646
 
                              g_free);
647
 
    }
648
 
 
649
 
  g_assert (modmap != NULL);
650
 
 
651
 
  return modmap;
652
 
}