mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
Add configuration system
The config file format could still be improved though...
This commit is contained in:
parent
d1b062bad9
commit
6621e3abc2
3 changed files with 79 additions and 28 deletions
19
README.md
19
README.md
|
@ -77,8 +77,17 @@ Bar:
|
|||
Audio Flyin:
|
||||
- Audio control
|
||||
|
||||
## Configuration for your system
|
||||
Copy my personal config(found under data/config) into ~/.config/gBar/config and modify it to your needs(Mine will 100% not work, since it is dependant on my dotfiles).
|
||||
The config must be *exactly* formatted the following way(Don't forget the space between the variable and the data!):
|
||||
```
|
||||
[Variable]: [value]
|
||||
[Variable]: [value]
|
||||
[...]
|
||||
```
|
||||
|
||||
## Plugins
|
||||
gBar utilizes a plugin system for custom widgets.
|
||||
gBar utilizes a plugin system for custom widgets anyone can create without modifying the source code.
|
||||
Plugins are native shared-libraries, which need to be placed inside ```~/.local/lib/gBar```, ```/usr/lib/gBar``` or ```/usr/local/lib/gBar```.
|
||||
Inside example/ there is an example plugin setup. To build and run it, run the following commands inside the example directory:
|
||||
|
||||
|
@ -133,12 +142,8 @@ First, find where the data is located for gBar. Possible locations:
|
|||
Delete /tmp/gBar__audio.
|
||||
This happens, when you kill the widget before it closes automatically after a few seconds.
|
||||
|
||||
### CPU Temperature is wrong/Lock doesn't work
|
||||
*This is caused by the way my system and/or Linux is setup.*
|
||||
|
||||
Temperature: Edit the variable ```tempFilePath``` in ```src/System.cpp``` to the correct thermal zone file and recompile. The one for my system is *very* likely wrong.
|
||||
|
||||
Lock: There is no generic way to lock a system. So please, implement it to suit your needs (Replace XXX by a shell command in ```src/System.cpp```)
|
||||
### CPU Temperature is wrong / Lock doesn't work / Exiting WM does not work
|
||||
See *Configuration for your system*
|
||||
|
||||
### The icons are not showing!
|
||||
Please install a Nerd Font from https://www.nerdfonts.com (I use Caskaydia Cove NF), and change style.css/style.scss accordingly (Refer to 'I want to customize the colors' for that)
|
||||
|
|
4
data/config
Normal file
4
data/config
Normal file
|
@ -0,0 +1,4 @@
|
|||
CPUThermalZone: /sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input
|
||||
SuspendCommand: ~/.config/scripts/sys.sh suspend
|
||||
LockCommand: ~/.config/scripts/sys.sh lock
|
||||
ExitCommand: killall Hyprland
|
|
@ -21,6 +21,63 @@
|
|||
|
||||
namespace System
|
||||
{
|
||||
struct Config
|
||||
{
|
||||
std::string cpuThermalZone = ""; // idk, no standard way of doing this.
|
||||
std::string suspendCommand = "systemctl suspend";
|
||||
std::string lockCommand = ""; // idk, no standard way of doing this.
|
||||
std::string exitCommand = ""; // idk, no standard way of doing this.
|
||||
};
|
||||
|
||||
static Config config;
|
||||
|
||||
void LoadConfig()
|
||||
{
|
||||
const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
|
||||
std::ifstream file;
|
||||
if (xdgConfigHome)
|
||||
{
|
||||
file = std::ifstream(std::string(xdgConfigHome) + "/gBar/config");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string home = getenv("HOME");
|
||||
file = std::ifstream(home + "/.config/gBar/config");
|
||||
}
|
||||
if (!file.is_open())
|
||||
{
|
||||
LOG("Failed opening config!");
|
||||
return;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
std::string* prop = nullptr;
|
||||
if (line.find("CPUThermalZone: ") != std::string::npos)
|
||||
{
|
||||
prop = &config.cpuThermalZone;
|
||||
}
|
||||
else if (line.find("SuspendCommand: ") != std::string::npos)
|
||||
{
|
||||
prop = &config.suspendCommand;
|
||||
}
|
||||
else if (line.find("LockCommand: ") != std::string::npos)
|
||||
{
|
||||
prop = &config.lockCommand;
|
||||
}
|
||||
else if (line.find("ExitCommand: ") != std::string::npos)
|
||||
{
|
||||
prop = &config.exitCommand;
|
||||
}
|
||||
if (prop == nullptr)
|
||||
{
|
||||
LOG("Warning: unknown config var: " << line);
|
||||
continue;
|
||||
}
|
||||
*prop = line.substr(line.find(' ') + 1); // Everything after space is data
|
||||
}
|
||||
}
|
||||
|
||||
struct CPUTimestamp
|
||||
{
|
||||
size_t total = 0;
|
||||
|
@ -72,8 +129,7 @@ namespace System
|
|||
|
||||
double GetCPUTemp()
|
||||
{
|
||||
constexpr const char* tempFilePath = "/sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon2/temp1_input";
|
||||
std::ifstream tempFile(tempFilePath);
|
||||
std::ifstream tempFile(config.cpuThermalZone);
|
||||
if (!tempFile.is_open())
|
||||
{
|
||||
return 0.f;
|
||||
|
@ -141,7 +197,7 @@ namespace System
|
|||
struct statvfs stat;
|
||||
int err = statvfs("/", &stat);
|
||||
ASSERT(err == 0, "Cannot stat root!");
|
||||
|
||||
|
||||
DiskInfo out{};
|
||||
out.totalGiB = (double)(stat.f_blocks * stat.f_frsize) / (1024 * 1024 * 1024);
|
||||
out.usedGiB = (double)((stat.f_blocks - stat.f_bfree) * stat.f_frsize) / (1024 * 1024 * 1024);
|
||||
|
@ -396,36 +452,22 @@ namespace System
|
|||
|
||||
void ExitWM()
|
||||
{
|
||||
#ifdef HAS_HYPRLAND
|
||||
system("killall Hyprland");
|
||||
#else
|
||||
LOG("Implement me!");
|
||||
#endif
|
||||
system(config.exitCommand.c_str());
|
||||
}
|
||||
|
||||
void Lock()
|
||||
{
|
||||
#ifdef HAS_SYS
|
||||
// My personal lock script
|
||||
system("~/.config/scripts/sys.sh lock");
|
||||
#else
|
||||
LOG("Lock not implemented! Please implement me below!");
|
||||
// system("XXX");
|
||||
#endif
|
||||
system(config.lockCommand.c_str());
|
||||
}
|
||||
|
||||
void Suspend()
|
||||
{
|
||||
#ifdef HAS_SYS
|
||||
// My personal suspend script
|
||||
system("~/.config/scripts/sys.sh suspend");
|
||||
#else
|
||||
system("systemctl suspend");
|
||||
#endif
|
||||
system(config.suspendCommand.c_str());
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
LoadConfig();
|
||||
#ifdef HAS_NVIDIA
|
||||
NvidiaGPU::Init();
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue