2023-01-13 15:13:56 +00:00
|
|
|
#include "Window.h"
|
|
|
|
#include "Common.h"
|
|
|
|
#include "System.h"
|
|
|
|
#include "Bar.h"
|
|
|
|
#include "AudioFlyin.h"
|
2023-01-14 22:18:34 +00:00
|
|
|
#include "BluetoothDevices.h"
|
2023-01-28 14:07:07 +00:00
|
|
|
#include "Plugin.h"
|
2023-01-30 15:57:15 +00:00
|
|
|
#include "Config.h"
|
2023-01-13 15:13:56 +00:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-07-14 17:36:23 +00:00
|
|
|
const char* audioTmpFilePath = "/tmp/gBar__audio";
|
|
|
|
const char* bluetoothTmpFilePath = "/tmp/gBar__bluetooth";
|
|
|
|
|
|
|
|
static bool tmpFileOpen = false;
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-02-22 15:45:29 +00:00
|
|
|
void OpenAudioFlyin(Window& window, int32_t monitor, AudioFlyin::Type type)
|
|
|
|
{
|
2023-07-14 17:36:23 +00:00
|
|
|
tmpFileOpen = true;
|
|
|
|
if (access(audioTmpFilePath, F_OK) != 0)
|
2023-02-22 15:45:29 +00:00
|
|
|
{
|
2023-07-14 17:36:23 +00:00
|
|
|
FILE* audioTempFile = fopen(audioTmpFilePath, "w");
|
2023-02-22 15:45:29 +00:00
|
|
|
AudioFlyin::Create(window, monitor, type);
|
|
|
|
fclose(audioTempFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Already open, close
|
2023-07-14 17:36:23 +00:00
|
|
|
LOG("Audio flyin already open (/tmp/gBar__audio exists)! Exiting...");
|
2023-02-22 15:45:29 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-14 17:46:27 +00:00
|
|
|
void CloseTmpFiles(int sig)
|
|
|
|
{
|
|
|
|
if (tmpFileOpen)
|
|
|
|
{
|
|
|
|
remove(audioTmpFilePath);
|
|
|
|
remove(bluetoothTmpFilePath);
|
|
|
|
}
|
|
|
|
if (sig != 0)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2024-01-21 15:22:10 +00:00
|
|
|
void PrintHelp()
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2024-01-21 15:22:10 +00:00
|
|
|
LOG("==============================================\n"
|
|
|
|
"| gBar |\n"
|
|
|
|
"==============================================\n"
|
|
|
|
"gBar, a fast status bar + widgets\n"
|
|
|
|
"\n"
|
|
|
|
"Basic usage: \n"
|
|
|
|
"\tgBar [OPTIONS...] WIDGET [MONITOR]\n"
|
|
|
|
"\n"
|
|
|
|
"Sample usage:\n"
|
2024-01-21 16:13:45 +00:00
|
|
|
"\tgBar bar 0 \tOpens the status bar on monitor 0\n"
|
|
|
|
"\tgBar audio \tOpens the audio flyin on the current monitor\n"
|
2024-01-21 15:22:10 +00:00
|
|
|
"\n"
|
|
|
|
"All options:\n"
|
2024-01-21 16:13:45 +00:00
|
|
|
"\t--help/-h \tPrints this help page and exits afterwards\n"
|
|
|
|
"\t--config/-c DIR\tOverrides the config search path to DIR and appends DIR to the CSS search path.\n"
|
|
|
|
"\t \t DIR cannot contain path shorthands like e.g. \"~\""
|
2024-01-21 15:22:10 +00:00
|
|
|
"\n"
|
|
|
|
"All available widgets:\n"
|
2024-01-21 16:13:45 +00:00
|
|
|
"\tbar \tThe main status bar\n"
|
|
|
|
"\taudio \tAn audio volume slider flyin\n"
|
|
|
|
"\tmic \tA microphone volume slider flyin\n"
|
|
|
|
"\tbluetooth \tA bluetooth connection widget\n"
|
|
|
|
"\t[plugin] \tTries to open and run the plugin lib[plugin].so\n");
|
2024-01-21 15:22:10 +00:00
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2024-01-21 15:22:10 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
std::string widget;
|
2023-01-13 15:13:56 +00:00
|
|
|
int32_t monitor = -1;
|
2024-01-21 16:13:45 +00:00
|
|
|
std::string overrideConfigLocation = "";
|
2024-01-21 15:22:10 +00:00
|
|
|
|
|
|
|
// Arg parsing
|
|
|
|
for (int i = 1; i < argc; i++)
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2024-01-21 15:22:10 +00:00
|
|
|
std::string arg = argv[i];
|
|
|
|
if (arg.size() < 1 || arg[0] != '-')
|
|
|
|
{
|
|
|
|
// This must be the widget selection
|
|
|
|
widget = arg;
|
|
|
|
if (i + 1 < argc)
|
|
|
|
{
|
|
|
|
std::string mon = argv[i + 1];
|
|
|
|
if (mon.size() < 1 || mon[0] != '-')
|
|
|
|
{
|
|
|
|
// Next comes the monitor
|
|
|
|
monitor = std::stoi(mon);
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Not the monitor
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (arg == "-h" || arg == "--help")
|
|
|
|
{
|
|
|
|
PrintHelp();
|
|
|
|
return 0;
|
|
|
|
}
|
2024-01-21 16:13:45 +00:00
|
|
|
else if (arg == "-c" || arg == "--config")
|
|
|
|
{
|
|
|
|
ASSERT(i + 1 < argc, "Not enough arguments provided for -c/--config!");
|
|
|
|
overrideConfigLocation = argv[i + 1];
|
|
|
|
i += 1;
|
|
|
|
}
|
2024-01-21 15:22:10 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG("Warning: Unknown CLI option \"" << arg << "\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (widget == "")
|
|
|
|
{
|
|
|
|
LOG("Error: Widget to open not specified!\n");
|
|
|
|
PrintHelp();
|
|
|
|
return 0;
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
2024-01-21 15:22:10 +00:00
|
|
|
if (argc <= 1)
|
|
|
|
{
|
|
|
|
LOG("Error: Too little arguments\n");
|
|
|
|
PrintHelp();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
signal(SIGINT, CloseTmpFiles);
|
2024-01-21 16:13:45 +00:00
|
|
|
System::Init(overrideConfigLocation);
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-06-10 21:42:41 +00:00
|
|
|
Window window(monitor);
|
2024-01-21 16:13:45 +00:00
|
|
|
window.Init(overrideConfigLocation);
|
2024-01-21 15:22:10 +00:00
|
|
|
if (widget == "bar")
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
|
|
|
Bar::Create(window, monitor);
|
|
|
|
}
|
2024-01-21 15:22:10 +00:00
|
|
|
else if (widget == "audio")
|
2023-01-13 15:13:56 +00:00
|
|
|
{
|
2023-02-22 15:45:29 +00:00
|
|
|
OpenAudioFlyin(window, monitor, AudioFlyin::Type::Speaker);
|
|
|
|
}
|
2024-01-21 15:22:10 +00:00
|
|
|
else if (widget == "mic")
|
2023-02-22 15:45:29 +00:00
|
|
|
{
|
|
|
|
OpenAudioFlyin(window, monitor, AudioFlyin::Type::Microphone);
|
2023-01-13 15:13:56 +00:00
|
|
|
}
|
2023-01-30 15:57:15 +00:00
|
|
|
#ifdef WITH_BLUEZ
|
2024-01-21 15:22:10 +00:00
|
|
|
else if (widget == "bluetooth")
|
2023-01-14 22:18:34 +00:00
|
|
|
{
|
2023-01-30 15:57:15 +00:00
|
|
|
if (RuntimeConfig::Get().hasBlueZ)
|
|
|
|
{
|
2023-07-14 17:36:23 +00:00
|
|
|
if (access(bluetoothTmpFilePath, F_OK) != 0)
|
|
|
|
{
|
|
|
|
tmpFileOpen = true;
|
|
|
|
FILE* bluetoothTmpFile = fopen(bluetoothTmpFilePath, "w");
|
|
|
|
BluetoothDevices::Create(window, monitor);
|
|
|
|
fclose(bluetoothTmpFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Already open, close
|
|
|
|
LOG("Bluetooth widget already open (/tmp/gBar__bluetooth exists)! Exiting...");
|
|
|
|
exit(0);
|
|
|
|
}
|
2023-01-30 15:57:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG("Blutooth disabled, cannot open bluetooth widget!");
|
|
|
|
exit(1);
|
|
|
|
}
|
2023-01-14 22:18:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2023-01-28 14:07:07 +00:00
|
|
|
else
|
|
|
|
{
|
2024-01-21 15:22:10 +00:00
|
|
|
Plugin::LoadWidgetFromPlugin(widget, window, monitor);
|
2023-01-28 14:07:07 +00:00
|
|
|
}
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-06-10 21:42:41 +00:00
|
|
|
window.Run();
|
2023-01-13 15:13:56 +00:00
|
|
|
|
|
|
|
System::FreeResources();
|
2023-07-14 17:46:27 +00:00
|
|
|
CloseTmpFiles(0);
|
2023-01-13 15:13:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|