Skip to content

Commit

Permalink
Use std::optional instead of mir::optional_value in
Browse files Browse the repository at this point in the history
`miral::launch_app_env`
  • Loading branch information
tarek-y-ismail committed Jan 22, 2025
1 parent d558ab2 commit 1d6a14f
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/include/server/mir/frontend/connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#ifndef MIR_FRONTEND_CONNECTOR_H_
#define MIR_FRONTEND_CONNECTOR_H_

#include <mir/optional_value.h>
#include <functional>
#include <memory>
#include <optional>
#include <string>

namespace mir
Expand All @@ -41,7 +41,7 @@ class Connector

virtual int client_socket_fd(std::function<void(std::shared_ptr<scene::Session> const& session)> const& connect_handler) const = 0;

virtual auto socket_name() const -> optional_value<std::string> = 0;
virtual auto socket_name() const -> std::optional<std::string> = 0;

protected:
Connector() = default;
Expand Down
5 changes: 2 additions & 3 deletions src/include/server/mir/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define MIR_SERVER_H_

#include "mir/shell/window_manager_builder.h"
#include "mir/optional_value.h"
#include "mir_toolkit/common.h"

#include <functional>
Expand Down Expand Up @@ -472,10 +471,10 @@ class Server
std::function<bool(std::shared_ptr<scene::Session> const&, char const*)> const& extension_filter);

/// Get the name of the Wayland endpoint (if any) usable as a $WAYLAND_DISPLAY value
auto wayland_display() const -> optional_value<std::string>;
auto wayland_display() const -> std::optional<std::string>;

/// Get the name of the X11 display usable as a $DISPLAY value
auto x11_display() const -> optional_value<std::string>;
auto x11_display() const -> std::optional<std::string>;

auto get_activation_token() const -> std::string;

Expand Down
4 changes: 2 additions & 2 deletions src/miral/launch_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ auto execute_with_environment(std::vector<std::string> const app, Environment& a

auto miral::launch_app_env(
std::vector<std::string> const& app,
mir::optional_value<std::string> const& wayland_display,
mir::optional_value<std::string> const& x11_display,
std::optional<std::string> const& wayland_display,
std::optional<std::string> const& x11_display,
std::optional<std::string> const& xdg_activation_token,
miral::AppEnvironment const& app_env) -> pid_t
{
Expand Down
4 changes: 2 additions & 2 deletions src/miral/launch_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace miral
using AppEnvironment = std::map<std::string, std::optional<std::string>>;

auto launch_app_env(std::vector<std::string> const& app,
mir::optional_value<std::string> const& wayland_display,
mir::optional_value<std::string> const& x11_display,
std::optional<std::string> const& wayland_display,
std::optional<std::string> const& x11_display,
std::optional<std::string> const& xdg_activation_token,
AppEnvironment const& app_env) -> pid_t;
}
Expand Down
14 changes: 12 additions & 2 deletions src/miral/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,23 @@ auto miral::MirRunner::display_config_file() const -> std::string
return self->display_config_file;
}

namespace
{
auto optional_to_mir_optional(std::optional<std::string> const& opt) -> mir::optional_value<std::string>
{
if (!opt)
return {};
return mir::optional_value{*opt};
}
}

auto miral::MirRunner::wayland_display() const -> mir::optional_value<std::string>
{
std::lock_guard lock{self->mutex};

if (auto const server = self->weak_server.lock())
{
return server->wayland_display();
return optional_to_mir_optional(server->wayland_display());
}

return {};
Expand All @@ -292,7 +302,7 @@ auto miral::MirRunner::x11_display() const -> mir::optional_value<std::string>

if (auto const server = self->weak_server.lock())
{
return server->x11_display();
return optional_to_mir_optional(server->x11_display());
}

return {};
Expand Down
1 change: 1 addition & 0 deletions src/miral/x11_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <mir/options/configuration.h>
#include <mir/main_loop.h>
#include <mir/fd.h>
#include <mir/fatal.h>

namespace mo = mir::options;

Expand Down
3 changes: 2 additions & 1 deletion src/server/frontend_wayland/wayland_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "mir/graphics/graphic_buffer_allocator.h"
#include "mir/frontend/wayland.h"

#include <optional>
#include <sys/eventfd.h>
#include <sys/stat.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -525,7 +526,7 @@ void mf::WaylandConnector::on_surface_created(
compositor_global->on_surface_created(client, id, callback);
}

auto mf::WaylandConnector::socket_name() const -> optional_value<std::string>
auto mf::WaylandConnector::socket_name() const -> std::optional<std::string>
{
return wayland_display;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/frontend_wayland/wayland_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class WaylandConnector : public Connector
/// Callback is never called if a wl_surface with the id is never created
void on_surface_created(wl_client* client, uint32_t id, std::function<void(WlSurface*)> const& callback);

auto socket_name() const -> optional_value<std::string> override;
auto socket_name() const -> std::optional<std::string> override;

auto get_extension(std::string const& name) const -> std::shared_ptr<void>;

Expand Down
4 changes: 2 additions & 2 deletions src/server/frontend_xwayland/xwayland_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int mf::XWaylandConnector::client_socket_fd(
return -1;
}

auto mf::XWaylandConnector::socket_name() const -> optional_value<std::string>
auto mf::XWaylandConnector::socket_name() const -> std::optional<std::string>
{
std::lock_guard lock{mutex};

Expand All @@ -111,7 +111,7 @@ auto mf::XWaylandConnector::socket_name() const -> optional_value<std::string>
}
else
{
return optional_value<std::string>();
return std::nullopt;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/frontend_xwayland/xwayland_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class XWaylandConnector : public Connector, public std::enable_shared_from_this<
int client_socket_fd(
std::function<void(std::shared_ptr<scene::Session> const& session)> const& connect_handler) const override;

auto socket_name() const -> optional_value<std::string> override;
auto socket_name() const -> std::optional<std::string> override;

private:
std::shared_ptr<Executor> const main_loop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <boost/lexical_cast.hpp>

#include <optional>
#include <string>
#include <cstdlib>

Expand Down Expand Up @@ -53,9 +54,9 @@ struct NullConnector : mf::Connector
return -1;
}

mir::optional_value<std::string> socket_name() const override
std::optional<std::string> socket_name() const override
{
return mir::optional_value<std::string>();
return std::optional<std::string>();
}
};
}
Expand Down
5 changes: 3 additions & 2 deletions src/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "frontend_wayland/wayland_connector.h"
#include <iostream>
#include <optional>

namespace mo = mir::options;
namespace mi = mir::input;
Expand Down Expand Up @@ -462,15 +463,15 @@ auto mir::Server::open_wayland_client_socket() -> Fd
BOOST_THROW_EXCEPTION(std::logic_error("Cannot open connection when not running"));
}

auto mir::Server::wayland_display() const -> optional_value<std::string>
auto mir::Server::wayland_display() const -> std::optional<std::string>
{
if (auto const config = self->server_config)
return config->the_wayland_connector()->socket_name();

BOOST_THROW_EXCEPTION(std::logic_error("Cannot open connection when not running"));
}

auto mir::Server::x11_display() const -> mir::optional_value<std::string>
auto mir::Server::x11_display() const -> std::optional<std::string>
{
if (auto const config = self->server_config)
return config->the_xwayland_connector()->socket_name();
Expand Down

0 comments on commit 1d6a14f

Please sign in to comment.