111 lines
3.1 KiB
C++
111 lines
3.1 KiB
C++
// Copyright (c) 2011 Bryan Schumaker
|
|
#include <version.h>
|
|
#include <audio.h>
|
|
#include <prefs.h>
|
|
#include "ocarina.h"
|
|
|
|
static int old_w, old_h;
|
|
static bool ignore_configure_event = false;
|
|
|
|
static gboolean configure(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|
{
|
|
int w = event->configure.width;
|
|
int h = event->configure.height;
|
|
int cur_w = libsaria::prefs::get("ocarina.window.w");
|
|
int cur_h = libsaria::prefs::get("ocarina.window.h");
|
|
|
|
if (ignore_configure_event == true) {
|
|
ignore_configure_event = false;
|
|
return FALSE;
|
|
}
|
|
|
|
if (w != cur_w)
|
|
libsaria::prefs::set("ocarina.window.w", w);
|
|
if (h != cur_h)
|
|
libsaria::prefs::set("ocarina.window.h", h);
|
|
return FALSE;
|
|
}
|
|
|
|
static void window_state(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|
{
|
|
bool maximized = libsaria::prefs::get("ocarina.window.maximized");
|
|
|
|
if (!(event->window_state.changed_mask & GDK_WINDOW_STATE_MAXIMIZED))
|
|
return;
|
|
|
|
maximized = event->window_state.new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
|
|
|
|
println("Maximization changed to: %d", maximized);
|
|
libsaria::prefs::set("ocarina.window.maximized", maximized);
|
|
ignore_configure_event = true;
|
|
if (maximized) {
|
|
println("Restoring old (w,h): (%d, %d)", old_w, old_h);
|
|
libsaria::prefs::set("ocarina.window.w", old_w);
|
|
libsaria::prefs::set("ocarina.window.h", old_h);
|
|
}
|
|
}
|
|
|
|
static gboolean key_pressed(GtkWindow *window, GdkEvent *event, gpointer data)
|
|
{
|
|
string key = gdk_keyval_name(event->key.keyval);
|
|
if (key.substr(0, 3) == "KP_")
|
|
key = key.substr(3);
|
|
|
|
if (playlist_key_press(key))
|
|
return TRUE;
|
|
|
|
if (key == "Escape") {
|
|
gtk_window_set_focus(window, NULL);
|
|
return TRUE;
|
|
}
|
|
|
|
if (playlist_entry_focused())
|
|
return FALSE;
|
|
|
|
/*
|
|
* TODO: something for banning / unbanning songs
|
|
* something for incrementing / decrementing the pause after N count
|
|
*/
|
|
if (key == "b" || key == "l" || key == "r") {
|
|
playlist_switch_to(key);
|
|
gtk_window_set_focus(window, NULL);
|
|
} else if (key == "j" || key == "k")
|
|
playlist_focus_treeview();
|
|
else if (key >= "0" && key <= "9")
|
|
playlist_switch_to_n(atoi(key.c_str()));
|
|
else if (key == "n")
|
|
libsaria::deck::next();
|
|
else if (key == "N")
|
|
libsaria::deck::prev();
|
|
else if (key == "slash")
|
|
playlist_focus_entry();
|
|
else if (key == "space")
|
|
libsaria::audio::toggle_play();
|
|
else if (key == "Return")
|
|
playlist_focus_treeview();
|
|
else {
|
|
println("Unhandled key: " + key);
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void init_window()
|
|
{
|
|
GtkWindow *window = GTK_WINDOW(get_widget("MainWindow"));
|
|
|
|
gtk_window_set_title(window, ("Ocarina " + vers_str()).c_str());
|
|
gtk_window_set_icon_from_file(window, lib_file("ocarina.png").c_str(), NULL);
|
|
|
|
old_h = libsaria::prefs::init("ocarina.window.h", 600);
|
|
old_w = libsaria::prefs::init("ocarina.window.w", 900);
|
|
gtk_window_resize(window, old_w, old_h);
|
|
if (libsaria::prefs::init("ocarina.window.maximized", false) == true)
|
|
gtk_window_maximize(window);
|
|
|
|
connect_signal("MainWindow", "destroy", gtk_main_quit, NULL);
|
|
connect_signal("MainWindow", "configure-event", G_CALLBACK(configure), NULL);
|
|
connect_signal("MainWindow", "window-state-event", G_CALLBACK(window_state), NULL);
|
|
connect_signal("MainWindow", "key-press-event", G_CALLBACK(key_pressed), NULL);
|
|
}
|