示例#1
0
QXcbScreen::QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int number)
    : QXcbObject(connection)
    , m_screen(screen)
    , m_number(number)
{
    printf ("\n");
    printf ("Information of screen %d:\n", screen->root);
    printf ("  width.........: %d\n", screen->width_in_pixels);
    printf ("  height........: %d\n", screen->height_in_pixels);
    printf ("  depth.........: %d\n", screen->root_depth);
    printf ("  white pixel...: %x\n", screen->white_pixel);
    printf ("  black pixel...: %x\n", screen->black_pixel);
    printf ("\n");

    const quint32 mask = XCB_CW_EVENT_MASK;
    const quint32 values[] = {
        // XCB_CW_EVENT_MASK
        XCB_EVENT_MASK_ENTER_WINDOW
        | XCB_EVENT_MASK_LEAVE_WINDOW
        | XCB_EVENT_MASK_PROPERTY_CHANGE
    };

    xcb_change_window_attributes(xcb_connection(), screen->root, mask, values);

    xcb_generic_error_t *error;

    xcb_get_property_reply_t *reply =
        xcb_get_property_reply(xcb_connection(),
            xcb_get_property(xcb_connection(), false, screen->root,
                             atom(QXcbAtom::_NET_SUPPORTING_WM_CHECK),
                             XCB_ATOM_WINDOW, 0, 1024), &error);

    if (reply && reply->format == 32 && reply->type == XCB_ATOM_WINDOW) {
        xcb_window_t windowManager = *((xcb_window_t *)xcb_get_property_value(reply));

        if (windowManager != XCB_WINDOW_NONE) {
            xcb_get_property_reply_t *windowManagerReply =
                xcb_get_property_reply(xcb_connection(),
                    xcb_get_property(xcb_connection(), false, windowManager,
                                     atom(QXcbAtom::_NET_WM_NAME),
                                     atom(QXcbAtom::UTF8_STRING), 0, 1024), &error);
            if (windowManagerReply && windowManagerReply->format == 8 && windowManagerReply->type == atom(QXcbAtom::UTF8_STRING)) {
                m_windowManagerName = QString::fromUtf8((const char *)xcb_get_property_value(windowManagerReply), xcb_get_property_value_length(windowManagerReply));
                printf("Running window manager: %s\n", qPrintable(m_windowManagerName));
            } else if (error) {
                connection->handleXcbError(error);
                free(error);
            }

            free(windowManagerReply);
        }
    } else if (error) {
        connection->handleXcbError(error);
        free(error);
    }

    free(reply);

    m_syncRequestSupported = m_windowManagerName != QLatin1String("KWin");
}
示例#2
0
static xcb_window_t xdndProxy(QXcbConnection *c, xcb_window_t w)
{
    xcb_window_t proxy = XCB_NONE;

    xcb_get_property_cookie_t cookie = Q_XCB_CALL2(xcb_get_property(c->xcb_connection(), false, w, c->atom(QXcbAtom::XdndProxy),
                                                        XCB_ATOM_WINDOW, 0, 1), c);
    xcb_get_property_reply_t *reply = xcb_get_property_reply(c->xcb_connection(), cookie, 0);

    if (reply && reply->type == XCB_ATOM_WINDOW)
        proxy = *((xcb_window_t *)xcb_get_property_value(reply));
    free(reply);

    if (proxy == XCB_NONE)
        return proxy;

    // exists and is real?
    cookie = Q_XCB_CALL2(xcb_get_property(c->xcb_connection(), false, proxy, c->atom(QXcbAtom::XdndProxy),
                                                        XCB_ATOM_WINDOW, 0, 1), c);
    reply = xcb_get_property_reply(c->xcb_connection(), cookie, 0);

    if (reply && reply->type == XCB_ATOM_WINDOW) {
        xcb_window_t p = *((xcb_window_t *)xcb_get_property_value(reply));
        if (proxy != p)
            proxy = 0;
    } else {
        proxy = 0;
    }

    free(reply);

    return proxy;
}
示例#3
0
EAPI int
ecore_x_window_prop_card32_list_get(Ecore_X_Window win,
                                    Ecore_X_Atom   atom,
                                    unsigned int **list)
{
   xcb_get_property_cookie_t cookie;
   xcb_get_property_reply_t *reply;
   int num = -1;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN;

   if (list) *list = NULL;

   cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0, win, atom,
                                       XCB_ATOM_CARDINAL, 0, 0x7fffffff);
   reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
   if (!reply) return -1;

   if ((reply->type != XCB_ATOM_CARDINAL) || (reply->format != 32))
     num = -1;
   else if ((reply->value_len == 0) || (!xcb_get_property_value(reply)))
     num = 0;
   else
     {
        num = reply->value_len;
        if (list)
          {
             unsigned int *val;
             void *data;
             int i = 0;

             val = malloc(num * sizeof(unsigned int));
             if (!val)
               {
                  free(reply);
                  return num;
               }
             data = xcb_get_property_value(reply);
             for (i = 0; i < num; i++)
               val[i] = ((unsigned long *)data)[i];
             *list = val;
          }
     }

   free(reply);
   return num;
}
示例#4
0
文件: hidden.c 项目: notaudrey/qtwm2
uint32_t get_wm_state(xcb_drawable_t win) {
    xcb_get_property_reply_t *reply;
    xcb_get_property_cookie_t cookie;
    uint32_t *statep;
    uint32_t state = 0;

    cookie = xcb_get_property(conn, false, win, wm_state, wm_state, 0,
                              sizeof (int32_t));

    reply = xcb_get_property_reply(conn, cookie, NULL);
    if (NULL == reply) {
        fprintf(stderr, "qtwm: Couldn't get properties for win %d\n", win);
        return -1;
    }

    /* Length is 0 if we didn't find it. */
    if (0 == xcb_get_property_value_length(reply)) {
        goto bad;
    }

    statep = xcb_get_property_value(reply);
    state = *statep;

bad:
    free(reply);
    return state;
}
示例#5
0
void QXcbScreen::readXResources()
{
    int offset = 0;
    QByteArray resources;
    while(1) {
        xcb_get_property_reply_t *reply =
            xcb_get_property_reply(xcb_connection(),
                xcb_get_property_unchecked(xcb_connection(), false, screen()->root,
                                 XCB_ATOM_RESOURCE_MANAGER,
                                 XCB_ATOM_STRING, offset/4, 8192), NULL);
        bool more = false;
        if (reply && reply->format == 8 && reply->type == XCB_ATOM_STRING) {
            resources += QByteArray((const char *)xcb_get_property_value(reply), xcb_get_property_value_length(reply));
            offset += xcb_get_property_value_length(reply);
            more = reply->bytes_after != 0;
        }

        if (reply)
            free(reply);

        if (!more)
            break;
    }

    QList<QByteArray> split = resources.split('\n');
    for (int i = 0; i < split.size(); ++i) {
        const QByteArray &r = split.at(i);
        int value;
        if (xResource(r, "Xft.dpi:\t", &value))
            m_forcedDpi = value;
        else if (xResource(r, "Xft.hintstyle:\t", &value))
            m_hintStyle = QFontEngine::HintStyle(value);
    }
}
示例#6
0
//! Process _NET_WM_STRUT reply and update fields
void Client::process_ewmh_strut(xcb_get_property_cookie_t gpc)
{
    autofree_ptr<xcb_get_property_reply_t> gpr(
        xcb_get_property_reply(g_xcb.connection, gpc, NULL)
        );

    if (!gpr) {
        WARN << "Could not retrieve _NET_WM_STRUT for window";
        m_ewmh_strut.clear();
        return;
    }

    TRACE << *gpr;

    if (gpr->type != XCB_ATOM_CARDINAL ||
        gpr->format != 32 || gpr->length != 4)
    {
        WARN << "Could not retrieve _NET_WM_STRUT for window";
        m_ewmh_strut.clear();
        return;
    }

    uint32_t* strut = (uint32_t*)xcb_get_property_value(gpr.get());

    m_ewmh_strut.valid = true;

    m_ewmh_strut.left = strut[0];
    m_ewmh_strut.right = strut[1];
    m_ewmh_strut.top = strut[2];
    m_ewmh_strut.bottom = strut[3];

    INFO << "EWMH _NET_WM_STRUT of window " << window() << " is "
         << m_ewmh_strut;
}
示例#7
0
/** Get a window state (WM_STATE).
 * \param cookie The cookie.
 * \return The current state of the window, or 0 on error.
 */
