chiark / gitweb /
terminal: forward evdev RESYNC events to linked devices
[elogind.git] / src / libsystemd-terminal / sysview-internal.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright (C) 2014 David Herrmann <dh.herrmann@gmail.com>
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #pragma once
23
24 #include <inttypes.h>
25 #include <libudev.h>
26 #include <stdbool.h>
27 #include <stdlib.h>
28 #include <systemd/sd-bus.h>
29 #include <systemd/sd-event.h>
30 #include "hashmap.h"
31 #include "list.h"
32 #include "macro.h"
33 #include "sysview.h"
34 #include "util.h"
35
36 /*
37  * Devices
38  */
39
40 struct sysview_device {
41         sysview_seat *seat;
42         char *name;
43         unsigned int type;
44
45         union {
46                 struct {
47                         struct udev_device *ud;
48                 } evdev, drm;
49         };
50 };
51
52 sysview_device *sysview_find_device(sysview_context *c, const char *name);
53
54 int sysview_device_new(sysview_device **out, sysview_seat *seat, const char *name);
55 sysview_device *sysview_device_free(sysview_device *device);
56
57 DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_device*, sysview_device_free);
58
59 /*
60  * Sessions
61  */
62
63 struct sysview_session {
64         sysview_seat *seat;
65         char *name;
66         char *path;
67
68         sd_bus_slot *slot_take_control;
69
70         bool custom : 1;
71         bool public : 1;
72         bool wants_control : 1;
73         bool has_control : 1;
74 };
75
76 sysview_session *sysview_find_session(sysview_context *c, const char *name);
77
78 int sysview_session_new(sysview_session **out, sysview_seat *seat, const char *name);
79 sysview_session *sysview_session_free(sysview_session *session);
80
81 DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_session*, sysview_session_free);
82
83 /*
84  * Seats
85  */
86
87 struct sysview_seat {
88         sysview_context *context;
89         char *name;
90
91         Hashmap *session_map;
92         Hashmap *device_map;
93
94         bool scanned : 1;
95         bool public : 1;
96 };
97
98 sysview_seat *sysview_find_seat(sysview_context *c, const char *name);
99
100 int sysview_seat_new(sysview_seat **out, sysview_context *c, const char *name);
101 sysview_seat *sysview_seat_free(sysview_seat *seat);
102
103 DEFINE_TRIVIAL_CLEANUP_FUNC(sysview_seat*, sysview_seat_free);
104
105 /*
106  * Contexts
107  */
108
109 struct sysview_context {
110         sd_event *event;
111         sd_bus *sysbus;
112         struct udev *ud;
113         uint64_t custom_sid;
114
115         Hashmap *seat_map;
116         Hashmap *session_map;
117         Hashmap *device_map;
118
119         sd_event_source *scan_src;
120         sysview_event_fn event_fn;
121         void *userdata;
122
123         /* udev scanner */
124         struct udev_monitor *ud_monitor;
125         sd_event_source *ud_monitor_src;
126
127         /* logind scanner */
128         sd_bus_slot *ld_slot_manager_signal;
129         sd_bus_slot *ld_slot_list_seats;
130         sd_bus_slot *ld_slot_list_sessions;
131
132         bool scan_logind : 1;
133         bool scan_evdev : 1;
134         bool scan_drm : 1;
135         bool running : 1;
136         bool scanned : 1;
137         bool rescan : 1;
138 };
139
140 int sysview_context_rescan(sysview_context *c);