Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/util/wf-autohide-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ WayfireAutohidingWindow::WayfireAutohidingWindow(WayfireOutput *output,
auto display = Gdk::Display::get_default();
signals.push_back(WayfireShellApp::get().signal_monitor_list_changed().connect([=] ()
{
Glib::signal_idle().connect_once([=] () { this->reinit_ext_hotspots(); });
this->reinit_ext_hotspots();
}));


Expand Down Expand Up @@ -280,13 +280,6 @@ void WayfireAutohidingWindow::reinit_ext_hotspots()
}

adjacent_edges_hotspots.clear();
if ((this->output->monitor == nullptr) || !(this->output->monitor->is_valid()))
{
// Catch a too-soon reinit
std::cout << "Monitor is not valid" << std::endl;
Glib::signal_timeout().connect_once([this] () {reinit_ext_hotspots();}, 100);
return;
}

std::cout << "Monitor reinit hotspots " << this->output->monitor->get_connector() << std::endl;

Expand Down
74 changes: 43 additions & 31 deletions src/util/wf-shell-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,45 +248,57 @@ void WayfireShellApp::on_activate()
}
}

void WayfireShellApp::output_list_updated(const int pos, const int rem, const int add)
bool WayfireShellApp::sanity_check_outputs()
{
auto display = Gdk::Display::get_default();
auto monitor_list = display->get_monitors();
auto context = g_main_context_default();

for (int i = pos; i < pos + add; i++)
for (guint count = 0; count < monitor_list->get_n_items(); count++)
{
auto monitor = std::dynamic_pointer_cast<Gdk::Monitor>(monitor_list->get_object(i));

/* XXX: Workaround bug that causes a new output to have
* no name. We use the name for various reasons so we need
* it to be valid when signaling new output to the apps.
* We set a timer for 100ms, then print a warning if the
* timeout fired. */
auto monitor = std::dynamic_pointer_cast<Gdk::Monitor>(monitor_list->get_object(count));
std::string output_name = monitor->get_connector();
if (output_name.empty())
{
return false;
}
}

return true;
}

bool cancel_wait = false;
auto timeout_signal = Glib::signal_timeout().connect([&cancel_wait] ()
void WayfireShellApp::output_list_updated(const int pos, const int rem, const int add)
{
/* XXX: Workaround bug that causes a new output to have
* no name. We use the name for various reasons so we need
* it to be valid when signaling new output to the apps.
* We set a timer for 100ms, then print a warning if the
* timeout fired.
*
* Moved up here because context-looping as before would cause a crash
* on quick plug/unplug
*/
debounce_monitor_hotplug.disconnect();

if (!sanity_check_outputs())
{
debounce_monitor_hotplug = Glib::signal_idle().connect([=] ()
{
cancel_wait = true;
output_list_updated(0, 0, 0);
return G_SOURCE_REMOVE;
}, 100);
});
return;
}

while (output_name.empty() && !cancel_wait)
{
g_main_context_iteration(context, true);
output_name = monitor->get_connector();
}
/* XXX: End workaround*/

timeout_signal.disconnect();
if (cancel_wait)
{
std::cerr << "Timeout reached while waiting for output name." <<
(output_name.empty() ?
" Our local output object does not have a name at this point." :
"") << std::endl;
} /* XXX: End workaround. */
auto display = Gdk::Display::get_default();
auto monitor_list = display->get_monitors();

for (guint count = 0; count < monitor_list->get_n_items(); count++)
{
auto monitor = std::dynamic_pointer_cast<Gdk::Monitor>(monitor_list->get_object(count));

std::string output_name = monitor->get_connector();
if (monitor->get_connector() == live_preview_output_name)
{
live_preview_output = gdk_wayland_monitor_get_wl_output(monitor->gobj());
Expand All @@ -303,7 +315,6 @@ void WayfireShellApp::output_list_updated(const int pos, const int rem, const in

void WayfireShellApp::add_output(GMonitor monitor)
{
std::cout << monitor->get_connector() << " plug" << std::endl;
auto it = std::find_if(monitors.begin(), monitors.end(),
[monitor] (auto& output) { return output->monitor == monitor; });

Expand All @@ -328,13 +339,12 @@ void WayfireShellApp::add_output(GMonitor monitor)

void WayfireShellApp::rem_output(GMonitor monitor)
{
std::cout << monitor->get_connector() << " unplug" << std::endl;
auto it = std::find_if(monitors.begin(), monitors.end(),
[monitor] (auto& output) { return output->monitor == monitor; });

handle_output_removed(it->get());
if (it != monitors.end())
{
handle_output_removed(it->get());
monitors.erase(it);
} else
{
Expand Down Expand Up @@ -380,7 +390,9 @@ void WayfireShellApp::init_app()
}

WayfireShellApp::~WayfireShellApp()
{}
{
debounce_monitor_hotplug.disconnect();
}

std::unique_ptr<WayfireShellApp> WayfireShellApp::instance;
WayfireShellApp& WayfireShellApp::get()
Expand Down
3 changes: 3 additions & 0 deletions src/util/wf-shell-app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ class WayfireShellApp
std::vector<Glib::RefPtr<Gtk::CssProvider>> css_rules;
sigc::signal<void()> monitor_list_changed;

bool sanity_check_outputs();

protected:
/** This should be initialized by the subclass in each program which uses
* wf-shell-app */
bool alternative_monitors = false; /* Used to skip monitor management in lockscreen */
static std::unique_ptr<WayfireShellApp> instance;
std::optional<std::string> cmdline_config;
std::optional<std::string> cmdline_css;
sigc::connection debounce_monitor_hotplug;

Glib::RefPtr<Gtk::Application> app;
bool activated = false;
Expand Down
Loading