Merge lp:~davidmhewitt/wingpanel-indicator-keyboard/fix-1650986-xml-config into lp:~wingpanel-devs/wingpanel-indicator-keyboard/trunk

Proposed by David Hewitt on 2017-02-18
Status: Merged
Approved by: Daniel Fore on 2017-02-26
Approved revision: 67
Merged at revision: 66
Proposed branch: lp:~davidmhewitt/wingpanel-indicator-keyboard/fix-1650986-xml-config
Merge into: lp:~wingpanel-devs/wingpanel-indicator-keyboard/trunk
Diff against target: 125 lines (+35/-55)
2 files modified
src/CMakeLists.txt (+2/-1)
src/LayoutsManager.vala (+33/-54)
To merge this branch: bzr merge lp:~davidmhewitt/wingpanel-indicator-keyboard/fix-1650986-xml-config
Reviewer Review Type Date Requested Status
Santiago code 2017-02-18 Approve on 2017-02-25
WingPanel Devs 2017-02-18 Pending
Review via email: mp+317703@code.launchpad.net

Commit message

Load XKB config names from evdev.xml instead of evdev.lst

Description of the change

The list of XKB keyboard configurations was being read from evdev.lst. All documentation online about how to create keyboard maps refers to creating them in evdev.xml.

I checked and both files contain the exact same base configurations for every language and keymap. But, it's likely that any custom or new keyboard maps will be added to the XML files.

This branch should have no functionality impact whatsoever for the average user. But for the case in the attached bug, where custom layouts are not displayed, this branch resolves that.

To be able to add a custom keyboard map, you must be running a version of the keyboard plug that supports loading configs from XML too. See the following branch:
https://code.launchpad.net/~davidmhewitt/switchboard-plug-keyboard/fix-1650986-load-xml-config/+merge/317412

To post a comment you must log in.
67. By David Hewitt on 2017-02-25

Improved code based on Santiago's comments

Santiago (santileortiz) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2016-04-20 21:02:50 +0000
3+++ src/CMakeLists.txt 2017-02-25 10:48:25 +0000
4@@ -1,7 +1,7 @@
5 find_package (PkgConfig)
6
7 # Add all your dependencies to the list below
8-pkg_check_modules (DEPS REQUIRED wingpanel-2.0 granite)
9+pkg_check_modules (DEPS REQUIRED wingpanel-2.0 granite libxml-2.0)
10
11 add_definitions (${DEPS_CFLAGS})
12 link_directories (${DEPS_LIBRARY_DIRS})
13@@ -21,6 +21,7 @@
14 PACKAGES
15 wingpanel-2.0
16 granite
17+ libxml-2.0
18 OPTIONS
19 --thread
20 )
21
22=== modified file 'src/LayoutsManager.vala'
23--- src/LayoutsManager.vala 2016-04-20 21:02:50 +0000
24+++ src/LayoutsManager.vala 2017-02-25 10:48:25 +0000
25@@ -94,67 +94,46 @@
26 }
27
28 public string? get_name_for_xkb_layout (string language, string? variant) {
29- var file = File.new_for_path ("/usr/share/X11/xkb/rules/evdev.lst");
30-
31- if (!file.query_exists ()) {
32- critical ("File '%s' doesn't exist.", file.get_path ());
33+ debug (@"get_name_for_xkb_layout ($language $variant)");
34+ Xml.Doc* doc = Xml.Parser.parse_file ("/usr/share/X11/xkb/rules/evdev.xml");
35+ if (doc == null) {
36+ critical ("'evdev.xml' not found or permissions incorrect\n");
37 return null;
38 }
39
40+ Xml.XPath.Context cntx = new Xml.XPath.Context (doc);
41+ string xpath = "";
42+
43 if (variant == null) {
44- try {
45- var dis = new DataInputStream (file.read ());
46- string line;
47- bool layout_found = false;
48- while ((line = dis.read_line (null)) != null) {
49- if (layout_found) {
50- if ("!" in line || line == "") {
51- break;
52- }
53-
54- var parts = line.chug ().split (" ", 2);
55- if (parts[0] == language) {
56- return dgettext ("xkeyboard-config", parts[1].chug ());
57- }
58- } else {
59- if ("!" in line && "layout" in line) {
60- layout_found = true;
61- }
62- }
63- }
64- } catch (Error e) {
65- error ("%s", e.message);
66- }
67-
68- return null;
69+ xpath = @"/xkbConfigRegistry/layoutList/layout/configItem/name[text()='$language']/../description";
70 } else {
71- try {
72- var dis = new DataInputStream (file.read ());
73- string line;
74- bool variant_found = false;
75- while ((line = dis.read_line (null)) != null) {
76- if (variant_found) {
77- if ("!" in line || line == "") {
78- break;
79- }
80-
81- var parts = line.chug ().split (" ", 2);
82- var subparts = parts[1].chug ().split (":", 2);
83- if (subparts[0] == language && parts[0] == variant) {
84- return dgettext ("xkeyboard-config", subparts[1].chug ());
85- }
86- } else {
87- if ("!" in line && "variant" in line) {
88- variant_found = true;
89- }
90- }
91- }
92- } catch (Error e) {
93- error ("%s", e.message);
94- }
95-
96+ xpath = @"/xkbConfigRegistry/layoutList/layout/configItem/name[text()='$language']/../../variantList/variant/configItem/name[text()='$variant']/../description";
97+ }
98+
99+ Xml.XPath.Object* res = cntx.eval_expression (xpath);
100+
101+ if (res == null) {
102+ delete doc;
103+ critical ("Unable to parse 'evdev.xml'");
104+ return null;
105+ }
106+
107+ if (res->type != Xml.XPath.ObjectType.NODESET || res->nodesetval == null) {
108+ delete res;
109+ delete doc;
110+ warning (@"No name for $language:$variant found in 'evdev.xml'");
111 return null;
112 }
113+
114+ string? name = null;
115+ Xml.Node* node = res->nodesetval->item (0);
116+ if (node != null) {
117+ name = dgettext ("xkeyboard-config", node->get_content ());
118+ }
119+
120+ delete res;
121+ delete doc;
122+ return name;
123 }
124
125 public string get_current (bool shorten = false) {

Subscribers

People subscribed via source and target branches

to all changes: