diff options
author | simonb <simonb> | 2006-07-03 17:18:17 (GMT) |
---|---|---|
committer | simonb <simonb> | 2006-07-03 17:18:17 (GMT) |
commit | 12e80f3faf33240a09086198ef9ade997b089dd5 (patch) | |
tree | 3be0af37ae2723fc4694ca2f8adf31020ea941eb /src/FbWinFrame.cc | |
parent | 7d2f7740d1dddf1017c0610ccbdd3fe9527c29d8 (diff) | |
download | fluxbox-12e80f3faf33240a09086198ef9ade997b089dd5.zip fluxbox-12e80f3faf33240a09086198ef9ade997b089dd5.tar.bz2 |
fix gravity
Diffstat (limited to 'src/FbWinFrame.cc')
-rw-r--r-- | src/FbWinFrame.cc | 148 |
1 files changed, 77 insertions, 71 deletions
diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index eafcb79..339c53e 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc | |||
@@ -232,39 +232,31 @@ void FbWinFrame::shade() { | |||
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | void FbWinFrame::move(int x, int y, int win_gravity) { | 235 | void FbWinFrame::move(int x, int y) { |
236 | moveResize(x, y, 0, 0, true, false, win_gravity); | 236 | moveResize(x, y, 0, 0, true, false); |
237 | } | 237 | } |
238 | 238 | ||
239 | void FbWinFrame::resize(unsigned int width, unsigned int height, int win_gravity) { | 239 | void FbWinFrame::resize(unsigned int width, unsigned int height) { |
240 | moveResize(0, 0, width, height, false, true, win_gravity); | 240 | moveResize(0, 0, width, height, false, true); |
241 | } | 241 | } |
242 | 242 | ||
243 | // need an atomic moveresize where possible | 243 | // need an atomic moveresize where possible |
244 | void FbWinFrame::moveResizeForClient(int x, int y, unsigned int width, unsigned int height, bool move, bool resize, int win_gravity) { | 244 | void FbWinFrame::moveResizeForClient(int x, int y, unsigned int width, unsigned int height, bool move, bool resize, int win_gravity, unsigned int client_bw) { |
245 | // total height for frame | 245 | // total height for frame |
246 | 246 | ||
247 | unsigned int total_height = height; | 247 | if (resize) // these fns check if the elements are "on" |
248 | height += titlebarHeight() + handleHeight(); | ||
248 | 249 | ||
249 | if (resize) { | 250 | gravityTranslate(x, y, win_gravity, client_bw, false); |
250 | // having a titlebar = 1 extra border + titlebar height | 251 | setActiveGravity(win_gravity, client_bw); |
251 | if (m_use_titlebar) | 252 | moveResize(x, y, width, height, move, resize); |
252 | total_height += m_titlebar.height() + m_titlebar.borderWidth(); | ||
253 | // having a handle = 1 extra border + handle height | ||
254 | if (m_use_handle) | ||
255 | total_height += m_handle.height() + m_handle.borderWidth(); | ||
256 | } | ||
257 | moveResize(x, y, width, total_height, move, resize, win_gravity); | ||
258 | } | 253 | } |
259 | 254 | ||
260 | void FbWinFrame::resizeForClient(unsigned int width, unsigned int height, int win_gravity) { | 255 | void FbWinFrame::resizeForClient(unsigned int width, unsigned int height, int win_gravity, unsigned int client_bw) { |
261 | moveResizeForClient(0, 0, width, height, false, true, win_gravity); | 256 | moveResizeForClient(0, 0, width, height, false, true, win_gravity, client_bw); |
262 | } | 257 | } |
263 | 258 | ||
264 | void FbWinFrame::moveResize(int x, int y, unsigned int width, unsigned int height, bool move, bool resize, int win_gravity) { | 259 | void FbWinFrame::moveResize(int x, int y, unsigned int width, unsigned int height, bool move, bool resize) { |
265 | if(win_gravity!=ForgetGravity) { | ||
266 | gravityTranslate(x, y, width + m_window.borderWidth()*2, height + m_window.borderWidth()*2, win_gravity, false); | ||
267 | } | ||
268 | if (move && x == window().x() && y == window().y()) | 260 | if (move && x == window().x() && y == window().y()) |
269 | move = false; | 261 | move = false; |
270 | 262 | ||
@@ -946,6 +938,10 @@ void FbWinFrame::reconfigure() { | |||
946 | if (m_tab_container.empty()) | 938 | if (m_tab_container.empty()) |
947 | return; | 939 | return; |
948 | 940 | ||
941 | int grav_x=0, grav_y=0; | ||
942 | // negate gravity | ||
943 | gravityTranslate(grav_x, grav_y, -m_active_gravity, m_active_orig_client_bw, false); | ||
944 | |||
949 | m_bevel = theme().bevelWidth(); | 945 | m_bevel = theme().bevelWidth(); |
950 | // reconfigure can't set borderwidth, as it doesn't know | 946 | // reconfigure can't set borderwidth, as it doesn't know |
951 | // if it's meant to be borderless or not | 947 | // if it's meant to be borderless or not |
@@ -1035,6 +1031,10 @@ void FbWinFrame::reconfigure() { | |||
1035 | m_window.width(), client_height); | 1031 | m_window.width(), client_height); |
1036 | } | 1032 | } |
1037 | 1033 | ||
1034 | gravityTranslate(grav_x, grav_y, m_active_gravity, m_active_orig_client_bw, false); | ||
1035 | // if the location changes, shift it | ||
1036 | if (grav_x != 0 || grav_y != 0) | ||
1037 | move(grav_x + x(), grav_y + y()); | ||
1038 | 1038 | ||
1039 | // render the theme | 1039 | // render the theme |
1040 | if (isVisible()) { | 1040 | if (isVisible()) { |
@@ -1532,6 +1532,12 @@ void FbWinFrame::applyTabContainer() { | |||
1532 | 1532 | ||
1533 | void FbWinFrame::setBorderWidth(unsigned int border_width) { | 1533 | void FbWinFrame::setBorderWidth(unsigned int border_width) { |
1534 | int bw_changes = 0; | 1534 | int bw_changes = 0; |
1535 | |||
1536 | int grav_x=0, grav_y=0; | ||
1537 | // negate gravity | ||
1538 | gravityTranslate(grav_x, grav_y, -m_active_gravity, m_active_orig_client_bw, false); | ||
1539 | |||
1540 | |||
1535 | // we need to change the size of the window | 1541 | // we need to change the size of the window |
1536 | // if the border width changes... | 1542 | // if the border width changes... |
1537 | if (m_use_titlebar) | 1543 | if (m_use_titlebar) |
@@ -1570,6 +1576,12 @@ void FbWinFrame::setBorderWidth(unsigned int border_width) { | |||
1570 | 1576 | ||
1571 | if (m_tabmode == EXTERNAL) | 1577 | if (m_tabmode == EXTERNAL) |
1572 | alignTabs(); | 1578 | alignTabs(); |
1579 | |||
1580 | gravityTranslate(grav_x, grav_y, m_active_gravity, m_active_orig_client_bw, false); | ||
1581 | // if the location changes, shift it | ||
1582 | if (grav_x != 0 || grav_y != 0) | ||
1583 | move(grav_x + x(), grav_y + y()); | ||
1584 | |||
1573 | } | 1585 | } |
1574 | 1586 | ||
1575 | void FbWinFrame::applyFocusLabel(FbTk::TextButton &button) { | 1587 | void FbWinFrame::applyFocusLabel(FbTk::TextButton &button) { |
@@ -1635,11 +1647,7 @@ private: | |||
1635 | // this function translates its arguments according to win_gravity | 1647 | // this function translates its arguments according to win_gravity |
1636 | // if win_gravity is negative, it does an inverse translation | 1648 | // if win_gravity is negative, it does an inverse translation |
1637 | // This function should be used when a window is mapped/unmapped/pos configured | 1649 | // This function should be used when a window is mapped/unmapped/pos configured |
1638 | void FbWinFrame::gravityTranslate(int &x, int &y, int win_gravity, bool move_frame) { | 1650 | void FbWinFrame::gravityTranslate(int &x, int &y, int win_gravity, unsigned int client_bw, bool move_frame) { |
1639 | gravityTranslate(x, y, m_window.width(), m_window.height(), win_gravity, move_frame); | ||
1640 | } | ||
1641 | //use width and height given instead of the real values, allows figuring out where to place a window before doing a moveResize | ||
1642 | void FbWinFrame::gravityTranslate(int &x, int &y, unsigned int width, unsigned int height, int win_gravity, bool move_frame) { | ||
1643 | bool invert = false; | 1651 | bool invert = false; |
1644 | if (win_gravity < 0) { | 1652 | if (win_gravity < 0) { |
1645 | invert = true; | 1653 | invert = true; |
@@ -1657,6 +1665,9 @@ void FbWinFrame::gravityTranslate(int &x, int &y, unsigned int width, unsigned i | |||
1657 | * have been if there was no frame. | 1665 | * have been if there was no frame. |
1658 | * Hope that makes enough sense. | 1666 | * Hope that makes enough sense. |
1659 | * | 1667 | * |
1668 | * NOTE: the gravity calculations are INDEPENDENT of the client | ||
1669 | * window width/height. | ||
1670 | * | ||
1660 | * If you get confused with the calculations, draw a picture. | 1671 | * If you get confused with the calculations, draw a picture. |
1661 | * | 1672 | * |
1662 | */ | 1673 | */ |
@@ -1664,60 +1675,54 @@ void FbWinFrame::gravityTranslate(int &x, int &y, unsigned int width, unsigned i | |||
1664 | // We calculate offsets based on the gravity and frame aspects | 1675 | // We calculate offsets based on the gravity and frame aspects |
1665 | // and at the end apply those offsets +ve or -ve depending on 'invert' | 1676 | // and at the end apply those offsets +ve or -ve depending on 'invert' |
1666 | 1677 | ||
1678 | // These will be set to the resulting offsets for adjusting the frame position | ||
1667 | int x_offset = 0; | 1679 | int x_offset = 0; |
1668 | int y_offset = 0; | 1680 | int y_offset = 0; |
1669 | 1681 | ||
1670 | /* win_gravity: placed at the reference point | 1682 | // These are the amount that the frame is larger than the client window |
1671 | * StaticGravity the left top corner of the client window | 1683 | // Note that the client window's x,y is offset by it's borderWidth, which |
1672 | * NorthWestGravity the left top corner of the frame window | 1684 | // is removed by fluxbox, so the gravity needs to account for this change |
1673 | * NorthGravity the center of the frame window's top side | ||
1674 | * NorthEastGravity the right top corner of the frame window | ||
1675 | * EastGravity the center of the frame window's right side | ||
1676 | * SouthEastGravity the right bottom corner of the frame window | ||
1677 | * SouthGravity the center of the frame window's bottom side | ||
1678 | * SouthWestGravity the left bottom corner of the frame window | ||
1679 | * WestGravity the center of the frame window's left side | ||
1680 | * CenterGravity the center of the frame window | ||
1681 | */ | ||
1682 | |||
1683 | 1685 | ||
1684 | //vertical offset | 1686 | // unsigned int width_offset = 0; // no side decorations |
1685 | //North Gravities don't require a vertical offset | ||
1686 | //South Gravities | ||
1687 | if (win_gravity==SouthWestGravity || win_gravity==SouthGravity || | ||
1688 | win_gravity==SouthEastGravity) { | ||
1689 | //We start on the frame so going the full height would take us one pixel past the edge of the frame | ||
1690 | y_offset-=height-1; | ||
1691 | } | ||
1692 | 1687 | ||
1693 | //vertical centering | 1688 | // these functions already check if the title/handle is used |
1694 | if (win_gravity==WestGravity || win_gravity==CenterGravity || | 1689 | int height_offset = - titlebarHeight() - handleHeight(); |
1695 | win_gravity==EastGravity) { | ||
1696 | y_offset-=height/2; | ||
1697 | } | ||
1698 | 1690 | ||
1699 | //horizontal offset | 1691 | int bw_diff = client_bw - m_window.borderWidth(); |
1700 | //West Gravities don't require a horizontal offset | ||
1701 | //East Gravities | ||
1702 | if (win_gravity==NorthEastGravity || win_gravity==EastGravity || | ||
1703 | win_gravity==SouthEastGravity ) { | ||
1704 | //Starting on the frame so offset of one width would end up one pixel beyond the border | ||
1705 | x_offset-=width-1; | ||
1706 | } | ||
1707 | //horizontal centering | ||
1708 | if (win_gravity==NorthGravity || win_gravity==CenterGravity || | ||
1709 | win_gravity==SouthGravity ) { | ||
1710 | x_offset-=width/2; | ||
1711 | } | ||
1712 | 1692 | ||
1713 | if( win_gravity==StaticGravity ) { | 1693 | // mostly no X offset, since we don't have extra frame on the sides |
1714 | if (m_use_titlebar) | 1694 | switch (win_gravity) { |
1715 | y_offset -= m_titlebar.height() + m_titlebar.borderWidth(); | 1695 | case NorthEastGravity: |
1716 | x_offset -= m_window.borderWidth(); | 1696 | x_offset += bw_diff; |
1717 | y_offset -= m_window.borderWidth(); | 1697 | case NorthGravity: |
1698 | x_offset += bw_diff; | ||
1699 | case NorthWestGravity: | ||
1700 | // no offset, since the top point is still the same | ||
1701 | break; | ||
1702 | case SouthEastGravity: | ||
1703 | x_offset += bw_diff; | ||
1704 | case SouthGravity: | ||
1705 | x_offset += bw_diff; | ||
1706 | case SouthWestGravity: | ||
1707 | // window shifted down by height of titlebar, and the handle | ||
1708 | // since that's necessary to get the bottom of the frame | ||
1709 | // all the way up | ||
1710 | y_offset += 2*bw_diff + height_offset; | ||
1711 | break; | ||
1712 | case EastGravity: | ||
1713 | x_offset += bw_diff; | ||
1714 | case CenterGravity: | ||
1715 | x_offset += bw_diff; | ||
1716 | case WestGravity: | ||
1717 | // these centered ones are a little more interesting | ||
1718 | y_offset += bw_diff + height_offset/2; | ||
1719 | break; | ||
1720 | case StaticGravity: | ||
1721 | x_offset += bw_diff; | ||
1722 | y_offset += -titlebarHeight() + bw_diff; | ||
1723 | break; | ||
1718 | } | 1724 | } |
1719 | 1725 | ||
1720 | |||
1721 | if (invert) { | 1726 | if (invert) { |
1722 | x_offset = -x_offset; | 1727 | x_offset = -x_offset; |
1723 | y_offset = -y_offset; | 1728 | y_offset = -y_offset; |
@@ -1725,6 +1730,7 @@ void FbWinFrame::gravityTranslate(int &x, int &y, unsigned int width, unsigned i | |||
1725 | 1730 | ||
1726 | x += x_offset; | 1731 | x += x_offset; |
1727 | y += y_offset; | 1732 | y += y_offset; |
1733 | |||
1728 | if (move_frame && (x_offset != 0 || y_offset != 0)) { | 1734 | if (move_frame && (x_offset != 0 || y_offset != 0)) { |
1729 | move(x, y); | 1735 | move(x, y); |
1730 | } | 1736 | } |