]> Dogcows Code - chaz/openbox/blobdiff - src/client.cc
add printf for when a window requests its desktop
[chaz/openbox] / src / client.cc
index 604a2e5d5309c55686fd14677e6f06990e4ea762..f0266bcee869b6c2fc8cfa470b3dd1f1caf70f3a 100644 (file)
@@ -8,6 +8,7 @@
 #include "frame.hh"
 #include "screen.hh"
 #include "openbox.hh"
+#include "bindings.hh"
 #include "otk/display.hh"
 #include "otk/property.hh"
 
@@ -37,15 +38,15 @@ Client::Client(int screen, Window window)
   // update EVERYTHING the first time!!
 
   // we default to NormalState, visible
-  _wmstate = NormalState; _iconic = false;
-  // no default decors or functions, each has to be enabled
-  _decorations = _functions = 0;
+  _wmstate = NormalState;
   // start unfocused
   _focused = false;
   // not a transient by default of course
   _transient_for = 0;
   // pick a layer to start from
   _layer = Layer_Normal;
+  // default to not urgent
+  _urgent = false;
   
   getArea();
   getDesktop();
@@ -54,8 +55,7 @@ Client::Client(int screen, Window window)
   getType();
   getMwmHints();
 
-  getState(); // gets all the states except for iconic, which is found from
-              // the desktop == ICONIC_DESKTOP
+  getState();
   getShaped();
 
   updateProtocols();
@@ -66,15 +66,23 @@ Client::Client(int screen, Window window)
   
   getGravity();        // get the attribute gravity
   updateNormalHints(); // this may override the attribute gravity
-  updateWMHints(true); // also get the initial_state and set _iconic
+  // also get the initial_state and set _iconic if we aren't "starting"
+  // when we're "starting" that means we should use whatever state was already
+  // on the window over the initial map state, because it was already mapped
+  updateWMHints(openbox->state() != Openbox::State_Starting);
   updateTitle();
   updateIconTitle();
   updateClass();
   updateStrut();
 
-  // restores iconic state when we restart.
-  // this will override the initial_state if that was set
-  if (_desktop == ICONIC_DESKTOP) _iconic = true;
+  // this makes sure that these windows appear on all desktops
+  if (_type == Type_Dock || _type == Type_Desktop)
+    _desktop = 0xffffffff;
+  
+  // set the desktop hint, to make sure that it always exists, and to reflect
+  // any changes we've made here
+  otk::Property::set(_window, otk::Property::atoms.net_wm_desktop,
+                     otk::Property::atoms.cardinal, (unsigned)_desktop);
   
   changeState();
 }
@@ -121,12 +129,12 @@ void Client::getDesktop()
   // defaults to the current desktop
   _desktop = openbox->screen(_screen)->desktop();
 
-  if (!otk::Property::get(_window, otk::Property::atoms.net_wm_desktop,
-                          otk::Property::atoms.cardinal,
-                          (long unsigned*)&_desktop)) {
-    // make sure the hint exists
-    otk::Property::set(_window, otk::Property::atoms.net_wm_desktop,
-                       otk::Property::atoms.cardinal, (unsigned)_desktop);
+  if (otk::Property::get(_window, otk::Property::atoms.net_wm_desktop,
+                         otk::Property::atoms.cardinal,
+                         (long unsigned*)&_desktop)) {
+#ifdef DEBUG
+    printf("DEBUG: Window requested desktop: %d\n", _desktop);
+#endif
   }
 }
 
