Skip to content

Commit d535efa

Browse files
authored
Merge pull request #356 from WayfireWM/panel-outputs
panel: Add outputs option for per-output configuration
2 parents a77b467 + aa34acb commit d535efa

5 files changed

Lines changed: 113 additions & 15 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: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

424425
void 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+
432486
void 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

470552
std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance()
@@ -474,8 +556,7 @@ std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance()
474556

475557
void WayfirePanelApp::handle_new_output(WayfireOutput *output)
476558
{
477-
priv->panels[output] = std::unique_ptr<WayfirePanel>(
478-
new WayfirePanel(output));
559+
update_panels();
479560
}
480561

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

src/panel/panel.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ 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);
49+
void update_panels();
4850
void on_config_reload() override;
4951
void reload_css();
5052
std::shared_ptr<WayfireIPC> get_ipc_server_instance();
51-
std::shared_ptr<WayfireIPC> ipc_server;
53+
std::shared_ptr<WayfireIPC> ipc_server = nullptr;
5254

5355
private:
5456
WayfirePanelApp();

src/util/wf-shell-app.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,16 @@ void WayfireShellApp::on_activate()
249249

250250
void WayfireShellApp::output_list_updated(const int pos, const int rem, const int add)
251251
{
252-
auto display = Gdk::Display::get_default();
253-
auto monitors = display->get_monitors();
254-
for (int i = 0; i < add; i++)
252+
auto display = Gdk::Display::get_default();
253+
auto monitors = display->get_monitors();
254+
int num_monitors = monitors->get_n_items();
255+
for (int i = 0; i < num_monitors; i++)
255256
{
256-
auto obj = std::dynamic_pointer_cast<Gdk::Monitor>(monitors->get_object(i + pos));
257-
add_output(obj);
257+
auto obj = std::dynamic_pointer_cast<Gdk::Monitor>(monitors->get_object(i));
258+
if (obj && !obj->get_connector().empty())
259+
{
260+
add_output(obj);
261+
}
258262
}
259263
}
260264

@@ -297,6 +301,11 @@ Gio::Application::Flags WayfireShellApp::get_extra_application_flags()
297301
return Gio::Application::Flags::NONE;
298302
}
299303

304+
std::vector<std::unique_ptr<WayfireOutput>>*WayfireShellApp::get_wayfire_outputs()
305+
{
306+
return &monitors;
307+
}
308+
300309
WayfireShellApp::WayfireShellApp()
301310
{}
302311

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)