| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /* Backend selection for the host window. */
- #include <unistd.h>
- #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_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();
- }
|