Merge lp:~mterry/unity-greeter/keyboard-indicator into lp:unity-greeter

Proposed by Michael Terry
Status: Merged
Merged at revision: 244
Proposed branch: lp:~mterry/unity-greeter/keyboard-indicator
Merge into: lp:unity-greeter
Diff against target: 262 lines (+137/-26)
2 files modified
src/unity-greeter.vala (+27/-14)
src/user-list.vala (+110/-12)
To merge this branch: bzr merge lp:~mterry/unity-greeter/keyboard-indicator
Reviewer Review Type Date Requested Status
Robert Ancell Approve
Review via email: mp+86442@code.launchpad.net

Description of the change

Adds a keyboard indicator. Requires a fix to lightdm first: https://code.launchpad.net/~mterry/lightdm/fix-get-layout/+merge/86427

To post a comment you must log in.
Revision history for this message
Haggai Eran (haggai-eran) wrote :

Hi,

I think this works nicely, for switching layout in the greeter.(I've tried it without updating lightdm, so I'm not sure if it was supposed to work, but it did.) But I think there are two issues with this patch:
First, I'm not sure it is a good idea to show all the keyboard layouts available in the system. If an administrator sets the system-wide layouts as some set of layouts, I think showing that set would be enough (or perhaps moving the rest of the layouts to a second level menu).
In addition, other system-wide settings related to keyboard layouts aren't honored, such as the layout switch key.

