Skip to content

Commit

Permalink
Implement xdg-activation v1 protocol plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kode54 committed Sep 15, 2023
1 parent 03b7255 commit 0587e54
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions metadata/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ install_data('zoom.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('scale-title-filter.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('wsets.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('wayfire-shell.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
install_data('xdg-activation.xml', install_dir: conf_data.get('PLUGIN_XML_DIR'))
8 changes: 8 additions & 0 deletions metadata/xdg-activation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<wayfire>
<plugin name="xdg-activation">
<_short>XDG Activation Protocol</_short>
<_long>An implementation of the xdg-activation-v1 protocol.</_long>
<category>Utility</category>
</plugin>
</wayfire>
2 changes: 1 addition & 1 deletion plugins/protocols/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
protocol_plugins = [
'foreign-toplevel', 'gtk-shell', 'wayfire-shell',
'foreign-toplevel', 'gtk-shell', 'wayfire-shell', 'xdg-activation',
]

all_include_dirs = [wayfire_api_inc, wayfire_conf_inc, plugins_common_inc]
Expand Down
67 changes: 67 additions & 0 deletions plugins/protocols/xdg-activation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "wayfire/core.hpp"
#include "wayfire/signal-definitions.hpp"
#include "wayfire/view.hpp"
#include <memory>
#include <wayfire/plugin.hpp>
#include <wayfire/view.hpp>
#include <wayfire/nonstd/wlroots-full.hpp>
#include <wayfire/window-manager.hpp>
#include "config.h"

extern "C"
{
#include <wlr/types/wlr_xdg_activation_v1.h>
}

class wayfire_xdg_activation_protocol_impl : public wf::plugin_interface_t
{
public:
void init() override
{
xdg_activation = wlr_xdg_activation_v1_create(wf::get_core().display);
xdg_activation_request_activate.notify = xdg_activation_handle_request_activate;

wl_signal_add(&xdg_activation->events.request_activate, &xdg_activation_request_activate);
}

void fini() override
{}

bool is_unloadable() override
{
return false;
}

private:
static void xdg_activation_handle_request_activate(struct wl_listener *listener, void *data)
{
auto event = static_cast<const struct wlr_xdg_activation_v1_request_activate_event*>(data);

wayfire_view view = wf::wl_surface_to_wayfire_view(event->surface->resource);
if (!view)
{
LOGI("Could not get view");
return;
}

if (!event->token->seat)
{
LOGI("Denying focus request, seat wasn't supplied");
return;
}

if (!view->get_output())
{
LOGI("View has no output");
return;
}

LOGI("Activating view");
view->get_output()->focus_view(view, true);
}

struct wlr_xdg_activation_v1 *xdg_activation;
struct wl_listener xdg_activation_request_activate;
};

DECLARE_WAYFIRE_PLUGIN(wayfire_xdg_activation_protocol_impl);

0 comments on commit 0587e54

Please sign in to comment.