mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-22 13:35:57 +01:00
Added icons to the status bar
This commit is contained in:
parent
acb177bf4d
commit
2d82458260
4 changed files with 35 additions and 22 deletions
|
@ -19,12 +19,16 @@ Bar {
|
|||
height=20
|
||||
monitor=0
|
||||
enabled=1
|
||||
mod_pad_in=8
|
||||
|
||||
font.main=Noto Sans
|
||||
font.secondary=Noto Sans
|
||||
|
||||
col.bg=0xff111111
|
||||
col.high=0xffff3333
|
||||
|
||||
module=left,0xff8000ff,0xffffffff,1,workspaces
|
||||
module=right,0xffffffff,0xff00ff33,1000,$date +%a,\ %b\ %Y\ \ %I:%M\ %p$
|
||||
module=left,X,0xff8000ff,0xffffffff,1,workspaces
|
||||
module=right,X,0xffffffff,0xff00ff33,1000,$date +%a,\ %b\ %Y\ \ %I:%M\ %p$
|
||||
}
|
||||
|
||||
# colors
|
||||
|
|
|
@ -210,8 +210,8 @@ void CStatusBar::destroy() {
|
|||
m_pCairo = nullptr;
|
||||
}
|
||||
|
||||
int CStatusBar::getTextWidth(std::string text) {
|
||||
cairo_select_font_face(m_pCairo, "Noto Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||
int CStatusBar::getTextWidth(std::string text, std::string font) {
|
||||
cairo_select_font_face(m_pCairo, font.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||
cairo_set_font_size(m_pCairo, 12);
|
||||
|
||||
cairo_text_extents_t textextents;
|
||||
|
@ -220,8 +220,8 @@ int CStatusBar::getTextWidth(std::string text) {
|
|||
return textextents.width + 1 /* pad */;
|
||||
}
|
||||
|
||||
void CStatusBar::drawText(Vector2D pos, std::string text, uint32_t color) {
|
||||
cairo_select_font_face(m_pCairo, "Noto Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||
void CStatusBar::drawText(Vector2D pos, std::string text, uint32_t color, std::string font) {
|
||||
cairo_select_font_face(m_pCairo, font.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||
cairo_set_font_size(m_pCairo, 12);
|
||||
cairo_set_source_rgba(m_pCairo, RED(color), GREEN(color), BLUE(color), ALPHA(color));
|
||||
cairo_move_to(m_pCairo, pos.x, pos.y);
|
||||
|
@ -311,8 +311,8 @@ int CStatusBar::drawWorkspacesModule(SBarModule* mod, int off) {
|
|||
|
||||
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"));
|
||||
|
||||
drawText(Vector2D(off + m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - getTextWidth(workspaceName) / 2.f, getTextHalfY()),
|
||||
workspaceName, WORKSPACE == MOUSEWORKSPACEID ? 0xFF111111 : 0xFFFFFFFF);
|
||||
drawText(Vector2D(off + m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - getTextWidth(workspaceName, ConfigManager::getString("bar:font.main")) / 2.f, getTextHalfY()),
|
||||
workspaceName, WORKSPACE == MOUSEWORKSPACEID ? 0xFF111111 : 0xFFFFFFFF, ConfigManager::getString("bar:font.main"));
|
||||
|
||||
drawnWorkspaces++;
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ int CStatusBar::drawModule(SBarModule* mod, int off) {
|
|||
if (mod->isPad)
|
||||
return mod->pad;
|
||||
|
||||
const int PAD = 4;
|
||||
const int PAD = ConfigManager::getInt("bar:mod_pad_in");
|
||||
|
||||
// check if we need to update
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - mod->updateLast).count() > mod->updateEveryMs) {
|
||||
|
@ -337,7 +337,8 @@ int CStatusBar::drawModule(SBarModule* mod, int off) {
|
|||
|
||||
// We have the value, draw the module!
|
||||
|
||||
const auto MODULEWIDTH = getTextWidth(mod->valueCalculated) + PAD;
|
||||
const auto MODULEWIDTH = getTextWidth(mod->valueCalculated, ConfigManager::getString("bar:font.main")) + PAD;
|
||||
const auto ICONWIDTH = getTextWidth(mod->icon, ConfigManager::getString("bar:font.secondary"));
|
||||
|
||||
if (!MODULEWIDTH || mod->valueCalculated == "")
|
||||
return 0; // empty module
|
||||
|
@ -348,16 +349,17 @@ int CStatusBar::drawModule(SBarModule* mod, int off) {
|
|||
position = Vector2D(off, 0);
|
||||
break;
|
||||
case RIGHT:
|
||||
position = Vector2D(m_vecSize.x - off - MODULEWIDTH, 0);
|
||||
position = Vector2D(m_vecSize.x - off - MODULEWIDTH - ICONWIDTH, 0);
|
||||
break;
|
||||
case CENTER:
|
||||
position = Vector2D(m_vecSize.x / 2.f - MODULEWIDTH / 2.f, 0);
|
||||
position = Vector2D(m_vecSize.x / 2.f - (MODULEWIDTH + ICONWIDTH) / 2.f, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
drawCairoRectangle(position, Vector2D(MODULEWIDTH, m_vecSize.y), mod->bgcolor);
|
||||
drawCairoRectangle(position, Vector2D(MODULEWIDTH + ICONWIDTH, m_vecSize.y), mod->bgcolor);
|
||||
|
||||
drawText(position + Vector2D(PAD / 2, getTextHalfY()), mod->valueCalculated, mod->color);
|
||||
drawText(position + Vector2D(PAD / 2, getTextHalfY()), mod->icon, mod->color, ConfigManager::getString("bar:font.secondary"));
|
||||
drawText(position + Vector2D(PAD / 2 + ICONWIDTH, getTextHalfY()), mod->valueCalculated, mod->color, ConfigManager::getString("bar:font.main"));
|
||||
|
||||
return MODULEWIDTH;
|
||||
return MODULEWIDTH + ICONWIDTH;
|
||||
}
|
|
@ -21,6 +21,7 @@ enum ModuleAlignment {
|
|||
struct SBarModule {
|
||||
ModuleAlignment alignment;
|
||||
std::string value;
|
||||
std::string icon;
|
||||
std::string valueCalculated = "";
|
||||
uint64_t color;
|
||||
uint64_t bgcolor;
|
||||
|
@ -67,9 +68,9 @@ private:
|
|||
cairo_surface_t* m_pCairoSurface = nullptr;
|
||||
cairo_t* m_pCairo = nullptr;
|
||||
|
||||
void drawText(Vector2D, std::string, uint32_t);
|
||||
void drawText(Vector2D, std::string, uint32_t, std::string);
|
||||
void drawCairoRectangle(Vector2D, Vector2D, uint32_t);
|
||||
int getTextWidth(std::string);
|
||||
int getTextWidth(std::string, std::string);
|
||||
int drawModule(SBarModule*, int);
|
||||
int drawWorkspacesModule(SBarModule*, int);
|
||||
int getTextHalfY();
|
||||
|
|
|
@ -22,15 +22,16 @@ void ConfigManager::init() {
|
|||
configValues["bar:height"].intValue = 15;
|
||||
configValues["bar:col.bg"].intValue = 0xFF111111;
|
||||
configValues["bar:col.high"].intValue = 0xFFFF3333;
|
||||
configValues["bar:font.main"].strValue = "Noto Sans";
|
||||
configValues["bar:font.secondary"].strValue = "Noto Sans";
|
||||
configValues["bar:mod_pad_in"].intValue = 4;
|
||||
|
||||
configValues["status_command"].strValue = "date +%I:%M\\ %p"; // Time
|
||||
|
||||
configValues["status_command"].strValue = "date +%I:%M\\ %p"; // Time // Deprecated
|
||||
|
||||
// Set Colors ARGB
|
||||
configValues["col.active_border"].intValue = 0x77FF3333;
|
||||
configValues["col.inactive_border"].intValue = 0x77222222;
|
||||
|
||||
|
||||
// animations
|
||||
configValues["anim.speed"].floatValue = 1;
|
||||
configValues["anim.enabled"].intValue = 1;
|
||||
|
@ -163,6 +164,9 @@ void parseModule(const std::string& COMMANDC, const std::string& VALUE) {
|
|||
return;
|
||||
}
|
||||
|
||||
const auto ICON = valueCopy.substr(0, valueCopy.find_first_of(","));
|
||||
valueCopy = valueCopy.substr(valueCopy.find_first_of(",") + 1);
|
||||
|
||||
const auto COL1 = valueCopy.substr(0, valueCopy.find_first_of(","));
|
||||
valueCopy = valueCopy.substr(valueCopy.find_first_of(",") + 1);
|
||||
|
||||
|
@ -193,6 +197,8 @@ void parseModule(const std::string& COMMANDC, const std::string& VALUE) {
|
|||
return;
|
||||
}
|
||||
|
||||
module.icon = ICON;
|
||||
|
||||
module.value = COMMAND;
|
||||
|
||||
g_pWindowManager->statusBar->modules.push_back(module);
|
||||
|
@ -292,7 +298,7 @@ void ConfigManager::loadConfigLoadVars() {
|
|||
|
||||
const char* const ENVHOME = getenv("HOME");
|
||||
|
||||
const std::string CONFIGPATH = ENVHOME + (std::string) "/.config/hypr/hypr.conf";
|
||||
const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprd.conf" : (std::string) "/.config/hypr/hypr.conf");
|
||||
|
||||
std::ifstream ifs;
|
||||
ifs.open(CONFIGPATH.c_str());
|
||||
|
@ -364,7 +370,7 @@ void ConfigManager::applyKeybindsToX() {
|
|||
void ConfigManager::tick() {
|
||||
const char* const ENVHOME = getenv("HOME");
|
||||
|
||||
const std::string CONFIGPATH = ENVHOME + (std::string)"/.config/hypr/hypr.conf";
|
||||
const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprd.conf" : (std::string) "/.config/hypr/hypr.conf");
|
||||
|
||||
struct stat fileStat;
|
||||
int err = stat(CONFIGPATH.c_str(), &fileStat);
|
||||
|
|
Loading…
Reference in a new issue