From d11aa42ace928efc3dd1eebc8988b6bbbc005b2b Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Tue, 22 Feb 2011 22:07:39 +0100 Subject: bugfix: consistent use of 'int' for alpha values (#3187373) WindowMenuAccessor returned strange alpha values if compiled with 'g++ -Os'; unholy black magic happens if template faces functions returning only 'usigned char'. --- src/ButtonTool.cc | 2 +- src/ButtonTool.hh | 2 +- src/ClockTool.cc | 2 +- src/ClockTool.hh | 2 +- src/FbTk/Container.cc | 2 +- src/FbTk/Container.hh | 2 +- src/FbTk/FbWindow.cc | 8 ++++---- src/FbTk/FbWindow.hh | 6 +++--- src/FbTk/MenuTheme.hh | 4 ++-- src/FbTk/Transparent.cc | 10 +++++----- src/FbTk/Transparent.hh | 8 ++++---- src/FbWinFrame.cc | 22 ++++++++++++---------- src/FbWinFrame.hh | 10 +++++----- src/FbWinFrameTheme.hh | 6 +++--- src/FocusControl.cc | 2 +- src/GenericTool.cc | 2 +- src/GenericTool.hh | 2 +- src/IconbarTool.cc | 2 +- src/IconbarTool.hh | 4 ++-- src/SystemTray.hh | 2 +- src/ToolTheme.hh | 6 +++--- src/ToolbarItem.hh | 2 +- src/Window.hh | 10 +++++----- src/WindowMenuAccessor.hh | 4 +++- src/WorkspaceNameTool.cc | 2 +- src/WorkspaceNameTool.hh | 2 +- 26 files changed, 65 insertions(+), 61 deletions(-) diff --git a/src/ButtonTool.cc b/src/ButtonTool.cc index 0e11733..ad54534 100644 --- a/src/ButtonTool.cc +++ b/src/ButtonTool.cc @@ -49,7 +49,7 @@ void ButtonTool::updateSizing() { btn.setBorderWidth(theme()->border().width()); } -void ButtonTool::renderTheme(unsigned char alpha) { +void ButtonTool::renderTheme(int alpha) { FbTk::Button &btn = static_cast(window()); btn.setGC(static_cast(*theme()).gc()); diff --git a/src/ButtonTool.hh b/src/ButtonTool.hh index 484fea6..ec74618 100644 --- a/src/ButtonTool.hh +++ b/src/ButtonTool.hh @@ -41,7 +41,7 @@ public: virtual ~ButtonTool(); protected: - void renderTheme(unsigned char alpha); + void renderTheme(int 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 f6a9797..257058f 100644 --- a/src/ClockTool.cc +++ b/src/ClockTool.cc @@ -334,7 +334,7 @@ void ClockTool::reRender() { } -void ClockTool::renderTheme(unsigned char alpha) { +void ClockTool::renderTheme(int alpha) { m_button.setAlpha(alpha); m_button.setJustify(m_theme->justify()); diff --git a/src/ClockTool.hh b/src/ClockTool.hh index cbc676f..d2b9dca 100644 --- a/src/ClockTool.hh +++ b/src/ClockTool.hh @@ -69,7 +69,7 @@ public: private: void updateTime(); void update(FbTk::Subject *subj); - void renderTheme(unsigned char alpha); + void renderTheme(int alpha); void reRender(); void updateSizing(); diff --git a/src/FbTk/Container.cc b/src/FbTk/Container.cc index e1d2e07..b944c98 100644 --- a/src/FbTk/Container.cc +++ b/src/FbTk/Container.cc @@ -440,7 +440,7 @@ void Container::for_each(std::mem_fun_t function) { std::for_each(begin(), end(), function); } -void Container::setAlpha(unsigned char alpha) { +void Container::setAlpha(int alpha) { FbWindow::setAlpha(alpha); STLUtil::forAll(m_item_list, std::bind2nd(std::mem_fun(&Button::setAlpha), alpha)); } diff --git a/src/FbTk/Container.hh b/src/FbTk/Container.hh index bd5e3aa..f3d9bac 100644 --- a/src/FbTk/Container.hh +++ b/src/FbTk/Container.hh @@ -91,7 +91,7 @@ public: bool updateLock() const { return m_update_lock; } void for_each(std::mem_fun_t function); - void setAlpha(unsigned char alpha); // set alpha on all windows + void setAlpha(int alpha); // set alpha on all windows ItemList::iterator begin() { return m_item_list.begin(); } ItemList::iterator end() { return m_item_list.end(); } diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc index 5b52a03..00dde66 100644 --- a/src/FbTk/FbWindow.cc +++ b/src/FbTk/FbWindow.cc @@ -171,7 +171,7 @@ void FbWindow::invalidateBackground() { void FbWindow::updateBackground(bool only_if_alpha) { Pixmap newbg = m_lastbg_pm; - unsigned char alpha = 255; + int alpha = 255; bool free_newbg = false; if (m_lastbg_pm == None && !m_lastbg_color_set) @@ -344,7 +344,7 @@ void FbWindow::updateTransparent(int the_x, int the_y, unsigned int the_width, u #endif // HAVE_XRENDER } -void FbWindow::setAlpha(unsigned char alpha) { +void FbWindow::setAlpha(int alpha) { #ifdef HAVE_XRENDER if (FbTk::Transparent::haveComposite()) { if (m_transparent.get() != 0) { @@ -371,7 +371,7 @@ void FbWindow::setAlpha(unsigned char alpha) { #endif // HAVE_XRENDER } -unsigned char FbWindow::alpha() const { +int FbWindow::alpha() const { #ifdef HAVE_XRENDER if (m_transparent.get()) return m_transparent->alpha(); @@ -588,7 +588,7 @@ long FbWindow::eventMask() const { } -void FbWindow::setOpaque(unsigned char alpha) { +void FbWindow::setOpaque(int alpha) { #ifdef HAVE_XRENDER static Atom m_alphaatom = XInternAtom(display(), "_NET_WM_WINDOW_OPACITY", False); unsigned long opacity = alpha * 0x1010101; diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh index edeffe1..9e92923 100644 --- a/src/FbTk/FbWindow.hh +++ b/src/FbTk/FbWindow.hh @@ -88,7 +88,7 @@ public: unsigned int height = 0, Pixmap dest_override = None, bool override_is_offset = false); - void setAlpha(unsigned char alpha); + void setAlpha(int alpha); virtual FbWindow &operator = (const FbWindow &win); /// assign a new X window to this @@ -176,7 +176,7 @@ public: unsigned int borderWidth() const { return m_border_width; } unsigned long borderColor() const { return m_border_color; } unsigned int depth() const { return m_depth; } - unsigned char alpha() const; + int alpha() const; int screenNumber() const; long eventMask() const; @@ -188,7 +188,7 @@ public: bool operator != (const FbWindow &win) const { return m_window != win.m_window; } // used for composite - void setOpaque(unsigned char alpha); + void setOpaque(int alpha); void setRenderer(FbWindowRenderer &renderer) { m_renderer = &renderer; } void sendConfigureNotify(int x, int y, unsigned int width, diff --git a/src/FbTk/MenuTheme.hh b/src/FbTk/MenuTheme.hh index c10615b..eb19798 100644 --- a/src/FbTk/MenuTheme.hh +++ b/src/FbTk/MenuTheme.hh @@ -107,7 +107,7 @@ public: unsigned int bevelWidth() const { return *m_bevel_width; } unsigned char alpha() const { return m_alpha; } - void setAlpha(unsigned char alpha) { m_alpha = alpha; } + void setAlpha(int alpha) { m_alpha = alpha; } // this isn't actually a theme item // but we'll let it be here for now, until there's a better way to // get resources into menu @@ -154,7 +154,7 @@ private: Display *m_display; GContext t_text_gc, f_text_gc, u_text_gc, h_text_gc, d_text_gc, hilite_gc; - unsigned char m_alpha; + int m_alpha; unsigned int m_delay; ///< in msec unsigned int m_real_title_height; ///< the calculated item height (from font and menu.titleHeight) unsigned int m_real_item_height; ///< the calculated item height (from font and menu.itemHeight) diff --git a/src/FbTk/Transparent.cc b/src/FbTk/Transparent.cc index bf8a110..04fee67 100644 --- a/src/FbTk/Transparent.cc +++ b/src/FbTk/Transparent.cc @@ -43,7 +43,7 @@ using std::endl; namespace { #ifdef HAVE_XRENDER -Picture createAlphaPic(Window drawable, unsigned char alpha) { +Picture createAlphaPic(Window drawable, int alpha) { Display *disp = FbTk::App::instance()->display(); _FB_USES_NLS; @@ -149,7 +149,7 @@ bool Transparent::haveComposite(bool for_real) { return s_use_composite; } -Transparent::Transparent(Drawable src, Drawable dest, unsigned char alpha, int screen_num): +Transparent::Transparent(Drawable src, Drawable dest, int 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) { @@ -196,7 +196,7 @@ Transparent::~Transparent() { #endif // HAVE_XRENDER } -void Transparent::setAlpha(unsigned char alpha) { +void Transparent::setAlpha(int alpha) { if (m_source == 0 || !s_render) return; @@ -254,7 +254,7 @@ void Transparent::setSource(Drawable source, int screen_num) { return; // save old alpha value so we can recreate new later // with the same value - unsigned char old_alpha = m_alpha; + int old_alpha = m_alpha; if (m_alpha_pic != 0) freeAlpha(); @@ -314,7 +314,7 @@ void Transparent::render(int src_x, int src_y, #endif // HAVE_XRENDER } -void Transparent::allocAlpha(unsigned char alpha) { +void Transparent::allocAlpha(int alpha) { #ifdef HAVE_XRENDER if (m_source == 0 || !s_render) return; diff --git a/src/FbTk/Transparent.hh b/src/FbTk/Transparent.hh index 154c223..8e9d9b9 100644 --- a/src/FbTk/Transparent.hh +++ b/src/FbTk/Transparent.hh @@ -29,10 +29,10 @@ namespace FbTk { /// renders to drawable together with an alpha mask class Transparent { public: - Transparent(Drawable source, Drawable dest, unsigned char alpha, int screen_num); + Transparent(Drawable source, Drawable dest, int alpha, int screen_num); ~Transparent(); /// sets alpha value - void setAlpha(unsigned char alpha); + void setAlpha(int alpha); /// sets source drawable void setSource(Drawable src, int screen_num); /// sets destination drawable @@ -45,7 +45,7 @@ public: int dest_x, int dest_y, unsigned int width, unsigned int height) const; - unsigned char alpha() const { return m_alpha; } + int alpha() const { return m_alpha; } Drawable dest() const { return m_dest; } Drawable source() const { return m_source; } @@ -55,7 +55,7 @@ public: private: void freeAlpha(); - void allocAlpha(unsigned char newval); + void allocAlpha(int newval); unsigned long m_alpha_pic; unsigned long m_src_pic; unsigned long m_dest_pic; diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index 9c35925..d5b4b70 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc @@ -427,7 +427,7 @@ void FbWinFrame::alignTabs() { void FbWinFrame::notifyMoved(bool clear) { // not important if no alpha... - unsigned char alpha = getAlpha(m_state.focused); + int alpha = getAlpha(m_state.focused); if (alpha == 255) return; @@ -482,7 +482,7 @@ void FbWinFrame::setFocus(bool newvalue) { if (FbTk::Transparent::haveRender() && getAlpha(true) != getAlpha(false)) { // different alpha for focused and unfocused - unsigned char alpha = getAlpha(m_state.focused); + int alpha = getAlpha(m_state.focused); if (FbTk::Transparent::haveComposite()) { m_tab_container.setAlpha(255); m_window.setOpaque(alpha); @@ -536,7 +536,7 @@ void FbWinFrame::applyState() { frameExtentSig().notify(); } -void FbWinFrame::setAlpha(bool focused, unsigned char alpha) { +void FbWinFrame::setAlpha(bool focused, int alpha) { if (focused) m_focused_alpha = alpha; else @@ -547,7 +547,7 @@ void FbWinFrame::setAlpha(bool focused, unsigned char alpha) { } void FbWinFrame::applyAlpha() { - unsigned char alpha = getAlpha(m_state.focused); + int alpha = getAlpha(m_state.focused); if (FbTk::Transparent::haveComposite()) m_window.setOpaque(alpha); else { @@ -557,8 +557,11 @@ void FbWinFrame::applyAlpha() { } } -unsigned char FbWinFrame::getAlpha(bool focused) const { - return focused ? m_focused_alpha : m_unfocused_alpha; +int FbWinFrame::getAlpha(bool focused) const { + if (focused) + return m_focused_alpha; + else + return m_unfocused_alpha; } void FbWinFrame::setDefaultAlpha() { @@ -966,8 +969,7 @@ void FbWinFrame::reconfigure() { if (isVisible()) { // update transparency settings if (FbTk::Transparent::haveRender()) { - unsigned char alpha = - getAlpha(m_state.focused); + int alpha = getAlpha(m_state.focused); if (FbTk::Transparent::haveComposite()) { m_tab_container.setAlpha(255); m_window.setOpaque(alpha); @@ -1168,7 +1170,7 @@ void FbWinFrame::applyTitlebar() { getCurrentFocusPixmap(label_pm, title_pm, label_color, title_color); - unsigned char alpha = getAlpha (m_state.focused); + int alpha = getAlpha (m_state.focused); m_titlebar.setAlpha(alpha); m_label.setAlpha(alpha); @@ -1220,7 +1222,7 @@ void FbWinFrame::renderHandles() { void FbWinFrame::applyHandles() { - unsigned char alpha = getAlpha(m_state.focused); + int alpha = getAlpha(m_state.focused); m_handle.setAlpha(alpha); m_grip_left.setAlpha(alpha); m_grip_right.setAlpha(alpha); diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh index 7cdf9bb..162bf3d 100644 --- a/src/FbWinFrame.hh +++ b/src/FbWinFrame.hh @@ -121,9 +121,9 @@ public: void updateTabProperties() { alignTabs(); } /// Alpha settings - void setAlpha(bool focused, unsigned char value); + void setAlpha(bool focused, int value); void applyAlpha(); - unsigned char getAlpha(bool focused) const; + int getAlpha(bool focused) const; void setDefaultAlpha(); bool getUseDefaultAlpha() const; @@ -377,9 +377,9 @@ private: bool m_need_render; int m_button_size; ///< size for all titlebar buttons /// alpha values - typedef FbTk::ConstObjectAccessor AlphaAcc; - FbTk::DefaultValue m_focused_alpha; - FbTk::DefaultValue m_unfocused_alpha; + typedef FbTk::ConstObjectAccessor AlphaAcc; + FbTk::DefaultValue m_focused_alpha; + FbTk::DefaultValue m_unfocused_alpha; FbTk::Shape m_shape; }; diff --git a/src/FbWinFrameTheme.hh b/src/FbWinFrameTheme.hh index fd2a7e9..3c28cbd 100644 --- a/src/FbWinFrameTheme.hh +++ b/src/FbWinFrameTheme.hh @@ -74,8 +74,8 @@ public: unsigned int bevelWidth() const { return *m_bevel_width; } unsigned int handleWidth() const { return *m_handle_width; } - unsigned char alpha() const { return m_alpha; } - void setAlpha(unsigned char alpha) { m_alpha = alpha; } + int alpha() const { return m_alpha; } + void setAlpha(int alpha) { m_alpha = alpha; } IconbarTheme &iconbarTheme() { return m_iconbar_theme; } @@ -107,7 +107,7 @@ private: Cursor m_cursor_right_side; Cursor m_cursor_top_side; Cursor m_cursor_bottom_side; - unsigned char m_alpha; + int m_alpha; IconbarTheme m_iconbar_theme; }; diff --git a/src/FocusControl.cc b/src/FocusControl.cc index 341ad0d..9afa605 100644 --- a/src/FocusControl.cc +++ b/src/FocusControl.cc @@ -78,7 +78,7 @@ FocusControl::FocusControl(BScreen &screen): m_focused_list(screen), m_creation_order_list(screen), m_focused_win_list(screen), m_creation_order_win_list(screen), m_cycling_list(0), - m_was_iconic(false), + m_was_iconic(0), m_cycling_last(0), m_ignore_mouse_x(-1), m_ignore_mouse_y(-1) { diff --git a/src/GenericTool.cc b/src/GenericTool.cc index 67d737f..41388ce 100644 --- a/src/GenericTool.cc +++ b/src/GenericTool.cc @@ -75,7 +75,7 @@ unsigned int GenericTool::borderWidth() const { return m_window->borderWidth(); } -void GenericTool::renderTheme(unsigned char alpha) { +void GenericTool::renderTheme(int alpha) { m_window->setAlpha(alpha); m_window->clear(); } diff --git a/src/GenericTool.hh b/src/GenericTool.hh index b64edcf..5d7c8d4 100644 --- a/src/GenericTool.hh +++ b/src/GenericTool.hh @@ -60,7 +60,7 @@ public: const FbTk::FbWindow &window() const { return *m_window; } protected: - virtual void renderTheme(unsigned char alpha); + virtual void renderTheme(int alpha); private: void update(FbTk::Subject *subj); diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 503e04b..62eae0d 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -475,7 +475,7 @@ void IconbarTool::updateSizing() { } -void IconbarTool::renderTheme(unsigned char alpha) { +void IconbarTool::renderTheme(int alpha) { m_alpha = alpha; renderTheme(); diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index efb4a1a..cb8304f 100644 --- a/src/IconbarTool.hh +++ b/src/IconbarTool.hh @@ -81,7 +81,7 @@ private: void renderButton(IconButton &button, bool clear = true); /// render all buttons void renderTheme(); - void renderTheme(unsigned char alpha); + void renderTheme(int alpha); /// destroy all icons void deleteIcons(); /// add or move a single window @@ -111,7 +111,7 @@ private: FbTk::Resource m_rc_client_padding; ///< padding of the text FbTk::Resource m_rc_use_pixmap; ///< if iconbar should use win pixmap or not FbMenu m_menu; - unsigned char m_alpha; + int m_alpha; }; #endif // ICONBARTOOL_HH diff --git a/src/SystemTray.hh b/src/SystemTray.hh index 153220c..3209790 100644 --- a/src/SystemTray.hh +++ b/src/SystemTray.hh @@ -74,7 +74,7 @@ public: int numClients() const { return m_clients.size(); } const FbTk::FbWindow &window() const { return m_window; } - void renderTheme(unsigned char alpha) { + void renderTheme(int alpha) { m_window.setBorderWidth(m_theme->border().width()); m_window.setBorderColor(m_theme->border().color()); m_window.setAlpha(alpha); diff --git a/src/ToolTheme.hh b/src/ToolTheme.hh index 9c34114..693aac6 100644 --- a/src/ToolTheme.hh +++ b/src/ToolTheme.hh @@ -41,8 +41,8 @@ public: // textures const FbTk::Texture &texture() const { return *m_texture; } const FbTk::BorderTheme &border() const { return m_border; } - unsigned char alpha() const { return m_alpha; } - void setAlpha(unsigned char alpha) { m_alpha = alpha; } + int alpha() const { return m_alpha; } + void setAlpha(int alpha) { m_alpha = alpha; } virtual FbTk::Subject &reconfigSig() { return FbTk::Theme::reconfigSig(); } virtual const FbTk::Subject &reconfigSig() const { return FbTk::Theme::reconfigSig(); } @@ -56,7 +56,7 @@ protected: private: FbTk::ThemeItem m_texture; FbTk::BorderTheme m_border; - unsigned char m_alpha; + int m_alpha; }; #endif // TOOLTHEME_HH diff --git a/src/ToolbarItem.hh b/src/ToolbarItem.hh index 4a92c97..f5d1a2a 100644 --- a/src/ToolbarItem.hh +++ b/src/ToolbarItem.hh @@ -54,7 +54,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(unsigned char alpha) = 0; + virtual void renderTheme(int alpha) = 0; // insist implemented, even if blank virtual void parentMoved() = 0; // called when moved from hiding diff --git a/src/Window.hh b/src/Window.hh index 8ce9563..fee2807 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -198,11 +198,11 @@ public: // ------------------ // Per window transparency addons - unsigned char getFocusedAlpha() const { return frame().getAlpha(true); } - unsigned char getUnfocusedAlpha() const { return frame().getAlpha(false); } - void setFocusedAlpha(unsigned char alpha) { frame().setAlpha(true, alpha); } - void setUnfocusedAlpha(unsigned char alpha) { frame().setAlpha(false, alpha); } - void updateAlpha(bool focused, unsigned char alpha) { frame().setAlpha(focused, alpha); } + int getFocusedAlpha() const { return frame().getAlpha(true); } + int getUnfocusedAlpha() const { return frame().getAlpha(false); } + void setFocusedAlpha(int alpha) { frame().setAlpha(true, alpha); } + void setUnfocusedAlpha(int alpha) { frame().setAlpha(false, alpha); } + void updateAlpha(bool focused, int alpha) { frame().setAlpha(focused, alpha); } bool getUseDefaultAlpha() const { return frame().getUseDefaultAlpha(); } void setDefaultAlpha() { frame().setDefaultAlpha(); } diff --git a/src/WindowMenuAccessor.hh b/src/WindowMenuAccessor.hh index 91994b9..383923b 100644 --- a/src/WindowMenuAccessor.hh +++ b/src/WindowMenuAccessor.hh @@ -37,7 +37,9 @@ public: operator Ret() const { FluxboxWindow *fbwin = FbMenu::window(); - return fbwin ? (fbwin->*m_getter)() : m_def; + if (fbwin) + return (Ret)(fbwin->*m_getter)(); + return m_def; } FbTk::Accessor &operator =(const Ret &val) { FluxboxWindow *fbwin = FbMenu::window(); diff --git a/src/WorkspaceNameTool.cc b/src/WorkspaceNameTool.cc index fc944f9..3a4b275 100644 --- a/src/WorkspaceNameTool.cc +++ b/src/WorkspaceNameTool.cc @@ -147,7 +147,7 @@ void WorkspaceNameTool::reRender() { } } -void WorkspaceNameTool::renderTheme(unsigned char alpha) { +void WorkspaceNameTool::renderTheme(int alpha) { m_button.setJustify(m_theme->justify()); m_button.setBorderWidth(m_theme->border().width()); diff --git a/src/WorkspaceNameTool.hh b/src/WorkspaceNameTool.hh index bd034b7..de95663 100644 --- a/src/WorkspaceNameTool.hh +++ b/src/WorkspaceNameTool.hh @@ -64,7 +64,7 @@ private: /// Called when workspace changed on \c screen void updateForScreen(BScreen &screen); - void renderTheme(unsigned char alpha); + void renderTheme(int alpha); void reRender(); void updateSizing(); FbTk::TextButton m_button; -- cgit v0.11.2