From 53c38faa8a792a077dbc4c23219ee703e5fa3c8c Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Mon, 6 Jun 2011 12:07:26 +0200 Subject: Handle simple key events. * Use ctrl+w or ctrl+q or esc to quit. * Uset ctrl+1-5 to change tabs. --- src/mainwindow.cc | 33 +++++++++++++++++++++++++++++++++ src/mainwindow.h | 1 + 2 files changed, 34 insertions(+) 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; -- cgit v1.2.3