|
10 | 10 | #include "wayfire/plugin.hpp" |
11 | 11 | #include "wayfire/signal-definitions.hpp" |
12 | 12 | #include <wayfire/plugins/common/geometry-animation.hpp> |
| 13 | +#include <wayfire/plugins/common/preview-indication.hpp> |
13 | 14 | #include "wayfire/plugins/grid.hpp" |
14 | 15 | #include "wayfire/plugins/crossfade.hpp" |
15 | 16 | #include <wayfire/window-manager.hpp> |
@@ -55,6 +56,13 @@ class wayfire_grid : public wf::plugin_interface_t, public wf::per_output_tracke |
55 | 56 | std::vector<std::string> slots = {"unused", "bl", "b", "br", "l", "c", "r", "tl", "t", "tr"}; |
56 | 57 | wf::ipc_activator_t bindings[10]; |
57 | 58 | wf::ipc_activator_t restore{"grid/restore"}; |
| 59 | + wf::option_wrapper_t<int> snap_threshold{"move/snap_threshold"}; |
| 60 | + wf::option_wrapper_t<int> quarter_snap_threshold{"move/quarter_snap_threshold"}; |
| 61 | + struct |
| 62 | + { |
| 63 | + std::shared_ptr<wf::preview_indication_t> preview; |
| 64 | + wf::grid::slot_t slot_id = wf::grid::SLOT_NONE; |
| 65 | + } slot; |
58 | 66 |
|
59 | 67 | wf::plugin_activation_data_t grab_interface{ |
60 | 68 | .name = "grid", |
@@ -102,13 +110,60 @@ class wayfire_grid : public wf::plugin_interface_t, public wf::per_output_tracke |
102 | 110 | }); |
103 | 111 | } |
104 | 112 |
|
105 | | - wf::get_core().connect(&grid_request_signal_cb); |
| 113 | + wf::get_core().connect(&grid_handle_move_signal_cb); |
106 | 114 | } |
107 | 115 |
|
108 | | - wf::signal::connection_t<wf::grid::grid_request_signal> grid_request_signal_cb = |
109 | | - [=] (wf::grid::grid_request_signal *ev) |
| 116 | + wf::signal::connection_t<wf::grid::grid_handle_move_signal> grid_handle_move_signal_cb = |
| 117 | + [=] (wf::grid::grid_handle_move_signal *ev) |
110 | 118 | { |
111 | 119 | ev->carried_out = true; |
| 120 | + wf::grid::slot_t new_slot_id = ev->operation == wf::grid::MOVE_OP_CLEAR_PREVIEW ? |
| 121 | + wf::grid::slot_t::SLOT_NONE : |
| 122 | + wf::grid::calc_slot(ev->output, ev->input, snap_threshold, quarter_snap_threshold); |
| 123 | + |
| 124 | + if ((ev->operation == wf::grid::MOVE_OP_DROP) && new_slot_id) |
| 125 | + { |
| 126 | + ev->view->toplevel()->pending().tiled_edges = wf::grid::get_tiled_edges_for_slot(new_slot_id); |
| 127 | + auto desired_size = wf::grid::get_slot_dimensions(ev->view->get_output(), new_slot_id); |
| 128 | + ev->view->get_data_safe<wf_grid_slot_data>()->slot = new_slot_id; |
| 129 | + ensure_grid_view(ev->view)->adjust_target_geometry( |
| 130 | + adjust_for_workspace(ev->view->get_wset(), desired_size, |
| 131 | + ev->view->get_output()->wset()->get_current_workspace()), |
| 132 | + ev->view->toplevel()->pending().tiled_edges); |
| 133 | + new_slot_id = wf::grid::slot_t::SLOT_NONE; |
| 134 | + } |
| 135 | + |
| 136 | + /* No changes in the slot, just return */ |
| 137 | + if (slot.slot_id == new_slot_id) |
| 138 | + { |
| 139 | + return; |
| 140 | + } |
| 141 | + |
| 142 | + /* Destroy previous preview */ |
| 143 | + if (slot.preview) |
| 144 | + { |
| 145 | + auto input = ev->input; |
| 146 | + slot.preview->set_target_geometry({input.x, input.y, 1, 1}, 0, true); |
| 147 | + slot.preview = nullptr; |
| 148 | + } |
| 149 | + |
| 150 | + slot.slot_id = new_slot_id; |
| 151 | + |
| 152 | + /* Show a preview overlay */ |
| 153 | + if (new_slot_id) |
| 154 | + { |
| 155 | + wf::geometry_t slot_geometry = wf::grid::get_slot_dimensions(ev->output, new_slot_id); |
| 156 | + /* Unknown slot geometry, can't show a preview */ |
| 157 | + if ((slot_geometry.width <= 0) || (slot_geometry.height <= 0)) |
| 158 | + { |
| 159 | + return; |
| 160 | + } |
| 161 | + |
| 162 | + auto input = ev->input; |
| 163 | + slot.preview = std::make_shared<wf::preview_indication_t>( |
| 164 | + wf::geometry_t{input.x, input.y, 1, 1}, ev->output, "move"); |
| 165 | + slot.preview->set_target_geometry(slot_geometry, 1); |
| 166 | + } |
112 | 167 | }; |
113 | 168 |
|
114 | 169 | void handle_new_output(wf::output_t *output) override |
|
0 commit comments