~kalgasnik/lightdm-gtk-greeter/gtk-710888-GtkInfoBar-visibility

« back to all changes in this revision

Viewing changes to src/lightdm-gtk-greeter.c

  • Committer: Sean Davis
  • Date: 2015-01-27 12:27:46 UTC
  • mfrom: (316.1.4 pre2.0-bugfixes)
  • Revision ID: smd.seandavis@gmail.com-20150127122746-vxtg73e7w2qiglej
Merge pre2.0 fixes branch, tested, builds with make distcheck, all is well

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
#include "src/lightdm-gtk-greeter-css-fallback.h"
54
54
#include "src/lightdm-gtk-greeter-css-application.h"
55
55
 
56
 
 
57
56
static LightDMGreeter *greeter;
58
57
 
59
58
/* State file */
61
60
static gchar *state_filename;
62
61
static void save_state_file (void);
63
62
 
64
 
/* Terminating */
65
 
GSList *pids_to_close = NULL;
 
63
/* List of spawned processes */
 
64
static GSList *pids_to_close = NULL;
 
65
static GPid spawn_argv_pid (gchar **argv, GSpawnFlags flags, gint *pfd, GError **perror);
 
66
#if defined(AT_SPI_COMMAND) || defined(INDICATOR_SERVICES_COMMAND)
 
67
static GPid spawn_line_pid (const gchar *line, GSpawnFlags flags, GError **perror);
 
68
#endif
 
69
static void close_pid (GPid pid, gboolean remove);
66
70
static void sigterm_cb (gpointer user_data);
67
 
static void close_pid (GPid *pid, gboolean remove);
68
71
 
69
72
/* Screen window */
70
73
static GtkOverlay *screen_overlay;
148
151
/* External command (keyboard, reader) */
149
152
typedef struct
150
153
{
 
154
    const gchar *name;
 
155
 
151
156
    gchar **argv;
152
157
    gint argc;
153
158
 
156
161
    GtkWidget *widget;
157
162
} MenuCommand;
158
163
 
159
 
static MenuCommand *menu_command_parse (const gchar *value, GtkWidget *menu_item);
160
 
