Commit 4324de38 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone] Fixed the FD watch event source priority.

The event source based on FD watcher had wrong priority, which resulted in that
GDK and GTK events stuck forever, and GTK dialogs won't show up.

This CL fixes the priority of the FD watcher source to be higher than the one
for the main work source, and also enables the GTK file selection dialog in
Ozone builds.

The implementation currently requires use_glib=true.  There are other things
(e.g., dialog modality) that will be fixed in subsequent CLs.

R=kylechar@chromium.org, thomasanderson@chromium.org

Bug: 1008755
Change-Id: I673cff846ea6d03db25190481fe391b4c6e76650
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1892954Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Alexander Dunaev <adunaev@igalia.com>
Cr-Commit-Position: refs/heads/master@{#713089}
parent a8d28954
...@@ -20,6 +20,21 @@ namespace base { ...@@ -20,6 +20,21 @@ namespace base {
namespace { namespace {
// Priorities of event sources are important to let everything be processed.
// In particular, GTK event source should have the highest priority (because
// UI events come from it), then Wayland events (the ones coming from the FD
// watcher), and the lowest priority is GLib events (our base message pump).
//
// The g_source API uses ints to denote priorities, and the lower is its value,
// the higher is the priority (i.e., they are ordered backwards).
constexpr int kPriorityWork = G_PRIORITY_DEFAULT_IDLE;
constexpr int kPriorityFdWatch = G_PRIORITY_DEFAULT_IDLE - 10;
// See the explanation above.
static_assert(G_PRIORITY_DEFAULT < kPriorityFdWatch &&
kPriorityFdWatch < kPriorityWork,
"Wrong priorities are set for event sources!");
// Return a timeout suitable for the glib loop according to |next_task_time|, -1 // Return a timeout suitable for the glib loop according to |next_task_time|, -1
// to block forever, 0 to return right away, or a timeout in milliseconds from // to block forever, 0 to return right away, or a timeout in milliseconds from
// now. // now.
...@@ -218,8 +233,7 @@ MessagePumpGlib::MessagePumpGlib() ...@@ -218,8 +233,7 @@ MessagePumpGlib::MessagePumpGlib()
work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource)); work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource));
static_cast<WorkSource*>(work_source_)->pump = this; static_cast<WorkSource*>(work_source_)->pump = this;
g_source_add_poll(work_source_, wakeup_gpollfd_.get()); g_source_add_poll(work_source_, wakeup_gpollfd_.get());
// Use a low priority so that we let other events in the queue go first. g_source_set_priority(work_source_, kPriorityWork);
g_source_set_priority(work_source_, G_PRIORITY_DEFAULT_IDLE);
// This is needed to allow Run calls inside Dispatch. // This is needed to allow Run calls inside Dispatch.
g_source_set_can_recurse(work_source_, TRUE); g_source_set_can_recurse(work_source_, TRUE);
g_source_attach(work_source_, context_); g_source_attach(work_source_, context_);
...@@ -294,6 +308,7 @@ bool MessagePumpGlib::FdWatchController::InitOrUpdate(int fd, ...@@ -294,6 +308,7 @@ bool MessagePumpGlib::FdWatchController::InitOrUpdate(int fd,
g_source_add_poll(source_, poll_fd_.get()); g_source_add_poll(source_, poll_fd_.get());
g_source_set_can_recurse(source_, TRUE); g_source_set_can_recurse(source_, TRUE);
g_source_set_callback(source_, nullptr, nullptr, nullptr); g_source_set_callback(source_, nullptr, nullptr, nullptr);
g_source_set_priority(source_, kPriorityFdWatch);
watcher_ = watcher; watcher_ = watcher;
return true; return true;
......
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/shell_dialogs/select_file_dialog.h" #include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
#if defined(USE_X11) #if defined(USE_X11)
#include "ui/events/platform/x11/x11_event_source.h" // nogncheck #include "ui/events/platform/x11/x11_event_source.h" // nogncheck
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" // nogncheck
#endif #endif
namespace { namespace {
...@@ -66,14 +66,12 @@ void OnFileFilterDataDestroyed(std::string* file_extension) { ...@@ -66,14 +66,12 @@ void OnFileFilterDataDestroyed(std::string* file_extension) {
delete file_extension; delete file_extension;
} }
#if defined(USE_X11) // Runs DesktopWindowTreeHostLinux::EnableEventListening() when the file-picker
// Runs DesktopWindowTreeHostX11::EnableEventListening() when the file-picker
// is closed. // is closed.
void OnFilePickerDestroy(base::OnceClosure* callback_raw) { void OnFilePickerDestroy(base::OnceClosure* callback_raw) {
std::unique_ptr<base::OnceClosure> callback = base::WrapUnique(callback_raw); std::unique_ptr<base::OnceClosure> callback = base::WrapUnique(callback_raw);
std::move(*callback).Run(); std::move(*callback).Run();
} }
#endif
} // namespace } // namespace
...@@ -189,20 +187,18 @@ void SelectFileDialogImplGTK::SelectFileImpl( ...@@ -189,20 +187,18 @@ void SelectFileDialogImplGTK::SelectFileImpl(
params_map_[dialog] = params; params_map_[dialog] = params;
#if defined(USE_X11)
// Disable input events handling in the host window to make this dialog modal. // Disable input events handling in the host window to make this dialog modal.
if (owning_window) { if (owning_window) {
aura::WindowTreeHost* host = owning_window->GetHost(); views::DesktopWindowTreeHostLinux* host =
static_cast<views::DesktopWindowTreeHostLinux*>(
owning_window->GetHost());
if (host) { if (host) {
// In some circumstances (e.g. dialog from flash plugin) the mouse has // In some circumstances (e.g. dialog from flash plugin) the mouse has
// been captured and by turning off event listening, it is never // been captured and by turning off event listening, it is never
// released. So we manually ensure there is no current capture. // released. So we manually ensure there is no current capture.
host->ReleaseCapture(); host->ReleaseCapture();
std::unique_ptr<base::OnceClosure> callback = std::unique_ptr<base::OnceClosure> callback =
std::make_unique<base::OnceClosure>( std::make_unique<base::OnceClosure>(host->DisableEventListening());
views::DesktopWindowTreeHostLinux::GetHostForWidget(
host->GetAcceleratedWidget())
->DisableEventListening());
// OnFilePickerDestroy() is called when |dialog| destroyed, which allows // OnFilePickerDestroy() is called when |dialog| destroyed, which allows
// to invoke the callback function to re-enable event handling on the // to invoke the callback function to re-enable event handling on the
// owning window. // owning window.
...@@ -212,7 +208,6 @@ void SelectFileDialogImplGTK::SelectFileImpl( ...@@ -212,7 +208,6 @@ void SelectFileDialogImplGTK::SelectFileImpl(
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
} }
} }
#endif
#if !GTK_CHECK_VERSION(3, 90, 0) #if !GTK_CHECK_VERSION(3, 90, 0)
gtk_widget_show_all(dialog); gtk_widget_show_all(dialog);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment