gui: Move window keypress handling to window.cpp
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
253898e9b5
commit
acdeb785f5
54
gui/gui.cpp
54
gui/gui.cpp
|
@ -105,58 +105,6 @@ static void on_fav_toggled()
|
|||
|
||||
|
||||
|
||||
/*
|
||||
* Keyboard shortcuts
|
||||
*/
|
||||
static bool on_window_key_pressed(GdkEventKey *event)
|
||||
{
|
||||
Gtk::Notebook *notebook = lib :: get_widget<Gtk::Notebook>("o_notebook");
|
||||
Gtk::Window *window = lib :: get_widget<Gtk::Window>("o_window");
|
||||
std::string key = gdk_keyval_name(event->keyval);
|
||||
|
||||
if (key.size() >= 3) {
|
||||
if (key.substr(0, 3) == "KP_")
|
||||
key = key.substr(3);
|
||||
}
|
||||
|
||||
if (key == "Escape")
|
||||
window->set_focus(*window);
|
||||
else if (key == "slash")
|
||||
tab_focus_search();
|
||||
else if (key >= "0" && key <= "9") {
|
||||
unsigned int n = atoi(key.c_str());
|
||||
if (n < deck::get_queues().size())
|
||||
notebook->set_current_page(n);
|
||||
} else if (key == "c")
|
||||
notebook->set_current_page(deck::get_queues().size());
|
||||
else if (key == "h")
|
||||
notebook->set_current_page(deck::get_queues().size() + 1);
|
||||
else if (key == "m")
|
||||
notebook->set_current_page(deck::get_queues().size() + 3);
|
||||
else if (key == "n")
|
||||
o_next();
|
||||
else if (key == "N")
|
||||
audio :: prev();
|
||||
else if (key == "p")
|
||||
notebook->set_current_page(deck::get_queues().size() + 2);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool on_window_key_released(GdkEventKey *event)
|
||||
{
|
||||
std::string key = gdk_keyval_name(event->keyval);
|
||||
|
||||
if (key == "space")
|
||||
o_toggle();
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Idle func
|
||||
*/
|
||||
|
@ -213,8 +161,6 @@ Gtk::Window *setup_gui()
|
|||
/* Keyboard shortcuts */
|
||||
Gtk::Window *window = window_init();
|
||||
|
||||
window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed));
|
||||
window->signal_key_release_event().connect(sigc::ptr_fun(on_window_key_released));
|
||||
window->set_can_focus();
|
||||
window->set_icon_from_file(lib :: share_file("ocarina.png"));
|
||||
|
||||
|
|
|
@ -1,16 +1,69 @@
|
|||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <core/deck.h>
|
||||
#include <core/version.h>
|
||||
#include <gui/controls.h>
|
||||
#include <gui/ocarina.h>
|
||||
#include <gui/tabs.h>
|
||||
|
||||
const std::string appname = "Ocarina ";
|
||||
|
||||
static bool on_window_key_pressed(GdkEventKey *event)
|
||||
{
|
||||
Gtk::Notebook *notebook = lib :: get_widget<Gtk::Notebook>("o_notebook");
|
||||
Gtk::Window *window = lib :: get_widget<Gtk::Window>("o_window");
|
||||
std::string key = gdk_keyval_name(event->keyval);
|
||||
|
||||
if (key.size() >= 3) {
|
||||
if (key.substr(0, 3) == "KP_")
|
||||
key = key.substr(3);
|
||||
}
|
||||
|
||||
if (key == "Escape")
|
||||
window->set_focus(*window);
|
||||
else if (key == "slash")
|
||||
tab_focus_search();
|
||||
else if (key >= "0" && key <= "9") {
|
||||
unsigned int n = atoi(key.c_str());
|
||||
if (n < deck::get_queues().size())
|
||||
notebook->set_current_page(n);
|
||||
} else if (key == "c")
|
||||
notebook->set_current_page(deck::get_queues().size());
|
||||
else if (key == "h")
|
||||
notebook->set_current_page(deck::get_queues().size() + 1);
|
||||
else if (key == "m")
|
||||
notebook->set_current_page(deck::get_queues().size() + 3);
|
||||
else if (key == "n")
|
||||
o_next();
|
||||
else if (key == "N")
|
||||
audio :: prev();
|
||||
else if (key == "p")
|
||||
notebook->set_current_page(deck::get_queues().size() + 2);
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool on_window_key_released(GdkEventKey *event)
|
||||
{
|
||||
std::string key = gdk_keyval_name(event->keyval);
|
||||
|
||||
if (key == "space")
|
||||
o_toggle();
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Gtk::Window *window_init()
|
||||
{
|
||||
Gtk::Window *window = lib :: get_widget<Gtk::Window>("o_window");
|
||||
|
||||
window->set_title(appname + get_version());
|
||||
window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed));
|
||||
window->signal_key_release_event().connect(sigc::ptr_fun(on_window_key_released));
|
||||
|
||||
return window;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue