hyprfocus: init new plugin

This commit is contained in:
Vaxry 2025-06-19 17:26:02 +02:00
parent c0e675dd87
commit f444ff0089
No known key found for this signature in database
GPG Key ID: 665806380871D640
7 changed files with 209 additions and 0 deletions

View File

@ -7,6 +7,7 @@ This repo houses official plugins for Hyprland.
- csgo-vulkan-fix -> fixes custom resolutions on CS:GO with `-vulkan`
- hyprbars -> adds title bars to windows
- hyprexpo -> adds an expo-like workspace overview
- hyprfocus -> flashfocus for hyprland
- hyprscrolling -> adds a scrolling layout to hyprland
- hyprtrails -> adds smooth trails behind moving windows
- hyprwinwrap -> clone of xwinwrap, allows you to put any app as a wallpaper

27
hyprfocus/CMakeLists.txt Normal file
View File

@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.27)
project(hyprfocus
DESCRIPTION "flashfocus for Hyprland"
VERSION 0.1
)
set(CMAKE_CXX_STANDARD 23)
file(GLOB_RECURSE SRC "*.cpp")
add_library(hyprfocus SHARED ${SRC})
find_package(PkgConfig REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET
hyprland
libdrm
libinput
libudev
pangocairo
pixman-1
wayland-server
xkbcommon
)
target_link_libraries(hyprfocus PRIVATE rt PkgConfig::deps)
install(TARGETS hyprfocus)

4
hyprfocus/Makefile Normal file
View File

@ -0,0 +1,4 @@
all:
$(CXX) -shared -fPIC --no-gnu-unique main.cpp -o hyprfocus.so -g `pkg-config --cflags pixman-1 libdrm hyprland pangocairo libinput libudev wayland-server xkbcommon` -std=c++2b -O2
clean:
rm ./hyprfocus.so

22
hyprfocus/README.md Normal file
View File

@ -0,0 +1,22 @@
# hyprfocus
Flashfocus for Hyprland.
## Configuring
### Animations
Hyprfocus exposes two animation leaves: `hyprfocusIn` and `hyprfocusOut`:
```ini
animation = hyprfocusIn, 1, 1.7, myCurve
animation = hyprfocusOut, 1, 1.7, myCurve2
```
### Variables
| name | description | type | default |
| --- | --- | --- | --- |
|mode|which mode to use (flash / bounce / slide) | str | flash |
| fade_opacity | for flash, what opacity to flash to | float | 0.8 |
| bounce_strength | for bounce, what fraction of the window's size to jump to | float | 0.95 |
| slide_height | for slice, how far up to slide | float | 20 |

5
hyprfocus/globals.hpp Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include <hyprland/src/plugins/PluginAPI.hpp>
inline HANDLE PHANDLE = nullptr;

141
hyprfocus/main.cpp Normal file
View File

