1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 keybindings.c for ObConf, the configuration tool for Openbox
4 Copyright (c) 2007 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
22 static gboolean mapping = FALSE;
23 static gchar *saved_text = NULL;
24 static GtkListStore *binding_store;
26 static gboolean validate_key(const gchar *s);
28 void keybindings_setup_tab()
31 GtkCellRenderer *render;
32 GtkTreeViewColumn *column;
33 GtkTreeSelection *select;
38 w = get_widget("chain_quit_key");
39 s = tree_get_string("keyboard/chainQuitKey", "C-g");
40 gtk_entry_set_text(GTK_ENTRY(w), s);
44 w = get_widget("key_bindings");
45 binding_store = gtk_list_store_new(2, G_TYPE_STRING, GTK_TYPE_COMBO_BOX);
46 gtk_tree_view_set_model(GTK_TREE_VIEW(w), GTK_TREE_MODEL(binding_store));
47 g_object_unref (binding_store);
49 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(w)),
50 GTK_SELECTION_SINGLE);
52 /* text column for the keys */
53 render = gtk_cell_renderer_text_new();
54 column = gtk_tree_view_column_new_with_attributes
55 ("Key", render, "text", 0, NULL);
56 gtk_tree_view_append_column(GTK_TREE_VIEW(w), column);
58 /* combo box column, for the actions */
59 render = gtk_cell_renderer_combo_new();
60 column = gtk_tree_view_column_new_with_attributes
61 ("Action", render, "text", 0, NULL);
62 gtk_tree_view_append_column(GTK_TREE_VIEW(w), column);
67 void on_chain_quit_key_focus_in(GtkEntry *w, gpointer data)
69 g_assert(saved_text == NULL);
70 saved_text = g_strdup(gtk_entry_get_text(w));
73 void on_chain_quit_key_focus_out(GtkEntry *w, gpointer data)
79 s = gtk_entry_get_text(w);
80 if (!validate_key(s)) {
81 g_print("bad key binding: %s\n", s);
82 gtk_entry_set_text(w, saved_text);
84 tree_set_string("keyboard/chainQuitKey", s);
90 static gboolean validate_key(const gchar *s)
93 const gchar *valid[] = { "Mod1", "Mod2", "Mod3", "Mod4", "Mod5",
94 "Control", "C", "Alt", "A", "Meta", "M",
95 "Super", "W", "Shift", "S", "Hyper", "H",
98 while ((next = strchr(s, '-'))) {
99 /* it's a modifier, validate it */
101 gboolean found = FALSE;
103 for (it = valid; *it && !found; ++it)
104 if (!g_ascii_strncasecmp(*it, s, strlen(*it)))
108 g_print("Invalid modifier\n");
112 s = next + 1; /* skip past the '-' */
114 /* we're at the real key part */
115 if (!gdk_keyval_from_name(s)) {
116 g_print("Invalid key: %s\n", s);