]> Dogcows Code - chaz/openbox/blobdiff - src/screen.cc
more user friendly net_showing_desktop support
[chaz/openbox] / src / screen.cc
index b556e7acdc3e02d4b1868d753f8c74180d9c3d56..3461178d6c3d80ac616af0778c63e3b6ff870da9 100644 (file)
@@ -44,6 +44,8 @@ Screen::Screen(int screen)
   assert(screen >= 0); assert(screen < ScreenCount(**otk::display));
   _info = otk::display->screenInfo(screen);
 
+  _showing_desktop = false;
+
   ::running = false;
   XErrorHandler old = XSetErrorHandler(::anotherWMRunning);
   XSelectInput(**otk::display, _info->rootWindow(),
@@ -397,13 +399,13 @@ void Screen::changeSupportedAtoms()
     otk::Property::atoms.net_client_list_stacking,
     otk::Property::atoms.net_desktop_names,
     otk::Property::atoms.net_close_window,
+    otk::Property::atoms.net_desktop_layout,
+    otk::Property::atoms.net_showing_desktop,
     otk::Property::atoms.net_wm_name,
     otk::Property::atoms.net_wm_visible_name,
     otk::Property::atoms.net_wm_icon_name,
     otk::Property::atoms.net_wm_visible_icon_name,
-/*
     otk::Property::atoms.net_wm_desktop,
-*/
     otk::Property::atoms.net_wm_strut,
     otk::Property::atoms.net_wm_window_type,
     otk::Property::atoms.net_wm_window_type_desktop,
@@ -745,9 +747,6 @@ void Screen::raiseWindow(Client *client)
   const ClientList::iterator end = _stacking.end();
 
   // the stacking list is from highest to lowest
-//  for (;it != end, ++it) {
-//    if ((*it)->layer() <= client->layer() && m != *it) break;
-//  }
   for (; it != end && ((*it)->layer() > client->layer() || m == *it); ++it);
 
   /*
@@ -881,6 +880,41 @@ void Screen::installColormap(bool install) const
     XUninstallColormap(**otk::display, _info->colormap());
 }
 
+void Screen::showDesktop(bool show)
+{
+  if (show == _showing_desktop) return; // no change
+
+  // save the window focus, and restore it when leaving the show-desktop mode
+  static Window saved_focus = 0;
+  if (show) {
+    Client *c = openbox->focusedClient();
+    if (c) saved_focus = c->window();
+  }
+  
+  _showing_desktop = show;
+
+  ClientList::iterator it, end = clients.end();
+  for (it = clients.begin(); it != end; ++it) {
+    if ((*it)->type() == Client::Type_Desktop) {
+      if (show)
+        (*it)->focus();
+    } else
+      (*it)->showhide();
+  }
+
+  if (!show) {
+    Client *f = openbox->focusedClient();
+    if (!f || f->type() == Client::Type_Desktop) {
+      Client *c = openbox->findClient(saved_focus);
+      if (c) c->focus();
+    }
+  }
+
+  otk::Property::set(_info->rootWindow(),
+                     otk::Property::atoms.net_showing_desktop,
+                     otk::Property::atoms.cardinal,
+                     show ? 1 : 0);
+}
 
 void Screen::propertyHandler(const XPropertyEvent &e)
 {
@@ -915,6 +949,8 @@ void Screen::clientMessageHandler(const XClientMessageEvent &e)
     changeDesktop(e.data.l[0]);
   } else if (e.message_type == otk::Property::atoms.net_number_of_desktops) {
     changeNumDesktops(e.data.l[0]);
+  } else if (e.message_type == otk::Property::atoms.net_showing_desktop) {
+    showDesktop(e.data.l[0] != 0);
   }
 }
 
@@ -932,8 +968,11 @@ void Screen::mapRequestHandler(const XMapRequestEvent &e)
 #ifdef DEBUG
     printf("DEBUG: MAP REQUEST CAUGHT IN SCREEN. IGNORED.\n");
 #endif
-  } else
+  } else {
+    if (_showing_desktop)
+      showDesktop(false); // leave showing-the-desktop mode
     manageWindow(e.window);
+  }
 }
 
 }
This page took 0.024739 seconds and 4 git commands to generate.