Currently it seems that you cannot set system-wide settings graphically (see bug #854714), but you could still have such settings when upgrading from a previous release, or maybe using console-setup configuration.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Committed with small changes to style (brace on end of line, use of var instead of weak references). There's definitely too many items in the list, but there's not an obvious way of chosing which layouts to show so we should solve that as a separate patch. Haggai, can you open a bug for that?

review: Approve
Revision history for this message
Haggai Eran (haggai-eran) wrote :

Sure, I'll open a new bug.

Revision history for this message
Martin Pitt (pitti) wrote :

This introduced a major regression, see bug 783827.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-greeter.vala'
2--- src/unity-greeter.vala 2011-12-09 18:06:18 +0000
3+++ src/unity-greeter.vala 2011-12-20 18:06:39 +0000
4@@ -131,15 +131,15 @@
5
6 if (test_mode)
7 {
8- user_list.add_entry ("alice", "가나다라마", "/usr/share/backgrounds/Darkening_Clockwork_by_Matt_Katzenberger.jpg", true);
9- user_list.add_entry ("chris", "Christopher Halse Rogers!!!!!!!!!!!!!!!", "/usr/share/backgrounds/Darkening_Clockwork_by_Matt_Katzenberger.jpg", true);
10- user_list.add_entry ("jorge", "Jorge O Castro", "/usr/share/backgrounds/PurpleDancers_by_Emilio_Merlino.jpg");
11- user_list.add_entry ("ken", "Ken VanDine", "/usr/share/backgrounds/Small_flowers_by_Dariusz_Duma.jpg");
12- user_list.add_entry ("matthew", "Matthew Paul Thomas", "/usr/share/backgrounds/Not_Alone_by_Deacon_MacMillan.jpg");
13- user_list.add_entry ("otto", "Otto Greenslade", "/usr/share/backgrounds/Mount_Snowdon,_Wales_by_Adam_Vellender.jpg");
14- user_list.add_entry ("pitti", "Martin Pitt", "/usr/share/backgrounds/Stalking_Ocelot_by_Sayantan_Chaudhuri.jpg");
15- user_list.add_entry ("desrt", "Ryan Lortie", "/usr/share/backgrounds/Power_of_Words_by_Antonio_Litterio.jpg");
16- user_list.add_entry ("*guest", _("Guest Session"), null, true);
17+ user_list.add_entry ("alice", "가나다라마", "/usr/share/backgrounds/Darkening_Clockwork_by_Matt_Katzenberger.jpg", get_layout_by_name ("cn"), true);
18+ user_list.add_entry ("chris", "Christopher Halse Rogers!!!!!!!!!!!!!!!", "/usr/share/backgrounds/Darkening_Clockwork_by_Matt_Katzenberger.jpg", null, true);
19+ user_list.add_entry ("jorge", "Jorge O Castro", "/usr/share/backgrounds/PurpleDancers_by_Emilio_Merlino.jpg", get_layout_by_name ("us"));
20+ user_list.add_entry ("ken", "Ken VanDine", "/usr/share/backgrounds/Small_flowers_by_Dariusz_Duma.jpg", get_layout_by_name ("uk"));
21+ user_list.add_entry ("matthew", "Matthew Paul Thomas", "/usr/share/backgrounds/Not_Alone_by_Deacon_MacMillan.jpg", get_layout_by_name ("uk"));
22+ user_list.add_entry ("otto", "Otto Greenslade", "/usr/share/backgrounds/Mount_Snowdon,_Wales_by_Adam_Vellender.jpg", get_layout_by_name ("uk"));
23+ user_list.add_entry ("pitti", "Martin Pitt", "/usr/share/backgrounds/Stalking_Ocelot_by_Sayantan_Chaudhuri.jpg", get_layout_by_name ("de"));
24+ user_list.add_entry ("desrt", "Ryan Lortie", "/usr/share/backgrounds/Power_of_Words_by_Antonio_Litterio.jpg", get_layout_by_name ("ca"));
25+ user_list.add_entry ("*guest", _("Guest Session"), null, null, true);
26
27 user_list.add_session ("gnome", "Ubuntu");
28 user_list.add_session ("gnome-shell", "GNOME");
29@@ -151,7 +151,7 @@
30 else
31 {
32 if (greeter.hide_users_hint)
33- user_list.add_entry ("*other", _("Login"), null);
34+ user_list.add_entry ("*other", _("Login"), null, null);
35 else
36 {
37 var users = LightDM.UserList.get_instance ();
38@@ -165,7 +165,7 @@
39 if (greeter.has_guest_account_hint)
40 {
41 debug ("Adding guest account entry");
42- user_list.add_entry ("*guest", _("Guest Session"), null);
43+ user_list.add_entry ("*guest", _("Guest Session"), null, null);
44 }
45
46 if (greeter.select_user_hint != null)
47@@ -179,7 +179,18 @@
48 user_list.start_session.connect (start_session_cb);
49 user_selected_cb (user_list.selected);
50 }
51-
52+
53+ private LightDM.Layout? get_layout_by_name (string name)
54+ {
55+ unowned GLib.List<weak LightDM.Layout> layouts = LightDM.get_layouts ();
56+ foreach (weak LightDM.Layout layout in layouts)
57+ {
58+ if (layout.name == name)
59+ return layout;
60+ }
61+ return null;
62+ }
63+
64 private void monitors_changed_cb (Gdk.Screen screen)
65 {
66 Gdk.Rectangle geometry;
67@@ -199,7 +210,9 @@
68 if (user.real_name == "")
69 label = user.name;
70
71- user_list.add_entry (user.name, label, user.background, user.logged_in);
72+ var layout = get_layout_by_name (user.layout);
73+
74+ user_list.add_entry (user.name, label, user.background, layout, user.logged_in);
75 }
76
77 private void user_removed_cb (LightDM.User user)
78@@ -383,7 +396,7 @@
79 text = greeter.authentication_user;
80 }
81
82- user_list.add_entry ("*other", text, null);
83+ user_list.add_entry ("*other", text, null, null);
84 }
85
86 private void start_authentication ()
87
88=== modified file 'src/user-list.vala'
89--- src/user-list.vala 2011-12-09 18:06:18 +0000
90+++ src/user-list.vala 2011-12-20 18:06:39 +0000
91@@ -74,6 +74,9 @@
92
93 /* True if should be marked as active */
94 public bool is_active;
95+
96+ /* Keyboard layout to use for this user by default */
97+ public LightDM.Layout keyboard_layout;
98 }
99
100 private class IndicatorMenuItem : Gtk.MenuItem
101@@ -312,6 +315,8 @@
102 public List<Indicator.Object> indicator_objects;
103 private Gtk.CheckMenuItem high_contrast_item;
104
105+ private Gtk.Label keyboard_label = null;
106+
107 private Pid keyboard_pid = 0;
108 private Gtk.Window? keyboard_window = null;
109
110@@ -515,18 +520,8 @@
111 }
112 }
113
114- void setup_indicators ()
115+ Gtk.Widget make_a11y_indicator ()
116 {
117- /* Set indicators to run with reduced functionality */
118- greeter_set_env ("INDICATOR_GREETER_MODE", "1");
119-
120- /* Don't allow virtual file systems? */
121- greeter_set_env ("GIO_USE_VFS", "local");
122- greeter_set_env ("GVFS_DISABLE_FUSE", "1");
123-
124- /* Hint to have gnome-settings-daemon run in greeter mode */
125- greeter_set_env ("RUNNING_UNDER_GDM", "1");
126-
127 var a11y_item = new Gtk.MenuItem ();
128 var hbox = new Gtk.HBox (false, 3);
129 hbox.show ();
130@@ -548,6 +543,106 @@
131 item.toggled.connect (screen_reader_toggled_cb);
132 item.show ();
133 a11y_item.submenu.append (item);
134+ return a11y_item;
135+ }
136+
137+ void set_layout (LightDM.Layout? layout)
138+ {
139+ if (layout == null)
140+ layout = LightDM.get_layout (); /* default layout */
141+
142+ var item = layout.get_data<Gtk.RadioMenuItem> ("unity-greeter-radio");
143+ if (item != null)
144+ item.active = true; /* will trigger callback to do rest of work */
145+ }
146+
147+ void layout_toggled_cb (Gtk.CheckMenuItem item)
148+ {
149+ if (!item.active)
150+ return;
151+
152+ var layout = item.get_data<LightDM.Layout> ("unity-greeter-layout");
153+ if (layout == null)
154+ return;
155+
156+ keyboard_label.label = layout.short_description;
157+ LightDM.set_layout (layout);
158+ }
159+
160+ static int cmp_layout (LightDM.Layout? a, LightDM.Layout? b)
161+ {
162+ if (a == null && b == null)
163+ return 0;
164+ else if (a == null)
165+ return 1;
166+ else if (b == null)
167+ return -1;
168+ else
169+ {
170+ /* Use a dumb, ascii comparison for now. If it turns out that some
171+ descriptions can be in unicode, we'll have to use libicu's collation
172+ algorithms. */
173+ return strcmp (a.description, b.description);
174+ }
175+ }
176+
177+ Gtk.Widget make_keyboard_indicator ()
178+ {
179+ var keyboard_item = new Gtk.MenuItem ();
180+ var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3);
181+ hbox.show ();
182+ keyboard_item.add (hbox);
183+ var image = new Gtk.Image.from_icon_name ("keyboard", Gtk.IconSize.LARGE_TOOLBAR);
184+ image.show ();
185+ hbox.add (image);
186+ keyboard_label = new Gtk.Label ("");
187+ keyboard_label.width_chars = 2;
188+ keyboard_label.show ();
189+ hbox.add (keyboard_label);
190+ keyboard_item.show ();
191+
192+ var submenu = new Gtk.Menu ();
193+ keyboard_item.set_submenu (submenu);
194+
195+ List<weak LightDM.Layout> layouts = LightDM.get_layouts ().copy ();
196+ layouts.sort (cmp_layout);
197+
198+ weak SList<Gtk.RadioMenuItem> group = null;
199+
200+ foreach (weak LightDM.Layout layout in layouts) {
201+ var item = new Gtk.RadioMenuItem.with_label (group, layout.description);
202+ group = item.get_group ();
203+
204+ item.show ();
205+
206+ /* LightDM does not change its layout list during its lifetime, so this is safe */
207+ item.set_data("unity-greeter-layout", layout);
208+ layout.set_data("unity-greeter-radio", item);
209+
210+ item.toggled.connect (layout_toggled_cb);
211+
212+ submenu.append (item);
213+ }
214+
215+ return keyboard_item;
216+ }
217+
218+ void setup_indicators ()
219+ {
220+ /* Set indicators to run with reduced functionality */
221+ greeter_set_env ("INDICATOR_GREETER_MODE", "1");
222+
223+ /* Don't allow virtual file systems? */
224+ greeter_set_env ("GIO_USE_VFS", "local");
225+ greeter_set_env ("GVFS_DISABLE_FUSE", "1");
226+
227+ /* Hint to have gnome-settings-daemon run in greeter mode */
228+ greeter_set_env ("RUNNING_UNDER_GDM", "1");
229+
230+ var keyboard_item = make_keyboard_indicator ();
231+ menubar.insert (keyboard_item, (int) menubar.get_children ().length () - 1);
232+
233+ var a11y_item = make_a11y_indicator ();
234 menubar.insert (a11y_item, (int) menubar.get_children ().length () - 1);
235
236 debug ("LANG=%s LANGUAGE=%s", Environment.get_variable ("LANG"), Environment.get_variable ("LANGUAGE"));
237@@ -801,7 +896,7 @@
238 return null;
239 }
240
241- public void add_entry (string name, string label, string? background, bool is_active = false)
242+ public void add_entry (string name, string label, string? background, LightDM.Layout? keyboard_layout, bool is_active = false)
243 {
244 var e = find_entry (name);
245 if (e == null)
246@@ -813,6 +908,7 @@
247 e.layout = create_pango_layout (label);
248 e.layout.set_font_description (Pango.FontDescription.from_string ("Ubuntu 16"));
249 e.background = background != null ? background : default_background;
250+ e.keyboard_layout = keyboard_layout;
251 e.is_active = is_active;
252
253 if (selected_entry == null)
254@@ -983,6 +1079,8 @@
255 change_background ();
256 user_selected (selected_entry.name);
257 }
258+
259+ set_layout (selected_entry.keyboard_layout);
260 }
261
262 scroll_target_location = entries.index (selected_entry);

Subscribers

People subscribed via source and target branches