Skip to content

Commit

Permalink
Implement xdg-activation-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed May 4, 2021
1 parent f8d7c17 commit 46dc890
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/sway/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ struct sway_server {
struct wlr_text_input_manager_v3 *text_input;
struct wlr_foreign_toplevel_manager_v1 *foreign_toplevel_manager;

struct wlr_xdg_activation_v1 *xdg_activation_v1;
struct wl_listener xdg_activation_v1_request_activate;

// The timeout for transactions, after which a transaction is applied
// regardless of readiness.
size_t txn_timeout_ms;
Expand Down Expand Up @@ -141,5 +144,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data);
void handle_server_decoration(struct wl_listener *listener, void *data);
void handle_xdg_decoration(struct wl_listener *listener, void *data);
void handle_pointer_constraint(struct wl_listener *listener, void *data);
void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
void *data);

#endif
1 change: 1 addition & 0 deletions sway/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sway_sources = files(
'main.c',
'server.c',
'swaynag.c',
'xdg_activation_v1.c',
'xdg_decoration.c',

'desktop/desktop.c',
Expand Down
7 changes: 7 additions & 0 deletions sway/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <wlr/types/wlr_tablet_v2.h>
#include <wlr/types/wlr_viewporter.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_activation_v1.h>
#include <wlr/types/wlr_xdg_decoration_v1.h>
#include <wlr/types/wlr_xdg_foreign_registry.h>
#include <wlr/types/wlr_xdg_foreign_v1.h>
Expand Down Expand Up @@ -159,6 +160,12 @@ bool server_init(struct sway_server *server) {
wlr_xdg_foreign_v1_create(server->wl_display, foreign_registry);
wlr_xdg_foreign_v2_create(server->wl_display, foreign_registry);

server->xdg_activation_v1 = wlr_xdg_activation_v1_create(server->wl_display);
server->xdg_activation_v1_request_activate.notify =
xdg_activation_v1_handle_request_activate;
wl_signal_add(&server->xdg_activation_v1->events.request_activate,
&server->xdg_activation_v1_request_activate);

// Avoid using "wayland-0" as display socket
char name_candidate[16];
for (int i = 1; i <= 32; ++i) {
Expand Down
20 changes: 20 additions & 0 deletions sway/xdg_activation_v1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <wlr/types/wlr_xdg_activation_v1.h>
#include "sway/tree/view.h"

void xdg_activation_v1_handle_request_activate(struct wl_listener *listener,
void *data) {
const struct wlr_xdg_activation_v1_request_activate_event *event = data;

if (!wlr_surface_is_xdg_surface(event->surface)) {
return;
}

struct wlr_xdg_surface *xdg_surface =
wlr_xdg_surface_from_wlr_surface(event->surface);
struct sway_view *view = xdg_surface->data;
if (!xdg_surface->mapped || view == NULL) {
return;
}

view_request_activate(view);
}

0 comments on commit 46dc890

Please sign in to comment.