Skip to content

Commit

Permalink
add animation speed override option
Browse files Browse the repository at this point in the history
  • Loading branch information
KZDKM committed Apr 11, 2024
1 parent 0d7922b commit e3137ae
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ hyprpm enable Hyprspace

### Animation
- The panel uses the `windows` curve for a slide-in animation
- Use `plugin:overview:overrideAnimSpeed` to override the animation speed

### Behaviors
- `plugin:overview:autoDrag` mouse click always drags window when overview is open
Expand Down
1 change: 1 addition & 0 deletions src/Globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace Config {
extern bool showNewWorkspace;
extern bool showEmptyWorkspace;

extern float overrideAnimSpeed;
extern float dragAlpha;
}

Expand Down
28 changes: 25 additions & 3 deletions src/Overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@

CHyprspaceWidget::CHyprspaceWidget(uint64_t inOwnerID) {
ownerID = inOwnerID;
// FIXME: add null check
curYOffset.create(g_pConfigManager->getAnimationPropertyConfig("windows"), AVARDAMAGE_ENTIRE);
workspaceScrollOffset.create(g_pConfigManager->getAnimationPropertyConfig("windows"), AVARDAMAGE_ENTIRE);

curAnimationConfig = *g_pConfigManager->getAnimationPropertyConfig("windows");

// the fuck is pValues???
curAnimation = *curAnimationConfig.pValues;
curAnimationConfig.pValues = &curAnimation;

if (Config::overrideAnimSpeed > 0)
curAnimation.internalSpeed = Config::overrideAnimSpeed;

curYOffset.create(&curAnimationConfig, AVARDAMAGE_ENTIRE);
workspaceScrollOffset.create(&curAnimationConfig, AVARDAMAGE_ENTIRE);
curYOffset.setValueAndWarp(Config::panelHeight);
workspaceScrollOffset.setValueAndWarp(0);
}
Expand Down Expand Up @@ -61,6 +70,19 @@ void CHyprspaceWidget::hide() {
g_pCompositor->scheduleFrameForMonitor(owner);
}

void CHyprspaceWidget::updateConfig() {
curAnimationConfig = *g_pConfigManager->getAnimationPropertyConfig("windows");

curAnimation = *curAnimationConfig.pValues;
curAnimationConfig.pValues = &curAnimation;

if (Config::overrideAnimSpeed > 0)
curAnimation.internalSpeed = Config::overrideAnimSpeed;

curYOffset.create(&curAnimationConfig, AVARDAMAGE_ENTIRE);
workspaceScrollOffset.create(&curAnimationConfig, AVARDAMAGE_ENTIRE);
}

bool CHyprspaceWidget::isActive() {
return active;
}
5 changes: 5 additions & 0 deletions src/Overview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class CHyprspaceWidget {

uint64_t ownerID;

SAnimationPropertyConfig curAnimationConfig;
SAnimationPropertyConfig curAnimation;

// for slide-in animation
CAnimatedVariable<float> curYOffset;

Expand All @@ -29,6 +32,8 @@ class CHyprspaceWidget {
void show();
void hide();

void updateConfig();

void draw(timespec*); // call before renderWorkspaceWindows

void reserveArea(); // call after arrangeLayersForMonitor
Expand Down
12 changes: 9 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using namespace std;

CFunctionHook* renderWorkspaceWindowsHook;
CFunctionHook* arrangeLayersForMonitorHook;
CFunctionHook* recalculateMonitorHook;
CFunctionHook* changeWorkspaceHook;
CFunctionHook* getWorkspaceRuleForHook;
CFunctionHook* onMouseEventHook;
Expand Down Expand Up @@ -49,6 +48,8 @@ bool Config::exitOnSwitch = false;
bool Config::showNewWorkspace = true;
bool Config::showEmptyWorkspace = true;

float Config::overrideAnimSpeed = 0;

float Config::dragAlpha = 0.2;

int hyprsplitNumWorkspaces = -1;
Expand Down Expand Up @@ -245,6 +246,12 @@ void reloadConfig() {
Config::showNewWorkspace = std::any_cast<Hyprlang::INT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:showNewWorkspace")->getValue());
Config::showEmptyWorkspace = std::any_cast<Hyprlang::INT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:showEmptyWorkspace")->getValue());

Config::overrideAnimSpeed = std::any_cast<Hyprlang::FLOAT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:overrideAnimSpeed")->getValue());

for (auto& widget : g_overviewWidgets) {
widget->updateConfig();
}

Config::dragAlpha = std::any_cast<Hyprlang::FLOAT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:dragAlpha")->getValue());

Hyprlang::CConfigValue* numWorkspacesConfig = HyprlandAPI::getConfigValue(pHandle, "plugin:hyprsplit:num_workspaces");
Expand Down Expand Up @@ -296,6 +303,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE inHandle) {
HyprlandAPI::addConfigValue(pHandle, "plugin:overview:showNewWorkspace", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(pHandle, "plugin:overview:showEmptyWorkspace", Hyprlang::INT{1});

HyprlandAPI::addConfigValue(pHandle, "plugin:overview:overrideAnimSpeed", Hyprlang::FLOAT{0.0});
HyprlandAPI::addConfigValue(pHandle, "plugin:overview:dragAlpha", Hyprlang::FLOAT{0.2});

reloadConfig();
Expand Down Expand Up @@ -365,8 +373,6 @@ APICALL EXPORT void PLUGIN_EXIT() {
arrangeLayersForMonitorHook->unhook();
if (changeWorkspaceHook)
changeWorkspaceHook->unhook();
if (recalculateMonitorHook)
recalculateMonitorHook->unhook();
if (getWorkspaceRuleForHook)
getWorkspaceRuleForHook->unhook();
if (onMouseEventHook)
Expand Down

0 comments on commit e3137ae

Please sign in to comment.