Skip to content

Commit

Permalink
Add boolean to control whether or not the view is resized to the outp…
Browse files Browse the repository at this point in the history
…ut geometry
  • Loading branch information
soreau committed Aug 14, 2024
1 parent ced9902 commit e37224f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
24 changes: 13 additions & 11 deletions ipc-scripts/pin-view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

import os
import sys
from wayfire_socket import *
from wayfire import WayfireSocket
from wayfire.extra.wpe import WPE

if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} <view_id> <layer> [workspace_x], [workspace_y]")
if len(sys.argv) < 4:
print(f"Usage: {sys.argv[0]} <view_id: int> <layer: str> <resize: bool> [workspace_x: int], [workspace_y: int]")
exit(1)

addr = os.getenv('WAYFIRE_SOCKET')
addr = os.getenv("WAYFIRE_SOCKET")

commands_sock = WayfireSocket(addr)
sock = WayfireSocket(addr)
wpe = WPE(sock)

for view in commands_sock.list_views():
for view in sock.list_views():
if view["id"] == int(sys.argv[1]):
if len(sys.argv) == 3:
commands_sock.pin_view(int(sys.argv[1]), sys.argv[2], None, None)
if len(sys.argv) == 4:
commands_sock.pin_view(int(sys.argv[1]), sys.argv[2], int(sys.argv[3]), None)
elif len(sys.argv) == 5:
commands_sock.pin_view(int(sys.argv[1]), sys.argv[2], int(sys.argv[3]), int(sys.argv[4]))
wpe.pin_view(int(sys.argv[1]), sys.argv[2], sys.argv[3].lower() == "true", None, None)
if len(sys.argv) == 5:
wpe.pin_view(int(sys.argv[1]), sys.argv[2], sys.argv[3].lower() == "true", int(sys.argv[4]), None)
elif len(sys.argv) == 6:
wpe.pin_view(int(sys.argv[1]), sys.argv[2], sys.argv[3].lower() == "true", int(sys.argv[4]), int(sys.argv[5]))
23 changes: 13 additions & 10 deletions src/pin-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class pin_view_data : public wf::custom_data_t
public:
wf::geometry_t geometry;
wf::point_t workspace;
wf::view_role_t role, current_role;
wf::view_role_t role;
};
class wayfire_pin_view : public wf::plugin_interface_t
{
Expand All @@ -63,6 +63,7 @@ class wayfire_pin_view : public wf::plugin_interface_t
{
WFJSON_EXPECT_FIELD(data, "view-id", number_unsigned);
WFJSON_EXPECT_FIELD(data, "layer", string);
WFJSON_EXPECT_FIELD(data, "resize", boolean);
/* workspace x,y */
WFJSON_OPTIONAL_FIELD(data, "x", number_unsigned);
WFJSON_OPTIONAL_FIELD(data, "y", number_unsigned);
Expand All @@ -75,11 +76,7 @@ class wayfire_pin_view : public wf::plugin_interface_t
if (!view->get_data<pin_view_data>())
{
pin_view_data pv_data;
pv_data.current_role = pv_data.role = view->role;
if (!data.contains("x"))
{
pv_data.current_role = wf::VIEW_ROLE_DESKTOP_ENVIRONMENT;
}
pv_data.role = view->role;

if (auto toplevel = toplevel_cast(view))
{
Expand Down Expand Up @@ -117,6 +114,7 @@ class wayfire_pin_view : public wf::plugin_interface_t
layer = wf::scene::layer::TOP;
}

bool resize = data["resize"];
auto og = output->get_relative_geometry();
int x = 0, y = 0;
if (data.contains("x"))
Expand All @@ -130,19 +128,24 @@ class wayfire_pin_view : public wf::plugin_interface_t
wf::point_t nws{x, y};
if (auto toplevel = toplevel_cast(view))
{
auto vg = toplevel->get_geometry();
auto cws = output->wset()->get_view_main_workspace(toplevel);
toplevel->set_geometry(wf::geometry_t{(nws.x - cws.x) * og.width,
(nws.y - cws.y) * og.height, og.width, og.height});
(nws.y - cws.y) * og.height, resize ? og.width : vg.width,
resize ? og.height : vg.height});
}
} else
{
if (auto toplevel = toplevel_cast(view))
{
auto vg = toplevel->get_geometry();
wf::point_t nws = output->wset()->get_current_workspace();
auto cws = output->wset()->get_view_main_workspace(toplevel);
auto vg = toplevel->get_geometry();
toplevel->move(vg.x + (nws.x - cws.x) * og.width, vg.y + (nws.y - cws.y) * og.height);
toplevel->set_geometry(og);
if (resize)
{
toplevel->set_geometry(og);
}
}

view->role = wf::VIEW_ROLE_DESKTOP_ENVIRONMENT;
Expand Down Expand Up @@ -199,7 +202,7 @@ class wayfire_pin_view : public wf::plugin_interface_t
for (auto & view : wf::get_core().get_all_views())
{
auto pvd = view->get_data<pin_view_data>();
if (!pvd || (pvd->current_role != wf::VIEW_ROLE_DESKTOP_ENVIRONMENT))
if (!pvd || (view->role != wf::VIEW_ROLE_DESKTOP_ENVIRONMENT))
{
continue;
}
Expand Down

0 comments on commit e37224f

Please sign in to comment.