summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Tiefenbruck <mark@fluxbox.org>2007-12-27 04:42:10 (GMT)
committerMark Tiefenbruck <mark@fluxbox.org>2007-12-27 04:42:10 (GMT)
commit1f5cd12facc662de240b36bf3c5c14f40adf391b (patch)
treed468908abf2e988265b0c2295dbd265d82ef89b6
parentf5024351e79e92d551d561e9756f0869e51af505 (diff)
downloadfluxbox_lack-1f5cd12facc662de240b36bf3c5c14f40adf391b.zip
fluxbox_lack-1f5cd12facc662de240b36bf3c5c14f40adf391b.tar.bz2
simplify the window transparency menu and handling a bit
-rw-r--r--src/AlphaMenu.cc22
-rw-r--r--src/AlphaMenu.hh15
-rw-r--r--src/CurrentWindowCmd.cc2
-rw-r--r--src/FbTk/DefaultValue.hh4
-rw-r--r--src/FbWinFrame.cc62
-rw-r--r--src/FbWinFrame.hh12
-rw-r--r--src/MenuCreator.cc4
-rw-r--r--src/Remember.cc2
-rw-r--r--src/Window.hh2
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,
47 47
48 // build menu... 48 // build menu...
49 49
50 const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha,
51 "Use Defaults",
52 "Default transparency settings for this window");
53 FbTk::MenuItem *usedefault_item =
54 new AlphaMenuSelectItem(usedefault_label, &object, *this);
55 insert(usedefault_item);
56
57 const FbTk::FbString focused_alpha_label = 50 const FbTk::FbString focused_alpha_label =
58 _FB_XTEXT(Configmenu, FocusedAlpha, 51 _FB_XTEXT(Configmenu, FocusedAlpha,
59 "Focused Window Alpha", 52 "Focused Window Alpha",
@@ -72,6 +65,13 @@ AlphaMenu::AlphaMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
72 new IntResMenuItem< ObjectResource<AlphaObject, int> >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this); 65 new IntResMenuItem< ObjectResource<AlphaObject, int> >(unfocused_alpha_label, m_unfocused_alpha_resource, 0, 255, *this);
73 insert(unfocused_alpha_item); 66 insert(unfocused_alpha_item);
74 67
68 const FbTk::FbString usedefault_label = _FB_XTEXT(Windowmenu, DefaultAlpha,
69 "Use Defaults",
70 "Default transparency settings for this window");
71 FbTk::MenuItem *usedefault_item =
72 new AlphaMenuSelectItem(usedefault_label, &object, *this);
73 insert(usedefault_item);
74
75 updateMenu(); 75 updateMenu();
76} 76}
77 77
@@ -80,18 +80,18 @@ void AlphaMenu::move(int x, int y) {
80 FbTk::Menu::move(x, y); 80 FbTk::Menu::move(x, y);
81 81
82 if (isVisible()) { 82 if (isVisible()) {
83 ((AlphaMenuSelectItem *)find(0))->updateLabel(); 83 // TODO: hardcoding the indices is a bad idea
84 ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(0))->updateLabel();
84 ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); 85 ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel();
85 ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel();
86 frameWindow().updateBackground(false); 86 frameWindow().updateBackground(false);
87 FbTk::Menu::clearWindow(); 87 FbTk::Menu::clearWindow();
88 } 88 }
89} 89}
90 90
91void AlphaMenu::show() { 91void AlphaMenu::show() {
92 ((AlphaMenuSelectItem *)find(0))->updateLabel(); 92 // TODO: hardcoding the indices is a bad idea
93 ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(0))->updateLabel();
93 ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel(); 94 ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(1))->updateLabel();
94 ((IntResMenuItem< ObjectResource<AlphaObject, int> >*)find(2))->updateLabel();
95 frameWindow().updateBackground(false); 95 frameWindow().updateBackground(false);
96 FbTk::Menu::clearWindow(); 96 FbTk::Menu::clearWindow();
97 97
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:
38 38
39 virtual void setFocusedAlpha(int alpha) = 0; 39 virtual void setFocusedAlpha(int alpha) = 0;
40 virtual void setUnfocusedAlpha(int alpha) = 0; 40 virtual void setUnfocusedAlpha(int alpha) = 0;
41 virtual void setUseDefaultAlpha(bool use_default) = 0; 41 virtual void setDefaultAlpha() = 0;
42 42
43 virtual ~AlphaObject() {}; 43 virtual ~AlphaObject() {};
44}; 44};
@@ -69,22 +69,11 @@ public:
69 69
70 bool isSelected() const { return m_object->getUseDefaultAlpha(); } 70 bool isSelected() const { return m_object->getUseDefaultAlpha(); }
71 void click(int button, int time, unsigned int mods) { 71 void click(int button, int time, unsigned int mods) {
72 bool newval = !m_object->getUseDefaultAlpha(); 72 m_object->setDefaultAlpha();
73 m_object->setUseDefaultAlpha(newval);
74 // items 1 and 2 (the focused/unfocused values) are only enabled if we don't use default values
75 m_parent.setItemEnabled(1, !newval);
76 m_parent.setItemEnabled(2, !newval);
77 m_parent.show(); // cheat to refreshing the window 73 m_parent.show(); // cheat to refreshing the window
78 FbTk::MenuItem::click(button, time, mods); 74 FbTk::MenuItem::click(button, time, mods);
79 } 75 }
80 76
81 void updateLabel() {
82 bool val = m_object->getUseDefaultAlpha();
83 m_parent.setItemEnabled(1, !val);
84 m_parent.setItemEnabled(2, !val);
85 m_parent.updateMenu();
86 }
87
88private: 77private:
89 AlphaObject *m_object; 78 AlphaObject *m_object;
90 AlphaMenu &m_parent; 79 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,
519void SetAlphaCmd::real_execute() { 519void SetAlphaCmd::real_execute() {
520 if (m_focus == 256 && m_unfocus == 256) { 520 if (m_focus == 256 && m_unfocus == 256) {
521 // made up signal to return to default 521 // made up signal to return to default
522 fbwindow().setUseDefaultAlpha(true); 522 fbwindow().setDefaultAlpha();
523 return; 523 return;
524 } 524 }
525 525
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:
34 inline const T &get() const { return m_use_default ? m_default : m_actual; } 34 inline const T &get() const { return m_use_default ? m_default : m_actual; }
35 inline void set(const T &val) { m_use_default = false; m_actual = val; } 35 inline void set(const T &val) { m_use_default = false; m_actual = val; }
36 inline void restoreDefault() { m_use_default = true; } 36 inline void restoreDefault() { m_use_default = true; }
37 inline void isDefault() const { return m_use_default; } 37 inline bool isDefault() const { return m_use_default; }
38 38
39 inline DefaultValue<T> &operator =(const T &val) { 39 inline DefaultValue<T> &operator =(const T &val) {
40 set(val); return *this; 40 set(val); return *this;
@@ -62,7 +62,7 @@ public:
62 } 62 }
63 inline void set(const T &val) { m_use_default = false; m_actual = val; } 63 inline void set(const T &val) { m_use_default = false; m_actual = val; }
64 inline void restoreDefault() { m_use_default = true; } 64 inline void restoreDefault() { m_use_default = true; }
65 inline void isDefault() const { return m_use_default; } 65 inline bool isDefault() const { return m_use_default; }
66 66
67 inline DefaultAccessor<T, Receiver> &operator =(const T &val) { 67 inline DefaultAccessor<T, Receiver> &operator =(const T &val) {
68 set(val); return *this; 68 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
87 m_use_handle(true), 87 m_use_handle(true),
88 m_focused(false), 88 m_focused(false),
89 m_visible(false), 89 m_visible(false),
90 m_use_default_alpha(2),
91 m_button_pm(0), 90 m_button_pm(0),
92 m_tabmode(screen.getDefaultInternalTabs()?INTERNAL:EXTERNAL), 91 m_tabmode(screen.getDefaultInternalTabs()?INTERNAL:EXTERNAL),
93 m_active_gravity(0), 92 m_active_gravity(0),
@@ -96,8 +95,8 @@ FbWinFrame::FbWinFrame(BScreen &screen, FbWinFrameTheme &theme, FbTk::ImageContr
96 m_button_size(1), 95 m_button_size(1),
97 m_height_before_shade(1), 96 m_height_before_shade(1),
98 m_shaded(false), 97 m_shaded(false),
99 m_focused_alpha(0), 98 m_focused_alpha(theme, &FbWinFrameTheme::focusedAlpha),
100 m_unfocused_alpha(0), 99 m_unfocused_alpha(theme, &FbWinFrameTheme::unfocusedAlpha),
101 m_themelistener(*this), 100 m_themelistener(*this),
102 m_shape(m_window, theme.shapePlace()), 101 m_shape(m_window, theme.shapePlace()),
103 m_disable_themeshape(false) { 102 m_disable_themeshape(false) {
@@ -509,50 +508,19 @@ void FbWinFrame::setFocus(bool newvalue) {
509} 508}
510 509
511void FbWinFrame::setAlpha(bool focused, unsigned char alpha) { 510void FbWinFrame::setAlpha(bool focused, unsigned char alpha) {
512 if (m_use_default_alpha == 2) {
513 /// Set basic defaults
514 m_focused_alpha = getAlpha(true);
515 m_unfocused_alpha = getAlpha(false);
516 }
517 m_use_default_alpha = 0;
518
519 if (focused) 511 if (focused)
520 m_focused_alpha = alpha; 512 m_focused_alpha = alpha;
521 else 513 else
522 m_unfocused_alpha = alpha; 514 m_unfocused_alpha = alpha;
523 515
524 if (m_focused == focused) { 516 if (m_focused == focused)
525 if (FbTk::Transparent::haveComposite()) 517 applyAlpha();
526 m_window.setOpaque(alpha);
527 else {
528 // don't need to setAlpha, since apply updates them anyway
529 applyAll();
530 clearAll();
531 }
532 }
533} 518}
534 519
535unsigned char FbWinFrame::getAlpha(bool focused) const 520void FbWinFrame::applyAlpha() {
536{ 521 unsigned char alpha = getAlpha(m_focused);
537 return getUseDefaultAlpha() ?
538 (focused ? theme().focusedAlpha() : theme().unfocusedAlpha())
539 : (focused ? m_focused_alpha : m_unfocused_alpha);
540}
541
542void FbWinFrame::setUseDefaultAlpha(bool default_alpha)
543{
544 if (getUseDefaultAlpha() == default_alpha)
545 return;
546
547 if (!default_alpha && m_use_default_alpha == 2) {
548 m_focused_alpha = theme().focusedAlpha();
549 m_unfocused_alpha = theme().unfocusedAlpha();
550 }
551
552 m_use_default_alpha = default_alpha;
553
554 if (FbTk::Transparent::haveComposite()) 522 if (FbTk::Transparent::haveComposite())
555 m_window.setOpaque(getAlpha(m_focused)); 523 m_window.setOpaque(alpha);
556 else { 524 else {
557 // don't need to setAlpha, since apply updates them anyway 525 // don't need to setAlpha, since apply updates them anyway
558 applyAll(); 526 applyAll();
@@ -560,6 +528,22 @@ void FbWinFrame::setUseDefaultAlpha(bool default_alpha)
560 } 528 }
561} 529}
562 530
531unsigned char FbWinFrame::getAlpha(bool focused) const {
532 return focused ? m_focused_alpha : m_unfocused_alpha;
533}
534
535void FbWinFrame::setDefaultAlpha() {
536 if (getUseDefaultAlpha())
537 return;
538 m_focused_alpha.restoreDefault();
539 m_unfocused_alpha.restoreDefault();
540 applyAlpha();
541}
542
543bool FbWinFrame::getUseDefaultAlpha() const {
544 return m_focused_alpha.isDefault() && m_unfocused_alpha.isDefault();
545}
546
563void FbWinFrame::addLeftButton(FbTk::Button *btn) { 547void FbWinFrame::addLeftButton(FbTk::Button *btn) {
564 if (btn == 0) // valid button? 548 if (btn == 0) // valid button?
565 return; 549 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 @@
32#include "FbTk/FbPixmap.hh" 32#include "FbTk/FbPixmap.hh"
33#include "FbTk/XLayerItem.hh" 33#include "FbTk/XLayerItem.hh"
34#include "FbTk/TextButton.hh" 34#include "FbTk/TextButton.hh"
35#include "FbTk/DefaultValue.hh"
35#include "Container.hh" 36#include "Container.hh"
36#include "Shape.hh" 37#include "Shape.hh"
37 38
@@ -153,10 +154,11 @@ public:
153 154
154 /// Alpha settings 155 /// Alpha settings
155 void setAlpha(bool focused, unsigned char value); 156 void setAlpha(bool focused, unsigned char value);
157 void applyAlpha();
156 unsigned char getAlpha(bool focused) const; 158 unsigned char getAlpha(bool focused) const;
157 159
158 void setUseDefaultAlpha(bool use_default); 160 void setDefaultAlpha();
159 bool getUseDefaultAlpha() const { return m_use_default_alpha; } 161 bool getUseDefaultAlpha() const;
160 162
161 /// add a button to the left of the label 163 /// add a button to the left of the label
162 void addLeftButton(FbTk::Button *btn); 164 void addLeftButton(FbTk::Button *btn);
@@ -349,7 +351,6 @@ private:
349 bool m_use_handle; ///< if we should use handle 351 bool m_use_handle; ///< if we should use handle
350 bool m_focused; ///< focused/unfocused mode 352 bool m_focused; ///< focused/unfocused mode
351 bool m_visible; ///< if we are currently showing 353 bool m_visible; ///< if we are currently showing
352 unsigned char m_use_default_alpha;
353 ///< do we use screen or window alpha settings ? (0 = window, 1 = default, 2 = default and window never set) 354 ///< do we use screen or window alpha settings ? (0 = window, 1 = default, 2 = default and window never set)
354 355
355 /** 356 /**
@@ -398,8 +399,9 @@ private:
398 int m_button_size; ///< size for all titlebar buttons 399 int m_button_size; ///< size for all titlebar buttons
399 unsigned int m_height_before_shade; ///< height before shade, so we can restore it when we unshade 400 unsigned int m_height_before_shade; ///< height before shade, so we can restore it when we unshade
400 bool m_shaded; ///< wheter we're shaded or not 401 bool m_shaded; ///< wheter we're shaded or not
401 unsigned char m_focused_alpha; ///< focused alpha value 402 /// alpha values
402 unsigned char m_unfocused_alpha; ///< unfocused alpha value 403 FbTk::DefaultAccessor<unsigned char, FbWinFrameTheme> m_focused_alpha;
404 FbTk::DefaultAccessor<unsigned char, FbWinFrameTheme> m_unfocused_alpha;
403 405
404 class ThemeListener: public FbTk::Observer { 406 class ThemeListener: public FbTk::Observer {
405 public: 407 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:
200 WindowCmd<void>::window()->setUnfocusedAlpha(alpha); 200 WindowCmd<void>::window()->setUnfocusedAlpha(alpha);
201 } 201 }
202 202
203 void setUseDefaultAlpha(bool use_default) { 203 void setDefaultAlpha() {
204 if (WindowCmd<void>::window() == 0) 204 if (WindowCmd<void>::window() == 0)
205 return; 205 return;
206 WindowCmd<void>::window()->setUseDefaultAlpha(use_default); 206 WindowCmd<void>::window()->setDefaultAlpha();
207 } 207 }
208 208
209}; 209};
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) {
1120 win.setDecorationMask(app->decostate); 1120 win.setDecorationMask(app->decostate);
1121 1121
1122 if (app->alpha_remember) { 1122 if (app->alpha_remember) {
1123 win.frame().setUseDefaultAlpha(false); 1123 win.frame().setDefaultAlpha();
1124 win.frame().setAlpha(true,app->focused_alpha); 1124 win.frame().setAlpha(true,app->focused_alpha);
1125 win.frame().setAlpha(false,app->unfocused_alpha); 1125 win.frame().setAlpha(false,app->unfocused_alpha);
1126 } 1126 }
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:
245 void updateAlpha(bool focused, unsigned char alpha) { frame().setAlpha(focused, alpha); } 245 void updateAlpha(bool focused, unsigned char alpha) { frame().setAlpha(focused, alpha); }
246 246
247 bool getUseDefaultAlpha() const { return frame().getUseDefaultAlpha(); } 247 bool getUseDefaultAlpha() const { return frame().getUseDefaultAlpha(); }
248 void setUseDefaultAlpha(bool default_alpha) { frame().setUseDefaultAlpha(default_alpha); } 248 void setDefaultAlpha() { frame().setDefaultAlpha(); }
249 // ------------------ 249 // ------------------
250 250
251 /// close current client 251 /// close current client