If you use _NET_WM_STATE http://standards.freedesktop.org/wm-spec/latest/ar01s05.html#id2569140 , then you set the property before matching the window, but after matching the window, you must send a client message and the window manager will update the property. Read the part of EWMH that launches "To change the state of the displayed window, the client MUST send the _NET_WM_STATE client message to the root window ..."
This is due to the fact that as soon as you type a window, the window manager is responsible for maintaining its state, there will be a race if both the application and WM can directly change the property.
See the source code for toolkits such as GTK +, for example, code.
source share