2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Add AllowLinuxNvidiaOpenGL option.

This commit is contained in:
John Preston
2022-02-02 15:33:41 +03:00
parent 38137e16a0
commit 67c538ae8f
7 changed files with 97 additions and 17 deletions

View File

@@ -7,13 +7,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "settings/settings_experimental.h"
#include "ui/boxes/confirm_box.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/gl/gl_detection.h"
#include "base/options.h"
#include "core/application.h"
#include "chat_helpers/tabbed_panel.h"
#include "lang/lang_keys.h"
#include "window/window_peer_menu.h"
#include "window/window_session_controller.h"
#include "window/window_controller.h"
#include "styles/style_settings.h"
#include "styles/style_layers.h"
@@ -21,27 +27,61 @@ namespace Settings {
namespace {
void AddOption(
not_null<Window::Controller*> window,
not_null<Ui::VerticalLayout*> container,
base::options::option<bool> &option) {
base::options::option<bool> &option,
rpl::producer<> resetClicks) {
auto &lifetime = container->lifetime();
const auto name = option.name().isEmpty() ? option.id() : option.name();
AddButton(
const auto toggles = lifetime.make_state<rpl::event_stream<bool>>();
std::move(
resetClicks
) | rpl::map_to(
option.defaultValue()
) | rpl::start_to_stream(*toggles, lifetime);
const auto button = AddButton(
container,
rpl::single(name),
st::settingsButton
)->toggleOn(rpl::single(option.value()))->toggledChanges(
option.relevant() ? st::settingsButton : st::settingsOptionDisabled
)->toggleOn(toggles->events_starting_with(option.value()));
const auto restarter = (option.relevant() && option.restartRequired())
? button->lifetime().make_state<base::Timer>()
: nullptr;
if (restarter) {
restarter->setCallback([=] {
window->show(Box<Ui::ConfirmBox>(
tr::lng_settings_need_restart(tr::now),
tr::lng_settings_restart_now(tr::now),
tr::lng_settings_restart_later(tr::now),
[] { Core::Restart(); }));
});
}
button->toggledChanges(
) | rpl::start_with_next([=, &option](bool toggled) {
if (!option.relevant() && toggled != option.defaultValue()) {
toggles->fire_copy(option.defaultValue());
window->showToast(
tr::lng_settings_experimental_irrelevant(tr::now));
return;
}
option.set(toggled);
if (restarter) {
restarter->callOnce(st::settingsButton.toggle.duration);
}
}, container->lifetime());
const auto &description = option.description();
if (!description.isEmpty()) {
AddSkip(container, st::settingsCheckboxesSkip);
AddDividerText(container, rpl::single(description));
AddSkip(container, st::settingsCheckboxesSkip);
}
}
void SetupExperimental(
not_null<Window::SessionController*> controller,
not_null<Window::Controller*> window,
not_null<Ui::VerticalLayout*> container) {
AddSkip(container, st::settingsCheckboxesSkip);
@@ -52,21 +92,42 @@ void SetupExperimental(
st::boxLabel),
st::settingsDividerLabelPadding);
AddDivider(container);
auto reset = (Button*)nullptr;
if (base::options::changed()) {
const auto wrap = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
const auto inner = wrap->entity();
AddDivider(inner);
AddSkip(inner, st::settingsCheckboxesSkip);
reset = AddButton(
inner,
tr::lng_settings_experimental_restore(),
st::settingsButton);
reset->addClickHandler([=] {
base::options::reset();
wrap->hide(anim::type::normal);
});
AddSkip(inner, st::settingsCheckboxesSkip);
}
AddDivider(container);
AddSkip(container, st::settingsCheckboxesSkip);
const auto addToggle = [&](const char name[]) {
AddOption(container, base::options::lookup<bool>(name));
AddOption(
window,
container,
base::options::lookup<bool>(name),
(reset
? (reset->clicks() | rpl::to_empty)
: rpl::producer<>()));
};
addToggle(ChatHelpers::kOptionTabbedPanelShowOnClick);
AddSkip(container, st::settingsCheckboxesSkip);
addToggle(Window::kOptionViewProfileInChatsListContextMenu);
AddSkip(container, st::settingsCheckboxesSkip);
addToggle(Ui::GL::kOptionAllowLinuxNvidiaOpenGL);
}
} // namespace
@@ -82,7 +143,7 @@ void Experimental::setupContent(
not_null<Window::SessionController*> controller) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
SetupExperimental(controller, content);
SetupExperimental(&controller->window(), content);
Ui::ResizeFitChild(this, content);
}