Convert window class into window widget
[luakit.git] / rc.lua
blobc858ee38b39a85cd35e7cd7892eebfe02de4a7ed
1 #!./luakit -c
3 -- Widget construction aliases
4 function eventbox() return widget{type="eventbox"} end
5 function hbox() return widget{type="hbox"} end
6 function label() return widget{type="label"} end
7 function notebook() return widget{type="notebook"} end
8 function vbox() return widget{type="vbox"} end
9 function webview() return widget{type="webview"} end
10 function window() return widget{type="window"} end
12 function widget_setup(w)
13 print("new widget", w.type)
14 if w.type == "window" then
15 -- Call the quit function if this was the last window left
16 w:add_signal("destroy", function ()
17 if #luakit.windows == 0 then luakit.quit() end
18 end)
19 end
20 end
22 widget.add_signal("new", function(w)
23 w:add_signal("init", function(w)
24 widget_setup(w)
25 end)
26 end)
28 -- Create main widgets
29 win = window()
30 layout = vbox()
31 win:set_child(layout)
33 -- Create tabbed notebook to store webviews
34 tabs = notebook()
35 layout:pack_start(tabs, true, true, 0)
37 -- Create "status bar"
39 left = label()
40 left.text = "left"
41 left:set_alignment(0.0, 0.0)
43 right = label()
44 right.text = "right"
45 right:set_alignment(1.0, 0.0)
47 sbar_layout = hbox()
48 sbar_layout:pack_start(left, true, true, 2)
49 sbar_layout:pack_start(right, false, false, 2)
51 statusbar = eventbox()
52 statusbar:set_child(sbar_layout)
54 layout:pack_start(statusbar, false, false, 0)
56 if #uris == 0 then
57 uris = { "http://github.com/mason-larobina/luakit" }
58 end
60 for _, uri in ipairs(uris) do
61 view = webview()
62 tabs:append(view)
64 view:add_signal("property::title", function (v)
65 local title = v:get_prop("title")
66 tabs:set_title(v, title)
67 win.title = title
68 left.text = title
69 right.text = v:get_prop("uri")
70 end)
72 view:add_signal("link-hover", function(v, link)
73 print(view, link)
74 end)
76 view:add_signal("link-unhover", function(v, link)
77 print(view, link)
78 end)
80 view.uri = uri
81 end