From 6494d60866601788b93a783e91438bab6b353d38 Mon Sep 17 00:00:00 2001 From: dusanx Date: Sun, 26 Apr 2009 02:26:40 +0200 Subject: Merged Barrucadu code --- sampleconfig | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sampleconfig (limited to 'sampleconfig') diff --git a/sampleconfig b/sampleconfig new file mode 100644 index 0000000..e318e49 --- /dev/null +++ b/sampleconfig @@ -0,0 +1,40 @@ + +# example uzbl config. in a real config, we should obey the xdg spec + +# all keys in the behavior group are optional. if not set, the corresponding behavior is disabed. +# bindings_internal denote keys to trigger actions internally in uzbl +# bindings_external denote keys to trigger scripts outside uzbl + +# keyboard behavior is vimstyle by default (all actions -> 1 key). set +# always_insert_mode to always be in insert mode and disable going out of it. +# if you do this, make sure you've set a modkey so you can reach the actions +# from insert mode by combining them with the modkey + +[behavior] +history_file = /tmp/uzbl.history +download_handler = ./extra/download.sh +fifo_dir = /tmp +always_insert_mode = 0 +modkey = Mod4 + +[bindings_internal] +next = n +forward = m +stop = s +refresh = r +reload = R +home = h +follow_link_here = f +follow_link_new_tab = F +follow_link_new_window = w +zoom_in = + +zoom_out = - + + +[bindings_external] +./extra/insert_bookmark.sh = b +./extra/load_url_from_history.sh = u +./extra/load_url_from_bookmarks.sh = U + + +[network] -- cgit v1.2.3 From fcc0bbbd28859746df814ca5771dbe465fb0f4bb Mon Sep 17 00:00:00 2001 From: dusanx Date: Sun, 26 Apr 2009 13:21:28 +0200 Subject: Merged Dieterbe code --- AUTHORS | 6 ++ README | 24 ++++++- TODO | 3 +- sampleconfig | 3 +- uzbl | Bin 0 -> 28968 bytes uzbl.c | 200 ++++++++++++++++++++++++++--------------------------------- 6 files changed, 117 insertions(+), 119 deletions(-) create mode 100755 uzbl (limited to 'sampleconfig') diff --git a/AUTHORS b/AUTHORS index 0849060..57f2bc2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,2 +1,8 @@ Original code taken from webkit example application whis is copyrighted 2006, 2007 Apple Inc and 2007 Alp Toker enhancements to form uzbl made by Dieter Plaetinck. + +Michael Walker (Barrucadu) - Original threaded FIFO interface. Command adding methods. + +Zane Ashby (HashBox) - Rewrote FIFO interface. Fixed various bugs. + +(sentientswitch) - Cleaned up code. Added some commands. diff --git a/README b/README index 89098ea..e58962d 100644 --- a/README +++ b/README @@ -57,9 +57,27 @@ So, assume each entry is about 80 chars, you visit 100 pages per day (?), and yo (50 * 1000 * 1000 ) / ( 80 * 100 ) = 6250 days or 17 years. There is code to run a benchmark in the 'extra' dir. For results & interpretation, see http://dieter.plaetinck.be/poor_mans_dmenu_benchmark +CONTROL: +- FIFO opened in /tmp/uzbl_pid +- See config file for commands +- Press ESC to toggle the command entry. +- Press enter after typing a command to use it. - - -NOTE: +NOTES: - My c skills are very rusty, it will take me a while to get back up to speed - For more thoughts & ideas see http://bbs.archlinux.org/viewtopic.php?id=67463 + +REPO's: +- http://github.com/Dieterbe/uzbl + master -> uzbl stable branch + experimental -> bleeding edge stuff that may break. after QA codes gets merged into master +- various contributors also have their clones on github (http://github.com/dusanx, http://github.com/Barrucadu/uzbl, ...). + They may be developing specific features, which get merged into Dieters experimental branch + + +KNOWN BUGS +- Segfault occurs on shutdown, almost definitely FIFO related (I'm not seeing this bug now, but the warning was here when I forked the code and I haven't touched the FIFO bit) +- Segfaults when using zoom commands (happens when max zoom already reached?). +- Something in the FIFO code causes CPU usage to jump. +- Segfaults when loading aliases from config file (currently aliases are defined in the code as a 'work-around'). +- Segfaults when setting the xwin variable \ No newline at end of file diff --git a/TODO b/TODO index 52df75c..2f5bef8 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ * implement all the ideas from README +* Support for binding keyboard shortcuts in config file. * where to put proxy config? webkit support? * do not store the 'http://' part in the history file * improve commandline arguments @@ -6,5 +7,5 @@ * history logging broken. logs always starting url because i made uri const SOMEDAY: -figure out caching with webkit and in general how we can speed everything +figure out caching with webkit and in general how we can speed up everything figure out how webkit intercepts key input diff --git a/sampleconfig b/sampleconfig index e318e49..3a4bae1 100644 --- a/sampleconfig +++ b/sampleconfig @@ -18,7 +18,7 @@ always_insert_mode = 0 modkey = Mod4 [bindings_internal] -next = n +back = b forward = m stop = s refresh = r @@ -36,5 +36,4 @@ zoom_out = - ./extra/load_url_from_history.sh = u ./extra/load_url_from_bookmarks.sh = U - [network] diff --git a/uzbl b/uzbl new file mode 100755 index 0000000..49c6721 Binary files /dev/null and b/uzbl differ diff --git a/uzbl.c b/uzbl.c index 34a3404..ca8b40f 100644 --- a/uzbl.c +++ b/uzbl.c @@ -43,18 +43,17 @@ #include static GtkWidget* main_window; -static GtkWidget* uri_entry; static GtkWidget* mainbar; static WebKitWebView* web_view; static gchar* main_title; static gchar selected_url[500]; /* Behaviour variables */ -static gchar* history_file = NULL; -static gchar* fifodir = NULL; -static gchar* download_handler = NULL; -static gchar* always_insert_mode = NULL; -static gchar* modkey = NULL; +static gchar* history_file = NULL; +static gchar* fifodir = NULL; +static gchar* download_handler = NULL; +static gboolean always_insert_mode = 0; +static gchar* modkey = NULL; static char fifopath[64]; static gint load_progress; @@ -66,23 +65,22 @@ static gboolean verbose = FALSE; static GOptionEntry entries[] = { - { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", NULL }, - { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, - { NULL } + { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", NULL }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL }, + { NULL } }; typedef struct { - const char *command; - void (*func)(WebKitWebView*); - const gboolean param_allow; - const gboolean param_optional; + const char *command; + void (*func_1_param)(WebKitWebView*); + void (*func_2_params)(WebKitWebView*, char *); } Command; typedef struct { - const char *binding; - const char *action; + const char *binding; + const char *action; } Binding; static Binding internal_bindings[256]; @@ -115,9 +113,9 @@ link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpoin //TODO implementation roadmap pending.. //ADD HOVER URL TO WINDOW TITLE - selected_url[0]='\0'; + selected_url[0] = '\0'; if (link) { - strcpy (selected_url,link); + strcpy (selected_url, link); } update_title (GTK_WINDOW (main_window)); @@ -140,8 +138,6 @@ progress_change_cb (WebKitWebView* page, gint progress, gpointer data) { static void load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) { const gchar* uri = webkit_web_frame_get_uri(frame); - if (uri) - gtk_entry_set_text (GTK_ENTRY (uri_entry), uri); } static void @@ -149,28 +145,21 @@ destroy_cb (GtkWidget* widget, gpointer data) { gtk_main_quit (); } -static void -activate_uri_entry_cb (GtkWidget* entry, gpointer data) { - const gchar * uri = gtk_entry_get_text (GTK_ENTRY (entry)); - g_assert (uri); - webkit_web_view_load_uri (web_view, uri); -} - static void log_history_cb () { - FILE * output_file = fopen(history_file, "a"); + FILE * output_file = fopen (history_file, "a"); if (output_file == NULL) { - fprintf(stderr, "Cannot open %s for logging\n", history_file); + fprintf (stderr, "Cannot open %s for logging\n", history_file); } else { time_t rawtime; struct tm * timeinfo; char buffer [80]; time ( &rawtime ); timeinfo = localtime ( &rawtime ); - strftime (buffer,80,"%Y-%m-%d %H:%M:%S",timeinfo); + strftime (buffer, 80, "%Y-%m-%d %H:%M:%S", timeinfo); - fprintf(output_file, "%s %s\n",buffer, uri); - fclose(output_file); + fprintf (output_file, "%s %s\n", buffer, uri); + fclose (output_file); } } @@ -178,13 +167,13 @@ log_history_cb () { // TODO: reload, home, quit static Command commands[] = { - { "back", &go_back_cb, false, false }, - { "forward", &go_forward_cb, false, false }, - { "refresh", &webkit_web_view_reload, false, false }, //Buggy - { "stop", &webkit_web_view_stop_loading, false, false }, - { "zoom_in", &webkit_web_view_zoom_in, false, false }, //Can crash (when max zoom reached?). - { "zoom_out", &webkit_web_view_zoom_out, false, false } , - { "go", &webkit_web_view_load_uri, true, false } + { "back", &go_back_cb, NULL }, + { "forward", &go_forward_cb, NULL }, + { "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 } //{ "get uri", &webkit_web_view_get_uri}, }; @@ -192,88 +181,81 @@ static Command commands[] = static void parse_command(const char *command) { - int i = 0; - bool done = false; - void (*func)(WebKitWebView*); - - char * command_name = strtok (command," "); - char * command_param = strtok (NULL, " ,"); //dunno how this works, but it seems to work - + int i; Command *c; - for (i = 0; i < LENGTH(commands); i++) { - c = &commands[i]; - if (!strncmp (command_name, c->command, strlen (c->command))) { - func = c->func; - done = true; + char * command_name = strtok (command, " "); + char * command_param = strtok (NULL, " ,"); //dunno how this works, but it seems to work + + Command *c_tmp; + 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 (done) { - if (c->param_allow) { - if(command_param != NULL) { - printf("command executing: \"%s %s\"\n", command_name, command_param); - //func (web_view, command_param); + 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->param_optional) { - printf("command executing: \"%s\"\n", command_name); - func (web_view); + 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); + fprintf (stderr, "command needs a parameter. \"%s\" is not complete\n", command_name); } } - } else { - printf("command executing: \"%s\"\n", command_name); - func (web_view); + } 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", command); + fprintf (stderr, "command \"%s\" not understood. ignoring.\n", command); } } static void *control_fifo() { - if (fifodir) { - sprintf (fifopath, "%s/uzbl_%d", fifodir, (int) xwin); - } else { - sprintf (fifopath, "/tmp/uzbl_%d", (int) xwin); - } + if (fifodir) { + sprintf (fifopath, "%s/uzbl_%d", fifodir, (int) xwin); + } else { + sprintf (fifopath, "/tmp/uzbl_%d", (int) xwin); + } - if (mkfifo (fifopath, 0666) == -1) { - printf ("Possible error creating fifo\n"); - } + if (mkfifo (fifopath, 0666) == -1) { + printf ("Possible error creating fifo\n"); + } - printf ("Control fifo opened in %s\n", fifopath); + printf ("Control fifo opened in %s\n", fifopath); - while (true) { - FILE *fifo = fopen(fifopath, "r"); - if (!fifo) { - printf("Could not open %s for reading\n", fifopath); - return NULL; - } + while (true) { + FILE *fifo = fopen (fifopath, "r"); + if (!fifo) { + printf ("Could not open %s for reading\n", fifopath); + return NULL; + } - char buffer[256]; - memset (buffer, 0, sizeof (buffer)); - while (!feof (fifo) && fgets (buffer, sizeof (buffer), fifo)) { - if (strcmp (buffer, "\n")) { - buffer[strlen (buffer) - 1] = '\0'; // Remove newline - parse_command (buffer); - } + char buffer[256]; + memset (buffer, 0, sizeof (buffer)); + while (!feof (fifo) && fgets (buffer, sizeof (buffer), fifo)) { + if (strcmp (buffer, "\n")) { + buffer[strlen (buffer) - 1] = '\0'; // Remove newline + parse_command (buffer); + } + } } - } - return NULL; + return NULL; } static void setup_threading () { - pthread_t control_thread; - pthread_create(&control_thread, NULL, control_fifo, NULL); + pthread_t control_thread; + pthread_create(&control_thread, NULL, control_fifo, NULL); } - - - static void update_title (GtkWindow* window) { GString* string = g_string_new (main_title); @@ -289,7 +271,6 @@ update_title (GtkWindow* window) { gtk_window_set_title (window, title); g_free (title); } - static void MsgBox (const char *s) { @@ -302,26 +283,24 @@ MsgBox (const char *s) { gtk_widget_destroy (dialog); } - static gboolean key_press_cb (WebKitWebView* page, GdkEventKey* event) { int i; 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) - return(result); + return result; for (i = 0; i < num_internal_bindings; i++) { - if (event->string[0] == internal_bindings[i].binding[0]) { - parse_command(internal_bindings[i].action); - result = FALSE; - } + if (event->string[0] == internal_bindings[i].binding[0]) { + parse_command (internal_bindings[i].action); + result = FALSE; + } } - return(result); + return result; } - static GtkWidget* create_browser () { GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); @@ -335,19 +314,14 @@ create_browser () { g_signal_connect (G_OBJECT (web_view), "load-committed", G_CALLBACK (load_commit_cb), web_view); g_signal_connect (G_OBJECT (web_view), "load-committed", G_CALLBACK (log_history_cb), web_view); g_signal_connect (G_OBJECT (web_view), "hovering-over-link", G_CALLBACK (link_hover_cb), web_view); - g_signal_connect (G_OBJECT (web_view), "key-press-event", G_CALLBACK(key_press_cb), web_view); + g_signal_connect (G_OBJECT (web_view), "key-press-event", G_CALLBACK (key_press_cb), web_view); return scrolled_window; } static GtkWidget* create_mainbar () { - mainbar = gtk_hbox_new(FALSE, 0); - uri_entry = gtk_entry_new(); - gtk_entry_set_width_chars(GTK_ENTRY(uri_entry), 40); - gtk_entry_set_text(GTK_ENTRY(uri_entry), "http://"); - gtk_box_pack_start (GTK_BOX (mainbar), uri_entry, TRUE,TRUE , 0); - gtk_signal_connect_object (GTK_OBJECT (uri_entry), "activate", GTK_SIGNAL_FUNC (activate_uri_entry_cb), GTK_OBJECT (uri_entry)); + mainbar = gtk_hbox_new (FALSE, 0); //status_context_id = gtk_statusbar_get_context_id (main_statusbar, "Link Hover"); @@ -395,7 +369,7 @@ settings_init () { download_handler = g_key_file_get_value (config, "behavior", "download_handler", NULL); if (download_handler) { - printf ("Download manager: %s\n", history_file); + printf ("Download manager: %s\n", download_handler); } else { printf ("Download manager disabled\n"); } @@ -403,21 +377,21 @@ settings_init () { if (! fifodir) fifodir = g_key_file_get_value (config, "behavior", "fifodir", NULL); if (fifodir) { - printf ("Fifo directory: %s\n", history_file); + printf ("Fifo directory: %s\n", fifodir); } else { printf ("Fifo directory: /tmp\n"); } always_insert_mode = g_key_file_get_value (config, "behavior", "always_insert_mode", NULL); if (always_insert_mode) { - printf ("Always insert mode: %s\n", history_file); + printf ("Always insert mode: %s\n", always_insert_mode); } else { printf ("Always insert mode disabled/\n"); } modkey = g_key_file_get_value (config, "behavior", "modkey", NULL); if (modkey) { - printf ("Mod key: %s\n", history_file); + printf ("Mod key: %s\n", modkey); } else { printf ("Mod key disabled/\n"); } -- cgit v1.2.3 From ea8e3196e6e3318ae500090172f04155815b9791 Mon Sep 17 00:00:00 2001 From: dusanx Date: Sun, 26 Apr 2009 14:31:45 +0200 Subject: Insert and non-insert mode --- AUTHORS | 2 ++ sampleconfig | 2 +- uzbl | Bin 28968 -> 29051 bytes uzbl.c | 48 +++++++++++++++++++++++++++++++++++------------- 4 files changed, 38 insertions(+), 14 deletions(-) (limited to 'sampleconfig') diff --git a/AUTHORS b/AUTHORS index 57f2bc2..fc49fea 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,5 @@ Michael Walker (Barrucadu) - Original threaded FIFO inter Zane Ashby (HashBox) - Rewrote FIFO interface. Fixed various bugs. (sentientswitch) - Cleaned up code. Added some commands. + +Dusan Popovic (dusanx) - Key handling and stuff diff --git a/sampleconfig b/sampleconfig index 3a4bae1..4231041 100644 --- a/sampleconfig +++ b/sampleconfig @@ -14,7 +14,7 @@ history_file = /tmp/uzbl.history download_handler = ./extra/download.sh fifo_dir = /tmp -always_insert_mode = 0 +always_insert_mode = 1 modkey = Mod4 [bindings_internal] diff --git a/uzbl b/uzbl index 49c6721..1f8a0f8 100755 Binary files a/uzbl and b/uzbl differ diff --git a/uzbl.c b/uzbl.c index ca8b40f..dca1bda 100644 --- a/uzbl.c +++ b/uzbl.c @@ -30,6 +30,7 @@ #define LENGTH(x) (sizeof x / sizeof x[0]) +#define GDK_Escape 0xff1b #include #include @@ -52,7 +53,8 @@ static gchar selected_url[500]; static gchar* history_file = NULL; static gchar* fifodir = NULL; static gchar* download_handler = NULL; -static gboolean always_insert_mode = 0; +static gboolean always_insert_mode = FALSE; +static gboolean insert_mode = FALSE; static gchar* modkey = NULL; static char fifopath[64]; @@ -258,7 +260,10 @@ setup_threading () { static void update_title (GtkWindow* window) { - GString* string = g_string_new (main_title); + GString* string = 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"); if (load_progress < 100) g_string_append_printf (string, " (%d%%)", load_progress); @@ -291,13 +296,32 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event) if (event->type != GDK_KEY_PRESS) return result; - for (i = 0; i < num_internal_bindings; i++) { - if (event->string[0] == internal_bindings[i].binding[0]) { - parse_command (internal_bindings[i].action); - result = FALSE; - } + //TURN OFF INSERT MODE + if (insert_mode && (event->keyval == GDK_Escape)) { + insert_mode = FALSE; + update_title (GTK_WINDOW (main_window)); + return TRUE; } + //TURN ON INSERT MODE + if (!insert_mode && (event->string[0] == 'i')) { + insert_mode = TRUE; + update_title (GTK_WINDOW (main_window)); + return TRUE; + } + + //INTERNAL KEYS + if (always_insert_mode || !insert_mode) { + for (i = 0; i < num_internal_bindings; i++) { + if (event->string[0] == internal_bindings[i].binding[0]) { + parse_command (internal_bindings[i].action); + result = TRUE; + } + } + } + if (!result) + result = (insert_mode ? FALSE : TRUE); + return result; } @@ -382,12 +406,8 @@ settings_init () { printf ("Fifo directory: /tmp\n"); } - always_insert_mode = g_key_file_get_value (config, "behavior", "always_insert_mode", NULL); - if (always_insert_mode) { - printf ("Always insert mode: %s\n", always_insert_mode); - } else { - printf ("Always insert mode disabled/\n"); - } + 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")); modkey = g_key_file_get_value (config, "behavior", "modkey", NULL); if (modkey) { @@ -421,6 +441,8 @@ main (int argc, char* argv[]) { g_thread_init (NULL); settings_init (); + if (always_insert_mode) + insert_mode = TRUE; GtkWidget* vbox = gtk_vbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), create_mainbar (), FALSE, TRUE, 0); -- cgit v1.2.3 From 8fd8038469121da41fa8d436dcc47a8fe2f31a63 Mon Sep 17 00:00:00 2001 From: dusanx Date: Sun, 26 Apr 2009 14:35:08 +0200 Subject: Small fix --- sampleconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sampleconfig') diff --git a/sampleconfig b/sampleconfig index 4231041..3a4bae1 100644 --- a/sampleconfig +++ b/sampleconfig @@ -14,7 +14,7 @@ history_file = /tmp/uzbl.history download_handler = ./extra/download.sh fifo_dir = /tmp -always_insert_mode = 1 +always_insert_mode = 0 modkey = Mod4 [bindings_internal] -- cgit v1.2.3 From e0b702fb695c43ff324eec28e79f96af602f49aa Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Sun, 26 Apr 2009 14:45:41 +0100 Subject: Added show_status variable and toggle_status key. Fixed a conflicting binding. --- .gitignore | 1 - sampleconfig | 5 +++-- uzbl | Bin 29051 -> 0 bytes 3 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 .gitignore delete mode 100755 uzbl (limited to 'sampleconfig') diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d6df486..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -uzbl diff --git a/sampleconfig b/sampleconfig index 3a4bae1..3849b12 100644 --- a/sampleconfig +++ b/sampleconfig @@ -16,6 +16,7 @@ download_handler = ./extra/download.sh fifo_dir = /tmp always_insert_mode = 0 modkey = Mod4 +show_status = 0 [bindings_internal] back = b @@ -29,10 +30,10 @@ follow_link_new_tab = F follow_link_new_window = w zoom_in = + zoom_out = - - +toggle_status = S [bindings_external] -./extra/insert_bookmark.sh = b +./extra/insert_bookmark.sh = B ./extra/load_url_from_history.sh = u ./extra/load_url_from_bookmarks.sh = U diff --git a/uzbl b/uzbl deleted file mode 100755 index 1f8a0f8..0000000 Binary files a/uzbl and /dev/null differ -- cgit v1.2.3