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

Reload window-rules on config change #877

Merged
merged 4 commits into from
Nov 25, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 29 additions & 11 deletions plugins/window-rules/window-rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ class wayfire_window_rules_t : public wf::plugin_interface_t
void apply(const std::string & signal, wf::signal_data_t *data);

private:
void setup_rules_from_config();
wf::lexer_t _lexer;

wf::signal_callback_t _created;
wf::signal_callback_t _maximized;
wf::signal_callback_t _unmaximized;
wf::signal_callback_t _minimized;
wf::signal_callback_t _fullscreened;
wf::signal_callback_t reload_config;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small thing: wf::signal_callback_t is deprecated, new code should use wf::signal_connection_t (and also whenever possible, please initialize lambda as soon as you declare it, I think it should be possible here).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. I will make changes and make a commit when I'm a little free. I more or less copied the code from commands plugin.


std::vector<std::shared_ptr<wf::rule_t>> _rules;

Expand All @@ -48,17 +50,7 @@ void wayfire_window_rules_t::init()
_lambda_registrations = wf::lambda_rules_registrations_t::get_instance();
_lambda_registrations->window_rule_instances++;

// Build rule list.
auto section = wf::get_core().config.get_section("window-rules");
for (auto opt : section->get_registered_options())
{
_lexer.reset(opt->get_value_str());
auto rule = wf::rule_parser_t().parse(_lexer);
if (rule != nullptr)
{
_rules.push_back(rule);
}
}
setup_rules_from_config();

// Created rule handler.
_created = [=] (wf::signal_data_t *data)
Expand Down Expand Up @@ -94,6 +86,13 @@ void wayfire_window_rules_t::init()
apply("fullscreened", data);
};
output->connect_signal("view-fullscreen", &_fullscreened);

/* Auto-reload config */
reload_config = [=] (wf::signal_data_t*)
{
setup_rules_from_config();
};
wf::get_core().connect_signal("reload-config", &reload_config);
}

void wayfire_window_rules_t::fini()
Expand All @@ -109,6 +108,8 @@ void wayfire_window_rules_t::fini()
{
wf::get_core().erase_data<wf::lambda_rules_registrations_t>();
}

wf::get_core().disconnect_signal("reload-config", &reload_config);
}

void wayfire_window_rules_t::apply(const std::string & signal,
Expand Down Expand Up @@ -203,4 +204,21 @@ void wayfire_window_rules_t::apply(const std::string & signal,
}
}

void wayfire_window_rules_t::setup_rules_from_config()
{
_rules.clear();

// Build rule list.
auto section = wf::get_core().config.get_section("window-rules");
for (auto opt : section->get_registered_options())
{
_lexer.reset(opt->get_value_str());
auto rule = wf::rule_parser_t().parse(_lexer);
if (rule != nullptr)
{
_rules.push_back(rule);
}
}
}

DECLARE_WAYFIRE_PLUGIN(wayfire_window_rules_t);