chiark / gitweb /
b0db610400bd28f892a0f3180c42dcf35b090008
[elogind.git] / src / console / consoled.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <errno.h>
25 #include <inttypes.h>
26 #include <libudev.h>
27 #include <stdlib.h>
28 #include "grdev.h"
29 #include "idev.h"
30 #include "list.h"
31 #include "macro.h"
32 #include "pty.h"
33 #include "sd-bus.h"
34 #include "sd-event.h"
35 #include "sysview.h"
36 #include "term.h"
37 #include "unifont.h"
38
39 typedef struct Manager Manager;
40 typedef struct Session Session;
41 typedef struct Display Display;
42 typedef struct Workspace Workspace;
43 typedef struct Terminal Terminal;
44
45 /*
46  * Terminals
47  */
48
49 struct Terminal {
50         Workspace *workspace;
51         LIST_FIELDS(Terminal, terminals_by_workspace);
52
53         term_utf8 utf8;
54         term_parser *parser;
55         term_screen *screen;
56         Pty *pty;
57 };
58
59 int terminal_new(Terminal **out, Workspace *w);
60 Terminal *terminal_free(Terminal *t);
61
62 DEFINE_TRIVIAL_CLEANUP_FUNC(Terminal*, terminal_free);
63
64 void terminal_resize(Terminal *t);
65 void terminal_run(Terminal *t);
66 void terminal_feed(Terminal *t, idev_data *data);
67 bool terminal_draw(Terminal *t, const grdev_display_target *target);
68
69 /*
70  * Workspaces
71  */
72
73 struct Workspace {
74         unsigned long ref;
75         Manager *manager;
76         LIST_FIELDS(Workspace, workspaces_by_manager);
77
78         LIST_HEAD(Terminal, terminal_list);
79         Terminal *current;
80
81         LIST_HEAD(Session, session_list);
82         uint32_t width;
83         uint32_t height;
84 };
85
86 int workspace_new(Workspace **out, Manager *m);
87 Workspace *workspace_ref(Workspace *w);
88 Workspace *workspace_unref(Workspace *w);
89
90 DEFINE_TRIVIAL_CLEANUP_FUNC(Workspace*, workspace_unref);
91
92 Workspace *workspace_attach(Workspace *w, Session *s);
93 Workspace *workspace_detach(Workspace *w, Session *s);
94 void workspace_refresh(Workspace *w);
95
96 void workspace_dirty(Workspace *w);
97 void workspace_feed(Workspace *w, idev_data *data);
98 bool workspace_draw(Workspace *w, const grdev_display_target *target);
99
100 /*
101  * Displays
102  */
103
104 struct Display {
105         Session *session;
106         LIST_FIELDS(Display, displays_by_session);
107         grdev_display *grdev;
108         uint32_t width;
109         uint32_t height;
110 };
111
112 int display_new(Display **out, Session *s, grdev_display *grdev);
113 Display *display_free(Display *d);
114
115 DEFINE_TRIVIAL_CLEANUP_FUNC(Display*, display_free);
116
117 void display_refresh(Display *d);
118 void display_render(Display *d, Workspace *w);
119
120 /*
121  * Sessions
122  */
123
124 struct Session {
125         Manager *manager;
126         sysview_session *sysview;
127         grdev_session *grdev;
128         idev_session *idev;
129
130         LIST_FIELDS(Session, sessions_by_workspace);
131         Workspace *my_ws;
132         Workspace *active_ws;
133
134         LIST_HEAD(Display, display_list);
135         sd_event_source *redraw_src;
136 };
137
138 int session_new(Session **out, Manager *m, sysview_session *session);
139 Session *session_free(Session *s);
140
141 DEFINE_TRIVIAL_CLEANUP_FUNC(Session*, session_free);
142
143 void session_dirty(Session *s);
144
145 void session_add_device(Session *s, sysview_device *device);
146 void session_remove_device(Session *s, sysview_device *device);
147 void session_refresh_device(Session *s, sysview_device *device, struct udev_device *ud);
148
149 /*
150  * Managers
151  */
152
153 struct Manager {
154         sd_event *event;
155         sd_bus *sysbus;
156         unifont *uf;
157         sysview_context *sysview;
158         grdev_context *grdev;
159         idev_context *idev;
160         LIST_HEAD(Workspace, workspace_list);
161 };
162
163 int manager_new(Manager **out);
164 Manager *manager_free(Manager *m);
165
166 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
167
168 int manager_run(Manager *m);