fix: add Wayland support (#26022)

This commit is contained in:
Valentin Hăloiu 2020-10-20 20:24:52 +02:00 committed by GitHub
parent d38c47e748
commit c4525b4ea6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 272 additions and 159 deletions

View file

@ -15,9 +15,16 @@
#include "shell/browser/unresponsive_suppressor.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "ui/base/glib/glib_signal.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gtk/gtk_util.h"
#if defined(USE_X11)
#include "ui/events/platform/x11/x11_event_source.h"
#endif
#if defined(USE_OZONE) || defined(USE_X11)
#include "ui/base/ui_base_features.h"
#endif
namespace file_dialog {
DialogSettings::DialogSettings() = default;
@ -135,11 +142,15 @@ class FileChooserDialog {
this);
gtk_widget_show_all(dialog_);
// We need to call gtk_window_present after making the widgets visible to
// make sure window gets correctly raised and gets focus.
x11::Time time = ui::X11EventSource::GetInstance()->GetTimestamp();
gtk_window_present_with_time(GTK_WINDOW(dialog_),
static_cast<uint32_t>(time));
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform()) {
// We need to call gtk_window_present after making the widgets visible to
// make sure window gets correctly raised and gets focus.
x11::Time time = ui::X11EventSource::GetInstance()->GetTimestamp();
gtk_window_present_with_time(GTK_WINDOW(dialog_),
static_cast<uint32_t>(time));
}
#endif
}
void RunSaveAsynchronous(

View file

@ -22,6 +22,10 @@
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
#if defined(USE_OZONE) || defined(USE_X11)
#include "ui/base/ui_base_features.h"
#endif
namespace electron {
namespace gtkui {
@ -222,12 +226,14 @@ void BuildSubmenuFromModel(ui::MenuModel* model,
}
#if defined(USE_X11)
ui::Accelerator accelerator;
if (model->GetAcceleratorAt(i, &accelerator)) {
gtk_widget_add_accelerator(menu_item, "activate", nullptr,
GetGdkKeyCodeForAccelerator(accelerator),
GetGdkModifierForAccelerator(accelerator),
GTK_ACCEL_VISIBLE);
if (!features::IsUsingOzonePlatform()) {
ui::Accelerator accelerator;
if (model->GetAcceleratorAt(i, &accelerator)) {
gtk_widget_add_accelerator(menu_item, "activate", nullptr,
GetGdkKeyCodeForAccelerator(accelerator),
GetGdkModifierForAccelerator(accelerator),
GTK_ACCEL_VISIBLE);
}
}
#endif

View file

@ -13,10 +13,17 @@
#include "shell/browser/native_window_views.h"
#include "shell/browser/unresponsive_suppressor.h"
#include "ui/base/glib/glib_signal.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gtk/gtk_util.h"
#if defined(USE_X11)
#include "ui/events/platform/x11/x11_event_source.h"
#endif
#if defined(USE_OZONE) || defined(USE_X11)
#include "ui/base/ui_base_features.h"
#endif
#define ANSI_FOREGROUND_RED "\x1b[31m"
#define ANSI_FOREGROUND_BLACK "\x1b[30m"
#define ANSI_TEXT_BOLD "\x1b[1m"
@ -133,11 +140,16 @@ class GtkMessageBox : public NativeWindowObserver {
void Show() {
gtk_widget_show(dialog_);
// We need to call gtk_window_present after making the widgets visible to
// make sure window gets correctly raised and gets focus.
x11::Time time = ui::X11EventSource::GetInstance()->GetTimestamp();
gtk_window_present_with_time(GTK_WINDOW(dialog_),
static_cast<uint32_t>(time));
#if defined(USE_X11)
if (!features::IsUsingOzonePlatform()) {
// We need to call gtk_window_present after making the widgets visible to
// make sure window gets correctly raised and gets focus.
x11::Time time = ui::X11EventSource::GetInstance()->GetTimestamp();
gtk_window_present_with_time(GTK_WINDOW(dialog_),
static_cast<uint32_t>(time));
}
#endif
}
int RunSynchronous() {

View file

@ -17,7 +17,7 @@
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
#if defined(USE_X11)
#if defined(OS_LINUX)
#include "ui/gtk/gtk_util.h"
#endif
@ -282,7 +282,7 @@ void MenuBar::ButtonPressed(views::Button* source, const ui::Event& event) {
void MenuBar::RefreshColorCache() {
const ui::NativeTheme* theme = GetNativeTheme();
if (theme) {
#if defined(USE_X11)
#if defined(OS_LINUX)
background_color_ = gtk::GetBgColor("GtkMenuBar#menubar");
enabled_color_ =
gtk::GetFgColor("GtkMenuBar#menubar GtkMenuItem#menuitem GtkLabel");
@ -319,7 +319,7 @@ void MenuBar::UpdateViewColors() {
// set child colors
if (menu_model_ == nullptr)
return;
#if defined(USE_X11)
#if defined(OS_LINUX)
const auto& textColor = has_focus_ ? enabled_color_ : disabled_color_;
for (auto* child : GetChildrenInZOrder()) {
auto* button = static_cast<SubmenuButton*>(child);

View file

@ -90,7 +90,7 @@ class MenuBar : public views::AccessiblePaneView,
void RefreshColorCache();
SkColor background_color_;
#if defined(USE_X11)
#if defined(OS_LINUX)
SkColor enabled_color_;
SkColor disabled_color_;
#endif