/* Backend selection for the host window. */ #include #include "host.h" #include "window.h" static int open; static int headless; int host_window_open(unsigned int w, unsigned int h, const char *title) { int rv; if (open) { if ((unsigned int)host_window_width() == w && (unsigned int)host_window_height() == h) return 0; return -1; } headless = host_opts.headless ? 1 : 0; rv = headless ? host_headless_open(w, h, title) : host_sdl_open(w, h, title); if (rv == 0) open = 1; return rv; } void host_window_close(void) { if (!open) return; if (headless) host_headless_close(); else host_sdl_close(); open = 0; } void *host_window_fb(void) { if (!open) return 0; return headless ? host_headless_fb() : host_sdl_fb(); } unsigned int host_window_width(void) { if (!open) return 0; return headless ? host_headless_width() : host_sdl_width(); } unsigned int host_window_height(void) { if (!open) return 0; return headless ? host_headless_height() : host_sdl_height(); } void host_window_present(int x, int y, unsigned int w, unsigned int h) { (void)x; (void)y; (void)w; (void)h; if (!open) return; if (headless) host_headless_present(); else host_sdl_present(); } void host_window_pump(unsigned int timeout_ms) { if (!open) { if (timeout_ms) usleep(timeout_ms * 1000u); return; } if (headless) host_headless_pump(timeout_ms); else host_sdl_pump(timeout_ms); } int host_window_pointer(struct win_pointer *out) { if (!open) return -1; return headless ? host_headless_pointer(out) : host_sdl_pointer(out); } int host_window_event(struct win_event *out) { if (!open) return 0; return headless ? host_headless_event(out) : host_sdl_event(out); } int host_window_scroll(struct win_scroll *out) { if (!open) return 0; return headless ? host_headless_scroll(out) : host_sdl_scroll(out); } int host_window_key(void) { if (!open) return 0; return headless ? host_headless_key() : host_sdl_key(); } int host_window_screen(unsigned int *w, unsigned int *h) { if (!open) return -1; return headless ? host_headless_screen(w, h) : host_sdl_screen(w, h); } int host_window_set_cursor(int shape) { if (!open) return -1; if (!headless) host_sdl_set_cursor(shape); return 0; } int host_window_key_wait(unsigned int timeout_ms) { if (!open) { host_window_pump(timeout_ms); return 0; } return headless ? host_headless_key_wait(timeout_ms) : host_sdl_key_wait(timeout_ms); } const char *host_window_backend(void) { if (!open) return "none"; return headless ? host_headless_backend() : host_sdl_backend(); }