2023-01-13 15:13:56 +00:00
|
|
|
#include "Bar.h"
|
|
|
|
|
|
|
|
#include "System.h"
|
|
|
|
#include "Common.h"
|
2023-01-29 20:31:00 +00:00
|
|
|
#include "Config.h"
|
2023-03-17 23:02:40 +00:00
|
|
|
#include "SNI.h"
|
2023-07-18 23:07:32 +00:00
|
|
|
#include <cmath>
|
2023-05-03 16:37:36 +00:00
|
|
|
#include <mutex>
|
2023-01-13 15:13:56 +00:00
|
|
|
|
|
|
|
namespace Bar
|
|
|
|
{
|
2023-10-31 23:34:33 +00:00
|
|
|
enum Side
|
|
|
|
{
|
|
|
|
Left,
|
|
|
|
Right,
|
|
|
|
Center
|
|
|
|
};
|
|
|
|
|
|
|
|
Alignment SideToAlignment(Side side)
|
|
|
|
{
|
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case Left: return Alignment::Left;
|
|
|
|
case Right: return Alignment::Right;
|
|
|
|
case Center: return Alignment::Fill;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TransitionType SideToDefaultTransition(Side side)
|
|
|
|
{
|
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case Right:
|
|
|
|
case Center: return TransitionType::SlideLeft;
|
|
|
|
case Left: return TransitionType::SlideRight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RotatedIcons()
|
|
|
|
{
|
|
|
|
return (Config::Get().location == 'L' || Config::Get().location == 'R') && Config::Get().iconsAlwaysUp;
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
static int32_t monitorID;
|
|
|
|
|
|
|
|
namespace DynCtx
|
|
|
|
{
|
|
|
|
constexpr uint32_t updateTime = 1000;
|
|
|
|
constexpr uint32_t updateTimeFast = 100;
|
|
|
|
|
|
|
|
static Revealer* powerBoxRevealer;
|
|
|
|
static void PowerBoxEvent(EventBox&, bool hovered)
|
|
|
|
{
|
|
|
|
powerBoxRevealer->SetRevealed(hovered);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Text* cpuText;
|
2023-02-04 15:09:08 +00:00
|
|
|
static TimerResult UpdateCPU(Sensor& sensor)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
double usage = System::GetCPUUsage();
|
|
|
|
double temp = System::GetCPUTemp();
|
|
|
|
|
2023-09-07 15:24:41 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
sensor.SetValue(usage);
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
2023-01-28 22:47:55 +00:00
|
|
|
static Text* batteryText;
|
2023-10-28 21:29:27 +00:00
|
|
|
static bool wasCharging = false;
|
2023-02-04 15:09:08 +00:00
|
|
|
static TimerResult UpdateBattery(Sensor& sensor)
|
2023-01-28 22:47:55 +00:00
|
|
|
{
|
|
|
|
double percentage = System::GetBatteryPercentage();
|
|
|
|
|
2023-09-07 15:24:41 +00:00
|
|
|
std::string text = "Battery: " + Utils::ToStringPrecision(percentage * 100, "%0.1f") + "%";
|
|
|
|
if (Config::Get().sensorTooltips)
|
|
|
|
{
|
|
|
|
sensor.SetTooltip(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
batteryText->SetText(text);
|
|
|
|
}
|
2023-01-28 22:47:55 +00:00
|
|
|
sensor.SetValue(percentage);
|
2023-10-28 21:29:27 +00:00
|
|
|
|
|
|
|
bool isCharging = System::IsBatteryCharging();
|
|
|
|
if (isCharging && !wasCharging && sensor.Get() != nullptr)
|
|
|
|
{
|
|
|
|
sensor.AddClass("battery-charging");
|
|
|
|
batteryText->AddClass("battery-charging");
|
|
|
|
wasCharging = true;
|
|
|
|
}
|
|
|
|
else if (!isCharging && wasCharging)
|
|
|
|
{
|
|
|
|
sensor.RemoveClass("battery-charging");
|
|
|
|
batteryText->RemoveClass("battery-charging");
|
|
|
|
wasCharging = false;
|
|
|
|
}
|
2023-01-28 22:47:55 +00:00
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
static Text* ramText;
|
2023-02-04 15:09:08 +00:00
|
|
|
static TimerResult UpdateRAM(Sensor& sensor)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
System::RAMInfo info = System::GetRAMInfo();
|
|
|
|
double used = info.totalGiB - info.freeGiB;
|
|
|
|
double usedPercent = used / info.totalGiB;
|
|
|
|
|
2023-09-07 15:24:41 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
sensor.SetValue(usedPercent);
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
2023-01-30 16:23:28 +00:00
|
|
|
#if defined WITH_NVIDIA || defined WITH_AMD
|
2023-01-13 15:13:56 +00:00
|
|
|
static Text* gpuText;
|
2023-02-04 15:09:08 +00:00
|
|
|
static TimerResult UpdateGPU(Sensor& sensor)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
System::GPUInfo info = System::GetGPUInfo();
|
|
|
|
|
2023-09-07 15:24:41 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
sensor.SetValue(info.utilisation / 100);
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Text* vramText;
|
2023-02-04 15:09:08 +00:00
|
|
|
static TimerResult UpdateVRAM(Sensor& sensor)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
System::VRAMInfo info = System::GetVRAMInfo();
|
|
|
|
|
2023-09-07 15:24:41 +00:00
|
|
|
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);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
sensor.SetValue(info.usedGiB / info.totalGiB);
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static Text* diskText;
|
2023-02-04 15:09:08 +00:00
|
|
|
static TimerResult UpdateDisk(Sensor& sensor)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
System::DiskInfo info = System::GetDiskInfo();
|
|
|
|
|
2023-09-08 14:34:17 +00:00
|
|
|
std::string text = "Disk " + info.partition + ": " + Utils::ToStringPrecision(info.usedGiB, "%0.2f") + "GiB/" +
|
2023-09-07 15:24:41 +00:00
|
|
|
Utils::ToStringPrecision(info.totalGiB, "%0.2f") + "GiB";
|
|
|
|
if (Config::Get().sensorTooltips)
|
|
|
|
{
|
|
|
|
sensor.SetTooltip(text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
diskText->SetText(text);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
sensor.SetValue(info.usedGiB / info.totalGiB);
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
2023-01-30 15:57:15 +00:00
|
|
|
#ifdef WITH_BLUEZ
|
2023-01-14 22:18:34 +00:00
|
|
|
static Button* btIconText;
|
2023-01-13 15:13:56 +00:00
|
|
|
static Text* btDevText;
|
|
|
|
static TimerResult UpdateBluetooth(Box&)
|
|
|
|
{
|
|
|
|
System::BluetoothInfo info = System::GetBluetoothInfo();
|
|
|
|
if (info.defaultController.empty())
|
|
|
|
{
|
|
|
|
btIconText->SetClass("bt-label-off");
|
2023-05-04 21:25:57 +00:00
|
|
|
btIconText->SetText("");
|
2023-01-13 15:13:56 +00:00
|
|
|
btDevText->SetText("");
|
|
|
|
}
|
|
|
|
else if (info.devices.empty())
|
|
|
|
{
|
|
|
|
btIconText->SetClass("bt-label-on");
|
2023-05-03 21:21:21 +00:00
|
|
|
btIconText->SetText("");
|
2023-01-13 15:13:56 +00:00
|
|
|
btDevText->SetText("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
btIconText->SetClass("bt-label-connected");
|
2023-05-03 21:21:21 +00:00
|
|
|
btIconText->SetText("");
|
2023-01-13 15:13:56 +00:00
|
|
|
std::string btDev;
|
2023-01-14 13:47:30 +00:00
|
|
|
std::string tooltip;
|
2023-01-13 15:13:56 +00:00
|
|
|
for (auto& dev : info.devices)
|
|
|
|
{
|
2023-01-14 22:18:34 +00:00
|
|
|
if (!dev.connected)
|
|
|
|
continue;
|
2023-01-15 10:09:06 +00:00
|
|
|
std::string ico = System::BTTypeToIcon(dev);
|
2023-01-14 13:47:30 +00:00
|
|
|
tooltip += dev.name + " & ";
|
2023-01-13 15:13:56 +00:00
|
|
|
btDev += ico;
|
2023-10-31 23:34:33 +00:00
|
|
|
|
|
|
|
if (RotatedIcons())
|
|
|
|
{
|
|
|
|
btDev += "\n";
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
2023-01-14 13:47:30 +00:00
|
|
|
// Delete last delim
|
|
|
|
if (tooltip.size())
|
|
|
|
tooltip.erase(tooltip.end() - 3, tooltip.end());
|
2023-10-31 23:34:33 +00:00
|
|
|
if (btDev.size() && btDev.back() == '\n')
|
|
|
|
btDev.erase(btDev.end() - 1);
|
|
|
|
|
2023-01-14 13:47:30 +00:00
|
|
|
btDevText->SetTooltip(tooltip);
|
2023-01-13 15:13:56 +00:00
|
|
|
btDevText->SetText(std::move(btDev));
|
|
|
|
}
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
2023-01-14 22:18:34 +00:00
|
|
|
|
|
|
|
void OnBTClick(Button&)
|
|
|
|
{
|
|
|
|
System::OpenBTWidget();
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
#endif
|
|
|
|
|
2023-05-03 16:37:36 +00:00
|
|
|
static std::mutex packageTextLock;
|
|
|
|
static TimerResult UpdatePackages(Text& text)
|
|
|
|
{
|
|
|
|
System::GetOutdatedPackagesAsync(
|
|
|
|
[&](uint32_t numOutdatedPackages)
|
|
|
|
{
|
|
|
|
packageTextLock.lock();
|
|
|
|
if (numOutdatedPackages)
|
|
|
|
{
|
|
|
|
text.SetText(" ");
|
2023-05-03 17:02:26 +00:00
|
|
|
text.SetVisible(true);
|
2023-05-03 16:37:36 +00:00
|
|
|
text.SetClass("package-outofdate");
|
|
|
|
text.SetTooltip("Updates available! (" + std::to_string(numOutdatedPackages) + " packages)");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text.SetText("");
|
2023-05-03 17:02:26 +00:00
|
|
|
text.SetVisible(false);
|
2023-05-03 16:37:36 +00:00
|
|
|
text.SetClass("package-empty");
|
|
|
|
text.SetTooltip("");
|
|
|
|
}
|
|
|
|
packageTextLock.unlock();
|
|
|
|
});
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
2023-08-21 16:19:46 +00:00
|
|
|
Widget* audioSlider;
|
|
|
|
Widget* micSlider;
|
|
|
|
Text* audioIcon;
|
|
|
|
Text* micIcon;
|
2023-02-22 15:45:29 +00:00
|
|
|
void OnChangeVolumeSink(Slider&, double value)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-02-22 15:45:29 +00:00
|
|
|
System::SetVolumeSink(value);
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 15:45:29 +00:00
|
|
|
void OnChangeVolumeSource(Slider&, double value)
|
|
|
|
{
|
|
|
|
System::SetVolumeSource(value);
|
|
|
|
}
|
|
|
|
|
2023-08-21 16:19:46 +00:00
|
|
|
// For text
|
|
|
|
double audioVolume = 0;
|
|
|
|
void OnChangeVolumeSinkDelta(double delta)
|
|
|
|
{
|
|
|
|
audioVolume += delta;
|
|
|
|
audioVolume = std::clamp(audioVolume, 0.0, 1.0);
|
|
|
|
System::SetVolumeSink(audioVolume);
|
|
|
|
}
|
|
|
|
|
|
|
|
double micVolume = 0;
|
|
|
|
void OnChangeVolumeSourceDelta(double delta)
|
|
|
|
{
|
|
|
|
micVolume += delta;
|
|
|
|
micVolume = std::clamp(micVolume, 0.0, 1.0);
|
|
|
|
System::SetVolumeSource(micVolume);
|
|
|
|
}
|
|
|
|
|
2023-02-22 15:45:29 +00:00
|
|
|
TimerResult UpdateAudio(Widget&)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
System::AudioInfo info = System::GetAudioInfo();
|
2023-08-21 16:19:46 +00:00
|
|
|
if (Config::Get().audioNumbers)
|
|
|
|
{
|
|
|
|
audioVolume = info.sinkVolume;
|
|
|
|
((Text*)audioSlider)->SetText(Utils::ToStringPrecision(info.sinkVolume * 100, "%0.0f") + "%");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((Slider*)audioSlider)->SetValue(info.sinkVolume);
|
|
|
|
}
|
2023-02-22 15:45:29 +00:00
|
|
|
if (info.sinkMuted)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-02-22 15:45:29 +00:00
|
|
|
audioIcon->SetText("");
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-22 15:45:29 +00:00
|
|
|
audioIcon->SetText("");
|
|
|
|
}
|
|
|
|
if (Config::Get().audioInput)
|
|
|
|
{
|
2023-08-21 16:19:46 +00:00
|
|
|
if (Config::Get().audioNumbers)
|
|
|
|
{
|
|
|
|
micVolume = info.sourceVolume;
|
|
|
|
((Text*)micSlider)->SetText(Utils::ToStringPrecision(info.sourceVolume * 100, "%0.0f") + "%");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((Slider*)micSlider)->SetValue(info.sinkVolume);
|
|
|
|
}
|
2023-02-22 15:45:29 +00:00
|
|
|
if (info.sourceMuted)
|
|
|
|
{
|
|
|
|
micIcon->SetText("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
micIcon->SetText("");
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
2023-02-10 16:20:26 +00:00
|
|
|
Text* networkText;
|
|
|
|
TimerResult UpdateNetwork(NetworkSensor& sensor)
|
|
|
|
{
|
|
|
|
double bpsUp = System::GetNetworkBpsUpload(updateTime / 1000.0);
|
|
|
|
double bpsDown = System::GetNetworkBpsDownload(updateTime / 1000.0);
|
|
|
|
|
|
|
|
std::string upload = Utils::StorageUnitDynamic(bpsUp, "%0.1f%s");
|
|
|
|
std::string download = Utils::StorageUnitDynamic(bpsDown, "%0.1f%s");
|
|
|
|
|
2023-09-07 15:24:41 +00:00
|
|
|
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");
|
|
|
|
}
|
2023-02-10 16:20:26 +00:00
|
|
|
|
|
|
|
sensor.SetUp(bpsUp);
|
|
|
|
sensor.SetDown(bpsDown);
|
|
|
|
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
TimerResult UpdateTime(Text& text)
|
|
|
|
{
|
|
|
|
text.SetText(System::GetTime());
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
|
|
|
|
2023-03-03 19:44:51 +00:00
|
|
|
#ifdef WITH_WORKSPACES
|
2023-09-01 22:05:08 +00:00
|
|
|
static std::vector<Button*> workspaces;
|
2023-01-13 15:13:56 +00:00
|
|
|
TimerResult UpdateWorkspaces(Box&)
|
|
|
|
{
|
2023-02-24 12:23:34 +00:00
|
|
|
System::PollWorkspaces((uint32_t)monitorID, workspaces.size());
|
2023-01-13 15:13:56 +00:00
|
|
|
for (size_t i = 0; i < workspaces.size(); i++)
|
|
|
|
{
|
2023-02-24 12:23:34 +00:00
|
|
|
switch (System::GetWorkspaceStatus(i + 1))
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-01-30 15:57:15 +00:00
|
|
|
case System::WorkspaceStatus::Dead: workspaces[i]->SetClass("ws-dead"); break;
|
|
|
|
case System::WorkspaceStatus::Inactive: workspaces[i]->SetClass("ws-inactive"); break;
|
|
|
|
case System::WorkspaceStatus::Visible: workspaces[i]->SetClass("ws-visible"); break;
|
|
|
|
case System::WorkspaceStatus::Current: workspaces[i]->SetClass("ws-current"); break;
|
|
|
|
case System::WorkspaceStatus::Active: workspaces[i]->SetClass("ws-active"); break;
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
2023-01-29 11:07:24 +00:00
|
|
|
workspaces[i]->SetText(System::GetWorkspaceSymbol(i));
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
return TimerResult::Ok;
|
|
|
|
}
|
2023-02-12 13:57:32 +00:00
|
|
|
|
|
|
|
void ScrollWorkspaces(EventBox&, ScrollDirection direction)
|
|
|
|
{
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case ScrollDirection::Up:
|
|
|
|
if (Config::Get().workspaceScrollInvert)
|
|
|
|
System::GotoNextWorkspace('+');
|
|
|
|
else
|
|
|
|
System::GotoNextWorkspace('-');
|
|
|
|
break;
|
|
|
|
case ScrollDirection::Down:
|
|
|
|
if (Config::Get().workspaceScrollInvert)
|
|
|
|
System::GotoNextWorkspace('-');
|
|
|
|
else
|
|
|
|
System::GotoNextWorkspace('+');
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetSensor(Widget& parent, TimerCallback<Sensor>&& callback, const std::string& sensorClass, const std::string& textClass, Text*& textPtr,
|
|
|
|
Side side)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
auto eventBox = Widget::Create<EventBox>();
|
2023-10-21 16:32:51 +00:00
|
|
|
Utils::SetTransform(*eventBox, {-1, false, SideToAlignment(side)});
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
auto box = Widget::Create<Box>();
|
|
|
|
box->SetSpacing({0, false});
|
2023-07-20 23:08:07 +00:00
|
|
|
box->SetOrientation(Utils::GetOrientation());
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-11-01 16:08:13 +00:00
|
|
|
std::unique_ptr<Revealer> revealer = nullptr;
|
2023-09-07 15:24:41 +00:00
|
|
|
if (!Config::Get().sensorTooltips)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-11-01 16:08:13 +00:00
|
|
|
revealer = Widget::Create<Revealer>();
|
2023-10-21 16:32:51 +00:00
|
|
|
revealer->SetTransition({Utils::GetTransitionType(SideToDefaultTransition(side)), 500});
|
2023-09-07 15:24:41 +00:00
|
|
|
// 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>();
|
|
|
|
text->SetClass(textClass);
|
|
|
|
text->SetAngle(Utils::GetAngle());
|
2023-10-21 16:32:51 +00:00
|
|
|
// Since we don't know, on which side the text is, add padding to both sides.
|
|
|
|
// This creates double padding on the side opposite to the sensor.
|
|
|
|
// TODO: Remove that padding.
|
|
|
|
Utils::SetTransform(*text, {-1, true, Alignment::Fill, 6, 6});
|
2023-09-07 15:24:41 +00:00
|
|
|
textPtr = text.get();
|
|
|
|
revealer->AddChild(std::move(text));
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 15:09:08 +00:00
|
|
|
auto sensor = Widget::Create<Sensor>();
|
|
|
|
sensor->SetClass(sensorClass);
|
2023-07-18 23:07:32 +00:00
|
|
|
double angle = -90;
|
|
|
|
switch (Config::Get().location)
|
|
|
|
{
|
|
|
|
case 'T':
|
|
|
|
case 'B': angle = -90; break;
|
|
|
|
case 'L':
|
2023-10-31 23:34:33 +00:00
|
|
|
case 'R': angle = RotatedIcons() ? -90 : 0; break;
|
2023-07-18 23:07:32 +00:00
|
|
|
}
|
|
|
|
sensor->SetStyle({angle});
|
2023-02-04 15:09:08 +00:00
|
|
|
sensor->AddTimer<Sensor>(std::move(callback), DynCtx::updateTime);
|
2023-07-20 23:08:07 +00:00
|
|
|
Utils::SetTransform(*sensor, {24, true, Alignment::Fill});
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case Side::Right:
|
|
|
|
case Side::Center:
|
|
|
|
{
|
|
|
|
if (!Config::Get().sensorTooltips)
|
|
|
|
box->AddChild(std::move(revealer));
|
|
|
|
box->AddChild(std::move(sensor));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Side::Left:
|
|
|
|
{
|
|
|
|
// Invert
|
|
|
|
box->AddChild(std::move(sensor));
|
|
|
|
if (!Config::Get().sensorTooltips)
|
|
|
|
box->AddChild(std::move(revealer));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
eventBox->AddChild(std::move(box));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.AddChild(std::move(eventBox));
|
|
|
|
}
|
|
|
|
|
2023-02-22 15:45:29 +00:00
|
|
|
// Handles in and out
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetAudio(Widget& parent, Side side)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-02-22 15:45:29 +00:00
|
|
|
enum class AudioType
|
|
|
|
{
|
|
|
|
Input,
|
|
|
|
Output
|
|
|
|
};
|
2023-08-21 16:19:46 +00:00
|
|
|
auto widgetAudioVolume = [](Widget& parent, AudioType type)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-08-21 16:19:46 +00:00
|
|
|
if (Config::Get().audioNumbers)
|
2023-02-22 15:45:29 +00:00
|
|
|
{
|
2023-08-21 16:19:46 +00:00
|
|
|
auto eventBox = Widget::Create<EventBox>();
|
|
|
|
auto text = Widget::Create<Text>();
|
|
|
|
text->SetAngle(Utils::GetAngle());
|
|
|
|
Utils::SetTransform(*text, {-1, true, Alignment::Fill});
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case AudioType::Input:
|
|
|
|
text->SetClass("mic-volume");
|
|
|
|
DynCtx::micSlider = text.get();
|
|
|
|
break;
|
|
|
|
case AudioType::Output:
|
|
|
|
text->SetClass("audio-volume");
|
|
|
|
DynCtx::audioSlider = text.get();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
eventBox->SetScrollFn(
|
|
|
|
[type, text = text.get()](EventBox&, ScrollDirection direction)
|
|
|
|
{
|
|
|
|
double delta = (double)Config::Get().audioScrollSpeed / 100.;
|
|
|
|
delta *= direction == ScrollDirection::Down ? -1 : 1;
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case AudioType::Input: DynCtx::OnChangeVolumeSourceDelta(delta); break;
|
|
|
|
case AudioType::Output: DynCtx::OnChangeVolumeSinkDelta(delta); break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
eventBox->AddChild(std::move(text));
|
|
|
|
parent.AddChild(std::move(eventBox));
|
2023-02-22 15:45:29 +00:00
|
|
|
}
|
2023-08-21 16:19:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
auto slider = Widget::Create<Slider>();
|
|
|
|
slider->SetOrientation(Utils::GetOrientation());
|
|
|
|
Utils::SetTransform(*slider, {100, true, Alignment::Fill});
|
|
|
|
slider->SetInverted(true);
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case AudioType::Input:
|
|
|
|
slider->SetClass("mic-volume");
|
|
|
|
slider->OnValueChange(DynCtx::OnChangeVolumeSource);
|
|
|
|
DynCtx::micSlider = slider.get();
|
|
|
|
break;
|
|
|
|
case AudioType::Output:
|
|
|
|
slider->SetClass("audio-volume");
|
|
|
|
slider->OnValueChange(DynCtx::OnChangeVolumeSink);
|
|
|
|
DynCtx::audioSlider = slider.get();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
slider->SetRange({0, 1, 0.01});
|
|
|
|
slider->SetScrollSpeed((double)Config::Get().audioScrollSpeed / 100.);
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-08-21 16:19:46 +00:00
|
|
|
parent.AddChild(std::move(slider));
|
|
|
|
}
|
2023-02-04 14:07:05 +00:00
|
|
|
};
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
auto widgetAudioBody = [&widgetAudioVolume, side](Widget& parent, AudioType type)
|
2023-02-04 14:07:05 +00:00
|
|
|
{
|
|
|
|
auto box = Widget::Create<Box>();
|
|
|
|
box->SetSpacing({8, false});
|
2023-10-21 16:32:51 +00:00
|
|
|
Utils::SetTransform(*box, {-1, false, SideToAlignment(side)});
|
2023-07-20 23:08:07 +00:00
|
|
|
box->SetOrientation(Utils::GetOrientation());
|
2023-02-04 14:07:05 +00:00
|
|
|
{
|
|
|
|
auto icon = Widget::Create<Text>();
|
2023-07-20 23:08:07 +00:00
|
|
|
icon->SetAngle(Utils::GetAngle());
|
2023-02-22 15:45:29 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case AudioType::Input:
|
|
|
|
icon->SetClass("mic-icon");
|
|
|
|
icon->SetText("");
|
|
|
|
DynCtx::micIcon = icon.get();
|
|
|
|
break;
|
|
|
|
case AudioType::Output:
|
|
|
|
icon->SetClass("audio-icon");
|
|
|
|
icon->SetText(" ");
|
2023-10-31 23:34:33 +00:00
|
|
|
if (!RotatedIcons())
|
|
|
|
Utils::SetTransform(*icon, {-1, true, Alignment::Fill, 0, 6});
|
2023-02-22 15:45:29 +00:00
|
|
|
DynCtx::audioIcon = icon.get();
|
|
|
|
break;
|
|
|
|
}
|
2023-02-04 14:07:05 +00:00
|
|
|
|
|
|
|
if (Config::Get().audioRevealer)
|
|
|
|
{
|
|
|
|
EventBox& eventBox = (EventBox&)parent;
|
|
|
|
auto revealer = Widget::Create<Revealer>();
|
2023-10-21 16:32:51 +00:00
|
|
|
revealer->SetTransition({Utils::GetTransitionType(SideToDefaultTransition(side)), 500});
|
2023-02-04 14:07:05 +00:00
|
|
|
// Add event to eventbox for the revealer to open
|
2023-02-12 13:28:46 +00:00
|
|
|
eventBox.SetHoverFn(
|
2023-02-04 14:07:05 +00:00
|
|
|
[slideRevealer = revealer.get()](EventBox&, bool hovered)
|
|
|
|
{
|
|
|
|
slideRevealer->SetRevealed(hovered);
|
|
|
|
});
|
|
|
|
{
|
2023-08-21 16:19:46 +00:00
|
|
|
widgetAudioVolume(*revealer, type);
|
2023-02-04 14:07:05 +00:00
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-02-04 14:07:05 +00:00
|
|
|
box->AddChild(std::move(revealer));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Straight forward
|
2023-08-21 16:19:46 +00:00
|
|
|
widgetAudioVolume(*box, type);
|
2023-02-04 14:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
box->AddChild(std::move(icon));
|
|
|
|
}
|
|
|
|
parent.AddChild(std::move(box));
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Config::Get().audioRevealer)
|
|
|
|
{
|
2023-02-22 15:45:29 +00:00
|
|
|
// Need an EventBox
|
|
|
|
if (Config::Get().audioInput)
|
|
|
|
{
|
|
|
|
auto eventBox = Widget::Create<EventBox>();
|
|
|
|
widgetAudioBody(*eventBox, AudioType::Input);
|
|
|
|
parent.AddChild(std::move(eventBox));
|
|
|
|
}
|
2023-02-04 14:07:05 +00:00
|
|
|
// Need an EventBox
|
|
|
|
auto eventBox = Widget::Create<EventBox>();
|
2023-02-22 15:45:29 +00:00
|
|
|
widgetAudioBody(*eventBox, AudioType::Output);
|
2023-02-04 14:07:05 +00:00
|
|
|
parent.AddChild(std::move(eventBox));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just invoke it.
|
2023-02-22 15:45:29 +00:00
|
|
|
if (Config::Get().audioInput)
|
|
|
|
{
|
|
|
|
widgetAudioBody(parent, AudioType::Input);
|
|
|
|
}
|
|
|
|
widgetAudioBody(parent, AudioType::Output);
|
2023-02-04 14:07:05 +00:00
|
|
|
}
|
2023-02-22 15:45:29 +00:00
|
|
|
parent.AddTimer<Widget>(DynCtx::UpdateAudio, DynCtx::updateTimeFast);
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetPackages(Widget& parent, Side)
|
2023-05-03 16:37:36 +00:00
|
|
|
{
|
|
|
|
auto text = Widget::Create<Text>();
|
|
|
|
text->SetText("");
|
2023-05-03 17:02:26 +00:00
|
|
|
text->SetVisible(false);
|
2023-05-03 16:37:36 +00:00
|
|
|
text->SetClass("package-empty");
|
2023-07-20 23:08:07 +00:00
|
|
|
text->SetAngle(Utils::GetAngle());
|
2023-05-03 17:02:26 +00:00
|
|
|
text->AddTimer<Text>(DynCtx::UpdatePackages, 1000 * Config::Get().checkUpdateInterval, TimerDispatchBehaviour::ImmediateDispatch);
|
2023-10-31 23:34:33 +00:00
|
|
|
|
|
|
|
// Fix alignment when icons are always upside
|
|
|
|
if (RotatedIcons())
|
|
|
|
{
|
|
|
|
Utils::SetTransform(*text, Transform{}, 10, 0);
|
|
|
|
}
|
|
|
|
|
2023-05-03 16:37:36 +00:00
|
|
|
parent.AddChild(std::move(text));
|
|
|
|
}
|
|
|
|
|
2023-01-30 15:57:15 +00:00
|
|
|
#ifdef WITH_BLUEZ
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetBluetooth(Widget& parent, Side side)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
auto box = Widget::Create<Box>();
|
|
|
|
box->SetSpacing({0, false});
|
2023-07-20 23:08:07 +00:00
|
|
|
box->SetOrientation(Utils::GetOrientation());
|
2023-10-21 16:32:51 +00:00
|
|
|
Utils::SetTransform(*box, {-1, false, SideToAlignment(side)});
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
auto devText = Widget::Create<Text>();
|
2023-07-20 23:08:07 +00:00
|
|
|
devText->SetAngle(Utils::GetAngle());
|
2023-01-13 15:13:56 +00:00
|
|
|
DynCtx::btDevText = devText.get();
|
|
|
|
devText->SetClass("bt-num");
|
2023-10-31 23:34:33 +00:00
|
|
|
if (side == Side::Left && !RotatedIcons())
|
|
|
|
{
|
2023-10-21 16:32:51 +00:00
|
|
|
Utils::SetTransform(*devText, {-1, true, Alignment::Fill, 6, 0});
|
2023-10-31 23:34:33 +00:00
|
|
|
}
|
2023-11-01 16:08:13 +00:00
|
|
|
else if (RotatedIcons())
|
2023-10-31 23:34:33 +00:00
|
|
|
{
|
|
|
|
Utils::SetTransform(*devText, {}, 6, 0);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-01-14 22:18:34 +00:00
|
|
|
auto iconText = Widget::Create<Button>();
|
|
|
|
iconText->OnClick(DynCtx::OnBTClick);
|
2023-07-20 23:08:07 +00:00
|
|
|
iconText->SetAngle(Utils::GetAngle());
|
2023-01-13 15:13:56 +00:00
|
|
|
DynCtx::btIconText = iconText.get();
|
|
|
|
|
2023-10-31 23:34:33 +00:00
|
|
|
if (!RotatedIcons())
|
|
|
|
{
|
|
|
|
// Only add end margin when icon is rotated with the bar.
|
|
|
|
Utils::SetTransform(*iconText, {-1, true, Alignment::Fill, 0, 6});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Align it more properly
|
|
|
|
Utils::SetTransform(*iconText, {}, 0, 6);
|
|
|
|
}
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case Side::Right:
|
|
|
|
case Side::Center:
|
|
|
|
{
|
|
|
|
box->AddChild(std::move(devText));
|
|
|
|
box->AddChild(std::move(iconText));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Side::Left:
|
|
|
|
{
|
|
|
|
// Invert
|
|
|
|
box->AddChild(std::move(iconText));
|
|
|
|
box->AddChild(std::move(devText));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
2023-01-29 11:23:44 +00:00
|
|
|
box->AddTimer<Box>(DynCtx::UpdateBluetooth, DynCtx::updateTime);
|
2023-01-13 15:13:56 +00:00
|
|
|
|
|
|
|
parent.AddChild(std::move(box));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetNetwork(Widget& parent, Side side)
|
2023-02-10 16:20:26 +00:00
|
|
|
{
|
|
|
|
auto eventBox = Widget::Create<EventBox>();
|
2023-10-21 16:32:51 +00:00
|
|
|
Utils::SetTransform(*eventBox, {-1, false, SideToAlignment(side)});
|
2023-02-10 16:20:26 +00:00
|
|
|
{
|
|
|
|
auto box = Widget::Create<Box>();
|
|
|
|
box->SetSpacing({0, false});
|
2023-07-20 23:08:07 +00:00
|
|
|
box->SetOrientation(Utils::GetOrientation());
|
2023-02-10 16:20:26 +00:00
|
|
|
{
|
2023-10-21 16:32:51 +00:00
|
|
|
auto revealer = Widget::Create<Revealer>();
|
2023-09-07 15:24:41 +00:00
|
|
|
if (!Config::Get().sensorTooltips)
|
2023-02-10 16:20:26 +00:00
|
|
|
{
|
2023-10-21 16:32:51 +00:00
|
|
|
revealer->SetTransition({Utils::GetTransitionType(SideToDefaultTransition(side)), 500});
|
2023-09-07 15:24:41 +00:00
|
|
|
// 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>();
|
|
|
|
text->SetClass("network-data-text");
|
|
|
|
text->SetAngle(Utils::GetAngle());
|
2023-10-21 16:32:51 +00:00
|
|
|
// Margins have the same problem as the WidgetSensor ones...
|
|
|
|
Utils::SetTransform(*text, {-1, true, Alignment::Fill, 6, 6});
|
2023-09-07 15:24:41 +00:00
|
|
|
DynCtx::networkText = text.get();
|
|
|
|
revealer->AddChild(std::move(text));
|
|
|
|
}
|
2023-02-10 16:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto sensor = Widget::Create<NetworkSensor>();
|
|
|
|
sensor->SetLimitUp({(double)Config::Get().minUploadBytes, (double)Config::Get().maxUploadBytes});
|
|
|
|
sensor->SetLimitDown({(double)Config::Get().minDownloadBytes, (double)Config::Get().maxDownloadBytes});
|
2023-07-20 23:08:07 +00:00
|
|
|
sensor->SetAngle(Utils::GetAngle());
|
2023-02-10 16:20:26 +00:00
|
|
|
sensor->AddTimer<NetworkSensor>(DynCtx::UpdateNetwork, DynCtx::updateTime);
|
2023-07-20 23:08:07 +00:00
|
|
|
Utils::SetTransform(*sensor, {24, true, Alignment::Fill});
|
2023-02-10 16:20:26 +00:00
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case Side::Right:
|
|
|
|
case Side::Center:
|
|
|
|
{
|
|
|
|
if (!Config::Get().sensorTooltips)
|
|
|
|
box->AddChild(std::move(revealer));
|
|
|
|
box->AddChild(std::move(sensor));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Side::Left:
|
|
|
|
{
|
|
|
|
// Invert
|
|
|
|
box->AddChild(std::move(sensor));
|
|
|
|
if (!Config::Get().sensorTooltips)
|
|
|
|
box->AddChild(std::move(revealer));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-02-10 16:20:26 +00:00
|
|
|
}
|
|
|
|
eventBox->AddChild(std::move(box));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.AddChild(std::move(eventBox));
|
|
|
|
}
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetSensors(Widget& parent, Side side)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-10-21 16:32:51 +00:00
|
|
|
WidgetSensor(parent, DynCtx::UpdateDisk, "disk-util-progress", "disk-data-text", DynCtx::diskText, side);
|
2023-01-30 16:23:28 +00:00
|
|
|
#if defined WITH_NVIDIA || defined WITH_AMD
|
|
|
|
if (RuntimeConfig::Get().hasNvidia || RuntimeConfig::Get().hasAMD)
|
2023-01-30 15:57:15 +00:00
|
|
|
{
|
2023-10-21 16:32:51 +00:00
|
|
|
WidgetSensor(parent, DynCtx::UpdateVRAM, "vram-util-progress", "vram-data-text", DynCtx::vramText, side);
|
|
|
|
WidgetSensor(parent, DynCtx::UpdateGPU, "gpu-util-progress", "gpu-data-text", DynCtx::gpuText, side);
|
2023-01-30 15:57:15 +00:00
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
#endif
|
2023-10-21 16:32:51 +00:00
|
|
|
WidgetSensor(parent, DynCtx::UpdateRAM, "ram-util-progress", "ram-data-text", DynCtx::ramText, side);
|
|
|
|
WidgetSensor(parent, DynCtx::UpdateCPU, "cpu-util-progress", "cpu-data-text", DynCtx::cpuText, side);
|
2023-01-28 22:47:55 +00:00
|
|
|
// Only show battery percentage if battery folder is set and exists
|
2023-01-30 15:57:15 +00:00
|
|
|
if (System::GetBatteryPercentage() >= 0)
|
|
|
|
{
|
2023-10-21 16:32:51 +00:00
|
|
|
WidgetSensor(parent, DynCtx::UpdateBattery, "battery-util-progress", "battery-data-text", DynCtx::batteryText, side);
|
2023-01-28 22:47:55 +00:00
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetPower(Widget& parent, Side side)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-05-23 20:38:19 +00:00
|
|
|
// TODO: Abstract this (Currently not DRY)
|
|
|
|
static bool activatedExit = false;
|
|
|
|
static bool activatedLock = false;
|
|
|
|
static bool activatedSuspend = false;
|
|
|
|
static bool activatedReboot = false;
|
|
|
|
static bool activatedShutdown = false;
|
|
|
|
|
|
|
|
auto setActivate = [](Button& button, bool& activeBool, bool activate)
|
|
|
|
{
|
|
|
|
if (activate)
|
|
|
|
{
|
|
|
|
button.AddClass("system-confirm");
|
|
|
|
button.AddTimer<Button>(
|
|
|
|
[&](Button& button)
|
|
|
|
{
|
|
|
|
button.RemoveClass("system-confirm");
|
|
|
|
activeBool = false;
|
|
|
|
return TimerResult::Delete;
|
|
|
|
},
|
|
|
|
2000, TimerDispatchBehaviour::LateDispatch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
button.RemoveClass("system-confirm");
|
|
|
|
}
|
|
|
|
activeBool = activate;
|
|
|
|
};
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
auto eventBox = Widget::Create<EventBox>();
|
2023-02-12 13:28:46 +00:00
|
|
|
eventBox->SetHoverFn(DynCtx::PowerBoxEvent);
|
2023-10-21 16:32:51 +00:00
|
|
|
Utils::SetTransform(*eventBox, {-1, false, SideToAlignment(side)});
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
auto powerBox = Widget::Create<Box>();
|
|
|
|
powerBox->SetClass("power-box");
|
|
|
|
powerBox->SetSpacing({0, false});
|
2023-07-20 23:08:07 +00:00
|
|
|
powerBox->SetOrientation(Utils::GetOrientation());
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
auto revealer = Widget::Create<Revealer>();
|
|
|
|
DynCtx::powerBoxRevealer = revealer.get();
|
2023-10-21 16:32:51 +00:00
|
|
|
revealer->SetTransition({Utils::GetTransitionType(SideToDefaultTransition(side)), 500});
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
auto powerBoxExpand = Widget::Create<Box>();
|
|
|
|
powerBoxExpand->SetClass("power-box-expand");
|
2023-10-31 23:34:33 +00:00
|
|
|
if (!RotatedIcons())
|
|
|
|
{
|
|
|
|
powerBoxExpand->SetSpacing({8, true});
|
|
|
|
Utils::SetTransform(*powerBoxExpand, {-1, true, Alignment::Fill, 0, 6});
|
|
|
|
}
|
2023-07-20 23:08:07 +00:00
|
|
|
powerBoxExpand->SetOrientation(Utils::GetOrientation());
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
auto exitButton = Widget::Create<Button>();
|
|
|
|
exitButton->SetClass("exit-button");
|
2023-05-04 21:25:57 +00:00
|
|
|
exitButton->SetText("");
|
2023-07-20 23:08:07 +00:00
|
|
|
exitButton->SetAngle(Utils::GetAngle());
|
2023-10-31 23:34:33 +00:00
|
|
|
if (RotatedIcons())
|
|
|
|
{
|
|
|
|
// Align in center
|
|
|
|
Utils::SetTransform(*exitButton, Transform{}, 0, 2);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
exitButton->OnClick(
|
2023-05-23 20:38:19 +00:00
|
|
|
[setActivate](Button& but)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-05-23 20:38:19 +00:00
|
|
|
if (activatedExit)
|
|
|
|
{
|
|
|
|
System::ExitWM();
|
|
|
|
setActivate(but, activatedExit, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setActivate(but, activatedExit, true);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
auto lockButton = Widget::Create<Button>();
|
|
|
|
lockButton->SetClass("sleep-button");
|
|
|
|
lockButton->SetText("");
|
2023-07-20 23:08:07 +00:00
|
|
|
lockButton->SetAngle(Utils::GetAngle());
|
2023-10-31 23:34:33 +00:00
|
|
|
if (RotatedIcons())
|
|
|
|
{
|
|
|
|
// Align in center
|
|
|
|
Utils::SetTransform(*lockButton, Transform{}, 0, 2);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
lockButton->OnClick(
|
2023-05-23 20:38:19 +00:00
|
|
|
[setActivate](Button& but)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-05-23 20:38:19 +00:00
|
|
|
if (activatedLock)
|
|
|
|
{
|
|
|
|
System::Lock();
|
|
|
|
setActivate(but, activatedLock, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setActivate(but, activatedLock, true);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
auto sleepButton = Widget::Create<Button>();
|
|
|
|
sleepButton->SetClass("sleep-button");
|
2023-05-04 21:25:57 +00:00
|
|
|
sleepButton->SetText("");
|
2023-07-20 23:08:07 +00:00
|
|
|
sleepButton->SetAngle(Utils::GetAngle());
|
2023-10-31 23:34:33 +00:00
|
|
|
if (RotatedIcons())
|
|
|
|
{
|
|
|
|
// Align in center
|
|
|
|
Utils::SetTransform(*sleepButton, Transform{}, 0, 2);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
sleepButton->OnClick(
|
2023-05-23 20:38:19 +00:00
|
|
|
[setActivate](Button& but)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-05-23 20:38:19 +00:00
|
|
|
if (activatedSuspend)
|
|
|
|
{
|
|
|
|
System::Suspend();
|
|
|
|
setActivate(but, activatedSuspend, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setActivate(but, activatedSuspend, true);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
auto rebootButton = Widget::Create<Button>();
|
|
|
|
rebootButton->SetClass("reboot-button");
|
2023-05-04 21:25:57 +00:00
|
|
|
rebootButton->SetText("");
|
2023-07-20 23:08:07 +00:00
|
|
|
rebootButton->SetAngle(Utils::GetAngle());
|
2023-10-31 23:34:33 +00:00
|
|
|
|
|
|
|
if (!RotatedIcons())
|
|
|
|
{
|
|
|
|
Utils::SetTransform(*rebootButton, {-1, false, Alignment::Fill, 0, 6});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Align in center
|
|
|
|
Utils::SetTransform(*rebootButton, Transform{}, 0, 2);
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
rebootButton->OnClick(
|
2023-05-23 20:38:19 +00:00
|
|
|
[setActivate](Button& but)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-05-23 20:38:19 +00:00
|
|
|
if (activatedReboot)
|
|
|
|
{
|
|
|
|
System::Reboot();
|
|
|
|
setActivate(but, activatedReboot, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setActivate(but, activatedReboot, true);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
powerBoxExpand->AddChild(std::move(exitButton));
|
|
|
|
powerBoxExpand->AddChild(std::move(lockButton));
|
|
|
|
powerBoxExpand->AddChild(std::move(sleepButton));
|
|
|
|
powerBoxExpand->AddChild(std::move(rebootButton));
|
|
|
|
}
|
|
|
|
|
|
|
|
revealer->AddChild(std::move(powerBoxExpand));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto powerButton = Widget::Create<Button>();
|
|
|
|
powerButton->SetClass("power-button");
|
|
|
|
powerButton->SetText(" ");
|
2023-07-20 23:08:07 +00:00
|
|
|
powerButton->SetAngle(Utils::GetAngle());
|
2023-10-31 23:34:33 +00:00
|
|
|
|
|
|
|
Utils::SetTransform(*powerButton, {24, false, Alignment::Fill}, RotatedIcons() ? 10 : 0, 0);
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
powerButton->OnClick(
|
2023-05-23 20:38:19 +00:00
|
|
|
[setActivate](Button& but)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-05-23 20:38:19 +00:00
|
|
|
if (activatedShutdown)
|
|
|
|
{
|
|
|
|
System::Shutdown();
|
|
|
|
setActivate(but, activatedShutdown, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setActivate(but, activatedShutdown, true);
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
});
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
switch (side)
|
|
|
|
{
|
|
|
|
case Side::Right:
|
|
|
|
case Side::Center:
|
|
|
|
{
|
|
|
|
powerBox->AddChild(std::move(revealer));
|
|
|
|
powerBox->AddChild(std::move(powerButton));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Side::Left:
|
|
|
|
{
|
|
|
|
// Invert
|
|
|
|
powerBox->AddChild(std::move(powerButton));
|
|
|
|
powerBox->AddChild(std::move(revealer));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
eventBox->AddChild(std::move(powerBox));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.AddChild(std::move(eventBox));
|
|
|
|
}
|
|
|
|
|
2023-03-03 19:44:51 +00:00
|
|
|
#ifdef WITH_WORKSPACES
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetWorkspaces(Widget& parent, Side side)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-02-12 13:57:32 +00:00
|
|
|
auto eventBox = Widget::Create<EventBox>();
|
|
|
|
eventBox->SetScrollFn(DynCtx::ScrollWorkspaces);
|
2023-10-21 16:32:51 +00:00
|
|
|
Utils::SetTransform(*eventBox, {-1, false, SideToAlignment(side)});
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-02-12 13:57:32 +00:00
|
|
|
auto box = Widget::Create<Box>();
|
|
|
|
box->SetSpacing({8, true});
|
2023-07-20 23:08:07 +00:00
|
|
|
box->SetOrientation(Utils::GetOrientation());
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-09-01 22:05:08 +00:00
|
|
|
DynCtx::workspaces.resize(Config::Get().numWorkspaces);
|
2023-02-12 13:57:32 +00:00
|
|
|
for (size_t i = 0; i < DynCtx::workspaces.size(); i++)
|
|
|
|
{
|
|
|
|
auto workspace = Widget::Create<Button>();
|
2023-07-20 23:08:07 +00:00
|
|
|
Utils::SetTransform(*workspace, {8, false, Alignment::Fill});
|
2023-02-12 13:57:32 +00:00
|
|
|
workspace->OnClick(
|
|
|
|
[i](Button&)
|
|
|
|
{
|
|
|
|
System::GotoWorkspace((uint32_t)i + 1);
|
|
|
|
});
|
|
|
|
DynCtx::workspaces[i] = workspace.get();
|
|
|
|
box->AddChild(std::move(workspace));
|
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
2023-02-12 13:57:32 +00:00
|
|
|
box->AddTimer<Box>(DynCtx::UpdateWorkspaces, DynCtx::updateTimeFast);
|
|
|
|
eventBox->AddChild(std::move(box));
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
2023-02-12 13:57:32 +00:00
|
|
|
parent.AddChild(std::move(eventBox));
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
void WidgetTime(Widget& parent, Side side)
|
|
|
|
{
|
|
|
|
auto time = Widget::Create<Text>();
|
|
|
|
Utils::SetTransform(*time, {-1, false, SideToAlignment(side)});
|
|
|
|
time->SetAngle(Utils::GetAngle());
|
|
|
|
time->SetClass("time-text");
|
|
|
|
time->SetText("Uninitialized");
|
|
|
|
time->AddTimer<Text>(DynCtx::UpdateTime, 1000);
|
|
|
|
parent.AddChild(std::move(time));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChooseWidgetToDraw(const std::string& widgetName, Widget& parent, Side side)
|
|
|
|
{
|
|
|
|
if (widgetName == "Workspaces")
|
|
|
|
{
|
|
|
|
#ifdef WITH_WORKSPACES
|
|
|
|
if (RuntimeConfig::Get().hasWorkspaces)
|
|
|
|
{
|
|
|
|
WidgetWorkspaces(parent, side);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Time")
|
|
|
|
{
|
|
|
|
WidgetTime(parent, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Tray")
|
|
|
|
{
|
|
|
|
#ifdef WITH_SNI
|
|
|
|
SNI::WidgetSNI(parent);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Packages")
|
|
|
|
{
|
|
|
|
WidgetPackages(parent, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Audio")
|
|
|
|
{
|
|
|
|
WidgetAudio(parent, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Bluetooth")
|
|
|
|
{
|
|
|
|
#ifdef WITH_BLUEZ
|
|
|
|
if (RuntimeConfig::Get().hasBlueZ)
|
|
|
|
WidgetBluetooth(parent, side);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Network")
|
|
|
|
{
|
|
|
|
if (Config::Get().networkWidget && RuntimeConfig::Get().hasNet)
|
|
|
|
WidgetNetwork(parent, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Cheeky shorthand for all sensors
|
|
|
|
if (widgetName == "Sensors")
|
|
|
|
{
|
|
|
|
WidgetSensors(parent, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Disk")
|
|
|
|
{
|
|
|
|
WidgetSensor(parent, DynCtx::UpdateDisk, "disk-util-progress", "disk-data-text", DynCtx::diskText, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "VRAM")
|
|
|
|
{
|
|
|
|
#if defined WITH_NVIDIA || defined WITH_AMD
|
|
|
|
if (RuntimeConfig::Get().hasNvidia || RuntimeConfig::Get().hasAMD)
|
|
|
|
WidgetSensor(parent, DynCtx::UpdateVRAM, "vram-util-progress", "vram-data-text", DynCtx::vramText, side);
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (widgetName == "GPU")
|
|
|
|
{
|
|
|
|
#if defined WITH_NVIDIA || defined WITH_AMD
|
|
|
|
if (RuntimeConfig::Get().hasNvidia || RuntimeConfig::Get().hasAMD)
|
|
|
|
WidgetSensor(parent, DynCtx::UpdateGPU, "gpu-util-progress", "gpu-data-text", DynCtx::gpuText, side);
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (widgetName == "RAM")
|
|
|
|
{
|
|
|
|
WidgetSensor(parent, DynCtx::UpdateRAM, "ram-util-progress", "ram-data-text", DynCtx::ramText, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "CPU")
|
|
|
|
{
|
|
|
|
WidgetSensor(parent, DynCtx::UpdateCPU, "cpu-util-progress", "cpu-data-text", DynCtx::cpuText, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Battery")
|
|
|
|
{
|
|
|
|
// Only show battery percentage if battery folder is set and exists
|
|
|
|
if (System::GetBatteryPercentage() >= 0)
|
|
|
|
WidgetSensor(parent, DynCtx::UpdateBattery, "battery-util-progress", "battery-data-text", DynCtx::batteryText, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (widgetName == "Power")
|
|
|
|
{
|
|
|
|
WidgetPower(parent, side);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG("Warning: Unkwown widget name " << widgetName << "!"
|
2023-10-28 21:05:06 +00:00
|
|
|
<< "\n\tKnown names are: Workspaces, Time, Tray, Packages, Audio, Bluetooth, Network, Sensors, Disk, "
|
2023-10-21 16:32:51 +00:00
|
|
|
"VRAM, GPU, RAM, CPU, Battery, Power");
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
void Create(Window& window, int32_t monitor)
|
|
|
|
{
|
|
|
|
monitorID = monitor;
|
|
|
|
|
|
|
|
auto mainWidget = Widget::Create<Box>();
|
2023-07-20 23:08:07 +00:00
|
|
|
mainWidget->SetOrientation(Utils::GetOrientation());
|
2023-06-10 21:44:28 +00:00
|
|
|
mainWidget->SetSpacing({0, false});
|
2023-01-13 15:13:56 +00:00
|
|
|
mainWidget->SetClass("bar");
|
|
|
|
{
|
2023-06-10 21:44:28 +00:00
|
|
|
// Calculate how much space we need have for the left widget.
|
|
|
|
// The center widget will come directly after that.
|
|
|
|
// This ensures that the center widget is centered.
|
2023-07-18 23:07:32 +00:00
|
|
|
bool topToBottom = Config::Get().location == 'L' || Config::Get().location == 'R';
|
|
|
|
int windowCenter = (topToBottom ? window.GetHeight() : window.GetWidth()) / 2;
|
2023-06-10 21:44:28 +00:00
|
|
|
int endLeftWidgets = windowCenter - Config::Get().timeSpace / 2;
|
|
|
|
|
|
|
|
if (!Config::Get().centerTime)
|
|
|
|
{
|
|
|
|
// Don't care if time is centered or not.
|
|
|
|
endLeftWidgets = -1;
|
|
|
|
}
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
auto left = Widget::Create<Box>();
|
2023-10-21 16:32:51 +00:00
|
|
|
left->SetSpacing({6, false});
|
2023-07-20 23:08:07 +00:00
|
|
|
left->SetOrientation(Utils::GetOrientation());
|
2023-06-10 21:44:28 +00:00
|
|
|
// For centerTime the width of the left widget handles the centering.
|
|
|
|
// For not centerTime we want to set it as much right as possible. So let this expand as much as possible.
|
2023-10-21 16:32:51 +00:00
|
|
|
Utils::SetTransform(*left, {endLeftWidgets, !Config::Get().centerTime, Alignment::Left, 12, 0});
|
|
|
|
|
|
|
|
for (auto& widget : Config::Get().widgetsLeft)
|
2023-01-30 15:57:15 +00:00
|
|
|
{
|
2023-10-21 16:32:51 +00:00
|
|
|
ChooseWidgetToDraw(widget, *left, Side::Left);
|
2023-01-30 15:57:15 +00:00
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-06-10 21:44:28 +00:00
|
|
|
auto center = Widget::Create<Box>();
|
2023-07-20 23:08:07 +00:00
|
|
|
center->SetOrientation(Utils::GetOrientation());
|
|
|
|
Utils::SetTransform(*center, {(int)Config::Get().timeSpace, false, Alignment::Left});
|
2023-10-21 16:32:51 +00:00
|
|
|
center->SetSpacing({6, false});
|
|
|
|
|
|
|
|
for (auto& widget : Config::Get().widgetsCenter)
|
2023-06-10 21:44:28 +00:00
|
|
|
{
|
2023-10-21 16:32:51 +00:00
|
|
|
ChooseWidgetToDraw(widget, *center, Side::Center);
|
2023-06-10 21:44:28 +00:00
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
|
|
|
|
auto right = Widget::Create<Box>();
|
|
|
|
right->SetClass("right");
|
2023-10-21 16:32:51 +00:00
|
|
|
right->SetSpacing({6, false});
|
2023-07-20 23:08:07 +00:00
|
|
|
right->SetOrientation(Utils::GetOrientation());
|
|
|
|
Utils::SetTransform(*right, {-1, true, Alignment::Right, 0, 10});
|
2023-03-17 23:02:40 +00:00
|
|
|
|
2023-10-21 16:32:51 +00:00
|
|
|
for (auto& widget : Config::Get().widgetsRight)
|
|
|
|
{
|
|
|
|
ChooseWidgetToDraw(widget, *right, Side::Right);
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mainWidget->AddChild(std::move(left));
|
2023-06-10 21:44:28 +00:00
|
|
|
mainWidget->AddChild(std::move(center));
|
2023-01-13 15:13:56 +00:00
|
|
|
mainWidget->AddChild(std::move(right));
|
|
|
|
}
|
2023-07-18 23:07:32 +00:00
|
|
|
|
|
|
|
Anchor anchor;
|
|
|
|
switch (Config::Get().location)
|
|
|
|
{
|
|
|
|
case 'T': anchor = Anchor::Top | Anchor::Left | Anchor::Right; break;
|
|
|
|
case 'B': anchor = Anchor::Bottom | Anchor::Left | Anchor::Right; break;
|
|
|
|
case 'L': anchor = Anchor::Left | Anchor::Top | Anchor::Bottom; break;
|
|
|
|
case 'R': anchor = Anchor::Right | Anchor::Top | Anchor::Bottom; break;
|
|
|
|
default: LOG("Invalid location char \"" << Config::Get().location << "\"!"); anchor = Anchor::Top | Anchor::Left | Anchor::Right;
|
|
|
|
}
|
|
|
|
window.SetAnchor(anchor);
|
2023-06-10 21:42:41 +00:00
|
|
|
window.SetMainWidget(std::move(mainWidget));
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
|
|
|
}
|