refactor: validate_mb_bindings
This commit is contained in:
parent
5daa4de136
commit
e1fd60f264
34
init.lua
34
init.lua
|
@ -35,7 +35,6 @@ local math = math
|
|||
local max = math.max
|
||||
local abs = math.abs
|
||||
local pairs = pairs
|
||||
local ipairs = ipairs
|
||||
|
||||
-- ------------------------------------------------------------
|
||||
|
||||
|
@ -517,37 +516,6 @@ function nice.add_window_decoration(c)
|
|||
collectgarbage "collect"
|
||||
end
|
||||
|
||||
local function validate_mb_bindings()
|
||||
local action_mbs = {
|
||||
"mb_move",
|
||||
"mb_contextmenu",
|
||||
"mb_resize",
|
||||
"mb_win_shade_rollup",
|
||||
"mb_win_shade_rolldown",
|
||||
}
|
||||
local mb_specified = { false, false, false, false, false }
|
||||
local mb
|
||||
local mb_conflict_test
|
||||
for _, action_mb in ipairs(action_mbs) do
|
||||
mb = _private[action_mb]
|
||||
if mb then
|
||||
assert(mb >= 1 and mb <= 5, "Invalid mouse button specified!")
|
||||
mb_conflict_test = mb_specified[mb]
|
||||
if not mb_conflict_test then
|
||||
mb_specified[mb] = action_mb
|
||||
else
|
||||
error(
|
||||
|
||||
("%s and %s can not be bound to the same mouse button"):format(
|
||||
action_mb,
|
||||
mb_conflict_test
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function nice.apply_client_shape(c)
|
||||
c.shape = shapes.rounded_rect {
|
||||
tl = _private.titlebar_radius,
|
||||
|
@ -577,7 +545,7 @@ function nice.initialize(args)
|
|||
end
|
||||
end
|
||||
|
||||
validate_mb_bindings()
|
||||
utils.validate_mb_bindings(_private)
|
||||
|
||||
_G.client.connect_signal("request::titlebars", function(c)
|
||||
-- Callback
|
||||
|
|
33
utils.lua
33
utils.lua
|
@ -5,7 +5,6 @@ local widgets = require "awesome-wm-nice.widgets"
|
|||
local wlayout_fixed = require "wibox.layout.fixed"
|
||||
|
||||
local gdk = lgi.require("Gdk", "3.0")
|
||||
local floor = math.floor
|
||||
|
||||
local utils = {}
|
||||
|
||||
|
@ -45,7 +44,7 @@ function utils.get_dominant_color(client)
|
|||
local cgeo = client:geometry()
|
||||
local x_offset = 2
|
||||
local y_offset = 2
|
||||
local x_lim = floor(cgeo.width / 2)
|
||||
local x_lim = math.floor(cgeo.width / 2)
|
||||
for x_pos = 0, x_lim, 2 do
|
||||
for y_pos = 0, 8, 1 do
|
||||
pb = gdk.pixbuf_get_from_surface(
|
||||
|
@ -136,4 +135,34 @@ function utils.create_titlebar_items(c, group)
|
|||
return titlebar_group_items
|
||||
end
|
||||
|
||||
function utils.validate_mb_bindings(private)
|
||||
local action_mbs = {
|
||||
"mb_move",
|
||||
"mb_contextmenu",
|
||||
"mb_resize",
|
||||
"mb_win_shade_rollup",
|
||||
"mb_win_shade_rolldown",
|
||||
}
|
||||
local mb_specified = { false, false, false, false, false }
|
||||
local mb
|
||||
local mb_conflict_test
|
||||
for _, action_mb in ipairs(action_mbs) do
|
||||
mb = private[action_mb]
|
||||
if mb then
|
||||
assert(mb >= 1 and mb <= 5, "Invalid mouse button specified!")
|
||||
mb_conflict_test = mb_specified[mb]
|
||||
if not mb_conflict_test then
|
||||
mb_specified[mb] = action_mb
|
||||
else
|
||||
error(
|
||||
("%s and %s can not be bound to the same mouse button"):format(
|
||||
action_mb,
|
||||
mb_conflict_test
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return utils
|
||||
|
|
Loading…
Reference in New Issue