Example #1
0
File: window.c Project: Fresne/i3
/*
 * Updates the WM_CLASS (consisting of the class and instance) for the
 * given window.
 *
 */
void window_update_class(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
    if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
        DLOG("WM_CLASS not set.\n");
        FREE(prop);
        return;
    }

    /* We cannot use asprintf here since this property contains two
     * null-terminated strings (for compatibility reasons). Instead, we
     * use strdup() on both strings */
    const size_t prop_length = xcb_get_property_value_length(prop);
    char *new_class = smalloc(prop_length + 1);
    memcpy(new_class, xcb_get_property_value(prop), prop_length);
    new_class[prop_length] = '\0';

    FREE(win->class_instance);
    FREE(win->class_class);

    win->class_instance = sstrdup(new_class);
    if ((strlen(new_class) + 1) < prop_length)
        win->class_class = sstrdup(new_class + strlen(new_class) + 1);
    else
        win->class_class = NULL;
    LOG("WM_CLASS changed to %s (instance), %s (class)\n",
        win->class_instance, win->class_class);

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

    run_assignments(win);

    free(new_class);
    free(prop);
}
Example #2
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

    }
Example #3
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;
}
Example #4
0
File: window.c Project: Fresne/i3
/*
 * Updates the name by using _NET_WM_NAME (encoded in UTF-8) for the given
 * window. Further updates using window_update_name_legacy will be ignored.
 *
 */
void window_update_name(i3Window *win, xcb_get_property_reply_t *prop, bool before_mgmt) {
    if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
        DLOG("_NET_WM_NAME not specified, not changing\n");
        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));
    win->name_x_changed = true;
    LOG("_NET_WM_NAME changed to \"%s\"\n", i3string_as_utf8(win->name));

    win->uses_net_wm_name = true;

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

    run_assignments(win);

    free(prop);
}
Example #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);
        if (r.startsWith("Xft.dpi:\t")) {
            bool ok;
            int dpi = r.mid(sizeof("Xft.dpi:")).toInt(&ok);
            if (ok)
                m_forcedDpi = dpi;
            break;
        }
    }
}
Example #6
0
QTC_EXPORT bool
qtcX11IsEmbed(xcb_window_t win)
{
    if (qtcUnlikely(!win))
        return false;
    xcb_atom_t xembed_atom = qtc_x11_atoms[QTC_X11_ATOM_XEMBED_INFO];
    xcb_get_property_reply_t *reply =
        qtcX11Call(get_property, 0, win, xembed_atom,
                   xembed_atom, 0, 1);
    if (!reply) {
        return false;
    }
    bool res = xcb_get_property_value_length(reply) > 0;
    free(reply);
    return res;
}
Example #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
xwindow_get_state_reply(xcb_get_property_cookie_t cookie)
{
    /* If no property is set, we just assume a sane default. */
    uint32_t result = XCB_ICCCM_WM_STATE_NORMAL;
    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);

        p_delete(&prop_r);
    }

    return result;
}
Example #8
0
static void UpdateApps (services_discovery_t *sd)
{
    services_discovery_sys_t *p_sys = sd->p_sys;
    xcb_connection_t *conn = p_sys->conn;

    xcb_get_property_reply_t *r =
        xcb_get_property_reply (conn,
            xcb_get_property (conn, false, p_sys->root_window,
                              p_sys->net_client_list, XA_WINDOW, 0, 1024),
            NULL);
    if (r == NULL)
        return; /* FIXME: remove all entries */

    xcb_window_t *ent = xcb_get_property_value (r);
    int n = xcb_get_property_value_length (r) / 4;
    void *newnodes = NULL, *oldnodes = p_sys->apps;

    for (int i = 0; i < n; i++)
    {
        xcb_window_t id = *(ent++);
        struct app *app;

        struct app **pa = tfind (&id, &oldnodes, cmpapp);
        if (pa != NULL) /* existing entry */
        {
            app = *pa;
            tdelete (app, &oldnodes, cmpapp);
        }
        else /* new entry */
        {
            app = AddApp (sd, id);
            if (app == NULL)
                continue;
        }

        pa = tsearch (app, &newnodes, cmpapp);
        if (pa == NULL /* OOM */ || *pa != app /* buggy window manager */)
            DelApp (app);
    }
    free (r);

    /* Remove old nodes */
    tdestroy (oldnodes, DelApp);
    p_sys->apps = newnodes;
}
Example #9
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;
}
Example #10
0
File: window.c Project: Fresne/i3
/*
 * Updates the MOTIF_WM_HINTS. The container's border style should be set to
 * `motif_border_style' if border style is not BS_NORMAL.
 *
 * i3 only uses this hint when it specifies a window should have no
 * title bar, or no decorations at all, which is how most window managers
 * handle it.
 *
 * The EWMH spec intended to replace Motif hints with _NET_WM_WINDOW_TYPE, but
 * it is still in use by popular widget toolkits such as GTK+ and Java AWT.
 *
 */
