-
Notifications
You must be signed in to change notification settings - Fork 1
/
screens.lua
340 lines (296 loc) · 8.95 KB
/
screens.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
-------------------------------------------------------------
-- Carrot clients key bindings and rules
-------------------------------------------------------------
-- Copyright (c) 2018 Pouyan Heyratpour <[email protected]>
-- Licensed under the GNU General Public License v3:
-- https://opensource.org/licenses/GPL-3.0
-------------------------------------------------------------
local gears = require("gears")
local awful = require("awful")
local beautiful = require("beautiful") -- Theme handling library
local wibox = require("wibox") -- Widget and layout library
local lain = require("lain")
local vicious = require("vicious") -- Vicious Widgets
local freedesktop = require("freedesktop") -- Freedesktop.org menu and desktop icons support for Awesome WM
local _t = gears.table or awful.util.table -- 4.{0,1} compatibility
local markup = lain.util.markup
-- {{{ Actions
local function toggleClientMenu()
local instance = nil
return function ()
if instance and instance.wibox.visible then
instance:hide()
instance = nil
else
instance = awful.menu.clients({theme = {width = 250}})
end
end
end
local function setScreenWallpaper(s)
-- Wallpaper
if beautiful.wallpaper then
local wallpaper = beautiful.wallpaper
-- If wallpaper is a function, call it with the screen
if type(wallpaper) == "function" then
wallpaper = wallpaper(s)
end
gears.wallpaper.maximized(wallpaper, s, true)
end
end
-- }}}
-- {{{ Layouts Setup
local function setupLayouts()
awful.layout.layouts = {
awful.layout.suit.floating,
awful.layout.suit.tile,
awful.layout.suit.tile.left,
awful.layout.suit.tile.bottom,
awful.layout.suit.tile.top,
awful.layout.suit.fair,
awful.layout.suit.fair.horizontal,
awful.layout.suit.spiral,
awful.layout.suit.spiral.dwindle,
awful.layout.suit.max,
awful.layout.suit.max.fullscreen,
awful.layout.suit.magnifier,
awful.layout.suit.corner.nw,
awful.layout.suit.corner.ne,
awful.layout.suit.corner.sw,
awful.layout.suit.corner.se,
lain.layout.cascade,
lain.layout.cascade.tile,
lain.layout.centerwork,
lain.layout.centerwork.horizontal,
lain.layout.termfair,
lain.layout.termfair.center,
}
-- Table of layouts to cover with awful.layout.inc, order matters.
lain.layout.termfair.nmaster = 3
lain.layout.termfair.ncol = 1
lain.layout.termfair.center.nmaster = 3
lain.layout.termfair.center.ncol = 1
lain.layout.cascade.tile.offset_x = 2
lain.layout.cascade.tile.offset_y = 32
lain.layout.cascade.tile.extra_padding = 5
lain.layout.cascade.tile.nmaster = 5
lain.layout.cascade.tile.ncol = 2
end
-- }}}
-- {{{ Screen Setup
-- Screen builder
local function newScreenBuilder(tags, apps, builders)
-- Create a wibox for each screen and add it
return (function(s)
-- Each screen has its own tag table.
awful.tag(tags, s, awful.layout.layouts[1])
-- Unique per screen
s.mytaglist = builders.taglist(s)
s.mypromptbox = builders.promptbox(s)
s.mytasklist = builders.tasklist(s)
s.mylayoutbox = builders.layoutbox(s)
-- Common between screens
local mylauncher = builders.launcher(s)
local mykeyboardlayout = builders.kbdlayout(s)
local mybattery = builders.battery(s)
local mysystray = builders.systray(s)
local mytextclock = builders.clock(s)
-- Create the top wibox
s.mywibox = awful.wibar({
position = "top",
screen = s,
})
-- Add widgets to the wibox
s.mywibox:setup({
layout = wibox.layout.align.horizontal,
{ -- Left widgets
layout = wibox.layout.fixed.horizontal,
mylauncher,
s.mytaglist,
s.mypromptbox,
},
s.mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
mysystray,
mykeyboardlayout,
mybattery,
mytextclock,
s.mylayoutbox,
},
})
-- Wallpaper
setScreenWallpaper(s)
-- Quake application
s.quake = lain.util.quake({ app = apps.terminal })
-- Let theme create wibox
-- beautiful.at_screen_connect(s)
end)
end
-- }}}
-- {{{ Widgets Builders
-- Launcher
local function newLauncherBuilder(menu)
return (function(s)
local launcher = awful.widget.launcher({
image = beautiful.awesome_icon or (awesome.icon_path .. "/awesome16.png"),
menu = menu,
})
return launcher
end)
end
-- Taglist
local function newTaglistBuilder(modkey)
local buttons = _t.join(
awful.button({}, 1, function(t)
t:view_only()
end),
awful.button({modkey}, 1, function(t)
if client.focus then
client.focus:move_to_tag(t)
end
end),
awful.button({}, 3, awful.tag.viewtoggle),
awful.button({modkey}, 3, function(t)
if client.focus then
client.focus:toggle_tag(t)
end
end),
awful.button({}, 4, function(t) awful.tag.viewnext(t.screen) end),
awful.button({}, 5, function(t) awful.tag.viewprev(t.screen) end)
)
return (function(s)
return awful.widget.taglist(s, awful.widget.taglist.filter.all, buttons)
end)
end
-- Promptbox
local function newPromptboxBuilder()
return (function(s)
return awful.widget.prompt()
end)
end
-- Tasklist
local function newTasklistBuilder()
local buttons = _t.join(
-- Left mouse button: minimize/restore
awful.button({}, 1, function (c)
if c == client.focus then
c.minimized = true
else
-- Without this, the following
-- :isvisible() makes no sense
c.minimized = false
if not c:isvisible() and c.first_tag then
c.first_tag:view_only()
end
-- This will also un-minimize
-- the client, if needed
client.focus = c
c:raise()
end
end),
-- Middle mouse button: quit
awful.button({}, 2, function (c)
c:kill()
end),
-- Right mouse button: client menu
awful.button({}, 3, toggleClientMenu),
-- Mouse wheel up: next client in current tag
awful.button({}, 4, function ()
awful.client.focus.byidx(1)
end),
-- Mouse wheel down: previouse client in current tag
awful.button({}, 5, function ()
awful.client.focus.byidx(-1)
end)
)
return (function(s)
return awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, buttons)
end)
end
-- Keyboard map indicator and switcher
local function newKeyboardLayoutBuilder()
return (function(s)
return awful.widget.keyboardlayout()
end)
end
-- Battery status indicator
local function newBatteryBuilder()
return (function(s)
local battery = lain.widget.bat({
settings = (function()
local perc = bat_now.perc ~= "N/A" and bat_now.perc .. "%" or bat_now.perc
if bat_now.ac_status == 1 then
perc = perc .. " plug"
end
widget:set_markup(markup.fontfg(beautiful.font, "#aaaaaa", perc .. " "))
end)
})
return battery.widget
end)
end
-- Systray
local function newSystrayBuilder()
return (function(s)
return wibox.widget.systray()
end)
end
-- Create a textclock widget
local function newClockBuilder()
return (function(s)
local clock = wibox.widget.textclock(markup("#7788af", "%A %d %B ") .. markup("#ab7367", ">") .. markup("#de5e1e", " %H:%M "))
-- Calendar
clock.calendar = lain.widget.cal({
attach_to = { clock },
notification_preset = {
font = beautiful.font,
-- fg = theme.fg_normal,
-- bg = theme.bg_normal,
fg = "#aaaaaa",
bg = "#000000",
}
})
return clock
end)
end
-- Layoutbox
local function newLayoutboxBuilder()
local buttons = _t.join(
awful.button({}, 1, function () awful.layout.inc(1) end),
awful.button({}, 3, function () awful.layout.inc(-1) end),
awful.button({}, 4, function () awful.layout.inc(1) end),
awful.button({}, 5, function () awful.layout.inc(-1) end)
)
return (function(s)
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen.
local lb = awful.widget.layoutbox(s)
lb:buttons(buttons)
return lb
end)
end
-- }}}
local function setup(config, menu)
-- Layouts
setupLayouts()
awful.util.tagnames = config.tags
-- Builders
local builders = {
launcher = newLauncherBuilder(menu);
taglist = newTaglistBuilder(config.mod);
promptbox = newPromptboxBuilder();
tasklist = newTasklistBuilder();
kbdlayout = newKeyboardLayoutBuilder();
battery = newBatteryBuilder();
systray = newSystrayBuilder();
clock = newClockBuilder();
layoutbox = newLayoutboxBuilder();
}
local screenBuilder = newScreenBuilder(config.tags, config.apps, builders)
-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
screen.connect_signal("property::geometry", setScreenWallpaper)
awful.screen.connect_for_each_screen(screenBuilder)
end
return {
Setup = setup;
}
-- vim: foldmethod=marker:filetype=lua:expandtab:shiftwidth=2:tabstop=2:softtabstop=2:textwidth=80