diff options
Diffstat (limited to 'src/Screen.cc')
-rw-r--r-- | src/Screen.cc | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/src/Screen.cc b/src/Screen.cc index 80466df..574c51a 100644 --- a/src/Screen.cc +++ b/src/Screen.cc | |||
@@ -22,7 +22,7 @@ | |||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
24 | 24 | ||
25 | // $Id: Screen.cc,v 1.127 2003/04/18 12:51:14 fluxgen Exp $ | 25 | // $Id: Screen.cc,v 1.128 2003/04/20 12:21:35 rathnor Exp $ |
26 | 26 | ||
27 | 27 | ||
28 | #include "Screen.hh" | 28 | #include "Screen.hh" |
@@ -1618,6 +1618,95 @@ void BScreen::setFocusedWindow(WinClient &winclient) { | |||
1618 | } | 1618 | } |
1619 | } | 1619 | } |
1620 | 1620 | ||
1621 | void BScreen::dirFocus(FluxboxWindow &win, FocusDir dir) { | ||
1622 | // change focus to the window in direction dir from the given window | ||
1623 | |||
1624 | // we scan through the list looking for the window that is "closest" | ||
1625 | // in the given direction | ||
1626 | |||
1627 | FluxboxWindow *foundwin = 0; | ||
1628 | int weight = 999999, exposure = 0; // extreme values | ||
1629 | int borderW = getBorderWidth(), | ||
1630 | top = win.getYFrame(), | ||
1631 | bottom = win.getYFrame() + win.getHeight() + 2*borderW, | ||
1632 | left = win.getXFrame(), | ||
1633 | right = win.getXFrame() + win.getWidth() + 2*borderW; | ||
1634 | |||
1635 | Workspace::Windows &wins = getCurrentWorkspace()->getWindowList(); | ||
1636 | Workspace::Windows::iterator it = wins.begin(); | ||
1637 | for (; it != wins.end(); ++it) { | ||
1638 | if ((*it) == &win) continue; // skip self | ||
1639 | |||
1640 | // we check things against an edge, and within the bounds (draw a picture) | ||
1641 | int edge=0, upper=0, lower=0, oedge=0, oupper=0, olower=0; | ||
1642 | |||
1643 | int otop = (*it)->getYFrame(), | ||
1644 | obottom = (*it)->getYFrame() + (*it)->getHeight() + 2*borderW, | ||
1645 | oleft = (*it)->getXFrame(), | ||
1646 | oright = (*it)->getXFrame() + (*it)->getWidth() + 2*borderW; | ||
1647 | // check if they intersect | ||
1648 | switch (dir) { | ||
1649 | case FOCUSUP: | ||
1650 | edge = obottom; | ||
1651 | oedge = bottom; | ||
1652 | upper = left; | ||
1653 | oupper = oleft; | ||
1654 | lower = right; | ||
1655 | olower = oright; | ||
1656 | break; | ||
1657 | case FOCUSDOWN: | ||
1658 | edge = top; | ||
1659 | oedge = otop; | ||
1660 | upper = left; | ||
1661 | oupper = oleft; | ||
1662 | lower = right; | ||
1663 | olower = oright; | ||
1664 | break; | ||
1665 | case FOCUSLEFT: | ||
1666 | edge = oright; | ||
1667 | oedge = right; | ||
1668 | upper = top; | ||
1669 | oupper = otop; | ||
1670 | lower = bottom; | ||
1671 | olower = obottom; | ||
1672 | break; | ||
1673 | case FOCUSRIGHT: | ||
1674 | edge = left; | ||
1675 | oedge = oleft; | ||
1676 | upper = top; | ||
1677 | oupper = otop; | ||
1678 | lower = bottom; | ||
1679 | olower = obottom; | ||
1680 | break; | ||
1681 | } | ||
1682 | |||
1683 | if (oedge < edge) continue; // not in the right direction | ||
1684 | if (olower <= upper || oupper >= lower) { | ||
1685 | // outside our horz bounds, get a heavy weight penalty | ||
1686 | int myweight = 100000 + oedge - edge + abs(upper-oupper)+abs(lower-olower); | ||
1687 | if (myweight < weight) { | ||
1688 | foundwin = *it; | ||
1689 | exposure = 0; | ||
1690 | weight = myweight; | ||
1691 | } | ||
1692 | } else if ((oedge - edge) < weight) { | ||
1693 | foundwin = *it; | ||
1694 | weight = oedge - edge; | ||
1695 | exposure = ((lower < olower)?lower:olower) - ((upper > oupper)?upper:oupper); | ||
1696 | } else if (foundwin && oedge - edge == weight) { | ||
1697 | int myexp = ((lower < olower)?lower:olower) - ((upper > oupper)?upper:oupper); | ||
1698 | if (myexp > exposure) { | ||
1699 | foundwin = *it; | ||
1700 | // weight is same | ||
1701 | exposure = myexp; | ||
1702 | } | ||
1703 | } // else not improvement | ||
1704 | } | ||
1705 | |||
1706 | if (foundwin) | ||
1707 | foundwin->setInputFocus(); | ||
1708 | } | ||
1709 | |||
1621 | void BScreen::initMenu() { | 1710 | void BScreen::initMenu() { |
1622 | I18n *i18n = I18n::instance(); | 1711 | I18n *i18n = I18n::instance(); |
1623 | 1712 | ||