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

(#1762) Allow shells to enable XWayland by default #3133

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions debian/libmiral6.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,5 @@ libmiral.so.6 libmiral6 #MINVER#
MIRAL_4.1@MIRAL_4.1 4.1.0
(c++)"miral::WaylandExtensions::zwp_input_method_v1@MIRAL_4.1" 4.1.0
(c++)"miral::WaylandExtensions::zwp_input_panel_v1@MIRAL_4.1" 4.1.0
MIRAL_4.2@MIRAL_4.2 4.2.0
(c++)"miral::X11Support::default_to_enabled()@MIRAL_4.2" 4.2.0
11 changes: 10 additions & 1 deletion include/miral/miral/x11_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace mir { class Server; }

namespace miral
{
/// Add a user configuration option for X11 support.
/// Add user configuration options for X11 support.
/// \remark Since MirAL 2.4
class X11Support
{
Expand All @@ -36,6 +36,15 @@ class X11Support
X11Support(X11Support const&);
auto operator=(X11Support const&) -> X11Support&;

/**
* Set X11 support as enabled by default.
*
* \return A reference to the modified miral::X11Support object with
* the updated default configuration.
* \remark Since MirAL 4.2
*/
auto default_to_enabled() -> X11Support&;

private:
struct Self;
std::shared_ptr<Self> self;
Expand Down
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(MIRPLATFORM_ABI 27)

set(MIRAL_VERSION_MAJOR 4)
set(MIRAL_VERSION_MINOR 1)
set(MIRAL_VERSION_MINOR 2)
set(MIRAL_VERSION_PATCH 0)
set(MIRAL_VERSION ${MIRAL_VERSION_MAJOR}.${MIRAL_VERSION_MINOR}.${MIRAL_VERSION_PATCH})

Expand Down Expand Up @@ -51,4 +51,3 @@ set(MIR_SERVER_GRAPHICS_PLATFORM_ABI ${MIR_SERVER_GRAPHICS_PLATFORM_ABI} PARENT_
set(MIR_SERVER_INPUT_PLATFORM_ABI ${MIR_SERVER_INPUT_PLATFORM_ABI} PARENT_SCOPE)
set(MIR_SERVER_GRAPHICS_PLATFORM_VERSION ${MIR_SERVER_GRAPHICS_PLATFORM_VERSION} PARENT_SCOPE)
set(MIR_INPUT_PLATFORM_VERSION_SCRIPT ${MIR_INPUT_PLATFORM_VERSION_SCRIPT} PARENT_SCOPE)

7 changes: 7 additions & 0 deletions src/miral/symbols.map
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,10 @@ global:

} MIRAL_4.0;

MIRAL_4.2 {
global:
extern "C++" {
miral::X11Support::default_to_enabled*;
};

} MIRAL_4.1;
9 changes: 7 additions & 2 deletions src/miral/x11_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace mo = mir::options;

struct miral::X11Support::Self
{
bool x11_enabled{false};
};

miral::X11Support::X11Support() : self{std::make_shared<Self>()}
Expand All @@ -38,8 +39,7 @@ void miral::X11Support::operator()(mir::Server& server) const

server.add_configuration_option(
mo::x11_display_opt,
"Enable X11 support", mir::OptionType::null);

"Enable X11 support [{1|true|on|yes, 0|false|off|no}].", self->x11_enabled);

auto const x11_scale_default = []() -> char const* {
if (auto const gdk_scale = getenv("GDK_SCALE"))
Expand Down Expand Up @@ -96,4 +96,9 @@ miral::X11Support::~X11Support() = default;
miral::X11Support::X11Support(X11Support const&) = default;
auto miral::X11Support::operator=(X11Support const&) -> X11Support& = default;

auto miral::X11Support::default_to_enabled() -> X11Support&
{
self->x11_enabled = true;

return *this;
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ std::shared_ptr<mf::Connector>
enabled_wayland_extensions.end()};

auto const enable_repeat = options->get<bool>(options::enable_key_repeat_opt);
auto const x11_enabled = options->is_set(mo::x11_display_opt) && options->get<bool>(mo::x11_display_opt);

return std::make_shared<mf::WaylandConnector>(
the_shell(),
Expand All @@ -356,7 +357,7 @@ std::shared_ptr<mf::Connector>
arw_socket,
configure_wayland_extensions(
wayland_extensions,
options->is_set(mo::x11_display_opt),
x11_enabled,
wayland_extension_hooks),
wayland_extension_filter,
enable_repeat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ std::shared_ptr<mf::Connector> mir::DefaultServerConfiguration::the_xwayland_con
return xwayland_connector([this]() -> std::shared_ptr<mf::Connector> {

auto options = the_options();
if (options->is_set(mo::x11_display_opt))
auto const x11_enabled = options->is_set(mo::x11_display_opt) && options->get<bool>(mo::x11_display_opt);

if (x11_enabled)
{
try
{
Expand Down
45 changes: 35 additions & 10 deletions tests/miral/external_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ struct ExternalClient : miral::TestServer
}

miral::ExternalClientLauncher external_client;
miral::X11Support x11;
miral::X11Support x11_disabled_by_default{};
miral::X11Support x11_enabled_by_default{miral::X11Support{}.default_to_enabled()};

std::string const output = tmpnam(nullptr);

Expand All @@ -66,7 +67,7 @@ struct ExternalClient : miral::TestServer
getline(in, result);
return result;
}

bool cannot_start_X_server()
{
// Starting an X server on LP builder, or Fedora CI, doesn't work
Expand Down Expand Up @@ -101,7 +102,7 @@ TEST_F(ExternalClient, default_app_env_x11_is_as_expected)
if (cannot_start_X_server())
return; // Starting an X server doesn't work - skip the test

add_server_init(x11);
add_server_init(x11_disabled_by_default);
add_to_environment("MIR_SERVER_ENABLE_X11", "");
start_server();

Expand All @@ -126,7 +127,7 @@ TEST_F(ExternalClient, override_app_env_x11_can_unset)
return; // Starting an X server doesn't work - skip the test

add_to_environment(app_x11_env, "-GDK_BACKEND");
add_server_init(x11);
add_server_init(x11_disabled_by_default);
add_to_environment("MIR_SERVER_ENABLE_X11", "");
start_server();

Expand All @@ -139,7 +140,7 @@ TEST_F(ExternalClient, override_app_env_x11_can_unset_and_set)
return; // Starting an X server doesn't work - skip the test

add_to_environment(app_x11_env, "-GDK_BACKEND:QT_QPA_PLATFORM=xcb");
add_server_init(x11);
add_server_init(x11_disabled_by_default);
add_to_environment("MIR_SERVER_ENABLE_X11", "");
start_server();

Expand All @@ -153,7 +154,7 @@ TEST_F(ExternalClient, override_app_env_x11_can_set_and_unset)
return; // Starting an X server doesn't work - skip the test

add_to_environment(app_x11_env, "QT_QPA_PLATFORM=xcb:-GDK_BACKEND");
add_server_init(x11);
add_server_init(x11_disabled_by_default);
add_to_environment("MIR_SERVER_ENABLE_X11", "");
start_server();

Expand All @@ -167,7 +168,7 @@ TEST_F(ExternalClient, stray_separators_are_ignored)
return; // Starting an X server doesn't work - skip the test

add_to_environment(app_x11_env, "::QT_QPA_PLATFORM=xcb::-GDK_BACKEND::");
add_server_init(x11);
add_server_init(x11_disabled_by_default);
add_to_environment("MIR_SERVER_ENABLE_X11", "");
start_server();

Expand All @@ -181,7 +182,7 @@ TEST_F(ExternalClient, empty_override_does_nothing)
return; // Starting an X server doesn't work - skip the test

add_to_environment(app_x11_env, "");
add_server_init(x11);
add_server_init(x11_disabled_by_default);
add_to_environment("MIR_SERVER_ENABLE_X11", "");
start_server();

Expand All @@ -198,7 +199,7 @@ TEST_F(ExternalClient, strange_override_does_nothing)
return; // Starting an X server doesn't work - skip the test

add_to_environment(app_x11_env, "=====");
add_server_init(x11);
add_server_init(x11_disabled_by_default);
add_to_environment("MIR_SERVER_ENABLE_X11", "");
start_server();

Expand All @@ -215,7 +216,7 @@ TEST_F(ExternalClient, another_strange_override_does_nothing)
return; // Starting an X server doesn't work - skip the test

add_to_environment(app_x11_env, ":::");
add_server_init(x11);
add_server_init(x11_disabled_by_default);
add_to_environment("MIR_SERVER_ENABLE_X11", "");
start_server();

Expand Down Expand Up @@ -244,3 +245,27 @@ TEST_F(ExternalClient, split_command)
<< "test.command=\"" + test.command + "\"";
}
}

TEST_F(ExternalClient, x11_disabled_by_default_is_as_expected)
{
if (cannot_start_X_server())
return; // Starting an X server doesn't work - skip the test

add_server_init(x11_disabled_by_default);
start_server();

auto result = external_client.launch_using_x11({"bash", "-c", "exit"});
EXPECT_THAT(result, Eq(-1));
}

TEST_F(ExternalClient, x11_enabled_by_default_is_as_expected)
{
if (cannot_start_X_server())
return; // Starting an X server doesn't work - skip the test

add_server_init(x11_enabled_by_default);
start_server();

auto result = external_client.launch_using_x11({"bash", "-c", "exit"});
EXPECT_THAT(result, Ne(-1));
}