]> git.ozlabs.org Git - petitboot/blob - ui/twin/pbt-scr.h
Increase X screen size
[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 <libtwin/twin.h>
22 #include <libtwin/twin_jpeg.h>
23 #include <libtwin/twin_linux_mouse.h>
24 #include <libtwin/twin_linux_js.h>
25 #include <libtwin/twin_png.h>
26
27 #if defined(HAVE_LIBTWIN_TWIN_X11_H)
28 # include <libtwin/twin_x11.h>
29 #endif
30 #if defined(HAVE_LIBTWIN_TWIN_FBDEV_H)
31 # include <libtwin/twin_fbdev.h>
32 #endif
33
34 #define DBG(fmt, args...) pb_log("DBG: " fmt, ## args)
35 #define DBGS(fmt, args...) \
36         pb_log("DBG:%s:%d: " fmt, __func__, __LINE__, ## args)
37
38 struct pbt_quad {
39         twin_coord_t x;
40         twin_coord_t y;
41         twin_coord_t width;
42         twin_coord_t height;
43 };
44
45 /**
46  * struct pbt_border - A window border.
47  * @left: Pixel count for left side.
48  * @fill_color: Border fill color.
49  */
50
51 struct pbt_border {
52     unsigned int left;
53     unsigned int right;
54     unsigned int top;
55     unsigned int bottom;
56     twin_argb32_t fill_color;
57 };
58
59 enum {
60         pbt_debug_red = 0x00800000,
61         pbt_debug_green = 0x00008000,
62         pbt_debug_blue = 0x00000080,
63 };
64
65 static const struct pbt_border pbt_thin_border = {
66         .right = 2,
67         .left = 2,
68         .top = 2,
69         .bottom = 2,
70 };
71
72 static const struct pbt_border pbt_right_border = {
73         .right = 2
74 };
75
76 static const struct pbt_border pbt_red_debug_border = {
77         .right = 1,
78         .left = 1,
79         .top = 1,
80         .bottom = 1,
81         .fill_color = pbt_debug_red,
82 };
83
84 static const struct pbt_border pbt_green_debug_border = {
85         .right = 1,
86         .left = 1,
87         .top = 1,
88         .bottom = 1,
89         .fill_color = pbt_debug_green,
90 };
91
92 static const struct pbt_border pbt_blue_debug_border = {
93         .right = 1,
94         .left = 1,
95         .top = 1,
96         .bottom = 1,
97         .fill_color = pbt_debug_blue,
98 };
99
100 static const struct pbt_border pbt_yellow_debug_border = {
101         .right = 1,
102         .left = 1,
103         .top = 1,
104         .bottom = 1,
105         .fill_color = pbt_debug_green + pbt_debug_red,
106 };
107
108 void pbt_border_draw(twin_pixmap_t *pixmap, const struct pbt_border *border);
109
110 struct pbt_cursor {
111         twin_pixmap_t *pixmap;
112         int hx;
113         int hy;
114 };
115
116 enum pbt_twin_backend {
117         pbt_twin_x11 = 1,
118         pbt_twin_fbdev,
119 };
120
121 struct pbt_twin_ctx {
122         union {
123                 void *ptr;
124 #if defined(HAVE_LIBTWIN_TWIN_X11_H)
125                 twin_x11_t *x11;
126 #endif
127 #if defined(HAVE_LIBTWIN_TWIN_FBDEV_H)
128                 twin_fbdev_t *fbdev;
129 #endif
130         };
131         enum pbt_twin_backend backend;
132 };
133
134 struct pbt_scr {
135         struct pbt_twin_ctx twin_ctx;
136         twin_screen_t *tscreen;
137         twin_pixmap_t *cursor;
138 };
139
140 struct pbt_scr *pbt_scr_init(void *talloc_ctx, enum pbt_twin_backend backend,
141         unsigned int width, unsigned int height,
142         const char *filename_background,
143         twin_bool_t (*scr_event_cb)(twin_screen_t *tscreen,
144                 twin_event_t *event));
145
146 static inline struct pbt_scr *pbt_scr_from_tscreen(twin_screen_t *tscreen)
147 {
148         size_t offset = (size_t)&((struct pbt_scr *)0)->tscreen;
149         return (struct pbt_scr *)((char *)tscreen - offset);
150 }
151
152 void pbt_image_draw(twin_pixmap_t *dest, twin_pixmap_t *image);
153
154 #define pbt_dump_event(_s, _w, _e) _pbt_dump_event(_s, _w, _e, __func__, __LINE__)
155 void _pbt_dump_event(const char *text, twin_window_t *twindow,
156         const twin_event_t *tevent, const char *func,  int line);
157
158 twin_pixmap_t *pbt_background_load(twin_screen_t *tscreen,
159         const char *filename);
160 twin_pixmap_t *pbt_icon_load(const char *filename);
161 const char *pbt_icon_chooser(const char *hint);
162 int pbt_window_contains(const twin_window_t *window, const twin_event_t *event);
163 void pbt_window_redraw(twin_window_t *twindow);
164
165 #define pbt_dump_pixmap(_p)                     \
166         DBGS("pixmap(%p): {x,y,w,h} = {%d,%d,%d,%d}\n", \
167                 _p,                                     \
168                 _p->x,                                  \
169                 _p->y,                                  \
170                 _p->width,                              \
171                 _p->height)
172
173
174 #endif