⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eggaccelerators.c

📁 lumaQQ的源文件
💻 C
📖 第 1 页 / 共 2 页
字号:

  return !bad_keyval;
}


/**
 * egg_virtual_accelerator_name:
 * @accelerator_key:  accelerator keyval
 * @accelerator_mods: accelerator modifier mask
 * @returns:          a newly-allocated accelerator name
 * 
 * Converts an accelerator keyval and modifier mask
 * into a string parseable by egg_accelerator_parse_virtual().
 * For example, if you pass in #GDK_q and #EGG_VIRTUAL_CONTROL_MASK,
 * this function returns "<Control>q".
 *
 * The caller of this function must free the returned string.
 */
gchar*
egg_virtual_accelerator_name (guint                  accelerator_key,
                              EggVirtualModifierType accelerator_mods)
{
  static const gchar text_release[] = "<Release>";
  static const gchar text_shift[] = "<Shift>";
  static const gchar text_control[] = "<Control>";
  static const gchar text_mod1[] = "<Alt>";
  static const gchar text_mod2[] = "<Mod2>";
  static const gchar text_mod3[] = "<Mod3>";
  static const gchar text_mod4[] = "<Mod4>";
  static const gchar text_mod5[] = "<Mod5>";
  static const gchar text_meta[] = "<Meta>";
  static const gchar text_super[] = "<Super>";
  static const gchar text_hyper[] = "<Hyper>";
  guint l;
  gchar *keyval_name;
  gchar *accelerator;

  accelerator_mods &= EGG_VIRTUAL_MODIFIER_MASK;

  keyval_name = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
  if (!keyval_name)
    keyval_name = "";

  l = 0;
  if (accelerator_mods & EGG_VIRTUAL_RELEASE_MASK)
    l += sizeof (text_release) - 1;
  if (accelerator_mods & EGG_VIRTUAL_SHIFT_MASK)
    l += sizeof (text_shift) - 1;
  if (accelerator_mods & EGG_VIRTUAL_CONTROL_MASK)
    l += sizeof (text_control) - 1;
  if (accelerator_mods & EGG_VIRTUAL_ALT_MASK)
    l += sizeof (text_mod1) - 1;
  if (accelerator_mods & EGG_VIRTUAL_MOD2_MASK)
    l += sizeof (text_mod2) - 1;
  if (accelerator_mods & EGG_VIRTUAL_MOD3_MASK)
    l += sizeof (text_mod3) - 1;
  if (accelerator_mods & EGG_VIRTUAL_MOD4_MASK)
    l += sizeof (text_mod4) - 1;
  if (accelerator_mods & EGG_VIRTUAL_MOD5_MASK)
    l += sizeof (text_mod5) - 1;
  if (accelerator_mods & EGG_VIRTUAL_META_MASK)
    l += sizeof (text_meta) - 1;
  if (accelerator_mods & EGG_VIRTUAL_HYPER_MASK)
    l += sizeof (text_hyper) - 1;
  if (accelerator_mods & EGG_VIRTUAL_SUPER_MASK)
    l += sizeof (text_super) - 1;
  l += strlen (keyval_name);

  accelerator = g_new (gchar, l + 1);

  l = 0;
  accelerator[l] = 0;
  if (accelerator_mods & EGG_VIRTUAL_RELEASE_MASK)
    {
      strcpy (accelerator + l, text_release);
      l += sizeof (text_release) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_SHIFT_MASK)
    {
      strcpy (accelerator + l, text_shift);
      l += sizeof (text_shift) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_CONTROL_MASK)
    {
      strcpy (accelerator + l, text_control);
      l += sizeof (text_control) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_ALT_MASK)
    {
      strcpy (accelerator + l, text_mod1);
      l += sizeof (text_mod1) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_MOD2_MASK)
    {
      strcpy (accelerator + l, text_mod2);
      l += sizeof (text_mod2) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_MOD3_MASK)
    {
      strcpy (accelerator + l, text_mod3);
      l += sizeof (text_mod3) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_MOD4_MASK)
    {
      strcpy (accelerator + l, text_mod4);
      l += sizeof (text_mod4) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_MOD5_MASK)
    {
      strcpy (accelerator + l, text_mod5);
      l += sizeof (text_mod5) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_META_MASK)
    {
      strcpy (accelerator + l, text_meta);
      l += sizeof (text_meta) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_HYPER_MASK)
    {
      strcpy (accelerator + l, text_hyper);
      l += sizeof (text_hyper) - 1;
    }
  if (accelerator_mods & EGG_VIRTUAL_SUPER_MASK)
    {
      strcpy (accelerator + l, text_super);
      l += sizeof (text_super) - 1;
    }
  
  strcpy (accelerator + l, keyval_name);

  return accelerator;
}

void
egg_keymap_resolve_virtual_modifiers (GdkKeymap              *keymap,
                                      EggVirtualModifierType  virtual_mods,
                                      GdkModifierType        *concrete_mods)
{
  GdkModifierType concrete;
  int i;
  const EggModmap *modmap;

  g_return_if_fail (GDK_IS_KEYMAP (keymap));
  g_return_if_fail (concrete_mods != NULL);
  
  modmap = egg_keymap_get_modmap (keymap);
  
  /* Not so sure about this algorithm. */
  
  concrete = 0;
  i = 0;
  while (i < EGG_MODMAP_ENTRY_LAST)
    {
      if (modmap->mapping[i] & virtual_mods)
        concrete |= (1 << i);

      ++i;
    }

  *concrete_mods = concrete;
}

