+ } else if (e->xclient.message_type ==
+ xatom->getAtom(XAtom::net_number_of_desktops)) {
+ // NET_NUMBER_OF_DESKTOPS
+ BScreen *screen = searchScreen(e->xclient.window);
+
+ if (e->xclient.data.l[0] > 0) {
+ if ((unsigned) e->xclient.data.l[0] < screen->getWorkspaceCount()) {
+ // shrink
+ for (int i = screen->getWorkspaceCount();
+ i > e->xclient.data.l[0]; --i)
+ screen->removeLastWorkspace();
+ // removeLast already sets the current workspace to the
+ // last available one.
+ } else if ((unsigned) e->xclient.data.l[0] >
+ screen->getWorkspaceCount()) {
+ // grow
+ for(int i = screen->getWorkspaceCount();
+ i < e->xclient.data.l[0]; ++i)
+ screen->addWorkspace();
+ }
+ }
+ } else if (e->xclient.message_type ==
+ xatom->getAtom(XAtom::net_close_window)) {
+ // NET_CLOSE_WINDOW
+ BlackboxWindow *win = searchWindow(e->xclient.window);
+ if (win && win->validateClient())
+ win->close(); // could this be smarter?
+ } else if (e->xclient.message_type ==
+ xatom->getAtom(XAtom::net_wm_moveresize)) {
+ // NET_WM_MOVERESIZE
+ BlackboxWindow *win = searchWindow(e->xclient.window);
+ if (win && win->validateClient()) {
+ int x_root = e->xclient.data.l[0],
+ y_root = e->xclient.data.l[1];
+ if ((Atom) e->xclient.data.l[2] ==
+ xatom->getAtom(XAtom::net_wm_moveresize_move)) {
+ win->beginMove(x_root, y_root);
+ } else {
+ if ((Atom) e->xclient.data.l[2] ==
+ xatom->getAtom(XAtom::net_wm_moveresize_size_topleft))
+ win->beginResize(x_root, y_root, BlackboxWindow::TopLeft);
+ else if ((Atom) e->xclient.data.l[2] ==
+ xatom->getAtom(XAtom::net_wm_moveresize_size_topright))
+ win->beginResize(x_root, y_root, BlackboxWindow::TopRight);
+ else if ((Atom) e->xclient.data.l[2] ==
+ xatom->getAtom(XAtom::net_wm_moveresize_size_bottomleft))
+ win->beginResize(x_root, y_root, BlackboxWindow::BottomLeft);
+ else if ((Atom) e->xclient.data.l[2] ==
+ xatom->getAtom(XAtom::net_wm_moveresize_size_bottomright))
+ win->beginResize(x_root, y_root, BlackboxWindow::BottomRight);
+ }
+ }
+ } else if (e->xclient.message_type ==
+ xatom->getAtom(XAtom::net_wm_state)) {
+ // NET_WM_STATE
+ BlackboxWindow *win = searchWindow(e->xclient.window);
+ if (win && win->validateClient()) {
+ const Atom action = (Atom) e->xclient.data.l[0];
+ const Atom state[] = { (Atom) e->xclient.data.l[1],
+ (Atom) e->xclient.data.l[2] };
+
+ for (int i = 0; i < 2; ++i) {
+ if (! state[i])
+ continue;
+
+ if ((Atom) e->xclient.data.l[0] == 1) {
+ // ADD
+ if (state[i] == xatom->getAtom(XAtom::net_wm_state_modal)) {
+ win->setModal(True);
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_maximized_vert)) {
+ if (win->isMaximizedHoriz()) {
+ win->maximize(0); // unmaximize
+ win->maximize(1); // full
+ } else if (! win->isMaximized()) {
+ win->maximize(2); // vert
+ }
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_maximized_horz)) {
+ if (win->isMaximizedVert()) {
+ win->maximize(0); // unmaximize
+ win->maximize(1); // full
+ } else if (! win->isMaximized()) {
+ win->maximize(3); // horiz
+ }
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_shaded)) {
+ if (! win->isShaded())
+ win->shade();
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_skip_taskbar)) {
+ win->setSkipTaskbar(True);
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_skip_pager)) {
+ win->setSkipPager(True);
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_fullscreen)) {
+ win->setFullscreen(True);
+ }
+ } else if (action == 0) {
+ // REMOVE
+ if (state[i] == xatom->getAtom(XAtom::net_wm_state_modal)) {
+ win->setModal(False);
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_maximized_vert)) {
+ if (win->isMaximizedFull()) {
+ win->maximize(0); // unmaximize
+ win->maximize(3); // horiz
+ } else if (win->isMaximizedVert()) {
+ win->maximize(0); // unmaximize
+ }
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_maximized_horz)) {
+ if (win->isMaximizedFull()) {
+ win->maximize(0); // unmaximize
+ win->maximize(2); // vert
+ } else if (win->isMaximizedHoriz()) {
+ win->maximize(0); // unmaximize
+ }
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_shaded)) {
+ if (win->isShaded())
+ win->shade();
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_skip_taskbar)) {
+ win->setSkipTaskbar(False);
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_skip_pager)) {
+ win->setSkipPager(False);
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_fullscreen)) {
+ win->setFullscreen(False);
+ }
+ } else if (action == 2) {
+ // TOGGLE
+ if (state[i] == xatom->getAtom(XAtom::net_wm_state_modal)) {
+ win->setModal(! win->isModal());
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_maximized_vert)) {
+ if (win->isMaximizedFull()) {
+ win->maximize(0); // unmaximize
+ win->maximize(3); // horiz
+ } else if (win->isMaximizedVert()) {
+ win->maximize(0); // unmaximize
+ } else if (win->isMaximizedHoriz()) {
+ win->maximize(0); // unmaximize
+ win->maximize(1); // full
+ } else {
+ win->maximize(2); // vert
+ }
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_maximized_horz)) {
+ if (win->isMaximizedFull()) {
+ win->maximize(0); // unmaximize
+ win->maximize(2); // vert
+ } else if (win->isMaximizedHoriz()) {
+ win->maximize(0); // unmaximize
+ } else if (win->isMaximizedVert()) {
+ win->maximize(0); // unmaximize
+ win->maximize(1); // full
+ } else {
+ win->maximize(3); // horiz
+ }
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_shaded)) {
+ win->shade();
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_skip_taskbar)) {
+ win->setSkipTaskbar(! win->skipTaskbar());
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_skip_pager)) {
+ win->setSkipPager(! win->skipPager());
+ } else if (state[i] ==
+ xatom->getAtom(XAtom::net_wm_state_fullscreen)) {
+ win->setFullscreen(! win->isFullscreen());
+ }
+ }
+ }
+ }