void X11WindowedBackend::grabKeyboard(xcb_timestamp_t time) { const bool oldState = m_keyboardGrabbed; if (m_keyboardGrabbed) { xcb_ungrab_keyboard(m_connection, time); xcb_ungrab_pointer(m_connection, time); m_keyboardGrabbed = false; } else { const auto c = xcb_grab_keyboard_unchecked(m_connection, false, window(), time, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); ScopedCPointer<xcb_grab_keyboard_reply_t> grab(xcb_grab_keyboard_reply(m_connection, c, nullptr)); if (grab.isNull()) { return; } if (grab->status == XCB_GRAB_STATUS_SUCCESS) { const auto c = xcb_grab_pointer_unchecked(m_connection, false, window(), XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, window(), XCB_CURSOR_NONE, time); ScopedCPointer<xcb_grab_pointer_reply_t> grab(xcb_grab_pointer_reply(m_connection, c, nullptr)); if (grab.isNull() || grab->status != XCB_GRAB_STATUS_SUCCESS) { xcb_ungrab_keyboard(m_connection, time); return; } m_keyboardGrabbed = true; } } if (oldState != m_keyboardGrabbed) { updateWindowTitle(); xcb_flush(m_connection); } }
bool grabXKeyboard(xcb_window_t w) { if (QWidget::keyboardGrabber() != NULL) return false; if (keyboard_grabbed) return false; if (qApp->activePopupWidget() != NULL) return false; if (w == XCB_WINDOW_NONE) w = rootWindow(); const xcb_grab_keyboard_cookie_t c = xcb_grab_keyboard_unchecked(connection(), false, w, xTime(), XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); ScopedCPointer<xcb_grab_keyboard_reply_t> grab(xcb_grab_keyboard_reply(connection(), c, NULL)); if (grab.isNull()) { return false; } if (grab->status != XCB_GRAB_STATUS_SUCCESS) { return false; } keyboard_grabbed = true; return true; }
static void towel_window_grab_input(towel_window_t *win) { xcb_grab_pointer_cookie_t pointer_cookie; xcb_grab_keyboard_cookie_t keyboard_cookie; xcb_grab_pointer_reply_t *pointer_reply; xcb_grab_keyboard_reply_t *keyboard_reply; pointer_cookie = xcb_grab_pointer_unchecked(win->conn, 0, win->id, XCB_EVENT_MASK_NO_EVENT, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, win->id, XCB_CURSOR_NONE, XCB_TIME_CURRENT_TIME); keyboard_cookie = xcb_grab_keyboard_unchecked(win->conn, 0, win->id, XCB_TIME_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); pointer_reply = xcb_grab_pointer_reply(win->conn, pointer_cookie, NULL); keyboard_reply = xcb_grab_keyboard_reply(win->conn, keyboard_cookie, NULL); #if DEBUG fprintf(stderr, "p: %d, k: %d\n", pointer_reply->status, keyboard_reply->status); #endif free(pointer_reply); free(keyboard_reply); }
static void _e_alert_display(void) { xcb_char2b_t *str = NULL; xcb_query_text_extents_cookie_t cookie; xcb_query_text_extents_reply_t *reply; int x = 0, w = 0; tainted = _e_alert_root_tainted_get(); str = _e_alert_build_string(title); cookie = xcb_query_text_extents_unchecked(conn, font, strlen(title), str); reply = xcb_query_text_extents_reply(conn, cookie, NULL); if (reply) { fa = reply->font_ascent; fh = (fa + reply->font_descent); fw = reply->overall_width; free(reply); } free(str); /* move buttons */ x = 20; w = (WINDOW_WIDTH / 2) - 40; _e_alert_button_move_resize(btn1, x, WINDOW_HEIGHT - 20 - (fh + 20), w, (fh + 20)); x = ((WINDOW_WIDTH / 2) + 20); _e_alert_button_move_resize(btn2, x, WINDOW_HEIGHT - 20 - (fh + 20), w, (fh + 20)); comp_win = _e_alert_comp_win_get(); if (comp_win) { xcb_rectangle_t rect; int wx = 0, wy = 0; wx = ((sw - WINDOW_WIDTH) / 2); wy = ((sh - WINDOW_HEIGHT) / 2); rect.x = wx; rect.y = wy; rect.width = WINDOW_WIDTH; rect.height = WINDOW_HEIGHT; xcb_shape_rectangles(conn, XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, XCB_CLIP_ORDERING_UNSORTED, comp_win, 0, 0, 1, &rect); xcb_reparent_window(conn, win, comp_win, wx, wy); } /* map and raise main window */ xcb_map_window(conn, win); _e_alert_window_raise(win); /* grab pointer & keyboard */ xcb_grab_pointer_unchecked(conn, 0, win, (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE), XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE, XCB_CURRENT_TIME); xcb_grab_keyboard_unchecked(conn, 0, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); xcb_set_input_focus(conn, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME); /* flush screen */ xcb_flush(conn); /* sync */ _e_alert_sync(); }