Skip to content

Commit

Permalink
Reuse lib_ui's title control side deduction code
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin committed Jul 19, 2023
1 parent 86cc3c5 commit 8bdac85
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
11 changes: 2 additions & 9 deletions Telegram/SourceFiles/media/view/media_view_pip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ For license and copyright information please follow this link:
#include "base/power_save_blocker.h"
#include "base/event_filter.h"
#include "ui/platform/ui_platform_utility.h"
#include "ui/platform/ui_platform_window_title.h"
#include "ui/widgets/buttons.h"
#include "ui/wrap/fade_wrap.h"
#include "ui/widgets/shadow.h"
Expand All @@ -48,14 +49,6 @@ namespace {
constexpr auto kPipLoaderPriority = 2;
constexpr auto kMsInSecond = 1000;

[[nodiscard]] bool IsWindowControlsOnLeft() {
using Control = Ui::Platform::TitleControls::Control;
const auto controlsLayout = Ui::Platform::TitleControlsLayout();
return ranges::contains(controlsLayout.left, Control::Close)
|| (controlsLayout.left.size() > controlsLayout.right.size()
&& !ranges::contains(controlsLayout.right, Control::Close));
}

[[nodiscard]] QRect ScreenFromPosition(QPoint point) {
const auto screen = QGuiApplication::screenAt(point);
const auto use = screen ? screen : QGuiApplication::primaryScreen();
Expand Down Expand Up @@ -1265,7 +1258,7 @@ void Pip::setupButtons() {
rect.y(),
volumeToggleWidth,
volumeToggleHeight);
if (!IsWindowControlsOnLeft()) {
if (!Ui::Platform::TitleControlsOnLeft()) {
_close.area.moveLeft(rect.x()
+ rect.width()
- (_close.area.x() - rect.x())
Expand Down
12 changes: 1 addition & 11 deletions Telegram/SourceFiles/platform/platform_overlay_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ For license and copyright information please follow this link:

#include "ui/effects/animations.h"
#include "ui/platform/ui_platform_window_title.h"
#include "ui/platform/ui_platform_utility.h"
#include "ui/widgets/rp_window.h"
#include "ui/abstract_button.h"
#include "styles/style_media_view.h"
Expand Down Expand Up @@ -228,16 +227,7 @@ rpl::producer<bool> DefaultOverlayWidgetHelper::controlsSideRightValue() {

return TitleControlsLayoutValue(
) | rpl::map([=](const TitleControls::Layout &layout) {
// See TitleControls::updateControlsPosition.
if (ranges::contains(layout.left, TitleControl::Close)) {
return false;
} else if (ranges::contains(layout.right, TitleControl::Close)) {
return true;
} else if (layout.left.size() > layout.right.size()) {
return false;
} else {
return true;
}
return !TitleControlsOnLeft(layout);
}) | rpl::distinct_until_changed();
}

Expand Down

0 comments on commit 8bdac85

Please sign in to comment.