]> Dogcows Code - chaz/openbox/blobdiff - src/client.cc
centered gravities lose one borderwidth when mapping too
[chaz/openbox] / src / client.cc
index df136bf29a586cf5a3b611f051ac335e58980bc9..d005a0bdaad5acf032c5c04ea9bec24170bfa427 100644 (file)
@@ -47,6 +47,7 @@ Client::Client(int screen, Window window)
   // pick a layer to start from
   _layer = Layer_Normal;
   
+  getGravity();
   getArea();
   getDesktop();
 
@@ -60,7 +61,6 @@ Client::Client(int screen, Window window)
   getShaped();
 
   updateProtocols();
-  updateNormalHints();
   updateWMHints();
   updateTitle();
   updateIconTitle();
@@ -91,6 +91,26 @@ Client::~Client()
 }
 
 
+void Client::getGravity()
+{
+  XSizeHints size;
+  XWindowAttributes wattrib;
+  Status ret;
+  long junk;
+
+  if (XGetWMNormalHints(**otk::display, _window, &size, &junk) &&
+      size.flags & PWinGravity) {
+    // first try the normal hints
+    _gravity = size.win_gravity;
+  } else {
+    // then fall back to the attribute
+    ret = XGetWindowAttributes(**otk::display, _window, &wattrib);
+    assert(ret != BadWindow);
+    _gravity = wattrib.win_gravity;
+  }
+}
+
+
 void Client::getDesktop()
 {
   // defaults to the current desktop
@@ -378,7 +398,6 @@ void Client::updateNormalHints()
   int oldgravity = _gravity;
 
   // defaults
-  _gravity = NorthWestGravity;
   _size_inc.setPoint(1, 1);
   _base_size.setPoint(0, 0);
   _min_size.setPoint(0, 0);
@@ -391,8 +410,18 @@ void Client::updateNormalHints()
   if (XGetWMNormalHints(**otk::display, _window, &size, &ret)) {
     _positioned = (size.flags & (PPosition|USPosition));
 
-    if (size.flags & PWinGravity)
+    if (size.flags & PWinGravity) {
       _gravity = size.win_gravity;
+      
+      // if the client has a frame, i.e. has already been mapped and is
+      // changing its gravity
+      if (_gravity != oldgravity) {
+        // move our idea of the client's position based on its new gravity
+        int x, y;
+        frame->frameGravity(x, y);
+        _area.setPos(x, y);
+      }
+    }
 
     if (size.flags & PMinSize)
       _min_size.setPoint(size.min_width, size.min_height);
@@ -406,15 +435,6 @@ void Client::updateNormalHints()
     if (size.flags & PResizeInc)
       _size_inc.setPoint(size.width_inc, size.height_inc);
   }
-
-  // if the client has a frame, i.e. has already been mapped and is
-  // changing its gravity
-  if (frame && _gravity != oldgravity) {
-    // move our idea of the client's position based on its new gravity
-    int x, y;
-    frame->frameGravity(x, y);
-    _area.setPos(x, y);
-  }
 }
 
 
@@ -760,9 +780,6 @@ void Client::toggleClientBorder(bool addborder)
   case NorthWestGravity:
   case WestGravity:
   case SouthWestGravity:
-  case NorthGravity:
-  case CenterGravity:
-  case SouthGravity:
     break;
   case NorthEastGravity:
   case EastGravity:
@@ -770,6 +787,9 @@ void Client::toggleClientBorder(bool addborder)
     if (addborder) x -= _border_width * 2;
     else           x += _border_width * 2;
     break;
+  case NorthGravity:
+  case SouthGravity:
+  case CenterGravity:
   case ForgetGravity:
   case StaticGravity:
     if (addborder) x -= _border_width;
@@ -779,11 +799,8 @@ void Client::toggleClientBorder(bool addborder)
   switch(_gravity) {
   default:
   case NorthWestGravity:
-  case WestGravity:
   case NorthGravity:
-  case CenterGravity:
   case NorthEastGravity:
-  case EastGravity:
     break;
   case SouthWestGravity:
   case SouthGravity:
@@ -791,6 +808,9 @@ void Client::toggleClientBorder(bool addborder)
     if (addborder) y -= _border_width * 2;
     else           y += _border_width * 2;
     break;
+  case WestGravity:
+  case EastGravity:
+  case CenterGravity:
   case ForgetGravity:
   case StaticGravity:
     if (addborder) y -= _border_width;
This page took 0.022205 seconds and 4 git commands to generate.