diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index f007cf49f2..aea428d678 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -77,7 +77,7 @@ void IntroWidget::onCheckUpdateStatus() { if (Sandbox::updatingState() == Application::UpdatingReady) { if (_update) return; _update.create(this, lang(lng_menu_update).toUpper(), st::defaultBoxButton); - _update->show(); + if (!_a_show.animating()) _update->show(); _update->setClickedCallback([] { checkReadyUpdate(); App::restart(); @@ -194,6 +194,8 @@ void IntroWidget::animShow(const QPixmap &bgAnimCache, bool back) { _a_show.stop(); step()->show(); + _settings->show(); + if (_update) _update->show(); if (step()->hasBack()) { _back->showFast(); } else { @@ -203,6 +205,8 @@ void IntroWidget::animShow(const QPixmap &bgAnimCache, bool back) { step()->hide(); _back->hideFast(); + _settings->hide(); + if (_update) _update->hide(); a_coordUnder = back ? anim::ivalue(-st::slideShift, 0) : anim::ivalue(0, -st::slideShift); a_coordOver = back ? anim::ivalue(0, width()) : anim::ivalue(width(), 0); @@ -228,6 +232,8 @@ void IntroWidget::step_show(float64 ms, bool timer) { if (step()->hasBack()) { _back->showFast(); } + _settings->show(); + if (_update) _update->show(); if (App::app()) App::app()->mtpUnpause(); } else { a_coordUnder.update(dt, Window::SlideAnimation::transition()); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index e3dd2d5ee0..86984e5435 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -162,8 +162,6 @@ void MainWindow::onStateChanged(Qt::WindowState state) { void MainWindow::initHook() { Platform::MainWindow::initHook(); - setWindowIcon(wndIcon); - Application::instance()->installEventFilter(this); connect(windowHandle(), SIGNAL(windowStateChanged(Qt::WindowState)), this, SLOT(onStateChanged(Qt::WindowState))); connect(windowHandle(), SIGNAL(activeChanged()), this, SLOT(onWindowActiveChanged()), Qt::QueuedConnection); diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 10e61acf9d..208b4d3d53 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -191,6 +191,10 @@ MainWindow::MainWindow() _psUpdateIndicatorTimer.setSingleShot(true); } +void MainWindow::initHook() { + setWindowIcon(wndIcon); +} + bool MainWindow::psHasTrayIcon() const { return trayIcon || ((useAppIndicator || (useStatusIcon && trayIconChecked)) && (cWorkMode() != dbiwmWindowOnly)); } diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.h b/Telegram/SourceFiles/platform/linux/main_window_linux.h index 315924d791..4ce43c0369 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.h +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.h @@ -60,6 +60,7 @@ public slots: void psUpdateIndicator(); protected: + void initHook() override; bool psHasTrayIcon() const; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index 15aec9e32b..e2e6340988 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.h +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.h @@ -25,13 +25,6 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org namespace Platform { -class MacPrivate : public PsMacWindowPrivate { -public: - void activeSpaceChanged(); - void darkModeChanged(); - -}; - class MainWindow : public Window::MainWindow { Q_OBJECT @@ -64,8 +57,14 @@ public: void closeWithoutDestroy() override; + int getCustomTitleHeight() const { + return _customTitleHeight; + } + ~MainWindow(); + class Private; + public slots: void psShowTrayMenu(); @@ -82,6 +81,7 @@ private slots: protected: void stateChangedHook(Qt::WindowState state) override; + void initHook() override; QImage psTrayIcon(bool selected = false) const; bool psHasTrayIcon() const { @@ -106,7 +106,8 @@ protected: private: void createGlobalMenu(); - MacPrivate _private; + friend class Private; + std_::unique_ptr _private; mutable bool psIdle; mutable QTimer psIdleTimer; @@ -128,6 +129,8 @@ private: QAction *psNewChannel = nullptr; QAction *psShowTelegram = nullptr; + int _customTitleHeight = 0; + }; } // namespace Platform diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index f165dc88af..3e0851c9dc 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -28,18 +28,72 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "platform/platform_notifications_manager.h" #include "boxes/contactsbox.h" #include "boxes/aboutbox.h" - #include "lang.h" +#include "platform/mac/mac_utilities.h" #include -#include #include - +#include #include +#include + +@interface MainWindowObserver : NSObject { +} + +- (id) init:(MainWindow::Private*)window; +- (void) activeSpaceDidChange:(NSNotification *)aNotification; +- (void) darkModeChanged:(NSNotification *)aNotification; +- (void) screenIsLocked:(NSNotification *)aNotification; +- (void) screenIsUnlocked:(NSNotification *)aNotification; +- (void) windowWillEnterFullScreen:(NSNotification *)aNotification; +- (void) windowWillExitFullScreen:(NSNotification *)aNotification; + +@end namespace Platform { -void MacPrivate::activeSpaceChanged() { +class MainWindow::Private { +public: + Private(MainWindow *window); + + void setWindowBadge(const QString &str); + void startBounce(); + + void enableShadow(WId winId); + + bool filterNativeEvent(void *event); + + void willEnterFullScreen(); + void willExitFullScreen(); + + void initCustomTitle(NSWindow *window, NSView *view); + + ~Private(); + +private: + MainWindow *_public; + friend class MainWindow; + + MainWindowObserver *_observer; + +}; + +} // namespace Platform + +@implementation MainWindowObserver { + +MainWindow::Private *_private; + +} + +- (id) init:(MainWindow::Private*)window { + if (self = [super init]) { + _private = window; + } + return self; +} + +- (void) activeSpaceDidChange:(NSNotification *)aNotification { if (auto manager = Window::Notifications::Default::manager()) { manager->enumerateNotifications([](QWidget *widget) { objc_activateWnd(widget->winId()); @@ -47,14 +101,110 @@ void MacPrivate::activeSpaceChanged() { } } -void MacPrivate::darkModeChanged() { +- (void) darkModeChanged:(NSNotification *)aNotification { Notify::unreadCounterUpdated(); } +- (void) screenIsLocked:(NSNotification *)aNotification { + Global::SetScreenIsLocked(true); +} + +- (void) screenIsUnlocked:(NSNotification *)aNotification { + Global::SetScreenIsLocked(false); +} + +- (void) windowWillEnterFullScreen:(NSNotification *)aNotification { + _private->willEnterFullScreen(); +} + +- (void) windowWillExitFullScreen:(NSNotification *)aNotification { + _private->willExitFullScreen(); +} + +@end + +namespace Platform { + +MainWindow::Private::Private(MainWindow *window) +: _public(window) +, _observer([[MainWindowObserver alloc] init:this]) { + @autoreleasepool { + + [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:_observer selector:@selector(activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil]; + [[NSDistributedNotificationCenter defaultCenter] addObserver:_observer selector:@selector(darkModeChanged:) name:Q2NSString(strNotificationAboutThemeChange()) object:nil]; + [[NSDistributedNotificationCenter defaultCenter] addObserver:_observer selector:@selector(screenIsLocked:) name:Q2NSString(strNotificationAboutScreenLocked()) object:nil]; + [[NSDistributedNotificationCenter defaultCenter] addObserver:_observer selector:@selector(screenIsUnlocked:) name:Q2NSString(strNotificationAboutScreenUnlocked()) object:nil]; + +#ifndef OS_MAC_STORE + // Register defaults for the whitelist of apps that want to use media keys + [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey, nil]]; +#endif // !OS_MAC_STORE + + } +} + +void MainWindow::Private::setWindowBadge(const QString &str) { + @autoreleasepool { + + [[NSApp dockTile] setBadgeLabel:Q2NSString(str)]; + + } +} + +void MainWindow::Private::startBounce() { + [NSApp requestUserAttention:NSInformationalRequest]; +} + +void MainWindow::Private::initCustomTitle(NSWindow *window, NSView *view) { + [window setStyleMask:[window styleMask] | NSFullSizeContentViewWindowMask]; + [window setTitlebarAppearsTransparent:YES]; + auto inner = [window contentLayoutRect]; + auto full = [view frame]; + _public->_customTitleHeight = qMax(qRound(full.size.height - inner.size.height), 0); + +#ifndef OS_MAC_OLD + [[NSNotificationCenter defaultCenter] addObserver:_observer selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window]; + [[NSNotificationCenter defaultCenter] addObserver:_observer selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window]; +#endif // !OS_MAC_OLD +} + +void MainWindow::Private::willEnterFullScreen() { + _public->setTitleVisibility(false); +} + +void MainWindow::Private::willExitFullScreen() { + _public->setTitleVisibility(true); +} + +void MainWindow::Private::enableShadow(WId winId) { +// [[(NSView*)winId window] setStyleMask:NSBorderlessWindowMask]; +// [[(NSView*)winId window] setHasShadow:YES]; +} + +bool MainWindow::Private::filterNativeEvent(void *event) { + NSEvent *e = static_cast(event); + if (e && [e type] == NSSystemDefined && [e subtype] == SPSystemDefinedEventMediaKeys) { +#ifndef OS_MAC_STORE + // If event tap is not installed, handle events that reach the app instead + if (![SPMediaKeyTap usesGlobalMediaKeyTap]) { + return objc_handleMediaKeyEvent(e); + } +#else // !OS_MAC_STORE + return objc_handleMediaKeyEvent(e); +#endif // else for !OS_MAC_STORE + } + return false; +} + +MainWindow::Private::~Private() { + [_observer release]; +} + MainWindow::MainWindow() : icon256(qsl(":/gui/art/icon256.png")) , iconbig256(qsl(":/gui/art/iconbig256.png")) -, wndIcon(QPixmap::fromImage(iconbig256, Qt::ColorOnly)) { +, wndIcon(QPixmap::fromImage(iconbig256, Qt::ColorOnly)) +, _private(std_::make_unique(this)) { QImage tray(qsl(":/gui/art/osxtray.png")); trayImg = tray.copy(0, cRetina() ? 0 : tray.width() / 2, tray.width() / (cRetina() ? 2 : 4), tray.width() / (cRetina() ? 2 : 4)); trayImgSel = tray.copy(tray.width() / (cRetina() ? 2 : 4), cRetina() ? 0 : tray.width() / 2, tray.width() / (cRetina() ? 2 : 4), tray.width() / (cRetina() ? 2 : 4)); @@ -81,6 +231,18 @@ void MainWindow::stateChangedHook(Qt::WindowState state) { } } +void MainWindow::initHook() { + _customTitleHeight = 0; + if (auto view = reinterpret_cast(winId())) { + if (auto window = [view window]) { + if ([window respondsToSelector:@selector(contentLayoutRect)] + && [window respondsToSelector:@selector(setTitlebarAppearsTransparent:)]) { + _private->initCustomTitle(window, view); + } + } + } +} + void MainWindow::onHideAfterFullScreen() { hide(); } @@ -124,7 +286,6 @@ void MainWindow::psUpdateWorkmode() { if (auto manager = Platform::Notifications::manager()) { manager->updateDelegate(); } - setWindowIcon(wndIcon); } void _placeCounter(QImage &img, int size, int count, const style::color &bg, const style::color &color) { @@ -166,10 +327,9 @@ void MainWindow::psUpdateCounter() { int32 counter = App::histories().unreadBadge(); setWindowTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram")); - setWindowIcon(wndIcon); QString cnt = (counter < 1000) ? QString("%1").arg(counter) : QString("..%1").arg(counter % 100, 2, 10, QChar('0')); - _private.setWindowBadge(counter ? cnt : QString()); + _private->setWindowBadge(counter ? cnt : QString()); if (trayIcon) { bool muted = App::histories().unreadOnlyMuted(); @@ -195,7 +355,7 @@ void MainWindow::psFirstShow() { bool showShadows = true; show(); - _private.enableShadow(winId()); + _private->enableShadow(winId()); if (cWindowPos().maximized) { setWindowState(Qt::WindowMaximized); } @@ -353,11 +513,11 @@ void MainWindow::psMacUpdateMenu() { } void MainWindow::psFlash() { - _private.startBounce(); + return _private->startBounce(); } bool MainWindow::psFilterNativeEvent(void *event) { - return _private.filterNativeEvent(event); + return _private->filterNativeEvent(event); } bool MainWindow::eventFilter(QObject *obj, QEvent *evt) { diff --git a/Telegram/SourceFiles/platform/mac/window_title_mac.h b/Telegram/SourceFiles/platform/mac/window_title_mac.h new file mode 100644 index 0000000000..6409888e3e --- /dev/null +++ b/Telegram/SourceFiles/platform/mac/window_title_mac.h @@ -0,0 +1,46 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +#pragma once + +#include "window/window_title.h" + +namespace Ui { +class PlainShadow; +} // namespace Ui + +namespace Platform { + +class TitleWidget : public Window::TitleWidget { +public: + TitleWidget(QWidget *parent, int height); + +protected: + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + +private: + ChildWidget _shadow; + +}; + +Window::TitleWidget *CreateTitleWidget(QWidget *parent); + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/mac/window_title_mac.mm b/Telegram/SourceFiles/platform/mac/window_title_mac.mm new file mode 100644 index 0000000000..4927d0cb19 --- /dev/null +++ b/Telegram/SourceFiles/platform/mac/window_title_mac.mm @@ -0,0 +1,53 @@ +/* +This file is part of Telegram Desktop, +the official desktop version of Telegram messaging app, see https://telegram.org + +Telegram Desktop is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +It is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +In addition, as a special exception, the copyright holders give permission +to link the code of portions of this program with the OpenSSL library. + +Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org +*/ +#include "stdafx.h" +#include "platform/mac/window_title_mac.h" + +#include "ui/widgets/shadow.h" +#include "styles/style_window.h" +#include "platform/platform_main_window.h" + +namespace Platform { + +TitleWidget::TitleWidget(QWidget *parent, int height) : Window::TitleWidget(parent) +, _shadow(this, st::titleShadow) { + setAttribute(Qt::WA_OpaquePaintEvent); + resize(width(), height); +} + +void TitleWidget::paintEvent(QPaintEvent *e) { + Painter(this).fillRect(rect(), st::titleBg); +} + +void TitleWidget::resizeEvent(QResizeEvent *e) { + _shadow->setGeometry(0, height() - st::lineWidth, width(), st::lineWidth); +} + +Window::TitleWidget *CreateTitleWidget(QWidget *parent) { + if (auto window = qobject_cast(parent)) { + if (auto height = window->getCustomTitleHeight()) { + return new TitleWidget(parent, height); + } + } + return nullptr; +} + +} // namespace Platform diff --git a/Telegram/SourceFiles/platform/platform_window_title.h b/Telegram/SourceFiles/platform/platform_window_title.h index 6291c5d7e8..1211acbbe8 100644 --- a/Telegram/SourceFiles/platform/platform_window_title.h +++ b/Telegram/SourceFiles/platform/platform_window_title.h @@ -22,9 +22,11 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "window/window_title.h" -#if defined Q_OS_WIN +#ifdef Q_OS_MAC +#include "platform/mac/window_title_mac.h" +#elif defined Q_OS_WIN // Q_OS_MAC #include "platform/win/window_title_win.h" -#else // Q_OS_WIN +#elif defined Q_OS_WINRT || defined Q_OS_LINUX namespace Platform { inline Window::TitleWidget *CreateTitleWidget(QWidget *parent) { @@ -32,4 +34,4 @@ inline Window::TitleWidget *CreateTitleWidget(QWidget *parent) { } } // namespace Platform -#endif // else for Q_OS_WIN +#endif // Q_OS_MAC || Q_OS_WIN || Q_OS_WINRT || Q_OS_LINUX diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index bf2863d2af..7124be4132 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -777,6 +777,8 @@ void MainWindow::initHook() { } psInitSysMenu(); + + setWindowIcon(wndIcon); } bool MainWindow::psHasNativeNotifications() { diff --git a/Telegram/SourceFiles/platform/win/window_title_win.cpp b/Telegram/SourceFiles/platform/win/window_title_win.cpp index 32437e1436..582e8fb288 100644 --- a/Telegram/SourceFiles/platform/win/window_title_win.cpp +++ b/Telegram/SourceFiles/platform/win/window_title_win.cpp @@ -47,6 +47,7 @@ TitleWidget::TitleWidget(QWidget *parent) : Window::TitleWidget(parent) }); setAttribute(Qt::WA_OpaquePaintEvent); + resize(width(), st::titleHeight); } void TitleWidget::init() { diff --git a/Telegram/SourceFiles/pspecific_mac_p.h b/Telegram/SourceFiles/pspecific_mac_p.h index 5a613ceeae..5e3219a90c 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.h +++ b/Telegram/SourceFiles/pspecific_mac_p.h @@ -17,29 +17,8 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org */ #pragma once -class PsMacWindowData; - -class PsMacWindowPrivate { -public: - PsMacWindowPrivate(); - - void setWindowBadge(const QString &str); - void startBounce(); - - void enableShadow(WId winId); - - bool filterNativeEvent(void *event); - - virtual void activeSpaceChanged() { - } - virtual void darkModeChanged() { - } - - ~PsMacWindowPrivate(); - - PsMacWindowData *data; - -}; +// e is NSEvent* +bool objc_handleMediaKeyEvent(void *e); void objc_holdOnTop(WId winId); bool objc_darkMode(); diff --git a/Telegram/SourceFiles/pspecific_mac_p.mm b/Telegram/SourceFiles/pspecific_mac_p.mm index a99d5585a7..b5965b08f5 100644 --- a/Telegram/SourceFiles/pspecific_mac_p.mm +++ b/Telegram/SourceFiles/pspecific_mac_p.mm @@ -28,19 +28,15 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "lang.h" #include -#include #include - +#include #include - #include using Platform::Q2NSString; using Platform::NSlang; using Platform::NS2QString; -bool handleMediaKeyEvent(NSEvent *e); - @interface qVisualize : NSObject { } @@ -152,68 +148,12 @@ ApplicationDelegate *_sharedDelegate = nil; - (void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)e { if (e && [e type] == NSSystemDefined && [e subtype] == SPSystemDefinedEventMediaKeys) { - handleMediaKeyEvent(e); + objc_handleMediaKeyEvent(e); } } @end -@interface ObserverHelper : NSObject { -} - -- (id) init:(PsMacWindowPrivate *)aWnd; -- (void) activeSpaceDidChange:(NSNotification *)aNotification; -- (void) darkModeChanged:(NSNotification *)aNotification; -- (void) screenIsLocked:(NSNotification *)aNotification; -- (void) screenIsUnlocked:(NSNotification *)aNotification; - -@end - -class PsMacWindowData { -public: - PsMacWindowData(PsMacWindowPrivate *wnd) : - wnd(wnd), - observerHelper([[ObserverHelper alloc] init:wnd]) { - } - - ~PsMacWindowData() { - [observerHelper release]; - } - - PsMacWindowPrivate *wnd; - ObserverHelper *observerHelper; - -}; - -@implementation ObserverHelper { - PsMacWindowPrivate *wnd; -} - -- (id) init:(PsMacWindowPrivate *)aWnd { - if (self = [super init]) { - wnd = aWnd; - } - return self; -} - -- (void) activeSpaceDidChange:(NSNotification *)aNotification { - wnd->activeSpaceChanged(); -} - -- (void) darkModeChanged:(NSNotification *)aNotification { - wnd->darkModeChanged(); -} - -- (void) screenIsLocked:(NSNotification *)aNotification { - Global::SetScreenIsLocked(true); -} - -- (void) screenIsUnlocked:(NSNotification *)aNotification { - Global::SetScreenIsLocked(false); -} - -@end - namespace Platform { void SetWatchingMediaKeys(bool watching) { @@ -224,34 +164,6 @@ void SetWatchingMediaKeys(bool watching) { } // namespace Platform -PsMacWindowPrivate::PsMacWindowPrivate() : data(new PsMacWindowData(this)) { - @autoreleasepool { - - [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:data->observerHelper selector:@selector(activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil]; - [[NSDistributedNotificationCenter defaultCenter] addObserver:data->observerHelper selector:@selector(darkModeChanged:) name:Q2NSString(strNotificationAboutThemeChange()) object:nil]; - [[NSDistributedNotificationCenter defaultCenter] addObserver:data->observerHelper selector:@selector(screenIsLocked:) name:Q2NSString(strNotificationAboutScreenLocked()) object:nil]; - [[NSDistributedNotificationCenter defaultCenter] addObserver:data->observerHelper selector:@selector(screenIsUnlocked:) name:Q2NSString(strNotificationAboutScreenUnlocked()) object:nil]; - -#ifndef OS_MAC_STORE - // Register defaults for the whitelist of apps that want to use media keys - [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers], kMediaKeyUsingBundleIdentifiersDefaultsKey, nil]]; -#endif // OS_MAC_STORE - - } -} - -void PsMacWindowPrivate::setWindowBadge(const QString &str) { - @autoreleasepool { - - [[NSApp dockTile] setBadgeLabel:Q2NSString(str)]; - - } -} - -void PsMacWindowPrivate::startBounce() { - [NSApp requestUserAttention:NSInformationalRequest]; -} - void objc_holdOnTop(WId winId) { NSWindow *wnd = [reinterpret_cast(winId) window]; [wnd setHidesOnDeactivate:NO]; @@ -289,7 +201,9 @@ void objc_activateWnd(WId winId) { [wnd orderFront:wnd]; } -bool handleMediaKeyEvent(NSEvent *e) { +bool objc_handleMediaKeyEvent(void *ev) { + auto e = reinterpret_cast(ev); + int keyCode = (([e data1] & 0xFFFF0000) >> 16); int keyFlags = ([e data1] & 0x0000FFFF); int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA; @@ -330,26 +244,6 @@ bool handleMediaKeyEvent(NSEvent *e) { return false; } -void PsMacWindowPrivate::enableShadow(WId winId) { -// [[(NSView*)winId window] setStyleMask:NSBorderlessWindowMask]; -// [[(NSView*)winId window] setHasShadow:YES]; -} - -bool PsMacWindowPrivate::filterNativeEvent(void *event) { - NSEvent *e = static_cast(event); - if (e && [e type] == NSSystemDefined && [e subtype] == SPSystemDefinedEventMediaKeys) { -#ifndef OS_MAC_STORE - // If event tap is not installed, handle events that reach the app instead - if (![SPMediaKeyTap usesGlobalMediaKeyTap]) { - return handleMediaKeyEvent(e); - } -#else // !OS_MAC_STORE - return handleMediaKeyEvent(e); -#endif // else for !OS_MAC_STORE - } - return false; -} - void objc_debugShowAlert(const QString &str) { @autoreleasepool { @@ -366,10 +260,6 @@ void objc_outputDebugString(const QString &str) { } } -PsMacWindowPrivate::~PsMacWindowPrivate() { - delete data; -} - bool objc_idleSupported() { int64 idleTime = 0; return objc_idleTime(idleTime); diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index a49e874501..8a0fb16cba 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -39,11 +39,11 @@ MainWindow::MainWindow() : QWidget() } } }); - - _title = Platform::CreateTitleWidget(this); } void MainWindow::init() { + initHook(); + _positionUpdatedTimer->setSingleShot(true); connect(_positionUpdatedTimer, SIGNAL(timeout()), this, SLOT(savePositionByTimer())); @@ -51,10 +51,11 @@ void MainWindow::init() { p.setColor(QPalette::Window, st::windowBg->c); setPalette(p); - if (_title) _title->init(); + if ((_title = Platform::CreateTitleWidget(this))) { + _title->init(); + } initSize(); - initHook(); } HitTestResult MainWindow::hitTest(const QPoint &p) const { @@ -104,6 +105,13 @@ void MainWindow::positionUpdated() { _positionUpdatedTimer->start(SaveWindowPositionTimeout); } +void MainWindow::setTitleVisibility(bool visible) { + if (_title && (_title->isHidden() == visible)) { + _title->setVisible(visible); + updateControlsGeometry(); + } +} + int32 MainWindow::screenNameChecksum(const QString &name) const { auto bytes = name.toUtf8(); return hashCrc32(bytes.constData(), bytes.size()); @@ -114,9 +122,13 @@ void MainWindow::setPositionInited() { } void MainWindow::resizeEvent(QResizeEvent *e) { + updateControlsGeometry(); +} + +void MainWindow::updateControlsGeometry() { auto bodyTop = 0; - if (_title) { - _title->setGeometry(0, bodyTop, width(), st::titleHeight); + if (_title && !_title->isHidden()) { + _title->setGeometry(0, bodyTop, width(), _title->height()); bodyTop += _title->height(); } _body->setGeometry(0, bodyTop, width(), height() - bodyTop); diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index f1c0e8fc4c..594bf2dd27 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -40,6 +40,8 @@ public: } void positionUpdated(); + void setTitleVisibility(bool visible); + virtual void closeWithoutDestroy(); virtual ~MainWindow(); @@ -70,6 +72,7 @@ private slots: } private: + void updateControlsGeometry(); void initSize(); ChildObject _positionUpdatedTimer; diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index 6faf9b7d57..141f4a54c2 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -369,6 +369,8 @@ '<(src_loc)/platform/mac/main_window_mac.h', '<(src_loc)/platform/mac/notifications_manager_mac.mm', '<(src_loc)/platform/mac/notifications_manager_mac.h', + '<(src_loc)/platform/mac/window_title_mac.mm', + '<(src_loc)/platform/mac/window_title_mac.h', '<(src_loc)/platform/win/main_window_win.cpp', '<(src_loc)/platform/win/main_window_win.h', '<(src_loc)/platform/win/notifications_manager_win.cpp', @@ -605,6 +607,8 @@ '<(src_loc)/platform/mac/main_window_mac.h', '<(src_loc)/platform/mac/notifications_manager_mac.mm', '<(src_loc)/platform/mac/notifications_manager_mac.h', + '<(src_loc)/platform/mac/window_title_mac.mm', + '<(src_loc)/platform/mac/window_title_mac.h', '<(sp_media_key_tap_loc)/SPMediaKeyTap.m', '<(sp_media_key_tap_loc)/SPMediaKeyTap.h', '<(sp_media_key_tap_loc)/SPInvocationGrabbing/NSObject+SPInvocationGrabbing.m', @@ -628,6 +632,8 @@ '<(src_loc)/platform/win/main_window_win.h', '<(src_loc)/platform/win/notifications_manager_win.cpp', '<(src_loc)/platform/win/notifications_manager_win.h', + '<(src_loc)/platform/win/window_title_win.cpp', + '<(src_loc)/platform/win/window_title_win.h', '<(src_loc)/platform/win/windows_app_user_model_id.cpp', '<(src_loc)/platform/win/windows_app_user_model_id.h', '<(src_loc)/platform/win/windows_dlls.cpp',