static int x11_xinput2_poll(ManyMouseEvent *event) { if (dequeue_event(event)) /* ...favor existing events in the queue... */ return 1; pump_events(); /* pump runloop for new hardware events... */ return dequeue_event(event); /* see if anything had shown up... */ } /* x11_xinput2_poll */
void waitForRelease(int what) { Input *i = getInput(); InputDescriptor id; while (true) { pump_events(); id = i->getDescriptor(); switch (what) { case 0: if (!id.left) goto done; break; case 1: if (!id.right) goto done; break; case 2: if (!id.up) goto done; break; case 3: if (!id.down) goto done; break; case 4: if (!id.button1) goto done; break; case 5: if (!id.button2) goto done; break; case 6: if (!id.button3) goto done; break; } } done:; }
int32_t run(Filesystem* fs, ConfigSettings* cs) { // Create main window XInitThreads(); XSetErrorHandler(x11_error_handler); m_x11_display = XOpenDisplay(NULL); CE_ASSERT(m_x11_display != NULL, "Unable to open X11 display"); int screen = DefaultScreen(m_x11_display); int depth = DefaultDepth(m_x11_display, screen); Visual* visual = DefaultVisual(m_x11_display, screen); m_x11_parent_window = (m_parent_window_handle == 0) ? RootWindow(m_x11_display, screen) : (Window) m_parent_window_handle; // Create main window XSetWindowAttributes win_attribs; win_attribs.background_pixmap = 0; win_attribs.border_pixel = 0; win_attribs.event_mask = FocusChangeMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; m_x11_window = XCreateWindow(m_x11_display, m_x11_parent_window, 0, 0, cs->window_width, cs->window_height, 0, depth, InputOutput, visual, CWBorderPixel | CWEventMask, &win_attribs ); CE_ASSERT(m_x11_window != None, "Unable to create X window"); // Do we have detectable autorepeat? Bool detectable; m_x11_detectable_autorepeat = (bool) XkbSetDetectableAutoRepeat(m_x11_display, true, &detectable); // Build hidden cursor Pixmap bm_no; XColor black, dummy; Colormap colormap; static char no_data[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; colormap = XDefaultColormap(m_x11_display, screen); XAllocNamedColor(m_x11_display, colormap, "black", &black, &dummy); bm_no = XCreateBitmapFromData(m_x11_display, m_x11_window, no_data, 8, 8); m_x11_hidden_cursor = XCreatePixmapCursor(m_x11_display, bm_no, bm_no, &black, &black, 0, 0); m_wm_delete_message = XInternAtom(m_x11_display, "WM_DELETE_WINDOW", False); XSetWMProtocols(m_x11_display, m_x11_window, &m_wm_delete_message, 1); oswindow_set_window(m_x11_display, m_x11_window); bgfx::x11SetDisplayWindow(m_x11_display, m_x11_window); XMapRaised(m_x11_display, m_x11_window); // Get screen configuration m_screen_config = XRRGetScreenInfo(m_x11_display, RootWindow(m_x11_display, screen)); Rotation rr_old_rot; const SizeID rr_old_sizeid = XRRConfigCurrentConfiguration(m_screen_config, &rr_old_rot); // Start main thread MainThreadArgs mta; mta.fs = fs; mta.cs = cs; Thread main_thread; main_thread.start(func, &mta); while (!s_exit) { pump_events(); } main_thread.stop(); // Restore previous screen configuration if changed Rotation rr_cur_rot; const SizeID rr_cur_sizeid = XRRConfigCurrentConfiguration(m_screen_config, &rr_cur_rot); if (rr_cur_rot != rr_old_rot || rr_cur_sizeid != rr_old_sizeid) { XRRSetScreenConfig(m_x11_display, m_screen_config, RootWindow(m_x11_display, screen), rr_old_sizeid, rr_old_rot, CurrentTime); } XRRFreeScreenConfigInfo(m_screen_config); XDestroyWindow(m_x11_display, m_x11_window); XCloseDisplay(m_x11_display); return EXIT_SUCCESS; }