From 1f5cd12facc662de240b36bf3c5c14f40adf391b Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Wed, 26 Dec 2007 20:42:10 -0800 Subject: simplify the window transparency menu and handling a bit --- src/AlphaMenu.cc | 22 ++++++++--------- src/AlphaMenu.hh | 15 ++---------- src/CurrentWindowCmd.cc | 2 +- src/FbTk/DefaultValue.hh | 4 ++-- src/FbWinFrame.cc | 62 ++++++++++++++++++------------------------------ src/FbWinFrame.hh | 12 ++++++---- src/MenuCreator.cc | 4 ++-- src/Remember.cc | 2 +- src/Window.hh | 2 +- 9 files changed, 50 insertions(+), 75 deletions(-) diff --git a/src/AlphaMenu.cc b/src/AlphaMenu.cc index 8985fc7..8cd225a 100644 --- a/src/AlphaMenu.cc +++ b/src/AlphaMenu.cc @@ -47,13 +47,6 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, // build menu... - const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha, - "Use Defaults", - "Default transparency settings for this window"); - FbTk::MenuItem *usedefault_item = - new AlphaMenuSelectItem(usedefault_label, &object, *this); - insert(usedefault_item); - const FbTk::FbString focused_alpha_label = _FB_XTEXT(Configmenu, FocusedAlpha, "Focused Window Alpha", @@ -72,6 +65,13 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl, new IntResMenuItem< ObjectResource >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this); insert(unfocused_alpha_item); + const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha, + "Use Defaults", + "Default transparency settings for this window"); + FbTk::MenuItem *usedefault_item = + new AlphaMenuSelectItem(usedefault_label, &object, *this); + insert(usedefault_item); + updateMenu(); } @@ -80,18 +80,18 @@ void AlphaMenu::move(int x, int y) { FbTk::Menu::move(x, y); if (isVisible()) { - ((AlphaMenuSelectItem *)find(0))->updateLabel(); + // TODO: hardcoding the indices is a bad idea + ((IntResMenuItem< ObjectResource >*)find(0))->updateLabel(); ((IntResMenuItem< ObjectResource >*)find(1))->updateLabel(); - ((IntResMenuItem< ObjectResource >*)find(2))->updateLabel(); frameWindow().updateBackground(false); FbTk::Menu::clearWindow(); } } void AlphaMenu::show() { - ((AlphaMenuSelectItem *)find(0))->updateLabel(); + // TODO: hardcoding the indices is a bad idea + ((IntResMenuItem< ObjectResource >*)find(0))->updateLabel(); ((IntResMenuItem< ObjectResource >*)find(1))->updateLabel(); - ((IntResMenuItem< ObjectResource >*)find(2))->updateLabel(); frameWindow().updateBackground(false); FbTk::Menu::clearWindow(); diff --git a/src/AlphaMenu.hh b/src/AlphaMenu.hh index 6323fe1..70f9c50 100644 --- a/src/AlphaMenu.hh +++ b/src/AlphaMenu.hh @@ -38,7 +38,7 @@ public: virtual void setFocusedAlpha(int alpha) = 0; virtual void setUnfocusedAlpha(int alpha) = 0; - virtual void setUseDefaultAlpha(bool use_default) = 0; + virtual void setDefaultAlpha() = 0; virtual ~AlphaObject() {}; }; @@ -69,22 +69,11 @@ public: bool isSelected() const { return m_object->getUseDefaultAlpha(); } void click(int button, int time, unsigned int mods) { - bool newval = !m_object->getUseDefaultAlpha(); - m_object->setUseDefaultAlpha(newval); - // items 1 and 2 (the focused/unfocused values) are only enabled if we don't use default values - m_parent.setItemEnabled(1, !newval); - m_parent.setItemEnabled(2, !newval); + m_object->setDefaultAlpha(); m_parent.show(); // cheat to refreshing the window FbTk::MenuItem::click(button, time, mods); } - void updateLabel() { - bool val = m_object->getUseDefaultAlpha(); - m_parent.setItemEnabled(1, !val); - m_parent.setItemEnabled(2, !val); - m_parent.updateMenu(); - } - private: AlphaObject *m_object; AlphaMenu &m_parent; diff --git a/src/CurrentWindowCmd.cc b/src/CurrentWindowCmd.cc index 072f3c5..cd54deb 100644 --- a/src/CurrentWindowCmd.cc +++ b/src/CurrentWindowCmd.cc @@ -519,7 +519,7 @@ SetAlphaCmd::SetAlphaCmd(int focused, bool relative, void SetAlphaCmd::real_execute() { if (m_focus == 256 && m_unfocus == 256) { // made up signal to return to default - fbwindow().setUseDefaultAlpha(true); + fbwindow().setDefaultAlpha(); return; } diff --git a/src/FbTk/DefaultValue.hh b/src/FbTk/DefaultValue.hh index 9f52212..4e7eb49 100644 --- a/src/FbTk/DefaultValue.hh +++ b/src/FbTk/DefaultValue.hh @@ -34,7 +34,7 @@ public: inline const T &get() const { return m_use_default ? m_default : m_actual; } inline void set(const T &val) { m_use_default = false; m_actual = val; } inline void restoreDefault() { m_use_default = true; } - inline void isDefault() const { return m_use_default; } + inline bool isDefault() const { return m_use_default; } inline DefaultValue &operator =(const T &val) { set(val); return *this; @@ -62,7 +62,7 @@ public: } inline void set(const T &val) { m_use_default = false; m_actual = val; } inline void restoreDefault() { m_use_default = true; } - inline void isDefault() const { return m_use_default; } + inline bool isDefault() const { return m_use_default; } inline DefaultAccessor &operator =(const T &val) { set(val); return *this; diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index e96b72f..a0de468 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc @@ -87,7 +87,6 @@ FbWinFrame::FbWinFrame(BScreen &screen, FbWinFrameTheme &theme, FbTk::ImageContr m_use_handle(true), m_focused(false), m_visible(false), - m_use_default_alpha(2), m_button_pm(0), m_tabmode(screen.getDefaultInternalTabs()?INTERNAL:EXTERNAL), m_active_gravity(0), @@ -96,8 +95,8 @@ FbWinFrame::FbWinFrame(BScreen &screen, FbWinFrameTheme &theme, FbTk::ImageContr m_button_size(1), m_height_before_shade(1), m_shaded(false), - m_focused_alpha(0), - m_unfocused_alpha(0), + m_focused_alpha(theme, &FbWinFrameTheme::focusedAlpha), + m_unfocused_alpha(theme, &FbWinFrameTheme::unfocusedAlpha), m_themelistener(*this), m_shape(m_window, theme.shapePlace()), m_disable_themeshape(false) { @@ -509,50 +508,19 @@ void FbWinFrame::setFocus(bool newvalue) { } void FbWinFrame::setAlpha(bool focused, unsigned char alpha) { - if (m_use_default_alpha == 2) { - /// Set basic defaults - m_focused_alpha = getAlpha(true); - m_unfocused_alpha = getAlpha(false); - } - m_use_default_alpha = 0; - if (focused) m_focused_alpha = alpha; else m_unfocused_alpha = alpha; - if (m_focused == focused) { - if (FbTk::Transparent::haveComposite()) - m_window.setOpaque(alpha); - else { - // don't need to setAlpha, since apply updates them anyway - applyAll(); - clearAll(); - } - } + if (m_focused == focused) + applyAlpha(); } -unsigned char FbWinFrame::getAlpha(bool focused) const -{ - return getUseDefaultAlpha() ? - (focused ? theme().focusedAlpha() : theme().unfocusedAlpha()) - : (focused ? m_focused_alpha : m_unfocused_alpha); -} - -void FbWinFrame::setUseDefaultAlpha(bool default_alpha) -{ - if (getUseDefaultAlpha() == default_alpha) - return; - - if (!default_alpha && m_use_default_alpha == 2) { - m_focused_alpha = theme().focusedAlpha(); - m_unfocused_alpha = theme().unfocusedAlpha(); - } - - m_use_default_alpha = default_alpha; - +void FbWinFrame::applyAlpha() { + unsigned char alpha = getAlpha(m_focused); if (FbTk::Transparent::haveComposite()) - m_window.setOpaque(getAlpha(m_focused)); + m_window.setOpaque(alpha); else { // don't need to setAlpha, since apply updates them anyway applyAll(); @@ -560,6 +528,22 @@ void FbWinFrame::setUseDefaultAlpha(bool default_alpha) } } +unsigned char FbWinFrame::getAlpha(bool focused) const { + return focused ? m_focused_alpha : m_unfocused_alpha; +} + +void FbWinFrame::setDefaultAlpha() { + if (getUseDefaultAlpha()) + return; + m_focused_alpha.restoreDefault(); + m_unfocused_alpha.restoreDefault(); + applyAlpha(); +} + +bool FbWinFrame::getUseDefaultAlpha() const { + return m_focused_alpha.isDefault() && m_unfocused_alpha.isDefault(); +} + void FbWinFrame::addLeftButton(FbTk::Button *btn) { if (btn == 0) // valid button? return; diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh index 5af852e..ea0a179 100644 --- a/src/FbWinFrame.hh +++ b/src/FbWinFrame.hh @@ -32,6 +32,7 @@ #include "FbTk/FbPixmap.hh" #include "FbTk/XLayerItem.hh" #include "FbTk/TextButton.hh" +#include "FbTk/DefaultValue.hh" #include "Container.hh" #include "Shape.hh" @@ -153,10 +154,11 @@ public: /// Alpha settings void setAlpha(bool focused, unsigned char value); + void applyAlpha(); unsigned char getAlpha(bool focused) const; - void setUseDefaultAlpha(bool use_default); - bool getUseDefaultAlpha() const { return m_use_default_alpha; } + void setDefaultAlpha(); + bool getUseDefaultAlpha() const; /// add a button to the left of the label void addLeftButton(FbTk::Button *btn); @@ -349,7 +351,6 @@ private: bool m_use_handle; ///< if we should use handle bool m_focused; ///< focused/unfocused mode bool m_visible; ///< if we are currently showing - unsigned char m_use_default_alpha; ///< do we use screen or window alpha settings ? (0 = window, 1 = default, 2 = default and window never set) /** @@ -398,8 +399,9 @@ private: int m_button_size; ///< size for all titlebar buttons unsigned int m_height_before_shade; ///< height before shade, so we can restore it when we unshade bool m_shaded; ///< wheter we're shaded or not - unsigned char m_focused_alpha; ///< focused alpha value - unsigned char m_unfocused_alpha; ///< unfocused alpha value + /// alpha values + FbTk::DefaultAccessor m_focused_alpha; + FbTk::DefaultAccessor m_unfocused_alpha; class ThemeListener: public FbTk::Observer { public: diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index baa49fb..48f3151 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -200,10 +200,10 @@ public: WindowCmd::window()->setUnfocusedAlpha(alpha); } - void setUseDefaultAlpha(bool use_default) { + void setDefaultAlpha() { if (WindowCmd::window() == 0) return; - WindowCmd::window()->setUseDefaultAlpha(use_default); + WindowCmd::window()->setDefaultAlpha(); } }; diff --git a/src/Remember.cc b/src/Remember.cc index a48f399..ba7bf81 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -1120,7 +1120,7 @@ void Remember::setupFrame(FluxboxWindow &win) { win.setDecorationMask(app->decostate); if (app->alpha_remember) { - win.frame().setUseDefaultAlpha(false); + win.frame().setDefaultAlpha(); win.frame().setAlpha(true,app->focused_alpha); win.frame().setAlpha(false,app->unfocused_alpha); } diff --git a/src/Window.hh b/src/Window.hh index 5dbe055..490c178 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -245,7 +245,7 @@ public: void updateAlpha(bool focused, unsigned char alpha) { frame().setAlpha(focused, alpha); } bool getUseDefaultAlpha() const { return frame().getUseDefaultAlpha(); } - void setUseDefaultAlpha(bool default_alpha) { frame().setUseDefaultAlpha(default_alpha); } + void setDefaultAlpha() { frame().setDefaultAlpha(); } // ------------------ /// close current client -- cgit v0.11.2