static void shortcuts_accel_cleared_cb (GtkCellRenderer* renderer, const gchar* tree_path, GtkTreeModel* model) { GtkTreeIter iter; if (gtk_tree_model_get_iter_from_string (model, &iter, tree_path)) { GtkAction* action; const gchar* accel_path; GtkTreeIter child_iter; GtkTreeModel* liststore; gtk_tree_model_get (model, &iter, 6, &action, -1); accel_path = gtk_action_get_accel_path (action); gtk_accel_map_change_entry (accel_path, 0, 0, FALSE); gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (model), &child_iter, &iter); liststore = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model)); gtk_list_store_set (GTK_LIST_STORE (liststore), &child_iter, 1, 0, 2, 0, -1); g_object_unref (action); } }
static void gimp_action_view_accel_cleared (GtkCellRendererAccel *accel, const char *path_string, GimpActionView *view) { GtkAction *action; guint action_accel_key; GdkModifierType action_accel_mask; const gchar *accel_path; accel_path = gimp_action_view_get_accel_action (view, path_string, &action, &action_accel_key, &action_accel_mask); if (! accel_path) return; if (action_accel_key == GDK_KEY_F1) { gimp_message_literal (view->manager->gimp, G_OBJECT (view), GIMP_MESSAGE_ERROR, _("F1 cannot be remapped.")); return; } if (! gtk_accel_map_change_entry (accel_path, 0, 0, FALSE)) { gimp_message_literal (view->manager->gimp, G_OBJECT (view), GIMP_MESSAGE_ERROR, _("Removing shortcut failed.")); } }
static void menus_remove_accels (gpointer data, const gchar *accel_path, guint accel_key, GdkModifierType accel_mods, gboolean changed) { gtk_accel_map_change_entry (accel_path, 0, 0, TRUE); }
static void spice_hotkey_set_accel(const gchar *accel_path, const gchar *key) { gchar *accel; guint accel_key; GdkModifierType accel_mods; accel = spice_hotkey_to_gtk_accelerator(key); gtk_accelerator_parse(accel, &accel_key, &accel_mods); g_free(accel); gtk_accel_map_change_entry(accel_path, accel_key, accel_mods, TRUE); }
static void update_accel_due_to_scripts_migration (gpointer data, const gchar *accel_path, guint accel_key, GdkModifierType accel_mods, gboolean changed) { char *old_scripts_location_esc = data; char *old_scripts_pt; old_scripts_pt = strstr (accel_path, old_scripts_location_esc); if (old_scripts_pt != NULL) { /* There's a mention of the deprecated scripts directory in the accel. Remove it, and * add a migrated one. */ char *tmp; char *tmp2; GString *new_accel_path; /* base part of accel */ tmp = g_strndup (accel_path, old_scripts_pt - accel_path); new_accel_path = g_string_new (tmp); g_free (tmp); /* new script directory, escaped */ tmp = nautilus_get_scripts_directory_path (); tmp2 = nautilus_escape_action_name (tmp, ""); g_free (tmp); g_string_append (new_accel_path, tmp2); g_free (tmp2); /* script path relative to scripts directory */ g_string_append (new_accel_path, old_scripts_pt + strlen (old_scripts_location_esc)); /* exchange entry */ gtk_accel_map_change_entry (accel_path, 0, 0, FALSE); gtk_accel_map_change_entry (new_accel_path->str, accel_key, accel_mods, TRUE); g_string_free (new_accel_path, TRUE); } }
static guint accel_map_parse_accel_path (GScanner *scanner) { guint accel_key = 0; GdkModifierType accel_mods = 0; gchar *path, *accel; /* parse accel path */ g_scanner_get_next_token (scanner); if (scanner->token != G_TOKEN_STRING) return G_TOKEN_STRING; /* test if the next token is an accelerator */ g_scanner_peek_next_token (scanner); if (scanner->next_token != G_TOKEN_STRING) { /* if not so, eat that token and error out */ g_scanner_get_next_token (scanner); return G_TOKEN_STRING; } /* get the full accelerator specification */ path = g_strdup (scanner->value.v_string); g_scanner_get_next_token (scanner); accel = g_strdup (scanner->value.v_string); /* ensure the entry is present */ gtk_accel_map_add_entry (path, 0, 0); /* and propagate it */ gtk_accelerator_parse (accel, &accel_key, &accel_mods); gtk_accel_map_change_entry (path, accel_key, accel_mods, TRUE); g_free (accel); g_free (path); /* check correct statement end */ g_scanner_get_next_token (scanner); if (scanner->token != ')') return ')'; else return G_TOKEN_NONE; }
static void windows_actions_update_display_accels (GimpActionGroup *group) { GList *list; gint i; for (list = gimp_get_display_iter (group->gimp), i = 0; list && i < 10; list = g_list_next (list), i++) { GimpDisplay *display = list->data; GtkAction *action; gchar *action_name; if (! gimp_display_get_image (display)) break; action_name = gimp_display_get_action_name (display); action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name); g_free (action_name); if (action) { const gchar *accel_path; guint accel_key; accel_path = gtk_action_get_accel_path (action); if (i < 9) accel_key = GDK_KEY_1 + i; else accel_key = GDK_KEY_0; gtk_accel_map_change_entry (accel_path, accel_key, GDK_MOD1_MASK, TRUE); } } }
/** * gtk_accel_map_add_entry: * @accel_path: valid accelerator path * @accel_key: the accelerator key * @accel_mods: the accelerator modifiers * * Registers a new accelerator with the global accelerator map. * This function should only be called once per @accel_path * with the canonical @accel_key and @accel_mods for this path. * To change the accelerator during runtime programatically, use * gtk_accel_map_change_entry(). * * Set @accel_key and @accel_mods to 0 to request a removal of * the accelerator. * * Note that @accel_path string will be stored in a #GQuark. Therefore, if you * pass a static string, you can save some memory by interning it first with * g_intern_static_string(). */ void gtk_accel_map_add_entry (const gchar *accel_path, guint accel_key, GdkModifierType accel_mods) { AccelEntry *entry; g_return_if_fail (_gtk_accel_path_is_valid (accel_path)); if (!accel_key) accel_mods = 0; else accel_mods &= gtk_accelerator_get_default_mod_mask (); entry = accel_path_lookup (accel_path); if (entry) { if (!entry->std_accel_key && !entry->std_accel_mods && (accel_key || accel_mods)) { entry->std_accel_key = accel_key; entry->std_accel_mods = accel_mods; if (!entry->changed) gtk_accel_map_change_entry (entry->accel_path, accel_key, accel_mods, TRUE); } } else { entry = g_slice_new0 (AccelEntry); entry->accel_path = g_intern_string (accel_path); entry->std_accel_key = accel_key; entry->std_accel_mods = accel_mods; entry->accel_key = accel_key; entry->accel_mods = accel_mods; entry->changed = FALSE; entry->lock_count = 0; g_hash_table_insert (accel_entry_ht, entry, entry); do_accel_map_changed (entry); } }
static void gimp_action_view_accel_cleared (GtkCellRendererAccel *accel, const char *path_string, GimpActionView *view) { GtkAction *action; const gchar *accel_path; accel_path = gimp_action_view_get_accel_action (view, path_string, &action); if (! accel_path) return; if (! gtk_accel_map_change_entry (accel_path, 0, 0, FALSE)) { gimp_message_literal (view->manager->gimp, G_OBJECT (view), GIMP_MESSAGE_ERROR, _("Removing shortcut failed.")); } }
int clip_GTK_ACCELMAPCHANGEENTRY(ClipMachine * ClipMachineMemory) { gchar *accel_path = _clip_parc(ClipMachineMemory, 1); guint accel_key = _clip_parni(ClipMachineMemory, 2); GdkModifierType accel_mods = _clip_parni(ClipMachineMemory, 3); gboolean replace = BOOL_OPTION(ClipMachineMemory, 4, 1); CHECKARG(1, CHARACTER_type_of_ClipVarType); CHECKARG(2, NUMERIC_type_of_ClipVarType); CHECKARG(3, NUMERIC_type_of_ClipVarType); CHECKOPT(4, LOGICAL_type_of_ClipVarType); _clip_retl(ClipMachineMemory, gtk_accel_map_change_entry(accel_path, accel_key, accel_mods, replace)); return 0; err: return 1; }
static void gimp_action_view_conflict_response (GtkWidget *dialog, gint response_id, ConfirmData *confirm_data) { gtk_widget_destroy (dialog); if (response_id == GTK_RESPONSE_OK) { if (! gtk_accel_map_change_entry (confirm_data->accel_path, confirm_data->accel_key, confirm_data->accel_mask, TRUE)) { gimp_message_literal (confirm_data->manager->gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR, _("Changing shortcut failed.")); } } g_free (confirm_data->accel_path); g_slice_free (ConfirmData, confirm_data); }
static void gimp_action_view_accel_edited (GtkCellRendererAccel *accel, const char *path_string, guint accel_key, GdkModifierType accel_mask, guint hardware_keycode, GimpActionView *view) { GtkAction *action; guint action_accel_key; GdkModifierType action_accel_mask; const gchar *accel_path; accel_path = gimp_action_view_get_accel_action (view, path_string, &action, &action_accel_key, &action_accel_mask); if (! accel_path) return; if (accel_key == action_accel_key && accel_mask == action_accel_mask) return; if (! accel_key || /* Don't allow arrow keys, they are all swallowed by the canvas * and cannot be invoked anyway, the same applies to space. */ accel_key == GDK_KEY_Left || accel_key == GDK_KEY_Right || accel_key == GDK_KEY_Up || accel_key == GDK_KEY_Down || accel_key == GDK_KEY_space || accel_key == GDK_KEY_KP_Space) { gimp_message_literal (view->manager->gimp, G_OBJECT (view), GIMP_MESSAGE_ERROR, _("Invalid shortcut.")); } else if (accel_key == GDK_KEY_F1 || action_accel_key == GDK_KEY_F1) { gimp_message_literal (view->manager->gimp, G_OBJECT (view), GIMP_MESSAGE_ERROR, _("F1 cannot be remapped.")); } else if (! gtk_accel_map_change_entry (accel_path, accel_key, accel_mask, FALSE)) { GtkTreeModel *model; GtkAction *conflict_action = NULL; GtkTreeIter iter; gboolean iter_valid; model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); for (iter_valid = gtk_tree_model_get_iter_first (model, &iter); iter_valid; iter_valid = gtk_tree_model_iter_next (model, &iter)) { GtkTreeIter child_iter; gboolean child_valid; for (child_valid = gtk_tree_model_iter_children (model, &child_iter, &iter); child_valid; child_valid = gtk_tree_model_iter_next (model, &child_iter)) { guint child_accel_key; GdkModifierType child_accel_mask; gtk_tree_model_get (model, &child_iter, GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY, &child_accel_key, GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK, &child_accel_mask, -1); if (accel_key == child_accel_key && accel_mask == child_accel_mask) { gtk_tree_model_get (model, &child_iter, GIMP_ACTION_VIEW_COLUMN_ACTION, &conflict_action, -1); break; } } if (conflict_action) break; } if (conflict_action != action) { if (conflict_action) { gimp_action_view_conflict_confirm (view, conflict_action, accel_key, accel_mask, accel_path); g_object_unref (conflict_action); } else { gimp_message_literal (view->manager->gimp, G_OBJECT (view), GIMP_MESSAGE_ERROR, _("Changing shortcut failed.")); } } } }
static void rstto_settings_init (GObject *object) { gchar *accelmap_path = NULL; RsttoSettings *settings = RSTTO_SETTINGS (object); settings->priv = g_new0 (RsttoSettingsPriv, 1); settings->priv->channel = xfconf_channel_new ("ristretto"); accelmap_path = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, "ristretto/accels.scm"); if (accelmap_path) { gtk_accel_map_load (accelmap_path); g_free (accelmap_path); accelmap_path = NULL; } else { /* If the accels.scm file is missing, we are probably * dealing with a first-boot. Add default accelerators. */ gtk_accel_map_change_entry ("<Window>/fullscreen", GDK_KEY_F, 0, FALSE); gtk_accel_map_change_entry ("<Window>/unfullscreen", GDK_KEY_Escape, 0, FALSE); gtk_accel_map_change_entry ("<Window>/next-image", GDK_KEY_Page_Down, 0, FALSE); gtk_accel_map_change_entry ("<Window>/previous-image", GDK_KEY_Page_Up, 0, FALSE); gtk_accel_map_change_entry ("<Window>/quit", GDK_KEY_q, 0, FALSE); gtk_accel_map_change_entry ("<Window>/delete", GDK_KEY_Delete, GDK_SHIFT_MASK, FALSE); gtk_accel_map_change_entry ("<Window>/refresh", GDK_KEY_r, GDK_CONTROL_MASK, FALSE); gtk_accel_map_change_entry ("<Actions>/RsttoWindow/play", GDK_KEY_F5, 0, FALSE); } settings->priv->slideshow_timeout = 5; settings->priv->bgcolor = g_new0 (GdkColor, 1); settings->priv->bgcolor_fullscreen = g_new0 (GdkColor, 1); settings->priv->navigationbar_position = g_strdup ("left"); settings->priv->show_toolbar = TRUE; settings->priv->window_width = 600; settings->priv->window_height = 440; settings->priv->wrap_images = TRUE; settings->priv->show_thumbnailbar = TRUE; settings->priv->show_statusbar = TRUE; settings->priv->use_thunar_properties = TRUE; settings->priv->maximize_on_startup = TRUE; settings->priv->hide_thumbnails_fullscreen = TRUE; settings->priv->errors.missing_thumbnailer = TRUE; settings->priv->thumbnail_size = THUMBNAIL_SIZE_NORMAL; xfconf_g_property_bind ( settings->priv->channel, "/window/width", G_TYPE_UINT, settings, "window-width"); xfconf_g_property_bind ( settings->priv->channel, "/window/height", G_TYPE_UINT, settings, "window-height"); xfconf_g_property_bind ( settings->priv->channel, "/file/current-uri", G_TYPE_STRING, settings, "current-uri"); xfconf_g_property_bind ( settings->priv->channel, "/window/toolbar/show", G_TYPE_BOOLEAN, settings, "show-toolbar"); xfconf_g_property_bind ( settings->priv->channel, "/window/navigationbar/sort-type", G_TYPE_UINT, settings, "sort-type"); xfconf_g_property_bind ( settings->priv->channel, "/window/navigationbar/position", G_TYPE_STRING, settings, "navigationbar-position"); xfconf_g_property_bind ( settings->priv->channel, "/window/thumbnails/show", G_TYPE_BOOLEAN, settings, "show-thumbnailbar"); xfconf_g_property_bind ( settings->priv->channel, "/window/statusbar/show", G_TYPE_BOOLEAN, settings, "show-statusbar"); xfconf_g_property_bind ( settings->priv->channel, "/window/thumbnails/size", G_TYPE_UINT, settings, "thumbnail-size"); xfconf_g_property_bind ( settings->priv->channel, "/window/thumbnails/hide-fullscreen", G_TYPE_BOOLEAN, settings, "hide-thumbnails-fullscreen"); xfconf_g_property_bind ( settings->priv->channel, "/slideshow/timeout", G_TYPE_UINT, settings, "slideshow-timeout"); xfconf_g_property_bind ( settings->priv->channel, "/window/bgcolor-override", G_TYPE_BOOLEAN, settings, "bgcolor-override"); xfconf_g_property_bind_gdkcolor ( settings->priv->channel, "/window/bgcolor", settings, "bgcolor"); xfconf_g_property_bind_gdkcolor ( settings->priv->channel, "/window/bgcolor-fullscreen", settings, "bgcolor-fullscreen"); xfconf_g_property_bind ( settings->priv->channel, "/window/invert-zoom-direction", G_TYPE_BOOLEAN, settings, "invert-zoom-direction"); xfconf_g_property_bind ( settings->priv->channel, "/window/show-clock", G_TYPE_BOOLEAN, settings, "show-clock"); xfconf_g_property_bind ( settings->priv->channel, "/image/wrap", G_TYPE_BOOLEAN, settings, "wrap-images"); xfconf_g_property_bind ( settings->priv->channel, "/image/limit-quality", G_TYPE_BOOLEAN, settings, "limit-quality"); xfconf_g_property_bind ( settings->priv->channel, "/window/use-thunar-properties", G_TYPE_BOOLEAN, settings, "use-thunar-properties"); xfconf_g_property_bind ( settings->priv->channel, "/window/maximize-on-startup", G_TYPE_BOOLEAN, settings, "maximize-on-startup"); xfconf_g_property_bind ( settings->priv->channel, "/errors/missing-thumbnailer", G_TYPE_BOOLEAN, settings, "show-error-missing-thumbnailer"); xfconf_g_property_bind ( settings->priv->channel, "/desktop/type", G_TYPE_STRING, settings, "desktop-type"); }
static void gimp_action_view_accel_edited (GtkCellRendererAccel *accel, const char *path_string, guint accel_key, GdkModifierType accel_mask, guint hardware_keycode, GimpActionView *view) { GtkAction *action; const gchar *accel_path; accel_path = gimp_action_view_get_accel_action (view, path_string, &action); if (! accel_path) return; if (! accel_key) { gimp_message_literal (view->manager->gimp, G_OBJECT (view), GIMP_MESSAGE_ERROR, _("Invalid shortcut.")); } else if (! gtk_accel_map_change_entry (accel_path, accel_key, accel_mask, FALSE)) { GtkTreeModel *model; GtkAction *conflict_action = NULL; GtkTreeIter iter; gboolean iter_valid; model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); for (iter_valid = gtk_tree_model_get_iter_first (model, &iter); iter_valid; iter_valid = gtk_tree_model_iter_next (model, &iter)) { GtkTreeIter child_iter; gboolean child_valid; for (child_valid = gtk_tree_model_iter_children (model, &child_iter, &iter); child_valid; child_valid = gtk_tree_model_iter_next (model, &child_iter)) { guint child_accel_key; GdkModifierType child_accel_mask; gtk_tree_model_get (model, &child_iter, GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY, &child_accel_key, GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK, &child_accel_mask, -1); if (accel_key == child_accel_key && accel_mask == child_accel_mask) { gtk_tree_model_get (model, &child_iter, GIMP_ACTION_VIEW_COLUMN_ACTION, &conflict_action, -1); break; } } if (conflict_action) break; } if (conflict_action != action) { if (conflict_action) { gimp_action_view_conflict_confirm (view, conflict_action, accel_key, accel_mask, accel_path); g_object_unref (conflict_action); } else { gimp_message_literal (view->manager->gimp, G_OBJECT (view), GIMP_MESSAGE_ERROR, _("Changing shortcut failed.")); } } } }
static void keys_change_notify (GSettings *settings, const gchar *key, gpointer user_data) { GVariant *val; KeyEntry *key_entry; GdkModifierType mask; guint keyval; _terminal_debug_print (TERMINAL_DEBUG_ACCELS, "key %s changed\n", key); val = g_settings_get_value (settings, key); #ifdef MATE_ENABLE_DEBUG _TERMINAL_DEBUG_IF (TERMINAL_DEBUG_ACCELS) { if (val == NULL) _terminal_debug_print (TERMINAL_DEBUG_ACCELS, " changed to be unset\n"); else if (!g_variant_is_of_type (val, G_VARIANT_TYPE_STRING)) _terminal_debug_print (TERMINAL_DEBUG_ACCELS, " changed to non-string value\n"); else _terminal_debug_print (TERMINAL_DEBUG_ACCELS, " changed to \"%s\"\n", g_variant_get_string (val, NULL)); } #endif key_entry = g_hash_table_lookup (gsettings_key_to_entry, key); if (!key_entry) { /* shouldn't really happen, but let's be safe */ _terminal_debug_print (TERMINAL_DEBUG_ACCELS, " WARNING: KeyEntry for changed key not found, bailing out\n"); return; } if (!binding_from_value (val, &keyval, &mask)) { const char *str = g_variant_is_of_type (val, G_VARIANT_TYPE_STRING) ? g_variant_get_string (val, NULL) : NULL; g_printerr ("The value \"%s\" of configuration key %s is not a valid accelerator\n", str ? str : "(null)", key_entry->gsettings_key); return; } key_entry->gsettings_keyval = keyval; key_entry->gsettings_mask = mask; /* Unlock the path, so we can change its accel */ if (!key_entry->accel_path_unlocked) gtk_accel_map_unlock_path (key_entry->accel_path); /* sync over to GTK */ _terminal_debug_print (TERMINAL_DEBUG_ACCELS, "changing path %s to %s\n", key_entry->accel_path, binding_name (keyval, mask)); /* memleak */ inside_gsettings_notify += 1; /* Note that this may return FALSE, e.g. when the entry was already set correctly. */ gtk_accel_map_change_entry (key_entry->accel_path, keyval, mask, TRUE); inside_gsettings_notify -= 1; /* Lock the path if the GSettings key isn't writable */ key_entry->accel_path_unlocked = g_settings_is_writable (settings, key); if (!key_entry->accel_path_unlocked) gtk_accel_map_lock_path (key_entry->accel_path); /* This seems necessary to update the tree model, since sometimes the * notification on the notification_group seems not to be emitted correctly. * Without this change, when trying to set an accel to e.g. Alt-T (while the main * menu in the terminal windows is _Terminal with Alt-T mnemonic) only displays * the accel change after a re-expose of the row. * FIXME: Find out *why* the accel-changed signal is wrong here! */ if (edit_keys_store) gtk_tree_model_foreach (GTK_TREE_MODEL (edit_keys_store), update_model_foreach, key_entry); g_variant_unref(val); }