Skip to content

Commit

Permalink
fix: hopefully less build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Dec 2, 2023
1 parent 93bbd99 commit 43d4cc4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 21 deletions.
14 changes: 12 additions & 2 deletions src/widgets/BaseWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,11 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message,
break;

case WM_NCMOUSEMOVE: {
if (!this->ui_.titlebarButtons)
{
break;
}

if (overButton())
{
*result = 0;
Expand All @@ -619,13 +624,16 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message,
break;

case WM_NCMOUSELEAVE: {
this->ui_.titlebarButtons->leave();
if (this->ui_.titlebarButtons)
{
this->ui_.titlebarButtons->leave();
}
}
break;

case WM_NCLBUTTONDOWN:
case WM_NCLBUTTONUP: {
if (!overButton())
if (!this->ui_.titlebarButtons || !overButton())
{
break;
}
Expand Down Expand Up @@ -715,6 +723,7 @@ void BaseWindow::calcButtonsSizes()
return;
}

#ifdef USEWINSDK
if ((static_cast<float>(this->width()) / this->scale()) < 300)
{
this->ui_.titlebarButtons->setSmallSize();
Expand All @@ -723,6 +732,7 @@ void BaseWindow::calcButtonsSizes()
{
this->ui_.titlebarButtons->setRegularSize();
}
#endif
}

void BaseWindow::drawCustomWindowFrame(QPainter &painter)
Expand Down
49 changes: 34 additions & 15 deletions src/widgets/helper/TitlebarButtons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,34 @@ TitleBarButtons::TitleBarButtons(QWidget *window, TitleBarButton *minButton,

void TitleBarButtons::hover(size_t ht, QPoint at)
{
auto [button, others] = this->buttonForHt(ht);
button->ncEnter();
button->ncMove(button->mapFromGlobal(at));
for (auto *other : others)
TitleBarButton *hovered{};
TitleBarButton *other1{};
TitleBarButton *other2{};
switch (ht)
{
other->ncLeave();
case HTMAXBUTTON:
hovered = this->maxButton_;
other1 = this->minButton_;
other2 = this->closeButton_;
break;
case HTMINBUTTON:
hovered = this->minButton_;
other1 = this->maxButton_;
other2 = this->closeButton_;
break;
case HTCLOSE:
hovered = this->closeButton_;
other1 = this->minButton_;
other2 = this->maxButton_;
break;
default:
Q_ASSERT_X(false, Q_FUNC_INFO, "Precondition violated");
return;
}
hovered->ncEnter();
hovered->ncMove(hovered->mapFromGlobal(at));
other1->ncLeave();
other2->ncLeave();
}

void TitleBarButtons::leave()
Expand All @@ -38,13 +59,13 @@ void TitleBarButtons::leave()

void TitleBarButtons::mouseDown(size_t ht, QPoint at)
{
auto [button, others] = this->buttonForHt(ht);
auto *button = this->buttonForHt(ht);
button->ncMouseDown(button->mapFromGlobal(at));
}

void TitleBarButtons::mouseUp(size_t ht, QPoint at)
{
auto [button, others] = this->buttonForHt(ht);
auto *button = this->buttonForHt(ht);
button->ncMouseUp(button->mapFromGlobal(at));
}

Expand All @@ -70,21 +91,19 @@ void TitleBarButtons::setRegularSize()
this->closeButton_->setScaleIndependantSize(46, 30);
}

std::pair<TitleBarButton *, std::array<TitleBarButton *, 2>>
TitleBarButtons::buttonForHt(size_t ht) const
TitleBarButton *TitleBarButtons::buttonForHt(size_t ht) const
{
switch (ht)
{
case HTMAXBUTTON:
return {this->maxButton_, {this->minButton_, this->closeButton_}};
return this->maxButton_;
case HTMINBUTTON:
return {this->minButton_, {this->maxButton_, this->closeButton_}};
return this->minButton_;
case HTCLOSE:
return {this->closeButton_, {this->minButton_, this->maxButton_}};
return this->closeButton_;
default:
Q_ASSERT_X(false, Q_FUNC_INFO, "No button for hittest value found");
return {this->closeButton_,
{this->minButton_, this->maxButton_}}; // fallback
Q_ASSERT_X(false, Q_FUNC_INFO, "Precondition violated");
return nullptr;
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/widgets/helper/TitlebarButtons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class QWidget;

#include <QtGlobal>

#include <tuple>

namespace chatterino {

#ifdef USEWINSDK
Expand All @@ -18,9 +16,18 @@ class TitleBarButtons : QObject
TitleBarButtons(QWidget *window, TitleBarButton *minButton,
TitleBarButton *maxButton, TitleBarButton *closeButton);

/// @pre ht must be one of { HTMAXBUTTON, HTMINBUTTON, HTCLOSE }.
/// @param at The global position of the event
void hover(size_t ht, QPoint at);

void leave();

/// @pre ht must be one of { HTMAXBUTTON, HTMINBUTTON, HTCLOSE }.
/// @param at The global position of the event
void mouseDown(size_t ht, QPoint at);

/// @pre ht must be one of { HTMAXBUTTON, HTMINBUTTON, HTCLOSE }.
/// @param at The global position of the event
void mouseUp(size_t ht, QPoint at);

void updateMaxButton();
Expand All @@ -29,8 +36,8 @@ class TitleBarButtons : QObject
void setRegularSize();

private:
std::pair<TitleBarButton *, std::array<TitleBarButton *, 2>> buttonForHt(
size_t ht) const;
/// @pre ht must be one of { HTMAXBUTTON, HTMINBUTTON, HTCLOSE }.
TitleBarButton *buttonForHt(size_t ht) const;

QWidget *window_ = nullptr;
TitleBarButton *minButton_ = nullptr;
Expand Down

0 comments on commit 43d4cc4

Please sign in to comment.