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

feature: implementation of xdg_activation_v1 because I want my auto focuses #3639

Merged
merged 8 commits into from
Oct 30, 2024
28 changes: 22 additions & 6 deletions src/server/frontend_wayland/xdg_activation_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
#include "xdg_activation_v1.h"
#include "wl_surface.h"
#include "wl_seat.h"
#include "wl_client.h"
#include "mir/main_loop.h"
#include "mir/scene/surface.h"
#include "mir/shell/shell.h"
#include "mir/shell/focus_controller.h"
#include "mir/wayland/protocol_error.h"
#include "mir/log.h"
#include <random>
#include <chrono>
Expand Down Expand Up @@ -120,6 +122,7 @@ class XdgActivationTokenV1 : public wayland::XdgActivationTokenV1
std::optional<struct wl_resource*> seat;
std::optional<std::string> app_id;
std::optional<struct wl_resource*> requesting_surface;
bool used = false;
};
}
}
Expand Down Expand Up @@ -259,9 +262,18 @@ void mf::XdgActivationTokenV1::set_surface(struct wl_resource* surface)

void mf::XdgActivationTokenV1::commit()
{
// In the event of a failure, we send 'done' with a new, invalid token
// which cannot be used later.
if (used)
{
BOOST_THROW_EXCEPTION(mw::ProtocolError(
resource,
Error::already_used,
"The activation token has already been used"));
return;
}

used = true;

// In the event of a failure, we send 'done' with a new, invalid token which cannot be used later.
if (seat && serial)
{
// First, assert that the seat still exists.
Expand All @@ -273,8 +285,13 @@ void mf::XdgActivationTokenV1::commit()
return;
}

// TODO:
// Next, verify that the serial belongs to the seat
auto event = client->event_for(serial.value());
if (!event)
{
mir::log_error("XdgActivationTokenV1::commit serial not found");
mattkae marked this conversation as resolved.
Show resolved Hide resolved
send_done_event(generate_token());
return;
}
}

if (app_id)
Expand Down Expand Up @@ -309,10 +326,9 @@ void mf::XdgActivationTokenV1::commit()
}

auto const& scene_surface = scene_surface_opt.value();

if (focus_controller->focused_surface() != scene_surface)
{
mir::log_error("XdgActivationTokenV1::commit the focused surface is not the surface that requesteda ctivation");
mir::log_error("XdgActivationTokenV1::commit the focused surface is not the surface that requested activation");
mattkae marked this conversation as resolved.
Show resolved Hide resolved
send_done_event(generate_token());
return;
}
Expand Down
Loading