uint32_t
window_state_get_reply(xcb_get_property_cookie_t cookie, int* pStateFound)
{

    /* This is a bug fixed in updated versions of awesome already */
    /* setting the result to 0 maps to XCB_WM_STATE_WITHDRAWN which */
    /* causes a problem in scan. The default value should be XCB_WM_STATE_NORMAL */
    /* returning 0 inside pStateFound to indicate to the caller that */
    /* it was not found */
    uint32_t result = XCB_WM_STATE_NORMAL;

    if (pStateFound){
        *pStateFound = 0;
    }

    xcb_get_property_reply_t *prop_r;

    if((prop_r = xcb_get_property_reply(globalconf.connection, cookie, NULL)))
    {
        if(xcb_get_property_value_length(prop_r)){
            result = *(uint32_t *) xcb_get_property_value(prop_r);
            if (pStateFound){
                *pStateFound = 1;
            }
        }

        p_delete(&prop_r);
    }

    return result;
}
示例#8
0
//! Process _NET_WM_STATE reply and update fields
void Client::process_ewmh_state(xcb_get_property_cookie_t gpc)
{
    autofree_ptr<xcb_get_property_reply_t> gpr(
        xcb_get_property_reply(g_xcb.connection, gpc, NULL)
        );

    if (!gpr || gpr->type != XCB_ATOM_ATOM) {
        INFO << "Could not retrieve _NET_WM_STATE for window";
        return;
    }

    TRACE << *gpr;

    m_state_sticky = false;
    m_state_above = false;
    m_state_fullscreen = false;
    m_state_maximized_vert = false;
    m_state_maximized_horz = false;
    m_state_skip_taskbar = false;
    m_state_skip_pager = false;

    xcb_atom_t* atoms = (xcb_atom_t*)xcb_get_property_value(gpr.get());
    int n = xcb_get_property_value_length(gpr.get()) / sizeof(xcb_atom_t);

    // iterate and apply properties to window

    for (int i = 0; i < n; ++i)
        change_ewmh_state(atoms[i], EWMH_STATE_ADD);
}
示例#9
0
void QXcbScreen::updateGeometry(xcb_timestamp_t timestamp)
{
    if (connection()->hasXRandr()) {
        xcb_randr_get_crtc_info_reply_t *crtc = xcb_randr_get_crtc_info_reply(xcb_connection(),
            xcb_randr_get_crtc_info_unchecked(xcb_connection(), m_crtc, timestamp), NULL);
        if (crtc) {
            m_geometry = QRect(crtc->x, crtc->y, crtc->width, crtc->height);
            m_availableGeometry = m_geometry;
            free(crtc);
        }
    }

    xcb_get_property_reply_t * workArea =
        xcb_get_property_reply(xcb_connection(),
            xcb_get_property_unchecked(xcb_connection(), false, screen()->root,
                             atom(QXcbAtom::_NET_WORKAREA),
                             XCB_ATOM_CARDINAL, 0, 1024), NULL);

    if (workArea && workArea->type == XCB_ATOM_CARDINAL && workArea->format == 32 && workArea->value_len >= 4) {
        // If workArea->value_len > 4, the remaining ones seem to be for virtual desktops.
        // But QScreen doesn't know about that concept.  In reality there could be a
        // "docked" panel (with _NET_WM_STRUT_PARTIAL atom set) on just one desktop.
        // But for now just assume the first 4 values give us the geometry of the
        // "work area", AKA "available geometry"
        uint32_t *geom = (uint32_t*)xcb_get_property_value(workArea);
        QRect virtualAvailableGeometry(geom[0], geom[1], geom[2], geom[3]);
        // Take the intersection of the desktop's available geometry with this screen's geometry
        // to get the part of the available geometry which belongs to this screen.
        m_availableGeometry = m_geometry & virtualAvailableGeometry;
    }
    free(workArea);
}
示例#10
0
文件: xcb.c 项目: eplanet/i3lock
xcb_window_t find_focused_window(xcb_connection_t *conn, const xcb_window_t root) {
    xcb_window_t result = XCB_NONE;

    _init_net_active_window(conn);

    xcb_get_property_reply_t *prop_reply = xcb_get_property_reply(
        conn,
        xcb_get_property_unchecked(
            conn, false, root, _NET_ACTIVE_WINDOW, XCB_GET_PROPERTY_TYPE_ANY, 0, 1 /* word */),
        NULL);
    if (prop_reply == NULL) {
        goto out;
    }
    if (xcb_get_property_value_length(prop_reply) == 0) {
        goto out_prop;
    }
    if (prop_reply->type != XCB_ATOM_WINDOW) {
        goto out_prop;
    }

    result = *((xcb_window_t *)xcb_get_property_value(prop_reply));

out_prop:
    free(prop_reply);
out:
    return result;
}
示例#11
0
char *xcb_util_get_property(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t atom,
        xcb_atom_t type, size_t size) {
    xcb_get_property_cookie_t cookie;
    xcb_get_property_reply_t *reply;
    xcb_generic_error_t *err;
    int reply_length;
    char *content;

    cookie = xcb_get_property(conn, 0, window, atom, type, 0, size);
    reply = xcb_get_property_reply(conn, cookie, &err);
    if (err != NULL) {
        FREE(err);
        return NULL;
    }

    if (reply == NULL || (reply_length = xcb_get_property_value_length(reply)) == 0) {
        FREE(reply);
        return NULL;
    }

    if (reply->bytes_after > 0) {
        size_t adjusted_size = size + ceil(reply->bytes_after / 4.0);
        FREE(reply);
        return xcb_util_get_property(conn, window, atom, type, adjusted_size);
    }

    if (asprintf(&content, "%.*s", reply_length, (char *)xcb_get_property_value(reply)) < 0) {
        FREE(reply);
        return NULL;
    }

    FREE(reply);
    return content;
}
示例#12
0
//! Process WM_STATE reply and update fields
void Client::process_wm_state(xcb_get_property_cookie_t gpc)
{
    // *** process WM_STATE property

    autofree_ptr<xcb_get_property_reply_t> gpr(
        xcb_get_property_reply(g_xcb.connection, gpc, NULL)
        );

    if (!gpr) {
        WARN << "Could not retrieve WM_STATE for window";
        m_wm_state = XCB_ICCCM_WM_STATE_NORMAL;
        return;
    }

    TRACE << *gpr;

    if (gpr->type != g_xcb.WM_STATE.atom ||
        gpr->format != 32 || gpr->length != 2)
    {
        WARN << "Could not retrieve WM_STATE for window";
        m_wm_state = XCB_ICCCM_WM_STATE_NORMAL;
        return;
    }

    m_wm_state = (xcb_icccm_wm_state_t)(
        *(uint32_t*)xcb_get_property_value(gpr.get())
        );

    INFO << "ICCCM WM_STATE of window " << window() << " is "
         << IcccmWmStateFormatter(m_wm_state);
}
示例#13
0
文件: window.c 项目: Fresne/i3
/*
 * Updates the WM_WINDOW_ROLE
 *
 */
