[Xcb] XGetIconSizes()

Russell Shaw rjshaw at netspace.net.au
Sun May 17 20:14:19 PDT 2009


Russell Shaw wrote:
> Russell Shaw wrote:
>> Hi,
>> What's the XCB replacement for XGetIconSizes() ?
> 
> Looks like there isn't one. XGetIconSizes() returns a list
> of "XIconSize" structs. I couldn't figure out how to return
> a list, so i'm just using the first one:
...

I can return an array of size-hints now. Guess no-one is using xcb
if basic stuff like this is missing.


//XGetIconSizes in GetHints.c
//xcb_wm_hints_t
/**
  * @brief Size hints structure.
  */
typedef struct {
   /** WM-specified minimum icon size */
   uint32_t min_width, min_height;
   /** WM-specified maximum icon size */
   uint32_t max_width, max_height;
   /** WM-specified resize increments */
   int32_t width_inc, height_inc;
} xcb_wm_icon_size_hints_hints_t;

/** Number of elements in this structure */
#define XCB_NUM_WM_ICON_SIZE_HINTS_ELEMENTS 6

//xcb_get_wm_hints
xcb_get_property_cookie_t
xcb_get_wm_icon_size_hints(xcb_connection_t *c, xcb_window_t window)
{
   //return xcb_get_property(c, 0, window, WM_ICON_SIZE, WM_ICON_SIZE, 0L, 
XCB_NUM_WM_ICON_SIZE_HINTS_ELEMENTS);	// 60L in Xlib
   return xcb_get_property(c, 0, window, WM_ICON_SIZE, WM_ICON_SIZE, 0L, 60L); 
//  60L in Xlib
}

//xcb_get_wm_hints_unchecked
xcb_get_property_cookie_t
xcb_get_wm_icon_size_hints_unchecked(xcb_connection_t *c, xcb_window_t window)
{
   //return xcb_get_property_unchecked(c, 0, window, WM_ICON_SIZE, WM_ICON_SIZE, 
0L, XCB_NUM_WM_ICON_SIZE_HINTS_ELEMENTS);	// 60L in Xlib
   return xcb_get_property_unchecked(c, 0, window, WM_ICON_SIZE, WM_ICON_SIZE, 
0L, 60L);	    // 60L in Xlib
}

//xcb_get_wm_hints_from_reply
uint8_t
xcb_get_wm_icon_size_hints_from_reply(xcb_wm_icon_size_hints_hints_t 
**size_list, int *count,
                             xcb_get_property_reply_t *reply)
{
   if(!reply)
     return 0;

   unsigned long nitems = xcb_get_property_value_length(reply);

   if ((reply->type != WM_ICON_SIZE) ||
       (nitems < (XCB_NUM_WM_ICON_SIZE_HINTS_ELEMENTS)) ||
       (nitems % (XCB_NUM_WM_ICON_SIZE_HINTS_ELEMENTS) != 0) ||
       (reply->format != 32))
     return 0;

   unsigned long bytes = nitems * reply->format >> 3;

   xcb_wm_icon_size_hints_hints_t *hints = malloc(bytes);

   if (!hints) {
     return 0;
   }

   memcpy(hints, xcb_get_property_value(reply), bytes);

   *count = nitems/XCB_NUM_WM_ICON_SIZE_HINTS_ELEMENTS;
   *size_list = hints;

   return 1;
}

//xcb_get_wm_hints_reply
uint8_t
xcb_get_wm_icon_size_hints_reply(xcb_connection_t *c,
                        xcb_get_property_cookie_t cookie,
		       xcb_wm_icon_size_hints_hints_t **size_list, int *count,
                        xcb_generic_error_t **e)
{
   xcb_get_property_reply_t *reply = xcb_get_property_reply(c, cookie, e);
   int ret = xcb_get_wm_icon_size_hints_from_reply(size_list, count, reply);
   free(reply);
   return ret;
}


More information about the Xcb mailing list