mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-22 13:35:57 +01:00
Render bar fully with cairo to enable alpha blending
This commit is contained in:
parent
1a05147c92
commit
565bcd3e5f
2 changed files with 12 additions and 29 deletions
|
@ -175,7 +175,7 @@ void CStatusBar::setup(int MonitorID) {
|
||||||
m_iPixmap = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
m_iPixmap = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
||||||
xcb_create_pixmap(g_pWindowManager->DisplayConnection, g_pWindowManager->Depth, m_iPixmap, m_iWindowID, m_vecSize.x, m_vecSize.y);
|
xcb_create_pixmap(g_pWindowManager->DisplayConnection, g_pWindowManager->Depth, m_iPixmap, m_iWindowID, m_vecSize.x, m_vecSize.y);
|
||||||
|
|
||||||
// setup contexts.. ugh..
|
// setup contexts
|
||||||
|
|
||||||
auto contextBG = &m_mContexts["BG"];
|
auto contextBG = &m_mContexts["BG"];
|
||||||
contextBG->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
contextBG->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
||||||
|
@ -187,25 +187,6 @@ void CStatusBar::setup(int MonitorID) {
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
auto contextBGT = &m_mContexts["BGT"];
|
|
||||||
contextBGT->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
|
||||||
|
|
||||||
values[0] = 0x00000000;
|
|
||||||
values[1] = 0x00000000;
|
|
||||||
xcb_create_gc(g_pWindowManager->DisplayConnection, contextBGT->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, values);
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
auto contextHIGH = &m_mContexts["HIGH"];
|
|
||||||
contextHIGH->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
|
||||||
|
|
||||||
values[0] = ConfigManager::getInt("bar:col.high");
|
|
||||||
values[1] = ConfigManager::getInt("bar:col.high");
|
|
||||||
xcb_create_gc(g_pWindowManager->DisplayConnection, contextHIGH->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, values);
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
m_pCairoSurface = cairo_xcb_surface_create(g_pWindowManager->DisplayConnection, m_iPixmap, g_pWindowManager->VisualType,
|
m_pCairoSurface = cairo_xcb_surface_create(g_pWindowManager->DisplayConnection, m_iPixmap, g_pWindowManager->VisualType,
|
||||||
m_vecSize.x, m_vecSize.y);
|
m_vecSize.x, m_vecSize.y);
|
||||||
m_pCairo = cairo_create(m_pCairoSurface);
|
m_pCairo = cairo_create(m_pCairoSurface);
|
||||||
|
@ -247,6 +228,12 @@ void CStatusBar::drawText(Vector2D pos, std::string text, uint32_t color) {
|
||||||
cairo_show_text(m_pCairo, text.c_str());
|
cairo_show_text(m_pCairo, text.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CStatusBar::drawCairoRectangle(Vector2D pos, Vector2D size, uint32_t color) {
|
||||||
|
cairo_set_source_rgba(m_pCairo, RED(color), GREEN(color), BLUE(color), ALPHA(color));
|
||||||
|
cairo_rectangle(m_pCairo, pos.x, pos.y, size.x, size.y);
|
||||||
|
cairo_fill(m_pCairo);
|
||||||
|
}
|
||||||
|
|
||||||
int CStatusBar::getTextHalfY() {
|
int CStatusBar::getTextHalfY() {
|
||||||
return m_vecSize.y - (m_vecSize.y - 9) / 2.f;
|
return m_vecSize.y - (m_vecSize.y - 9) / 2.f;
|
||||||
}
|
}
|
||||||
|
@ -268,10 +255,7 @@ void CStatusBar::draw() {
|
||||||
cairo_restore(m_pCairo);
|
cairo_restore(m_pCairo);
|
||||||
//
|
//
|
||||||
|
|
||||||
if (ALPHA((uint32_t)ConfigManager::getInt("bar:col.bg")) != 0) {
|
drawCairoRectangle(Vector2D(0, 0), m_vecSize, ConfigManager::getInt("bar:col.bg"));
|
||||||
xcb_rectangle_t rectangles[] = {{(int)0, (int)0, (int)m_vecSize.x, (int)m_vecSize.y}};
|
|
||||||
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, m_mContexts["BG"].GContext, 1, rectangles);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -325,8 +309,7 @@ int CStatusBar::drawWorkspacesModule(SBarModule* mod, int off) {
|
||||||
|
|
||||||
std::string workspaceName = std::to_string(openWorkspaces[i]);
|
std::string workspaceName = std::to_string(openWorkspaces[i]);
|
||||||
|
|
||||||
xcb_rectangle_t rectangleActive[] = {{off + m_vecSize.y * drawnWorkspaces, 0, m_vecSize.y, m_vecSize.y}};
|
drawCairoRectangle(Vector2D(off + m_vecSize.y * drawnWorkspaces, 0), Vector2D(m_vecSize.y, m_vecSize.y), WORKSPACE == MOUSEWORKSPACEID ? ConfigManager::getInt("bar:col.high") : ConfigManager::getInt("bar:col.bg"));
|
||||||
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, WORKSPACE == MOUSEWORKSPACEID ? m_mContexts["HIGH"].GContext : m_mContexts["BG"].GContext, 1, rectangleActive);
|
|
||||||
|
|
||||||
drawText(Vector2D(off + m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - getTextWidth(workspaceName) / 2.f, getTextHalfY()),
|
drawText(Vector2D(off + m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - getTextWidth(workspaceName) / 2.f, getTextHalfY()),
|
||||||
workspaceName, WORKSPACE == MOUSEWORKSPACEID ? 0xFF111111 : 0xFFFFFFFF);
|
workspaceName, WORKSPACE == MOUSEWORKSPACEID ? 0xFF111111 : 0xFFFFFFFF);
|
||||||
|
@ -372,8 +355,7 @@ int CStatusBar::drawModule(SBarModule* mod, int off) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
xcb_rectangle_t rects[] = {{ position.x, position.y, MODULEWIDTH, m_vecSize.y }};
|
drawCairoRectangle(position, Vector2D(MODULEWIDTH, m_vecSize.y), mod->bgcolor);
|
||||||
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, mod->bgcontext, 1, rects);
|
|
||||||
|
|
||||||
drawText(position + Vector2D(PAD / 2, getTextHalfY()), mod->valueCalculated, mod->color);
|
drawText(position + Vector2D(PAD / 2, getTextHalfY()), mod->valueCalculated, mod->color);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ struct SBarModule {
|
||||||
uint64_t updateEveryMs;
|
uint64_t updateEveryMs;
|
||||||
std::chrono::system_clock::time_point updateLast;
|
std::chrono::system_clock::time_point updateLast;
|
||||||
|
|
||||||
xcb_gcontext_t bgcontext = NULL;
|
xcb_gcontext_t bgcontext = NULL; // deprecated
|
||||||
|
|
||||||
// PADS
|
// PADS
|
||||||
bool isPad = false;
|
bool isPad = false;
|
||||||
|
@ -68,6 +68,7 @@ private:
|
||||||
cairo_t* m_pCairo = nullptr;
|
cairo_t* m_pCairo = nullptr;
|
||||||
|
|
||||||
void drawText(Vector2D, std::string, uint32_t);
|
void drawText(Vector2D, std::string, uint32_t);
|
||||||
|
void drawCairoRectangle(Vector2D, Vector2D, uint32_t);
|
||||||
int getTextWidth(std::string);
|
int getTextWidth(std::string);
|
||||||
int drawModule(SBarModule*, int);
|
int drawModule(SBarModule*, int);
|
||||||
int drawWorkspacesModule(SBarModule*, int);
|
int drawWorkspacesModule(SBarModule*, int);
|
||||||
|
|
Loading…
Reference in a new issue