ui/ncurses: clear DNS server setting before appending new servers
[petitboot] / ui / twin / pbt-scr.h
1 /*
2  *  Copyright Geoff Levand <geoff@infradead.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #if !defined(_PBT_SCR_H)
19 #define _PBT_SCR_H
20
21 #include <waiter/waiter.h>
22
23 #include <libtwin/twin.h>
24 #include <libtwin/twin_jpeg.h>
25 #include <libtwin/twin_linux_mouse.h>
26 #include <libtwin/twin_linux_js.h>
27 #include <libtwin/twin_png.h>
28
29 #if defined(HAVE_LIBTWIN_TWIN_X11_H)
30 # include <libtwin/twin_x11.h>
31 #endif
32 #if defined(HAVE_LIBTWIN_TWIN_FBDEV_H)
33 # include <libtwin/twin_fbdev.h>
34 #endif
35
36 #define DBG(fmt, args...) pb_debug("DBG: " fmt, ## args)
37 #define DBGS(fmt, args...) \
38         pb_debug("DBG:%s:%d: " fmt, __func__, __LINE__, ## args)
39
40 struct pbt_quad {
41         twin_coord_t x;
42         twin_coord_t y;
43         twin_coord_t width;
44         twin_coord_t height;
45 };
46
47 /**
48  * struct pbt_border - A window border.
49  * @left: Pixel count for left side.
50  * @fill_color: Border fill color.
51  */
52
53 struct pbt_border {
54     unsigned int left;
55     unsigned int right;
56     unsigned int top;
57     unsigned int bottom;
58     twin_argb32_t fill_color;
59 };
60
61 enum {
62         pbt_debug_red = 0x00800000,
63         pbt_debug_green = 0x00008000,
64         pbt_debug_blue = 0x00000080,
65 };
66
67 static const struct pbt_border pbt_thin_border = {
68         .right = 2,
69         .left = 2,
70         .top = 2,
71         .bottom = 2,
72 };
73
74 static const struct pbt_border pbt_right_border = {
75         .right = 2
76 };
77
78 static const struct pbt_border pbt_red_debug_border = {
79         .right = 1,
80         .left = 1,
81         .top = 1,
82         .bottom = 1,
83         .fill_color = pbt_debug_red,
84 };
85
86 static const struct pbt_border pbt_green_debug_border = {
87         .right = 1,
88         .left = 1,
89         .top = 1,
90         .bottom = 1,
91         .fill_color = pbt_debug_green,
92 };
93
94 static const struct pbt_border pbt_blue_debug_border = {
95         .right = 1,
96         .left = 1,
97         .top = 1,
98         .bottom = 1,
99         .fill_color = pbt_debug_blue,
100 };
101
102 static const struct pbt_border pbt_yellow_debug_border = {
103         .right = 1,
104         .left = 1,
105         .top = 1,
106         .bottom = 1,
107         .fill_color = pbt_debug_green + pbt_debug_red,
108 };
109
110 void pbt_border_draw(twin_pixmap_t *pixmap, const struct pbt_border *border);
111
112 struct pbt_cursor {
113         twin_pixmap_t *pixmap;
114         int hx;
115         int hy;
116 };
117
118 enum pbt_twin_backend {
119         pbt_twin_x11 = 1,
120         pbt_twin_fbdev,
121 };
122
123 struct pbt_twin_ctx {
124         union {
125                 void *ptr;
126 #if defined(HAVE_LIBTWIN_TWIN_X11_H)
127                 twin_x11_t *x11;
128 #endif
129 #if defined(HAVE_LIBTWIN_TWIN_FBDEV_H)
130                 twin_fbdev_t *fbdev;
131 #endif
132         };
133         enum pbt_twin_backend backend;
134 };
135
136 struct pbt_scr {
137         struct pbt_twin_ctx twin_ctx;
138         twin_screen_t *tscreen;
139         twin_pixmap_t *cursor;
140 };
141
142 struct pbt_scr *pbt_scr_init(void *talloc_ctx, struct waitset *waitset,
143         enum pbt_twin_backend backend,
144         unsigned int width, unsigned int height,
145         const char *filename_background,
146         twin_bool_t (*scr_event_cb)(twin_screen_t *tscreen,
147                 twin_event_t *event));
148
149 static inline struct pbt_scr *pbt_scr_from_tscreen(twin_screen_t *tscreen)
150 {
151         size_t offset = (size_t)&((struct pbt_scr *)0)->tscreen;
152         return (struct pbt_scr *)((char *)tscreen - offset);
153 }
154
155 void pbt_image_draw(twin_pixmap_t *dest, twin_pixmap_t *image);
156
157 #define pbt_dump_event(_s, _w, _e) _pbt_dump_event(_s, _w, _e, __func__, __LINE__)
158 void _pbt_dump_event(const char *text, twin_window_t *twindow,
159         const twin_event_t *tevent, const char *func,  int line);
160
161 twin_pixmap_t *pbt_background_load(twin_screen_t *tscreen,
162         const char *filename);
163 twin_pixmap_t *pbt_icon_load(const char *filename);
164 const char *pbt_icon_chooser(const char *hint);
165 int pbt_window_contains(const twin_window_t *window, const twin_event_t *event);
166 void pbt_window_redraw(twin_window_t *twindow);
167
168 #define pbt_dump_pixmap(_p)                     \
169         DBGS("pixmap(%p): {x,y,w,h} = {%d,%d,%d,%d}\n", \
170                 _p,                                     \
171                 _p->x,                                  \
172                 _p->y,                                  \
173                 _p->width,                              \
174                 _p->height)
175
176
177 #endif