Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

c - X11: _NET_FRAME_EXTENTS window property. Not consistent return with XCB

The code in question is similar to this SO topic: Get X11 window caption height. The link points to answer with Xlib code. The idea is to get window properties, _NET_FRAME_EXTENTS namely. The code waits untill the window manager will set the decoration sizes. The code in the answer skips all events till the property returned.

Basically I do the same with XCB. I want to know the decoration sizes of a window that I had just created. The pseudocode what I do with XCB:

cookie = xcb_get_property(...)
reply  = xcb_get_property_reply(..., cookie, ...)
if(NULL == reply){
 /* fail */
}
if(reply->type != type){
 /* fail */
}
prop_size  = xcb_get_property_value_length(reply);
prop_val   = xcb_get_property_value       (reply);
if(0 == prop_size){
 /* fail */
}

if(/* not failed */){
     copy returned data here
     print and return success.
}
if(/* failed */)
     then wait for events and skip them

repeat the above untill success

The problem is that sometimes values being returned as zeros, and sometimes the values are correct. As you can see from above code, the success condition is only when the type match and there is some data that are read. The request is checked with cookie so, as I understand, the reply belongs to the request. I do map the window and flush events before I call the above code.

The question is, how to get WM decorations properly with XCB?

question from:https://stackoverflow.com/questions/65540910/x11-net-frame-extents-window-property-not-consistent-return-with-xcb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I got tied to the linked SO topic. The answer in the topic do the right thing and gives a great insight but fails to execute it properly.

The solution is to wait for XCB_PROPERTY_NOTIFY event and compare the recieved atom with a _NET_FRAME_EXTENTS atom. If all checks went good, then WM has set the _NET_FRAME_EXTENTS property. Not earlier than that specific event is recieved, there is a sense to get values of the property. That is why I got zeroes in some invocations of the application. My original solution may get the property value earlier before WM sets the property.

Some pseudocode:

loop:
 ev = xcb_wait_for_event(...);

 ...error checks...

 if((ev->response_type & ~0x80) == XCB_PROPERTY_NOTIFY){
  xcb_property_notify_event_t *pe = (xcb_property_notify_event_t*)ev;
  if(pe->atom == {_NET_FRAME_EXTENTS atom}){
   ...get the _NET_FRAME_EXTENTS property...
  }
 }
 ...
 loop end;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...