~robert-ancell/lightdm/private-mir-connection-merge

« back to all changes in this revision

Viewing changes to src/seat-unity.c

  • Committer: Robert Ancell
  • Date: 2013-07-23 02:24:45 UTC
  • mfrom: (1723 trunk)
  • mto: This revision was merged to the branch mainline in revision 1741.
  • Revision ID: robert.ancell@canonical.com-20130723022445-gpaq8vtkp4hods7r
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#include <string.h>
13
13
#include <fcntl.h>
14
14
#include <errno.h>
 
15
#include <glib/gstdio.h>
15
16
 
16
17
#include "seat-unity.h"
17
18
#include "configuration.h"
18
19
#include "xserver-local.h"
 
20
#include "xgreeter.h"
19
21
#include "xsession.h"
20
22
#include "mir-server.h"
21
23
#include "vt.h"
71
73
    /* TRUE if using VT switching fallback */
72
74
    gboolean use_vt_switching;
73
75
 
74
 
    /* The currently visible display */
75
 
    Display *active_display;
 
76
    /* The currently visible session */
 
77
    Session *active_session;
 
78
    DisplayServer *active_display_server;
76
79
};
77
80
 
78
81
G_DEFINE_TYPE (SeatUnity, seat_unity, SEAT_TYPE);
91
94
        g_source_remove (seat->priv->compositor_timeout);
92
95
    seat->priv->compositor_timeout = 0;
93
96
 
 
97
    /* Finished with the VT */
 
98
    vt_unref (seat->priv->vt);
 
99
    seat->priv->vt = -1;
 
100
 
94
101
    if (seat_get_is_stopping (SEAT (seat)))
95
102
    {
96
103
        SEAT_CLASS (seat_unity_parent_class)->stop (SEAT (seat));
143
150
             close (fd);
144
151
         }
145
152
    }
 
153
 
 
154
    if (seat->priv->stopping_plymouth)
 
155
    {      
 
156
        seat->priv->stopping_plymouth = FALSE;
 
157
        plymouth_quit (TRUE);
 
158
    }  
146
159
}
147
160
 
148
161
static void
169
182
    SeatUnity *seat = data;
170
183
    gsize n_to_read = 0;
171
184
    guint16 id, payload_length;
172
 
    guint8 *payload;
 
185
    /*guint8 *payload;*/
173
186
  
174
187
    if (condition == G_IO_HUP)
