* Move the view to the target output and put it at the coordinates of the grab. * Also take into account view's fullscreen and tiled state. * * Unmapped views are ignored. */
| 574 | * Unmapped views are ignored. |
| 575 | */ |
| 576 | void adjust_view_on_output(drag_done_signal *ev) |
| 577 | { |
| 578 | // Any one of the views that are being dragged. |
| 579 | // They are all part of the same view tree. |
| 580 | auto parent = wf::find_topmost_parent(ev->main_view); |
| 581 | if (!parent->is_mapped()) |
| 582 | { |
| 583 | return; |
| 584 | } |
| 585 | |
| 586 | const bool change_output = parent->get_output() != ev->focused_output; |
| 587 | auto old_wset = parent->get_wset(); |
| 588 | if (change_output) |
| 589 | { |
| 590 | start_move_view_to_wset(parent, ev->focused_output->wset()); |
| 591 | } |
| 592 | |
| 593 | // Calculate the position we're leaving the view on |
| 594 | auto output_delta = -wf::origin(ev->focused_output->get_layout_geometry()); |
| 595 | auto grab = ev->grab_position + output_delta; |
| 596 | |
| 597 | auto output_geometry = ev->focused_output->get_relative_geometry(); |
| 598 | auto current_ws = ev->focused_output->wset()->get_current_workspace(); |
| 599 | wf::point_t target_ws{ |
| 600 | (int)std::floor(1.0 * grab.x / output_geometry.width), |
| 601 | (int)std::floor(1.0 * grab.y / output_geometry.height), |
| 602 | }; |
| 603 | target_ws = target_ws + current_ws; |
| 604 | |
| 605 | auto gsize = ev->focused_output->wset()->get_workspace_grid_size(); |
| 606 | target_ws.x = wf::clamp(target_ws.x, 0, gsize.width - 1); |
| 607 | target_ws.y = wf::clamp(target_ws.y, 0, gsize.height - 1); |
| 608 | |
| 609 | // view to focus at the end of drag |
| 610 | auto focus_view = ev->main_view; |
| 611 | |
| 612 | for (auto& v : ev->all_views) |
| 613 | { |
| 614 | if (!v.view->is_mapped()) |
| 615 | { |
| 616 | // Maybe some dialog got unmapped |
| 617 | continue; |
| 618 | } |
| 619 | |
| 620 | auto bbox = wf::view_bounding_box_up_to(v.view, "wobbly"); |
| 621 | auto wm = v.view->get_geometry(); |
| 622 | |
| 623 | wf::point_t wm_offset = wf::origin(wm) + -wf::origin(bbox); |
| 624 | bbox = wf::move_drag::find_geometry_around( |
| 625 | wf::dimensions(bbox), grab, v.relative_grab); |
| 626 | |
| 627 | wf::point_t target = wf::origin(bbox) + wm_offset; |
| 628 | v.view->move(target.x, target.y); |
| 629 | if (v.view->pending_fullscreen()) |
| 630 | { |
| 631 | wf::get_core().default_wm->fullscreen_request(v.view, ev->focused_output, true, target_ws); |
| 632 | } else if (v.view->pending_tiled_edges()) |
| 633 | { |
no test coverage detected