aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Pawel Tomak <satherot@gmail.com>2010-03-11 21:43:15 +0100
committerGravatar Pawel Tomak <satherot@gmail.com>2010-03-11 21:43:15 +0100
commitf01a759117615d20dc2d24d710610c0a64db34a9 (patch)
treee463c20424ee9cd52ad7abfb1a93428bcce9f9eb
parentbb862588a60e48ac47759b0b8fda36d9a0775df8 (diff)
parent5f6fe61088d70438ac50da1ace531925061f5704 (diff)
Merge branch 'experimental' of git://github.com/Dieterbe/uzbl into eFormFiller
-rw-r--r--Makefile34
-rw-r--r--examples/config/config17
-rw-r--r--examples/data/scripts/follower.js26
-rwxr-xr-xexamples/data/scripts/instance-select-wmii.sh2
-rwxr-xr-xexamples/data/scripts/uzbl-cookie-daemon5
-rwxr-xr-xexamples/data/scripts/uzbl-event-manager58
-rwxr-xr-xexamples/data/scripts/uzbl-tabbed30
-rwxr-xr-xexamples/data/scripts/uzblcat1
-rw-r--r--src/uzbl-core.c11
-rw-r--r--tests/test-expand.c7
10 files changed, 105 insertions, 86 deletions
diff --git a/Makefile b/Makefile
index 79a7297..6526ce6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,40 +1,28 @@
# first entries are for gnu make, 2nd for BSD make. see http://lists.uzbl.org/pipermail/uzbl-dev-uzbl.org/2009-July/000177.html
-CFLAGS:=-std=c99 $(shell pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0) -ggdb -Wall -W -DARCH="\"$(shell uname -m)\"" -lgthread-2.0 -DCOMMIT="\"$(shell ./misc/hash.sh)\"" $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic
-CFLAGS!=echo -std=c99 `pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0` -ggdb -Wall -W -DARCH='"\""'`uname -m`'"\""' -lgthread-2.0 -DCOMMIT='"\""'`./misc/hash.sh`'"\""' $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic
+CFLAGS:=-std=c99 $(shell pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0) -ggdb -Wall -W -DARCH="\"$(shell uname -m)\"" -DCOMMIT="\"$(shell ./misc/hash.sh)\"" $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic
+CFLAGS!=echo -std=c99 `pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0` -ggdb -Wall -W -DARCH='"\""'`uname -m`'"\""' -DCOMMIT='"\""'`./misc/hash.sh`'"\""' $(CPPFLAGS) -fPIC -W -Wall -Wextra -pedantic
-LDFLAGS:=$(shell pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0) -pthread $(LDFLAGS)
-LDFLAGS!=echo `pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0` -pthread $(LDFLAGS)
+LDFLAGS:=$(shell pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0) $(LDFLAGS)
+LDFLAGS!=echo `pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0` $(LDFLAGS)
SRC = $(wildcard src/*.c)
HEAD = $(wildcard src/*.h)
-TOBJ = $(SRC:.c=.o)
-OBJ = $(foreach obj, $(TOBJ), $(notdir $(obj)))
+OBJ = $(foreach obj, $(SRC:.c=.o), $(notdir $(obj)))
-all: uzbl-browser options
-
-options:
- @echo
- @echo BUILD OPTIONS:
- @echo "CFLAGS = ${CFLAGS}"
- @echo "LDFLAGS = ${LDFLAGS}"
- @echo
- @echo See the README file for usage instructions.
+all: uzbl-browser
+VPATH:=src
.c.o:
- @echo COMPILING $<
+ @echo -e "${CC} -c ${CFLAGS} $<"
@${CC} -c ${CFLAGS} $<
- @echo ... done.
${OBJ}: ${HEAD}
-uzbl-core: ${TOBJ} # why doesn't ${OBJ} work?
- @echo
- @echo LINKING object files
+uzbl-core: ${OBJ}
+ @echo -e "\n${CC} -o $@ ${OBJ} ${LDFLAGS}"
@${CC} -o $@ ${OBJ} ${LDFLAGS}
- @echo ... done.
-
uzbl-browser: uzbl-core
@@ -50,7 +38,7 @@ RUN_PREFIX?=$(PREFIX)
force:
# When compiling unit tests, compile uzbl as a library first
-tests: ${TOBJ} force
+tests: ${OBJ} force
$(CC) -shared -Wl ${OBJ} -o ./tests/libuzbl-core.so
cd ./tests/; $(MAKE)
diff --git a/examples/config/config b/examples/config/config
index 418ced3..d52e65b 100644
--- a/examples/config/config
+++ b/examples/config/config
@@ -57,12 +57,12 @@ set new_window = sh 'uzbl-browser -u $8'
# Load start handler
@on_event LOAD_START @set_status <span foreground="khaki">wait</span>
+# Reset the keycmd on navigation
+@on_event LOAD_START @set_mode
# Load commit handlers
@on_event LOAD_COMMIT @set_status <span foreground="green">recv</span>
#@on_event LOAD_COMMIT script @scripts_dir/scroll-percentage.js
-# Reset the keycmd on navigation
-@on_event LOAD_COMMIT @set_mode
# Load finish handlers
@on_event LOAD_FINISH @set_status <span foreground="gold">done</span>
@@ -186,7 +186,7 @@ set ebind = @mode_bind global,-insert
# === Mouse bindings =========================================================
# Middle click open in new window
-@bind <Button2> = sh 'if [ "\@SELECTED_URI" ]; then uzbl-browser -u "\@SELECTED_URI"; else echo "uri $(xclip -o)" > $4; fi'
+@bind <Button2> = sh 'if [ "\@SELECTED_URI" ]; then uzbl-browser -u "\@SELECTED_URI"; else echo "uri $(xclip -o | sed s/\\\@/%40/g)" > $4; fi'
# === Keyboard bindings ======================================================
@@ -235,8 +235,10 @@ set ebind = @mode_bind global,-insert
# --- Uzbl tabbed binds ---
# Tab opening
@cbind gn = event NEW_TAB
+@cbind gN = event NEW_TAB_NEXT
@cbind go<uri:>_ = event NEW_TAB %s
-@cbind gY = sh 'echo "event NEW_TAB `xclip -selection primary -o`" > $4'
+@cbind gO<uri:>_ = event NEW_TAB_NEXT %s
+@cbind gY = sh 'echo "event NEW_TAB `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4'
# Closing / resting
@cbind gC = exit
@cbind gQ = event CLEAN_TABS
@@ -267,7 +269,8 @@ set preset = event PRESET_TABS
@cbind !dump = sh "echo dump_config > $4"
# Reload config
@cbind !reload = sh "sed '/^# === Post-load misc commands/,$d' $1 > $4"
-# If you want to see all events being triggered:
+# Use socat to directly inject commands into uzbl-core and view events
+# raised by uzbl-core:
@cbind <Ctrl><Alt>t = sh 'xterm -e "socat unix-connect:$5 -"'
#@cbind <Ctrl><Alt>t = sh 'urxvt -e socat unix-connect:$5 -'
@@ -293,9 +296,9 @@ set toggle_cmd_ins = @toggle_modes command insert
@cbind yy = sh 'echo -n $7 | xclip'
# Go the page from primary selection
-@cbind p = sh 'echo "uri `xclip -selection primary -o`" > $4'
+@cbind p = sh 'echo "uri `xclip -selection primary -o | sed s/\\\@/%40/g`" > $4'
# Go to the page in clipboard
-@cbind P = sh 'echo "uri `xclip -selection clipboard -o`" > $4'
+@cbind P = sh 'echo "uri `xclip -selection clipboard -o | sed s/\\\@/%40/g`" > $4'
# Start a new uzbl instance from the page in primary selection
@cbind 'p = sh 'exec uzbl-browser --uri $(xclip -o)'
diff --git a/examples/data/scripts/follower.js b/examples/data/scripts/follower.js
index 604b779..dc37b46 100644
--- a/examples/data/scripts/follower.js
+++ b/examples/data/scripts/follower.js
@@ -16,7 +16,7 @@
// be done with:
//
// @on_event LOAD_COMMIT script /path/to/follower.js
-//
+//
// Then you can bind it to a key:
//
// @bind f* = js follower.follow('%s', matchSpec, handler, hintStyler)
@@ -26,7 +26,7 @@
// set these to follower.genericMatchSpec, follower.genericHandler and
// follower.genericHintStyler respectively.
//
-// For example,
+// For example,
//
// @bind f* = js follower.follow('%s', follower.genericMatchSpec, follower.genericHandler, follower.genericHintStyler)
// @bind F* = js follower.follow('%s', follower.onlyLinksMatchSpec, follower.newPageHandler, follower.newPageHintStyler)
@@ -53,7 +53,7 @@
// * What elements are hinted.
// * The style of the hints displayed.
// * How the hints are handled.
-//
+//
// In order to customize behavior, write an alternative, and pass that in to
// follower.follow invocation. You _will_ have to modify this script, but only
// locally, it beats having to copy the entire script under a new name and
@@ -75,11 +75,11 @@ String.prototype.lpad = function(padding, length) {
return padded;
}
-function Follower() {
+function Follower() {
// Globals
- var uzblID = 'uzbl-follow'; // ID to apply to each hint.
- var uzblContainerID = 'uzbl-follow-container'; // ID to apply to the div containing hints.
+ var uzblID = 'uzbl-follow'; // ID to apply to each hint.
+ var uzblContainerID = 'uzbl-follow-container'; // ID to apply to the div containing hints.
// Translation table, used to display something other than numbers as hint
// labels. Typically set to the ten keys of the home row.
@@ -147,7 +147,7 @@ function Follower() {
}
Uzbl.run("event SET_KEYCMD");
}
-
+
// Handler to open links in a new page. The rest is the same as before.
this.newPageHandler = function(node) {
if (node) {
@@ -387,24 +387,24 @@ function Follower() {
// The main hinting function. I don't know how to do default values to
// functions, so all arguments must be specified. Use generics if you must.
this.follow = function(target, matchSpec, handler, hintStyler) {
- var container = generateHintContainer(); // Get a container to hold all hints.
+ var container = generateHintContainer(); // Get a container to hold all hints.
var allHintables = generateHintables(matchSpec); // Get all items that can be hinted.
- hintables = filterHintables(allHintables, target); // Filter them based on current input.
-
+ hintables = filterHintables(allHintables, target); // Filter them based on current input.
+
clearHints(); // Clear existing hints, if any.
if (hintables[0].length == 0) {
// Nothing was hinted, user pressed an unknown key, maybe?
// Do nothing.
} else if (hintables[0].length == 1) {
- handler(hintables[0][0]); // Only one hint remains, handle it.
+ handler(hintables[0][0]); // Only one hint remains, handle it.
} else {
- drawHints(container, hintables, hintStyler); // Draw whatever hints remain.
+ drawHints(container, hintables, hintStyler); // Draw whatever hints remain.
}
return;
};
-}
+}
// Make on-click links clickable.
try {
diff --git a/examples/data/scripts/instance-select-wmii.sh b/examples/data/scripts/instance-select-wmii.sh
index 2bf13ba..fdd27e6 100755
--- a/examples/data/scripts/instance-select-wmii.sh
+++ b/examples/data/scripts/instance-select-wmii.sh
@@ -6,7 +6,7 @@
# you can select one from a list, or go to the next/previous one
# It does not change the layout (stacked/tiled/floating) nor does it
# changes the size or viewing mode of a uzbl window
-# When your current uzbl window is maximized, the one you change to
+# When your current uzbl window is maximized, the one you change to
# will be maximized as well.
# See http://www.uzbl.org/wiki/wmii for more info
# $1 must be one of 'list', 'next', 'prev'
diff --git a/examples/data/scripts/uzbl-cookie-daemon b/examples/data/scripts/uzbl-cookie-daemon
index fde8b8e..ed88de4 100755
--- a/examples/data/scripts/uzbl-cookie-daemon
+++ b/examples/data/scripts/uzbl-cookie-daemon
@@ -269,8 +269,9 @@ def daemonize():
sys.stderr.write("fork #2 failed")
sys.exit(1)
- sys.stdout.flush()
- sys.stderr.flush()
+ if sys.stdout.isatty():
+ sys.stdout.flush()
+ sys.stderr.flush()
devnull = '/dev/null'
stdin = file(devnull, 'r')
diff --git a/examples/data/scripts/uzbl-event-manager b/examples/data/scripts/uzbl-event-manager
index 9624b14..7fa4a09 100755
--- a/examples/data/scripts/uzbl-event-manager
+++ b/examples/data/scripts/uzbl-event-manager
@@ -39,6 +39,7 @@ from signal import signal, SIGTERM
from optparse import OptionParser
from traceback import print_exc
from functools import partial
+from itertools import count
def xdghome(key, default):
@@ -107,15 +108,6 @@ def error(msg):
sys.stderr.write("%s: error: %s\n" % (SCRIPTNAME, msg))
-def counter():
- '''Generate unique object id's.'''
-
- i = 0
- while True:
- i += 1
- yield i
-
-
def find_plugins(plugin_dirs):
'''Find all event manager plugins in the plugin dirs and return a
dictionary of {'plugin-name.py': '/full/path/to/plugin-name.py', ...}'''
@@ -201,8 +193,9 @@ def daemonize():
sys.stderr.write("fork #2 failed")
sys.exit(1)
- sys.stdout.flush()
- sys.stderr.flush()
+ if sys.stdout.isatty():
+ sys.stdout.flush()
+ sys.stderr.flush()
devnull = '/dev/null'
stdin = file(devnull, 'r')
@@ -318,7 +311,7 @@ def parse_msg(uzbl, msg):
class EventHandler(object):
- nexthid = counter().next
+ nexthid = count().next
def __init__(self, event, handler, *args, **kargs):
if not callable(handler):
@@ -348,7 +341,7 @@ class EventHandler(object):
class UzblInstance(object):
# Give all plugins access to the main config dict.
- config = CONFIG
+ global_config = CONFIG
def __init__(self, parent, client_socket):
@@ -385,21 +378,40 @@ class UzblInstance(object):
print (u'%s!-- %s' % (' ' * self.depth, msg)).encode('utf-8')
- def export(self, name, function):
- '''Export `function(uzbl, *args, ..)` inside a plugin to the uzbl
- object like so `uzbl.function(*args, ..)`. This will allow other
- plugins to call functions inside the current plugin (which is currently
- calling this function) via the uzbl object.'''
+ def export(self, attr, object, prepend=True):
+ '''Attach an object to the current class instance. This is the
+ preferred method of sharing functionality, functions and objects
+ between plugins.
+
+ If the object is callable you may wish to turn the callable object in
+ to an "instance method call" by using the `functools.partial(..)`
+ tool to prepend the `self` object to the callable objects argument
+ list.
+
+ Example session from a plugins POV:
+ >>> config_dict = {'foo': 'data..', 'bar': 'other data..'}
+ >>> uzbl.export('config', config_dict)
+ >>> uzbl.config is config_dict
+ True
+ >>> print uzbl.config['foo']
+ data..
+ >>> uzbl.export('get', lambda uzbl, key: uzbl.config[key])
+ >>> print uzbl.get('bar')
+ other data..
+ '''
+
+ if prepend and callable(object):
+ object = partial(object, self)
- self.__dict__.__setitem__(name, partial(function, self))
+ self.__dict__.__setitem__(attr, object)
def export_dict(self, export_dict):
- '''Export multiple (name, function)'s at once inside a dict of the
- form `{name1: function1, name2: function2, ...}`.'''
+ '''Export multiple (attr, object)'s at once inside a dict of the
+ form `{attr1: object1, attr2: object2, ...}`.'''
- for (name, function) in export_dict.items():
- self.export(name, function)
+ for (attr, object) in export_dict.items():
+ self.export(attr, object)
def connect(self, event, handler, *args, **kargs):
diff --git a/examples/data/scripts/uzbl-tabbed b/examples/data/scripts/uzbl-tabbed
index 7bd90d5..f07bae4 100755
--- a/examples/data/scripts/uzbl-tabbed
+++ b/examples/data/scripts/uzbl-tabbed
@@ -371,8 +371,9 @@ class SocketClient:
class UzblInstance:
'''Uzbl instance meta-data/meta-action object.'''
- def __init__(self, parent, tab, name, uri, title, switch):
+ def __init__(self, parent, tab, name, uri, title, switch, process):
+ self.process = process
self.parent = parent
self.tab = tab
self.name = name
@@ -488,6 +489,13 @@ class UzblInstance:
self.parent.update_tablist()
elif type == "NEW_TAB":
self.parent.new_tab(args)
+ elif type == "NEW_BG_TAB":
+ self.parent.new_tab(args, '', 0)
+ elif type == "NEW_TAB_NEXT":
+ self.parent.new_tab(args, next=True)
+ elif type == "NEW_BG_TAB_NEXT":
+ self.parent.new_tab(args, '', 0, next=True)
+
elif type == "NEXT_TAB":
if args:
self.parent.next_tab(int(args))
@@ -521,6 +529,18 @@ class UzblInstance:
self._client.close()
self._client = None
+ pid = self.process.pid
+ timeout = time.time() + 5
+
+ while self.process.poll() is None and time.time() < timeout:
+ # Sleep between polls.
+ time.sleep(0.1)
+
+ if self.process.poll() is None:
+ # uzbl instance didn't exit in time.
+ error("quit timeout expired, sending SIGTERM to uzbl instance")
+ self.process.terminate()
+
class UzblTabbed:
'''A tabbed version of uzbl using gtk.Notebook'''
@@ -966,7 +986,7 @@ class UzblTabbed:
return False
- def new_tab(self, uri='', title='', switch=None):
+ def new_tab(self, uri='', title='', switch=None, next=False):
'''Add a new tab to the notebook and start a new instance of uzbl.
Use the switch option to negate config['switch_to_new_tabs'] option
when you need to load multiple tabs at a time (I.e. like when
@@ -974,7 +994,7 @@ class UzblTabbed:
tab = gtk.Socket()
tab.show()
- self.notebook.append_page(tab)
+ self.notebook.insert_page(tab, position=next and self.notebook.get_current_page() + 1 or -1)
sid = tab.get_id()
uri = uri.strip()
name = "%d-%d" % (os.getpid(), self.next_pid())
@@ -987,9 +1007,9 @@ class UzblTabbed:
cmd = ['uzbl-browser', '-n', name, '-s', str(sid),
'--connect-socket', self.socket_path, '--uri', uri]
- subprocess.Popen(cmd) # TODO: do i need close_fds=True ?
+ process = subprocess.Popen(cmd) # TODO: do i need close_fds=True ?
- uzbl = UzblInstance(self, tab, name, uri, title, switch)
+ uzbl = UzblInstance(self, tab, name, uri, title, switch, process)
SocketClient.instances_queue[name] = uzbl
self.tabs[tab] = uzbl
diff --git a/examples/data/scripts/uzblcat b/examples/data/scripts/uzblcat
index e955608..4aa4b9e 100755
--- a/examples/data/scripts/uzblcat
+++ b/examples/data/scripts/uzblcat
@@ -9,4 +9,3 @@ for line in stdin:
stdout.write(line[0:-1])
# vim: set noet ff=unix
-
diff --git a/src/uzbl-core.c b/src/uzbl-core.c
index 6d90d09..d449ab3 100644
--- a/src/uzbl-core.c
+++ b/src/uzbl-core.c
@@ -500,7 +500,10 @@ clean_up(void) {
g_free(uzbl.info.pid_str);
g_free(uzbl.state.executable_path);
- g_hash_table_destroy(uzbl.behave.commands);
+ if (uzbl.behave.commands) {
+ g_hash_table_destroy(uzbl.behave.commands);
+ uzbl.behave.commands = NULL;
+ }
if(uzbl.state.event_buffer)
g_ptr_array_free(uzbl.state.event_buffer, TRUE);
@@ -1082,9 +1085,9 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result, const char *fi
size_t size;
JSStringRef prop, val;
JSObjectRef exc = JSValueToObject(context, js_exc, NULL);
-
+
printf("Exception occured while executing script:\n");
-
+
/* Print file */
prop = JSStringCreateWithUTF8CString("sourceURL");
val = JSValueToStringCopy(context, JSObjectGetProperty(context, exc, prop, NULL), NULL);
@@ -1108,7 +1111,7 @@ eval_js(WebKitWebView * web_view, gchar *script, GString *result, const char *fi
}
JSStringRelease(prop);
JSStringRelease(val);
-
+
/* Print message */
val = JSValueToStringCopy(context, exc, NULL);
size = JSStringGetMaximumUTF8CStringSize(val);
diff --git a/tests/test-expand.c b/tests/test-expand.c
index 7ea3d61..f64aba8 100644
--- a/tests/test-expand.c
+++ b/tests/test-expand.c
@@ -31,12 +31,6 @@ extern gchar* expand(char*, guint);
extern void make_var_to_name_hash(void);
void
-test_keycmd (void) {
- uzbl.state.keycmd = "gg winslow";
- g_assert_cmpstr(expand("@keycmd", 0), ==, "gg winslow");
-}
-
-void
test_uri (void) {
g_assert_cmpstr(expand("@uri", 0), ==, "");
@@ -184,7 +178,6 @@ main (int argc, char *argv[]) {
g_type_init();
g_test_init(&argc, &argv, NULL);
- g_test_add_func("/test-expand/@keycmd", test_keycmd);
g_test_add_func("/test-expand/@useragent", test_useragent);
g_test_add_func("/test-expand/@uri", test_uri);
g_test_add_func("/test-expand/@TITLE", test_TITLE);