aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar keis <keijser@gmail.com>2009-10-28 16:08:14 +0100
committerGravatar keis <keijser@gmail.com>2009-10-28 16:08:14 +0100
commit9fe687b21c31dd56a398f30c946bd354cb6b169f (patch)
tree5cc4ec0e88bb101316967618574ca20814d75c03 /examples
parentf5ca0aa5c05df75dd3268e85feb8947b92486aaf (diff)
parent9d7ae1b21aefac2cf5418667bd150c110bf8932e (diff)
Merge branch 'experimental' of git://github.com/Dieterbe/uzbl into prompt
Diffstat (limited to 'examples')
-rw-r--r--examples/config/uzbl/config26
-rw-r--r--examples/data/uzbl/plugins/bind.py4
-rw-r--r--examples/data/uzbl/plugins/keycmd.py82
-rw-r--r--examples/data/uzbl/plugins/mode.py1
-rwxr-xr-xexamples/data/uzbl/scripts/event_manager.py31
5 files changed, 93 insertions, 51 deletions
diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config
index e5b3c6a..4b04d7a 100644
--- a/examples/config/uzbl/config
+++ b/examples/config/uzbl/config
@@ -13,6 +13,8 @@ set toggle_modes = request TOGGLE_MODES
set on_event = request ON_EVENT
# request PROGRESS_CONFIG <key> = <value>
set progress = request PROGRESS_CONFIG
+# request MODMAP From To
+set modmap = request MODMAP
set set_mode = set mode =
set set_status = set status_message =
@@ -26,7 +28,7 @@ set scripts_dir = $XDG_DATA_HOME/uzbl:/usr/local/share/uzbl/examples/data/uzb
set download_handler = spawn @scripts_dir/download.sh
set cookie_handler = talk_to_socket $XDG_CACHE_HOME/uzbl/cookie_daemon_socket
-set scheme_handler = spawn @scripts_dir/scheme.py
+set scheme_handler = sync_spawn @scripts_dir/scheme.py
# New window handler options
#set new_window = sh 'echo uri "$8" > $4' # open in same window
@@ -42,8 +44,8 @@ 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 an editable
-# element on the loaded site has initial focus
+# Generate a FORM_ACTIVE event if an editable
+# element on the loaded site has initial focus
@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
@@ -98,6 +100,14 @@ set fifo_dir = /tmp
set socket_dir = /tmp
+# === Binding modmaps ========================================================
+
+#modmap from to
+@modmap Control Ctrl
+@modmap ISO_Left_Tab Shift-Tab
+@modmap space Space
+
+
# === Keyboard bindings ======================================================
# With this command you can enter in any command at runtime when prefixed with
@@ -133,7 +143,8 @@ set socket_dir = /tmp
@bind gg _ = uri http://www.google.com/search?q=%s
# Enclose the executable in quotes if it has spaces. Any additional parameters you use will
# appear AFTER the default parameters
-#@bind B = spawn @scripts_dir/insert_bookmark.sh
+# use a script to insert bookmarks. or use the EM/keycmd technique a bit further down
+@bind B = spawn @scripts_dir/insert_bookmark.sh
@bind U = spawn @scripts_dir/load_url_from_history.sh
@bind u = spawn @scripts_dir/load_url_from_bookmarks.sh
# with the sample yank script, you can yank one of the arguments into clipboard/selection
@@ -159,7 +170,7 @@ set socket_dir = /tmp
@bind XS = sh 'echo "js alert (\\"This is sent by the shell via a fifo\\")" > "$4"'
@bind !dump = sh "echo dump_config > $4"
-@bind !reload = sh 'cat $1 > $4'
+@bind !reload = sh "sed '/^# === Post-load misc commands/,$d' $1 > $4"
# this script allows you to configure (per domain) values to fill in form fields (eg login information) and to fill in these values automatically
set formfiller = spawn @scripts_dir/formfiller
@@ -188,9 +199,8 @@ set formfiller = spawn @scripts_dir/formfiller
@bind o<uri:>_ = uri %s
@bind O<uri:"\@uri">_ = uri %s
-# Prints tab separated "uri title keyword tags" to the bookmarks file.
-# TODO: Improve bookmarks script to handle this format & include date in bookmark format.
-@bind <Ctrl>b<name:>_<tags:>_ = sh 'echo -e "$6 $7 %s %s" >> $XDG_DATA_HOME/uzbl/bookmarks'
+# multi-stage binding way to write bookmarks to file from inside uzbl.
+@bind <Ctrl>b<tags:>_ = sh 'echo -e "$6 %s" >> $XDG_DATA_HOME/uzbl/bookmarks'
# Multi-stage bindings with blank prompts (similar behaviour to emacs M-c M-s bindings?)
@bind <Ctrl>a<:><Ctrl>q = exit
diff --git a/examples/data/uzbl/plugins/bind.py b/examples/data/uzbl/plugins/bind.py
index 8cd0702..356b6bd 100644
--- a/examples/data/uzbl/plugins/bind.py
+++ b/examples/data/uzbl/plugins/bind.py
@@ -24,7 +24,7 @@ starts_with_mod = re.compile('^<([A-Z][A-Za-z0-9-_]*)>')
find_prompts = re.compile('<([^:>]*):(\"[^>]*\"|)>').split
# For accessing a bind glob stack.
-MOD_CMD, ON_EXEC, HAS_ARGS, GLOB = range(4)
+MOD_CMD, ON_EXEC, HAS_ARGS, GLOB, MORE = range(5)
class BindParseError(Exception):
@@ -188,7 +188,7 @@ class Bind(object):
stack.append((mod_cmd, on_exec, has_args, glob, index))
self.stack = list(reversed(stack))
- self.is_global = len(self.stack) == 1
+ self.is_global = (len(self.stack) == 1 and self.stack[0][MOD_CMD])
def __getitem__(self, depth):
diff --git a/examples/data/uzbl/plugins/keycmd.py b/examples/data/uzbl/plugins/keycmd.py
index 109bb38..d01d2ac 100644
--- a/examples/data/uzbl/plugins/keycmd.py
+++ b/examples/data/uzbl/plugins/keycmd.py
@@ -2,18 +2,11 @@ import re
# Map these functions/variables in the plugins namespace to the uzbl object.
__export__ = ['clear_keycmd', 'set_keycmd', 'set_cursor_pos', 'get_keylet',
- 'clear_current', 'clear_modcmd']
+ 'clear_current', 'clear_modcmd', 'add_modmap']
# Hold the keylets.
UZBLS = {}
-# Simple key names map.
-SIMPLEKEYS = {
- 'Control': 'Ctrl',
- 'ISO_Left_Tab': 'Shift-Tab',
- 'space':'Space',
-}
-
# Keycmd format which includes the markup for the cursor.
KEYCMD_FORMAT = "%s<span @cursor_style>%s</span>%s"
@@ -46,6 +39,9 @@ class Keylet(object):
self.keycmd = ''
self.cursor = 0
+ # Key modmaps.
+ self.modmap = {}
+
# Keylet string repr cache.
self._repr_cache = None
@@ -65,6 +61,20 @@ class Keylet(object):
return ''.join(['<%s>' % key for key in self.held]) + self.modcmd
+ def key_modmap(self, key):
+ '''Make some obscure names for some keys friendlier.'''
+
+ if key in self.modmap:
+ return self.modmap[key]
+
+ elif key.endswith('_L') or key.endswith('_R'):
+ # Remove left-right discrimination and try again.
+ return self.key_modmap(key[:-2])
+
+ else:
+ return key
+
+
def __repr__(self):
'''Return a string representation of the keylet.'''
@@ -85,17 +95,30 @@ class Keylet(object):
return self._repr_cache
-def make_simple(key):
- '''Make some obscure names for some keys friendlier.'''
+def add_modmap(uzbl, key, map=None):
+ '''Add modmaps.'''
+
+ keylet = get_keylet(uzbl)
+ if not map:
+ if key in keylet.modmap:
+ map = keylet.modmap[key]
+ del keylet.modmap[key]
+ uzbl.event("DEL_MODMAP", key, map)
+
+ else:
+ keylet.modmap[key] = map
+ uzbl.event("NEW_MODMAP", key, map)
+
+
+def modmap_parse(uzbl, map):
+ '''Parse a modmap definiton.'''
- # Remove left-right discrimination.
- if key.endswith('_L') or key.endswith('_R'):
- key = key[:-2]
+ split = [s.strip() for s in map.split(' ') if s.split()]
- if key in SIMPLEKEYS:
- key = SIMPLEKEYS[key]
+ if not split or len(split) > 2:
+ raise Exception('Invalid modmap arugments: %r' % map)
- return key
+ add_modmap(uzbl, *split)
def add_instance(uzbl, *args):
@@ -134,7 +157,6 @@ def clear_keycmd(uzbl):
config = uzbl.get_config()
if 'keycmd' not in config or config['keycmd'] != '':
uzbl.set('keycmd', '')
- uzbl.send('update_gui')
uzbl.event('KEYCMD_CLEAR')
@@ -152,7 +174,6 @@ def clear_modcmd(uzbl, clear_held=False):
config = uzbl.get_config()
if 'modcmd' not in config or config['modcmd'] != '':
uzbl.set('modcmd', '')
- uzbl.send('update_gui')
uzbl.event('MODCMD_CLEAR')
@@ -194,19 +215,16 @@ def update_event(uzbl, k, execute=True):
uzbl.set('modcmd', uzbl_escape(new_modcmd))
if 'keycmd_events' in config and config['keycmd_events'] != '1':
- return uzbl.send('update_gui')
+ return
new_keycmd = k.get_keycmd()
if not new_keycmd or new_keycmd != keycmd:
- uzbl.set('keycmd', '')
- return uzbl.send('update_gui')
-
+ return uzbl.set('keycmd', '')
# Generate the pango markup for the cursor in the keycmd.
curchar = keycmd[k.cursor] if k.cursor < len(keycmd) else ' '
chunks = [keycmd[:k.cursor], curchar, keycmd[k.cursor+1:]]
uzbl.set('keycmd', KEYCMD_FORMAT % tuple(map(uzbl_escape, chunks)))
- uzbl.send('update_gui')
def inject_char(str, index, char):
@@ -229,10 +247,11 @@ def key_press(uzbl, key):
if key.startswith('Shift_'):
return
- if len(key) > 1:
- key = make_simple(key)
-
k = get_keylet(uzbl)
+ key = k.key_modmap(key.strip())
+ if key.startswith("ISO_"):
+ return
+
if key == 'Space' and not k.held and k.keycmd:
k.keycmd = inject_char(k.keycmd, k.cursor, ' ')
k.cursor += 1
@@ -271,10 +290,9 @@ def key_release(uzbl, key):
3. Check if any modkey is held, if so set modcmd mode.
4. Update the keycmd uzbl variable if anything changed.'''
- if len(key) > 1:
- key = make_simple(key)
-
k = get_keylet(uzbl)
+ key = k.key_modmap(key)
+
if key in ['Shift', 'Tab'] and 'Shift-Tab' in k.held:
key = 'Shift-Tab'
@@ -286,9 +304,6 @@ def key_release(uzbl, key):
uzbl.event('MODCMD_EXEC', k)
k.held.remove(key)
- #k.is_modcmd = False
- #k.modcmd = ''
- #update_event(uzbl, k)
clear_modcmd(uzbl)
@@ -390,6 +405,7 @@ def init(uzbl):
'KEYCMD_EXEC_CURRENT': keycmd_exec_current,
'SET_CURSOR_POS': set_cursor_pos,
'FOCUS_LOST': focus_changed,
- 'FOCUS_GAINED': focus_changed}
+ 'FOCUS_GAINED': focus_changed,
+ 'MODMAP': modmap_parse}
uzbl.connect_dict(connects)
diff --git a/examples/data/uzbl/plugins/mode.py b/examples/data/uzbl/plugins/mode.py
index ad0d9a8..e7705a0 100644
--- a/examples/data/uzbl/plugins/mode.py
+++ b/examples/data/uzbl/plugins/mode.py
@@ -88,7 +88,6 @@ def set_mode(uzbl, mode=None):
config['mode_indicator'] = mode
uzbl.clear_keycmd()
- uzbl.send('update_gui')
uzbl.event("MODE_CHANGED", mode)
diff --git a/examples/data/uzbl/scripts/event_manager.py b/examples/data/uzbl/scripts/event_manager.py
index 391fb84..9c269c7 100755
--- a/examples/data/uzbl/scripts/event_manager.py
+++ b/examples/data/uzbl/scripts/event_manager.py
@@ -45,6 +45,12 @@ from traceback import print_exc
# ::: Default configuration section ::::::::::::::::::::::::::::::::::::::::::
# ============================================================================
+# Automagically set during `make install`
+PREFIX = None
+
+# Check if PREFIX not set and set to default /usr/local/
+if not PREFIX:
+ PREFIX = '/usr/local/'
def xdghome(key, default):
'''Attempts to use the environ XDG_*_HOME paths if they exist otherwise
@@ -60,16 +66,18 @@ def xdghome(key, default):
DATA_DIR = os.path.join(xdghome('DATA', '.local/share/'), 'uzbl/')
CACHE_DIR = os.path.join(xdghome('CACHE', '.cache/'), 'uzbl/')
+
# Config dict (NOT the same as the uzbl.config).
config = {
'verbose': False,
'daemon_mode': True,
+ 'auto_close': False,
'plugins_load': [],
'plugins_ignore': [],
'plugin_dirs': [os.path.join(DATA_DIR, 'plugins/'),
- '/usr/local/share/uzbl/examples/data/uzbl/plugins/'],
+ os.path.join(PREFIX, 'share/uzbl/examples/data/uzbl/plugins/')],
'server_socket': os.path.join(CACHE_DIR, 'event_daemon'),
'pid_file': os.path.join(CACHE_DIR, 'event_daemon.pid'),
@@ -657,16 +665,18 @@ class UzblEventDaemon(dict):
'''Clean up after instance close.'''
try:
- if client not in self['uzbls']:
- return
-
- uzbl = self['uzbls'][client]
- uzbl.close()
- del self['uzbls'][client]
+ if client in self['uzbls']:
+ uzbl = self['uzbls'][client]
+ uzbl.close()
+ del self['uzbls'][client]
except:
print_exc()
+ if not len(self['uzbls']) and config['auto_close']:
+ echo('auto closing event manager.')
+ self.running = False
+
def quit(self):
'''Close all instance socket objects, server socket and delete the
@@ -776,6 +786,9 @@ if __name__ == "__main__":
parser.add_option('-n', '--no-daemon', dest="daemon",
action="store_true", help="don't enter daemon mode.")
+ parser.add_option('-a', '--auto-close', dest='autoclose',
+ action='store_true', help='auto close after all instances disconnect.')
+
(options, args) = parser.parse_args()
# init like {start|stop|..} daemon control section.
@@ -824,6 +837,10 @@ if __name__ == "__main__":
echo('ignoring plugin(s): %s' % ', '.join(plugins_ignore))
+ if options.autoclose:
+ config['auto_close'] = True
+ echo('will auto close.')
+
if options.pid:
config['pid_file'] = options.pid
echo("pid file location: %r" % config['pid_file'])