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

window-rules: allow setting alpha for non-toplevel windows #2032

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions plugins/window-rules/view-action-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "wayfire/output.hpp"
#include "wayfire/toplevel-view.hpp"
#include "wayfire/view.hpp"
#include "wayfire/workspace-set.hpp"
#include "wayfire/plugins/grid.hpp"
#include "wayfire/util/log.hpp"
#include "wayfire/view-transform.hpp"
Expand All @@ -15,7 +14,6 @@

#include <algorithm>
#include <cfloat>
#include <iostream>
#include <string>
#include <vector>

Expand All @@ -27,6 +25,30 @@ view_action_interface_t::~view_action_interface_t()
bool view_action_interface_t::execute(const std::string & name,
const std::vector<variant_t> & args)
{
const auto& execute_set_alpha = [&]
{
auto alpha = _validate_alpha(args);
if (std::get<0>(alpha))
{
_set_alpha(std::get<1>(alpha));
}
};

if (!_view)
{
// We have a non-toplevel view. We can only adjust alpha for it ...

if ((name != "set") || (args.size() != 2) || (wf::get_string(args[0]) != "alpha"))
{
LOGW("The only allowed action for non-toplevel views is",
" set alpha <double>, matched ", _nontoplevel);
return true;
}

execute_set_alpha();
return false;
}

if (name == "set")
{
auto id = wf::get_string(args.at(0));
Expand All @@ -51,11 +73,7 @@ bool view_action_interface_t::execute(const std::string & name,

if (id == "alpha")
{
auto alpha = _validate_alpha(args);
if (std::get<0>(alpha))
{
_set_alpha(std::get<1>(alpha));
}
execute_set_alpha();
} else if (id == "geometry")
{
auto geometry = _validate_geometry(args);
Expand Down Expand Up @@ -215,9 +233,10 @@ bool view_action_interface_t::execute(const std::string & name,
return true;
}

void view_action_interface_t::set_view(wayfire_toplevel_view view)
void view_action_interface_t::set_view(wayfire_view view)
{
_view = view;
_nontoplevel = view;
_view = toplevel_cast(view);
}

void view_action_interface_t::_maximize()
Expand Down Expand Up @@ -374,11 +393,11 @@ void view_action_interface_t::_set_alpha(float alpha)

// Apply view transformer if needed and set alpha.
auto tr = wf::ensure_named_transformer<wf::scene::view_2d_transformer_t>(
_view, wf::TRANSFORMER_2D, "alpha", _view);
_nontoplevel, wf::TRANSFORMER_2D, "alpha", _nontoplevel);
if (fabs(tr->alpha - alpha) > FLT_EPSILON)
{
tr->alpha = alpha;
_view->damage();
_nontoplevel->damage();

LOGI("View action interface: Alpha set to ", alpha, ".");
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/window-rules/view-action-interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class view_action_interface_t : public action_interface_t
virtual bool execute(const std::string & name,
const std::vector<variant_t> & args) override;

void set_view(wayfire_toplevel_view view);
void set_view(wayfire_view view);

private:
void _maximize();
Expand Down Expand Up @@ -55,6 +55,7 @@ class view_action_interface_t : public action_interface_t
wf::geometry_t _get_workspace_grid_geometry(wf::output_t *output) const;

wayfire_toplevel_view _view;
wayfire_view _nontoplevel;
};
} // End namespace wf.

Expand Down
13 changes: 6 additions & 7 deletions plugins/window-rules/window-rules.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <algorithm>
#include <cfloat>
#include <memory>
#include <vector>

Expand All @@ -26,7 +24,7 @@ class wayfire_window_rules_t : public wf::per_output_plugin_instance_t
public:
void init() override;
void fini() override;
void apply(const std::string & signal, wayfire_toplevel_view view);
void apply(const std::string & signal, wayfire_view view);

private:
void setup_rules_from_config();
Expand All @@ -35,7 +33,7 @@ class wayfire_window_rules_t : public wf::per_output_plugin_instance_t
// Created rule handler.
wf::signal::connection_t<wf::view_mapped_signal> on_view_mapped = [=] (wf::view_mapped_signal *ev)
{
apply("created", toplevel_cast(ev->view));
apply("created", ev->view);
};

// Maximized rule handler.
Expand Down Expand Up @@ -95,19 +93,20 @@ void wayfire_window_rules_t::fini()
}
}

void wayfire_window_rules_t::apply(const std::string & signal, wayfire_toplevel_view view)
void wayfire_window_rules_t::apply(const std::string & signal, wayfire_view view)
{
if (view == nullptr)
{
return;
}

if ((signal == "maximized") && (view->pending_tiled_edges() != wf::TILED_EDGES_ALL))
auto toplevel = toplevel_cast(view);
if ((signal == "maximized") && (!toplevel || (toplevel->pending_tiled_edges() != wf::TILED_EDGES_ALL)))
{
return;
}

if ((signal == "unmaximized") && (view->pending_tiled_edges() == wf::TILED_EDGES_ALL))
if ((signal == "unmaximized") && (!toplevel || (toplevel->pending_tiled_edges() == wf::TILED_EDGES_ALL)))
{
return;
}
Expand Down
Loading