From 6f5172dd32a4fdaf5cf58ec10af61f5a3f8157cd Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 8 Apr 2022 22:19:37 +0200 Subject: [PATCH] Added autogenerated config + warning --- src/bar/Bar.cpp | 7 ++- src/config/ConfigManager.cpp | 28 ++++++++++-- src/config/ConfigManager.hpp | 2 + src/config/defaultConfig.hpp | 84 ++++++++++++++++++++++++++++++++++++ src/defines.hpp | 1 + 5 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 src/config/defaultConfig.hpp diff --git a/src/bar/Bar.cpp b/src/bar/Bar.cpp index b8ec70f..c0d87e5 100644 --- a/src/bar/Bar.cpp +++ b/src/bar/Bar.cpp @@ -431,10 +431,13 @@ int CStatusBar::getTextHalfY() { } void CStatusBar::drawErrorScreen() { - drawCairoRectangle(Vector2D(0, 0), m_vecSize, 0xFFaa1111); + if (ConfigManager::getInt("autogenerated") == 1) + drawCairoRectangle(Vector2D(0, 0), m_vecSize, 0xffffff33); + else + drawCairoRectangle(Vector2D(0, 0), m_vecSize, 0xFFaa1111); + drawText(Vector2D(1, getTextHalfY()), ConfigManager::parseError, 0xff000000, ConfigManager::getString("bar:font.main")); - // do all the drawing cuz we return later cairo_surface_flush(m_pCairoSurface); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1ee88f5..916b652 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -51,6 +51,8 @@ void ConfigManager::init() { configValues["animations:borders"].intValue = 1; configValues["animations:workspaces"].intValue = 0; + configValues["autogenerated"].intValue = 0; + if (!g_pWindowManager->statusBar) { isFirstLaunch = true; } @@ -348,11 +350,25 @@ void ConfigManager::loadConfigLoadVars() { ifs.open(CONFIGPATH.c_str()); if (!ifs.good()) { - Debug::log(WARN, "Config reading error. (No file?)"); - ConfigManager::parseError = "The config could not be read. (No file?)"; + Debug::log(WARN, "Config reading error. (No file? Attempting to generate, backing up old one if exists)"); + try { + std::filesystem::rename(CONFIGPATH, CONFIGPATH + ".backup"); + } catch (...) { /* Probably doesn't exist */ + } - ifs.close(); - return; + std::ofstream ofs; + ofs.open(CONFIGPATH, std::ios::trunc); + + ofs << AUTOCONFIG; + + ofs.close(); + + ifs.open(CONFIGPATH); + + if (!ifs.good()) { + parseError = "Broken config file! (Could not open)"; + return; + } } std::string line = ""; @@ -383,6 +399,10 @@ void ConfigManager::loadConfigLoadVars() { // recalc all workspaces g_pWindowManager->recalcAllWorkspaces(); + if (configValues["autogenerated"].intValue == 1) { + parseError = "Warning: You're using an autogenerated config! (config file: " + CONFIGPATH + " ) SUPER+Enter -> xterm SUPER+T -> Alacritty SUPER+M -> exit Hypr"; + } + // Reload the bar as well, don't load it before the default is loaded. if (loadBar && g_pWindowManager->statusBar && (configValues["bar:enabled"].intValue == 1 || parseError != "")) { g_pWindowManager->statusBar->destroy(); diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 3fe681f..1ecc217 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -6,6 +6,8 @@ #include "../defines.hpp" #include +#include "defaultConfig.hpp" + enum ELayouts { LAYOUT_DWINDLE = 0, LAYOUT_MASTER diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp new file mode 100644 index 0000000..46fdc0d --- /dev/null +++ b/src/config/defaultConfig.hpp @@ -0,0 +1,84 @@ +#pragma once + +#include + +inline const std::string AUTOCONFIG = R"#( +######################################################################################## +AUTOGENERATED HYPR CONFIG. +PLEASE USE THE CONFIG PROVIDED IN THE GIT REPO /examples/hypr.conf AND EDIT IT, +OR EDIT THIS ONE ACCORDING TO THE WIKI INSTRUCTIONS. +######################################################################################## + +autogenerated=1 # remove this line to get rid of the warning on top. + +gaps_in=5 +border_size=1 +gaps_out=20 +rounding=0 +max_fps=60 # max fps for updates of config & animations +focus_when_hover=1 # 0 - do not switch the focus when hover (only for tiling) +main_mod=SUPER # For moving, resizing +intelligent_transients=1 # keeps transients always on top. +no_unmap_saving=1 # disables saving unmapped windows (seems to break sometimes) +scratchpad_mon=0 # self-explanatory + +# Layout +layout=0 # 0 - dwindle (default), 1 - master +layout { + no_gaps_when_only=0 # disables gaps and borders when only window on screen +} + +# Bar config +Bar { + height=20 + monitor=0 + enabled=1 + mod_pad_in=8 + no_tray_saving=1 # using this doesnt save the tray between reloads but fixes an issue with the bar disappearing. + + font.main=Noto Sans + font.secondary=Noto Sans + + col.bg=0xff111111 + col.high=0xffff3333 + + module=left,X,0xff8000ff,0xffffffff,1,workspaces + module=pad,left,10 + module=left,,0xff7000dd,0xff7000dd,1,tray + module=right,X,0xffffffff,0xff00ff33,1000,$date +%a,\ %b\ %Y\ \ %I:%M\ %p$ +} + +# colors +col.active_border=0x77ff3333 +col.inactive_border=0x77222222 + +# animations +Animations { + enabled=1 + speed=5 + cheap=1 # highly recommended + borders=0 + workspaces=0 # not really recommended +} + +# keybinds +bind=SUPER,R,exec,dmenu_run +bind=SUPER,T,exec,alacritty +bind=SUPER,M,exec,pkill Hypr +bind=SUPER,RETURN,exec,xterm +bind=SUPER,G,exec,google-chrome-stable + +bind=SUPER,C,killactive, + +bind=SUPER,F,fullscreen, + +bind=SUPER,1,workspace,1 +bind=SUPER,2,workspace,2 +bind=SUPER,3,workspace,3 +bind=SUPER,4,workspace,4 +bind=SUPER,5,workspace,5 +bind=SUPER,6,workspace,6 +bind=SUPER,7,workspace,7 +bind=SUPER,8,workspace,8 +bind=SUPER,9,workspace,9 +)#"; \ No newline at end of file diff --git a/src/defines.hpp b/src/defines.hpp index 2615364..c147896 100644 --- a/src/defines.hpp +++ b/src/defines.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "./helpers/Vector.hpp" #include "./utilities/Debug.hpp"