From b2368c54a8e1aacf43972900717033d6cc1363ce Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 6 Jul 2021 00:53:21 -0700 Subject: [PATCH] tests: Fix the `screen` template rendering with multiple screens. It only worked for a single screen. It still isn't perfect, but much better than it was. --- tests/examples/screen/client_snap.lua | 2 +- .../screen/gap_single_client_false.lua | 2 +- .../screen/gap_single_client_true.lua | 2 +- tests/examples/screen/gaps.lua | 2 +- tests/examples/screen/gaps2.lua | 2 +- tests/examples/screen/geometry.lua | 8 +- tests/examples/screen/mfpol.lua | 4 +- tests/examples/screen/mfpol2.lua | 2 +- tests/examples/screen/mwfact.lua | 2 +- tests/examples/screen/mwfact2.lua | 2 +- tests/examples/screen/padding.lua | 8 +- tests/examples/screen/struts.lua | 4 +- tests/examples/screen/template.lua | 84 +++++++++---------- tests/examples/screen/tiled_clients.lua | 2 +- tests/examples/screen/tiling_area.lua | 2 +- tests/examples/screen/workarea.lua | 4 +- 16 files changed, 66 insertions(+), 66 deletions(-) diff --git a/tests/examples/screen/client_snap.lua b/tests/examples/screen/client_snap.lua index 25b635e67..19d97ccbb 100644 --- a/tests/examples/screen/client_snap.lua +++ b/tests/examples/screen/client_snap.lua @@ -39,7 +39,7 @@ local clients = { return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, draw_client_snap = true, --FIXME diff --git a/tests/examples/screen/gap_single_client_false.lua b/tests/examples/screen/gap_single_client_false.lua index fd09a79ee..274ac0b7b 100644 --- a/tests/examples/screen/gap_single_client_false.lua +++ b/tests/examples/screen/gap_single_client_false.lua @@ -35,7 +35,7 @@ local clients = { return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, draw_gaps = true, diff --git a/tests/examples/screen/gap_single_client_true.lua b/tests/examples/screen/gap_single_client_true.lua index 53a75434c..633ffc071 100644 --- a/tests/examples/screen/gap_single_client_true.lua +++ b/tests/examples/screen/gap_single_client_true.lua @@ -35,7 +35,7 @@ local clients = { return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, draw_gaps = true, diff --git a/tests/examples/screen/gaps.lua b/tests/examples/screen/gaps.lua index d8f358ca4..d495a1e42 100644 --- a/tests/examples/screen/gaps.lua +++ b/tests/examples/screen/gaps.lua @@ -36,7 +36,7 @@ local clients = { return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, draw_gaps = true, diff --git a/tests/examples/screen/gaps2.lua b/tests/examples/screen/gaps2.lua index 544c5833b..85cb5a460 100644 --- a/tests/examples/screen/gaps2.lua +++ b/tests/examples/screen/gaps2.lua @@ -36,7 +36,7 @@ local clients = { return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, draw_gaps = true, diff --git a/tests/examples/screen/geometry.lua b/tests/examples/screen/geometry.lua index b7765cd18..a32f62828 100644 --- a/tests/examples/screen/geometry.lua +++ b/tests/examples/screen/geometry.lua @@ -29,8 +29,8 @@ end --DOC_HIDE } return { --DOC_HIDE - factor = 2 , --DOC_HIDE - show_boxes = false, --DOC_HIDE - highlight_geometry = true , --DOC_HIDE - draw_wibar = wibar, --DOC_HIDE + factor = 2 , --DOC_HIDE + show_boxes = false , --DOC_HIDE + highlight_geometry = true , --DOC_HIDE + draw_wibars = {wibar}, --DOC_HIDE } --DOC_HIDE diff --git a/tests/examples/screen/mfpol.lua b/tests/examples/screen/mfpol.lua index 569a4962e..2465526af 100644 --- a/tests/examples/screen/mfpol.lua +++ b/tests/examples/screen/mfpol.lua @@ -45,9 +45,9 @@ for _,c in ipairs(clients) do end return { - factor = 2 , + factor = 2, show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, } diff --git a/tests/examples/screen/mfpol2.lua b/tests/examples/screen/mfpol2.lua index e096758d2..8e54c8b94 100644 --- a/tests/examples/screen/mfpol2.lua +++ b/tests/examples/screen/mfpol2.lua @@ -47,7 +47,7 @@ end return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, } diff --git a/tests/examples/screen/mwfact.lua b/tests/examples/screen/mwfact.lua index 10767a4e3..d89cb40d7 100644 --- a/tests/examples/screen/mwfact.lua +++ b/tests/examples/screen/mwfact.lua @@ -48,7 +48,7 @@ end return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, draw_mwfact = true, diff --git a/tests/examples/screen/mwfact2.lua b/tests/examples/screen/mwfact2.lua index f44980f93..ea92fe161 100644 --- a/tests/examples/screen/mwfact2.lua +++ b/tests/examples/screen/mwfact2.lua @@ -51,7 +51,7 @@ end return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, draw_mwfact = true, diff --git a/tests/examples/screen/padding.lua b/tests/examples/screen/padding.lua index 3f8b54f67..323816966 100644 --- a/tests/examples/screen/padding.lua +++ b/tests/examples/screen/padding.lua @@ -32,8 +32,8 @@ end --DOC_HIDE } --DOC_HIDE return { --DOC_HIDE - factor = 2 , --DOC_HIDE - show_boxes = false, --DOC_HIDE - highlight_padding_area = true , --DOC_HIDE - draw_wibar = wibar, --DOC_HIDE + factor = 2 , --DOC_HIDE + show_boxes = false , --DOC_HIDE + highlight_padding_area = true , --DOC_HIDE + draw_wibars = {wibar}, --DOC_HIDE } --DOC_HIDE diff --git a/tests/examples/screen/struts.lua b/tests/examples/screen/struts.lua index d8ac11db1..42498661b 100644 --- a/tests/examples/screen/struts.lua +++ b/tests/examples/screen/struts.lua @@ -51,9 +51,9 @@ local clients = { --DOC_HIDE } --DOC_HIDE return { --DOC_HIDE - factor = 2 , --DOC_HIDE + factor = 2, --DOC_HIDE show_boxes = true, --DOC_HIDE - draw_wibar = wibar, --DOC_HIDE + draw_wibars = {wibar}, --DOC_HIDE draw_clients = clients, --DOC_HIDE display_screen_info = false, --DOC_HIDE draw_struts = true, --DOC_HIDE diff --git a/tests/examples/screen/template.lua b/tests/examples/screen/template.lua index 7a68725fe..be2d8db84 100644 --- a/tests/examples/screen/template.lua +++ b/tests/examples/screen/template.lua @@ -160,11 +160,12 @@ local function draw_client(_, c, name, offset, label, alpha) end -local function compute_ruler(_, rect, name) - table.insert(hrulers, { +local function compute_ruler(s, rect, name) + hrulers[s], vrulers[s] = hrulers[s] or {}, vrulers[s] or {} + table.insert(hrulers[s], { label = name, x = rect.x, width = rect.width }) - table.insert(vrulers, { + table.insert(vrulers[s], { label = name, y = rect.y, height = rect.height }) end @@ -309,8 +310,8 @@ end local function draw_rulers(s) -- The table has a maximum of 4 entries, the sort algorithm is irrelevant. - while not bubble_sort(hrulers, "x", "width" ) do end - while not bubble_sort(vrulers, "y", "height") do end + while not bubble_sort(hrulers[s], "x", "width" ) do end + while not bubble_sort(vrulers[s], "y", "height") do end cr:set_line_width(1) cr:set_dash(nil) @@ -320,7 +321,7 @@ local function draw_rulers(s) dx = get_text_height() + 10 - for k, ruler in ipairs(vrulers) do + for k, ruler in ipairs(vrulers[s]) do draw_vruler(s, dx, sx, ruler, k) end @@ -406,10 +407,6 @@ local function evaluate_translation(draw_gaps, draw_struts, draw_mwfact, draw_cl end end -local function translate() - cr:translate(tr_x, tr_y * 0.66) -end - local function draw_gaps(s) cr:translate(-tr_x, -tr_y) @@ -473,7 +470,7 @@ local function draw_struts(s) if left > 0 then draw_hruler( s, - 0, + s.geometry.y*0.66, get_text_height(), {x = s.geometry.x+tr_x*2, width = left, color = colors.gaps.."66", align = true}, 1 @@ -484,7 +481,7 @@ local function draw_struts(s) draw_vruler( s, get_text_height()*1.5, - 0, + s.geometry.x*0.66, {y=s.geometry.y+tr_y*(1/factor), height = top, color = colors.gaps.."66", align = true}, 1 ) @@ -493,7 +490,7 @@ local function draw_struts(s) if right > 0 then draw_hruler( s, - 0, + s.geometry.y*0.66, get_text_height(), {x = s.geometry.x, width = left, color = colors.gaps.."66", align = true}, 1 @@ -504,7 +501,7 @@ local function draw_struts(s) draw_vruler( s, get_text_height()*1.5, - 0, + s.geometry.x*0.66, { y = s.geometry.y+tr_y*(1/factor)+s.geometry.height - bottom, height = bottom, @@ -667,8 +664,8 @@ local function draw_info(s) end -- Compute the rulers size. -for _=1, screen.count() do - local s = screen[1] +for k=1, screen.count() do + local s = screen[k] -- The padding. compute_ruler(s, s.tiling_area, "tiling_area") @@ -699,16 +696,15 @@ sew, seh = sew + 5*get_text_height(), seh + 5*get_text_height() img = cairo.SvgSurface.create(image_path..".svg", sew, seh) cr = cairo.Context(img) -cr:set_line_width(1.5) -cr:set_dash({10,4},1) - -- Instead of adding origin offset everywhere, translate the viewport. -translate() +cr:translate(tr_x, tr_y * 0.66) -- Draw the various areas. for k=1, screen.count() do - local s = screen[1] + local s = screen[k] + cr:set_line_width(1.5) + cr:set_dash({10,4},1) -- The outer geometry. draw_area(s, s.geometry, "geometry", (k-1)*10, args.highlight_geometry) @@ -727,8 +723,10 @@ for k=1, screen.count() do draw_rulers(s) -- Draw the wibar. - if args.draw_wibar then - draw_struct(s, args.draw_wibar, 'wibar', (k-1)*10, 'Wibar') + for _, wibar in ipairs(args.draw_wibars or {}) do + if wibar.screen == s then + draw_struct(s, wibar, 'wibar', (k-1)*10, 'Wibar') + end end local skip_gaps = s.selected_tag @@ -740,28 +738,30 @@ for k=1, screen.count() do -- Draw clients. if args.draw_clients then for label,c in pairs(args.draw_clients) do - local gap = c:tags()[1].gap - if args.draw_gaps and gap > 0 and (not c.floating) and not skip_gaps then - local proxy = { - x = c.x - gap, - y = c.y - gap, - width = c.width + 2*gap, - height = c.height + 2*gap, - } + if c.screen == s then + local gap = c:tags()[1].gap + if args.draw_gaps and gap > 0 and (not c.floating) and not skip_gaps then + local proxy = { + x = c.x - gap, + y = c.y - gap, + width = c.width + 2*gap, + height = c.height + 2*gap, + } - draw_client(s, proxy, 'gaps', (k-1)*10, nil, "11") - elseif args.draw_client_snap and c.floating then - local proxy = { - x = c.x - sd, - y = c.y - sd, - width = c.width + 2*sd, - height = c.height + 2*sd, - } + draw_client(s, proxy, 'gaps', (k-1)*10, nil, "11") + elseif args.draw_client_snap and c.floating then + local proxy = { + x = c.x - sd, + y = c.y - sd, + width = c.width + 2*sd, + height = c.height + 2*sd, + } - draw_client(s, proxy, 'gaps', (k-1)*10, nil, "11") + draw_client(s, proxy, 'gaps', (k-1)*10, nil, "11") + end + + draw_client(s, c, 'tiling_client', (k-1)*10, label) end - - draw_client(s, c, 'tiling_client', (k-1)*10, label) end end diff --git a/tests/examples/screen/tiled_clients.lua b/tests/examples/screen/tiled_clients.lua index dceff3478..677942312 100644 --- a/tests/examples/screen/tiled_clients.lua +++ b/tests/examples/screen/tiled_clients.lua @@ -47,7 +47,7 @@ end return { factor = 2 , show_boxes = true, - draw_wibar = wibar, + draw_wibars = {wibar}, draw_clients = clients, display_screen_info = false, } diff --git a/tests/examples/screen/tiling_area.lua b/tests/examples/screen/tiling_area.lua index 5b80e6128..4f4024fb7 100644 --- a/tests/examples/screen/tiling_area.lua +++ b/tests/examples/screen/tiling_area.lua @@ -27,5 +27,5 @@ return { factor = 2 , show_boxes = false, highlight_tiling_area = true , - draw_wibar = wibar, + draw_wibars = {wibar}, } diff --git a/tests/examples/screen/workarea.lua b/tests/examples/screen/workarea.lua index 26a2266ae..4f4b0e8f4 100644 --- a/tests/examples/screen/workarea.lua +++ b/tests/examples/screen/workarea.lua @@ -35,8 +35,8 @@ end --DOC_HIDE } return { --DOC_HIDE - factor = 2 , --DOC_HIDE + factor = 2, --DOC_HIDE show_boxes = false, --DOC_HIDE highlight_workarea = true , --DOC_HIDE - draw_wibar = wibar, --DOC_HIDE + draw_wibars = {wibar}, --DOC_HIDE } --DOC_HIDE