aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-10-23 21:19:00 +0200
committerGravatar Dieter Plaetinck <dieter@plaetinck.be>2009-10-23 21:19:00 +0200
commitabb9589ab1b65f3ecc0c0d082e9c873ce984fc6d (patch)
tree74032f05f873213dd6d6f60895dc16ba5a3b0a9a
parente4dbe44c227887ea359406aafa6cfaedc7cb800a (diff)
parente802d5187c9619f4c8f03802350e29435a3ec9d3 (diff)
Merge commit 'e802d5187c9619f4c8f03802350e29435a3ec9d3' into experimental
-rw-r--r--callbacks.c7
-rw-r--r--events.c2
-rw-r--r--examples/config/uzbl/config5
-rw-r--r--uzbl-core.c114
-rw-r--r--uzbl-core.h19
5 files changed, 60 insertions, 87 deletions
diff --git a/callbacks.c b/callbacks.c
index a9cdc79..593fdac 100644
--- a/callbacks.c
+++ b/callbacks.c
@@ -62,10 +62,7 @@ cmd_set_status() {
void
cmd_load_uri() {
- GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*));
- g_array_append_val (a, uzbl.state.uri);
- load_uri(uzbl.gui.web_view, a, NULL);
- g_array_free (a, TRUE);
+ load_uri_imp (uzbl.state.uri);
}
void
@@ -661,7 +658,7 @@ populate_popup_cb(WebKitWebView *v, GtkMenu *m, void *c) {
hit++;
}
- if((mi->context == WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) &&
+ if((mi->context == WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) &&
(context <= WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) &&
!hit) {
if(mi->issep) {
diff --git a/events.c b/events.c
index c955a90..76c0055 100644
--- a/events.c
+++ b/events.c
@@ -152,7 +152,7 @@ send_event(int type, const gchar *details, const gchar *custom_event) {
/* expand shell vars */
if(details) {
buf = g_strdup(details);
- p_val = parseenv(g_strdup(buf ? g_strchug(buf) : " "));
+ p_val = parseenv(buf ? g_strchug(buf) : " ");
g_free(buf);
}
diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config
index c3babe0..1ca1770 100644
--- a/examples/config/uzbl/config
+++ b/examples/config/uzbl/config
@@ -42,6 +42,11 @@ set new_window = sh 'uzbl-browser -u $8' # equivalent to the default beh
@on_event LOAD_FINISH @set_status <span foreground="gold">done</span>
@on_event LOAD_FINISH spawn @scripts_dir/history.sh
+# Generate a FORM_ACTIVE event if a text element on the loaded site
+# has initial focus unfortunatelly this only works for text elements,
+# yet due to webkit limitations
+@on_event LOAD_FINISH js if(document.activeElement.type == 'text') {Uzbl.run("event FORM_ACTIVE");}
+
# Switch to insert mode if a (editable) html form is clicked
@on_event FORM_ACTIVE @set_mode insert
# Switch to command mode if anything else is clicked
diff --git a/uzbl-core.c b/uzbl-core.c
index df50596..ef9852b 100644
--- a/uzbl-core.c
+++ b/uzbl-core.c
@@ -444,21 +444,22 @@ find_existing_file(gchar* path_list) {
}
+/* Returns a new string with environment $variables expanded */
gchar*
-parseenv (char* string) {
+parseenv (gchar* string) {
extern char** environ;
- gchar* tmpstr = NULL;
+ gchar* tmpstr = NULL, * out;
int i = 0;
+ out = g_strdup(string);
while (environ[i] != NULL) {
gchar** env = g_strsplit (environ[i], "=", 2);
gchar* envname = g_strconcat ("$", env[0], NULL);
if (g_strrstr (string, envname) != NULL) {
- tmpstr = g_strdup(string);
- g_free (string);
- string = str_replace(envname, env[1], tmpstr);
+ tmpstr = out;
+ out = str_replace(envname, env[1], out);
g_free (tmpstr);
}
@@ -467,7 +468,7 @@ parseenv (char* string) {
i++;
}
- return string;
+ return out;
}
@@ -664,28 +665,6 @@ commands_hash(void)
/* -- CORE FUNCTIONS -- */
-void
-free_action(gpointer act) {
- Action *action = (Action*)act;
- g_free(action->name);
- if (action->param)
- g_free(action->param);
- g_free(action);
-}
-
-Action*
-new_action(const gchar *name, const gchar *param) {
- Action *action = g_new(Action, 1);
-
- action->name = g_strdup(name);
- if (param)
- action->param = g_strdup(param);
- else
- action->param = NULL;
-
- return action;
-}
-
bool
file_exists (const char * filename) {
return (access(filename, F_OK) == 0);
@@ -696,7 +675,7 @@ set_var(WebKitWebView *page, GArray *argv, GString *result) {
(void) page; (void) result;
gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2);
if (split[0] != NULL) {
- gchar *value = parseenv(g_strdup(split[1] ? g_strchug(split[1]) : " "));
+ gchar *value = parseenv(split[1] ? g_strchug(split[1]) : " ");
set_var_value(g_strstrip(split[0]), value);
g_free(value);
}
@@ -921,37 +900,8 @@ act_dump_config_as_events() {
void
load_uri (WebKitWebView *web_view, GArray *argv, GString *result) {
- (void) result;
-
- if (argv_idx(argv, 0)) {
- GString* newuri = g_string_new (argv_idx(argv, 0));
- if (g_strstr_len (argv_idx(argv, 0), 11, "javascript:") != NULL) {
- run_js(web_view, argv, NULL);
- return;
- }
- if (!soup_uri_new(argv_idx(argv, 0))) {
- GString* fullpath = g_string_new ("");
- if (g_path_is_absolute (newuri->str))
- g_string_assign (fullpath, newuri->str);
- else {
- gchar* wd;
- wd = g_get_current_dir ();
- g_string_assign (fullpath, g_build_filename (wd, newuri->str, NULL));
- free(wd);
- }
- struct stat stat_result;
- if (! g_stat(fullpath->str, &stat_result)) {
- g_string_prepend (fullpath, "file://");
- g_string_assign (newuri, fullpath->str);
- }
- else
- g_string_prepend (newuri, "http://");
- g_string_free (fullpath, TRUE);
- }
- /* if we do handle cookies, ask our handler for them */
- webkit_web_view_load_uri (web_view, newuri->str);
- g_string_free (newuri, TRUE);
- }
+ (void) web_view; (void) result;
+ load_uri_imp (argv_idx (argv, 0));
}
/* Javascript*/
@@ -1571,13 +1521,13 @@ set_var_value(const gchar *name, gchar *val) {
}
/* custom vars */
- c = malloc(sizeof(uzbl_cmdprop));
+ c = g_malloc(sizeof(uzbl_cmdprop));
c->type = TYPE_STR;
c->dump = 0;
c->func = NULL;
c->writeable = 1;
buf = g_strdup(val);
- c->ptr.s = malloc(sizeof(char *));
+ c->ptr.s = g_malloc(sizeof(char *));
*c->ptr.s = buf;
g_hash_table_insert(uzbl.comm.proto_var,
g_strdup(name), (gpointer) c);
@@ -2315,6 +2265,8 @@ void
initialize(int argc, char *argv[]) {
if (!g_thread_supported ())
g_thread_init (NULL);
+ gtk_init (&argc, &argv);
+
uzbl.state.executable_path = g_strdup(argv[0]);
uzbl.state.selected_url = NULL;
uzbl.state.searchtx = NULL;
@@ -2357,14 +2309,45 @@ initialize(int argc, char *argv[]) {
create_browser();
}
+void
+load_uri_imp(gchar *uri) {
+ GString* newuri;
+ if (g_strstr_len (uri, 11, "javascript:") != NULL) {
+ eval_js(uzbl.gui.web_view, uri, NULL);
+ return;
+ }
+ newuri = g_string_new (uri);
+ if (!soup_uri_new(uri)) {
+ GString* fullpath = g_string_new ("");
+ if (g_path_is_absolute (newuri->str))
+ g_string_assign (fullpath, newuri->str);
+ else {
+ gchar* wd;
+ wd = g_get_current_dir ();
+ g_string_assign (fullpath, g_build_filename (wd, newuri->str, NULL));
+ free(wd);
+ }
+ struct stat stat_result;
+ if (! g_stat(fullpath->str, &stat_result)) {
+ g_string_prepend (fullpath, "file://");
+ g_string_assign (newuri, fullpath->str);
+ }
+ else
+ g_string_prepend (newuri, "http://");
+ g_string_free (fullpath, TRUE);
+ }
+ /* if we do handle cookies, ask our handler for them */
+ webkit_web_view_load_uri (uzbl.gui.web_view, newuri->str);
+ g_string_free (newuri, TRUE);
+}
+
+
#ifndef UZBL_LIBRARY
/** -- MAIN -- **/
int
main (int argc, char* argv[]) {
initialize(argc, argv);
- gtk_init (&argc, &argv);
-
uzbl.gui.scrolled_win = gtk_scrolled_window_new (NULL, NULL);
//main_window_ref = g_object_ref(scrolled_window);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (uzbl.gui.scrolled_win),
@@ -2448,8 +2431,7 @@ main (int argc, char* argv[]) {
if (uri_override) {
set_var_value("uri", uri_override);
g_free(uri_override);
- } else if (uzbl.state.uri)
- cmd_load_uri();
+ }
gtk_main ();
clean_up();
diff --git a/uzbl-core.h b/uzbl-core.h
index 21707f9..43d5a3b 100644
--- a/uzbl-core.h
+++ b/uzbl-core.h
@@ -211,11 +211,6 @@ extern UzblCore uzbl;
typedef void sigfunc(int);
-typedef struct {
- char* name;
- char* param;
-} Action;
-
/* XDG Stuff */
typedef struct {
gchar* environmental;
@@ -237,7 +232,7 @@ GArray*
read_file_by_line (const gchar *path);
gchar*
-parseenv (char* string);
+parseenv (gchar* string);
void
clean_up(void);
@@ -248,23 +243,17 @@ catch_sigterm(int s);
sigfunc *
setup_signal(int signe, sigfunc *shandler);
-gchar*
-parseenv (char* string);
-
gboolean
set_var_value(const gchar *name, gchar *val);
void
-print(WebKitWebView *page, GArray *argv, GString *result);
+load_uri_imp(gchar *uri);
void
-commands_hash(void);
+print(WebKitWebView *page, GArray *argv, GString *result);
void
-free_action(gpointer act);
-
-Action*
-new_action(const gchar *name, const gchar *param);
+commands_hash(void);
bool
file_exists (const char * filename);