Add option for sensor tooltips instead of sliders

Partially implements https://github.com/scorpion-26/gBar/issues/48
This commit is contained in:
scorpion-26 2023-09-07 17:24:41 +02:00
parent d811b14767
commit 0812c3680f
5 changed files with 112 additions and 40 deletions

View file

@ -101,6 +101,9 @@ NetworkAdapter: eno1
# Disables the network widget when set to false # Disables the network widget when set to false
NetworkWidget: true NetworkWidget: true
# Use tooltips instead of sliders for the sensors
SensorTooltips: false
# Enables tray icons # Enables tray icons
EnableSNI: true EnableSNI: true

View file

@ -163,6 +163,11 @@ in {
default = true; default = true;
description = "Disables the network widget when set to false"; 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 { EnableSNI = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;

View file

@ -28,7 +28,15 @@ namespace Bar
double usage = System::GetCPUUsage(); double usage = System::GetCPUUsage();
double temp = System::GetCPUTemp(); 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); sensor.SetValue(usage);
return TimerResult::Ok; return TimerResult::Ok;
} }
@ -38,7 +46,15 @@ namespace Bar
{ {
double percentage = System::GetBatteryPercentage(); 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); sensor.SetValue(percentage);
return TimerResult::Ok; return TimerResult::Ok;
} }
@ -50,7 +66,15 @@ namespace Bar
double used = info.totalGiB - info.freeGiB; double used = info.totalGiB - info.freeGiB;
double usedPercent = used / info.totalGiB; 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); sensor.SetValue(usedPercent);
return TimerResult::Ok; return TimerResult::Ok;
} }
@ -61,8 +85,16 @@ namespace Bar
{ {
System::GPUInfo info = System::GetGPUInfo(); System::GPUInfo info = System::GetGPUInfo();
gpuText->SetText("GPU: " + Utils::ToStringPrecision(info.utilisation, "%0.1f") + "% " + Utils::ToStringPrecision(info.coreTemp, "%0.1f") + std::string text = "GPU: " + Utils::ToStringPrecision(info.utilisation, "%0.1f") + "% " +
"°C"); Utils::ToStringPrecision(info.coreTemp, "%0.1f") + "°C";
if (Config::Get().sensorTooltips)
{
sensor.SetTooltip(text);
}
else
{
gpuText->SetText(text);
}
sensor.SetValue(info.utilisation / 100); sensor.SetValue(info.utilisation / 100);
return TimerResult::Ok; return TimerResult::Ok;
} }
@ -72,8 +104,16 @@ namespace Bar
{ {
System::VRAMInfo info = System::GetVRAMInfo(); System::VRAMInfo info = System::GetVRAMInfo();
vramText->SetText("VRAM: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" + Utils::ToStringPrecision(info.totalGiB, "%0.2f") + std::string text = "VRAM: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" +
"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); sensor.SetValue(info.usedGiB / info.totalGiB);
return TimerResult::Ok; return TimerResult::Ok;
} }
@ -84,8 +124,16 @@ namespace Bar
{ {
System::DiskInfo info = System::GetDiskInfo(); System::DiskInfo info = System::GetDiskInfo();
diskText->SetText("Disk: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" + Utils::ToStringPrecision(info.totalGiB, "%0.2f") + std::string text = "Disk: " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" +
"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); sensor.SetValue(info.usedGiB / info.totalGiB);
return TimerResult::Ok; return TimerResult::Ok;
} }
@ -246,7 +294,15 @@ namespace Bar
std::string upload = Utils::StorageUnitDynamic(bpsUp, "%0.1f%s"); std::string upload = Utils::StorageUnitDynamic(bpsUp, "%0.1f%s");
std::string download = Utils::StorageUnitDynamic(bpsDown, "%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.SetUp(bpsUp);
sensor.SetDown(bpsDown); sensor.SetDown(bpsDown);
@ -311,21 +367,25 @@ namespace Bar
Utils::SetTransform(*box, {-1, true, Alignment::Right}); Utils::SetTransform(*box, {-1, true, Alignment::Right});
box->SetOrientation(Utils::GetOrientation()); box->SetOrientation(Utils::GetOrientation());
{ {
auto revealer = Widget::Create<Revealer>(); if (!Config::Get().sensorTooltips)
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>(); auto revealer = Widget::Create<Revealer>();
text->SetClass(textClass); revealer->SetTransition({Utils::GetTransitionType(), 500});
text->SetAngle(Utils::GetAngle()); // Add event to eventbox for the revealer to open
Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); eventBox->SetHoverFn(
textPtr = text.get(); [textRevealer = revealer.get()](EventBox&, bool hovered)
revealer->AddChild(std::move(text)); {
textRevealer->SetRevealed(hovered);
});
{
auto text = Widget::Create<Text>();
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<Sensor>(); auto sensor = Widget::Create<Sensor>();
@ -342,7 +402,6 @@ namespace Bar
sensor->AddTimer<Sensor>(std::move(callback), DynCtx::updateTime); sensor->AddTimer<Sensor>(std::move(callback), DynCtx::updateTime);
Utils::SetTransform(*sensor, {24, true, Alignment::Fill}); Utils::SetTransform(*sensor, {24, true, Alignment::Fill});
box->AddChild(std::move(revealer));
box->AddChild(std::move(sensor)); box->AddChild(std::move(sensor));
} }
eventBox->AddChild(std::move(box)); eventBox->AddChild(std::move(box));
@ -543,21 +602,25 @@ namespace Bar
Utils::SetTransform(*box, {-1, true, Alignment::Right}); Utils::SetTransform(*box, {-1, true, Alignment::Right});
box->SetOrientation(Utils::GetOrientation()); box->SetOrientation(Utils::GetOrientation());
{ {
auto revealer = Widget::Create<Revealer>(); if (!Config::Get().sensorTooltips)
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>(); auto revealer = Widget::Create<Revealer>();
text->SetClass("network-data-text"); revealer->SetTransition({Utils::GetTransitionType(), 500});
text->SetAngle(Utils::GetAngle()); // Add event to eventbox for the revealer to open
Utils::SetTransform(*text, {-1, true, Alignment::Fill, 0, 6}); eventBox->SetHoverFn(
DynCtx::networkText = text.get(); [textRevealer = revealer.get()](EventBox&, bool hovered)
revealer->AddChild(std::move(text)); {
textRevealer->SetRevealed(hovered);
});
{
auto text = Widget::Create<Text>();
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<NetworkSensor>(); auto sensor = Widget::Create<NetworkSensor>();
@ -567,7 +630,6 @@ namespace Bar
sensor->AddTimer<NetworkSensor>(DynCtx::UpdateNetwork, DynCtx::updateTime); sensor->AddTimer<NetworkSensor>(DynCtx::UpdateNetwork, DynCtx::updateTime);
Utils::SetTransform(*sensor, {24, true, Alignment::Fill}); Utils::SetTransform(*sensor, {24, true, Alignment::Fill});
box->AddChild(std::move(revealer));
box->AddChild(std::move(sensor)); box->AddChild(std::move(sensor));
} }
eventBox->AddChild(std::move(box)); eventBox->AddChild(std::move(box));

View file

@ -204,6 +204,7 @@ void Config::Load()
AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty); AddConfigVar("WorkspaceScrollInvert", config.workspaceScrollInvert, lineView, foundProperty);
AddConfigVar("UseHyprlandIPC", config.useHyprlandIPC, lineView, foundProperty); AddConfigVar("UseHyprlandIPC", config.useHyprlandIPC, lineView, foundProperty);
AddConfigVar("EnableSNI", config.enableSNI, lineView, foundProperty); AddConfigVar("EnableSNI", config.enableSNI, lineView, foundProperty);
AddConfigVar("SensorTooltips", config.sensorTooltips, lineView, foundProperty);
AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty); AddConfigVar("MinUploadBytes", config.minUploadBytes, lineView, foundProperty);
AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty); AddConfigVar("MaxUploadBytes", config.maxUploadBytes, lineView, foundProperty);

View file

@ -33,6 +33,7 @@ public:
bool workspaceScrollInvert = false; // Up = +1, instead of Up = -1 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 useHyprlandIPC = true; // Use Hyprland IPC instead of ext_workspaces protocol (Less buggy, but also less performant)
bool enableSNI = true; // Enable tray icon 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 // 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" uint32_t minUploadBytes = 0; // Bottom limit of the network widgets upload. Everything below it is considered "under"