compositor: quick fix for sub-surface mapping
[profile/ivi/weston-ivi-shell.git] / src / logind-util.h
1 /*
2  * Copyright © 2013 David Herrmann
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include "config.h"
24
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "compositor.h"
31
32 struct weston_logind;
33
34 #if defined(HAVE_SYSTEMD_LOGIN) && defined(HAVE_DBUS)
35
36 #include <systemd/sd-login.h>
37
38 int
39 weston_logind_open(struct weston_logind *wl, const char *path,
40                    int flags);
41
42 void
43 weston_logind_close(struct weston_logind *wl, int fd);
44
45 void
46 weston_logind_restore(struct weston_logind *wl);
47
48 int
49 weston_logind_activate_vt(struct weston_logind *wl, int vt);
50
51 int
52 weston_logind_connect(struct weston_logind **out,
53                       struct weston_compositor *compositor,
54                       const char *seat_id, int tty);
55
56 void
57 weston_logind_destroy(struct weston_logind *wl);
58
59 static inline int
60 weston_sd_session_get_vt(const char *sid, unsigned int *out)
61 {
62 #ifdef HAVE_SYSTEMD_LOGIN_209
63         return sd_session_get_vt(sid, out);
64 #else
65         int r;
66         char *tty;
67
68         r = sd_session_get_tty(sid, &tty);
69         if (r < 0)
70                 return r;
71
72         r = sscanf(tty, "tty%u", out);
73         free(tty);
74
75         if (r != 1)
76                 return -EINVAL;
77
78         return 0;
79 #endif
80 }
81
82 #else /* defined(HAVE_SYSTEMD_LOGIN) && defined(HAVE_DBUS) */
83
84 static inline int
85 weston_logind_open(struct weston_logind *wl, const char *path,
86                    int flags)
87 {
88         return -ENOSYS;
89 }
90
91 static inline void
92 weston_logind_close(struct weston_logind *wl, int fd)
93 {
94 }
95
96 static inline void
97 weston_logind_restore(struct weston_logind *wl)
98 {
99 }
100
101 static inline int
102 weston_logind_activate_vt(struct weston_logind *wl, int vt)
103 {
104         return -ENOSYS;
105 }
106
107 static inline int
108 weston_logind_connect(struct weston_logind **out,
109                       struct weston_compositor *compositor,
110                       const char *seat_id, int tty)
111 {
112         return -ENOSYS;
113 }
114
115 static inline void
116 weston_logind_destroy(struct weston_logind *wl)
117 {
118 }
119
120 #endif /* defined(HAVE_SYSTEMD_LOGIN) && defined(HAVE_DBUS) */