chiark / gitweb /
f85c1a07917e07c2d5c1cfdbc110140fcd326b54
[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 "grdev.h"
25 #include "idev.h"
26 #include "list.h"
27 #include "macro.h"
28 #include "pty.h"
29 #include "sd-bus.h"
30 #include "sd-event.h"
31 #include "sysview.h"
32 #include "term.h"
33 #include "unifont.h"
34
35 typedef struct Manager Manager;
36 typedef struct Session Session;
37 typedef struct Display Display;
38 typedef struct Workspace Workspace;
39 typedef struct Terminal Terminal;
40
41 /*
42  * Terminals
43  */
44
45 struct Terminal {
46         Workspace *workspace;
47         LIST_FIELDS(Terminal, terminals_by_workspace);
48
49         term_utf8 utf8;
50         term_parser *parser;
51         term_screen *screen;
52         Pty *pty;
53 };
54
55 int terminal_new(Terminal **out, Workspace *w);
56 Terminal *terminal_free(Terminal *t);
57
58 DEFINE_TRIVIAL_CLEANUP_FUNC(Terminal*, terminal_free);
59
60 void terminal_resize(Terminal *t);
61 void terminal_run(Terminal *t);
62 void terminal_feed(Terminal *t, idev_data *data);
63 bool terminal_draw(Terminal *t, const grdev_display_target *target);
64
65 /*
66  * Workspaces
67  */
68
69 struct Workspace {
70         unsigned long ref;
71         Manager *manager;
72         LIST_FIELDS(Workspace, workspaces_by_manager);
73
74         LIST_HEAD(Terminal, terminal_list);
75         Terminal *current;
76
77         LIST_HEAD(Session, session_list);
78         uint32_t width;
79         uint32_t height;
80 };
81
82 int workspace_new(Workspace **out, Manager *m);
83 Workspace *workspace_ref(Workspace *w);
84 Workspace *workspace_unref(Workspace *w);
85
86 DEFINE_TRIVIAL_CLEANUP_FUNC(Workspace*, workspace_unref);
87
88 Workspace *workspace_attach(Workspace *w, Session *s);
89 Workspace *workspace_detach(Workspace *w, Session *s);
90 void workspace_refresh(Workspace *w);
91
92 void workspace_dirty(Workspace *w);
93 void workspace_feed(Workspace *w, idev_data *data);
94 bool workspace_draw(Workspace *w, const grdev_display_target *target);
95
96 /*
97  * Displays
98  */
99
100 struct Display {
101         Session *session;
102         LIST_FIELDS(Display, displays_by_session);
103         grdev_display *grdev;
104         uint32_t width;
105         uint32_t height;
106 };
107
108 int display_new(Display **out, Session *s, grdev_display *grdev);
109 Display *display_free(Display *d);
110
111 DEFINE_TRIVIAL_CLEANUP_FUNC(Display*, display_free);
112
113 void display_refresh(Display *d);
114 void display_render(Display *d, Workspace *w);
115
116 /*
117  * Sessions
118  */
119
120 struct Session {
121         Manager *manager;
122         sysview_session *sysview;
123         grdev_session *grdev;
124         idev_session *idev;
125
126         LIST_FIELDS(Session, sessions_by_workspace);
127         Workspace *my_ws;
128         Workspace *active_ws;
129
130         LIST_HEAD(Display, display_list);
131         sd_event_source *redraw_src;
132 };
133
134 int session_new(Session **out, Manager *m, sysview_session *session);
135 Session *session_free(Session *s);
136
137 DEFINE_TRIVIAL_CLEANUP_FUNC(Session*, session_free);
138
139 void session_dirty(Session *s);
140
141 void session_add_device(Session *s, sysview_device *device);
142 void session_remove_device(Session *s, sysview_device *device);
143 void session_refresh_device(Session *s, sysview_device *device, struct udev_device *ud);
144
145 /*
146  * Managers
147  */
148
149 struct Manager {
150         sd_event *event;
151         sd_bus *sysbus;
152         unifont *uf;
153         sysview_context *sysview;
154         grdev_context *grdev;
155         idev_context *idev;
156         LIST_HEAD(Workspace, workspace_list);
157 };
158
159 int manager_new(Manager **out);
160 Manager *manager_free(Manager *m);
161
162 DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
163
164 int manager_run(Manager *m);