-
Notifications
You must be signed in to change notification settings - Fork 1
/
clients.lua
301 lines (259 loc) · 8.05 KB
/
clients.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
-------------------------------------------------------------
-- 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 wibox = require("wibox")
local beautiful = require("beautiful") -- Theme handling library
local _t = gears.table or awful.util.table -- 4.{0,1} compatibility
-- {{{ Actions
-- No border for maximized clients
function getClientSuitableBorder(c)
local border = {
width = c.border_width,
color = c.border_color,
}
if c.maximized then -- no borders if only 1 client visible
border.width = 0
elseif #awful.screen.focused().clients > 1 then
border.width = beautiful.border_width
border.color = beautiful.border_focus
end
return border
end
-- }}}
-- {{{ Key bindings
local function newKeyBindings(modkey)
local keys = _t.join(
awful.key({ modkey, }, "f",
function (c)
c.fullscreen = not c.fullscreen
c:raise()
end,
{description = "toggle fullscreen", group = "client"}
),
awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end,
{description = "close", group = "client"}
),
awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle,
{description = "toggle floating", group = "client"}
),
awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end,
{description = "move to master", group = "client"}
),
awful.key({ modkey, }, "o", function (c) c:move_to_screen() end,
{description = "move to screen", group = "client"}
),
awful.key({ modkey, }, "t", function (c)
c.ontop = not c.ontop
end,
{description = "toggle keep on top", group = "client"}
),
awful.key({ modkey, }, "n",
function (c)
-- The client currently has the input focus, so it cannot be
-- minimized, since minimized clients can't have the focus.
c.minimized = true
end ,
{description = "minimize", group = "client"}
),
-- Size change
awful.key({ modkey, }, "m",
function (c)
c.maximized = not c.maximized
c:raise()
end ,
{description = "(un)maximize", group = "client"}
),
awful.key({ modkey, "Control" }, "m",
function (c)
c.maximized_vertical = not c.maximized_vertical
c:raise()
end ,
{description = "(un)maximize vertically", group = "client"}
),
awful.key({ modkey, "Shift" }, "m",
function (c)
c.maximized_horizontal = not c.maximized_horizontal
c:raise()
end ,
{description = "(un)maximize horizontally", group = "client"}
)
)
return keys
end
-- }}}
-- {{{ Mouse bindings
local function newMouseBindings(modkey)
local buttons = _t.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize)
)
return buttons
end
-- }}}
-- {{{ Rules
-- Rules to apply to new clients (through the "manage" signal).
local function newRules(keys, buttons)
local 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 = keys,
buttons = buttons,
screen = awful.screen.preferred,
placement = awful.placement.no_overlap+awful.placement.no_offscreen
}
},
-- Floating clients.
{
rule_any = {
instance = {
"DTA", -- Firefox addon DownThemAll.
"copyq", -- Includes session name in class.
},
class = {
"Arandr",
"Gpick",
"Kruler",
"MessageWin", -- kalarm.
"Sxiv",
"Wpa_gui",
"pinentry",
"veromix",
"xtightvncviewer"
},
name = {
"Event Tester", -- xev.
},
role = {
"AlarmWindow", -- Thunderbird's calendar.
"pop-up", -- e.g. Google Chrome's (detached) Developer Tools.
}
},
properties = { floating = true }
},
-- Add titlebars to normal clients and dialogs
{
rule_any = {type = { "normal", "dialog" }},
properties = { titlebars_enabled = true }
},
-- Set Firefox to always map on the tag named "2" on screen 1.
-- { rule = { class = "Firefox" },
-- properties = { screen = 1, tag = "2" } },
}
return rules
end
-- }}}
-- {{{ Signals
-- Signal function to execute when a new client appears.
local function sigManage(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
-- Add a titlebar if titlebars_enabled is set to true in the rules.
local function sigRequestTitlebars(c)
-- buttons for the titlebar
local buttons = _t.join(
-- Left mouse button: move
awful.button({}, 1, function()
client.focus = c
c:raise()
awful.mouse.client.move(c)
end),
-- Middle mouse button: move
awful.button({}, 2, function()
c:kill()
end),
-- Right mouse button: resize
awful.button({}, 3, function()
client.focus = c
c:raise()
awful.mouse.client.resize(c)
end),
-- Mouse wheel up: increase opacity
awful.button({}, 4, function()
end),
-- Mouse wheel down: decrease opacity
awful.button({}, 5, function()
end)
)
awful.titlebar(c, {size = 16}):setup({
{ -- Left
awful.titlebar.widget.iconwidget(c),
buttons = buttons,
layout = wibox.layout.fixed.horizontal
},
{ -- Middle
{ -- Title
align = "center",
widget = awful.titlebar.widget.titlewidget(c)
},
buttons = buttons,
layout = wibox.layout.flex.horizontal
},
{ -- Right
awful.titlebar.widget.floatingbutton(c),
awful.titlebar.widget.maximizedbutton(c),
awful.titlebar.widget.stickybutton(c),
awful.titlebar.widget.ontopbutton(c),
awful.titlebar.widget.closebutton(c),
layout = wibox.layout.fixed.horizontal()
},
layout = wibox.layout.align.horizontal
})
end
-- Enable sloppy focus, so that focus follows mouse.
local function sigMouseEnter(c)
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
and awful.client.focus.filter(c) then
client.focus = c
end
end
local function sigPropertyMaximized(c)
local border = getClientSuitableBorder(c)
c.border_width = border.width
c.border_color = border.color
end
local function sigFocus(c)
local border = getClientSuitableBorder(c)
c.border_width = border.width
c.border_color = beautiful.border_focus
end
local function sigUnfocus(c)
c.border_color = beautiful.border_normal
end
-- }}}
local function setup(config)
require("awful.autofocus")
local keys = newKeyBindings(config.mod)
local buttons = newMouseBindings(config.mod)
awful.rules.rules = newRules(keys, buttons)
client.connect_signal("focus", sigFocus)
client.connect_signal("manage", sigManage)
client.connect_signal("unfocus", sigUnfocus)
client.connect_signal("mouse::enter", sigMouseEnter)
client.connect_signal("property:maximized", sigPropertyMaximized)
client.connect_signal("request::titlebars", sigRequestTitlebars)
end
return {
Setup = setup;
}
-- vim: foldmethod=marker:filetype=lua:expandtab:shiftwidth=2:tabstop=2:softtabstop=2:textwidth=80