shl: move githead into a source file
[platform/upstream/kmscon.git] / src / tsm_screen.h
1 /*
2  * TSM - Screen Management
3  *
4  * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
5  * Copyright (c) 2011 University of Tuebingen
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files
9  * (the "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included
16  * in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26
27 /*
28  * Screen Management
29  * This screen does not emulate any terminal at all. This subsystem just
30  * provides functions to draw a screen to a framebuffer and modifying the state
31  * of it.
32  */
33
34 #ifndef TSM_SCREEN_H
35 #define TSM_SCREEN_H
36
37 #include <inttypes.h>
38 #include <stdarg.h>
39 #include <stdbool.h>
40 #include <stdlib.h>
41 #include "tsm_unicode.h"
42
43 /* screen objects */
44
45 struct tsm_screen;
46
47 /**
48  * tsm_log_t:
49  * @data: user-provided data
50  * @file: Source code file where the log message originated or NULL
51  * @line: Line number in source code or 0
52  * @func: C function name or NULL
53  * @subs: Subsystem where the message came from or NULL
54  * @sev: Kernel-style severity between 0=FATAL and 7=DEBUG
55  * @format: printf-formatted message
56  * @args: arguments for printf-style @format
57  *
58  * This is the type of a logging callback function. You can always pass NULL
59  * instead of such a function to disable logging.
60  */
61 typedef void (*tsm_log_t) (void *data,
62                            const char *file,
63                            int line,
64                            const char *func,
65                            const char *subs,
66                            unsigned int sev,
67                            const char *format,
68                            va_list args);
69
70 #define TSM_SCREEN_INSERT_MODE  0x01
71 #define TSM_SCREEN_AUTO_WRAP    0x02
72 #define TSM_SCREEN_REL_ORIGIN   0x04
73 #define TSM_SCREEN_INVERSE      0x08
74 #define TSM_SCREEN_HIDE_CURSOR  0x10
75 #define TSM_SCREEN_FIXED_POS    0x20
76 #define TSM_SCREEN_ALTERNATE    0x40
77
78 #define TSM_SCREEN_OPT_RENDER_TIMING    0x01
79
80 struct tsm_screen_attr {
81         int8_t fccode;                  /* foreground color code or <0 for rgb */
82         int8_t bccode;                  /* background color code or <0 for rgb */
83         uint8_t fr;                     /* foreground red */
84         uint8_t fg;                     /* foreground green */
85         uint8_t fb;                     /* foreground blue */
86         uint8_t br;                     /* background red */
87         uint8_t bg;                     /* background green */
88         uint8_t bb;                     /* background blue */
89         unsigned int bold : 1;          /* bold character */
90         unsigned int underline : 1;     /* underlined character */
91         unsigned int inverse : 1;       /* inverse colors */
92         unsigned int protect : 1;       /* cannot be erased */
93 };
94
95 typedef int (*tsm_screen_prepare_cb) (struct tsm_screen *con,
96                                       void *data);
97 typedef int (*tsm_screen_draw_cb) (struct tsm_screen *con,
98                                    uint32_t id,
99                                    const uint32_t *ch,
100                                    size_t len,
101                                    unsigned int width,
102                                    unsigned int posx,
103                                    unsigned int posy,
104                                    const struct tsm_screen_attr *attr,
105                                    void *data);
106 typedef int (*tsm_screen_render_cb) (struct tsm_screen *con,
107                                      void *data);
108
109 int tsm_screen_new(struct tsm_screen **out, tsm_log_t log, void *log_data);
110 void tsm_screen_ref(struct tsm_screen *con);
111 void tsm_screen_unref(struct tsm_screen *con);
112
113 void tsm_screen_set_opts(struct tsm_screen *scr, unsigned int opts);
114 void tsm_screen_reset_opts(struct tsm_screen *scr, unsigned int opts);
115 unsigned int tsm_screen_get_opts(struct tsm_screen *scr);
116
117 unsigned int tsm_screen_get_width(struct tsm_screen *con);
118 unsigned int tsm_screen_get_height(struct tsm_screen *con);
119 int tsm_screen_resize(struct tsm_screen *con, unsigned int x,
120                       unsigned int y);
121 int tsm_screen_set_margins(struct tsm_screen *con,
122                            unsigned int top, unsigned int bottom);
123 void tsm_screen_set_max_sb(struct tsm_screen *con, unsigned int max);
124 void tsm_screen_clear_sb(struct tsm_screen *con);
125
126 void tsm_screen_sb_up(struct tsm_screen *con, unsigned int num);
127 void tsm_screen_sb_down(struct tsm_screen *con, unsigned int num);
128 void tsm_screen_sb_page_up(struct tsm_screen *con, unsigned int num);
129 void tsm_screen_sb_page_down(struct tsm_screen *con, unsigned int num);
130 void tsm_screen_sb_reset(struct tsm_screen *con);
131
132 void tsm_screen_set_def_attr(struct tsm_screen *con,
133                              const struct tsm_screen_attr *attr);
134 void tsm_screen_reset(struct tsm_screen *con);
135 void tsm_screen_set_flags(struct tsm_screen *con, unsigned int flags);
136 void tsm_screen_reset_flags(struct tsm_screen *con, unsigned int flags);
137 unsigned int tsm_screen_get_flags(struct tsm_screen *con);
138
139 unsigned int tsm_screen_get_cursor_x(struct tsm_screen *con);
140 unsigned int tsm_screen_get_cursor_y(struct tsm_screen *con);
141
142 void tsm_screen_set_tabstop(struct tsm_screen *con);
143 void tsm_screen_reset_tabstop(struct tsm_screen *con);
144 void tsm_screen_reset_all_tabstops(struct tsm_screen *con);
145
146 void tsm_screen_write(struct tsm_screen *con, tsm_symbol_t ch,
147                       const struct tsm_screen_attr *attr);
148 void tsm_screen_newline(struct tsm_screen *con);
149 void tsm_screen_scroll_up(struct tsm_screen *con, unsigned int num);
150 void tsm_screen_scroll_down(struct tsm_screen *con, unsigned int num);
151 void tsm_screen_move_to(struct tsm_screen *con, unsigned int x,
152                         unsigned int y);
153 void tsm_screen_move_up(struct tsm_screen *con, unsigned int num,
154                         bool scroll);
155 void tsm_screen_move_down(struct tsm_screen *con, unsigned int num,
156                           bool scroll);
157 void tsm_screen_move_left(struct tsm_screen *con, unsigned int num);
158 void tsm_screen_move_right(struct tsm_screen *con, unsigned int num);
159 void tsm_screen_move_line_end(struct tsm_screen *con);
160 void tsm_screen_move_line_home(struct tsm_screen *con);
161 void tsm_screen_tab_right(struct tsm_screen *con, unsigned int num);
162 void tsm_screen_tab_left(struct tsm_screen *con, unsigned int num);
163 void tsm_screen_insert_lines(struct tsm_screen *con, unsigned int num);
164 void tsm_screen_delete_lines(struct tsm_screen *con, unsigned int num);
165 void tsm_screen_insert_chars(struct tsm_screen *con, unsigned int num);
166 void tsm_screen_delete_chars(struct tsm_screen *con, unsigned int num);
167 void tsm_screen_erase_cursor(struct tsm_screen *con);
168 void tsm_screen_erase_chars(struct tsm_screen *con, unsigned int num);
169 void tsm_screen_erase_cursor_to_end(struct tsm_screen *con,
170                                     bool protect);
171 void tsm_screen_erase_home_to_cursor(struct tsm_screen *con,
172                                      bool protect);
173 void tsm_screen_erase_current_line(struct tsm_screen *con,
174                                    bool protect);
175 void tsm_screen_erase_screen_to_cursor(struct tsm_screen *con,
176                                        bool protect);
177 void tsm_screen_erase_cursor_to_screen(struct tsm_screen *con,
178                                        bool protect);
179 void tsm_screen_erase_screen(struct tsm_screen *con, bool protect);
180
181 void tsm_screen_selection_reset(struct tsm_screen *con);
182 void tsm_screen_selection_start(struct tsm_screen *con,
183                                 unsigned int posx,
184                                 unsigned int posy);
185 void tsm_screen_selection_target(struct tsm_screen *con,
186                                  unsigned int posx,
187                                  unsigned int posy);
188 int tsm_screen_selection_copy(struct tsm_screen *con, char **out);
189
190 void tsm_screen_draw(struct tsm_screen *con,
191                      tsm_screen_prepare_cb prepare_cb,
192                      tsm_screen_draw_cb draw_cb,
193                      tsm_screen_render_cb render_cb,
194                      void *data);
195
196 #endif /* TSM_SCREEN_H */