Skip to content

Commit

Permalink
chore(player): control bar hidden behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ffiirree committed Mar 25, 2024
1 parent 4fa1610 commit 08c4498
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/player/control-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ ControlWidget::ControlWidget(FramelessWindow *parent)
bool ControlWidget::hideable() const
{
const auto pos = mapFromGlobal(QCursor::pos());
return !title_bar_->geometry().contains(pos) && !control_bar_->geometry().contains(pos) &&
return !(title_bar_->geometry() + QMargins{ 0, 0, 0, 25 }).contains(pos) &&
!(control_bar_->geometry() + QMargins{ 0, 25, 0, 0 }).contains(pos) &&
!speed_box_->view()->isVisible();
}

Expand Down
18 changes: 10 additions & 8 deletions src/player/video-player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ VideoPlayer::VideoPlayer(QWidget *parent)

// control bar
control_ = new ControlWidget(this);

// clang-format off
connect(control_, &ControlWidget::pause, this, &VideoPlayer::pause);
connect(control_, &ControlWidget::resume, this, &VideoPlayer::resume);
Expand Down Expand Up @@ -70,11 +71,11 @@ VideoPlayer::VideoPlayer(QWidget *parent)

timer_ = new QTimer(this);
timer_->setSingleShot(true);
timer_->start(2500ms);
timer_->start(2000ms);
connect(timer_, &QTimer::timeout, [this] {
if (control_->isVisible() && control_->hideable()) {
if (control_->hideable()) {
setCursor(Qt::BlankCursor);
control_->hide();
if (control_->isVisible()) control_->hide();
}
});

Expand Down Expand Up @@ -421,12 +422,13 @@ void VideoPlayer::setVolume(const int volume) { control_->setVolume(std::clamp<i
bool VideoPlayer::event(QEvent *event)
{
if (event->type() == QEvent::HoverMove) {
timer_->start(2500ms);
timer_->start(2000ms);

if (control_ && !control_->isVisible()) {
setCursor(Qt::ArrowCursor);
control_->show();
}
setCursor(Qt::ArrowCursor);
if (!control_->isVisible() && !control_->hideable()) control_->show();
}
else if (event->type() == QEvent::Show) {
control_->hide();
}

return FramelessWindow::event(event);
Expand Down
6 changes: 4 additions & 2 deletions src/widgets/framelesswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ bool FramelessWindow::nativeEvent(const QByteArray& eventType, void *message, Q_
}
}

if (IsFullscreen(hwnd) || IsMaximized(hwnd) || isSizeFixed()) {
const auto fullscreen = IsFullscreen(hwnd);

if (fullscreen || IsMaximized(hwnd) || isSizeFixed()) {
switch (res) {
case HTTOP:
case HTRIGHT:
Expand All @@ -288,7 +290,7 @@ bool FramelessWindow::nativeEvent(const QByteArray& eventType, void *message, Q_
}
}

if (res == HTCLIENT && titlebar_ && titlebar_->isVisible()) {
if (!fullscreen && res == HTCLIENT && titlebar_ && titlebar_->isVisible()) {
if (const auto pos = mapFromGlobal(QPoint{ GET_X_LPARAM(wmsg->lParam), GET_Y_LPARAM(wmsg->lParam) });
titlebar_->geometry().contains(pos) && !titlebar_->isInSystemButtons(pos)) {
*result = HTCAPTION;
Expand Down

0 comments on commit 08c4498

Please sign in to comment.