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
=== modified file 'src/unity-greeter.vala'
--- src/unity-greeter.vala 2011-12-09 18:06:18 +0000
+++ src/unity-greeter.vala 2011-12-20 18:06:39 +0000
@@ -131,15 +131,15 @@
131131
132 if (test_mode)132 if (test_mode)
133 {133 {
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);
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);
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"));
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"));
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"));
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"));
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"));
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"));
142 user_list.add_entry ("*guest", _("Guest Session"), null, true);142 user_list.add_entry ("*guest", _("Guest Session"), null, null, true);
143143
144 user_list.add_session ("gnome", "Ubuntu");144 user_list.add_session ("gnome", "Ubuntu");
145 user_list.add_session ("gnome-shell", "GNOME");145 user_list.add_session ("gnome-shell", "GNOME");
@@ -151,7 +151,7 @@
151 else151 else
152 {152 {
153 if (greeter.hide_users_hint)153 if (greeter.hide_users_hint)
154 user_list.add_entry ("*other", _("Login"), null);154 user_list.add_entry ("*other", _("Login"), null, null);
155 else155 else
156 {156 {
157 var users = LightDM.UserList.get_instance ();157 var users = LightDM.UserList.get_instance ();
@@ -165,7 +165,7 @@
165 if (greeter.has_guest_account_hint)165 if (greeter.has_guest_account_hint)
166 {166 {
167 debug ("Adding guest account entry");167 debug ("Adding guest account entry");
168 user_list.add_entry ("*guest", _("Guest Session"), null);168 user_list.add_entry ("*guest", _("Guest Session"), null, null);
169 }169 }
170170
171 if (greeter.select_user_hint != null)171 if (greeter.select_user_hint != null)
@@ -179,7 +179,18 @@
179 user_list.start_session.connect (start_session_cb);179 user_list.start_session.connect (start_session_cb);
180 user_selected_cb (user_list.selected);180 user_selected_cb (user_list.selected);
181 }181 }
182 182
183 private LightDM.Layout? get_layout_by_name (string name)
184 {
185 unowned GLib.List<weak LightDM.Layout> layouts = LightDM.get_layouts ();
186 foreach (weak LightDM.Layout layout in layouts)
187 {
188 if (layout.name == name)
189 return layout;
190 }
191 return null;
192 }
193
183 private void monitors_changed_cb (Gdk.Screen screen)194 private void monitors_changed_cb (Gdk.Screen screen)
184 {195 {
185 Gdk.Rectangle geometry;196 Gdk.Rectangle geometry;
@@ -199,7 +210,9 @@
199 if (user.real_name == "")210 if (user.real_name == "")
200 label = user.name;211 label = user.name;
201212
202 user_list.add_entry (user.name, label, user.background, user.logged_in);213 var layout = get_layout_by_name (user.layout);
214
215 user_list.add_entry (user.name, label, user.background, layout, user.logged_in);
203 }216 }
204217
205 private void user_removed_cb (LightDM.User user)218 private void user_removed_cb (LightDM.User user)
@@ -383,7 +396,7 @@
383 text = greeter.authentication_user;396 text = greeter.authentication_user;
384 }397 }
385398
386 user_list.add_entry ("*other", text, null);399 user_list.add_entry ("*other", text, null, null);
387 }400 }
388401
389 private void start_authentication ()402 private void start_authentication ()
390403
=== modified file 'src/user-list.vala'
--- src/user-list.vala 2011-12-09 18:06:18 +0000
+++ src/user-list.vala 2011-12-20 18:06:39 +0000
@@ -74,6 +74,9 @@
7474
75 /* True if should be marked as active */75 /* True if should be marked as active */
76 public bool is_active;76 public bool is_active;
77
78 /* Keyboard layout to use for this user by default */
79 public LightDM.Layout keyboard_layout;
77}80}
7881
79private class IndicatorMenuItem : Gtk.MenuItem82private class IndicatorMenuItem : Gtk.MenuItem
@@ -312,6 +315,8 @@
312 public List<Indicator.Object> indicator_objects;315 public List<Indicator.Object> indicator_objects;
313 private Gtk.CheckMenuItem high_contrast_item;316 private Gtk.CheckMenuItem high_contrast_item;
314317
318 private Gtk.Label keyboard_label = null;
319
315 private Pid keyboard_pid = 0;320 private Pid keyboard_pid = 0;
316 private Gtk.Window? keyboard_window = null;321 private Gtk.Window? keyboard_window = null;
317322
@@ -515,18 +520,8 @@
515 }520 }
516 }521 }
517522
518 void setup_indicators ()523 Gtk.Widget make_a11y_indicator ()
519 {524 {
520 /* Set indicators to run with reduced functionality */
521 greeter_set_env ("INDICATOR_GREETER_MODE", "1");
522
523 /* Don't allow virtual file systems? */
524 greeter_set_env ("GIO_USE_VFS", "local");
525 greeter_set_env ("GVFS_DISABLE_FUSE", "1");
526
527 /* Hint to have gnome-settings-daemon run in greeter mode */
528 greeter_set_env ("RUNNING_UNDER_GDM", "1");
529
530 var a11y_item = new Gtk.MenuItem ();525 var a11y_item = new Gtk.MenuItem ();
531 var hbox = new Gtk.HBox (false, 3);526 var hbox = new Gtk.HBox (false, 3);
532 hbox.show ();527 hbox.show ();
@@ -548,6 +543,106 @@
548 item.toggled.connect (screen_reader_toggled_cb);543 item.toggled.connect (screen_reader_toggled_cb);
549 item.show ();544 item.show ();
550 a11y_item.submenu.append (item);545 a11y_item.submenu.append (item);
546 return a11y_item;
547 }
548
549 void set_layout (LightDM.Layout? layout)
550 {
551 if (layout == null)
552 layout = LightDM.get_layout (); /* default layout */
553
554 var item = layout.get_data<Gtk.RadioMenuItem> ("unity-greeter-radio");
555 if (item != null)
556 item.active = true; /* will trigger callback to do rest of work */
557 }
558
559 void layout_toggled_cb (Gtk.CheckMenuItem item)
560 {
561 if (!item.active)
562 return;
563
564 var layout = item.get_data<LightDM.Layout> ("unity-greeter-layout");
565 if (layout == null)
566 return;
567
568 keyboard_label.label = layout.short_description;
569 LightDM.set_layout (layout);
570 }
571
572 static int cmp_layout (LightDM.Layout? a, LightDM.Layout? b)
573 {
574 if (a == null && b == null)
575 return 0;
576 else if (a == null)
577 return 1;
578 else if (b == null)
579 return -1;
580 else
581 {
582 /* Use a dumb, ascii comparison for now. If it turns out that some
583 descriptions can be in unicode, we'll have to use libicu's collation
584 algorithms. */
585 return strcmp (a.description, b.description);
586 }
587 }
588
589 Gtk.Widget make_keyboard_indicator ()
590 {
591 var keyboard_item = new Gtk.MenuItem ();
592 var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3);
593 hbox.show ();
594 keyboard_item.add (hbox);
595 var image = new Gtk.Image.from_icon_name ("keyboard", Gtk.IconSize.LARGE_TOOLBAR);
596 image.show ();
597 hbox.add (image);
598 keyboard_label = new Gtk.Label ("");
599 keyboard_label.width_chars = 2;
600 keyboard_label.show ();
601 hbox.add (keyboard_label);
602 keyboard_item.show ();
603
604 var submenu = new Gtk.Menu ();
605 keyboard_item.set_submenu (submenu);
606
607 List<weak LightDM.Layout> layouts = LightDM.get_layouts ().copy ();
608 layouts.sort (cmp_layout);
609
610 weak SList<Gtk.RadioMenuItem> group = null;
611
612 foreach (weak LightDM.Layout layout in layouts) {
613 var item = new Gtk.RadioMenuItem.with_label (group, layout.description);
614 group = item.get_group ();
615
616 item.show ();
617
618 /* LightDM does not change its layout list during its lifetime, so this is safe */
619 item.set_data("unity-greeter-layout", layout);
620 layout.set_data("unity-greeter-radio", item);
621
622 item.toggled.connect (layout_toggled_cb);
623
624 submenu.append (item);
625 }
626
627 return keyboard_item;
628 }
629
630 void setup_indicators ()
631 {
632 /* Set indicators to run with reduced functionality */
633 greeter_set_env ("INDICATOR_GREETER_MODE", "1");
634
635 /* Don't allow virtual file systems? */
636 greeter_set_env ("GIO_USE_VFS", "local");
637 greeter_set_env ("GVFS_DISABLE_FUSE", "1");
638
639 /* Hint to have gnome-settings-daemon run in greeter mode */
640 greeter_set_env ("RUNNING_UNDER_GDM", "1");
641
642 var keyboard_item = make_keyboard_indicator ();
643 menubar.insert (keyboard_item, (int) menubar.get_children ().length () - 1);
644
645 var a11y_item = make_a11y_indicator ();
551 menubar.insert (a11y_item, (int) menubar.get_children ().length () - 1);646 menubar.insert (a11y_item, (int) menubar.get_children ().length () - 1);
552647
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"));
@@ -801,7 +896,7 @@
801 return null;896 return null;
802 }897 }
803898
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)
805 {900 {
806 var e = find_entry (name);901 var e = find_entry (name);
807 if (e == null)902 if (e == null)
@@ -813,6 +908,7 @@
813 e.layout = create_pango_layout (label);908 e.layout = create_pango_layout (label);
814 e.layout.set_font_description (Pango.FontDescription.from_string ("Ubuntu 16"));909 e.layout.set_font_description (Pango.FontDescription.from_string ("Ubuntu 16"));
815 e.background = background != null ? background : default_background;910 e.background = background != null ? background : default_background;
911 e.keyboard_layout = keyboard_layout;
816 e.is_active = is_active;912 e.is_active = is_active;
817913
818 if (selected_entry == null)914 if (selected_entry == null)
@@ -983,6 +1079,8 @@
983 change_background ();1079 change_background ();
984 user_selected (selected_entry.name);1080 user_selected (selected_entry.name);
985 }1081 }
1082
1083 set_layout (selected_entry.keyboard_layout);
986 }1084 }
9871085
988 scroll_target_location = entries.index (selected_entry);1086 scroll_target_location = entries.index (selected_entry);

Subscribers

People subscribed via source and target branches