bling/widget/tabbar/modern.lua

273 lines
7.9 KiB
Lua
Raw Normal View History

local awful = require("awful")
2020-11-24 01:13:58 +01:00
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful")
local xresources = require("beautiful.xresources")
local dpi = xresources.apply_dpi
2021-01-23 23:04:22 +01:00
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
2020-11-24 01:13:58 +01:00
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"
local bg_focus = beautiful.tabbar_bg_focus or beautiful.bg_focus or "#000000"
local fg_focus = beautiful.tabbar_fg_focus or beautiful.fg_focus or "#ffffff"
local bg_focus_inactive = beautiful.tabbar_bg_focus_inactive or bg_focus
local fg_focus_inactive = beautiful.tabbar_fg_focus_inactive or fg_focus
local bg_normal_inactive = beautiful.tabbar_bg_normal_inactive or bg_normal
local fg_normal_inactive = beautiful.tabbar_fg_normal_inactive or fg_normal
2020-11-24 01:13:58 +01:00
local font = beautiful.tabbar_font or beautiful.font or "Hack 15"
local size = beautiful.tabbar_size or dpi(40)
2021-08-27 20:01:22 +02:00
local border_radius = beautiful.mstab_border_radius
or beautiful.border_radius
or 6
2021-01-28 20:23:01 +01:00
local position = beautiful.tabbar_position or "top"
2021-08-27 20:01:22 +02:00
local close_color = beautiful.tabbar_color_close
or beautiful.xcolor1
or "#f9929b"
2020-11-24 01:13:58 +01:00
local min_color = beautiful.tabbar_color_min or beautiful.xcolor3 or "#fbdf90"
2021-08-27 20:01:22 +02:00
local float_color = beautiful.tabbar_color_float
or beautiful.xcolor5
or "#ccaced"
2020-11-24 01:13:58 +01:00
-- Helper to create buttons
local function create_title_button(c, color_focus, color_unfocus)
2021-08-27 20:01:22 +02:00
local tb_color = wibox.widget({
2020-11-29 11:57:51 +01:00
wibox.widget.textbox(),
2020-11-24 01:13:58 +01:00
forced_width = dpi(8),
forced_height = dpi(8),
bg = color_focus,
shape = gears.shape.circle,
2021-08-27 20:01:22 +02:00
widget = wibox.container.background,
})
2020-11-24 01:13:58 +01:00
2021-08-27 20:01:22 +02:00
local tb = wibox.widget({
2020-11-24 01:13:58 +01:00
tb_color,
width = dpi(25),
2020-11-24 06:24:49 +01:00
height = dpi(25),
2020-11-24 01:13:58 +01:00
strategy = "min",
2021-08-27 20:01:22 +02:00
layout = wibox.layout.constraint,
})
2020-11-24 01:13:58 +01:00
local function update()
if client.focus == c then
tb_color.bg = color_focus
else
tb_color.bg = color_unfocus
end
end
update()
c:connect_signal("focus", update)
c:connect_signal("unfocus", update)
2021-08-27 20:01:22 +02:00
tb:connect_signal("mouse::enter", function()
tb_color.bg = color_focus .. "70"
end)
2021-08-27 20:01:22 +02:00
tb:connect_signal("mouse::leave", function()
tb_color.bg = color_focus
end)
2020-11-24 01:13:58 +01:00
tb.visible = true
return tb
end
local function create(c, focused_bool, buttons, inactive_bool)
2020-11-24 01:13:58 +01:00
-- local flexlist = wibox.layout.flex.horizontal()
local title_temp = c.name or c.class or "-"
title_temp = gears.string.xml_escape(title_temp)
local bg_temp = inactive_bool and bg_normal_inactive or bg_normal
local fg_temp = inactive_bool and fg_normal_inactive or fg_normal
2020-11-24 01:13:58 +01:00
if focused_bool then
bg_temp = inactive_bool and bg_focus_inactive or bg_focus
fg_temp = inactive_bool and fg_focus_inactive or fg_focus
2020-11-24 01:13:58 +01:00
end
local text_temp = wibox.widget.textbox()
text_temp.align = "center"
text_temp.valign = "center"
text_temp.font = font
2021-08-27 20:01:22 +02:00
text_temp.markup = "<span foreground='"
.. fg_temp
.. "'>"
.. title_temp
.. "</span>"
2020-11-24 01:13:58 +01:00
c:connect_signal("property::name", function(_)
local title_temp = c.name or c.class or "-"
2021-08-27 20:01:22 +02:00
text_temp.markup = "<span foreground='"
.. fg_temp
.. "'>"
.. title_temp
.. "</span>"
2020-11-24 01:13:58 +01:00
end)
2021-08-27 20:01:22 +02:00
local tab_content = wibox.widget({
{
awful.widget.clienticon(c),
2021-03-10 10:26:30 +01:00
top = dpi(6),
left = dpi(15),
2021-03-10 10:26:30 +01:00
bottom = dpi(6),
2021-08-27 20:01:22 +02:00
widget = wibox.container.margin,
},
text_temp,
nill,
expand = "none",
2021-08-27 20:01:22 +02:00
layout = wibox.layout.align.horizontal,
})
2020-11-24 01:13:58 +01:00
local close = create_title_button(c, close_color, bg_normal)
2021-08-27 20:01:22 +02:00
close:connect_signal("button::press", function()
c:kill()
end)
local floating = create_title_button(c, float_color, bg_normal)
2021-08-27 20:01:22 +02:00
floating:connect_signal("button::press", function()
c.floating = not c.floating
end)
local min = create_title_button(c, min_color, bg_normal)
2021-08-27 20:01:22 +02:00
min:connect_signal("button::press", function()
c.minimized = true
end)
2020-11-24 01:13:58 +01:00
if focused_bool then
2021-08-27 20:01:22 +02:00
tab_content = wibox.widget({
2020-11-24 01:13:58 +01:00
{
awful.widget.clienticon(c),
top = dpi(10),
2020-11-24 06:24:49 +01:00
left = dpi(15),
bottom = dpi(10),
2021-08-27 20:01:22 +02:00
widget = wibox.container.margin,
2020-11-24 01:13:58 +01:00
},
text_temp,
{
2021-08-27 20:01:22 +02:00
{ min, floating, close, layout = wibox.layout.fixed.horizontal },
top = dpi(10),
right = dpi(10),
bottom = dpi(10),
2021-08-27 20:01:22 +02:00
widget = wibox.container.margin,
},
2020-11-24 01:13:58 +01:00
expand = "none",
2021-08-27 20:01:22 +02:00
layout = wibox.layout.align.horizontal,
})
2020-11-24 01:13:58 +01:00
end
local main_content = nil
local left_shape = nil
local right_shape = nil
if position == "top" then
2021-08-27 20:01:22 +02:00
main_content = wibox.widget({
{
tab_content,
bg = bg_temp,
2021-08-27 20:01:22 +02:00
shape = helpers.shape.prrect(
border_radius,
true,
true,
false,
false
),
widget = wibox.container.background,
},
top = dpi(8),
2021-08-27 20:01:22 +02:00
widget = wibox.container.margin,
})
2021-08-27 20:01:22 +02:00
left_shape = helpers.shape.prrect(
border_radius,
false,
false,
true,
false
)
right_shape = helpers.shape.prrect(
border_radius,
false,
false,
false,
true
)
else
2021-08-27 20:01:22 +02:00
main_content = wibox.widget({
{
tab_content,
bg = bg_temp,
2021-08-27 20:01:22 +02:00
shape = helpers.shape.prrect(
border_radius,
false,
false,
true,
true
),
widget = wibox.container.background,
},
bottom = dpi(8),
2021-08-27 20:01:22 +02:00
widget = wibox.container.margin,
})
2021-08-27 20:01:22 +02:00
left_shape = helpers.shape.prrect(
border_radius,
false,
true,
false,
false
)
right_shape = helpers.shape.prrect(
border_radius,
true,
false,
false,
false
)
end
2020-11-24 01:13:58 +01:00
local wid_temp = wibox.widget({
buttons = buttons,
{
2020-11-26 01:42:05 +01:00
{
{
2020-11-29 11:57:51 +01:00
wibox.widget.textbox(),
2020-11-26 01:42:05 +01:00
bg = bg_normal,
shape = left_shape,
2021-08-27 20:01:22 +02:00
widget = wibox.container.background,
2020-11-26 01:42:05 +01:00
},
bg = bg_temp,
shape = gears.rectangle,
2021-08-27 20:01:22 +02:00
widget = wibox.container.background,
2020-11-26 01:42:05 +01:00
},
2020-11-26 05:14:53 +01:00
width = border_radius + (border_radius / 2),
height = size,
2020-11-26 01:42:05 +01:00
strategy = "exact",
2021-08-27 20:01:22 +02:00
layout = wibox.layout.constraint,
2020-11-26 01:42:05 +01:00
},
main_content,
2020-11-26 01:42:05 +01:00
{
{
{
2020-11-29 11:57:51 +01:00
wibox.widget.textbox(),
2020-11-26 01:42:05 +01:00
bg = bg_normal,
shape = right_shape,
2021-08-27 20:01:22 +02:00
widget = wibox.container.background,
2020-11-26 01:42:05 +01:00
},
bg = bg_temp,
shape = gears.rectangle,
2021-08-27 20:01:22 +02:00
widget = wibox.container.background,
2020-11-26 01:42:05 +01:00
},
2020-11-26 05:14:53 +01:00
width = border_radius + (border_radius / 2),
height = size,
2020-11-26 01:42:05 +01:00
strategy = "exact",
2021-08-27 20:01:22 +02:00
layout = wibox.layout.constraint,
2020-11-26 01:42:05 +01:00
},
2021-08-27 20:01:22 +02:00
layout = wibox.layout.align.horizontal,
2020-11-24 01:13:58 +01:00
})
return wid_temp
end
return {
layout = wibox.layout.flex.horizontal,
create = create,
position = position,
2020-11-24 01:13:58 +01:00
size = size,
bg_normal = bg_normal,
2021-08-27 20:01:22 +02:00
bg_focus = bg_focus,
2020-11-24 01:13:58 +01:00
}