void window_update_role(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
    if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
        DLOG("WM_WINDOW_ROLE not set.\n");
        FREE(prop);
        return;
    }

    char *new_role;
    if (asprintf(&new_role, "%.*s", xcb_get_property_value_length(prop),
                 (char *)xcb_get_property_value(prop)) == -1) {
        perror("asprintf()");
        DLOG("Could not get WM_WINDOW_ROLE\n");
        free(prop);
        return;
    }
    FREE(win->role);
    win->role = new_role;
    LOG("WM_WINDOW_ROLE changed to \"%s\"\n", win->role);

    if (before_mgmt) {
        free(prop);
        return;
    }

    run_assignments(win);

    free(prop);
}
示例#14
0
/*
 * Find virtual roots (_NET_VIRTUAL_ROOTS)
 */
static xcb_window_t *
Find_Roots(xcb_connection_t * dpy, xcb_window_t root, unsigned int *num)
{
    xcb_atom_t atom_virtual_root;

    xcb_get_property_cookie_t prop_cookie;
    xcb_get_property_reply_t *prop_reply;

    xcb_window_t *prop_ret = NULL;

    *num = 0;

    atom_virtual_root = Get_Atom (dpy, "_NET_VIRTUAL_ROOTS");
    if (atom_virtual_root == XCB_ATOM_NONE)
        return NULL;

    prop_cookie = xcb_get_property (dpy, False, root, atom_virtual_root,
                                    XCB_ATOM_WINDOW, 0, 0x7fffffff);
    prop_reply = xcb_get_property_reply (dpy, prop_cookie, NULL);
    if (!prop_reply)
        return NULL;

    if ((prop_reply->value_len > 0) && (prop_reply->type == XCB_ATOM_WINDOW)
        && (prop_reply->format == 32)) {
        int length = xcb_get_property_value_length (prop_reply);
        prop_ret = malloc(length);
        if (prop_ret) {
            memcpy (prop_ret, xcb_get_property_value(prop_reply), length);
            *num = prop_reply->value_len;
        }
    }
    free (prop_reply);

    return prop_ret;
}
示例#15
0
/*
 * Get X ID (array) property
 *
 * At most len items are returned in val.
 * If the property was successfully fetched the number of items stored in
 * val is returned, otherwise -1 is returned.
 * Note: Return value 0 means that the property exists but has no elements.
 */
