all repos — fluxbox @ 63d9d695be8156530fabf1d2e033225bfa71bab1

custom fork of the fluxbox windowmanager

Refactor FbWinFrame

FbWinFrame is now simpler to read due to less overall noise.
Mathias Gumz akira@fluxbox.org
commit

63d9d695be8156530fabf1d2e033225bfa71bab1

parent

0d8a3dfb6b47753577881b11f25b2a95163ce158

2 files changed, 317 insertions(+), 515 deletions(-)

jump to
M src/FbWinFrame.ccsrc/FbWinFrame.cc

@@ -21,6 +21,13 @@ // DEALINGS IN THE SOFTWARE.

#include "FbWinFrame.hh" +#include "Keys.hh" +#include "FbWinFrameTheme.hh" +#include "Screen.hh" +#include "FocusableTheme.hh" +#include "IconButton.hh" +#include "RectangleUtil.hh" + #include "FbTk/ImageControl.hh" #include "FbTk/EventManager.hh" #include "FbTk/App.hh"

@@ -31,16 +38,9 @@ #include "FbTk/CompareEqual.hh"

#include "FbTk/TextUtils.hh" #include "FbTk/STLUtil.hh" -#include "FbWinFrameTheme.hh" -#include "Screen.hh" -#include "FocusableTheme.hh" -#include "IconButton.hh" -#include "RectangleUtil.hh" +#include <X11/X.h> #include <algorithm> -#include <X11/X.h> - -#include "Keys.hh" using std::max; using std::mem_fun;

@@ -48,6 +48,63 @@ using std::string;

