Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure font size(s) via default_preset #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,38 @@ cyclefocus = {
display_prev_count = 3,

-- Default preset to use for entries.
-- `preset_for_offset` (below) gets added to it.
default_preset = {},
-- `preset_for_offset` (below) gets added/applied to it.
-- The settings below are used by the default handlers.
default_preset = {
base_font_name = 'sans',
base_font_size = 8,
base_icon_size = dpi(24),
scale_factor_for_entry_offset = {
["0"] = 1.5,
}
},

--- Templates for entries in the list.
-- The following arguments get passed to a callback:
-- - client: the current client object.
-- - idx: index number of current entry in clients list.
-- - displayed_list: the list of entries in the list, possibly filtered.
preset_for_offset = {
-- Default callback, which will gets applied for all offsets (first).
-- Default callback, which gets applied for all offsets (first).
default = function (preset, args)
-- Default font and icon size (gets overwritten for current/0 index).
preset.font = 'sans 8'
preset.icon_size = dpi(24)
local default_preset = cyclefocus.default_preset
local scale_factors = default_preset.scale_factor_for_entry_offset
local factor = scale_factors and scale_factors[tostring(args.offset)] or 1
local font_size = (default_preset.base_font_size or 8) * factor
local font_name = default_preset.base_font_name or 'sans'
preset.font = string.format('%s %d', font_name, font_size)
preset.icon_size = (default_preset.base_icon_size or dpi(24)) * factor
preset.text = escape_markup(cyclefocus.get_client_title(args.client, false))
end,

-- Preset for current entry.
["0"] = function (preset, args)
preset.font = 'sans 14'
preset.icon_size = dpi(36)
preset.text = escape_markup(cyclefocus.get_client_title(args.client, true))
-- Add screen number if there is more than one.
if screen.count() > 1 then
Expand Down