Beispiel #1
0
xcb_window_t getinputfocus() {
	xcb_get_input_focus_cookie_t k=xcb_get_input_focus(c);
	xcb_get_input_focus_reply_t *r=xcb_get_input_focus_reply(c,k,0);
	xcb_window_t w=r->focus;
	free(r);
	return w;
}
Beispiel #2
0
client_t *get_focus_client(void)
{
    xcb_get_input_focus_cookie_t c = xcb_get_input_focus(wm_conf.connection);
    xcb_get_input_focus_reply_t *r = xcb_get_input_focus_reply(wm_conf.connection, c, NULL);
    client_t *focus_client = NULL;
    if (r) {
        focus_client = find_client(r->focus);
        free(r);
    }
    return focus_client;
}
Beispiel #3
0
ExcCode screen_get_focused(xcb_window_t *res) {
	xcb_get_input_focus_cookie_t cookie = xcb_get_input_focus(display);
	xcb_get_input_focus_reply_t *reply =
			xcb_get_input_focus_reply(display, cookie, NULL);
	if (reply == NULL) {
		*res = root;
		return 0;
	}
	*res = reply->focus;
	free(reply);
	return 0;
}
Beispiel #4
0
void XGetInputFocus(Display *display, Window *focus, int *revert_to_return) {
	xcb_get_input_focus_cookie_t cookie;
	xcb_get_input_focus_reply_t *reply;

	cookie = xcb_get_input_focus(display);
 	reply = xcb_get_input_focus_reply(display, cookie, NULL);

	if (reply == NULL)
		fatal("Error in X11 communication\n");

	*focus = reply->focus;
	*revert_to_return = reply->revert_to;
	free(reply);
}
Beispiel #5
0
xcb_window_t
get_focused_window(xcb_connection_t * conn)
{
	xcb_window_t    win = 0;
	xcb_get_input_focus_cookie_t input_focus_cookie;
	xcb_get_input_focus_reply_t *input_focus_reply;

	input_focus_cookie = xcb_get_input_focus(conn);
	input_focus_reply = xcb_get_input_focus_reply(conn, input_focus_cookie, NULL);
	if (!input_focus_reply)
		errx(1, "Cannot get focused window.");
	win = input_focus_reply->focus;
	free(input_focus_reply);
	return win;
}
bool LinuxWindowCapture::ExtractWindowProperties( xcb_window_t winId, QRect* winRect, bool* winFocus ) {
  if( !winId )
    return false;

  xcb_connection_t* xcbConn = QX11Info::connection();

  xcb_get_geometry_cookie_t geometryC = xcb_get_geometry( xcbConn, winId );
  CScopedPointer< xcb_get_geometry_reply_t > geometryR( xcb_get_geometry_reply( xcbConn, geometryC, nullptr ) );
  if( !geometryR ) return false;

  // assume the parent window is the screen then we can just use the coordinates directly
  int x = geometryR->x;
  int y = geometryR->y;

  CScopedPointer< xcb_query_tree_reply_t > treeR( xcb_query_tree_reply( xcbConn, xcb_query_tree( xcbConn, winId ), nullptr ) );
  if ( !treeR ) return false;

  // if the parent isn't screen translate coords
  if ( treeR->parent != QX11Info::appRootWindow() ) {
    xcb_translate_coordinates_cookie_t
                    translateC = xcb_translate_coordinates( xcbConn, winId, QX11Info::appRootWindow(), x, y );
    CScopedPointer< xcb_translate_coordinates_reply_t >
                    translateR( xcb_translate_coordinates_reply( xcbConn, translateC, nullptr ) );
    if ( !translateR ) return false;

    x = translateR->dst_x;
    y = translateR->dst_y;
  }
  winRect->setRect( x, y, geometryR->width, geometryR->height );

  xcb_get_input_focus_cookie_t focusC = xcb_get_input_focus( xcbConn );
  CScopedPointer < xcb_get_input_focus_reply_t > focusR( xcb_get_input_focus_reply( xcbConn, focusC, nullptr ) );
  if ( !focusR ) return false;

  *winFocus = ( focusR->focus == winId );
  return true;
}
Beispiel #7
0
static void
_e_alert_sync(void)
{
   free(xcb_get_input_focus_reply(conn,
                                  xcb_get_input_focus(conn), NULL));
}
Beispiel #8
0
static xcb_rectangle_t get_window_position(void) {
    xcb_rectangle_t result = (xcb_rectangle_t){logical_px(50), logical_px(50), MAX_WIDTH, font.height + 2 * BORDER + 2 * PADDING};

    xcb_get_property_reply_t *supporting_wm_reply = NULL;
    xcb_get_input_focus_reply_t *input_focus = NULL;
    xcb_get_geometry_reply_t *geometry = NULL;
    xcb_get_property_reply_t *wm_class = NULL;
    xcb_translate_coordinates_reply_t *coordinates = NULL;

    xcb_atom_t A__NET_SUPPORTING_WM_CHECK;
    xcb_intern_atom_cookie_t nswc_cookie = xcb_intern_atom(conn, 0, strlen("_NET_SUPPORTING_WM_CHECK"), "_NET_SUPPORTING_WM_CHECK");
    xcb_intern_atom_reply_t *nswc_reply = xcb_intern_atom_reply(conn, nswc_cookie, NULL);
    if (nswc_reply == NULL) {
        ELOG("Could not intern atom _NET_SUPPORTING_WM_CHECK\n");
        exit(-1);
    }
    A__NET_SUPPORTING_WM_CHECK = nswc_reply->atom;
    free(nswc_reply);

    supporting_wm_reply = xcb_get_property_reply(
        conn, xcb_get_property(conn, false, root, A__NET_SUPPORTING_WM_CHECK, XCB_ATOM_WINDOW, 0, 32), NULL);
    xcb_window_t *supporting_wm_win = NULL;
    if (supporting_wm_reply == NULL || xcb_get_property_value_length(supporting_wm_reply) == 0) {
        DLOG("Could not determine EWMH support window.\n");
    } else {
        supporting_wm_win = xcb_get_property_value(supporting_wm_reply);
    }

    /* In rare cases, the window holding the input focus might disappear while we are figuring out its
     * position. To avoid this, we grab the server in the meantime. */
    xcb_grab_server(conn);

    input_focus = xcb_get_input_focus_reply(conn, xcb_get_input_focus(conn), NULL);
    if (input_focus == NULL || input_focus->focus == XCB_NONE) {
        DLOG("Failed to receive the current input focus or no window has the input focus right now.\n");
        goto free_resources;
    }

    /* We need to ignore the EWMH support window to which the focus can be set if there's no suitable window to focus. */
    if (supporting_wm_win != NULL && input_focus->focus == *supporting_wm_win) {
        DLOG("Input focus is on the EWMH support window, ignoring.\n");
        goto free_resources;
    }

    geometry = xcb_get_geometry_reply(conn, xcb_get_geometry(conn, input_focus->focus), NULL);
    if (geometry == NULL) {
        DLOG("Failed to received window geometry.\n");
        goto free_resources;
    }

    wm_class = xcb_get_property_reply(
        conn, xcb_get_property(conn, false, input_focus->focus, XCB_ATOM_WM_CLASS, XCB_GET_PROPERTY_TYPE_ANY, 0, 32), NULL);

    /* We need to find out whether the input focus is on an i3 frame window. If it is, we must not translate the coordinates. */
    if (wm_class == NULL || xcb_get_property_value_length(wm_class) == 0 || strcmp(xcb_get_property_value(wm_class), "i3-frame") != 0) {
        coordinates = xcb_translate_coordinates_reply(
            conn, xcb_translate_coordinates(conn, input_focus->focus, root, geometry->x, geometry->y), NULL);
        if (coordinates == NULL) {
            DLOG("Failed to translate coordinates.\n");
            goto free_resources;
        }

        DLOG("Determined coordinates of window with input focus at x = %i / y = %i.\n", coordinates->dst_x, coordinates->dst_y);
        result.x += coordinates->dst_x;
        result.y += coordinates->dst_y;
    } else {
        DLOG("Determined coordinates of window with input focus at x = %i / y = %i.\n", geometry->x, geometry->y);
        result.x += geometry->x;
        result.y += geometry->y;
    }

free_resources:
    xcb_ungrab_server(conn);
    xcb_flush(conn);

    FREE(supporting_wm_reply);
    FREE(input_focus);
    FREE(geometry);
    FREE(wm_class);
    FREE(coordinates);
    return result;
}
void QXcbConnection::sync()
{
    // from xcb_aux_sync
    xcb_get_input_focus_cookie_t cookie = Q_XCB_CALL(xcb_get_input_focus(xcb_connection()));
    free(xcb_get_input_focus_reply(xcb_connection(), cookie, 0));
}
static void
_cairo_boilerplate_xcb_sync_server (xcb_target_closure_t *xtc)
{
    free (xcb_get_input_focus_reply (xtc->c,
				     xcb_get_input_focus (xtc->c), NULL));
}