Skip to content

Commit

Permalink
feat(effect): make magiclamp look good with hidden panels
Browse files Browse the repository at this point in the history
If the panel is hidden, the animation can be clipped some distance away
from the screen edge. To fix that, move the icon offscreen.
  • Loading branch information
zzag authored and romangg committed Jul 10, 2023
1 parent 118e009 commit 5d39eb5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/effect/kwineffects/effect_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class KWINEFFECTS_EXPORT EffectWindow : public QObject
virtual void unrefWindow() = 0;

virtual bool isDeleted() const = 0;
virtual bool isHidden() const = 0;

virtual bool isMinimized() const = 0;
virtual double opacity() const = 0;
Expand Down
7 changes: 7 additions & 0 deletions lib/render/effect/window_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ class effects_window_impl : public EffectWindow
*window.ref_win);
}

bool isHidden() const override
{
return std::visit(
overload{[](auto&& ref_win) { return static_cast<bool>(ref_win->isHiddenInternal()); }},
*window.ref_win);
}

bool isMinimized() const override
{
return std::visit(overload{[](auto&& ref_win) {
Expand Down
19 changes: 19 additions & 0 deletions plugins/effects/magiclamp/magiclamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ void MagicLampEffect::apply(effect::window_paint_data& data, WindowQuadList& qua
position = Right;
}
}

// If the panel is hidden, move the icon offscreen so the animation looks correct.
if (panel->isHidden()) {
const QRectF panelScreen = effects->clientArea(ScreenArea, panel);
switch (position) {
case Bottom:
icon.moveTop(panelScreen.y() + panelScreen.height());
break;
case Top:
icon.moveTop(panelScreen.y() - icon.height());
break;
case Left:
icon.moveLeft(panelScreen.x() - icon.width());
break;
case Right:
icon.moveLeft(panelScreen.x() + panelScreen.width());
break;
}
}
} else {
// we did not find a panel, so it might be autohidden
QRect iconScreen
Expand Down

0 comments on commit 5d39eb5

Please sign in to comment.