Skip to content

Commit b930855

Browse files
committed
panel: Add outputs option for per-output configuration
This adds a new option named 'outputs' that is a list of output names on which a panel instance should be rendered. The default value is '*' wildcard, which means all outputs.
1 parent 8ad21ca commit b930855

5 files changed

Lines changed: 94 additions & 2 deletions

File tree

metadata/panel.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
<_short>Autohide Duration</_short>
3434
<default>300</default>
3535
</option>
36+
<option name="outputs" type="string">
37+
<_short>Outputs on which to show a panel instance</_short>
38+
<_long>A comma separated list of output names on which to show panel instances. Set to * wildcard for all outputs.</_long>
39+
<default>*</default>
40+
</option>
3641
<option name="position" type="string">
3742
<_short>Panel Position</_short>
3843
<default>top</default>

src/panel/panel.cpp

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,96 @@ class WayfirePanelApp::impl
411411
{
412412
public:
413413
std::map<WayfireOutput*, std::unique_ptr<WayfirePanel>> panels;
414+
WfOption<std::string> *panel_outputs = NULL;
414415
};
415416

416417
void WayfirePanelApp::on_config_reload()
417418
{
419+
if (!priv->panel_outputs)
420+
{
421+
priv->panel_outputs = new WfOption<std::string>("panel/outputs");
422+
}
423+
418424
for (auto& p : priv->panels)
419425
{
420426
p.second->handle_config_reload();
421427
}
422428
}
423429

430+
bool WayfirePanelApp::panel_allowed_by_config(bool allowed, std::string output_name)
431+
{
432+
if (allowed)
433+
{
434+
return std::string(*priv->panel_outputs).find("*") != std::string::npos ||
435+
std::string(*priv->panel_outputs).find(output_name) != std::string::npos;
436+
} else
437+
{
438+
return std::string(*priv->panel_outputs).find("*") == std::string::npos &&
439+
std::string(*priv->panel_outputs).find(output_name) == std::string::npos;
440+
}
441+
}
442+
424443
void WayfirePanelApp::on_activate()
425444
{
426445
WayfireShellApp::on_activate();
427446

447+
priv->panel_outputs->set_callback([=] ()
448+
{
449+
/* First case: Panel exists on the output but is not allowed by config: Remove panel */
450+
for (auto& o : *get_wayfire_outputs())
451+
{
452+
auto output = o.get();
453+
auto output_name = o->monitor->get_connector();
454+
if (panel_allowed_by_config(false, output_name))
455+
{
456+
std::cout << "Removing panel from output: " << output_name << std::endl;
457+
priv->panels.erase(output);
458+
}
459+
}
460+
461+
/* Second case: Panel doe not exist for the output but is allowed by config: Add panel */
462+
for (auto& o : *get_wayfire_outputs())
463+
{
464+
auto output = o.get();
465+
auto output_name = o->monitor->get_connector();
466+
467+
const auto it = std::find_if(priv->panels.begin(), priv->panels.end(),
468+
[&output_name] (const auto& panel)
469+
{
470+
return panel.first->monitor->get_connector() == output_name;
471+
});
472+
473+
if ((it == priv->panels.end()) && panel_allowed_by_config(true, output_name))
474+
{
475+
std::cout << "Adding panel for output: " << output_name << std::endl;
476+
priv->panels[output] = std::unique_ptr<WayfirePanel>(
477+
new WayfirePanel(output));
478+
479+
priv->panels[output]->handle_config_reload();
480+
priv->panels[output]->set_panel_app(this);
481+
priv->panels[output]->init_widgets();
482+
}
483+
}
484+
});
485+
486+
if (priv->panels.empty())
487+
{
488+
std::cout << std::endl <<
489+
"WARNING: wf-panel outputs option did not match any outputs, " \
490+
"so none were created. Set the [panel] outputs option to * " \
491+
"wildcard character in wf-shell configuariton file to match " \
492+
"all outputs, or set one or more of the following detected outputs:" <<
493+
std::endl << std::endl;
494+
495+
for (auto& o : *get_wayfire_outputs())
496+
{
497+
std::cout << o->monitor->get_connector() << std::endl;
498+
}
499+
500+
std::cout << std::endl << "Currently the [panel] outputs option is set to: " <<
501+
std::string(*priv->panel_outputs) << std::endl;
502+
}
503+
428504
const static std::vector<std::pair<std::string, std::string>> icon_sizes_args =
429505
{
430506
{"panel/minimal_height", ""},
@@ -466,8 +542,12 @@ std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance()
466542

467543
void WayfirePanelApp::handle_new_output(WayfireOutput *output)
468544
{
469-
priv->panels[output] = std::unique_ptr<WayfirePanel>(
470-
new WayfirePanel(output));
545+
if (panel_allowed_by_config(true, output->monitor->get_connector()))
546+
{
547+
std::cout << "Adding panel for output: " << output->monitor->get_connector() << std::endl;
548+
priv->panels[output] = std::unique_ptr<WayfirePanel>(
549+
new WayfirePanel(output));
550+
}
471551
}
472552

473553
WayfirePanel*WayfirePanelApp::panel_for_wl_output(wl_output *output)

src/panel/panel.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class WayfirePanelApp : public WayfireShellApp
4545
void on_activate() override;
4646
void handle_new_output(WayfireOutput *output) override;
4747
void handle_output_removed(WayfireOutput *output) override;
48+
bool panel_allowed_by_config(bool allowed, std::string output_name);
4849
void on_config_reload() override;
4950
void reload_css();
5051
std::shared_ptr<WayfireIPC> get_ipc_server_instance();

src/util/wf-shell-app.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ Gio::Application::Flags WayfireShellApp::get_extra_application_flags()
297297
return Gio::Application::Flags::NONE;
298298
}
299299

300+
std::vector<std::unique_ptr<WayfireOutput>>*WayfireShellApp::get_wayfire_outputs()
301+
{
302+
return &monitors;
303+
}
304+
300305
WayfireShellApp::WayfireShellApp()
301306
{}
302307

src/util/wf-shell-app.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class WayfireShellApp
8989
void add_css_file(std::string file, int priority);
9090
virtual Gio::Application::Flags get_extra_application_flags();
9191
virtual std::string get_application_name() = 0;
92+
std::vector<std::unique_ptr<WayfireOutput>> *get_wayfire_outputs();
9293

9394
/**
9495
* WayfireShellApp is a singleton class.

0 commit comments

Comments
 (0)