@@ -33,20 +33,13 @@ def __init__(self):
33
33
trackers .con_tracker_get ().connect (self , "icon-press" , self .on_icon_pressed )
34
34
35
35
self .placeholder_text = placeholder_text
36
- self .current_icon_name = None
37
- self .current_flag_id = 0
38
- self .original_group = 0
36
+ self .lockscreen_layout_source = None
37
+ self .system_layout_source = None
39
38
40
- self .keyboard_controller = singletons .KeyboardLayoutController
41
- trackers .con_tracker_get ().connect (self .keyboard_controller ,
42
- "config-changed" ,
43
- self .on_config_changed )
44
-
45
- trackers .con_tracker_get ().connect (self .keyboard_controller ,
46
- "layout-changed" ,
47
- self .on_layout_changed )
48
-
49
- self .set_lockscreen_keyboard_layout ()
39
+ self .cinnamon = singletons .CinnamonClient
40
+ self .cinnamon .connect ("current-input-source-changed" , self .on_current_layout_changed )
41
+ self .cinnamon .connect ("input-sources-changed" , self .on_layout_sources_changed )
42
+ self .on_layout_sources_changed (self .cinnamon )
50
43
51
44
trackers .con_tracker_get ().connect (self ,
52
45
"destroy" ,
@@ -59,25 +52,18 @@ def on_draw(self, widget, cr, data=None):
59
52
update_layout_icon(), just so GtkEntry thinks there's an icon there,
60
53
that way it allocates space for it, and responds to clicks in the area.
61
54
"""
62
- if not self .keyboard_controller .get_enabled ():
63
- return False
64
-
65
55
icon_rect = widget .get_icon_area (Gtk .EntryIconPosition .PRIMARY )
66
56
x = icon_rect .x
67
57
y = icon_rect .y + 2
68
58
width = (icon_rect .width // 2 ) * 2
69
59
height = icon_rect .height - 4
70
60
71
61
handled = False
72
-
73
62
if settings .get_show_flags ():
74
- name = self .keyboard_controller .get_current_icon_name ()
75
-
76
63
ui_scale = self .get_scale_factor ()
77
64
78
- if name :
79
- filename = "/usr/share/iso-flag-png/%s.png" % name
80
-
65
+ if self .lockscreen_layout_source .flag_name != "" :
66
+ filename = "/usr/share/iso-flag-png/%s.png" % self .lockscreen_layout_source .flag_name
81
67
try :
82
68
pixbuf = GdkPixbuf .Pixbuf .new_from_file_at_size (filename , - 1 , height * ui_scale )
83
69
@@ -98,26 +84,37 @@ def on_draw(self, widget, cr, data=None):
98
84
99
85
cr .paint ()
100
86
101
- self .keyboard_controller .render_cairo_subscript (cr ,
102
- render_x + (logical_width / 2 ),
103
- render_y + (logical_height / 2 ),
104
- logical_width / 2 ,
105
- logical_height / 2 ,
106
- self .keyboard_controller .get_current_flag_id ())
87
+ if self .lockscreen_layout_source .dupe_id > 0 :
88
+ x = render_x + logical_width / 2
89
+ y = render_y + logical_height / 2
90
+ width = logical_width / 2 + 2
91
+ height = logical_height / 2 + 2
92
+
93
+ cr .set_source_rgba (0 , 0 , 0 , 0.5 )
94
+ cr .rectangle (x , y , width , height )
95
+ cr .fill ()
96
+
97
+ cr .set_source_rgba (1.0 , 1.0 , 1.0 , 0.8 )
98
+ cr .rectangle (x + 1 , y + 1 , width - 2 , height - 2 )
99
+ cr .fill ()
100
+
101
+ cr .set_source_rgba (0.0 , 0.0 , 0.0 , 1.0 )
102
+ cr .select_font_face ("sans" , cairo .FontSlant .NORMAL , cairo .FontWeight .BOLD )
103
+ cr .set_font_size (height - 2.0 )
104
+
105
+ dupe_str = str (self .lockscreen_layout_source .dupe_id )
106
+
107
+ ext = cr .text_extents (dupe_str )
108
+ cr .move_to ((x + (width / 2.0 ) - (ext .width / 2.0 )),
109
+ (y + (height / 2.0 ) + (ext .height / 2.0 )))
110
+ cr .show_text (dupe_str )
107
111
108
112
handled = True
109
113
except GLib .Error :
110
114
pass
111
115
112
116
if not handled :
113
- if settings .get_use_layout_variant_names ():
114
- name = self .keyboard_controller .get_current_variant_label ()
115
- else :
116
- name = self .keyboard_controller .get_current_short_group_label ()
117
-
118
- if settings .get_show_upper_case_layout ():
119
- name = name .upper ()
120
-
117
+ name = self .lockscreen_layout_source .short_name
121
118
ctx = widget .get_style_context ()
122
119
ctx .save ()
123
120
@@ -167,16 +164,27 @@ def pulse(self):
167
164
self .progress_pulse ()
168
165
return True
169
166
170
- def on_layout_changed (self , controller , layout ):
167
+ def on_current_layout_changed (self , cinnamon ):
168
+ if not self .cinnamon .has_multiple_keyboard_layouts ():
169
+ return
170
+
171
+ self .lockscreen_layout_source = self .cinnamon .get_current_layout_source ()
172
+
171
173
self .grab_focus ()
172
174
self .update_layout_icon ()
173
175
174
- def on_config_changed (self , controller ):
176
+ def on_layout_sources_changed (self , cinnamon ):
177
+ if not self .cinnamon .has_multiple_keyboard_layouts ():
178
+ return
179
+
180
+ self .system_layout_source = self .cinnamon .get_current_layout_source ()
181
+ self .lockscreen_layout_source = self .system_layout_source
182
+
175
183
self .set_lockscreen_keyboard_layout ()
176
184
177
185
def on_icon_pressed (self , entry , icon_pos , event ):
178
186
if icon_pos == Gtk .EntryIconPosition .PRIMARY :
179
- self .keyboard_controller . next_group ()
187
+ self .cinnamon . activate_next_layout ()
180
188
elif icon_pos == Gtk .EntryIconPosition .SECONDARY :
181
189
if self .get_input_purpose () == Gtk .InputPurpose .FREE_FORM :
182
190
self .set_visibility (False )
@@ -195,62 +203,46 @@ def update_layout_icon(self):
195
203
also ensures a redraw at the correct time to update the flag image.
196
204
"""
197
205
self .set_icon_from_icon_name (Gtk .EntryIconPosition .PRIMARY , "screensaver-blank" )
198
- self .set_icon_tooltip_text (Gtk .EntryIconPosition .PRIMARY , self .keyboard_controller .get_current_name ())
199
-
200
- self .update_saved_group (self .keyboard_controller .get_current_group ())
206
+ self .set_icon_tooltip_text (Gtk .EntryIconPosition .PRIMARY , self .lockscreen_layout_source .display_name )
201
207
202
208
def on_destroy (self , widget , data = None ):
203
209
self .stop_progress ()
204
210
205
- trackers .con_tracker_get ().disconnect (self .keyboard_controller ,
206
- "config-changed" ,
207
- self .on_config_changed )
208
-
209
- trackers .con_tracker_get ().disconnect (self .keyboard_controller ,
210
- "layout-changed" ,
211
- self .on_layout_changed )
212
-
213
211
self .restore_original_layout ()
214
212
215
213
def set_lockscreen_keyboard_layout (self ):
216
- if not self .keyboard_controller .get_enabled ():
217
- return
218
-
219
214
# If there are multiple keyboard layouts, we want to store
220
215
# the one the user ends up using in the unlock widget, as they'll
221
216
# want to use the same one each time, at least until they change
222
217
# their password.
223
218
224
- saved_group = settings .get_kb_group ()
225
- self .original_group = self .keyboard_controller .get_current_group ()
226
-
227
- new_group = 0
219
+ saved_index = settings .get_kb_group ()
220
+ new_index = 0
228
221
229
- if saved_group == - 1 :
230
- new_group = self .original_group
222
+ if saved_index == - 1 :
223
+ new_index = self .system_layout_source .index
224
+ settings .set_kb_group (new_index )
231
225
else :
232
- new_group = saved_group
226
+ new_index = saved_index
227
+
228
+ if new_index != self .system_layout_source .index :
229
+ self .cinnamon .activate_layout_index (new_index )
233
230
234
- self .keyboard_controller .set_current_group (new_group )
235
- self .update_saved_group (new_group )
236
231
self .update_layout_icon ()
237
232
238
233
trackers .con_tracker_get ().connect (self ,
239
234
"draw" ,
240
235
self .on_draw )
241
236
242
- def update_saved_group (self , group ):
243
- settings .set_kb_group (group )
244
-
245
237
def restore_original_layout (self ):
246
238
"""
247
239
Called when the unlock dialog is destroyed, restores
248
240
the group that was active before the screensaver was activated.
249
241
"""
250
- if not self .keyboard_controller . get_enabled () :
251
- return
242
+ if settings . get_kb_group () != self .lockscreen_layout_source . index :
243
+ settings . set_kb_group ( self . lockscreen_layout_source . index )
252
244
253
- self .keyboard_controller . set_current_group (self .original_group )
245
+ self .cinnamon . activate_layout_index (self .system_layout_source . index )
254
246
255
247
def grab_focus (self ):
256
248
Gtk .Widget .grab_focus (self )
0 commit comments