diff options
author | Barrucadu <mike@barrucadu.co.uk> | 2009-04-29 19:14:40 +0100 |
---|---|---|
committer | Barrucadu <mike@barrucadu.co.uk> | 2009-04-29 19:14:40 +0100 |
commit | 2668b7723dff9460bb2b4ca842025c8ad6dae753 (patch) | |
tree | af7fbb1e97d3901a58c3ea9dba15fcb18756aae9 | |
parent | 353aefa427b0153fe1db25781771bf1c52fab4d6 (diff) | |
parent | e0e74bb34d1ce7ff52f28fccb4f0c7bdf6740e92 (diff) |
Merge branch 'dieter/experimental' into experimental
Conflicts:
examples/scripts/load_url_from_bookmarks.sh
examples/scripts/load_url_from_history.sh
-rw-r--r-- | TODO | 16 | ||||
-rwxr-xr-x | examples/scripts/load_url_from_bookmarks.sh | 2 | ||||
-rwxr-xr-x | examples/scripts/load_url_from_history.sh | 2 | ||||
-rw-r--r-- | uzbl.c | 137 |
4 files changed, 82 insertions, 75 deletions
@@ -15,7 +15,21 @@ ASAP * select/fork based instead of the pthread stuff -> drops dependency, more lightweight. * on website, see if we can <pre><?php include('..'); ?></pre> the documentation inside the uzbl project itself, so we need to maintain the stuff on only 1 place * see if we can use the github bugtracker (anonymous posting allowed?) -* allow user to change bindings for navigation (up,down,left,right, page up, page down etc) +* allow user to change bindings for navigation (up,down,left,right, page up, page down etc)and use vim-like defaults +* put on uzbl.org that you can use http://github.com/Dieterbe/uzbl/issues after registering +* make default size configurable, and optional +* on uzbl.org commits overview: add date+time and repository +* how to handle different content types? (text-plain, image/png, application/pdf,... maybe a map of content-type to uzbl/command + xdg already has a spec for this i think + different "opening" modes (open as configured vs ask before opening) + integration with download and new window thingies? +* see if/how we can remove /bin/bash from scripts +* unify internal and external bindings. +* unify command triggering, whether they came in through fifo or keybind +* add to bottom /* vi: set et ts=4: */ +* ideal uri editor: awesome mode like FF, some keyb shortcuts (erase search string, go to end/begin of string,..), history (if you patch dmenu to be in vertical mode and you order correctly, that's it), support copy paste +* get rid of the home page concept. allow user to make keybinds to go to one or more "homepages". a home page is nothing special. + SOMEDAY: check if we can make the settings loading less hard coded. eg( keep a list of all settings, and for each one, try to load it) diff --git a/examples/scripts/load_url_from_bookmarks.sh b/examples/scripts/load_url_from_bookmarks.sh index 7dffafe..428695b 100755 --- a/examples/scripts/load_url_from_bookmarks.sh +++ b/examples/scripts/load_url_from_bookmarks.sh @@ -8,5 +8,5 @@ else file=./examples/bookmarks #useful when developing fi -goto=`awk '{print $1}' $file | dmenu` #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. +goto=`awk '{print $1}' $file | dmenu -i` #NOTE: it's the job of the script that inserts bookmarks to make sure there are no dupes. [ -n "$goto" ] && uzblctrl -s $4 -c "uri $goto" diff --git a/examples/scripts/load_url_from_history.sh b/examples/scripts/load_url_from_history.sh index 08cf413..ec8334d 100755 --- a/examples/scripts/load_url_from_history.sh +++ b/examples/scripts/load_url_from_history.sh @@ -2,5 +2,5 @@ # you probably really want this in your $XDG_DATA_HOME (eg $HOME/.local/share/uzbl/history) history_file=/tmp/uzbl.history -goto=`awk '{print $3}' $history_file | sort | uniq | dmenu` +goto=`awk '{print $3}' $history_file | sort | uniq | dmenu -i` [ -n "$goto" ] && uzblctrl -s $4 -c "uri $goto" @@ -77,18 +77,14 @@ static gchar* modkey = NULL; static guint modmask = 0; static gchar* home_page = NULL; -typedef struct { - const char *binding; - const char *action; -} Binding; - /* settings from config: group bindings_internal */ -static Binding internal_bindings[256]; -static int num_internal_bindings = 0; +static GHashTable *internal_bindings; /* settings from config: group bindings_external */ -static Binding external_bindings[256]; -static int num_external_bindings = 0; +static GHashTable *external_bindings; + +/* command list */ +static GHashTable *commands; /* commandline arguments (set initial values for the state variables) */ static GOptionEntry entries[] = @@ -102,7 +98,7 @@ static GOptionEntry entries[] = /* for internal list of commands */ typedef struct { - const char *command; + gpointer command; void (*func_1_param)(WebKitWebView*); void (*func_2_params)(WebKitWebView*, const gchar *); } Command; @@ -258,10 +254,11 @@ log_history_cb () { g_string_free (args, TRUE); } } - + /* -- command to callback/function map for things we cannot attach to any signals */ // TODO: reload, home, quit -static Command commands[] = + +static Command cmdlist[] = { { "back", &go_back_cb, NULL }, { "forward", &go_forward_cb, NULL }, @@ -273,9 +270,22 @@ static Command commands[] = { "toggle_status", &toggle_status_cb, NULL }, { "home" , &go_home, NULL }, { "exit" , &close_uzbl, NULL }, + { NULL, NULL, NULL } //{ "get uri", &webkit_web_view_get_uri}, }; +static void +commands_hash(void) +{ + unsigned int i = 0; + commands = g_hash_table_new(g_str_hash, g_str_equal); + + while(cmdlist[i].command != NULL){ + g_hash_table_insert(commands, cmdlist[i].command, &cmdlist[i]); + i++; + } +} + /* -- CORE FUNCTIONS -- */ static bool @@ -350,42 +360,32 @@ run_command(const char *command, const char *args) { static void parse_command(const char *cmd) { - unsigned int i; - Command *c = NULL; - char buffer[512]; - strcpy (buffer, cmd); - const gchar * command_name = strtok (buffer, " "); - const gchar * command_param = strtok (NULL, " ,"); - - 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) { - c = c_tmp; - } - } - if (c != NULL) { - if (c->func_2_params != NULL) { - if (command_param != NULL) { - printf ("command executing: \"%s %s\"\n", command_name, command_param); - c->func_2_params (web_view, command_param); - } else { - if (c->func_1_param != NULL) { - printf ("command executing: \"%s\"\n", command_name); - c->func_1_param (web_view); - } else { - fprintf (stderr, "command needs a parameter. \"%s\" is not complete\n", command_name); - } - } - } else if (c->func_1_param != NULL) { - printf ("command executing: \"%s\"\n", command_name); - c->func_1_param (web_view); - } - } else { - fprintf (stderr, "command \"%s\" not understood. ignoring.\n", cmd); + Command *c = NULL; + char buffer[512]; + strcpy (buffer, cmd); + char * command_name = strtok (buffer, " "); + gchar * command_param = strtok (NULL, " ,"); + + if((c = g_hash_table_lookup(commands, command_name)) != NULL){ + if (c->func_2_params != NULL) { + if (command_param != NULL) { + printf ("command executing: \"%s %s\"\n", command_name, command_param); + c->func_2_params (web_view, command_param); + } else { + if (c->func_1_param != NULL) { + printf ("command executing: \"%s\"\n", command_name); + c->func_1_param (web_view); + } else + fprintf (stderr, "command needs a parameter. \"%s\" is not complete\n", command_name); + } + } else if (c->func_1_param != NULL) { + printf ("command executing: \"%s\"\n", command_name); + c->func_1_param (web_view); } + } else + fprintf (stderr, "command \"%s\" not understood. ignoring.\n", cmd); } - + static void *control_socket() { if (socket_dir) { @@ -487,7 +487,7 @@ static gboolean key_press_cb (WebKitWebView* page, GdkEventKey* event) { (void) page; - int i; + gpointer act; gboolean result=FALSE; //TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further. if (event->type != GDK_KEY_PRESS || event->keyval == GDK_Page_Up || event->keyval == GDK_Page_Down || event->keyval == GDK_Up || event->keyval == GDK_Down || event->keyval == GDK_Left || event->keyval == GDK_Right) @@ -501,25 +501,19 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event) } //INTERNAL BINDINGS - for (i = 0; i < num_internal_bindings; i++) { - if (strcmp(event->string, internal_bindings[i].binding) == 0) { - if (!insert_mode || (event->state == modmask)) { - parse_command (internal_bindings[i].action); - result = TRUE; - } - } - } + if((act = g_hash_table_lookup(internal_bindings, event->string)) != NULL) + if (!insert_mode || (event->state == modmask)) { + parse_command (act); + result = TRUE; + } //EXTERNAL BINDINGS - for (i = 0; i < num_external_bindings; i++) { - if (strcmp(event->string, external_bindings[i].binding) == 0) { - if (!insert_mode || (event->state == modmask)) { - run_command(external_bindings[i].action, NULL); - result = TRUE; - } - } - } - + if((act = g_hash_table_lookup(external_bindings, event->string)) != NULL) + if (!insert_mode || (event->state == modmask)) { + parse_command (act); + result = TRUE; + } + if (!result) result = (insert_mode ? FALSE : TRUE); @@ -569,14 +563,8 @@ GtkWidget* create_window () { static void add_binding (char *binding, char *action, bool internal) { - Binding bind = {binding, action}; - if (internal) { - internal_bindings[num_internal_bindings] = bind; - num_internal_bindings ++; - } else { - external_bindings[num_external_bindings] = bind; - num_external_bindings ++; - } + g_hash_table_insert(internal ? internal_bindings : external_bindings, + binding, action); } static void @@ -713,8 +701,13 @@ main (int argc, char* argv[]) { g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); + /* initialize has tables */ + internal_bindings = g_hash_table_new(g_str_hash, g_str_equal); + external_bindings = g_hash_table_new(g_str_hash, g_str_equal); settings_init (); + commands_hash (); + if (always_insert_mode) insert_mode = TRUE; |