]> git.rmz.io Git - dotfiles.git/blob - awesome/rc.lua
add a shutdown menu
[dotfiles.git] / awesome / rc.lua
1 -- Standard awesome library
2 gears = require("gears")
3 awful = require("awful")
4 awful.rules = require("awful.rules")
5 require("awful.autofocus")
6 -- Widget and layout library
7 wibox = require("wibox")
8 -- Theme handling library
9 beautiful = require("beautiful")
10 -- Notification library
11 naughty = require("naughty")
12 menubar = require("menubar")
13 -- Pulseaudio widget
14 --local APW = require("apw/widget")
15
16 -- {{{ Error handling
17 -- Check if awesome encountered an error during startup and fell back to
18 -- another config (This code will only ever execute for the fallback config)
19 if awesome.startup_errors then
20 naughty.notify({ preset = naughty.config.presets.critical,
21 title = "Oops, there were errors during startup!",
22 text = awesome.startup_errors })
23 end
24
25 -- Handle runtime errors after startup
26 do
27 local in_error = false
28 awesome.connect_signal("debug::error", function (err)
29 -- Make sure we don't go into an endless error loop
30 if in_error then return end
31 in_error = true
32
33 naughty.notify({ preset = naughty.config.presets.critical,
34 title = "Oops, an error happened!",
35 text = err })
36 in_error = false
37 end)
38 end
39 -- }}}
40
41 -- {{{ Variable definitions
42 -- Themes define colours, icons, and wallpapers
43 beautiful.init("/usr/share/awesome/themes/default/theme.lua")
44
45 -- This is used later as the default terminal and editor to run.
46 terminal = "konsole"
47 editor = os.getenv("EDITOR") or "vim"
48 editor_cmd = terminal .. " -e " .. editor
49
50 -- Default modkey.
51 -- Usually, Mod4 is the key with a logo between Control and Alt.
52 -- If you do not like this or do not have such a key,
53 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
54 -- However, you can use another modifier like Mod1, but it may interact with others.
55 modkey = "Mod4"
56
57 -- Tags
58 require("tags")
59 -- }}}
60
61 -- {{{ Wallpaper
62 if beautiful.wallpaper then
63 for s = 1, screen.count() do
64 gears.wallpaper.maximized(beautiful.wallpaper, s, true)
65 end
66 end
67 -- }}}
68
69 -- {{{ Menu
70 -- Setup global menu keys
71 awful.menu.menu_keys.up = { "k", "Up"}
72 awful.menu.menu_keys.down = { "j", "Down"}
73 awful.menu.menu_keys.enter = { "l", "Right"}
74 awful.menu.menu_keys.back = { "h", "Left"}
75
76 -- Create a laucher widget and a main menu
77 myawesomemenu = {
78 { "manual", terminal .. " -e man awesome" },
79 { "edit config", editor_cmd .. " " .. awesome.conffile },
80 { "restart", awesome.restart },
81 { "quit", awesome.quit }
82 }
83
84 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
85 { "open terminal", terminal }
86 }
87 })
88
89 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
90 menu = mymainmenu })
91
92 myshutdownmenu = awful.menu({ items = { { "shutdown", "systemctl poweroff" },
93 { "restart", "systemctl restart" },
94 { "suspend", "systemctl suspend" },
95 }
96 })
97
98 -- Menubar configuration
99 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
100 -- }}}
101
102 -- {{{ Wibox
103 -- Create a textclock widget
104 mytextclock = awful.widget.textclock()
105
106 -- Create a wibox for each screen and add it
107 mywibox = {}
108 mypromptbox = {}
109 mylayoutbox = {}
110 mytaglist = {}
111 mytaglist.buttons = awful.util.table.join(
112 awful.button({ }, 1, awful.tag.viewonly),
113 awful.button({ modkey }, 1, awful.client.movetotag),
114 awful.button({ }, 3, awful.tag.viewtoggle),
115 awful.button({ modkey }, 3, awful.client.toggletag),
116 awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
117 awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
118 )
119 mytasklist = {}
120 mytasklist.buttons = awful.util.table.join(
121 awful.button({ }, 1, function (c)
122 if c == client.focus then
123 c.minimized = true
124 else
125 -- Without this, the following
126 -- :isvisible() makes no sense
127 c.minimized = false
128 if not c:isvisible() then
129 awful.tag.viewonly(c:tags()[1])
130 end
131 -- This will also un-minimize
132 -- the client, if needed
133 client.focus = c
134 c:raise()
135 end
136 end),
137 awful.button({ }, 2, function (c) c:kill() end),
138 awful.button({ }, 3, function ()
139 if instance then
140 instance:hide()
141 instance = nil
142 else
143 instance = awful.menu.clients({ width=250 })
144 end
145 end),
146 awful.button({ }, 4, function ()
147 awful.client.focus.byidx(1)
148 if client.focus then client.focus:raise() end
149 end),
150 awful.button({ }, 5, function ()
151 awful.client.focus.byidx(-1)
152 if client.focus then client.focus:raise() end
153 end))
154
155 for s = 1, screen.count() do
156 -- Create a promptbox for each screen
157 mypromptbox[s] = awful.widget.prompt()
158 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
159 -- We need one layoutbox per screen.
160 mylayoutbox[s] = awful.widget.layoutbox(s)
161 mylayoutbox[s]:buttons(awful.util.table.join(
162 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
163 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
164 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
165 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
166 -- Create a taglist widget
167 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
168
169 -- Create a tasklist widget
170 mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
171
172 -- Create the wibox
173 mywibox[s] = awful.wibox({ position = "top", screen = s })
174
175 -- Widgets that are aligned to the left
176 local left_layout = wibox.layout.fixed.horizontal()
177 left_layout:add(mylauncher)
178 left_layout:add(mytaglist[s])
179 left_layout:add(mypromptbox[s])
180
181 -- Widgets that are aligned to the right
182 local right_layout = wibox.layout.fixed.horizontal()
183 if s == 1 then right_layout:add(wibox.widget.systray()) end
184 --right_layout:add(APW)
185 right_layout:add(mytextclock)
186 right_layout:add(mylayoutbox[s])
187
188 -- Now bring it all together (with the tasklist in the middle)
189 local layout = wibox.layout.align.horizontal()
190 layout:set_left(left_layout)
191 layout:set_middle(mytasklist[s])
192 layout:set_right(right_layout)
193
194 mywibox[s]:set_widget(layout)
195 end
196 -- }}}
197
198 -- Mouse/Key Bindings
199 require("bindings")
200
201 -- Rules
202 require("rules")
203
204 -- {{{ Signals
205 -- Signal function to execute when a new client appears.
206 client.connect_signal("manage", function (c, startup)
207 -- Enable sloppy focus
208 c:connect_signal("mouse::enter", function(c)
209 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
210 and awful.client.focus.filter(c) then
211 client.focus = c
212 end
213 end)
214
215 if not startup then
216 -- Set the windows at the slave,
217 -- i.e. put it at the end of others instead of setting it master.
218 -- awful.client.setslave(c)
219
220 -- Put windows in a smart way, only if they does not set an initial position.
221 if not c.size_hints.user_position and not c.size_hints.program_position then
222 awful.placement.no_overlap(c)
223 awful.placement.no_offscreen(c)
224 end
225 end
226 end)
227
228 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
229 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
230 -- }}}
231
232 -- {{{ Autostart applications
233 require("autostart")
234 -- }}}