Add an option to draw clients.
Change how wibox are drawn to build a more flexible function reusable in the context of clients. Add `clients` option to the template. This new option needs an associative table `{ ['label'] = client }` to work. Where label will be a text rendered on the middle of the client area. Add a new example: `texts/examples/screen/tiled_clients.lua`.
This commit is contained in:
parent
3791daaeaf
commit
fcc3d0b590
|
@ -483,6 +483,8 @@ end
|
||||||
-- * maximized clients
|
-- * maximized clients
|
||||||
-- * floating clients
|
-- * floating clients
|
||||||
--
|
--
|
||||||
|
-- @DOC_screen_tiled_clients_EXAMPLE@
|
||||||
|
--
|
||||||
-- @property tiled_clients
|
-- @property tiled_clients
|
||||||
-- @param table The clients list, ordered from top to bottom.
|
-- @param table The clients list, ordered from top to bottom.
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ local colors = {
|
||||||
tiling_area = "#ff0000",
|
tiling_area = "#ff0000",
|
||||||
padding_area= "#ff0000",
|
padding_area= "#ff0000",
|
||||||
wibar = "#000000",
|
wibar = "#000000",
|
||||||
|
tiling_client = "#ff0000",
|
||||||
}
|
}
|
||||||
|
|
||||||
local function draw_area(_, rect, name, offset, highlight)
|
local function draw_area(_, rect, name, offset, highlight)
|
||||||
|
@ -123,26 +124,29 @@ local function draw_solid_area(_, rect, name, offset, alpha)
|
||||||
cr:stroke()
|
cr:stroke()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw_wibar(_, wibar, offset)
|
local function write_on_area_middle(rect, text, offset)
|
||||||
draw_solid_area(_, wibar, 'wibar', offset)
|
-- Prepare to write on the rect area
|
||||||
|
|
||||||
-- Prepare to write on the wibar area
|
|
||||||
local pctx = PangoCairo.font_map_get_default():create_context()
|
local pctx = PangoCairo.font_map_get_default():create_context()
|
||||||
local playout = Pango.Layout.new(pctx)
|
local playout = Pango.Layout.new(pctx)
|
||||||
local pdesc = Pango.FontDescription()
|
local pdesc = Pango.FontDescription()
|
||||||
pdesc:set_absolute_size(11 * Pango.SCALE)
|
pdesc:set_absolute_size(11 * Pango.SCALE)
|
||||||
playout:set_font_description(pdesc)
|
playout:set_font_description(pdesc)
|
||||||
|
|
||||||
-- Write wibar on the bar area
|
-- Write 'text' on the rect area
|
||||||
playout.attributes, playout.text = Pango.parse_markup('Wibar', -1, 0)
|
playout.attributes, playout.text = Pango.parse_markup(text, -1, 0)
|
||||||
local _, logical = playout:get_pixel_extents()
|
local _, logical = playout:get_pixel_extents()
|
||||||
local dx = (wibar.width*factor - logical.width) / 2
|
local dx = (rect.x*factor+offset) + (rect.width*factor - logical.width) / 2
|
||||||
local dy = (wibar.height*factor - logical.height) / 2
|
local dy = (rect.y*factor+offset) + (rect.height*factor - logical.height) / 2
|
||||||
cr:set_source_rgb(0, 0, 0)
|
cr:set_source_rgb(0, 0, 0)
|
||||||
cr:move_to(dx, dy)
|
cr:move_to(dx, dy)
|
||||||
cr:show_layout(playout)
|
cr:show_layout(playout)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function draw_struct(_, struct, name, offset, label)
|
||||||
|
draw_solid_area(_, struct, name, offset)
|
||||||
|
if type(label) == 'string' then
|
||||||
|
write_on_area_middle(struct, label, offset)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function compute_ruler(_, rect, name)
|
local function compute_ruler(_, rect, name)
|
||||||
|
@ -374,7 +378,14 @@ for k=1, screen.count() do
|
||||||
|
|
||||||
-- Draw the wibar.
|
-- Draw the wibar.
|
||||||
if args.draw_wibar then
|
if args.draw_wibar then
|
||||||
draw_wibar(s, args.draw_wibar, (k-1)*10)
|
draw_struct(s, args.draw_wibar, 'wibar', (k-1)*10, 'Wibar')
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Draw clients.
|
||||||
|
if args.draw_clients then
|
||||||
|
for label,c in pairs(args.draw_clients) do
|
||||||
|
draw_struct(s, c, 'tiling_client', (k-1)*10, label)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw the informations.
|
-- Draw the informations.
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
--DOC_GEN_IMAGE --DOC_NO_USAGE --DOC_HIDE_ALL
|
||||||
|
|
||||||
|
screen[1]._resize {x = 0, width = 640, height = 480}
|
||||||
|
|
||||||
|
|
||||||
|
local awful = {
|
||||||
|
wibar = require("awful.wibar"),
|
||||||
|
tag = require("awful.tag"),
|
||||||
|
tag_layout = require("awful.layout.suit.tile")
|
||||||
|
}
|
||||||
|
|
||||||
|
function awful.spawn(_, args)
|
||||||
|
local c = client.gen_fake{}
|
||||||
|
c:tags({args.tag})
|
||||||
|
assert(#c:tags() == 1)
|
||||||
|
assert(c:tags()[1] == args.tag)
|
||||||
|
end
|
||||||
|
|
||||||
|
screen[1].padding = {
|
||||||
|
left = 40,
|
||||||
|
right = 40,
|
||||||
|
top = 20,
|
||||||
|
bottom = 20,
|
||||||
|
}
|
||||||
|
|
||||||
|
local wibar = awful.wibar {
|
||||||
|
position = "top",
|
||||||
|
height = 24,
|
||||||
|
}
|
||||||
|
|
||||||
|
awful.tag.add("1", {
|
||||||
|
screen = screen[1],
|
||||||
|
selected = true,
|
||||||
|
layout = awful.tag_layout.right,
|
||||||
|
gap = 5
|
||||||
|
})
|
||||||
|
|
||||||
|
local clients = {
|
||||||
|
['client #1'] = client.gen_fake{},
|
||||||
|
['client #2'] = client.gen_fake{},
|
||||||
|
['client #3'] = client.gen_fake{}
|
||||||
|
}
|
||||||
|
for _,c in ipairs(clients) do
|
||||||
|
c:tags{"1"}
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
factor = 2 ,
|
||||||
|
show_boxes = true,
|
||||||
|
draw_wibar = wibar,
|
||||||
|
draw_clients = clients,
|
||||||
|
display_screen_info = false,
|
||||||
|
}
|
Loading…
Reference in New Issue