Merge lp:~attente/indicator-keyboard/unity-greeter-default-layout into lp:indicator-keyboard

Proposed by William Hua
Status: Merged
Approved by: Ted Gould
Approved revision: 124
Merged at revision: 125
Proposed branch: lp:~attente/indicator-keyboard/unity-greeter-default-layout
Merge into: lp:indicator-keyboard
Diff against target: 250 lines (+177/-12)
3 files modified
lib/Makefile.am (+4/-3)
lib/greeter.vala (+26/-0)
lib/main.vala (+147/-9)
To merge this branch: bzr merge lp:~attente/indicator-keyboard/unity-greeter-default-layout
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Ted Gould (community) Approve
Michael Terry Approve
Review via email: mp+188756@code.launchpad.net

Commit message

Set the selected user's first keyboard layout whenever it changes under unity-greeter. (LP #1233945)

Description of the change

Set the selected user's first keyboard layout whenever it changes under unity-greeter. (LP #1233945)

This needs https://code.launchpad.net/~attente/unity-greeter/entry-selected-signal/+merge/188755 to actually work.

To post a comment you must log in.
122. By William Hua

ocd

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
123. By William Hua

Get greeter unique bus name from environment.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
124. By William Hua

Switch to default layout for non-users in unity-greeter.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Terry (mterry) wrote :

This works for me. I don't want to top-approve because I'm not on the indicator team, but it's fine from an end-user standpoint.

review: Approve
Revision history for this message
Ted Gould (ted) wrote :

