Skip to content

Commit

Permalink
improve moving dialogs to other outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Aug 23, 2024
1 parent b048cdf commit 5abcff3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 63 deletions.
17 changes: 4 additions & 13 deletions plugins/common/wayfire/plugins/common/move-drag-interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "wayfire/scene.hpp"
#include "wayfire/seat.hpp"
#include "wayfire/signal-definitions.hpp"
#include "wayfire/view-helpers.hpp"
#include <memory>
#include <wayfire/nonstd/reverse.hpp>
#include <wayfire/plugins/common/util.hpp>
Expand Down Expand Up @@ -279,16 +280,6 @@ struct dragged_view_t
wf::geometry_t last_bbox;
};

inline wayfire_toplevel_view get_toplevel(wayfire_toplevel_view view)
{
while (view->parent)
{
view = view->parent;
}

return view;
}

inline std::vector<wayfire_toplevel_view> get_target_views(wayfire_toplevel_view grabbed,
bool join_views)
{
Expand Down Expand Up @@ -492,7 +483,7 @@ class core_drag_t : public signal::provider_t

if (options.join_views)
{
grab_view = get_toplevel(grab_view);
grab_view = find_topmost_parent(grab_view);
}

this->view = grab_view;
Expand Down Expand Up @@ -556,7 +547,7 @@ class core_drag_t : public signal::provider_t

if (options.join_views)
{
view = get_toplevel(view);
view = find_topmost_parent(view);
}

auto bbox = view->get_transformed_node()->get_bounding_box() +
Expand Down Expand Up @@ -775,7 +766,7 @@ inline void adjust_view_on_output(drag_done_signal *ev)
{
// Any one of the views that are being dragged.
// They are all part of the same view tree.
auto parent = get_toplevel(ev->main_view);
auto parent = find_topmost_parent(ev->main_view);
if (!parent->is_mapped())
{
return;
Expand Down
24 changes: 6 additions & 18 deletions plugins/scale/scale-title-overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "wayfire/plugins/scale-signal.hpp"
#include "wayfire/scene-operations.hpp"
#include "wayfire/signal-definitions.hpp"
#include "wayfire/view-helpers.hpp"
#include "wayfire/view-transform.hpp"

#include <memory>
Expand All @@ -17,19 +18,6 @@
#include <wayfire/scene.hpp>
#include <wayfire/scene-render.hpp>

/**
* Get the topmost parent of a view.
*/
static wayfire_toplevel_view find_toplevel_parent(wayfire_toplevel_view view)
{
while (view->parent)
{
view = view->parent;
}

return view;
}

/**
* Class storing an overlay with a view's title, only stored for parent views.
*/
Expand Down Expand Up @@ -141,7 +129,7 @@ class title_overlay_node_t : public node_t
wf::dimensions_t find_maximal_title_size()
{
wf::dimensions_t max_size = {0, 0};
auto parent = find_toplevel_parent(view);
auto parent = find_topmost_parent(view);

for (auto v : parent->enumerate_views())
{
Expand Down Expand Up @@ -169,7 +157,7 @@ class title_overlay_node_t : public node_t
return false;
}

auto parent = find_toplevel_parent(view);
auto parent = find_topmost_parent(view);

if ((this->parent.show_view_title_overlay ==
scale_show_title_t::title_overlay_t::MOUSE) &&
Expand Down Expand Up @@ -213,7 +201,7 @@ class title_overlay_node_t : public node_t
* TODO: check if this wastes too high CPU power when views are being
* animated and maybe redraw less frequently
*/
auto& tex = get_overlay_texture(find_toplevel_parent(view));
auto& tex = get_overlay_texture(find_topmost_parent(view));
if ((tex.overlay.tex.tex == (GLuint) - 1) ||
(output_scale != tex.par.output_scale) ||
(tex.overlay.tex.width > box.width * output_scale) ||
Expand Down Expand Up @@ -253,7 +241,7 @@ class title_overlay_node_t : public node_t
wayfire_toplevel_view view_, position pos_, scale_show_title_t& parent_) :
node_t(false), view(view_), parent(parent_), pos(pos_)
{
auto parent = find_toplevel_parent(view);
auto parent = find_topmost_parent(view);
auto& title = get_overlay_texture(parent);

if (title.overlay.tex.tex != (GLuint) - 1)
Expand Down Expand Up @@ -500,7 +488,7 @@ void scale_show_title_t::update_title_overlay_mouse()
wayfire_toplevel_view v = scale_find_view_at(wf::get_core().get_cursor_position(), output);
if (v)
{
v = find_toplevel_parent(v);
v = wf::find_topmost_parent(v);

if (v->role != wf::VIEW_ROLE_TOPLEVEL)
{
Expand Down
23 changes: 4 additions & 19 deletions plugins/scale/scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,14 @@ class wayfire_scale : public wf::per_output_plugin_instance_t,
}
}

/** Return the topmost parent */
wayfire_toplevel_view get_top_parent(wayfire_toplevel_view view)
{
while (view && view->parent)
{
view = view->parent;
}

return view;
}

/* Fade all views' alpha to inactive alpha except the
* view argument */
void fade_out_all_except(wayfire_toplevel_view view)
{
for (auto& e : scale_data)
{
auto v = e.first;
if (get_top_parent(v) == get_top_parent(view))
if (wf::find_topmost_parent(v) == wf::find_topmost_parent(view))
{
continue;
}
Expand Down Expand Up @@ -495,7 +484,7 @@ class wayfire_scale : public wf::per_output_plugin_instance_t,
// Focus the view under the mouse
current_focus_view = view;
fade_out_all_except(view);
fade_in(get_top_parent(view));
fade_in(wf::find_topmost_parent(view));

// End scale
initial_focus_view.reset();
Expand Down Expand Up @@ -548,11 +537,7 @@ class wayfire_scale : public wf::per_output_plugin_instance_t,
/* Get the workspace for the center point of the untransformed view geometry */
wf::point_t get_view_main_workspace(wayfire_toplevel_view view)
{
while (view->parent)
{
view = view->parent;
}

view = wf::find_topmost_parent(view);
auto ws = output->wset()->get_current_workspace();
auto og = output->get_layout_geometry();
auto vg = view->get_geometry();
Expand Down Expand Up @@ -787,7 +772,7 @@ class wayfire_scale : public wf::per_output_plugin_instance_t,
auto views = get_views();

return std::find(
views.begin(), views.end(), get_top_parent(view)) != views.end();
views.begin(), views.end(), wf::find_topmost_parent(view)) != views.end();
}

/* Convenience assignment function */
Expand Down
11 changes: 6 additions & 5 deletions plugins/single_plugins/move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,13 @@ class wayfire_move : public wf::per_output_plugin_instance_t,
*/
wayfire_toplevel_view get_target_view(wayfire_toplevel_view view)
{
while (view && view->parent && join_views)
if (join_views)
{
return wf::find_topmost_parent(view);
} else
{
view = view->parent;
return view;
}

return view;
}

bool can_move_view(wayfire_toplevel_view view)
Expand Down Expand Up @@ -305,7 +306,7 @@ class wayfire_move : public wf::per_output_plugin_instance_t,
auto target_output = wf::get_core().output_layout->get_output_at(grab_position.x, grab_position.y);
if (target_output && (view->get_output() != target_output))
{
auto parent = wf::move_drag::get_toplevel(view);
auto parent = wf::find_topmost_parent(view);
auto offset = wf::origin(parent->get_output()->get_layout_geometry()) +
-wf::origin(target_output->get_layout_geometry());

Expand Down
6 changes: 4 additions & 2 deletions plugins/single_plugins/oswitch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "wayfire/plugin.hpp"
#include "wayfire/toplevel-view.hpp"
#include "wayfire/view-helpers.hpp"
#include <wayfire/output.hpp>
#include <wayfire/core.hpp>
#include <wayfire/view.hpp>
Expand Down Expand Up @@ -46,8 +47,9 @@ class wayfire_oswitch : public wf::plugin_interface_t
void switch_to_output_with_window(wf::output_t *target_output)
{
auto current_output = wf::get_core().seat->get_active_output();
auto view = wf::toplevel_cast(wf::get_active_view_for_output(current_output));
LOGI("Found view ", view);
auto view =
wf::find_topmost_parent(wf::toplevel_cast(wf::get_active_view_for_output(current_output)));

if (view)
{
move_view_to_output(view, target_output, true);
Expand Down
15 changes: 15 additions & 0 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output,
wf::geometry_t old_output_g;
wf::geometry_t new_output_g;

int delta_x = 0;
int delta_y = 0;

if (reconfigure)
{
edges = v->pending_tiled_edges();
Expand All @@ -533,6 +536,9 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output,
auto ratio_y = (double)new_output_g.height / old_output_g.height;
view_g.x *= ratio_x;
view_g.y *= ratio_y;

delta_x = view_g.x - v->get_pending_geometry().x;
delta_y = view_g.y - v->get_pending_geometry().y;
}

assert(new_output);
Expand All @@ -556,6 +562,15 @@ void wf::move_view_to_output(wayfire_toplevel_view v, wf::output_t *new_output,
auto new_g = wf::clamp(view_g, new_output->workarea->get_workarea());
v->set_geometry(new_g);
}

for (auto& dialog : v->enumerate_views())
{
if ((dialog != v) && (delta_x || delta_y))
{
dialog->move(dialog->get_pending_geometry().x + delta_x,
dialog->get_pending_geometry().y + delta_y);
}
}
}

emit_view_moved_to_wset(v, old_wset, new_output->wset());
Expand Down
7 changes: 1 addition & 6 deletions src/view/xwayland/xwayland-toplevel-view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ class wayfire_xwayland_view : public wf::toplevel_view_interface_t, public wayfi
configure_geometry.x -= og.x;
configure_geometry.y -= og.y;

wayfire_toplevel_view view = {this};
while (view->parent)
{
view = view->parent;
}

wayfire_toplevel_view view = wf::find_topmost_parent(wayfire_toplevel_view{this});
auto vg = view->get_pending_geometry();

// View workspace relative to current workspace
Expand Down

0 comments on commit 5abcff3

Please sign in to comment.