Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions src/widgets/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#include <QStandardItemModel>
#include <QVBoxLayout>

#ifdef Q_OS_WIN
# include <dwmapi.h>
#endif

namespace chatterino {

Window::Window(WindowType type, QWidget *parent)
Expand All @@ -76,12 +80,6 @@ Window::Window(WindowType type, QWidget *parent)
if (type == WindowType::Main)
{
this->resize(int(600 * this->scale()), int(500 * this->scale()));
#ifdef Q_OS_LINUX
if (this->theme->window.background.alpha() != 255)
{
this->setAttribute(Qt::WA_TranslucentBackground);
}
#endif
}
else
{
Expand All @@ -107,6 +105,8 @@ Window::Window(WindowType type, QWidget *parent)
},
this->signalHolder_);
}

this->updateWindowTransparency();
}

WindowType Window::getType()
Expand Down Expand Up @@ -265,10 +265,49 @@ void Window::updateStreamerModeIcon()
#endif
}

#ifdef CHATTERINO_SUPPORTS_WINDOW_TRANSPARENCY
void Window::updateWindowTransparency()
{
if (this->type_ == WindowType::Main)
{
if (this->theme->window.background.alpha() != 255)
{
this->setAttribute(Qt::WA_TranslucentBackground);

# ifdef Q_OS_WIN
DWM_BLURBEHIND bb = {0};
bb.dwFlags = DWM_BB_ENABLE;
bb.fEnable = TRUE;
bb.hRgnBlur = nullptr;
::DwmEnableBlurBehindWindow(reinterpret_cast<HWND>(this->winId()),
&bb);
this->enabledBlurBehind_ = true;
# endif
}
# ifdef Q_OS_WIN
else if (this->enabledBlurBehind_)
{
DWM_BLURBEHIND bb = {0};
bb.dwFlags = DWM_BB_ENABLE;
bb.fEnable = FALSE;
bb.hRgnBlur = nullptr;
::DwmEnableBlurBehindWindow(reinterpret_cast<HWND>(this->winId()),
&bb);
this->enabledBlurBehind_ = false;
}
# endif
}
}
#endif

void Window::themeChangedEvent()
{
this->updateStreamerModeIcon();
BaseWindow::themeChangedEvent();

#ifdef CHATTERINO_SUPPORTS_WINDOW_TRANSPARENCY
this->updateWindowTransparency();
#endif
}

void Window::addDebugStuff(HotkeyController::HotkeyMap &actions)
Expand Down
12 changes: 12 additions & 0 deletions src/widgets/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Channel;

enum class WindowType { Main, Popup, Attached };

#if defined(Q_OS_LINUX) || defined(Q_OS_WIN)
# define CHATTERINO_SUPPORTS_WINDOW_TRANSPARENCY
#endif

class Window : public BaseWindow
{
Q_OBJECT
Expand Down Expand Up @@ -58,6 +62,14 @@ class Window : public BaseWindow
PixmapButton *streamerModeTitlebarIcon_ = nullptr;
void updateStreamerModeIcon();

#ifdef CHATTERINO_SUPPORTS_WINDOW_TRANSPARENCY
void updateWindowTransparency();

# ifdef Q_OS_WIN
bool enabledBlurBehind_ = false;
# endif
#endif

friend class Notebook;
};

Expand Down
Loading