From d2f6c62591f64a795d10a8a92968c58eb7298e1d Mon Sep 17 00:00:00 2001 From: dusanx Date: Sun, 26 Apr 2009 22:01:41 +0200 Subject: Status bar --- uzbl.c | 84 ++++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 28 deletions(-) (limited to 'uzbl.c') diff --git a/uzbl.c b/uzbl.c index dca1bda..984e181 100644 --- a/uzbl.c +++ b/uzbl.c @@ -45,6 +45,7 @@ static GtkWidget* main_window; static GtkWidget* mainbar; +static GtkWidget* mainbar_label; static WebKitWebView* web_view; static gchar* main_title; static gchar selected_url[500]; @@ -55,6 +56,8 @@ static gchar* fifodir = NULL; static gchar* download_handler = NULL; static gboolean always_insert_mode = FALSE; static gboolean insert_mode = FALSE; +static gboolean show_status = FALSE; +static gboolean status_top = FALSE; static gchar* modkey = NULL; static char fifopath[64]; @@ -105,6 +108,16 @@ go_forward_cb (GtkWidget* widget, gpointer data) { webkit_web_view_go_forward (web_view); } +static void +cb_toggle_status() { + if (show_status) { + gtk_widget_hide(mainbar); + } else { + gtk_widget_show(mainbar); + } + show_status = !show_status; + update_title (GTK_WINDOW (main_window)); +} static void link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) { @@ -174,17 +187,18 @@ static Command commands[] = { "refresh", &webkit_web_view_reload, NULL }, //Buggy { "stop", &webkit_web_view_stop_loading, NULL }, { "zoom_in", &webkit_web_view_zoom_in, NULL }, //Can crash (when max zoom reached?). - { "zoom_out", &webkit_web_view_zoom_out, NULL } , - { "uri", NULL, &webkit_web_view_load_uri } + { "zoom_out", &webkit_web_view_zoom_out, NULL }, + { "uri", NULL, &webkit_web_view_load_uri }, + { "toggle_status", &cb_toggle_status, NULL} //{ "get uri", &webkit_web_view_get_uri}, }; /* -- CORE FUNCTIONS -- */ - + static void parse_command(const char *command) { int i; - Command *c; + Command *c = NULL; char * command_name = strtok (command, " "); char * command_param = strtok (NULL, " ,"); //dunno how this works, but it seems to work @@ -260,34 +274,35 @@ setup_threading () { static void update_title (GtkWindow* window) { - GString* string = g_string_new (""); + GString* string_long = g_string_new (""); + GString* string_short = g_string_new (""); if (!always_insert_mode) - g_string_append (string, (insert_mode ? "[I] " : "[C] ")); - g_string_append (string, main_title); - g_string_append (string, " - Uzbl browser"); + g_string_append (string_long, (insert_mode ? "[I] " : "[C] ")); + g_string_append (string_long, main_title); + g_string_append (string_short, main_title); + g_string_append (string_long, " - Uzbl browser"); + g_string_append (string_short, " - Uzbl browser"); if (load_progress < 100) - g_string_append_printf (string, " (%d%%)", load_progress); + g_string_append_printf (string_long, " (%d%%)", load_progress); if (selected_url[0]!=0) { - g_string_append_printf (string, " -> (%s)", selected_url); + g_string_append_printf (string_long, " -> (%s)", selected_url); } - gchar* title = g_string_free (string, FALSE); - gtk_window_set_title (window, title); - g_free (title); + gchar* title_long = g_string_free (string_long, FALSE); + gchar* title_short = g_string_free (string_short, FALSE); + + if (show_status) { + gtk_window_set_title (window, title_short); + gtk_label_set_text(mainbar_label, title_long); + } else { + gtk_window_set_title (window, title_long); + } + + g_free (title_long); + g_free (title_short); } -static void -MsgBox (const char *s) { - GtkWidget* dialog = gtk_message_dialog_new (main_window, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - "%s", s); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - static gboolean key_press_cb (WebKitWebView* page, GdkEventKey* event) { @@ -346,9 +361,10 @@ create_browser () { static GtkWidget* create_mainbar () { mainbar = gtk_hbox_new (FALSE, 0); - - //status_context_id = gtk_statusbar_get_context_id (main_statusbar, "Link Hover"); - + mainbar_label = gtk_label_new (""); + gtk_misc_set_alignment (mainbar_label, 0, 0); + gtk_misc_set_padding (mainbar_label, 2, 2); + gtk_box_pack_start (GTK_BOX (mainbar), mainbar_label, TRUE, TRUE, 0); return mainbar; } @@ -409,6 +425,12 @@ settings_init () { always_insert_mode = g_key_file_get_boolean (config, "behavior", "always_insert_mode", NULL); printf ("Always insert mode: %s\n", (always_insert_mode ? "TRUE" : "FALSE")); + show_status = g_key_file_get_boolean (config, "behavior", "show_status", NULL); + printf ("Show status: %s\n", (show_status ? "TRUE" : "FALSE")); + + status_top = g_key_file_get_boolean (config, "behavior", "status_top", NULL); + printf ("Status top: %s\n", (status_top ? "TRUE" : "FALSE")); + modkey = g_key_file_get_value (config, "behavior", "modkey", NULL); if (modkey) { printf ("Mod key: %s\n", modkey); @@ -445,8 +467,11 @@ main (int argc, char* argv[]) { insert_mode = TRUE; GtkWidget* vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0); + if (status_top) + gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), create_browser (), TRUE, TRUE, 0); + if (!status_top) + gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0); main_window = create_window (); gtk_container_add (GTK_CONTAINER (main_window), vbox); @@ -465,6 +490,9 @@ main (int argc, char* argv[]) { printf("window_id %i\n",(int) xwin); printf("pid %i\n", getpid ()); + if (!show_status) + gtk_widget_hide(mainbar); + setup_threading (); gtk_main (); -- cgit v1.2.3