+static void SetNETWMState(X11Window windowHandle, bool throughRoot, NETWMStateAction action, Atom atom1, Atom atom2)
+{
+ if(atomsSupported[_net_wm_state])
+ {
+ int format;
+ unsigned long count, fill;
+ Atom type;
+ char * data = null;
+ uint state = WithdrawnState;
+
+ /*if(XGetWindowProperty(xGlobalDisplay, windowHandle, atoms[wm_state], 0, 3, False,
+ atoms[wm_state], &type, &format, &count, &fill, &data) == Success && count)
+ {
+ state = *(uint *)data;
+ XFree(data);
+ } */
+ if(!throughRoot) //state == WithdrawnState)
+ {
+ // We need to handle modifying these ourselves for withdrawn windows...
+ if(action == add)
+ {
+ Atom values[2] = { atom1, atom2 };
+ XChangeProperty(xGlobalDisplay, windowHandle, atoms[_net_wm_state], XA_ATOM,
+ 32, PropModeAppend, (byte *)values, atom2 ? 2 : 1);
+ }
+ else if(XGetWindowProperty(xGlobalDisplay, windowHandle, atoms[_net_wm_state], 0, 32, False,
+ XA_ATOM, &type, &format, &count, &fill, &data) == Success)
+ {
+ Atom * values = (Atom *) data;
+ int i;
+ for (i = 0; i < count; i++)
+ {
+ if(values[i] == atom1 || (atom2 && values[i] == atom2))
+ {
+ if(i < count - 1)
+ memmove(values + i, values + i + 1, sizeof(Atom) * (count - i - 1));
+ count--;
+ i--;
+ }
+ }
+ XChangeProperty(xGlobalDisplay, windowHandle, atoms[_net_wm_state], XA_ATOM, 32, PropModeReplace, (byte *)values, (int)count);
+ XFree(data);
+ }
+ }
+ else
+ {
+ XClientMessageEvent event = { 0 };
+ event.type = ClientMessage;
+ event.message_type = atoms[_net_wm_state];
+ event.display = xGlobalDisplay;
+ event.serial = 0;
+ event.window = windowHandle;
+ event.send_event = 1;
+ event.format = 32;
+ event.data.l[0] = action;
+ event.data.l[1] = atom1;
+ event.data.l[2] = atom2;
+ XSendEvent(xGlobalDisplay, DefaultRootWindow(xGlobalDisplay), bool::false,
+ SubstructureRedirectMask | SubstructureNotifyMask, (union _XEvent *)&event);
+ }
+ }
+
+}
+