simplify the window transparency menu and handling a bit

This commit is contained in:
Mark Tiefenbruck 2007-12-26 20:42:10 -08:00
parent f5024351e7
commit 1f5cd12fac
9 changed files with 50 additions and 75 deletions

View file

@ -47,13 +47,6 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
// build menu... // 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 = const FbTk::FbString focused_alpha_label =
_FB_XTEXT(Configmenu, FocusedAlpha, _FB_XTEXT(Configmenu, FocusedAlpha,
"Focused Window Alpha", "Focused Window Alpha",
@ -72,6 +65,13 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
new IntResMenuItem< ObjectResource<AlphaObject, int> >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this); new IntResMenuItem< ObjectResource<AlphaObject, int> >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this);
insert(unfocused_alpha_item); 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(); updateMenu();
} }
@ -80,18 +80,18 @@ void AlphaMenu::move(int x, int y) {
FbTk::Menu::move(x, y); FbTk::Menu::move(x, y);
if (isVisible()) { if (isVisible()) {
((AlphaMenuSelectItem *)find(0))->updateLabel(); // TODO: hardcoding the indices is a bad idea
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(0))->updateLabel();
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel();
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel();
frameWindow().updateBackground(false); frameWindow().updateBackground(false);
FbTk::Menu::clearWindow(); FbTk::Menu::clearWindow();
} }
} }
void AlphaMenu::show() { void AlphaMenu::show() {
((AlphaMenuSelectItem *)find(0))->updateLabel(); // TODO: hardcoding the indices is a bad idea
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(0))->updateLabel();
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel();
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel();
frameWindow().updateBackground(false); frameWindow().updateBackground(false);
FbTk::Menu::clearWindow(); FbTk::Menu::clearWindow();

View file

@ -38,7 +38,7 @@ public:
virtual void setFocusedAlpha(int alpha) = 0; virtual void setFocusedAlpha(int alpha) = 0;
virtual void setUnfocusedAlpha(int alpha) = 0; virtual void setUnfocusedAlpha(int alpha) = 0;
virtual void setUseDefaultAlpha(bool use_default) = 0; virtual void setDefaultAlpha() = 0;
virtual ~AlphaObject() {}; virtual ~AlphaObject() {};
}; };
@ -69,22 +69,11 @@ public:
bool isSelected() const { return m_object->getUseDefaultAlpha(); } bool isSelected() const { return m_object->getUseDefaultAlpha(); }
void click(int button, int time, unsigned int mods) { void click(int button, int time, unsigned int mods) {
bool newval = !m_object->getUseDefaultAlpha(); m_object->setDefaultAlpha();
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_parent.show(); // cheat to refreshing the window m_parent.show(); // cheat to refreshing the window
FbTk::MenuItem::click(button, time, mods); 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: private:
AlphaObject *m_object; AlphaObject *m_object;
AlphaMenu &m_parent; AlphaMenu &m_parent;

View file

@ -519,7 +519,7 @@ SetAlphaCmd::SetAlphaCmd(int focused, bool relative,
void SetAlphaCmd::real_execute() { void SetAlphaCmd::real_execute() {
if (m_focus == 256 && m_unfocus == 256) { if (m_focus == 256 && m_unfocus == 256) {
// made up signal to return to default // made up signal to return to default
fbwindow().setUseDefaultAlpha(true); fbwindow().setDefaultAlpha();
return; return;
} }

View file

@ -34,7 +34,7 @@ public:
inline const T &get() const { return m_use_default ? m_default : m_actual; } 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 set(const T &val) { m_use_default = false; m_actual = val; }
inline void restoreDefault() { m_use_default = true; } 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<T> &operator =(const T &val) { inline DefaultValue<T> &operator =(const T &val) {
set(val); return *this; set(val); return *this;
@ -62,7 +62,7 @@ public:
} }
inline void set(const T &val) { m_use_default = false; m_actual = val; } inline void set(const T &val) { m_use_default = false; m_actual = val; }
inline void restoreDefault() { m_use_default = true; } 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<T, Receiver> &operator =(const T &val) { inline DefaultAccessor<T, Receiver> &operator =(const T &val) {
set(val); return *this; set(val); return *this;

View file

@ -87,7 +87,6 @@ FbWinFrame::FbWinFrame(BScreen &screen, FbWinFrameTheme &theme, FbTk::ImageContr
m_use_handle(true), m_use_handle(true),
m_focused(false), m_focused(false),
m_visible(false), m_visible(false),
m_use_default_alpha(2),
m_button_pm(0), m_button_pm(0),
m_tabmode(screen.getDefaultInternalTabs()?INTERNAL:EXTERNAL), m_tabmode(screen.getDefaultInternalTabs()?INTERNAL:EXTERNAL),
m_active_gravity(0), m_active_gravity(0),
@ -96,8 +95,8 @@ FbWinFrame::FbWinFrame(BScreen &screen, FbWinFrameTheme &theme, FbTk::ImageContr
m_button_size(1), m_button_size(1),
m_height_before_shade(1), m_height_before_shade(1),
m_shaded(false), m_shaded(false),
m_focused_alpha(0), m_focused_alpha(theme, &FbWinFrameTheme::focusedAlpha),
m_unfocused_alpha(0), m_unfocused_alpha(theme, &FbWinFrameTheme::unfocusedAlpha),
m_themelistener(*this), m_themelistener(*this),
m_shape(m_window, theme.shapePlace()), m_shape(m_window, theme.shapePlace()),
m_disable_themeshape(false) { m_disable_themeshape(false) {
@ -509,50 +508,19 @@ void FbWinFrame::setFocus(bool newvalue) {
} }
void FbWinFrame::setAlpha(bool focused, unsigned char alpha) { 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) if (focused)
m_focused_alpha = alpha; m_focused_alpha = alpha;
else else
m_unfocused_alpha = alpha; m_unfocused_alpha = alpha;
if (m_focused == focused) { if (m_focused == focused)
if (FbTk::Transparent::haveComposite()) applyAlpha();
m_window.setOpaque(alpha);
else {
// don't need to setAlpha, since apply updates them anyway
applyAll();
clearAll();
}
}
} }
unsigned char FbWinFrame::getAlpha(bool focused) const void FbWinFrame::applyAlpha() {
{ unsigned char alpha = getAlpha(m_focused);
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;
if (FbTk::Transparent::haveComposite()) if (FbTk::Transparent::haveComposite())
m_window.setOpaque(getAlpha(m_focused)); m_window.setOpaque(alpha);
else { else {
// don't need to setAlpha, since apply updates them anyway // don't need to setAlpha, since apply updates them anyway
applyAll(); 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) { void FbWinFrame::addLeftButton(FbTk::Button *btn) {
if (btn == 0) // valid button? if (btn == 0) // valid button?
return; return;

View file

@ -32,6 +32,7 @@
#include "FbTk/FbPixmap.hh" #include "FbTk/FbPixmap.hh"
#include "FbTk/XLayerItem.hh" #include "FbTk/XLayerItem.hh"
#include "FbTk/TextButton.hh" #include "FbTk/TextButton.hh"
#include "FbTk/DefaultValue.hh"
#include "Container.hh" #include "Container.hh"
#include "Shape.hh" #include "Shape.hh"
@ -153,10 +154,11 @@ public:
/// Alpha settings /// Alpha settings
void setAlpha(bool focused, unsigned char value); void setAlpha(bool focused, unsigned char value);
void applyAlpha();
unsigned char getAlpha(bool focused) const; unsigned char getAlpha(bool focused) const;
void setUseDefaultAlpha(bool use_default); void setDefaultAlpha();
bool getUseDefaultAlpha() const { return m_use_default_alpha; } bool getUseDefaultAlpha() const;
/// add a button to the left of the label /// add a button to the left of the label
void addLeftButton(FbTk::Button *btn); void addLeftButton(FbTk::Button *btn);
@ -349,7 +351,6 @@ private:
bool m_use_handle; ///< if we should use handle bool m_use_handle; ///< if we should use handle
bool m_focused; ///< focused/unfocused mode bool m_focused; ///< focused/unfocused mode
bool m_visible; ///< if we are currently showing 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) ///< 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 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 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 bool m_shaded; ///< wheter we're shaded or not
unsigned char m_focused_alpha; ///< focused alpha value /// alpha values
unsigned char m_unfocused_alpha; ///< unfocused alpha value FbTk::DefaultAccessor<unsigned char, FbWinFrameTheme> m_focused_alpha;
FbTk::DefaultAccessor<unsigned char, FbWinFrameTheme> m_unfocused_alpha;
class ThemeListener: public FbTk::Observer { class ThemeListener: public FbTk::Observer {
public: public:

View file

@ -200,10 +200,10 @@ public:
WindowCmd<void>::window()->setUnfocusedAlpha(alpha); WindowCmd<void>::window()->setUnfocusedAlpha(alpha);
} }
void setUseDefaultAlpha(bool use_default) { void setDefaultAlpha() {
if (WindowCmd<void>::window() == 0) if (WindowCmd<void>::window() == 0)
return; return;
WindowCmd<void>::window()->setUseDefaultAlpha(use_default); WindowCmd<void>::window()->setDefaultAlpha();
} }
}; };

View file

@ -1120,7 +1120,7 @@ void Remember::setupFrame(FluxboxWindow &win) {
win.setDecorationMask(app->decostate); win.setDecorationMask(app->decostate);
if (app->alpha_remember) { if (app->alpha_remember) {
win.frame().setUseDefaultAlpha(false); win.frame().setDefaultAlpha();
win.frame().setAlpha(true,app->focused_alpha); win.frame().setAlpha(true,app->focused_alpha);
win.frame().setAlpha(false,app->unfocused_alpha); win.frame().setAlpha(false,app->unfocused_alpha);
} }

View file

@ -245,7 +245,7 @@ public:
void updateAlpha(bool focused, unsigned char alpha) { frame().setAlpha(focused, alpha); } void updateAlpha(bool focused, unsigned char alpha) { frame().setAlpha(focused, alpha); }
bool getUseDefaultAlpha() const { return frame().getUseDefaultAlpha(); } bool getUseDefaultAlpha() const { return frame().getUseDefaultAlpha(); }
void setUseDefaultAlpha(bool default_alpha) { frame().setUseDefaultAlpha(default_alpha); } void setDefaultAlpha() { frame().setDefaultAlpha(); }
// ------------------ // ------------------
/// close current client /// close current client