Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr 06 unidirectional maximization support #2597

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion plugins/decor/deco-layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ enum decoration_layout_action_t
/* Button actions */
DECORATION_ACTION_CLOSE = 3,
DECORATION_ACTION_TOGGLE_MAXIMIZE = 4,
DECORATION_ACTION_MINIMIZE = 5,
DECORATION_ACTION_TOGGLE_MAXIMIZE_VERTICALLY = 5,
DECORATION_ACTION_TOGGLE_MAXIMIZE_HORIZONTALLY = 6,
DECORATION_ACTION_MINIMIZE = 7,
};

class decoration_theme_t;
Expand Down
83 changes: 56 additions & 27 deletions plugins/decor/deco-subsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <cairo.h>

namespace wf::decor
{
class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_interaction_t,
public wf::touch_interaction_t
{
Expand Down Expand Up @@ -64,8 +66,8 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
} title_texture;

public:
wf::decor::decoration_theme_t theme;
wf::decor::decoration_layout_t layout;
decoration_theme_t theme;
decoration_layout_t layout;
wf::region_t cached_region;

wf::dimensions_t size;
Expand All @@ -82,12 +84,10 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
view->connect(&title_set);
if (view->parent)
{
theme.set_buttons(wf::decor::button_type_t(wf::decor::BUTTON_TOGGLE_MAXIMIZE |
wf::decor::BUTTON_CLOSE));
theme.set_buttons(button_type_t(BUTTON_TOGGLE_MAXIMIZE | BUTTON_CLOSE));
} else
{
theme.set_buttons(wf::decor::button_type_t(wf::decor::BUTTON_MINIMIZE |
wf::decor::BUTTON_TOGGLE_MAXIMIZE | wf::decor::BUTTON_CLOSE));
theme.set_buttons(button_type_t(BUTTON_MINIMIZE | BUTTON_TOGGLE_MAXIMIZE | BUTTON_CLOSE));
}

// make sure to hide frame if the view is fullscreen
Expand Down Expand Up @@ -125,7 +125,7 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
auto renderables = layout.get_renderable_areas();
for (auto item : renderables)
{
if (item->get_type() == wf::decor::DECORATION_AREA_TITLE)
if (item->get_type() == DECORATION_AREA_TITLE)
{
OpenGL::render_begin(fb);
fb.logic_scissor(scissor);
Expand Down Expand Up @@ -193,10 +193,10 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
if (!our_damage.empty())
{
instructions.push_back(wf::scene::render_instruction_t{
.instance = this,
.target = target,
.damage = std::move(our_damage),
});
.instance = this,
.target = target,
.damage = std::move(our_damage),
});
}
}

Expand Down Expand Up @@ -241,41 +241,69 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in

void handle_pointer_button(const wlr_pointer_button_event& ev) override
{
if (ev.button != BTN_LEFT)
auto action = layout.handle_press_event(ev.state == WL_POINTER_BUTTON_STATE_PRESSED);
if (action.action == DECORATION_ACTION_TOGGLE_MAXIMIZE)
{
// Fixup the maximize action.
if (ev.button == BTN_MIDDLE)
{
action.action = DECORATION_ACTION_TOGGLE_MAXIMIZE_VERTICALLY;
} else if (ev.button == BTN_RIGHT)
{
action.action = DECORATION_ACTION_TOGGLE_MAXIMIZE_HORIZONTALLY;
} else if (ev.button != BTN_LEFT)
{
return;
}
} else if (ev.button != BTN_LEFT)
{
return;
}

handle_action(layout.handle_press_event(ev.state == WL_POINTER_BUTTON_STATE_PRESSED));
handle_action(action);
}

void handle_action(wf::decor::decoration_layout_t::action_response_t action)
void handle_action(decoration_layout_t::action_response_t action)
{
if (auto view = _view.lock())
{
switch (action.action)
{
case wf::decor::DECORATION_ACTION_MOVE:
case DECORATION_ACTION_MOVE:
return wf::get_core().default_wm->move_request(view);

case wf::decor::DECORATION_ACTION_RESIZE:
case DECORATION_ACTION_RESIZE:
return wf::get_core().default_wm->resize_request(view, action.edges);

case wf::decor::DECORATION_ACTION_CLOSE:
case DECORATION_ACTION_CLOSE:
return view->close();

case wf::decor::DECORATION_ACTION_TOGGLE_MAXIMIZE:
if (view->pending_tiled_edges())
case DECORATION_ACTION_TOGGLE_MAXIMIZE:
case DECORATION_ACTION_TOGGLE_MAXIMIZE_VERTICALLY:
case DECORATION_ACTION_TOGGLE_MAXIMIZE_HORIZONTALLY:
{
// Get the last maximization state that was requested;
// it is this value that needs to be toggled.
maximization_t maximization = view->pending_maximization();

// Toggle the state if appropriate.
if (((action.action == DECORATION_ACTION_TOGGLE_MAXIMIZE) ||
(action.action == DECORATION_ACTION_TOGGLE_MAXIMIZE_VERTICALLY)))
{
return wf::get_core().default_wm->tile_request(view, 0);
} else
maximization ^= maximization_t::vertical;
}

if (((action.action == DECORATION_ACTION_TOGGLE_MAXIMIZE) ||
(action.action == DECORATION_ACTION_TOGGLE_MAXIMIZE_HORIZONTALLY)))
{
return wf::get_core().default_wm->tile_request(view, wf::TILED_EDGES_ALL);
maximization ^= maximization_t::horizontal;
}

break;
// Request the new maximize state.
return wf::get_core().default_wm->tile_request(view, maximization.as_tiled_edges());
}

case wf::decor::DECORATION_ACTION_MINIMIZE:
case DECORATION_ACTION_MINIMIZE:
return wf::get_core().default_wm->minimize_request(view, true);
break;

Expand Down Expand Up @@ -337,7 +365,7 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
}
};