void window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, border_style_t *motif_border_style) {
/* This implementation simply mirrors Gnome's Metacity. Official
     * documentation of this hint is nowhere to be found.
     * For more information see:
     * https://people.gnome.org/~tthurman/docs/metacity/xprops_8h-source.html
     * http://stackoverflow.com/questions/13787553/detect-if-a-x11-window-has-decorations
     */
#define MWM_HINTS_DECORATIONS (1 << 1)
#define MWM_DECOR_ALL (1 << 0)
#define MWM_DECOR_BORDER (1 << 1)
#define MWM_DECOR_TITLE (1 << 3)

    if (motif_border_style != NULL)
        *motif_border_style = BS_NORMAL;

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

    /* The property consists of an array of 5 uint64_t's. The first value is a bit
     * mask of what properties the hint will specify. We are only interested in
     * MWM_HINTS_DECORATIONS because it indicates that the second value of the
     * array tells us which decorations the window should have, each flag being
     * a particular decoration. */
    uint64_t *motif_hints = (uint64_t *)xcb_get_property_value(prop);

    if (motif_border_style != NULL && motif_hints[0] & MWM_HINTS_DECORATIONS) {
        if (motif_hints[1] & MWM_DECOR_ALL || motif_hints[1] & MWM_DECOR_TITLE)
            *motif_border_style = BS_NORMAL;
        else if (motif_hints[1] & MWM_DECOR_BORDER)
            *motif_border_style = BS_PIXEL;
        else
            *motif_border_style = BS_NONE;
    }

    FREE(prop);

#undef MWM_HINTS_DECORATIONS
#undef MWM_DECOR_ALL
#undef MWM_DECOR_BORDER
#undef MWM_DECOR_TITLE
}
Example #11
0
static struct app *AddApp (services_discovery_t *sd, xcb_window_t xid)
{
    services_discovery_sys_t *p_sys = sd->p_sys;
    char *mrl, *name;

    if (asprintf (&mrl, "window://0x%"PRIx8, xid) == -1)
        return NULL;

    xcb_get_property_reply_t *r =
        xcb_get_property_reply (p_sys->conn,
            xcb_get_property (p_sys->conn, 0, xid, p_sys->net_wm_name, 0,
                              0, 1023 /* max size */), NULL);
    if (r != NULL)
    {
        name = strndup (xcb_get_property_value (r),
                        xcb_get_property_value_length (r));
        if (name != NULL)
            EnsureUTF8 (name); /* don't trust third party apps too much ;-) */
        free (r);
    }
    /* TODO: use WM_NAME (Latin-1) for very old apps */
    else
        name = NULL;

    input_item_t *item = input_item_NewCard (mrl, name ? name : mrl); /* FIXME */
    free (mrl);
    free (name);
    if (item == NULL)
        return NULL;

    struct app *app = malloc (sizeof (*app));
    if (app == NULL)
    {
        input_item_Release (item);
        return NULL;
    }
    app->xid = xid;
    app->item = item;
    app->owner = sd;
    services_discovery_AddSubItem(sd, p_sys->apps_root, item);
    return app;
}
Example #12
0
File: window.c Project: Fresne/i3
/*
 * Updates the TRANSIENT_FOR (logical parent window).
 *
 */
void window_update_transient_for(i3Window *win, xcb_get_property_reply_t *prop) {
    if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
        DLOG("TRANSIENT_FOR not set on window 0x%08x.\n", win->id);
        win->transient_for = XCB_NONE;
        FREE(prop);
        return;
    }

    xcb_window_t transient_for;
    if (!xcb_icccm_get_wm_transient_for_from_reply(&transient_for, prop)) {
        free(prop);
        return;
    }

    DLOG("Transient for changed to 0x%08x (window 0x%08x)\n", transient_for, win->id);

    win->transient_for = transient_for;

    free(prop);
}
Example #13
0
File: window.c Project: Fresne/i3
/*
 * Updates the CLIENT_LEADER (logical parent window).
 *
 */
void window_update_leader(i3Window *win, xcb_get_property_reply_t *prop) {
    if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
        DLOG("CLIENT_LEADER not set on window 0x%08x.\n", win->id);
        win->leader = XCB_NONE;
        FREE(prop);
        return;
    }

    xcb_window_t *leader = xcb_get_property_value(prop);
    if (leader == NULL) {
        free(prop);
        return;
    }

    DLOG("Client leader changed to %08x\n", *leader);

    win->leader = *leader;

    free(prop);
}
Example #14
0
File: window.c Project: Fresne/i3
/*
 * Updates the _NET_WM_STRUT_PARTIAL (reserved pixels at the screen edges)
 *
 */
