2021-03-23 11:31:18 +01:00
|
|
|
#include <wlr/types/wlr_xdg_activation_v1.h>
|
2024-02-15 12:01:24 +01:00
|
|
|
#include <wlr/types/wlr_xdg_shell.h>
|
2022-11-19 04:05:24 +01:00
|
|
|
#include "sway/desktop/launcher.h"
|
2021-03-23 11:31:18 +01:00
|
|
|
#include "sway/tree/view.h"
|
2022-11-30 19:54:50 +01:00
|
|
|
#include "sway/tree/workspace.h"
|
2021-03-23 11:31:18 +01:00
|
|
|
|
|
|
|
void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
const struct wlr_xdg_activation_v1_request_activate_event *event = data;
|
|
|
|
|
|
|
|
struct wlr_xdg_surface *xdg_surface =
|
2023-02-01 20:24:40 +01:00
|
|
|
wlr_xdg_surface_try_from_wlr_surface(event->surface);
|
2022-09-12 23:53:09 +02:00
|
|
|
if (xdg_surface == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-23 11:31:18 +01:00
|
|
|
struct sway_view *view = xdg_surface->data;
|
2022-11-19 04:05:24 +01:00
|
|
|
if (view == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-08 00:13:25 +01:00
|
|
|
struct launcher_ctx *ctx = event->token->data;
|
|
|
|
if (ctx == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-05 21:49:45 +01:00
|
|
|
if (!xdg_surface->surface->mapped) {
|
2022-11-19 04:05:24 +01:00
|
|
|
// This is a startup notification. If we are tracking it, the data
|
|
|
|
// field is a launcher_ctx.
|
2024-02-08 00:13:25 +01:00
|
|
|
if (ctx->activated) {
|
2022-11-19 04:05:24 +01:00
|
|
|
// This ctx has already been activated and cannot be used again
|
|
|
|
// for a startup notification. It will be destroyed
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
ctx->activated = true;
|
|
|
|
view_assign_ctx(view, ctx);
|
|
|
|
}
|
2021-03-23 11:31:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-08 00:13:25 +01:00
|
|
|
// This is an activation request. If this context is internal we have ctx->seat.
|
2024-02-28 22:22:09 +01:00
|
|
|
if (ctx->seat) {
|
|
|
|
view_request_activate(view, ctx->seat);
|
|
|
|
return;
|
2024-02-08 00:13:25 +01:00
|
|
|
}
|
|
|
|
|
2024-02-28 22:22:09 +01:00
|
|
|
// Otherwise, activate if passed from another focused client
|
|
|
|
if (ctx->token->seat && ctx->had_focused_surface) {
|
|
|
|
view_request_activate(view, ctx->token->seat->data);
|
2023-12-27 07:26:02 +01:00
|
|
|
} else {
|
|
|
|
// The token is valid, but cannot be used to activate a window
|
|
|
|
view_request_urgent(view);
|
2024-02-08 00:13:25 +01:00
|
|
|
}
|
2021-03-23 11:31:18 +01:00
|
|
|
}
|
2022-11-30 19:54:50 +01:00
|
|
|
|
|
|
|
void xdg_activation_v1_handle_new_token(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_xdg_activation_token_v1 *token = data;
|
|
|
|
struct sway_seat *seat = token->seat ? token->seat->data :
|
|
|
|
input_manager_current_seat();
|
|
|
|
|
|
|
|
struct sway_workspace *ws = seat_get_focused_workspace(seat);
|
|
|
|
if (ws) {
|
|
|
|
launcher_ctx_create(token, &ws->node);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|