fb6a034ea76ae79d317f6160d7749bd268d9b3de
[ardour.git] / libs / gtkmm2ext / keyboard.cc
1 /*
2     Copyright (C) 2001 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <vector>
21
22 #include <algorithm>
23 #include <cerrno>
24 #include <ctype.h>
25
26 #include "pbd/gstdio_compat.h"
27
28 #include <gtkmm/widget.h>
29 #include <gtkmm/window.h>
30 #include <gtkmm/accelmap.h>
31 #include <gdk/gdkkeysyms.h>
32
33 #include "pbd/error.h"
34 #include "pbd/convert.h"
35 #include "pbd/file_utils.h"
36 #include "pbd/search_path.h"
37 #include "pbd/xml++.h"
38 #include "pbd/debug.h"
39 #include "pbd/unwind.h"
40
41 #include "gtkmm2ext/keyboard.h"
42 #include "gtkmm2ext/actions.h"
43 #include "gtkmm2ext/debug.h"
44
45 #include "i18n.h"
46
47 using namespace PBD;
48 using namespace Gtk;
49 using namespace Gtkmm2ext;
50 using namespace std;
51
52 guint Keyboard::edit_but = 3;
53 guint Keyboard::edit_mod = GDK_CONTROL_MASK;
54 guint Keyboard::delete_but = 3;
55 guint Keyboard::delete_mod = GDK_SHIFT_MASK;
56 guint Keyboard::insert_note_but = 1;
57 guint Keyboard::insert_note_mod = GDK_CONTROL_MASK;
58
59 #ifdef GTKOSX
60
61 uint Keyboard::PrimaryModifier = GDK_MOD2_MASK;   // Command
62 guint Keyboard::SecondaryModifier = GDK_CONTROL_MASK; // Control
63 guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK; // Shift
64 guint Keyboard::Level4Modifier = GDK_MOD1_MASK; // Alt/Option
65 guint Keyboard::CopyModifier = GDK_CONTROL_MASK;      // Control
66 guint Keyboard::RangeSelectModifier = GDK_SHIFT_MASK;
67 guint Keyboard::button2_modifiers = Keyboard::SecondaryModifier|Keyboard::Level4Modifier;
68
69 const char* Keyboard::primary_modifier_name() { return _("Command"); }
70 const char* Keyboard::secondary_modifier_name() { return _("Control"); }
71 const char* Keyboard::tertiary_modifier_name() { return S_("Key|Shift"); }
72 const char* Keyboard::level4_modifier_name() { return _("Option"); }
73 const char* Keyboard::copy_modifier_name() { return _("Control"); }
74 const char* Keyboard::rangeselect_modifier_name() { return S_("Key|Shift"); }
75
76 guint Keyboard::snap_mod = Keyboard::Level4Modifier|Keyboard::TertiaryModifier; // XXX this is probably completely wrong
77 guint Keyboard::snap_delta_mod = Keyboard::Level4Modifier;
78
79 #else
80
81 guint Keyboard::PrimaryModifier = GDK_CONTROL_MASK; // Control
82 guint Keyboard::SecondaryModifier = GDK_MOD1_MASK;  // Alt/Option
83 guint Keyboard::TertiaryModifier = GDK_SHIFT_MASK;  // Shift
84 guint Keyboard::Level4Modifier = GDK_MOD4_MASK;     // Mod4/Windows
85 guint Keyboard::CopyModifier = GDK_CONTROL_MASK;
86 guint Keyboard::RangeSelectModifier = GDK_SHIFT_MASK;
87 guint Keyboard::button2_modifiers = 0; /* not used */
88
89 const char* Keyboard::primary_modifier_name() { return _("Control"); }
90 const char* Keyboard::secondary_modifier_name() { return _("Alt"); }
91 const char* Keyboard::tertiary_modifier_name() { return S_("Key|Shift"); }
92 const char* Keyboard::level4_modifier_name() { return _("Windows"); }
93 const char* Keyboard::copy_modifier_name() { return _("Control"); }
94 const char* Keyboard::rangeselect_modifier_name() { return S_("Key|Shift"); }
95
96 guint Keyboard::snap_mod = Keyboard::SecondaryModifier;
97 guint Keyboard::snap_delta_mod = Keyboard::SecondaryModifier|Keyboard::Level4Modifier;
98
99 #endif
100
101 guint Keyboard::GainFineScaleModifier = Keyboard::PrimaryModifier;
102 guint Keyboard::GainExtraFineScaleModifier = Keyboard::SecondaryModifier;
103
104 guint Keyboard::ScrollZoomVerticalModifier = Keyboard::SecondaryModifier;
105 guint Keyboard::ScrollZoomHorizontalModifier = Keyboard::PrimaryModifier;
106 guint Keyboard::ScrollHorizontalModifier = Keyboard::TertiaryModifier;
107
108 Keyboard*    Keyboard::_the_keyboard = 0;
109 Gtk::Window* Keyboard::current_window = 0;
110 bool         Keyboard::_some_magic_widget_has_focus = false;
111
112 std::string Keyboard::user_keybindings_path;
113 bool Keyboard::can_save_keybindings = false;
114 bool Keyboard::bindings_changed_after_save_became_legal = false;
115 map<string,string> Keyboard::binding_files;
116 string Keyboard::_current_binding_name;
117 map<AccelKey,pair<string,string>,Keyboard::AccelKeyLess> Keyboard::release_keys;
118
119 /* set this to initially contain the modifiers we care about, then track changes in ::set_edit_modifier() etc. */
120
121 GdkModifierType Keyboard::RelevantModifierKeyMask;
122
123 void
124 Keyboard::magic_widget_grab_focus ()
125 {
126         _some_magic_widget_has_focus = true;
127 }
128
129 void
130 Keyboard::magic_widget_drop_focus ()
131 {
132         _some_magic_widget_has_focus = false;
133 }
134
135 bool
136 Keyboard::some_magic_widget_has_focus ()
137 {
138         return _some_magic_widget_has_focus;
139 }
140
141 Keyboard::Keyboard ()
142 {
143         if (_the_keyboard == 0) {
144                 _the_keyboard = this;
145                 _current_binding_name = _("Unknown");
146         }
147
148         RelevantModifierKeyMask = (GdkModifierType) gtk_accelerator_get_default_mod_mask ();
149
150         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | PrimaryModifier);
151         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | SecondaryModifier);
152         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | TertiaryModifier);
153         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | Level4Modifier);
154         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | CopyModifier);
155         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | RangeSelectModifier);
156
157         gtk_accelerator_set_default_mod_mask (RelevantModifierKeyMask);
158
159         snooper_id = gtk_key_snooper_install (_snooper, (gpointer) this);
160 }
161
162 Keyboard::~Keyboard ()
163 {
164         gtk_key_snooper_remove (snooper_id);
165 }
166
167 XMLNode&
168 Keyboard::get_state (void)
169 {
170         XMLNode* node = new XMLNode ("Keyboard");
171         char buf[32];
172
173         snprintf (buf, sizeof (buf), "%d", CopyModifier);
174         node->add_property ("copy-modifier", buf);
175         snprintf (buf, sizeof (buf), "%d", edit_but);
176         node->add_property ("edit-button", buf);
177         snprintf (buf, sizeof (buf), "%d", edit_mod);
178         node->add_property ("edit-modifier", buf);
179         snprintf (buf, sizeof (buf), "%d", delete_but);
180         node->add_property ("delete-button", buf);
181         snprintf (buf, sizeof (buf), "%d", delete_mod);
182         node->add_property ("delete-modifier", buf);
183         snprintf (buf, sizeof (buf), "%d", snap_mod);
184         node->add_property ("snap-modifier", buf);
185         snprintf (buf, sizeof (buf), "%d", snap_delta_mod);
186         node->add_property ("snap-delta-modifier", buf);
187         snprintf (buf, sizeof (buf), "%d", insert_note_but);
188         node->add_property ("insert-note-button", buf);
189         snprintf (buf, sizeof (buf), "%d", insert_note_mod);
190         node->add_property ("insert-note-modifier", buf);
191
192         return *node;
193 }
194
195 int
196 Keyboard::set_state (const XMLNode& node, int /*version*/)
197 {
198         const XMLProperty* prop;
199
200         if ((prop = node.property ("copy-modifier")) != 0) {
201                 sscanf (prop->value().c_str(), "%d", &CopyModifier);
202         }
203
204         if ((prop = node.property ("edit-button")) != 0) {
205                 sscanf (prop->value().c_str(), "%d", &edit_but);
206         }
207
208         if ((prop = node.property ("edit-modifier")) != 0) {
209                 sscanf (prop->value().c_str(), "%d", &edit_mod);
210         }
211
212         if ((prop = node.property ("delete-button")) != 0) {
213                 sscanf (prop->value().c_str(), "%d", &delete_but);
214         }
215
216         if ((prop = node.property ("delete-modifier")) != 0) {
217                 sscanf (prop->value().c_str(), "%d", &delete_mod);
218         }
219
220         if ((prop = node.property ("snap-modifier")) != 0) {
221                 sscanf (prop->value().c_str(), "%d", &snap_mod);
222         }
223
224         if ((prop = node.property ("snap-delta-modifier")) != 0) {
225                 sscanf (prop->value().c_str(), "%d", &snap_delta_mod);
226         }
227
228         if ((prop = node.property ("insert-note-button")) != 0) {
229                 sscanf (prop->value().c_str(), "%d", &insert_note_but);
230         }
231
232         if ((prop = node.property ("insert-note-modifier")) != 0) {
233                 sscanf (prop->value().c_str(), "%d", &insert_note_mod);
234         }
235
236         return 0;
237 }
238
239 gint
240 Keyboard::_snooper (GtkWidget *widget, GdkEventKey *event, gpointer data)
241 {
242         return ((Keyboard *) data)->snooper (widget, event);
243 }
244
245 gint
246 Keyboard::snooper (GtkWidget *widget, GdkEventKey *event)
247 {
248         uint32_t keyval;
249         bool ret = false;
250
251         DEBUG_TRACE (
252                 DEBUG::Keyboard,
253                 string_compose (
254                         "Snoop widget %1 name: [%6] key %2 type %3 state %4 magic %5\n",
255                         widget, event->keyval, event->type, event->state, _some_magic_widget_has_focus,
256                         gtk_widget_get_name (widget)
257                         )
258                 );
259
260         if (event->keyval == GDK_Shift_R) {
261                 keyval = GDK_Shift_L;
262
263         } else if (event->keyval == GDK_Control_R) {
264                 keyval = GDK_Control_L;
265
266         } else {
267                 keyval = event->keyval;
268         }
269
270         if (event->state & ScrollZoomVerticalModifier) {
271                 /* There is a special and rather hacky situation in Editor which makes
272                    it useful to know when the modifier key for vertical zoom has been
273                    released, so emit a signal here (see Editor::_stepping_axis_view).
274                    Note that the state bit for the modifier key is set for the key-up
275                    event when the modifier is released, but not the key-down when it
276                    is pressed, so we get here on key-up, which is what we want.
277                 */
278                 ZoomVerticalModifierReleased (); /* EMIT SIGNAL */
279         }
280
281         if (event->type == GDK_KEY_PRESS) {
282
283                 if (find (state.begin(), state.end(), keyval) == state.end()) {
284                         state.push_back (keyval);
285                         sort (state.begin(), state.end());
286
287                 } else {
288
289                         /* key is already down. if its also used for release,
290                            prevent auto-repeat events.
291                         */
292
293                         for (map<AccelKey,two_strings,AccelKeyLess>::iterator k = release_keys.begin(); k != release_keys.end(); ++k) {
294
295                                 const AccelKey& ak (k->first);
296
297                                 if (keyval == ak.get_key() && (Gdk::ModifierType)((event->state & Keyboard::RelevantModifierKeyMask) | Gdk::RELEASE_MASK) == ak.get_mod()) {
298                                         DEBUG_TRACE (DEBUG::Keyboard, "Suppress auto repeat\n");
299                                         ret = true;
300                                         break;
301                                 }
302                         }
303                 }
304
305         } else if (event->type == GDK_KEY_RELEASE) {
306
307                 State::iterator i;
308
309                 if ((i = find (state.begin(), state.end(), keyval)) != state.end()) {
310                         state.erase (i);
311                         sort (state.begin(), state.end());
312                 }
313
314                 for (map<AccelKey,two_strings,AccelKeyLess>::iterator k = release_keys.begin(); k != release_keys.end(); ++k) {
315
316                         const AccelKey& ak (k->first);
317                         two_strings ts (k->second);
318
319                         if (keyval == ak.get_key() && (Gdk::ModifierType)((event->state & Keyboard::RelevantModifierKeyMask) | Gdk::RELEASE_MASK) == ak.get_mod()) {
320                                 Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (ts.first.c_str(), ts.second.c_str());
321                                 if (act) {
322                                         DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Activate %1 %2\n", ts.first, ts.second));
323                                         act->activate();
324                                         DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Use repeat, suppress other\n", ts.first, ts.second));
325                                         ret = true;
326                                 }
327                                 break;
328                         }
329                 }
330         }
331
332         /* Special keys that we want to handle in
333            any dialog, no matter whether it uses
334            the regular set of accelerators or not
335         */
336
337         if (event->type == GDK_KEY_RELEASE && modifier_state_equals (event->state, PrimaryModifier)) {
338                 switch (event->keyval) {
339                 case GDK_w:
340                         close_current_dialog ();
341                         ret = true;
342                         break;
343                 }
344         }
345
346         DEBUG_TRACE (DEBUG::Keyboard, string_compose ("snooper returns %1\n", ret));
347
348         return ret;
349 }
350
351 void
352 Keyboard::close_current_dialog ()
353 {
354         if (current_window) {
355                 current_window->hide ();
356                 current_window = 0;
357         }
358 }
359
360 bool
361 Keyboard::key_is_down (uint32_t keyval)
362 {
363         return find (state.begin(), state.end(), keyval) != state.end();
364 }
365
366 bool
367 Keyboard::enter_window (GdkEventCrossing *, Gtk::Window* win)
368 {
369         current_window = win;
370         DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Entering window, title = %1\n", win->get_title()));
371         return false;
372 }
373
374 bool
375 Keyboard::leave_window (GdkEventCrossing *ev, Gtk::Window* /*win*/)
376 {
377         if (ev) {
378                 switch (ev->detail) {
379                 case GDK_NOTIFY_INFERIOR:
380                         DEBUG_TRACE (DEBUG::Keyboard, "INFERIOR crossing ... out\n");
381                         break;
382
383                 case GDK_NOTIFY_VIRTUAL:
384                         DEBUG_TRACE (DEBUG::Keyboard, "VIRTUAL crossing ... out\n");
385                         /* fallthru */
386
387                 default:
388                         DEBUG_TRACE (DEBUG::Keyboard, "REAL crossing ... out\n");
389                         DEBUG_TRACE (DEBUG::Keyboard, "Clearing current target\n");
390                         state.clear ();
391                         current_window = 0;
392                 }
393         } else {
394                 current_window = 0;
395         }
396
397         return false;
398 }
399
400 bool
401 Keyboard::focus_in_window (GdkEventFocus *, Gtk::Window* win)
402 {
403         current_window = win;
404         DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Focusing in window, title = %1\n", win->get_title()));
405         return false;
406 }
407
408 bool
409 Keyboard::focus_out_window (GdkEventFocus * ev, Gtk::Window* win)
410 {
411         if (ev) {
412                 state.clear ();
413                 current_window = 0;
414         }  else {
415                 current_window = 0;
416         }
417
418         DEBUG_TRACE (DEBUG::Keyboard, string_compose ("Foucusing out window, title = %1\n", win->get_title()));
419
420         return false;
421 }
422
423 void
424 Keyboard::set_edit_button (guint but)
425 {
426         edit_but = but;
427 }
428
429 void
430 Keyboard::set_edit_modifier (guint mod)
431 {
432         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask & ~edit_mod);
433         edit_mod = mod;
434         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | edit_mod);
435 }
436
437 void
438 Keyboard::set_delete_button (guint but)
439 {
440         delete_but = but;
441 }
442
443 void
444 Keyboard::set_delete_modifier (guint mod)
445 {
446         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask & ~delete_mod);
447         delete_mod = mod;
448         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | delete_mod);
449 }
450
451 void
452 Keyboard::set_insert_note_button (guint but)
453 {
454         insert_note_but = but;
455 }
456
457 void
458 Keyboard::set_insert_note_modifier (guint mod)
459 {
460         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask & ~insert_note_mod);
461         insert_note_mod = mod;
462         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | insert_note_mod);
463 }
464
465
466 void
467 Keyboard::set_modifier (uint32_t newval, uint32_t& var)
468 {
469         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask & ~var);
470         var = newval;
471         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | var);
472 }
473
474 void
475 Keyboard::set_snap_modifier (guint mod)
476 {
477         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask & ~snap_mod);
478         snap_mod = mod;
479         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | snap_mod);
480 }
481
482 void
483 Keyboard::set_snap_delta_modifier (guint mod)
484 {
485         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask & ~snap_delta_mod);
486         snap_delta_mod = mod;
487         RelevantModifierKeyMask = GdkModifierType (RelevantModifierKeyMask | snap_delta_mod);
488 }
489
490 bool
491 Keyboard::is_edit_event (GdkEventButton *ev)
492 {
493         return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) &&
494                 (ev->button == Keyboard::edit_button()) &&
495                 ((ev->state & RelevantModifierKeyMask) == Keyboard::edit_modifier());
496 }
497
498 bool
499 Keyboard::is_insert_note_event (GdkEventButton *ev)
500 {
501         return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) &&
502                 (ev->button == Keyboard::insert_note_button()) &&
503                 ((ev->state & RelevantModifierKeyMask) == Keyboard::insert_note_modifier());
504 }
505
506 bool
507 Keyboard::is_button2_event (GdkEventButton* ev)
508 {
509 #ifdef GTKOSX
510         return (ev->button == 2) ||
511                 ((ev->button == 1) &&
512                  ((ev->state & Keyboard::button2_modifiers) == Keyboard::button2_modifiers));
513 #else
514         return ev->button == 2;
515 #endif
516 }
517
518 bool
519 Keyboard::is_delete_event (GdkEventButton *ev)
520 {
521         return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) &&
522                 (ev->button == Keyboard::delete_button()) &&
523                 ((ev->state & RelevantModifierKeyMask) == Keyboard::delete_modifier());
524 }
525
526 bool
527 Keyboard::is_context_menu_event (GdkEventButton *ev)
528 {
529         return (ev->type == GDK_BUTTON_PRESS || ev->type == GDK_BUTTON_RELEASE) &&
530                 (ev->button == 3) &&
531                 ((ev->state & RelevantModifierKeyMask) == 0);
532 }
533
534 bool
535 Keyboard::no_modifiers_active (guint state)
536 {
537         return (state & RelevantModifierKeyMask) == 0;
538 }
539
540 bool
541 Keyboard::modifier_state_contains (guint state, ModifierMask mask)
542 {
543         return (state & mask) == (guint) mask;
544 }
545
546 bool
547 Keyboard::modifier_state_equals (guint state, ModifierMask mask)
548 {
549         return (state & RelevantModifierKeyMask) == (guint) mask;
550 }
551
552 void
553 Keyboard::keybindings_changed ()
554 {
555         if (Keyboard::can_save_keybindings) {
556                 Keyboard::bindings_changed_after_save_became_legal = true;
557         }
558
559         Keyboard::save_keybindings ();
560 }
561
562 void
563 Keyboard::set_can_save_keybindings (bool yn)
564 {
565         can_save_keybindings = yn;
566 }
567
568 void
569 Keyboard::save_keybindings ()
570 {
571         if (can_save_keybindings && bindings_changed_after_save_became_legal) {
572                 Gtk::AccelMap::save (user_keybindings_path);
573         }
574 }
575
576 bool
577 Keyboard::load_keybindings (string path)
578 {
579         try {
580                 info << "Loading bindings from " << path << endl;
581
582                 Gtk::AccelMap::load (path);
583
584                 _current_binding_name = _("Unknown");
585
586                 for (map<string,string>::iterator x = binding_files.begin(); x != binding_files.end(); ++x) {
587                         if (path == x->second) {
588                                 _current_binding_name = x->first;
589                                 break;
590                         }
591                 }
592
593
594         } catch (...) {
595                 error << string_compose (_("key bindings file not found at \"%2\" or contains errors."), path)
596                       << endmsg;
597                 return false;
598         }
599
600         /* now find all release-driven bindings */
601
602         vector<string> groups;
603         vector<string> names;
604         vector<string> tooltips;
605         vector<AccelKey> bindings;
606
607         ActionManager::get_all_actions (groups, names, tooltips, bindings);
608
609         vector<string>::iterator g;
610         vector<AccelKey>::iterator b;
611         vector<string>::iterator n;
612
613         release_keys.clear ();
614
615         for (n = names.begin(), b = bindings.begin(), g = groups.begin(); n != names.end(); ++n, ++b, ++g) {
616                 stringstream s;
617                 s << "Action: " << *n << " Group: " << *g << " Binding: ";
618
619                 if ((*b).get_key() != GDK_VoidSymbol) {
620                         s << b->get_key() << " w/mod " << hex << b->get_mod() << dec << " = " << b->get_abbrev () << "\n";
621                 } else {
622                         s << "unbound\n";
623                 }
624
625                 DEBUG_TRACE (DEBUG::Bindings, s.str ());
626         }
627
628         for (n = names.begin(), b = bindings.begin(), g = groups.begin(); n != names.end(); ++n, ++b, ++g) {
629                 if ((*b).get_mod() & Gdk::RELEASE_MASK) {
630                         release_keys.insert (pair<AccelKey,two_strings> (*b, two_strings (*g, *n)));
631                 }
632         }
633
634         return true;
635 }
636
637 int
638 Keyboard::reset_bindings ()
639 {
640         if (Glib::file_test (user_keybindings_path,  Glib::FILE_TEST_EXISTS)) {
641
642                 string new_path = user_keybindings_path;
643                 new_path += ".old";
644
645                 if (::g_rename (user_keybindings_path.c_str(), new_path.c_str())) {
646                         error << string_compose (_("Cannot rename your own keybinding file (%1)"), strerror (errno)) << endmsg;
647                         return -1;
648                 }
649         }
650
651         {
652                 PBD::Unwinder<bool> uw (can_save_keybindings, false);
653                 setup_keybindings ();
654         }
655
656         return 0;
657 }