void window_update_strut_partial(i3Window *win, xcb_get_property_reply_t *prop) {
    if (prop == NULL || xcb_get_property_value_length(prop) == 0) {
        DLOG("_NET_WM_STRUT_PARTIAL not set.\n");
        FREE(prop);
        return;
    }

    uint32_t *strut;
    if (!(strut = xcb_get_property_value(prop))) {
        free(prop);
        return;
    }

    DLOG("Reserved pixels changed to: left = %d, right = %d, top = %d, bottom = %d\n",
         strut[0], strut[1], strut[2], strut[3]);

    win->reserved = (struct reservedpx){strut[0], strut[1], strut[2], strut[3]};

    free(prop);
}
Example #15
0
QTC_EXPORT int32_t
qtcX11GetShortProp(xcb_window_t win, xcb_atom_t atom)
{
    if (qtcUnlikely(!win))
        return -1;
    int32_t res = -1;
    xcb_get_property_reply_t *reply =
        qtcX11Call(get_property, 0, win, atom, XCB_ATOM_CARDINAL, 0, 1);
    if (!reply) {
        return -1;
    }
    if (xcb_get_property_value_length(reply) > 0) {
        uint32_t val = *(int32_t*)xcb_get_property_value(reply);
        if (val < 512) {
            res = val;
        }
    }
    free(reply);
    return res;
}
Example #16
0
void
set_window_opacity(xcwm_window_t *window, xcwm_property_t *property)
{
  xcb_get_property_cookie_t cookie;
  cookie = xcb_get_property(window->context->conn, 0, window->window_id, property->atom, XCB_ATOM_CARDINAL, 0L, 4L);

  xcb_get_property_reply_t *reply = xcb_get_property_reply(window->context->conn, cookie, NULL);
  if (reply)
    {
      int nitems = xcb_get_property_value_length(reply);
      uint32_t *value = xcb_get_property_value(reply);

      if (value && nitems == 4)
        {
          window->opacity = *value;
        }

      free(reply);
    }
}
Example #17
0
static void
get_resources(xcb_connection_t *connection, xcb_screen_t *screen, cairo_xcb_resources_t *resources)
{
    xcb_get_property_cookie_t cookie;
    xcb_get_property_reply_t *reply;
    struct resource_parser parser;
    int offset;
    cairo_bool_t has_more_data;

    resources->xft_antialias = TRUE;
    resources->xft_lcdfilter = -1;
    resources->xft_hinting = TRUE;
    resources->xft_hintstyle = FC_HINT_FULL;
    resources->xft_rgba = FC_RGBA_UNKNOWN;

    resource_parser_init (&parser, resources);

    offset = 0;
    has_more_data = FALSE;
    do {
	cookie = xcb_get_property (connection, 0, screen->root, XCB_ATOM_RESOURCE_MANAGER, XCB_ATOM_STRING, offset, 1024);
	reply = xcb_get_property_reply (connection, cookie, NULL);

	if (reply) {
	    if (reply->format == 8 && reply->type == XCB_ATOM_STRING) {
		char *value = (char *) xcb_get_property_value (reply);
		int length = xcb_get_property_value_length (reply);

		offset += length / 4; /* X needs the offset in 'long' units */
		has_more_data = reply->bytes_after > 0;

		if (! resource_parser_update (&parser, value, length))
		    has_more_data = FALSE; /* early exit on error */
	    }

	    free (reply);
	}
    } while (has_more_data);

    resource_parser_done (&parser);
}
Example #18
0
void get_net_frame_window(xcb_window_t window, xcb_window_t *res) {
	xcb_atom_t net_frame_window;
	if (create_atom("_NET_FRAME_WINDOW", 1, &net_frame_window)) {
		*res = window;
		return;
	}
	xcb_get_property_cookie_t cookie =
			xcb_get_property(display, 0, window,
			net_frame_window, XCB_ATOM_ANY, 0, 1);
	xcb_get_property_reply_t *reply =
			xcb_get_property_reply(display, cookie, NULL);
	if (
		reply == NULL ||
		reply->type == XCB_ATOM_NONE || reply->format != 32 ||
		xcb_get_property_value_length(reply) != sizeof (xcb_window_t)
	) {
		*res = window;
		return;
	}
	*res = *(xcb_window_t *) xcb_get_property_value(reply);
	free(reply);
}
Example #19
0
void QXcbDrag::handleEnter(QWindow *window, const xcb_client_message_event_t *event)
{
    Q_UNUSED(window);
    DEBUG() << "handleEnter" << window;

    xdnd_types.clear();

    int version = (int)(event->data.data32[1] >> 24);
    if (version > xdnd_version)
        return;

    xdnd_dragsource = event->data.data32[0];

    if (event->data.data32[1] & 1) {
        // get the types from XdndTypeList
        xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, xdnd_dragsource,
                                                            atom(QXcbAtom::XdndTypelist), XCB_ATOM_ATOM,
                                                            0, xdnd_max_type);
        xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0);
        if (reply && reply->type != XCB_NONE && reply->format == 32) {
            int length = xcb_get_property_value_length(reply) / 4;
            if (length > xdnd_max_type)
                length = xdnd_max_type;

            xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply);
            for (int i = 0; i < length; ++i)
                xdnd_types.append(atoms[i]);
        }
        free(reply);
    } else {
        // get the types from the message
        for(int i = 2; i < 5; i++) {
            if (event->data.data32[i])
                xdnd_types.append(event->data.data32[i]);
        }
    }
    for(int i = 0; i < xdnd_types.length(); ++i)
        DEBUG() << "    " << connection()->atomName(xdnd_types.at(i));
}
Example #20
0
/**
 * To be documented.
 * @param window   The window (Unused).
 * @param property The property atom (Unused).
 * @param type     The type atom (Unused).
 * @param size     The size (Unused).
 * @param data     The returned data.
 * @param num      The size of the data.
 * @return         1 on success, 0 otherwise.
 *
 * FIXME: To be fixed.
 */
