]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/x-server-xmir.c
Fix guest session AppArmor rules for input methods and remove incorrect rule that...
[sojka/lightdm.git] / src / x-server-xmir.c
1 /*
2  * Copyright (C) 2010-2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation, either version 3 of the License, or (at your option) any later
7  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
8  * license.
9  */
10
11 #include <config.h>
12
13 #include "x-server-xmir.h"
14
15 struct XServerXmirPrivate
16 {
17     /* Compositor we are running under */
18     UnitySystemCompositor *compositor;
19
20     /* TRUE if we are waiting for the compositor to start */
21     gboolean waiting_for_compositor;
22
23     /* ID to report to Mir */
24     gchar *mir_id;
25
26     /* Filename of socket Mir is listening on */
27     gchar *mir_socket;
28 };
29
30 G_DEFINE_TYPE (XServerXmir, x_server_xmir, X_SERVER_LOCAL_TYPE);
31
32 static void
33 compositor_ready_cb (UnitySystemCompositor *compositor, XServerXmir *server)
34 {
35     gboolean result;
36
37     if (!server->priv->waiting_for_compositor)
38         return;
39     server->priv->waiting_for_compositor = FALSE;
40
41     result = X_SERVER_LOCAL_CLASS (x_server_xmir_parent_class)->start (DISPLAY_SERVER (server));
42     if (!result)
43         display_server_stop (DISPLAY_SERVER (server));
44 }
45
46 static void
47 compositor_stopped_cb (UnitySystemCompositor *compositor, XServerXmir *server)
48 {
49     display_server_stop (DISPLAY_SERVER (server));  
50 }
51
52 XServerXmir *
53 x_server_xmir_new (UnitySystemCompositor *compositor)
54 {
55     XServerXmir *server;
56
57     server = g_object_new (X_SERVER_XMIR_TYPE, NULL);
58     x_server_local_set_command (X_SERVER_LOCAL (server), "Xmir");
59     server->priv->compositor = g_object_ref (compositor);
60     g_signal_connect (compositor, DISPLAY_SERVER_SIGNAL_READY, G_CALLBACK (compositor_ready_cb), server);
61     g_signal_connect (compositor, DISPLAY_SERVER_SIGNAL_STOPPED, G_CALLBACK (compositor_stopped_cb), server);
62
63     return server;
64 }
65
66 void
67 x_server_xmir_set_mir_id (XServerXmir *server, const gchar *id)
68 {
69     g_return_if_fail (server != NULL);
70     g_free (server->priv->mir_id);
71     server->priv->mir_id = g_strdup (id);
72 }
73
74 const gchar *
75 x_server_xmir_get_mir_id (XServerXmir *server)
76 {
77     g_return_val_if_fail (server != NULL, NULL);
78     return server->priv->mir_id;
79 }
80
81 void
82 x_server_xmir_set_mir_socket (XServerXmir *server, const gchar *socket)
83 {
84     g_return_if_fail (server != NULL);
85     g_free (server->priv->mir_socket);
86     server->priv->mir_socket = g_strdup (socket);
87 }
88
89 static void
90 x_server_xmir_add_args (XServerLocal *x_server, GString *command)
91 {
92     XServerXmir *server = X_SERVER_XMIR (x_server);
93
94     if (server->priv->mir_id)
95         g_string_append_printf (command, " -mir %s", server->priv->mir_id);
96
97     if (server->priv->mir_socket)
98         g_string_append_printf (command, " -mirSocket %s", server->priv->mir_socket);
99 }
100
101 static DisplayServer *
102 x_server_xmir_get_parent (DisplayServer *server)
103 {
104     return DISPLAY_SERVER (X_SERVER_XMIR (server)->priv->compositor);
105 }
106
107 static gint
108 x_server_xmir_get_vt (DisplayServer *server)
109 {
110     return display_server_get_vt (DISPLAY_SERVER (X_SERVER_XMIR (server)->priv->compositor));
111 }
112
113 static gboolean
114 x_server_xmir_start (DisplayServer *display_server)
115 {
116     XServerXmir *server = X_SERVER_XMIR (display_server);
117
118     if (display_server_get_is_ready (DISPLAY_SERVER (server->priv->compositor)))
119         return X_SERVER_LOCAL_CLASS (x_server_xmir_parent_class)->start (display_server);
120     else
121     {
122         if (!server->priv->waiting_for_compositor)
123         {
124             server->priv->waiting_for_compositor = TRUE;
125             if (!display_server_start (DISPLAY_SERVER (server->priv->compositor)))
126                 return FALSE;
127         }
128         return TRUE;
129     }
130 }
131
132 static void
133 x_server_xmir_init (XServerXmir *server)
134 {
135     server->priv = G_TYPE_INSTANCE_GET_PRIVATE (server, X_SERVER_XMIR_TYPE, XServerXmirPrivate);
136 }
137
138 static void
139 x_server_xmir_finalize (GObject *object)
140 {
141     XServerXmir *self = X_SERVER_XMIR (object);
142
143     if (self->priv->compositor)
144     {
145         g_signal_handlers_disconnect_matched (self->priv->compositor, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, self);
146         g_object_unref (self->priv->compositor);
147     }
148     g_free (self->priv->mir_id);
149     g_free (self->priv->mir_socket);
150
151     G_OBJECT_CLASS (x_server_xmir_parent_class)->finalize (object);
152 }
153
154 static void
155 x_server_xmir_class_init (XServerXmirClass *klass)
156 {
157     GObjectClass *object_class = G_OBJECT_CLASS (klass);
158     DisplayServerClass *display_server_class = DISPLAY_SERVER_CLASS (klass);
159     XServerLocalClass *x_server_local_class = X_SERVER_LOCAL_CLASS (klass);  
160
161     x_server_local_class->add_args = x_server_xmir_add_args;
162     display_server_class->get_parent = x_server_xmir_get_parent;
163     display_server_class->get_vt = x_server_xmir_get_vt;
164     display_server_class->start = x_server_xmir_start;
165     object_class->finalize = x_server_xmir_finalize;
166
167     g_type_class_add_private (klass, sizeof (XServerXmirPrivate));
168 }