@@ -299,7 +307,7 @@ void Client::getArea()
 void Client::getState()
 {
   _modal = _shaded = _max_horz = _max_vert = _fullscreen = _above = _below =
-    _skip_taskbar = _skip_pager = false;
+    _iconic = _skip_taskbar = _skip_pager = false;
   
   unsigned long *state;
   unsigned long num = (unsigned) -1;
@@ -311,6 +319,8 @@ void Client::getState()
         _modal = true;
       else if (state[i] == otk::Property::atoms.net_wm_state_shaded)
         _shaded = true;
+      else if (state[i] == otk::Property::atoms.net_wm_state_hidden)
+        _iconic = true;
       else if (state[i] == otk::Property::atoms.net_wm_state_skip_taskbar)
         _skip_taskbar = true;
       else if (state[i] == otk::Property::atoms.net_wm_state_skip_pager)
@@ -454,7 +464,7 @@ void Client::updateWMHints(bool initstate)
 
   // assume a window takes input if it doesnt specify
   _can_focus = true;
-  _urgent = false;
+  bool ur = false;
   
   if ((hints = XGetWMHints(**otk::display, _window)) != NULL) {
     if (hints->flags & InputHint)
@@ -465,7 +475,7 @@ void Client::updateWMHints(bool initstate)
       _iconic = hints->initial_state == IconicState;
 
     if (hints->flags & XUrgencyHint)
-      _urgent = true;
+      ur = true;
 
     if (hints->flags & WindowGroupHint) {
       if (hints->window_group != _group) {
@@ -478,6 +488,14 @@ void Client::updateWMHints(bool initstate)
 
     XFree(hints);
   }
+
+  if (ur != _urgent) {
+    _urgent = ur;
+    // fire the urgent callback if we're mapped, otherwise, wait until after
+    // we're mapped
+    if (_urgent && frame)
+      fireUrgent();
+  }
 }
 
 
@@ -668,9 +686,10 @@ void Client::setDesktop(long target)
   
   _desktop = target;
 
-  // set the desktop hint
-  otk::Property::set(_window, otk::Property::atoms.net_wm_desktop,
-                     otk::Property::atoms.cardinal, (unsigned)_desktop);
+  // set the desktop hint, but not if we're iconifying
+  if (_desktop != ICONIC_DESKTOP)
+    otk::Property::set(_window, otk::Property::atoms.net_wm_desktop,
+                       otk::Property::atoms.cardinal, (unsigned)_desktop);
   
   // 'move' the window to the new desktop
   if (_desktop == openbox->screen(_screen)->desktop() ||
@@ -1158,8 +1177,8 @@ void Client::applyStartupState()
   // these are in a carefully crafted order..
 
   if (_iconic) {
+    printf("MAP ICONIC\n");
     _iconic = false;
-    _desktop = 0;    // set some other source desktop so this goes through
     setDesktop(ICONIC_DESKTOP);
   }
   if (_fullscreen) {
@@ -1170,6 +1189,8 @@ void Client::applyStartupState()
     _shaded = false;
     shade(true);
   }
+  if (_urgent)
+    fireUrgent();
   
   if (_max_vert); // XXX: incomplete
   if (_max_horz); // XXX: incomplete
@@ -1182,6 +1203,14 @@ void Client::applyStartupState()
 }
 
 
+void Client::fireUrgent()
+{
+  // call the python UrgentNotify callbacks
+  EventData data(_screen, this, EventUrgentNotify, 0);
+  openbox->bindings()->fireEvent(&data);
+}
+
+
 void Client::shade(bool shade)
 {
   if (!(_functions & Func_Shade) || // can't
@@ -1244,7 +1273,7 @@ void Client::fullscreen(bool fs)
 }
 
 
-bool Client::focus() const
+bool Client::focus()
 {
   // won't try focus if the client doesn't want it, or if the window isn't
   // visible on the screen
@@ -1253,12 +1282,21 @@ bool Client::focus() const
   if (_focused) return true;
 
   // do a check to see if the window has already been unmapped or destroyed
+  // do this intelligently while watching out for unmaps we've generated
+  // (ignore_unmaps > 0)
   XEvent ev;
-  if (XCheckTypedWindowEvent(**otk::display, _window, UnmapNotify, &ev) ||
-      XCheckTypedWindowEvent(**otk::display, _window, DestroyNotify, &ev)) {
+  if (XCheckTypedWindowEvent(**otk::display, _window, DestroyNotify, &ev)) {
     XPutBackEvent(**otk::display, &ev);
     return false;
   }
+  while (XCheckTypedWindowEvent(**otk::display, _window, UnmapNotify, &ev)) {
+    if (ignore_unmaps) {
+      unmapHandler(ev.xunmap);
+    } else {
+      XPutBackEvent(**otk::display, &ev);
+      return false;
+    }
+  }
 
   if (_can_focus)
     XSetInputFocus(**otk::display, _window,
This page took 0.024891 seconds and 4 git commands to generate.