@ -0,0 +1,141 @@
#define WLR_USE_UNSTABLE
#include <unistd.h>
#include <vector>
#include <hyprland/src/includes.hpp>
#include <any>
#include <sstream>
#define private public
#include <hyprland/src/Compositor.hpp>
#include <hyprland/src/config/ConfigValue.hpp>
#include <hyprland/src/helpers/AnimatedVariable.hpp>
#include <hyprland/src/managers/AnimationManager.hpp>
#include <hyprland/src/managers/eventLoop/EventLoopManager.hpp>
#include <hyprland/src/managers/LayoutManager.hpp>
#include <hyprland/src/config/ConfigManager.hpp>
#undef private
#include "globals.hpp"
#include <hyprutils/string/VarList.hpp>
#include <hyprutils/animation/BezierCurve.hpp>
using namespace Hyprutils::String;
using namespace Hyprutils::Animation;
// Do NOT change this function.
APICALL EXPORT std::string PLUGIN_API_VERSION() {
return HYPRLAND_API_VERSION;
}
static void onFocusChange(PHLWINDOW window) {
if (!window)
return;
static const auto POPACITY = CConfigValue<Hyprlang::FLOAT>("plugin:hyprfocus:fade_opacity");
static const auto PBOUNCE = CConfigValue<Hyprlang::FLOAT>("plugin:hyprfocus:bounce_strength");
static const auto PSLIDE = CConfigValue<Hyprlang::FLOAT>("plugin:hyprfocus:slide_height");
static const auto PMODE = CConfigValue<std::string>("plugin:hyprfocus:mode");
const auto PIN = g_pConfigManager->getAnimationPropertyConfig("hyprfocusIn");
const auto POUT = g_pConfigManager->getAnimationPropertyConfig("hyprfocusOut");
if (*PMODE == "flash") {
window->m_activeInactiveAlpha->setConfig(PIN);
*window->m_activeInactiveAlpha = std::clamp(*POPACITY, 0.F, 1.F);
window->m_activeInactiveAlpha->setCallbackOnEnd([w = PHLWINDOWREF{window}, POUT](WP<CBaseAnimatedVariable> pav) {
if (!w)
return;
w->m_activeInactiveAlpha->setConfig(POUT);
g_pCompositor->updateWindowAnimatedDecorationValues(w.lock());
w->updateDynamicRules();
w->m_activeInactiveAlpha->setCallbackOnEnd(nullptr);
});
} else if (*PMODE == "bounce") {
const auto ORIGINAL = CBox{window->m_realPosition->goal(), window->m_realSize->goal()};
window->m_realPosition->setConfig(PIN);
window->m_realSize->setConfig(PIN);
auto box = ORIGINAL.copy().scaleFromCenter(std::clamp(*PBOUNCE, 0.1F, 1.F));
*window->m_realPosition = box.pos();
*window->m_realSize = box.size();
window->m_realSize->setCallbackOnEnd([w = PHLWINDOWREF{window}, POUT, ORIGINAL](WP<CBaseAnimatedVariable> pav) {
if (!w)
return;
w->m_realSize->setConfig(POUT);
w->m_realPosition->setConfig(POUT);
if (w->m_isFloating) {
*w->m_realPosition = ORIGINAL.pos();
*w->m_realSize = ORIGINAL.size();
} else
g_pLayoutManager->getCurrentLayout()->recalculateWindow(w.lock());
w->m_realSize->setCallbackOnEnd(nullptr);
});
} else if (*PMODE == "slide") {
const auto ORIGINAL = window->m_realPosition->goal();
window->m_realPosition->setConfig(PIN);
*window->m_realPosition = ORIGINAL - Vector2D{0.F, std::clamp(*PSLIDE, 0.F, 150.F)};
window->m_realPosition->setCallbackOnEnd([w = PHLWINDOWREF{window}, POUT, ORIGINAL](WP<CBaseAnimatedVariable> pav) {
if (!w)
return;
w->m_realPosition->setConfig(POUT);
if (w->m_isFloating)
*w->m_realPosition = ORIGINAL;
else
g_pLayoutManager->getCurrentLayout()->recalculateWindow(w.lock());
w->m_realPosition->setCallbackOnEnd(nullptr);
});
}
}
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
PHANDLE = handle;
const std::string HASH = __hyprland_api_get_hash();
if (HASH != GIT_COMMIT_HASH) {
HyprlandAPI::addNotification(PHANDLE, "[hyprwinwrap] Failure in initialization: Version mismatch (headers ver is not equal to running hyprland ver)",
CHyprColor{1.0, 0.2, 0.2, 1.0}, 5000);
throw std::runtime_error("[hww] Version mismatch");
}
// clang-format off
static auto P = HyprlandAPI::registerCallbackDynamic(PHANDLE, "activeWindow", [&](void* self, SCallbackInfo& info, std::any data) { onFocusChange(std::any_cast<PHLWINDOW>(data)); });
// clang-format on
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprfocus:mode", Hyprlang::STRING{"flash"});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprfocus:fade_opacity", Hyprlang::FLOAT{0.8F});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprfocus:slide_height", Hyprlang::FLOAT{20.F});
HyprlandAPI::addConfigValue(PHANDLE, "plugin:hyprfocus:bounce_strength", Hyprlang::FLOAT{0.95F});
// this will not be cleaned up after we are unloaded but it doesn't really matter,
// as if we create this again it will just overwrite the old one.
g_pConfigManager->m_animationTree.createNode("hyprfocusIn", "windowsIn");
g_pConfigManager->m_animationTree.createNode("hyprfocusOut", "windowsOut");
return {"hyprfocus", "Flashfocus for Hyprland", "Vaxry", "1.0"};
}
APICALL EXPORT void PLUGIN_EXIT() {
// reset the callbacks to avoid crashes
for (const auto& w : g_pCompositor->m_windows) {
if (!validMapped(w))
continue;
w->m_realSize->setCallbackOnEnd(nullptr);
w->m_realPosition->setCallbackOnEnd(nullptr);
w->m_activeInactiveAlpha->setCallbackOnEnd(nullptr);
}
}

View File

@ -100,3 +100,12 @@ build = [
"make -C hyprscrolling all",
]
since_hyprland = 6066
[hyprfocus]
description = "Flashfocus for Hyprland"
authors = ["Vaxry"]
output = "hyprfocus/hyprfocus.so"
build = [
"make -C hyprfocus all",
]
since_hyprland = 6066