Merge pull request #789 from aroig/gh/layout-names

fixes to keyboard layout names
This commit is contained in:
Emmanuel Lepage Vallée 2016-03-31 00:30:35 -04:00
commit fdc25bbb99
2 changed files with 14 additions and 6 deletions

View File

@ -214,7 +214,7 @@ function keyboardlayout.get_groups_from_group_names(group_names)
end end
if section then if section then
section = string.gsub(section, "%(([%w_]+)%)", "%1") section = string.gsub(section, "%(([%w-_]+)%)", "%1")
end end
table.insert(layout_groups, { vendor = vendor, table.insert(layout_groups, { vendor = vendor,
@ -241,10 +241,7 @@ local function update_layout(self)
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 = self.layout_name(v)
if v.section ~= nil then
layout_name = layout_name .. "(" .. v.section .. ")"
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
@ -260,7 +257,13 @@ function keyboardlayout.new()
self.widget = widget self.widget = widget
update_layout(self); self.layout_name = function(v)
local name = v.file
if v.section ~= nil then
name = name .. "(" .. v.section .. ")"
end
return name
end
self.next_layout = function() self.next_layout = function()
self.set_layout((self._current + 1) % (#self._layout + 1)) self.set_layout((self._current + 1) % (#self._layout + 1))
@ -275,6 +278,8 @@ function keyboardlayout.new()
awesome.xkb_set_layout_group(group_number); awesome.xkb_set_layout_group(group_number);
end end
update_layout(self);
-- 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)

View File

@ -23,6 +23,9 @@ describe("awful.widget.keyboardlayout get_groups_from_group_names", function()
{ file = "de", group_idx = 1 }, { file = "de", group_idx = 1 },
{ file = "jp", group_idx = 1 } { file = "jp", group_idx = 1 }
}, },
["us(altgr-intl)"] = {
{ file = "us", group_idx = 1, section = "altgr-intl" }
},
-- possible eight variations of a single term -- possible eight variations of a single term
["de"] = { ["de"] = {
{ file = "de", group_idx = 1 } { file = "de", group_idx = 1 }