static MenuCommand *menu_command_parse_extended (const gchar *value, GtkWidget *menu_item,
 
164
static MenuCommand *menu_command_parse (const gchar *name, const gchar *value, GtkWidget *menu_item);
 
165
static MenuCommand *menu_command_parse_extended (const gchar *name,
 
166
                                                 const gchar *value, GtkWidget *menu_item,
161
167
                                                 const gchar *xid_app, const gchar *xid_arg);
162
168
static gboolean menu_command_run (MenuCommand *command);
163
169
static gboolean menu_command_stop (MenuCommand *command);
349
355
 
350
356
/* Terminating */
351
357
 
 
358
static GPid
 
359
spawn_argv_pid (gchar **argv, GSpawnFlags flags, gint *pfd, GError **perror)
 
360
{
 
361
    GPid pid = 0;
 
362
    GError *error = NULL;
 
363
    gboolean spawned = FALSE;
 
364
 
 
365
    if (pfd)
 
366
        spawned = g_spawn_async_with_pipes (NULL, argv, NULL, flags, NULL, NULL, &pid, NULL, pfd, NULL, perror);
 
367
    else
 
368
        spawned = g_spawn_async (NULL, argv, NULL, flags, NULL, NULL, &pid, &error);
 
369
 
 
370
    if (spawned)
 
371
    {
 
372
        pids_to_close = g_slist_prepend (pids_to_close, GINT_TO_POINTER (pid));
 
373
        g_debug ("[PIDs] Command executed (#%d): %s", pid, argv[0]);
 
374
    }
 
375
    else if (perror)
 
376
    {
 
377
        *perror = error;
 
378
    }
 
379
    else
 
380
    {
 
381
        g_warning ("[PIDs] Failed to execute command: %s", argv[0]);
 
382
        g_clear_error (&error);
 
383
    }
 
384
 
 
385
    return pid;
 
386
}
 
387
 
 
388
#if defined(AT_SPI_COMMAND) || defined(INDICATOR_SERVICES_COMMAND)
 
389
static GPid
 
390
spawn_line_pid (const gchar *line, GSpawnFlags flags, GError **perror)
 
391
{
 
392
    gint argc = 0;
 
393
    gchar **argv = NULL;
 
394
    GError *error = NULL;
 
395
 
 
396
    if (g_shell_parse_argv (line, &argc, &argv, &error))
 
397
    {
 
398
        GPid pid = spawn_argv_pid (argv, flags, NULL, perror);
 
399
        g_strfreev (argv);
 
400
        return pid;
 
401
    }
 
402
    else if (!perror && error)
 
403
    {
 
404
        g_warning ("[PIDs] Failed to parse command line: %s, %s", error->message, line);
 
405
        g_clear_error (&error);
 
406
    }
 
407
    else if (error)
 
408
        *perror = error;
 
409
 
 
410
    return 0;
 
411
}
 
412
#endif
 
413
 
 
414
static void
 
415
close_pid (GPid pid, gboolean remove)
 
416
{
 
417
    if (!pid)
 
418
        return;
 
419
 
 
420
    if (remove)
 
421
        pids_to_close = g_slist_remove (pids_to_close, GINT_TO_POINTER (pid));
 
422
 
 
423
    if (kill (pid, SIGTERM) == 0)
 
424
        g_debug ("[PIDs] Process terminated: #%d", pid);
 
425
    else
 
426
        g_warning ("[PIDs] Failed to terminate process #%d: %s", pid, g_strerror (errno));
 
427
 
 
428
    waitpid (pid, NULL, 0);
 
429
}
 
430
 
352
431
static void
353
432
sigterm_cb (gpointer user_data)
354
433
{
358
437
    gtk_main_quit ();
359
438
}
360
439
 
361
 
static void
362
 
close_pid (GPid *ppid, gboolean remove)
363
 
{
364
 
    if (!ppid || !*ppid)
365
 
        return;
366
 
 
367
 
    if (remove)
368
 
        pids_to_close = g_slist_remove (pids_to_close, GINT_TO_POINTER (*ppid));
369
 
 
370
 
    kill (*ppid, SIGTERM);
371
 
    waitpid (*ppid, NULL, 0);
372
 
    *ppid = 0;
373
 
}
374
 
 
375
440
/* Power window */
376
441
 
377
442
static gboolean
682
747
/* MenuCommand */
683
748
 
684
749
static MenuCommand*
685
 
menu_command_parse (const gchar *value, GtkWidget *menu_item)
 
750
menu_command_parse (const gchar *name, const gchar *value, GtkWidget *menu_item)
686
751
{
687
 
    return menu_command_parse_extended (value, menu_item, NULL, NULL);
 
752
    return menu_command_parse_extended (name, value, menu_item, NULL, NULL);
688
753
}
689
754
 
690
755
static MenuCommand*
691
 
menu_command_parse_extended (const gchar *value,    /* String to parse */
 
756
menu_command_parse_extended (const gchar *name,
 
757
                             const gchar *value,    /* String to parse */
692
758
                             GtkWidget *menu_item,  /* Menu item to connect */
693
759
                             const gchar *xid_app,  /* Program that have "xembed" mode support */
694
760
                             const gchar *xid_arg)  /* Argument that must be added to command line */
703
769
    if (!g_shell_parse_argv (value, &argc, &argv, &error))
704
770
    {
705
771
        if (error)
706
 
            g_warning ("Failed to parse command line: %s", error->message);
 
772
            g_warning ("[Command/%s] Failed to parse command line: %s", name, error->message);
707
773
        g_clear_error (&error);
708
774
        return NULL;
709
775
    }
737
803
            else
738
804
            {
739
805
                if (error)
740
 
                    g_warning ("Failed to parse command line: %s", error->message);
 
806
                    g_warning ("[Command/%s] Failed to parse command line: %s", name, error->message);
741
807
                g_clear_error (&error);
742
808
            }
743
809
            g_free (new_value);
749
815
            gtk_overlay_add_overlay (screen_overlay, command->widget);
750
816
        }
751
817
    }
 
818
    command->name = name;
752
819
    return command;
753
820
}
754
821
 
758
825
    g_return_val_if_fail (command && g_strv_length (command->argv), FALSE);
759
826
 
760
827
    GError *error = NULL;
761
 
    gboolean spawned = FALSE;
 
828
    command->pid = 0;
 
