Skip to content

Commit

Permalink
Merge branch 'pyt0xic:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
WingsZeng authored May 31, 2024
2 parents 49f27df + aa7262d commit e66e52b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 18 deletions.
3 changes: 2 additions & 1 deletion hyprpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ output = "hyprfocus.so"
commit_pins = [
["1c460e98f870676b15871fe4e5bfeb1a32a3d6d8", "2af0c1e87e3cdcef3c8f9c7def918982312d0b75"],
["c5e28ebcfe00a510922779b2c568cfa52a317445", "c5e28ebcfe00a510922779b2c568cfa52a317445"],
["0c513ba91bd73106be99e35b1a020d24e5ae874a", "e44b956dd4b7507489219bd2b02a3886d547b7e2"]
["0c513ba91bd73106be99e35b1a020d24e5ae874a", "e44b956dd4b7507489219bd2b02a3886d547b7e2"],
["cba1ade848feac44b2eda677503900639581c3f4", "49dbe19e08f963e01ac4ba17b42719956d390ec7"],
]
build = [
"make all"
Expand Down
2 changes: 1 addition & 1 deletion src/Flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void CFlash::setup(HANDLE pHandle, std::string animationName) {
// hyprfocus_log(LOG, "Active opacity: {}", g_fActiveOpacity);
}

void CFlash::onWindowFocus(CWindow *pWindow, HANDLE pHandle) {
void CFlash::onWindowFocus(PHLWINDOW pWindow, HANDLE pHandle) {
hyprfocus_log(LOG, "Flash onWindowFocus start");
IFocusAnimation::onWindowFocus(pWindow, pHandle);

Expand Down
2 changes: 1 addition & 1 deletion src/Flash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class CFlash : public IFocusAnimation {
public:
void onWindowFocus(CWindow *pWindow, HANDLE pHandle) override;
void onWindowFocus(PHLWINDOW pWindow, HANDLE pHandle) override;
void init(HANDLE pHandle, std::string animationName) override;
void setup(HANDLE pHandle, std::string animationName) override;
};
2 changes: 1 addition & 1 deletion src/IFocusAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void IFocusAnimation::setup(HANDLE pHandle, std::string animationName) {
// hyprfocus_log(LOG, "Setting up focus animation: {}", animationName);
}

void IFocusAnimation::onWindowFocus(CWindow *pWindow, HANDLE pHandle) {
void IFocusAnimation::onWindowFocus(PHLWINDOW pWindow, HANDLE pHandle) {
hyprfocus_log(LOG, "Base callback for animation: {}", m_szAnimationName);
static const auto *inBezier =
(Hyprlang::STRING const *)(HyprlandAPI::getConfigValue(
Expand Down
2 changes: 1 addition & 1 deletion src/IFocusAnimation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class IFocusAnimation {
public:
virtual void onWindowFocus(CWindow *pWindow, HANDLE pHandle);
virtual void onWindowFocus(PHLWINDOW pWindow, HANDLE pHandle);
virtual void init(HANDLE pHandle, std::string animationName);
virtual void setup(HANDLE pHandle, std::string animationName);

Expand Down
2 changes: 1 addition & 1 deletion src/Shrink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void CShrink::setup(HANDLE pHandle, std::string animationName) {
// hyprfocus_log(LOG, "Shrink percentage: {}", g_fShrinkPercentage);
}

void CShrink::onWindowFocus(CWindow *pWindow, HANDLE pHandle) {
void CShrink::onWindowFocus(PHLWINDOW pWindow, HANDLE pHandle) {
std::string currentAnimStyle =
pWindow->m_vRealSize.getConfig()->internalStyle;
hyprfocus_log(LOG, "Current animation style: {}", currentAnimStyle);
Expand Down
2 changes: 1 addition & 1 deletion src/Shrink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class CShrink : public IFocusAnimation {
public:
void onWindowFocus(CWindow *pWindow, HANDLE pHandle) override;
void onWindowFocus(PHLWINDOW pWindow, HANDLE pHandle) override;
void init(HANDLE pHandle, std::string animationName) override;
void setup(HANDLE pHandle, std::string animationName) override;

Expand Down
23 changes: 12 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Log.hpp"
#define WLR_USE_UNSTABLE
#include <hyprland/src/devices/IPointer.hpp>
#include <hyprland/src/helpers/WLClasses.hpp>

#include "Globals.hpp"
#include <hyprland/src/plugins/PluginAPI.hpp>
Expand All @@ -13,13 +14,13 @@
#include "Flash.hpp"
#include "Shrink.hpp"

CWindow *g_pPreviouslyFocusedWindow = nullptr;
PHLWINDOW g_pPreviouslyFocusedWindow = nullptr;
bool g_bMouseWasPressed = false;
bool g_bWorkspaceChanged = false;

std::unordered_map<std::string, std::unique_ptr<IFocusAnimation>> g_mAnimations;

static bool OnSameWorkspace(CWindow *pWindow1, CWindow *pWindow2) {
static bool OnSameWorkspace(PHLWINDOW pWindow1, PHLWINDOW pWindow2) {
if (pWindow1 == pWindow2) {
return true;
} else if (pWindow1 == nullptr || pWindow2 == nullptr) {
Expand All @@ -31,7 +32,7 @@ static bool OnSameWorkspace(CWindow *pWindow1, CWindow *pWindow2) {
}
}

void flashWindow(CWindow *pWindow) {
void flashWindow(PHLWINDOW pWindow) {
// static const Hyprlang::STRING *focusAnimation = nullptr;
// if (g_bMouseWasPressed == true) {
// hyprfocus_log(LOG, "Mouse was pressed");
Expand Down Expand Up @@ -85,7 +86,7 @@ void flashCurrentWindow(std::string) {
static void onActiveWindowChange(void *self, std::any data) {
try {
hyprfocus_log(LOG, "Active window changed");
auto *const PWINDOW = std::any_cast<CWindow *>(data);
auto const PWINDOW = std::any_cast<PHLWINDOW>(data);
static auto *const PHYPRFOCUSENABLED =
(Hyprlang::INT *const *)HyprlandAPI::getConfigValue(
PHANDLE, "plugin:hyprfocus:enabled")
Expand Down Expand Up @@ -141,11 +142,11 @@ static void onActiveWindowChange(void *self, std::any data) {

static void onMouseButton(void *self, std::any data) {
try {
auto *const PWLRMOUSEBUTTONEVENT =
std::any_cast<wlr_pointer_button_event *>(data);
auto const PWLRMOUSEBUTTONEVENT =
std::any_cast<IPointer::SButtonEvent>(data);
hyprfocus_log(LOG, "Mouse button state: {}",
(int)PWLRMOUSEBUTTONEVENT->state);
g_bMouseWasPressed = (int)PWLRMOUSEBUTTONEVENT->state == 1;
(int)PWLRMOUSEBUTTONEVENT.state);
g_bMouseWasPressed = (int)PWLRMOUSEBUTTONEVENT.state == 1;

} catch (std::bad_any_cast &e) {
hyprfocus_log(ERR, "Cast Error: {}", e.what());
Expand Down Expand Up @@ -188,14 +189,14 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
hyprfocus_log(LOG, "Reloaded config");

// Register callbacks
HyprlandAPI::registerCallbackDynamic(
static auto P1 = HyprlandAPI::registerCallbackDynamic(
PHANDLE, "activeWindow",
[&](void *self, SCallbackInfo &info, std::any data) {
onActiveWindowChange(self, data);
});
hyprfocus_log(LOG, "Registered active window change callback");

HyprlandAPI::registerCallbackDynamic(
static auto P2 = HyprlandAPI::registerCallbackDynamic(
PHANDLE, "mouseButton",
[&](void *self, SCallbackInfo &info, std::any data) {
onMouseButton(self, data);
Expand Down

0 comments on commit e66e52b

Please sign in to comment.