From b88f9b2a9e6a08cfb663b7177a9c037250d48fea Mon Sep 17 00:00:00 2001 From: rathnor Date: Fri, 31 Oct 2003 10:37:09 +0000 Subject: fix a number of positioning and sizing issues --- ChangeLog | 7 +++++++ src/Container.cc | 36 +++++++++++++++++++++++++++--------- src/FbWinFrame.cc | 20 ++++++++++++++------ src/IconButton.cc | 18 +++++++----------- src/Screen.cc | 12 ++++++------ src/SystemTray.hh | 4 +++- src/Toolbar.cc | 42 +++++++++++++++++++++++++++++++----------- src/ToolbarItem.hh | 4 +++- 8 files changed, 98 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index f2915a0..5570542 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ (Format: Year/Month/Day) Changes for 0.9.6: +*03/10/31: + * Fix iconbar button alignment and squash inactive tools (Simon) + - also fix a bunch of rounding issues + -> keep in mind that titlebar/iconbar width may not be exactly + divisible by the number of clients/labels in it + Container.cc FbWinFrame.cc SystemTray.hh Screen.cc ToolbarItem.hh + Toolbar.cc *03/10/30: * Fix handling of theme's with a zero handleWidth (Simon) FbWinFrame.cc diff --git a/src/Container.cc b/src/Container.cc index 3eda052..242a7f1 100644 --- a/src/Container.cc +++ b/src/Container.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Container.cc,v 1.6 2003/10/26 21:05:03 fluxgen Exp $ +// $Id: Container.cc,v 1.7 2003/10/31 10:37:09 rathnor Exp $ #include "Container.hh" @@ -30,7 +30,6 @@ Container::Container(const FbTk::FbWindow &parent): FbTk::FbWindow(parent, 0, 0, 1, 1, ExposureMask), m_selected(0), m_update_lock(false) { - FbTk::EventManager::instance()->add(*this, *this); } @@ -177,18 +176,37 @@ void Container::repositionItems() { ItemList::iterator it = m_item_list.begin(); const ItemList::iterator it_end = m_item_list.end(); - int next_x = 0; - for (; it != it_end; ++it, next_x += max_width_per_client) { + int borderW = m_item_list.front()->borderWidth(); + + int rounding_error = width() - ((maxWidthPerClient() + borderW)* m_item_list.size() - borderW); + + int next_x = -borderW; // zero so the border of the first shows + int extra = 0; + for (; it != it_end; ++it, next_x += max_width_per_client + borderW + extra) { + if (rounding_error != 0) { + --rounding_error; + extra = 1; + } else { + extra = 0; + } // resize each clients including border in size - (*it)->moveResize(next_x - (*it)->borderWidth(), - -(*it)->borderWidth(), - max_width_per_client - (*it)->borderWidth(), - height() + (*it)->borderWidth()); + (*it)->moveResize(next_x, + -borderW, + max_width_per_client + extra, + height()); (*it)->clear(); } } unsigned int Container::maxWidthPerClient() const { - return (size() == 0 ? width() : (width() + size()*m_item_list.front()->borderWidth())/size()); + int count = size(); + if (count == 0) + return width(); + else { + int borderW = m_item_list.front()->borderWidth(); + // there're count-1 borders to fit in with the windows + // -> 1 per window plus end + return (width() - (count - 1) * borderW) / count; + } } diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index 862ec29..1e3cb97 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWinFrame.cc,v 1.61 2003/10/30 20:27:51 rathnor Exp $ +// $Id: FbWinFrame.cc,v 1.62 2003/10/31 10:37:09 rathnor Exp $ #include "FbWinFrame.hh" @@ -229,6 +229,8 @@ void FbWinFrame::setFocus(bool newvalue) { if (m_focused == newvalue) return; + m_focused = newvalue; + if (currentLabel()) { if (newvalue) // focused renderButtonFocus(*m_current_label); @@ -236,10 +238,8 @@ void FbWinFrame::setFocus(bool newvalue) { renderButtonUnfocus(*m_current_label); } - m_focused = newvalue; - - renderButtons(); renderTitlebar(); + renderButtons(); // parent relative buttons -> need render after titlebar renderHandles(); } @@ -713,6 +713,7 @@ void FbWinFrame::redrawTitle() { return; int button_width = label().width()/m_labelbuttons.size(); + int rounding_error = label().width() - m_labelbuttons.size()*button_width; //!! TODO: bevel //int border_width = m_labelbuttons.front()->window().borderWidth(); int border_width = m_labelbuttons.size() != 0 ? @@ -720,13 +721,20 @@ void FbWinFrame::redrawTitle() { LabelList::iterator btn_it = m_labelbuttons.begin(); LabelList::iterator btn_it_end = m_labelbuttons.end(); + int extra = 0; for (unsigned int last_x = 0; btn_it != btn_it_end; - ++btn_it, last_x += button_width + border_width) { + ++btn_it, last_x += button_width + border_width + extra) { // since we add border width pixel we should remove // the same size for inside width so we can fit all buttons into label + if (rounding_error != 0) { + extra = 1; + --rounding_error; + } else + extra = 0; + (*btn_it)->moveResize(last_x - border_width, - border_width, - button_width, + button_width + extra, label().height() + border_width); if (isVisible()) (*btn_it)->clear(); diff --git a/src/IconButton.cc b/src/IconButton.cc index c6b876e..2f68ecf 100644 --- a/src/IconButton.cc +++ b/src/IconButton.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconButton.cc,v 1.8 2003/09/10 21:41:18 fluxgen Exp $ +// $Id: IconButton.cc,v 1.9 2003/10/31 10:37:09 rathnor Exp $ #include "IconButton.hh" @@ -118,7 +118,6 @@ void IconButton::resize(unsigned int width, unsigned int height) { } void IconButton::clear() { - FbTk::TextButton::clear(); setupWindow(); } @@ -152,7 +151,7 @@ void IconButton::update(FbTk::Subject *subj) { m_icon_pixmap.copy(hints->icon_pixmap); m_icon_pixmap.scale(m_icon_window.height(), m_icon_window.height()); - m_icon_window.setBackgroundPixmap(m_icon_pixmap.drawable()); + setBackgroundPixmap(m_icon_pixmap.drawable()); } else { // no icon pixmap m_icon_window.move(0, 0); @@ -186,15 +185,12 @@ void IconButton::update(FbTk::Subject *subj) { } void IconButton::setupWindow() { - - m_icon_window.clear(); - if (m_win.clientList().size() == 0) - return; - - setText(m_win.winClient().title()); - // draw with x offset and y offset - drawText(); + if (!m_win.clientList().empty()) { + setText(m_win.winClient().title()); + // draw with x offset and y offset + } + FbTk::TextButton::clear(); } void IconButton::drawText(int x, int y) { diff --git a/src/Screen.cc b/src/Screen.cc index 34173a3..1aa2e73 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Screen.cc,v 1.239 2003/10/28 17:39:59 rathnor Exp $ +// $Id: Screen.cc,v 1.240 2003/10/31 10:37:09 rathnor Exp $ #include "Screen.hh" @@ -328,17 +328,17 @@ BScreen::BScreen(FbTk::ResourceManager &rm, rootWindow().setCursor(XCreateFontCursor(disp, XC_left_ptr)); Fluxbox *fluxbox = Fluxbox::instance(); + // load this screens resources + fluxbox->load_rc(*this); + + FbTk::ThemeManager::instance().load(Fluxbox::instance()->getStyleFilename()); + // setup image cache engine m_image_control.reset(new FbTk::ImageControl(scrn, true, fluxbox->colorsPerChannel(), fluxbox->getCacheLife(), fluxbox->getCacheMax())); imageControl().installRootColormap(); root_colormap_installed = true; - // load this screens resources - fluxbox->load_rc(*this); - - FbTk::ThemeManager::instance().load(Fluxbox::instance()->getStyleFilename()); - #ifdef SLIT if (slit()) // this will load theme and reconfigure slit FbTk::ThemeManager::instance().loadTheme(slit()->theme()); diff --git a/src/SystemTray.hh b/src/SystemTray.hh index 82d163c..84d78fa 100644 --- a/src/SystemTray.hh +++ b/src/SystemTray.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: SystemTray.hh,v 1.2 2003/08/16 12:12:21 fluxgen Exp $ +// $Id: SystemTray.hh,v 1.3 2003/10/31 10:37:09 rathnor Exp $ #ifndef SYSTEMTRAY_HH #define SYSTEMTRAY_HH @@ -49,6 +49,8 @@ public: void show(); void hide(); + bool active() { return !m_clients.empty(); } + bool clientMessage(const XClientMessageEvent &event); void exposeEvent(XExposeEvent &event); void handleEvent(XEvent &event); diff --git a/src/Toolbar.cc b/src/Toolbar.cc index ded81e2..9b76ed6 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Toolbar.cc,v 1.125 2003/10/14 00:21:52 fluxgen Exp $ +// $Id: Toolbar.cc,v 1.126 2003/10/31 10:37:09 rathnor Exp $ #include "Toolbar.hh" @@ -832,7 +832,7 @@ void Toolbar::saveOnHead(int head) { void Toolbar::rearrangeItems() { if (m_resize_lock || screen().isShuttingdown() || - m_item_list.size() == 0) + m_item_list.empty()) return; // lock this m_resize_lock = true; @@ -841,37 +841,57 @@ void Toolbar::rearrangeItems() { ItemList::iterator item_it_end = m_item_list.end(); int fixed_width = 0; // combined size of all fixed items int fixed_items = 0; // number of fixed items + int relative_items = 0; for (; item_it != item_it_end; ++item_it) { - if ((*item_it)->type() == ToolbarItem::FIXED) { + if ((*item_it)->type() == ToolbarItem::FIXED && (*item_it)->active()) { fixed_width += (*item_it)->width() + (*item_it)->borderWidth()*2; fixed_items++; + } else if ((*item_it)->type() == ToolbarItem::RELATIVE && (*item_it)->active()) { + relative_items++; } } - // calculate what's going to be left over to the relative sized items + + // calculate what's going to be le ft over to the relative sized items int relative_width = 0; + int rounding_error = 0; if (fixed_items == 0) // no fixed items, then the rest is the entire width relative_width = width(); else { - const int relative_items = m_item_list.size() - fixed_items; if (relative_items == 0) relative_width = 0; - else // size left after fixed items / number of relative items + else { // size left after fixed items / number of relative items relative_width = (width() - fixed_width)/relative_items; + rounding_error = width() - fixed_width - relative_items*relative_width; + } } - // now move and resize the items - int next_x = m_item_list.front()->borderWidth(); + int next_x = 0; for (item_it = m_item_list.begin(); item_it != item_it_end; ++item_it) { + if (!(*item_it)->active()) { + (*item_it)->hide(); + continue; + } + + int borderW = (*item_it)->borderWidth(); + (*item_it)->show(); if ((*item_it)->type() == ToolbarItem::RELATIVE) { - (*item_it)->moveResize(next_x, 0, relative_width, height()); + int extra = 0; + if (rounding_error != 0) { // distribute rounding error over all relatives + extra = 1; + --rounding_error; + } + + (*item_it)->moveResize(next_x, -borderW, extra + relative_width-2*borderW, height()); } else { // fixed size - (*item_it)->moveResize(next_x, 0, + (*item_it)->moveResize(next_x, -borderW, (*item_it)->width(), height()); } - next_x += (*item_it)->width() + (*item_it)->borderWidth()*2; + next_x += (*item_it)->width() + borderW*2; } // unlock m_resize_lock = false; + frame.window.clear(); + } void Toolbar::deleteItems() { diff --git a/src/ToolbarItem.hh b/src/ToolbarItem.hh index dc60264..57088e0 100644 --- a/src/ToolbarItem.hh +++ b/src/ToolbarItem.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ToolbarItem.hh,v 1.2 2003/08/13 09:36:12 fluxgen Exp $ +// $Id: ToolbarItem.hh,v 1.3 2003/10/31 10:37:09 rathnor Exp $ #ifndef TOOLBARITEM_HH #define TOOLBARITEM_HH @@ -47,6 +47,8 @@ public: virtual unsigned int width() const = 0; virtual unsigned int height() const = 0; virtual unsigned int borderWidth() const = 0; + // some items might be there, but effectively empty, so shouldn't appear + virtual bool active() { return true; } void setType(Type type) { m_type = type; } Type type() const { return m_type; } -- cgit v0.11.2