From: Dana Jansens Date: Sun, 28 Apr 2002 00:11:19 +0000 (+0000) Subject: added UnderMouse windwo placement. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=20cd70c4665de85ffe3a04f9aa47acb9666e4f39;p=chaz%2Fopenbox added UnderMouse windwo placement. --- diff --git a/CHANGELOG b/CHANGELOG index 0a1e90fe..21c1f4c7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ Changelog for Openbox: +1.1.0: + * added UnderMouse window placement algorithm/type. (Ben Jansens) + 1.0.0: * maximizing windows takes the slit into account as well as the toolbar when 'Full Maximization' is off (Ben Jansens) diff --git a/nls/C/Configmenu.m b/nls/C/Configmenu.m index 741e468d..1fcaba84 100644 --- a/nls/C/Configmenu.m +++ b/nls/C/Configmenu.m @@ -30,6 +30,8 @@ $ #Cascade # Cascade Placement $ #BestFit # Best Fit Placement +$ #UnderMouse +# Under Mouse Placement $ #LeftRight # Left to Right $ #RightLeft diff --git a/src/Configmenu.cc b/src/Configmenu.cc index 0bef3d2e..e11c7c38 100644 --- a/src/Configmenu.cc +++ b/src/Configmenu.cc @@ -237,6 +237,9 @@ Configmenu::Placementmenu::Placementmenu(Configmenu *cm) : "Cascade Placement"), BScreen::CascadePlacement); insert(i18n->getMessage(ConfigmenuSet, ConfigmenuBestFit, "Best Fit Placement"), BScreen::BestFitPlacement); + insert(i18n->getMessage(ConfigmenuSet, ConfigmenuUnderMouse, + "Under Mouse Placement"), + BScreen::UnderMousePlacement); insert(i18n->getMessage(ConfigmenuSet, ConfigmenuLeftRight, "Left to Right"), BScreen::LeftRight); insert(i18n->getMessage(ConfigmenuSet, ConfigmenuRightLeft, @@ -251,34 +254,27 @@ Configmenu::Placementmenu::Placementmenu(Configmenu *cm) : } void Configmenu::Placementmenu::setValues() { - switch (configmenu->screen.placementPolicy()) { - case BScreen::RowSmartPlacement: - setItemSelected(0, True); - break; - - case BScreen::ColSmartPlacement: - setItemSelected(1, True); - break; - - case BScreen::CascadePlacement: - setItemSelected(2, True); - break; - - case BScreen::BestFitPlacement: - setItemSelected(3, True); - break; - } - - Bool rl = (configmenu->screen.rowPlacementDirection() == + const int p = configmenu->screen.placementPolicy(); + setItemSelected(0, p == BScreen::RowSmartPlacement); + setItemSelected(1, p == BScreen::ColSmartPlacement); + setItemSelected(2, p == BScreen::CascadePlacement); + setItemSelected(3, p == BScreen::BestFitPlacement); + setItemSelected(4, p == BScreen::UnderMousePlacement); + + bool rl = (configmenu->screen.rowPlacementDirection() == BScreen::LeftRight), tb = (configmenu->screen.colPlacementDirection() == BScreen::TopBottom); - setItemSelected(4, rl); - setItemSelected(5, !rl); + setItemSelected(5, rl); + setItemEnabled(5, p != BScreen::UnderMousePlacement); + setItemSelected(6, !rl); + setItemEnabled(6, p != BScreen::UnderMousePlacement); - setItemSelected(6, tb); - setItemSelected(7, !tb); + setItemSelected(7, tb); + setItemEnabled(7, p != BScreen::UnderMousePlacement); + setItemSelected(8, !tb); + setItemEnabled(8, p != BScreen::UnderMousePlacement); } void Configmenu::Placementmenu::reconfigure() { @@ -298,74 +294,39 @@ void Configmenu::Placementmenu::itemSelected(int button, int index) { switch (item->function()) { case BScreen::RowSmartPlacement: configmenu->screen.setPlacementPolicy(item->function()); - - setItemSelected(0, True); - setItemSelected(1, False); - setItemSelected(2, False); - setItemSelected(3, False); - break; case BScreen::ColSmartPlacement: configmenu->screen.setPlacementPolicy(item->function()); - - setItemSelected(0, False); - setItemSelected(1, True); - setItemSelected(2, False); - setItemSelected(3, False); - break; case BScreen::CascadePlacement: configmenu->screen.setPlacementPolicy(item->function()); - - setItemSelected(0, False); - setItemSelected(1, False); - setItemSelected(2, True); - setItemSelected(3, False); - break; case BScreen::BestFitPlacement: configmenu->screen.setPlacementPolicy(item->function()); + break; - setItemSelected(0, False); - setItemSelected(1, False); - setItemSelected(2, False); - setItemSelected(3, True); - + case BScreen::UnderMousePlacement: + configmenu->screen.setPlacementPolicy(item->function()); break; case BScreen::LeftRight: configmenu->screen.setRowPlacementDirection(BScreen::LeftRight); - - setItemSelected(4, True); - setItemSelected(5, False); - break; case BScreen::RightLeft: configmenu->screen.setRowPlacementDirection(BScreen::RightLeft); - - setItemSelected(4, False); - setItemSelected(5, True); - break; case BScreen::TopBottom: configmenu->screen.setColPlacementDirection(BScreen::TopBottom); - - setItemSelected(6, True); - setItemSelected(7, False); - break; case BScreen::BottomTop: configmenu->screen.setColPlacementDirection(BScreen::BottomTop); - - setItemSelected(6, False); - setItemSelected(7, True); - break; } + setValues(); } diff --git a/src/Screen.cc b/src/Screen.cc index 43ab26b9..a5c6c793 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -1026,6 +1026,7 @@ void BScreen::setPlacementPolicy(int p) { case CascadePlacement: placement = "CascadePlacement"; break; case BestFitPlacement: placement = "BestFitPlacement"; break; case ColSmartPlacement: placement = "ColSmartPlacement"; break; + case UnderMousePlacement: placement = "UnderMousePlacement"; break; default: case RowSmartPlacement: placement = "RowSmartPlacement"; break; } @@ -1220,7 +1221,7 @@ void BScreen::load() { if (config.getValue(rname.str(), rclass.str(), s)) { if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length())) resource.row_direction = RightLeft; - else if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length())) + else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length())) resource.row_direction = LeftRight; } else resource.row_direction = LeftRight; @@ -1231,7 +1232,7 @@ void BScreen::load() { if (config.getValue(rname.str(), rclass.str(), s)) { if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length())) resource.col_direction = BottomTop; - else if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length())) + else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length())) resource.col_direction = TopBottom; } else resource.col_direction = TopBottom; @@ -1272,7 +1273,7 @@ void BScreen::load() { s.length())) { resource.sloppy_focus = true; resource.auto_raise = true; - } else if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) { + } else { //if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) { resource.sloppy_focus = true; resource.auto_raise = false; } @@ -1299,7 +1300,9 @@ void BScreen::load() { resource.placement_policy = ColSmartPlacement; else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length())) resource.placement_policy = BestFitPlacement; - else if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length())) + else if (0 == strncasecmp(s.c_str(), "UnderMousePlacement", s.length())) + resource.placement_policy = UnderMousePlacement; + else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length())) resource.placement_policy = CascadePlacement; } else resource.placement_policy = CascadePlacement; @@ -1323,7 +1326,7 @@ void BScreen::load() { if (config.getValue(rname.str(), rclass.str(), s)) { if (strncasecmp(s.c_str(), "European", s.length())) resource.date_format = B_EuropeanDate; - else if (strncasecmp(s.c_str(), "American", s.length())) + else //if (strncasecmp(s.c_str(), "American", s.length())) resource.date_format = B_AmericanDate; } else resource.date_format = B_AmericanDate; diff --git a/src/Screen.h b/src/Screen.h index fc285319..3b536d27 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -312,7 +312,8 @@ public: void updateNetizenWindowLower(Window); enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement, - BestFitPlacement, LeftRight, RightLeft, TopBottom, BottomTop }; + BestFitPlacement, UnderMousePlacement, + LeftRight, RightLeft, TopBottom, BottomTop }; enum { LeftJustify = 1, RightJustify, CenterJustify }; enum { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet }; enum { Restart = 1, RestartOther, Exit, Shutdown, Execute, Reconfigure, diff --git a/src/Workspace.cc b/src/Workspace.cc index 39210743..c1a0d602 100644 --- a/src/Workspace.cc +++ b/src/Workspace.cc @@ -444,6 +444,26 @@ Point *Workspace::bestFitPlacement(const Size &win_size, const Rect &space) { return NULL; //fall back to cascade } +Point *Workspace::underMousePlacement(const Size &win_size, const Rect &space) { + Point *pt; + + int x, y, rx, ry; + Window c, r; + unsigned int m; + XQueryPointer(screen.getOpenbox().getXDisplay(), screen.getRootWindow(), + &r, &c, &rx, &ry, &x, &y, &m); + pt = new Point(rx - win_size.w() / 2, ry - win_size.h() / 2); + + if (pt->x() < space.x()) + pt->setX(space.x()); + if (pt->y() < space.y()) + pt->setY(space.y()); + if (pt->x() + win_size.w() > space.x() + space.w()) + pt->setX(space.x() + space.w() - win_size.w()); + if (pt->y() + win_size.h() > space.y() + space.h()) + pt->setY(space.y() + space.h() - win_size.h()); + return pt; +} Point *Workspace::rowSmartPlacement(const Size &win_size, const Rect &space) { bool placed=false; @@ -587,8 +607,8 @@ Point *const Workspace::cascadePlacement(const OpenboxWindow &win, void Workspace::placeWindow(OpenboxWindow &win) { Rect space = screen.availableArea(); - const Size window_size(win.area().w()+screen.getBorderWidth() * 4, - win.area().h()+screen.getBorderWidth() * 4); + const Size window_size(win.area().w()+screen.getBorderWidth() * 2, + win.area().h()+screen.getBorderWidth() * 2); Point *place = NULL; LinkedListIterator it(windowList); @@ -602,6 +622,9 @@ void Workspace::placeWindow(OpenboxWindow &win) { case BScreen::ColSmartPlacement: place = colSmartPlacement(window_size, space); break; + case BScreen::UnderMousePlacement: + place = underMousePlacement(window_size, space); + break; } // switch if (place == NULL) diff --git a/src/Workspace.h b/src/Workspace.h index 12d4dfc2..ab8dad3f 100644 --- a/src/Workspace.h +++ b/src/Workspace.h @@ -48,6 +48,7 @@ private: protected: void placeWindow(OpenboxWindow &); Point *bestFitPlacement(const Size &win_size, const Rect &space); + Point *underMousePlacement(const Size &win_size, const Rect &space); Point *rowSmartPlacement(const Size &win_size, const Rect &space); Point *colSmartPlacement(const Size &win_size, const Rect &space); Point *const cascadePlacement(const OpenboxWindow &window, const Rect &space);