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;
25 static gboolean validate_key(const gchar *s);
27 void keybindings_setup_tab()
34 w = get_widget("chain_quit_key");
35 s = tree_get_string("keyboard/chainQuitKey", "C-g");
36 gtk_entry_set_text(GTK_ENTRY(w), s);
42 void on_chain_quit_key_focus_in(GtkEntry *w, gpointer data)
44 g_assert(saved_text == NULL);
45 saved_text = g_strdup(gtk_entry_get_text(w));
48 void on_chain_quit_key_focus_out(GtkEntry *w, gpointer data)
54 s = gtk_entry_get_text(w);
55 if (!validate_key(s)) {
56 g_print("bad key binding: %s\n", s);
57 gtk_entry_set_text(w, saved_text);
59 tree_set_string("keyboard/chainQuitKey", s);
65 static gboolean validate_key(const gchar *s)
68 const gchar *valid[] = { "Mod1", "Mod2", "Mod3", "Mod4", "Mod5",
69 "Control", "C", "Alt", "A", "Meta", "M",
70 "Super", "W", "Shift", "S", "Hyper", "H",
73 while ((next = strchr(s, '-'))) {
74 /* it's a modifier, validate it */
76 gboolean found = FALSE;
78 for (it = valid; *it && !found; ++it)
79 if (!g_ascii_strncasecmp(*it, s, strlen(*it)))
83 g_print("Invalid modifier\n");
87 s = next + 1; /* skip past the '-' */
89 /* we're at the real key part */
90 if (!gdk_keyval_from_name(s)) {
91 g_print("Invalid key: %s\n", s);