-
Notifications
You must be signed in to change notification settings - Fork 170
/
wm.cpp
139 lines (116 loc) · 3.71 KB
/
wm.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "wm.hpp"
#include "wayfire/output.hpp"
#include "wayfire/view-helpers.hpp"
#include "wayfire/view.hpp"
#include "wayfire/core.hpp"
#include "wayfire/workspace-set.hpp"
#include "wayfire/output-layout.hpp"
#include <wayfire/seat.hpp>
#include <wayfire/window-manager.hpp>
#include <wayfire/util/log.hpp>
#include <wayfire/nonstd/wlroots-full.hpp>
#include "../output/output-impl.hpp"
#include "wayfire/signal-definitions.hpp"
#include <linux/input-event-codes.h>
static void idle_shutdown(void *data)
{
wf::get_core().shutdown();
}
void wayfire_exit::init()
{
key = [] (const wf::keybinding_t&)
{
auto output_impl = static_cast<wf::output_impl_t*>(wf::get_core().seat->get_active_output());
if (output_impl->is_inhibited())
{
return false;
}
idle_shutdown(nullptr);
return true;
};
output->add_key(wf::create_option_string<wf::keybinding_t>(
"<ctrl> <alt> KEY_BACKSPACE"), &key);
}
void wayfire_exit::fini()
{
output->rem_binding(&key);
}
void wayfire_close::init()
{
wf::option_wrapper_t<wf::activatorbinding_t> key("core/close_top_view");
callback = [=] (const wf::activator_data_t& ev)
{
if (!output->activate_plugin(&grab_interface))
{
return false;
}
output->deactivate_plugin(&grab_interface);
auto view = wf::get_core().seat->get_active_view();
if (view && (view->role == wf::VIEW_ROLE_TOPLEVEL))
{
view->close();
}
return true;
};
output->add_activator(key, &callback);
}
void wayfire_close::fini()
{
output->rem_binding(&callback);
}
void wayfire_focus::init()
{
on_pointer_button = [=] (wf::input_event_signal<wlr_pointer_button_event> *ev)
{
if ((ev->mode == wf::input_event_processing_mode_t::IGNORE) ||
(ev->event->state != WLR_BUTTON_PRESSED))
{
return;
}
/* focus_btns->get_value() does not compile */
wf::option_sptr_t<wf::activatorbinding_t> tmp = focus_btns;
if ((!focus_modifiers && wf::get_core().seat->get_keyboard_modifiers()) ||
!tmp->get_value().has_match(wf::buttonbinding_t(0, ev->event->button)))
{
return;
}
bool changed_focus =
this->check_focus_surface(wf::get_core().get_cursor_focus_view());
bool pass_through = (pass_btns || !changed_focus);
ev->mode = pass_through ? wf::input_event_processing_mode_t::FULL :
wf::input_event_processing_mode_t::NO_CLIENT;
};
wf::get_core().connect(&on_pointer_button);
// build touch gesture
auto on_tap = std::make_unique<wf::touch::touch_action_t>(1, true);
std::vector<std::unique_ptr<wf::touch::gesture_action_t>> actions;
actions.emplace_back(std::move(on_tap));
const auto& on_tap_action = [this] ()
{
this->check_focus_surface(wf::get_core().get_touch_focus_view());
};
this->tap_gesture =
std::make_unique<wf::touch::gesture_t>(std::move(actions), on_tap_action);
wf::get_core().add_touch_gesture(tap_gesture);
}
bool wayfire_focus::check_focus_surface(wayfire_view view)
{
auto& core = wf::get_core();
if (!view || !view->is_mapped() || !core.seat->get_active_output() ||
!core.seat->get_active_output()->can_activate_plugin(grab_interface.capabilities))
{
return false;
}
if (!view->get_keyboard_focus_surface())
{
wf::view_bring_to_front(view);
return false;
}
auto old_focus = core.seat->get_active_view();
core.default_wm->focus_raise_view(view);
return core.seat->get_active_view() != old_focus;
}
void wayfire_focus::fini()
{
wf::get_core().rem_touch_gesture(tap_gesture);
}