mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 23:27:09 +02:00
Removed macOS tray implementation from main window.
This commit is contained in:
parent
aee1ef78da
commit
fbae5bdbcf
2 changed files with 0 additions and 126 deletions
|
@ -66,7 +66,6 @@ private:
|
|||
|
||||
void hideAndDeactivate();
|
||||
void updateIconCounters();
|
||||
[[nodiscard]] QIcon generateIconForTray(int counter, bool muted) const;
|
||||
|
||||
std::unique_ptr<Private> _private;
|
||||
|
||||
|
|
|
@ -65,17 +65,6 @@ namespace {
|
|||
// fullscreen mode, after that we'll hide the window no matter what.
|
||||
constexpr auto kHideAfterFullscreenTimeoutMs = 3000;
|
||||
|
||||
[[nodiscard]] QImage TrayIconBack(bool darkMode) {
|
||||
static const auto WithColor = [](QColor color) {
|
||||
return st::macTrayIcon.instance(color, 100);
|
||||
};
|
||||
static const auto DarkModeResult = WithColor({ 255, 255, 255 });
|
||||
static const auto LightModeResult = WithColor({ 0, 0, 0, 180 });
|
||||
auto result = darkMode ? DarkModeResult : LightModeResult;
|
||||
result.detach();
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class MainWindow::Private {
|
||||
|
@ -249,17 +238,6 @@ void MainWindow::stateChangedHook(Qt::WindowState state) {
|
|||
}
|
||||
|
||||
void MainWindow::handleActiveChangedHook() {
|
||||
// On macOS just remove trayIcon menu if the window is not active.
|
||||
// So we will activate the window on click instead of showing the menu.
|
||||
if (isActiveForTrayMenu()) {
|
||||
if (trayIcon
|
||||
&& trayIconMenu
|
||||
&& trayIcon->contextMenu() != trayIconMenu) {
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
}
|
||||
} else if (trayIcon) {
|
||||
trayIcon->setContextMenu(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::initHook() {
|
||||
|
@ -302,74 +280,9 @@ void MainWindow::psTrayMenuUpdated() {
|
|||
}
|
||||
|
||||
void MainWindow::psSetupTrayIcon() {
|
||||
if (!trayIcon) {
|
||||
trayIcon = new QSystemTrayIcon(this);
|
||||
trayIcon->setIcon(generateIconForTray(
|
||||
Core::App().unreadBadge(),
|
||||
Core::App().unreadBadgeMuted()));
|
||||
if (isActiveForTrayMenu()) {
|
||||
trayIcon->setContextMenu(trayIconMenu);
|
||||
} else {
|
||||
trayIcon->setContextMenu(nullptr);
|
||||
}
|
||||
attachToTrayIcon(trayIcon);
|
||||
} else {
|
||||
updateIconCounters();
|
||||
}
|
||||
|
||||
trayIcon->show();
|
||||
}
|
||||
|
||||
void MainWindow::workmodeUpdated(Core::Settings::WorkMode mode) {
|
||||
psSetupTrayIcon();
|
||||
if (mode == Core::Settings::WorkMode::WindowOnly) {
|
||||
if (trayIcon) {
|
||||
trayIcon->setContextMenu(0);
|
||||
delete trayIcon;
|
||||
trayIcon = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _placeCounter(QImage &img, int size, int count, style::color bg, style::color color) {
|
||||
if (!count) return;
|
||||
auto savedRatio = img.devicePixelRatio();
|
||||
img.setDevicePixelRatio(1.);
|
||||
|
||||
{
|
||||
Painter p(&img);
|
||||
PainterHighQualityEnabler hq(p);
|
||||
|
||||
auto cnt = (count < 100) ? QString("%1").arg(count) : QString("..%1").arg(count % 100, 2, 10, QChar('0'));
|
||||
auto cntSize = cnt.size();
|
||||
|
||||
p.setBrush(bg);
|
||||
p.setPen(Qt::NoPen);
|
||||
int32 fontSize, skip;
|
||||
if (size == 22) {
|
||||
skip = 1;
|
||||
fontSize = 8;
|
||||
} else {
|
||||
skip = 2;
|
||||
fontSize = 16;
|
||||
}
|
||||
style::font f(fontSize, 0, 0);
|
||||
int32 w = f->width(cnt), d, r;
|
||||
if (size == 22) {
|
||||
d = (cntSize < 2) ? 3 : 2;
|
||||
r = (cntSize < 2) ? 6 : 5;
|
||||
} else {
|
||||
d = (cntSize < 2) ? 6 : 5;
|
||||
r = (cntSize < 2) ? 9 : 11;
|
||||
}
|
||||
p.drawRoundedRect(QRect(size - w - d * 2 - skip, size - f->height - skip, w + d * 2, f->height), r, r);
|
||||
|
||||
p.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
p.setFont(f);
|
||||
p.setPen(color);
|
||||
p.drawText(size - w - d - skip, size - f->height + f->ascent - skip, cnt);
|
||||
}
|
||||
img.setDevicePixelRatio(savedRatio);
|
||||
}
|
||||
|
||||
void MainWindow::unreadCounterChangedHook() {
|
||||
|
@ -378,7 +291,6 @@ void MainWindow::unreadCounterChangedHook() {
|
|||
|
||||
void MainWindow::updateIconCounters() {
|
||||
const auto counter = Core::App().unreadBadge();
|
||||
const auto muted = Core::App().unreadBadgeMuted();
|
||||
|
||||
const auto string = !counter
|
||||
? QString()
|
||||
|
@ -386,43 +298,6 @@ void MainWindow::updateIconCounters() {
|
|||
? QString("%1").arg(counter)
|
||||
: QString("..%1").arg(counter % 100, 2, 10, QChar('0'));
|
||||
_private->setWindowBadge(string);
|
||||
|
||||
if (trayIcon) {
|
||||
trayIcon->setIcon(generateIconForTray(counter, muted));
|
||||
}
|
||||
}
|
||||
|
||||
QIcon MainWindow::generateIconForTray(int counter, bool muted) const {
|
||||
auto result = QIcon();
|
||||
auto lightMode = TrayIconBack(false);
|
||||
auto darkMode = TrayIconBack(true);
|
||||
auto lightModeActive = darkMode;
|
||||
auto darkModeActive = darkMode;
|
||||
lightModeActive.detach();
|
||||
darkModeActive.detach();
|
||||
const auto size = 22 * cIntRetinaFactor();
|
||||
const auto &bg = (muted ? st::trayCounterBgMute : st::trayCounterBg);
|
||||
_placeCounter(lightMode, size, counter, bg, st::trayCounterFg);
|
||||
_placeCounter(darkMode, size, counter, bg, muted ? st::trayCounterFgMacInvert : st::trayCounterFg);
|
||||
_placeCounter(lightModeActive, size, counter, st::trayCounterBgMacInvert, st::trayCounterFgMacInvert);
|
||||
_placeCounter(darkModeActive, size, counter, st::trayCounterBgMacInvert, st::trayCounterFgMacInvert);
|
||||
result.addPixmap(Ui::PixmapFromImage(
|
||||
std::move(lightMode)),
|
||||
QIcon::Normal,
|
||||
QIcon::Off);
|
||||
result.addPixmap(Ui::PixmapFromImage(
|
||||
std::move(darkMode)),
|
||||
QIcon::Normal,
|
||||
QIcon::On);
|
||||
result.addPixmap(Ui::PixmapFromImage(
|
||||
std::move(lightModeActive)),
|
||||
QIcon::Active,
|
||||
QIcon::Off);
|
||||
result.addPixmap(Ui::PixmapFromImage(
|
||||
std::move(darkModeActive)),
|
||||
QIcon::Active,
|
||||
QIcon::On);
|
||||
return result;
|
||||
}
|
||||
|
||||
void MainWindow::createGlobalMenu() {
|
||||
|
|
Loading…
Add table
Reference in a new issue