Hypr/src/bar/Bar.hpp

80 lines
2 KiB
C++
Raw Normal View History

2021-11-21 11:25:26 +01:00
#pragma once
#include <unordered_map>
#include "../defines.hpp"
#include "../ipc/ipc.hpp"
2021-11-27 19:07:33 +01:00
#include "BarCommands.hpp"
#include <chrono>
2021-11-21 11:25:26 +01:00
struct SDrawingContext {
xcb_gcontext_t GContext;
xcb_font_t Font;
};
2021-11-27 19:07:33 +01:00
enum ModuleAlignment {
LEFT = 0,
CENTER,
RIGHT
};
struct SBarModule {
ModuleAlignment alignment;
std::string value;
std::string valueCalculated = "";
uint64_t color;
uint64_t bgcolor;
uint64_t updateEveryMs;
std::chrono::system_clock::time_point updateLast;
xcb_gcontext_t bgcontext = NULL;
// PADS
bool isPad = false;
int pad = 0;
};
2021-11-21 11:25:26 +01:00
class CStatusBar {
public:
EXPOSED_MEMBER(WindowID, xcb_window_t, i);
2021-11-21 17:40:02 +01:00
EXPOSED_MEMBER(MonitorID, int, i);
2021-11-24 19:17:13 +01:00
EXPOSED_MEMBER(StatusCommand, std::string, sz); // TODO: make the bar better
2021-11-27 19:07:33 +01:00
EXPOSED_MEMBER(LastWindowName, std::string, sz);
2021-11-27 20:24:50 +01:00
EXPOSED_MEMBER(IsCovered, bool, b);
2021-11-21 11:25:26 +01:00
void draw();
2021-11-21 20:40:22 +01:00
void setup(int MonitorID);
2021-11-21 12:40:03 +01:00
void destroy();
2021-11-27 19:07:33 +01:00
void setupModule(SBarModule*);
void destroyModule(SBarModule*);
2021-11-21 11:25:26 +01:00
std::vector<int> openWorkspaces;
EXPOSED_MEMBER(CurrentWorkspace, int, i);
2021-11-27 19:07:33 +01:00
std::vector<SBarModule> modules;
2021-11-21 11:25:26 +01:00
private:
Vector2D m_vecSize;
Vector2D m_vecPosition;
xcb_pixmap_t m_iPixmap;
// Cairo
cairo_surface_t* m_pCairoSurface = nullptr;
cairo_t* m_pCairo = nullptr;
void drawText(Vector2D, std::string, uint32_t);
int getTextWidth(std::string);
2021-11-27 19:07:33 +01:00
int drawModule(SBarModule*, int);
int drawWorkspacesModule(SBarModule*, int);
int getTextHalfY();
2021-11-21 11:25:26 +01:00
std::unordered_map<std::string, SDrawingContext> m_mContexts;
};
// Main thread for the bar. Is only initted once in main.cpp so we can do this.
int64_t barMainThread();