Move helpers to one single place

This commit is contained in:
Grumph 2021-01-23 23:04:22 +01:00
parent 2ffdfc918c
commit d41e202b43
7 changed files with 74 additions and 55 deletions

34
helpers/client.lua Normal file
View File

@ -0,0 +1,34 @@
local awful = require("awful")
local _client = {}
--- Turn off passed client
-- Remove current tag from window's tags
--
-- @param c a client
function _client.turn_off(c)
local current_tag = awful.tag.selected(c.screen)
local ctags = {}
for k, tag in pairs(c:tags()) do
if tag ~= current_tag then table.insert(ctags, tag) end
end
c:tags(ctags)
end
--- Turn on passed client (add current tag to window's tags)
--
-- @param c A client
function _client.turn_on(c)
local current_tag = awful.tag.selected(c.screen)
ctags = {current_tag}
for k, tag in pairs(c:tags()) do
if tag ~= current_tag then table.insert(ctags, tag) end
end
c:tags(ctags)
c:raise()
client.focus = c
end
return _client

7
helpers/init.lua Normal file
View File

@ -0,0 +1,7 @@
return {
client = require(... .. ".client"),
color = require(... .. ".color"),
filesystem = require(... .. ".filesystem"),
shape = require(... .. ".shape"),
time = require(... .. ".time")
}

23
helpers/shape.lua Normal file
View File

@ -0,0 +1,23 @@
local gears = require("gears")
shape = {}
-- Create rounded rectangle shape (in one line)
function shape.rrect(radius)
return function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, radius)
end
end
-- Create partially rounded rect
function shape.prrect(radius, tl, tr, br, bl)
return function(cr, width, height)
gears.shape.partially_rounded_rect(cr, width, height, tl, tr, br, bl,
radius)
end
end
return shape

View File

@ -1,45 +0,0 @@
local awful = require("awful")
local gears = require("gears")
local helpers = {}
-- Turn off passed client (remove current tag from window's tags)
helpers.turn_off = function(c)
local current_tag = awful.tag.selected(c.screen)
local ctags = {}
for k, tag in pairs(c:tags()) do
if tag ~= current_tag then table.insert(ctags, tag) end
end
c:tags(ctags)
end
-- Turn on passed client
helpers.turn_on = function(c)
local current_tag = awful.tag.selected(c.screen)
ctags = {current_tag}
for k, tag in pairs(c:tags()) do
if tag ~= current_tag then table.insert(ctags, tag) end
end
c:tags(ctags)
c:raise()
client.focus = c
end
-- Create rounded rectangle shape (in one line)
helpers.rrect = function(radius)
return function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, radius)
end
end
-- Create partially rounded rect
helpers.prrect = function(radius, tl, tr, br, bl)
return function(cr, width, height)
gears.shape.partially_rounded_rect(cr, width, height, tl, tr, br, bl,
radius)
end
end
return helpers

View File

@ -14,7 +14,7 @@ local awful = require("awful")
local wibox = require("wibox")
local gears = require("gears")
local beautiful = require("beautiful")
local helpers = require(tostring(...):match(".*bling.module") .. ".helpers")
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
local bar_style = beautiful.tabbar_style or "default"
local bar = require(tostring(...):match(".*bling") .. ".widget.tabbar." ..
@ -147,9 +147,9 @@ tabbed.switch_to = function(tabobj, new_idx)
tabobj.focused_idx = new_idx
for idx, c in ipairs(tabobj.clients) do
if idx ~= new_idx then
helpers.turn_off(c)
helpers.client.turn_off(c)
else
helpers.turn_on(c)
helpers.client.turn_on(c)
c:raise()
if old_focused_c and old_focused_c.valid then
c:swap(old_focused_c)

View File

@ -2,7 +2,7 @@ local awful = require("awful")
local gears = require("gears")
local beautiful = require("beautiful")
local helpers = require(tostring(...):match(".*bling.module") .. ".helpers")
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
-- It might actually swallow too much, that's why there is a filter option by classname
-- without the don't-swallow-list it would also swallow for example
@ -58,12 +58,12 @@ local function manage_clientspawn(c)
if (tostring(parent_pid) == tostring(parent_client.pid)) and check_if_swallow(c) then
c:connect_signal("unmanage", function()
helpers.turn_on(parent_client)
helpers.client.turn_on(parent_client)
copy_size(parent_client, c)
end)
copy_size(c, parent_client)
helpers.turn_off(parent_client)
helpers.client.turn_off(parent_client)
end
end

View File

@ -4,7 +4,7 @@ local wibox = require("wibox")
local beautiful = require("beautiful")
local xresources = require("beautiful.xresources")
local dpi = xresources.apply_dpi
local helpers = require(tostring(...):match(".*bling") .. ".module.helpers")
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
local bg_normal = beautiful.tabbar_bg_normal or beautiful.bg_normal or "#ffffff"
local fg_normal = beautiful.tabbar_fg_normal or beautiful.fg_normal or "#000000"
@ -134,7 +134,7 @@ local function create(c, focused_bool, buttons)
{
wibox.widget.textbox(),
bg = bg_normal,
shape = helpers.prrect(border_radius, false, false, true,
shape = helpers.shape.prrect(border_radius, false, false, true,
false),
widget = wibox.container.background
},
@ -151,7 +151,7 @@ local function create(c, focused_bool, buttons)
{
tab_content,
bg = bg_temp,
shape = helpers.prrect(border_radius, true, true, false, false),
shape = helpers.shape.prrect(border_radius, true, true, false, false),
widget = wibox.container.background
},
top = dpi(8),
@ -162,7 +162,7 @@ local function create(c, focused_bool, buttons)
{
wibox.widget.textbox(),
bg = bg_normal,
shape = helpers.prrect(border_radius, false, false, false,
shape = helpers.shape.prrect(border_radius, false, false, false,
true),
widget = wibox.container.background
},