From f956c0f227d6d039218e15c95204faafb13dde5a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 2 Sep 2024 23:42:40 +0300 Subject: [PATCH] Added experimental option to disable touch bar on macOS. --- .../SourceFiles/platform/mac/main_window_mac.mm | 9 +++++++-- .../SourceFiles/settings/settings_experimental.cpp | 1 + Telegram/SourceFiles/window/main_window.cpp | 14 ++++++++++++++ Telegram/SourceFiles/window/main_window.h | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index f4e49f798..6d3514d34 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/mac/main_window_mac.h" #include "data/data_session.h" -#include "mainwidget.h" #include "core/application.h" #include "core/sandbox.h" #include "main/main_session.h" @@ -25,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_specific.h" #include "platform/platform_notifications_manager.h" #include "base/platform/base_platform_info.h" +#include "base/options.h" #include "boxes/peer_list_controllers.h" #include "boxes/about_box.h" #include "lang/lang_keys.h" @@ -300,7 +300,12 @@ void MainWindow::initHook() { if (auto view = reinterpret_cast(winId())) { if (auto window = [view window]) { _private->setNativeWindow(window, view); - _private->initTouchBar(window, &controller()); + if (!base::options::lookup( + Window::kOptionDisableTouchbar).value()) { + _private->initTouchBar(window, &controller()); + } else { + LOG(("Touch Bar was disabled from Experimental Settings.")); + } } } } diff --git a/Telegram/SourceFiles/settings/settings_experimental.cpp b/Telegram/SourceFiles/settings/settings_experimental.cpp index c17eda5b8..983497e8a 100644 --- a/Telegram/SourceFiles/settings/settings_experimental.cpp +++ b/Telegram/SourceFiles/settings/settings_experimental.cpp @@ -156,6 +156,7 @@ void SetupExperimental( addToggle(Core::kOptionSkipUrlSchemeRegister); addToggle(Data::kOptionExternalVideoPlayer); addToggle(Window::kOptionNewWindowsSizeAsFirst); + addToggle(Window::kOptionDisableTouchbar); } } // namespace diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 7702952c1..208ed561c 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -74,9 +74,23 @@ base::options::toggle OptionNewWindowsSizeAsFirst({ .description = "Open new windows with a size of the main window.", }); +base::options::toggle OptionDisableTouchbar({ + .id = kOptionDisableTouchbar, + .name = "Disable Touch Bar (macOS only).", + .scope = [] { +#ifdef Q_OS_MAC + return true; +#else // !Q_OS_MAC + return false; +#endif // !Q_OS_MAC + }, + .restartRequired = true, +}); + } // namespace. const char kOptionNewWindowsSizeAsFirst[] = "new-windows-size-as-first"; +const char kOptionDisableTouchbar[] = "touchbar-disabled"; const QImage &Logo() { static const auto result = QImage(u":/gui/art/logo_256.png"_q); diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index 85d495e7e..d0b5fedce 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -55,6 +55,7 @@ struct CounterLayerArgs { }; extern const char kOptionNewWindowsSizeAsFirst[]; +extern const char kOptionDisableTouchbar[]; [[nodiscard]] QImage GenerateCounterLayer(CounterLayerArgs &&args); [[nodiscard]] QImage WithSmallCounter(QImage image, CounterLayerArgs &&args);