From 7449a0c44c578c1be4de1726349cf6d28d08f31b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 8 Apr 2022 22:07:40 +0200 Subject: [PATCH] Added default config & warning about it --- src/config/ConfigManager.cpp | 32 ++++++++++++++--- src/config/ConfigManager.hpp | 2 ++ src/config/defaultConfig.hpp | 68 ++++++++++++++++++++++++++++++++++++ src/includes.hpp | 1 + 4 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 src/config/defaultConfig.hpp diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4eb617b9..39e9409e 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -40,6 +40,8 @@ CConfigManager::CConfigManager() { configValues["input:kb_options"].strValue = ""; configValues["input:kb_rules"].strValue = ""; configValues["input:kb_model"].strValue = ""; + + configValues["autogenerated"].intValue = 0; } void CConfigManager::init() { @@ -289,14 +291,27 @@ void CConfigManager::loadConfigLoadVars() { const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf"); std::ifstream ifs; - ifs.open(CONFIGPATH.c_str()); + ifs.open(CONFIGPATH); if (!ifs.good()) { - Debug::log(WARN, "Config reading error. (No file?)"); - 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 = ""; @@ -335,6 +350,8 @@ void CConfigManager::loadConfigLoadVars() { // parseError will be displayed next frame if (parseError != "") g_pHyprError->queueCreate(parseError + "\nHyprland may not work correctly.", CColor(255, 50, 50, 255)); + else if (configValues["autogenerated"].intValue == 1) + g_pHyprError->queueCreate("Warning: You're using an autogenerated config! (config file: " + CONFIGPATH + " )\nSUPER+Enter -> kitty\nSUPER+T -> Alacritty\nSUPER+M -> exit Hyprland", CColor(255, 255, 70, 255)); else g_pHyprError->destroy(); } @@ -344,6 +361,11 @@ void CConfigManager::tick() { const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf"); + if (!std::filesystem::exists(CONFIGPATH)) { + loadConfigLoadVars(); + return; + } + struct stat fileStat; int err = stat(CONFIGPATH.c_str(), &fileStat); if (err != 0) { diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 8c38efa5..4537c4b8 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -10,6 +10,8 @@ #include #include "../Window.hpp" +#include "defaultConfig.hpp" + struct SConfigValue { int64_t intValue = -1; float floatValue = -1; diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp new file mode 100644 index 00000000..550d0601 --- /dev/null +++ b/src/config/defaultConfig.hpp @@ -0,0 +1,68 @@ +#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. + +monitor=,1920x1080@60,0x0,0.5,1 + +input { + kb_layout= + kb_variant= + kb_model= + kb_options= + kb_rules= +} + +general { + max_fps=60 + sensitivity=0.25 + main_mod=SUPER + + gaps_in=5 + gaps_out=20 + border_size=2 + col.active_border=0x66ee1111 + col.inactive_border=0x66333333 +} + +decoration { + rounding=10 +} + +animations { + enabled=1 + speed=7 + windows_speed=6 # specific speeds for components can be made with name_speed=float. 0 means use global (speed=float). If not set, will use the global value. + windows=1 + borders=1 + borders_speed=20 + fadein=1 # fade in AND out + fadein_speed=20 +} + +# basic binds +bind=SUPER,return,exec,kitty +bind=SUPER,T,exec,alacritty +bind=SUPER,C,killactive, +bind=SUPER,M,exec,pkill Hyprland +bind=SUPER,V,togglefloating, + +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 +bind=SUPER,0,workspace,10 +)#"; \ No newline at end of file diff --git a/src/includes.hpp b/src/includes.hpp index bc25a74a..7faefcfa 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #if true