update transparent window backgrounds on bg change
simonb simonb
4 files changed,
53 insertions(+),
4 deletions(-)
M
ChangeLog
→
ChangeLog
@@ -1,6 +1,9 @@
(Format: Year/Month/Day) Changes for 0.9.16: *06/04/21: + * Update all transparent things when bg changes (Simon) + (fixes sf.net #1446516 - slit transparency on start) + FbTk/... FbPixmap.cc FbWindow.hh/cc * Make border between tabs same width/color as window border (Simon) (sf.net #1473870) FbWinFrame.cc
M
src/FbTk/FbPixmap.cc
→
src/FbTk/FbPixmap.cc
@@ -25,6 +25,7 @@ #include "FbPixmap.hh"
#include "App.hh" #include "GContext.hh" #include "Transparent.hh" +#include "FbWindow.hh" #include <X11/Xutil.h> #include <X11/Xatom.h>@@ -390,9 +391,14 @@
void FbPixmap::setRootPixmap(int screen_num, Pixmap pm) { if (!m_root_pixmaps) { m_root_pixmaps = new Pixmap[ScreenCount(display())]; + for (int i=0; i < ScreenCount(display()); ++i) + m_root_pixmaps[i] = None; } - m_root_pixmaps[screen_num] = pm; + if (m_root_pixmaps[screen_num] != pm) { + m_root_pixmaps[screen_num] = pm; + FbWindow::updatedAlphaBackground(screen_num); + } } Pixmap FbPixmap::getRootPixmap(int screen_num, bool force_update) {
M
src/FbTk/FbWindow.cc
→
src/FbTk/FbWindow.cc
@@ -118,8 +118,10 @@
FbWindow::~FbWindow() { // Need to free xrender pics before destroying window - if (m_transparent.get() != 0) + if (m_transparent.get() != 0) { + removeAlphaWin(*this); m_transparent.reset(0); + } if (m_window != 0) { // so we don't get any dangling eventhandler for this window@@ -127,6 +129,7 @@ FbTk::EventManager::instance()->remove(m_window);
if (m_destroy) XDestroyWindow(display(), m_window); } + } void FbWindow::setBackgroundColor(const FbTk::Color &bg_color) {@@ -319,8 +322,10 @@
void FbWindow::setAlpha(unsigned char alpha) { #ifdef HAVE_XRENDER if (FbTk::Transparent::haveComposite()) { - if (m_transparent.get() != 0) + if (m_transparent.get() != 0) { + removeAlphaWin(*this); m_transparent.reset(0); + } // don't setOpaque, let controlling objects do that // since it's only needed on toplevel windows@@ -330,10 +335,13 @@ alpha = 255;
if (m_transparent.get() == 0 && alpha < 255) { m_transparent.reset(new Transparent(FbPixmap::getRootPixmap(screenNumber()), window(), alpha, screenNumber())); + addAlphaWin(*this); } else if (alpha < 255 && alpha != m_transparent->alpha()) m_transparent->setAlpha(alpha); - else if (alpha == 255) + else if (alpha == 255) { + removeAlphaWin(*this); m_transparent.reset(0); // destroy transparent object + } } #endif // HAVE_XRENDER }@@ -590,6 +598,29 @@ event.xconfigure.override_redirect = false;
XSendEvent(disp, window(), False, StructureNotifyMask, &event); +} + +FbWindow::FbWinList FbWindow::m_alpha_wins; + +void FbWindow::addAlphaWin(FbWindow &win) { + m_alpha_wins.insert(&win); +} + +void FbWindow::removeAlphaWin(FbWindow &win) { + FbWinList::iterator it = m_alpha_wins.find(&win); + if (it != m_alpha_wins.end()) + m_alpha_wins.erase(it); +} + +void FbWindow::updatedAlphaBackground(int screen) { + FbWinList::iterator it = m_alpha_wins.begin(); + FbWinList::iterator it_end = m_alpha_wins.end(); + for (; it != it_end; ++it) { + if ((*it)->screenNumber() == screen) { + (*it)->updateBackground(false); + (*it)->clear(); + } + } } bool operator == (Window win, const FbWindow &fbwin) {
M
src/FbTk/FbWindow.hh
→
src/FbTk/FbWindow.hh
@@ -29,6 +29,7 @@
#include <X11/Xlib.h> #include <memory> #include <string> +#include <set> namespace FbTk {@@ -194,6 +195,8 @@
/// forces full background change, recalcing of alpha values if necessary void updateBackground(bool only_if_alpha); + static void updatedAlphaBackground(int screen); + protected: /// creates a window with x window client (m_window = client) explicit FbWindow(Window client);@@ -226,6 +229,12 @@ unsigned long m_lastbg_color;
Pixmap m_lastbg_pm; FbWindowRenderer *m_renderer; + + static void addAlphaWin(FbWindow &win); + static void removeAlphaWin(FbWindow &win); + + typedef std::set<FbWindow *> FbWinList; + static FbWinList m_alpha_wins; }; bool operator == (Window win, const FbWindow &fbwin);