From 42c1fd3ae3dd058e146b7350c65b74386123c25c Mon Sep 17 00:00:00 2001 From: rathnor Date: Sun, 12 Sep 2004 14:56:20 +0000 Subject: preliminary support for composite/compositing manager. Also general work for consistency with transparency resources --- ChangeLog | 18 +++++++++++++ src/ArrowButton.cc | 4 ++- src/ButtonTool.cc | 7 +++-- src/ButtonTool.hh | 4 +-- src/ClockTool.cc | 31 ++++++++++++++-------- src/ClockTool.hh | 5 ++-- src/FbTk/FbWindow.cc | 24 +++++++++++++---- src/FbTk/FbWindow.hh | 5 +++- src/FbTk/Menu.cc | 11 +++++--- src/FbTk/Transparent.cc | 68 ++++++++++++++++++++++++++++++++++++++---------- src/FbTk/Transparent.hh | 9 +++++-- src/FbWinFrame.cc | 55 +++++++++++++++++++++++++++------------ src/FbWinFrameTheme.cc | 16 +++--------- src/FbWinFrameTheme.hh | 12 ++++++--- src/GenericTool.cc | 10 +++---- src/GenericTool.hh | 4 +-- src/IconbarTool.cc | 13 ++++++--- src/IconbarTool.hh | 4 ++- src/Screen.cc | 50 ++++++++++++++++++++++++++++------- src/Screen.hh | 5 ++-- src/Slit.cc | 28 ++++++++++++++++---- src/Slit.hh | 3 ++- src/SystemTray.hh | 4 +-- src/ToolFactory.cc | 24 ++++++++++------- src/ToolTheme.cc | 10 ++----- src/ToolTheme.hh | 7 ++--- src/Toolbar.cc | 50 ++++++++++++++++++++++++++++++++--- src/Toolbar.hh | 7 +++-- src/ToolbarItem.hh | 4 +-- src/ToolbarTheme.cc | 11 +------- src/ToolbarTheme.hh | 5 ++-- src/WorkspaceNameTool.cc | 29 +++++++++++++-------- src/WorkspaceNameTool.hh | 5 ++-- src/fluxbox.cc | 7 ++++- src/fluxbox.hh | 5 ++-- 35 files changed, 388 insertions(+), 166 deletions(-) diff --git a/ChangeLog b/ChangeLog index b5106ae..a508ff6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,24 @@ (Format: Year/Month/Day) Changes for 0.9.11 *04/09/12: + * Preliminary support for Composite extension (Simon) + - Relies on external compositing manager using _NET_WM_WINDOW_OPACITY + - NOTE: Also make alpha resource setting more consistent. + Alpha values are no longer in theme, but are in init file. Possible + values are (all beginning with session.screenN.), * means changed/new: + - menu.alpha (*) + - slit.alpha + - window.focus.alpha (*) + - window.unfocus.alpha (*) + - toolbar.alpha (*) + - Changed menu around a bit. If you don't have/want a compositing + manager, but Composite is enabled, you can override it by setting + session.forcePseudoTransparency: true + - Fix a couple of bugs with transparency in toolbar/buttons + fluxbox.hh/cc Screen.hh/cc FbWinFrame.hh/cc FbWinFrameTheme.hh/cc + Slit.hh/cc Toolbar.hh/cc ToolbarTheme.hh/cc ToolbarItem.hh + ToolFactory.cc *Tool.hh/cc ArrowButton.cc FbTk/FbWindow.hh/cc + FbTk/Transparent.hh/cc FbTk/Menu.cc * Minor cleaning, moved Resource<> from fluxbox.cc to Resources.cc (Henrik) *04/09/11: * The include directive in menu can now take diff --git a/src/ArrowButton.cc b/src/ArrowButton.cc index 724562f..4e93a02 100644 --- a/src/ArrowButton.cc +++ b/src/ArrowButton.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ArrowButton.cc,v 1.8 2004/08/26 15:09:33 rathnor Exp $ +// $Id: ArrowButton.cc,v 1.9 2004/09/12 14:56:18 rathnor Exp $ #include "ArrowButton.hh" #include "ButtonTheme.hh" @@ -52,11 +52,13 @@ ArrowButton::ArrowButton(ArrowButton::Type arrow_type, void ArrowButton::clear() { FbTk::Button::clear(); + updateTransparent(); drawArrow(); } void ArrowButton::exposeEvent(XExposeEvent &event) { FbTk::Button::exposeEvent(event); + updateTransparent(event.x, event.y, event.width, event.height); drawArrow(); } diff --git a/src/ButtonTool.cc b/src/ButtonTool.cc index 0640048..6ec9570 100644 --- a/src/ButtonTool.cc +++ b/src/ButtonTool.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ButtonTool.cc,v 1.5 2004/08/29 08:33:12 rathnor Exp $ +// $Id: ButtonTool.cc,v 1.6 2004/09/12 14:56:18 rathnor Exp $ #include "ButtonTool.hh" @@ -36,7 +36,6 @@ ButtonTool::ButtonTool(FbTk::Button *button, m_cache_pressed_pm(0), m_image_ctrl(img_ctrl) { - renderTheme(); } ButtonTool::~ButtonTool() { @@ -53,13 +52,13 @@ void ButtonTool::updateSizing() { btn.setBorderWidth(theme().border().width()); } -void ButtonTool::renderTheme() { +void ButtonTool::renderTheme(unsigned char alpha) { FbTk::Button &btn = static_cast(window()); btn.setGC(static_cast(theme()).gc()); btn.setBorderColor(theme().border().color()); btn.setBorderWidth(theme().border().width()); - btn.setAlpha(theme().alpha()); + btn.setAlpha(alpha); btn.updateTheme(static_cast(theme())); Pixmap old_pm = m_cache_pm; diff --git a/src/ButtonTool.hh b/src/ButtonTool.hh index 73d9b76..ccc984c 100644 --- a/src/ButtonTool.hh +++ b/src/ButtonTool.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ButtonTool.hh,v 1.2 2004/08/29 08:33:12 rathnor Exp $ +// $Id: ButtonTool.hh,v 1.3 2004/09/12 14:56:18 rathnor Exp $ #ifndef BUTTONTOOL_HH #define BUTTONTOOL_HH @@ -41,7 +41,7 @@ public: virtual ~ButtonTool(); protected: - void renderTheme(); + void renderTheme(unsigned char alpha); void updateSizing(); Pixmap m_cache_pm, m_cache_pressed_pm; FbTk::ImageControl &m_image_ctrl; diff --git a/src/ClockTool.cc b/src/ClockTool.cc index dbc128f..f428fae 100644 --- a/src/ClockTool.cc +++ b/src/ClockTool.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ClockTool.cc,v 1.14 2004/08/31 15:26:38 rathnor Exp $ +// $Id: ClockTool.cc,v 1.15 2004/09/12 14:56:18 rathnor Exp $ #include "ClockTool.hh" @@ -178,13 +178,15 @@ void ClockTool::move(int x, int y) { void ClockTool::resize(unsigned int width, unsigned int height) { m_button.resize(width, height); - renderTheme(); + reRender(); + m_button.clear(); } void ClockTool::moveResize(int x, int y, unsigned int width, unsigned int height) { m_button.moveResize(x, y, width, height); - renderTheme(); + reRender(); + m_button.clear(); } void ClockTool::show() { @@ -255,22 +257,29 @@ void ClockTool::updateSizing() { m_button.setBorderWidth(m_theme.border().width()); } -void ClockTool::renderTheme() { - Pixmap old_pm = m_pixmap; +void ClockTool::reRender() { + if (m_theme.texture().usePixmap()) { + if (m_pixmap) + m_screen.imageControl().removeImage(m_pixmap); + m_pixmap = m_screen.imageControl().renderImage(width(), height(), + m_theme.texture()); + m_button.setBackgroundPixmap(m_pixmap); + } +} + +void ClockTool::renderTheme(unsigned char alpha) { if (!m_theme.texture().usePixmap()) { + if (m_pixmap) + m_screen.imageControl().removeImage(m_pixmap); m_pixmap = 0; m_button.setBackgroundColor(m_theme.texture().color()); } else { - m_pixmap = m_screen.imageControl().renderImage(m_button.width(), m_button.height(), m_theme.texture()); - m_button.setBackgroundPixmap(m_pixmap); + reRender(); } - if (old_pm) - m_screen.imageControl().removeImage(old_pm); - m_button.setJustify(m_theme.justify()); m_button.setBorderWidth(m_theme.border().width()); m_button.setBorderColor(m_theme.border().color()); - m_button.setAlpha(m_theme.alpha()); + m_button.setAlpha(alpha); m_button.clear(); } diff --git a/src/ClockTool.hh b/src/ClockTool.hh index a8e9362..23d2b48 100644 --- a/src/ClockTool.hh +++ b/src/ClockTool.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ClockTool.hh,v 1.5 2004/08/29 08:33:12 rathnor Exp $ +// $Id: ClockTool.hh,v 1.6 2004/09/12 14:56:18 rathnor Exp $ #ifndef CLOCKTOOL_HH #define CLOCKTOOL_HH @@ -65,7 +65,8 @@ public: private: void updateTime(); void update(FbTk::Subject *subj); - void renderTheme(); + void renderTheme(unsigned char alpha); + void reRender(); void updateSizing(); FbTk::TextButton m_button; diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc index 2e69339..7e6c863 100644 --- a/src/FbTk/FbWindow.cc +++ b/src/FbTk/FbWindow.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWindow.cc,v 1.42 2004/09/11 22:59:15 fluxgen Exp $ +// $Id: FbWindow.cc,v 1.43 2004/09/12 14:56:19 rathnor Exp $ #include "FbWindow.hh" #include "FbPixmap.hh" @@ -161,6 +161,9 @@ void FbWindow::clearArea(int x, int y, void FbWindow::updateTransparent(int the_x, int the_y, unsigned int the_width, unsigned int the_height) { #ifdef HAVE_XRENDER + if (!m_transparent.get()) + return; + if (width() == 0 || height() == 0) return; @@ -174,9 +177,6 @@ void FbWindow::updateTransparent(int the_x, int the_y, unsigned int the_width, u the_y = 0; } - if (!m_transparent.get()) - return; - // update source and destination if needed Pixmap root = FbPixmap::getRootPixmap(screenNumber()); if (m_transparent->source() != root) @@ -215,7 +215,13 @@ void FbWindow::updateTransparent(int the_x, int the_y, unsigned int the_width, u void FbWindow::setAlpha(unsigned char alpha) { #ifdef HAVE_XRENDER - if (m_transparent.get() == 0 && alpha < 255) { + if (FbTk::Transparent::haveComposite()) { + if (m_transparent.get() != 0) + m_transparent.reset(0); + + // don't setOpaque, let controlling objects do that + // since it's only needed on toplevel windows + } else if (m_transparent.get() == 0 && alpha < 255) { m_transparent.reset(new Transparent(FbPixmap::getRootPixmap(screenNumber()), window(), alpha, screenNumber())); } else if (alpha < 255 && alpha != m_transparent->alpha()) m_transparent->setAlpha(alpha); @@ -395,6 +401,14 @@ long FbWindow::eventMask() const { } +void FbWindow::setOpaque(unsigned char alpha) { +#ifdef HAVE_XRENDER + static Atom m_alphaatom = XInternAtom(display(), "_NET_WM_WINDOW_OPACITY", False); + unsigned int opacity = alpha << 24; + changeProperty(m_alphaatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity, 1l); +#endif // HAVE_XRENDER +} + void FbWindow::setBufferPixmap(Pixmap pm) { m_buffer_pm = pm; } diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh index c39b8c1..d408216 100644 --- a/src/FbTk/FbWindow.hh +++ b/src/FbTk/FbWindow.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWindow.hh,v 1.34 2004/09/11 12:33:14 rathnor Exp $ +// $Id: FbWindow.hh,v 1.35 2004/09/12 14:56:19 rathnor Exp $ #ifndef FBTK_FBWINDOW_HH #define FBTK_FBWINDOW_HH @@ -163,6 +163,9 @@ public: inline bool operator == (const FbWindow &win) const { return m_window == win.m_window; } inline bool operator != (const FbWindow &win) const { return m_window != win.m_window; } + // used for composite + void setOpaque(unsigned char alpha); + protected: /// creates a window with x window client (m_window = client) explicit FbWindow(Window client); diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index 5cfb1d1..b1e186d 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Menu.cc,v 1.84 2004/09/11 22:59:15 fluxgen Exp $ +// $Id: Menu.cc,v 1.85 2004/09/12 14:56:19 rathnor Exp $ //use GNU extensions #ifndef _GNU_SOURCE @@ -1379,10 +1379,14 @@ void Menu::keyPressEvent(XKeyEvent &event) { void Menu::reconfigure() { - if (alpha() == 255 && m_transp.get() != 0) { + if (FbTk::Transparent::haveComposite()) { + if (m_transp.get() != 0) + m_transp.reset(0); + + menu.window.setOpaque(alpha()); + } else if (alpha() == 255 && m_transp.get() != 0) { m_transp.reset(0); } else if (alpha () < 255) { - if (m_transp.get() == 0) { m_transp.reset(new Transparent(FbPixmap::getRootPixmap(screenNumber()), m_real_frame_pm.drawable(), alpha(), @@ -1484,7 +1488,6 @@ void Menu::renderTransp(int x, int y, if (m_transp->source() != root) m_transp->setSource(root, screenNumber()); - if (m_transp->dest() != m_real_frame_pm.drawable()) m_transp->setDest(m_real_frame_pm.drawable(), screenNumber()); diff --git a/src/FbTk/Transparent.cc b/src/FbTk/Transparent.cc index b6521b9..f8ca2a8 100644 --- a/src/FbTk/Transparent.cc +++ b/src/FbTk/Transparent.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Transparent.cc,v 1.8 2004/09/11 15:52:23 rathnor Exp $ +// $Id: Transparent.cc,v 1.9 2004/09/12 14:56:20 rathnor Exp $ #include "Transparent.hh" #include "App.hh" @@ -99,26 +99,67 @@ namespace FbTk { bool Transparent::s_init = false; bool Transparent::s_render = false; +bool Transparent::s_composite = false; -Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int screen_num): - m_alpha_pic(0), m_src_pic(0), m_dest_pic(0), - m_source(src), m_dest(dest), m_alpha(alpha) { - +void Transparent::init() { Display *disp = FbTk::App::instance()->display(); - // check for RENDER support - if (!s_init) { - int major_opcode, first_event, first_error; - if (XQueryExtension(disp, "RENDER", + int major_opcode, first_event, first_error; + if (XQueryExtension(disp, "RENDER", + &major_opcode, + &first_event, &first_error) == False) { + s_render = false; + s_composite = false; + } else { // we have RENDER support + s_render = true; + + if (XQueryExtension(disp, "Composite", &major_opcode, &first_event, &first_error) == False) { - s_render = false; - } else { // we got RENDER support - s_render = true; + s_composite = false; + } else { // we have Composite support + s_composite = true; } - s_init = true; } + s_init = true; +} +void Transparent::usePseudoTransparent(bool no_composite) { + if (s_composite != no_composite) + return; + + s_init = false; + init(); // only use render if we have it + + if (no_composite) + s_composite = false; +} + +bool Transparent::haveComposite(bool for_real) { + if (for_real) { + Display *disp = FbTk::App::instance()->display(); + int major_opcode, first_event, first_error; + + return (XQueryExtension(disp, "Composite", + &major_opcode, + &first_event, &first_error) == True); + } else { + if (!s_init) + init(); + + return s_composite; + } +} + +Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int screen_num): + m_alpha_pic(0), m_src_pic(0), m_dest_pic(0), + m_source(src), m_dest(dest), m_alpha(alpha) { + + Display *disp = FbTk::App::instance()->display(); + + // check for Extension support + if (!s_init) + init(); #ifdef HAVE_XRENDER if (!s_render) @@ -126,7 +167,6 @@ Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int s allocAlpha(m_alpha); - XRenderPictFormat *format = XRenderFindVisualFormat(disp, DefaultVisual(disp, screen_num)); diff --git a/src/FbTk/Transparent.hh b/src/FbTk/Transparent.hh index fe29826..9aeeead 100644 --- a/src/FbTk/Transparent.hh +++ b/src/FbTk/Transparent.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Transparent.hh,v 1.3 2003/05/13 21:16:27 fluxgen Exp $ +// $Id: Transparent.hh,v 1.4 2004/09/12 14:56:20 rathnor Exp $ #ifndef FBTK_TRANSPARENT_HH #define FBTK_TRANSPARENT_HH @@ -50,6 +50,10 @@ public: Drawable dest() const { return m_dest; } Drawable source() const { return m_source; } + static bool haveComposite(bool for_real = false); + static bool haveRender() { if (!s_init) init(); return s_render; } + static void usePseudoTransparent(bool no_composite); + private: void freeAlpha(); void allocAlpha(unsigned char newval); @@ -61,7 +65,8 @@ private: static bool s_init; static bool s_render; ///< wheter we have RENDER support - + static bool s_composite; ///< wheter we have Composite support + static void init(); }; }; // end namespace FbTk diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index d01b5cf..f5916af 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWinFrame.cc,v 1.78 2004/08/11 13:17:56 fluxgen Exp $ +// $Id: FbWinFrame.cc,v 1.79 2004/09/12 14:56:18 rathnor Exp $ #include "FbWinFrame.hh" @@ -29,6 +29,7 @@ #include "FbTk/App.hh" #include "FbTk/SimpleCommand.hh" #include "FbTk/Compose.hh" +#include "FbTk/Transparent.hh" #include "CompareWindow.hh" #include "FbWinFrameTheme.hh" @@ -215,7 +216,8 @@ void FbWinFrame::moveResize(int x, int y, unsigned int width, unsigned int heigh } else if (move) { m_window.move(x, y); // this stuff will be caught by reconfigure if resized - if (theme().alpha() != 255) { + unsigned char alpha = (m_focused?theme().focusedAlpha():theme().unfocusedAlpha()); + if (alpha != 255) { // restart update timer m_update_timer.start(); } @@ -240,6 +242,13 @@ void FbWinFrame::setFocus(bool newvalue) { renderButtonActive(*m_current_label); } + if (theme().focusedAlpha() != theme().unfocusedAlpha() && FbTk::Transparent::haveComposite()) { + if (m_focused) + m_window.setOpaque(theme().focusedAlpha()); + else + m_window.setOpaque(theme().unfocusedAlpha()); + } + renderTitlebar(); renderButtons(); // parent relative buttons -> need render after titlebar renderHandles(); @@ -894,8 +903,9 @@ void FbWinFrame::renderTitlebar() { else m_titlebar.setBackgroundColor(title_color); - m_titlebar.setAlpha(theme().alpha()); - m_label.setAlpha(theme().alpha()); + unsigned char alpha = (m_focused?theme().focusedAlpha():theme().unfocusedAlpha()); + m_titlebar.setAlpha(alpha); + m_label.setAlpha(alpha); renderLabelButtons(); redrawTitlebar(); @@ -953,9 +963,10 @@ void FbWinFrame::renderHandles() { } } - m_handle.setAlpha(theme().alpha()); - m_grip_left.setAlpha(theme().alpha()); - m_grip_right.setAlpha(theme().alpha()); + unsigned char alpha = (m_focused?theme().focusedAlpha():theme().unfocusedAlpha()); + m_handle.setAlpha(alpha); + m_grip_left.setAlpha(alpha); + m_grip_right.setAlpha(alpha); m_grip_left.clear(); m_grip_left.updateTransparent(); @@ -999,12 +1010,19 @@ void FbWinFrame::renderButtons() { void FbWinFrame::init() { - // setup update timer - FbTk::RefCount update_transp(new FbTk::SimpleCommand(*this, - &FbWinFrame::updateTransparent)); - m_update_timer.setCommand(update_transp); - m_update_timer.setTimeout(10L); - m_update_timer.fireOnce(true); + if (FbTk::Transparent::haveComposite()) { + if (m_focused) + m_window.setOpaque(theme().focusedAlpha()); + else + m_window.setOpaque(theme().unfocusedAlpha()); + } else { + // setup update timer + FbTk::RefCount update_transp(new FbTk::SimpleCommand(*this, + &FbWinFrame::updateTransparent)); + m_update_timer.setCommand(update_transp); + m_update_timer.setTimeout(10L); + m_update_timer.fireOnce(true); + } if (theme().handleWidth() == 0) m_use_handle = false; @@ -1052,6 +1070,7 @@ void FbWinFrame::setupButton(FbTk::Button &btn) { btn.setBackgroundPixmap(m_button_pm); else btn.setBackgroundColor(m_button_color); + btn.setAlpha(theme().focusedAlpha()); } else { // unfocused btn.setGC(m_theme.buttonPicUnfocusGC()); if (m_button_unfocused_pm) @@ -1059,9 +1078,9 @@ void FbWinFrame::setupButton(FbTk::Button &btn) { else btn.setBackgroundColor(m_button_unfocused_color); + btn.setAlpha(theme().unfocusedAlpha()); } - btn.setAlpha(theme().alpha()); } void FbWinFrame::render(const FbTk::Texture &tex, FbTk::Color &col, Pixmap &pm, @@ -1182,7 +1201,7 @@ void FbWinFrame::renderButtonFocus(FbTk::TextButton &button) { button.setGC(theme().labelTextFocusGC()); button.setJustify(theme().justify()); button.setBorderWidth(1); - button.setAlpha(theme().alpha()); + button.setAlpha(theme().focusedAlpha()); if (m_label_focused_pm != 0) { // already set @@ -1198,7 +1217,7 @@ void FbWinFrame::renderButtonActive(FbTk::TextButton &button) { button.setGC(theme().labelTextActiveGC()); button.setJustify(theme().justify()); button.setBorderWidth(1); - button.setAlpha(theme().alpha()); + button.setAlpha(theme().focusedAlpha()); if (m_label_active_pm != 0) { // already set @@ -1214,7 +1233,7 @@ void FbWinFrame::renderButtonUnfocus(FbTk::TextButton &button) { button.setGC(theme().labelTextUnfocusGC()); button.setJustify(theme().justify()); button.setBorderWidth(1); - button.setAlpha(theme().alpha()); + button.setAlpha(theme().unfocusedAlpha()); if (m_label_unfocused_pm != 0) { // already set @@ -1246,6 +1265,8 @@ private: } void FbWinFrame::updateTransparent() { + if (FbTk::Transparent::haveComposite()) + return; m_label.clear(); m_label.updateTransparent(); diff --git a/src/FbWinFrameTheme.cc b/src/FbWinFrameTheme.cc index e2e89fc..0161155 100644 --- a/src/FbWinFrameTheme.cc +++ b/src/FbWinFrameTheme.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWinFrameTheme.cc,v 1.18 2004/05/24 15:30:52 rathnor Exp $ +// $Id: FbWinFrameTheme.cc,v 1.19 2004/09/12 14:56:18 rathnor Exp $ #include "FbWinFrameTheme.hh" #include "App.hh" @@ -58,7 +58,6 @@ FbWinFrameTheme::FbWinFrameTheme(int screen_num): m_font(*this, "window.font", "Window.Font"), m_textjustify(*this, "window.justify", "Window.Justify"), m_shape_place(*this, "window.roundCorners", "Window.RoundCorners"), - m_alpha(*this, "window.alpha", "Window.Alpha"), m_title_height(*this, "window.title.height", "Window.Title.Height"), m_bevel_width(*this, "window.bevelWidth", "Window.BevelWidth"), m_handle_width(*this, "window.handleWidth", "Window.handleWidth"), @@ -67,12 +66,13 @@ FbWinFrameTheme::FbWinFrameTheme(int screen_num): m_label_text_unfocus_gc(RootWindow(FbTk::App::instance()->display(), screen_num)), m_label_text_active_gc(RootWindow(FbTk::App::instance()->display(), screen_num)), m_button_pic_focus_gc(RootWindow(FbTk::App::instance()->display(), screen_num)), - m_button_pic_unfocus_gc(RootWindow(FbTk::App::instance()->display(), screen_num)) { + m_button_pic_unfocus_gc(RootWindow(FbTk::App::instance()->display(), screen_num)), + m_focused_alpha(255), + m_unfocused_alpha(255) { *m_title_height = 0; // set defaults m_font->load("fixed"); - *m_alpha = 255; // create cursors Display *disp = FbTk::App::instance()->display(); @@ -105,20 +105,12 @@ bool FbWinFrameTheme::fallback(FbTk::ThemeItem_base &item) { } else if (item.name() == "window.label.active.textColor") { return FbTk::ThemeManager::instance().loadItem(item, "window.label.unfocus.textColor", "Window.Label.Unfocus.TextColor"); - } else if (item.name() == "window.alpha") { - *m_alpha = 255; - return true; } return false; } void FbWinFrameTheme::reconfigTheme() { - if (*m_alpha > 255) - *m_alpha = 255; - else if (*m_alpha < 0) - *m_alpha = 0; - if (*m_bevel_width > 20) *m_bevel_width = 20; else if (*m_bevel_width < 0) diff --git a/src/FbWinFrameTheme.hh b/src/FbWinFrameTheme.hh index 71f8753..e8397d0 100644 --- a/src/FbWinFrameTheme.hh +++ b/src/FbWinFrameTheme.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: FbWinFrameTheme.hh,v 1.15 2004/01/11 16:13:09 fluxgen Exp $ +// $Id: FbWinFrameTheme.hh,v 1.16 2004/09/12 14:56:18 rathnor Exp $ #ifndef FBWINFRAMETHEME_HH #define FBWINFRAMETHEME_HH @@ -94,12 +94,16 @@ public: inline Shape::ShapePlace shapePlace() const { return *m_shape_place; } inline const BorderTheme &border() const { return m_border; } - unsigned char alpha() const { return *m_alpha; } unsigned int titleHeight() const { return *m_title_height; } unsigned int bevelWidth() const { return *m_bevel_width; } unsigned int handleWidth() const { return *m_handle_width; } + unsigned char focusedAlpha() const { return m_focused_alpha; } + unsigned char unfocusedAlpha() const { return m_unfocused_alpha; } + void setFocusedAlpha(unsigned char alpha) { m_focused_alpha = alpha; } + void setUnfocusedAlpha(unsigned char alpha) { m_unfocused_alpha = alpha; } + private: FbTk::ThemeItem m_label_focus, m_label_unfocus, m_label_active; FbTk::ThemeItem m_title_focus, m_title_unfocus; @@ -114,7 +118,7 @@ private: FbTk::ThemeItem m_textjustify; FbTk::ThemeItem m_shape_place; - FbTk::ThemeItem m_alpha, m_title_height, m_bevel_width, m_handle_width; + FbTk::ThemeItem m_title_height, m_bevel_width, m_handle_width; BorderTheme m_border; FbTk::GContext m_label_text_focus_gc, m_label_text_unfocus_gc, m_label_text_active_gc; @@ -125,6 +129,8 @@ private: Cursor m_cursor_lower_right_angle; Cursor m_cursor_upper_left_angle; Cursor m_cursor_upper_right_angle; + unsigned char m_focused_alpha; + unsigned char m_unfocused_alpha; }; #endif // FBWINFRAMETHEME_HH diff --git a/src/GenericTool.cc b/src/GenericTool.cc index 05da41b..671a4eb 100644 --- a/src/GenericTool.cc +++ b/src/GenericTool.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: GenericTool.cc,v 1.3 2004/01/13 14:41:32 rathnor Exp $ +// $Id: GenericTool.cc,v 1.4 2004/09/12 14:56:18 rathnor Exp $ #include "GenericTool.hh" #include "FbTk/FbWindow.hh" @@ -76,13 +76,13 @@ unsigned int GenericTool::borderWidth() const { return m_window->borderWidth(); } - -void GenericTool::renderTheme() { - m_window->setAlpha(theme().alpha()); +void GenericTool::renderTheme(unsigned char alpha) { + m_window->setAlpha(alpha); m_window->clear(); m_window->updateTransparent(); } void GenericTool::update(FbTk::Subject *subj) { - renderTheme(); + m_window->clear(); + m_window->updateTransparent(); } diff --git a/src/GenericTool.hh b/src/GenericTool.hh index 75aad16..9633157 100644 --- a/src/GenericTool.hh +++ b/src/GenericTool.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: GenericTool.hh,v 1.2 2003/10/26 20:11:27 fluxgen Exp $ +// $Id: GenericTool.hh,v 1.3 2004/09/12 14:56:18 rathnor Exp $ #ifndef GENERICTOOL_HH #define GENERICTOOL_HH @@ -57,7 +57,7 @@ public: const FbTk::FbWindow &window() const { return *m_window; } protected: - virtual void renderTheme(); + virtual void renderTheme(unsigned char alpha); private: void update(FbTk::Subject *subj); diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 88670cb..b36690f 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconbarTool.cc,v 1.45 2004/09/05 00:37:16 fluxgen Exp $ +// $Id: IconbarTool.cc,v 1.46 2004/09/12 14:56:18 rathnor Exp $ #include "IconbarTool.hh" @@ -309,6 +309,7 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, BScr screen.iconListSig().attach(this); screen.currentWorkspaceSig().attach(this); // setup focus timer + FbTk::RefCount timer_cmd(new FbTk::SimpleCommand(*this, &IconbarTool::timedRender)); timeval to; to.tv_sec = 0; @@ -557,6 +558,12 @@ void IconbarTool::updateSizing() { } +void IconbarTool::renderTheme(unsigned char alpha) { + + m_alpha = alpha; + renderTheme(); +} + void IconbarTool::renderTheme() { // update button sizes before we get max width per client! @@ -619,7 +626,7 @@ void IconbarTool::renderTheme() { // set to zero so its consistent and not ugly m_icon_container.setBorderWidth(m_theme.border().width()); m_icon_container.setBorderColor(m_theme.border().color()); - m_icon_container.setAlpha(m_theme.alpha()); + m_icon_container.setAlpha(m_alpha); // update buttons IconList::iterator icon_it = m_icon_list.begin(); @@ -632,7 +639,7 @@ void IconbarTool::renderTheme() { void IconbarTool::renderButton(IconButton &button, bool clear) { button.setPixmap(*m_rc_use_pixmap); - button.setAlpha(m_theme.alpha()); + button.setAlpha(m_alpha); // The last button is always the regular width bool wider_button = false; diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index 96b51b5..e9036e7 100644 --- a/src/IconbarTool.hh +++ b/src/IconbarTool.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: IconbarTool.hh,v 1.15 2004/08/29 08:33:12 rathnor Exp $ +// $Id: IconbarTool.hh,v 1.16 2004/09/12 14:56:18 rathnor Exp $ #ifndef ICONBARTOOL_HH #define ICONBARTOOL_HH @@ -87,6 +87,7 @@ private: void renderButton(IconButton &button, bool clear = true); /// render all buttons void renderTheme(); + void renderTheme(unsigned char alpha); /// destroy all icons void deleteIcons(); /// remove a single window @@ -121,6 +122,7 @@ private: FbTk::Resource m_rc_use_pixmap; ///< if iconbar should use win pixmap or not FbTk::Timer m_focus_timer; ///< so we can update current window without flicker while changing attached clients FbMenu m_menu; + unsigned char m_alpha; }; #endif // ICONBARTOOL_HH diff --git a/src/Screen.cc b/src/Screen.cc index 4752ed4..9f5b07e 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Screen.cc,v 1.291 2004/09/11 23:01:34 fluxgen Exp $ +// $Id: Screen.cc,v 1.292 2004/09/12 14:56:18 rathnor Exp $ #include "Screen.hh" @@ -68,6 +68,7 @@ #include "FbTk/StringUtil.hh" #include "FbTk/ImageControl.hh" #include "FbTk/EventManager.hh" +#include "FbTk/Transparent.hh" //use GNU extensions #ifndef _GNU_SOURCE @@ -176,7 +177,9 @@ BScreen::ScreenResource::ScreenResource(FbTk::ResourceManager &rm, focus_model(rm, CLICKTOFOCUS, scrname+".focusModel", altscrname+".FocusModel"), workspaces(rm, 1, scrname+".workspaces", altscrname+".Workspaces"), edge_snap_threshold(rm, 0, scrname+".edgeSnapThreshold", altscrname+".EdgeSnapThreshold"), - menu_alpha(rm, 255, scrname+".menuAlpha", altscrname+".MenuAlpha"), + focused_alpha(rm, 255, scrname+".window.focus.alpha", altscrname+".Window.Focus.Alpha"), + unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha", altscrname+".Window.Unfocus.Alpha"), + menu_alpha(rm, 255, scrname+".menu.alpha", altscrname+".Menu.Alpha"), menu_delay(rm, 0, scrname + ".menuDelay", altscrname+".MenuDelay"), menu_delay_close(rm, 0, scrname + ".menuDelayClose", altscrname+".MenuDelayClose"), menu_mode(rm, FbTk::MenuTheme::DELAY_OPEN, scrname+".menuMode", altscrname+".MenuMode"), @@ -276,8 +279,8 @@ BScreen::BScreen(FbTk::ResourceManager &rm, imageControl().installRootColormap(); root_colormap_installed = true; - - + m_windowtheme->setFocusedAlpha(*resource.focused_alpha); + m_windowtheme->setUnfocusedAlpha(*resource.unfocused_alpha); m_menutheme->setAlpha(*resource.menu_alpha); m_menutheme->setMenuMode(*resource.menu_mode); // clamp values @@ -654,6 +657,8 @@ void BScreen::hideWindowMenus(const FluxboxWindow* except) { void BScreen::reconfigure() { + m_windowtheme->setFocusedAlpha(*resource.focused_alpha); + m_windowtheme->setUnfocusedAlpha(*resource.unfocused_alpha); m_menutheme->setAlpha(*resource.menu_alpha); m_menutheme->setMenuMode(*resource.menu_mode); @@ -1814,14 +1819,41 @@ void BScreen::setupConfigmenu(FbTk::Menu &menu) { "AntiAlias", "Use Anti-aliased fonts", *resource.antialias, save_and_reconfigure); #endif // USE_XFT -#undef _BOOLITEM #ifdef HAVE_XRENDER - FbTk::MenuItem *menu_alpha_item = new IntResMenuItem("Menu Alpha", resource.menu_alpha, - 0, 255); - menu_alpha_item->setCommand(saverc_cmd); - menu.insert(menu_alpha_item); + if (FbTk::Transparent::haveRender() || + FbTk::Transparent::haveComposite()) { + + const char *alphamenu_label = _FBTEXT(Configmenu, Transparency, + "Transparency", "Menu containing various transparency options"); + FbTk::Menu *alpha_menu = createMenu(alphamenu_label ? alphamenu_label : ""); + + if (FbTk::Transparent::haveComposite(true)) { + alpha_menu->insert(new BoolMenuItem(_FBTEXT(Configmenu, ForcePseudoTrans, + "Force Pseudo-Transparency", "When composite is available, still use old pseudo-transparency"), + Fluxbox::instance()->getPseudoTrans(), save_and_reconfigure)); + } + + FbTk::MenuItem *focused_alpha_item = new IntResMenuItem(_FBTEXT(Configmenu, FocusedAlpha, "Focused Window Alpha", "Transparency level of the focused window"), + resource.focused_alpha, 0, 255); + focused_alpha_item->setCommand(saverc_cmd); + alpha_menu->insert(focused_alpha_item); + + FbTk::MenuItem *unfocused_alpha_item = new IntResMenuItem(_FBTEXT(Configmenu, UnfocusedAlpha, "Unfocused Window Alpha", "Transparency level of unfocused windows"), + resource.unfocused_alpha, 0, 255); + unfocused_alpha_item->setCommand(saverc_cmd); + alpha_menu->insert(unfocused_alpha_item); + + FbTk::MenuItem *menu_alpha_item = new IntResMenuItem(_FBTEXT(Configmenu, MenuAlpha, "Menu Alpha", "Transparency level of menu"), + resource.menu_alpha, 0, 255); + menu_alpha_item->setCommand(saverc_cmd); + alpha_menu->insert(menu_alpha_item); + + alpha_menu->update(); + menu.insert(alphamenu_label, alpha_menu); + } #endif // HAVE_XRENDER +#undef _BOOLITEM // finaly update menu diff --git a/src/Screen.hh b/src/Screen.hh index ad460a8..2cfbe73 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Screen.hh,v 1.145 2004/09/11 13:29:35 fluxgen Exp $ +// $Id: Screen.hh,v 1.146 2004/09/12 14:56:19 rathnor Exp $ #ifndef SCREEN_HH #define SCREEN_HH @@ -434,7 +434,8 @@ private: FbTk::Resource windowmenufile; FbTk::Resource focus_model; bool ordered_dither; - FbTk::Resource workspaces, edge_snap_threshold, menu_alpha, menu_delay, menu_delay_close; + FbTk::Resource workspaces, edge_snap_threshold, focused_alpha, + unfocused_alpha, menu_alpha, menu_delay, menu_delay_close; FbTk::Resource menu_mode; FbTk::Resource placement_policy; FbTk::Resource row_direction; diff --git a/src/Slit.cc b/src/Slit.cc index 0023965..4413c48 100644 --- a/src/Slit.cc +++ b/src/Slit.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Slit.cc,v 1.101 2004/09/11 18:58:27 fluxgen Exp $ +// $Id: Slit.cc,v 1.102 2004/09/12 14:56:19 rathnor Exp $ #include "Slit.hh" @@ -296,7 +296,12 @@ Slit::Slit(BScreen &scr, FbTk::XLayer &layer, const char *filename) FbTk::EventManager::instance()->add(*this, frame.window); - frame.window.setAlpha(*m_rc_alpha); + if (FbTk::Transparent::haveComposite()) { + frame.window.setOpaque(*m_rc_alpha); + } else { + frame.window.setAlpha(*m_rc_alpha); + } + m_layeritem.reset(new FbTk::XLayerItem(frame.window, layer)); m_layermenu.reset(new LayerMenu(scr.menuTheme(), scr.imageControl(), @@ -679,7 +684,11 @@ void Slit::reconfigure() { if (tmp) image_ctrl.removeImage(tmp); - frame.window.setAlpha(*m_rc_alpha); + if (FbTk::Transparent::haveComposite()) { + frame.window.setOpaque(*m_rc_alpha); + } else { + frame.window.setAlpha(*m_rc_alpha); + } clearWindow(); int x = 0, y = 0; @@ -1195,9 +1204,9 @@ void Slit::setupMenu() { 0, 255); // setup command for alpha value MacroCommand *alpha_macrocmd = new MacroCommand(); - RefCount clear_cmd(new SimpleCommand(*this, &Slit::clearWindow)); + RefCount alpha_cmd(new SimpleCommand(*this, &Slit::updateAlpha)); alpha_macrocmd->add(saverc_cmd); - alpha_macrocmd->add(clear_cmd); + alpha_macrocmd->add(alpha_cmd); RefCount set_alpha_cmd(alpha_macrocmd); alpha_menuitem->setCommand(set_alpha_cmd); @@ -1263,3 +1272,12 @@ void Slit::saveOnHead(int head) { reconfigure(); } +void Slit::updateAlpha() { + // called when the alpha resource is changed + if (FbTk::Transparent::haveComposite()) { + frame.window.setOpaque(*m_rc_alpha); + } else { + frame.window.setAlpha(*m_rc_alpha); + clearWindow(); + } +} diff --git a/src/Slit.hh b/src/Slit.hh index 8b3249f..6f5b428 100644 --- a/src/Slit.hh +++ b/src/Slit.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -/// $Id: Slit.hh,v 1.42 2004/09/11 18:58:27 fluxgen Exp $ +/// $Id: Slit.hh,v 1.43 2004/09/12 14:56:19 rathnor Exp $ #ifndef SLIT_HH #define SLIT_HH @@ -120,6 +120,7 @@ public: const SlitClients &clients() const { return m_client_list; } SlitClients &clients() { return m_client_list; } private: + void updateAlpha(); void clearWindow(); void setupMenu(); diff --git a/src/SystemTray.hh b/src/SystemTray.hh index 2091241..91a017d 100644 --- a/src/SystemTray.hh +++ b/src/SystemTray.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: SystemTray.hh,v 1.6 2004/08/29 08:33:12 rathnor Exp $ +// $Id: SystemTray.hh,v 1.7 2004/09/12 14:56:19 rathnor Exp $ #ifndef SYSTEMTRAY_HH #define SYSTEMTRAY_HH @@ -65,7 +65,7 @@ public: int numClients() const { return m_clients.size(); } const FbTk::FbWindow &window() const { return m_window; } - inline void renderTheme() {} + inline void renderTheme(unsigned char alpha) {} inline void updateSizing() {} private: diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc index 6c1d4f8..160e1b3 100644 --- a/src/ToolFactory.cc +++ b/src/ToolFactory.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ToolFactory.cc,v 1.8 2004/09/11 13:40:57 fluxgen Exp $ +// $Id: ToolFactory.cc,v 1.9 2004/09/12 14:56:19 rathnor Exp $ #include "ToolFactory.hh" @@ -83,25 +83,26 @@ ToolFactory::ToolFactory(BScreen &screen):m_screen(screen), } ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &parent, Toolbar &tbar) { + ToolbarItem * item; unsigned int button_size = 24; if (tbar.theme().buttonSize() > 0) button_size = tbar.theme().buttonSize(); if (name == "workspacename") { - WorkspaceNameTool *item = new WorkspaceNameTool(parent, + WorkspaceNameTool *witem = new WorkspaceNameTool(parent, *m_workspace_theme, screen()); using namespace FbTk; RefCount showmenu(new ShowMenuAboveToolbar(tbar)); - item->button().setOnClick(showmenu); - return item; + witem->button().setOnClick(showmenu); + item = witem; } else if (name == "iconbar") { - return new IconbarTool(parent, m_iconbar_theme, + item = new IconbarTool(parent, m_iconbar_theme, screen(), tbar.menu()); } else if (name == "systemtray") { - return new SystemTray(parent); + item = new SystemTray(parent); } else if (name == "clock") { - return new ClockTool(parent, m_clock_theme, screen(), tbar.menu()); + item = new ClockTool(parent, m_clock_theme, screen(), tbar.menu()); } else if (name == "nextworkspace" || name == "prevworkspace") { @@ -118,7 +119,7 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow & 0, 0, button_size, button_size); win->setOnClick(cmd); - return new ButtonTool(win, ToolbarItem::SQUARE, + item = new ButtonTool(win, ToolbarItem::SQUARE, dynamic_cast(*m_button_theme), screen().imageControl()); @@ -137,13 +138,16 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow & 0, 0, button_size, button_size); win->setOnClick(cmd); - return new ButtonTool(win, ToolbarItem::SQUARE, + item = new ButtonTool(win, ToolbarItem::SQUARE, dynamic_cast(*m_button_theme), screen().imageControl()); } - return 0; + if (item) + item->renderTheme(tbar.alpha()); + + return item; } void ToolFactory::updateThemes() { diff --git a/src/ToolTheme.cc b/src/ToolTheme.cc index cdd4bf7..c13ec96 100644 --- a/src/ToolTheme.cc +++ b/src/ToolTheme.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ToolTheme.cc,v 1.7 2004/08/25 17:16:40 rathnor Exp $ +// $Id: ToolTheme.cc,v 1.8 2004/09/12 14:56:19 rathnor Exp $ #include "ToolTheme.hh" @@ -29,7 +29,7 @@ ToolTheme::ToolTheme(int screen_num, const std::string &name, const std::string TextTheme(*this, name, altname), m_texture(*this, name, altname), m_border(*this, name, altname), - m_alpha(*this, name+".alpha", altname+".Alpha") { + m_alpha(255) { } @@ -54,12 +54,6 @@ bool ToolTheme::fallback(FbTk::ThemeItem_base &item) { return FbTk::ThemeManager::instance().loadItem(item, "toolbar.justify", "Toolbar.Justify"); - } else if (item.name().find(".alpha") != std::string::npos) { - if (!FbTk::ThemeManager::instance().loadItem(item, - "toolbar.alpha", - "Toolbar.Alpha")) - *m_alpha = 255; - return true; } return false; diff --git a/src/ToolTheme.hh b/src/ToolTheme.hh index 5ca5401..ef4bbdf 100644 --- a/src/ToolTheme.hh +++ b/src/ToolTheme.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ToolTheme.hh,v 1.5 2004/01/13 14:41:32 rathnor Exp $ +// $Id: ToolTheme.hh,v 1.6 2004/09/12 14:56:19 rathnor Exp $ #ifndef TOOLTHEME_HH #define TOOLTHEME_HH @@ -48,7 +48,8 @@ public: // textures const FbTk::Texture &texture() const { return *m_texture; } const BorderTheme &border() const { return m_border; } - inline unsigned char alpha() const { return *m_alpha; } + inline unsigned char alpha() const { return m_alpha; } + inline void setAlpha(unsigned char alpha) { m_alpha = alpha; } protected: FbTk::ThemeItem &textureTheme() { return m_texture; } @@ -56,7 +57,7 @@ protected: private: FbTk::ThemeItem m_texture; BorderTheme m_border; - FbTk::ThemeItem m_alpha; + unsigned char m_alpha; }; #endif // TOOLTHEME_HH diff --git a/src/Toolbar.cc b/src/Toolbar.cc index 19e85db..b1471aa 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Toolbar.cc,v 1.154 2004/09/11 13:34:01 fluxgen Exp $ +// $Id: Toolbar.cc,v 1.155 2004/09/12 14:56:19 rathnor Exp $ #include "Toolbar.hh" @@ -46,6 +46,7 @@ #include "FbTk/EventManager.hh" #include "FbTk/SimpleCommand.hh" #include "FbTk/StringUtil.hh" +#include "FbTk/Transparent.hh" // use GNU extensions @@ -170,7 +171,7 @@ Toolbar::Frame::Frame(FbTk::EventHandler &evh, int screen_num): 0, 0, // pos 10, 10, // size // event mask - ButtonPressMask | ButtonReleaseMask | + ButtonPressMask | ButtonReleaseMask | ExposureMask | EnterWindowMask | LeaveWindowMask | SubstructureNotifyMask, true) // override redirect @@ -216,6 +217,8 @@ Toolbar::Toolbar(BScreen &scrn, FbTk::XLayer &layer, size_t width): m_rc_visible(scrn.resourceManager(), true, scrn.name() + ".toolbar.visible", scrn.altName() + ".Toolbar.Visible"), m_rc_width_percent(scrn.resourceManager(), 65, scrn.name() + ".toolbar.widthPercent", scrn.altName() + ".Toolbar.WidthPercent"), + m_rc_alpha(scrn.resourceManager(), 255, + scrn.name() + ".toolbar.alpha", scrn.altName() + ".Toolbar.Alpha"), m_rc_layernum(scrn.resourceManager(), Fluxbox::Layer(Fluxbox::instance()->getDesktopLayer()), scrn.name() + ".toolbar.layer", scrn.altName() + ".Toolbar.Layer"), m_rc_on_head(scrn.resourceManager(), 0, @@ -450,7 +453,13 @@ void Toolbar::reconfigure() { frame.window.setBorderColor(theme().border().color()); frame.window.setBorderWidth(theme().border().width()); - frame.window.setAlpha(theme().alpha()); + + bool have_composite = FbTk::Transparent::haveComposite(); + if (have_composite) { + frame.window.setOpaque(alpha()); + } else { + frame.window.setAlpha(alpha()); + } frame.window.clear(); frame.window.updateTransparent(); @@ -466,7 +475,7 @@ void Toolbar::reconfigure() { rearrangeItems(); for (item_it = m_item_list.begin(); item_it != item_it_end; ++item_it) { - (*item_it)->renderTheme(); + (*item_it)->renderTheme(alpha()); } menu().reconfigure(); @@ -872,6 +881,22 @@ void Toolbar::setupMenus() { } menu().insert(_FBTEXT(Menu, Placement, "Placement", "Title of Placement menu"), &placementMenu()); placementMenu().update(); + + + // this saves resources and clears the slit window to update alpha value + FbTk::MenuItem *alpha_menuitem = + new IntResMenuItem(_FBTEXT(Common, Alpha, "Alpha", "Transparency level"), + m_rc_alpha, + 0, 255); + // setup command for alpha value + MacroCommand *alpha_macrocmd = new MacroCommand(); + RefCount alpha_cmd(new SimpleCommand(*this, &Toolbar::updateAlpha)); + alpha_macrocmd->add(save_resources); + alpha_macrocmd->add(alpha_cmd); + RefCount set_alpha_cmd(alpha_macrocmd); + alpha_menuitem->setCommand(set_alpha_cmd); + + menu().insert(alpha_menuitem); menu().update(); } @@ -1012,3 +1037,20 @@ void Toolbar::deleteItems() { } m_tools.clear(); } + +void Toolbar::updateAlpha() { + // called when the alpha resource is changed + if (FbTk::Transparent::haveComposite()) { + frame.window.setOpaque(*m_rc_alpha); + } else { + frame.window.setAlpha(*m_rc_alpha); + frame.window.clear(); + frame.window.updateTransparent(); + + ItemList::iterator item_it = m_item_list.begin(); + ItemList::iterator item_it_end = m_item_list.end(); + for (item_it = m_item_list.begin(); item_it != item_it_end; ++item_it) { + (*item_it)->renderTheme(alpha()); + } + } +} diff --git a/src/Toolbar.hh b/src/Toolbar.hh index 5a00855..6e49e10 100644 --- a/src/Toolbar.hh +++ b/src/Toolbar.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Toolbar.hh,v 1.53 2004/06/07 21:32:11 fluxgen Exp $ +// $Id: Toolbar.hh,v 1.54 2004/09/12 14:56:19 rathnor Exp $ #ifndef TOOLBAR_HH #define TOOLBAR_HH @@ -131,7 +131,8 @@ public: bool isVertical() const; inline int getOnHead() const { return *m_rc_on_head; } - + + inline unsigned char alpha() const { return *m_rc_alpha; } private: void rearrangeItems(); void deleteItems(); @@ -140,6 +141,7 @@ private: void setupMenus(); void clearStrut(); void updateStrut(); + void updateAlpha(); bool m_hidden; ///< hidden state @@ -179,6 +181,7 @@ private: // resources FbTk::Resource m_rc_auto_hide, m_rc_maximize_over, m_rc_visible; FbTk::Resource m_rc_width_percent; + FbTk::Resource m_rc_alpha; FbTk::Resource m_rc_layernum; FbTk::Resource m_rc_on_head; FbTk::Resource m_rc_placement; diff --git a/src/ToolbarItem.hh b/src/ToolbarItem.hh index 0e77766..90fe6f3 100644 --- a/src/ToolbarItem.hh +++ b/src/ToolbarItem.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ToolbarItem.hh,v 1.6 2004/08/29 08:33:13 rathnor Exp $ +// $Id: ToolbarItem.hh,v 1.7 2004/09/12 14:56:19 rathnor Exp $ #ifndef TOOLBARITEM_HH #define TOOLBARITEM_HH @@ -55,7 +55,7 @@ public: // Tools should NOT listen to theme changes - they'll get notified by // the toolbar instead. Otherwise there are ordering problems. - virtual void renderTheme() = 0; + virtual void renderTheme(unsigned char alpha) = 0; // just update theme items that affect the size virtual void updateSizing() = 0; diff --git a/src/ToolbarTheme.cc b/src/ToolbarTheme.cc index 0c3e3ea..f9d00ee 100644 --- a/src/ToolbarTheme.cc +++ b/src/ToolbarTheme.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ToolbarTheme.cc,v 1.16 2004/08/25 17:16:40 rathnor Exp $ +// $Id: ToolbarTheme.cc,v 1.17 2004/09/12 14:56:19 rathnor Exp $ #include "ToolbarTheme.hh" @@ -50,7 +50,6 @@ ToolbarTheme::ToolbarTheme(int screen_num): m_border(*this, "toolbar", "Toolbar"), m_bevel_width(*this, "toolbar.bevelWidth", "Toolbar.BevelWidth"), m_shape(*this, "toolbar.shaped", "Toolbar.Shaped"), - m_alpha(*this, "toolbar.alpha", "Toolbar.Alpha"), m_height(*this, "toolbar.height", "Toolbar.Height"), m_button_size(*this, "toolbar.button.size", "Toolbar.Button.Size") { // set default value @@ -69,9 +68,6 @@ bool ToolbarTheme::fallback(FbTk::ThemeItem_base &item) { return FbTk::ThemeManager::instance().loadItem(item, "borderWidth", "BorderWidth"); } else if (item.name().find(".borderColor") != std::string::npos) { return FbTk::ThemeManager::instance().loadItem(item, "borderColor", "BorderColor"); - } else if (item.name() == "toolbar.alpha") { - *m_alpha = 255; - return true; } else if (item.name() == "toolbar.bevelWidth") { return FbTk::ThemeManager::instance().loadItem(item, "bevelWidth", "BevelWidth"); } @@ -79,11 +75,6 @@ bool ToolbarTheme::fallback(FbTk::ThemeItem_base &item) { } void ToolbarTheme::reconfigTheme() { - if (*m_alpha > 255) - *m_alpha = 255; - else if (*m_alpha < 0) - *m_alpha = 0; - if (*m_bevel_width > 20) *m_bevel_width = 20; diff --git a/src/ToolbarTheme.hh b/src/ToolbarTheme.hh index aa654c8..ef486f1 100644 --- a/src/ToolbarTheme.hh +++ b/src/ToolbarTheme.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ToolbarTheme.hh,v 1.11 2004/05/24 15:30:52 rathnor Exp $ +// $Id: ToolbarTheme.hh,v 1.12 2004/09/12 14:56:19 rathnor Exp $ #ifndef TOOLBARTHEME_HH #define TOOLBARTHEME_HH @@ -46,7 +46,6 @@ public: inline int bevelWidth() const { return *m_bevel_width; } inline bool shape() const { return *m_shape; } - inline unsigned char alpha() const { return *m_alpha; } inline int height() const { return *m_height; } inline int buttonSize() const { return *m_button_size; } private: @@ -55,7 +54,7 @@ private: FbTk::ThemeItem m_bevel_width; FbTk::ThemeItem m_shape; - FbTk::ThemeItem m_alpha, m_height, m_button_size; + FbTk::ThemeItem m_height, m_button_size; }; #endif // TOOLBARTHEME_HH diff --git a/src/WorkspaceNameTool.cc b/src/WorkspaceNameTool.cc index 245fce5..1dc339f 100644 --- a/src/WorkspaceNameTool.cc +++ b/src/WorkspaceNameTool.cc @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: WorkspaceNameTool.cc,v 1.10 2004/08/29 08:33:13 rathnor Exp $ +// $Id: WorkspaceNameTool.cc,v 1.11 2004/09/12 14:56:19 rathnor Exp $ #include "WorkspaceNameTool.hh" @@ -46,7 +46,6 @@ WorkspaceNameTool::WorkspaceNameTool(const FbTk::FbWindow &parent, screen.currentWorkspaceSig().attach(this); theme.reconfigSig().attach(this); - renderTheme(); } WorkspaceNameTool::~WorkspaceNameTool() { @@ -74,7 +73,8 @@ void WorkspaceNameTool::update(FbTk::Subject *subj) { resize(width(), height()); resizeSig().notify(); } - renderTheme(); + reRender(); + m_button.clear(); } unsigned int WorkspaceNameTool::width() const { @@ -113,22 +113,29 @@ void WorkspaceNameTool::updateSizing() { m_button.setBorderWidth(m_theme.border().width()); } -void WorkspaceNameTool::renderTheme() { - Pixmap tmp = m_pixmap; +void WorkspaceNameTool::reRender() { + if (m_theme.texture().usePixmap()) { + if (m_pixmap) + m_screen.imageControl().removeImage(m_pixmap); + m_pixmap = m_screen.imageControl().renderImage(width(), height(), + m_theme.texture()); + m_button.setBackgroundPixmap(m_pixmap); + } +} + +void WorkspaceNameTool::renderTheme(unsigned char alpha) { if (!m_theme.texture().usePixmap()) { + if (m_pixmap) + m_screen.imageControl().removeImage(m_pixmap); m_pixmap = 0; m_button.setBackgroundColor(m_theme.texture().color()); } else { - m_pixmap = m_screen.imageControl().renderImage(width(), height(), - m_theme.texture()); - m_button.setBackgroundPixmap(m_pixmap); + reRender(); } - if (tmp) - m_screen.imageControl().removeImage(tmp); m_button.setJustify(m_theme.justify()); m_button.setBorderWidth(m_theme.border().width()); m_button.setBorderColor(m_theme.border().color()); - m_button.setAlpha(m_theme.alpha()); + m_button.setAlpha(alpha); m_button.clear(); } diff --git a/src/WorkspaceNameTool.hh b/src/WorkspaceNameTool.hh index bc6dd63..01bece7 100644 --- a/src/WorkspaceNameTool.hh +++ b/src/WorkspaceNameTool.hh @@ -20,7 +20,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: WorkspaceNameTool.hh,v 1.5 2004/08/29 08:33:13 rathnor Exp $ +// $Id: WorkspaceNameTool.hh,v 1.6 2004/09/12 14:56:19 rathnor Exp $ #ifndef WORKSPACENAMETOOL_HH #define WORKSPACENAMETOOL_HH @@ -53,7 +53,8 @@ public: FbTk::Button &button() { return m_button; } const FbTk::Button &button() const { return m_button; } private: - void renderTheme(); + void renderTheme(unsigned char alpha); + void reRender(); void updateSizing(); FbTk::TextButton m_button; const ToolTheme &m_theme; diff --git a/src/fluxbox.cc b/src/fluxbox.cc index c7828ac..24f2556 100644 --- a/src/fluxbox.cc +++ b/src/fluxbox.cc @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: fluxbox.cc,v 1.256 2004/09/12 14:01:29 fluxgen Exp $ +// $Id: fluxbox.cc,v 1.257 2004/09/12 14:56:19 rathnor Exp $ #include "fluxbox.hh" @@ -49,6 +49,7 @@ #include "FbTk/RefCount.hh" #include "FbTk/SimpleCommand.hh" #include "FbTk/CompareEqual.hh" +#include "FbTk/Transparent.hh" //Use GNU extensions #ifndef _GNU_SOURCE @@ -203,6 +204,7 @@ Fluxbox::Fluxbox(int argc, char **argv, const char *dpy_name, const char *rcfile m_screen_rm(m_resourcemanager), m_rc_tabs(m_resourcemanager, true, "session.tabs", "Session.Tabs"), m_rc_ignoreborder(m_resourcemanager, false, "session.ignoreBorder", "Session.IgnoreBorder"), + m_rc_pseudotrans(m_resourcemanager, false, "session.forcePseudoTransparency", "Session.forcePseudoTransparency"), m_rc_colors_per_channel(m_resourcemanager, 4, "session.colorsPerChannel", "Session.ColorsPerChannel"), m_rc_numlayers(m_resourcemanager, 13, "session.numLayers", "Session.NumLayers"), @@ -1469,6 +1471,9 @@ void Fluxbox::load_rc() { if (m_rc_menufile->empty()) m_rc_menufile.setDefaultValue(); + + if (FbTk::Transparent::haveComposite()) + FbTk::Transparent::usePseudoTransparent(*m_rc_pseudotrans); if (!m_rc_slitlistfile->empty()) { *m_rc_slitlistfile = StringUtil::expandFilename(*m_rc_slitlistfile); diff --git a/src/fluxbox.hh b/src/fluxbox.hh index 96b883d..6258651 100644 --- a/src/fluxbox.hh +++ b/src/fluxbox.hh @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: fluxbox.hh,v 1.90 2004/08/31 15:26:39 rathnor Exp $ +// $Id: fluxbox.hh,v 1.91 2004/09/12 14:56:19 rathnor Exp $ #ifndef FLUXBOX_HH #define FLUXBOX_HH @@ -114,8 +114,8 @@ public: enum TabsAttachArea{ATTACH_AREA_WINDOW= 0, ATTACH_AREA_TITLEBAR}; - inline bool getIgnoreBorder() const { return *m_rc_ignoreborder; } + inline bool &getPseudoTrans() { return *m_rc_pseudotrans; } inline const std::vector& getTitlebarRight() const { return *m_rc_titlebar_right; } inline const std::vector& getTitlebarLeft() const { return *m_rc_titlebar_left; } @@ -251,6 +251,7 @@ private: //--- Resources FbTk::Resource m_rc_tabs, m_rc_ignoreborder; + FbTk::Resource m_rc_pseudotrans; FbTk::Resource m_rc_colors_per_channel, m_rc_numlayers, m_rc_double_click_interval, m_rc_update_delay_time; FbTk::Resource m_rc_stylefile, -- cgit v0.11.2