From e1bff5432860622327dc8d81b8f9ef374588c5cb Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 30 Nov 2010 20:20:02 -0700 Subject: remove parseenv(). it's not documented, it doesn't do anything that @(echo $X)@ can't, and it's not very efficient (it iterates through the entire environment every time an event is sent) --- src/uzbl-core.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/uzbl-core.h') diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b5a502e..6c926c6 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -228,9 +228,6 @@ itos(int val); gchar* strfree(gchar *str); -gchar* -parseenv (gchar* string); - void clean_up(void); -- cgit v1.2.3 From 4fbba2d523ba65b2dad15cf264eb168157cf0f15 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 29 Nov 2010 20:11:54 -0700 Subject: remove the positional arguments entirely (breaks backward compatibility) --- examples/config/config | 8 ++-- examples/data/scripts/auth.py | 2 +- examples/data/scripts/scheme.py | 2 +- src/uzbl-core.c | 90 +++++++++++++++-------------------------- src/uzbl-core.h | 4 +- 5 files changed, 41 insertions(+), 65 deletions(-) (limited to 'src/uzbl-core.h') diff --git a/examples/config/config b/examples/config/config index 22414ad..3c1a2fe 100644 --- a/examples/config/config +++ b/examples/config/config @@ -47,7 +47,7 @@ set authentication_handler = sync_spawn @scripts_dir/auth.py # === Dynamic event handlers ================================================= # Open link in new window -@on_event NEW_WINDOW sh 'uzbl-browser ${8:+-u "$8"}' %r +@on_event NEW_WINDOW sh 'uzbl-browser ${1:+-u "$1"}' %r # Open in current window #@on_event NEW_WINDOW uri %s # Open in new tab @@ -181,7 +181,7 @@ set ebind = @mode_bind global,-insert # --- Mouse bindings --------------------------------------------------------- # Middle click open in new window -@bind = sh 'if [ "$8" ]; then uzbl-browser -u "$8"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' \@SELECTED_URI +@bind = sh 'if [ "$1" ]; then uzbl-browser -u "$1"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"; fi' \@SELECTED_URI # --- Keyboard bindings ------------------------------------------------------ @@ -268,9 +268,9 @@ set ebind = @mode_bind global,-insert # Yanking & pasting binds @cbind yu = sh 'echo -n "$UZBL_URI" | xclip' -@cbind yU = sh 'echo -n $8 | xclip' \@SELECTED_URI +@cbind yU = sh 'echo -n "$1" | xclip' \@SELECTED_URI @cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip' -@cbind yY = sh 'echo -n $8 | xclip' \@SELECTED_URI +@cbind yY = sh 'echo -n "$1" | xclip' \@SELECTED_URI # Clone current window @cbind c = sh 'uzbl-browser -u "$UZBL_URI"' diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py index 9c1b4fc..592a2c6 100755 --- a/examples/data/scripts/auth.py +++ b/examples/data/scripts/auth.py @@ -46,7 +46,7 @@ def getText(authInfo, authHost, authRealm): return rv, output if __name__ == '__main__': - rv, output = getText(sys.argv[8], sys.argv[9], sys.argv[10]) + rv, output = getText(sys.argv[1], sys.argv[2], sys.argv[3]) if (rv == gtk.RESPONSE_OK): print output; else: diff --git a/examples/data/scripts/scheme.py b/examples/data/scripts/scheme.py index 0916466..4b0b7ca 100755 --- a/examples/data/scripts/scheme.py +++ b/examples/data/scripts/scheme.py @@ -13,7 +13,7 @@ def detach_open(cmd): print 'USED' if __name__ == '__main__': - uri = sys.argv[8] + uri = sys.argv[1] u = urlparse.urlparse(uri) if u.scheme == 'mailto': detach_open(['xterm', '-e', 'mail', u.path]) diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 3a04027..dcdd4c7 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -1209,30 +1209,19 @@ sharg_append(GArray *a, const gchar *str) { g_array_append_val(a, s); } -// make sure that the args string you pass can properly be interpreted (eg properly escaped against whitespace, quotes etc) +/* make sure that the args string you pass can properly be interpreted (eg + * properly escaped against whitespace, quotes etc) */ gboolean -run_command (const gchar *command, const guint npre, const gchar **args, - const gboolean sync, char **output_stdout) { - //command [args] +run_command (const gchar *command, const gchar **args, const gboolean sync, + char **output_stdout) { GError *err = NULL; GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); - gchar *pid = itos(getpid()); - gchar *xwin = itos(uzbl.xwin); guint i; sharg_append(a, command); - for (i = 0; i < npre; i++) /* add n args before the default vars */ - sharg_append(a, args[i]); - sharg_append(a, uzbl.state.config_file); - sharg_append(a, pid); - sharg_append(a, xwin); - sharg_append(a, uzbl.comm.fifo_path); - sharg_append(a, uzbl.comm.socket_path); - sharg_append(a, uzbl.state.uri); - sharg_append(a, uzbl.gui.main_title); - - for (i = npre; i < g_strv_length((gchar**)args); i++) + + for (i = 0; i < g_strv_length((gchar**)args); i++) sharg_append(a, args[i]); gboolean result; @@ -1263,8 +1252,6 @@ run_command (const gchar *command, const guint npre, const gchar **args, g_printerr("error on run_command: %s\n", err->message); g_error_free (err); } - g_free (pid); - g_free (xwin); g_array_free (a, TRUE); return result; } @@ -1307,75 +1294,64 @@ split_quoted(const gchar* src, const gboolean unquote) { } void -spawn(WebKitWebView *web_view, GArray *argv, GString *result) { - (void)web_view; (void)result; +_spawn(GArray *argv, char **output_stdout) { gchar *path = NULL; + gchar *arg_car = argv_idx(argv, 0); + const gchar **arg_cdr = &g_array_index(argv, const gchar *, 1); - //TODO: allow more control over argument order so that users can have some arguments before the default ones from run_command, and some after - if (argv_idx(argv, 0) && - ((path = find_existing_file(argv_idx(argv, 0)))) ) { - run_command(path, 0, - ((const gchar **) (argv->data + sizeof(gchar*))), - FALSE, NULL); + if (arg_car && (path = find_existing_file(arg_car))) { + run_command(path, arg_cdr, (output_stdout != NULL), output_stdout); g_free(path); } } void -spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - gchar *path = NULL; - if (argv_idx(argv, 0) && - ((path = find_existing_file(argv_idx(argv, 0)))) ) { - run_command(path, 0, - ((const gchar **) (argv->data + sizeof(gchar*))), - TRUE, &uzbl.comm.sync_stdout); - g_free(path); - } + _spawn(argv, NULL); } void -spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; + + _spawn(argv, &uzbl.comm.sync_stdout); +} + +void +_spawn_sh(GArray *argv, char **output_stdout) { if (!uzbl.behave.shell_cmd) { g_printerr ("spawn_sh: shell_cmd is not set!\n"); return; } - guint i; - gchar *spacer = g_strdup(""); - g_array_insert_val(argv, 1, spacer); + gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE); + gchar *cmdname = g_strdup(cmd[0]); + g_array_insert_val(argv, 1, cmdname); for (i = 1; i < g_strv_length(cmd); i++) g_array_prepend_val(argv, cmd[i]); - if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, FALSE, NULL); - g_free (spacer); + if (cmd) run_command(cmd[0], (const gchar **) argv->data, + (output_stdout != NULL), output_stdout); + g_free (cmdname); g_strfreev (cmd); } void -spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - if (!uzbl.behave.shell_cmd) { - g_printerr ("spawn_sh_sync: shell_cmd is not set!\n"); - return; - } - guint i; - gchar *spacer = g_strdup(""); - g_array_insert_val(argv, 1, spacer); - gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE); + _spawn_sh(argv, NULL); +} - for (i = 1; i < g_strv_length(cmd); i++) - g_array_prepend_val(argv, cmd[i]); +void +spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) { + (void)web_view; (void)result; - if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, - TRUE, &uzbl.comm.sync_stdout); - g_free (spacer); - g_strfreev (cmd); + _spawn_sh(argv, &uzbl.comm.sync_stdout); } void diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b5a502e..412d9fc 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -262,8 +262,8 @@ void close_uzbl (WebKitWebView *page, GArray *argv, GString *result); gboolean -run_command(const gchar *command, const guint npre, - const gchar **args, const gboolean sync, char **output_stdout); +run_command(const gchar *command, const gchar **args, const gboolean sync, + char **output_stdout); void spawn(WebKitWebView *web_view, GArray *argv, GString *result); -- cgit v1.2.3 From 59adc0787f7b77922c671964e471d0fd2dd7fc90 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Fri, 3 Dec 2010 13:47:09 -0700 Subject: let webkit handle downloads (breaks backward compatibility) --- README | 9 ++- examples/config/config | 1 + examples/data/scripts/download.sh | 34 +++++------ src/callbacks.c | 125 ++++++++++++++++++++++++++++++++++++-- src/callbacks.h | 5 +- src/events.c | 7 ++- src/events.h | 3 +- src/uzbl-core.c | 1 + src/uzbl-core.h | 1 + 9 files changed, 154 insertions(+), 32 deletions(-) (limited to 'src/uzbl-core.h') diff --git a/README b/README index 34556f2..6dddb35 100644 --- a/README +++ b/README @@ -668,8 +668,13 @@ Events have this format: * `EVENT [uzbl_instance_name] TITLE_CHANGED title_name`: When the title of the page (and hence maybe, the window title) changed. `title_name` is the new title. -* `EVENT [uzbl_instance_name] DOWNLOAD_REQUEST download_uri`: When content needs - to be downloaded, `download_uri` is the URI to get. +* `EVENT [uzbl_instance_name] DOWNLOAD_STARTED destination_path`: A download + has been started, the file will be saved to `destination_path`. +* `EVENT [uzbl_instance_name] DOWNLOAD_PROGRESS destination_path progress`: + While a download is active this event notifies you of the progress. + `progress` is a decimal between 0 and 1. +* `EVENT [uzbl_instance_name] DOWNLOAD_COMPLETE destination_path`: The + download being saved to `destination_path` is now complete. * `EVENT [uzbl_instance_name] LINK_HOVER uri`: The mouse hovers over the link `uri`. * `EVENT [uzbl_instance_name] LINK_UNHOVER uri`: The mouse leaves the link diff --git a/examples/config/config b/examples/config/config index 855f7c2..64e1c94 100644 --- a/examples/config/config +++ b/examples/config/config @@ -43,6 +43,7 @@ set scripts_dir = $XDG_DATA_HOME/uzbl:@prefix/share/uzbl/examples/data:scri set cookie_handler = talk_to_socket $XDG_CACHE_HOME/uzbl/cookie_daemon_socket set scheme_handler = sync_spawn @scripts_dir/scheme.py set authentication_handler = sync_spawn @scripts_dir/auth.py +set download_handler = sync_spawn @scripts_dir/download.sh # === Dynamic event handlers ================================================= diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh index 606aa62..c6d95f7 100755 --- a/examples/data/scripts/download.sh +++ b/examples/data/scripts/download.sh @@ -1,26 +1,26 @@ #!/bin/sh -# just an example of how you could handle your downloads -# try some pattern matching on the uri to determine what we should do +# +# uzbl's example configuration sets this script up as its download_handler. +# when uzbl starts a download it runs this script. +# if the script prints a file path to stdout, uzbl will save the download to +# that path. +# if nothing is printed to stdout, the download will be cancelled. . $UZBL_UTIL_DIR/uzbl-args.sh . $UZBL_UTIL_DIR/uzbl-dir.sh -# Some sites block the default wget --user-agent.. -GET="wget --user-agent=Firefox --content-disposition --load-cookies=$UZBL_COOKIE_JAR" +# the URL that is being downloaded +uri=$1 -url="$1" +# a filename suggested by the server or based on the URL +suggested_filename=${2:-$(echo "$uri" | sed 's/\W/-/g')} -http_proxy="$2" -export http_proxy +# the mimetype of the file being downloaded +content_type=$3 -if [ -z "$url" ]; then - echo "you must supply a url! ($url)" - exit 1 -fi +# the size of the downloaded file in bytes. this is not always accurate, since +# the server might not have sent a size with its response headers. +total_size=$4 -# only changes the dir for the $get sub process -if echo "$url" | grep -E '.*\.torrent' >/dev/null; then - ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") -else - ( cd "$UZBL_DOWNLOAD_DIR"; $GET "$url") -fi +# just save the file to the default directory with the suggested name +echo $UZBL_DOWNLOAD_DIR/$suggested_filename diff --git a/src/callbacks.c b/src/callbacks.c index f596472..803428d 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -771,13 +771,128 @@ create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer us return NULL; } +void +download_progress_cb(WebKitDownload *download, GParamSpec *pspec, gpointer user_data) { + (void) pspec; (void) user_data; + + gdouble progress; + g_object_get(download, "progress", &progress, NULL); + + const gchar *dest_uri = webkit_download_get_destination_uri(download); + const gchar *dest_path = dest_uri + strlen("file://"); + + gchar *details = g_strdup_printf("%s %.2lf", dest_path, progress); + send_event(DOWNLOAD_PROGRESS, details, NULL); + g_free(details); +} + +void +download_status_cb(WebKitDownload *download, GParamSpec *pspec, gpointer user_data) { + (void) pspec; (void) user_data; + + WebKitDownloadStatus status; + g_object_get(download, "status", &status, NULL); + + switch(status) { + case WEBKIT_DOWNLOAD_STATUS_CREATED: + case WEBKIT_DOWNLOAD_STATUS_STARTED: + case WEBKIT_DOWNLOAD_STATUS_ERROR: + case WEBKIT_DOWNLOAD_STATUS_CANCELLED: + return; /* these are irrelevant */ + case WEBKIT_DOWNLOAD_STATUS_FINISHED: + { + const gchar *dest_uri = webkit_download_get_destination_uri(download); + const gchar *dest_path = dest_uri + strlen("file://"); + send_event(DOWNLOAD_COMPLETE, dest_path, NULL); + } + } +} + gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) { - (void) web_view; - (void) user_data; +download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_data) { + (void) web_view; (void) user_data; - send_event(DOWNLOAD_REQ, webkit_download_get_uri ((WebKitDownload*)download), NULL); - return (FALSE); + /* get the URI being downloaded */ + const gchar *uri = webkit_download_get_uri(download); + + if (uzbl.state.verbose) + printf("Download requested -> %s\n", uri); + + if (!uzbl.behave.download_handler) { + webkit_download_cancel(download); + return FALSE; /* reject downloads when there's no download handler */ + } + + /* get a reasonable suggestion for a filename */ + const gchar *suggested_filename; + g_object_get(download, "suggested-filename", &suggested_filename, NULL); + + /* get the mimetype of the download */ + const gchar *content_type; + WebKitNetworkResponse *r = webkit_download_get_network_response(download); + /* downloads can be initiated from the context menu, in that case there is + no network response yet and trying to get one would crash. */ + if(WEBKIT_IS_NETWORK_RESPONSE(r)) { + SoupMessage *m = webkit_network_response_get_message(r); + SoupMessageHeaders *h; + g_object_get(m, "response-headers", &h, NULL); + content_type = soup_message_headers_get_one(h, "Content-Type"); + } else + content_type = "application/octet-stream"; + + /* get the filesize of the download, as given by the server. + (this may be inaccurate, there's nothing we can do about that.) */ + unsigned int total_size = webkit_download_get_total_size(download); + + gchar *ev = g_strdup_printf("'%s' '%s' '%s' %d", uri, suggested_filename, + content_type, total_size); + run_handler(uzbl.behave.download_handler, ev); + g_free(ev); + + /* no response, cancel the download */ + if(!uzbl.comm.sync_stdout) { + webkit_download_cancel(download); + return FALSE; + } + + /* no response, cancel the download */ + if(uzbl.comm.sync_stdout[0] == 0) { + webkit_download_cancel(download); + uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); + return FALSE; + } + + /* we got a response, it's the path we should download the file to */ + gchar *destination_path = uzbl.comm.sync_stdout; + uzbl.comm.sync_stdout = NULL; + + /* presumably people don't need newlines in their filenames. */ + char *p = strchr(destination_path, '\n'); + if ( p != NULL ) *p = '\0'; + + /* set up progress callbacks */ + g_signal_connect(download, "notify::status", G_CALLBACK(download_status_cb), NULL); + g_signal_connect(download, "notify::progress", G_CALLBACK(download_progress_cb), NULL); + + /* convert relative path to absolute path */ + if(destination_path[0] != '/') { + gchar *rel_path = destination_path; + gchar *cwd = g_get_current_dir(); + destination_path = g_strconcat(cwd, "/", destination_path, NULL); + g_free(cwd); + g_free(rel_path); + } + + send_event(DOWNLOAD_STARTED, destination_path, NULL); + + /* convert absolute path to file:// URI */ + gchar *destination_uri = g_strconcat("file://", destination_path, NULL); + g_free(destination_path); + + webkit_download_set_destination_uri(download, destination_uri); + g_free(destination_uri); + + return TRUE; } gboolean diff --git a/src/callbacks.h b/src/callbacks.h index a4258f2..40fa80d 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -133,9 +133,6 @@ cmd_load_start(); WebKitWebSettings* view_settings(); -gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); - void toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result); @@ -197,7 +194,7 @@ request_starting_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitWebRes create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data); gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); +download_cb (WebKitWebView *web_view, WebKitDownload *download, gpointer user_data); void populate_popup_cb(WebKitWebView *v, GtkMenu *m, void *c); diff --git a/src/events.c b/src/events.c index 20e3675..55775a8 100644 --- a/src/events.c +++ b/src/events.c @@ -22,7 +22,6 @@ const char *event_table[LAST_EVENT] = { "REQUEST_STARTING" , "KEY_PRESS" , "KEY_RELEASE" , - "DOWNLOAD_REQUEST" , "COMMAND_EXECUTED" , "LINK_HOVER" , "TITLE_CHANGED" , @@ -45,10 +44,12 @@ const char *event_table[LAST_EVENT] = { "PLUG_CREATED" , "COMMAND_ERROR" , "BUILTINS" , - "PTR_MOVE" "PTR_MOVE" , "SCROLL_VERT" , - "SCROLL_HORIZ" + "SCROLL_HORIZ" , + "DOWNLOAD_STARTED" , + "DOWNLOAD_PROGRESS", + "DOWNLOAD_COMPLETE" }; void diff --git a/src/events.h b/src/events.h index bc7960d..4b04dd2 100644 --- a/src/events.h +++ b/src/events.h @@ -7,7 +7,7 @@ enum event_type { LOAD_START, LOAD_COMMIT, LOAD_FINISH, LOAD_ERROR, REQUEST_STARTING, - KEY_PRESS, KEY_RELEASE, DOWNLOAD_REQ, COMMAND_EXECUTED, + KEY_PRESS, KEY_RELEASE, COMMAND_EXECUTED, LINK_HOVER, TITLE_CHANGED, GEOMETRY_CHANGED, WEBINSPECTOR, NEW_WINDOW, SELECTION_CHANGED, VARIABLE_SET, FIFO_SET, SOCKET_SET, @@ -16,6 +16,7 @@ enum event_type { FOCUS_LOST, FOCUS_GAINED, FILE_INCLUDED, PLUG_CREATED, COMMAND_ERROR, BUILTINS, PTR_MOVE, SCROLL_VERT, SCROLL_HORIZ, + DOWNLOAD_STARTED, DOWNLOAD_PROGRESS, DOWNLOAD_COMPLETE, /* must be last entry */ LAST_EVENT diff --git a/src/uzbl-core.c b/src/uzbl-core.c index cb20fd7..c960936 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -93,6 +93,7 @@ const struct var_name_to_ptr_t { { "cookie_handler", PTR_V_STR(uzbl.behave.cookie_handler, 1, cmd_set_cookie_handler)}, { "authentication_handler", PTR_V_STR(uzbl.behave.authentication_handler, 1, set_authentication_handler)}, { "scheme_handler", PTR_V_STR(uzbl.behave.scheme_handler, 1, NULL)}, + { "download_handler", PTR_V_STR(uzbl.behave.download_handler, 1, NULL)}, { "fifo_dir", PTR_V_STR(uzbl.behave.fifo_dir, 1, cmd_fifo_dir)}, { "socket_dir", PTR_V_STR(uzbl.behave.socket_dir, 1, cmd_socket_dir)}, { "http_debug", PTR_V_INT(uzbl.behave.http_debug, 1, cmd_http_debug)}, diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b5a502e..a62c3a6 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -133,6 +133,7 @@ typedef struct { gchar* fantasy_font_family; gchar* cursive_font_family; gchar* scheme_handler; + gchar* download_handler; gboolean show_status; gboolean forward_keys; gboolean status_top; -- cgit v1.2.3 From 04a5223d6abb42c42acc31c8b50ed11a049c59db Mon Sep 17 00:00:00 2001 From: keis Date: Tue, 30 Nov 2010 21:45:57 +0100 Subject: cookies rework * send events on cookie changes * add command to add a new cookie parses same syntax as events no ADD_COOKIE event is raised for these cookies * add command to delete a cookie parses same syntax as events, ignoring everything after 5th argument no DELETE_COOKIE event is raised for these cookies --- src/cookie-jar.c | 26 +++++++++++++++++++++++--- src/cookie-jar.h | 1 + src/events.c | 4 +++- src/events.h | 1 + src/uzbl-core.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/uzbl-core.h | 6 ++++++ 6 files changed, 88 insertions(+), 5 deletions(-) (limited to 'src/uzbl-core.h') diff --git a/src/cookie-jar.c b/src/cookie-jar.c index f2e340b..626e454 100644 --- a/src/cookie-jar.c +++ b/src/cookie-jar.c @@ -12,6 +12,7 @@ #include "cookie-jar.h" #include "uzbl-core.h" +#include "events.h" static void uzbl_cookie_jar_session_feature_init(SoupSessionFeatureInterface *iface, gpointer user_data); @@ -38,6 +39,8 @@ soup_cookie_jar_socket_init(UzblCookieJar *jar) { jar->handler = NULL; jar->socket_path = NULL; jar->connection_fd = -1; + jar->in_get_callback = 0; + jar->in_manual_add = 0; } static void @@ -141,7 +144,7 @@ request_started(SoupSessionFeature *feature, SoupSession *session, static void changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) { - (void) old_cookie; + SoupCookie * cookie = new_cookie ? new_cookie : old_cookie; UzblCookieJar *uzbl_jar = UZBL_COOKIE_JAR(jar); @@ -155,6 +158,25 @@ changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) { if(uzbl_jar->in_get_callback) return; + gchar *scheme = cookie->secure ? "https" : "http"; + + /* send a ADD or DELETE -_COOKIE event depending on what have changed */ + if(!uzbl_jar->in_manual_add) { + gchar *expires = NULL; + if(cookie->expires) + expires = g_strdup_printf ("%d", soup_date_to_time_t (cookie->expires)); + + gchar * eventstr = g_strdup_printf ("'%s' '%s' '%s' '%s' '%s' '%s'", + cookie->domain, cookie->path, cookie->name, cookie->value, scheme, expires?expires:""); + if(new_cookie) + send_event(ADD_COOKIE, eventstr, NULL); + else + send_event(DELETE_COOKIE, eventstr, NULL); + g_free(eventstr); + if(expires) + g_free(expires); + } + /* the cookie daemon is only interested in new cookies and changed ones, it can take care of deleting expired cookies on its own. */ if(!new_cookie) @@ -162,8 +184,6 @@ changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) { GString *s = g_string_new ("PUT"); - gchar *scheme = new_cookie->secure ? "https" : "http"; - if(has_socket_handler(uzbl_jar)) { g_string_append_c(s, 0); /* null-terminate the PUT */ g_string_append_len(s, scheme, strlen(scheme)+1); diff --git a/src/cookie-jar.h b/src/cookie-jar.h index 80af00e..f3e3733 100644 --- a/src/cookie-jar.h +++ b/src/cookie-jar.h @@ -16,6 +16,7 @@ typedef struct { int connection_fd; gboolean in_get_callback; + gboolean in_manual_add; } UzblCookieJar; typedef struct { diff --git a/src/events.c b/src/events.c index b02cb89..baaf8f3 100644 --- a/src/events.c +++ b/src/events.c @@ -49,7 +49,9 @@ const char *event_table[LAST_EVENT] = { "SCROLL_HORIZ" , "DOWNLOAD_STARTED" , "DOWNLOAD_PROGRESS", - "DOWNLOAD_COMPLETE" + "DOWNLOAD_COMPLETE", + "ADD_COOKIE" , + "DELETE_COOKIE" }; void diff --git a/src/events.h b/src/events.h index 4b04dd2..3c7b933 100644 --- a/src/events.h +++ b/src/events.h @@ -17,6 +17,7 @@ enum event_type { PLUG_CREATED, COMMAND_ERROR, BUILTINS, PTR_MOVE, SCROLL_VERT, SCROLL_HORIZ, DOWNLOAD_STARTED, DOWNLOAD_PROGRESS, DOWNLOAD_COMPLETE, + ADD_COOKIE, DELETE_COOKIE, /* must be last entry */ LAST_EVENT diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 1fc8593..eb340e0 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -613,7 +613,9 @@ struct {const char *key; CommandInfo value;} cmdlist[] = { "menu_editable_remove", {menu_remove_edit, TRUE} }, { "hardcopy", {hardcopy, TRUE} }, { "include", {include, TRUE} }, - { "show_inspector", {show_inspector, 0} } + { "show_inspector", {show_inspector, 0} }, + { "add_cookie", {add_cookie, 0} }, + { "delete_cookie", {delete_cookie, 0} } }; void @@ -907,6 +909,57 @@ show_inspector(WebKitWebView *page, GArray *argv, GString *result) { webkit_web_inspector_show(uzbl.gui.inspector); } +void +add_cookie(WebKitWebView *page, GArray *argv, GString *result) { + (void) page; (void) result; + gchar *host, *path, *name, *value; + gboolean http_only = 0, secure = 0; + SoupDate *expires = NULL; + + if(argv->len != 6) + return; + + // Parse with same syntax as ADD_COOKIE event + host = argv_idx (argv, 0); + path = argv_idx (argv, 1); + name = argv_idx (argv, 2); + value = argv_idx (argv, 3); + secure = strcmp (argv_idx (argv, 4), "https") == 0; + if (strlen (argv_idx (argv, 5)) != 0) + expires = soup_date_new_from_time_t ( + strtoul (argv_idx (argv, 5), NULL, 10)); + + // Create new cookie + SoupCookie * cookie = soup_cookie_new (name, value, host, path, -1); + soup_cookie_set_secure (cookie, secure); + if (expires) + soup_cookie_set_expires (cookie, expires); + + // Add cookie to jar + uzbl.net.soup_cookie_jar->in_manual_add = 1; + soup_cookie_jar_add_cookie (SOUP_COOKIE_JAR (uzbl.net.soup_cookie_jar), cookie); + uzbl.net.soup_cookie_jar->in_manual_add = 0; +} + +void +delete_cookie(WebKitWebView *page, GArray *argv, GString *result) { + (void) page; (void) result; + + if(argv->len < 4) + return; + + SoupCookie * cookie = soup_cookie_new ( + argv_idx (argv, 2), + argv_idx (argv, 3), + argv_idx (argv, 0), + argv_idx (argv, 1), + 0); + + uzbl.net.soup_cookie_jar->in_manual_add = 1; + soup_cookie_jar_delete_cookie (SOUP_COOKIE_JAR (uzbl.net.soup_cookie_jar), cookie); + uzbl.net.soup_cookie_jar->in_manual_add = 0; +} + void act_dump_config() { dump_config(); diff --git a/src/uzbl-core.h b/src/uzbl-core.h index b521f93..098cc95 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -451,6 +451,12 @@ include(WebKitWebView *page, GArray *argv, GString *result); void show_inspector(WebKitWebView *page, GArray *argv, GString *result); +void +add_cookie(WebKitWebView *page, GArray *argv, GString *result); + +void +delete_cookie(WebKitWebView *page, GArray *argv, GString *result); + void builtins(); -- cgit v1.2.3 From d080d45c79ae77abaef06ea99eb0a8969c8dffe3 Mon Sep 17 00:00:00 2001 From: keis Date: Fri, 17 Dec 2010 22:53:12 +0100 Subject: refactor spawn-functions added generic functions spawn and spawn_sh wrapped by spawn_sync,spawn_async,spawn_sh_sync and spawn_sh_async --- src/uzbl-core.c | 59 +++++++++++++++++++++++---------------------------------- src/uzbl-core.h | 4 ++-- 2 files changed, 26 insertions(+), 37 deletions(-) (limited to 'src/uzbl-core.h') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index eb340e0..e0d31f7 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -583,9 +583,9 @@ struct {const char *key; CommandInfo value;} cmdlist[] = { "js", {run_js, TRUE} }, { "script", {run_external_js, 0} }, { "toggle_status", {toggle_status_cb, 0} }, - { "spawn", {spawn, 0} }, + { "spawn", {spawn_async, 0} }, { "sync_spawn", {spawn_sync, 0} }, // needed for cookie handler - { "sh", {spawn_sh, 0} }, + { "sh", {spawn_sh_async, 0} }, { "sync_sh", {spawn_sh_sync, 0} }, // needed for cookie handler { "exit", {close_uzbl, 0} }, { "search", {search_forward_text, TRUE} }, @@ -1313,37 +1313,33 @@ split_quoted(const gchar* src, const gboolean unquote) { } void -spawn(WebKitWebView *web_view, GArray *argv, GString *result) { - (void)web_view; (void)result; +spawn(GArray *argv, gboolean sync) { gchar *path = NULL; //TODO: allow more control over argument order so that users can have some arguments before the default ones from run_command, and some after if (argv_idx(argv, 0) && ((path = find_existing_file(argv_idx(argv, 0)))) ) { run_command(path, 0, - ((const gchar **) (argv->data + sizeof(gchar*))), - FALSE, NULL); + ((const gchar **) (argv->data + sizeof(gchar*))), + sync, sync?&uzbl.comm.sync_stdout:NULL); g_free(path); } } void -spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn_async(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - gchar *path = NULL; - - if (argv_idx(argv, 0) && - ((path = find_existing_file(argv_idx(argv, 0)))) ) { - run_command(path, 0, - ((const gchar **) (argv->data + sizeof(gchar*))), - TRUE, &uzbl.comm.sync_stdout); - g_free(path); - } + spawn(argv, FALSE); } void -spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; + spawn(argv, TRUE); +} + +void +spawn_sh(GArray *argv, gboolean sync) { if (!uzbl.behave.shell_cmd) { g_printerr ("spawn_sh: shell_cmd is not set!\n"); return; @@ -1357,31 +1353,24 @@ spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result) { for (i = 1; i < g_strv_length(cmd); i++) g_array_prepend_val(argv, cmd[i]); - if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, FALSE, NULL); + if (cmd) + run_command(cmd[0], g_strv_length(cmd) + 1, + (const gchar **) argv->data, + sync, sync?&uzbl.comm.sync_stdout:NULL); g_free (spacer); g_strfreev (cmd); } void -spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) { +spawn_sh_async(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - if (!uzbl.behave.shell_cmd) { - g_printerr ("spawn_sh_sync: shell_cmd is not set!\n"); - return; - } - - guint i; - gchar *spacer = g_strdup(""); - g_array_insert_val(argv, 1, spacer); - gchar **cmd = split_quoted(uzbl.behave.shell_cmd, TRUE); - - for (i = 1; i < g_strv_length(cmd); i++) - g_array_prepend_val(argv, cmd[i]); + spawn_sh(argv, FALSE); +} - if (cmd) run_command(cmd[0], g_strv_length(cmd) + 1, (const gchar **) argv->data, - TRUE, &uzbl.comm.sync_stdout); - g_free (spacer); - g_strfreev (cmd); +void +spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) { + (void)web_view; (void)result; + spawn_sh(argv, TRUE); } void diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 098cc95..f7cc993 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -264,10 +264,10 @@ run_command(const gchar *command, const guint npre, const gchar **args, const gboolean sync, char **output_stdout); void -spawn(WebKitWebView *web_view, GArray *argv, GString *result); +spawn_async(WebKitWebView *web_view, GArray *argv, GString *result); void -spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result); +spawn_sh_async(WebKitWebView *web_view, GArray *argv, GString *result); void spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result); -- cgit v1.2.3 From 29c15cf845d41ff4aa3cf2cb4d30a83c14485070 Mon Sep 17 00:00:00 2001 From: keis Date: Fri, 17 Dec 2010 23:23:57 +0100 Subject: add sync_spawn_exec command this command will execute the lines written by the program as uzbl-commands --- src/uzbl-core.c | 23 ++++++++++++++++++++--- src/uzbl-core.h | 3 +++ 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src/uzbl-core.h') diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 2a88e76..03741de 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -585,6 +585,7 @@ struct {const char *key; CommandInfo value;} cmdlist[] = { "toggle_status", {toggle_status_cb, 0} }, { "spawn", {spawn_async, 0} }, { "sync_spawn", {spawn_sync, 0} }, // needed for cookie handler + { "sync_spawn_exec", {spawn_sync_exec, 0} }, // needed for load_cookies.sh :( { "sh", {spawn_sh_async, 0} }, { "sync_sh", {spawn_sh_sync, 0} }, // needed for cookie handler { "exit", {close_uzbl, 0} }, @@ -1313,7 +1314,7 @@ split_quoted(const gchar* src, const gboolean unquote) { } void -spawn(GArray *argv, gboolean sync) { +spawn(GArray *argv, gboolean sync, gboolean exec) { gchar *path = NULL; //TODO: allow more control over argument order so that users can have some arguments before the default ones from run_command, and some after @@ -1324,6 +1325,16 @@ spawn(GArray *argv, gboolean sync) { run_command(path, 0, ((const gchar **) (argv->data + sizeof(gchar*))), sync, sync?&uzbl.comm.sync_stdout:NULL); + // run each line of output from the program as a command + if (sync && exec && uzbl.comm.sync_stdout) { + gchar *head = uzbl.comm.sync_stdout; + gchar *tail; + while (tail = strchr (head, '\n')) { + *tail = '\0'; + parse_cmd_line(head, NULL); + head = tail + 1; + } + } g_free(path); } } @@ -1331,13 +1342,19 @@ spawn(GArray *argv, gboolean sync) { void spawn_async(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - spawn(argv, FALSE); + spawn(argv, FALSE, FALSE); } void spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) { (void)web_view; (void)result; - spawn(argv, TRUE); + spawn(argv, TRUE, FALSE); +} + +void +spawn_sync_exec(WebKitWebView *web_view, GArray *argv, GString *result) { + (void)web_view; (void)result; + spawn(argv, TRUE, TRUE); } void diff --git a/src/uzbl-core.h b/src/uzbl-core.h index f7cc993..98ae342 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -275,6 +275,9 @@ spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result); void spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result); +void +spawn_sync_exec(WebKitWebView *web_view, GArray *argv, GString *result); + void parse_command(const char *cmd, const char *param, GString *result); -- cgit v1.2.3 From 6a357cfa2b005cd594ba1183c71531acd4b09556 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 27 Dec 2010 09:44:25 -0700 Subject: add an ifdef for GTK3 scrollable changes --- src/callbacks.c | 4 ++-- src/uzbl-core.c | 33 ++++++++++++++++++++++----------- src/uzbl-core.h | 3 +++ 3 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src/uzbl-core.h') diff --git a/src/callbacks.c b/src/callbacks.c index ee6cf58..673979e 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -324,8 +324,8 @@ cmd_scrollbars_visibility() { uzbl.gui.bar_v = gtk_range_get_adjustment (GTK_RANGE (uzbl.gui.scbar_v)); uzbl.gui.bar_h = gtk_range_get_adjustment (GTK_RANGE (uzbl.gui.scbar_h)); } - gtk_scrollable_set_hadjustment (GTK_SCROLLABLE(uzbl.gui.web_view), uzbl.gui.bar_h); - gtk_scrollable_set_vadjustment (GTK_SCROLLABLE(uzbl.gui.web_view), uzbl.gui.bar_v); + + set_webview_scroll_adjustments(); } /* requires webkit >=1.1.14 */ diff --git a/src/uzbl-core.c b/src/uzbl-core.c index cc680c2..73ed5c6 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -2277,6 +2277,27 @@ retrieve_geometry() { uzbl.gui.geometry = g_string_free(buf, FALSE); } +void +set_webview_scroll_adjustments() { +#ifdef GTK3 + gtk_scrollable_set_hadjustment (GTK_SCROLLABLE(uzbl.gui.web_view), uzbl.gui.bar_h); + gtk_scrollable_set_vadjustment (GTK_SCROLLABLE(uzbl.gui.web_view), uzbl.gui.bar_v); +#else + gtk_widget_set_scroll_adjustments (GTK_WIDGET (uzbl.gui.web_view), + uzbl.gui.bar_h, uzbl.gui.bar_v); +#endif + + g_object_connect((GObject*)uzbl.gui.bar_v, + "signal::value-changed", (GCallback)scroll_vert_cb, NULL, + "signal::changed", (GCallback)scroll_vert_cb, NULL, + NULL); + + g_object_connect((GObject*)uzbl.gui.bar_h, + "signal::value-changed", (GCallback)scroll_horiz_cb, NULL, + "signal::changed", (GCallback)scroll_horiz_cb, NULL, + NULL); +} + /* set up gtk, gobject, variable defaults and other things that tests and other * external applications need to do anyhow */ void @@ -2418,18 +2439,8 @@ main (int argc, char* argv[]) { uzbl.gui.bar_v = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_v); uzbl.gui.scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL); uzbl.gui.bar_h = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_h); - gtk_scrollable_set_hadjustment (GTK_SCROLLABLE(uzbl.gui.web_view), uzbl.gui.bar_h); - gtk_scrollable_set_vadjustment (GTK_SCROLLABLE(uzbl.gui.web_view), uzbl.gui.bar_v); - g_object_connect((GObject*)uzbl.gui.bar_v, - "signal::value-changed", (GCallback)scroll_vert_cb, NULL, - "signal::changed", (GCallback)scroll_vert_cb, NULL, - NULL); - - g_object_connect((GObject*)uzbl.gui.bar_h, - "signal::value-changed", (GCallback)scroll_horiz_cb, NULL, - "signal::changed", (GCallback)scroll_horiz_cb, NULL, - NULL); + set_webview_scroll_adjustments(); gchar *xwin = g_strdup_printf("%d", (int)uzbl.xwin); g_setenv("UZBL_XID", xwin, TRUE); diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 98ae342..097fbfc 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -397,6 +397,9 @@ dump_config_as_events(); void retrieve_geometry(); +void +set_webview_scroll_adjustments(); + void event(WebKitWebView *page, GArray *argv, GString *result); -- cgit v1.2.3 From 0f3d7ef6f8150e30ebab28895ddb4c4c3beefb8c Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 3 Jan 2011 10:52:41 -0700 Subject: add accept_languages setting --- README | 1 + src/callbacks.c | 11 +++++++++++ src/callbacks.h | 3 +++ src/uzbl-core.c | 1 + src/uzbl-core.h | 1 + 5 files changed, 17 insertions(+) (limited to 'src/uzbl-core.h') diff --git a/README b/README index e4e3cab..98ae22c 100644 --- a/README +++ b/README @@ -329,6 +329,7 @@ file). rendered content. * `useragent`: The User-Agent to send to the browser, expands variables in its definition. +* `accept_languages`: The Accept-Language header to send with HTTP requests. * `zoom_level`: The factor by which elements in the page are scaled with respect to their original size. Setting this will resize the currently displayed page. * `zoom_type`: Whether to use "full-content" zoom (defaults to true). With diff --git a/src/callbacks.c b/src/callbacks.c index 673979e..7b06873 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -308,6 +308,17 @@ cmd_useragent() { } } +void +set_accept_languages() { + if (*uzbl.net.accept_languages == ' ') { + g_free (uzbl.net.accept_languages); + uzbl.net.accept_languages = NULL; + } else { + g_object_set(G_OBJECT(uzbl.net.soup_session), + SOUP_SESSION_ACCEPT_LANGUAGE, uzbl.net.accept_languages, NULL); + } +} + void cmd_javascript_windows() { g_object_set (G_OBJECT(view_settings()), "javascript-can-open-windows-automatically", diff --git a/src/callbacks.h b/src/callbacks.h index 40fa80d..899e959 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -82,6 +82,9 @@ cmd_socket_dir(); void cmd_useragent() ; +void +set_accept_languages(); + void cmd_autoload_img(); diff --git a/src/uzbl-core.c b/src/uzbl-core.c index b7b8b00..2a91563 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -102,6 +102,7 @@ const struct var_name_to_ptr_t { { "max_conns", PTR_V_INT(uzbl.net.max_conns, 1, cmd_max_conns)}, { "max_conns_host", PTR_V_INT(uzbl.net.max_conns_host, 1, cmd_max_conns_host)}, { "useragent", PTR_V_STR(uzbl.net.useragent, 1, cmd_useragent)}, + { "accept_languages", PTR_V_STR(uzbl.net.accept_languages, 1, set_accept_languages)}, { "javascript_windows", PTR_V_INT(uzbl.behave.javascript_windows, 1, cmd_javascript_windows)}, /* requires webkit >=1.1.14 */ { "view_source", PTR_V_INT(uzbl.behave.view_source, 0, cmd_view_source)}, diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 129c6a5..7076095 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -111,6 +111,7 @@ typedef struct { SoupLogger *soup_logger; char *proxy_url; char *useragent; + char *accept_languages; gint max_conns; gint max_conns_host; } Network; -- cgit v1.2.3 From b869e6a8e127ff674600a1141fc2bae9b77067cb Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Thu, 6 Jan 2011 16:41:30 -0700 Subject: split the status bar into left-aligned and right-aligned parts (thanks k0ral) --- AUTHORS | 1 + README | 12 +++++---- src/uzbl-core.c | 75 +++++++++++++++++++++++++++++++++------------------------ src/uzbl-core.h | 13 ++++++++-- 4 files changed, 63 insertions(+), 38 deletions(-) (limited to 'src/uzbl-core.h') diff --git a/AUTHORS b/AUTHORS index f7e4a16..6522237 100644 --- a/AUTHORS +++ b/AUTHORS @@ -52,6 +52,7 @@ In alphabetical order: Jan Kolkmeier (jouz) - scrolling, link following Jason Woofenden (JasonWoof) - geometry=maximized, link following Jochen Sprickerhof - session.sh enhancements + k0ral - split status bar Lars-Dominik Braun (PromyLOPh) - added ability to enable/disable the webkit page cache Laurence Withers (lwithers) - talk_to_socket Luca Bruno - bashims fixes diff --git a/README b/README index 98ae22c..051fe6b 100644 --- a/README +++ b/README @@ -291,8 +291,10 @@ file). * `keycmd`: Holds the input buffer (callback: update input buffer). * `show_status`: Show statusbar or not. * `status_top`: statusbar on top? -* `status_format`: Marked up, to be expanded string for statusbar (callback: - update statusbar). +* `status_format`: Marked up, to be expanded string for statusbar's left side + (callback: update statusbar). +* `status_format_right`: Marked up, to be expanded string for statusbar's right side + (callback: update statusbar). * `status_background`: color which can be used to override Gtk theme. * `title_format_long`: titlebar string when no statusbar shown (will be expanded). @@ -470,10 +472,10 @@ that should be evaluated on every update need to be escaped: set title_format_short = \\\@(date)\\\@ # the title will stay constant as a literal "@(date)@" -The `status_format` variable can contain +The `status_format` and `status_format_right` variables can contain [Pango](http://library.gnome.org/devel/pango/stable/PangoMarkupFormat.html) -markup . In the `status_format`, variables that might contain characters like -`<`, `&` and `>`, should be wrapped in a `@[ ]@` substitution so that they don't +markup . In these variables, expansions that might produce the characters `<`, +`&` or `>` should be wrapped in `@[ ]@` substitutions so that they don't interfere with the status bar's markup; see the sample config for examples. ### EXTERNAL SCRIPTS diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 2a91563..4a1b071 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -85,6 +85,7 @@ const struct var_name_to_ptr_t { { "show_status", PTR_V_INT(uzbl.behave.show_status, 1, cmd_set_status)}, { "status_top", PTR_V_INT(uzbl.behave.status_top, 1, move_statusbar)}, { "status_format", PTR_V_STR(uzbl.behave.status_format, 1, NULL)}, + { "status_format_right", PTR_V_STR(uzbl.behave.status_format_right, 1, NULL)}, { "status_background", PTR_V_STR(uzbl.behave.status_background, 1, set_status_background)}, { "title_format_long", PTR_V_STR(uzbl.behave.title_format_long, 1, NULL)}, { "title_format_short", PTR_V_STR(uzbl.behave.title_format_short, 1, NULL)}, @@ -1873,42 +1874,43 @@ init_socket(gchar *dir) { /* return dir or, on error, free dir and return NULL * return NULL; } -/* - NOTE: we want to keep variables like b->title_format_long in their "unprocessed" state - it will probably improve performance if we would "cache" the processed variant, but for now it works well enough... -*/ -// this function may be called very early when the templates are not set (yet), hence the checks void update_title (void) { Behaviour *b = &uzbl.behave; - gchar *parsed; - const gchar *current_title; - /* this check is here because if we're starting up or shutting down it might not be a window */ - gboolean have_main_window = !uzbl.state.plug_mode && GTK_IS_WINDOW(uzbl.gui.main_window); - if(have_main_window) - current_title = gtk_window_get_title (GTK_WINDOW(uzbl.gui.main_window)); + const gchar *title_format = b->title_format_long; + /* Update the status bar if shown */ if (b->show_status) { - if (b->title_format_short && have_main_window) { - parsed = expand(b->title_format_short, 0); - if(!current_title || strcmp(current_title, parsed)) - gtk_window_set_title (GTK_WINDOW(uzbl.gui.main_window), parsed); - g_free(parsed); - } - if (b->status_format && GTK_IS_LABEL(uzbl.gui.mainbar_label)) { - parsed = expand(b->status_format, 0); - gtk_label_set_markup(GTK_LABEL(uzbl.gui.mainbar_label), parsed); + title_format = b->title_format_short; + + /* Left side */ + if (b->status_format && GTK_IS_LABEL(uzbl.gui.mainbar_label_left)) { + gchar *parsed = expand(b->status_format, 0); + gtk_label_set_markup(GTK_LABEL(uzbl.gui.mainbar_label_left), parsed); g_free(parsed); } - } else { - if (b->title_format_long && have_main_window) { - parsed = expand(b->title_format_long, 0); - if(!current_title || strcmp(current_title, parsed)) - gtk_window_set_title (GTK_WINDOW(uzbl.gui.main_window), parsed); + + /* Right side */ + if (b->status_format_right && GTK_IS_LABEL(uzbl.gui.mainbar_label_right)) { + gchar *parsed = expand(b->status_format_right, 0); + gtk_label_set_markup(GTK_LABEL(uzbl.gui.mainbar_label_right), parsed); g_free(parsed); } } + + /* Update window title */ + /* If we're starting up or shutting down there might not be a window yet. */ + gboolean have_main_window = !uzbl.state.plug_mode && GTK_IS_WINDOW(uzbl.gui.main_window); + if (title_format && have_main_window) { + gchar *parsed = expand(title_format, 0); + const gchar *current_title = gtk_window_get_title (GTK_WINDOW(uzbl.gui.main_window)); + /* xmonad hogs CPU if the window title updates too frequently, so we + * don't set it unless we need to. */ + if(!current_title || strcmp(current_title, parsed)) + gtk_window_set_title (GTK_WINDOW(uzbl.gui.main_window), parsed); + g_free(parsed); + } } void @@ -1946,12 +1948,23 @@ create_mainbar () { GUI *g = &uzbl.gui; g->mainbar = gtk_hbox_new (FALSE, 0); - g->mainbar_label = gtk_label_new (""); - gtk_label_set_selectable((GtkLabel *)g->mainbar_label, TRUE); - gtk_label_set_ellipsize(GTK_LABEL(g->mainbar_label), PANGO_ELLIPSIZE_END); - gtk_misc_set_alignment (GTK_MISC(g->mainbar_label), 0, 0); - gtk_misc_set_padding (GTK_MISC(g->mainbar_label), 2, 2); - gtk_box_pack_start (GTK_BOX (g->mainbar), g->mainbar_label, TRUE, TRUE, 0); + + /* Left panel */ + g->mainbar_label_left = gtk_label_new (""); + gtk_label_set_selectable(GTK_LABEL(g->mainbar_label_left), TRUE); + gtk_misc_set_alignment (GTK_MISC(g->mainbar_label_left), 0, 0); + gtk_misc_set_padding (GTK_MISC(g->mainbar_label_left), 2, 2); + + gtk_box_pack_start (GTK_BOX (g->mainbar), g->mainbar_label_left, FALSE, FALSE, 0); + + /* Right panel */ + g->mainbar_label_right = gtk_label_new (""); + gtk_label_set_selectable(GTK_LABEL(g->mainbar_label_right), TRUE); + gtk_misc_set_alignment (GTK_MISC(g->mainbar_label_right), 1, 0); + gtk_misc_set_padding (GTK_MISC(g->mainbar_label_right), 2, 2); + gtk_label_set_ellipsize(GTK_LABEL(g->mainbar_label_right), PANGO_ELLIPSIZE_START); + + gtk_box_pack_start (GTK_BOX (g->mainbar), g->mainbar_label_right, TRUE, TRUE, 0); g_object_connect((GObject*)g->mainbar, "signal::key-press-event", (GCallback)key_press_cb, NULL, diff --git a/src/uzbl-core.h b/src/uzbl-core.h index 7076095..f81722d 100644 --- a/src/uzbl-core.h +++ b/src/uzbl-core.h @@ -51,8 +51,12 @@ typedef struct { GtkPlug* plug; GtkWidget* scrolled_win; GtkWidget* vbox; + + /* Mainbar */ GtkWidget* mainbar; - GtkWidget* mainbar_label; + GtkWidget* mainbar_label_left; + GtkWidget* mainbar_label_right; + GtkScrollbar* scbar_v; // Horizontal and Vertical Scrollbar GtkScrollbar* scbar_h; // (These are still hidden) GtkAdjustment* bar_v; // Information about document length @@ -119,10 +123,15 @@ typedef struct { /* behaviour */ typedef struct { + /* Status bar */ gchar* status_format; + gchar* status_format_right; + gchar* status_background; + + /* Window title */ gchar* title_format_short; gchar* title_format_long; - gchar* status_background; + gchar* fifo_dir; gchar* socket_dir; gchar* cookie_handler; -- cgit v1.2.3