2023-01-13 15:13:56 +00:00
|
|
|
#pragma once
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "Widget.h"
|
|
|
|
#include "Common.h"
|
|
|
|
|
|
|
|
enum class Anchor
|
|
|
|
{
|
|
|
|
Top = BIT(0),
|
|
|
|
Bottom = BIT(1),
|
|
|
|
Left = BIT(2),
|
|
|
|
Right = BIT(3)
|
|
|
|
};
|
|
|
|
DEFINE_ENUM_FLAGS(Anchor);
|
|
|
|
|
2023-10-21 14:40:41 +00:00
|
|
|
enum class Layer
|
|
|
|
{
|
|
|
|
Top,
|
|
|
|
Overlay
|
|
|
|
};
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
class Window
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Window() = default;
|
2023-06-10 21:42:41 +00:00
|
|
|
Window(int32_t monitor);
|
2024-03-15 18:18:47 +00:00
|
|
|
Window(const std::string& monitor);
|
2023-01-13 15:13:56 +00:00
|
|
|
Window(Window&& window) noexcept = default;
|
|
|
|
Window& operator=(Window&& other) noexcept = default;
|
|
|
|
~Window();
|
|
|
|
|
2024-01-21 16:13:45 +00:00
|
|
|
void Init(const std::string& overrideConfigLocation);
|
2023-06-10 21:42:41 +00:00
|
|
|
void Run();
|
2023-01-13 15:13:56 +00:00
|
|
|
|
|
|
|
void Close();
|
|
|
|
|
|
|
|
void SetAnchor(Anchor anchor) { m_Anchor = anchor; }
|
|
|
|
void SetMargin(Anchor anchor, int32_t margin);
|
|
|
|
void SetExclusive(bool exclusive) { m_Exclusive = exclusive; }
|
2024-03-15 18:18:47 +00:00
|
|
|
void SetLayer(Layer layer) { m_Layer = layer; }
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-06-10 21:42:41 +00:00
|
|
|
void SetMainWidget(std::unique_ptr<Widget>&& mainWidget);
|
|
|
|
|
2023-06-10 21:43:03 +00:00
|
|
|
int GetWidth() const;
|
2023-07-18 23:05:33 +00:00
|
|
|
int GetHeight() const;
|
2023-08-01 15:09:27 +00:00
|
|
|
|
2024-03-15 18:18:47 +00:00
|
|
|
// Returns the connector name of the currnet monitor
|
|
|
|
std::string GetName() const { return m_MonitorName; }
|
|
|
|
|
|
|
|
// Callback when the widget should be recreated
|
|
|
|
std::function<void()> OnWidget;
|
|
|
|
|
2023-01-13 15:13:56 +00:00
|
|
|
private:
|
2024-03-15 18:18:47 +00:00
|
|
|
void Create();
|
|
|
|
void Destroy();
|
|
|
|
|
2023-01-14 22:18:34 +00:00
|
|
|
void UpdateMargin();
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2023-01-28 16:29:10 +00:00
|
|
|
void LoadCSS(GtkCssProvider* provider);
|
|
|
|
|
2023-08-01 15:09:27 +00:00
|
|
|
void MonitorAdded(GdkDisplay* display, GdkMonitor* monitor);
|
|
|
|
void MonitorRemoved(GdkDisplay* display, GdkMonitor* monitor);
|
|
|
|
|
2023-06-10 21:42:41 +00:00
|
|
|
GtkWindow* m_Window = nullptr;
|
2023-01-13 15:13:56 +00:00
|
|
|
GtkApplication* m_App = nullptr;
|
|
|
|
|
|
|
|
std::unique_ptr<Widget> m_MainWidget;
|
|
|
|
|
|
|
|
Anchor m_Anchor;
|
2023-01-14 22:18:34 +00:00
|
|
|
std::array<std::pair<Anchor, int32_t>, 4> m_Margin;
|
2023-01-13 15:13:56 +00:00
|
|
|
bool m_Exclusive = true;
|
2023-10-21 14:40:41 +00:00
|
|
|
Layer m_Layer = Layer::Top;
|
2023-01-13 15:13:56 +00:00
|
|
|
|
2024-03-15 18:18:47 +00:00
|
|
|
// The monitor we are currently on.
|
|
|
|
std::string m_MonitorName;
|
|
|
|
|
|
|
|
// The monitor we want to be on.
|
|
|
|
std::string m_TargetMonitor;
|
|
|
|
|
2023-06-10 21:42:41 +00:00
|
|
|
GdkMonitor* m_Monitor = nullptr;
|
2024-03-15 18:18:47 +00:00
|
|
|
|
2024-03-15 18:29:56 +00:00
|
|
|
bool bShouldQuit = false;
|
2024-03-15 18:18:47 +00:00
|
|
|
bool bHandleMonitorChanges = false;
|
2023-01-13 15:13:56 +00:00
|
|
|
};
|