File: xdg-activation.cpp

package info (click to toggle)
wayfire 0.9.0-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,732 kB
  • sloc: cpp: 49,708; xml: 2,783; ansic: 699; makefile: 161
file content (64 lines) | stat: -rw-r--r-- 1,782 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#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/toplevel-view.hpp>
#include <wayfire/nonstd/wlroots-full.hpp>
#include <wayfire/window-manager.hpp>
#include "config.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)
        {
            LOGE("Could not get view");
            return;
        }

        auto toplevel = wf::toplevel_cast(view);
        if (!toplevel)
        {
            LOGE("Could not get toplevel view");
            return;
        }

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

        LOGI("Activating view");
        wf::get_core().default_wm->focus_request(toplevel);
    }

    struct wlr_xdg_activation_v1 *xdg_activation;
    struct wl_listener xdg_activation_request_activate;
};

DECLARE_WAYFIRE_PLUGIN(wayfire_xdg_activation_protocol_impl);