Skip to content

Commit b0576d5

Browse files
committed
panel: Fix widgets disappearing after tty switch
1 parent aeea5d7 commit b0576d5

3 files changed

Lines changed: 62 additions & 51 deletions

File tree

src/panel/panel.cpp

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -440,49 +440,67 @@ bool WayfirePanelApp::panel_allowed_by_config(bool allowed, std::string output_n
440440
}
441441
}
442442

443-
void WayfirePanelApp::on_activate()
443+
void WayfirePanelApp::update_panels()
444444
{
445-
WayfireShellApp::on_activate();
446-
447-
priv->panel_outputs->set_callback([=] ()
445+
/* First case: Panel exists on the output but is not allowed by config: Remove panel */
446+
for (auto& o : *get_wayfire_outputs())
448447
{
449-
/* First case: Panel exists on the output but is not allowed by config: Remove panel */
450-
for (auto& o : *get_wayfire_outputs())
448+
auto output = o.get();
449+
auto output_name = o->monitor->get_connector();
450+
if (panel_allowed_by_config(false, output_name))
451451
{
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-
}
452+
std::cout << "Removing panel from output: " << output_name << std::endl;
453+
priv->panels.erase(output);
459454
}
455+
}
460456

461-
/* Second case: Panel does 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();
457+
/* Second case: Panel does not exist for the output but is allowed by config: Add panel */
458+
for (auto& o : *get_wayfire_outputs())
459+
{
460+
auto output = o.get();
461+
auto output_name = o->monitor->get_connector();
466462

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-
});
463+
const auto it = std::find_if(priv->panels.begin(), priv->panels.end(),
464+
[&output_name] (const auto& panel)
465+
{
466+
return panel.first->monitor->get_connector() == output_name;
467+
});
472468

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));
469+
if ((it == priv->panels.end()) && panel_allowed_by_config(true, output_name))
470+
{
471+
std::cout << "Adding panel for output: " << output_name << std::endl;
472+
priv->panels[output] = std::unique_ptr<WayfirePanel>(
473+
new WayfirePanel(output));
474+
}
475+
}
478476

479-
priv->panels[output]->handle_config_reload();
480-
priv->panels[output]->set_panel_app(this);
481-
priv->panels[output]->init_widgets();
482-
}
477+
if (ipc_server)
478+
{
479+
for (auto& p : priv->panels)
480+
{
481+
p.second->handle_config_reload();
482+
p.second->set_panel_app(this);
483+
p.second->init_widgets();
483484
}
485+
}
486+
}
487+
488+
void WayfirePanelApp::on_activate()
489+
{
490+
WayfireShellApp::on_activate();
491+
492+
priv->panel_outputs->set_callback([=] ()
493+
{
494+
update_panels();
484495
});
485496

497+
if (!ipc_server)
498+
{
499+
ipc_server = WayfireIPC::get_instance();
500+
}
501+
502+
update_panels();
503+
486504
if (priv->panels.empty())
487505
{
488506
std::cout << std::endl <<
@@ -526,13 +544,6 @@ void WayfirePanelApp::on_activate()
526544
new CssFromConfigFont("panel/battery_font", ".battery {", "}");
527545
new CssFromConfigFont("panel/clock_font", ".clock {", "}");
528546
new CssFromConfigFont("panel/weather_font", ".weather {", "}");
529-
530-
ipc_server = WayfireIPC::get_instance();
531-
for (auto& p : priv->panels)
532-
{
533-
p.second->set_panel_app(this);
534-
p.second->init_widgets();
535-
}
536547
}
537548

538549
std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance()
@@ -542,12 +553,7 @@ std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance()
542553

543554
void WayfirePanelApp::handle_new_output(WayfireOutput *output)
544555
{
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-
}
556+
update_panels();
551557
}
552558

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

src/panel/panel.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ class WayfirePanelApp : public WayfireShellApp
4646
void handle_new_output(WayfireOutput *output) override;
4747
void handle_output_removed(WayfireOutput *output) override;
4848
bool panel_allowed_by_config(bool allowed, std::string output_name);
49+
void update_panels();
4950
void on_config_reload() override;
5051
void reload_css();
5152
std::shared_ptr<WayfireIPC> get_ipc_server_instance();
52-
std::shared_ptr<WayfireIPC> ipc_server;
53+
std::shared_ptr<WayfireIPC> ipc_server = nullptr;
5354

5455
private:
5556
WayfirePanelApp();

src/util/wf-shell-app.cpp

Lines changed: 9 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

0 commit comments

Comments
 (0)