wf::simple_decorator_t::simple_decorator_t(wayfire_toplevel_view view)
simple_decorator_t::simple_decorator_t(wayfire_toplevel_view view)
{
this->view = view;
deco = std::make_shared<simple_decoration_node_t>(view);
Expand Down Expand Up @@ -368,12 +396,12 @@ wf::simple_decorator_t::simple_decorator_t(wayfire_toplevel_view view)
};
}

wf::simple_decorator_t::~simple_decorator_t()
simple_decorator_t::~simple_decorator_t()
{
wf::scene::remove_child(deco);
}

wf::decoration_margins_t wf::simple_decorator_t::get_margins(const wf::toplevel_state_t& state)
wf::decoration_margins_t simple_decorator_t::get_margins(const wf::toplevel_state_t& state)
{
if (state.fullscreen)
{
Expand All @@ -389,3 +417,4 @@ wf::decoration_margins_t wf::simple_decorator_t::get_margins(const wf::toplevel_
.top = titlebar,
};
}
} // namespace wf::decor
5 changes: 3 additions & 2 deletions plugins/decor/deco-subsurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <wayfire/signal-definitions.hpp>
#include <wayfire/toplevel-view.hpp>

class simple_decoration_node_t;
namespace wf
namespace wf::decor
{
class simple_decoration_node_t;

/**
* A decorator object attached as custom data to a toplevel object.
*/
Expand Down
15 changes: 9 additions & 6 deletions plugins/decor/decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "wayfire/toplevel-view.hpp"
#include "wayfire/toplevel.hpp"

namespace wf::decor
{
class wayfire_decoration : public wf::plugin_interface_t
{
wf::view_matcher_t ignore_views{"decoration/ignore_views"};
Expand All @@ -28,7 +30,7 @@ class wayfire_decoration : public wf::plugin_interface_t
{
// First check whether the toplevel already has decoration
// In that case, we should just set the correct margins
if (auto deco = toplevel->get_data<wf::simple_decorator_t>())
if (auto deco = toplevel->get_data<simple_decorator_t>())
{
toplevel->pending().margins = deco->get_margins(toplevel->pending());
continue;
Expand Down Expand Up @@ -111,8 +113,8 @@ class wayfire_decoration : public wf::plugin_interface_t
{
auto toplevel = view->toplevel();

toplevel->store_data(std::make_unique<wf::simple_decorator_t>(view));
auto deco = toplevel->get_data<wf::simple_decorator_t>();
toplevel->store_data(std::make_unique<simple_decorator_t>(view));
auto deco = toplevel->get_data<simple_decorator_t>();
auto& pending = toplevel->pending();
pending.margins = deco->get_margins(pending);

Expand All @@ -128,7 +130,7 @@ class wayfire_decoration : public wf::plugin_interface_t

void remove_decoration(wayfire_toplevel_view view)
{
view->toplevel()->erase_data<wf::simple_decorator_t>();
view->toplevel()->erase_data<simple_decorator_t>();
auto& pending = view->toplevel()->pending();
if (!pending.fullscreen && !pending.tiled_edges)
{
Expand All @@ -140,7 +142,7 @@ class wayfire_decoration : public wf::plugin_interface_t

bool is_toplevel_decorated(const std::shared_ptr<wf::toplevel_t>& toplevel)
{
return toplevel->has_data<wf::simple_decorator_t>();
return toplevel->has_data<simple_decorator_t>();
}

void update_view_decoration(wayfire_view view)
Expand All @@ -163,5 +165,6 @@ class wayfire_decoration : public wf::plugin_interface_t
}
}
};
} // namespace wf::decor

DECLARE_WAYFIRE_PLUGIN(wayfire_decoration);
DECLARE_WAYFIRE_PLUGIN(wf::decor::wayfire_decoration);
Loading