YggdrasilWM  0.1.1
A tiny window manager coded in C++
main.cpp File Reference

Main file. More...

#include <cstdlib>
#include <memory>
#include <cxxopts.hpp>
#include "WindowManager.hpp"
#include "Logger.hpp"
#include "Config/ConfigHandler.hpp"
#include "X11wrapper/baseX11Wrapper.hpp"
#include "X11wrapper/X11Wrapper.hpp"
#include "EventHandler.hpp"
Include dependency graph for main.cpp:

Functions

int main (int argc, char **argv)
 YggdrasilWM Uses cxxopts to parse command line arguments and starts the WindowManager. creates a Logger and a ConfigHandler. More...
 

Detailed Description

Main file.

Yb dP 8 w 8 Yb dP 8b d8 YbdP .d88 .d88 .d88 8d8b .d88 d88b w 8 Yb db dP 8YbmdP8 YP 8 8 8 8 8 8 8P 8 8 Yb. 8 8 YbdPYbdP 8 " 8 88Y88 Y88Y88 8 `Y88 Y88P 8 8 YP YP 8 8 wwdP wwdP Yggdrasil Window Manager https://github.com/corecaps/YggdrasilWM Copyright (C) 2024 jgarcia jgarc.nosp@m.ia@s.nosp@m.tuden.nosp@m.t.42.nosp@m..fr corec.nosp@m.aps@.nosp@m.gmail.nosp@m..com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Date
2024-02-11 YggdrasilWM is a tiny window manager for X11.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

YggdrasilWM Uses cxxopts to parse command line arguments and starts the WindowManager. creates a Logger and a ConfigHandler.

