]> Dogcows Code - chaz/openbox/blobdiff - src/Window.cc
properly watch for windows on other workspaces when mapping.
[chaz/openbox] / src / Window.cc
index 71da3df7f1fdd93771d9eca943a1c69110482b1a..f18d4dead2aaafdb4adef0f1a84392f2eba14ebb 100644 (file)
@@ -62,11 +62,6 @@ extern "C" {
 using std::string;
 using std::abs;
 
-// change this to change what modifier keys openbox uses for mouse bindings
-// for example: Mod1Mask | ControlMask
-//          or: ControlMask| ShiftMask
-const unsigned int ModMask = Mod1Mask;
-
 /*
  * Initializes the class with default values/the window's set initial values.
  */
@@ -126,8 +121,8 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
 
   blackbox_attrib.workspace = window_number = BSENTINEL;
 
-  blackbox_attrib.flags = blackbox_attrib.attrib = blackbox_attrib.stack
-    = blackbox_attrib.decoration = 0l;
+  blackbox_attrib.flags = blackbox_attrib.attrib = blackbox_attrib.stack = 0l;
+  blackbox_attrib.decoration = DecorNormal;
   blackbox_attrib.premax_x = blackbox_attrib.premax_y = 0;
   blackbox_attrib.premax_w = blackbox_attrib.premax_h = 0;
 
@@ -147,7 +142,7 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
 
   functions = Func_Resize | Func_Move | Func_Iconify | Func_Maximize;
   mwm_decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
-                    Decor_Iconify | Decor_Maximize | Decor_Close;
+                    Decor_Iconify | Decor_Maximize;
 
   client.normal_hint_flags = 0;
   client.window_group = None;
@@ -173,9 +168,8 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
   // get size, aspect, minimum/maximum size and other hints set by the
   // client
 
-  if (! getBlackboxHints()) {
+  if (! getBlackboxHints())
     getNetWMHints();
-  }
 
   getWMProtocols();
   getWMHints();
@@ -235,8 +229,14 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
   
   setAllowedActions();
 
-  enableDecor(True);
+  setupDecor();
   
+  if (decorations & Decor_Titlebar)
+    createTitlebar();
+
+  if (decorations & Decor_Handle)
+    createHandle();
+
   // apply the size and gravity hint to the frame
 
   upsize();
@@ -401,15 +401,33 @@ BlackboxWindow::~BlackboxWindow(void) {
 
 
 void BlackboxWindow::enableDecor(bool enable) {
-  if (enable) {
+  blackbox_attrib.flags |= AttribDecoration;
+  blackbox_attrib.decoration = enable ? DecorNormal : DecorNone;
+  setupDecor();
+    
+  // we can not be shaded if we lack a titlebar
+  if (! (decorations & Decor_Titlebar) && flags.shaded)
+    shade();
+    
+  if (flags.visible && frame.window) {
+    XMapSubwindows(blackbox->getXDisplay(), frame.window);
+    XMapWindow(blackbox->getXDisplay(), frame.window);
+  }
+
+  reconfigure();
+  setState(current_state);
+}
+
+
+void BlackboxWindow::setupDecor() {
+  if (blackbox_attrib.decoration != DecorNone) {
     // start with everything on
-    decorations =
+    decorations = Decor_Close |
       (mwm_decorations & Decor_Titlebar ? Decor_Titlebar : 0) |
       (mwm_decorations & Decor_Border ? Decor_Border : 0) |
       (mwm_decorations & Decor_Handle ? Decor_Handle : 0) |
       (mwm_decorations & Decor_Iconify ? Decor_Iconify : 0) |
-      (mwm_decorations & Decor_Maximize ? Decor_Maximize : 0) |
-      (mwm_decorations & Decor_Close ? Decor_Close : 0);
+      (mwm_decorations & Decor_Maximize ? Decor_Maximize : 0);
 
     if (! (functions & Func_Close)) decorations &= ~Decor_Close;
     if (! (functions & Func_Maximize)) decorations &= ~Decor_Maximize;
@@ -440,14 +458,6 @@ void BlackboxWindow::enableDecor(bool enable) {
   } else {
     decorations = 0;
   }
-    
-  destroyTitlebar();
-  if (decorations & Decor_Titlebar)
-    createTitlebar();
-
-  destroyHandle();
-  if (decorations & Decor_Handle)
-    createHandle();
 }
 
 /*
@@ -582,11 +592,6 @@ void BlackboxWindow::decorate(void) {
   if (decorations & Decor_Border) {
     frame.fborder_pixel = screen->getWindowStyle()->f_focus.pixel();
     frame.uborder_pixel = screen->getWindowStyle()->f_unfocus.pixel();
-    blackbox_attrib.flags |= AttribDecoration;
-    blackbox_attrib.decoration = DecorNormal;
-  } else {
-    blackbox_attrib.flags |= AttribDecoration;
-    blackbox_attrib.decoration = DecorNone;
   }
 
   if (decorations & Decor_Handle) {
@@ -882,6 +887,8 @@ void BlackboxWindow::reconfigure(void) {
 
 
 void BlackboxWindow::grabButtons(void) {
+  mod_mask = blackbox->getMouseModMask();
+
   if (! screen->isSloppyFocus() || screen->doClickRaise())
     // grab button 1 for changing focus/raising
     blackbox->grabButton(Button1, 0, frame.plate, True, ButtonPressMask,
@@ -889,17 +896,17 @@ void BlackboxWindow::grabButtons(void) {
                          screen->allowScrollLock());
   
   if (functions & Func_Move)
-    blackbox->grabButton(Button1, ModMask, frame.window, True,
+    blackbox->grabButton(Button1, mod_mask, frame.window, True,
                          ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
                          GrabModeAsync, frame.window, None,
                          screen->allowScrollLock());
   if (functions & Func_Resize)
-    blackbox->grabButton(Button3, ModMask, frame.window, True,
+    blackbox->grabButton(Button3, mod_mask, frame.window, True,
                          ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
                          GrabModeAsync, frame.window, None,
                          screen->allowScrollLock());
   // alt+middle lowers the window
-  blackbox->grabButton(Button2, ModMask, frame.window, True,
+  blackbox->grabButton(Button2, mod_mask, frame.window, True,
                        ButtonReleaseMask, GrabModeAsync, GrabModeAsync,
                        frame.window, None,
                        screen->allowScrollLock());
@@ -908,9 +915,9 @@ void BlackboxWindow::grabButtons(void) {
 
 void BlackboxWindow::ungrabButtons(void) {
   blackbox->ungrabButton(Button1, 0, frame.plate);
-  blackbox->ungrabButton(Button1, ModMask, frame.window);
-  blackbox->ungrabButton(Button2, ModMask, frame.window);
-  blackbox->ungrabButton(Button3, ModMask, frame.window);
+  blackbox->ungrabButton(Button1, mod_mask, frame.window);
+  blackbox->ungrabButton(Button2, mod_mask, frame.window);
+  blackbox->ungrabButton(Button3, mod_mask, frame.window);
 }
 
 
@@ -1303,7 +1310,7 @@ void BlackboxWindow::getMWMHints(void) {
   if (mwm_hint->flags & MwmHintsDecorations) {
     if (mwm_hint->decorations & MwmDecorAll) {
       mwm_decorations = Decor_Titlebar | Decor_Handle | Decor_Border |
-                        Decor_Iconify | Decor_Maximize | Decor_Close;
+                        Decor_Iconify | Decor_Maximize;
     } else {
       mwm_decorations = 0;
 
@@ -1389,18 +1396,16 @@ bool BlackboxWindow::getBlackboxHints(void) {
   if (blackbox_hint->flags & AttribDecoration) {
     switch (blackbox_hint->decoration) {
     case DecorNone:
-      enableDecor(False);
+      blackbox_attrib.decoration = DecorNone;
       break;
 
     case DecorTiny:
     case DecorTool:
     case DecorNormal:
     default:
-      enableDecor(True);
+      // blackbox_attrib.decoration defaults to DecorNormal
       break;
     }
-
-    reconfigure();
   }
   
   delete [] blackbox_hint;
@@ -1417,7 +1422,7 @@ void BlackboxWindow::getTransientInfo(void) {
   }
 
   // we have no transient_for until we find a new one
-  client.transient_for = 0;
+  client.transient_for = (BlackboxWindow *) 0;
 
   Window trans_for;
   if (! XGetTransientForHint(blackbox->getXDisplay(), client.window,
@@ -2322,18 +2327,6 @@ void BlackboxWindow::restoreAttributes(void) {
       enableDecor(True);
       break;
     }
-
-    // we can not be shaded if we lack a titlebar
-    if (! (decorations & Decor_Titlebar) && flags.shaded)
-      shade();
-
-    if (flags.visible && frame.window) {
-      XMapSubwindows(blackbox->getXDisplay(), frame.window);
-      XMapWindow(blackbox->getXDisplay(), frame.window);
-    }
-
-    reconfigure();
-    setState(current_state);
   }
 
   // with the state set it will then be the map event's job to read the
@@ -2618,6 +2611,14 @@ void BlackboxWindow::mapRequestEvent(const XMapRequestEvent *re) {
           client.window);
 #endif // DEBUG
 
+  /*
+     Even though the window wants to be shown, if it is not on the current
+     workspace, then it isn't going to be shown right now.
+  */
+  if (blackbox_attrib.workspace != screen->getCurrentWorkspaceID() &&
+      blackbox_attrib.workspace < screen->getWorkspaceCount())
+    if (current_state == NormalState) current_state = WithdrawnState;
+
   switch (current_state) {
   case IconicState:
     iconify();
@@ -2636,8 +2637,8 @@ void BlackboxWindow::mapRequestEvent(const XMapRequestEvent *re) {
     if (isNormal()) {
       if (! blackbox->isStartup()) {
         XSync(blackbox->getXDisplay(), False); // make sure the frame is mapped
-        if (screen->doFocusNew()|| (isTransient() && getTransientFor() &&
-                                    getTransientFor()->isFocused())) {
+        if (screen->doFocusNew() || (isTransient() && getTransientFor() &&
+                                     getTransientFor()->isFocused())) {
           setInputFocus();
         }
         if (screen->getPlacementPolicy() == BScreen::ClickMousePlacement) {
@@ -2701,7 +2702,7 @@ void BlackboxWindow::propertyNotifyEvent(const XPropertyEvent *pe) {
   if (pe->state == PropertyDelete)
     return;
 
-#ifdef    DEBUG
+#if 0
   fprintf(stderr, "BlackboxWindow::propertyNotifyEvent(): for 0x%lx\n",
           client.window);
 #endif
@@ -2713,14 +2714,17 @@ void BlackboxWindow::propertyNotifyEvent(const XPropertyEvent *pe) {
     break;
 
   case XA_WM_TRANSIENT_FOR: {
+    bool s = flags.stuck;
+    
     // determine if this is a transient window
     getTransientInfo();
 
     // adjust the window decorations based on transience
     if (isTransient()) {
-      decorations &= ~(Decor_Maximize | Decor_Handle);
       functions &= ~Func_Maximize;
       setAllowedActions();
+      setupDecor();
+      if (flags.stuck != s) stick();
     }
 
     reconfigure();
@@ -2756,17 +2760,15 @@ void BlackboxWindow::propertyNotifyEvent(const XPropertyEvent *pe) {
       ungrabButtons();
       if (client.max_width <= client.min_width &&
           client.max_height <= client.min_height) {
-        decorations &= ~(Decor_Maximize | Decor_Handle);
         functions &= ~(Func_Resize | Func_Maximize);
       } else {
-        if (! isTransient()) {
-          decorations |= Decor_Maximize | Decor_Handle;
+        if (! isTransient())
           functions |= Func_Maximize;
-        }
         functions |= Func_Resize;
       }
       grabButtons();
       setAllowedActions();
+      setupDecor();
     }
 
     Rect old_rect = frame.rect;
@@ -2801,7 +2803,7 @@ void BlackboxWindow::propertyNotifyEvent(const XPropertyEvent *pe) {
 
 
 void BlackboxWindow::exposeEvent(const XExposeEvent *ee) {
-#ifdef DEBUG
+#if 0
   fprintf(stderr, "BlackboxWindow::exposeEvent() for 0x%lx\n", client.window);
 #endif
 
@@ -2869,7 +2871,7 @@ void BlackboxWindow::buttonPressEvent(const XButtonEvent *be) {
 
   if (frame.maximize_button == be->window && be->button <= 3) {
     redrawMaximizeButton(True);
-  } else if (be->button == 1 || (be->button == 3 && be->state == ModMask)) {
+  } else if (be->button == 1 || (be->button == 3 && be->state == mod_mask)) {
     if (! flags.focused)
       setInputFocus();
 
@@ -2995,7 +2997,7 @@ void BlackboxWindow::buttonReleaseEvent(const XButtonEvent *re) {
   } else if (flags.resizing) {
     endResize();
   } else if (re->window == frame.window) {
-    if (re->button == 2 && re->state == ModMask)
+    if (re->button == 2 && re->state == mod_mask)
       XUngrabPointer(blackbox->getXDisplay(), CurrentTime);
   }
 }
@@ -3610,7 +3612,7 @@ void BlackboxWindow::endResize(void) {
 
 
 void BlackboxWindow::motionNotifyEvent(const XMotionEvent *me) {
-#ifdef DEBUG
+#if 0
   fprintf(stderr, "BlackboxWindow::motionNotifyEvent() for 0x%lx\n",
           client.window);
 #endif
@@ -3620,15 +3622,17 @@ void BlackboxWindow::motionNotifyEvent(const XMotionEvent *me) {
   } else if (flags.resizing) {
     doResize(me->x_root, me->y_root);
   } else {
-    if (!flags.resizing && me->state & Button1Mask && (functions & Func_Move) &&
+    if ((functions & Func_Move) &&
+       (me->state & Button1Mask) &&
         (frame.title == me->window || frame.label == me->window ||
          frame.handle == me->window || frame.window == me->window)) {
       beginMove(me->x_root, me->y_root);
     } else if ((functions & Func_Resize) &&
-               (me->state & Button1Mask && (me->window == frame.right_grip ||
-                                            me->window == frame.left_grip)) ||
-               (me->state & Button3Mask && me->state & ModMask &&
-                me->window == frame.window)) {
+               ((me->state & Button1Mask) && (me->window == frame.right_grip ||
+                                              me->window == frame.left_grip)) ||
+               ((me->state & Button3Mask) && (me->state & mod_mask) &&
+                (frame.title == me->window || frame.label == me->window ||
+                 frame.handle == me->window || frame.window == me->window))) {
       unsigned int zones = screen->getResizeZones();
       Corner corner;
       
@@ -3727,6 +3731,12 @@ void BlackboxWindow::restore(bool remap) {
   if (flags.shaded && ! flags.iconic)
     setState(NormalState);
 
+  // erase the netwm stuff that we read when a window maps, so that it
+  // doesn't persist between mappings.
+  // (these are the ones read in getNetWMFlags().)
+  xatom->eraseValue(client.window, XAtom::net_wm_desktop);
+  xatom->eraseValue(client.window, XAtom::net_wm_state);
+
   restoreGravity(client.rect);
 
   XUnmapWindow(blackbox->getXDisplay(), frame.window);
@@ -3812,18 +3822,6 @@ void BlackboxWindow::changeBlackboxHints(const BlackboxHints *net) {
       enableDecor(True);
       break;
     }
-
-    // we can not be shaded if we lack a titlebar
-    if (flags.shaded && ! (decorations & Decor_Titlebar))
-      shade();
-
-    if (flags.visible && frame.window) {
-      XMapSubwindows(blackbox->getXDisplay(), frame.window);
-      XMapWindow(blackbox->getXDisplay(), frame.window);
-    }
-
-    reconfigure();
-    setState(current_state);
   }
 }
 
This page took 0.031911 seconds and 4 git commands to generate.