kranewl

A wlroots-based dynamic Wayland compositor, written in C++, configurable with Lua
git clone git://git.deurzen.net/kranewl
Log | Files | Refs | LICENSE

commit f23757338401e8bebd3da3462de50984fba48618
parent 477325b3c93e39cb48e116fe14db6df5484beb18
Author: deurzen <max@deurzen.net>
Date:   Thu,  2 Jun 2022 16:26:55 +0200

reorders calls to compositor set up routines

Diffstat:
Minclude/kranewl/env.hh | 1+
Minclude/kranewl/model.hh | 3++-
Minclude/kranewl/server.hh | 6++++--
Msrc/kranewl/env.cc | 17+++++++++++++++++
Msrc/kranewl/main.cc | 10++++++----
Msrc/kranewl/model.cc | 15+++++++++------
6 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/include/kranewl/env.hh b/include/kranewl/env.hh @@ -2,4 +2,5 @@ #include <string> +bool file_exists(std::string const&); void parse_and_set_env_vars(std::string const&); diff --git a/include/kranewl/model.hh b/include/kranewl/model.hh @@ -38,7 +38,8 @@ public: Model(Config const&); ~Model(); - void initialize(std::string const&, std::optional<std::string>); + void evaluate_user_env_vars(std::string const&); + void run_user_autostart(std::optional<std::string>); void register_server(Server_ptr); void exit(); diff --git a/include/kranewl/server.hh b/include/kranewl/server.hh @@ -23,8 +23,10 @@ public: Server(Model_ptr); ~Server(); - void run() noexcept; - void terminate() noexcept; + void initialize(); + void start(); + void run(); + void terminate(); void relinquish_focus(); diff --git a/src/kranewl/env.cc b/src/kranewl/env.cc @@ -1,5 +1,9 @@ #include <kranewl/env.hh> +extern "C" { +#include <sys/stat.h> +} + #include <cctype> #include <cstdint> #include <cstdlib> @@ -9,6 +13,16 @@ #include <spdlog/spdlog.h> +bool +file_exists(std::string const& path) +{ + struct stat buffer; + if (!stat(path.c_str(), &buffer)) + return true; + + return false; +} + static inline std::string evaluate_value(std::string const& value) { @@ -34,6 +48,9 @@ evaluate_value(std::string const& value) void parse_and_set_env_vars(std::string const& env_path) { + if (!file_exists(env_path)) + return; + struct Assignment_ctype : std::ctype<char> { Assignment_ctype() : std::ctype<char>(get_table()) diff --git a/src/kranewl/main.cc b/src/kranewl/main.cc @@ -64,11 +64,13 @@ main(int argc, char** argv) Model model{config}; Server server{&model}; - model.initialize( - options.env_path, - options.autostart_path - ); + signal(SIGPIPE, SIG_IGN); + server.initialize(); + model.evaluate_user_env_vars(options.env_path); + server.start(); + model.run_user_autostart(options.autostart_path); server.run(); + return EXIT_SUCCESS; } diff --git a/src/kranewl/model.cc b/src/kranewl/model.cc @@ -98,17 +98,20 @@ Model::~Model() {} void -Model::initialize( - std::string const& env_path, - [[maybe_unused]] std::optional<std::string> autostart_path -) +Model::evaluate_user_env_vars(std::string const& env_path) { TRACE(); - parse_and_set_env_vars(env_path); +} +void +Model::run_user_autostart( + [[maybe_unused]] std::optional<std::string> autostart_path +) +{ + TRACE(); #ifdef NDEBUG - if (autostart_path) { + if (autostart_path && file_exists(*autostart_path)) { spdlog::info("Executing autostart file at {}", *autostart_path); exec_external(*autostart_path); }