From e1fd60f2642b7a37879002368bb930719440c3b4 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Tue, 28 Dec 2021 19:05:49 +0100 Subject: [PATCH] refactor: validate_mb_bindings --- init.lua | 34 +--------------------------------- utils.lua | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/init.lua b/init.lua index e592404..9ec2e66 100644 --- a/init.lua +++ b/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 diff --git a/utils.lua b/utils.lua index 0fede3d..cb65d4a 100644 --- a/utils.lua +++ b/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