175
188
    {
198
211
            seat->priv->read_buffer = g_realloc (seat->priv->read_buffer, n_total);
199
212
 
200
213
        status = g_io_channel_read_chars (source,
201
 
                                          seat->priv->read_buffer + seat->priv->read_buffer_n_used,
 
214
                                          (gchar *)seat->priv->read_buffer + seat->priv->read_buffer_n_used,
202
215
                                          n_to_read,
203
216
                                          &n_read,
204
217
                                          &error);
219
232
    /* Read payload */
220
233
    if (seat->priv->read_buffer_n_used < 4 + payload_length)
221
234
        return TRUE;
222
 
    payload = seat->priv->read_buffer + 4;
 
235
    /*payload = seat->priv->read_buffer + 4;*/
223
236
 
224
237
    switch (id)
225
238
    {
306
319
        if (active_vt >= vt_get_min ())
307
320
        {
308
321
            g_debug ("Compositor will replace Plymouth");
 
322
            SEAT_UNITY (seat)->priv->stopping_plymouth = TRUE;
309
323
            SEAT_UNITY (seat)->priv->vt = active_vt;
310
324
            plymouth_deactivate ();
311
325
        }
462
476
 
463
477
static DisplayServer *
464
478
seat_unity_create_display_server (Seat *seat, const gchar *session_type)
465
 
{
 
479
{  
466
480
    if (strcmp (session_type, "x") == 0)
467
481
        return create_x_server (seat);
468
482
    else if (strcmp (session_type, "mir") == 0)
474
488
    }
475
489
}
476
490
 
 
491
static Greeter *
 
492
seat_unity_create_greeter_session (Seat *seat)
 
493
{
 
494
    XGreeter *greeter_session;
 
495
 
 
496
    greeter_session = xgreeter_new ();
 
497
    session_set_env (SESSION (greeter_session), "XDG_SEAT", "seat0");
 
498
 
 
499
    return GREETER (greeter_session);
 
500
}
 
501
 
477
502
static Session *
478
 
seat_unity_create_session (Seat *seat, Display *display)
 
503
seat_unity_create_session (Seat *seat)
479
504
{
480
 
    XServerLocal *xserver;
481
505
    XSession *session;
482
 
    int vt_number;
483
 
    gchar *t;
484
 
 
485
 
    xserver = XSERVER_LOCAL (display_get_display_server (display));
486
 
 
487
 
    if (SEAT_UNITY (seat)->priv->use_vt_switching)
488
 
        vt_number = xserver_local_get_vt (xserver);
489
 
    else
490
 
        vt_number = SEAT_UNITY (seat)->priv->vt;
491
506
 
492
507
    session = xsession_new ();
493
 
    t = g_strdup_printf ("/dev/tty%d", vt_number);
494
 
    session_set_tty (SESSION (session), t);
495
 
    g_free (t);
496
 
 
497
 
    /* Set variables for logind */
498
508
    session_set_env (SESSION (session), "XDG_SEAT", "seat0");
499
 
    t = g_strdup_printf ("%d", vt_number);
500
 
    session_set_env (SESSION (session), "XDG_VTNR", t);
501
 
    g_free (t);
502
509
 
503
510
    return SESSION (session);
504
511
}
505
512
 
506
513
static void
507
 
seat_unity_set_active_display (Seat *seat, Display *display)
 
514
seat_unity_set_active_session (Seat *seat, Session *session)
508
515
{
509
 
    XServerLocal *xserver;
510
 
    const gchar *id;
 
516
    DisplayServer *display_server;
511
517
 
512
518
    /* If no compositor, have to use VT switching */
513
519
    if (SEAT_UNITY (seat)->priv->use_vt_switching)
514
520
    {
515
 
        gint vt = xserver_local_get_vt (XSERVER_LOCAL (display_get_display_server (display)));
 
521
        gint vt = display_server_get_vt (session_get_display_server (session));
516
522
        if (vt >= 0)
517
523
            vt_set_active (vt);
518
524
 
519
 
        SEAT_CLASS (seat_unity_parent_class)->set_active_display (seat, display);
520
 
        return;
521
 
    }
522
 
 
523
 
    if (display == SEAT_UNITY (seat)->priv->active_display)
524
 
        return;
525
 
    SEAT_UNITY (seat)->priv->active_display = display;
526
 
 
527
 
    xserver = XSERVER_LOCAL (display_get_display_server (display));
528
 
    id = xserver_local_get_mir_id (xserver);
529
 
 
530
 
    g_debug ("Switching to Mir session %s", id);
531
 
    write_message (SEAT_UNITY (seat), USC_MESSAGE_SET_ACTIVE_SESSION, id, strlen (id));
532
 
 
533
 
    SEAT_CLASS (seat_unity_parent_class)->set_active_display (seat, display);
 
525
        SEAT_CLASS (seat_unity_parent_class)->set_active_session (seat, session);
 
526
        return;
 
527
    }
 
528
 
 
529
    if (session == SEAT_UNITY (seat)->priv->active_session)
 
530
        return;
 
531
    SEAT_UNITY (seat)->priv->active_session = g_object_ref (session);
 
532
 
 
533
    display_server = session_get_display_server (session);
 
534
    if (SEAT_UNITY (seat)->priv->active_display_server != display_server)
 
535
    {
 
536
        const gchar *id;
 
537
 
 
538
        SEAT_UNITY (seat)->priv->active_display_server = g_object_ref (display_server);
 
539
        id = xserver_local_get_mir_id (XSERVER_LOCAL (display_server));
 
540
 
 
541
        g_debug ("Switching to Mir session %s", id);
 
542
        write_message (SEAT_UNITY (seat), USC_MESSAGE_SET_ACTIVE_SESSION, (const guint8 *) id, strlen (id));
 
543
    }
 
544
 
 
545
    SEAT_CLASS (seat_unity_parent_class)->set_active_session (seat, session);
534
546
}
535
547
 
536
 
static Display *
537
 
seat_unity_get_active_display (Seat *seat)
 
548
static Session *
 
549
seat_unity_get_active_session (Seat *seat)
538
550
{
539
551
    if (SEAT_UNITY (seat)->priv->use_vt_switching)
540
552
    {
544
556
        if (vt < 0)
545
557
            return NULL;
546
558
 
547
 
        for (link = seat_get_displays (seat); link; link = link->next)
 
559
        for (link = seat_get_sessions (seat); link; link = link->next)
548
560
        {
549
 
            Display *display = link->data;
550
 
            XServerLocal *xserver;
551
 
 
552
 
            xserver = XSERVER_LOCAL (display_get_display_server (display));
553
 
            if (xserver_local_get_vt (xserver) == vt)
554
 
                return display;
 
561
            Session *session = link->data;
 
562
            if (display_server_get_vt (session_get_display_server (session)) == vt)
 
563
                return session;
555
564
        }
556
565
 
557
566
        return NULL;
558
567
    }
559
568
 
560
 
    return SEAT_UNITY (seat)->priv->active_display;
 
569
    return SEAT_UNITY (seat)->priv->active_session;
561
570
}
562
571
 
563
572
static void
564
 
seat_unity_run_script (Seat *seat, Display *display, Process *script)
 
573
seat_unity_run_script (Seat *seat, DisplayServer *display_server, Process *script)
565
574
{
566
575
    const gchar *path;
567
576
    XServerLocal *xserver;
568
577
 
569
 
    xserver = XSERVER_LOCAL (display_get_display_server (display));
 
578
    xserver = XSERVER_LOCAL (display_server);
570
579
    path = xserver_local_get_authority_file_path (xserver);
571
580
    process_set_env (script, "DISPLAY", xserver_get_address (XSERVER (xserver)));
572
581
    process_set_env (script, "XAUTHORITY", path);
573
582
 
574
 
    SEAT_CLASS (seat_unity_parent_class)->run_script (seat, display, script);
 
583
    SEAT_CLASS (seat_unity_parent_class)->run_script (seat, display_server, script);
575
584
}
576
585
 
577
586
static void
588
597
}
589
598
 