EAPI int
ecore_x_window_prop_xid_get(Ecore_X_Window win __UNUSED__,
                            Ecore_X_Atom atom  __UNUSED__,
                            Ecore_X_Atom type  __UNUSED__,
                            Ecore_X_ID        *xids,
                            unsigned int       len)
{
   xcb_get_property_reply_t *reply;
   int num = len;

   reply = _ecore_xcb_reply_get();
   if (!reply)
      return -1;

   if (reply->type == XCB_NONE)
      num = 0;
   else if (reply->format == 32)
     {
        if (reply->value_len < len)
           num = xcb_get_property_value_length(reply);

        if (xids)
           memcpy(xids, xcb_get_property_value(reply), num);
     }

   return num;
} /* ecore_x_window_prop_xid_get */
示例#16
0
void
property_update_net_wm_pid(client_t *c,
                           xcb_get_property_reply_t *reply)
{
    bool no_reply = !reply;

    if(no_reply)
    {
        xcb_get_property_cookie_t prop_c =
            xcb_get_property_unchecked(globalconf.connection, false, c->window, _NET_WM_PID, XCB_ATOM_CARDINAL, 0L, 1L);
        reply = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
    }

    if(reply && reply->value_len)
    {
        uint32_t *rdata = xcb_get_property_value(reply);
        if(rdata)
        {
            luaA_object_push(globalconf.L, c);
            client_set_pid(globalconf.L, -1, *rdata);
            lua_pop(globalconf.L, 1);
        }
    }

    if(no_reply)
        p_delete(&reply);
}
示例#17
0
bool KWinKScreenHelperEffect::nativeEventFilter(const QByteArray &eventType, void *message, long int *result)
{
    Q_UNUSED(result);

    if (eventType != "xcb_generic_event_t") {
        return false;
    }

#ifdef HAVE_XCB
    if (m_isValid && QX11Info::isPlatformX11()) {
        auto e = static_cast<xcb_generic_event_t *>(message);
        const uint8_t type = e->response_type & ~0x80;
        if (type == XCB_PROPERTY_NOTIFY) {
            auto *event = reinterpret_cast<xcb_property_notify_event_t *>(e);
            if (event->window == QX11Info::appRootWindow()) {
                if (event->atom != m_atom) {
                    return false;
                }

                auto cookie = xcb_get_property(QX11Info::connection(), false, QX11Info::appRootWindow(), m_atom, XCB_ATOM_CARDINAL, 0, 1);
                QScopedPointer<xcb_get_property_reply_t, QScopedPointerPodDeleter> reply(xcb_get_property_reply(QX11Info::connection(), cookie, NULL));
                if (reply.isNull() || reply.data()->value_len != 1 || reply.data()->format != uint8_t(32)) {
                    return false;
                }

                auto *data = reinterpret_cast<uint32_t *>(xcb_get_property_value(reply.data()));
                if (!data) {
                    return false;
                }

                switch(*data) {
                case 1:
                    m_state = FadingOutState;
                    break;
                case 2:
                    m_state = FadedOutState;
                    if (m_running) {
                        Q_EMIT fadedOut();
                    }
                    break;
                case 3:
                    m_state = FadingInState;
                    m_running = false;
                    m_abortTimer.stop();
                    break;
                default:
                    m_state = NormalState;
                    m_running = false;
                }

                Q_EMIT stateChanged(m_state);
            }
        }
    }
#else
    Q_UNUSED(message);
#endif

    return false;
}
示例#18
0
    QByteArray getSettings()
    {
        QXcbConnectionGrabber connectionGrabber(screen->connection());

        int offset = 0;
        QByteArray settings;
        xcb_atom_t _xsettings_atom = screen->connection()->atom(QXcbAtom::_XSETTINGS_SETTINGS);
        while (1) {
            xcb_get_property_cookie_t get_prop_cookie =
                    xcb_get_property_unchecked(screen->xcb_connection(),
                                               false,
                                               x_settings_window,
                                               _xsettings_atom,
                                               _xsettings_atom,
                                               offset/4,
                                               8192);
            xcb_get_property_reply_t *reply = xcb_get_property_reply(screen->xcb_connection(), get_prop_cookie, NULL);
            bool more = false;
            if (!reply)
                return settings;

            settings += QByteArray((const char *)xcb_get_property_value(reply), xcb_get_property_value_length(reply));
            offset += xcb_get_property_value_length(reply);
            more = reply->bytes_after != 0;

            free(reply);

            if (!more)
                break;
        }

        return settings;
    }
