Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use namespace ShapeCorners instead of prefix #228

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions ClassDiagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
classDiagram

namespace KWin {
class Effect {
class KWinEffect {
prePaintWindow()
}

Expand Down Expand Up @@ -36,7 +36,7 @@ classDiagram
}

namespace kwin4_shapecorners_effect {
class ShapeCornersEffect {
class Effect {
m_shader_manager
m_managed
+prePaintWindow()
Expand All @@ -49,7 +49,7 @@ classDiagram
windowResized()
}

class ShapeCornersWindow {
class Window {
name: QString
isTiled: bool
isMaximized: bool
Expand All @@ -64,15 +64,15 @@ classDiagram
hasEffect()
}

class ShapeCornersShader {
class Shader {
m_shader: GLShader
IsValid()
GetShader()
Bind()
UnBind()
}

class ShapeCornersColor {
class Color {
r: float
g: float
b: float
Expand All @@ -86,15 +86,15 @@ classDiagram
}

namespace kwin4_shapecorners_config {
class ShapeCornersKCM {
class KCM {
ui: UI::Form
+defaults()
+load()
+save()
update_windows()
}

class ShapeCornersConfig {
class Config {
Size: UInt
ShadowSize: UInt
ShadowColor: Color
Expand Down Expand Up @@ -127,23 +127,23 @@ classDiagram
+save()
}

Effect <|-- OffscreenEffect
OffscreenEffect <|-- ShapeCornersEffect
ShapeCornersWindow o-- ShapeCornersColor
KWinEffect <|-- OffscreenEffect
OffscreenEffect <|-- Effect
Window o-- Color

GLShader --o ShaderManager
ShapeCornersEffect o-- ShapeCornersWindow
EffectWindow <-- ShapeCornersWindow
ShapeCornersEffect --> ShapeCornersShader
EffectWindow <.. ShapeCornersEffect
QDBusConnection <.. ShapeCornersEffect
ShapeCornersWindow --> ShapeCornersConfig
Effect o-- Window
EffectWindow <-- Window
Effect --> Shader
EffectWindow <.. Effect
QDBusConnection <.. Effect
Window --> Config

KCModule <|-- ShapeCornersKCM
QDBusConnection <.. ShapeCornersKCM
ShapeCornersKCM --> ShapeCornersConfig
KCModule <|-- KCM
QDBusConnection <.. KCM
KCM --> Config

ShapeCornersShader ..> ShapeCornersWindow
GLShader <-- ShapeCornersShader
ShaderManager <-- ShapeCornersShader
Shader ..> Window
GLShader <-- Shader
ShaderManager <-- Shader
```
60 changes: 30 additions & 30 deletions SequenceDiagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@ sequenceDiagram
participant OffscreenEffect
end
Box kwin4_shapecorners_effect
participant ShapeCornersEffect
participant ShapeCornersShader
participant Effect
participant Shader
participant shapecorners.frag
participant ShapeCornersWindow
participant ShapeCornersConfig
participant Window
participant Config
end

loop approximately 60 frames per second
KWin->>+ShapeCornersEffect: prePaintWindow()
ShapeCornersEffect->>+ShapeCornersWindow: animateProperties()
ShapeCornersWindow->>+ShapeCornersConfig: read config
ShapeCornersConfig-->>-ShapeCornersWindow: values
Note over ShapeCornersWindow: calculates<br>animation
Note over ShapeCornersWindow: stores window<br>properties
KWin->>+Effect: prePaintWindow()
Effect->>+Window: animateProperties()
Window->>+Config: read config
Config-->>-Window: values
Note over Window: calculates<br>animation
Note over Window: stores window<br>properties
alt animation not finished
ShapeCornersWindow-)EffectWindow: addFullRepaint()
Window-)EffectWindow: addFullRepaint()
end
ShapeCornersWindow-->>-ShapeCornersEffect: done
Window-->>-Effect: done
alt window has round corners
ShapeCornersEffect-)EffectWindow: add paint / remove opaque / set translucent
Effect-)EffectWindow: add paint / remove opaque / set translucent
end
ShapeCornersEffect->>+OffscreenEffect: OffscreenEffect::<br>prePaintWindow()
Effect->>+OffscreenEffect: OffscreenEffect::<br>prePaintWindow()
EffectWindow-->>OffscreenEffect: notifies painting parameters
OffscreenEffect-->>-ShapeCornersEffect: done
ShapeCornersEffect-->>-KWin: done prePaint
OffscreenEffect-->>-Effect: done
Effect-->>-KWin: done prePaint

alt if painting is required
KWin->>+ShapeCornersEffect: drawWindow()
ShapeCornersEffect->>+ShapeCornersShader: Bind()
ShapeCornersShader->>+ShapeCornersWindow: read properties
ShapeCornersWindow-->>-ShapeCornersShader: values
ShapeCornersShader->>+shapecorners.frag: setUniform()
shapecorners.frag-->>-ShapeCornersShader: done
ShapeCornersShader-)ShaderManager: pushShader()
ShapeCornersShader-->>-ShapeCornersEffect: done
ShapeCornersEffect->>+OffscreenEffect: OffscreenEffect::<br>drawWindow()
KWin->>+Effect: drawWindow()
Effect->>+Shader: Bind()
Shader->>+Window: read properties
Window-->>-Shader: values
Shader->>+shapecorners.frag: setUniform()
shapecorners.frag-->>-Shader: done
Shader-)ShaderManager: pushShader()
Shader-->>-Effect: done
Effect->>+OffscreenEffect: OffscreenEffect::<br>drawWindow()
OffscreenEffect->>+ShaderManager: render window
par parallel render each pixel
ShaderManager->>+shapecorners.frag: render shader
shapecorners.frag-->>-ShaderManager: done
end
ShaderManager-->>-OffscreenEffect: done
OffscreenEffect-->>-ShapeCornersEffect: done
ShapeCornersEffect->>+ShapeCornersShader: Unbind()
ShapeCornersShader-)ShaderManager: popShader()
ShapeCornersShader-->>-ShapeCornersEffect: done
ShapeCornersEffect-->>-KWin: done draw
OffscreenEffect-->>-Effect: done
Effect->>+Shader: Unbind()
Shader-)ShaderManager: popShader()
Shader-->>-Effect: done
Effect-->>-KWin: done draw
end
end
```
16 changes: 8 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
set(effect_SRCS
ShapeCornersEffect.h
ShapeCornersEffect.cpp
ShapeCornersShader.h
ShapeCornersShader.cpp
ShapeCornersWindow.h
ShapeCornersWindow.cpp
ShapeCornersColor.h
Effect.h
Effect.cpp
Shader.h
Shader.cpp
Window.h
Window.cpp
Color.h
plugin.cpp
)

kconfig_add_kcfg_files(effect_SRCS ShapeCornersConfig.kcfgc)
kconfig_add_kcfg_files(effect_SRCS Config.kcfgc)
kcoreaddons_add_plugin(kwin4_effect_shapecorners SOURCES ${effect_SRCS} INSTALL_NAMESPACE "kwin/effects/plugins/")

target_link_libraries(kwin4_effect_shapecorners
Expand Down
136 changes: 136 additions & 0 deletions src/Color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//
// Created by matin on 07/05/24.
//

#ifndef KWIN4_EFFECT_SHAPECORNERS_COLOR_H
#define KWIN4_EFFECT_SHAPECORNERS_COLOR_H

#include <QColor>
#include <sstream>
#include <cmath>

namespace ShapeCorners {
struct Color {

float r;
float g;
float b;
float a;

constexpr Color() :
Color(0, 0, 0, 0) {};

explicit Color(const QColor &c) :
Color(c.red(), c.green(), c.blue(), c.alpha()) {}

constexpr Color(int r, int g, int b, int a = 255) :
r(static_cast<float>(r)),
g(static_cast<float>(g)),
b(static_cast<float>(b)),
a(static_cast<float>(a)) {}

[[maybe_unused]] constexpr Color(float r, float g, float b, float a = 255.0f) :
r(r), g(g), b(b), a(a) {}

constexpr Color operator-(const Color &c) const {
return {
r - c.r,
g - c.g,
b - c.b,
a - c.a
};
}

constexpr Color operator+(const Color &c) const {
return {
r + c.r,
g + c.g,
b + c.b,
a + c.a
};
}

template<typename T>
constexpr Color operator*(const T &f) const {
return {
r * f,
g * f,
b * f,
a * f
};
}

template<typename T>
constexpr Color operator/(const T &f) const {
return {
r / f,
g / f,
b / f,
a / f
};
}

[[nodiscard]] constexpr bool isZero() const {
return (
r == 0 &&
g == 0 &&
b == 0 &&
a == 0
);
}

[[nodiscard]] QColor toQColor() const {
return {
static_cast<int>(r),
static_cast<int>(g),
static_cast<int>(b),
static_cast<int>(a)
};
}

[[maybe_unused]] [[nodiscard]] std::string toString() const {
std::stringstream ss;
ss << "[ " << r << " , " << g << " , " << b << " , " << a << " ]";
return ss.str();
}

constexpr void operator+=(const Color &c) {
r += c.r;
g += c.g;
b += c.b;
a += c.a;
}

constexpr void round() {
r = std::round(r);
g = std::round(g);
b = std::round(b);
a = std::round(a);
}

constexpr void clamp() {
r = std::clamp(r, 0.0f, 255.0f);
g = std::clamp(g, 0.0f, 255.0f);
b = std::clamp(b, 0.0f, 255.0f);
a = std::clamp(a, 0.0f, 255.0f);
}

constexpr void setAlpha(int alpha) {
a = static_cast<float>(alpha);
}

[[maybe_unused]] constexpr void setRed(int red) {
r = static_cast<float>(red);
}

[[maybe_unused]] constexpr void setGreen(int green) {
g = static_cast<float>(green);
}

[[maybe_unused]] constexpr void setBlue(int blue) {
b = static_cast<float>(blue);
}
};
}

#endif //KWIN4_EFFECT_SHAPECORNERS_COLOR_H
5 changes: 5 additions & 0 deletions src/Config.kcfgc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
File=kcm/options.kcfg
NameSpace=ShapeCorners
ClassName=Config
Singleton=true
Mutators=false
Loading
Loading