using FbTk::STLUtil::forAll; +namespace { + +enum { UNFOCUS = 0, FOCUS, PRESSED }; + +const long _mask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask; + +const struct { + FbWinFrame::TabPlacement where; + FbTk::Orientation orient; + FbTk::Container::Alignment align; + bool is_horizontal; +} _values[] = { + { /* unused */ }, + { FbWinFrame::TOPLEFT, FbTk::ROT0, FbTk::Container::LEFT, true }, + { FbWinFrame::TOP, FbTk::ROT0, FbTk::Container::CENTER, true }, + { FbWinFrame::TOPRIGHT, FbTk::ROT0, FbTk::Container::RIGHT, true }, + { FbWinFrame::BOTTOMLEFT, FbTk::ROT0, FbTk::Container::LEFT, true }, + { FbWinFrame::BOTTOM, FbTk::ROT0, FbTk::Container::CENTER, true }, + { FbWinFrame::BOTTOMRIGHT,FbTk::ROT0, FbTk::Container::RIGHT, true }, + { FbWinFrame::LEFTTOP, FbTk::ROT270, FbTk::Container::RIGHT, false }, + { FbWinFrame::LEFT, FbTk::ROT270, FbTk::Container::CENTER, false }, + { FbWinFrame::LEFTBOTTOM, FbTk::ROT270, FbTk::Container::LEFT, false }, + { FbWinFrame::RIGHTTOP, FbTk::ROT90, FbTk::Container::LEFT, false }, + { FbWinFrame::RIGHT, FbTk::ROT90, FbTk::Container::LEFT, false }, + { FbWinFrame::RIGHTBOTTOM,FbTk::ROT90, FbTk::Container::LEFT, false }, +}; + +/// renders to pixmap or sets color +void render(FbTk::Color &col, Pixmap &pm, unsigned int width, unsigned int height, + const FbTk::Texture &tex, + FbTk::ImageControl& ictl, + FbTk::Orientation orient = FbTk::ROT0) { + + Pixmap tmp = pm; + if (!tex.usePixmap()) { + pm = None; + col = tex.color(); + } else { + pm = ictl.renderImage(width, height, tex, orient); + } + + if (tmp) + ictl.removeImage(tmp); + +} + +void bg_pm_or_color(FbTk::FbWindow& win, Pixmap& pm, FbTk::Color& color) { + if (pm) { + win.setBackgroundPixmap(pm); + } else { + win.setBackgroundColor(color); + } +} + + +} // end anonymous + FbWinFrame::FbWinFrame(BScreen &screen, unsigned int client_depth, WindowState &state, FocusableTheme<FbWinFrameTheme> &theme):

@@ -55,61 +112,41 @@ m_screen(screen),

m_theme(theme), m_imagectrl(screen.imageControl()), m_state(state), - m_window(theme->screenNum(), state.x, state.y, state.width, state.height, - ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | EnterWindowMask | - LeaveWindowMask, true, false, - client_depth, InputOutput, - ((client_depth == 32) && (screen.rootWindow().depth() == 32) ? screen.rootWindow().visual() : CopyFromParent), - ((client_depth == 32) && (screen.rootWindow().depth() == 32) ? screen.rootWindow().colormap() : CopyFromParent)), + m_window(theme->screenNum(), state.x, state.y, state.width, state.height, _mask, true, false, + client_depth, InputOutput, + ((client_depth == 32) && (screen.rootWindow().depth() == 32) ? screen.rootWindow().visual() : CopyFromParent), + ((client_depth == 32) && (screen.rootWindow().depth() == 32) ? screen.rootWindow().colormap() : CopyFromParent)), m_layeritem(window(), *screen.layerManager().getLayer(ResourceLayer::NORMAL)), - m_titlebar(m_window, 0, 0, 100, 16, - ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | ExposureMask | - EnterWindowMask | LeaveWindowMask, - false, false, screen.rootWindow().decorationDepth(), InputOutput, - screen.rootWindow().decorationVisual(), - screen.rootWindow().decorationColormap()), + m_titlebar(m_window, 0, 0, 100, 16, _mask, false, false, + screen.rootWindow().decorationDepth(), InputOutput, + screen.rootWindow().decorationVisual(), + screen.rootWindow().decorationColormap()), m_tab_container(m_titlebar), m_label(m_titlebar, m_theme->font(), FbTk::BiDiString("")), - m_handle(m_window, 0, 0, 100, 5, - ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | ExposureMask | - EnterWindowMask | LeaveWindowMask, - false, false, screen.rootWindow().decorationDepth(), InputOutput, - screen.rootWindow().decorationVisual(), - screen.rootWindow().decorationColormap()), - m_grip_right(m_handle, 0, 0, 10, 4, - ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | ExposureMask | - EnterWindowMask | LeaveWindowMask, - false, false, screen.rootWindow().decorationDepth(), InputOutput, - screen.rootWindow().decorationVisual(), - screen.rootWindow().decorationColormap()), - m_grip_left(m_handle, 0, 0, 10, 4, - ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | ExposureMask | - EnterWindowMask | LeaveWindowMask, - false, false, screen.rootWindow().decorationDepth(), InputOutput, - screen.rootWindow().decorationVisual(), - screen.rootWindow().decorationColormap()), - m_clientarea(m_window, 0, 0, 100, 100, - ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | ExposureMask | - EnterWindowMask | LeaveWindowMask), + m_handle(m_window, 0, 0, 100, 5, _mask, false, false, + screen.rootWindow().decorationDepth(), InputOutput, + screen.rootWindow().decorationVisual(), + screen.rootWindow().decorationColormap()), + m_grip_right(m_handle, 0, 0, 10, 4, _mask, false, false, + screen.rootWindow().decorationDepth(), InputOutput, + screen.rootWindow().decorationVisual(), + screen.rootWindow().decorationColormap()), + m_grip_left(m_handle, 0, 0, 10, 4, _mask, false, false, + screen.rootWindow().decorationDepth(), InputOutput, + screen.rootWindow().decorationVisual(), + screen.rootWindow().decorationColormap()), + m_clientarea(m_window, 0, 0, 100, 100, _mask), m_bevel(1), m_use_titlebar(true), m_use_tabs(true), m_use_handle(true), m_visible(false), - m_button_pm(0), m_tabmode(screen.getDefaultInternalTabs()?INTERNAL:EXTERNAL), m_active_orig_client_bw(0), m_need_render(true), m_button_size(1), - m_focused_alpha(AlphaAcc(*theme.focusedTheme(), &FbWinFrameTheme::alpha)), - m_unfocused_alpha(AlphaAcc(*theme.unfocusedTheme(), &FbWinFrameTheme::alpha)), m_shape(m_window, theme->shapePlace()) { + init(); }

@@ -198,7 +235,7 @@ m_visible = true;

if (m_need_render) { renderAll(); - applyAll(); + applyAll(); clearAll(); }

@@ -269,19 +306,11 @@ alignTabs();

if (resize) { if (m_tabmode == EXTERNAL) { - switch(m_screen.getTabPlacement()) { - case LEFTTOP: - case RIGHTTOP: - case LEFT: - case RIGHT: - case LEFTBOTTOM: - case RIGHTBOTTOM: - m_tab_container.setMaxTotalSize(height); - break; - default: - m_tab_container.setMaxTotalSize(width); - break; + unsigned int s = width; + if (!_values[m_screen.getTabPlacement()].is_horizontal) { + s = height; } + m_tab_container.setMaxTotalSize(s); } reconfigure(); }

@@ -293,20 +322,11 @@ m_window.moveResize(x, y, width, height);

m_state.saveGeometry(window().x(), window().y(), window().width(), window().height()); if (m_tabmode == EXTERNAL) { - - switch(m_screen.getTabPlacement()) { - case LEFTTOP: - case RIGHTTOP: - case LEFT: - case RIGHT: - case LEFTBOTTOM: - case RIGHTBOTTOM: - m_tab_container.setMaxTotalSize(height); - break; - default: - m_tab_container.setMaxTotalSize(width); - break; + unsigned int s = width; + if (!_values[m_screen.getTabPlacement()].is_horizontal) { + s = height; } + m_tab_container.setMaxTotalSize(s); alignTabs(); } }

@@ -316,131 +336,67 @@ if (m_tabmode != EXTERNAL)

return; - FbTk::Orientation orig_orient = m_tab_container.orientation(); - unsigned int orig_tabwidth = m_tab_container.maxWidthPerClient(); + FbTk::Container& tabs = tabcontainer(); + FbTk::Orientation orig_orient = tabs.orientation(); + unsigned int orig_tabwidth = tabs.maxWidthPerClient(); if (orig_tabwidth != m_screen.getTabWidth()) - m_tab_container.setMaxSizePerClient(m_screen.getTabWidth()); + tabs.setMaxSizePerClient(m_screen.getTabWidth()); - int tabx = 0, taby = 0; - switch (m_screen.getTabPlacement()) { - case TOPLEFT: - if (orig_orient != FbTk::ROT0) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT0); - m_tab_container.setAlignment(FbTk::Container::LEFT); - m_tab_container.setMaxTotalSize(m_window.width()); - tabx = x(); - taby = y() - yOffset(); - break; - case TOP: - if (orig_orient != FbTk::ROT0) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT0); - m_tab_container.setAlignment(FbTk::Container::CENTER); - m_tab_container.setMaxTotalSize(m_window.width()); - tabx = x() + (width() - m_tab_container.width())/2; - taby = y() - yOffset(); - break; - case TOPRIGHT: - if (orig_orient != FbTk::ROT0) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT0); - m_tab_container.setAlignment(FbTk::Container::RIGHT); - m_tab_container.setMaxTotalSize(m_window.width()); - tabx = x() + width() - m_tab_container.width(); - taby = y() - yOffset(); - break; - case LEFTTOP: - if (orig_orient != FbTk::ROT270) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT270); - m_tab_container.setAlignment(FbTk::Container::RIGHT); - m_tab_container.setMaxTotalSize(m_window.height()); - tabx = x() - xOffset(); - taby = y(); - break; - case LEFT: - if (orig_orient != FbTk::ROT270) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT270); - m_tab_container.setAlignment(FbTk::Container::CENTER); - m_tab_container.setMaxTotalSize(m_window.height()); - tabx = x() - xOffset(); - taby = y() + (height() - m_tab_container.height())/2; - break; - case LEFTBOTTOM: - if (orig_orient != FbTk::ROT270) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT270); - m_tab_container.setAlignment(FbTk::Container::LEFT); - m_tab_container.setMaxTotalSize(m_window.height()); - tabx = x() - xOffset(); - taby = y() + height() - m_tab_container.height(); - break; - case RIGHTTOP: - if (orig_orient != FbTk::ROT90) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT90); - m_tab_container.setAlignment(FbTk::Container::LEFT); - m_tab_container.setMaxTotalSize(m_window.height()); - tabx = x() + width() + m_window.borderWidth(); - taby = y(); - break; - case RIGHT: - if (orig_orient != FbTk::ROT90) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT90); - m_tab_container.setAlignment(FbTk::Container::CENTER); - m_tab_container.setMaxTotalSize(m_window.height()); - tabx = x() + width() + m_window.borderWidth(); - taby = y() + (height() - m_tab_container.height())/2; - break; - case RIGHTBOTTOM: - if (orig_orient != FbTk::ROT90) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT90); - m_tab_container.setAlignment(FbTk::Container::RIGHT); - m_tab_container.setMaxTotalSize(m_window.height()); - tabx = x() + width() + m_window.borderWidth(); - taby = y() + height() - m_tab_container.height(); - break; - case BOTTOMLEFT: - if (orig_orient != FbTk::ROT0) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT0); - m_tab_container.setAlignment(FbTk::Container::LEFT); - m_tab_container.setMaxTotalSize(m_window.width()); - tabx = x(); - taby = y() + height() + m_window.borderWidth(); - break; - case BOTTOM: - if (orig_orient != FbTk::ROT0) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT0); - m_tab_container.setAlignment(FbTk::Container::CENTER); - m_tab_container.setMaxTotalSize(m_window.width()); - tabx = x() + (width() - m_tab_container.width())/2; - taby = y() + height() + m_window.borderWidth(); - break; - case BOTTOMRIGHT: - if (orig_orient != FbTk::ROT0) m_tab_container.hide(); - m_tab_container.setOrientation(FbTk::ROT0); - m_tab_container.setAlignment(FbTk::Container::RIGHT); - m_tab_container.setMaxTotalSize(m_window.width()); - tabx = x() + width() - m_tab_container.width(); - taby = y() + height() + m_window.borderWidth(); - break; + int bw = window().borderWidth(); + int size = width(); + int tab_x = x(); + int tab_y = y(); + + TabPlacement p = m_screen.getTabPlacement(); + if (orig_orient != _values[p].orient) { + tabs.hide(); + } + if (!_values[p].is_horizontal) { + size = height(); } + tabs.setOrientation(_values[p].orient); + tabs.setAlignment(_values[p].align); + tabs.setMaxTotalSize(size); - unsigned int w = m_window.width(), h = m_window.height(); - translateSize(m_tab_container.orientation(), w, h); + int w = static_cast<int>(width()); + int h = static_cast<int>(height()); + int xo = xOffset(); + int yo = yOffset(); + int tw = static_cast<int>(tabs.width()); + int th = static_cast<int>(tabs.height()); + + switch (p) { + case TOPLEFT: tab_y -= yo; break; + case TOP: tab_x += (w - tw)/2; tab_y -= yo; break; + case TOPRIGHT: tab_x += w - tw; tab_y -= yo; break; + case BOTTOMLEFT: tab_y += h + bw; break; + case BOTTOM: tab_x += (w - tw)/2; tab_y += h + bw; break; + case BOTTOMRIGHT: tab_x += w - tw; tab_y += h + bw; break; + case LEFTTOP: tab_x -= xo; break; + case LEFT: tab_x -= xo; tab_y += (h - th)/2; break; + case LEFTBOTTOM: tab_x -= xo; tab_y += h - th; break; + case RIGHTTOP: tab_x += w + bw; break; + case RIGHT: tab_x += w + bw; tab_y += (h - th)/2; break; + case RIGHTBOTTOM: tab_x += w + bw; tab_y += h - th; break; + } - if (m_tab_container.orientation() != orig_orient || - m_tab_container.maxWidthPerClient() != orig_tabwidth) { + if (tabs.orientation() != orig_orient || + tabs.maxWidthPerClient() != orig_tabwidth) { renderTabContainer(); if (m_visible && m_use_tabs) { applyTabContainer(); - m_tab_container.clear(); - m_tab_container.show(); + tabs.clear(); + tabs.show(); } } - if (m_tab_container.parent()->window() != m_screen.rootWindow().window()) { - m_tab_container.reparent(m_screen.rootWindow(), tabx, taby); - m_label.clear(); - m_layeritem.addWindow(m_tab_container); + if (tabs.parent()->window() != m_screen.rootWindow().window()) { + tabs.reparent(m_screen.rootWindow(), tab_x, tab_y); + tabs.clear(); + m_layeritem.addWindow(tabs); } else { - m_tab_container.move(tabx, taby); + tabs.move(tab_x, tab_y); } }

@@ -499,16 +455,16 @@ return;

m_state.focused = newvalue; - if (FbTk::Transparent::haveRender() && + if (FbTk::Transparent::haveRender() && getAlpha(true) != getAlpha(false)) { // different alpha for focused and unfocused + int alpha = getAlpha(m_state.focused); - if (FbTk::Transparent::haveComposite()) { - m_tab_container.setAlpha(255); - m_window.setOpaque(alpha); - } else { - m_tab_container.setAlpha(alpha); - m_window.setOpaque(255); + int opaque = 255; + if (!FbTk::Transparent::haveComposite()) { + std::swap(alpha, opaque); } + m_tab_container.setAlpha(alpha); + m_window.setOpaque(opaque); } setBorderWidth();

@@ -556,11 +512,7 @@ frameExtentSig().emit();

} void FbWinFrame::setAlpha(bool focused, int alpha) { - if (focused) - m_focused_alpha = alpha; - else - m_unfocused_alpha = alpha; - + m_alpha[focused] = alpha; if (m_state.focused == focused) applyAlpha(); }

@@ -577,22 +529,25 @@ }

} int FbWinFrame::getAlpha(bool focused) const { - if (focused) - return m_focused_alpha; - else - return m_unfocused_alpha; + return m_alpha[focused]; } void FbWinFrame::setDefaultAlpha() { if (getUseDefaultAlpha()) return; - m_focused_alpha.restoreDefault(); - m_unfocused_alpha.restoreDefault(); + m_alpha[UNFOCUS] = theme().unfocusedTheme()->alpha(); + m_alpha[FOCUS] = theme().unfocusedTheme()->alpha(); applyAlpha(); } bool FbWinFrame::getUseDefaultAlpha() const { - return m_focused_alpha.isDefault() && m_unfocused_alpha.isDefault(); + if (m_alpha[UNFOCUS] != theme().unfocusedTheme()->alpha()) { + return false; + } else if (m_alpha[FOCUS] != theme().focusedTheme()->alpha()) { + return false; + } + + return true; } void FbWinFrame::addLeftButton(FbTk::Button *btn) {

@@ -737,14 +692,15 @@ return false;

m_titlebar.hide(); m_use_titlebar = false; - if (static_cast<signed int>(m_window.height() - m_titlebar.height() - - m_titlebar.borderWidth()) <= 0) { - m_window.resize(m_window.width(), 1); - } else { - // only take away one borderwidth (as the other border is still the "top" border) - m_window.resize(m_window.width(), m_window.height() - m_titlebar.height() - - m_titlebar.borderWidth()); - } + + int h = height(); + int th = m_titlebar.height(); + int tbw = m_titlebar.borderWidth(); + + // only take away one borderwidth (as the other border is still the "top" + // border) + h = std::max(1, h - th - tbw); + m_window.resize(m_window.width(), h); return true; }

@@ -756,7 +712,8 @@

m_titlebar.show(); m_use_titlebar = true; - // only add one borderwidth (as the other border is still the "top" border) + // only add one borderwidth (as the other border is still the "top" + // border) m_window.resize(m_window.width(), m_window.height() + m_titlebar.height() + m_titlebar.borderWidth());

@@ -767,22 +724,22 @@

bool FbWinFrame::hideHandle() { if (!m_use_handle) return false; + m_handle.hide(); m_grip_left.hide(); m_grip_right.hide(); m_use_handle = false; - if (static_cast<signed int>(m_window.height() - m_handle.height() - - m_handle.borderWidth()) <= 0) { - m_window.resize(m_window.width(), 1); - } else { - // only take away one borderwidth (as the other border is still the "top" border) - m_window.resize(m_window.width(), m_window.height() - m_handle.height() - - m_handle.borderWidth()); - } + int h = m_window.height(); + int hh = m_handle.height(); + int hbw = m_handle.borderWidth(); + + // only take away one borderwidth (as the other border is still the "top" + // border) + h = std::max(1, h - hh - hbw); + m_window.resize(m_window.width(), h); return true; - } bool FbWinFrame::showHandle() {

@@ -833,18 +790,19 @@ evm.remove(m_window);

} void FbWinFrame::exposeEvent(XExposeEvent &event) { + FbTk::FbWindow* win = 0; if (m_titlebar == event.window) { - m_titlebar.clearArea(event.x, event.y, event.width, event.height); + win = &m_titlebar; } else if (m_tab_container == event.window) { - m_tab_container.clearArea(event.x, event.y, event.width, event.height); + win = &m_tab_container; } else if (m_label == event.window) { - m_label.clearArea(event.x, event.y, event.width, event.height); + win = &m_label; } else if (m_handle == event.window) { - m_handle.clearArea(event.x, event.y, event.width, event.height); + win = &m_handle; } else if (m_grip_left == event.window) { - m_grip_left.clearArea(event.x, event.y, event.width, event.height); + win = &m_grip_left; } else if (m_grip_right == event.window) { - m_grip_right.clearArea(event.x, event.y, event.width, event.height); + win = &m_grip_right; } else { if (m_tab_container.tryExposeEvent(event))

@@ -869,8 +827,11 @@ compare);

if (it != m_buttons_right.end()) (*it)->exposeEvent(event); + + return; } + win->clearArea(event.x, event.y, event.width, event.height); } void FbWinFrame::handleEvent(XEvent &event) {

@@ -912,23 +873,13 @@ } else

m_titlebar.lower(); if (m_tabmode == EXTERNAL) { - unsigned int neww, newh; - switch (m_screen.getTabPlacement()) { - case TOPLEFT: - case TOP: - case TOPRIGHT: - case BOTTOMLEFT: - case BOTTOM: - case BOTTOMRIGHT: - neww = m_tab_container.width(); - newh = buttonHeight(); - break; - default: - neww = buttonHeight(); - newh = m_tab_container.height(); - break; + unsigned int h = buttonHeight(); + unsigned int w = m_tab_container.width(); + if (!_values[m_screen.getTabPlacement()].is_horizontal) { + w = m_tab_container.height(); + std::swap(w, h); } - m_tab_container.resize(neww, newh); + m_tab_container.resize(w, h); alignTabs(); }

@@ -989,13 +940,12 @@ if (isVisible()) {

// update transparency settings if (FbTk::Transparent::haveRender()) { int alpha = getAlpha(m_state.focused); - if (FbTk::Transparent::haveComposite()) { - m_tab_container.setAlpha(255); - m_window.setOpaque(alpha); - } else { - m_tab_container.setAlpha(alpha); - m_window.setOpaque(255); + int opaque = 255; + if (!FbTk::Transparent::haveComposite()) { + std::swap(alpha, opaque); } + m_tab_container.setAlpha(alpha); + m_window.setOpaque(opaque); } renderAll(); applyAll();

@@ -1084,8 +1034,7 @@ m_label.moveResize(next_x, m_bevel, space_left, button_size);

m_tab_container.invalidateBackground(); if (m_tabmode == INTERNAL) - m_tab_container.moveResize(next_x, m_bevel, - space_left, button_size); + m_tab_container.moveResize(next_x, m_bevel, space_left, button_size); else { if (m_use_tabs) { if (m_tab_container.orientation() == FbTk::ROT0) {

@@ -1132,25 +1081,24 @@ m_need_render = true;

return; } + typedef FbTk::ThemeProxy<FbWinFrameTheme> TP; + TP& ft = theme().focusedTheme(); + TP& uft = theme().unfocusedTheme(); + // render pixmaps - render(theme().focusedTheme()->titleTexture(), m_title_focused_color, - m_title_focused_pm, - m_titlebar.width(), m_titlebar.height()); + render(m_title_face.color[FOCUS], m_title_face.pm[FOCUS], m_titlebar.width(), m_titlebar.height(), + ft->titleTexture(), m_imagectrl); - render(theme().unfocusedTheme()->titleTexture(), m_title_unfocused_color, - m_title_unfocused_pm, - m_titlebar.width(), m_titlebar.height()); + render(m_title_face.color[UNFOCUS], m_title_face.pm[UNFOCUS], m_titlebar.width(), m_titlebar.height(), + uft->titleTexture(), m_imagectrl); //!! TODO: don't render label if internal tabs - render(theme().focusedTheme()->iconbarTheme()->texture(), - m_label_focused_color, m_label_focused_pm, - m_label.width(), m_label.height()); - - render(theme().unfocusedTheme()->iconbarTheme()->texture(), - m_label_unfocused_color, m_label_unfocused_pm, - m_label.width(), m_label.height()); + render(m_label_face.color[FOCUS], m_label_face.pm[FOCUS], m_label.width(), m_label.height(), + ft->iconbarTheme()->texture(), m_imagectrl); + render(m_label_face.color[UNFOCUS], m_label_face.pm[UNFOCUS], m_label.width(), m_label.height(), + uft->iconbarTheme()->texture(), m_imagectrl); } void FbWinFrame::renderTabContainer() {

@@ -1159,21 +1107,23 @@ m_need_render = true;

return; } - const FbTk::Texture *tc_focused = &theme().focusedTheme()->iconbarTheme()->texture(); - const FbTk::Texture *tc_unfocused = &theme().unfocusedTheme()->iconbarTheme()->texture(); + typedef FbTk::ThemeProxy<FbWinFrameTheme> TP; + TP& ft = theme().focusedTheme(); + TP& uft = theme().unfocusedTheme(); + FbTk::Container& tabs = tabcontainer(); + const FbTk::Texture *tc_focused = &ft->iconbarTheme()->texture(); + const FbTk::Texture *tc_unfocused = &uft->iconbarTheme()->texture(); if (m_tabmode == EXTERNAL && tc_focused->type() & FbTk::Texture::PARENTRELATIVE) - tc_focused = &theme().focusedTheme()->titleTexture(); + tc_focused = &ft->titleTexture(); if (m_tabmode == EXTERNAL && tc_unfocused->type() & FbTk::Texture::PARENTRELATIVE) - tc_unfocused = &theme().unfocusedTheme()->titleTexture(); + tc_unfocused = &uft->titleTexture(); - render(*tc_focused, m_tabcontainer_focused_color, - m_tabcontainer_focused_pm, - m_tab_container.width(), m_tab_container.height(), m_tab_container.orientation()); + render(m_tabcontainer_face.color[FOCUS], m_tabcontainer_face.pm[FOCUS], + tabs.width(), tabs.height(), *tc_focused, m_imagectrl, tabs.orientation()); - render(*tc_unfocused, m_tabcontainer_unfocused_color, - m_tabcontainer_unfocused_pm, - m_tab_container.width(), m_tab_container.height(), m_tab_container.orientation()); + render(m_tabcontainer_face.color[UNFOCUS], m_tabcontainer_face.pm[UNFOCUS], + tabs.width(), tabs.height(), *tc_unfocused, m_imagectrl, tabs.orientation()); renderButtons();

@@ -1181,15 +1131,8 @@ }

void FbWinFrame::applyTitlebar() { - // set up pixmaps for titlebar windows - Pixmap label_pm = None; - Pixmap title_pm = None; - FbTk::Color label_color; - FbTk::Color title_color; - getCurrentFocusPixmap(label_pm, title_pm, - label_color, title_color); - - int alpha = getAlpha (m_state.focused); + int f = m_state.focused; + int alpha = getAlpha(f); m_titlebar.setAlpha(alpha); m_label.setAlpha(alpha);

@@ -1197,17 +1140,10 @@ if (m_tabmode != INTERNAL) {

m_label.setGC(theme()->iconbarTheme()->text().textGC()); m_label.setJustify(theme()->iconbarTheme()->text().justify()); - if (label_pm != 0) - m_label.setBackgroundPixmap(label_pm); - else - m_label.setBackgroundColor(label_color); + bg_pm_or_color(m_label, m_label_face.pm[f], m_label_face.color[f]); } - if (title_pm != 0) - m_titlebar.setBackgroundPixmap(title_pm); - else - m_titlebar.setBackgroundColor(title_color); - + bg_pm_or_color(m_titlebar, m_title_face.pm[f], m_title_face.color[f]); applyButtons(); }

@@ -1221,64 +1157,39 @@ m_need_render = true;

return; } - render(theme().focusedTheme()->handleTexture(), m_handle_focused_color, - m_handle_focused_pm, - m_handle.width(), m_handle.height()); + typedef FbTk::ThemeProxy<FbWinFrameTheme> TP; + TP& ft = theme().focusedTheme(); + TP& uft = theme().unfocusedTheme(); - render(theme().unfocusedTheme()->handleTexture(), m_handle_unfocused_color, - m_handle_unfocused_pm, - m_handle.width(), m_handle.height()); + render(m_handle_face.color[FOCUS], m_handle_face.pm[FOCUS], + m_handle.width(), m_handle.height(), + ft->handleTexture(), m_imagectrl); - render(theme().focusedTheme()->gripTexture(), m_grip_focused_color, - m_grip_focused_pm, - m_grip_left.width(), m_grip_left.height()); + render(m_handle_face.color[UNFOCUS], m_handle_face.pm[UNFOCUS], + m_handle.width(), m_handle.height(), + uft->handleTexture(), m_imagectrl); - render(theme().unfocusedTheme()->gripTexture(), m_grip_unfocused_color, - m_grip_unfocused_pm, - m_grip_left.width(), m_grip_left.height()); + render(m_grip_face.color[FOCUS], m_grip_face.pm[FOCUS], + m_grip_left.width(), m_grip_left.height(), + ft->handleTexture(), m_imagectrl); + render(m_grip_face.color[UNFOCUS], m_grip_face.pm[UNFOCUS], + m_grip_left.width(), m_grip_left.height(), + uft->handleTexture(), m_imagectrl); } void FbWinFrame::applyHandles() { + bool f = m_state.focused; int alpha = getAlpha(m_state.focused); + m_handle.setAlpha(alpha); + bg_pm_or_color(m_handle, m_handle_face.pm[f], m_handle_face.color[f]); + m_grip_left.setAlpha(alpha); m_grip_right.setAlpha(alpha); - - if (m_state.focused) { - - if (m_handle_focused_pm) { - m_handle.setBackgroundPixmap(m_handle_focused_pm); - } else { - m_handle.setBackgroundColor(m_handle_focused_color); - } - - if (m_grip_focused_pm) { - m_grip_left.setBackgroundPixmap(m_grip_focused_pm); - m_grip_right.setBackgroundPixmap(m_grip_focused_pm); - } else { - m_grip_left.setBackgroundColor(m_grip_focused_color); - m_grip_right.setBackgroundColor(m_grip_focused_color); - } - - } else { - - if (m_handle_unfocused_pm) { - m_handle.setBackgroundPixmap(m_handle_unfocused_pm); - } else { - m_handle.setBackgroundColor(m_handle_unfocused_color); - } - - if (m_grip_unfocused_pm) { - m_grip_left.setBackgroundPixmap(m_grip_unfocused_pm); - m_grip_right.setBackgroundPixmap(m_grip_unfocused_pm); - } else { - m_grip_left.setBackgroundColor(m_grip_unfocused_color); - m_grip_right.setBackgroundColor(m_grip_unfocused_color); - } - } - + bg_pm_or_color(m_grip_left, m_grip_face.pm[f], m_grip_face.color[f]); + bg_pm_or_color(m_grip_right, m_grip_face.pm[f], m_grip_face.color[f]); } void FbWinFrame::renderButtons() {

@@ -1288,17 +1199,22 @@ m_need_render = true;

return; } - render(theme().focusedTheme()->buttonTexture(), m_button_color, - m_button_pm, - m_button_size, m_button_size); + typedef FbTk::ThemeProxy<FbWinFrameTheme> TP; + TP& ft = theme().focusedTheme(); + TP& uft = theme().unfocusedTheme(); + + render(m_button_face.color[UNFOCUS], m_button_face.pm[UNFOCUS], + m_button_size, m_button_size, + uft->buttonTexture(), m_imagectrl); + + render(m_button_face.color[FOCUS], m_button_face.pm[FOCUS], + m_button_size, m_button_size, + ft->buttonTexture(), m_imagectrl); - render(theme().unfocusedTheme()->buttonTexture(), m_button_unfocused_color, - m_button_unfocused_pm, - m_button_size, m_button_size); + render(m_button_face.color[PRESSED], m_button_face.pm[PRESSED], + m_button_size, m_button_size, + theme()->buttonPressedTexture(), m_imagectrl); - render(theme()->buttonPressedTexture(), m_button_pressed_color, - m_button_pressed_pm, - m_button_size, m_button_size); } void FbWinFrame::applyButtons() {

@@ -1315,15 +1231,18 @@

if (theme()->handleWidth() == 0) m_use_handle = false; + m_alpha[UNFOCUS] = theme().unfocusedTheme()->alpha(); + m_alpha[FOCUS] = theme().focusedTheme()->alpha(); + m_handle.showSubwindows(); // clear pixmaps - m_title_focused_pm = m_title_unfocused_pm = 0; - m_label_focused_pm = m_label_unfocused_pm = 0; - m_tabcontainer_focused_pm = m_tabcontainer_unfocused_pm = 0; - m_handle_focused_pm = m_handle_unfocused_pm = 0; - m_button_pm = m_button_unfocused_pm = m_button_pressed_pm = 0; - m_grip_unfocused_pm = m_grip_focused_pm = 0; + m_title_face.pm[UNFOCUS] = m_title_face.pm[FOCUS] = 0; + m_label_face.pm[UNFOCUS] = m_label_face.pm[FOCUS] = 0; + m_tabcontainer_face.pm[UNFOCUS] = m_tabcontainer_face.pm[FOCUS] = 0; + m_handle_face.pm[UNFOCUS] = m_handle_face.pm[FOCUS] = 0; + m_button_face.pm[UNFOCUS] = m_button_face.pm[FOCUS] = m_button_face.pm[PRESSED] = 0; + m_grip_face.pm[UNFOCUS] = m_grip_face.pm[FOCUS] = 0; m_button_size = 26;

@@ -1351,84 +1270,28 @@ /**

Setups upp background, pressed pixmap/color of the button to current theme */ void FbWinFrame::applyButton(FbTk::Button &btn) { - if (m_button_pressed_pm) - btn.setPressedPixmap(m_button_pressed_pm); - else - btn.setPressedColor(m_button_pressed_color); - Pixmap pm = m_state.focused ? m_button_pm : m_button_unfocused_pm; - btn.setAlpha(getAlpha(m_state.focused)); - btn.setGC(theme()->buttonPicGC()); - if (pm) - btn.setBackgroundPixmap(pm); - else - btn.setBackgroundColor(m_state.focused ? m_button_color - : m_button_unfocused_color); -} - -void FbWinFrame::render(const FbTk::Texture &tex, FbTk::Color &col, Pixmap &pm, - unsigned int w, unsigned int h, FbTk::Orientation orient) { - - Pixmap tmp = pm; - if (!tex.usePixmap()) { - pm = None; - col = tex.color(); + if (m_button_face.pm[PRESSED]) { + btn.setPressedPixmap(m_button_face.pm[PRESSED]); } else { - pm = m_imagectrl.renderImage(w, h, tex, orient); + btn.setPressedColor(m_button_face.color[PRESSED]); } - if (tmp) - m_imagectrl.removeImage(tmp); + bool f = m_state.focused; + btn.setAlpha(getAlpha(f)); + btn.setGC(theme()->buttonPicGC()); + + bg_pm_or_color(btn, m_button_face.pm[f], m_button_face.color[f]); } -void FbWinFrame::getCurrentFocusPixmap(Pixmap &label_pm, Pixmap &title_pm, - FbTk::Color &label_color, FbTk::Color &title_color) { - if (m_state.focused) { - if (m_label_focused_pm != 0) - label_pm = m_label_focused_pm; - else - label_color = m_label_focused_color; - if (m_title_focused_pm != 0) - title_pm = m_title_focused_pm; - else - title_color = m_title_focused_color; - } else { - if (m_label_unfocused_pm != 0) - label_pm = m_label_unfocused_pm; - else - label_color = m_label_unfocused_color; +void FbWinFrame::applyTabContainer() { - if (m_title_unfocused_pm != 0) - title_pm = m_title_unfocused_pm; - else - title_color = m_title_unfocused_color; - } -} - -void FbWinFrame::applyTabContainer() { m_tab_container.setAlpha(getAlpha(m_state.focused)); - - // do the parent container - Pixmap tabcontainer_pm = None; - FbTk::Color *tabcontainer_color = NULL; - if (m_state.focused) { - if (m_tabcontainer_focused_pm != 0) - tabcontainer_pm = m_tabcontainer_focused_pm; - else - tabcontainer_color = &m_tabcontainer_focused_color; - } else { - if (m_tabcontainer_unfocused_pm != 0) - tabcontainer_pm = m_tabcontainer_unfocused_pm; - else - tabcontainer_color = &m_tabcontainer_unfocused_color; - } - - if (tabcontainer_pm != 0) - m_tab_container.setBackgroundPixmap(tabcontainer_pm); - else - m_tab_container.setBackgroundColor(*tabcontainer_color); + bg_pm_or_color(m_tab_container, + m_tabcontainer_face.pm[m_state.focused], + m_tabcontainer_face.color[m_state.focused]); // and the labelbuttons in it FbTk::Container::ItemList::iterator btn_it = m_tab_container.begin();

@@ -1641,54 +1504,28 @@

int FbWinFrame::widthOffset() const { if (m_tabmode != EXTERNAL || !m_use_tabs) return 0; - - // same height offset for top and bottom tabs - switch (m_screen.getTabPlacement()) { - case LEFTTOP: - case RIGHTTOP: - case LEFT: - case RIGHT: - case LEFTBOTTOM: - case RIGHTBOTTOM: - return m_tab_container.width() + m_window.borderWidth(); - break; - default: // kill warning - break; + if (_values[m_screen.getTabPlacement()].is_horizontal) { + return 0; } - return 0; + return m_tab_container.width() + m_window.borderWidth(); } int FbWinFrame::heightOffset() const { if (m_tabmode != EXTERNAL || !m_use_tabs) return 0; - switch (m_screen.getTabPlacement()) { - case TOPLEFT: - case TOP: - case TOPRIGHT: - case BOTTOMLEFT: - case BOTTOM: - case BOTTOMRIGHT: - return m_tab_container.height() + m_window.borderWidth(); - break; - default: // kill warning - break; + if (!_values[m_screen.getTabPlacement()].is_horizontal) { + return 0; } - return 0; + return m_tab_container.height() + m_window.borderWidth(); } int FbWinFrame::xOffset() const { if (m_tabmode != EXTERNAL || !m_use_tabs) return 0; - - switch (m_screen.getTabPlacement()) { - case LEFTTOP: - case LEFT: - case LEFTBOTTOM: + TabPlacement p = m_screen.getTabPlacement(); + if (p == LEFTTOP || p == LEFT || p == LEFTBOTTOM) { return m_tab_container.width() + m_window.borderWidth(); - break; - default: // kill warning - break; } return 0; }

@@ -1696,15 +1533,9 @@

int FbWinFrame::yOffset() const { if (m_tabmode != EXTERNAL || !m_use_tabs) return 0; - - switch (m_screen.getTabPlacement()) { - case TOPLEFT: - case TOP: - case TOPRIGHT: + TabPlacement p = m_screen.getTabPlacement(); + if (p == TOPLEFT || p == TOP || p == TOPRIGHT) { return m_tab_container.height() + m_window.borderWidth(); - break; - default: // kill warning - break; } return 0; }

@@ -1725,7 +1556,7 @@ m_screen.showGeometry(i, j);

} bool FbWinFrame::insideTitlebar(Window win) const { - return + return gripLeft().window() != win && gripRight().window() != win && window().window() != win;

@@ -1740,14 +1571,14 @@ using RectangleUtil::insideBorder;

int borderw = window().borderWidth(); if ( // if mouse is currently on the window border, ignore it ( - ! insideBorder(window(), x, y, borderw) - && ( externalTabMode() + ! insideBorder(window(), x, y, borderw) + && ( externalTabMode() || ! insideBorder(tabcontainer(), x, y, borderw) ) ) || // or if mouse was on border when it was last clicked ( - ! insideBorder(window(), last_x, last_y, borderw) - && ( externalTabMode() + ! insideBorder(window(), last_x, last_y, borderw) + && ( externalTabMode() || ! insideBorder(tabcontainer(), last_x, last_y, borderw ) ) ) ) context = Keys::ON_WINDOWBORDER;
M src/FbWinFrame.hhsrc/FbWinFrame.hh

@@ -30,7 +30,6 @@ #include "FbTk/RefCount.hh"

#include "FbTk/Color.hh" #include "FbTk/LayerItem.hh" #include "FbTk/TextButton.hh" -#include "FbTk/DefaultValue.hh" #include "FbTk/Container.hh" #include "FbTk/Shape.hh" #include "FbTk/Signal.hh"

@@ -73,12 +72,6 @@ /// create a top level window

FbWinFrame(BScreen &screen, unsigned int client_depth, WindowState &state, FocusableTheme<FbWinFrameTheme> &theme); -/* /// create a frame window inside another FbWindow, NOT IMPLEMENTED! - FbWinFrame(BScreen &screen, FbWinFrameTheme &theme, FbTk::ImageControl &imgctrl, - const FbTk::FbWindow &parent, - int x, int y, - unsigned int width, unsigned int height); -*/ /// destroy frame ~FbWinFrame();

@@ -119,8 +112,8 @@ void updateTabProperties() { alignTabs(); }

/// Alpha settings void setAlpha(bool focused, int value); - void applyAlpha(); int getAlpha(bool focused) const; + void applyAlpha(); void setDefaultAlpha(); bool getUseDefaultAlpha() const;

@@ -258,10 +251,6 @@ void renderTabContainer(); // and labelbuttons

void renderButtons(); // subset of renderTitlebar - don't call directly - /// renders to pixmap or sets color - void render(const FbTk::Texture &tex, FbTk::Color &col, Pixmap &pm, - unsigned int width, unsigned int height, FbTk::Orientation orient = FbTk::ROT0); - //@} // these return true/false for if something changed

@@ -286,8 +275,10 @@ void applyHandles();

void applyTabContainer(); // and label buttons void applyButtons(); // only called within applyTitlebar +#if 0 void getCurrentFocusPixmap(Pixmap &label_pm, Pixmap &title_pm, FbTk::Color &label_color, FbTk::Color &title_color); +#endif /// initiate inserted button for current theme void applyButton(FbTk::Button &btn);

@@ -338,36 +329,19 @@ /**

@name pixmaps and colors for rendering */ //@{ - Pixmap m_title_focused_pm; ///< pixmap for focused title - FbTk::Color m_title_focused_color; ///< color for focused title - Pixmap m_title_unfocused_pm; ///< pixmap for unfocused title - FbTk::Color m_title_unfocused_color; ///< color for unfocused title - Pixmap m_label_focused_pm; ///< pixmap for focused label (only visible with external tabs) - FbTk::Color m_label_focused_color; ///< color for focused label - Pixmap m_label_unfocused_pm; ///< pixmap for unfocused label - FbTk::Color m_label_unfocused_color; ///< color for unfocused label + // 0-unfocus, 1-focus + struct Face { Pixmap pm[2]; FbTk::Color color[2]; }; + // 0-unfocus, 1-focus, 2-pressed + struct BtnFace { Pixmap pm[3]; FbTk::Color color[3]; }; - Pixmap m_tabcontainer_focused_pm; ///< pixmap for focused tab container - FbTk::Color m_tabcontainer_focused_color; ///< color for focused tab container - Pixmap m_tabcontainer_unfocused_pm; ///< pixmap for unfocused tab container - FbTk::Color m_tabcontainer_unfocused_color; ///< color for unfocused tab container - - FbTk::Color m_handle_focused_color, m_handle_unfocused_color; - Pixmap m_handle_focused_pm, m_handle_unfocused_pm; - - - Pixmap m_button_pm; ///< normal button - FbTk::Color m_button_color; ///< normal color button - Pixmap m_button_unfocused_pm; ///< unfocused button - FbTk::Color m_button_unfocused_color; ///< unfocused color button - Pixmap m_button_pressed_pm; ///< pressed button - FbTk::Color m_button_pressed_color; ///< pressed button color + Face m_title_face; + Face m_label_face; + Face m_tabcontainer_face; + Face m_handle_face; + Face m_grip_face; + BtnFace m_button_face; - Pixmap m_grip_focused_pm; - FbTk::Color m_grip_focused_color; ///< if no pixmap is given for grip, use this color - Pixmap m_grip_unfocused_pm; ///< unfocused pixmap for grip - FbTk::Color m_grip_unfocused_color; ///< unfocused color for grip if no pixmap is given //@} TabMode m_tabmode;

@@ -376,10 +350,7 @@ unsigned int m_active_orig_client_bw;

bool m_need_render; int m_button_size; ///< size for all titlebar buttons - /// alpha values - typedef FbTk::ConstObjectAccessor<int, FbWinFrameTheme> AlphaAcc; - FbTk::DefaultValue<int, AlphaAcc> m_focused_alpha; - FbTk::DefaultValue<int, AlphaAcc> m_unfocused_alpha; + int m_alpha[2]; // 0-unfocused, 1-focused FbTk::Shape m_shape; };