Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x11-platform] Make window title a configuration option #2349

Merged
merged 14 commits into from Mar 3, 2022
6 changes: 3 additions & 3 deletions src/platforms/x11/graphics/display.cpp
Expand Up @@ -79,6 +79,7 @@ class XGLContext : public mir::renderer::gl::Context
}

mgx::X11Window::X11Window(mx::X11Resources* x11_resources,
std::string title,
EGLDisplay egl_dpy,
geom::Size const size,
EGLConfig const egl_cfg)
Expand Down Expand Up @@ -111,9 +112,6 @@ mgx::X11Window::X11Window(mx::X11Resources* x11_resources,
// Enable the WM_DELETE_WINDOW protocol for the window (causes a client message to be sent when window is closed)
conn->change_property(win, x11_resources->WM_PROTOCOLS, XCB_ATOM_ATOM, 32, 1, &x11_resources->WM_DELETE_WINDOW);

// Set the window title
std::string title{"Mir on X"};

// Include hostname in title when X-forwarding
if (getenv("SSH_CONNECTION"))
{
Expand Down Expand Up @@ -146,6 +144,7 @@ unsigned long mgx::X11Window::red_mask() const
}

mgx::Display::Display(std::shared_ptr<mir::X::X11Resources> const& x11_resources,
std::string const title,
std::vector<X11OutputConfig> const& requested_sizes,
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const& gl_config,
Expand All @@ -164,6 +163,7 @@ mgx::Display::Display(std::shared_ptr<mir::X::X11Resources> const& x11_resources
auto actual_size = requested_size.size;
auto window = std::make_unique<X11Window>(
x11_resources.get(),
title,
shared_egl.display(),
actual_size,
shared_egl.config());
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/x11/graphics/display.h
Expand Up @@ -53,6 +53,7 @@ class X11Window
{
public:
X11Window(mir::X::X11Resources* x11_resources,
std::string title,
EGLDisplay egl_dpy,
geometry::Size const size,
EGLConfig const egl_cfg);
Expand All @@ -71,6 +72,7 @@ class Display : public graphics::Display
{
public:
explicit Display(std::shared_ptr<mir::X::X11Resources> const& x11_resources,
std::string const title,
std::vector<X11OutputConfig> const& requested_size,
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const& gl_config,
Expand Down
8 changes: 8 additions & 0 deletions src/platforms/x11/graphics/graphics.cpp
Expand Up @@ -38,6 +38,7 @@ namespace geom = mir::geometry;
namespace
{
char const* x11_displays_option_name{"x11-output"};
char const* x11_window_title_option_name{"x11-window-title"};
}

mir::UniqueModulePtr<mg::DisplayPlatform> create_display_platform(
Expand All @@ -57,9 +58,11 @@ mir::UniqueModulePtr<mg::DisplayPlatform> create_display_platform(
}

auto output_sizes = mgx::Platform::parse_output_sizes(options->get<std::string>(x11_displays_option_name));
auto const title = options->get<std::string>(x11_window_title_option_name);

return mir::make_module_ptr<mgx::Platform>(
std::move(x11_resources),
std::move(title),
move(output_sizes),
report
);
Expand All @@ -82,6 +85,11 @@ void add_graphics_platform_options(boost::program_options::options_description&
boost::program_options::value<std::string>()->default_value("1280x1024"),
"[mir-on-X specific] Colon separated list of WIDTHxHEIGHT sizes for \"output\" windows."
" ^SCALE may also be appended to any output");

config.add_options()
(x11_window_title_option_name,
boost::program_options::value<std::string>()->default_value("Mir on X"),
"[mir-on-X specific] Title for the banner of the generated X11 window");
}

mg::PlatformPriority probe_graphics_platform()
Expand Down
4 changes: 3 additions & 1 deletion src/platforms/x11/graphics/platform.cpp
Expand Up @@ -108,9 +108,11 @@ auto mgx::Platform::parse_output_sizes(std::string output_sizes) -> std::vector<
}

mgx::Platform::Platform(std::shared_ptr<mir::X::X11Resources> const& x11_resources,
std::string title,
std::vector<X11OutputConfig> output_sizes,
std::shared_ptr<mg::DisplayReport> const& report)
: x11_resources{x11_resources},
title{std::move(title)},
report{report},
output_sizes{move(output_sizes)}
{
Expand All @@ -128,5 +130,5 @@ mir::UniqueModulePtr<mg::Display> mgx::Platform::create_display(
std::shared_ptr<DisplayConfigurationPolicy> const& initial_conf_policy,
std::shared_ptr<GLConfig> const& gl_config)
{
return make_module_ptr<mgx::Display>(x11_resources, output_sizes, initial_conf_policy, gl_config, report);
return make_module_ptr<mgx::Display>(x11_resources, title, output_sizes, initial_conf_policy, gl_config, report);
}
2 changes: 2 additions & 0 deletions src/platforms/x11/graphics/platform.h
Expand Up @@ -61,6 +61,7 @@ class Platform : public graphics::DisplayPlatform
static auto parse_output_sizes(std::string output_sizes) -> std::vector<X11OutputConfig>;

explicit Platform(std::shared_ptr<mir::X::X11Resources> const& x11_resources,
std::string const title,
std::vector<X11OutputConfig> output_sizes,
std::shared_ptr<DisplayReport> const& report);
~Platform() = default;
Expand All @@ -71,6 +72,7 @@ class Platform : public graphics::DisplayPlatform
std::shared_ptr<GLConfig> const& gl_config) override;
private:
std::shared_ptr<mir::X::X11Resources> const x11_resources;
std::string const title;
std::shared_ptr<DisplayReport> const report;
std::vector<X11OutputConfig> const output_sizes;
};
Expand Down
1 change: 1 addition & 0 deletions tests/unit-tests/platforms/x11/test_display.cpp
Expand Up @@ -103,6 +103,7 @@ class X11DisplayTest : public ::testing::Test
{
return std::make_shared<mgx::Display>(
mt::fake_shared(x11_resources),
"Mir on X",
sizes,
mt::fake_shared(null_display_configuration_policy),
mt::fake_shared(mock_gl_config),
Expand Down
1 change: 1 addition & 0 deletions tests/unit-tests/platforms/x11/test_display_generic.cpp
Expand Up @@ -91,6 +91,7 @@ class DisplayTestGeneric : public ::testing::Test
{
auto const platform = std::make_shared<mg::X::Platform>(
std::make_shared<mtd::MockX11Resources>(),
"Mir on X",
std::vector<mg::X::X11OutputConfig>{{{1280, 1024}}},
std::make_shared<mir::report::null::DisplayReport>());
return platform->create_display(
Expand Down
2 changes: 2 additions & 0 deletions tests/unit-tests/platforms/x11/test_platform.cpp
Expand Up @@ -69,6 +69,7 @@ class X11GraphicsPlatformTest : public ::testing::Test
{
return std::make_shared<mg::X::Platform>(
std::make_shared<mtd::MockX11Resources>(),
"Mir on X",
std::vector<mg::X::X11OutputConfig>{{{1280, 1024}}},
std::make_shared<mir::report::null::DisplayReport>());
}
Expand All @@ -88,6 +89,7 @@ TEST_F(X11GraphicsPlatformTest, failure_to_open_x11_display_results_in_an_error)
{
std::make_shared<mg::X::Platform>(
nullptr,
"Mir on X",
std::vector<mg::X::X11OutputConfig>{{{1280, 1024}}},
std::make_shared<mir::report::null::DisplayReport>());
}, std::exception);
Expand Down