2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 14:17:45 +00:00

Add option to disable title widget (#44)

This commit is contained in:
ilya-fedin
2020-05-17 21:59:33 +04:00
committed by GitHub
parent d799c2492c
commit 1b762e83ed
8 changed files with 80 additions and 20 deletions

View File

@@ -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";

View File

@@ -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 бота",

View File

@@ -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);

View File

@@ -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<int> gRecentStickersLimit = 20;
void SetRecentStickersLimit(int limit) {
if (limit >= 0 || limit <= 200) {

View File

@@ -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<int> RecentStickersLimitChanges();

View File

@@ -370,6 +370,35 @@ void SetupKotatoSystem(not_null<Ui::VerticalLayout*> container) {
AddSkip(container);
AddSubsectionTitle(container, tr::ktg_settings_system());
#if defined Q_OS_WIN || defined Q_OS_MAC
const auto useNativeDecorationsToggled = Ui::CreateChild<rpl::event_stream<bool>>(
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<ConfirmBox>(
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<int, QString> trayIconOptions = {
{ 0, TrayIconLabel(0) },
{ 1, TrayIconLabel(1) },

View File

@@ -633,17 +633,20 @@ UINT MainWindow::_taskbarCreatedMsgId = 0;
MainWindow::MainWindow(not_null<Window::Controller*> 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

View File

@@ -357,7 +357,7 @@ void MainWindow::init() {
updatePalette();
if ((_title = Platform::CreateTitleWidget(this))) {
if (!UseNativeDecorations() && (_title = Platform::CreateTitleWidget(this))) {
_title->init();
}