65
66
/* Panel Widgets */
66
67
static GtkWindow *panel_window;
67
static GtkWidget *clock_label;
68
static GtkWidget *menubar, *power_menuitem, *session_menuitem, *language_menuitem, *a11y_menuitem, *session_badge;
68
static GtkWidget *menubar;
69
static GtkWidget *power_menuitem, *language_menuitem, *a11y_menuitem, *session_menuitem, *session_badge;
69
70
static GtkWidget *suspend_menuitem, *hibernate_menuitem, *restart_menuitem, *shutdown_menuitem;
70
static GtkWidget *keyboard_menuitem;
71
static GtkWidget *keyboard_menuitem, *clock_menuitem, *clock_label, *host_menuitem;
71
72
static GtkMenu *session_menu, *language_menu;
73
74
/* Login Window Widgets */
141
142
GdkPixbuf* default_user_pixbuf = NULL;
142
143
gchar* default_user_icon = "avatar-default";
145
static const gchar *INDICATOR_DATA_INDEX = "indicator-custom-index-data";
146
static const gchar *INDICATOR_DATA_OBJECT = "indicator-custom-object-data";
147
static const gchar *INDICATOR_DATA_ENTRY = "indicator-custom-entry-data";
148
static const gchar *INDICATOR_DATA_BOX = "indicator-custom-box-data";
149
static const gchar *INDICATOR_DATA_MENUITEMS = "indicator-custom-menuitems-data";
145
152
pam_message_finalize (PAMConversationMessage *message)
158
165
for (item = items; item; item = item->next)
160
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item->data), "indicator-custom-index-data")) < index)
167
if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item->data), INDICATOR_DATA_INDEX)) < index)
164
171
g_list_free (items);
166
gtk_menu_shell_insert (GTK_MENU_SHELL (menubar), GTK_WIDGET (indicator_item), insert_pos);
173
gtk_widget_show (indicator_item);
174
gtk_menu_shell_insert (GTK_MENU_SHELL (menubar), indicator_item, insert_pos);
169
177
#ifdef HAVE_LIBINDICATOR
176
184
g_return_val_if_fail (GTK_IS_WIDGET (menuitem), FALSE);
178
io = g_object_get_data (G_OBJECT (menuitem), "indicator-custom-object-data");
179
entry = g_object_get_data (G_OBJECT (menuitem), "indicator-custom-entry-data");
186
io = g_object_get_data (G_OBJECT (menuitem), INDICATOR_DATA_OBJECT);
187
entry = g_object_get_data (G_OBJECT (menuitem), INDICATOR_DATA_ENTRY);
181
189
g_return_val_if_fail (INDICATOR_IS_OBJECT (io), FALSE);
195
203
g_return_if_fail (GTK_IS_WIDGET (widget));
197
io = g_object_get_data (G_OBJECT (widget), "indicator-custom-object-data");
198
entry = g_object_get_data (G_OBJECT (widget), "indicator-custom-entry-data");
205
io = g_object_get_data (G_OBJECT (widget), INDICATOR_DATA_OBJECT);
206
entry = g_object_get_data (G_OBJECT (widget), INDICATOR_DATA_ENTRY);
200
208
g_return_if_fail (INDICATOR_IS_OBJECT (io));
206
214
create_menuitem (IndicatorObject *io, IndicatorObjectEntry *entry, GtkWidget *menubar)
208
216
GtkWidget *box, *menuitem;
209
gint index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (io), "indicator-custom-index-data"));
217
gint index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (io), INDICATOR_DATA_INDEX));
211
219
#if GTK_CHECK_VERSION (3, 0, 0)
212
220
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
218
226
gtk_widget_add_events(GTK_WIDGET(menuitem), GDK_SCROLL_MASK);
220
g_object_set_data (G_OBJECT (menuitem), "indicator-custom-box-data", box);
221
g_object_set_data (G_OBJECT (menuitem), "indicator-custom-object-data", io);
222
g_object_set_data (G_OBJECT (menuitem), "indicator-custom-entry-data", entry);
223
g_object_set_data (G_OBJECT (menuitem), "indicator-custom-index-data", GINT_TO_POINTER (index));
228
g_object_set_data (G_OBJECT (menuitem), INDICATOR_DATA_BOX, box);
229
g_object_set_data (G_OBJECT (menuitem), INDICATOR_DATA_OBJECT, io);
230
g_object_set_data (G_OBJECT (menuitem), INDICATOR_DATA_ENTRY, entry);
231
g_object_set_data (G_OBJECT (menuitem), INDICATOR_DATA_INDEX, GINT_TO_POINTER (index));
225
233
g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK (entry_activated), NULL);
226
234
g_signal_connect (G_OBJECT (menuitem), "scroll-event", G_CALLBACK (entry_scrolled), NULL);
248
256
GtkWidget *menuitem;
250
258
/* if the menuitem doesn't already exist, create it now */
251
menuitem_lookup = g_object_get_data (G_OBJECT (io), "indicator-custom-menuitems-data");
259
menuitem_lookup = g_object_get_data (G_OBJECT (io), INDICATOR_DATA_MENUITEMS);
252
260
g_return_if_fail (menuitem_lookup);
253
261
menuitem = g_hash_table_lookup (menuitem_lookup, entry);
254
262
if (!GTK_IS_WIDGET (menuitem))
268
276
GtkWidget *menuitem;
271
io = g_object_get_data (G_OBJECT (widget), "indicator-custom-object-data");
279
io = g_object_get_data (G_OBJECT (widget), INDICATOR_DATA_OBJECT);
272
280
if (!INDICATOR_IS_OBJECT (io))
275
entry = g_object_get_data (G_OBJECT (widget), "indicator-custom-entry-data");
283
entry = g_object_get_data (G_OBJECT (widget), INDICATOR_DATA_ENTRY);
276
284
if (entry != userdata)
279
menuitem_lookup = g_object_get_data (G_OBJECT (io), "indicator-custom-menuitems-data");
287
menuitem_lookup = g_object_get_data (G_OBJECT (io), INDICATOR_DATA_MENUITEMS);
280
288
g_return_if_fail (menuitem_lookup);
281
289
menuitem = g_hash_table_lookup (menuitem_lookup, entry);
282
290
if (GTK_IS_WIDGET (menuitem))
408
416
g_hash_table_insert (builtin_items, "~session", session_menuitem);
409
417
g_hash_table_insert (builtin_items, "~language", language_menuitem);
410
418
g_hash_table_insert (builtin_items, "~a11y", a11y_menuitem);
419
g_hash_table_insert (builtin_items, "~host", host_menuitem);
420
g_hash_table_insert (builtin_items, "~clock", clock_menuitem);
412
422
g_hash_table_iter_init (&iter, builtin_items);
413
423
while (g_hash_table_iter_next (&iter, NULL, &iter_value))
417
427
for (i = 0; i < length; ++i)
419
if (names[i][0] == '~' && g_hash_table_lookup_extended (builtin_items, names[i], NULL, &iter_value))
429
if (names[i][0] == '~')
420
430
{ /* Built-in indicators */
421
g_object_set_data (G_OBJECT (iter_value), "indicator-custom-index-data", GINT_TO_POINTER (i));
422
add_indicator_to_panel (iter_value, i);
423
g_hash_table_remove (builtin_items, (gconstpointer)names[i]);
431
if (g_hash_table_lookup_extended (builtin_items, names[i], NULL, &iter_value))
432
g_hash_table_remove (builtin_items, (gconstpointer)names[i]);
433
else if (g_strcmp0 (names[i], "~separator") == 0)
435
GtkWidget *separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
436
iter_value = gtk_separator_menu_item_new ();
437
gtk_widget_show (separator);
438
gtk_container_add (iter_value, separator);
440
else if (g_strcmp0 (names[i], "~spacer") == 0)
442
iter_value = gtk_separator_menu_item_new ();
443
gtk_menu_item_set_label (iter_value, "");
444
gtk_widget_set_hexpand (iter_value, TRUE);
450
g_object_set_data (G_OBJECT (iter_value), INDICATOR_DATA_INDEX, GINT_TO_POINTER (i));
451
add_indicator_to_panel (iter_value, i);
427
456
#ifdef HAVE_LIBINDICATOR
473
502
GList *entries, *lp;
475
504
/* used to store/fetch menu entries */
476
g_object_set_data_full (G_OBJECT (io), "indicator-custom-menuitems-data",
505
g_object_set_data_full (G_OBJECT (io), INDICATOR_DATA_MENUITEMS,
477
506
g_hash_table_new (g_direct_hash, g_direct_equal),
478
507
(GDestroyNotify) g_hash_table_destroy);
479
g_object_set_data (G_OBJECT (io), "indicator-custom-index-data", GINT_TO_POINTER (i));
508
g_object_set_data (G_OBJECT (io), INDICATOR_DATA_INDEX, GINT_TO_POINTER (i));
481
510
g_signal_connect (G_OBJECT (io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED,
482
511
G_CALLBACK (entry_added), menubar);
1665
1694
gchar *font_name, **tokens;
1668
/* Hide the clock since indicators are about to eat the screen. */
1669
gtk_widget_hide(GTK_WIDGET(clock_label));
1671
1697
g_object_get (gtk_settings_get_default (), "gtk-font-name", &font_name, NULL);
1672
1698
tokens = g_strsplit (font_name, " ", -1);
1673
1699
length = g_strv_length (tokens);
1691
1717
g_object_set (gtk_settings_get_default (), "gtk-font-name", default_font_name, NULL);
1692
/* Show the clock as needed */
1693
gtk_widget_show_all(GTK_WIDGET(clock_label));
2141
2165
strftime(time_str, 50, clock_format, timeinfo);
2142
2166
markup = g_markup_printf_escaped("<b>%s</b>", time_str);
2143
if (g_strcmp0(markup, gtk_label_get_label(GTK_LABEL(clock_label))) != 0)
2144
gtk_label_set_markup( GTK_LABEL(clock_label), markup );
2167
if (g_strcmp0(markup, gtk_label_get_label (GTK_LABEL (clock_label))) != 0)
2168
gtk_label_set_markup (GTK_LABEL (clock_label), markup);
2145
2169
g_free(markup);
2441
2465
gtk_style_context_add_class(GTK_STYLE_CONTEXT(gtk_widget_get_style_context(GTK_WIDGET(panel_window))), GTK_STYLE_CLASS_MENUBAR);
2442
2466
g_signal_connect (G_OBJECT (panel_window), "draw", G_CALLBACK (background_window_draw), NULL);
2444
gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (builder, "hostname_label")), lightdm_get_hostname ());
2445
2468
session_menu = GTK_MENU(gtk_builder_get_object (builder, "session_menu"));
2446
2469
language_menu = GTK_MENU(gtk_builder_get_object (builder, "language_menu"));
2447
clock_label = GTK_WIDGET(gtk_builder_get_object (builder, "clock_label"));
2448
2470
menubar = GTK_WIDGET (gtk_builder_get_object (builder, "menubar"));
2449
2471
/* Never allow the panel-window to be moved via the menubar */
2450
2472
#if GTK_CHECK_VERSION (3, 0, 0)
2509
2531
language_menuitem = GTK_WIDGET (gtk_builder_get_object (builder, "language_menuitem"));
2510
2532
a11y_menuitem = GTK_WIDGET (gtk_builder_get_object (builder, "a11y_menuitem"));
2511
2533
power_menuitem = GTK_WIDGET (gtk_builder_get_object (builder, "power_menuitem"));
2534
clock_menuitem = GTK_WIDGET (gtk_builder_get_object (builder, "clock_menuitem"));
2535
host_menuitem = GTK_WIDGET (gtk_builder_get_object (builder, "host_menuitem"));
2513
2537
gtk_accel_map_add_entry ("<Login>/a11y/font", GDK_KEY_F1, 0);
2514
2538
gtk_accel_map_add_entry ("<Login>/a11y/contrast", GDK_KEY_F2, 0);
2538
2562
g_free (value);
2542
gtk_widget_set_no_show_all(GTK_WIDGET(clock_label),
2543
!g_key_file_get_boolean (config, "greeter", "show-clock", NULL));
2544
gtk_widget_show_all(GTK_WIDGET(clock_label));
2545
clock_format = g_key_file_get_value (config, "greeter", "clock-format", NULL);
2547
clock_format = "%a, %H:%M";
2548
clock_timeout_thread();
2550
2565
/* Session menu */
2551
2566
if (gtk_widget_get_visible (session_menuitem))
2652
2667
g_signal_connect (G_OBJECT (power_menuitem),"activate", G_CALLBACK(power_menu_cb), NULL);
2671
if (gtk_widget_get_visible (host_menuitem))
2672
gtk_menu_item_set_label (GTK_MENU_ITEM (host_menuitem), lightdm_get_hostname ());
2675
if (gtk_widget_get_visible (clock_menuitem))
2677
gtk_menu_item_set_label (GTK_MENU_ITEM (clock_menuitem), "");
2678
clock_label = gtk_bin_get_child (GTK_BIN (clock_menuitem));
2679
clock_format = g_key_file_get_value (config, "greeter", "clock-format", NULL);
2681
clock_format = "%a, %H:%M";
2682
clock_timeout_thread ();
2683
gdk_threads_add_timeout (1000, (GSourceFunc) clock_timeout_thread, NULL);
2655
2686
/* Users combobox */
2656
2687
renderer = gtk_cell_renderer_text_new();
2657
2688
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (user_combo), renderer, TRUE);
2762
2793
gtk_widget_set_sensitive (keyboard_menuitem, a11y_keyboard_command != NULL);
2763
2794
gtk_widget_set_visible (keyboard_menuitem, a11y_keyboard_command != NULL);
2764
gdk_threads_add_timeout (1000, (GSourceFunc) clock_timeout_thread, NULL);
2766
2796
/* focus fix (source: unity-greeter) */
2767
2797
GdkWindow* root_window = gdk_get_default_root_window ();