]> Dogcows Code - chaz/openbox/blobdiff - src/Window.cc
check to make sure the workspaces is > 0 not != 0
[chaz/openbox] / src / Window.cc
index fd79bfe1da1b4367f1fff99ca901ee93c5b7f7fd..226ac023f4f51dbca598e63b30ab7b03f9026e07 100644 (file)
@@ -44,6 +44,7 @@ extern "C" {
 
 #include "i18n.hh"
 #include "blackbox.hh"
+#include "Clientmenu.hh"
 #include "Font.hh"
 #include "GCCache.hh"
 #include "Iconmenu.hh"
@@ -58,6 +59,11 @@ extern "C" {
 
 using std::string;
 
+// 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.
  */
@@ -175,12 +181,6 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
     return;
   }
 
-  if (isKDESystrayWindow()) {
-    screen->addSystrayWindow(client.window);
-    delete this;
-    return;
-  }
-
   frame.window = createToplevelWindow();
   frame.plate = createChildWindow(frame.window);
   associateClientWindow();
@@ -199,29 +199,16 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
   // adjust the window decorations/behavior based on the window type
   switch (window_type) {
   case Type_Desktop:
-    // desktop windows are not managed by us, we just make sure they stay on the
-    // bottom.
-    return;
-
   case Type_Dock:
-    // docks (such as kicker) cannot be moved, and appear on all workspaces
-    functions &= ~(Func_Move);
-    flags.stuck = True;
-  case Type_Toolbar:
   case Type_Menu:
+  case Type_Toolbar:
   case Type_Utility:
-    // these windows have minimal decorations, only a titlebar, and cannot
-    // be resized or iconified
-    decorations &= ~(Decor_Maximize | Decor_Handle | Decor_Border |
-                     Decor_Iconify);
-    functions &= ~(Func_Resize | Func_Maximize | Func_Iconify);
-    break;
-
   case Type_Splash:
-    // splash screens have no functionality or decorations, they are left up
-    // to the application which created them
+    // none of these windows are decorated or manipulated by the window manager
     decorations = 0;
     functions = 0;
+    blackbox_attrib.workspace = 0;  // we do need to belong to a workspace
+    flags.stuck = True;             // we show up on all workspaces
     break;
 
   case Type_Dialog:
@@ -422,7 +409,7 @@ Window BlackboxWindow::createToplevelWindow(void) {
                              ButtonMotionMask | EnterWindowMask;
 
   return XCreateWindow(blackbox->getXDisplay(), screen->getRootWindow(),
-                       -1, -1, 1, 1, frame.border_w, screen->getDepth(),
+                       0, 0, 1, 1, frame.border_w, screen->getDepth(),
                        InputOutput, screen->getVisual(), create_mask,
                        &attrib_create);
 }
@@ -462,10 +449,14 @@ void BlackboxWindow::associateClientWindow(void) {
   XSelectInput(blackbox->getXDisplay(), frame.plate, SubstructureRedirectMask);
 
   XGrabServer(blackbox->getXDisplay());
-  XSelectInput(blackbox->getXDisplay(), client.window, NoEventMask);
-  XReparentWindow(blackbox->getXDisplay(), client.window, frame.plate, 0, 0);
+
+  unsigned long event_mask = PropertyChangeMask | FocusChangeMask |
+                             StructureNotifyMask;
   XSelectInput(blackbox->getXDisplay(), client.window,
-               PropertyChangeMask | FocusChangeMask | StructureNotifyMask);
+               event_mask & ~StructureNotifyMask);
+  XReparentWindow(blackbox->getXDisplay(), client.window, frame.plate, 0, 0);
+  XSelectInput(blackbox->getXDisplay(), client.window, event_mask);
+
   XUngrabServer(blackbox->getXDisplay());
 
   XRaiseWindow(blackbox->getXDisplay(), frame.plate);
@@ -833,24 +824,27 @@ void BlackboxWindow::reconfigure(void) {
 
 
 void BlackboxWindow::grabButtons(void) {
-  if ((! screen->isSloppyFocus()) || screen->doClickRaise())
+  if (! screen->isSloppyFocus() || screen->doClickRaise())
     // grab button 1 for changing focus/raising
     blackbox->grabButton(Button1, 0, frame.plate, True, ButtonPressMask,
-                         GrabModeSync, GrabModeSync, frame.plate, None);
-
+                         GrabModeSync, GrabModeSync, frame.plate, None,
+                         screen->allowScrollLock());
+  
   if (functions & Func_Move)
-    blackbox->grabButton(Button1, Mod1Mask, frame.window, True,
+    blackbox->grabButton(Button1, ModMask, frame.window, True,
                          ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
-                         GrabModeAsync, frame.window,
-                         blackbox->getMoveCursor());
+                         GrabModeAsync, frame.window, None,
+                         screen->allowScrollLock());
   if (functions & Func_Resize)
-    blackbox->grabButton(Button3, Mod1Mask, frame.window, True,
+    blackbox->grabButton(Button3, ModMask, frame.window, True,
                          ButtonReleaseMask | ButtonMotionMask, GrabModeAsync,
-                         GrabModeAsync, frame.window, None);
+                         GrabModeAsync, frame.window, None,
+                         screen->allowScrollLock());
   // alt+middle lowers the window
-  blackbox->grabButton(Button2, Mod1Mask, frame.window, True,
+  blackbox->grabButton(Button2, ModMask, frame.window, True,
                        ButtonReleaseMask, GrabModeAsync, GrabModeAsync,
-                       frame.window, None);
+                       frame.window, None,
+                       screen->allowScrollLock());
 }
 
 
@@ -858,9 +852,9 @@ void BlackboxWindow::ungrabButtons(void) {
   if ((! screen->isSloppyFocus()) || screen->doClickRaise())
     blackbox->ungrabButton(Button1, 0, frame.plate);
 
-  blackbox->ungrabButton(Button1, Mod1Mask, frame.window);
-  blackbox->ungrabButton(Button2, Mod1Mask, frame.window);
-  blackbox->ungrabButton(Button3, Mod1Mask, frame.window);
+  blackbox->ungrabButton(Button1, ModMask, frame.window);
+  blackbox->ungrabButton(Button2, ModMask, frame.window);
+  blackbox->ungrabButton(Button3, ModMask, frame.window);
 }
 
 
@@ -1090,9 +1084,12 @@ void BlackboxWindow::getWMHints(void) {
 
     // add window to the appropriate group
     BWindowGroup *group = blackbox->searchGroup(client.window_group);
-    if (! group) // no group found, create it!
-      group = new BWindowGroup(blackbox, client.window_group);
-    group->addWindow(this);
+    if (! group) { // no group found, create it!
+      new BWindowGroup(blackbox, client.window_group);
+      group = blackbox->searchGroup(client.window_group);
+    }
+    if (group)
+      group->addWindow(this);
   }
 
   client.wm_hint_flags = wmhint->flags;
@@ -1431,15 +1428,6 @@ void BlackboxWindow::getTransientInfo(void) {
 }
 
 
-bool BlackboxWindow::isKDESystrayWindow(void) {
-  Window systray;
-  if (xatom->getValue(client.window, XAtom::kde_net_wm_system_tray_window_for,
-                      XAtom::window, systray) && systray)
-    return True;
-  return False;
-}
-
-
 BlackboxWindow *BlackboxWindow::getTransientFor(void) const {
   if (client.transient_for &&
       client.transient_for != (BlackboxWindow*) ~0ul)
@@ -1569,12 +1557,18 @@ bool BlackboxWindow::setInputFocus(void) {
     return True;
   }
 #endif
-  if (! frame.rect.intersects(screen->getRect())) {
-    // client is outside the screen, move it to the center
-    configure((screen->getWidth() - frame.rect.width()) / 2,
-              (screen->getHeight() - frame.rect.height()) / 2,
-              frame.rect.width(), frame.rect.height());
-  }
+  /*
+     We only do this check for normal windows and dialogs because other windows
+     do this on purpose, such as kde's kicker, and we don't want to go moving
+     it.
+  */
+  if (window_type == Type_Normal || window_type == Type_Dialog)
+    if (! frame.rect.intersects(screen->getRect())) {
+      // client is outside the screen, move it to the center
+      configure((screen->getWidth() - frame.rect.width()) / 2,
+                (screen->getHeight() - frame.rect.height()) / 2,
+                frame.rect.width(), frame.rect.height());
+    }
 
   if (client.transientList.size() > 0) {
     // transfer focus to any modal transients
@@ -1636,11 +1630,13 @@ void BlackboxWindow::iconify(void) {
    * split second, leaving us with a ghost window... so, we need to do this
    * while the X server is grabbed
    */
+  unsigned long event_mask = PropertyChangeMask | FocusChangeMask |
+                             StructureNotifyMask;
   XGrabServer(blackbox->getXDisplay());
-  XSelectInput(blackbox->getXDisplay(), client.window, NoEventMask);
-  XUnmapWindow(blackbox->getXDisplay(), client.window);
   XSelectInput(blackbox->getXDisplay(), client.window,
-               PropertyChangeMask | FocusChangeMask | StructureNotifyMask);
+               event_mask & ~StructureNotifyMask);
+  XUnmapWindow(blackbox->getXDisplay(), client.window);
+  XSelectInput(blackbox->getXDisplay(), client.window, event_mask);
   XUngrabServer(blackbox->getXDisplay());
 
   XUnmapWindow(blackbox->getXDisplay(), frame.window);
@@ -1749,10 +1745,12 @@ void BlackboxWindow::withdraw(void) {
 
   XGrabServer(blackbox->getXDisplay());
 
-  XSelectInput(blackbox->getXDisplay(), client.window, NoEventMask);
-  XUnmapWindow(blackbox->getXDisplay(), client.window);
+  unsigned long event_mask = PropertyChangeMask | FocusChangeMask |
+                             StructureNotifyMask;
   XSelectInput(blackbox->getXDisplay(), client.window,
-               PropertyChangeMask | FocusChangeMask | StructureNotifyMask);
+               event_mask & ~StructureNotifyMask);
+  XUnmapWindow(blackbox->getXDisplay(), client.window);
+  XSelectInput(blackbox->getXDisplay(), client.window, event_mask);
 
   XUngrabServer(blackbox->getXDisplay());
 
@@ -1799,8 +1797,21 @@ void BlackboxWindow::maximize(unsigned int button) {
   blackbox_attrib.premax_h =
     client.rect.height() + frame.margin.top + frame.margin.bottom;
 
-  const Rect &screen_area = screen->availableArea();
-  frame.changing = screen_area;
+#ifdef    XINERAMA
+  if (screen->isXineramaActive() && blackbox->doXineramaMaximizing()) {
+    // find the area to use
+    RectList availableAreas = screen->allAvailableAreas();
+    RectList::iterator it, end = availableAreas.end();
+
+    for (it = availableAreas.begin(); it != end; ++it)
+      if (it->intersects(frame.rect)) break;
+    if (it == end) // the window isn't inside an area
+      it = availableAreas.begin(); // so just default to the first one
+
+    frame.changing = *it;
+  } else
+#endif
+  frame.changing = screen->availableArea();
 
   switch(button) {
   case 1:
@@ -1922,11 +1933,10 @@ void BlackboxWindow::stick(void) {
 
     if (! flags.iconic)
       screen->reassociateWindow(this, BSENTINEL, True);
-    else
-      // temporary fix since sticky windows suck. set the hint to what we
-      // actually hold in our data.
-      xatom->setValue(client.window, XAtom::net_wm_desktop, XAtom::cardinal,
-                      blackbox_attrib.workspace);
+    // temporary fix since sticky windows suck. set the hint to what we
+    // actually hold in our data.
+    xatom->setValue(client.window, XAtom::net_wm_desktop, XAtom::cardinal,
+                    blackbox_attrib.workspace);
 
     setState(current_state);
   } else {
@@ -2050,6 +2060,9 @@ void BlackboxWindow::setFocusFlag(bool focus) {
 
   if (isFocused())
     blackbox->setFocusedWindow(this);
+  
+  Clientmenu *menu = screen->getWorkspace(blackbox_attrib.workspace)->getMenu();
+  menu->setItemSelected(window_number, isFocused());
 }
 
 
@@ -2518,9 +2531,22 @@ void BlackboxWindow::mapRequestEvent(const XMapRequestEvent *re) {
   default:
     show();
     screen->getWorkspace(blackbox_attrib.workspace)->raiseWindow(this);
-    if (! blackbox->isStartup() && (isTransient() || screen->doFocusNew())) {
-      XSync(blackbox->getXDisplay(), False); // make sure the frame is mapped..
-      setInputFocus();
+    if (isNormal()) {
+      if (! blackbox->isStartup()) {
+        XSync(blackbox->getXDisplay(), False); // make sure the frame is mapped
+        if (screen->doFocusNew()|| (isTransient() && getTransientFor() &&
+                                    getTransientFor()->isFocused())) {
+          setInputFocus();
+        }
+        if (screen->getPlacementPolicy() == BScreen::ClickMousePlacement) {
+          int x, y, rx, ry;
+          Window c, r;
+          unsigned int m;
+          XQueryPointer(blackbox->getXDisplay(), screen->getRootWindow(),
+                        &r, &c, &rx, &ry, &x, &y, &m);
+          beginMove(rx, ry);
+        }
+      }
     }
     break;
   }
@@ -2716,7 +2742,7 @@ void BlackboxWindow::configureRequestEvent(const XConfigureRequestEvent *cr) {
     configure(req.x(), req.y(), req.width(), req.height());
   }
 
-  if (cr->value_mask & CWStackMode) {
+  if (cr->value_mask & CWStackMode && !isDesktop()) {
     switch (cr->detail) {
     case Below:
     case BottomIf:
@@ -2739,9 +2765,9 @@ void BlackboxWindow::buttonPressEvent(const XButtonEvent *be) {
           client.window);
 #endif
 
-  if (frame.maximize_button == be->window) {
+  if (frame.maximize_button == be->window && be->button <= 3) {
     redrawMaximizeButton(True);
-  } else if (be->button == 1 || (be->button == 3 && be->state == Mod1Mask)) {
+  } else if (be->button == 1 || (be->button == 3 && be->state == ModMask)) {
     if (! flags.focused)
       setInputFocus();
 
@@ -2817,13 +2843,19 @@ void BlackboxWindow::buttonPressEvent(const XButtonEvent *be) {
   // mouse wheel up
   } else if (be->button == 4) {
     if ((be->window == frame.label ||
-         be->window == frame.title) &&
+         be->window == frame.title ||
+         be->window == frame.maximize_button ||
+         be->window == frame.iconify_button ||
+         be->window == frame.close_button) &&
         ! flags.shaded)
       shade();
   // mouse wheel down
   } else if (be->button == 5) {
     if ((be->window == frame.label ||
-         be->window == frame.title) &&
+         be->window == frame.title ||
+         be->window == frame.maximize_button ||
+         be->window == frame.iconify_button ||
+         be->window == frame.close_button) &&
         flags.shaded)
       shade();
   }
@@ -2836,21 +2868,22 @@ void BlackboxWindow::buttonReleaseEvent(const XButtonEvent *re) {
           client.window);
 #endif
 
-  if (re->window == frame.maximize_button) {
+  if (re->window == frame.maximize_button &&
+      re->button >= 1 && re->button <= 3) {
     if ((re->x >= 0 && re->x <= static_cast<signed>(frame.button_w)) &&
         (re->y >= 0 && re->y <= static_cast<signed>(frame.button_w))) {
       maximize(re->button);
     } else {
       redrawMaximizeButton(flags.maximized);
     }
-  } else if (re->window == frame.iconify_button) {
+  } else if (re->window == frame.iconify_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))) {
       iconify();
     } else {
       redrawIconifyButton(False);
     }
-  } else if (re->window == frame.close_button) {
+  } 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)))
       close();
@@ -2860,7 +2893,7 @@ void BlackboxWindow::buttonReleaseEvent(const XButtonEvent *re) {
   } else if (flags.resizing) {
     endResize();
   } else if (re->window == frame.window) {
-    if (re->button == 2 && re->state == Mod1Mask)
+    if (re->button == 2 && re->state == ModMask)
       XUngrabPointer(blackbox->getXDisplay(), CurrentTime);
   }
 }
@@ -3007,48 +3040,50 @@ void BlackboxWindow::doMove(int x_root, int y_root) {
       }
     }
 
-    // try snap to the screen's available area
-    Rect srect = screen->availableArea();
-
-    int dleft = std::abs(wleft - srect.left()),
-       dright = std::abs(wright - srect.right()),
-         dtop = std::abs(wtop - srect.top()),
-      dbottom = std::abs(wbottom - srect.bottom());
-
-    // snap left?
-    if (dleft < snap_distance && dleft <= dright)
-      dx = srect.left();
-    // snap right?
-    else if (dright < snap_distance)
-      dx = srect.right() - frame.rect.width() + 1;
-
-    // snap top?
-    if (dtop < snap_distance && dtop <= dbottom)
-      dy = srect.top();
-    // snap bottom?
-    else if (dbottom < snap_distance)
-      dy = srect.bottom() - frame.rect.height() + 1;
-
-    srect = screen->getRect(); // now get the full screen
-
-    dleft = std::abs(wleft - srect.left()),
-      dright = std::abs(wright - srect.right()),
-      dtop = std::abs(wtop - srect.top()),
-      dbottom = std::abs(wbottom - srect.bottom());
-
-    // snap left?
-    if (dleft < snap_distance && dleft <= dright)
-      dx = srect.left();
-    // snap right?
-    else if (dright < snap_distance)
-      dx = srect.right() - frame.rect.width() + 1;
-
-    // snap top?
-    if (dtop < snap_distance && dtop <= dbottom)
-      dy = srect.top();
-    // snap bottom?
-    else if (dbottom < snap_distance)
-      dy = srect.bottom() - frame.rect.height() + 1;
+    RectList snaplist; // the list of rects we will try to snap to
+
+    // snap to the strut (and screen boundaries for xinerama)
+#ifdef    XINERAMA
+    if (screen->isXineramaActive() && blackbox->doXineramaSnapping())
+      snaplist.insert(snaplist.begin(),
+                      screen->allAvailableAreas().begin(),
+                      screen->allAvailableAreas().end());
+    else
+#endif // XINERAMA
+      if (! screen->doFullMax())
+        snaplist.push_back(screen->availableArea());
+    
+    // always snap to the screen edges
+    snaplist.push_back(screen->getRect());
+
+    RectList::const_iterator it, end = snaplist.end();
+    for (it = snaplist.begin(); it != end; ++it) {
+      const Rect &srect = *it;
+
+      // if we're not in the rectangle then don't snap to it.
+      if (! srect.intersects(Rect(wleft, wtop, frame.rect.width(),
+                                  frame.rect.height())))
+        continue;
+
+      int dleft = std::abs(wleft - srect.left()),
+         dright = std::abs(wright - srect.right()),
+           dtop = std::abs(wtop - srect.top()),
+        dbottom = std::abs(wbottom - srect.bottom());
+
+        // snap left?
+        if (dleft < snap_distance && dleft <= dright)
+          dx = srect.left();
+        // snap right?
+        else if (dright < snap_distance)
+          dx = srect.right() - frame.rect.width() + 1;
+
+        // snap top?
+        if (dtop < snap_distance && dtop <= dbottom)
+          dy = srect.top();
+        // snap bottom?
+        else if (dbottom < snap_distance)
+          dy = srect.bottom() - frame.rect.height() + 1;
+    }
   }
 
   if (screen->doOpaqueMove()) {
@@ -3277,7 +3312,7 @@ void BlackboxWindow::motionNotifyEvent(const XMotionEvent *me) {
     } else if ((functions & Func_Resize) &&
                (me->state & Button1Mask && (me->window == frame.right_grip ||
                                             me->window == frame.left_grip)) ||
-               (me->state & Button3Mask && me->state & Mod1Mask &&
+               (me->state & Button3Mask && me->state & ModMask &&
                 me->window == frame.window)) {
       unsigned int zones = screen->getResizeZones();
       Corner corner;
@@ -3672,16 +3707,8 @@ BWindowGroup::BWindowGroup(Blackbox *b, Window _group)
     return;
   }
 
-  /*
-    watch for destroy notify on the group window (in addition to
-    any other events we are looking for)
-
-    since some managed windows can also be window group controllers,
-    we need to make sure that we don't clobber the event mask for the
-    managed window
-  */
   XSelectInput(blackbox->getXDisplay(), group,
-               wattrib.your_event_mask | StructureNotifyMask);
+               PropertyChangeMask | FocusChangeMask | StructureNotifyMask);
 
   blackbox->saveGroupSearch(group, this);
 }
This page took 0.033308 seconds and 4 git commands to generate.