Skip to content

Commit 105e581

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

3 files changed

Lines changed: 59 additions & 46 deletions

File tree

src/panel/panel.cpp

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -440,49 +440,69 @@ 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())
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();
462+
463+
const auto it = std::find_if(priv->panels.begin(), priv->panels.end(),
464+
[&output_name] (const auto& panel)
463465
{
464-
auto output = o.get();
465-
auto output_name = o->monitor->get_connector();
466+
return panel.first->monitor->get_connector() == output_name;
467+
});
466468

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-
});
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));
472474

473-
if ((it == priv->panels.end()) && panel_allowed_by_config(true, output_name))
475+
if (ipc_server)
474476
{
475-
std::cout << "Adding panel for output: " << output_name << std::endl;
476-
priv->panels[output] = std::unique_ptr<WayfirePanel>(
477-
new WayfirePanel(output));
478-
479477
priv->panels[output]->handle_config_reload();
480478
priv->panels[output]->set_panel_app(this);
481479
priv->panels[output]->init_widgets();
482480
}
483481
}
482+
}
483+
}
484+
485+
void WayfirePanelApp::on_activate()
486+
{
487+
WayfireShellApp::on_activate();
488+
489+
priv->panel_outputs->set_callback([=] ()
490+
{
491+
update_panels();
484492
});
485493

494+
if (!ipc_server)
495+
{
496+
ipc_server = WayfireIPC::get_instance();
497+
}
498+
499+
for (auto& p : priv->panels)
500+
{
501+
p.second->handle_config_reload();
502+
p.second->set_panel_app(this);
503+
p.second->init_widgets();
504+
}
505+
486506
if (priv->panels.empty())
487507
{
488508
std::cout << std::endl <<
@@ -526,13 +546,6 @@ void WayfirePanelApp::on_activate()
526546
new CssFromConfigFont("panel/battery_font", ".battery {", "}");
527547
new CssFromConfigFont("panel/clock_font", ".clock {", "}");
528548
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-
}
536549
}
537550

538551
std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance()
@@ -542,12 +555,7 @@ std::shared_ptr<WayfireIPC> WayfirePanelApp::get_ipc_server_instance()
542555

543556
void WayfirePanelApp::handle_new_output(WayfireOutput *output)
544557
{
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-
}
558+
update_panels();
551559
}
552560

553561
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)