mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
Initialise GTK early
This commit is contained in:
parent
2a66f1d64c
commit
6815d8e017
6 changed files with 39 additions and 20 deletions
|
@ -149,8 +149,8 @@ namespace AudioFlyin
|
|||
padding = Widget::Create<Box>();
|
||||
mainWidget->AddChild(std::move(padding));
|
||||
|
||||
window = Window(std::move(mainWidget), monitor);
|
||||
window.SetExclusive(false);
|
||||
window.SetAnchor(Anchor::Bottom);
|
||||
window.SetMainWidget(std::move(mainWidget));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -739,7 +739,7 @@ namespace Bar
|
|||
mainWidget->AddChild(std::move(time));
|
||||
mainWidget->AddChild(std::move(right));
|
||||
}
|
||||
window = Window(std::move(mainWidget), monitor);
|
||||
window.SetAnchor(Anchor::Left | Anchor::Right | Anchor::Top);
|
||||
window.SetMainWidget(std::move(mainWidget));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,10 +298,10 @@ namespace BluetoothDevices
|
|||
WidgetHeader(*mainWidget);
|
||||
WidgetBody(*mainWidget);
|
||||
|
||||
window = Window(std::move(mainWidget), monitor);
|
||||
window.SetExclusive(false);
|
||||
window.SetMargin(Anchor::Top, 8);
|
||||
window.SetAnchor(Anchor::Right | Anchor::Top);
|
||||
window.SetMainWidget(std::move(mainWidget));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <gtk-layer-shell.h>
|
||||
|
||||
Window::Window(std::unique_ptr<Widget>&& mainWidget, int32_t monitor) : m_MainWidget(std::move(mainWidget)), m_Monitor(monitor) {}
|
||||
Window::Window(int32_t monitor) : m_MonitorID(monitor) {}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ Window::~Window()
|
|||
}
|
||||
}
|
||||
|
||||
void Window::Run(int argc, char** argv)
|
||||
void Window::Init(int argc, char** argv)
|
||||
{
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
|
@ -28,6 +28,23 @@ void Window::Run(int argc, char** argv)
|
|||
|
||||
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), (GtkStyleProvider*)CSS::GetProvider(), GTK_STYLE_PROVIDER_PRIORITY_USER);
|
||||
|
||||
GdkDisplay* defaultDisplay = gdk_display_get_default();
|
||||
ASSERT(defaultDisplay != nullptr, "Cannot get display!");
|
||||
if (m_MonitorID != -1)
|
||||
{
|
||||
m_Monitor = gdk_display_get_monitor(defaultDisplay, m_MonitorID);
|
||||
ASSERT(m_Monitor, "Cannot get monitor!");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Monitor = gdk_display_get_primary_monitor(defaultDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::Run()
|
||||
{
|
||||
ASSERT(m_MainWidget, "Main Widget not set!");
|
||||
|
||||
m_Window = (GtkWindow*)gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
|
||||
gtk_layer_init_for_window(m_Window);
|
||||
|
@ -35,15 +52,7 @@ void Window::Run(int argc, char** argv)
|
|||
if (m_Exclusive)
|
||||
gtk_layer_auto_exclusive_zone_enable(m_Window);
|
||||
|
||||
GdkDisplay* defaultDisplay = gdk_display_get_default();
|
||||
ASSERT(defaultDisplay != nullptr, "Cannot get display!");
|
||||
GdkMonitor* selectedMon = nullptr;
|
||||
if (m_Monitor != -1)
|
||||
{
|
||||
selectedMon = gdk_display_get_monitor(defaultDisplay, m_Monitor);
|
||||
ASSERT(selectedMon != nullptr, "Cannot get monitor!");
|
||||
gtk_layer_set_monitor(m_Window, selectedMon);
|
||||
}
|
||||
gtk_layer_set_monitor(m_Window, m_Monitor);
|
||||
|
||||
if (FLAG_CHECK(m_Anchor, Anchor::Left))
|
||||
{
|
||||
|
@ -100,6 +109,11 @@ void Window::UpdateMargin()
|
|||
}
|
||||
}
|
||||
|
||||
void Window::SetMainWidget(std::unique_ptr<Widget>&& mainWidget)
|
||||
{
|
||||
m_MainWidget = std::move(mainWidget);
|
||||
}
|
||||
|
||||
void Window::SetMargin(Anchor anchor, int32_t margin)
|
||||
{
|
||||
if (FLAG_CHECK(anchor, Anchor::Left))
|
||||
|
|
12
src/Window.h
12
src/Window.h
|
@ -16,12 +16,13 @@ class Window
|
|||
{
|
||||
public:
|
||||
Window() = default;
|
||||
Window(std::unique_ptr<Widget>&& mainWidget, int32_t monitor);
|
||||
Window(int32_t monitor);
|
||||
Window(Window&& window) noexcept = default;
|
||||
Window& operator=(Window&& other) noexcept = default;
|
||||
~Window();
|
||||
|
||||
void Run(int argc, char** argv);
|
||||
void Init(int argc, char** argv);
|
||||
void Run();
|
||||
|
||||
void Close();
|
||||
|
||||
|
@ -29,12 +30,14 @@ public:
|
|||
void SetMargin(Anchor anchor, int32_t margin);
|
||||
void SetExclusive(bool exclusive) { m_Exclusive = exclusive; }
|
||||
|
||||
void SetMainWidget(std::unique_ptr<Widget>&& mainWidget);
|
||||
|
||||
private:
|
||||
void UpdateMargin();
|
||||
|
||||
void LoadCSS(GtkCssProvider* provider);
|
||||
|
||||
GtkWindow* m_Window;
|
||||
GtkWindow* m_Window = nullptr;
|
||||
GtkApplication* m_App = nullptr;
|
||||
|
||||
std::unique_ptr<Widget> m_MainWidget;
|
||||
|
@ -43,5 +46,6 @@ private:
|
|||
std::array<std::pair<Anchor, int32_t>, 4> m_Margin;
|
||||
bool m_Exclusive = true;
|
||||
|
||||
int32_t m_Monitor;
|
||||
int32_t m_MonitorID;
|
||||
GdkMonitor* m_Monitor = nullptr;
|
||||
};
|
||||
|
|
|
@ -41,7 +41,8 @@ int main(int argc, char** argv)
|
|||
monitor = atoi(argv[2]);
|
||||
}
|
||||
|
||||
Window window;
|
||||
Window window(monitor);
|
||||
window.Init(argc, argv);
|
||||
ASSERT(argc >= 2, "Too little arguments!");
|
||||
if (strcmp(argv[1], "bar") == 0)
|
||||
{
|
||||
|
@ -74,7 +75,7 @@ int main(int argc, char** argv)
|
|||
Plugin::LoadWidgetFromPlugin(argv[1], window, monitor);
|
||||
}
|
||||
|
||||
window.Run(argc, argv);
|
||||
window.Run();
|
||||
|
||||
System::FreeResources();
|
||||
if (flyin)
|
||||
|
|
Loading…
Reference in a new issue