gBar/src/gBar.cpp

87 lines
1.8 KiB
C++
Raw Normal View History

2023-01-13 15:13:56 +00:00
#include "Window.h"
#include "Common.h"
#include "System.h"
#include "Bar.h"
#include "AudioFlyin.h"
#include "BluetoothDevices.h"
#include "Plugin.h"
#include "Config.h"
2023-01-13 15:13:56 +00:00
#include <cmath>
#include <cstdio>
#include <unistd.h>
const char* audioTmpFileOpen = "/tmp/gBar__audio";
static bool flyin = false;
void OpenAudioFlyin(Window& window, int32_t monitor, AudioFlyin::Type type)
{
flyin = true;
if (access(audioTmpFileOpen, F_OK) != 0)
{
FILE* audioTempFile = fopen(audioTmpFileOpen, "w");
AudioFlyin::Create(window, monitor, type);
fclose(audioTempFile);
}
else
{
// Already open, close
LOG("Audio flyin already open");
exit(0);
}
}
2023-01-13 15:13:56 +00:00
int main(int argc, char** argv)
{
System::Init();
int32_t monitor = -1;
if (argc >= 3)
{
monitor = atoi(argv[2]);
}
2023-06-10 21:42:41 +00:00
Window window(monitor);
window.Init(argc, argv);
2023-01-13 15:13:56 +00:00
ASSERT(argc >= 2, "Too little arguments!");
if (strcmp(argv[1], "bar") == 0)
{
Bar::Create(window, monitor);
}
else if (strcmp(argv[1], "audio") == 0)
{
OpenAudioFlyin(window, monitor, AudioFlyin::Type::Speaker);
}
else if (strcmp(argv[1], "mic") == 0)
{
OpenAudioFlyin(window, monitor, AudioFlyin::Type::Microphone);
2023-01-13 15:13:56 +00:00
}
#ifdef WITH_BLUEZ
else if (strcmp(argv[1], "bluetooth") == 0)
{
if (RuntimeConfig::Get().hasBlueZ)
{
BluetoothDevices::Create(window, monitor);
}
else
{
LOG("Blutooth disabled, cannot open bluetooth widget!");
exit(1);
}
}
#endif
else
{
Plugin::LoadWidgetFromPlugin(argv[1], window, monitor);
}
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();
if (flyin)
2023-01-13 15:13:56 +00:00
{
remove(audioTmpFileOpen);
}
return 0;
}