EAPI int
ecore_x_window_prop_property_get(Ecore_X_Window window __UNUSED__,
                                 Ecore_X_Atom property __UNUSED__,
                                 Ecore_X_Atom type     __UNUSED__,
                                 int size              __UNUSED__,
                                 unsigned char       **data,
                                 int                  *num)
{
   xcb_get_property_reply_t *reply;

   /* make sure these are initialized */
   if (num)
      *num = 0L;

   if (data)
      *data = NULL;
   else /* we can't store the retrieved data, so just return */
      return 0;

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

   if ((reply->format != size) ||
       (reply->value_len == 0))
      return 0;

   *data = malloc(reply->value_len);
   if (!*data)
      return 0;

   memcpy(*data, xcb_get_property_value(reply),
          xcb_get_property_value_length(reply));

   if (num)
      *num = reply->value_len;

   return reply->format;
} /* ecore_x_window_prop_property_get */
Example #21
0
/*
 * Get CARD32 (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_card32_get(Ecore_X_Window win __UNUSED__,
                               Ecore_X_Atom atom  __UNUSED__,
                               unsigned int      *val,
                               unsigned int       len)
{
   xcb_get_property_reply_t *reply;

   reply = _ecore_xcb_reply_get();
   if (!reply ||
       (reply->type != ECORE_X_ATOM_CARDINAL) ||
       (reply->format != 32))
      return -1;

   if (reply->value_len < len)
      len = xcb_get_property_value_length(reply);

   if (val)
      memcpy(val, xcb_get_property_value(reply), len);

   return (int)len;
} /* ecore_x_window_prop_card32_get */
Example #22
0
/*
 * Get CARD32 (array) property of any length
 *
 * 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_card32_list_get(Ecore_X_Window win __UNUSED__,
                                    Ecore_X_Atom atom  __UNUSED__,
                                    unsigned int     **plist)
{
   xcb_get_property_reply_t *reply;
   int num = -1;

   if (plist)
      *plist = NULL;

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

   if ((reply->type == XCB_NONE) ||
       (reply->value_len == 0))
      num = 0;
   else if ((reply->type == ECORE_X_ATOM_CARDINAL) &&
            (reply->format == 32))
     {
        uint32_t *val;

        num = xcb_get_property_value_length(reply);
        if (plist)
          {
             val = (uint32_t *)malloc (num);
             if (!val)
                goto error;

             memcpy(val, xcb_get_property_value(reply), num);
             *plist = val;
          }
     }

error:

   return num;
} /* ecore_x_window_prop_card32_list_get */
Example #23
0
int fwm_handle_wmname_change(void *data, xcb_connection_t *c, uint8_t state, xcb_window_t window, xcb_atom_t atom, xcb_get_property_reply_t *prop) {
    printf("WM_NAME change for 0x%08x: ", window);
    fwm_mwin_t *managed_window = fwm_wt_get(gd.wt, window);
    if (!managed_window) {
        printf("is not being managed.\n");
        return 0;
    }
    if (managed_window->name) {
        printf("was named \"%.*s\"; now ", managed_window->name_len, managed_window->name);
        free(managed_window->name);
    }
    if (!prop) {
        managed_window->name_len = 0;
        managed_window->name = NULL;
        printf("has no name.\n");
        return 1;
    }
    managed_window->name_len = xcb_get_property_value_length(prop);
    managed_window->name = malloc(managed_window->name_len);
    strncpy(managed_window->name, xcb_get_property_value(prop), managed_window->name_len);
    printf("is named \"%.*s\".\n", managed_window->name_len, managed_window->name);
    return 1;
}
Example #24
0
File: util.cpp Project: nyorain/ny
Property readProperty(xcb_connection_t& connection, xcb_atom_t atom, xcb_window_t window,
	xcb_generic_error_t* error, bool del)
{
	error = nullptr;
	xcb_generic_error_t* errorPtr;
	auto length = 1;

	auto cookie = xcb_get_property(&connection, false, window, atom, XCB_ATOM_ANY, 0, length);
	auto reply = xcb_get_property_reply(&connection, cookie, &errorPtr);

	if(reply && !errorPtr && (reply->bytes_after || del))
	{
		length = reply->length;
		free(reply);

		cookie = xcb_get_property(&connection, del, window, atom, XCB_ATOM_ANY, 0, length);
		reply = xcb_get_property_reply(&connection, cookie, &errorPtr);
	}

	Property ret {};
	if(!errorPtr && reply)
	{
		ret.format = reply->format;
		ret.type = reply->type;

		auto begin = static_cast<uint8_t*>(xcb_get_property_value(reply));
		ret.data = {begin, begin + xcb_get_property_value_length(reply)};
		free(reply);
	}
	else if(errorPtr)
	{
		if(error) *error = *errorPtr;
		free(errorPtr);
	}

	return ret;
}
bool QXcbNativeInterface::systrayVisualHasAlphaChannel() {
    const QXcbScreen *screen = static_cast<QXcbScreen *>(QGuiApplication::primaryScreen()->handle());

    if (m_systrayVisualId == XCB_NONE) {
        xcb_connection_t *xcb_conn = screen->xcb_connection();
        xcb_atom_t tray_atom = screen->atom(QXcbAtom::_NET_SYSTEM_TRAY_VISUAL);

        xcb_window_t systray_window = locateSystemTray(xcb_conn, screen);
        if (systray_window == XCB_WINDOW_NONE)
            return false;

        // Get the xcb property for the _NET_SYSTEM_TRAY_VISUAL atom
        xcb_get_property_cookie_t systray_atom_cookie;
        xcb_get_property_reply_t *systray_atom_reply;

        systray_atom_cookie = xcb_get_property_unchecked(xcb_conn, false, systray_window,
                                                        tray_atom, XCB_ATOM_VISUALID, 0, 1);
        systray_atom_reply = xcb_get_property_reply(xcb_conn, systray_atom_cookie, 0);

        if (!systray_atom_reply)
            return false;

        if (systray_atom_reply->value_len > 0 && xcb_get_property_value_length(systray_atom_reply) > 0) {
            xcb_visualid_t * vids = (uint32_t *)xcb_get_property_value(systray_atom_reply);
            m_systrayVisualId = vids[0];
        }

        free(systray_atom_reply);
    }

    if (m_systrayVisualId != XCB_NONE) {
        quint8 depth = screen->depthOfVisual(m_systrayVisualId);
        return depth == 32;
    } else {
        return false;
    }
}
Example #26
0
static void
read_properties(struct wlc_xwm *xwm, struct wlc_x11_window *win, const xcb_atom_t *props, size_t nmemb)
{
   assert(win);

   struct wlc_view *view;
   if (!(view = view_for_window(win)))
      return;

   xcb_get_property_cookie_t *cookies;
   if (!(cookies = chck_calloc_of(nmemb, sizeof(xcb_get_property_cookie_t))))
      return;

   for (uint32_t i = 0; i < nmemb; ++i)
      cookies[i] = xcb_get_property(x11.connection, 0, win->id, props[i], XCB_ATOM_ANY, 0, 2048);

   for (uint32_t i = 0; i < nmemb; ++i) {
      xcb_get_property_reply_t *reply;
      if (!(reply = xcb_get_property_reply(x11.connection, cookies[i], NULL)))
         continue;

      if (reply->type == XCB_ATOM_STRING || reply->type == x11.atoms[UTF8_STRING]) {
         // Class && Name
         // STRING == latin1, but we naively just read it as is. For full support we should convert to utf8.
         if (props[i] == XCB_ATOM_WM_CLASS) {
            wlc_view_set_class_ptr(view, xcb_get_property_value(reply), xcb_get_property_value_length(reply));
            wlc_dlog(WLC_DBG_XWM, "WM_CLASS: %s", view->data._class.data);
         } else if (props[i] == XCB_ATOM_WM_NAME || props[i] == x11.atoms[NET_WM_NAME]) {
            if (reply->type != XCB_ATOM_STRING  || !win->has_utf8_title) {
               wlc_view_set_title_ptr(view, xcb_get_property_value(reply), xcb_get_property_value_length(reply));
               win->has_utf8_title = true;
            }
            wlc_dlog(WLC_DBG_XWM, "(%d) %s %s %s", win->has_utf8_title, (reply->type == XCB_ATOM_STRING ? "STRING" : "UTF8_STRING"), (props[i] == XCB_ATOM_WM_NAME ? "WM_NAME" : "NET_WM_NAME"), view->data.title.data);
         }
      } else if (props[i] == XCB_ATOM_WM_TRANSIENT_FOR && reply->type == XCB_ATOM_WINDOW) {
         // Transient
         xcb_window_t *xid = xcb_get_property_value(reply);
         set_parent(xwm, win, *xid);
         wlc_dlog(WLC_DBG_XWM, "WM_TRANSIENT_FOR: %u", *xid);
      } else if (props[i] == x11.atoms[NET_WM_PID] && reply->type == XCB_ATOM_CARDINAL) {
         // PID
         wlc_dlog(WLC_DBG_XWM, "NET_WM_PID");
      } else if (props[i] == x11.atoms[NET_WM_WINDOW_TYPE] && reply->type == XCB_ATOM_ATOM) {
         // Window type
         view->type &= ~WLC_BIT_UNMANAGED | ~WLC_BIT_SPLASH | ~WLC_BIT_MODAL;
         xcb_atom_t *atoms = xcb_get_property_value(reply);
         for (uint32_t i = 0; i < reply->value_len; ++i) {
            if (atoms[i] == x11.atoms[NET_WM_WINDOW_TYPE_TOOLTIP] ||
                  atoms[i] == x11.atoms[NET_WM_WINDOW_TYPE_UTILITY] ||
                  atoms[i] == x11.atoms[NET_WM_WINDOW_TYPE_DND] ||
                  atoms[i] == x11.atoms[NET_WM_WINDOW_TYPE_DROPDOWN_MENU] ||
                  atoms[i] == x11.atoms[NET_WM_WINDOW_TYPE_POPUP_MENU] ||
                  atoms[i] == x11.atoms[NET_WM_WINDOW_TYPE_COMBO]) {
               wlc_view_set_type_ptr(view, WLC_BIT_UNMANAGED, true);
            }
            if (atoms[i] == x11.atoms[NET_WM_WINDOW_TYPE_DIALOG])
               wlc_view_set_type_ptr(view, WLC_BIT_MODAL, true);
            if (atoms[i] == x11.atoms[NET_WM_WINDOW_TYPE_SPLASH])
               wlc_view_set_type_ptr(view, WLC_BIT_SPLASH, true);
         }
         wlc_dlog(WLC_DBG_XWM, "NET_WM_WINDOW_TYPE: %u", view->type);
      } else if (props[i] == x11.atoms[WM_PROTOCOLS]) {
         xcb_atom_t *atoms = xcb_get_property_value(reply);
         for (uint32_t i = 0; i < reply->value_len; ++i) {
            if (atoms[i] == x11.atoms[WM_DELETE_WINDOW])
               win->has_delete_window = true;
         }
         wlc_dlog(WLC_DBG_XWM, "WM_PROTOCOLS: %u", view->type);
      } else if (props[i] == x11.atoms[WM_NORMAL_HINTS]) {
         wlc_dlog(WLC_DBG_XWM, "WM_NORMAL_HINTS");
      } else if (props[i] == x11.atoms[NET_WM_STATE]) {
         handle_state(win, xcb_get_property_value(reply), reply->value_len, NET_WM_STATE_ADD);
         wlc_dlog(WLC_DBG_XWM, "NET_WM_STATE");
      } else if (props[i] == x11.atoms[MOTIF_WM_HINTS]) {
         // Motif hints
         wlc_dlog(WLC_DBG_XWM, "MOTIF_WM_HINTS");
      }

      free(reply);
   }

   free(cookies);
}
Example #27
0
static gchar *i3ipc_connection_get_socket_path(i3ipcConnection *self, GError **err) {
  GError *tmp_error = NULL;
  xcb_intern_atom_reply_t *atom_reply;
  gchar *socket_path;
  char *atomname = "I3_SOCKET_PATH";
  size_t content_max_words = 256;
  xcb_screen_t *screen;
  xcb_intern_atom_cookie_t atom_cookie;
  xcb_window_t root;
  xcb_get_property_cookie_t prop_cookie;
  xcb_get_property_reply_t *prop_reply;

  g_return_val_if_fail(err == NULL || *err == NULL, NULL);

  if (self->priv->socket_path != NULL)
    return self->priv->socket_path;

  xcb_connection_t *conn = xcb_connect(NULL, NULL);

  screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;

  root = screen->root;

  atom_cookie = xcb_intern_atom(conn, 0, strlen(atomname), atomname);
  atom_reply = xcb_intern_atom_reply(conn, atom_cookie, NULL);

  if (atom_reply == NULL) {
    /* TODO i3ipc custom errors */
    g_free(atom_reply);
    tmp_error = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED, "socket path atom reply is null");
    g_propagate_error(err, tmp_error);
    return NULL;
  }

  prop_cookie = xcb_get_property_unchecked(conn,
      FALSE,                      /* _delete */
      root,                       /* window */
      atom_reply->atom,           /* property */
      XCB_GET_PROPERTY_TYPE_ANY,  /* type */
      0,                          /* long_offset */
      content_max_words           /* long_length */
      );

  prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);

  if (prop_reply == NULL) {
    /* TODO i3ipc custom errors */
    g_free(atom_reply);
    g_free(prop_reply);
    tmp_error = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED, "socket path property reply is null");
    g_propagate_error(err, tmp_error);
    return NULL;
  }

  int len = xcb_get_property_value_length(prop_reply);
  socket_path = malloc(len + 1);

  strncpy(socket_path, (char *)xcb_get_property_value(prop_reply), len);
  socket_path[len] = '\0';

  g_free(atom_reply);
  g_free(prop_reply);
  xcb_disconnect(conn);

  return socket_path;
}
Example #28
0
static xcb_window_t
recursive_Window_With_Name  (
    xcb_connection_t *dpy,
    xcb_window_t window,
    struct wininfo_cookies *cookies,
    const char *name)
{
    xcb_window_t *children;
    unsigned int nchildren;
    int i;
    xcb_window_t w = 0;
    xcb_generic_error_t *err;
    xcb_query_tree_reply_t *tree;
    struct wininfo_cookies *child_cookies;
    xcb_get_property_reply_t *prop;

    if (cookies->get_net_wm_name.sequence) {
	prop = xcb_get_property_reply (dpy, cookies->get_net_wm_name, &err);

	if (prop) {
	    if (prop->type == atom_utf8_string) {
		const char *prop_name = xcb_get_property_value (prop);
		int prop_name_len = xcb_get_property_value_length (prop);

		/* can't use strcmp, since prop.name is not null terminated */
		if (strncmp (prop_name, name, prop_name_len) == 0) {
		    w = window;
		}
	    }
	    free (prop);
	} else if (err) {
	    if (err->response_type == 0)
		Print_X_Error (dpy, err);
	    return 0;
	}
    }

    if (w) {
	xcb_discard_reply (dpy, cookies->get_wm_name.sequence);
    } else {
#ifdef USE_XCB_ICCCM
	xcb_get_text_property_reply_t nameprop;

	if (xcb_get_wm_name_reply (dpy, cookies->get_wm_name,
				   &nameprop, &err)) {
	    /* can't use strcmp, since nameprop.name is not null terminated */
	    if (strncmp (nameprop.name, name, nameprop.name_len) == 0) {
		w = window;
	    }

	    xcb_get_text_property_reply_wipe (&nameprop);
	}
#else
	prop = xcb_get_property_reply (dpy, cookies->get_wm_name, &err);

	if (prop) {
	    if (prop->type == XCB_ATOM_STRING) {
		const char *prop_name = xcb_get_property_value (prop);
		int prop_name_len = xcb_get_property_value_length (prop);

		/* can't use strcmp, since prop.name is not null terminated */
		if (strncmp (prop_name, name, prop_name_len) == 0) {
		    w = window;
		}
	    }
	    free (prop);
	}
#endif
	else if (err) {
	    if (err->response_type == 0)
		Print_X_Error (dpy, err);
	    return 0;
	}
    }

    if (w)
    {
	xcb_discard_reply (dpy, cookies->query_tree.sequence);
	return w;
    }

    tree = xcb_query_tree_reply (dpy, cookies->query_tree, &err);
    if (!tree) {
	if (err->response_type == 0)
	    Print_X_Error (dpy, err);
	return 0;
    }

    nchildren = xcb_query_tree_children_length (tree);
    children = xcb_query_tree_children (tree);
    child_cookies = calloc(nchildren, sizeof(struct wininfo_cookies));

    if (child_cookies == NULL)
	Fatal_Error("Failed to allocate memory in recursive_Window_With_Name");

    for (i = 0; i < nchildren; i++) {
	if (atom_net_wm_name && atom_utf8_string)
	    child_cookies[i].get_net_wm_name =
		xcb_get_net_wm_name (dpy, children[i]);
	child_cookies[i].get_wm_name = xcb_get_wm_name (dpy, children[i]);
	child_cookies[i].query_tree = xcb_query_tree (dpy, children[i]);
    }
    xcb_flush (dpy);

    for (i = 0; i < nchildren; i++) {
	w = recursive_Window_With_Name (dpy, children[i],
					&child_cookies[i], name);
	if (w)
	    break;
    }

    if (w)
    {
	/* clean up remaining replies */
	for (/* keep previous i */; i < nchildren; i++) {
	    if (child_cookies[i].get_net_wm_name.sequence)
		xcb_discard_reply (dpy,
				   child_cookies[i].get_net_wm_name.sequence);
	    xcb_discard_reply (dpy, child_cookies[i].get_wm_name.sequence);
	    xcb_discard_reply (dpy, child_cookies[i].query_tree.sequence);
	}
    }

    free (child_cookies);
    free (tree); /* includes storage for children[] */
    return (w);
}
Example #29
0
void init_tabletwm() {

	memset(&key_win, 0, sizeof(key_win));
	memset(&shutdown_win, 0, sizeof(shutdown_win));
	xcb_void_cookie_t void_cookie;
	xcb_intern_atom_cookie_t atom_cookie[TWM_ATOM_LAST_VALUE];
	uint32_t v[] = {XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_PROPERTY_CHANGE};
	int i;

	char *a_atoms[TWM_ATOM_LAST_VALUE] = {
		"WM_SIZE_HINTS",
		"WM_NORMAL_HINTS",
		"WM_PROTOCOLS",
		"WM_DELETE_WINDOW",
		"WM_TRANSIENT_FOR",
		"_NET_SUPPORTING_WM_CHECK",
		"_NET_WM_NAME",
		"_NET_SUPPORTED",

		"_NET_WM_WINDOW_TYPE",
		"_NET_WM_WINDOW_TYPE_DESKTOP",
		"_NET_WM_WINDOW_TYPE_DOCK",
		"_NET_WM_WINDOW_TYPE_TOOLBAR",
		"_NET_WM_WINDOW_TYPE_MENU",
		"_NET_WM_WINDOW_TYPE_UTILITY",
		"_NET_WM_WINDOW_TYPE_SPLASH",
		"_NET_WM_WINDOW_TYPE_DIALOG",
		"_NET_WM_WINDOW_TYPE_DROPDOWN_MENU",
		"_NET_WM_WINDOW_TYPE_POPUP_MENU",
		"_NET_WM_WINDOW_TYPE_TOOLTIP",
		"_NET_WM_WINDOW_TYPE_NOTIFICATION",
		"_NET_WM_WINDOW_TYPE_COMBO",
		"_NET_WM_WINDOW_TYPE_DND",
		"_NET_WM_WINDOW_TYPE_NORMAL",

		"_NET_WM_ALLOWED_ACTIONS",
		"_NET_WM_ACTION_MOVE",
		"_NET_WM_ACTION_RESIZE",
		"_NET_WM_ACTION_MINIMIZE",
		"_NET_WM_ACTION_SHADE",
		"_NET_WM_ACTION_STICK",
		"_NET_WM_ACTION_MAXIMIZE_HORZ",
		"_NET_WM_ACTION_MAXIMIZE_VERT",
		"_NET_WM_ACTION_FULLSCREEN",
		"_NET_WM_ACTION_CHANGE_DESKTOP",
		"_NET_WM_ACTION_CLOSE",
		"_NET_WM_ACTION_ABOVE",
		"_NET_WM_ACTION_BELOW",

		"WM_CLASS",
		"WM_STATE",
		"_NET_ACTIVE_WINDOW",
		"WM_HINTS",
		"_XKB_RULES_NAMES",
	};

	init_load_config();

	wincache_init();

	conn = xcb_connect(0, 0);
	assert(conn);

	scr = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
	width = scr->width_in_pixels;
	height = scr->height_in_pixels; // reserve the bottom part for the 1pixel-height, collapsed menu bar

	xcb_change_window_attributes(conn, scr->root, XCB_CW_EVENT_MASK, v);

	xcb_depth_iterator_t depth_iter;
	xcb_visualid_t root_visual = { 0 };
	visual_type = NULL;

	for (depth_iter = xcb_screen_allowed_depths_iterator (scr); depth_iter.rem; xcb_depth_next (&depth_iter)) {
		xcb_visualtype_iterator_t visual_iter;

		visual_iter = xcb_depth_visuals_iterator (depth_iter.data);
		for (; visual_iter.rem; xcb_visualtype_next (&visual_iter)) {
			if (scr->root_visual == visual_iter.data->visual_id) {
				visual_type = visual_iter.data;
				break;
			}
		}
	}

	/* get atoms */
	for(i=0; i < TWM_ATOM_LAST_VALUE; i++) {
		atom_cookie[i] = xcb_intern_atom_unchecked(conn, 0, strlen(a_atoms[i]), a_atoms[i]);
	};

	xcb_flush(conn);

	xcb_intern_atom_reply_t *atom_reply;
	for(i=0; i < TWM_ATOM_LAST_VALUE; i++) {
		atom_reply = xcb_intern_atom_reply(conn, atom_cookie[i], 0),
		atoms[i] = atom_reply->atom;
		free(atom_reply);
	};

	xcb_change_property(conn, XCB_PROP_MODE_REPLACE, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM_WM_DELETE_WINDOW]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_DESKTOP]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_DOCK]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_TOOLBAR]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_MENU]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED] , XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_UTILITY]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_SPLASH]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_DIALOG]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_DROPDOWN_MENU]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_POPUP_MENU]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_TOOLTIP]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_NOTIFICATION]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_COMBO]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_DND]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_WINDOW_TYPE_NORMAL]);

	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ALLOWED_ACTIONS]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_MOVE]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_RESIZE]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_MINIMIZE]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_SHADE]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_STICK]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_MAXIMIZE_HORZ]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_MAXIMIZE_VERT]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_FULLSCREEN]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_CHANGE_DESKTOP]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_CLOSE]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_ABOVE]);
	xcb_change_property(conn, XCB_PROP_MODE_APPEND, scr->root, atoms[TWM_ATOM__NET_SUPPORTED], XCB_ATOM_ATOM, 32, 1, &atoms[TWM_ATOM__NET_WM_ACTION_BELOW]);

	// This window contains the menu and the virtual keyboard (when showed)
	// It is also used to ensure that the window manager is recognized as an Extended Window Manager Hints WM
	// By default it occupies one pixel at the bottom of the screen, to allow to detect when the mouse is moved to the bottom

	xcb_get_property_cookie_t kbd_info_cookie;
	xcb_get_property_reply_t *kbd_info;
	kbd_info_cookie = xcb_get_property(conn, 0, scr->root, atoms[TWM__XKB_RULES_NAMES], XCB_ATOM_STRING, 0, 1024);

	key_win.window = xcb_generate_id(conn);
	uint32_t values[1] = {XCB_EVENT_MASK_EXPOSURE|XCB_EVENT_MASK_BUTTON_RELEASE|XCB_EVENT_MASK_BUTTON_PRESS|XCB_EVENT_MASK_ENTER_WINDOW|XCB_EVENT_MASK_LEAVE_WINDOW};
	void_cookie=xcb_create_window_checked (conn, XCB_COPY_FROM_PARENT, key_win.window, scr->root, 0, height-1, width, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual, XCB_CW_EVENT_MASK, values);

	xcb_flush(conn);

	kbd_info = xcb_get_property_reply(conn, kbd_info_cookie, 0);
	if (kbd_info!=NULL) {
		if (kbd_info->length>0) {
			char *p=((char *)(xcb_get_property_value(kbd_info)));
			int counter=0;
			int len, max;
			max=xcb_get_property_value_length(kbd_info);
			char *end=p+max;
			do {
				len = strnlen(p, max);
				if (*p!=0) {
					xkb_names[counter++] = strdup(p);
				}
				p+=len+1;
				max-=len+1;
			} while ((p < end) && (counter < 5));
		}
		free(kbd_info);
	}

	if (xcb_request_check(conn, void_cookie)) {
		printf("Can't create the fake window\n");
	} else {
		menuwin_init();
	}
	shutdown_init();
}
Example #30
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");
}