diff --git a/flake.lock b/flake.lock index 0356e87..dce26e3 100644 --- a/flake.lock +++ b/flake.lock @@ -9,11 +9,11 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1693851147, - "narHash": "sha256-kkI7FXwKufOmNIIQQHr868tneIV8ggqupBA0EJ/jAuI=", + "lastModified": 1694074808, + "narHash": "sha256-gFHAGWaGh5ZM144wPSYJ6EXam3xmyS2wLwjLhjd7OKU=", "owner": "hyprwm", "repo": "Hyprland", - "rev": "4ddcda93f5887792a953332bf1b487e4b2c3b4ed", + "rev": "0be6b03ee972fcc4921984f3b68469a2ee121511", "type": "github" }, "original": { @@ -49,11 +49,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1693158576, - "narHash": "sha256-aRTTXkYvhXosGx535iAFUaoFboUrZSYb1Ooih/auGp0=", + "lastModified": 1693844670, + "narHash": "sha256-t69F2nBB8DNQUWHD809oJZJVE+23XBrth4QZuVd6IE0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a999c1cc0c9eb2095729d5aa03e0d8f7ed256780", + "rev": "3c15feef7770eb5500a4b8792623e2d6f598c9c1", "type": "github" }, "original": { @@ -118,11 +118,11 @@ ] }, "locked": { - "lastModified": 1691841170, - "narHash": "sha256-RCTm1/MVWYPnReMgyp7tr2ogGYo/pvw38jZaFwemgPU=", + "lastModified": 1694025408, + "narHash": "sha256-oJNhGfZH8Z2w3ztXdzsYVg32//cWEcPVDM3+tp/ZVfU=", "owner": "hyprwm", "repo": "xdg-desktop-portal-hyprland", - "rev": "57a3a41ba6b358109e4fc25c6a4706b5f7d93c6b", + "rev": "022469529c8bc95acf222dc5a62389b04c8b1205", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 34c543b..3be3c6c 100644 --- a/flake.nix +++ b/flake.nix @@ -7,8 +7,10 @@ inherit (hyprland.inputs) nixpkgs; hyprlandSystems = fn: nixpkgs.lib.genAttrs (builtins.attrNames hyprland.packages) (system: fn system nixpkgs.legacyPackages.${system}); in { - packages = hyprlandSystems (system: pkgs: rec { - hy3 = pkgs.stdenv.mkDerivation { + packages = hyprlandSystems (system: pkgs: let + hyprlandPackage = hyprland.packages.${system}.hyprland; + in rec { + hy3 = hyprlandPackage.stdenv.mkDerivation { pname = "hy3"; version = "0.1"; src = ./.; @@ -16,10 +18,10 @@ nativeBuildInputs = with pkgs; [ cmake pkg-config ]; buildInputs = with pkgs; [ - hyprland.packages.${system}.hyprland.dev + hyprlandPackage.dev pango cairo - ] ++ hyprland.packages.${system}.hyprland.buildInputs; + ] ++ hyprlandPackage.buildInputs; # no noticeable impact on performance and greatly assists debugging cmakeBuildType = "Debug"; @@ -37,7 +39,9 @@ }); devShells = hyprlandSystems (system: pkgs: { - default = pkgs.mkShell { + default = pkgs.mkShell.override { + stdenv = pkgs.gcc13Stdenv; + } { name = "hy3"; nativeBuildInputs = with pkgs; [ diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index b51a2f8..5c6a376 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -68,16 +68,21 @@ void Hy3Layout::onWindowCreated(CWindow* window) { } void Hy3Layout::onWindowCreatedTiling(CWindow* window) { + hy3_log( + TRACE, + "onWindowCreatedTiling called with window {:x} (floating: {})", + (uintptr_t) window, + window->m_bIsFloating + ); if (window->m_bIsFloating) return; auto* existing = this->getNodeFromWindow(window); if (existing != nullptr) { - Debug::log( - WARN, - "Attempted to add a window(%p) that is already tiled(as %p) to the " - "layout", - window, - existing + hy3_log( + ERR, + "onWindowCreatedTiling called with a window ({:x}) that is already tiled (node: {:x})", + (uintptr_t) window, + (uintptr_t) existing ); return; } @@ -136,17 +141,17 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window) { } if (opening_into->data.type != Hy3NodeType::Group) { - Debug::log(ERR, "opening_into node %p was not of type Group", opening_into); + hy3_log(ERR, "opening_into node ({:x}) was not a group node", (uintptr_t) opening_into); errorNotif(); return; } if (opening_into->workspace_id != window->m_iWorkspaceID) { - Debug::log( + hy3_log( WARN, - "opening_into node %p has workspace %d which does not match the " - "opening window (workspace %d)", - opening_into, + "opening_into node ({:x}) is on workspace {} which does not match the new window " + "(workspace {})", + (uintptr_t) opening_into, opening_into->workspace_id, window->m_iWorkspaceID ); @@ -198,24 +203,17 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window) { children.insert(iter2, &node); } - Debug::log( + hy3_log( LOG, - "opened new window %p(node: %p) on window %p in %p", - window, - &node, - opening_after, - opening_into + "tiled window ({:x} as node {:x}) after node {:x} in node {:x}", + (uintptr_t) window, + (uintptr_t) &node, + (uintptr_t) opening_after, + (uintptr_t) opening_into ); node.markFocused(); opening_into->recalcSizePosRecursive(); - Debug::log( - LOG, - "opening_into (%p) contains new child (%p)? %d", - opening_into, - &node, - opening_into->data.as_group.hasChild(&node) - ); } void Hy3Layout::onWindowRemovedTiling(CWindow* window) { @@ -223,12 +221,16 @@ void Hy3Layout::onWindowRemovedTiling(CWindow* window) { = &HyprlandAPI::getConfigValue(PHANDLE, "plugin:hy3:node_collapse_policy")->intValue; auto* node = this->getNodeFromWindow(window); - Debug::log(LOG, "remove tiling %p (window %p)", node, window); - if (node == nullptr) { - Debug::log(ERR, "onWindowRemovedTiling node null?"); - return; - } + if (node == nullptr) return; + + hy3_log( + LOG, + "removing window ({:x} as node {:x}) from node {:x}", + (uintptr_t) window, + (uintptr_t) node, + (uintptr_t) node->parent + ); window->m_sSpecialRenderData.rounding = true; window->m_sSpecialRenderData.border = true; @@ -271,10 +273,16 @@ void Hy3Layout::onWindowRemovedTiling(CWindow* window) { } void Hy3Layout::onWindowFocusChange(CWindow* window) { - Debug::log(LOG, "Switched windows to %p", window); auto* node = this->getNodeFromWindow(window); if (node == nullptr) return; + hy3_log( + TRACE, + "changing window focus to window {:x} as node {:x}", + (uintptr_t) window, + (uintptr_t) node + ); + node->markFocused(); while (node->parent != nullptr) node = node->parent; node->recalcSizePosRecursive(); @@ -285,7 +293,7 @@ bool Hy3Layout::isWindowTiled(CWindow* window) { } void Hy3Layout::recalculateMonitor(const int& monitor_id) { - Debug::log(LOG, "Recalculate monitor %d", monitor_id); + hy3_log(LOG, "recalculating monitor {}", monitor_id); const auto monitor = g_pCompositor->getMonitorFromID(monitor_id); if (monitor == nullptr) return; @@ -322,7 +330,6 @@ void Hy3Layout::recalculateMonitor(const int& monitor_id) { int outer_gaps = -(*gaps_in - *gaps_out); auto gap_topleft_offset = Vector2D(outer_gaps, outer_gaps); auto gap_bottomright_offset = Vector2D(outer_gaps, outer_gaps); - Debug::log(LOG, "FS gaps: %d", outer_gaps); Hy3Node fakeNode = { .data = window, @@ -465,8 +472,6 @@ void Hy3Layout::resizeActiveWindow(const Vector2D& delta, eRectCorner corner, CW outer_node = outer_node->parent; } - Debug::log(LOG, "resizeActive - inner_node: %p, outer_node: %p", inner_node, outer_node); - auto& inner_group = inner_parent->data.as_group; // adjust the inner node switch (inner_group.layout) { @@ -610,11 +615,9 @@ void Hy3Layout::fullscreenRequestForWindow( } if (fullscreen_mode == FULLSCREEN_FULL) { - Debug::log(LOG, "fullscreen"); window->m_vRealPosition = monitor->vecPosition; window->m_vRealSize = monitor->vecSize; } else { - Debug::log(LOG, "vaxry hack"); // Copy of vaxry's massive hack // clang-format off @@ -625,7 +628,6 @@ void Hy3Layout::fullscreenRequestForWindow( int outer_gaps = -(*gaps_in - *gaps_out); auto gap_pos_offset = Vector2D(outer_gaps, outer_gaps); auto gap_size_offset = Vector2D(outer_gaps * 2, outer_gaps * 2); - Debug::log(LOG, "FS gaps: %d", outer_gaps); Hy3Node fakeNode = { .data = window, @@ -908,7 +910,6 @@ void Hy3Layout::shiftNode(Hy3Node& node, ShiftDirection direction, bool once, bo void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once, bool visible) { auto* node = this->getWorkspaceFocusedNode(workspace); - Debug::log(LOG, "ShiftWindow %p %d", node, direction); if (node == nullptr) return; this->shiftNode(*node, direction, once, visible); @@ -916,7 +917,6 @@ void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once, void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible) { auto* node = this->getWorkspaceFocusedNode(workspace); - Debug::log(LOG, "ShiftFocus %p %d", node, direction); if (node == nullptr) return; Hy3Node* target; @@ -1389,7 +1389,11 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { } if (monitor == nullptr) { - Debug::log(ERR, "Orphaned Node %x (workspace ID: %i)!!", node, node->workspace_id); + hy3_log( + ERR, + "node {:x}'s workspace has no associated monitor, cannot apply node data", + (uintptr_t) node + ); errorNotif(); return; } @@ -1401,7 +1405,13 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { // clang-format on if (!g_pCompositor->windowExists(window) || !window->m_bIsMapped) { - Debug::log(ERR, "Node %p holding invalid window %p!!", node, window); + hy3_log( + ERR, + "node {:x} is an unmapped window ({:x}), cannot apply node data, removing from tiled " + "layout", + (uintptr_t) node, + (uintptr_t) window + ); errorNotif(); this->onWindowRemovedTiling(window); return; @@ -1448,7 +1458,6 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { window->m_vRealPosition = calcPos; window->m_vRealSize = calcSize; - Debug::log(LOG, "Set size (%f %f)", calcSize.x, calcSize.y); g_pXWaylandManager->setWindowSize(window, calcSize); diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp index 4c44880..2a47b8e 100644 --- a/src/Hy3Node.cpp +++ b/src/Hy3Node.cpp @@ -31,7 +31,6 @@ Hy3GroupData::~Hy3GroupData() { } bool Hy3GroupData::hasChild(Hy3Node* node) { - Debug::log(LOG, "Searching for child %p of %p", this, node); for (auto child: this->children) { if (child == node) return true; @@ -88,13 +87,6 @@ Hy3NodeData::Hy3NodeData(Hy3GroupData group): type(Hy3NodeType::Group) { } Hy3NodeData::Hy3NodeData(Hy3NodeData&& from): type(from.type) { - Debug::log( - LOG, - "Move CTor type matches? %d is group? %d", - this->type == from.type, - this->type == Hy3NodeType::Group - ); - switch (from.type) { case Hy3NodeType::Window: this->as_window = from.as_window; break; case Hy3NodeType::Group: new (&this->as_group) Hy3GroupData(std::move(from.as_group)); break; @@ -126,13 +118,6 @@ Hy3NodeData& Hy3NodeData::operator=(Hy3GroupLayout layout) { } Hy3NodeData& Hy3NodeData::operator=(Hy3NodeData&& from) { - Debug::log( - LOG, - "operator= type matches? %d is group? %d", - this->type == from.type, - this->type == Hy3NodeType::Group - ); - if (this->type == Hy3NodeType::Group) { this->as_group.~Hy3GroupData(); } @@ -235,15 +220,6 @@ Hy3Node* Hy3Node::getFocusedNode(bool ignore_group_focus, bool stop_at_expanded) switch (this->data.type) { case Hy3NodeType::Window: return this; case Hy3NodeType::Group: - Debug::log( - LOG, - "focusing %p, gf: %d, ef: %d (stop: %d)", - this, - this->data.as_group.group_focused, - this->data.as_group.expand_focused, - stop_at_expanded - ); - if (this->data.as_group.focused_child == nullptr || (!ignore_group_focus && this->data.as_group.group_focused) || (stop_at_expanded && this->data.as_group.expand_focused != ExpandFocusType::NotExpanded)) @@ -360,7 +336,12 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) { } if (expanded_node == nullptr) { - Debug::log(ERR, "indiect expand target is missing"); + hy3_log( + ERR, + "recalcSizePosRecursive: unable to find expansion target of latch node {:x}", + (uintptr_t) this + ); + errorNotif(); return; } @@ -673,7 +654,7 @@ std::string Hy3Node::debugNode() { Hy3Node* Hy3Node::removeFromParentRecursive(Hy3Node** expand_actor) { Hy3Node* parent = this; - Debug::log(LOG, "Recursively removing parent nodes of %p", parent); + hy3_log(TRACE, "removing parent nodes of {:x} recursively", (uintptr_t) parent); if (this->parent != nullptr) { auto& actor = this->getExpandActor(); @@ -685,14 +666,7 @@ Hy3Node* Hy3Node::removeFromParentRecursive(Hy3Node** expand_actor) { while (parent != nullptr) { if (parent->parent == nullptr) { - Debug::log(ERR, "* UAF DEBUGGING - %p's parent is null, its the root group", parent); - - if (parent == this) { - Debug::log(ERR, "* UAF DEBUGGING - returning nullptr as this == root group"); - } else { - Debug::log(ERR, "* UAF DEBUGGING - deallocing %p and returning nullptr", parent); - parent->layout->nodes.remove(*parent); - } + if (parent != this) parent->layout->nodes.remove(*parent); return nullptr; } @@ -712,12 +686,12 @@ Hy3Node* Hy3Node::removeFromParentRecursive(Hy3Node** expand_actor) { } if (!group.children.remove(child)) { - Debug::log( + hy3_log( ERR, - "Was unable to remove child node %p from parent %p. Child likely has " - "a false parent pointer.", - child, - parent + "unable to remove child node {:x} from parent node {:x}, child's parent pointer is " + "likely dangling", + (uintptr_t) child, + (uintptr_t) parent ); errorNotif(); @@ -789,7 +763,8 @@ bool Hy3Node::swallowGroups(Hy3Node* into) { // group is wrong. if (into->parent == nullptr && child->data.type != Hy3NodeType::Group) return false; - Debug::log(LOG, "Swallowing %p into %p", child, into); + hy3_log(TRACE, "swallowing node {:x} into node {:x}", (uintptr_t) child, (uintptr_t) into); + Hy3Node::swapData(*into, *child); into->layout->nodes.remove(*child); diff --git a/src/SelectionHook.cpp b/src/SelectionHook.cpp index a99f0b6..29bffc0 100644 --- a/src/SelectionHook.cpp +++ b/src/SelectionHook.cpp @@ -8,7 +8,6 @@ inline CFunctionHook* g_LastSelectionHook = nullptr; void hook_updateDecos(void* thisptr, CWindow* window) { bool explicitly_selected = g_Hy3Layout->shouldRenderSelected(window); - Debug::log(LOG, "update decos for %p - selected: %d", window, explicitly_selected); auto* lastWindow = g_pCompositor->m_pLastWindow; if (explicitly_selected) { @@ -28,12 +27,14 @@ void init() { if (decoUpdateCandidates.size() != 1) { g_LastSelectionHook = nullptr; - Debug::log( + + hy3_log( ERR, - "Expected one matching function to hook for " - "\"updateWindowAnimatedDecorationValues\", found %d", + "expected one matching function to hook for" + "\"updateWindowAnimatedDecorationValues\", found {}", decoUpdateCandidates.size() ); + HyprlandAPI::addNotificationV2( PHANDLE, { diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp index 6d3504a..bbfcc5b 100644 --- a/src/TabGroup.cpp +++ b/src/TabGroup.cpp @@ -449,7 +449,6 @@ Hy3TabGroup::Hy3TabGroup(Hy3Node& node) { } void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) { - Debug::log(LOG, "updated tab bar for %p", &node); static const auto* gaps_in = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_in")->intValue; static const auto* gaps_out = &HyprlandAPI::getConfigValue(PHANDLE, "general:gaps_out")->intValue; static const auto* bar_height diff --git a/src/globals.hpp b/src/globals.hpp index 856f193..87b6296 100644 --- a/src/globals.hpp +++ b/src/globals.hpp @@ -1,4 +1,8 @@ +#pragma once + #include "Hy3Layout.hpp" +#include "log.hpp" + #include inline HANDLE PHANDLE = nullptr; diff --git a/src/log.hpp b/src/log.hpp new file mode 100644 index 0000000..60c30a1 --- /dev/null +++ b/src/log.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +template +void hy3_log(LogLevel level, const std::string& fmt, Args&&... args) { + Debug::log(level, "[hy3] " + fmt, args...); +}