/* browser-host: run the NebOS browser as a Linux/Wayland program. * * Usage: browser-host [--size WxH] [--root DIR] [--headless] * [--wait MS] [--shot FILE] [--keys KEYS] [URL|FILE] * * --keys types into a headless window, one key every 100 ms from 300 ms * after the first frame: plain characters, plus {enter} {esc} {tab} {bs} * {del} {up} {down} {left} {right} {ctrl-l}, {wait} (a 1 s pause) and * {click:X,Y} (a left click at canvas coordinates X,Y), * {rclick:X,Y} (a right click) and {move:X,Y} * (move the pointer there without a click, for hover). */ #include #include #include #include #include "host.h" extern void browser_start(const char *arg); static void usage(void) { fprintf(stderr, "usage: browser-host [--size WxH] [--root DIR] [--headless]\n" " [--wait MS] [--shot|--screenshot FILE]\n" " [--keys KEYS] [URL|FILE]\n"); } static int parse_size(const char *s, int *w, int *h) { char *end; *w = (int)strtol(s, &end, 10); if (end == s || (*end != 'x' && *end != 'X')) return -1; s = end + 1; *h = (int)strtol(s, &end, 10); if (end == s || *end) return -1; return (*w > 0 && *h > 0) ? 0 : -1; } int main(int argc, char **argv) { char argbuf[4096]; unsigned int arglen = 0; const char *root = 0; int i; memset(&host_opts, 0, sizeof(host_opts)); host_opts.wait_ms = 4000; argbuf[0] = '\0'; for (i = 1; i < argc; i++) { const char *a = argv[i]; if (!strcmp(a, "--size") && i + 1 < argc) { if (parse_size(argv[++i], &host_opts.width, &host_opts.height) != 0) { usage(); return 1; } } else if (!strcmp(a, "--root") && i + 1 < argc) { root = argv[++i]; } else if (!strcmp(a, "--headless")) { host_opts.headless = 1; } else if (!strcmp(a, "--wait") && i + 1 < argc) { host_opts.wait_ms = (unsigned int)strtoul(argv[++i], 0, 10); } else if (!strcmp(a, "--shot") && i + 1 < argc) { host_opts.shot = argv[++i]; } else if (!strcmp(a, "--screenshot") && i + 1 < argc) { host_opts.shot = argv[++i]; } else if (!strcmp(a, "--keys") && i + 1 < argc) { host_opts.keys = argv[++i]; } else if (!strcmp(a, "--help") || !strcmp(a, "-h")) { usage(); return 0; } else { size_t n = strlen(a); if (arglen && arglen + 1 < sizeof(argbuf)) argbuf[arglen++] = ' '; if (arglen + n >= sizeof(argbuf)) n = sizeof(argbuf) - arglen - 1; memcpy(argbuf + arglen, a, n); arglen += (unsigned int)n; argbuf[arglen] = '\0'; } } if (host_opts.headless && !host_opts.shot) host_opts.shot = "/tmp/opencode/browser.ppm"; if (host_runtime_init(argv[0], root) != 0) return 1; signal(SIGPIPE, SIG_IGN); browser_start(argbuf[0] ? argbuf : 0); return 0; }