diff options
author | Colin Guthrie <colin@mageia.org> | 2011-06-06 12:07:26 +0200 |
---|---|---|
committer | Colin Guthrie <colin@mageia.org> | 2011-06-06 12:18:14 +0200 |
commit | 53c38faa8a792a077dbc4c23219ee703e5fa3c8c (patch) | |
tree | c08cc3848d82850cf635e002ccea7f0bfb20849b | |
parent | 933b8a7009f72bccb378ed018a6578ccd443e748 (diff) |
Handle simple key events.
* Use ctrl+w or ctrl+q or esc to quit.
* Uset ctrl+1-5 to change tabs.
-rw-r--r-- | src/mainwindow.cc | 33 | ||||
-rw-r--r-- | src/mainwindow.h | 1 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 6a7e04c..ac41831 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -159,6 +159,39 @@ void MainWindow::on_realize() { #endif /* HAVE_GTK3 */ } +bool MainWindow::on_key_press_event(GdkEventKey* event) { + + if (GDK_KEY_Escape == event->keyval) { + Gtk::Main::quit(); + return true; + } + if (event->state & GDK_CONTROL_MASK) { + switch (event->keyval) { + case GDK_KEY_KP_1: + case GDK_KEY_KP_2: + case GDK_KEY_KP_3: + case GDK_KEY_KP_4: + case GDK_KEY_KP_5: + notebook->set_current_page(event->keyval - GDK_KEY_KP_1); + return true; + case GDK_KEY_1: + case GDK_KEY_2: + case GDK_KEY_3: + case GDK_KEY_4: + case GDK_KEY_5: + notebook->set_current_page(event->keyval - GDK_KEY_1); + return true; + case GDK_KEY_W: + case GDK_KEY_Q: + case GDK_KEY_w: + case GDK_KEY_q: + Gtk::Main::quit(); + return true; + } + } + return Gtk::Window::on_key_press_event(event); +} + MainWindow::~MainWindow() { GKeyFile* config = g_key_file_new(); g_assert(config); diff --git a/src/mainwindow.h b/src/mainwindow.h index bad9e47..559b639 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -100,6 +100,7 @@ public: protected: virtual void on_realize(); + virtual bool on_key_press_event(GdkEventKey* event); private: gboolean m_connected; |