@@ -419,20 +419,109 @@ class WayfirePanelApp::impl
419419{
420420 public:
421421 std::map<WayfireOutput*, std::unique_ptr<WayfirePanel>> panels;
422+ WfOption<std::string> *panel_outputs = NULL ;
422423};
423424
424425void WayfirePanelApp::on_config_reload ()
425426{
427+ if (!priv->panel_outputs )
428+ {
429+ priv->panel_outputs = new WfOption<std::string>(" panel/outputs" );
430+ }
431+
426432 for (auto & p : priv->panels )
427433 {
428434 p.second ->handle_config_reload ();
429435 }
430436}
431437
438+ bool WayfirePanelApp::panel_allowed_by_config (bool allowed, std::string output_name)
439+ {
440+ if (allowed)
441+ {
442+ return std::string (*priv->panel_outputs ).find (" *" ) != std::string::npos ||
443+ std::string (*priv->panel_outputs ).find (output_name) != std::string::npos;
444+ } else
445+ {
446+ return std::string (*priv->panel_outputs ).find (" *" ) == std::string::npos &&
447+ std::string (*priv->panel_outputs ).find (output_name) == std::string::npos;
448+ }
449+ }
450+
451+ void WayfirePanelApp::update_panels ()
452+ {
453+ for (auto & o : *get_wayfire_outputs ())
454+ {
455+ auto output = o.get ();
456+ auto output_name = o->monitor ->get_connector ();
457+
458+ if (panel_allowed_by_config (false , output_name))
459+ {
460+ std::cout << " Removing panel from output: " << output_name << std::endl;
461+ priv->panels .erase (output);
462+ }
463+
464+ const auto it = std::find_if (priv->panels .begin (), priv->panels .end (),
465+ [&output_name] (const auto & panel)
466+ {
467+ return panel.first ->monitor ->get_connector () == output_name;
468+ });
469+
470+ if ((it == priv->panels .end ()) && panel_allowed_by_config (true , output_name))
471+ {
472+ std::cout << " Adding panel for output: " << output_name << std::endl;
473+ priv->panels [output] = std::unique_ptr<WayfirePanel>(
474+ new WayfirePanel (output));
475+
476+ if (ipc_server)
477+ {
478+ priv->panels [output]->handle_config_reload ();
479+ priv->panels [output]->set_panel_app (this );
480+ priv->panels [output]->init_widgets ();
481+ }
482+ }
483+ }
484+ }
485+
432486void WayfirePanelApp::on_activate ()
433487{
434488 WayfireShellApp::on_activate ();
435489
490+ priv->panel_outputs ->set_callback ([=] ()
491+ {
492+ update_panels ();
493+ });
494+
495+ if (!ipc_server)
496+ {
497+ ipc_server = WayfireIPC::get_instance ();
498+ }
499+
500+ for (auto & p : priv->panels )
501+ {
502+ p.second ->handle_config_reload ();
503+ p.second ->set_panel_app (this );
504+ p.second ->init_widgets ();
505+ }
506+
507+ if (priv->panels .empty ())
508+ {
509+ std::cout << std::endl <<
510+ " WARNING: wf-panel outputs option did not match any outputs, " \
511+ " so none were created. Set the [panel] outputs option to * " \
512+ " wildcard character in wf-shell configuariton file to match " \
513+ " all outputs, or set one or more of the following detected outputs:" <<
514+ std::endl << std::endl;
515+
516+ for (auto & o : *get_wayfire_outputs ())
517+ {
518+ std::cout << o->monitor ->get_connector () << std::endl;
519+ }
520+
521+ std::cout << std::endl << " Currently the [panel] outputs option is set to: " <<
522+ std::string (*priv->panel_outputs ) << std::endl;
523+ }
524+
436525 const static std::vector<std::pair<std::string, std::string>> icon_sizes_args =
437526 {
438527 {" panel/minimal_height" , " " },
@@ -458,13 +547,6 @@ void WayfirePanelApp::on_activate()
458547 new CssFromConfigFont (" panel/battery_font" , " .battery {" , " }" );
459548 new CssFromConfigFont (" panel/clock_font" , " .clock {" , " }" );
460549 new CssFromConfigFont (" panel/weather_font" , " .weather {" , " }" );
461-
462- ipc_server = WayfireIPC::get_instance ();
463- for (auto & p : priv->panels )
464- {
465- p.second ->set_panel_app (this );
466- p.second ->init_widgets ();
467- }
468550}
469551
470552std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance ()
@@ -474,8 +556,7 @@ std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance()
474556
475557void WayfirePanelApp::handle_new_output (WayfireOutput *output)
476558{
477- priv->panels [output] = std::unique_ptr<WayfirePanel>(
478- new WayfirePanel (output));
559+ update_panels ();
479560}
480561
481562WayfirePanel*WayfirePanelApp::panel_for_wl_output (wl_output *output)
0 commit comments