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