Skip to content

Commit

Permalink
decor: Don't put minimize buttons on child views (#2057)
Browse files Browse the repository at this point in the history
* decor: Don't put minimize buttons on child views

Fixes #705.

* do not allow minimizing views with toplevel parents
  • Loading branch information
soreau authored and ammen99 committed Mar 13, 2024
1 parent 5c538b9 commit 9515f8d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
6 changes: 3 additions & 3 deletions plugins/decor/deco-button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class decoration_theme_t;

enum button_type_t
{
BUTTON_CLOSE,
BUTTON_TOGGLE_MAXIMIZE,
BUTTON_MINIMIZE,
BUTTON_CLOSE = 1 << 0,
BUTTON_TOGGLE_MAXIMIZE = 1 << 1,
BUTTON_MINIMIZE = 1 << 2,
};

class button_t
Expand Down
6 changes: 3 additions & 3 deletions plugins/decor/deco-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ wf::geometry_t decoration_layout_t::create_buttons(int width, int)
std::string button_name;
while (stream >> button_name)
{
if (button_name == "minimize")
if ((button_name == "minimize") && (theme.button_flags & BUTTON_MINIMIZE))
{
buttons.push_back(BUTTON_MINIMIZE);
}

if (button_name == "maximize")
if ((button_name == "maximize") && (theme.button_flags & BUTTON_TOGGLE_MAXIMIZE))
{
buttons.push_back(BUTTON_TOGGLE_MAXIMIZE);
}

if (button_name == "close")
if ((button_name == "close") && (theme.button_flags & BUTTON_CLOSE))
{
buttons.push_back(BUTTON_CLOSE);
}
Expand Down
9 changes: 9 additions & 0 deletions plugins/decor/deco-subsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
{
this->_view = view->weak_from_this();
view->connect(&title_set);
if (view->parent)
{
theme.set_buttons(wf::decor::button_type_t(wf::decor::BUTTON_TOGGLE_MAXIMIZE |
wf::decor::BUTTON_CLOSE));
} else
{
theme.set_buttons(wf::decor::button_type_t(wf::decor::BUTTON_MINIMIZE |
wf::decor::BUTTON_TOGGLE_MAXIMIZE | wf::decor::BUTTON_CLOSE));
}

// make sure to hide frame if the view is fullscreen
update_decoration_size();
Expand Down
6 changes: 6 additions & 0 deletions plugins/decor/deco-theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ int decoration_theme_t::get_border_size() const
return border_size;
}

/** @return The available border for resizing */
void decoration_theme_t::set_buttons(button_type_t flags)
{
button_flags = flags;
}

/**
* Fill the given rectangle with the background color(s).
*
Expand Down
3 changes: 3 additions & 0 deletions plugins/decor/deco-theme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class decoration_theme_t
int get_title_height() const;
/** @return The available border for resizing */
int get_border_size() const;
/** Set the flags for buttons */
void set_buttons(button_type_t flags);
button_type_t button_flags;

/**
* Fill the given rectangle with the background color(s).
Expand Down
6 changes: 6 additions & 0 deletions src/view/toplevel-view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ void wf::toplevel_view_interface_t::set_minimized(bool minim)
return;
}

if (this->parent && minim)
{
LOGE("Ignoring a request to minimize a view with a parent, minimize the parent instead!");
return;
}

this->minimized = minim;
wf::scene::set_node_enabled(get_root_node(), !minimized);

Expand Down

0 comments on commit 9515f8d

Please sign in to comment.