Added -w option

This commit is contained in:
Bob Polis 2022-09-24 10:42:42 +02:00
parent 022edf74e1
commit 9ada3dd260

View File

@ -31,10 +31,11 @@ std::unique_ptr<cairo_t, void(*)(cairo_t*)> main_context {nullptr, cairo_destroy
std::unique_ptr<cairo_surface_t, void(*)(cairo_surface_t*)> main_surface {nullptr, cairo_surface_destroy};
void print_help() {
std::cout << "usage: screensaver [-h|-l|--version]\n";
std::cout << "usage: screensaver [-h|-l|--version][-r][-w]\n";
std::cout << " -h, --help show this help text and exit\n";
std::cout << " -l, --list show available screensaver modules and exit\n";
std::cout << " -r, --random choose random module from available ones\n";
std::cout << " -w, --window show in resizable window instead of fullscreen\n";
std::cout << " --version show version number and exit\n";
}
@ -90,15 +91,17 @@ int main(int argc, const char * argv[]) {
sc::plugin<ScreensaverPlugin>::scan_plugins(plugin_dir, "saver");
std::string saver_name;
bool random_saver {false};
bool small_window {false};
int opt_char, opt_val;
struct option long_options[] = {
{"help", no_argument, nullptr, 'h'},
{"list", no_argument, nullptr, 'l'},
{"random", no_argument, nullptr, 'r'},
{"window", no_argument, nullptr, 'w'},
{"version", no_argument, &opt_val, 1},
{nullptr, 0, nullptr, 0}
};
while ((opt_char = getopt_long(argc, const_cast<char* const *>(argv), "hlr", long_options, nullptr)) != -1) {
while ((opt_char = getopt_long(argc, const_cast<char* const *>(argv), "hlrw", long_options, nullptr)) != -1) {
std::string arg {optarg ? optarg : ""};
switch (opt_char) {
case 0: {
@ -119,6 +122,9 @@ int main(int argc, const char * argv[]) {
case 'r':
random_saver = true;
break;
case 'w':
small_window = true;
break;
case '?':
throw std::runtime_error("unrecognized option");
}
@ -157,11 +163,8 @@ int main(int argc, const char * argv[]) {
sc::gui::SDLImageWrapper sdl_image;
// main window
#if DEBUG
sc::gui::Window& window {sc::gui::Window::new_window("Living Art")};
#else
sc::gui::Window& window {sc::gui::Window::new_window("Living Art", SDL_WINDOW_FULLSCREEN_DESKTOP)};
#endif
Uint32 flags {small_window ? SDL_WINDOW_RESIZABLE : SDL_WINDOW_FULLSCREEN_DESKTOP};
sc::gui::Window& window {sc::gui::Window::new_window("Living Art", flags)};
main_window = &window;
window.add_event_handler(handle_window_resize, SDL_WINDOWEVENT_RESIZED);
window.add_event_handler(handle_window_resize, SDL_WINDOWEVENT_SIZE_CHANGED);