diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.c | 121 | ||||
-rw-r--r-- | src/commands.h | 3 | ||||
-rw-r--r-- | src/uzbl-core.c | 7 | ||||
-rw-r--r-- | src/variables.c | 100 | ||||
-rw-r--r-- | src/variables.h | 8 |
5 files changed, 175 insertions, 64 deletions
diff --git a/src/commands.c b/src/commands.c index ff3b15f..032bb4a 100644 --- a/src/commands.c +++ b/src/commands.c @@ -18,11 +18,9 @@ CommandInfo cmdlist[] = { "stop", view_stop_loading, 0 }, { "zoom_in", view_zoom_in, 0 }, //Can crash (when max zoom reached?). { "zoom_out", view_zoom_out, 0 }, - { "toggle_zoom_type", toggle_zoom_type, 0 }, { "uri", load_uri, TRUE }, { "js", run_js, TRUE }, { "script", run_external_js, 0 }, - { "toggle_status", toggle_status, 0 }, { "spawn", spawn_async, 0 }, { "sync_spawn", spawn_sync, 0 }, { "sync_spawn_exec", spawn_sync_exec, 0 }, // needed for load_cookies.sh :( @@ -34,6 +32,7 @@ CommandInfo cmdlist[] = { "search_clear", search_clear, TRUE }, { "dehilight", dehilight, 0 }, { "set", set_var, TRUE }, + { "toggle", toggle_var, 0 }, { "dump_config", act_dump_config, 0 }, { "dump_config_as_events", act_dump_config_as_events, 0 }, { "chain", chain, 0 }, @@ -96,26 +95,11 @@ VIEWFUNC(go_back) VIEWFUNC(go_forward) #undef VIEWFUNC -void -toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result) { - (void)page; (void)argv; (void)result; - - int current_type = get_zoom_type(); - set_zoom_type(!current_type); -} - -void -toggle_status (WebKitWebView* page, GArray *argv, GString *result) { - (void)page; (void)argv; (void)result; - - int current_status = get_show_status(); - set_show_status(!current_status); -} - /* * scroll vertical 20 * scroll vertical 20% * scroll vertical -40 + * scroll vertical 20! * scroll vertical begin * scroll vertical end * scroll horizontal 10 @@ -164,6 +148,107 @@ set_var(WebKitWebView *page, GArray *argv, GString *result) { g_strfreev(split); } +void +toggle_var(WebKitWebView *page, GArray *argv, GString *result) { + (void) page; (void) result; + + if(!argv_idx(argv, 0)) + return; + + const gchar *var_name = argv_idx(argv, 0); + + uzbl_cmdprop *c = get_var_c(var_name); + + switch(c->type) { + case TYPE_STR: + { + const gchar *next; + + if(argv->len >= 3) { + gchar *current = get_var_value_string_c(c); + + guint i = 2; + const gchar *first = argv_idx(argv, 1); + const gchar *this = first; + next = argv_idx(argv, 2); + + while(next && strcmp(current, this)) { + this = next; + next = argv_idx(argv, ++i); + } + + if(!next) + next = first; + + g_free(current); + } else + next = ""; + + set_var_value_string_c(c, next); + break; + } + case TYPE_INT: + { + int current = get_var_value_int_c(c); + int next; + + if(argv->len >= 3) { + guint i = 2; + + int first = strtoul(argv_idx(argv, 1), NULL, 10); + int this = first; + + const gchar *next_s = argv_idx(argv, 2); + + while(next_s && this != current) { + this = strtoul(next_s, NULL, 10); + next_s = argv_idx(argv, ++i); + } + + if(next_s) + next = strtoul(next_s, NULL, 10); + else + next = first; + } else + next = !current; + + set_var_value_int_c(c, next); + break; + } + case TYPE_FLOAT: + { + float current = get_var_value_float_c(c); + float next; + + if(argv->len >= 3) { + guint i = 2; + + float first = strtod(argv_idx(argv, 1), NULL); + float this = first; + + const gchar *next_s = argv_idx(argv, 2); + + while(next_s && this != current) { + this = strtod(next_s, NULL); + next_s = argv_idx(argv, ++i); + } + + if(next_s) + next = strtod(next_s, NULL); + else + next = first; + } else + next = !current; + + set_var_value_float_c(c, next); + break; + } + default: + g_assert_not_reached(); + } + + send_set_var_event(var_name, c); +} void event(WebKitWebView *page, GArray *argv, GString *result) { diff --git a/src/commands.h b/src/commands.h index b8cf095..c39b541 100644 --- a/src/commands.h +++ b/src/commands.h @@ -58,10 +58,9 @@ void delete_cookie(WebKitWebView *page, GArray *argv, GString *result); void clear_cookies(WebKitWebView *pag, GArray *argv, GString *result); void download(WebKitWebView *pag, GArray *argv, GString *result); void set_var(WebKitWebView *page, GArray *argv, GString *result); +void toggle_var(WebKitWebView *page, GArray *argv, GString *result); void run_js (WebKitWebView * web_view, GArray *argv, GString *result); void run_external_js (WebKitWebView * web_view, GArray *argv, GString *result); -void toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result); -void toggle_status (WebKitWebView* page, GArray *argv, GString *result); void act_dump_config(WebKitWebView* page, GArray *argv, GString *result); void act_dump_config_as_events(WebKitWebView* page, GArray *argv, GString *result); diff --git a/src/uzbl-core.c b/src/uzbl-core.c index f90c5dd..e70b5e7 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -331,11 +331,15 @@ scroll(GtkAdjustment* bar, gchar *amount_str) { if (*end == '%') value += page_size * amount * 0.01; + else if (*end == '!') + value = amount; else value += amount; max_value = gtk_adjustment_get_upper(bar) - page_size; + if (value < 0) + value = 0; /* don't scroll past the beginning of the page */ if (value > max_value) value = max_value; /* don't scroll past the end of the page */ @@ -962,9 +966,10 @@ initialize(int argc, char** argv) { if (uzbl.state.socket_id || uzbl.state.embed) uzbl.state.plug_mode = TRUE; +#if !GLIB_CHECK_VERSION(2, 31, 0) if (!g_thread_supported()) g_thread_init(NULL); - +#endif /* TODO: move the handler setup to event_buffer_timeout and disarm the * handler in empty_event_buffer? */ diff --git a/src/variables.c b/src/variables.c index e414dac..7158faa 100644 --- a/src/variables.c +++ b/src/variables.c @@ -5,6 +5,11 @@ #include "io.h" #include "util.h" +uzbl_cmdprop * +get_var_c(const gchar *name) { + return g_hash_table_lookup(uzbl.behave.proto_var, name); +} + void send_set_var_event(const char *name, const uzbl_cmdprop *c) { /* check for the variable type */ @@ -41,8 +46,8 @@ send_set_var_event(const char *name, const uzbl_cmdprop *c) { void expand_variable(GString *buf, const gchar *name) { - uzbl_cmdprop* c; - if((c = g_hash_table_lookup(uzbl.behave.proto_var, name))) { + uzbl_cmdprop* c = get_var_c(name); + if(c) { if(c->type == TYPE_STR) { gchar *v = get_var_value_string_c(c); g_string_append(buf, v); @@ -54,50 +59,59 @@ expand_variable(GString *buf, const gchar *name) { } } +void +set_var_value_string_c(uzbl_cmdprop *c, const gchar *val) { + if(c->setter) + ((void (*)(const gchar *))c->setter)(val); + else { + g_free(*(c->ptr.s)); + *(c->ptr.s) = g_strdup(val); + } +} + +void +set_var_value_int_c(uzbl_cmdprop *c, int i) { + if(c->setter) + ((void (*)(int))c->setter)(i); + else + *(c->ptr.i) = i; +} + +void +set_var_value_float_c(uzbl_cmdprop *c, float f) { + if(c->setter) + ((void (*)(float))c->setter)(f); + else + *(c->ptr.f) = f; +} + gboolean set_var_value(const gchar *name, gchar *val) { - uzbl_cmdprop *c = NULL; - g_assert(val != NULL); - if( (c = g_hash_table_lookup(uzbl.behave.proto_var, name)) ) { + uzbl_cmdprop *c = get_var_c(name); + + if(c) { if(!c->writeable) return FALSE; - if(c->setter) { - switch(c->type) { - case TYPE_STR: - ((void (*)(const gchar *))c->setter)(val); - break; - case TYPE_INT: - { - int i = (int)strtoul(val, NULL, 10); - ((void (*)(int))c->setter)(i); - break; - } - case TYPE_FLOAT: - { - float f = strtod(val, NULL); - ((void (*)(float))c->setter)(f); - break; - } - default: - g_assert_not_reached(); - } - } else { - switch(c->type) { - case TYPE_STR: - g_free(*(c->ptr.s)); - *(c->ptr.s) = g_strdup(val); - break; - case TYPE_INT: - *(c->ptr.i) = (int)strtoul(val, NULL, 10); - break; - case TYPE_FLOAT: - *(c->ptr.f) = strtod(val, NULL); - break; - default: - g_assert_not_reached(); - } + switch(c->type) { + case TYPE_STR: + set_var_value_string_c(c, val); + break; + case TYPE_INT: + { + int i = (int)strtoul(val, NULL, 10); + set_var_value_int_c(c, i); + break; + } + case TYPE_FLOAT: + { + float f = strtod(val, NULL); + set_var_value_float_c(c, f); + break; + } + default: + g_assert_not_reached(); } send_set_var_event(name, c); @@ -148,7 +162,7 @@ get_var_value_string_c(const uzbl_cmdprop *c) { gchar* get_var_value_string(const gchar *name) { - uzbl_cmdprop *c = g_hash_table_lookup(uzbl.behave.proto_var, name); + uzbl_cmdprop *c = get_var_c(name); return get_var_value_string_c(c); } @@ -166,7 +180,7 @@ get_var_value_int_c(const uzbl_cmdprop *c) { int get_var_value_int(const gchar *name) { - uzbl_cmdprop *c = g_hash_table_lookup(uzbl.behave.proto_var, name); + uzbl_cmdprop *c = get_var_c(name); return get_var_value_int_c(c); } @@ -184,7 +198,7 @@ get_var_value_float_c(const uzbl_cmdprop *c) { float get_var_value_float(const gchar *name) { - uzbl_cmdprop *c = g_hash_table_lookup(uzbl.behave.proto_var, name); + uzbl_cmdprop *c = get_var_c(name); return get_var_value_float_c(c); } diff --git a/src/variables.h b/src/variables.h index 4f85474..dade652 100644 --- a/src/variables.h +++ b/src/variables.h @@ -10,6 +10,8 @@ #include "type.h" +uzbl_cmdprop *get_var_c(const gchar *name); + gboolean set_var_value(const gchar *name, gchar *val); void expand_variable(GString *buf, const gchar *name); void variables_hash(); @@ -21,6 +23,12 @@ int get_var_value_int(const char *name); float get_var_value_float_c(const uzbl_cmdprop *c); float get_var_value_float(const char *name); +void set_var_value_string_c(uzbl_cmdprop *c, const gchar *val); +void set_var_value_int_c(uzbl_cmdprop *c, int f); +void set_var_value_float_c(uzbl_cmdprop *c, float f); + +void send_set_var_event(const char *name, const uzbl_cmdprop *c); + void dump_config(); void dump_config_as_events(); |