From d2f6c62591f64a795d10a8a92968c58eb7298e1d Mon Sep 17 00:00:00 2001 From: dusanx Date: Sun, 26 Apr 2009 22:01:41 +0200 Subject: Status bar --- sampleconfig | 4 ++- uzbl | Bin 29051 -> 29298 bytes uzbl.c | 84 +++++++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 59 insertions(+), 29 deletions(-) diff --git a/sampleconfig b/sampleconfig index 3a4bae1..9c7336b 100644 --- a/sampleconfig +++ b/sampleconfig @@ -16,6 +16,8 @@ download_handler = ./extra/download.sh fifo_dir = /tmp always_insert_mode = 0 modkey = Mod4 +show_status = 1 +status_top = 0 [bindings_internal] back = b @@ -29,7 +31,7 @@ follow_link_new_tab = F follow_link_new_window = w zoom_in = + zoom_out = - - +toggle_status = t [bindings_external] ./extra/insert_bookmark.sh = b diff --git a/uzbl b/uzbl index 1f8a0f8..4375960 100755 Binary files a/uzbl and b/uzbl differ 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 From c6fd63a3f2c68f4341f5392efcc07a9673470679 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Sun, 26 Apr 2009 21:05:11 +0100 Subject: Now checks in $XDG_CONFIG_HOME for a "uzbl" file if no config file is specified. Does not check $XDG_CONFIG_DIRS yet. --- uzbl.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/uzbl.c b/uzbl.c index ce1d190..47f5e22 100644 --- a/uzbl.c +++ b/uzbl.c @@ -214,12 +214,12 @@ run_command(const char *command, const char *args) { static void parse_command(const char *command) { - int i; - Command *c; + int i = 0; + Command *c = NULL; char * command_name = strtok (command, " "); char * command_param = strtok (NULL, " ,"); //dunno how this works, but it seems to work - Command *c_tmp; + Command *c_tmp = NULL; for (i = 0; i < LENGTH (commands); i++) { c_tmp = &commands[i]; if (strncmp (command_name, c_tmp->command, strlen (c_tmp->command)) == 0) { @@ -399,6 +399,14 @@ settings_init () { gboolean res = NULL; gchar** keysi = NULL; gchar** keyse = NULL; + + if (! config_file) { + char* conf = getenv ("XDG_CONFIG_HOME"); + strcat (conf, "/uzbl"); + if (file_exists (conf)) + strcpy(config_file conf); + } + if (config_file) { config = g_key_file_new (); res = g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, NULL); -- cgit v1.2.3 From 76fc5c64883180d496842577e05423d55306ae49 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Sun, 26 Apr 2009 21:10:13 +0100 Subject: Poked code a bit. Doesn't quite work. --- uzbl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/uzbl.c b/uzbl.c index 47f5e22..9ce5669 100644 --- a/uzbl.c +++ b/uzbl.c @@ -401,10 +401,16 @@ settings_init () { gchar** keyse = NULL; if (! config_file) { - char* conf = getenv ("XDG_CONFIG_HOME"); - strcat (conf, "/uzbl"); - if (file_exists (conf)) - strcpy(config_file conf); + char* xdg = getenv ("XDG_CONFIG_HOME"); + char* conf = NULL; + if (xdg) { + strcpy (conf, xdg); + strcat (conf, "/uzbl"); + if (file_exists (conf)) { + printf ("Config file %s found.", conf); + strcpy(config_file, conf); + } + } } if (config_file) { -- cgit v1.2.3 From ba822fa5366b4163fbfa4c2aee2ac8faedd95991 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Sun, 26 Apr 2009 21:27:34 +0100 Subject: Now checks in $XDG_CONFIG_HOME/uzbl if --config is omitted. --- uzbl.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/uzbl.c b/uzbl.c index 9ce5669..cd23048 100644 --- a/uzbl.c +++ b/uzbl.c @@ -401,14 +401,15 @@ settings_init () { gchar** keyse = NULL; if (! config_file) { - char* xdg = getenv ("XDG_CONFIG_HOME"); - char* conf = NULL; + const char* xdg = getenv ("XDG_CONFIG_HOME"); + char* conf[256]; if (xdg) { + printf("XDG_CONFIG_DIR: %s\n", xdg); strcpy (conf, xdg); strcat (conf, "/uzbl"); if (file_exists (conf)) { - printf ("Config file %s found.", conf); - strcpy(config_file, conf); + printf ("Config file %s found.\n", conf); + config_file = &conf; } } } -- cgit v1.2.3 From 7f1b7eb459e8c3a8607eaf3eb0dad864455e6544 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Sun, 26 Apr 2009 21:36:39 +0100 Subject: Fixed a bug (varuable declared twice). --- uzbl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/uzbl.c b/uzbl.c index 8e9dac5..abd0566 100644 --- a/uzbl.c +++ b/uzbl.c @@ -67,7 +67,6 @@ static gchar* download_handler = NULL; static gboolean always_insert_mode = FALSE; static gboolean show_status = FALSE; static gboolean insert_mode = FALSE; -static gboolean show_status = FALSE; static gboolean status_top = FALSE; static gchar* modkey = NULL; -- cgit v1.2.3