示例#19
0
文件: window.c 项目: Fresne/i3
/*
 * Updates the name by using WM_NAME (encoded in COMPOUND_TEXT). We do not
 * touch what the client sends us but pass it to xcb_image_text_8. To get
 * proper unicode rendering, the application has to use _NET_WM_NAME (see
 * window_update_name()).
 *
 */
void window_update_name_legacy(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
    if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
        DLOG("WM_NAME not set (_NET_WM_NAME is what you want anyways).\n");
        FREE(prop);
        return;
    }

    /* ignore update when the window is known to already have a UTF-8 name */
    if (win->uses_net_wm_name) {
        free(prop);
        return;
    }

    i3string_free(win->name);
    win->name = i3string_from_utf8_with_length(xcb_get_property_value(prop),
                                               xcb_get_property_value_length(prop));

    LOG("WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));
    LOG("Using legacy window title. Note that in order to get Unicode window "
        "titles in i3, the application has to set _NET_WM_NAME (UTF-8)\n");

    win->name_x_changed = true;

    if (before_mgmt) {
        free(prop);
        return;
    }

    run_assignments(win);

    free(prop);
}
示例#20
0
static void
weston_wm_get_selection_targets(struct weston_wm *wm)
{
	struct x11_data_source *source;
	struct weston_compositor *compositor;
	struct weston_seat *seat = weston_wm_pick_seat(wm);
	xcb_get_property_cookie_t cookie;
	xcb_get_property_reply_t *reply;
	xcb_atom_t *value;
	char **p;
	uint32_t i;

	cookie = xcb_get_property(wm->conn,
				  1, /* delete */
				  wm->selection_window,
				  wm->atom.wl_selection,
				  XCB_GET_PROPERTY_TYPE_ANY,
				  0, /* offset */
				  4096 /* length */);

	reply = xcb_get_property_reply(wm->conn, cookie, NULL);
	if (reply == NULL)
		return;

	dump_property(wm, wm->atom.wl_selection, reply);

	if (reply->type != XCB_ATOM_ATOM) {
		free(reply);
		return;
	}

	source = zalloc(sizeof *source);
	if (source == NULL) {
		free(reply);
		return;
	}

	wl_signal_init(&source->base.destroy_signal);
	source->base.accept = data_source_accept;
	source->base.send = data_source_send;
	source->base.cancel = data_source_cancel;
	source->wm = wm;

	wl_array_init(&source->base.mime_types);
	value = xcb_get_property_value(reply);
	for (i = 0; i < reply->value_len; i++) {
		if (value[i] == wm->atom.utf8_string) {
			p = wl_array_add(&source->base.mime_types, sizeof *p);
			if (p)
				*p = strdup("text/plain;charset=utf-8");
		}
	}

	compositor = wm->server->compositor;
	weston_seat_set_selection(seat, &source->base,
				  wl_display_next_serial(compositor->wl_display));

	free(reply);
}
示例#21
0
EAPI int
ecore_x_window_prop_xid_list_get(Ecore_X_Window win,
                                 Ecore_X_Atom   atom,
                                 Ecore_X_Atom   type,
                                 Ecore_X_ID   **xids)
{
   xcb_get_property_cookie_t cookie;
   xcb_get_property_reply_t *reply;
   int num = -1;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN;

   if (xids) *xids = NULL;

   cookie = xcb_get_property_unchecked(_ecore_xcb_conn, 0, win, atom, type,
                                       0, 0x7fffffff);
   reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
   if (!reply) return -1;

   if ((reply->type != type) || (reply->format != 32))
     num = -1;
   else if ((reply->value_len == 0) || (!xcb_get_property_value(reply)))
     num = 0;
   else
     {
        Ecore_X_Atom *alst;
        void *val;

        num = xcb_get_property_value_length(reply);
        val = xcb_get_property_value(reply);
        alst = malloc(num * sizeof(Ecore_X_ID));
        if (alst)
          {
             int i = 0;

             for (i = 0; i < num; i++)
               alst[i] = ((unsigned long *)val)[i];
             *xids = alst;
          }
     }

   free(reply);
   return num;
}
示例#22
0
EAPI char *
ecore_x_window_prop_string_get(Ecore_X_Window win,
                               Ecore_X_Atom   type)
{
   xcb_get_property_cookie_t cookie;
   xcb_get_property_reply_t *reply;
   char *str = NULL;
   int len = 0;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   CHECK_XCB_CONN;

   cookie =
     xcb_get_property_unchecked(_ecore_xcb_conn, 0,
                                win ? win : ((xcb_screen_t *)_ecore_xcb_screen)->root,
                                type, XCB_GET_PROPERTY_TYPE_ANY, 0, 1000000L);
   reply = xcb_get_property_reply(_ecore_xcb_conn, cookie, NULL);
   if (!reply) return NULL;

   len = ((reply->value_len * reply->format) / 8);
   str = (char *)malloc((len + 1) * sizeof(char));
   memcpy(str, xcb_get_property_value(reply), len);
   str[len] = '\0';

   if (reply->type != ECORE_X_ATOM_UTF8_STRING)
     {
        Ecore_Xcb_Textproperty prop;
        int count = 0;
        char **list = NULL;
        Eina_Bool ret = EINA_FALSE;

        prop.value = strdup(str);
        prop.nitems = len;
        prop.encoding = reply->type;

#ifdef HAVE_ICONV
        ret = _ecore_xcb_utf8_textproperty_to_textlist(&prop, &list, &count);
#else
        ret = _ecore_xcb_mb_textproperty_to_textlist(&prop, &list, &count);
#endif
        if (ret)
          {
             if (count > 0)
               str = strdup(list[0]);
             else
               str = strdup((char *)prop.value);

             if (list) free(list);
          }
        else
          str = strdup((char *)prop.value);
     }

   free(reply);
   return str;
}
示例#23
0
/*!
  Returns WM_CLIENT_LEADER property for a given window.
 */
