Correct indentation of keyboardlayout.lua
Correct the indentation of keyboardlayout.lua, so that it complies with the vim modeline at the bottom of the file.
This commit is contained in:
parent
205fae2aab
commit
a005ad22b1
|
@ -20,108 +20,108 @@ local keyboardlayout = { mt = {} }
|
||||||
-- As to the country-code-like symbols below, refer to the names of XKB's
|
-- As to the country-code-like symbols below, refer to the names of XKB's
|
||||||
-- data files in /.../xkb/symbols/*.
|
-- data files in /.../xkb/symbols/*.
|
||||||
keyboardlayout.xkeyboard_country_code = {
|
keyboardlayout.xkeyboard_country_code = {
|
||||||
["ad"] = true, -- Andorra
|
["ad"] = true, -- Andorra
|
||||||
["af"] = true, -- Afganistan
|
["af"] = true, -- Afganistan
|
||||||
["al"] = true, -- Albania
|
["al"] = true, -- Albania
|
||||||
["am"] = true, -- Armenia
|
["am"] = true, -- Armenia
|
||||||
["ara"] = true, -- Arabic
|
["ara"] = true, -- Arabic
|
||||||
["at"] = true, -- Austria
|
["at"] = true, -- Austria
|
||||||
["az"] = true, -- Azerbaijan
|
["az"] = true, -- Azerbaijan
|
||||||
["ba"] = true, -- Bosnia and Herzegovina
|
["ba"] = true, -- Bosnia and Herzegovina
|
||||||
["bd"] = true, -- Bangladesh
|
["bd"] = true, -- Bangladesh
|
||||||
["be"] = true, -- Belgium
|
["be"] = true, -- Belgium
|
||||||
["bg"] = true, -- Bulgaria
|
["bg"] = true, -- Bulgaria
|
||||||
["br"] = true, -- Brazil
|
["br"] = true, -- Brazil
|
||||||
["bt"] = true, -- Bhutan
|
["bt"] = true, -- Bhutan
|
||||||
["bw"] = true, -- Botswana
|
["bw"] = true, -- Botswana
|
||||||
["by"] = true, -- Belarus
|
["by"] = true, -- Belarus
|
||||||
["ca"] = true, -- Canada
|
["ca"] = true, -- Canada
|
||||||
["cd"] = true, -- Congo
|
["cd"] = true, -- Congo
|
||||||
["ch"] = true, -- Switzerland
|
["ch"] = true, -- Switzerland
|
||||||
["cm"] = true, -- Cameroon
|
["cm"] = true, -- Cameroon
|
||||||
["cn"] = true, -- China
|
["cn"] = true, -- China
|
||||||
["cz"] = true, -- Czechia
|
["cz"] = true, -- Czechia
|
||||||
["de"] = true, -- Germany
|
["de"] = true, -- Germany
|
||||||
["dk"] = true, -- Denmark
|
["dk"] = true, -- Denmark
|
||||||
["ee"] = true, -- Estonia
|
["ee"] = true, -- Estonia
|
||||||
["epo"] = true, -- Esperanto
|
["epo"] = true, -- Esperanto
|
||||||
["es"] = true, -- Spain
|
["es"] = true, -- Spain
|
||||||
["et"] = true, -- Ethiopia
|
["et"] = true, -- Ethiopia
|
||||||
["fi"] = true, -- Finland
|
["fi"] = true, -- Finland
|
||||||
["fo"] = true, -- Faroe Islands
|
["fo"] = true, -- Faroe Islands
|
||||||
["fr"] = true, -- France
|
["fr"] = true, -- France
|
||||||
["gb"] = true, -- United Kingdom
|
["gb"] = true, -- United Kingdom
|
||||||
["ge"] = true, -- Georgia
|
["ge"] = true, -- Georgia
|
||||||
["gh"] = true, -- Ghana
|
["gh"] = true, -- Ghana
|
||||||
["gn"] = true, -- Guinea
|
["gn"] = true, -- Guinea
|
||||||
["gr"] = true, -- Greece
|
["gr"] = true, -- Greece
|
||||||
["hr"] = true, -- Croatia
|
["hr"] = true, -- Croatia
|
||||||
["hu"] = true, -- Hungary
|
["hu"] = true, -- Hungary
|
||||||
["ie"] = true, -- Ireland
|
["ie"] = true, -- Ireland
|
||||||
["il"] = true, -- Israel
|
["il"] = true, -- Israel
|
||||||
["in"] = true, -- India
|
["in"] = true, -- India
|
||||||
["iq"] = true, -- Iraq
|
["iq"] = true, -- Iraq
|
||||||
["ir"] = true, -- Iran
|
["ir"] = true, -- Iran
|
||||||
["is"] = true, -- Iceland
|
["is"] = true, -- Iceland
|
||||||
["it"] = true, -- Italy
|
["it"] = true, -- Italy
|
||||||
["jp"] = true, -- Japan
|
["jp"] = true, -- Japan
|
||||||
["ke"] = true, -- Kenya
|
["ke"] = true, -- Kenya
|
||||||
["kg"] = true, -- Kyrgyzstan
|
["kg"] = true, -- Kyrgyzstan
|
||||||
["kh"] = true, -- Cambodia
|
["kh"] = true, -- Cambodia
|
||||||
["kr"] = true, -- Korea
|
["kr"] = true, -- Korea
|
||||||
["kz"] = true, -- Kazakhstan
|
["kz"] = true, -- Kazakhstan
|
||||||
["la"] = true, -- Laos
|
["la"] = true, -- Laos
|
||||||
["latam"] = true, -- Latin America
|
["latam"] = true, -- Latin America
|
||||||
["latin"] = true, -- Latin
|
["latin"] = true, -- Latin
|
||||||
["lk"] = true, -- Sri Lanka
|
["lk"] = true, -- Sri Lanka
|
||||||
["lt"] = true, -- Lithuania
|
["lt"] = true, -- Lithuania
|
||||||
["lv"] = true, -- Latvia
|
["lv"] = true, -- Latvia
|
||||||
["ma"] = true, -- Morocco
|
["ma"] = true, -- Morocco
|
||||||
["mao"] = true, -- Maori
|
["mao"] = true, -- Maori
|
||||||
["me"] = true, -- Montenegro
|
["me"] = true, -- Montenegro
|
||||||
["mk"] = true, -- Macedonia
|
["mk"] = true, -- Macedonia
|
||||||
["ml"] = true, -- Mali
|
["ml"] = true, -- Mali
|
||||||
["mm"] = true, -- Myanmar
|
["mm"] = true, -- Myanmar
|
||||||
["mn"] = true, -- Mongolia
|
["mn"] = true, -- Mongolia
|
||||||
["mt"] = true, -- Malta
|
["mt"] = true, -- Malta
|
||||||
["mv"] = true, -- Maldives
|
["mv"] = true, -- Maldives
|
||||||
["ng"] = true, -- Nigeria
|
["ng"] = true, -- Nigeria
|
||||||
["nl"] = true, -- Netherlands
|
["nl"] = true, -- Netherlands
|
||||||
["no"] = true, -- Norway
|
["no"] = true, -- Norway
|
||||||
["np"] = true, -- Nepal
|
["np"] = true, -- Nepal
|
||||||
["ph"] = true, -- Philippines
|
["ph"] = true, -- Philippines
|
||||||
["pk"] = true, -- Pakistan
|
["pk"] = true, -- Pakistan
|
||||||
["pl"] = true, -- Poland
|
["pl"] = true, -- Poland
|
||||||
["pt"] = true, -- Portugal
|
["pt"] = true, -- Portugal
|
||||||
["ro"] = true, -- Romania
|
["ro"] = true, -- Romania
|
||||||
["rs"] = true, -- Serbia
|
["rs"] = true, -- Serbia
|
||||||
["ru"] = true, -- Russia
|
["ru"] = true, -- Russia
|
||||||
["se"] = true, -- Sweden
|
["se"] = true, -- Sweden
|
||||||
["si"] = true, -- Slovenia
|
["si"] = true, -- Slovenia
|
||||||
["sk"] = true, -- Slovakia
|
["sk"] = true, -- Slovakia
|
||||||
["sn"] = true, -- Senegal
|
["sn"] = true, -- Senegal
|
||||||
["sy"] = true, -- Syria
|
["sy"] = true, -- Syria
|
||||||
["th"] = true, -- Thailand
|
["th"] = true, -- Thailand
|
||||||
["tj"] = true, -- Tajikistan
|
["tj"] = true, -- Tajikistan
|
||||||
["tm"] = true, -- Turkmenistan
|
["tm"] = true, -- Turkmenistan
|
||||||
["tr"] = true, -- Turkey
|
["tr"] = true, -- Turkey
|
||||||
["tw"] = true, -- Taiwan
|
["tw"] = true, -- Taiwan
|
||||||
["tz"] = true, -- Tanzania
|
["tz"] = true, -- Tanzania
|
||||||
["ua"] = true, -- Ukraine
|
["ua"] = true, -- Ukraine
|
||||||
["us"] = true, -- USA
|
["us"] = true, -- USA
|
||||||
["uz"] = true, -- Uzbekistan
|
["uz"] = true, -- Uzbekistan
|
||||||
["vn"] = true, -- Vietnam
|
["vn"] = true, -- Vietnam
|
||||||
["za"] = true, -- South Africa
|
["za"] = true, -- South Africa
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Callback for updaing current layout
|
-- Callback for updaing current layout
|
||||||
local function update_status (self)
|
local function update_status (self)
|
||||||
self._current = awesome.xkb_get_layout_group();
|
self._current = awesome.xkb_get_layout_group();
|
||||||
local text = ""
|
local text = ""
|
||||||
if (#self._layout > 0) then
|
if (#self._layout > 0) then
|
||||||
text = (" " .. self._layout[self._current] .. " ")
|
text = (" " .. self._layout[self._current] .. " ")
|
||||||
end
|
end
|
||||||
self.widget:set_text(text)
|
self.widget:set_text(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Auxiliary function for the local function update_layout().
|
--- Auxiliary function for the local function update_layout().
|
||||||
|
@ -131,173 +131,173 @@ end
|
||||||
-- @tparam string group_names The string awesome.xkb_get_group_names() returns.
|
-- @tparam string group_names The string awesome.xkb_get_group_names() returns.
|
||||||
-- @treturn table An array of tables whose keys are vendor, file, section, and group_idx.
|
-- @treturn table An array of tables whose keys are vendor, file, section, and group_idx.
|
||||||
function keyboardlayout.get_groups_from_group_names(group_names)
|
function keyboardlayout.get_groups_from_group_names(group_names)
|
||||||
if group_names == nil then
|
if group_names == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Pattern elements to be captured.
|
-- Pattern elements to be captured.
|
||||||
local word_pat = "([%w_]+)"
|
local word_pat = "([%w_]+)"
|
||||||
local sec_pat = "(%b())"
|
local sec_pat = "(%b())"
|
||||||
local idx_pat = ":(%d)"
|
local idx_pat = ":(%d)"
|
||||||
-- Pairs of a pattern and its callback. In callbacks, set 'group_idx' to 1
|
-- Pairs of a pattern and its callback. In callbacks, set 'group_idx' to 1
|
||||||
-- and return it if there's no specification on 'group_idx' in the given
|
-- and return it if there's no specification on 'group_idx' in the given
|
||||||
-- pattern.
|
-- pattern.
|
||||||
local pattern_and_callback_pairs = {
|
local pattern_and_callback_pairs = {
|
||||||
-- vendor/file(section):group_idx
|
-- vendor/file(section):group_idx
|
||||||
["^" .. word_pat .. "/" .. word_pat .. sec_pat .. idx_pat .. "$"]
|
["^" .. word_pat .. "/" .. word_pat .. sec_pat .. idx_pat .. "$"]
|
||||||
= function(token, pattern)
|
= function(token, pattern)
|
||||||
local vendor, file, section, group_idx = string.match(token, pattern)
|
local vendor, file, section, group_idx = string.match(token, pattern)
|
||||||
return vendor, file, section, group_idx
|
return vendor, file, section, group_idx
|
||||||
end,
|
end,
|
||||||
-- vendor/file(section)
|
-- vendor/file(section)
|
||||||
["^" .. word_pat .. "/" .. word_pat .. sec_pat .. "$"]
|
["^" .. word_pat .. "/" .. word_pat .. sec_pat .. "$"]
|
||||||
= function(token, pattern)
|
= function(token, pattern)
|
||||||
local vendor, file, section = string.match(token, pattern)
|
local vendor, file, section = string.match(token, pattern)
|
||||||
return vendor, file, section, 1
|
return vendor, file, section, 1
|
||||||
end,
|
end,
|
||||||
-- vendor/file:group_idx
|
-- vendor/file:group_idx
|
||||||
["^" .. word_pat .. "/" .. word_pat .. idx_pat .. "$"]
|
["^" .. word_pat .. "/" .. word_pat .. idx_pat .. "$"]
|
||||||
= function(token, pattern)
|
= function(token, pattern)
|
||||||
local vendor, file, group_idx = string.match(token, pattern)
|
local vendor, file, group_idx = string.match(token, pattern)
|
||||||
return vendor, file, nil, group_idx
|
return vendor, file, nil, group_idx
|
||||||
end,
|
end,
|
||||||
-- vendor/file
|
-- vendor/file
|
||||||
["^" .. word_pat .. "/" .. word_pat .. "$"]
|
["^" .. word_pat .. "/" .. word_pat .. "$"]
|
||||||
= function(token, pattern)
|
= function(token, pattern)
|
||||||
local vendor, file = string.match(token, pattern)
|
local vendor, file = string.match(token, pattern)
|
||||||
return vendor, file, nil, 1
|
return vendor, file, nil, 1
|
||||||
end,
|
end,
|
||||||
-- file(section):group_idx
|
-- file(section):group_idx
|
||||||
["^" .. word_pat .. sec_pat .. idx_pat .. "$"]
|
["^" .. word_pat .. sec_pat .. idx_pat .. "$"]
|
||||||
= function(token, pattern)
|
= function(token, pattern)
|
||||||
local file, section, group_idx = string.match(token, pattern)
|
local file, section, group_idx = string.match(token, pattern)
|
||||||
return nil, file, section, group_idx
|
return nil, file, section, group_idx
|
||||||
end,
|
end,
|
||||||
-- file(section)
|
-- file(section)
|
||||||
["^" .. word_pat .. sec_pat .. "$"]
|
["^" .. word_pat .. sec_pat .. "$"]
|
||||||
= function(token, pattern)
|
= function(token, pattern)
|
||||||
local file, section = string.match(token, pattern)
|
local file, section = string.match(token, pattern)
|
||||||
return nil, file, section, 1
|
return nil, file, section, 1
|
||||||
end,
|
end,
|
||||||
-- file:group_idx
|
-- file:group_idx
|
||||||
["^" .. word_pat .. idx_pat .. "$"]
|
["^" .. word_pat .. idx_pat .. "$"]
|
||||||
= function(token, pattern)
|
= function(token, pattern)
|
||||||
local file, group_idx = string.match(token, pattern)
|
local file, group_idx = string.match(token, pattern)
|
||||||
return nil, file, nil, group_idx
|
return nil, file, nil, group_idx
|
||||||
end,
|
end,
|
||||||
-- file
|
-- file
|
||||||
["^" .. word_pat .. "$"]
|
["^" .. word_pat .. "$"]
|
||||||
= function(token, pattern)
|
= function(token, pattern)
|
||||||
local file = string.match(token, pattern)
|
local file = string.match(token, pattern)
|
||||||
return nil, file, nil, 1
|
return nil, file, nil, 1
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Split 'group_names' into 'tokens'. The separator is "+".
|
|
||||||
local tokens = {}
|
|
||||||
string.gsub(group_names, "[^+]+", function(match)
|
|
||||||
table.insert(tokens, match)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- For each token in 'tokens', check if it matches one of the patterns in
|
|
||||||
-- the array 'pattern_and_callback_pairs', where the patterns are used as
|
|
||||||
-- key. If a match is found, extract captured strings using the
|
|
||||||
-- corresponding callback function. Check if those extracted is country
|
|
||||||
-- specific part of a layout. If so, add it to 'layout_groups'; otherwise,
|
|
||||||
-- ignore it.
|
|
||||||
local layout_groups = {}
|
|
||||||
for i = 1, #tokens do
|
|
||||||
for pattern, callback in pairs(pattern_and_callback_pairs) do
|
|
||||||
local vendor, file, section, group_idx = callback(tokens[i], pattern)
|
|
||||||
if file then
|
|
||||||
if not keyboardlayout.xkeyboard_country_code[file] then
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
}
|
||||||
|
|
||||||
if section then
|
-- Split 'group_names' into 'tokens'. The separator is "+".
|
||||||
section = string.gsub(section, "%(([%w_]+)%)", "%1")
|
local tokens = {}
|
||||||
|
string.gsub(group_names, "[^+]+", function(match)
|
||||||
|
table.insert(tokens, match)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- For each token in 'tokens', check if it matches one of the patterns in
|
||||||
|
-- the array 'pattern_and_callback_pairs', where the patterns are used as
|
||||||
|
-- key. If a match is found, extract captured strings using the
|
||||||
|
-- corresponding callback function. Check if those extracted is country
|
||||||
|
-- specific part of a layout. If so, add it to 'layout_groups'; otherwise,
|
||||||
|
-- ignore it.
|
||||||
|
local layout_groups = {}
|
||||||
|
for i = 1, #tokens do
|
||||||
|
for pattern, callback in pairs(pattern_and_callback_pairs) do
|
||||||
|
local vendor, file, section, group_idx = callback(tokens[i], pattern)
|
||||||
|
if file then
|
||||||
|
if not keyboardlayout.xkeyboard_country_code[file] then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
if section then
|
||||||
|
section = string.gsub(section, "%(([%w_]+)%)", "%1")
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(layout_groups, { vendor = vendor,
|
||||||
|
file = file,
|
||||||
|
section = section,
|
||||||
|
group_idx = tonumber(group_idx) })
|
||||||
|
break
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
table.insert(layout_groups, { vendor = vendor,
|
return layout_groups
|
||||||
file = file,
|
|
||||||
section = section,
|
|
||||||
group_idx = tonumber(group_idx) })
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return layout_groups
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Callback for updating list of layouts
|
-- Callback for updating list of layouts
|
||||||
local function update_layout(self)
|
local function update_layout(self)
|
||||||
self._layout = {};
|
self._layout = {};
|
||||||
local layouts = keyboardlayout.get_groups_from_group_names(awesome.xkb_get_group_names())
|
local layouts = keyboardlayout.get_groups_from_group_names(awesome.xkb_get_group_names())
|
||||||
if layouts == nil or layouts[1] == nil then
|
if layouts == nil or layouts[1] == nil then
|
||||||
error("Failed to get list of keyboard groups")
|
error("Failed to get list of keyboard groups")
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
if #layouts == 1 then
|
if #layouts == 1 then
|
||||||
layouts[1].group_idx = 0
|
layouts[1].group_idx = 0
|
||||||
end
|
end
|
||||||
for _, v in ipairs(layouts) do
|
for _, v in ipairs(layouts) do
|
||||||
local layout_name = v.file
|
local layout_name = v.file
|
||||||
if v.section ~= nil then
|
if v.section ~= nil then
|
||||||
layout_name = layout_name .. "(" .. v.section .. ")"
|
layout_name = layout_name .. "(" .. v.section .. ")"
|
||||||
end
|
end
|
||||||
-- Please note that numbers of groups reported by xkb_get_group_names
|
-- Please note that numbers of groups reported by xkb_get_group_names
|
||||||
-- is greater by one than the real group number.
|
-- is greater by one than the real group number.
|
||||||
self._layout[v.group_idx - 1] = layout_name
|
self._layout[v.group_idx - 1] = layout_name
|
||||||
end
|
end
|
||||||
update_status(self)
|
update_status(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create a keyboard layout widget. It shows current keyboard layout name in a textbox.
|
--- Create a keyboard layout widget. It shows current keyboard layout name in a textbox.
|
||||||
-- @return A keyboard layout widget.
|
-- @return A keyboard layout widget.
|
||||||
function keyboardlayout.new()
|
function keyboardlayout.new()
|
||||||
local widget = textbox()
|
local widget = textbox()
|
||||||
local self = widget_base.make_widget(widget)
|
local self = widget_base.make_widget(widget)
|
||||||
|
|
||||||
self.widget = widget
|
self.widget = widget
|
||||||
|
|
||||||
update_layout(self);
|
update_layout(self);
|
||||||
|
|
||||||
self.next_layout = function()
|
self.next_layout = function()
|
||||||
new_layout = (self._current + 1) % (#self._layout + 1)
|
new_layout = (self._current + 1) % (#self._layout + 1)
|
||||||
self.set_layout(new_layout)
|
self.set_layout(new_layout)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.set_layout = function(group_number)
|
self.set_layout = function(group_number)
|
||||||
if (0 > group_number) or (group_number > #self._layout) then
|
if (0 > group_number) or (group_number > #self._layout) then
|
||||||
error("Invalid group number: " .. group_number ..
|
error("Invalid group number: " .. group_number ..
|
||||||
"expected number from 0 to " .. #self._layout)
|
"expected number from 0 to " .. #self._layout)
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
awesome.xkb_set_layout_group(group_number);
|
awesome.xkb_set_layout_group(group_number);
|
||||||
end
|
end
|
||||||
|
|
||||||
-- callback for processing layout changes
|
-- callback for processing layout changes
|
||||||
capi.awesome.connect_signal("xkb::map_changed",
|
capi.awesome.connect_signal("xkb::map_changed",
|
||||||
function () update_layout(self) end)
|
function () update_layout(self) end)
|
||||||
capi.awesome.connect_signal("xkb::group_changed",
|
capi.awesome.connect_signal("xkb::group_changed",
|
||||||
function () update_status(self) end);
|
function () update_status(self) end);
|
||||||
|
|
||||||
-- Mouse bindings
|
-- Mouse bindings
|
||||||
self:buttons(
|
self:buttons(
|
||||||
util.table.join(button({ }, 1, self.next_layout))
|
util.table.join(button({ }, 1, self.next_layout))
|
||||||
)
|
)
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
local _instance = nil;
|
local _instance = nil;
|
||||||
|
|
||||||
function keyboardlayout.mt:__call(...)
|
function keyboardlayout.mt:__call(...)
|
||||||
if _instance == nil then
|
if _instance == nil then
|
||||||
_instance = keyboardlayout.new(...)
|
_instance = keyboardlayout.new(...)
|
||||||
end
|
end
|
||||||
return _instance
|
return _instance
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(keyboardlayout, keyboardlayout.mt)
|
return setmetatable(keyboardlayout, keyboardlayout.mt)
|
||||||
|
|
Loading…
Reference in New Issue