590
599
static void
591
 
seat_unity_display_removed (Seat *seat, Display *display)
592
 
{
593
 
    if (seat_get_is_stopping (seat))
594
 
        return;
595
 
 
596
 
    /* If this is the only display and it failed to start then stop this seat */
597
 
    if (g_list_length (seat_get_displays (seat)) == 0 && !display_get_is_ready (display))
598
 
    {
599
 
        g_debug ("Stopping Unity seat, failed to start a display");
600
 
        seat_stop (seat);
601
 
        return;
602
 
    }
603
 
 
604
 
    /* Show a new greeter */
605
 
    if (display == seat_get_active_display (seat))
606
 
    {
607
 
        g_debug ("Active display stopped, switching to greeter");
608
 
        seat_switch_to_greeter (seat);
609
 
    }
610
 
}
611
 
 
612
 
static void
613
600
seat_unity_init (SeatUnity *seat)
614
601
{
615
602
    seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_UNITY_TYPE, SeatUnityPrivate);
633
620
    g_io_channel_unref (seat->priv->from_compositor_channel);
634
621
    g_free (seat->priv->read_buffer);
635
622
    g_object_unref (seat->priv->compositor_process);
 
623
    if (seat->priv->active_session)
 
624
        g_object_unref (seat->priv->active_session);
 
625
    if (seat->priv->active_display_server)
 
626
        g_object_unref (seat->priv->active_display_server);
636
627
 
637
628
    G_OBJECT_CLASS (seat_unity_parent_class)->finalize (object);
638
629
}
647
638
    seat_class->setup = seat_unity_setup;
648
639
    seat_class->start = seat_unity_start;
649
640
    seat_class->create_display_server = seat_unity_create_display_server;
 
641
    seat_class->create_greeter_session = seat_unity_create_greeter_session;
650
642
    seat_class->create_session = seat_unity_create_session;
651
 
    seat_class->set_active_display = seat_unity_set_active_display;
652
 
    seat_class->get_active_display = seat_unity_get_active_display;
 
643
    seat_class->set_active_session = seat_unity_set_active_session;
 
644
    seat_class->get_active_session = seat_unity_get_active_session;
653
645
    seat_class->run_script = seat_unity_run_script;
654
646
    seat_class->stop = seat_unity_stop;
655
 
    seat_class->display_removed = seat_unity_display_removed;
656
647
 
657
648
    g_type_class_add_private (klass, sizeof (SeatUnityPrivate));
658
649
}