xcb_window_t Toplevel::staticWmClientLeader(xcb_window_t w)
{
    xcb_connection_t *c = connection();
    auto cookie = xcb_get_property_unchecked(c, false, w, atoms->wm_client_leader, XCB_ATOM_WINDOW, 0, 10000);
    ScopedCPointer<xcb_get_property_reply_t> prop(xcb_get_property_reply(c, cookie, nullptr));
    if (prop.isNull() || prop->value_len <= 0) {
        return w;
    }
    return static_cast<xcb_window_t*>(xcb_get_property_value(prop.data()))[0];
}
示例#24
0
文件: window.c 项目: feler/ceres
/* window_get_state {{{
 */
uint32_t
window_get_state(xcb_get_property_cookie_t cookie)
{
    xcb_get_property_reply_t *reply = 
        xcb_get_property_reply(rootconf.connection, cookie, NULL);

    if(reply)
        if(xcb_get_property_value_length(reply))
            return *(uint32_t *) xcb_get_property_value(reply);
    return 0;
} /*  }}} */
示例#25
0
/** Update leader hint of a client.
 * \param c The client.
 * \param cookie Cookie returned by property_get_wm_client_leader.
 */
void
property_update_wm_client_leader(client_t *c, xcb_get_property_cookie_t cookie)
{
    xcb_get_property_reply_t *reply;
    void *data;

    reply = xcb_get_property_reply(globalconf.connection, cookie, NULL);

    if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
        c->leader_window = *(xcb_window_t *) data;

    p_delete(&reply);
}
示例#26
0
文件: Client.cpp 项目: jhanssen/nwm
void Client::updateLeader(xcb_connection_t* conn, xcb_get_property_cookie_t cookie)
{
    AutoPointer<xcb_get_property_reply_t> leader(xcb_get_property_reply(conn, cookie, 0));
    if (!leader || leader->type != XCB_ATOM_WINDOW || leader->format != 32 || !leader->length) {
        mGroup = ClientGroup::clientGroup(mWindow);
        mGroup->add(this);
        return;
    }

    const xcb_window_t win = *static_cast<xcb_window_t *>(xcb_get_property_value(leader));
    mGroup = ClientGroup::clientGroup(win);
    mGroup->add(this);
}
示例#27
0
    //_______________________________________________________
    bool ShadowHelper::checkSupported( void ) const
    {

        // create atom
        #if MENDA_HAVE_X11

        // make sure we are on X11
        if( !Helper::isX11() ) return false;

        // create atom
        xcb_atom_t netSupportedAtom( _helper.createAtom( "_NET_SUPPORTED" ) );
        if( !netSupportedAtom ) return false;

        // store connection locally
        xcb_connection_t* connection( Helper::connection() );

        // get property
        const quint32 maxLength = std::string().max_size();
        xcb_get_property_cookie_t cookie( xcb_get_property( connection, 0, QX11Info::appRootWindow(), netSupportedAtom, XCB_ATOM_ATOM, 0, (maxLength+3) / 4 ) );
        ScopedPointer<xcb_get_property_reply_t> reply( xcb_get_property_reply( connection, cookie, nullptr ) );
        if( !reply ) return false;

        // get reply length and data
        const int count( xcb_get_property_value_length( reply.data() )/sizeof( xcb_atom_t ) );
        xcb_atom_t *atoms = reinterpret_cast<xcb_atom_t*>( xcb_get_property_value( reply.data() ) );

        bool found( false );
        for( int i = 0; i < count && !found; ++i )
        {
            // get atom name and print
            xcb_atom_t atom( atoms[i] );

            xcb_get_atom_name_cookie_t cookie( xcb_get_atom_name( connection, atom ) );
            ScopedPointer<xcb_get_atom_name_reply_t> reply( xcb_get_atom_name_reply( connection, cookie, 0 ) );
            if( !reply ) continue;

            // get name and compare
            const QString name( QByteArray( xcb_get_atom_name_name( reply.data() ), xcb_get_atom_name_name_length( reply.data() ) ) );
            if( strcmp( netWMShadowAtomName, xcb_get_atom_name_name( reply.data() ) ) == 0 ) found = true;

        }

        return found;

        #else
        return false;
        #endif

    }
