summaryrefslogtreecommitdiff
path: root/src/wlt_toolkit.h
blob: 01d557b47a26d61d0ed2f99c94c5137f42fbec01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
 * wlt - Toolkit Helper
 *
 * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/*
 * Wayland Terminal toolkit helpers
 */

#ifndef WLT_TOOLKIT_H
#define WLT_TOOLKIT_H

#include <stdbool.h>
#include <stdlib.h>
#include "eloop.h"

struct wlt_display;
struct wlt_window;
struct wlt_widget;

enum wlt_display_event {
	WLT_DISPLAY_HUP,
	WLT_DISPLAY_READY,
};

struct wlt_rect {
	unsigned int x;
	unsigned int y;
	unsigned int width;
	unsigned int height;
};

struct wlt_shm_buffer {
	uint8_t *data;
	unsigned int width;
	unsigned int height;
	unsigned int stride;
};

enum cursor_type {
	WLT_CURSOR_NONE,
	WLT_CURSOR_TOP,
	WLT_CURSOR_BOTTOM,
	WLT_CURSOR_LEFT,
	WLT_CURSOR_RIGHT,
	WLT_CURSOR_TOP_LEFT,
	WLT_CURSOR_TOP_RIGHT,
	WLT_CURSOR_BOTTOM_LEFT,
	WLT_CURSOR_BOTTOM_RIGHT,
	WLT_CURSOR_DRAGGING,
	WLT_CURSOR_LEFT_PTR,
	WLT_CURSOR_IBEAM,
	WLT_CURSOR_NUM,
};

#define WLT_WINDOW_MAXIMIZED		0x01
#define WLT_WINDOW_FULLSCREEN		0x02

typedef void (*wlt_display_cb) (struct wlt_display *disp,
				unsigned int event,
				void *data);
typedef void (*wlt_window_close_cb) (struct wlt_window *wnd, void *data);
typedef void (*wlt_widget_redraw_cb) (struct wlt_widget *widget,
				      unsigned int flags,
				      void *data);
typedef void (*wlt_widget_destroy_cb) (struct wlt_widget *widget,
				       void *data);
typedef void (*wlt_widget_prepare_resize_cb) (struct wlt_widget *widget,
					      unsigned int flags,
					      unsigned int width,
					      unsigned int height,
					      unsigned int *min_width,
					      unsigned int *min_height,
					      unsigned int *new_width,
					      unsigned int *new_height,
					      void *data);
typedef void (*wlt_widget_resize_cb) (struct wlt_widget *widget,
				      unsigned int flags,
				      struct wlt_rect *allocation,
				      void *data);
typedef void (*wlt_widget_pointer_enter_cb) (struct wlt_widget *widget,
					     unsigned int x,
					     unsigned int y,
					     void *data);
typedef void (*wlt_widget_pointer_leave_cb) (struct wlt_widget *widget,
					     void *data);
typedef void (*wlt_widget_pointer_motion_cb) (struct wlt_widget *widget,
					      unsigned int x,
					      unsigned int y,
					      void *data);
typedef void (*wlt_widget_pointer_button_cb) (struct wlt_widget *widget,
					      uint32_t button,
					      uint32_t state,
					      void *data);
typedef bool (*wlt_widget_keyboard_cb) (struct wlt_widget *widget,
					unsigned int mods,
					uint32_t key,
					uint32_t state,
					bool handled,
					void *data);

int wlt_display_new(struct wlt_display **out,
		    struct ev_eloop *eloop);
void wlt_display_ref(struct wlt_display *disp);
void wlt_display_unref(struct wlt_display *disp);

int wlt_display_create_window(struct wlt_display *disp,
			      struct wlt_window **out,
			      unsigned int width,
			      unsigned int height,
			      void *data);
int wlt_display_register_cb(struct wlt_display *disp,
			    wlt_display_cb cb, void *data);
void wlt_display_unregister_cb(struct wlt_display *disp,
			       wlt_display_cb cb, void *data);

void wlt_window_ref(struct wlt_window *wnd);
void wlt_window_unref(struct wlt_window *wnd);

int wlt_window_create_widget(struct wlt_window *wnd,
			     struct wlt_widget **out,
			     void *data);
void wlt_window_schedule_redraw(struct wlt_window *wnd);
void wlt_window_damage(struct wlt_window *wnd,
		       struct wlt_rect *damage);
void wlt_window_get_buffer(struct wlt_window *wnd,
			   const struct wlt_rect *alloc,
			   struct wlt_shm_buffer *buf);
void wlt_window_move(struct wlt_window *wnd);
void wlt_window_resize(struct wlt_window *wnd, uint32_t edges);
int wlt_window_set_size(struct wlt_window *wnd,
			unsigned int width, unsigned int height);
void wlt_window_set_cursor(struct wlt_window *wnd, unsigned int cursor);
void wlt_window_set_close_cb(struct wlt_window *wnd,
			     wlt_window_close_cb cb);
void wlt_window_close(struct wlt_window *wnd);
void wlt_window_toggle_maximize(struct wlt_window *wnd);
void wlt_window_toggle_fullscreen(struct wlt_window *wnd);
struct ev_eloop *wlt_window_get_eloop(struct wlt_window *wnd);

void wlt_widget_destroy(struct wlt_widget *widget);
struct wlt_window *wlt_widget_get_window(struct wlt_widget *widget);
void wlt_widget_set_redraw_cb(struct wlt_widget *widget,
			      wlt_widget_redraw_cb cb);
void wlt_widget_set_destroy_cb(struct wlt_widget *widget,
			       wlt_widget_destroy_cb cb);
void wlt_widget_set_resize_cb(struct wlt_widget *widget,
			      wlt_widget_prepare_resize_cb prepare_cb,
			      wlt_widget_resize_cb cb);
void wlt_widget_set_pointer_cb(struct wlt_widget *widget,
			       wlt_widget_pointer_enter_cb enter_cb,
			       wlt_widget_pointer_leave_cb leave_cb,
			       wlt_widget_pointer_motion_cb motion_cb,
			       wlt_widget_pointer_button_cb button_cb);
void wlt_widget_set_keyboard_cb(struct wlt_widget *widget,
				wlt_widget_keyboard_cb cb);

static inline bool wlt_rect_contains(struct wlt_rect *rect,
				     unsigned int x,
				     unsigned int y)
{
	if (x >= rect->x + rect->width)
		return false;
	if (y >= rect->y + rect->height)
		return false;
	return true;
}

#endif /* WLT_TOOLKIT_H */