Task preview: more flexible layout control (#85)
* Task preview: +much more flexible layout control * Added awful import * requested changes * fixup! requested changes * fixup! fixup! requested changes * Fix nil error Because what you are returning is a `wibox.widget`, instead of using `setup` you must set the `widget` property of the popup. * fix docs * fixup! fix docs * task_preview docs update Add lua support to code block * task_preview docs update Just some nit picky things Co-authored-by: gokul <33443763+JavaCafe01@users.noreply.github.com>
This commit is contained in:
parent
37edd6e1eb
commit
46282edf72
|
@ -26,6 +26,49 @@ bling.widget.task_preview.enable {
|
|||
}
|
||||
```
|
||||
|
||||
To allow for more customization, there is also a `widget_structure` property (as seen in some default awesome widgets) which is optional. An example is as follows -
|
||||
```lua
|
||||
bling.widget.task_preview.enable {
|
||||
x = 20, -- The x-coord of the popup
|
||||
y = 20, -- The y-coord of the popup
|
||||
height = 200, -- The height of the popup
|
||||
width = 200, -- The width of the popup
|
||||
placement_fn = function(c) -- Place the widget using awful.placement (this overrides x & y)
|
||||
awful.placement.bottom(c, {
|
||||
margins = {
|
||||
bottom = 30
|
||||
}
|
||||
})
|
||||
end,
|
||||
-- Your widget will automatically conform to the given size due to a constraint container.
|
||||
widget_structure = {
|
||||
{
|
||||
{
|
||||
{
|
||||
id = 'icon_role',
|
||||
widget = awful.widget.clienticon, -- The client icon
|
||||
},
|
||||
{
|
||||
id = 'name_role' -- The client name / title
|
||||
widget = wibox.widget.textbox,
|
||||
}
|
||||
layout = wibox.layout.flex.horizontal
|
||||
},
|
||||
widget = wibox.container.margin,
|
||||
margins = 5
|
||||
},
|
||||
{
|
||||
id = 'image_role', -- The client preview
|
||||
resize = true,
|
||||
valign = 'center',
|
||||
halign = 'center'
|
||||
widget = wibox.widget.imagebox,
|
||||
},
|
||||
layout = wibox.layout.fixed.vertical
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Here are the signals available:
|
||||
|
||||
```lua
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
-- v (boolean)
|
||||
-- c (client)
|
||||
--
|
||||
|
||||
local awful = require("awful")
|
||||
local wibox = require("wibox")
|
||||
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
|
||||
local gears = require("gears")
|
||||
|
@ -12,8 +14,9 @@ local beautiful = require("beautiful")
|
|||
local dpi = beautiful.xresources.apply_dpi
|
||||
local cairo = require("lgi").cairo
|
||||
|
||||
local function draw_widget(c, task_preview_box, screen_radius, widget_bg,
|
||||
widget_border_color, widget_border_width, margin)
|
||||
-- TODO: rename structure to something better?
|
||||
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
|
||||
local content = gears.surface(c.content)
|
||||
|
@ -25,12 +28,13 @@ local function draw_widget(c, task_preview_box, screen_radius, widget_bg,
|
|||
cr.operator = cairo.Operator.SOURCE
|
||||
cr:paint()
|
||||
|
||||
task_preview_box:setup{
|
||||
local widget = wibox.widget{
|
||||
(widget_template or {
|
||||
{
|
||||
{
|
||||
{
|
||||
{
|
||||
image = gears.surface.load(c.icon),
|
||||
id = 'icon_role',
|
||||
resize = true,
|
||||
forced_height = dpi(20),
|
||||
forced_width = dpi(20),
|
||||
|
@ -38,7 +42,7 @@ local function draw_widget(c, task_preview_box, screen_radius, widget_bg,
|
|||
},
|
||||
{
|
||||
{
|
||||
markup = c.name,
|
||||
id = 'name_role',
|
||||
align = "center",
|
||||
widget = wibox.widget.textbox
|
||||
},
|
||||
|
@ -51,7 +55,7 @@ local function draw_widget(c, task_preview_box, screen_radius, widget_bg,
|
|||
{
|
||||
{
|
||||
{
|
||||
image = gears.surface.load(img),
|
||||
id = 'image_role',
|
||||
resize = true,
|
||||
clip_shape = helpers.shape.rrect(screen_radius),
|
||||
widget = wibox.widget.imagebox
|
||||
|
@ -74,7 +78,27 @@ local function draw_widget(c, task_preview_box, screen_radius, widget_bg,
|
|||
shape_border_color = widget_border_color,
|
||||
shape = helpers.shape.rrect(screen_radius),
|
||||
widget = wibox.container.background
|
||||
}),
|
||||
widget = wibox.container.constraint,
|
||||
width = widget_width,
|
||||
height = widget_height
|
||||
}
|
||||
|
||||
-- todo: have something like a create callback here?
|
||||
|
||||
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
|
||||
|
||||
for _, w in ipairs(widget:get_children_by_id("name_role")) do
|
||||
w.text = c.name
|
||||
end
|
||||
|
||||
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)
|
||||
|
@ -95,23 +119,24 @@ local enable = function(opts)
|
|||
local widget_border_width = beautiful.task_preview_widget_border_width or
|
||||
dpi(3)
|
||||
|
||||
local task_preview_box = wibox({
|
||||
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,
|
||||
width = widget_width,
|
||||
height = widget_height,
|
||||
bg = "#00000000"
|
||||
})
|
||||
|
||||
awesome.connect_signal("bling::task_preview::visibility", function(s, v, c)
|
||||
draw_widget(c, task_preview_box, screen_radius, widget_bg,
|
||||
widget_border_color, widget_border_width, margin)
|
||||
if v then
|
||||
-- Update task preview contents
|
||||
task_preview_box.widget = draw_widget(c, opts.structure, screen_radius, widget_bg,
|
||||
widget_border_color, widget_border_width, margin, widget_width, widget_height)
|
||||
end
|
||||
|
||||
if placement_fn then
|
||||
placement_fn(task_preview_box)
|
||||
else
|
||||
if not placement_fn then
|
||||
task_preview_box.x = s.geometry.x + widget_x
|
||||
task_preview_box.y = s.geometry.y + widget_y
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue