Locked accels hardcoded for GtkWindow



Hello!

I study GTK and struck with unexpected problem. I want use keys like
GDK_KEY_space or GDK_KEY_Return as shortcuts in my app, but when I try
to add entry to accel map there nothing happen. For example:

  GtkAccelGroup *accel_group = gtk_accel_group_new();
  GtkAction *action = gtk_action_new(name, label, tooltip, stock_id);
  g_signal_connect(action, "activate", callback, NULL);
  gtk_action_set_accel_path(action, accel_path);
  gtk_action_set_accel_group(action, accel_group);
  gtk_action_connect_accelerator(action);
  gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
  gtk_accel_map_add_entry(accel_path, GDK_KEY_space, 0);

work fine with alpha-numerical keys, but not with GDK_KEY_space or
some other keys. When I dug into GTK+ source code I found odd things.
In gtkaccelmap.c:internal_change_entry() nice snippet of code:

  /* 4) walk the acceleratables and figure whether they occupy
accel_key&accel_mods */
  if (accel_key)
    for (slist = win_list; slist; slist = slist->next)
      if (GTK_IS_WINDOW (slist->data))	/* bad kludge in lack of a
GtkAcceleratable */
	if (_gtk_window_query_nonaccels (slist->data, accel_key, accel_mods))
	  {
	    seen_accel = TRUE;
	    break;
	  }
  removable = !seen_accel;

I went farther and found in _gtk_window_query_nonaccels () from
gtkwindow.c that:

  /* movement keys are considered locked accels */
  if (!accel_mods)
    {
      static const guint bindings[] = {
	GDK_KEY_space, GDK_KEY_KP_Space, GDK_KEY_Return, GDK_KEY_ISO_Enter,
GDK_KEY_KP_Enter, GDK_KEY_Up, GDK_KEY_KP_Up, GDK_KEY_Down,
GDK_KEY_KP_Down,
	GDK_KEY_Left, GDK_KEY_KP_Left, GDK_KEY_Right, GDK_KEY_KP_Right,
GDK_KEY_Tab, GDK_KEY_KP_Tab, GDK_KEY_ISO_Left_Tab,
      };
      guint i;

      for (i = 0; i < G_N_ELEMENTS (bindings); i++)
	if (bindings[i] == accel_key)
	  return TRUE;
    }

What the hell is this?! Anyone know workarounds?

PS: Sorry for my miserable english, it's not my native language.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]