829
 
 
830
    g_debug ("[Command/%s] Running command", command->name);
 
831
 
762
832
    if (command->widget)
763
833
    {
764
834
        GtkSocket* socket = NULL;
765
835
        gint out_fd = 0;
 
836
        GPid pid = spawn_argv_pid (command->argv, G_SPAWN_SEARCH_PATH, &out_fd, &error);
766
837
 
767
 
        if (g_spawn_async_with_pipes (NULL, command->argv, NULL, G_SPAWN_SEARCH_PATH,
768
 
                                      NULL, NULL, &command->pid, NULL, &out_fd, NULL, &error))
 
838
        if (pid && out_fd)
769
839
        {
770
840
            gchar* text = NULL;
771
841
            GIOChannel* out_channel = g_io_channel_unix_new (out_fd);
782
852
                    gtk_container_add (GTK_CONTAINER (command->widget), GTK_WIDGET (socket));
783
853
                    gtk_socket_add_id (socket, id);
784
854
                    gtk_widget_show_all (GTK_WIDGET (command->widget));
785
 
                    spawned = TRUE;
 
855
 
 
856
                    command->pid = pid;
786
857
                }
787
858
                else
788
 
                    g_warning ("Failed to get '%s' socket: unrecognized output", command->argv[0]);
 
859
                    g_warning ("[Command/%s] Failed to get '%s' socket for: unrecognized output",
 
860
                               command->name, command->argv[0]);
789
861
 
790
862
                g_free (text);
791
863
            }
792
864
        }
 
865
 
 
866
        if (!command->pid && pid)
 
867
            close_pid (pid, TRUE);
793
868
    }
794
869
    else
795
870
    {
796
 
        spawned = g_spawn_async (NULL, command->argv, NULL,
797
 
                                 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
798
 
                                 NULL, NULL, &command->pid, &error);
799
 
        if (spawned)
 
871
        command->pid = spawn_argv_pid (command->argv, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, &error);
 
872
        if (command->pid)
800
873
            g_child_watch_add (command->pid, (GChildWatchFunc)menu_command_terminated_cb, command);
801
874
    }
802
875
 
803
 
    if (spawned)
804
 
    {
805
 
        pids_to_close = g_slist_prepend (pids_to_close, GINT_TO_POINTER (command->pid));
806
 
    }
807
 
    else
 
876
    if (!command->pid)
808
877
    {
809
878
        if (error)
810
 
            g_warning ("Command spawning error: '%s'", error->message);
811
 
        command->pid = 0;
 
879
            g_warning ("[Command/%s] Failed to run: %s", command->name, error->message);
812
880
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (command->menu_item), FALSE);
813
881
    }
814
882
    g_clear_error (&error);
815
 
    return spawned;
 
883
 
 
884
    return command->pid;
816
885
}
817
886
 
818
887
static gboolean
822
891
 
823
892
    if (command->pid)
824
893
    {
825
 
        close_pid (&command->pid, TRUE);
 
894
        g_debug ("[Command/%s] Stopping command", command->name);
 
895
        close_pid (command->pid, TRUE);
 
896
        command->pid = 0;
826
897
        if (command->menu_item)
827
898
            gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (command->menu_item), FALSE);
828
899
        if (command->widget)
1156
1227
 
1157
1228
    g_return_val_if_fail (INDICATOR_IS_OBJECT (io), FALSE);
1158
1229
 
1159
 
    g_signal_emit_by_name (io, "scroll", 1, event->direction);
1160
 
    g_signal_emit_by_name (io, "scroll-entry", entry, 1, event->direction);
 
1230
    g_signal_emit_by_name(io, INDICATOR_OBJECT_SIGNAL_ENTRY_SCROLLED, entry, 1, event->direction);
1161
1231
 
1162
1232
    return FALSE;
