]> Dogcows Code - chaz/openbox/blobdiff - src/Window.cc
added the X classes to the build process though they aren't sued by anything else...
[chaz/openbox] / src / Window.cc
index 8df9ddfe733af2da1c99ded8fa80de0da9ef7e1a..59b640955c5c33b917e733bf8ee8cb6a0a8f23eb 100644 (file)
@@ -1,6 +1,7 @@
 // Window.cc for Openbox
-// Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
-// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
+// Copyright (c) 2002 - 2002 Ben Jansens (ben at orodu.net)
+// Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry (shaleh at debian.org)
+// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
 //
 // Permission is hereby granted, free of charge, to any person obtaining a
 // copy of this software and associated documentation files (the "Software"),
@@ -216,7 +217,7 @@ OpenboxWindow::OpenboxWindow(Openbox &o, Window w, BScreen *s) : openbox(o) {
   }
   upsize();
 
-  Bool place_window = True;
+  place_window = true;
   if (openbox.isStartup() || flags.transient ||
       client.normal_hint_flags & (PPosition|USPosition)) {
     setGravityOffsets();
@@ -226,7 +227,7 @@ OpenboxWindow::OpenboxWindow(Openbox &o, Window w, BScreen *s) : openbox(o) {
         (signed) (frame.y + frame.y_border) >= 0 &&
         frame.x <= (signed) screen->size().w() &&
         frame.y <= (signed) screen->size().h()))
-      place_window = False;
+      place_window = false;
   }
 
   frame.window = createToplevelWindow(frame.x, frame.y, frame.width,
@@ -261,16 +262,16 @@ OpenboxWindow::OpenboxWindow(Openbox &o, Window w, BScreen *s) : openbox(o) {
 
   if (! screen->sloppyFocus())
     openbox.grabButton(Button1, 0, frame.plate, True, ButtonPressMask,
-        GrabModeSync, GrabModeSync, None, None);
+        GrabModeSync, GrabModeSync, frame.plate, None);
 
   openbox.grabButton(Button1, Mod1Mask, frame.window, True,
       ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
-      GrabModeAsync, None, openbox.getMoveCursor());
+      GrabModeAsync, frame.window, openbox.getMoveCursor());
   openbox.grabButton(Button2, Mod1Mask, frame.window, True,
-      ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None);
+      ButtonReleaseMask, GrabModeAsync, GrabModeAsync, frame.window, None);
   openbox.grabButton(Button3, Mod1Mask, frame.window, True,
       ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
-      GrabModeAsync, None, None);
+      GrabModeAsync, frame.window, None);
 
   positionWindows();
   XRaiseWindow(display, frame.plate);
@@ -538,24 +539,6 @@ void OpenboxWindow::associateClientWindow(void) {
   if (decorations.iconify) createIconifyButton();
   if (decorations.maximize) createMaximizeButton();
   if (decorations.close) createCloseButton();
-
-  if (frame.ubutton) {
-    if (frame.close_button)
-      XSetWindowBackgroundPixmap(display, frame.close_button, frame.ubutton);
-    if (frame.maximize_button)
-      XSetWindowBackgroundPixmap(display, frame.maximize_button,
-                                frame.ubutton);
-    if (frame.iconify_button)
-      XSetWindowBackgroundPixmap(display, frame.iconify_button, frame.ubutton);
-  } else {
-    if (frame.close_button)
-      XSetWindowBackground(display, frame.close_button, frame.ubutton_pixel);
-    if (frame.maximize_button)
-      XSetWindowBackground(display, frame.maximize_button,
-                          frame.ubutton_pixel);
-    if (frame.iconify_button)
-      XSetWindowBackground(display, frame.iconify_button, frame.ubutton_pixel);
-  }
 }
 
 
@@ -739,7 +722,7 @@ void OpenboxWindow::createMaximizeButton(void) {
 }
 
 
