]> Dogcows Code - chaz/openbox/blobdiff - src/Window.cc
sync with the 2.0 branch
[chaz/openbox] / src / Window.cc
index 08cad56db8c7ca10b87810353d07f203a9fdf51b..72643c2de73d4bddf8faa6cc9a28d36e67d913bb 100644 (file)
@@ -128,7 +128,8 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
 
   frame.border_w = 1;
   frame.window = frame.plate = frame.title = frame.handle = None;
-  frame.close_button = frame.iconify_button = frame.maximize_button = None;
+  frame.close_button = frame.iconify_button = frame.maximize_button =
+    frame.stick_button = None;
   frame.right_grip = frame.left_grip = None;
 
   frame.ulabel_pixel = frame.flabel_pixel = frame.utitle_pixel =
@@ -719,6 +720,9 @@ void BlackboxWindow::destroyTitlebar(void) {
   if (frame.maximize_button)
     destroyMaximizeButton();
 
+  if (frame.stick_button)
+    destroyStickyButton();
+  
   if (frame.ftitle)
     screen->getImageControl()->removeImage(frame.ftitle);
 
@@ -802,13 +806,28 @@ void BlackboxWindow::destroyMaximizeButton(void) {
   frame.maximize_button = None;
 }
 
+void BlackboxWindow::createStickyButton(void) {
+  if (frame.title != None) {
+    frame.stick_button = createChildWindow(frame.title,
+                                           ButtonPressMask |
+                                           ButtonReleaseMask |
+                                           ButtonMotionMask | ExposureMask);
+    blackbox->saveWindowSearch(frame.stick_button, this);
+  }
+}
+
+void BlackboxWindow::destroyStickyButton(void) {
+  blackbox->removeWindowSearch(frame.stick_button);
+  XDestroyWindow(blackbox->getXDisplay(), frame.stick_button);
+  frame.stick_button = None;
+}
 
 void BlackboxWindow::positionButtons(bool redecorate_label) {
   string layout = blackbox->getTitlebarLayout();
   string parsed;
 
-  bool hasclose, hasiconify, hasmaximize, haslabel;
-  hasclose = hasiconify = hasmaximize = haslabel = false;
+  bool hasclose, hasiconify, hasmaximize, haslabel, hasstick;
+  hasclose = hasiconify = hasmaximize = haslabel = hasstick = false;
 
   string::const_iterator it, end;
   for (it = layout.begin(), end = layout.end(); it != end; ++it) {
@@ -825,6 +844,12 @@ void BlackboxWindow::positionButtons(bool redecorate_label) {
         parsed += *it;
       }
       break;
+    case 'S':
+      if (!hasstick) {
+        hasstick = true;
+        parsed += *it;
+      }
+      break;
     case 'M':
       if (! hasmaximize && (decorations & Decor_Maximize)) {
         hasmaximize = true;
@@ -836,14 +861,18 @@ void BlackboxWindow::positionButtons(bool redecorate_label) {
         haslabel = true;
         parsed += *it;
       }
+      break;
     }
   }
+  
   if (! hasclose && frame.close_button)
     destroyCloseButton();
   if (! hasiconify && frame.iconify_button)
     destroyIconifyButton();
   if (! hasmaximize && frame.maximize_button)
     destroyMaximizeButton();
+  if (! hasstick && frame.stick_button)
+    destroyStickyButton();
   if (! haslabel)
     parsed += 'L';      // require that the label be in the layout
 
@@ -869,6 +898,12 @@ void BlackboxWindow::positionButtons(bool redecorate_label) {
                         frame.button_w, frame.button_w);
       x += frame.button_w + bsep;
       break;
+    case 'S':
+      if (! frame.stick_button) createStickyButton();
+      XMoveResizeWindow(blackbox->getXDisplay(), frame.stick_button, x, by,
+                        frame.button_w, frame.button_w);
+      x += frame.button_w + bsep;
+      break;
     case 'M':
       if (! frame.maximize_button) createMaximizeButton();
       XMoveResizeWindow(blackbox->getXDisplay(), frame.maximize_button, x, by,
@@ -1090,7 +1125,6 @@ void BlackboxWindow::getWMName(void) {
   xatom->setValue(client.window, XAtom::net_wm_visible_name, XAtom::utf8,
                   client.title);
 
-#define DEBUG_WITH_ID 1
 #ifdef DEBUG_WITH_ID
   // the 16 is the 8 chars of the debug text plus the number
   char *tmp = new char[client.title.length() + 16];
@@ -1218,10 +1252,12 @@ void BlackboxWindow::getWMNormalHints(void) {
     client.max_aspect_x = client.max_aspect_y = 1;
 #endif
 
-  // set no limit to how big a window can be by default
+  // don't limit the size of a window, the default max width is the biggest
+  // possible
   client.max_width = (unsigned) -1;
   client.max_height = (unsigned) -1;
 
+
   if (! XGetWMNormalHints(blackbox->getXDisplay(), client.window,
                           &sizehint, &icccm_mask))
     return;
@@ -1629,6 +1665,14 @@ void BlackboxWindow::configureShape(void) {
                           ShapeBounding, 0, 0, xrect, num,
                           ShapeUnion, Unsorted);
 }
+
+
+void BlackboxWindow::clearShape(void) {
+  XShapeCombineMask(blackbox->getXDisplay(), frame.window, ShapeBounding,
+                    frame.margin.left - frame.border_w,
+                    frame.margin.top - frame.border_w,
+                    None, ShapeSet);
+}
 #endif // SHAPE
 
 
@@ -2067,6 +2111,9 @@ void BlackboxWindow::stick(void) {
 
     setState(current_state);
   }
+
+  redrawAllButtons();
+  
   // go up the chain
   if (isTransient() && client.transient_for != (BlackboxWindow *) ~0ul &&
       client.transient_for->isStuck() != flags.stuck)
@@ -2532,6 +2579,7 @@ void BlackboxWindow::redrawAllButtons(void) const {
   if (frame.iconify_button) redrawIconifyButton(False);
   if (frame.maximize_button) redrawMaximizeButton(flags.maximized);
   if (frame.close_button) redrawCloseButton(False);
+  if (frame.stick_button) redrawStickyButton(flags.stuck);
 }
 
 
@@ -2633,7 +2681,7 @@ void BlackboxWindow::redrawCloseButton(bool pressed) const {
   XClearWindow(blackbox->getXDisplay(), frame.close_button);
 
   BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
-           screen->getWindowStyle()->b_pic_unfocus);
+           screen->getWindowStyle()->b_pic_unfocus, 0, 2);
   XDrawLine(blackbox->getXDisplay(), frame.close_button, pen.gc(),
             2, 2, (frame.button_w - 3), (frame.button_w - 3));
   XDrawLine(blackbox->getXDisplay(), frame.close_button, pen.gc(),
@@ -2641,6 +2689,40 @@ void BlackboxWindow::redrawCloseButton(bool pressed) const {
 }
 
 
+void BlackboxWindow::redrawStickyButton(bool pressed) const {
+  if (! pressed) {
+    if (flags.focused) {
+      if (frame.fbutton)
+        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
+                                   frame.stick_button, frame.fbutton);
+      else
+        XSetWindowBackground(blackbox->getXDisplay(), frame.stick_button,
+                             frame.fbutton_pixel);
+    } else {
+      if (frame.ubutton)
+        XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
+                                   frame.stick_button, frame.ubutton);
+      else
+        XSetWindowBackground(blackbox->getXDisplay(), frame.stick_button,
+                             frame.ubutton_pixel);
+    }
+  } else {
+    if (frame.pbutton)
+      XSetWindowBackgroundPixmap(blackbox->getXDisplay(),
+                                 frame.stick_button, frame.pbutton);
+    else
+      XSetWindowBackground(blackbox->getXDisplay(), frame.stick_button,
+                           frame.pbutton_pixel);
+  }
+  XClearWindow(blackbox->getXDisplay(), frame.stick_button);
+
+  BPen pen((flags.focused) ? screen->getWindowStyle()->b_pic_focus :
+           screen->getWindowStyle()->b_pic_unfocus);
+  
+  XFillRectangle(blackbox->getXDisplay(), frame.stick_button, pen.gc(),
+                 frame.button_w/2 - 1, frame.button_w/2 -1, 2, 2 );
+}
+
 void BlackboxWindow::mapRequestEvent(const XMapRequestEvent *re) {
   if (re->window != client.window)
     return;
@@ -2855,6 +2937,8 @@ void BlackboxWindow::exposeEvent(const XExposeEvent *ee) {
     redrawMaximizeButton(flags.maximized);
   else if (frame.iconify_button == ee->window)
     redrawIconifyButton(False);
+  else if (frame.stick_button == ee->window)
+    redrawStickyButton(flags.stuck);
 }
 
 
@@ -2887,10 +2971,10 @@ void BlackboxWindow::configureRequestEvent(const XConfigureRequestEvent *cr) {
                                  frame.margin.top + frame.margin.bottom);
 
       /*
-        if a position change ha been specified, then that position will be used
-        instead of determining a position based on the window's gravity.
+        if a position change has been specified, then that position will be
+        used instead of determining a position based on the window's gravity.
       */
-      if (cr->value_mask & (CWX | CWY)) {
+      if (! (cr->value_mask & (CWX | CWY))) {
         Corner corner;
         switch (client.win_gravity) {
         case NorthEastGravity:
@@ -2948,6 +3032,8 @@ void BlackboxWindow::buttonPressEvent(const XButtonEvent *be) {
       redrawIconifyButton(True);
     } else if (frame.close_button == be->window) {
       redrawCloseButton(True);
+    } else if (frame.stick_button == be->window) {
+      redrawStickyButton(True);
     } else if (frame.plate == be->window) {
       if (windowmenu && windowmenu->isVisible()) windowmenu->hide();
 
@@ -2971,7 +3057,8 @@ void BlackboxWindow::buttonPressEvent(const XButtonEvent *be) {
       screen->getWorkspace(blackbox_attrib.workspace)->raiseWindow(this);
     }
   } else if (be->button == 2 && (be->window != frame.iconify_button) &&
-             (be->window != frame.close_button)) {
+             (be->window != frame.close_button) &&
+             (be->window != frame.stick_button)) {
     screen->getWorkspace(blackbox_attrib.workspace)->lowerWindow(this);
   } else if (windowmenu && be->button == 3 &&
              (frame.title == be->window || frame.label == be->window ||
@@ -3019,7 +3106,8 @@ void BlackboxWindow::buttonPressEvent(const XButtonEvent *be) {
          be->window == frame.title ||
          be->window == frame.maximize_button ||
          be->window == frame.iconify_button ||
-         be->window == frame.close_button) &&
+         be->window == frame.close_button ||
+         be->window == frame.stick_button) &&
         ! flags.shaded)
       shade();
   // mouse wheel down
@@ -3028,7 +3116,8 @@ void BlackboxWindow::buttonPressEvent(const XButtonEvent *be) {
          be->window == frame.title ||
          be->window == frame.maximize_button ||
          be->window == frame.iconify_button ||
-         be->window == frame.close_button) &&
+         be->window == frame.close_button ||
+         be->window == frame.stick_button) &&
         flags.shaded)
       shade();
   }
@@ -3056,6 +3145,13 @@ void BlackboxWindow::buttonReleaseEvent(const XButtonEvent *re) {
     } else {
       redrawIconifyButton(False);
     }
+  } else if (re->window == frame.stick_button && re->button == 1) {
+    if ((re->x >= 0 && re->x <= static_cast<signed>(frame.button_w)) &&
+        (re->y >= 0 && re->y <= static_cast<signed>(frame.button_w))) {
+      stick();
+    } else {
+      redrawStickyButton(False);
+    }
   } else if (re->window == frame.close_button & re->button == 1) {
     if ((re->x >= 0 && re->x <= static_cast<signed>(frame.button_w)) &&
         (re->y >= 0 && re->y <= static_cast<signed>(frame.button_w)))
@@ -3619,34 +3715,42 @@ void BlackboxWindow::doResize(int x_root, int y_root) {
 
   unsigned int gw, gh;
   Corner anchor;
+  int dx, dy; // the amount of change in the size of the window
 
   switch (resize_dir) {
   case BottomLeft:
     anchor = TopRight;
-    frame.changing.setSize(frame.rect.width() - (x_root - frame.grab_x),
-                           frame.rect.height() + (y_root - frame.grab_y));
+    dx = - (x_root - frame.grab_x);
+    dy = + (y_root - frame.grab_y);
     break;
   case BottomRight:
     anchor = TopLeft;
-    frame.changing.setSize(frame.rect.width() + (x_root - frame.grab_x),
-                           frame.rect.height() + (y_root - frame.grab_y));
+    dx = + (x_root - frame.grab_x);
+    dy = + (y_root - frame.grab_y);
     break;
   case TopLeft:
     anchor = BottomRight;
-    frame.changing.setSize(frame.rect.width() - (x_root - frame.grab_x),
-                           frame.rect.height() - (y_root - frame.grab_y));
+    dx = - (x_root - frame.grab_x);
+    dy = - (y_root - frame.grab_y);
     break;
   case TopRight:
     anchor = BottomLeft;
-    frame.changing.setSize(frame.rect.width() + (x_root - frame.grab_x),
-                           frame.rect.height() - (y_root - frame.grab_y));
+    dx = + (x_root - frame.grab_x);
+    dy = - (y_root - frame.grab_y);
     break;
 
   default:
     assert(false); // unhandled Corner
     return;        // unreachable, for the compiler
   }
-  
+
+  // make sure the user cant resize the window smaller than 0, which makes it
+  // wrap around and become huge
+  if (dx < -(signed)client.rect.width()) dx = -(signed)client.rect.width();
+  if (dy < -(signed)client.rect.height()) dy = -(signed)client.rect.height();
+
+  frame.changing.setSize(frame.rect.width() + dx, frame.rect.height() + dy);
+
   constrain(anchor, &gw, &gh);
 
   XDrawRectangle(blackbox->getXDisplay(), screen->getRootWindow(),
@@ -3775,9 +3879,15 @@ void BlackboxWindow::leaveNotifyEvent(const XCrossingEvent*) {
 
 
 #ifdef    SHAPE
-void BlackboxWindow::shapeEvent(XShapeEvent *) {
-  if (blackbox->hasShapeExtensions() && flags.shaped) {
-    configureShape();
+void BlackboxWindow::shapeEvent(XShapeEvent *e) {
+  if (blackbox->hasShapeExtensions()) {
+    if (! e->shaped && flags.shaped) {
+      clearShape();
+      flags.shaped = False;
+    } else if (e->shaped) {
+      configureShape();
+      flags.shaped = True;
+    }
   }
 }
 #endif // SHAPE
@@ -4009,11 +4119,17 @@ void BlackboxWindow::constrain(Corner anchor,
     base_height = (client.base_height) ? client.base_height :
                                          client.min_height;
 
-  // constrain
-  if (dw < client.min_width) dw = client.min_width;
-  if (dh < client.min_height) dh = client.min_height;
-  if (dw > client.max_width) dw = client.max_width;
-  if (dh > client.max_height) dh = client.max_height;
+  // constrain, but only if the min/max are being used. if they aren't, then
+  // this resize is going to be from a ConfigureRequest because the window
+  // isn't allowed to be resized by the user. And in that case, we don't want
+  // to limit what the app can do
+  if (client.max_width > client.min_width ||
+      client.max_height > client.min_height) {
+    if (dw < client.min_width) dw = client.min_width;
+    if (dh < client.min_height) dh = client.min_height;
+    if (dw > client.max_width) dw = client.max_width;
+    if (dh > client.max_height) dh = client.max_height;
+  }
 
   assert(dw >= base_width && dh >= base_height);
 
This page took 0.03029 seconds and 4 git commands to generate.