Merge lp:~mterry/unity-greeter/keyboard-indicator into lp:unity-greeter
- keyboard-indicator
- Merge into trunk
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 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Ancell | Approve | ||
Review via email: mp+86442@code.launchpad.net |
Commit message
Description of the change
Adds a keyboard indicator. Requires a fix to lightdm first: https:/
To post a comment you must log in.
Revision history for this message
Haggai Eran (haggai-eran) wrote : | # |
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 | 131 | 131 | ||
6 | 132 | if (test_mode) | 132 | if (test_mode) |
7 | 133 | { | 133 | { |
17 | 134 | user_list.add_entry ("alice", "가나다라마", "/usr/share/backgrounds/Darkening_Clockwork_by_Matt_Katzenberger.jpg", true); | 134 | user_list.add_entry ("alice", "가나다라마", "/usr/share/backgrounds/Darkening_Clockwork_by_Matt_Katzenberger.jpg", get_layout_by_name ("cn"), true); |
18 | 135 | user_list.add_entry ("chris", "Christopher Halse Rogers!!!!!!!!!!!!!!!", "/usr/share/backgrounds/Darkening_Clockwork_by_Matt_Katzenberger.jpg", true); | 135 | user_list.add_entry ("chris", "Christopher Halse Rogers!!!!!!!!!!!!!!!", "/usr/share/backgrounds/Darkening_Clockwork_by_Matt_Katzenberger.jpg", null, true); |
19 | 136 | user_list.add_entry ("jorge", "Jorge O Castro", "/usr/share/backgrounds/PurpleDancers_by_Emilio_Merlino.jpg"); | 136 | user_list.add_entry ("jorge", "Jorge O Castro", "/usr/share/backgrounds/PurpleDancers_by_Emilio_Merlino.jpg", get_layout_by_name ("us")); |
20 | 137 | user_list.add_entry ("ken", "Ken VanDine", "/usr/share/backgrounds/Small_flowers_by_Dariusz_Duma.jpg"); | 137 | user_list.add_entry ("ken", "Ken VanDine", "/usr/share/backgrounds/Small_flowers_by_Dariusz_Duma.jpg", get_layout_by_name ("uk")); |
21 | 138 | user_list.add_entry ("matthew", "Matthew Paul Thomas", "/usr/share/backgrounds/Not_Alone_by_Deacon_MacMillan.jpg"); | 138 | user_list.add_entry ("matthew", "Matthew Paul Thomas", "/usr/share/backgrounds/Not_Alone_by_Deacon_MacMillan.jpg", get_layout_by_name ("uk")); |
22 | 139 | user_list.add_entry ("otto", "Otto Greenslade", "/usr/share/backgrounds/Mount_Snowdon,_Wales_by_Adam_Vellender.jpg"); | 139 | user_list.add_entry ("otto", "Otto Greenslade", "/usr/share/backgrounds/Mount_Snowdon,_Wales_by_Adam_Vellender.jpg", get_layout_by_name ("uk")); |
23 | 140 | user_list.add_entry ("pitti", "Martin Pitt", "/usr/share/backgrounds/Stalking_Ocelot_by_Sayantan_Chaudhuri.jpg"); | 140 | user_list.add_entry ("pitti", "Martin Pitt", "/usr/share/backgrounds/Stalking_Ocelot_by_Sayantan_Chaudhuri.jpg", get_layout_by_name ("de")); |
24 | 141 | user_list.add_entry ("desrt", "Ryan Lortie", "/usr/share/backgrounds/Power_of_Words_by_Antonio_Litterio.jpg"); | 141 | user_list.add_entry ("desrt", "Ryan Lortie", "/usr/share/backgrounds/Power_of_Words_by_Antonio_Litterio.jpg", get_layout_by_name ("ca")); |
25 | 142 | user_list.add_entry ("*guest", _("Guest Session"), null, true); | 142 | user_list.add_entry ("*guest", _("Guest Session"), null, null, true); |
26 | 143 | 143 | ||
27 | 144 | user_list.add_session ("gnome", "Ubuntu"); | 144 | user_list.add_session ("gnome", "Ubuntu"); |
28 | 145 | user_list.add_session ("gnome-shell", "GNOME"); | 145 | user_list.add_session ("gnome-shell", "GNOME"); |
29 | @@ -151,7 +151,7 @@ | |||
30 | 151 | else | 151 | else |
31 | 152 | { | 152 | { |
32 | 153 | if (greeter.hide_users_hint) | 153 | if (greeter.hide_users_hint) |
34 | 154 | user_list.add_entry ("*other", _("Login"), null); | 154 | user_list.add_entry ("*other", _("Login"), null, null); |
35 | 155 | else | 155 | else |
36 | 156 | { | 156 | { |
37 | 157 | var users = LightDM.UserList.get_instance (); | 157 | var users = LightDM.UserList.get_instance (); |
38 | @@ -165,7 +165,7 @@ | |||
39 | 165 | if (greeter.has_guest_account_hint) | 165 | if (greeter.has_guest_account_hint) |
40 | 166 | { | 166 | { |
41 | 167 | debug ("Adding guest account entry"); | 167 | debug ("Adding guest account entry"); |
43 | 168 | user_list.add_entry ("*guest", _("Guest Session"), null); | 168 | user_list.add_entry ("*guest", _("Guest Session"), null, null); |
44 | 169 | } | 169 | } |
45 | 170 | 170 | ||
46 | 171 | if (greeter.select_user_hint != null) | 171 | if (greeter.select_user_hint != null) |
47 | @@ -179,7 +179,18 @@ | |||
48 | 179 | user_list.start_session.connect (start_session_cb); | 179 | user_list.start_session.connect (start_session_cb); |
49 | 180 | user_selected_cb (user_list.selected); | 180 | user_selected_cb (user_list.selected); |
50 | 181 | } | 181 | } |
52 | 182 | 182 | ||
53 | 183 | private LightDM.Layout? get_layout_by_name (string name) | ||
54 | 184 | { | ||
55 | 185 | unowned GLib.List<weak LightDM.Layout> layouts = LightDM.get_layouts (); | ||
56 | 186 | foreach (weak LightDM.Layout layout in layouts) | ||
57 | 187 | { | ||
58 | 188 | if (layout.name == name) | ||
59 | 189 | return layout; | ||
60 | 190 | } | ||
61 | 191 | return null; | ||
62 | 192 | } | ||
63 | 193 | |||
64 | 183 | private void monitors_changed_cb (Gdk.Screen screen) | 194 | private void monitors_changed_cb (Gdk.Screen screen) |
65 | 184 | { | 195 | { |
66 | 185 | Gdk.Rectangle geometry; | 196 | Gdk.Rectangle geometry; |
67 | @@ -199,7 +210,9 @@ | |||
68 | 199 | if (user.real_name == "") | 210 | if (user.real_name == "") |
69 | 200 | label = user.name; | 211 | label = user.name; |
70 | 201 | 212 | ||
72 | 202 | user_list.add_entry (user.name, label, user.background, user.logged_in); | 213 | var layout = get_layout_by_name (user.layout); |
73 | 214 | |||
74 | 215 | user_list.add_entry (user.name, label, user.background, layout, user.logged_in); | ||
75 | 203 | } | 216 | } |
76 | 204 | 217 | ||
77 | 205 | private void user_removed_cb (LightDM.User user) | 218 | private void user_removed_cb (LightDM.User user) |
78 | @@ -383,7 +396,7 @@ | |||
79 | 383 | text = greeter.authentication_user; | 396 | text = greeter.authentication_user; |
80 | 384 | } | 397 | } |
81 | 385 | 398 | ||
83 | 386 | user_list.add_entry ("*other", text, null); | 399 | user_list.add_entry ("*other", text, null, null); |
84 | 387 | } | 400 | } |
85 | 388 | 401 | ||
86 | 389 | private void start_authentication () | 402 | private void start_authentication () |
87 | 390 | 403 | ||
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 | 74 | 74 | ||
93 | 75 | /* True if should be marked as active */ | 75 | /* True if should be marked as active */ |
94 | 76 | public bool is_active; | 76 | public bool is_active; |
95 | 77 | |||
96 | 78 | /* Keyboard layout to use for this user by default */ | ||
97 | 79 | public LightDM.Layout keyboard_layout; | ||
98 | 77 | } | 80 | } |
99 | 78 | 81 | ||
100 | 79 | private class IndicatorMenuItem : Gtk.MenuItem | 82 | private class IndicatorMenuItem : Gtk.MenuItem |
101 | @@ -312,6 +315,8 @@ | |||
102 | 312 | public List<Indicator.Object> indicator_objects; | 315 | public List<Indicator.Object> indicator_objects; |
103 | 313 | private Gtk.CheckMenuItem high_contrast_item; | 316 | private Gtk.CheckMenuItem high_contrast_item; |
104 | 314 | 317 | ||
105 | 318 | private Gtk.Label keyboard_label = null; | ||
106 | 319 | |||
107 | 315 | private Pid keyboard_pid = 0; | 320 | private Pid keyboard_pid = 0; |
108 | 316 | private Gtk.Window? keyboard_window = null; | 321 | private Gtk.Window? keyboard_window = null; |
109 | 317 | 322 | ||
110 | @@ -515,18 +520,8 @@ | |||
111 | 515 | } | 520 | } |
112 | 516 | } | 521 | } |
113 | 517 | 522 | ||
115 | 518 | void setup_indicators () | 523 | Gtk.Widget make_a11y_indicator () |
116 | 519 | { | 524 | { |
117 | 520 | /* Set indicators to run with reduced functionality */ | ||
118 | 521 | greeter_set_env ("INDICATOR_GREETER_MODE", "1"); | ||
119 | 522 | |||
120 | 523 | /* Don't allow virtual file systems? */ | ||
121 | 524 | greeter_set_env ("GIO_USE_VFS", "local"); | ||
122 | 525 | greeter_set_env ("GVFS_DISABLE_FUSE", "1"); | ||
123 | 526 | |||
124 | 527 | /* Hint to have gnome-settings-daemon run in greeter mode */ | ||
125 | 528 | greeter_set_env ("RUNNING_UNDER_GDM", "1"); | ||
126 | 529 | |||
127 | 530 | var a11y_item = new Gtk.MenuItem (); | 525 | var a11y_item = new Gtk.MenuItem (); |
128 | 531 | var hbox = new Gtk.HBox (false, 3); | 526 | var hbox = new Gtk.HBox (false, 3); |
129 | 532 | hbox.show (); | 527 | hbox.show (); |
130 | @@ -548,6 +543,106 @@ | |||
131 | 548 | item.toggled.connect (screen_reader_toggled_cb); | 543 | item.toggled.connect (screen_reader_toggled_cb); |
132 | 549 | item.show (); | 544 | item.show (); |
133 | 550 | a11y_item.submenu.append (item); | 545 | a11y_item.submenu.append (item); |
134 | 546 | return a11y_item; | ||
135 | 547 | } | ||
136 | 548 | |||
137 | 549 | void set_layout (LightDM.Layout? layout) | ||
138 | 550 | { | ||
139 | 551 | if (layout == null) | ||
140 | 552 | layout = LightDM.get_layout (); /* default layout */ | ||
141 | 553 | |||
142 | 554 | var item = layout.get_data<Gtk.RadioMenuItem> ("unity-greeter-radio"); | ||
143 | 555 | if (item != null) | ||
144 | 556 | item.active = true; /* will trigger callback to do rest of work */ | ||
145 | 557 | } | ||
146 | 558 | |||
147 | 559 | void layout_toggled_cb (Gtk.CheckMenuItem item) | ||
148 | 560 | { | ||
149 | 561 | if (!item.active) | ||
150 | 562 | return; | ||
151 | 563 | |||
152 | 564 | var layout = item.get_data<LightDM.Layout> ("unity-greeter-layout"); | ||
153 | 565 | if (layout == null) | ||
154 | 566 | return; | ||
155 | 567 | |||
156 | 568 | keyboard_label.label = layout.short_description; | ||
157 | 569 | LightDM.set_layout (layout); | ||
158 | 570 | } | ||
159 | 571 | |||
160 | 572 | static int cmp_layout (LightDM.Layout? a, LightDM.Layout? b) | ||
161 | 573 | { | ||
162 | 574 | if (a == null && b == null) | ||
163 | 575 | return 0; | ||
164 | 576 | else if (a == null) | ||
165 | 577 | return 1; | ||
166 | 578 | else if (b == null) | ||
167 | 579 | return -1; | ||
168 | 580 | else | ||
169 | 581 | { | ||
170 | 582 | /* Use a dumb, ascii comparison for now. If it turns out that some | ||
171 | 583 | descriptions can be in unicode, we'll have to use libicu's collation | ||
172 | 584 | algorithms. */ | ||
173 | 585 | return strcmp (a.description, b.description); | ||
174 | 586 | } | ||
175 | 587 | } | ||
176 | 588 | |||
177 | 589 | Gtk.Widget make_keyboard_indicator () | ||
178 | 590 | { | ||
179 | 591 | var keyboard_item = new Gtk.MenuItem (); | ||
180 | 592 | var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3); | ||
181 | 593 | hbox.show (); | ||
182 | 594 | keyboard_item.add (hbox); | ||
183 | 595 | var image = new Gtk.Image.from_icon_name ("keyboard", Gtk.IconSize.LARGE_TOOLBAR); | ||
184 | 596 | image.show (); | ||
185 | 597 | hbox.add (image); | ||
186 | 598 | keyboard_label = new Gtk.Label (""); | ||
187 | 599 | keyboard_label.width_chars = 2; | ||
188 | 600 | keyboard_label.show (); | ||
189 | 601 | hbox.add (keyboard_label); | ||
190 | 602 | keyboard_item.show (); | ||
191 | 603 | |||
192 | 604 | var submenu = new Gtk.Menu (); | ||
193 | 605 | keyboard_item.set_submenu (submenu); | ||
194 | 606 | |||
195 | 607 | List<weak LightDM.Layout> layouts = LightDM.get_layouts ().copy (); | ||
196 | 608 | layouts.sort (cmp_layout); | ||
197 | 609 | |||
198 | 610 | weak SList<Gtk.RadioMenuItem> group = null; | ||
199 | 611 | |||
200 | 612 | foreach (weak LightDM.Layout layout in layouts) { | ||
201 | 613 | var item = new Gtk.RadioMenuItem.with_label (group, layout.description); | ||
202 | 614 | group = item.get_group (); | ||
203 | 615 | |||
204 | 616 | item.show (); | ||
205 | 617 | |||
206 | 618 | /* LightDM does not change its layout list during its lifetime, so this is safe */ | ||
207 | 619 | item.set_data("unity-greeter-layout", layout); | ||
208 | 620 | layout.set_data("unity-greeter-radio", item); | ||
209 | 621 | |||
210 | 622 | item.toggled.connect (layout_toggled_cb); | ||
211 | 623 | |||
212 | 624 | submenu.append (item); | ||
213 | 625 | } | ||
214 | 626 | |||
215 | 627 | return keyboard_item; | ||
216 | 628 | } | ||
217 | 629 | |||
218 | 630 | void setup_indicators () | ||
219 | 631 | { | ||
220 | 632 | /* Set indicators to run with reduced functionality */ | ||
221 | 633 | greeter_set_env ("INDICATOR_GREETER_MODE", "1"); | ||
222 | 634 | |||
223 | 635 | /* Don't allow virtual file systems? */ | ||
224 | 636 | greeter_set_env ("GIO_USE_VFS", "local"); | ||
225 | 637 | greeter_set_env ("GVFS_DISABLE_FUSE", "1"); | ||
226 | 638 | |||
227 | 639 | /* Hint to have gnome-settings-daemon run in greeter mode */ | ||
228 | 640 | greeter_set_env ("RUNNING_UNDER_GDM", "1"); | ||
229 | 641 | |||
230 | 642 | var keyboard_item = make_keyboard_indicator (); | ||
231 | 643 | menubar.insert (keyboard_item, (int) menubar.get_children ().length () - 1); | ||
232 | 644 | |||
233 | 645 | var a11y_item = make_a11y_indicator (); | ||
234 | 551 | menubar.insert (a11y_item, (int) menubar.get_children ().length () - 1); | 646 | menubar.insert (a11y_item, (int) menubar.get_children ().length () - 1); |
235 | 552 | 647 | ||
236 | 553 | debug ("LANG=%s LANGUAGE=%s", Environment.get_variable ("LANG"), Environment.get_variable ("LANGUAGE")); | 648 | debug ("LANG=%s LANGUAGE=%s", Environment.get_variable ("LANG"), Environment.get_variable ("LANGUAGE")); |
237 | @@ -801,7 +896,7 @@ | |||
238 | 801 | return null; | 896 | return null; |
239 | 802 | } | 897 | } |
240 | 803 | 898 | ||
242 | 804 | public void add_entry (string name, string label, string? background, bool is_active = false) | 899 | public void add_entry (string name, string label, string? background, LightDM.Layout? keyboard_layout, bool is_active = false) |
243 | 805 | { | 900 | { |
244 | 806 | var e = find_entry (name); | 901 | var e = find_entry (name); |
245 | 807 | if (e == null) | 902 | if (e == null) |
246 | @@ -813,6 +908,7 @@ | |||
247 | 813 | e.layout = create_pango_layout (label); | 908 | e.layout = create_pango_layout (label); |
248 | 814 | e.layout.set_font_description (Pango.FontDescription.from_string ("Ubuntu 16")); | 909 | e.layout.set_font_description (Pango.FontDescription.from_string ("Ubuntu 16")); |
249 | 815 | e.background = background != null ? background : default_background; | 910 | e.background = background != null ? background : default_background; |
250 | 911 | e.keyboard_layout = keyboard_layout; | ||
251 | 816 | e.is_active = is_active; | 912 | e.is_active = is_active; |
252 | 817 | 913 | ||
253 | 818 | if (selected_entry == null) | 914 | if (selected_entry == null) |
254 | @@ -983,6 +1079,8 @@ | |||
255 | 983 | change_background (); | 1079 | change_background (); |
256 | 984 | user_selected (selected_entry.name); | 1080 | user_selected (selected_entry.name); |
257 | 985 | } | 1081 | } |
258 | 1082 | |||
259 | 1083 | set_layout (selected_entry.keyboard_layout); | ||
260 | 986 | } | 1084 | } |
261 | 987 | 1085 | ||
262 | 988 | scroll_target_location = entries.index (selected_entry); | 1086 | scroll_target_location = entries.index (selected_entry); |
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.