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
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2016-04-20 21:02:50 +0000
+++ src/CMakeLists.txt 2017-02-25 10:48:25 +0000
@@ -1,7 +1,7 @@
1find_package (PkgConfig)1find_package (PkgConfig)
22
3# Add all your dependencies to the list below3# Add all your dependencies to the list below
4pkg_check_modules (DEPS REQUIRED wingpanel-2.0 granite)4pkg_check_modules (DEPS REQUIRED wingpanel-2.0 granite libxml-2.0)
55
6add_definitions (${DEPS_CFLAGS})6add_definitions (${DEPS_CFLAGS})
7link_directories (${DEPS_LIBRARY_DIRS})7link_directories (${DEPS_LIBRARY_DIRS})
@@ -21,6 +21,7 @@
21PACKAGES21PACKAGES
22 wingpanel-2.022 wingpanel-2.0
23 granite23 granite
24 libxml-2.0
24OPTIONS25OPTIONS
25 --thread26 --thread
26)27)
2728
=== modified file 'src/LayoutsManager.vala'
--- src/LayoutsManager.vala 2016-04-20 21:02:50 +0000
+++ src/LayoutsManager.vala 2017-02-25 10:48:25 +0000
@@ -94,67 +94,46 @@
94 }94 }
9595
96 public string? get_name_for_xkb_layout (string language, string? variant) {96 public string? get_name_for_xkb_layout (string language, string? variant) {
97 var file = File.new_for_path ("/usr/share/X11/xkb/rules/evdev.lst");97 debug (@"get_name_for_xkb_layout ($language $variant)");
9898 Xml.Doc* doc = Xml.Parser.parse_file ("/usr/share/X11/xkb/rules/evdev.xml");
99 if (!file.query_exists ()) {99 if (doc == null) {
100 critical ("File '%s' doesn't exist.", file.get_path ());100 critical ("'evdev.xml' not found or permissions incorrect\n");
101 return null;101 return null;
102 }102 }
103103
104 Xml.XPath.Context cntx = new Xml.XPath.Context (doc);
105 string xpath = "";
106
104 if (variant == null) {107 if (variant == null) {
105 try {108 xpath = @"/xkbConfigRegistry/layoutList/layout/configItem/name[text()='$language']/../description";
106 var dis = new DataInputStream (file.read ());
107 string line;
108 bool layout_found = false;
109 while ((line = dis.read_line (null)) != null) {
110 if (layout_found) {
111 if ("!" in line || line == "") {
112 break;
113 }
114
115 var parts = line.chug ().split (" ", 2);
116 if (parts[0] == language) {
117 return dgettext ("xkeyboard-config", parts[1].chug ());
118 }
119 } else {
120 if ("!" in line && "layout" in line) {
121 layout_found = true;
122 }
123 }
124 }
125 } catch (Error e) {
126 error ("%s", e.message);
127 }
128
129 return null;
130 } else {109 } else {
131 try {110 xpath = @"/xkbConfigRegistry/layoutList/layout/configItem/name[text()='$language']/../../variantList/variant/configItem/name[text()='$variant']/../description";
132 var dis = new DataInputStream (file.read ());111 }
133 string line;112
134 bool variant_found = false;113 Xml.XPath.Object* res = cntx.eval_expression (xpath);
135 while ((line = dis.read_line (null)) != null) {114
136 if (variant_found) {115 if (res == null) {
137 if ("!" in line || line == "") {116 delete doc;
138 break;117 critical ("Unable to parse 'evdev.xml'");
139 }118 return null;
140119 }
141 var parts = line.chug ().split (" ", 2);120
142 var subparts = parts[1].chug ().split (":", 2);121 if (res->type != Xml.XPath.ObjectType.NODESET || res->nodesetval == null) {
143 if (subparts[0] == language && parts[0] == variant) {122 delete res;
144 return dgettext ("xkeyboard-config", subparts[1].chug ());123 delete doc;
145 }124 warning (@"No name for $language:$variant found in 'evdev.xml'");
146 } else {
147 if ("!" in line && "variant" in line) {
148 variant_found = true;
149 }
150 }
151 }
152 } catch (Error e) {
153 error ("%s", e.message);
154 }
155
156 return null;125 return null;
157 }126 }
127
128 string? name = null;
129 Xml.Node* node = res->nodesetval->item (0);
130 if (node != null) {
131 name = dgettext ("xkeyboard-config", node->get_content ());
132 }
133
134 delete res;
135 delete doc;
136 return name;
158 }137 }
159138
160 public string get_current (bool shorten = false) {139 public string get_current (bool shorten = false) {

Subscribers

People subscribed via source and target branches

to all changes: