| 1763 | } |
| 1764 | |
| 1765 | int run(DeviceOptions *opts) |
| 1766 | { |
| 1767 | int init_ret = -1; |
| 1768 | const char *display = NULL; |
| 1769 | bool disable_wayland = true; |
| 1770 | |
| 1771 | if (init_ret != 0 && !disable_wayland |
| 1772 | && (display = getenv("WAYLAND_DISPLAY")) != NULL |
| 1773 | && strlen32(display) != 0) { |
| 1774 | _system = CE_NEW(*_allocator, SystemWayland)(_queue); |
| 1775 | |
| 1776 | if ((init_ret = _system->init()) == 0) { |
| 1777 | _wl = (SystemWayland *)_system; |
| 1778 | window_system = WindowSystem::WAYLAND; |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | if (init_ret != 0 |
| 1783 | && (display = getenv("DISPLAY")) != NULL |
| 1784 | && strlen32(display) != 0) { |
| 1785 | _system = CE_NEW(*_allocator, SystemX11)(_queue); |
| 1786 | |
| 1787 | if ((init_ret = _system->init()) == 0) { |
| 1788 | _x11 = (SystemX11 *)_system; |
| 1789 | window_system = WindowSystem::X11; |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | _options = opts; |
| 1794 | |
| 1795 | int err = pipe(exit_pipe); |
| 1796 | CE_ASSERT(err != -1, "pipe: errno = %d", errno); |
| 1797 | CE_UNUSED(err); |
| 1798 | |
| 1799 | // Start main thread |
| 1800 | Thread main_thread; |
| 1801 | main_thread.start([](void *user_data) { |
| 1802 | int ec = crown::main_runtime(*((DeviceOptions *)user_data)); |
| 1803 | s_exit = true; |
| 1804 | // Write something just to unlock the listening select(). |
| 1805 | const ssize_t written = write(exit_pipe[1], &s_exit, sizeof(s_exit)); |
| 1806 | CE_UNUSED(written); |
| 1807 | return ec; |
| 1808 | } |
| 1809 | , opts |
| 1810 | ); |
| 1811 | |
| 1812 | _joypad.open(); |
| 1813 | |
| 1814 | // Input events loop. |
| 1815 | fd_set fdset; |
| 1816 | |
| 1817 | while (!s_exit) { |
| 1818 | FD_ZERO(&fdset); |
| 1819 | FD_SET(exit_pipe[0], &fdset); |
| 1820 | int maxfd = _system->set_fds(&fdset, exit_pipe[0]); |
| 1821 | maxfd = _joypad.set_fds(&fdset, maxfd); |
| 1822 |
no test coverage detected