window.lua

Wed, 01 Sep 2010 04:03:42 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 01 Sep 2010 04:03:42 +0100
changeset 2
1e9553b2f9a2
parent 1
4d7540af8518
permissions
-rw-r--r--

Add note about required patch

0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 ------------------
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Window class --
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 ------------------
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- Window class table
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 window = {}
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 -- Widget construction aliases
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local function entry() return widget{type="entry"} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local function eventbox() return widget{type="eventbox"} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local function hbox() return widget{type="hbox"} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local function label() return widget{type="label"} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local function notebook() return widget{type="notebook"} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local function vbox() return widget{type="vbox"} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 -- Build and pack window widgets
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 function window.build()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 -- Create a table for widgets and state variables for a window
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local w = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 win = widget{type="window"},
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 ebox = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 layout = vbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 tabs = notebook(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 -- Tab bar widgets
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 tbar = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 layout = hbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 ebox = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 titles = { },
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 },
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 -- Status bar widgets
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 sbar = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 layout = hbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 ebox = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 -- Left aligned widgets
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 l = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 layout = hbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 ebox = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 uri = label(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 loaded = label(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 },
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 -- Fills space between the left and right aligned widgets
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 sep = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 -- Right aligned widgets
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 r = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 layout = hbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 ebox = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 buf = label(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 ssl = label(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 tabi = label(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 scroll = label(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 },
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 },
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 -- Input bar widgets
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 ibar = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 layout = hbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 ebox = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 prompt = label(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 input = entry(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 },
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 }
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 -- Assemble window
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 w.ebox:set_child(w.layout)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 w.win:set_child(w.ebox)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 -- Pack tab bar
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 local t = w.tbar
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 t.ebox:set_child(t.layout, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 w.layout:pack_start(t.ebox, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 -- Pack notebook
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 w.layout:pack_start(w.tabs, true, true, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 -- Pack left-aligned statusbar elements
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 local l = w.sbar.l
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 l.layout:pack_start(l.uri, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 l.layout:pack_start(l.loaded, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 l.ebox:set_child(l.layout)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 -- Pack right-aligned statusbar elements
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 local r = w.sbar.r
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 r.layout:pack_start(r.buf, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 r.layout:pack_start(r.ssl, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 r.layout:pack_start(r.tabi, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 r.layout:pack_start(r.scroll, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 r.ebox:set_child(r.layout)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 -- Pack status bar elements
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 local s = w.sbar
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 s.layout:pack_start(l.ebox, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 s.layout:pack_start(s.sep, true, true, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 s.layout:pack_start(r.ebox, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 s.ebox:set_child(s.layout)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 w.layout:pack_start(s.ebox, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 -- Pack input bar
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 local i = w.ibar
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 i.layout:pack_start(i.prompt, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 i.layout:pack_start(i.input, true, true, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 i.ebox:set_child(i.layout)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 w.layout:pack_start(i.ebox, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 -- Other settings
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 i.input.show_frame = false
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 w.tabs.show_tabs = false
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 l.loaded:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 l.uri.selectable = true
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 r.ssl:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 return w
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 -- Table of functions to call on window creation. Normally used to add signal
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 -- handlers to the new windows widgets.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 window.init_funcs = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 -- Attach notebook widget signals
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 notebook_signals = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 w.tabs:add_signal("page-added", function (nbook, view, idx)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 w:update_tab_count(idx)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 w:update_tab_labels()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 end)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 w.tabs:add_signal("switch-page", function (nbook, view, idx)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 w:set_mode()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 w:update_tab_count(idx)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 w:update_win_title(view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 w:update_uri(view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 w:update_progress(view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 w:update_tab_labels(idx)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 w:update_buf()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 w:update_ssl(view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 end)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 last_win_check = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 w.win:add_signal("destroy", function ()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 -- call the quit function if this was the last window left
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 if #luakit.windows == 0 then luakit.quit() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 end)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 key_press_match = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 w.win:add_signal("key-press", function (_, mods, key)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 -- Reset command line completion
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 if w:get_mode() == "command" and key ~= "Tab" and w.compl_start then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 w:update_uri()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 w.compl_index = 0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 if w:hit(mods, key) then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 return true
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 end)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 apply_window_theme = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 local theme = lousy.theme.get()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 local s, i = w.sbar, w.ibar
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 -- Set foregrounds
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 for wi, v in pairs({
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 [s.l.uri] = theme.uri_sbar_fg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 [s.l.loaded] = theme.loaded_sbar_fg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 [s.r.buf] = theme.buf_sbar_fg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 [s.r.tabi] = theme.tabi_sbar_fg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 [s.r.scroll] = theme.scroll_sbar_fg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 [i.prompt] = theme.prompt_ibar_fg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 [i.input] = theme.input_ibar_fg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 }) do wi.fg = v end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 -- Set backgrounds
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 for wi, v in pairs({
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 [s.l.ebox] = theme.sbar_bg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 [s.r.ebox] = theme.sbar_bg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 [s.sep] = theme.sbar_bg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 [s.ebox] = theme.sbar_bg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 [i.ebox] = theme.ibar_bg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 [i.input] = theme.input_ibar_bg,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 }) do wi.bg = v end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 -- Set fonts
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 for wi, v in pairs({
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 [s.l.uri] = theme.uri_sbar_font,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 [s.l.loaded] = theme.loaded_sbar_font,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 [s.r.buf] = theme.buf_sbar_font,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 [s.r.ssl] = theme.ssl_sbar_font,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 [s.r.tabi] = theme.tabi_sbar_font,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 [s.r.scroll] = theme.scroll_sbar_font,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 [i.prompt] = theme.prompt_ibar_font,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 [i.input] = theme.input_ibar_font,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 }) do wi.font = v end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 }
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 -- Helper functions which operate on the window widgets or structure.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 window.methods = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 -- Return the widget in the currently active tab
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 get_current = function (w) return w.tabs:atindex(w.tabs:current()) end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 -- Check if given widget is the widget in the currently active tab
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 is_current = function (w, wi) return w.tabs:indexof(wi) == w.tabs:current() end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 get_tab_title = function (w, view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202 if not view then view = w:get_current() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203 return view:get_prop("title") or view.uri or "(Untitled)"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
204 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 new_tab = function (w, uri)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
207 local view = webview.new(w, uri)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208 w.tabs:append(view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
209 w:update_tab_count()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
210 return view
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
213 -- Wrapper around the bind plugin's hit method
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 hit = function (w, mods, key)
1
4d7540af8518 Initial set of changes to make 'insert' mode 'normal', eradicate 'command' mode and adjust key bindings appropriately (following common binding patterns from other browsers, and in places the nano text editor)
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
215 local caught, newbuf = lousy.bind.hit(w.binds or {}, mods, key, w.buffer, false, w)
0
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 if w.win then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217 w.buffer = newbuf
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218 w:update_buf()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
220 return caught
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
221 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
222
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
223 -- Wrapper around the bind plugin's match_cmd method
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
224 match_cmd = function (w, buffer)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
225 return lousy.bind.match_cmd(binds.commands, buffer, w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
226 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
227
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
228 -- enter command or characters into command line
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 enter_cmd = function (w, cmd)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230 local i = w.ibar.input
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
231 w:set_mode("command")
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232 i.text = cmd
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
233 i:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
234 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
236 -- insert a string into the command line at the current cursor position
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 insert_cmd = function (w, str)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238 if not str then return end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
239 local i = w.ibar.input
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 local text = i.text
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 local pos = i:get_position()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242 local left, right = string.sub(text, 1, pos), string.sub(text, pos+1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
243 i.text = left .. str .. right
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
244 i:set_position(pos + #str + 1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
245 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247 -- Command line completion of available commands
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
248 cmd_completion = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249 local i = w.ibar.input
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
250 local s = w.sbar.l.uri
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
251 local cmpl = {}
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253 -- Get last completion (is reset on key press other than <Tab>)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254 if not w.compl_start or w.compl_index == 0 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
255 w.compl_start = "^" .. string.sub(i.text, 2)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
256 w.compl_index = 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 -- Get suitable commands
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
260 for _, b in ipairs(binds.commands) do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
261 for _, c in pairs(b.commands) do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 if c and string.match(c, w.compl_start) then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
263 table.insert(cmpl, c)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
264 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
267
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
268 table.sort(cmpl)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
269
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
270 if #cmpl > 0 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
271 local text = ""
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272 for index, comp in pairs(cmpl) do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273 if index == w.compl_index then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
274 i.text = ":" .. comp .. " "
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
275 i:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
276 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
277 if text ~= "" then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
278 text = text .. " | "
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
279 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
280 text = text .. comp
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
281 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
282
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283 -- cycle through all possible completions
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
284 if w.compl_index == #cmpl then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
285 w.compl_index = 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
286 else
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
287 w.compl_index = w.compl_index + 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
288 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
289 s.text = lousy.util.escape(text)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
291 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
293 del_word = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294 local i = w.ibar.input
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
295 local text = i.text
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
296 local pos = i:get_position()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
297 if text and #text > 1 and pos > 1 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
298 local left, right = string.sub(text, 2, pos), string.sub(text, pos+1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
299 if not string.find(left, "%s") then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
300 left = ""
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
301 elseif string.find(left, "%w+%s*$") then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
302 left = string.sub(left, 0, string.find(left, "%w+%s*$") - 1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
303 elseif string.find(left, "%W+%s*$") then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
304 left = string.sub(left, 0, string.find(left, "%W+%s*$") - 1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
305 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
306 i.text = string.sub(text, 1, 1) .. left .. right
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
307 i:set_position(#left + 2)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
308 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
309 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
310
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
311 del_line = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
312 local i = w.ibar.input
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
313 if i.text ~= ":" then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
314 i.text = ":"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315 i:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
316 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
317 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
318
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
319 -- Search history adding
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
320 srch_hist_add = function (w, srch)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
321 if not w.srch_hist then w.srch_hist = {} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
322 -- Check overflow
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
323 local max_hist = globals.max_srch_history or 100
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
324 if #w.srch_hist > (max_hist + 5) then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
325 while #w.srch_hist > max_hist do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
326 table.remove(w.srch_hist, 1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
327 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329 table.insert(w.srch_hist, srch)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
330 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332 -- Search history traversing
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
333 srch_hist_prev = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
334 if not w.srch_hist then w.srch_hist = {} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 if not w.srch_hist_cursor then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
336 w.srch_hist_cursor = #w.srch_hist + 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
337 w.srch_hist_current = w.ibar.input.text
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
338 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
339 local c = w.srch_hist_cursor - 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
340 if w.srch_hist[c] then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
341 w.srch_hist_cursor = c
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
342 w.ibar.input.text = w.srch_hist[c]
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
343 w.ibar.input:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
346
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
347 srch_hist_next = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
348 if not w.srch_hist then w.srch_hist = {} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
349 local c = (w.srch_hist_cursor or #w.srch_hist) + 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
350 if w.srch_hist[c] then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
351 w.srch_hist_cursor = c
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
352 w.ibar.input.text = w.srch_hist[c]
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
353 w.ibar.input:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
354 elseif w.srch_hist_current then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
355 w.srch_hist_cursor = nil
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
356 w.ibar.input.text = w.srch_hist_current
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
357 w.ibar.input:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
358 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
359 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
360
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
361 -- Command history adding
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
362 cmd_hist_add = function (w, cmd)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
363 if not w.cmd_hist then w.cmd_hist = {} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
364 -- Make sure history doesn't overflow
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
365 local max_hist = globals.max_cmd_hist or 100
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
366 if #w.cmd_hist > (max_hist + 5) then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
367 while #w.cmd_hist > max_hist do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
368 table.remove(w.cmd_hist, 1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
369 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
370 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
371 table.insert(w.cmd_hist, cmd)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
372 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
373
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
374 -- Command history traversing
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
375 cmd_hist_prev = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
376 if not w.cmd_hist then w.cmd_hist = {} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
377 if not w.cmd_hist_cursor then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
378 w.cmd_hist_cursor = #w.cmd_hist + 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
379 w.cmd_hist_current = w.ibar.input.text
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
380 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
381 local c = w.cmd_hist_cursor - 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
382 if w.cmd_hist[c] then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
383 w.cmd_hist_cursor = c
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
384 w.ibar.input.text = w.cmd_hist[c]
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
385 w.ibar.input:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
386 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
387 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
388
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
389 cmd_hist_next = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
390 if not w.cmd_hist then w.cmd_hist = {} end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
391 local c = (w.cmd_hist_cursor or #w.cmd_hist) + 1
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
392 if w.cmd_hist[c] then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
393 w.cmd_hist_cursor = c
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
394 w.ibar.input.text = w.cmd_hist[c]
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
395 w.ibar.input:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
396 elseif w.cmd_hist_current then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
397 w.cmd_hist_cursor = nil
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
398 w.ibar.input.text = w.cmd_hist_current
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
399 w.ibar.input:set_position(-1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
400 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
401 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
402
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
403 -- GUI content update functions
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
404 update_tab_count = function (w, i, t)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
405 w.sbar.r.tabi.text = string.format("[%d/%d]", i or w.tabs:current(), t or w.tabs:count())
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
406 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
407
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
408 update_win_title = function (w, view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
409 if not view then view = w:get_current() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
410 local title = view:get_prop("title")
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
411 local uri = view.uri
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
412 if not title and not uri then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
413 w.win.title = "luakit"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
414 else
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
415 w.win.title = (title or "luakit") .. " - " .. (uri or "about:blank")
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
416 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
417 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
418
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
419 update_uri = function (w, view, uri)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
420 if not view then view = w:get_current() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
421 w.sbar.l.uri.text = lousy.util.escape((uri or (view and view.uri) or "about:blank"))
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
422 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
423
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
424 update_progress = function (w, view, p)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
425 if not view then view = w:get_current() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
426 if not p then p = view:get_prop("progress") end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
427 local loaded = w.sbar.l.loaded
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
428 if not view:loading() or p == 1 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
429 loaded:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
430 else
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
431 loaded:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
432 loaded.text = string.format("(%d%%)", p * 100)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
433 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
434 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
435
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
436 update_scroll = function (w, view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
437 if not view then view = w:get_current() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
438 local scroll = w.sbar.r.scroll
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
439 if view then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
440 local val, max = view:get_scroll_vert()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
441 if max == 0 then val = "All"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
442 elseif val == 0 then val = "Top"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
443 elseif val == max then val = "Bot"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
444 else val = string.format("%2d%%", (val/max) * 100)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
445 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
446 if scroll.text ~= val then scroll.text = val end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
447 scroll:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
448 else
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
449 scroll:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
450 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
451 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
452
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
453 update_ssl = function (w, view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
454 if not view then view = w:get_current() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
455 local trusted = view:ssl_trusted()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
456 local theme = lousy.theme.get()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
457 local ssl = w.sbar.r.ssl
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
458 if trusted ~= nil and not w.checking_ssl then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
459 ssl.fg = theme.notrust_fg
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
460 ssl.text = "(nocheck)"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
461 ssl:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
462 elseif trusted == true then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
463 ssl.fg = theme.trust_fg
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
464 ssl.text = "(trust)"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
465 ssl:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
466 elseif trusted == false then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
467 ssl.fg = theme.notrust_fg
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
468 ssl.text = "(notrust)"
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
469 ssl:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
470 else
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
471 ssl:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
472 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
473 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
474
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
475 update_buf = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
476 local buf = w.sbar.r.buf
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
477 if w.buffer then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
478 buf.text = lousy.util.escape(string.format(" %-3s", w.buffer))
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
479 buf:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
480 else
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
481 buf:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
482 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
483 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
484
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
485 update_binds = function (w, mode)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
486 -- Generate the list of active key & buffer binds for this mode
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
487 w.binds = lousy.util.table.join(binds.mode_binds[mode], binds.mode_binds.all)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
488 -- Clear & hide buffer
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
489 w.buffer = nil
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
490 w:update_buf()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
491 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
492
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
493 -- Tab label functions
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
494 -- TODO: Move these functions into a module (I.e. lousy.widget.tablist)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
495 make_tab_label = function (w, pos)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
496 local theme = lousy.theme.get()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
497 local t = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
498 label = label(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
499 sep = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
500 ebox = eventbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
501 layout = hbox(),
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
502 }
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
503 t.label.font = theme.tab_font
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
504 t.label:set_width(1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
505 t.layout:pack_start(t.label, true, true, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
506 t.layout:pack_start(t.sep, false, false, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
507 t.ebox:set_child(t.layout)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
508 t.ebox:add_signal("button-release", function (e, m, b)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
509 if b == 1 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
510 w.tabs:switch(pos)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
511 return true
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
512 elseif b == 2 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
513 w:close_tab(w.tabs:atindex(pos))
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
514 return true
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
515 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
516 end)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
517 return t
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
518 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
519
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
520 destroy_tab_label = function (w, t)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
521 if not t then t = table.remove(w.tbar.titles) end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
522 -- Destroy widgets without their own windows first (I.e. labels)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
523 for _, wi in ipairs{ t.label, t.sep, t.ebox, t.layout } do wi:destroy() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
524 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
525
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
526 update_tab_labels = function (w, current)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
527 local tb = w.tbar
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
528 local count, current = w.tabs:count(), current or w.tabs:current()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
529 tb.ebox:hide()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
530
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
531 -- Leave the tablist hidden if there is only one tab open
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
532 if count <= 1 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
533 return nil
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
534 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
535
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
536 if count ~= #tb.titles then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
537 -- Grow the number of labels
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
538 while count > #tb.titles do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
539 local t = w:make_tab_label(#tb.titles + 1)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
540 tb.layout:pack_start(t.ebox, true, true, 0)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
541 table.insert(tb.titles, t)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
542 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
543 -- Prune number of labels
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
544 while count < #tb.titles do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
545 w:destroy_tab_label()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
546 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
547 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
548
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
549 if count ~= 0 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
550 for i = 1, count do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
551 local view = w.tabs:atindex(i)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
552 local t = tb.titles[i]
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
553 local title = " " ..i.. " "..w:get_tab_title(view)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
554 t.label.text = lousy.util.escape(string.format("%-40s", title))
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
555 w:apply_tablabel_theme(t, i == current)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
556 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
557 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
558 tb.ebox:show()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
559 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
560
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
561 -- Theme functions
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
562 apply_tablabel_theme = function (w, t, selected)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
563 local theme = lousy.theme.get()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
564 selected = (selected and "_selected") or ""
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
565 t.label.fg = theme[string.format("tab%s_fg", selected)]
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
566 t.ebox.bg = theme[string.format("tab%s_bg", selected)]
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
567 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
568
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
569 close_win = function (w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
570 -- Close all tabs
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
571 while w.tabs:count() ~= 0 do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
572 w:close_tab()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
573 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
574
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
575 -- Recursively remove widgets from window
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
576 local children = lousy.util.recursive_remove(w.win)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
577 -- Destroy all widgets
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
578 for i, c in ipairs(lousy.util.table.join(children, {w.win})) do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
579 if c.hide then c:hide() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
580 c:destroy()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
581 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
582
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
583 -- Clear window struct
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
584 w = setmetatable(w, {})
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
585 for k, _ in pairs(w) do w[k] = nil end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
586
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
587 -- Quit if closed last window
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
588 if #luakit.windows == 0 then luakit.quit() end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
589 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
590 }
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
591
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
592 -- Ordered list of class index functions. Other classes (E.g. webview) are able
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
593 -- to add their own index functions to this list.
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
594 window.indexes = {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
595 -- Find function in window.methods first
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
596 function (w, k) return window.methods[k] end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
597 }
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
598
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
599 -- Create new window
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
600 function window.new(uris)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
601 local w = window.build()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
602
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
603 -- Set window metatable
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
604 setmetatable(w, {
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
605 __index = function (_, k)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
606 -- Check widget structure first
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
607 local v = rawget(w, k)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
608 if v then return v end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
609 -- Call each window index function
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
610 for _, index in ipairs(window.indexes) do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
611 v = index(w, k)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
612 if v then return v end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
613 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
614 end,
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
615 })
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
616
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
617 -- Call window init functions
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
618 for _, func in pairs(window.init_funcs) do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
619 func(w)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
620 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
621
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
622 -- Populate notebook with tabs
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
623 for _, uri in ipairs(uris or {}) do
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
624 w:new_tab(uri)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
625 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
626
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
627 -- Make sure something is loaded
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
628 if w.tabs:count() == 0 then
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
629 w:new_tab(globals.homepage)
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
630 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
631
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
632 -- Set initial mode
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
633 w:set_mode()
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
634
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
635 return w
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
636 end
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
637
98e4b0c9fcac Initial commit of default luakit config from 2010.08.30
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
638 -- vim: et:sw=4:ts=8:sts=4:tw=80

mercurial