Skip to content

Commit

Permalink
sketchybar: cpu mach_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Feb 27, 2024
1 parent 0a7e9c3 commit 1ac876c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions modules/darwin/desktop/addons/sketchybar/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ local cpu = sbar.add("item", "cpu", {
color = colors.blue
},
update_freq = 2,
mach_helper = "git.felix.sketchyhelper",
position = "right"
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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..
Expand Down
10 changes: 5 additions & 5 deletions packages/sketchyhelper/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/sketchyhelper/sketchybarhelper/sketchybar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1ac876c

Please sign in to comment.