45  {
46  std::cout << " YggdrasilWM Copyright (C) 2024 corecaps <corecaps@gmail.com> <jgarcia@student.42.fr>\n"
47  " This program comes with ABSOLUTELY NO WARRANTY.This is free software, and you are welcome\n"
48  " to redistribute it under certain conditions.\n"
49  " See the LICENCE file for more informations" << std::endl;
50  cxxopts::Options options(PROGRAM_NAME, "YggdrasilWM by corecaps. https://github.com/corecaps/YggdrasilWM");
51  options.add_options()
52  ("h,help", "Print help")
53  ("v,version", "display version", cxxopts::value<bool>())
54  ("l,log", "Specify the log file path", cxxopts::value<std::string>())
55  ("loglevel", "Specify the log level (0-2)", cxxopts::value<int>())
56  ("c,config", "Specify the config file path", cxxopts::value<std::string>())
57  ("d,display", "Specify the display to use", cxxopts::value<std::string>());
58  std::string logFilePath;
59  std::string display;
60  std::string configFilePath;
61  int logLevel = 0;
62  try {
63  auto result = options.parse(argc, argv);
64  if (result.count("help")) {
65  std::cout << options.help() << std::endl;
66  return EXIT_SUCCESS;
67  }
68  if (result["version"].as<bool>()) {
69  std::cout << PROGRAM_NAME << "\t" << PROGRAM_VERSION << "\n" << std::endl;
70  return EXIT_SUCCESS;
71  }
72  if (result.count("log")) {
73  logFilePath = result["log"].as<std::string>();
74  } else {
75  logFilePath = "wm.log";
76  }
77  if (result.count("loglevel")) {
78  logLevel = result["loglevel"].as<int>();
79  if (logLevel < 0 || logLevel > 2) {
80  std::cerr << "Invalid log level. It should be between 0 and 2." << std::endl;
81  return EXIT_FAILURE;
82  }
83  }
84  if (result.count("config")) {
85  configFilePath = result["config"].as<std::string>();
86  } else {
87  configFilePath = "";
88  }
89  if (result.count("display")) {
90  display = result["display"].as<std::string>();
91  } else {
92  display = "";
93  }
94  } catch (const cxxopts::OptionException &e) {
95  std::cerr << "Error parsing options: " << e.what() << std::endl;
96  std::cout << options.help() << std::endl;
97  return EXIT_FAILURE;
98  }
99  std::shared_ptr<BaseX11Wrapper> x11Wrapper = std::make_shared<X11Wrapper>();
100  // Logger::create(logFilePath, static_cast<LogLevel>(logLevel));
101  Logger::Create(std::cout, static_cast<LogLevel>(logLevel));
102  if (configFilePath.empty()) {
104  } else {
105  ConfigHandler::Create(configFilePath);
106  }
108  Logger::GetInstance()->Log("Starting " + std::string(PROGRAM_NAME) + " " + std::string(PROGRAM_VERSION), L_INFO);
109  try {
110  if (!display.empty()) {
111  Logger::GetInstance()->Log("Using display " + display, L_INFO);
112  WindowManager::create(x11Wrapper,display);
113  } else {
114  Logger::GetInstance()->Log("Using default display", L_INFO);
115  WindowManager::create(x11Wrapper);
116  }
117  } catch (const std::exception &e) {
118  Logger::GetInstance()->Log(e.what(), L_ERROR);
119  return EXIT_FAILURE;
120  }
121  try {
123  } catch (const std::exception &e) {
124  Logger::GetInstance()->Log(e.what(), L_ERROR);
125  return EXIT_FAILURE;
126  }
129  Logger::GetInstance()->Log("Exiting " + std::string(PROGRAM_NAME) + " " + std::string(PROGRAM_VERSION), L_INFO);
132  Logger::Destroy();
133  return (EXIT_SUCCESS);
134 }
LogLevel
Log levels L_INFO: Informational messages L_WARNING: Warning messages L_ERROR: Error messages.
Definition: Logger.hpp:48
@ L_ERROR
Definition: Logger.hpp:51
@ L_INFO
Definition: Logger.hpp:49
static ConfigHandler & GetInstance()
Get the ConfigHandler object Throws an exception if the object is not created.
Definition: ConfigHandler.cpp:46
static void Destroy()
Destroy the ConfigHandler object.
Definition: ConfigHandler.cpp:52
void configInit()
Initialize the ConfigHandler Read the configuration file and store the JSon root object in Json::Valu...
Definition: ConfigHandler.cpp:65
static void Create()
Definition: ConfigHandler.cpp:41
static void destroy()
Definition: EventHandler.cpp:392
virtual void Log(const std::string &message, LogLevel level) const
Log a message This method logs a message to the log file or stream. The message is only logged if the...
Definition: Logger.cpp:73
static void Create(const std::string &logFile, LogLevel logLevel)
Definition: Logger.cpp:31
static void Destroy()
Destroy the Logger:: Logger object closes the log file if it was opened.
Definition: Logger.cpp:99
static Logger * GetInstance()
Get the Logger object.
Definition: Logger.cpp:41
static void create(std::shared_ptr< BaseX11Wrapper > wrapper, const std::string &displayStr=std::string())
create a WindowManager object
Definition: WindowManager.cpp:45
void init()
Initialize the WindowManager set the event select mask on the root window creates clients for the exi...
Definition: WindowManager.cpp:76
void Run()
Run the window manager.
Definition: WindowManager.cpp:170
static WindowManager * getInstance()
Get the WindowManager instance this is a singleton class this function returns the instance of the Wi...
Definition: WindowManager.cpp:244
static void Destroy()
Destroy the WindowManager instance this function destroys the WindowManager instance and sets the ins...
Definition: WindowManager.cpp:213

References ConfigHandler::configInit(), ConfigHandler::Create(), Logger::Create(), WindowManager::create(), ConfigHandler::Destroy(), EventHandler::destroy(), Logger::Destroy(), WindowManager::Destroy(), ConfigHandler::GetInstance(), Logger::GetInstance(), WindowManager::getInstance(), WindowManager::init(), L_ERROR, L_INFO, Logger::Log(), and WindowManager::Run().

Here is the call graph for this function: