From 635a2fd5ed367d77a8748f75693c5eed30bb32db Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Thu, 15 Aug 2024 10:56:50 -0600 Subject: [PATCH] pin-view: More fixes --- src/pin-view.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pin-view.cpp b/src/pin-view.cpp index e1bf19f..83d8881 100644 --- a/src/pin-view.cpp +++ b/src/pin-view.cpp @@ -71,7 +71,8 @@ class wayfire_pin_view : public wf::plugin_interface_t auto view = wf::ipc::find_view_by_id(data["view-id"]); if (view) { - auto output = view->get_output(); + bool was_pinned = unpin(view); + auto output = view->get_output(); output->connect(&on_workspace_changed); if (!view->get_data()) { @@ -80,8 +81,11 @@ class wayfire_pin_view : public wf::plugin_interface_t if (auto toplevel = toplevel_cast(view)) { - pv_data.workspace = output->wset()->get_view_main_workspace(toplevel); - pv_data.geometry = toplevel->get_geometry(); + if (!was_pinned) + { + pv_data.workspace = output->wset()->get_view_main_workspace(toplevel); + pv_data.geometry = toplevel->get_geometry(); + } } view->store_data(std::make_unique(pv_data)); @@ -128,7 +132,8 @@ class wayfire_pin_view : public wf::plugin_interface_t y = data["y"].get(); } - view->role = view->get_data()->role; + auto pvd = view->get_data(); + view->role = pvd->role; wf::point_t nws{x, y}; if (auto toplevel = toplevel_cast(view)) @@ -140,12 +145,10 @@ class wayfire_pin_view : public wf::plugin_interface_t (nws.y - cws.y) * og.height, og.width, og.height}); } else { - auto vg = toplevel->get_geometry(); + auto vg = was_pinned ? pvd->geometry : toplevel->get_geometry(); toplevel->set_geometry(wf::geometry_t{vg.x + (nws.x - cws.x) * og.width, vg.y + (nws.y - cws.y) * og.height, vg.width, vg.height}); } - - output->wset()->remove_view(toplevel); } } else { @@ -159,8 +162,6 @@ class wayfire_pin_view : public wf::plugin_interface_t { toplevel->set_geometry(og); } - - output->wset()->remove_view(toplevel); } view->role = wf::VIEW_ROLE_DESKTOP_ENVIRONMENT; @@ -195,7 +196,6 @@ class wayfire_pin_view : public wf::plugin_interface_t toplevel->set_geometry(pvd->geometry); } - view->release_data(); on_workspace_changed.disconnect(); wf::view_mapped_signal map_signal; map_signal.view = view; @@ -217,6 +217,8 @@ class wayfire_pin_view : public wf::plugin_interface_t return wf::ipc::json_error("Failed to find view with given id. Perhaps it is not pinned."); } + view->release_data(); + return wf::ipc::json_ok(); }; @@ -250,6 +252,7 @@ class wayfire_pin_view : public wf::plugin_interface_t if (view->get_data()) { unpin(view); + view->release_data(); } }