resizing and closing
This commit is contained in:
parent
09ac1a0559
commit
7e2171681d
3 changed files with 30 additions and 5 deletions
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
struct timespec program_start;
|
struct timespec program_start;
|
||||||
|
|
||||||
int running = 1;
|
|
||||||
|
|
||||||
void init_timer() {
|
void init_timer() {
|
||||||
clock_gettime(CLOCK_MONOTONIC, &program_start);
|
clock_gettime(CLOCK_MONOTONIC, &program_start);
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +38,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
Renderer renderer = new_renderer();
|
Renderer renderer = new_renderer();
|
||||||
|
|
||||||
while (running) {
|
while (state.running) {
|
||||||
double time = time_since_start();
|
double time = time_since_start();
|
||||||
render(&renderer, state.width, state.height, time, shader_path, 0);
|
render(&renderer, state.width, state.height, time, shader_path, 0);
|
||||||
commit(&state);
|
commit(&state);
|
||||||
|
|
|
||||||
30
wayland.c
30
wayland.c
|
|
@ -34,6 +34,31 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = {
|
||||||
.ping = xdg_wm_base_ping,
|
.ping = xdg_wm_base_ping,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void xdg_toplevel_configure (
|
||||||
|
void *data,
|
||||||
|
struct xdg_toplevel *xdg_toplevel,
|
||||||
|
int32_t width,
|
||||||
|
int32_t height,
|
||||||
|
struct wl_array *states
|
||||||
|
) {
|
||||||
|
|
||||||
|
struct client_state *state = data;
|
||||||
|
state->width = width;
|
||||||
|
state->height = height;
|
||||||
|
// resize egl window
|
||||||
|
wl_egl_window_resize(state->egl_window, width, height, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) {
|
||||||
|
struct client_state *state = data;
|
||||||
|
state->running = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
||||||
|
.configure = xdg_toplevel_configure,
|
||||||
|
.close = xdg_toplevel_close,
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
registry_handle_global(void *data, struct wl_registry *registry,
|
registry_handle_global(void *data, struct wl_registry *registry,
|
||||||
uint32_t name, const char *interface, uint32_t version)
|
uint32_t name, const char *interface, uint32_t version)
|
||||||
|
|
@ -53,7 +78,6 @@ registry_handle_global(void *data, struct wl_registry *registry,
|
||||||
xdg_wm_base_add_listener(state->xdg_wm_base,
|
xdg_wm_base_add_listener(state->xdg_wm_base,
|
||||||
&xdg_wm_base_listener, state);
|
&xdg_wm_base_listener, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -160,6 +184,7 @@ void wayland_init(struct client_state *state) {
|
||||||
int width = 700, height = 700;
|
int width = 700, height = 700;
|
||||||
state->width = width;
|
state->width = width;
|
||||||
state->height = height;
|
state->height = height;
|
||||||
|
state->running = 1;
|
||||||
state->wl_display = wl_display_connect(NULL);
|
state->wl_display = wl_display_connect(NULL);
|
||||||
state->wl_registry = wl_display_get_registry(state->wl_display);
|
state->wl_registry = wl_display_get_registry(state->wl_display);
|
||||||
wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state);
|
wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state);
|
||||||
|
|
@ -170,7 +195,8 @@ void wayland_init(struct client_state *state) {
|
||||||
state->xdg_wm_base, state->wl_surface);
|
state->xdg_wm_base, state->wl_surface);
|
||||||
xdg_surface_add_listener(state->xdg_surface, &xdg_surface_listener, state);
|
xdg_surface_add_listener(state->xdg_surface, &xdg_surface_listener, state);
|
||||||
state->xdg_toplevel = xdg_surface_get_toplevel(state->xdg_surface);
|
state->xdg_toplevel = xdg_surface_get_toplevel(state->xdg_surface);
|
||||||
xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS!");
|
xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS! 🕴️");
|
||||||
|
xdg_toplevel_add_listener(state->xdg_toplevel, &xdg_toplevel_listener, state);
|
||||||
wl_surface_commit(state->wl_surface);
|
wl_surface_commit(state->wl_surface);
|
||||||
|
|
||||||
egl_init(state);
|
egl_init(state);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
struct client_state {
|
struct client_state {
|
||||||
int width, height;
|
int width, height;
|
||||||
|
int running;
|
||||||
/* Globals */
|
/* Globals */
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
struct wl_registry *wl_registry;
|
struct wl_registry *wl_registry;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue