]> Dogcows Code - chaz/openbox/blobdiff - src/Window.cc
better setting of atoms. plugged memory leak.
[chaz/openbox] / src / Window.cc
index c8c3760b917c2efe8f9a547bb2eb914d8b74bc52..80f201ad36a34a059f1685c11448db35bf523fbf 100644 (file)
@@ -261,16 +261,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 +538,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 +721,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 +742,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 +785,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();
 }
@@ -1314,10 +1301,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 +1339,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 +1364,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();
@@ -1472,12 +1455,6 @@ void OpenboxWindow::deiconify(bool reassoc, bool raise, bool initial) {
   // after the window is mapped, we need to start interactively moving it
   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;
@@ -1533,6 +1510,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();
 
@@ -1552,7 +1532,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;
   }
@@ -1626,12 +1606,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;
@@ -2208,7 +2189,6 @@ void OpenboxWindow::redrawCloseButton(Bool pressed) {
 
 
 void OpenboxWindow::mapRequestEvent(XMapRequestEvent *re) {
-  cout << "MAP REQUEST " << client.window << " " << client.title << endl;
   if (re->window == client.window) {
 #ifdef    DEBUG
     fprintf(stderr, i18n->getMessage(WindowSet, WindowMapRequest,
@@ -2259,12 +2239,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
@@ -2289,6 +2265,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);
 
@@ -2324,6 +2303,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;
@@ -2423,7 +2404,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();
       }
     }
@@ -2759,6 +2743,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);
@@ -2787,7 +2776,6 @@ void OpenboxWindow::startMove(int x, int y) {
   }
   frame.grab_x = x - frame.x - frame.border_w;
   frame.grab_y = y - frame.y - frame.border_w;
-  cout << "START MOVE " << client.window << " " << client.title << endl;
 }
 
 
@@ -2881,7 +2869,6 @@ void OpenboxWindow::endMove() {
   // cause problems
   XEvent e;
   while (XCheckTypedWindowEvent(display, frame.window, MotionNotify, &e));
-  cout << "END MOVE " << client.window << " " << client.title << endl;
 }
 
 
@@ -2900,7 +2887,6 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) {
     Bool left = resize_zone & ZoneLeft;
 
     if (! flags.resizing) {
-      cout << "START RESIZE " << client.window << " " << client.title << endl;
       Cursor cursor;
       if (resize_zone & ZoneTop)
         cursor = (resize_zone & ZoneLeft) ?
@@ -2974,8 +2960,7 @@ void OpenboxWindow::motionNotifyEvent(XMotionEvent *me) {
 
       screen->showGeometry(gx, gy);
     }
-  } else
-    cout << "MOTION " << client.window << " " << client.title << endl;
+  }
 }
 
 
@@ -3013,7 +2998,7 @@ void OpenboxWindow::shapeEvent(XShapeEvent *) {
 #endif // SHAPE
 
 
-Bool OpenboxWindow::validateClient(void) {
+bool OpenboxWindow::validateClient(void) {
   XSync(display, False);
 
   XEvent e;
@@ -3022,10 +3007,10 @@ Bool OpenboxWindow::validateClient(void) {
     XPutBackEvent(display, &e);
     openbox.ungrab();
 
-    return False;
+    return false;
   }
 
-  return True;
+  return true;
 }
 
 
@@ -3044,6 +3029,8 @@ void OpenboxWindow::restore(void) {
   XMapWindow(display, client.window);
 
   XFlush(display);
+
+  delete this;
 }
 
 
This page took 0.032 seconds and 4 git commands to generate.