void
egg_keymap_virtualize_modifiers (GdkKeymap              *keymap,
                                 GdkModifierType         concrete_mods,
                                 EggVirtualModifierType *virtual_mods)
{
  GdkModifierType virtual;
  int i;
  const EggModmap *modmap;
  
  g_return_if_fail (GDK_IS_KEYMAP (keymap));
  g_return_if_fail (virtual_mods != NULL);

  modmap = egg_keymap_get_modmap (keymap);
  
  /* Not so sure about this algorithm. */
  
  virtual = 0;
  i = 0;
  while (i < EGG_MODMAP_ENTRY_LAST)
    {
      if ((1 << i) & concrete_mods)
        {
          EggVirtualModifierType cleaned;
          
          cleaned = modmap->mapping[i] & ~(EGG_VIRTUAL_MOD2_MASK |
                                           EGG_VIRTUAL_MOD3_MASK |
                                           EGG_VIRTUAL_MOD4_MASK |
                                           EGG_VIRTUAL_MOD5_MASK);
          
          if (cleaned != 0)
            {
              virtual |= cleaned;
            }
          else
            {
              /* Rather than dropping mod2->mod5 if not bound,
               * go ahead and use the concrete names
               */
              virtual |= modmap->mapping[i];
            }
        }
      
      ++i;
    }
  
  *virtual_mods = virtual;
}

static void
reload_modmap (GdkKeymap *keymap,
               EggModmap *modmap)
{
  XModifierKeymap *xmodmap;
  int map_size;
  int i;

  /* FIXME multihead */
  xmodmap = XGetModifierMapping (gdk_x11_get_default_xdisplay ());

  memset (modmap->mapping, 0, sizeof (modmap->mapping));
  
  /* there are 8 modifiers, and the first 3 are shift, shift lock,
   * and control
   */
  map_size = 8 * xmodmap->max_keypermod;
  i = 3 * xmodmap->max_keypermod;
  while (i < map_size)
    {
      /* get the key code at this point in the map,
       * see if its keysym is one we're interested in
       */
      int keycode = xmodmap->modifiermap[i];
      GdkKeymapKey *keys;
      guint *keyvals;
      int n_entries;
      int j;
      EggVirtualModifierType mask;
      
      keys = NULL;
      keyvals = NULL;
      n_entries = 0;

      gdk_keymap_get_entries_for_keycode (keymap,
                                          keycode,
                                          &keys, &keyvals, &n_entries);
      
      mask = 0;
      j = 0;
      while (j < n_entries)
        {          
          if (keyvals[j] == GDK_Num_Lock)
            mask |= EGG_VIRTUAL_NUM_LOCK_MASK;
          else if (keyvals[j] == GDK_Scroll_Lock)
            mask |= EGG_VIRTUAL_SCROLL_LOCK_MASK;
          else if (keyvals[j] == GDK_Meta_L ||
                   keyvals[j] == GDK_Meta_R)
            mask |= EGG_VIRTUAL_META_MASK;
          else if (keyvals[j] == GDK_Hyper_L ||
                   keyvals[j] == GDK_Hyper_R)
            mask |= EGG_VIRTUAL_HYPER_MASK;
          else if (keyvals[j] == GDK_Super_L ||
                   keyvals[j] == GDK_Super_R)
            mask |= EGG_VIRTUAL_SUPER_MASK;
          else if (keyvals[j] == GDK_Mode_switch)
            mask |= EGG_VIRTUAL_MODE_SWITCH_MASK;
          
          ++j;
        }

      /* Mod1Mask is 1 << 3 for example, i.e. the
       * fourth modifier, i / keyspermod is the modifier
       * index
       */      
      modmap->mapping[i/xmodmap->max_keypermod] |= mask;
      
      g_free (keyvals);
      g_free (keys);      
      
      ++i;
    }

  /* Add in the not-really-virtual fixed entries */
  modmap->mapping[EGG_MODMAP_ENTRY_SHIFT] |= EGG_VIRTUAL_SHIFT_MASK;
  modmap->mapping[EGG_MODMAP_ENTRY_CONTROL] |= EGG_VIRTUAL_CONTROL_MASK;
  modmap->mapping[EGG_MODMAP_ENTRY_LOCK] |= EGG_VIRTUAL_LOCK_MASK;
  modmap->mapping[EGG_MODMAP_ENTRY_MOD1] |= EGG_VIRTUAL_ALT_MASK;
  modmap->mapping[EGG_MODMAP_ENTRY_MOD2] |= EGG_VIRTUAL_MOD2_MASK;
  modmap->mapping[EGG_MODMAP_ENTRY_MOD3] |= EGG_VIRTUAL_MOD3_MASK;
  modmap->mapping[EGG_MODMAP_ENTRY_MOD4] |= EGG_VIRTUAL_MOD4_MASK;
  modmap->mapping[EGG_MODMAP_ENTRY_MOD5] |= EGG_VIRTUAL_MOD5_MASK;
  
  XFreeModifiermap (xmodmap);
}

const EggModmap*
egg_keymap_get_modmap (GdkKeymap *keymap)
{
  EggModmap *modmap;

  /* This is all a hack, much simpler when we can just
   * modify GDK directly.
   */
  
  modmap = g_object_get_data (G_OBJECT (keymap),
                              "egg-modmap");

  if (modmap == NULL)
    {
      modmap = g_new0 (EggModmap, 1);

      /* FIXME modify keymap change events with an event filter
       * and force a reload if we get one
       */
      
      reload_modmap (keymap, modmap);
      
      g_object_set_data_full (G_OBJECT (keymap),
                              "egg-modmap",
                              modmap,
                              g_free);
    }

  g_assert (modmap != NULL);
  
  return modmap;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -