aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README44
-rwxr-xr-xbin/uzbl-tabbed564
-rw-r--r--docs/README.uzbl-event-manager27
-rw-r--r--examples/config/config22
-rw-r--r--examples/data/plugins/bind.py8
-rw-r--r--examples/data/plugins/history.py2
-rw-r--r--examples/data/plugins/keycmd.py218
-rwxr-xr-xexamples/data/scripts/auth.py2
-rwxr-xr-xexamples/data/scripts/download.sh14
-rwxr-xr-xexamples/data/scripts/formfiller.sh12
-rwxr-xr-xexamples/data/scripts/insert_temp.sh7
-rwxr-xr-xexamples/data/scripts/load_url_from_temps.sh22
-rw-r--r--examples/data/scripts/util/dmenu.sh7
-rw-r--r--examples/data/scripts/util/uzbl-dir.sh1
-rw-r--r--src/callbacks.c55
-rw-r--r--src/callbacks.h5
-rw-r--r--src/cookie-jar.c2
-rw-r--r--src/events.c91
-rw-r--r--src/events.h8
-rw-r--r--src/uzbl-core.c131
-rw-r--r--src/uzbl-core.h5
21 files changed, 575 insertions, 672 deletions
diff --git a/README b/README
index 6709bf5..7c5a673 100644
--- a/README
+++ b/README
@@ -104,7 +104,7 @@ There are several interfaces to interact with Uzbl:
When `uzbl` forks a new instance (eg "open in new window") it will use the same
command line arguments (eg the same `--config <file>`), except `--uri` and
-`--name`. If you made changes to the configuration at runtime, these are not
+`--named`. If you made changes to the configuration at runtime, these are not
passed on to the child.
#### Uzbl-browser
@@ -257,11 +257,14 @@ The following commands are recognized:
- Show the WebInspector
* `add_cookie <domain> <path> <name> <value> <scheme> <expires>`
- Adds a new cookie to the cookie jar
-* 'delete_cookie <domain> <path> <name> <value> [<scheme> <expires>]`
- - Deletes a matching cookie from the cookie jar. scheme and expire time
- is currently not considered when matching.
-* 'clear_cookies`
- - Clears all cookies from the cookie jar
+* `delete_cookie <domain> <path> <name> <value> [<scheme> <expires>]`
+ - Deletes a matching cookie from the cookie jar. scheme and expire time
+ is currently not considered when matching.
+* `clear_cookies`
+ - Clears all cookies from the cookie jar
+* `download <uri> [<destination path>]`
+ - Starts a download using the given uri. A destination file path can be given
+ to specify where the download should be written to.
### VARIABLES AND CONSTANTS
@@ -316,7 +319,8 @@ file).
* `socket_dir`: location to store sockets.
* `http_debug`: HTTP debug mode (value 0-3).
* `scrollbars_visible`: set to 1 to have GTK scrollbars if the document
- doesn't fit into the window (defaults to 0)
+ doesn't fit into the window (defaults to 0). (Note: This option does nothing
+ on GTK3 due to <https://bugs.webkit.org/show_bug.cgi?id=59197>)
* `javascript_windows`: Whether javascript can open windows automatically
* `shell_cmd`: Alias which will be expanded to use shell commands (eg `sh -c`).
* `print_events`: show events on stdout
@@ -506,9 +510,15 @@ Handler scripts (`download_handler`, `cookie_handler`, `scheme_handler` and
* download handler
- `$1 url`: The URL of the item to be downloaded.
- - `$2 suggested_filename`: A filename suggested by the server or based on the URL.
+ - `$2 suggested_filename`: A filename suggested by the server or based on the
+ URL.
- `$3 content_type`: The mimetype of the file to be downloaded.
- - `$4 total_size`: The size of the file to be downloaded in bytes. This may be inaccurate.
+ - `$4 total_size`: The size of the file to be downloaded in bytes. This may be
+ inaccurate.
+ - `$5 destination_path`: This is only present if the download was started
+ explicitly using the `download` command. If it is present, this is the path
+ that the file should be saved to. A download handler using WebKit's internal
+ downloader can just echo this path and exit when this argument is present.
* cookie handler
@@ -668,10 +678,14 @@ Events have this format:
`uri`.
* `EVENT [uzbl_instance_name] LINK_UNHOVER uri`: The mouse leaves the link
`uri`.
-* `EVENT [uzbl_instance_name] KEY_PRESS key_name`: The key (or mouse button)
+* `EVENT [uzbl_instance_name] KEY_PRESS 'mod_state' key_name`: The key (or mouse button)
`key_name` is pressed.
-* `EVENT [uzbl_instance_name] KEY_RELEASE key_name`: The key (or mouse button)
+* `EVENT [uzbl_instance_name] KEY_RELEASE 'mod_state' key_name`: The key (or mouse button)
`key_name` is released.
+* `EVENT [uzbl_instance_name] MOD_PRESS 'mod_state' mod_name`: A key mapped to
+ `mod_name` is pressed.
+* `EVENT [uzbl_instance_name] MOD_RELEASE 'mod_state' mod_name`: A key mapped to
+ `mod_name` is released.
* `EVENT [uzbl_instance_name] SELECTION_CHANGED selected_text`: When text is
selected in the `uzbl` window.
* `EVENT [uzbl_instance_name] NEW_WINDOW uri`: Request to creation of new `uzbl` window,
@@ -749,10 +763,6 @@ Events/requests which the EM and its plugins listens for
when the `<from>` key or button is pressed.
* `IGNORE_KEY`: Ignore a key pattern, specified by `<glob>`.
- `request IGNORE_KEY <glob>`
-* `MODKEY_ADDITION`: Create a compound modkey from multiple individual keys.
- - `request MODKEY_ADDITION <key1> <key2> <keyn> <result>`: The modkey
- `<result>` is considered pressed when all of `<key1>`, `<key2>`, and
- `<keyn>` are pressed.
* `TOGGLE_MODES`
- `request TOGGLE_MODES <mode1> <mode2> ... <moden>`
* `APPEND_KEYCMD`: Append a string to the current keycmd.
@@ -764,6 +774,8 @@ Events/requests which the EM and its plugins listens for
keycmd.
* `KEYCMD_STRIP_WORD`: Removes the last word from the keycmd, similar to
readline `^W`.
+ - `request KEYCMD_STRIP_WORD <seps>`: The `<seps>` argument is a list of
+ characters that are considered to separate words.
* `KEYCMD_EXEC_CURRENT`: (tries to) execute whatever is in the keycmd.
* `SET_KEYCMD`: Allow setting of the keycmd externally.
- `request SET_KEYCMD <string>`: Set the keycmd to `<string>`.
@@ -793,7 +805,7 @@ where `arguments` and `uri` are both optional. `arguments` can be:
* `-u`, `--uri=URI`: URI to load at startup. Equivalent to `uzbl <uri>` or `set
uri = URI` after `uzbl` has launched.
* `-v`, `--verbose`: Whether to print all messages or just errors.
-* `-n`, `--name=NAME`: Name of the current instance (defaults to Xorg window
+* `-n`, `--named=NAME`: Name of the current instance (defaults to Xorg window
id or random for GtkSocket mode).
* `-c`, `--config=FILE`: Path to config file or `-` for stdin.
* `-s`, `--socket=SOCKET`: Xembed socket ID.
diff --git a/bin/uzbl-tabbed b/bin/uzbl-tabbed
index a15967a..1a65788 100755
--- a/bin/uzbl-tabbed
+++ b/bin/uzbl-tabbed
@@ -72,7 +72,6 @@
# gtk_tab_pos = (top|left|bottom|right)
# gtk_refresh = 1000
# switch_to_new_tabs = 1
-# capture_new_windows = 1
# multiline_tabs = 1
#
# Tab title options:
@@ -88,8 +87,6 @@
# session_file = $HOME/.local/share/uzbl/session
#
# Inherited uzbl options:
-# fifo_dir = /tmp
-# socket_dir = /tmp
# icon_path = $HOME/.local/share/uzbl/uzbl.png
# status_background = #303030
#
@@ -199,7 +196,6 @@ config = {
'gtk_tab_pos': 'top', # Gtk tab position (top|left|bottom|right)
'gtk_refresh': 1000, # Tablist refresh millisecond interval
'switch_to_new_tabs': True, # Upon opening a new tab switch to it
- 'capture_new_windows': True, # Use uzbl_tabbed to catch new windows
'multiline_tabs': True, # Tabs overflow onto new tablist lines.
# Tab title options
@@ -215,8 +211,6 @@ config = {
'session_file': os.path.join(DATA_DIR, 'session'),
# Inherited uzbl options
- 'fifo_dir': '/tmp', # Path to look for uzbl fifo.
- 'socket_dir': '/tmp', # Path to look for uzbl socket.
'icon_path': os.path.join(DATA_DIR, 'uzbl.png'),
'status_background': "#303030", # Default background for all panels.
@@ -298,17 +292,20 @@ def escape(s):
return s
class SocketClient:
- '''Represents a Uzbl instance, which is not necessarly linked with a UzblInstance'''
+ '''Represents a connection to the uzbl-tabbed socket.'''
# List of UzblInstance objects not already linked with a SocketClient
instances_queue = {}
- def __init__(self, socket):
+ def __init__(self, socket, uzbl_tabbed):
self._buffer = ""
self._socket = socket
self._watchers = [io_add_watch(socket, IO_IN, self._socket_recv),\
io_add_watch(socket, IO_HUP, self._socket_closed)]
+
self.uzbl = None
+ self.uzbl_tabbed = uzbl_tabbed
+ self.dispatcher = GlobalEventDispatcher(uzbl_tabbed)
def _socket_recv(self, fd, condition):
@@ -328,26 +325,44 @@ class SocketClient:
'''An Uzbl instance sent some data, parse it'''
self._buffer += data
- if self.uzbl:
- if "\n" in self._buffer:
- cmds = self._buffer.split("\n")
- if cmds[-1]: # Last command has been received incomplete, don't process it
- self._buffer, cmds = cmds[-1], cmds[:-1]
- else:
- self._buffer = ""
+ if "\n" in self._buffer:
+ cmds = self._buffer.split("\n")
- for cmd in cmds:
- if cmd:
- self.uzbl.parse_command(cmd)
- else:
- name = re.findall('^EVENT \[(\d+-\d+)\] INSTANCE_START \d+$', self._buffer, re.M)
- uzbl = self.instances_queue.get(name[0])
+ if cmds[-1]: # Last command has been received incomplete, don't process it
+ self._buffer, cmds = cmds[-1], cmds[:-1]
+ else:
+ self._buffer = ""
+
+ for cmd in cmds:
+ if cmd:
+ self.handle_event(cmd)
+
+ def handle_event(self, cmd):
+ cmd = parse_event(cmd)
+ message, instance_name, message_type = cmd[0:3]
+ args = cmd[3:]
+
+ if not message == "EVENT":
+ return
+
+ # strip the surrounding []
+ instance_name = instance_name[1:-1]
+
+ if self.uzbl:
+ if not self.dispatcher.dispatch(message_type, args):
+ self.uzbl.dispatcher.dispatch(message_type, args)
+ elif message_type == 'INSTANCE_START':
+ uzbl = self.instances_queue.get(instance_name)
if uzbl:
- del self.instances_queue[name[0]]
- self.uzbl = uzbl
- self.uzbl.got_socket(self)
- self._feed("")
+ # we've found the uzbl we were waiting for
+ del self.instances_queue[instance_name]
+ else:
+ # an unsolicited uzbl has connected, how exciting!
+ uzbl = UzblInstance(self.uzbl_tabbed, None, '', '', False)
+ self.uzbl = uzbl
+ self.uzbl.got_socket(self)
+ self._feed("")
def send(self, data):
'''Child socket send function.'''
@@ -363,18 +378,84 @@ class SocketClient:
map(source_remove, self._watchers)
self._watchers = []
-class EventDispatcher:
- def __init__(self, uzbl):
- self.uzbl = uzbl
- self.parent = self.uzbl.parent
+def unquote(s):
+ '''Removes quotation marks around strings if any and interprets
+ \\-escape sequences using `string_escape`'''
+ if s and s[0] == s[-1] and s[0] in ['"', "'"]:
+ s = s[1:-1]
+ return s.encode('utf-8').decode('string_escape').decode('utf-8')
+
+_splitquoted = re.compile("( |\"(?:\\\\.|[^\"])*?\"|'(?:\\\\.|[^'])*?')")
+def parse_event(text):
+ '''Splits string on whitespace while respecting quotations'''
+ return [unquote(p) for p in _splitquoted.split(text) if p.strip()]
+
+class EventDispatcher:
def dispatch(self, message_type, args):
+ '''Returns True if the message was handled, False otherwise.'''
+
method = getattr(self, message_type.lower(), None)
if method is None:
- return
+ return False
+
+ method(*args)
+ return True
+
+class GlobalEventDispatcher(EventDispatcher):
+ def __init__(self, uzbl_tabbed):
+ self.uzbl_tabbed = uzbl_tabbed
+
+ def new_tab(self, uri = ''):
+ self.uzbl_tabbed.new_tab(uri)
+
+ def new_tab_bg(self, uri = ''):
+ self.uzbl_tabbed.new_tab(uri, switch = False)
- return method(*args)
+ def new_tab_next(self, uri = ''):
+ self.uzbl_tabbed.new_tab(uri, next=True)
+
+ def new_bg_tab_next(self, uri = ''):
+ self.uzbl_tabbed.new_tab(uri, switch = False, next = True)
+
+ def next_tab(self, step = 1):
+ self.uzbl_tabbed.next_tab(int(step))
+
+ def prev_tab(self, step = 1):
+ self.uzbl_tabbed.prev_tab(int(step))
+
+ def goto_tab(self, index):
+ self.uzbl_tabbed.goto_tab(int(index))
+
+ def first_tab(self):
+ self.uzbl_tabbed.goto_tab(0)
+
+ def last_tab(self):
+ self.uzbl_tabbed.goto_tab(-1)
+
+ def preset_tabs(self, *args):
+ self.uzbl_tabbed.run_preset_command(*args)
+
+ def bring_to_front(self):
+ self.uzbl_tabbed.window.present()
+
+ def clean_tabs(self):
+ self.uzbl_tabbed.clean_slate()
+
+ def exit_all_tabs(self):
+ self.uzbl_tabbed.quitrequest()
+
+class InstanceEventDispatcher(EventDispatcher):
+ def __init__(self, uzbl):
+ self.uzbl = uzbl
+ self.parent = self.uzbl.parent
+
+ def plug_created(self, plug_id):
+ if not self.uzbl.tab:
+ tab = self.parent.create_tab()
+ tab.add_id(int(plug_id))
+ self.uzbl.set_tab(tab)
def title_changed(self, title):
self.uzbl.title = title.strip()
@@ -417,71 +498,14 @@ class EventDispatcher:
def load_commit(self, uri):
self.uzbl.uri = uri
- def new_tab(self, uri = None):
- if uri:
- self.parent.new_tab(uri)
- else:
- self.parent.new_tab()
-
- def new_tab_bg(self, uri = None):
- if uri:
- self.parent.new_tab(uri, switch = False)
- else:
- self.parent.new_tab(switch = False)
-
- def new_tab_next(self, uri = None):
- if uri:
- self.parent.new_tab(uri, next=True)
- else:
- self.parent.new_tab(next=True)
-
- def new_bg_tab_next(self, uri = None):
- if uri:
- self.parent.new_tab(uri, switch = False, next = True)
- else:
- self.parent.new_tab(switch = False, next = True)
-
- def next_tab(self, step = None):
- if step:
- self.parent.next_tab(int(step))
- else:
- self.parent.next_tab()
-
- def prev_tab(self, step = None):
- if step:
- self.parent.prev_tab(int(step))
- else:
- self.parent.prev_tab()
-
- def goto_tab(self, index):
- self.parent.goto_tab(int(index))
-
- def first_tab(self):
- self.parent.goto_tab(0)
-
- def last_tab(self):
- self.parent.goto_tab(-1)
-
- def preset_tabs(self, *args):
- self.parent.parse_command(["preset"] + [ a for a in args ])
-
- def bring_to_front(self):
- self.parent.window.present()
-
- def clean_tabs(self):
- self.parent.clean_slate()
-
- def exit_all_tabs(self):
- self.parent.quitrequest()
-
class UzblInstance:
'''Uzbl instance meta-data/meta-action object.'''
- def __init__(self, parent, tab, name, uri, title, switch):
+ def __init__(self, parent, name, uri, title, switch):
self.parent = parent
- self.tab = tab
- self.dispatcher = EventDispatcher(self)
+ self.tab = None
+ self.dispatcher = InstanceEventDispatcher(self)
self.name = name
self.title = title
@@ -490,8 +514,11 @@ class UzblInstance:
self._client = None
self._switch = switch # Switch to tab after loading ?
- self.title_changed()
+ def set_tab(self, tab):
+ self.tab = tab
+ self.title_changed()
+ self.parent.tabs[self.tab] = self
def got_socket(self, client):
'''Uzbl instance is now connected'''
@@ -506,6 +533,9 @@ class UzblInstance:
def title_changed(self, gtk_only = True): # GTK-only is for indexes
'''self.title has changed, update the tabs list'''
+ if not self.tab:
+ return
+
tab_titles = config['tab_titles']
tab_indexes = config['tab_indexes']
show_ellipsis = config['show_ellipsis']
@@ -546,7 +576,8 @@ class UzblInstance:
''' Send the SET command to Uzbl '''
if self._client:
- self._client.send('set %s = %s') #TODO: escape chars ?
+ line = 'set %s = %s' % (key, val) #TODO: escape chars ?
+ self._client.send(line)
def exit(self):
@@ -555,27 +586,6 @@ class UzblInstance:
if self._client:
self._client.send('exit')
- def unquote(self, s):
- '''Removes quotation marks around strings if any and interprets
- \\-escape sequences using `string_escape`'''
- if s and s[0] == s[-1] and s[0] in ['"', "'"]:
- s = s[1:-1]
- return s.encode('utf-8').decode('string_escape').decode('utf-8')
-
- _splitquoted = re.compile("( |\"(?:\\\\.|[^\"])*?\"|'(?:\\\\.|[^'])*?')")
- def parse_event(self, text):
- '''Splits string on whitespace while respecting quotations'''
- return [self.unquote(p) for p in self._splitquoted.split(text) if p.strip()]
-
- def parse_command(self, cmd):
- ''' Parse event givent by the Uzbl instance '''
-
- cmd = self.parse_event(cmd)
- message, message_type, args = cmd[0], cmd[2], cmd[3:]
-
- if message == "EVENT":
- self.dispatcher.dispatch(message_type, args)
-
def close(self):
'''The remote instance exited'''
@@ -606,6 +616,13 @@ class UzblTabbed:
# Generates a unique id for uzbl socket filenames.
self.next_pid = counter().next
+ # Whether to reconfigure new uzbl instances
+ self.force_socket_dir = False
+ self.force_fifo_dir = False
+
+ self.fifo_dir = '/tmp' # Path to look for uzbl fifo.
+ self.socket_dir = '/tmp' # Path to look for uzbl socket.
+
# Create main window
self.window = gtk.Window()
try:
@@ -684,16 +701,12 @@ class UzblTabbed:
self.window.show()
self.wid = self.notebook.window.xid
- # Store information about the applications fifo and socket.
- fifo_filename = 'uzbltabbed_%d.fifo' % os.getpid()
+ # Store information about the application's socket.
socket_filename = 'uzbltabbed_%d.socket' % os.getpid()
- self._fifo = None
self._socket = None
- self.fifo_path = os.path.join(config['fifo_dir'], fifo_filename)
- self.socket_path = os.path.join(config['socket_dir'], socket_filename)
+ self.socket_path = os.path.join(self.socket_dir, socket_filename)
- # Now initialise the fifo and the socket
- self.init_fifo()
+ # Now initialise the the socket
self.init_socket()
# If we are using sessions then load the last one if it exists.
@@ -724,8 +737,7 @@ class UzblTabbed:
print_exc()
error("encounted error %r" % sys.exc_info()[1])
- # Unlink fifo socket
- self.unlink_fifo()
+ # Unlink socket
self.close_socket()
# Attempt to close all uzbl instances nicely.
@@ -763,7 +775,7 @@ class UzblTabbed:
'''A new uzbl instance was created'''
client, _ = sock.accept()
- self.clients[client] = SocketClient(client)
+ self.clients[client] = SocketClient(client, self)
return True
@@ -791,249 +803,45 @@ class UzblTabbed:
self._socket = None
- def init_fifo(self):
- '''Create interprocess communication fifo.'''
-
- if os.path.exists(self.fifo_path):
- if not os.access(self.fifo_path, os.F_OK | os.R_OK | os.W_OK):
- os.mkfifo(self.fifo_path)
-
- else:
- basedir = os.path.dirname(self.fifo_path)
- if not os.path.exists(basedir):
- os.makedirs(basedir)
-
- os.mkfifo(self.fifo_path)
-
- # Add event handlers for IO_IN & IO_HUP events.
- self.setup_fifo_watchers()
-
- echo("[fifo] listening at %r" % self.fifo_path)
-
- # Add atexit register to destroy the fifo on program termination.
- atexit.register(self.unlink_fifo)
-
-
- def unlink_fifo(self):
- '''Unlink the fifo socket. Note: This function is called automatically
- on exit by an atexit register.'''
-
- # Make sure the fifo fd is closed.
- self.close_fifo()
-
- # And unlink if the real fifo exists.
- if os.path.exists(self.fifo_path):
- os.unlink(self.fifo_path)
- echo("unlinked %r" % self.fifo_path)
-
-
- def close_fifo(self):
- '''Remove all event handlers watching the fifo and close the fd.'''
-
- # Already closed
- if self._fifo is None: return
-
- (fd, watchers) = self._fifo
- os.close(fd)
-
- # Stop all gobject io watchers watching the fifo.
- for gid in watchers:
- source_remove(gid)
-
- self._fifo = None
-
-
- def setup_fifo_watchers(self):
- '''Open fifo socket fd and setup gobject IO_IN & IO_HUP event
- handlers.'''
-
- # Close currently open fifo fd and kill all watchers
- self.close_fifo()
-
- fd = os.open(self.fifo_path, os.O_RDONLY | os.O_NONBLOCK)
-
- # Add gobject io event handlers to the fifo socket.
- watchers = [io_add_watch(fd, IO_IN, self.main_fifo_read),\
- io_add_watch(fd, IO_HUP, self.main_fifo_hangup)]
-
- self._fifo = (fd, watchers)
-
-
- def main_fifo_hangup(self, fd, cb_condition):
- '''Handle main fifo socket hangups.'''
-
- # Close old fd, open new fifo socket and add io event handlers.
- self.setup_fifo_watchers()
-
- # Kill the gobject event handler calling this handler function.
- return False
-
-
- def main_fifo_read(self, fd, cb_condition):
- '''Read from main fifo socket.'''
-
- self._buffer = os.read(fd, 1024)
- temp = self._buffer.split("\n")
- self._buffer = temp.pop()
- cmds = [s.strip().split() for s in temp if len(s.strip())]
-
- for cmd in cmds:
- try:
- #print cmd
- self.parse_command(cmd)
-
- except:
- print_exc()
- error("parse_command: invalid command %s" % ' '.join(cmd))
- raise
-
- return True
-
-
- def parse_command(self, cmd):
- '''Parse instructions from uzbl child processes.'''
-
- # Commands ( [] = optional, {} = required )
- # new [uri]
- # open new tab and head to optional uri.
- # newbg [uri]
- # open a new tab in the background
- # close [tab-num]
- # close current tab or close via tab id.
- # next [n-tabs]
- # open next tab or n tabs down. Supports negative indexing.
- # prev [n-tabs]
- # open prev tab or n tabs down. Supports negative indexing.
- # goto {tab-n}
- # goto tab n.
- # first
- # goto first tab.
- # last
- # goto last tab.
- # title {pid} {document-title}
- # updates tablist title.
- # uri {pid} {document-location}
- # updates tablist uri
- # bring_to_front
- # brings the gtk window to focus.
- # exit
- # exits uzbl_tabbed.py
-
- if cmd[0] == "new":
- if len(cmd) == 2:
- self.new_tab(cmd[1])
-
- else:
- self.new_tab()
-
- elif cmd[0] == "newbg":
- if len(cmd) == 2:
- self.new_tab(cmd[1], switch=False)
- else:
- self.new_tab(switch=False)
-
- elif cmd[0] == "newfromclip":
- uri = subprocess.Popen(['xclip','-selection','clipboard','-o'],\
- stdout=subprocess.PIPE).communicate()[0]
- if uri:
- self.new_tab(uri)
+ def run_preset_command(self, cmd, *args):
+ if len(args) < 1:
+ error("parse_command: invalid preset command")
- elif cmd[0] == "close":
- if len(cmd) == 2:
- self.close_tab(int(cmd[1]))
-
- else:
- self.close_tab()
-
- elif cmd[0] == "next":
- if len(cmd) == 2:
- self.next_tab(int(cmd[1]))
-
- else:
- self.next_tab()
+ elif cmd == "save":
+ path = os.path.join(config['saved_sessions_dir'], args[0])
+ self.save_session(path)
- elif cmd[0] == "prev":
- if len(cmd) == 2:
- self.prev_tab(int(cmd[1]))
+ elif cmd == "load":
+ path = os.path.join(config['saved_sessions_dir'], args[0])
+ self.load_session(path)
+ elif cmd == "del":
+ path = os.path.join(config['saved_sessions_dir'], args[0])
+ if os.path.isfile(path):
+ os.remove(path)
else:
- self.prev_tab()
-
- elif cmd[0] == "goto":
- self.goto_tab(int(cmd[1]))
-
- elif cmd[0] == "first":
- self.goto_tab(0)
-
- elif cmd[0] == "last":
- self.goto_tab(-1)
-
- elif cmd[0] in ["title", "uri"]:
- if len(cmd) > 2:
- uzbl = self.get_tab_by_name(int(cmd[1]))
- if uzbl:
- old = getattr(uzbl, cmd[0])
- new = ' '.join(cmd[2:])
- setattr(uzbl, cmd[0], new)
- if old != new:
- self.update_tablist()
-
- else:
- error("parse_command: no uzbl with name %r" % int(cmd[1]))
-
- elif cmd[0] == "preset":
- if len(cmd) < 3:
- error("parse_command: invalid preset command")
-
- elif cmd[1] == "save":
- path = os.path.join(config['saved_sessions_dir'], cmd[2])
- self.save_session(path)
-
- elif cmd[1] == "load":
- path = os.path.join(config['saved_sessions_dir'], cmd[2])
- self.load_session(path)
-
- elif cmd[1] == "del":
- path = os.path.join(config['saved_sessions_dir'], cmd[2])
- if os.path.isfile(path):
- os.remove(path)
+ error("parse_command: preset %r does not exist." % path)
- else:
- error("parse_command: preset %r does not exist." % path)
-
- elif cmd[1] == "list":
- # FIXME: what argument is this supposed to be passed,
- # and why?
- uzbl = self.get_tab_by_name(int(cmd[2]))
- if uzbl:
- if not os.path.isdir(config['saved_sessions_dir']):
- js = "js alert('No saved presets.');"
- uzbl._client.send(js)
-
- else:
- listdir = os.listdir(config['saved_sessions_dir'])
- listdir = "\\n".join(listdir)
- js = "js alert('Session presets:\\n\\n%s');" % listdir
- uzbl._client.send(js)
+ elif cmd == "list":
+ # FIXME: what argument is this supposed to be passed,
+ # and why?
+ uzbl = self.get_tab_by_name(int(args[0]))
+ if uzbl:
+ if not os.path.isdir(config['saved_sessions_dir']):
+ js = "js alert('No saved presets.');"
+ uzbl._client.send(js)
else:
- error("parse_command: unknown tab name.")
+ listdir = os.listdir(config['saved_sessions_dir'])
+ listdir = "\\n".join(listdir)
+ js = "js alert('Session presets:\\n\\n%s');" % listdir
+ uzbl._client.send(js)
else:
- error("parse_command: unknown parse command %r"\
- % ' '.join(cmd))
-
- elif cmd[0] == "bring_to_front":
- self.window.present()
-
- elif cmd[0] == "clean":
- self.clean_slate()
-
- elif cmd[0] == "exit":
- self.quitrequest()
+ error("parse_command: unknown tab name.")
else:
- error("parse_command: unknown command %r" % ' '.join(cmd))
+ error("parse_command: unknown parse command %r" % cmd)
def get_tab_by_name(self, name):
@@ -1045,6 +853,18 @@ class UzblTabbed:
return False
+ def create_tab(self, beside = False):
+ tab = gtk.Socket()
+ tab.show()
+
+ if beside:
+ pos = self.notebook.get_current_page() + 1
+ self.notebook.insert_page(tab, position=pos)
+ else:
+ self.notebook.append_page(tab)
+
+ self.notebook.set_tab_reorderable(tab, True)
+ return tab
def new_tab(self, uri='', title='', switch=None, next=False):
'''Add a new tab to the notebook and start a new instance of uzbl.
@@ -1052,10 +872,7 @@ class UzblTabbed:
when you need to load multiple tabs at a time (I.e. like when
restoring a session from a file).'''
- tab = gtk.Socket()
- tab.show()
- self.notebook.insert_page(tab, position=next and self.notebook.get_current_page() + 1 or -1)
- self.notebook.set_tab_reorderable(tab, True)
+ tab = self.create_tab(next)
sid = tab.get_id()
uri = uri.strip()
name = "%d-%d" % (os.getpid(), self.next_pid())
@@ -1070,9 +887,10 @@ class UzblTabbed:
'--connect-socket', self.socket_path, '--uri', str(uri)]
gobject.spawn_async(cmd, flags=gobject.SPAWN_SEARCH_PATH)
- uzbl = UzblInstance(self, tab, name, uri, title, switch)
+ uzbl = UzblInstance(self, name, uri, title, switch)
+ uzbl.set_tab(tab)
+
SocketClient.instances_queue[name] = uzbl
- self.tabs[tab] = uzbl
def clean_slate(self):
@@ -1085,16 +903,15 @@ class UzblTabbed:
uzbl = self.tabs[tab]
uzbl.exit()
-
def config_uzbl(self, uzbl):
'''Send bind commands for tab new/close/next/prev to a uzbl
instance.'''
- # Set definitions here
- # set(key, command back to fifo)
- if config['capture_new_windows']:
- uzbl.set("new_window", r'new $8')
+ if self.force_socket_dir:
+ uzbl.set("socket_dir", self.socket_dir)
+ if self.force_fifo_dir:
+ uzbl.set("fifo_dir", self.fifo_dir)
def goto_tab(self, index):
'''Goto tab n (supports negative indexing).'''
@@ -1411,9 +1228,8 @@ class UzblTabbed:
def quit(self, *args):
'''Cleanup and quit. Called by delete-event signal.'''
- # Close the fifo socket, remove any gobject io event handlers and
+ # Close the socket, remove any gobject io event handlers and
# delete socket.
- self.unlink_fifo()
self.close_socket()
# Remove all gobject timers that are still ticking.
@@ -1455,13 +1271,15 @@ if __name__ == "__main__":
import pprint
sys.stderr.write("%s\n" % pprint.pformat(config))
+ uzbl = UzblTabbed()
+
if options.socketdir:
- config['socket_dir'] = options.socketdir
+ uzbl.socket_dir = options.socketdir
+ uzbl.force_socket_dir = True
if options.fifodir:
- config['fifo_dir'] = options.fifodir
-
- uzbl = UzblTabbed()
+ uzbl.fifo_dir = options.fifodir
+ uzbl.force_fifo_dir = True
# All extra arguments given to uzbl_tabbed.py are interpreted as
# web-locations to opened in new tabs.
diff --git a/docs/README.uzbl-event-manager b/docs/README.uzbl-event-manager
index 23e185c..da26847 100644
--- a/docs/README.uzbl-event-manager
+++ b/docs/README.uzbl-event-manager
@@ -26,15 +26,36 @@ MODE_CHANGE <mode>
### keycmd.py ###
- Tracks the currently entered command
-- Connects To: FOCUS_GAINED, FOCUS_LOST, KEY_PRESS, KEY_RELEASE, (APPEND_KEYCMD,
+- Connects To: KEY_PRESS, KEY_RELEASE, MOD_PRESS, MOD_RELEASE, (APPEND_KEYCMD,
IGNORE_KEY, INJECT_KEYCMD, KEYCMD_BACKSPACE, KEYCMD_DELETE,
- KEYCMD_EXEC_CURRENT, KEYCMD_STRIP_WORD, MODKEY_ADDITION, MODMAP,
+ KEYCMD_EXEC_CURRENT, KEYCMD_STRIP_WORD, KEYCMD_CLEAR, MODMAP,
SET_CURSOR_POS, SET_KEYCMD)
-- Emits: KEYCMD_UPDATE, KEYCMD_EXEC, MODCMD_UPDATE, MODCMD_EXEC
+- Emits: KEYCMD_UPDATE, KEYCMD_EXEC, MODCMD_UPDATE, MODCMD_EXEC, KEYCMD_CLEARED
+ MODCMD_CLEARED
Maintains a command line that is manipulated by simple keypresses and a number
of events.
+APPEND_KEYCMD <str>
+ Appends `str` to the end of the keycmd
+
+INJECT_KEYCMD <str>
+ Inserts `str` at the cursor position
+
+KEYCMD_BACKSPACE
+ Removes the character at the cursor position in the keycmd
+
+KEYCMD_DELETE
+ Removes the character after the cursor position in the keycmd
+
+KEYCMD_EXEC_CURRENT
+ Raise a KEYCMD_EXEC with the current keylet and then clear the keycmd
+
+KEYCMD_STRIP_WORD [<separator>]
+ Removes the last word from the keycmd, similar to readline ^W
+
+KEYCMD_CLEAR
+ Clears the keycmd and raises KEYCMD_CLEARED
### bind.py ###
- Provides support for key bindings
diff --git a/examples/config/config b/examples/config/config
index 8ed533f..029ce57 100644
--- a/examples/config/config
+++ b/examples/config/config
@@ -91,7 +91,7 @@ set download_handler = sync_spawn @scripts_dir/download.sh
#@on_event CONFIG_CHANGED print Config changed: %1 = %2
# Scroll percentage calculation
-@on_event SCROLL_VERT set scroll_message = \@<(function(){var p='--';if(%3!=%2){p=(%1/(%3-%4));p=Math.round(10000*p)/100;};return p+'%';})()>\@
+@on_event SCROLL_VERT set scroll_message = \@<(function(){var p='--';if(%3<=%4){p=(%1/(%3-%4));p=Math.round(10000*p)/100;};return p+'%';})()>\@
# === Behaviour and appearance ===============================================
@@ -154,15 +154,11 @@ set useragent = Uzbl (Webkit @{WEBKIT_MAJOR}.@{WEBKIT_MINOR}) (@(+uname
@modmap <space> <Space>
@modmap <KP_Enter> <Enter>
-#modkey_addition <Key1> <Key2> <Result>
-@modkey_addition <Shift> <Ctrl> <Meta>
-@modkey_addition <Shift> <Tab> <Shift-Tab>
-@modkey_addition <Shift> <Insert> <Shift-Insert>
-
#ignore_key <glob>
@ignore_key <ISO_*>
@ignore_key <Shift>
@ignore_key <Multi_key>
+@ignore_key <Mod2>
# --- Bind aliases -----------------------------------------------------------
@@ -200,7 +196,7 @@ set ebind = @mode_bind global,-insert
@ebind <Delete> = event KEYCMD_DELETE
@ebind <Tab> = event START_COMPLETION
# Readline-ish bindings.
-@ebind <Ctrl>w = event KEYCMD_STRIP_WORD
+@ebind <Ctrl>w = event KEYCMD_STRIP_WORD \ -./&?=
@ebind <Ctrl>u = event SET_KEYCMD
@ebind <Ctrl>a = event SET_CURSOR_POS 0
@ebind <Ctrl>e = event SET_CURSOR_POS -1
@@ -290,8 +286,8 @@ set ebind = @mode_bind global,-insert
# 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:\"$UZBL_SOCKET\" -"'
-#@cbind <Ctrl><Alt>t = sh 'urxvt -e socat unix-connect:"$UZBL_SOCKET" -'
+@cbind <Ctrl><Mod1>t = sh 'xterm -e "socat unix-connect:\"$UZBL_SOCKET\" -"'
+#@cbind <Ctrl><Mod1>t = sh 'urxvt -e socat unix-connect:"$UZBL_SOCKET" -'
# Uri opening prompts
@cbind o<uri:>_ = uri %s
@@ -326,7 +322,7 @@ set ebind = @mode_bind global,-insert
# Start a new uzbl instance from the page in primary selection
@cbind 'p = sh 'echo "event REQ_NEW_WINDOW $(xclip -o)" > "$UZBL_FIFO"'
# paste primary selection into keycmd at the cursor position
-@bind <Shift-Insert> = sh 'echo "event INJECT_KEYCMD $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"'
+@bind <Shift><Insert> = sh 'echo "event INJECT_KEYCMD $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"'
# Bookmark inserting binds
@cbind <Ctrl>b<tags:>_ = sh 'echo `printf "$UZBL_URI %s"` >> "$XDG_DATA_HOME"/uzbl/bookmarks'
@@ -337,6 +333,10 @@ set ebind = @mode_bind global,-insert
@cbind U = spawn @scripts_dir/load_url_from_history.sh
@cbind u = spawn @scripts_dir/load_url_from_bookmarks.sh
+# Temporary bookmarks
+@cbind <Ctrl>d = spawn @scripts_dir/insert_temp.sh
+@cbind D = spawn @scripts_dir/load_url_from_temps.sh
+
# Link following (similar to vimperator and konqueror)
# Set custom keys you wish to use for navigation. Some common examples:
set follow_hint_keys = 0123456789
@@ -355,10 +355,10 @@ set follow_hint_keys = 0123456789
# This implementation allows you to save multiple profiles for each form
# (think about multiple accounts on some website).
set formfiller = spawn @scripts_dir/formfiller.sh
-@cbind za = @formfiller add
@cbind ze = @formfiller edit
@cbind zn = @formfiller new
@cbind zl = @formfiller load
+@cbind zo = @formfiller once
# --- Uzbl tabbed binds ------------------------------------------------------
diff --git a/examples/data/plugins/bind.py b/examples/data/plugins/bind.py
index 69fd863..fc8b392 100644
--- a/examples/data/plugins/bind.py
+++ b/examples/data/plugins/bind.py
@@ -372,11 +372,11 @@ def mode_changed(uzbl, mode):
uzbl.bindlet.reset()
-def match_and_exec(uzbl, bind, depth, keylet, bindlet):
+def match_and_exec(uzbl, bind, depth, modstate, keylet, bindlet):
(on_exec, has_args, mod_cmd, glob, more) = bind[depth]
cmd = keylet.modcmd if mod_cmd else keylet.keycmd
- if mod_cmd and keylet.held != mod_cmd:
+ if mod_cmd and modstate != mod_cmd:
return False
if has_args:
@@ -415,7 +415,7 @@ def match_and_exec(uzbl, bind, depth, keylet, bindlet):
return True
-def key_event(uzbl, keylet, mod_cmd=False, on_exec=False):
+def key_event(uzbl, modstate, keylet, mod_cmd=False, on_exec=False):
bindlet = uzbl.bindlet
depth = bindlet.depth
for bind in bindlet.get_binds():
@@ -423,7 +423,7 @@ def key_event(uzbl, keylet, mod_cmd=False, on_exec=False):
if (bool(t[MOD_CMD]) != mod_cmd) or (t[ON_EXEC] != on_exec):
continue
- if match_and_exec(uzbl, bind, depth, keylet, bindlet):
+ if match_and_exec(uzbl, bind, depth, modstate, keylet, bindlet):
return
bindlet.after()
diff --git a/examples/data/plugins/history.py b/examples/data/plugins/history.py
index 5e9e4e1..f42f86f 100644
--- a/examples/data/plugins/history.py
+++ b/examples/data/plugins/history.py
@@ -83,7 +83,7 @@ class History(object):
def __str__(self):
return "(History %s, %s)" % (self.cursor, self.prompt)
-def keycmd_exec(uzbl, keylet):
+def keycmd_exec(uzbl, modstate, keylet):
cmd = keylet.get_keycmd()
if cmd:
uzbl.history.add(cmd)
diff --git a/examples/data/plugins/keycmd.py b/examples/data/plugins/keycmd.py
index 928c597..1bb70e3 100644
--- a/examples/data/plugins/keycmd.py
+++ b/examples/data/plugins/keycmd.py
@@ -17,13 +17,10 @@ def uzbl_escape(str):
class Keylet(object):
- '''Small per-instance object that tracks all the keys held and characters
- typed.'''
+ '''Small per-instance object that tracks characters typed.'''
def __init__(self):
# Modcmd tracking
- self.held = set()
- self.ignored = set()
self.modcmd = ''
self.is_modcmd = False
@@ -33,7 +30,6 @@ class Keylet(object):
self.modmaps = {}
self.ignores = {}
- self.additions = {}
def get_keycmd(self):
@@ -48,7 +44,7 @@ class Keylet(object):
if not self.is_modcmd:
return ''
- return ''.join(self.held) + self.modcmd
+ return self.modcmd
def modmap_key(self, key):
@@ -65,28 +61,6 @@ class Keylet(object):
return key
- def find_addition(self, modkey):
- '''Key has just been pressed, check if this key + the held list
- results in a modkey addition. Return that addition and remove all
- modkeys that created it.'''
-
- # Intersection of (held list + modkey) and additions.
- added = (self.held | set([modkey])) & set(self.additions.keys())
- for key in added:
- if key == modkey or modkey in self.additions[key]:
- self.held -= self.additions[key]
- return key
-
- # Held list + ignored list + modkey.
- modkeys = self.held | self.ignored | set([modkey])
- for (key, value) in self.additions.items():
- if modkeys.issuperset(value):
- self.held -= value
- return key
-
- return modkey
-
-
def key_ignored(self, key):
'''Check if the given key is ignored by any ignore rules.'''
@@ -104,9 +78,6 @@ class Keylet(object):
if self.is_modcmd:
l.append('modcmd=%r' % self.get_modcmd())
- elif self.held:
- l.append('held=%r' % ''.join(sorted(self.held)))
-
if self.keycmd:
l.append('keycmd=%r' % self.get_keycmd())
@@ -132,10 +103,7 @@ def add_modmap(uzbl, key, map):
assert len(key)
modmaps = uzbl.keylet.modmaps
- if key[0] == "<" and key[-1] == ">":
- key = key[1:-1]
-
- modmaps[key] = map
+ modmaps[key.strip('<>')] = map.strip('<>')
uzbl.event("NEW_MODMAP", key, map)
@@ -171,45 +139,6 @@ def add_key_ignore(uzbl, glob):
uzbl.event('NEW_KEY_IGNORE', glob)
-def add_modkey_addition(uzbl, modkeys, result):
- '''Add a modkey addition definition.
-
- Examples:
- set mod_addition = request MODKEY_ADDITION
- @mod_addition <Shift> <Control> <Meta>
- @mod_addition <Left> <Up> <Left-Up>
- @mod_addition <Right> <Up> <Right-Up>
- ...
-
- Then:
- @bind <Right-Up> = <command1>
- @bind <Meta>o = <command2>
- ...
- '''
-
- additions = uzbl.keylet.additions
- modkeys = set(modkeys)
-
- assert len(modkeys) and result and result not in modkeys
-
- for (existing_result, existing_modkeys) in additions.items():
- if existing_result != result:
- assert modkeys != existing_modkeys
-
- additions[result] = modkeys
- uzbl.event('NEW_MODKEY_ADDITION', modkeys, result)
-
-
-def modkey_addition_parse(uzbl, modkeys):
- '''Parse modkey addition definition.'''
-
- keys = filter(None, map(unicode.strip, modkeys.split(" ")))
- keys = ['<%s>' % key.strip("<>") for key in keys if key.strip("<>")]
-
- assert len(keys) > 1
- add_modkey_addition(uzbl, keys[:-1], keys[-1])
-
-
def clear_keycmd(uzbl, *args):
'''Clear the keycmd for this uzbl instance.'''
@@ -220,15 +149,12 @@ def clear_keycmd(uzbl, *args):
uzbl.event('KEYCMD_CLEARED')
-def clear_modcmd(uzbl, clear_held=False):
+def clear_modcmd(uzbl):
'''Clear the modcmd for this uzbl instance.'''
k = uzbl.keylet
k.modcmd = ''
k.is_modcmd = False
- if clear_held:
- k.ignored = set()
- k.held = set()
del uzbl.config['modcmd']
uzbl.event('MODCMD_CLEARED')
@@ -244,28 +170,22 @@ def clear_current(uzbl):
clear_keycmd(uzbl)
-def focus_changed(uzbl, *args):
- '''Focus to the uzbl instance has now been lost which means all currently
- held keys in the held list will not get a KEY_RELEASE event so clear the
- entire held list.'''
-
- clear_modcmd(uzbl, clear_held=True)
-
-
-def update_event(uzbl, k, execute=True):
+def update_event(uzbl, modstate, k, execute=True):
'''Raise keycmd & modcmd update events.'''
- keycmd, modcmd = k.get_keycmd(), k.get_modcmd()
+ keycmd, modcmd = k.get_keycmd(), ''.join(modstate) + k.get_modcmd()
if k.is_modcmd:
- uzbl.event('MODCMD_UPDATE', k)
+ logger.debug('modcmd_update, %s' % modcmd)
+ uzbl.event('MODCMD_UPDATE', modstate, k)
else:
- uzbl.event('KEYCMD_UPDATE', k)
+ logger.debug('keycmd_update, %s' % keycmd)
+ uzbl.event('KEYCMD_UPDATE', modstate, k)
if uzbl.config.get('modcmd_updates', '1') == '1':
- new_modcmd = k.get_modcmd()
- if not new_modcmd:
+ new_modcmd = ''.join(modstate) + k.get_modcmd()
+ if not new_modcmd or not k.is_modcmd:
del uzbl.config['modcmd']
elif new_modcmd == modcmd:
@@ -293,54 +213,38 @@ def inject_str(str, index, inj):
return "%s%s%s" % (str[:index], inj, str[index:])
-def get_keylet_and_key(uzbl, key, add=True):
- '''Return the keylet and apply any transformations to the key as defined
- by the modmapping or modkey addition rules. Return None if the key is
- ignored.'''
-
+def parse_key_event(uzbl, key):
+ ''' Build a set from the modstate part of the event, and pass all keys through modmap '''
keylet = uzbl.keylet
- key = keylet.modmap_key(key)
- if len(key) == 1:
- return (keylet, key)
-
- modkey = "<%s>" % key.strip("<>")
-
- if keylet.key_ignored(modkey):
- if add:
- keylet.ignored.add(modkey)
-
- elif modkey in keylet.ignored:
- keylet.ignored.remove(modkey)
- modkey = keylet.find_addition(modkey)
-
- if keylet.key_ignored(modkey):
- return (keylet, None)
-
- return (keylet, modkey)
+ modstate, key = splitquoted(key)
+ modstate = set(['<%s>' % keylet.modmap_key(k) for k in modstate.split('|') if k])
+
+ key = keylet.modmap_key(key)
+ return modstate, key
def key_press(uzbl, key):
'''Handle KEY_PRESS events. Things done by this function include:
1. Ignore all shift key presses (shift can be detected by capital chars)
- 3. In non-modcmd mode:
+ 2. In non-modcmd mode:
a. append char to keycmd
- 4. If not in modcmd mode and a modkey was pressed set modcmd mode.
- 5. If in modcmd mode the pressed key is added to the held keys list.
- 6. Keycmd is updated and events raised if anything is changed.'''
+ 3. If not in modcmd mode and a modkey was pressed set modcmd mode.
+ 4. Keycmd is updated and events raised if anything is changed.'''
- (k, key) = get_keylet_and_key(uzbl, key.strip())
- if not key:
- return
+ k = uzbl.keylet
+ modstate, key = parse_key_event(uzbl, key)
+ k.is_modcmd = any(not k.key_ignored(m) for m in modstate)
- if key.lower() == '<space>' and not k.held and k.keycmd:
+ logger.debug('key press modstate=%s' % str(modstate))
+ if key.lower() == 'space' and not k.is_modcmd and k.keycmd:
k.keycmd = inject_str(k.keycmd, k.cursor, ' ')
k.cursor += 1
- elif not k.held and len(key) == 1:
-
+ elif not k.is_modcmd and len(key) == 1:
if uzbl.config.get('keycmd_events', '1') != '1':
+ # TODO, make a note on what's going on here
k.keycmd = ''
k.cursor = 0
del uzbl.config['keycmd']
@@ -349,33 +253,29 @@ def key_press(uzbl, key):
k.keycmd = inject_str(k.keycmd, k.cursor, key)
k.cursor += 1
- elif len(key) > 1:
- k.is_modcmd = True
- if key not in k.held:
- k.held.add(key)
+ elif len(key) == 1:
+ k.modcmd += key
else:
- k.is_modcmd = True
- k.modcmd += key
+ if not k.key_ignored('<%s>' % key):
+ modstate.add('<%s>' % key)
+ k.is_modcmd = True
- update_event(uzbl, k)
+ update_event(uzbl, modstate, k)
def key_release(uzbl, key):
'''Respond to KEY_RELEASE event. Things done by this function include:
- 1. Remove the key from the keylet held list.
- 2. If in a mod-command then raise a MODCMD_EXEC.
- 3. Check if any modkey is held, if so set modcmd mode.
- 4. Update the keycmd uzbl variable if anything changed.'''
-
- (k, key) = get_keylet_and_key(uzbl, key.strip(), add=False)
+ 1. If in a mod-command then raise a MODCMD_EXEC.
+ 2. Update the keycmd uzbl variable if anything changed.'''
+ k = uzbl.keylet
+ modstate, key = parse_key_event(uzbl, key)
- if key in k.held:
+ if len(key) > 1:
if k.is_modcmd:
- uzbl.event('MODCMD_EXEC', k)
+ uzbl.event('MODCMD_EXEC', modstate, k)
- k.held.remove(key)
clear_modcmd(uzbl)
@@ -385,7 +285,7 @@ def set_keycmd(uzbl, keycmd):
k = uzbl.keylet
k.keycmd = keycmd
k.cursor = len(keycmd)
- update_event(uzbl, k, False)
+ update_event(uzbl, set(), k, False)
def inject_keycmd(uzbl, keycmd):
@@ -394,7 +294,7 @@ def inject_keycmd(uzbl, keycmd):
k = uzbl.keylet
k.keycmd = inject_str(k.keycmd, k.cursor, keycmd)
k.cursor += len(keycmd)
- update_event(uzbl, k, False)
+ update_event(uzbl, set(), k, False)
def append_keycmd(uzbl, keycmd):
@@ -403,23 +303,29 @@ def append_keycmd(uzbl, keycmd):
k = uzbl.keylet
k.keycmd += keycmd
k.cursor = len(k.keycmd)
- update_event(uzbl, k, False)
+ update_event(uzbl, set(), k, False)
-def keycmd_strip_word(uzbl, sep):
+def keycmd_strip_word(uzbl, seps):
''' Removes the last word from the keycmd, similar to readline ^W '''
- sep = sep or ' '
+ seps = seps or ' '
k = uzbl.keylet
if not k.keycmd:
return
- head, tail = k.keycmd[:k.cursor].rstrip(sep), k.keycmd[k.cursor:]
- rfind = head.rfind(sep)
+ head, tail = k.keycmd[:k.cursor].rstrip(seps), k.keycmd[k.cursor:]
+ rfind = -1
+ for sep in seps:
+ p = head.rfind(sep)
+ if p >= 0 and rfind < p + 1:
+ rfind = p + 1
+ if rfind == len(head) and head[-1] in seps:
+ rfind -= 1
head = head[:rfind] if rfind + 1 else ''
k.keycmd = head + tail
k.cursor = len(head)
- update_event(uzbl, k, False)
+ update_event(uzbl, set(), k, False)
def keycmd_backspace(uzbl, *args):
@@ -431,7 +337,7 @@ def keycmd_backspace(uzbl, *args):
k.keycmd = k.keycmd[:k.cursor-1] + k.keycmd[k.cursor:]
k.cursor -= 1
- update_event(uzbl, k, False)
+ update_event(uzbl, set(), k, False)
def keycmd_delete(uzbl, *args):
@@ -442,14 +348,14 @@ def keycmd_delete(uzbl, *args):
return
k.keycmd = k.keycmd[:k.cursor] + k.keycmd[k.cursor+1:]
- update_event(uzbl, k, False)
+ update_event(uzbl, set(), k, False)
def keycmd_exec_current(uzbl, *args):
'''Raise a KEYCMD_EXEC with the current keylet and then clear the
keycmd.'''
- uzbl.event('KEYCMD_EXEC', uzbl.keylet)
+ uzbl.event('KEYCMD_EXEC', set(), uzbl.keylet)
clear_keycmd(uzbl)
@@ -476,7 +382,7 @@ def set_cursor_pos(uzbl, index):
cursor = len(k.keycmd)
k.cursor = cursor
- update_event(uzbl, k, False)
+ update_event(uzbl, set(), k, False)
# plugin init hook
@@ -485,8 +391,6 @@ def init(uzbl):
connect_dict(uzbl, {
'APPEND_KEYCMD': append_keycmd,
- 'FOCUS_GAINED': focus_changed,
- 'FOCUS_LOST': focus_changed,
'IGNORE_KEY': add_key_ignore,
'INJECT_KEYCMD': inject_keycmd,
'KEYCMD_BACKSPACE': keycmd_backspace,
@@ -496,7 +400,8 @@ def init(uzbl):
'KEYCMD_CLEAR': clear_keycmd,
'KEY_PRESS': key_press,
'KEY_RELEASE': key_release,
- 'MODKEY_ADDITION': modkey_addition_parse,
+ 'MOD_PRESS': key_press,
+ 'MOD_RELEASE': key_release,
'MODMAP': modmap_parse,
'SET_CURSOR_POS': set_cursor_pos,
'SET_KEYCMD': set_keycmd,
@@ -504,7 +409,6 @@ def init(uzbl):
export_dict(uzbl, {
'add_key_ignore': add_key_ignore,
- 'add_modkey_addition': add_modkey_addition,
'add_modmap': add_modmap,
'append_keycmd': append_keycmd,
'clear_current': clear_current,
diff --git a/examples/data/scripts/auth.py b/examples/data/scripts/auth.py
index 592a2c6..49fa41e 100755
--- a/examples/data/scripts/auth.py
+++ b/examples/data/scripts/auth.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
import gtk
import sys
diff --git a/examples/data/scripts/download.sh b/examples/data/scripts/download.sh
index fe566ed..dbc9caf 100755
--- a/examples/data/scripts/download.sh
+++ b/examples/data/scripts/download.sh
@@ -1,9 +1,17 @@
#!/bin/sh
# uzbl's example configuration sets this script up as its download_handler.
-# when uzbl starts a download it runs this script.
+# this script is run when uzbl encounters a URL that it can't display, and when
+# a download is requested using the 'download' command.
+#
# if the script prints a file path to stdout, uzbl will save the download to
-# that path.
-# if nothing is printed to stdout, the download will be cancelled.
+# that path using it's internal downloader.
+#
+# if nothing is printed to stdout, the internal download will be cancelled.
+# you could do your own download handling in your script that way.
+
+# if $5 is set, it is the path that was passed to uzbl's "download" command.
+# we want to use that if it's available.
+[ -n "$5" ] && echo "$5" && exit
. "$UZBL_UTIL_DIR/uzbl-dir.sh"
diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh
index 3dc9dc4..c1171a0 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -66,22 +66,22 @@ ParseFields ()
field = $0
sub ( /[^:]*:/, "", field )
- if ( parts[2] ~ /(text|password|search)/ )
+ if ( parts[2] ~ /^(text|password|search)$/ )
printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n",
parts[1], parts[2], field )
- else if ( parts[2] ~ /(checkbox|radio)/ )
+ else if ( parts[2] ~ /^(checkbox|radio)$/ )
printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",%s);\n",
parts[1], parts[2], parts[3], field )
- else if ( parts[2] == "textarea" ) {
+ else if ( parts[2] ~ /^textarea$/ ) {
field = ""
while (getline) {
if ( /^%/ ) break
sub ( /^\\/, "" )
gsub ( /"/, "\\\"" )
gsub ( /\\/, "\\\\" )
- field = field $0 "\\n"
+ field = field $0 "\\\\n"
}
printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n",
parts[1], parts[2], field )
@@ -116,7 +116,7 @@ Load ()
ParseProfile $option < "$file" \
| ParseFields \
- | sed 's/@/\\@/' \
+ | sed 's/@/\\@/g' \
> "$UZBL_FIFO"
}
@@ -132,7 +132,7 @@ Once ()
test -e "$tmpfile" &&
ParseFields < "$tmpfile" \
- | sed 's/@/\\@' \
+ | sed 's/@/\\@/g' \
> "$UZBL_FIFO"
}
diff --git a/examples/data/scripts/insert_temp.sh b/examples/data/scripts/insert_temp.sh
new file mode 100755
index 0000000..7ed8d22
--- /dev/null
+++ b/examples/data/scripts/insert_temp.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+
+>> "$UZBL_TEMPS_FILE" || exit 1
+
+echo "$UZBL_URI $UZBL_TITLE" >> "$UZBL_TEMPS_FILE"
diff --git a/examples/data/scripts/load_url_from_temps.sh b/examples/data/scripts/load_url_from_temps.sh
new file mode 100755
index 0000000..b46687b
--- /dev/null
+++ b/examples/data/scripts/load_url_from_temps.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+DMENU_SCHEME="temps"
+DMENU_OPTIONS="xmms vertical resize"
+
+. "$UZBL_UTIL_DIR/dmenu.sh"
+. "$UZBL_UTIL_DIR/uzbl-dir.sh"
+
+[ -r "$UZBL_TEMPS_FILE" ] || exit 1
+
+if [ -z "$DMENU_HAS_VERTICAL" ]; then
+ # because they are all after each other, just show the url, not their titles.
+ goto=$( awk '{ print $1 }' "$UZBL_TEMPS_FILE" | $DMENU )
+else
+ # show titles
+ goto=$( $DMENU < "$UZBL_TEMPS_FILE" | cut -d ' ' -f 1 )
+fi
+
+sed -i -e "\<^$goto <d" $UZBL_TEMPS_FILE
+
+[ -n "$goto" ] && echo "uri $goto" > "$UZBL_FIFO"
+#[ -n "$goto" ] && echo "uri $goto" | socat - "unix-connect:$UZBL_SOCKET"
diff --git a/examples/data/scripts/util/dmenu.sh b/examples/data/scripts/util/dmenu.sh
index f0d1651..0b7272e 100644
--- a/examples/data/scripts/util/dmenu.sh
+++ b/examples/data/scripts/util/dmenu.sh
@@ -30,6 +30,13 @@ case "$DMENU_SCHEME" in
SB="#ccffaa"
SF="#303030"
;;
+ # Temps
+ "temps" )
+ NB="#303030"
+ NF="khaki"
+ SB="#ccffaa"
+ SF="#303030"
+ ;;
# Default
* )
NB="#303030"
diff --git a/examples/data/scripts/util/uzbl-dir.sh b/examples/data/scripts/util/uzbl-dir.sh
index 3d28151..82510d8 100644
--- a/examples/data/scripts/util/uzbl-dir.sh
+++ b/examples/data/scripts/util/uzbl-dir.sh
@@ -15,5 +15,6 @@ UZBL_FORMS_DIR="$UZBL_DATA_DIR/dforms"
UZBL_CONFIG_FILE="$UZBL_CONFIG_DIR/config"
UZBL_COOKIE_FILE="$UZBL_DATA_DIR/cookies.txt"
UZBL_BOOKMARKS_FILE="$UZBL_DATA_DIR/bookmarks"
+UZBL_TEMPS_FILE="$UZBL_DATA_DIR/temps"
UZBL_HISTORY_FILE="$UZBL_DATA_DIR/history"
UZBL_SESSION_FILE="$UZBL_DATA_DIR/browser-session"
diff --git a/src/callbacks.c b/src/callbacks.c
index 360b0c4..fe6b8fd 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -12,21 +12,17 @@
void
set_proxy_url() {
- SoupURI *suri;
+ const gchar *url = uzbl.net.proxy_url;
+ SoupSession *session = uzbl.net.soup_session;
+ SoupURI *soup_uri = NULL;
- if (uzbl.net.proxy_url == NULL || *uzbl.net.proxy_url == ' ') {
- soup_session_remove_feature_by_type(uzbl.net.soup_session,
- (GType) SOUP_SESSION_PROXY_URI);
- }
- else {
- suri = soup_uri_new(uzbl.net.proxy_url);
- g_object_set(G_OBJECT(uzbl.net.soup_session),
- SOUP_SESSION_PROXY_URI,
- suri, NULL);
- soup_uri_free(suri);
- }
+ if (url != NULL || *url != 0 || *url != ' ')
+ soup_uri = soup_uri_new(url);
- return;
+ g_object_set(G_OBJECT(session), SOUP_SESSION_PROXY_URI, soup_uri, NULL);
+
+ if(soup_uri)
+ soup_uri_free(soup_uri);
}
@@ -348,16 +344,9 @@ cmd_javascript_windows() {
void
cmd_scrollbars_visibility() {
- if(uzbl.gui.scrollbars_visible) {
- uzbl.gui.bar_h = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (uzbl.gui.scrolled_win));
- uzbl.gui.bar_v = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (uzbl.gui.scrolled_win));
- }
- else {
- uzbl.gui.bar_v = gtk_range_get_adjustment (GTK_RANGE (uzbl.gui.scbar_v));
- uzbl.gui.bar_h = gtk_range_get_adjustment (GTK_RANGE (uzbl.gui.scbar_h));
- }
+ GtkPolicyType policy = uzbl.gui.scrollbars_visible ? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER;
- set_webview_scroll_adjustments();
+ gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW (uzbl.gui.scrolled_win), policy, policy );
}
/* requires webkit >=1.1.14 */
@@ -478,7 +467,7 @@ load_status_change_cb (WebKitWebView* web_view, GParamSpec param_spec) {
}
}
-void
+gboolean
load_error_cb (WebKitWebView* page, WebKitWebFrame* frame, gchar *uri, gpointer web_err, gpointer ud) {
(void) page; (void) frame; (void) ud;
GError *err = web_err;
@@ -488,6 +477,8 @@ load_error_cb (WebKitWebView* page, WebKitWebFrame* frame, gchar *uri, gpointer
TYPE_INT, err->code,
TYPE_STR, err->message,
NULL);
+
+ return FALSE;
}
void
@@ -549,7 +540,7 @@ key_press_cb (GtkWidget* window, GdkEventKey* event) {
(void) window;
if(event->type == GDK_KEY_PRESS)
- key_to_event(event->keyval, GDK_KEY_PRESS);
+ key_to_event(event->keyval, event->state, event->is_modifier, GDK_KEY_PRESS);
return uzbl.behave.forward_keys ? FALSE : TRUE;
}
@@ -559,7 +550,7 @@ key_release_cb (GtkWidget* window, GdkEventKey* event) {
(void) window;
if(event->type == GDK_KEY_RELEASE)
- key_to_event(event->keyval, GDK_KEY_RELEASE);
+ key_to_event(event->keyval, event->state, event->is_modifier, GDK_KEY_RELEASE);
return uzbl.behave.forward_keys ? FALSE : TRUE;
}
@@ -837,6 +828,11 @@ download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_dat
/* get the URI being downloaded */
const gchar *uri = webkit_download_get_uri(download);
+ /* get the destination path, if specified.
+ * this is only intended to be set when this function is trigger by an
+ * explicit download using uzbl's 'download' action. */
+ const gchar *destination = user_data;
+
if (uzbl.state.verbose)
printf("Download requested -> %s\n", uri);
@@ -883,6 +879,9 @@ download_cb(WebKitWebView *web_view, WebKitDownload *download, gpointer user_dat
gchar *total_size_s = g_strdup_printf("%d", total_size);
g_array_append_val(a, total_size_s);
+ if(destination)
+ g_array_append_val(a, destination);
+
GString *result = g_string_new ("");
run_parsed_command(c, a, result);
@@ -1054,4 +1053,10 @@ populate_popup_cb(WebKitWebView *v, GtkMenu *m, void *c) {
}
}
+gboolean
+scrollbars_policy_cb(WebKitWebView *view) {
+ (void) view;
+ return TRUE;
+}
+
/* vi: set et ts=4: */
diff --git a/src/callbacks.h b/src/callbacks.h
index d34b9fa..20eaa92 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -157,7 +157,7 @@ progress_change_cb (WebKitWebView* web_view, GParamSpec param_spec);
void
load_status_change_cb (WebKitWebView* web_view, GParamSpec param_spec);
-void
+gboolean
load_error_cb (WebKitWebView* page, WebKitWebFrame* frame, gchar *uri, gpointer web_err, gpointer ud);
void
@@ -222,3 +222,6 @@ scroll_vert_cb(GtkAdjustment *adjust, void *w);
gboolean
scroll_horiz_cb(GtkAdjustment *adjust, void *w);
+
+gboolean
+scrollbars_policy_cb(WebKitWebView *view);
diff --git a/src/cookie-jar.c b/src/cookie-jar.c
index bc7d022..c2ccd62 100644
--- a/src/cookie-jar.c
+++ b/src/cookie-jar.c
@@ -43,7 +43,7 @@ changed(SoupCookieJar *jar, SoupCookie *old_cookie, SoupCookie *new_cookie) {
gchar *expires = NULL;
if(cookie->expires)
- expires = g_strdup_printf ("%d", soup_date_to_time_t (cookie->expires));
+ expires = g_strdup_printf ("%ld", (long)soup_date_to_time_t (cookie->expires));
send_event (new_cookie ? ADD_COOKIE : DELETE_COOKIE, NULL,
TYPE_STR, cookie->domain,
diff --git a/src/events.c b/src/events.c
index 58dddfc..62d6414 100644
--- a/src/events.c
+++ b/src/events.c
@@ -23,6 +23,8 @@ const char *event_table[LAST_EVENT] = {
"REQUEST_STARTING" ,
"KEY_PRESS" ,
"KEY_RELEASE" ,
+ "MOD_PRESS" ,
+ "MOD_RELEASE" ,
"COMMAND_EXECUTED" ,
"LINK_HOVER" ,
"TITLE_CHANGED" ,
@@ -158,11 +160,13 @@ vsend_event(int type, const gchar *custom_event, va_list vargs) {
g_string_append_printf (event_message, "%d", va_arg (vargs, int));
break;
case TYPE_STR:
+ /* a string that needs to be escaped */
g_string_append_c (event_message, '\'');
append_escaped (event_message, va_arg (vargs, char*));
g_string_append_c (event_message, '\'');
break;
case TYPE_FORMATTEDSTR:
+ /* a string has already been escaped */
g_string_append (event_message, va_arg (vargs, char*));
break;
case TYPE_NAME:
@@ -200,31 +204,106 @@ send_event(int type, const gchar *custom_event, ...) {
va_end (vargs);
}
+gchar *
+get_modifier_mask(guint state) {
+ GString *modifiers = g_string_new("");
+
+ if(state & GDK_MODIFIER_MASK) {
+ if(state & GDK_SHIFT_MASK)
+ g_string_append(modifiers, "Shift|");
+ if(state & GDK_LOCK_MASK)
+ g_string_append(modifiers, "ScrollLock|");
+ if(state & GDK_CONTROL_MASK)
+ g_string_append(modifiers, "Ctrl|");
+ if(state & GDK_MOD1_MASK)
+ g_string_append(modifiers,"Mod1|");
+ if(state & GDK_MOD2_MASK)
+ g_string_append(modifiers,"Mod2|");
+ if(state & GDK_MOD3_MASK)
+ g_string_append(modifiers,"Mod3|");
+ if(state & GDK_MOD4_MASK)
+ g_string_append(modifiers,"Mod4|");
+ if(state & GDK_MOD5_MASK)
+ g_string_append(modifiers,"Mod5|");
+ if(state & GDK_BUTTON1_MASK)
+ g_string_append(modifiers,"Button1|");
+ if(state & GDK_BUTTON2_MASK)
+ g_string_append(modifiers,"Button2|");
+ if(state & GDK_BUTTON3_MASK)
+ g_string_append(modifiers,"Button3|");
+ if(state & GDK_BUTTON4_MASK)
+ g_string_append(modifiers,"Button4|");
+ if(state & GDK_BUTTON5_MASK)
+ g_string_append(modifiers,"Button5|");
+
+ if(modifiers->str[modifiers->len-1] == '|')
+ g_string_truncate(modifiers, modifiers->len-1);
+ }
+
+ return g_string_free(modifiers, FALSE);
+}
+
+guint key_to_modifier(guint keyval) {
+ /* FIXME
+ * Should really use XGetModifierMapping and/or Xkb to get actual mod keys
+ */
+ switch(keyval) {
+ case GDK_KEY_Shift_L:
+ case GDK_KEY_Shift_R:
+ return GDK_SHIFT_MASK;
+ case GDK_KEY_Control_L:
+ case GDK_KEY_Control_R:
+ return GDK_CONTROL_MASK;
+ case GDK_KEY_Alt_L:
+ case GDK_KEY_Alt_R:
+ return GDK_MOD1_MASK;
+ case GDK_KEY_Super_L:
+ case GDK_KEY_Super_R:
+ return GDK_MOD4_MASK;
+ case GDK_KEY_ISO_Level3_Shift:
+ return GDK_MOD5_MASK;
+ default:
+ return 0;
+ }
+}
+
/* Transform gdk key events to our own events */
void
-key_to_event(guint keyval, gint mode) {
+key_to_event(guint keyval, guint state, guint is_modifier, gint mode) {
gchar ucs[7];
gint ulen;
gchar *keyname;
guint32 ukval = gdk_keyval_to_unicode(keyval);
+ gchar *modifiers = NULL;
+ guint mod = key_to_modifier (keyval);
+ /* Get modifier state including this key press/release */
+ modifiers = get_modifier_mask(mode == GDK_KEY_PRESS ? state | mod : state & ~mod);
+
+ if(is_modifier && mod) {
+ send_event(mode == GDK_KEY_PRESS ? MOD_PRESS : MOD_RELEASE, NULL,
+ TYPE_STR, modifiers,
+ TYPE_NAME, get_modifier_mask (mod),
+ NULL);
+ }
/* check for printable unicode char */
/* TODO: Pass the keyvals through a GtkIMContext so that
* we also get combining chars right
*/
- if(g_unichar_isgraph(ukval)) {
+ else if(g_unichar_isgraph(ukval)) {
ulen = g_unichar_to_utf8(ukval, ucs);
ucs[ulen] = 0;
- send_event(mode == GDK_KEY_PRESS ? KEY_PRESS : KEY_RELEASE,
- NULL, TYPE_FORMATTEDSTR, ucs, NULL);
+ send_event(mode == GDK_KEY_PRESS ? KEY_PRESS : KEY_RELEASE, NULL,
+ TYPE_STR, modifiers, TYPE_STR, ucs, NULL);
}
/* send keysym for non-printable chars */
else if((keyname = gdk_keyval_name(keyval))){
- send_event(mode == GDK_KEY_PRESS ? KEY_PRESS : KEY_RELEASE,
- NULL, TYPE_NAME, keyname , NULL);
+ send_event(mode == GDK_KEY_PRESS ? KEY_PRESS : KEY_RELEASE, NULL,
+ TYPE_STR, modifiers, TYPE_NAME, keyname, NULL);
}
+ g_free(modifiers);
}
/* vi: set et ts=4: */
diff --git a/src/events.h b/src/events.h
index bd519a6..0c40206 100644
--- a/src/events.h
+++ b/src/events.h
@@ -13,7 +13,8 @@
enum event_type {
LOAD_START, LOAD_COMMIT, LOAD_FINISH, LOAD_ERROR,
REQUEST_STARTING,
- KEY_PRESS, KEY_RELEASE, COMMAND_EXECUTED,
+ KEY_PRESS, KEY_RELEASE, MOD_PRESS, MOD_RELEASE,
+ COMMAND_EXECUTED,
LINK_HOVER, TITLE_CHANGED, GEOMETRY_CHANGED,
WEBINSPECTOR, NEW_WINDOW, SELECTION_CHANGED,
VARIABLE_SET, FIFO_SET, SOCKET_SET,
@@ -41,7 +42,10 @@ vsend_event(int type, const gchar *custom_event, va_list vargs);
void
send_event(int type, const gchar *custom_event, ...) G_GNUC_NULL_TERMINATED;
+gchar *
+get_modifier_mask(guint state);
+
void
-key_to_event(guint keyval, gint mode);
+key_to_event(guint keyval, guint state, guint is_modifier, int mode);
#endif
diff --git a/src/uzbl-core.c b/src/uzbl-core.c
index e498762..046f596 100644
--- a/src/uzbl-core.c
+++ b/src/uzbl-core.c
@@ -47,12 +47,15 @@ GOptionEntry entries[] = {
"Uri to load at startup (equivalent to 'uzbl <uri>' or 'set uri = URI' after uzbl has launched)", "URI" },
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &uzbl.state.verbose,
"Whether to print all messages or just errors.", NULL },
- { "name", 'n', 0, G_OPTION_ARG_STRING, &uzbl.state.instance_name,
+ { "named", 'n', 0, G_OPTION_ARG_STRING, &uzbl.state.instance_name,
"Name of the current instance (defaults to Xorg window id or random for GtkSocket mode)", "NAME" },
{ "config", 'c', 0, G_OPTION_ARG_STRING, &uzbl.state.config_file,
"Path to config file or '-' for stdin", "FILE" },
+ /* TODO: explain the difference between these two options */
{ "socket", 's', 0, G_OPTION_ARG_INT, &uzbl.state.socket_id,
- "Xembed Socket ID", "SOCKET" },
+ "Xembed socket ID, this window should embed itself", "SOCKET" },
+ { "embed", 'e', 0, G_OPTION_ARG_NONE, &uzbl.state.embed,
+ "Whether this window should expect to be embedded", NULL },
{ "connect-socket", 0, 0, G_OPTION_ARG_STRING_ARRAY, &uzbl.state.connect_socket_names,
"Connect to server socket for event managing", "CSOCKET" },
{ "print-events", 'p', 0, G_OPTION_ARG_NONE, &uzbl.state.events_stdout,
@@ -134,7 +137,10 @@ const struct var_name_to_ptr_t {
{ "current_encoding", PTR_V_STR(uzbl.behave.current_encoding, 1, set_current_encoding)},
{ "enforce_96_dpi", PTR_V_INT(uzbl.behave.enforce_96dpi, 1, cmd_enforce_96dpi)},
{ "caret_browsing", PTR_V_INT(uzbl.behave.caret_browsing, 1, cmd_caret_browsing)},
+
+#if !GTK_CHECK_VERSION(3,0,0)
{ "scrollbars_visible", PTR_V_INT(uzbl.gui.scrollbars_visible, 1, cmd_scrollbars_visibility)},
+#endif
/* constants (not dumpable or writeable) */
{ "WEBKIT_MAJOR", PTR_C_INT(uzbl.info.webkit_major, NULL)},
@@ -464,30 +470,25 @@ scroll_cmd(WebKitWebView* page, GArray *argv, GString *result) {
(void) page; (void) result;
gchar *direction = g_array_index(argv, gchar*, 0);
gchar *argv1 = g_array_index(argv, gchar*, 1);
+ GtkAdjustment *bar = NULL;
if (g_strcmp0(direction, "horizontal") == 0)
- {
- if (g_strcmp0(argv1, "begin") == 0)
- gtk_adjustment_set_value(uzbl.gui.bar_h, gtk_adjustment_get_lower(uzbl.gui.bar_h));
- else if (g_strcmp0(argv1, "end") == 0)
- gtk_adjustment_set_value (uzbl.gui.bar_h, gtk_adjustment_get_upper(uzbl.gui.bar_h) -
- gtk_adjustment_get_page_size(uzbl.gui.bar_h));
- else
- scroll(uzbl.gui.bar_h, argv1);
- }
+ bar = uzbl.gui.bar_h;
else if (g_strcmp0(direction, "vertical") == 0)
- {
- if (g_strcmp0(argv1, "begin") == 0)
- gtk_adjustment_set_value(uzbl.gui.bar_v, gtk_adjustment_get_lower(uzbl.gui.bar_v));
- else if (g_strcmp0(argv1, "end") == 0)
- gtk_adjustment_set_value (uzbl.gui.bar_v, gtk_adjustment_get_upper(uzbl.gui.bar_v) -
- gtk_adjustment_get_page_size(uzbl.gui.bar_v));
- else
- scroll(uzbl.gui.bar_v, argv1);
+ bar = uzbl.gui.bar_v;
+ else {
+ if(uzbl.state.verbose)
+ puts("Unrecognized scroll format");
+ return;
}
+
+ if (g_strcmp0(argv1, "begin") == 0)
+ gtk_adjustment_set_value(bar, gtk_adjustment_get_lower(bar));
+ else if (g_strcmp0(argv1, "end") == 0)
+ gtk_adjustment_set_value (bar, gtk_adjustment_get_upper(bar) -
+ gtk_adjustment_get_page_size(bar));
else
- if(uzbl.state.verbose)
- puts("Unrecognized scroll format");
+ scroll(bar, argv1);
}
@@ -552,7 +553,8 @@ CommandInfo cmdlist[] =
{ "show_inspector", show_inspector, 0 },
{ "add_cookie", add_cookie, 0 },
{ "delete_cookie", delete_cookie, 0 },
- { "clear_cookies", clear_cookies, 0 }
+ { "clear_cookies", clear_cookies, 0 },
+ { "download", download, 0 }
};
void
@@ -741,6 +743,28 @@ clear_cookies(WebKitWebView *page, GArray *argv, GString *result) {
}
void
+download(WebKitWebView *web_view, GArray *argv, GString *result) {
+ (void) result;
+
+ const gchar *uri = argv_idx(argv, 0);
+ const gchar *destination = NULL;
+ if(argv->len > 1)
+ destination = argv_idx(argv, 1);
+
+ WebKitNetworkRequest *req = webkit_network_request_new(uri);
+ WebKitDownload *download = webkit_download_new(req);
+
+ download_cb(web_view, download, (gpointer)destination);
+
+ if(webkit_download_get_destination_uri(download))
+ webkit_download_start(download);
+ else
+ g_object_unref(download);
+
+ g_object_unref(req);
+}
+
+void
act_dump_config() {
dump_config();
}
@@ -1233,8 +1257,7 @@ parse_command(const char *cmd, const char *params, GString *result) {
void
move_statusbar() {
- if (!uzbl.gui.scrolled_win &&
- !uzbl.gui.mainbar)
+ if (!uzbl.gui.scrolled_win && !uzbl.gui.mainbar)
return;
g_object_ref(uzbl.gui.scrolled_win);
@@ -1419,12 +1442,13 @@ create_scrolled_win() {
g->web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
g->scrolled_win = gtk_scrolled_window_new(NULL, NULL);
+ WebKitWebFrame *wf = webkit_web_view_get_main_frame (g->web_view);
- gtk_scrolled_window_set_policy(
- GTK_SCROLLED_WINDOW(g->scrolled_win),
- GTK_POLICY_NEVER,
- GTK_POLICY_NEVER
- );
+#if !GTK_CHECK_VERSION(3,0,0)
+ /* hide the scrollbars by default */
+ uzbl.gui.scrollbars_visible = 0;
+ cmd_scrollbars_visibility();
+#endif
gtk_container_add(
GTK_CONTAINER(g->scrolled_win),
@@ -1454,6 +1478,10 @@ create_scrolled_win() {
"signal::focus-in-event", (GCallback)focus_cb, NULL,
"signal::focus-out-event", (GCallback)focus_cb, NULL,
NULL);
+
+ g_object_connect (G_OBJECT (wf),
+ "signal::scrollbars-policy-changed", (GCallback)scrollbars_policy_cb, NULL,
+ NULL);
}
@@ -1498,7 +1526,7 @@ create_window() {
gtk_window_set_title(GTK_WINDOW(window), "Uzbl browser");
#if GTK_CHECK_VERSION(3,0,0)
- gtk_window_set_has_resize_grip (window, FALSE);
+ gtk_window_set_has_resize_grip (GTK_WINDOW (window), FALSE);
#endif
/* if the window has been made small, it shouldn't try to resize itself due
@@ -1517,6 +1545,7 @@ create_window() {
GtkPlug*
create_plug() {
+ if(uzbl.state.embed) uzbl.state.socket_id = 0;
GtkPlug* plug = GTK_PLUG (gtk_plug_new (uzbl.state.socket_id));
g_signal_connect (G_OBJECT (plug), "destroy", G_CALLBACK (destroy_cb), NULL);
g_signal_connect (G_OBJECT (plug), "key-press-event", G_CALLBACK (key_press_cb), NULL);
@@ -1667,28 +1696,6 @@ retrieve_geometry() {
uzbl.gui.geometry = g_string_free(buf, FALSE);
}
-void
-set_webview_scroll_adjustments() {
-#if GTK_CHECK_VERSION(2,91,0)
- gtk_scrollable_set_hadjustment (GTK_SCROLLABLE(uzbl.gui.web_view), uzbl.gui.bar_h);
- gtk_scrollable_set_vadjustment (GTK_SCROLLABLE(uzbl.gui.web_view), uzbl.gui.bar_v);
-#else
- gtk_widget_set_scroll_adjustments (GTK_WIDGET (uzbl.gui.web_view),
- uzbl.gui.bar_h, uzbl.gui.bar_v);
-#endif
-
- g_object_connect((GObject*)uzbl.gui.bar_v,
- "signal::value-changed", (GCallback)scroll_vert_cb, NULL,
- "signal::changed", (GCallback)scroll_vert_cb, NULL,
- NULL);
-
- g_object_connect((GObject*)uzbl.gui.bar_h,
- "signal::value-changed", (GCallback)scroll_horiz_cb, NULL,
- "signal::changed", (GCallback)scroll_horiz_cb, NULL,
- NULL);
-}
-
-
/* Set up gtk, gobject, variable defaults and other things that tests and other
* external applications need to do anyhow */
void
@@ -1723,7 +1730,7 @@ initialize(int argc, char** argv) {
}
/* Embedded mode */
- if (uzbl.state.socket_id)
+ if (uzbl.state.socket_id || uzbl.state.embed)
uzbl.state.plug_mode = TRUE;
if (!g_thread_supported())
@@ -1834,12 +1841,18 @@ main (int argc, char* argv[]) {
}
/* Scrolling */
- uzbl.gui.scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL);
- uzbl.gui.bar_v = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_v);
- uzbl.gui.scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL);
- uzbl.gui.bar_h = gtk_range_get_adjustment((GtkRange*) uzbl.gui.scbar_h);
+ uzbl.gui.bar_h = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (uzbl.gui.scrolled_win));
+ uzbl.gui.bar_v = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (uzbl.gui.scrolled_win));
+
+ g_object_connect(G_OBJECT (uzbl.gui.bar_v),
+ "signal::value-changed", (GCallback)scroll_vert_cb, NULL,
+ "signal::changed", (GCallback)scroll_vert_cb, NULL,
+ NULL);
- set_webview_scroll_adjustments();
+ g_object_connect(G_OBJECT (uzbl.gui.bar_h),
+ "signal::value-changed", (GCallback)scroll_horiz_cb, NULL,
+ "signal::changed", (GCallback)scroll_horiz_cb, NULL,
+ NULL);
gchar *xwin = g_strdup_printf("%d", (int)uzbl.xwin);
g_setenv("UZBL_XID", xwin, TRUE);
@@ -1899,7 +1912,7 @@ main (int argc, char* argv[]) {
if (uzbl.state.verbose) {
printf("Uzbl start location: %s\n", argv[0]);
if (uzbl.state.socket_id)
- printf("plug_id %i\n", gtk_plug_get_id(uzbl.gui.plug));
+ printf("plug_id %i\n", (int)gtk_plug_get_id(uzbl.gui.plug));
else
printf("window_id %i\n",(int) uzbl.xwin);
printf("pid %i\n", getpid ());
diff --git a/src/uzbl-core.h b/src/uzbl-core.h
index affd334..3fde5dc 100644
--- a/src/uzbl-core.h
+++ b/src/uzbl-core.h
@@ -67,8 +67,6 @@ typedef struct {
GtkWidget* mainbar_label_right;
/* Scrolling */
- GtkScrollbar* scbar_v; /* Horizontal and Vertical Scrollbar */
- GtkScrollbar* scbar_h; /* (These are still hidden) */
GtkAdjustment* bar_v; /* Information about document length */
GtkAdjustment* bar_h; /* and scrolling position */
int scrollbars_visible;
@@ -109,6 +107,7 @@ typedef struct {
gchar* executable_path;
gchar* searchtx;
gboolean verbose;
+ gboolean embed;
GdkEventButton* last_button;
gchar* last_result;
gboolean plug_mode;
@@ -313,7 +312,6 @@ void dump_config();
void dump_config_as_events();
void retrieve_geometry();
-void set_webview_scroll_adjustments();
void event(WebKitWebView *page, GArray *argv, GString *result);
void init_connect_socket();
gboolean remove_socket_from_array(GIOChannel *chan);
@@ -325,6 +323,7 @@ void show_inspector(WebKitWebView *page, GArray *argv, GString *result);
void add_cookie(WebKitWebView *page, GArray *argv, GString *result);
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 builtins();
typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result);