From 1ac876ce77c53b78c6d19832705537eb1be3f307 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Mon, 26 Feb 2024 19:36:14 -0600 Subject: [PATCH] sketchybar: cpu mach_helper --- modules/darwin/desktop/addons/sketchybar/default.nix | 2 ++ .../addons/sketchybar/lua-config/items/stats/cpu.lua | 1 + .../desktop/addons/sketchybar/lua-config/sketchybarrc | 3 +++ packages/sketchyhelper/cpu.h | 10 +++++----- packages/sketchyhelper/sketchybarhelper/sketchybar.h | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/darwin/desktop/addons/sketchybar/default.nix b/modules/darwin/desktop/addons/sketchybar/default.nix index 42d57ff87..822896ef2 100644 --- a/modules/darwin/desktop/addons/sketchybar/default.nix +++ b/modules/darwin/desktop/addons/sketchybar/default.nix @@ -39,6 +39,8 @@ in jq lua5_4 wttrbar + pkgs.khanelinix.sketchyhelper + pkgs.khanelinix.dynamic-island-helper ]; # TODO: need to update nixpkg to support complex configurations diff --git a/modules/home/desktop/addons/sketchybar/lua-config/items/stats/cpu.lua b/modules/home/desktop/addons/sketchybar/lua-config/items/stats/cpu.lua index 858417c24..8169faa6b 100644 --- a/modules/home/desktop/addons/sketchybar/lua-config/items/stats/cpu.lua +++ b/modules/home/desktop/addons/sketchybar/lua-config/items/stats/cpu.lua @@ -20,6 +20,7 @@ local cpu = sbar.add("item", "cpu", { color = colors.blue }, update_freq = 2, + mach_helper = "git.felix.sketchyhelper", position = "right" }) diff --git a/modules/home/desktop/addons/sketchybar/lua-config/sketchybarrc b/modules/home/desktop/addons/sketchybar/lua-config/sketchybarrc index 5b70c1bc9..b649ee69e 100755 --- a/modules/home/desktop/addons/sketchybar/lua-config/sketchybarrc +++ b/modules/home/desktop/addons/sketchybar/lua-config/sketchybarrc @@ -9,9 +9,12 @@ os.execute( -- installed into the default search path then this would not be needed) package.cpath = package.cpath .. ";/Users/" .. os.getenv("USER") .. "/.local/share/sketchybar_lua/?.so" + -- Require the sketchybar module sbar = require("sketchybar") +sbar.exec("killall sketchyhelper || sketchyhelper git.felix.sketchyhelper >/dev/null 2>&1 &") + -- Bundle the entire initial configuration into a single message to sketchybar -- This improves startup times drastically, try removing both the begin and end -- config calls to see the difference -- yeah.. diff --git a/packages/sketchyhelper/cpu.h b/packages/sketchyhelper/cpu.h index afb54e458..54793e5f0 100644 --- a/packages/sketchyhelper/cpu.h +++ b/packages/sketchyhelper/cpu.h @@ -90,19 +90,19 @@ static inline void cpu_update(struct cpu *cpu) { char color[16]; if (total_perc >= .7) { - snprintf(color, 16, "%s", getenv("RED")); + snprintf(color, 16, "%s", "0xffed8796"); } else if (total_perc >= .3) { - snprintf(color, 16, "%s", getenv("PEACH")); + snprintf(color, 16, "%s", "0xfff5a97f"); } else if (total_perc >= .1) { - snprintf(color, 16, "%s", getenv("YELLOW")); + snprintf(color, 16, "%s", "0xffeed49f"); } else { - snprintf(color, 16, "%s", getenv("TEXT")); + snprintf(color, 16, "%s", "0xffcad3f5"); } snprintf(cpu->command, 256, // "--push cpu.sys %.2f " // "--push cpu.user %.2f " - "--set cpu.percent label=%.0f%% label.color=%s ", + "--set cpu label=%.0f%% label.color=%s ", // "--set cpu.top label=\"%s\"", // sys_perc, // user_perc, diff --git a/packages/sketchyhelper/sketchybarhelper/sketchybar.h b/packages/sketchyhelper/sketchybarhelper/sketchybar.h index ba95ee69d..1f7d5147e 100644 --- a/packages/sketchyhelper/sketchybarhelper/sketchybar.h +++ b/packages/sketchyhelper/sketchybarhelper/sketchybar.h @@ -83,7 +83,7 @@ static inline void mach_receive_message(mach_port_t port, struct mach_buffer* bu port, 1000, MACH_PORT_NULL ); - else + else msg_return = mach_msg(&buffer->message.header, MACH_RCV_MSG, 0,