]> git.rmz.io Git - dotfiles.git/blob - awesome/topbar.lua
move run_once to utils module
[dotfiles.git] / awesome / topbar.lua
1 -- utils
2 local utils = require("utils")
3
4 -- Widget and layout library
5 local wibox = require("wibox")
6
7 -- my widgets
8 local volume_widget = require("widgets/volume_widget")
9 if utils.host == "chronos" then
10 local battery_widget = require("widgets/battery_widget")
11 end
12 local network_widget = require("widgets/network_widget")
13
14 -- Create a textclock widget
15 mytextclock = awful.widget.textclock()
16
17 -- {{{ Wibox
18 -- Create a wibox for each screen and add it
19 mywibox = {}
20 mypromptbox = {}
21 mylayoutbox = {}
22 mytaglist = {}
23 mytaglist.buttons = awful.util.table.join(
24 awful.button({ }, 1, awful.tag.viewonly),
25 awful.button({ modkey }, 1, awful.client.movetotag),
26 awful.button({ }, 3, awful.tag.viewtoggle),
27 awful.button({ modkey }, 3, awful.client.toggletag),
28 awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
29 awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
30 )
31 mytasklist = {}
32 mytasklist.buttons = awful.util.table.join(
33 awful.button({ }, 1, function (c)
34 if c == client.focus then
35 c.minimized = true
36 else
37 -- Without this, the following
38 -- :isvisible() makes no sense
39 c.minimized = false
40 if not c:isvisible() then
41 awful.tag.viewonly(c:tags()[1])
42 end
43 -- This will also un-minimize
44 -- the client, if needed
45 client.focus = c
46 c:raise()
47 end
48 end),
49 awful.button({ }, 2, function (c) c:kill() end),
50 awful.button({ }, 3, function ()
51 if instance then
52 instance:hide()
53 instance = nil
54 else
55 instance = awful.menu.clients({ width=250 })
56 end
57 end),
58 awful.button({ }, 4, function ()
59 awful.client.focus.byidx(1)
60 if client.focus then client.focus:raise() end
61 end),
62 awful.button({ }, 5, function ()
63 awful.client.focus.byidx(-1)
64 if client.focus then client.focus:raise() end
65 end))
66
67
68 for s = 1, screen.count() do
69 -- Create a promptbox for each screen
70 mypromptbox[s] = awful.widget.prompt()
71 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
72 -- We need one layoutbox per screen.
73 mylayoutbox[s] = awful.widget.layoutbox(s)
74 mylayoutbox[s]:buttons(awful.util.table.join(
75 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
76 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
77 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
78 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
79 -- Create a taglist widget
80 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
81
82 -- Create a tasklist widget
83 mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
84
85 -- Create the wibox
86 mywibox[s] = awful.wibox({ position = "top", screen = s })
87
88 -- Widgets that are aligned to the left
89 local left_layout = wibox.layout.fixed.horizontal()
90 left_layout:add(mylauncher)
91 left_layout:add(mytaglist[s])
92 left_layout:add(mypromptbox[s])
93
94 -- Widgets that are aligned to the right
95 local right_layout = wibox.layout.fixed.horizontal()
96 if s == 1 then right_layout:add(wibox.widget.systray()) end
97 right_layout:add(network_widget)
98 right_layout:add(volume_widget)
99 if utils.host == "chronos" then
100 right_layout:add(battery_widget)
101 end
102 right_layout:add(mytextclock)
103 right_layout:add(mylayoutbox[s])
104
105 -- Now bring it all together (with the tasklist in the middle)
106 local layout = wibox.layout.align.horizontal()
107 layout:set_left(left_layout)
108 layout:set_middle(mytasklist[s])
109 layout:set_right(right_layout)
110
111 mywibox[s]:set_widget(layout)
112 end
113 -- }}}