示例#28
0
// retrieve a text property from a window
// technically we could use window_get_prop(), but this is better for character set support
char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom )
{
    xcb_get_property_cookie_t c  = xcb_get_property ( xcb->connection, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX );
    xcb_get_property_reply_t  *r = xcb_get_property_reply ( xcb->connection, c, NULL );
    if ( r ) {
        if ( xcb_get_property_value_length ( r ) > 0 ) {
            char *str = NULL;
            if ( r->type == netatoms[UTF8_STRING] ) {
                str = g_strndup ( xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) );
            }
            else if ( r->type == netatoms[STRING] ) {
                str = rofi_latin_to_utf8_strdup ( xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) );
            }
            else {
                str = g_strdup ( "Invalid encoding." );
            }

            free ( r );
            return str;
        }
        free ( r );
    }
    return NULL;
}
示例#29
0
/**
 * Get a window string property.
 * @param window The window
 * @param type The property
 *
 * Return window string property of a window. String must be free'd when done.
 *
 * To use this function, you must call before, and in order,
 * ecore_x_window_prop_string_get_prefetch(), which sends the GetProperty request,
 * then ecore_x_window_prop_string_get_fetch(), which gets the reply.
 */
EAPI char *
ecore_x_window_prop_string_get(Ecore_X_Window window __UNUSED__,
                               Ecore_X_Atom type     __UNUSED__)
{
   xcb_get_property_reply_t *reply;
   char *str = NULL;

   reply = _ecore_xcb_reply_get();
   if (!reply)
      return NULL;

   if (reply->type == ECORE_X_ATOM_UTF8_STRING)
     {
        int length;

        length = reply->value_len;
        str = (char *)malloc(length + 1);
        memcpy(str,
               xcb_get_property_value(reply),
               length);
        str[length] = '\0';
     }
   else
     {
        /* FIXME: to be done... */

/* #ifdef X_HAVE_UTF8_STRING */
/*         s = Xutf8TextPropertyToTextList(_ecore_xcb_conn, &xtp, */
/*                                         &list, &items); */
/* #else */
/*         s = XmbTextPropertyToTextList(_ecore_xcb_conn, &xtp, */
/*                                       &list, &items); */
/* #endif */
/*         if ((s == XLocaleNotSupported) || */
/*             (s == XNoMemory) || (s == XConverterNotFound)) */
/*           { */
/*              str = strdup((char *)xtp.value); */
/*           } */
/*         else if ((s >= Success) && (items > 0)) */
/*           { */
/*              str = strdup(list[0]); */
/*           } */
/*         if (list) */
/*            XFreeStringList(list); */
     }

   return str;
} /* ecore_x_window_prop_string_get */
示例#30
0
/** Get the opacity of a window.
 * \param cookie A cookie for a reply to a get property request for _NET_WM_WINDOW_OPACITY.
 * \return The opacity, between 0 and 1.
 */
double
xwindow_get_opacity_from_cookie(xcb_get_property_cookie_t cookie)
{
    xcb_get_property_reply_t *prop_r =
        xcb_get_property_reply(globalconf.connection, cookie, NULL);

    if(prop_r && prop_r->value_len && prop_r->format == 32)
    {
        uint32_t value = *(uint32_t *) xcb_get_property_value(prop_r);
        p_delete(&prop_r);
        return (double) value / (double) 0xffffffff;
    }
    p_delete(&prop_r);

    return -1;
}