-void OpenboxWindow::positionButtons(Bool redecorate_label) {
+void OpenboxWindow::positionButtons() {
   const char *format = openbox.getTitleBarLayout();
   const unsigned int bw = frame.bevel_w + 1;
   const unsigned int by = frame.bevel_w + 1;
@@ -760,37 +743,40 @@ void OpenboxWindow::positionButtons(Bool redecorate_label) {
   for (int i = 0; format[i] != '\0' && i < 4; i++) {
     switch(format[i]) {
     case 'C':
-      if (decorations.close && frame.close_button != None) {
+      if (decorations.close) {
+        if (frame.close_button == None)
+          createCloseButton();
         XMoveResizeWindow(display, frame.close_button, bx, by,
                           frame.button_w, frame.button_h);
         XMapWindow(display, frame.close_button);
         XClearWindow(display, frame.close_button);
         bx += frame.button_w + bw;
         hasclose = true;
-      } else if (frame.close_button)
-        XUnmapWindow(display, frame.close_button);
+      }
       break;
     case 'I':
-      if (decorations.iconify && frame.iconify_button != None) {
+      if (decorations.iconify) {
+        if (frame.iconify_button == None)
+          createIconifyButton();
         XMoveResizeWindow(display, frame.iconify_button, bx, by,
                           frame.button_w, frame.button_h);
         XMapWindow(display, frame.iconify_button);
         XClearWindow(display, frame.iconify_button);
         bx += frame.button_w + bw;
         hasiconify = true;
-      } else if (frame.close_button)
-        XUnmapWindow(display, frame.close_button);
+      }
       break;
     case 'M':
-      if (decorations.maximize && frame.maximize_button != None) {
+      if (decorations.maximize) {
+        if (frame.maximize_button == None)
+          createMaximizeButton();
         XMoveResizeWindow(display, frame.maximize_button, bx, by,
                           frame.button_w, frame.button_h);
         XMapWindow(display, frame.maximize_button);
         XClearWindow(display, frame.maximize_button);
         bx += frame.button_w + bw;
         hasmaximize = true;
-      } else if (frame.close_button)
-        XUnmapWindow(display, frame.close_button);
+      }
       break;
     case 'L':
       XMoveResizeWindow(display, frame.label, bx, by - 1,
@@ -800,20 +786,22 @@ void OpenboxWindow::positionButtons(Bool redecorate_label) {
     }
   }
 
-  if (!hasclose) {
-      openbox.removeWindowSearch(frame.close_button);
-      XDestroyWindow(display, frame.close_button);     
+  if (!hasclose && frame.close_button) {
+    openbox.removeWindowSearch(frame.close_button);
+    XDestroyWindow(display, frame.close_button);
+    frame.close_button = None;
   }
-  if (!hasiconify) {
-      openbox.removeWindowSearch(frame.iconify_button);
-      XDestroyWindow(display, frame.iconify_button);
+  if (!hasiconify && frame.iconify_button) {
+    openbox.removeWindowSearch(frame.iconify_button);
+    XDestroyWindow(display, frame.iconify_button);
+    frame.iconify_button = None;
   }
-  if (!hasmaximize) {
-      openbox.removeWindowSearch(frame.maximize_button);
-      XDestroyWindow(display, frame.maximize_button);                 
+  if (!hasmaximize && frame.iconify_button) {
+    openbox.removeWindowSearch(frame.maximize_button);
+    XDestroyWindow(display, frame.maximize_button);                 
+    frame.maximize_button = None;
   }
-  if (redecorate_label)
-    decorateLabel();
+
   redrawLabel();
   redrawAllButtons();
 }
@@ -857,6 +845,9 @@ void OpenboxWindow::reconfigure(void) {
     windowmenu->move(windowmenu->getX(), frame.y + frame.title_h);
     windowmenu->reconfigure();
   }
+  
+  // re-get the timeout delay
+  timer->setTimeout(openbox.getAutoRaiseDelay());
 }
 
 
@@ -1314,10 +1305,9 @@ void OpenboxWindow::configure(int dx, int dy,
 
     XMoveWindow(display, frame.window, frame.x, frame.y);
 
+    setFocusFlag(flags.focused);
     positionWindows();
     decorate();
-    setFocusFlag(flags.focused);
-    redrawAllButtons();
   } else {
     frame.x = dx;
     frame.y = dy;
@@ -1353,7 +1343,7 @@ void OpenboxWindow::configure(int dx, int dy,
 }
 
 
-Bool OpenboxWindow::setInputFocus(void) {
+bool OpenboxWindow::setInputFocus(void) {
   if (((signed) (frame.x + frame.width)) < 0) {
     if (((signed) (frame.y + frame.y_border)) < 0)
       configure(frame.border_w, frame.border_w, frame.width, frame.height);
@@ -1378,39 +1368,36 @@ Bool OpenboxWindow::setInputFocus(void) {
   openbox.grab();
   if (! validateClient()) return False;
 
-  Bool ret = False;
+  bool ret = false;
 
   if (client.transient && flags.modal) {
     ret = client.transient->setInputFocus();
   } else if (! flags.focused) {
-    if (focus_mode == F_LocallyActive || focus_mode == F_Passive)
+    if (focus_mode == F_LocallyActive || focus_mode == F_Passive) {
       XSetInputFocus(display, client.window,
-                    RevertToPointerRoot, CurrentTime);
-    else
-      XSetInputFocus(display, screen->getRootWindow(),
-                    RevertToNone, CurrentTime);
-
-    openbox.setFocusedWindow(this);
-
-    if (flags.send_focus_message) {
-      XEvent ce;
-      ce.xclient.type = ClientMessage;
-      ce.xclient.message_type = openbox.getWMProtocolsAtom();
-      ce.xclient.display = display;
-      ce.xclient.window = client.window;
-      ce.xclient.format = 32;
-      ce.xclient.data.l[0] = openbox.getWMTakeFocusAtom();
-      ce.xclient.data.l[1] = openbox.getLastTime();
-      ce.xclient.data.l[2] = 0l;
-      ce.xclient.data.l[3] = 0l;
-      ce.xclient.data.l[4] = 0l;
-      XSendEvent(display, client.window, False, NoEventMask, &ce);
-    }
+                      RevertToPointerRoot, CurrentTime);
+      openbox.focusWindow(this);
+
+      if (flags.send_focus_message) {
+        XEvent ce;
+        ce.xclient.type = ClientMessage;
+        ce.xclient.message_type = openbox.getWMProtocolsAtom();
+        ce.xclient.display = display;
+        ce.xclient.window = client.window;
+        ce.xclient.format = 32;
+        ce.xclient.data.l[0] = openbox.getWMTakeFocusAtom();
+        ce.xclient.data.l[1] = openbox.getLastTime();
+        ce.xclient.data.l[2] = 0l;
+        ce.xclient.data.l[3] = 0l;
+        ce.xclient.data.l[4] = 0l;
+        XSendEvent(display, client.window, False, NoEventMask, &ce);
+      }
 
-    if (screen->sloppyFocus() && screen->autoRaise())
-      timer->start();
+      if (screen->sloppyFocus() && screen->autoRaise())
+        timer->start();
 
-    ret = True;
+      ret = true;
+    }
   }
 
   openbox.ungrab();
@@ -1422,6 +1409,9 @@ Bool OpenboxWindow::setInputFocus(void) {
 void OpenboxWindow::iconify(void) {
   if (flags.iconic) return;
 
+  if (flags.moving)
+    endMove();
+
   if (windowmenu) windowmenu->hide();
 
   setState(IconicState);
@@ -1449,7 +1439,7 @@ void OpenboxWindow::iconify(void) {
 }
 
 
-void OpenboxWindow::deiconify(Bool reassoc, Bool raise) {
+void OpenboxWindow::deiconify(bool reassoc, bool raise, bool initial) {
   if (flags.iconic || reassoc)
     screen->reassociateWindow(this, -1, False);
   else if (workspace_number != screen->getCurrentWorkspace()->getWorkspaceID())
@@ -1467,14 +1457,8 @@ void OpenboxWindow::deiconify(Bool reassoc, Bool raise) {
 
   // if we're using the click to place placement type, then immediately
   // after the window is mapped, we need to start interactively moving it
-  if (!(flags.iconic || reassoc) &&
+  if (initial && place_window &&
       screen->placementPolicy() == BScreen::ClickMousePlacement) {
-    // if the last window wasn't placed yet, or we're just moving a window
-    // already, finish off that move cleanly
-    OpenboxWindow *w = openbox.getFocusedWindow();
-    if (w != (OpenboxWindow *) 0 && w->flags.moving)
-      w->endMove();
-
     int x, y, rx, ry;
     Window c, r;
     unsigned int m;
@@ -1530,6 +1514,9 @@ void OpenboxWindow::withdraw(void) {
 
 
 void OpenboxWindow::maximize(unsigned int button) {
+  if (flags.moving)
+    endMove();
+  
   // handle case where menu is open then the max button is used instead
   if (windowmenu && windowmenu->isVisible()) windowmenu->hide();
 
@@ -1549,7 +1536,7 @@ void OpenboxWindow::maximize(unsigned int button) {
     openbox_attrib.premax_x = openbox_attrib.premax_y = 0;
     openbox_attrib.premax_w = openbox_attrib.premax_h = 0;
 
-    redrawAllButtons();
+    redrawMaximizeButton(flags.maximized);
     setState(current_state);
     return;
   }
@@ -1623,12 +1610,13 @@ void OpenboxWindow::maximize(unsigned int button) {
 
   configure(dx, dy, dw, dh);
   screen->getWorkspace(workspace_number)->raiseWindow(this);
-  redrawAllButtons();
+  redrawMaximizeButton(flags.maximized);
   setState(current_state);
 }
 
 
 void OpenboxWindow::setWorkspace(int n) {
+  ASSERT(n < screen->getWorkspaceCount());
   workspace_number = n;
 
   openbox_attrib.flags |= AttribWorkspace;
@@ -2239,7 +2227,8 @@ void OpenboxWindow::mapRequestEvent(XMapRequestEvent *re) {
     case InactiveState:
     case ZoomState:
     default:
-      deiconify(False);
+      deiconify(False, True, True);     // specify that we're initializing the
+                                        // window
       break;
     }
 
@@ -2254,12 +2243,8 @@ void OpenboxWindow::mapNotifyEvent(XMapEvent *ne) {
     openbox.grab();
     if (! validateClient()) return;
 
-    if (decorations.titlebar) positionButtons();
-
     setState(NormalState);
 
-    redrawAllButtons();
-
     if (flags.transient || screen->focusNew())
       setInputFocus();
     else
@@ -2284,6 +2269,9 @@ void OpenboxWindow::unmapNotifyEvent(XUnmapEvent *ue) {
     openbox.grab();
     if (! validateClient()) return;
 
+    if (flags.moving)
+      endMove();
+    
     XChangeSaveSet(display, client.window, SetModeDelete);
     XSelectInput(display, client.window, NoEventMask);
 
@@ -2319,6 +2307,8 @@ void OpenboxWindow::unmapNotifyEvent(XUnmapEvent *ue) {
 
 void OpenboxWindow::destroyNotifyEvent(XDestroyWindowEvent *de) {
   if (de->window == client.window) {
+    if (flags.moving)
+      endMove();
     XUnmapWindow(display, frame.window);
 
     delete this;
@@ -2418,7 +2408,10 @@ void OpenboxWindow::propertyNotifyEvent(Atom atom) {
 
       if (decorations.close && (! frame.close_button)) {
         createCloseButton();
-        if (decorations.titlebar) positionButtons(True);
+        if (decorations.titlebar) {
+          positionButtons();
+          decorateLabel();
+        }
         if (windowmenu) windowmenu->reconfigure();
       }
     }
@@ -2593,7 +2586,7 @@ void OpenboxWindow::buttonPressEvent(XButtonEvent *be) {
           mx = be->x_root - windowmenu->getWidth() / 2;
           if (be->window == frame.title || be->window == frame.label) {
             my = frame.y + frame.title_h;
-          } else if (be->window = frame.handle) {
+          } else if (be->window == frame.handle) {
             my = frame.y + frame.y_handle - windowmenu->getHeight();
           } else { // (be->window == frame.window)
             if (be->y <= (signed) frame.bevel_w) {
@@ -2754,6 +2747,11 @@ void OpenboxWindow::buttonReleaseEvent(XButtonEvent *re) {
 void OpenboxWindow::startMove(int x, int y) {
   ASSERT(!flags.moving);
 
+  // make sure only one window is moving at a time
+  OpenboxWindow *w = openbox.getMaskedWindow();
+  if (w != (OpenboxWindow *) 0 && w->flags.moving)
+    w->endMove();
+  
   XGrabPointer(display, frame.window, False, PointerMotionMask |
                ButtonReleaseMask, GrabModeAsync, GrabModeAsync,
                None, openbox.getMoveCursor(), CurrentTime);
@@ -2871,6 +2869,10 @@ void OpenboxWindow::endMove() {
   }
   screen->hideGeometry();
   XUngrabPointer(display, CurrentTime);
+  // if there are any left over motions from the move, drop them now cuz they
+  // cause problems
+  XEvent e;
+  while (XCheckTypedWindowEvent(display, frame.window, MotionNotify, &e));
 }
 
 
@@ -2884,7 +2886,7 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) {
   else if (functions.resize &&
             (((me->state & Button1Mask) && (me->window == frame.right_grip ||
                                             me->window == frame.left_grip)) ||
-             (me->state & (Mod1Mask | Button3Mask) &&
+             (me->state == (Mod1Mask | Button3Mask) &&
                                             me->window == frame.window))) {
     Bool left = resize_zone & ZoneLeft;
 
@@ -3000,7 +3002,7 @@ void OpenboxWindow::shapeEvent(XShapeEvent *) {
 #endif // SHAPE
 
 
-Bool OpenboxWindow::validateClient(void) {
+bool OpenboxWindow::validateClient(void) {
   XSync(display, False);
 
   XEvent e;
@@ -3009,10 +3011,10 @@ Bool OpenboxWindow::validateClient(void) {
     XPutBackEvent(display, &e);
     openbox.ungrab();
 
-    return False;
+    return false;
   }
 
-  return True;
+  return true;
 }
 
 
@@ -3031,6 +3033,8 @@ void OpenboxWindow::restore(void) {
   XMapWindow(display, client.window);
 
   XFlush(display);
+
+  delete this;
 }
 
 
@@ -3088,21 +3092,25 @@ void OpenboxWindow::changeOpenboxHints(OpenboxHints *net) {
 
     default:
     case DecorNormal:
-      decorations.titlebar = decorations.border = decorations.handle =
-       decorations.iconify = decorations.maximize = decorations.menu = True;
+      decorations.titlebar = decorations.iconify = decorations.menu =
+        decorations.border = True;
+      decorations.handle = (functions.resize && !flags.transient);
+      decorations.maximize = functions.maximize;
 
       break;
 
     case DecorTiny:
       decorations.titlebar = decorations.iconify = decorations.menu = True;
-      decorations.border = decorations.handle = decorations.maximize = False;
+      decorations.border = decorations.border = decorations.handle = False;
+      decorations.maximize = functions.maximize;
+
       break;
 
     case DecorTool:
-      decorations.titlebar = decorations.menu = functions.move = True;
-      decorations.iconify = decorations.border = decorations.handle =
-       decorations.maximize = False;
+      decorations.titlebar = decorations.menu = True;
+      decorations.iconify = decorations.border = False;
+      decorations.handle = (functions.resize && !flags.transient);
+      decorations.maximize = functions.maximize;
 
       break;
     }
@@ -3198,9 +3206,9 @@ void OpenboxWindow::downsize(void) {
 void OpenboxWindow::right_fixsize(int *gx, int *gy) {
   // calculate the size of the client window and conform it to the
   // size specified by the size hints of the client window...
-  int dx = frame.resize_w - client.base_width - (frame.mwm_border_w * 2) -
+  int dx = 1 + frame.resize_w - client.base_width - (frame.mwm_border_w * 2) -
     (frame.border_w * 2) + (client.width_inc / 2);
-  int dy = frame.resize_h - frame.y_border - client.base_height -
+  int dy = 1 + frame.resize_h - frame.y_border - client.base_height -
     frame.handle_h - (frame.border_w * 3) - (frame.mwm_border_w * 2)
     + (client.height_inc / 2);
 
@@ -3218,9 +3226,9 @@ void OpenboxWindow::right_fixsize(int *gx, int *gy) {
   dx = (dx * client.width_inc) + client.base_width;
   dy = (dy * client.height_inc) + client.base_height;
 
-  frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2);
+  frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2) - 1;
   frame.resize_h = dy + frame.y_border + frame.handle_h +
-                   (frame.mwm_border_w * 2) +  (frame.border_w * 3);
+                   (frame.mwm_border_w * 2) +  (frame.border_w * 3) - 1;
   if (resize_zone & ZoneTop)
     frame.resize_y = frame.y + frame.height - frame.resize_h +
       screen->getBorderWidth() * 2;
@@ -3230,9 +3238,9 @@ void OpenboxWindow::right_fixsize(int *gx, int *gy) {
 void OpenboxWindow::left_fixsize(int *gx, int *gy) {
   // calculate the size of the client window and conform it to the
   // size specified by the size hints of the client window...
-  int dx = frame.x + frame.width - frame.resize_x - client.base_width -
+  int dx = 1 + frame.x + frame.width - frame.resize_x - client.base_width -
     (frame.mwm_border_w * 2) + (client.width_inc / 2);
-  int dy = frame.resize_h - frame.y_border - client.base_height -
+  int dy = 1 + frame.resize_h - frame.y_border - client.base_height -
     frame.handle_h - (frame.border_w * 3) - (frame.mwm_border_w * 2)
     + (client.height_inc / 2);
 
@@ -3250,11 +3258,11 @@ void OpenboxWindow::left_fixsize(int *gx, int *gy) {
   dx = (dx * client.width_inc) + client.base_width;
   dy = (dy * client.height_inc) + client.base_height;
 
-  frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2);
+  frame.resize_w = dx + (frame.mwm_border_w * 2) + (frame.border_w * 2) - 1;
   frame.resize_x = frame.x + frame.width - frame.resize_w +
                    (frame.border_w * 2);
   frame.resize_h = dy + frame.y_border + frame.handle_h +
-                   (frame.mwm_border_w * 2) + (frame.border_w * 3);
+                   (frame.mwm_border_w * 2) + (frame.border_w * 3) - 1;
   if (resize_zone & ZoneTop)
     frame.resize_y = frame.y + frame.height - frame.resize_h +
       screen->getBorderWidth() * 2;
This page took 0.03756 seconds and 4 git commands to generate.