1163
1233
}
1275
1345
    {
1276
1346
        /* Close any open menus instead of opening one */
1277
1347
        entries = indicator_object_get_entries (io);
1278
 
        for (lp = entries; lp; lp = g_list_next (entry))
 
1348
        for (lp = entries; lp; lp = g_list_next (lp))
1279
1349
        {
1280
1350
            entrydata = lp->data;
1281
1351
            gtk_menu_popdown (entrydata->menu);
1434
1504
            /* Don't allow virtual file systems? */
1435
1505
            greeter_set_env ("GIO_USE_VFS", "local");
1436
1506
            greeter_set_env ("GVFS_DISABLE_FUSE", "1");
1437
 
 
1438
 
            #ifdef START_INDICATOR_SERVICES
1439
 
            gchar *INDICATORS_CMD[] = {"init", "--user", "--startup-event", "indicator-services-start", NULL};
1440
 
            GError *error = NULL;
1441
 
            GPid pid = 0;
1442
 
 
1443
 
            if (g_spawn_async (NULL, INDICATORS_CMD, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &error))
1444
 
                pids_to_close = g_slist_prepend (pids_to_close, GINT_TO_POINTER (pid));
1445
 
            else
1446
 
                g_warning ("[Greeter] Failed to run 'init --startup-event indicator-services-start': %s", error->message);
1447
 
            g_clear_error (&error);
1448
 
            #endif
1449
1507
            inited = TRUE;
1450
1508
        }
1451
1509
 
2553
2611
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2554
2612
    textdomain (GETTEXT_PACKAGE);
2555
2613
 
2556
 
    g_unix_signal_add (SIGTERM, (GSourceFunc)sigterm_cb, pids_to_close);
 
2614
    g_unix_signal_add (SIGTERM, (GSourceFunc)sigterm_cb, NULL);
2557
2615
 
2558
2616
    config = g_key_file_new ();
2559
2617
    g_key_file_load_from_file (config, CONFIG_FILE, G_KEY_FILE_NONE, &error);
2692
2750
        g_object_set (gtk_settings_get_default (), "gtk-xft-rgba", value, NULL);
2693
2751
    g_free (value);
2694
2752
 
 
2753
    #ifdef AT_SPI_COMMAND
 
2754
    spawn_line_pid (AT_SPI_COMMAND, G_SPAWN_SEARCH_PATH, NULL);
 
2755
    #endif
 
2756
 
 
2757
    #ifdef INDICATOR_SERVICES_COMMAND
 
2758
    spawn_line_pid (INDICATOR_SERVICES_COMMAND, G_SPAWN_SEARCH_PATH, NULL);
 
2759
    #endif
2695
2760
 
2696
2761
    builder = gtk_builder_new ();
2697
2762
    if (!gtk_builder_add_from_string (builder, lightdm_gtk_greeter_ui,
2865
2930
    }
2866
2931
 
2867
2932
    value = g_key_file_get_value (config, "greeter", "keyboard", NULL);
2868
 
    a11y_keyboard_command = menu_command_parse_extended (value, keyboard_menuitem, "onboard", "--xid");
 
2933
    a11y_keyboard_command = menu_command_parse_extended ("keyboard", value, keyboard_menuitem, "onboard", "--xid");
2869
2934
    g_free (value);
2870
2935
 
2871
2936
    gtk_widget_set_visible (keyboard_menuitem, a11y_keyboard_command != NULL);
2872
2937
 
2873
2938
    value = g_key_file_get_value (config, "greeter", "reader", NULL);
2874
 
    a11y_reader_command = menu_command_parse (value, reader_menuitem);
 
2939
    a11y_reader_command = menu_command_parse ("reader", value, reader_menuitem);
2875
2940
    gtk_widget_set_visible (reader_menuitem, a11y_reader_command != NULL);
2876
2941
    g_free (value);
2877
2942
 
2878
 
    if (a11y_keyboard_command || a11y_reader_command)
2879
 
    {
2880
 
        gchar *AT_SPI_CMD[] = {"/usr/lib/at-spi2-core/at-spi-bus-launcher", "--launch-immediately", NULL};
2881
 
        GPid pid = 0;
2882
 
        if (g_spawn_async (NULL, AT_SPI_CMD, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &error))
2883
 
        {
2884
 
            g_debug ("[Greeter] AT-SPI launched");
2885
 
            pids_to_close = g_slist_prepend (pids_to_close, GINT_TO_POINTER (pid));
2886
 
        }
2887
 
        else
2888
 
            g_warning ("[Greeter] Failed to launch AT-SPI: %s", error->message);
2889
 
        g_clear_error (&error);
2890
 
    }
2891
 
 
2892
2943
    /* Power menu */
2893
2944
    if (gtk_widget_get_visible (power_menuitem))
2894
2945
    {