Code looks fine. If it works for mterry, that's good enough for me.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Makefile.am'
2--- lib/Makefile.am 2013-08-07 20:20:23 +0000
3+++ lib/Makefile.am 2013-10-02 18:56:23 +0000
4@@ -6,9 +6,10 @@
5 --metadatadir $(top_srcdir)/deps \
6 --vapidir $(top_srcdir)/deps
7
8-indicator_keyboard_service_SOURCES = main.vala \
9- source.vala \
10- common.vala
11+indicator_keyboard_service_SOURCES = main.vala \
12+ source.vala \
13+ common.vala \
14+ greeter.vala
15 indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \
16 --pkg gee-1.0 \
17 --pkg posix \
18
19=== added file 'lib/greeter.vala'
20--- lib/greeter.vala 1970-01-01 00:00:00 +0000
21+++ lib/greeter.vala 2013-10-02 18:56:23 +0000
22@@ -0,0 +1,26 @@
23+/*
24+ * Copyright 2013 Canonical Ltd.
25+ *
26+ * This program is free software: you can redistribute it and/or modify
27+ * it under the terms of the GNU General Public License as published by
28+ * the Free Software Foundation, version 3 of the License.
29+ *
30+ * This program is distributed in the hope that it will be useful,
31+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
32+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33+ * GNU General Public License for more details.
34+ *
35+ * You should have received a copy of the GNU General Public License
36+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
37+ *
38+ * Authors: William Hua <william.hua@canonical.com>
39+ */
40+
41+[DBus (name="com.canonical.UnityGreeter.List")]
42+public interface Greeter : Object {
43+
44+ public abstract string get_active_entry () throws IOError;
45+ public abstract void set_active_entry (string entry_name) throws IOError;
46+
47+ public signal void entry_selected (string entry_name);
48+}
49
50=== modified file 'lib/main.vala'
51--- lib/main.vala 2013-09-21 15:55:33 +0000
52+++ lib/main.vala 2013-10-02 18:56:23 +0000
53@@ -41,6 +41,8 @@
54 private MenuModel? menu_model;
55 private Menu? sources_menu;
56
57+ private Greeter? greeter;
58+ private string? greeter_user;
59 private uint lightdm_current;
60
61 [DBus (visible = false)]
62@@ -55,6 +57,18 @@
63 Gdk.init (ref args);
64 }
65
66+ if (is_login_user ()) {
67+ var name = Environment.get_variable ("UNITY_GREETER_DBUS_NAME");
68+
69+ if (name != null) {
70+ Bus.watch_name (BusType.SESSION,
71+ (!) name,
72+ BusNameWatcherFlags.NONE,
73+ handle_name_appeared,
74+ handle_name_vanished);
75+ }
76+ }
77+
78 indicator_settings = new Settings ("com.canonical.indicator.keyboard");
79 indicator_settings.changed["visible"].connect (handle_changed_visible);
80
81@@ -112,6 +126,108 @@
82 }
83
84 [DBus (visible = false)]
85+ private void update_greeter_user () {
86+ if (greeter_user == null && greeter != null) {
87+ try {
88+ greeter_user = ((!) greeter).get_active_entry ();
89+ } catch (IOError error) {
90+ warning ("error: %s", error.message);
91+ }
92+ }
93+
94+ string? source = null;
95+
96+ if (greeter_user != null) {
97+ var manager = Act.UserManager.get_default ();
98+
99+ if (manager.is_loaded) {
100+ Act.User? user = manager.get_user ((!) greeter_user);
101+
102+ if (user != null && ((!) user).is_loaded) {
103+ VariantIter outer;
104+ VariantIter inner;
105+
106+ var sources = ((!) user).input_sources;
107+ sources.get ("aa{ss}", out outer);
108+
109+ while (outer.next ("a{ss}", out inner)) {
110+ unowned string key;
111+ unowned string value;
112+
113+ while (inner.next ("{&s&s}", out key, out value)) {
114+ if (key == "xkb") {
115+ source = value;
116+ break;
117+ }
118+ }
119+
120+ if (source != null) {
121+ break;
122+ }
123+ }
124+
125+ if (source == null) {
126+ var layouts = ((!) user).xkeyboard_layouts;
127+
128+ if (layouts.length <= 0) {
129+ var user_list = LightDM.UserList.get_instance ();
130+ LightDM.User? light_user = user_list.get_user_by_name ((!) greeter_user);
131+
132+ if (light_user != null) {
133+ layouts = ((!) light_user).get_layouts ();
134+ }
135+ }
136+
137+ if (layouts.length > 0) {
138+ source = layouts[0];
139+ source = ((!) source).replace (" ", "+");
140+ source = ((!) source).replace ("\t", "+");
141+ }
142+ }
143+ }
144+ }
145+ }
146+
147+ if (source == null) {
148+ LightDM.Layout? layout = LightDM.get_layout ();
149+
150+ if (layout != null) {
151+ source = ((!) layout).name;
152+
153+ if (source != null) {
154+ source = ((!) source).replace (" ", "+");
155+ source = ((!) source).replace ("\t", "+");
156+ }
157+ }
158+ }
159+
160+ if (source != null) {
161+ var array = source_settings.get_value ("sources");
162+
163+ for (int i = 0; i < array.n_children (); i++) {
164+ unowned string type;
165+ unowned string name;
166+
167+ array.get_child (i, "(&s&s)", out type, out name);
168+
169+ if (type == "xkb" && name == (!) source) {
170+ source_settings.set_uint ("current", i);
171+ break;
172+ }
173+ }
174+ }
175+ }
176+
177+ [DBus (visible = false)]
178+ private void handle_entry_selected (string entry_name) {
179+ if (greeter_user == null || entry_name != (!) greeter_user) {
180+ greeter_user = entry_name;
181+
182+ update_greeter_user ();
183+ }
184+ }
185+
186+ [DBus (visible = false)]
187 private void migrate_keyboard_layouts () {
188 if (is_login_user ()) {
189 lightdm_current = source_settings.get_uint ("current");
190@@ -285,15 +401,20 @@
191 }
192 }
193
194- var layout = LightDM.get_layout ();
195-
196- var source = layout.name;
197- source = source.replace (" ", "+");
198- source = source.replace ("\t", "+");
199-
200- if (!added.contains (source)) {
201- list.add (source);
202- added.add (source);
203+ LightDM.Layout? layout = LightDM.get_layout ();
204+
205+ if (layout != null) {
206+ string? source = ((!) layout).name;
207+
208+ if (source != null) {
209+ source = ((!) source).replace (" ", "+");
210+ source = ((!) source).replace ("\t", "+");
211+
212+ if (!added.contains ((!) source)) {
213+ list.add ((!) source);
214+ added.add ((!) source);
215+ }
216+ }
217 }
218
219 var builder = new VariantBuilder (new VariantType ("a(ss)"));
220@@ -309,6 +430,8 @@
221 }
222
223 source_settings.set_value ("sources", builder.end ());
224+
225+ update_greeter_user ();
226 }
227
228 [DBus (visible = false)]
229@@ -617,6 +740,21 @@
230 }
231
232 [DBus (visible = false)]
233+ private void handle_name_appeared (DBusConnection connection, string name, string name_owner) {
234+ try {
235+ greeter = Bus.get_proxy_sync (BusType.SESSION, name, "/list");
236+ ((!) greeter).entry_selected.connect (handle_entry_selected);
237+ } catch (IOError error) {
238+ warning ("error: %s", error.message);
239+ }
240+ }
241+
242+ [DBus (visible = false)]
243+ private void handle_name_vanished (DBusConnection connection, string name) {
244+ greeter = null;
245+ }
246+
247+ [DBus (visible = false)]
248 private void handle_bus_acquired (DBusConnection connection, string name) {
249 try {
250 connection.export_action_group ("/com/canonical/indicator/keyboard", get_action_group ());

Subscribers

People subscribed via source and target branches

to all changes: