-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrc.lua
316 lines (283 loc) · 9.79 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
-- AWESOMEWM/touchscreen
-- Copyright (C) 2019 Zaoqi <[email protected]>
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as published
-- by the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Affero General Public License for more details.
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
local gears = require("gears")
local awful = require("awful")
require("awful.autofocus")
local wibox = require("wibox")
local beautiful = require("beautiful")
local naughty = require("naughty")
local menubar = require("menubar")
local freedesktop = require("fdo")
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then
naughty.notify{
preset = naughty.config.presets.critical,
title = "Oops, there were errors during startup!",
text = awesome.startup_errors }
end
beautiful.init(gears.filesystem.get_themes_dir() .. "default/theme.lua")
beautiful.font = "sans 12"
beautiful.menu_height = beautiful.xresources.apply_dpi(20)
beautiful.menu_width = beautiful.xresources.apply_dpi(200)
local terminal = "x-terminal-emulator"
local editor = os.getenv("EDITOR") or "editor"
local editor_cmd = terminal .. " -e " .. editor
-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
awful.layout.suit.max,
}
local mykeyboardheight = 100
local mykeyboardbar = awful.wibar{ position = "bottom", visible = false, height = mykeyboardheight }
local mykeyboard = "xvkbd"
local function update_mykeyboard_height()
local w, h = root.size()
if w > h then
mykeyboardheight = h*0.27
else
mykeyboardheight = h*0.2
end
mykeyboardheight = math.floor(mykeyboardheight)
mykeyboardbar:remove()
mykeyboardbar = awful.wibar{ position = "bottom", visible = false, height = mykeyboardheight }
end
update_mykeyboard_height()
local function set_mykeyboard()
awful.spawn("xvkbd -no-keypad")
end
local function kill_mykeyboard()
for _, c in ipairs(client.get()) do
if c.instance == mykeyboard then
c:kill()
end
end
mykeyboardbar.visible = false
end
local function mykeyboard_running()
for _, c in ipairs(client.get()) do
if c.instance == mykeyboard then
return true
end
end
return false
end
screen.connect_signal("tag::history::update", function() if mykeyboard_running() then set_mykeyboard() end end)
local myawesomemenu = {
{ "manual", terminal .. " -e man awesome" },
{ "edit config", editor_cmd .. " " .. awesome.conffile },
{ "restart", awesome.restart },
{ "quit", function() awesome.quit() end}
}
local mymainmenu = freedesktop.menu.build{
before = {
{ "awesome", myawesomemenu, beautiful.awesome_icon }
},
after = {
{ "open terminal", terminal },
{ "keyboard", {
{ "on", set_mykeyboard },
{ "off", kill_mykeyboard }}},
}
}
local mylauncher = awful.widget.launcher{
image = beautiful.awesome_icon,
menu = mymainmenu }
menubar.utils.terminal = terminal
local mytextclock = wibox.widget.textclock("%H:%M")
-- Create a wibox for each screen and add it
local taglist_buttons = gears.table.join(
awful.button({ }, 1, function(t) t:view_only() end))
local tasklist_buttons = gears.table.join(
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))
local myclosebutton=awful.widget.button{ image = beautiful.titlebar_close_button_normal }
myclosebutton:buttons(gears.table.join(
awful.button({}, 1, nil, function()
local c = client.focus
if c then
c:kill()
end
end)
))
local function set_wallpaper(s)
if beautiful.wallpaper then
local wallpaper = beautiful.wallpaper
if type(wallpaper) == "function" then
wallpaper = wallpaper(s)
end
gears.wallpaper.maximized(wallpaper, s, true)
end
end
screen.connect_signal("property::geometry",
function(s)
update_mykeyboard_height()
if mykeyboard_running() then set_mykeyboard() end
set_wallpaper(s) end)
awful.screen.connect_for_each_screen(function(s)
set_wallpaper(s)
-- Each screen has its own tag table.
awful.tag({ "1", "2", "3", "4" }, s, awful.layout.layouts[1])
s.mypromptbox = awful.widget.prompt()
-- We need one layoutbox per screen.
s.mylayoutbox = awful.widget.layoutbox(s)
s.mylayoutbox:buttons(gears.table.join())
s.mytaglist = awful.widget.taglist(s, awful.widget.taglist.filter.all, taglist_buttons)
s.mytasklist = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, tasklist_buttons)
local rtwi, rtht = root.size()
local mywiht = math.floor(math.max(rtwi, rtht)*0.04)
s.mywibox = awful.wibar{ position = "top", screen = s, height = mywiht }
s.mywibox:setup {
layout = wibox.layout.align.horizontal,
{
layout = wibox.layout.fixed.horizontal,
mylauncher,
s.mytaglist,
s.mypromptbox,
},
s.mytasklist,
{
layout = wibox.layout.fixed.horizontal,
wibox.widget.systray(),
myclosebutton,
mytextclock,
},
}
end)
root.buttons(gears.table.join())
local globalkeys = gears.table.join()
local clientkeys = gears.table.join()
local clientbuttons = gears.table.join(
awful.button({ }, 1, function (c)
if c.instance == mykeyboard then
else
client.focus = c
end
c:raise()
end))
root.keys(globalkeys)
awful.rules.rules = {
-- All clients will match this rule.
{ rule = { },
properties = {
border_width = beautiful.border_width,
border_color = beautiful.border_normal,
focus = awful.client.focus.filter,
raise = true,
keys = clientkeys,
buttons = clientbuttons,
screen = awful.screen.preferred,
placement = awful.placement.no_overlap+awful.placement.no_offscreen
}
},
{ rule = { instance = mykeyboard },
properties = {
floating = true,
above = true,
skip_taskbar = true, },
callback = function(kb)
for _, c in ipairs(client.get()) do
if c.instance == mykeyboard and c ~= kb then
c:kill()
end
end
mykeyboardbar.visible = true
kb:geometry(mykeyboardbar:geometry())
end },
{ rule_any = { type = { "dialog" } },
properties = {
floating = true,
titlebars_enabled = true, },
callback = function(c)
local cg = c:geometry()
local s = awful.screen.focused()
local wg = s.workarea
if cg.x+cg.width > wg.x+wg.width or cg.y+cg.height > wg.y+wg.height then
c.floating = false
awful.titlebar.hide(c)
else
c.floating = true
awful.titlebar.show(c)
end
end },
}
client.connect_signal("manage", function (c)
-- Set the windows at the slave,
-- i.e. put it at the end of others instead of setting it master.
-- if not awesome.startup then awful.client.setslave(c) end
if awesome.startup and
not c.size_hints.user_position
and not c.size_hints.program_position then
-- Prevent clients from being unreachable after screen count changes.
awful.placement.no_offscreen(c)
end
end)
client.connect_signal("request::titlebars", function(c)
local buttons = gears.table.join(
awful.button({ }, 1, function()
if c.instance == mykeyboard then
else
client.focus = c
end
c:raise()
awful.mouse.client.move(c)
end),
awful.button({ }, 3, function()
client.focus = c
c:raise()
awful.mouse.client.resize(c)
end)
)
awful.titlebar(c) : setup {
{
awful.titlebar.widget.iconwidget(c),
buttons = buttons,
layout = wibox.layout.fixed.horizontal
},
{
{
align = "center",
widget = awful.titlebar.widget.titlewidget(c)
},
buttons = buttons,
layout = wibox.layout.flex.horizontal
},
{
awful.titlebar.widget.closebutton (c),
layout = wibox.layout.fixed.horizontal()
},
layout = wibox.layout.align.horizontal
}
end)
-- Enable sloppy focus, so that focus follows mouse.
client.connect_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)
client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)