]> Dogcows Code - chaz/openbox/blobdiff - src/client.cc
add new actions from the ewmh spec
[chaz/openbox] / src / client.cc
index 603a08bdecc43276e6697ff2548e9fe7338c095b..e8a6b84bd14028f96b0e7e08147a09c454a7b9e3 100644 (file)
@@ -47,7 +47,6 @@ Client::Client(int screen, Window window)
   // pick a layer to start from
   _layer = Layer_Normal;
   
-  getGravity();
   getArea();
   getDesktop();
 
@@ -61,6 +60,8 @@ Client::Client(int screen, Window window)
   getShaped();
 
   updateProtocols();
+  getGravity(); // get the attribute gravity
+  updateNormalHints(); // this may override the attribute gravity
   updateWMHints();
   updateTitle();
   updateIconTitle();
@@ -93,21 +94,12 @@ 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;
-  }
+
+  ret = XGetWindowAttributes(**otk::display, _window, &wattrib);
+  assert(ret != BadWindow);
+  _gravity = wattrib.win_gravity;
 }
 
 
@@ -242,7 +234,7 @@ void Client::setupDecorAndFunctions()
     }
   }
 
-  // XXX: changeAllowedActions();
+  changeAllowedActions();
 }
 
 
@@ -415,7 +407,7 @@ void Client::updateNormalHints()
       
       // if the client has a frame, i.e. has already been mapped and is
       // changing its gravity
-      if (_gravity != oldgravity) {
+      if (frame && _gravity != oldgravity) {
         // move our idea of the client's position based on its new gravity
         int x, y;
         frame->frameGravity(x, y);
@@ -780,9 +772,6 @@ void Client::toggleClientBorder(bool addborder)
   case NorthWestGravity:
   case WestGravity:
   case SouthWestGravity:
-  case NorthGravity:
-  case CenterGravity:
-  case SouthGravity:
     break;
   case NorthEastGravity:
   case EastGravity:
@@ -790,6 +779,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;
@@ -799,11 +791,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:
@@ -811,6 +800,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;
@@ -909,7 +901,14 @@ void Client::shapeHandler(const XShapeEvent &e)
 #endif
 
 
-void Client::resize(Corner anchor, int w, int h, int x, int y)
+void Client::resize(Corner anchor, int w, int h)
+{
+  if (!(_functions & Func_Resize)) return;
+  internal_resize(anchor, w, h);
+}
+
+
+void Client::internal_resize(Corner anchor, int w, int h, int x, int y)
 {
   w -= _base_size.x(); 
   h -= _base_size.y();
@@ -971,11 +970,18 @@ void Client::resize(Corner anchor, int w, int h, int x, int y)
 
   // resize the frame to match the request
   frame->adjustSize();
-  move(x, y);
+  internal_move(x, y);
 }
 
 
 void Client::move(int x, int y)
+{
+  if (!(_functions & Func_Move)) return;
+  internal_move(x, y);
+}
+
+
+void Client::internal_move(int x, int y)
 {
   _area.setPos(x, y);
 
@@ -1066,6 +1072,30 @@ void Client::changeState()
 }
 
 
+void Client::changeAllowedActions(void)
+{
+  Atom actions[7];
+  int num = 0;
+
+  actions[num++] = otk::Property::atoms.net_wm_action_shade;
+  actions[num++] = otk::Property::atoms.net_wm_action_change_desktop;
+
+  if (_functions & Func_Close)
+    actions[num++] = otk::Property::atoms.net_wm_action_close;
+  if (_functions & Func_Move)
+        actions[num++] = otk::Property::atoms.net_wm_action_move;
+  if (_functions & Func_Resize)
+        actions[num++] = otk::Property::atoms.net_wm_action_resize;
+  if (_functions & Func_Maximize) {
+    actions[num++] = otk::Property::atoms.net_wm_action_maximize_horz;
+    actions[num++] = otk::Property::atoms.net_wm_action_maximize_vert;
+  }
+
+  otk::Property::set(_window, otk::Property::atoms.net_wm_allowed_actions,
+                     otk::Property::atoms.atom, actions, num);
+}
+
+
 void Client::shade(bool shade)
 {
   if (shade == _shaded) return; // already done
@@ -1187,13 +1217,13 @@ void Client::configureRequestHandler(const XConfigureRequestEvent &e)
     if (e.value_mask & (CWX | CWY)) {
       int x = (e.value_mask & CWX) ? e.x : _area.x();
       int y = (e.value_mask & CWY) ? e.y : _area.y();
-      resize(corner, w, h, x, y);
+      internal_resize(corner, w, h, x, y);
     } else // if JUST resizing...
-      resize(corner, w, h);
+      internal_resize(corner, w, h);
   } else if (e.value_mask & (CWX | CWY)) { // if JUST moving...
     int x = (e.value_mask & CWX) ? e.x : _area.x();
     int y = (e.value_mask & CWY) ? e.y : _area.y();
-    move(x, y);
+    internal_move(x, y);
   }
 
   if (e.value_mask & CWStackMode) {
This page took 0.024068 seconds and 4 git commands to generate.