simplify the window transparency menu and handling a bit
This commit is contained in:
parent
f5024351e7
commit
1f5cd12fac
9 changed files with 50 additions and 75 deletions
|
@ -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<AlphaObject, int> >(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<AlphaObject, int> >*)find(0))->updateLabel();
|
||||
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel();
|
||||
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)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<AlphaObject, int> >*)find(0))->updateLabel();
|
||||
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel();
|
||||
((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel();
|
||||
frameWindow().updateBackground(false);
|
||||
FbTk::Menu::clearWindow();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<T> &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<T, Receiver> &operator =(const T &val) {
|
||||
set(val); return *this;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<unsigned char, FbWinFrameTheme> m_focused_alpha;
|
||||
FbTk::DefaultAccessor<unsigned char, FbWinFrameTheme> m_unfocused_alpha;
|
||||
|
||||
class ThemeListener: public FbTk::Observer {
|
||||
public:
|
||||
|
|
|
@ -200,10 +200,10 @@ public:
|
|||
WindowCmd<void>::window()->setUnfocusedAlpha(alpha);
|
||||
}
|
||||
|
||||
void setUseDefaultAlpha(bool use_default) {
|
||||
void setDefaultAlpha() {
|
||||
if (WindowCmd<void>::window() == 0)
|
||||
return;
|
||||
WindowCmd<void>::window()->setUseDefaultAlpha(use_default);
|
||||
WindowCmd<void>::window()->setDefaultAlpha();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue