2021-07-15 00:17:46 +02:00
|
|
|
--
|
|
|
|
-- Provides:
|
|
|
|
-- bling::task_preview::visibility
|
|
|
|
-- s (screen)
|
|
|
|
-- v (boolean)
|
|
|
|
-- c (client)
|
|
|
|
--
|
2021-08-11 22:55:41 +02:00
|
|
|
local awful = require("awful")
|
2021-07-15 00:17:46 +02:00
|
|
|
local wibox = require("wibox")
|
|
|
|
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
|
|
|
|
local gears = require("gears")
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
local dpi = beautiful.xresources.apply_dpi
|
|
|
|
local cairo = require("lgi").cairo
|
|
|
|
|
2021-08-11 22:55:41 +02:00
|
|
|
-- TODO: rename structure to something better?
|
2021-08-27 20:01:22 +02:00
|
|
|
local function draw_widget(
|
|
|
|
c,
|
|
|
|
widget_template,
|
|
|
|
screen_radius,
|
|
|
|
widget_bg,
|
|
|
|
widget_border_color,
|
|
|
|
widget_border_width,
|
|
|
|
margin,
|
|
|
|
widget_width,
|
|
|
|
widget_height
|
|
|
|
)
|
|
|
|
if not pcall(function()
|
|
|
|
return type(c.content)
|
|
|
|
end) then
|
|
|
|
return
|
|
|
|
end
|
2021-11-03 22:59:53 +01:00
|
|
|
|
|
|
|
local content = nil
|
|
|
|
if c.active then
|
|
|
|
content = gears.surface(c.content)
|
|
|
|
elseif c.prev_content then
|
|
|
|
content = gears.surface(c.prev_content)
|
|
|
|
end
|
|
|
|
|
|
|
|
local img = nil
|
|
|
|
if content ~= nil then
|
|
|
|
local cr = cairo.Context(content)
|
|
|
|
local x, y, w, h = cr:clip_extents()
|
|
|
|
img = cairo.ImageSurface.create(cairo.Format.ARGB32, w - x, h - y)
|
|
|
|
cr = cairo.Context(img)
|
|
|
|
cr:set_source_surface(content, 0, 0)
|
|
|
|
cr.operator = cairo.Operator.SOURCE
|
|
|
|
cr:paint()
|
|
|
|
end
|
2021-07-15 00:17:46 +02:00
|
|
|
|
2021-08-27 20:01:22 +02:00
|
|
|
local widget = wibox.widget({
|
2021-08-11 22:55:41 +02:00
|
|
|
(widget_template or {
|
2021-07-15 00:17:46 +02:00
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
2021-08-27 20:01:22 +02:00
|
|
|
id = "icon_role",
|
2021-08-11 22:55:41 +02:00
|
|
|
resize = true,
|
|
|
|
forced_height = dpi(20),
|
|
|
|
forced_width = dpi(20),
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.widget.imagebox,
|
2021-08-11 22:55:41 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
2021-08-27 20:01:22 +02:00
|
|
|
id = "name_role",
|
2021-08-11 22:55:41 +02:00
|
|
|
align = "center",
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.widget.textbox,
|
2021-08-11 22:55:41 +02:00
|
|
|
},
|
|
|
|
left = dpi(4),
|
|
|
|
right = dpi(4),
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.container.margin,
|
2021-07-15 00:17:46 +02:00
|
|
|
},
|
2021-08-27 20:01:22 +02:00
|
|
|
layout = wibox.layout.align.horizontal,
|
2021-07-15 00:17:46 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
2021-08-11 22:55:41 +02:00
|
|
|
{
|
2021-08-27 20:01:22 +02:00
|
|
|
id = "image_role",
|
2021-08-11 22:55:41 +02:00
|
|
|
resize = true,
|
|
|
|
clip_shape = helpers.shape.rrect(screen_radius),
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.widget.imagebox,
|
2021-08-11 22:55:41 +02:00
|
|
|
},
|
|
|
|
valign = "center",
|
|
|
|
halign = "center",
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.container.place,
|
2021-07-15 00:17:46 +02:00
|
|
|
},
|
2021-08-11 22:55:41 +02:00
|
|
|
top = margin * 0.25,
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.container.margin,
|
2021-07-15 00:17:46 +02:00
|
|
|
},
|
2021-08-11 22:55:41 +02:00
|
|
|
fill_space = true,
|
2021-08-27 20:01:22 +02:00
|
|
|
layout = wibox.layout.fixed.vertical,
|
2021-07-15 00:17:46 +02:00
|
|
|
},
|
2021-08-11 22:55:41 +02:00
|
|
|
margins = margin,
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.container.margin,
|
2021-07-15 00:17:46 +02:00
|
|
|
},
|
2021-08-11 22:55:41 +02:00
|
|
|
bg = widget_bg,
|
|
|
|
shape_border_width = widget_border_width,
|
|
|
|
shape_border_color = widget_border_color,
|
|
|
|
shape = helpers.shape.rrect(screen_radius),
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.container.background,
|
2021-08-11 22:55:41 +02:00
|
|
|
}),
|
2021-07-15 00:17:46 +02:00
|
|
|
width = widget_width,
|
2021-08-11 22:58:19 +02:00
|
|
|
height = widget_height,
|
2021-08-27 20:01:22 +02:00
|
|
|
widget = wibox.container.constraint,
|
|
|
|
})
|
2021-08-11 22:55:41 +02:00
|
|
|
|
2021-08-11 22:58:19 +02:00
|
|
|
-- TODO: have something like a create callback here?
|
2021-08-11 22:55:41 +02:00
|
|
|
|
2021-08-11 22:58:19 +02:00
|
|
|
for _, w in ipairs(widget:get_children_by_id("image_role")) do
|
|
|
|
w.image = img -- TODO: copy it with gears.surface.xxx or something
|
|
|
|
end
|
2021-08-11 22:55:41 +02:00
|
|
|
|
2021-08-11 22:58:19 +02:00
|
|
|
for _, w in ipairs(widget:get_children_by_id("name_role")) do
|
|
|
|
w.text = c.name
|
|
|
|
end
|
2021-07-15 00:17:46 +02:00
|
|
|
|
2021-08-11 22:58:19 +02:00
|
|
|
for _, w in ipairs(widget:get_children_by_id("icon_role")) do
|
|
|
|
w.image = c.icon -- TODO: detect clienticon
|
|
|
|
end
|
|
|
|
|
|
|
|
return widget
|
|
|
|
end
|
|
|
|
|
|
|
|
local enable = function(opts)
|
|
|
|
local opts = opts or {}
|
|
|
|
|
|
|
|
local widget_x = opts.x or dpi(20)
|
|
|
|
local widget_y = opts.y or dpi(20)
|
|
|
|
local widget_height = opts.height or dpi(200)
|
|
|
|
local widget_width = opts.width or dpi(200)
|
|
|
|
local placement_fn = opts.placement_fn or nil
|
|
|
|
|
|
|
|
local margin = beautiful.task_preview_widget_margin or dpi(0)
|
|
|
|
local screen_radius = beautiful.task_preview_widget_border_radius or dpi(0)
|
|
|
|
local widget_bg = beautiful.task_preview_widget_bg or "#000000"
|
2021-08-27 20:01:22 +02:00
|
|
|
local widget_border_color = beautiful.task_preview_widget_border_color
|
|
|
|
or "#ffffff"
|
|
|
|
local widget_border_width = beautiful.task_preview_widget_border_width
|
|
|
|
or dpi(3)
|
|
|
|
|
|
|
|
local task_preview_box = awful.popup({
|
|
|
|
type = "dropdown_menu",
|
|
|
|
visible = false,
|
|
|
|
ontop = true,
|
|
|
|
placement = placement_fn,
|
|
|
|
widget = wibox.container.background, -- A dummy widget to make awful.popup not scream
|
|
|
|
input_passthrough = true,
|
|
|
|
bg = "#00000000",
|
|
|
|
})
|
2021-08-11 22:58:19 +02:00
|
|
|
|
2021-11-03 22:59:53 +01:00
|
|
|
tag.connect_signal("property::selected", function(t)
|
|
|
|
-- Awesome switches up tags on startup really fast it seems, probably depends on what rules you have set
|
|
|
|
-- which can cause the c.content to not show the correct image
|
|
|
|
gears.timer
|
|
|
|
{
|
|
|
|
timeout = 0.1,
|
|
|
|
call_now = false,
|
|
|
|
autostart = true,
|
|
|
|
single_shot = true,
|
|
|
|
callback = function()
|
|
|
|
if t.selected == true then
|
|
|
|
for _, c in ipairs(t:clients()) do
|
|
|
|
c.prev_content = gears.surface.duplicate_surface(c.content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end)
|
|
|
|
|
2021-08-11 22:58:19 +02:00
|
|
|
awesome.connect_signal("bling::task_preview::visibility", function(s, v, c)
|
|
|
|
if v then
|
|
|
|
-- Update task preview contents
|
2021-08-27 20:01:22 +02:00
|
|
|
task_preview_box.widget = draw_widget(
|
|
|
|
c,
|
|
|
|
opts.structure,
|
|
|
|
screen_radius,
|
|
|
|
widget_bg,
|
|
|
|
widget_border_color,
|
|
|
|
widget_border_width,
|
|
|
|
margin,
|
|
|
|
widget_width,
|
|
|
|
widget_height
|
|
|
|
)
|
2021-10-03 12:19:48 +02:00
|
|
|
else
|
|
|
|
task_preview_box.widget = nil
|
|
|
|
collectgarbage("collect")
|
2021-08-11 22:55:41 +02:00
|
|
|
end
|
|
|
|
|
2021-08-11 22:58:19 +02:00
|
|
|
if not placement_fn then
|
|
|
|
task_preview_box.x = s.geometry.x + widget_x
|
|
|
|
task_preview_box.y = s.geometry.y + widget_y
|
|
|
|
end
|
2021-08-11 22:55:41 +02:00
|
|
|
|
2021-08-11 22:58:19 +02:00
|
|
|
task_preview_box.visible = v
|
|
|
|
end)
|
|
|
|
end
|
2021-07-15 00:17:46 +02:00
|
|
|
|
2021-11-05 16:38:29 +01:00
|
|
|
return { enable = enable, draw_widget = draw_widget }
|