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