5 -- Widget construction aliases
6 function eventbox() return widget
{type="eventbox"} end
7 function hbox() return widget
{type="hbox"} end
8 function label() return widget
{type="label"} end
9 function notebook() return widget
{type="notebook"} end
10 function vbox() return widget
{type="vbox"} end
11 function webview() return widget
{type="webview"} end
12 function window() return widget
{type="window"} end
13 function entry() return widget
{type="entry"} end
15 -- Keep a list of windows and data objects
18 -- Widget type-specific default settings
19 widget
.add_signal("new", function(w
)
20 w
:add_signal("init", function(w
)
21 if w
.type == "window" then
22 -- Call the quit function if this was the last window left
23 w
:add_signal("destroy", function ()
24 if #luakit
.windows
== 0 then luakit
.quit() end
26 elseif w
.type == "label" or w
.type == "entry" then
27 w
.font
= "monospace normal 9"
32 -- Returns a nice window title
33 function mktitle(view
)
34 if not view
:get_prop("title") and not view
.uri
then return "luakit" end
35 return (view
:get_prop("title") or "luakit") .. " - " .. (view
.uri
or "about:blank")
38 -- Returns true if the given view is the currently active view
39 function iscurrent(nbook
, view
)
40 return nbook
:current() == nbook
:indexof(view
)
43 function mktabcount(nbook
, i
)
44 return string.format("[%d/%d]", i
or nbook
:current(), nbook
:count())
47 -- Returns a vim-like scroll indicator
48 function scroll_parse(view
)
49 val
, max = view
:get_vscroll()
54 elseif val
== max then
57 return string.format("%2d%%", (val
/max) * 100)
61 function autohide(nbook
, n
)
62 if not n
then n
= nbook
:count() end
64 nbook
.show_tabs
= false
66 nbook
.show_tabs
= true
70 function progress_update(w
, view
, p
)
71 if not p
then p
= view
:get_prop("progress") end
72 if not view
:loading() or p
== 1 then
76 w
.sbar
.loaded
.text
= string.format("(%d%%)", p
* 100)
80 function new_tab(w
, uri
)
85 -- Attach webview signals
86 view
:add_signal("title-changed", function (v
)
87 w
.tabs
:set_title(v
, v
:get_prop("title") or "(Untitled)")
88 if iscurrent(w
.tabs
, v
) then
89 w
.win
.title
= mktitle(v
)
93 view
:add_signal("property::uri", function(v
)
94 if not w
.tabs
:get_title(v
) then
95 w
.tabs
:set_title(v
, v
.uri
or "about:blank")
98 if iscurrent(w
.tabs
, v
) then
99 w
.sbar
.uri
.text
= v
.uri
or "about:blank"
103 view
:add_signal("load-start", function (v
)
104 if iscurrent(w
.tabs
, v
) then progress_update(w
, v
, 0) end
106 view
:add_signal("progress-update", function (v
)
107 if iscurrent(w
.tabs
, v
) then progress_update(w
, v
) end
110 view
:add_signal("expose", function(v
)
111 if iscurrent(w
.tabs
, v
) then
112 w
.sbar
.scroll
.text
= scroll_parse(v
)
122 -- Construct new window
123 function new_window(uris
)
124 -- Widget & state variables
129 -- Status bar widgets
151 w
.win
:set_child(w
.layout
)
152 w
.sbar
.ebox
:set_child(w
.sbar
.layout
)
153 w
.layout
:pack_start(w
.tabs
, true, true, 0)
154 w
.sbar
.layout
:pack_start(w
.sbar
.uri
, false, false, 0)
155 w
.sbar
.layout
:pack_start(w
.sbar
.loaded
, false, false, 0)
156 w
.sbar
.layout
:pack_start(w
.sbar
.sep
, true, true, 0)
158 -- Put the right-most labels in something backgroundable
159 w
.sbar
.rlayout
:pack_start(w
.sbar
.tabi
, false, false, 0)
160 w
.sbar
.rlayout
:pack_start(w
.sbar
.scroll
, false, false, 2)
161 w
.sbar
.rebox
:set_child(w
.sbar
.rlayout
)
163 w
.sbar
.layout
:pack_start(w
.sbar
.rebox
, false, false, 0)
164 w
.layout
:pack_start(w
.sbar
.ebox
, false, false, 0)
167 w
.ibar
.layout
:pack_start(w
.ibar
.prompt
, false, false, 0)
168 w
.ibar
.layout
:pack_start(w
.ibar
.input
, false, false, 0)
169 w
.ibar
.ebox
:set_child(w
.ibar
.layout
)
170 w
.layout
:pack_start(w
.ibar
.ebox
, false, false, 0)
172 w
.sbar
.uri
.fg
= "#fff"
173 w
.sbar
.uri
.selectable
= true
174 w
.sbar
.loaded
.fg
= "#888"
176 w
.sbar
.rebox
.bg
= "#000"
177 w
.sbar
.scroll
.fg
= "#fff"
178 w
.sbar
.scroll
.text
= "All"
179 w
.sbar
.tabi
.text
= "[0/0]"
180 w
.sbar
.tabi
.fg
= "#fff"
181 w
.sbar
.ebox
.bg
= "#000"
183 w
.ibar
.input
.show_frame
= false
184 w
.ibar
.input
.bg
= "#fff"
185 w
.ibar
.input
.fg
= "#000"
187 w
.ibar
.ebox
.bg
= "#fff"
188 w
.ibar
.prompt
.text
= "Hello"
189 w
.ibar
.prompt
.fg
= "#000"
191 -- Attach notebook signals
192 w
.tabs
:add_signal("page-added", function(nbook
, view
, idx
)
193 w
.sbar
.tabi
.text
= mktabcount(nbook
)
195 w
.tabs
:add_signal("switch-page", function(nbook
, view
, idx
)
196 w
.sbar
.tabi
.text
= mktabcount(nbook
, idx
)
197 w
.sbar
.uri
.text
= view
.uri
or "about:blank"
198 w
.win
.title
= mktitle(view
)
199 progress_update(w
, view
)
203 -- Mode specific actions
204 w
.win
:add_signal("mode-changed", function(win
, mode
)
205 if mode
== "normal" then
206 w
.ibar
.prompt
.text
= ""
209 w
.ibar
.input
.text
= ""
210 elseif mode
== "input" then
212 w
.ibar
.input
.text
= ""
213 w
.ibar
.prompt
.text
= " -- INPUT -- "
215 elseif mode
== "command" then
217 w
.ibar
.prompt
.text
= ""
218 w
.ibar
.input
.text
= ":"
225 for _
, uri
in ipairs(uris
) do
229 -- Make sure something is loaded
230 if w
.tabs
:count() == 0 then
231 new_tab(w
, "http://github.com/mason-larobina/luakit")