2021-01-15 22:12:34 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Nico Weber <thakis@chromium.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-15 22:12:34 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibCore/ArgsParser.h>
|
|
|
|
#include <LibGUI/Application.h>
|
2022-02-25 13:39:33 +03:00
|
|
|
#include <LibGUI/ConnectionToWindowServer.h>
|
2021-11-27 18:27:11 +03:00
|
|
|
#include <LibMain/Main.h>
|
2021-01-15 22:12:34 +03:00
|
|
|
|
2021-11-27 18:27:11 +03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2021-01-15 22:12:34 +03:00
|
|
|
{
|
2021-07-10 04:10:11 +03:00
|
|
|
int screen = 0;
|
2021-01-15 22:12:34 +03:00
|
|
|
int width = -1;
|
|
|
|
int height = -1;
|
2021-07-10 04:09:58 +03:00
|
|
|
int scale = -1;
|
2021-01-15 22:12:34 +03:00
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
|
|
|
args_parser.set_general_help("Change the screen resolution.");
|
2021-07-10 04:10:11 +03:00
|
|
|
args_parser.add_option(screen, "Screen", "screen", 's', "screen");
|
2021-01-15 22:12:34 +03:00
|
|
|
args_parser.add_positional_argument(width, "Width", "width");
|
|
|
|
args_parser.add_positional_argument(height, "Height", "height");
|
2021-01-15 22:53:53 +03:00
|
|
|
args_parser.add_positional_argument(scale, "Scale Factor", "scale", Core::ArgsParser::Required::No);
|
2021-11-27 18:27:11 +03:00
|
|
|
args_parser.parse(arguments);
|
2021-01-15 22:12:34 +03:00
|
|
|
|
2022-02-25 13:39:33 +03:00
|
|
|
// A Core::EventLoop is all we need, but ConnectionToWindowServer needs a full Application object.
|
2021-11-27 18:27:11 +03:00
|
|
|
char* dummy_argv[] = { arguments.argv[0] };
|
2021-01-15 22:12:34 +03:00
|
|
|
auto app = GUI::Application::construct(1, dummy_argv);
|
2022-02-25 13:39:33 +03:00
|
|
|
auto screen_layout = GUI::ConnectionToWindowServer::the().get_screen_layout();
|
2021-06-15 06:19:56 +03:00
|
|
|
if (screen < 0 || (size_t)screen >= screen_layout.screens.size()) {
|
|
|
|
warnln("invalid screen index: {}", screen);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
auto& main_screen = screen_layout.screens[screen];
|
|
|
|
main_screen.resolution = { width, height };
|
2021-07-10 04:09:58 +03:00
|
|
|
if (scale != -1)
|
|
|
|
main_screen.scale_factor = scale;
|
2022-02-25 13:39:33 +03:00
|
|
|
auto set_result = GUI::ConnectionToWindowServer::the().set_screen_layout(screen_layout, true);
|
2021-06-15 06:19:56 +03:00
|
|
|
if (!set_result.success()) {
|
|
|
|
warnln("failed to set resolution: {}", set_result.error_msg());
|
2021-01-15 22:12:34 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2021-11-27 18:27:11 +03:00
|
|
|
|
|
|
|
return 0;
|
2021-01-15 22:12:34 +03:00
|
|
|
}
|