diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 6e4bd6f68..56979530a 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2435,6 +2435,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_net_speed_boost_big" = "Big"; "ktg_settings_system" = "System"; +"ktg_settings_use_native_decorations" = "Native window decorations"; "ktg_settings_other" = "Other"; "ktg_profile_copy_id" = "Copy ID"; diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index 378e97582..f770cecf7 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -66,6 +66,7 @@ "ktg_net_speed_boost_medium": "Среднее", "ktg_net_speed_boost_big": "Высокое", "ktg_settings_system": "Система", + "ktg_settings_use_native_decorations": "Системные декорации окна", "ktg_settings_other": "Прочие", "ktg_profile_copy_id": "Копировать ID", "ktg_profile_bot_id": "ID бота", diff --git a/Telegram/SourceFiles/kotato/json_settings.cpp b/Telegram/SourceFiles/kotato/json_settings.cpp index b559915cd..f53f3e018 100644 --- a/Telegram/SourceFiles/kotato/json_settings.cpp +++ b/Telegram/SourceFiles/kotato/json_settings.cpp @@ -185,6 +185,7 @@ QByteArray GenerateSettingsJson(bool areDefault = false) { settings.insert(qsl("chat_list_lines"), DialogListLines()); settings.insert(qsl("disable_up_edit"), cDisableUpEdit()); settings.insert(qsl("confirm_before_calls"), cConfirmBeforeCall()); + settings.insert(qsl("native_decorations"), cUseNativeDecorations()); settings.insert(qsl("recent_stickers_limit"), RecentStickersLimit()); settings.insert(qsl("userpic_corner_type"), cUserpicCornersType()); settings.insert(qsl("always_show_top_userpic"), cShowTopBarUserpic()); @@ -400,6 +401,10 @@ bool Manager::readCustomFile() { cSetConfirmBeforeCall(v); }); + ReadBoolOption(settings, "native_decorations", [&](auto v) { + cSetUseNativeDecorations(v); + }); + ReadIntOption(settings, "recent_stickers_limit", [&](auto v) { if (v >= 0 && v <= 200) { SetRecentStickersLimit(v); diff --git a/Telegram/SourceFiles/kotato/settings.cpp b/Telegram/SourceFiles/kotato/settings.cpp index e119b0ce4..064d9592a 100644 --- a/Telegram/SourceFiles/kotato/settings.cpp +++ b/Telegram/SourceFiles/kotato/settings.cpp @@ -113,6 +113,12 @@ bool AddCustomReplace(QString from, QString to) { bool gConfirmBeforeCall = false; +bool gUseNativeDecorations = false; +bool UseNativeDecorations() { + static const auto NativeDecorations = cUseNativeDecorations(); + return NativeDecorations; +} + rpl::variable gRecentStickersLimit = 20; void SetRecentStickersLimit(int limit) { if (limit >= 0 || limit <= 200) { diff --git a/Telegram/SourceFiles/kotato/settings.h b/Telegram/SourceFiles/kotato/settings.h index deffe9867..1ad3aa63a 100644 --- a/Telegram/SourceFiles/kotato/settings.h +++ b/Telegram/SourceFiles/kotato/settings.h @@ -88,6 +88,9 @@ DeclareRefSetting(CustomReplacementsMap, CustomReplaces); bool AddCustomReplace(QString from, QString to); DeclareSetting(bool, ConfirmBeforeCall); +DeclareSetting(bool, UseNativeDecorations); +[[nodiscard]] bool UseNativeDecorations(); + void SetRecentStickersLimit(int limit); [[nodiscard]] int RecentStickersLimit(); [[nodiscard]] rpl::producer RecentStickersLimitChanges(); diff --git a/Telegram/SourceFiles/kotato/settings_menu.cpp b/Telegram/SourceFiles/kotato/settings_menu.cpp index de68eb6b0..3c84ca4ef 100644 --- a/Telegram/SourceFiles/kotato/settings_menu.cpp +++ b/Telegram/SourceFiles/kotato/settings_menu.cpp @@ -370,6 +370,35 @@ void SetupKotatoSystem(not_null container) { AddSkip(container); AddSubsectionTitle(container, tr::ktg_settings_system()); +#if defined Q_OS_WIN || defined Q_OS_MAC + const auto useNativeDecorationsToggled = Ui::CreateChild>( + container.get()); + AddButton( + container, + tr::ktg_settings_use_native_decorations(), + st::settingsButton + )->toggleOn( + useNativeDecorationsToggled->events_starting_with_copy(cUseNativeDecorations()) + )->toggledValue( + ) | rpl::filter([](bool enabled) { + return (enabled != cUseNativeDecorations()); + }) | rpl::start_with_next([=](bool enabled) { + const auto confirmed = [=] { + cSetUseNativeDecorations(enabled); + ::Kotato::JsonSettings::Write(); + App::restart(); + }; + const auto cancelled = [=] { + useNativeDecorationsToggled->fire(cUseNativeDecorations() == true); + }; + Ui::show(Box( + tr::lng_settings_need_restart(tr::now), + tr::lng_settings_restart_now(tr::now), + confirmed, + cancelled)); + }, container->lifetime()); +#endif // Q_OS_WIN || Q_OS_MAC + const QMap trayIconOptions = { { 0, TrayIconLabel(0) }, { 1, TrayIconLabel(1) }, diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index d71c4769c..74e8926d6 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -633,17 +633,20 @@ UINT MainWindow::_taskbarCreatedMsgId = 0; MainWindow::MainWindow(not_null controller) : Window::MainWindow(controller) , ps_tbHider_hWnd(createTaskbarHider()) { - QCoreApplication::instance()->installNativeEventFilter( - EventFilter::CreateInstance(this)); + if (!UseNativeDecorations()) { + QCoreApplication::instance()->installNativeEventFilter( + EventFilter::CreateInstance(this)); + + subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { + if (update.paletteChanged()) { + _psShadowWindows.setColor(st::windowShadowFg->c); + } + }); + } if (!_taskbarCreatedMsgId) { _taskbarCreatedMsgId = RegisterWindowMessage(L"TaskbarButtonCreated"); } - subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) { - if (update.paletteChanged()) { - _psShadowWindows.setColor(st::windowShadowFg->c); - } - }); } void MainWindow::TaskbarCreated() { @@ -654,16 +657,22 @@ void MainWindow::TaskbarCreated() { } void MainWindow::shadowsUpdate(ShadowsChanges changes, WINDOWPOS *position) { - _psShadowWindows.update(changes, position); + if (!UseNativeDecorations()) { + _psShadowWindows.update(changes, position); + } } void MainWindow::shadowsActivate() { -// _psShadowWindows.setColor(_shActive); - shadowsUpdate(ShadowsChange::Activate); + if (!UseNativeDecorations()) { +// _psShadowWindows.setColor(_shActive); + shadowsUpdate(ShadowsChange::Activate); + } } void MainWindow::shadowsDeactivate() { -// _psShadowWindows.setColor(_shInactive); +// if (!UseNativeDecorations()) { +// _psShadowWindows.setColor(_shInactive); +// } } void MainWindow::psShowTrayMenu() { @@ -827,14 +836,16 @@ void MainWindow::initHook() { } void MainWindow::initShadows() { - _psShadowWindows.init(this, st::windowShadowFg->c); - _shadowsWorking = true; - psUpdateMargins(); - shadowsUpdate(ShadowsChange::Hidden); + if (!UseNativeDecorations()) { + _psShadowWindows.init(this, st::windowShadowFg->c); + _shadowsWorking = true; + psUpdateMargins(); + shadowsUpdate(ShadowsChange::Hidden); + } } void MainWindow::firstShadowsUpdate() { - if (!(windowState() & Qt::WindowMinimized) && !isHidden()) { + if (!UseNativeDecorations() && !(windowState() & Qt::WindowMinimized) && !isHidden()) { shadowsUpdate(ShadowsChange::Moved | ShadowsChange::Resized | ShadowsChange::Shown); } } @@ -983,13 +994,17 @@ MainWindow::~MainWindow() { taskbarList.Reset(); } - _shadowsWorking = false; if (ps_menu) DestroyMenu(ps_menu); psDestroyIcons(); - _psShadowWindows.destroy(); + if (!UseNativeDecorations()) { + _shadowsWorking = false; + _psShadowWindows.destroy(); + } if (ps_tbHider_hWnd) DestroyWindow(ps_tbHider_hWnd); - EventFilter::Destroy(); + if (!UseNativeDecorations()) { + EventFilter::Destroy(); + } } } // namespace Platform diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index b109bc10e..f9e346cfd 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -357,7 +357,7 @@ void MainWindow::init() { updatePalette(); - if ((_title = Platform::CreateTitleWidget(this))) { + if (!UseNativeDecorations() && (_title = Platform::CreateTitleWidget(this))) { _title->init(); }