From ade141aadcb6b1d33cb0401a5a99a8dee990c8d8 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Sat, 13 Nov 2010 12:40:48 +0100 Subject: [PATCH] Update buffer in the statusbar --- callbacks.c | 18 +++++++++++++++++- callbacks.h | 2 ++ config.c | 9 ++++++--- shortcuts.c | 21 +++++++++++++++++++++ zathura.c | 10 ++++++++++ zathura.h | 1 + 6 files changed, 57 insertions(+), 4 deletions(-) diff --git a/callbacks.c b/callbacks.c index 0b5f007..80506e4 100644 --- a/callbacks.c +++ b/callbacks.c @@ -2,14 +2,30 @@ #include #include +#include #include "zathura.h" gboolean cb_destroy(GtkWidget* widget, gpointer data) { - if(Zathura.UI.session) + if(Zathura.UI.session) { girara_session_destroy(Zathura.UI.session); + } return TRUE; } + +void +buffer_changed(girara_session_t* session) +{ + g_return_if_fail(session != NULL); + g_return_if_fail(Zathura.UI.buffer != NULL); + + char* buffer = girara_buffer_get(session); + + if(buffer) { + girara_statusbar_item_set_text(session, Zathura.UI.buffer, buffer); + free(buffer); + } +} diff --git a/callbacks.h b/callbacks.h index bc544f1..254d7e8 100644 --- a/callbacks.h +++ b/callbacks.h @@ -4,7 +4,9 @@ #define CALLBACKS_H #include +#include gboolean cb_destroy(GtkWidget* widget, gpointer data); +void buffer_changed(girara_session_t* session); #endif // CALLBACKS_H diff --git a/config.c b/config.c index 7f81bc9..c8ce721 100644 --- a/config.c +++ b/config.c @@ -9,12 +9,15 @@ config_load_default() if(!Zathura.UI.session) return; + /* general settings */ + girara_mode_set(Zathura.UI.session, NORMAL); + /* define default shortcuts */ - girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, ALL, 0, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, ALL, 0, NULL); + girara_shortcut_add(Zathura.UI.session, GDK_CONTROL_MASK, GDK_c, NULL, sc_abort, 0, 0, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_Escape, NULL, sc_abort, 0, 0, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_a, NULL, sc_adjust_window, NORMAL, ADJUST_BESTFIT, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_s, NULL, sc_adjust_window, NORMAL, ADJUST_WIDTH, NULL); - girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, ALL, DELETE_LAST, NULL); + girara_shortcut_add(Zathura.UI.session, 0, GDK_BackSpace, NULL, sc_change_buffer, 0, DELETE_LAST, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_i, NULL, sc_change_mode, NORMAL, INSERT, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_m, NULL, sc_change_mode, NORMAL, ADD_MARKER, NULL); girara_shortcut_add(Zathura.UI.session, 0, GDK_apostrophe, NULL, sc_change_mode, NORMAL, EVAL_MARKER, NULL); diff --git a/shortcuts.c b/shortcuts.c index b47db30..658595c 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -5,10 +5,15 @@ #include "callbacks.h" #include "shortcuts.h" +#include "zathura.h" bool sc_abort(girara_session_t* session, girara_argument_t* argument) { + g_return_val_if_fail(session != NULL, false); + + girara_mode_set(session, NORMAL); + return false; } @@ -27,12 +32,28 @@ sc_change_buffer(girara_session_t* session, girara_argument_t* argument) bool sc_change_mode(girara_session_t* session, girara_argument_t* argument) { + g_return_val_if_fail(session != NULL, false); + + girara_mode_set(session, argument->n); + return false; } bool sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument) { + g_return_val_if_fail(session != NULL, false); + + if(!(GTK_WIDGET_VISIBLE(GTK_WIDGET(session->gtk.inputbar)))) + gtk_widget_show(GTK_WIDGET(session->gtk.inputbar)); + + if(argument->data) + { + gtk_entry_set_text(session->gtk.inputbar, (char*) argument->data); + gtk_widget_grab_focus(GTK_WIDGET(session->gtk.inputbar)); + gtk_editable_set_position(GTK_EDITABLE(session->gtk.inputbar), -1); + } + return false; } diff --git a/zathura.c b/zathura.c index d8656e7..25dbeb7 100644 --- a/zathura.c +++ b/zathura.c @@ -15,9 +15,19 @@ init_zathura() if(!girara_session_init(Zathura.UI.session)) return false; + /* UI */ + Zathura.UI.buffer = girara_statusbar_item_add(Zathura.UI.session, FALSE, FALSE, FALSE, NULL); + if(!Zathura.UI.buffer) { + girara_session_destroy(Zathura.UI.session); + return false; + } + /* signals */ g_signal_connect(G_OBJECT(Zathura.UI.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); + /* girara events */ + Zathura.UI.session->events.buffer_changed = buffer_changed; + /* configuration */ config_load_default(); diff --git a/zathura.h b/zathura.h index 1a824fc..d74a202 100644 --- a/zathura.h +++ b/zathura.h @@ -26,6 +26,7 @@ struct struct { girara_session_t* session; /**> girara interface session */ + girara_statusbar_item_t* buffer; /**> buffer statusbar entry */ } UI; } Zathura;