From 0812c3680f054f5b1e2e92d58ff3e7befd0d0134 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Thu, 7 Sep 2023 17:24:41 +0200 Subject: [PATCH] Add option for sensor tooltips instead of sliders Partially implements https://github.com/scorpion-26/gBar/issues/48 --- data/config | 3 ++ module.nix | 5 ++ src/Bar.cpp | 142 +++++++++++++++++++++++++++++++++++-------------- src/Config.cpp | 1 + src/Config.h | 1 + 5 files changed, 112 insertions(+), 40 deletions(-) diff --git a/data/config b/data/config index 66e07cd..848b8e4 100644 --- a/data/config +++ b/data/config @@ -101,6 +101,9 @@ NetworkAdapter: eno1 # Disables the network widget when set to false NetworkWidget: true +# Use tooltips instead of sliders for the sensors +SensorTooltips: false + # Enables tray icons EnableSNI: true diff --git a/module.nix b/module.nix index fd55eca..beda1fb 100644 --- a/module.nix +++ b/module.nix @@ -163,6 +163,11 @@ in { default = true; description = "Disables the network widget when set to false"; }; + SensorTooltips = mkOption { + type = types.bool; + default = true; + description = "Use tooltips instead of sliders for the sensors"; + }; EnableSNI = mkOption { type = types.bool; default = true; diff --git a/src/Bar.cpp b/src/Bar.cpp index f33e977..208631a 100644 --- a/src/Bar.cpp +++ b/src/Bar.cpp @@ -28,7 +28,15 @@ namespace Bar double usage = System::GetCPUUsage(); double temp = System::GetCPUTemp(); - cpuText->SetText("CPU: " + Utils::ToStringPrecision(usage * 100, "%0.1f") + "% " + Utils::ToStringPrecision(temp, "%0.1f") + "°C"); + std::string text = "CPU: " + Utils::ToStringPrecision(usage * 100, "%0.1f") + "% " + Utils::ToStringPrecision(temp, "%0.1f") + "°C"; + if (Config::Get().sensorTooltips) + { + sensor.SetTooltip(text); + } + else + { + cpuText->SetText(text); + } sensor.SetValue(usage); return TimerResult::Ok; } @@ -38,7 +46,15 @@ namespace Bar { double percentage = System::GetBatteryPercentage(); - batteryText->SetText("Battery: " + Utils::ToStringPrecision(percentage * 100, "%0.1f") + "%"); + std::string text = "Battery: " + Utils::ToStringPrecision(percentage * 100, "%0.1f") + "%"; + if (Config::Get().sensorTooltips) + { + sensor.SetTooltip(text); + } + else + { + batteryText->SetText(text); + } sensor.SetValue(percentage); return TimerResult::Ok; } @@ -50,7 +66,15 @@ namespace Bar double used = info.totalGiB - info.freeGiB; double usedPercent = used / info.totalGiB; - ramText->SetText("RAM: " + Utils::ToStringPrecision(used, "%0.2f") + "GiB/" + Utils::ToStringPrecision(info.totalGiB, "%0.2f") + "GiB"); + std::string text = "RAM: " + Utils::ToStringPrecision(used, "%0.2f") + "GiB/" + Utils::ToStringPrecision(info.totalGiB, "%0.2f") + "GiB"; + if (Config::Get().sensorTooltips) + { + sensor.SetTooltip(text); + } + else + { + ramText->SetText(text); + } sensor.SetValue(usedPercent); return TimerResult::Ok; } @@ -61,8 +85,16 @@ namespace Bar { System::GPUInfo info = System::GetGPUInfo(); - gpuText->SetText("GPU: " + Utils::ToStringPrecision(info.utilisation, "%0.1f") + "% " + Utils::ToStringPrecision(info.coreTemp, "%0.1f") + - "°C"); + std::string text = "GPU: " + Utils::ToStringPrecision(info.utilisation, "%0.1f") + "% " + + Utils::ToStringPrecision(info.coreTemp, "%0.1f") + "°C"; + if (Config::Get().sensorTooltips) + { + sensor.SetTooltip(text); + } + else + { + gpuText->SetText(text); + } sensor.SetValue(info.utilisation / 100); return TimerResult::Ok; } @@ -72,8 +104,16 @@ namespace Bar { System::VRAMInfo info = System::GetVRAMInfo(); - vramText->SetText("VRAM: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" + Utils::ToStringPrecision(info.totalGiB, "%0.2f") + - "GiB"); + std::string text = "VRAM: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" + + Utils::ToStringPrecision(info.totalGiB, "%0.2f") + "GiB"; + if (Config::Get().sensorTooltips) + { + sensor.SetTooltip(text); + } + else + { + vramText->SetText(text); + } sensor.SetValue(info.usedGiB / info.totalGiB); return TimerResult::Ok; } @@ -84,8 +124,16 @@ namespace Bar { System::DiskInfo info = System::GetDiskInfo(); - diskText->SetText("Disk: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" + Utils::ToStringPrecision(info.totalGiB, "%0.2f") + - "GiB"); + std::string text = "Disk: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" + + Utils::ToStringPrecision(info.totalGiB, "%0.2f") + "GiB"; + if (Config::Get().sensorTooltips) + { + sensor.SetTooltip(text); + } + else + { + diskText->SetText(text); + } sensor.SetValue(info.usedGiB / info.totalGiB); return TimerResult::Ok; } @@ -246,7 +294,15 @@ namespace Bar std::string upload = Utils::StorageUnitDynamic(bpsUp, "%0.1f%s"); std::string download = Utils::StorageUnitDynamic(bpsDown, "%0.1f%s"); - networkText->SetText(Config::Get().networkAdapter + ": " + upload + " Up/" + download + " Down"); + std::string text = Config::Get().networkAdapter + ": " + upload + " Up/" + download + " Down"; + if (Config::Get().sensorTooltips) + { + sensor.SetTooltip(text); + } + else + { + networkText->SetText(Config::Get().networkAdapter + ": " + upload + " Up/" + download + " Down"); + } sensor.SetUp(bpsUp); sensor.SetDown(bpsDown); @@ -311,21 +367,25 @@ namespace Bar Utils::SetTransform(*box, {-1, true, Alignment::Right}); box->SetOrientation(Utils::GetOrientation()); { - auto revealer = Widget::Create(); - revealer->SetTransition({Utils::GetTransitionType(), 500}); - // Add event to eventbox for the revealer to open - eventBox->SetHoverFn( - [textRevealer = revealer.get()](EventBox&, bool hovered) - { - textRevealer->SetRevealed(hovered); - }); + if (!Config::Get().sensorTooltips) { - auto text = Widget::Create(); - text->SetClass(textClass); - text->SetAngle(Utils::GetAngle()); - Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); - textPtr = text.get(); - revealer->AddChild(std::move(text)); + auto revealer = Widget::Create(); + revealer->SetTransition({Utils::GetTransitionType(), 500}); + // Add event to eventbox for the revealer to open + eventBox->SetHoverFn( + [textRevealer = revealer.get()](EventBox&, bool hovered) + { + textRevealer->SetRevealed(hovered); + }); + { + auto text = Widget::Create(); + text->SetClass(textClass); + text->SetAngle(Utils::GetAngle()); + Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); + textPtr = text.get(); + revealer->AddChild(std::move(text)); + } + box->AddChild(std::move(revealer)); } auto sensor = Widget::Create(); @@ -342,7 +402,6 @@ namespace Bar sensor->AddTimer(std::move(callback), DynCtx::updateTime); Utils::SetTransform(*sensor, {24, true, Alignment::Fill}); - box->AddChild(std::move(revealer)); box->AddChild(std::move(sensor)); } eventBox->AddChild(std::move(box)); @@ -543,21 +602,25 @@ namespace Bar Utils::SetTransform(*box, {-1, true, Alignment::Right}); box->SetOrientation(Utils::GetOrientation()); { - auto revealer = Widget::Create(); - revealer->SetTransition({Utils::GetTransitionType(), 500}); - // Add event to eventbox for the revealer to open - eventBox->SetHoverFn( - [textRevealer = revealer.get()](EventBox&, bool hovered) - { - textRevealer->SetRevealed(hovered); - }); + if (!Config::Get().sensorTooltips) { - auto text = Widget::Create(); - text->SetClass("network-data-text"); - text->SetAngle(Utils::GetAngle()); - Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); - DynCtx::networkText = text.get(); - revealer->AddChild(std::move(text)); + auto revealer = Widget::Create(); + revealer->SetTransition({Utils::GetTransitionType(), 500}); + // Add event to eventbox for the revealer to open + eventBox->SetHoverFn( + [textRevealer = revealer.get()](EventBox&, bool hovered) + { + textRevealer->SetRevealed(hovered); + }); + { + auto text = Widget::Create(); + text->SetClass("network-data-text"); + text->SetAngle(Utils::GetAngle()); + Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); + DynCtx::networkText = text.get(); + revealer->AddChild(std::move(text)); + } + box->AddChild(std::move(revealer)); } auto sensor = Widget::Create(); @@ -567,7 +630,6 @@ namespace Bar sensor->AddTimer(DynCtx::UpdateNetwork, DynCtx::updateTime); Utils::SetTransform(*sensor, {24, true, Alignment::Fill}); - box->AddChild(std::move(revealer)); box->AddChild(std::move(sensor)); } eventBox->AddChild(std::move(box)); diff --git a/src/Config.cpp b/src/Config.cpp index 54ad8b2..85b0e05 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -204,6 +204,7 @@ void Config::Load() AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty); AddConfigVar("UseHyprlandIPC", config.useHyprlandIPC, lineView, foundProperty); AddConfigVar("EnableSNI", config.enableSNI, lineView, foundProperty); + AddConfigVar("SensorTooltips", config.sensorTooltips, lineView, foundProperty); AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty); AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty); diff --git a/src/Config.h b/src/Config.h index d3d4edb..3800e32 100644 --- a/src/Config.h +++ b/src/Config.h @@ -33,6 +33,7 @@ public: bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1 bool useHyprlandIPC = true; // Use Hyprland IPC instead of ext_workspaces protocol (Less buggy, but also less performant) bool enableSNI = true; // Enable tray icon + bool sensorTooltips = false; // Use tooltips instead of sliders for the sensors // Controls for color progression of the network widget uint32_t minUploadBytes = 0; // Bottom limit of the network widgets upload. Everything below it is considered "under"