2022-03-16 20:50:55 +01:00
|
|
|
#include "defines.hpp"
|
|
|
|
#include "debug/Log.hpp"
|
2022-03-16 21:37:21 +01:00
|
|
|
#include "Compositor.hpp"
|
2022-03-17 15:53:45 +01:00
|
|
|
#include "config/ConfigManager.hpp"
|
2022-05-19 19:28:15 +02:00
|
|
|
#include "init/initHelpers.hpp"
|
2023-04-07 16:03:26 +02:00
|
|
|
|
2022-06-03 17:48:07 +02:00
|
|
|
#include <iostream>
|
2023-04-07 16:03:26 +02:00
|
|
|
#include <iterator>
|
|
|
|
#include <vector>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
void help() {
|
|
|
|
std::cout << "usage: Hyprland [arg [...]].\n";
|
|
|
|
std::cout << "\nArguments:\n";
|
|
|
|
std::cout << " --help -h - Show this message again\n";
|
|
|
|
std::cout << " --config FILE -c FILE - Specify config file to use\n";
|
|
|
|
std::cout << " --i-am-really-stupid - Omits root user privileges check (why would you do that?)\n";
|
|
|
|
}
|
|
|
|
|
2022-03-16 20:50:55 +01:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
|
|
|
|
if (!getenv("XDG_RUNTIME_DIR"))
|
2022-07-06 16:17:58 +02:00
|
|
|
throw std::runtime_error("XDG_RUNTIME_DIR is not set!");
|
2022-03-16 20:50:55 +01:00
|
|
|
|
2022-09-19 22:06:44 +02:00
|
|
|
// export HYPRLAND_CMD
|
|
|
|
std::string cmd = "";
|
|
|
|
for (auto i = 0; i < argc; ++i)
|
|
|
|
cmd += std::string(i == 0 ? "" : " ") + argv[i];
|
2023-04-07 16:03:26 +02:00
|
|
|
|
2022-09-19 22:06:44 +02:00
|
|
|
setenv("HYPRLAND_CMD", cmd.c_str(), 1);
|
2022-11-19 20:37:16 +01:00
|
|
|
setenv("XDG_BACKEND", "wayland", 1);
|
2023-01-09 21:26:19 +01:00
|
|
|
setenv("_JAVA_AWT_WM_NONREPARENTING", "1", 1);
|
2023-03-05 14:37:21 +01:00
|
|
|
setenv("MOZ_ENABLE_WAYLAND", "1", 1);
|
|
|
|
setenv("XDG_CURRENT_DESKTOP", "Hyprland", 1);
|
2022-09-19 22:06:44 +02:00
|
|
|
|
2022-05-19 19:28:15 +02:00
|
|
|
// parse some args
|
2023-04-07 16:03:26 +02:00
|
|
|
std::string configPath;
|
|
|
|
bool ignoreSudo = false;
|
|
|
|
|
|
|
|
std::vector<std::string> args{argv + 1, argv + argc};
|
|
|
|
|
|
|
|
for (auto it = args.begin(); it != args.end(); it++) {
|
|
|
|
if (it->compare("--i-am-really-stupid") == 0 && !ignoreSudo) {
|
|
|
|
std::cout << "[ WARNING ] Running Hyprland with superuser privileges might damage your system\n";
|
|
|
|
|
2022-05-19 19:28:15 +02:00
|
|
|
ignoreSudo = true;
|
2023-04-10 19:26:36 +02:00
|
|
|
} else if (it->compare("-c") == 0 || it->compare("--config") == 0) {
|
2023-06-09 12:15:18 +02:00
|
|
|
if (std::next(it) == args.end()) {
|
2023-04-07 16:03:26 +02:00
|
|
|
help();
|
2023-07-18 21:00:08 +02:00
|
|
|
|
2023-04-07 16:03:26 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
std::string next_arg = std::next(it)->c_str();
|
|
|
|
|
|
|
|
if (!std::filesystem::exists(next_arg)) {
|
|
|
|
std::cerr << "[ ERROR ] Config path '" << next_arg << "' doesn't exist!\n";
|
|
|
|
help();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
configPath = next_arg;
|
|
|
|
Debug::log(LOG, "User-specified config location: '%s'", configPath.c_str());
|
2023-04-10 19:26:36 +02:00
|
|
|
|
|
|
|
it++;
|
|
|
|
|
2023-04-07 16:03:26 +02:00
|
|
|
continue;
|
2023-07-18 21:00:08 +02:00
|
|
|
} else if (it->compare("-h") == 0 || it->compare("--help") == 0) {
|
2023-04-10 19:26:36 +02:00
|
|
|
help();
|
2023-07-18 21:00:08 +02:00
|
|
|
|
2023-04-10 19:26:36 +02:00
|
|
|
return 0;
|
2023-07-18 21:00:08 +02:00
|
|
|
} else {
|
|
|
|
std::cerr << "[ ERROR ] Unknown option '" << it->c_str() << "'!\n";
|
|
|
|
help();
|
|
|
|
|
|
|
|
return 1;
|
2022-12-16 18:17:31 +01:00
|
|
|
}
|
2023-04-07 16:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ignoreSudo && Init::isSudo()) {
|
|
|
|
std::cerr << "[ ERROR ] Hyprland was launched with superuser priveleges, but the privileges check is not omitted.\n";
|
|
|
|
std::cerr << " Hint: Use the --i-am-really-stupid flag to omit that check.\n";
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
} else if (ignoreSudo && Init::isSudo()) {
|
|
|
|
std::cout << "Superuser privileges check is omitted. I hope you know what you're doing.\n";
|
2022-05-19 19:28:15 +02:00
|
|
|
}
|
|
|
|
|
2022-06-03 17:48:07 +02:00
|
|
|
std::cout << "Welcome to Hyprland!\n";
|
2023-07-23 20:51:00 +02:00
|
|
|
Init::gainRealTime();
|
2022-03-16 21:37:21 +01:00
|
|
|
|
|
|
|
// let's init the compositor.
|
|
|
|
// it initializes basic Wayland stuff in the constructor.
|
2022-12-16 18:17:31 +01:00
|
|
|
g_pCompositor = std::make_unique<CCompositor>();
|
2022-07-14 22:55:24 +02:00
|
|
|
g_pCompositor->explicitConfigPath = configPath;
|
2022-03-16 21:37:21 +01:00
|
|
|
|
2023-03-05 14:37:21 +01:00
|
|
|
g_pCompositor->initServer();
|
|
|
|
|
2022-03-16 21:37:21 +01:00
|
|
|
Debug::log(LOG, "Hyprland init finished.");
|
|
|
|
|
|
|
|
// If all's good to go, start.
|
|
|
|
g_pCompositor->startCompositor();
|
2022-03-16 20:50:55 +01:00
|
|
|
|
2022-03-16 21:37:21 +01:00
|
|
|
// If we are here it means we got yote.
|
|
|
|
Debug::log(LOG, "Hyprland reached the end.");
|
2022-03-16 20:50:55 +01:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|