forked from kdwinter/awesome-configs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc.lua
394 lines (344 loc) · 15.2 KB
/
rc.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
-------------------------------------------------------------------------------
-- @file awesomerc.lua
-- @author Gigamo <gigamo@gmail.com>
-------------------------------------------------------------------------------
-- {{{1 Tables
local tags = { }
local statusbar = { }
local promptbox = { }
local taglist = { }
local layoutbox = { }
local settings = { }
-- {{{1 Imports
require('awful')
require('awful.autofocus')
require('awful.rules')
require('beautiful')
require('naughty')
require('debian.menu')
-- Load theme
beautiful.init(awful.util.getdir('config')..'/zenburn.lua')
-- {{{1 Variables
settings.modkey = 'Mod4'
settings.term = 'gnome-terminal'
settings.explorer = 'marlin'
settings.browser = 'google-chrome'
settings.editor_cmd = 'gedit'
settings.layouts =
{
awful.layout.suit.tile,
awful.layout.suit.tile.bottom,
awful.layout.suit.max
-- awful.layout.suit.magnifier,
-- awful.layout.suit.floating
}
mytasklist = {}
mytasklist.buttons = awful.util.table.join(
awful.button({ }, 1, function (c)
if c == client.focus then
c.minimized = true
else
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
-- This will also un-minimize
-- the client, if needed
client.focus = c
c:raise()
end
end),
awful.button({ }, 3, function ()
if instance then
instance:hide()
instance = nil
else
instance = awful.menu.clients({ width=250 })
end
end),
awful.button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
awful.button({ }, 5, function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end))
-- {{{1 Tags
--tags.settings = {
-- { name = '1', layout = settings.layouts[1] },
-- { name = '2', layout = settings.layouts[3] },
-- { name = '3', layout = settings.layouts[1] },
-- { name = '4', layout = settings.layouts[1], mwfact = 0.13 },
-- { name = '5', layout = settings.layouts[5] },
--}
--for s = 1, screen.count() do
-- tags[s] = {}
-- for i, v in ipairs(tags.settings) do
-- tags[s][i] = tag({ name = v.name })
-- tags[s][i].screen = s
-- awful.tag.setproperty(tags[s][i], 'layout', v.layout)
-- awful.tag.setproperty(tags[s][i], 'mwfact', v.mwfact)
-- awful.tag.setproperty(tags[s][i], 'hide', v.hide)
-- end
-- tags[s][1].selected = true
--end
tags = {}
for s = 1, screen.count() do
-- Each screen has its own tag table.
tags[s] = awful.tag({ 1, 2, 3, 4, 5 }, s, settings.layouts[1])
end
-- {{{1 Menu
-- Create a launcher widget and a main menu
myawesomemenu = {
-- { "manual", settings.term .. " -e man awesome" },
{ "edit config", settings.editor_cmd .. " " .. awesome.conffile },
{ "home screens", "/bin/sh /home/craig/.screenlayout/Home.sh" },
{ "work screens", "/bin/sh /home/craig/.screenlayout/WorkDesk.sh" },
{ "restart", awesome.restart },
{ "quit", awesome.quit }
}
mymainmenu = awful.menu.new({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
{ "Debian", debian.menu.Debian_menu.Debian },
{ "open terminal", settings.term }
}
})
mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
menu = mymainmenu })
-- {{{1 Widgets
systray = widget({ type = 'systray' })
thermalwidget = widget({ type = 'textbox', name = 'thermalwidget' })
memwidget = widget({ type = 'textbox', name = 'memwidget' })
batwidget = widget({ type = 'textbox', name = 'batwidget' })
clockwidget = awful.widget.textclock({ align = 'right' })
taglist.buttons = awful.util.table.join(
awful.button({ }, 1, awful.tag.viewonly),
awful.button({ }, 3, awful.tag.viewtoggle),
awful.button({ settings.modkey }, 1, awful.client.movetotag),
awful.button({ settings.modkey }, 3, awful.client.toggletag)
)
for s = 1, screen.count() do
promptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
layoutbox[s] = awful.widget.layoutbox(s)
layoutbox[s]:buttons(awful.util.table.join(
awful.button({ }, 1, function () awful.layout.inc(settings.layouts, 1) end),
awful.button({ }, 3, function () awful.layout.inc(settings.layouts, -1) end)
))
taglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, taglist.buttons)
mytasklist[s] = awful.widget.tasklist(function(c)
return awful.widget.tasklist.label.currenttags(c, s)
end, mytasklist.buttons)
statusbar[s] = awful.wibox(
{
position = 'top',
height = '14',
fg = beautiful.fg_normal,
bg = beautiful.bg_normal,
screen = s
})
statusbar[s].widgets =
{
{
mylauncher,
taglist[s],
layoutbox[s],
promptbox[s],
layout = awful.widget.layout.horizontal.leftright
},
systray,
clockwidget,
batwidget,
memwidget,
-- thermalwidget,
mytasklist[s],
layout = awful.widget.layout.horizontal.rightleft
}
end
-- {{{1 Binds
root.buttons(awful.util.table.join(
awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev)
))
local globalkeys = awful.util.table.join(
awful.key({ settings.modkey }, 'Left', awful.tag.viewprev),
awful.key({ settings.modkey }, 'Right', awful.tag.viewnext),
awful.key({ settings.modkey, }, 'Escape',awful.tag.history.restore),
awful.key({ settings.modkey }, 'x', function () awful.util.spawn(settings.term) end),
awful.key({ settings.modkey }, 'f', function () awful.util.spawn(settings.browser) end),
awful.key({ settings.modkey }, 'e', function () awful.util.spawn(settings.explorer) end),
awful.key({ settings.modkey, 'Control' }, 'r', awesome.restart),
awful.key({ settings.modkey, 'Shift' }, 'q', awesome.quit),
awful.key({ settings.modkey, }, 'j', function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
awful.key({ settings.modkey, }, 'k', function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
awful.key({ settings.modkey, 'Shift' }, 'j', function () awful.client.swap.byidx(1) end),
awful.key({ settings.modkey, 'Shift' }, 'k', function () awful.client.swap.byidx(-1) end),
awful.key({ settings.modkey, 'Control' }, 'j', function () awful.screen.focus_relative(1) end),
awful.key({ settings.modkey, 'Control' }, 'k', function () awful.screen.focus_relative(-1) end),
awful.key({ settings.modkey, }, 'u', awful.client.urgent.jumpto),
awful.key({ settings.modkey, }, 'Tab', function ()
awful.client.focus.history.previous()
if client.focus then client.focus:raise() end
end),
awful.key({ settings.modkey }, 'l', function () awful.tag.incmwfact(0.025) end),
awful.key({ settings.modkey }, 'h', function () awful.tag.incmwfact(-0.025) end),
awful.key({ settings.modkey, 'Shift' }, 'h', function () awful.client.incwfact(0.05) end),
awful.key({ settings.modkey, 'Shift' }, 'l', function () awful.client.incwfact(-0.05) end),
awful.key({ settings.modkey, 'Control' }, 'h', function () awful.tag.incnmaster(1) end),
awful.key({ settings.modkey, 'Control' }, 'l', function () awful.tag.incnmaster(-1) end),
awful.key({ settings.modkey }, 'space', function () awful.layout.inc(settings.layouts, 1) end),
awful.key({ settings.modkey, 'Shift' }, 'space', function () awful.layout.inc(settings.layouts, -1) end),
awful.key({ settings.modkey }, 'r', function () promptbox[mouse.screen]:run() end),
awful.key({ settings.modkey }, 'F12', function () awful.util.spawn("xlock") end),
awful.key({ }, '#121', function () awful.util.spawn_with_shell('dvol -t') end),
awful.key({ }, '#122', function () awful.util.spawn_with_shell('dvol -d 2') end),
awful.key({ }, '#123', function () awful.util.spawn_with_shell('dvol -i 2') end)
)
local clientkeys = awful.util.table.join(
awful.key({ settings.modkey }, 'c', function (c) c:kill() end),
awful.key({ settings.modkey, }, "o", awful.client.movetoscreen),
awful.key({ settings.modkey, 'Control' }, 'space', awful.client.floating.toggle),
awful.key({ settings.modkey, 'Shift' }, 'r', function (c) c:redraw() end),
awful.key({ settings.modkey }, 't', awful.client.togglemarked),
awful.key({ settings.modkey }, 'm', function (c)
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
end)
)
-- Compute the maximum number of digit we need, limited to 9
keynumber = 0
for s = 1, screen.count() do
keynumber = math.min(9, math.max(#tags[s], keynumber));
end
-- Bind all key numbers to tags.
-- Be careful: we use keycodes to make it works on any keyboard layout.
-- This should map on the top row of your keyboard, usually 1 to 9.
for i = 1, keynumber do
globalkeys = awful.util.table.join(globalkeys,
awful.key({ settings.modkey }, '#' .. i + 9, function ()
local screen = mouse.screen
if tags[screen][i] then
awful.tag.viewonly(tags[screen][i])
end
end),
awful.key({ settings.modkey, 'Control' }, '#' .. i + 9, function ()
local screen = mouse.screen
if tags[screen][i] then
awful.tag.viewtoggle(tags[screen][i])
end
end),
awful.key({ settings.modkey, 'Shift' }, '#' .. i + 9, function ()
if client.focus and tags[client.focus.screen][i] then
awful.client.movetotag(tags[client.focus.screen][i])
end
end),
awful.key({ settings.modkey, 'Control', 'Shift' }, '#' .. i + 9, function ()
if client.focus and tags[client.focus.screen][i] then
awful.client.toggletag(tags[client.focus.screen][i])
end
end)
)
end
local clientbuttons = awful.util.table.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ settings.modkey }, 1, awful.mouse.client.move),
awful.button({ settings.modkey }, 3, awful.mouse.client.resize)
)
root.keys(globalkeys)
-- {{{1 Signals
client.add_signal('manage', function (c, startup)
-- Enable sloppy focus
c:add_signal('mouse::enter', function (c)
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
and awful.client.focus.filter(c) then
client.focus = c
end
end)
if not startup then
awful.client.setslave(c)
awful.placement.no_overlap(c)
awful.placement.no_offscreen(c)
end
c.size_hints_honor = false
end)
awful.rules.rules = {
-- All clients will match this rule.
{ rule = { },
properties = { border_width = beautiful.border_width,
border_color = beautiful.border_normal,
focus = true,
keys = clientkeys,
buttons = clientbuttons } },
}
client.add_signal('focus', function(c) c.border_color = beautiful.border_focus end)
client.add_signal('unfocus', function(c) c.border_color = beautiful.border_normal end)
-- {{{1 Functions
function battery(id)
-- Ugly long HAL string
hal = io.popen('hal-get-property --udi /org/freedesktop/Hal/devices/computer_power_supply_battery_'..id..' --key battery.charge_level.percentage')
pwr = io.popen('hal-get-property --udi /org/freedesktop/Hal/devices/computer_power_supply_battery_'..id..' --key battery.rechargeable.is_charging')
if hal then
charge = hal:read('*all')
hal:close()
end
if pwr then
power = pwr:read('*all')
pwr:close()
if power:match('true') then
crm_indicator = ' ^'
else
crm_indicator = ' v'
end
end
return charge:gsub("\n", '')..'%'.. crm_indicator .. ' |'
end
function memory()
local memfile = io.open('/proc/meminfo')
if memfile then
for line in memfile:lines() do
if line:match("^MemTotal.*") then
mem_total = math.floor(tonumber(line:match("(%d+)")) / 1024)
elseif line:match("^MemFree.*") then
mem_free = math.floor(tonumber(line:match("(%d+)")) / 1024)
elseif line:match("^Buffers.*") then
mem_buffers = math.floor(tonumber(line:match("(%d+)")) / 1024)
elseif line:match("^Cached.*") then
mem_cached = math.floor(tonumber(line:match("(%d+)")) / 1024)
end
end
memfile:close()
end
local mem_in_use = mem_total - (mem_free + mem_buffers + mem_cached)
local mem_usage_percentage = math.floor(mem_in_use / mem_total * 100)
return mem_in_use..'Mb'..' | '
end
function thermal()
local temperature, howmany = 0, 0
local sensors = io.popen('sensors')
if sensors then
for line in sensors:lines() do
if line:match(':%s+%+([.%d]+)') then
howmany = howmany + 1
temperature = temperature + tonumber(line:match(':%s+%+([.%d]+)'))
end
end
sensors:close()
end
temperature = temperature / howmany
return temperature..'°C'..' | '
end
-- {{{1 Timers
battimer = timer { timeout = 30 }
battimer:add_signal('timeout', function() batwidget.text = battery('BAT1') end)
battimer:start()
memtimer = timer { timeout = 15 }
memtimer:add_signal('timeout', function() memwidget.text = memory() end)
memtimer:start()
thermaltimer = timer { timeout = 10 }
thermaltimer:add_signal('timeout', function() thermalwidget.text = thermal() end)
thermaltimer:start()
io.stderr:write("\n\rAwesome loaded at "..os.date('%B %d, %H:%M').."\r\n\n")