linux: Add CefWindowDelegate::GetLinuxWindowProperties (fixes #3383)

This commit is contained in:
Pedro de Carvalho Gomes 2024-08-05 12:12:33 -04:00 committed by Marshall Greenblatt
parent 295ea1f715
commit b61c106b6b
11 changed files with 193 additions and 10 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=a2e5caf4dc0ed5b43a6075678e3b7b7ae83834ae$
// $hash=bafa7ddf3dfbc3fa82b1fb8a064b51f0791b29b6$
//
#ifndef CEF_INCLUDE_CAPI_VIEWS_CEF_WINDOW_DELEGATE_CAPI_H_
@ -280,6 +280,15 @@ typedef struct _cef_window_delegate_t {
///
cef_runtime_style_t(CEF_CALLBACK* get_window_runtime_style)(
struct _cef_window_delegate_t* self);
///
/// Return Linux-specific window properties for correctly handling by window
/// managers
///
int(CEF_CALLBACK* get_linux_window_properties)(
struct _cef_window_delegate_t* self,
struct _cef_window_t* window,
struct _cef_linux_window_properties_t* properties);
} cef_window_delegate_t;
#ifdef __cplusplus

View File

@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "80fd8337eb375cb48d617cd7cf01b531ea577efc"
#define CEF_API_HASH_UNIVERSAL "231671a5669eaa29cd2c01a2e459857945c4ea01"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "81d92ace6598de3106b212d70454022678fb2e2b"
#define CEF_API_HASH_PLATFORM "f8a2808cad9b2250c0a5096c043547f8942e2b7d"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "c7b1f631ac53d876ea88f60a7f768b8f1ad1f0d8"
#define CEF_API_HASH_PLATFORM "064c88eb32b8b9932d85ed8023a11656647a3ac0"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "8dc9b5f33e800f9ac83253d6c7d714952ba8fa85"
#define CEF_API_HASH_PLATFORM "e934aa611c47fda69dbef4e46e11255300e37f9c"
#endif
#ifdef __cplusplus

View File

@ -1847,6 +1847,34 @@ typedef struct _cef_screen_info_t {
cef_rect_t available_rect;
} cef_screen_info_t;
///
/// Linux window properties, such as X11's WM_CLASS or Wayland's app_id.
/// Those are passed to CefWindowDelegate, so the client can set them
/// for the CefWindow's top-level. Thus, allowing window managers to correctly
/// display the application's information (e.g., icons).
///
typedef struct _cef_linux_window_properties_t {
///
/// Main window's Wayland's app_id
///
cef_string_t wayland_app_id;
///
/// Main window's WM_CLASS_CLASS in X11
///
cef_string_t wm_class_class;
///
/// Main window's WM_CLASS_NAME in X11
///
cef_string_t wm_class_name;
///
/// Main window's WM_WINDOW_ROLE in X11
///
cef_string_t wm_role_name;
} cef_linux_window_properties_t;
///
/// Supported menu IDs. Non-English translations can be provided for the
/// IDS_MENU_* strings in CefResourceBundleHandler::GetLocalizedString().

View File

@ -783,4 +783,36 @@ struct CefTaskInfoTraits {
///
using CefTaskInfo = CefStructBase<CefTaskInfoTraits>;
struct CefLinuxWindowPropertiesTraits {
using struct_type = cef_linux_window_properties_t;
static inline void init(struct_type* s) {}
static inline void clear(struct_type* s) {
cef_string_clear(&s->wayland_app_id);
cef_string_clear(&s->wm_class_class);
cef_string_clear(&s->wm_class_name);
cef_string_clear(&s->wm_role_name);
}
static inline void set(const struct_type* src,
struct_type* target,
bool copy) {
cef_string_set(src->wayland_app_id.str, src->wayland_app_id.length,
&target->wayland_app_id, copy);
cef_string_set(src->wm_class_class.str, src->wm_class_class.length,
&target->wm_class_class, copy);
cef_string_set(src->wm_class_name.str, src->wm_class_name.length,
&target->wm_class_name, copy);
cef_string_set(src->wm_role_name.str, src->wm_role_name.length,
&target->wm_role_name, copy);
}
};
///
/// Class representing the Linux-specific window properties required
/// for the window managers to correct group and display the window.
///
using CefLinuxWindowProperties = CefStructBase<CefLinuxWindowPropertiesTraits>;
#endif // CEF_INCLUDE_INTERNAL_CEF_TYPES_WRAPPERS_H_

View File

@ -278,6 +278,16 @@ class CefWindowDelegate : public CefPanelDelegate {
virtual cef_runtime_style_t GetWindowRuntimeStyle() {
return CEF_RUNTIME_STYLE_DEFAULT;
}
///
/// Return Linux-specific window properties for correctly handling by window
/// managers
///
/*--cef()--*/
virtual bool GetLinuxWindowProperties(CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) {
return false;
}
};
#endif // CEF_INCLUDE_VIEWS_CEF_WINDOW_DELEGATE_H_

View File

@ -429,6 +429,16 @@ void CefWindowView::CreateWidget(gfx::AcceleratedWidget parent_widget) {
auto bounds = cef_delegate()->GetInitialBounds(cef_window);
params.bounds = gfx::Rect(bounds.x, bounds.y, bounds.width, bounds.height);
#if BUILDFLAG(IS_LINUX)
CefLinuxWindowProperties linux_props;
if (cef_delegate()->GetLinuxWindowProperties(cef_window, linux_props)) {
params.wayland_app_id = CefString(&linux_props.wayland_app_id);
params.wm_class_class = CefString(&linux_props.wm_class_class);
params.wm_class_name = CefString(&linux_props.wm_class_name);
params.wm_role_name = CefString(&linux_props.wm_role_name);
}
#endif
if (has_native_parent) {
DCHECK(!params.bounds.IsEmpty());
} else {

View File

@ -9,14 +9,14 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=bcb4d6aea88f1445def6014708b69087f1a6dc74$
// $hash=2fca5c473412bd7acef54f5057dc55488271aaf9$
//
#include "libcef_dll/cpptoc/views/window_delegate_cpptoc.h"
#include "libcef_dll/ctocpp/views/view_ctocpp.h"
#include "libcef_dll/ctocpp/views/window_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
#include "libcef_dll/template_util.h"
namespace {
@ -600,6 +600,52 @@ window_delegate_get_window_runtime_style(struct _cef_window_delegate_t* self) {
return _retval;
}
int CEF_CALLBACK window_delegate_get_linux_window_properties(
struct _cef_window_delegate_t* self,
cef_window_t* window,
struct _cef_linux_window_properties_t* properties) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return 0;
}
// Verify param: window; type: refptr_diff
DCHECK(window);
if (!window) {
return 0;
}
// Verify param: properties; type: struct_byref
DCHECK(properties);
if (!properties) {
return 0;
}
if (!template_util::has_valid_size(properties)) {
DCHECK(false) << "invalid properties->[base.]size";
return 0;
}
// Translate param: properties; type: struct_byref
CefLinuxWindowProperties propertiesObj;
if (properties) {
propertiesObj.AttachTo(*properties);
}
// Execute
bool _retval = CefWindowDelegateCppToC::Get(self)->GetLinuxWindowProperties(
CefWindowCToCpp::Wrap(window), propertiesObj);
// Restore param: properties; type: struct_byref
if (properties) {
propertiesObj.DetachTo(*properties);
}
// Return type: bool
return _retval;
}
cef_size_t CEF_CALLBACK
window_delegate_get_preferred_size(struct _cef_view_delegate_t* self,
cef_view_t* view) {
@ -916,6 +962,8 @@ CefWindowDelegateCppToC::CefWindowDelegateCppToC() {
window_delegate_on_theme_colors_changed;
GetStruct()->get_window_runtime_style =
window_delegate_get_window_runtime_style;
GetStruct()->get_linux_window_properties =
window_delegate_get_linux_window_properties;
GetStruct()->base.base.get_preferred_size =
window_delegate_get_preferred_size;
GetStruct()->base.base.get_minimum_size = window_delegate_get_minimum_size;

View File

@ -9,11 +9,10 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=da609d625660ca617e1a01d5dc359932142e15a3$
// $hash=7bdd882f715040d06246576d0bafbbd7b9a39f8f$
//
#include "libcef_dll/ctocpp/views/window_delegate_ctocpp.h"
#include "libcef_dll/cpptoc/views/view_cpptoc.h"
#include "libcef_dll/cpptoc/views/window_cpptoc.h"
#include "libcef_dll/shutdown_checker.h"
@ -579,6 +578,33 @@ cef_runtime_style_t CefWindowDelegateCToCpp::GetWindowRuntimeStyle() {
return _retval;
}
NO_SANITIZE("cfi-icall")
bool CefWindowDelegateCToCpp::GetLinuxWindowProperties(
CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) {
shutdown_checker::AssertNotShutdown();
cef_window_delegate_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_linux_window_properties)) {
return false;
}
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: window; type: refptr_diff
DCHECK(window.get());
if (!window.get()) {
return false;
}
// Execute
int _retval = _struct->get_linux_window_properties(
_struct, CefWindowCppToC::Wrap(window), &properties);
// Return type: bool
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall")
CefSize CefWindowDelegateCToCpp::GetPreferredSize(CefRefPtr<CefView> view) {
shutdown_checker::AssertNotShutdown();

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=50ace2b6a45a23d4ff5d9a91ab7c37a893f7e0b4$
// $hash=ef831469d4dd59c3a20f0dfee3e8e945a52d7637$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_VIEWS_WINDOW_DELEGATE_CTOCPP_H_
@ -67,6 +67,8 @@ class CefWindowDelegateCToCpp
void OnThemeColorsChanged(CefRefPtr<CefWindow> window,
bool chrome_theme) override;
cef_runtime_style_t GetWindowRuntimeStyle() override;
bool GetLinuxWindowProperties(CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) override;
// CefPanelDelegate methods.

View File

@ -671,6 +671,19 @@ cef_runtime_style_t ViewsWindow::GetWindowRuntimeStyle() {
return CEF_RUNTIME_STYLE_DEFAULT;
}
#if defined(OS_LINUX)
bool ViewsWindow::GetLinuxWindowProperties(
CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) {
CefString(&properties.wayland_app_id) =
CefString(&properties.wm_class_class) =
CefString(&properties.wm_class_name) =
CefString(&properties.wm_role_name) = "cef";
return true;
}
#endif
void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) {
CEF_REQUIRE_UI_THREAD();
DCHECK(browser_view_);

View File

@ -162,6 +162,11 @@ class ViewsWindow : public CefBrowserViewDelegate,
const CefKeyEvent& event) override;
// CefWindowDelegate methods:
#if defined(OS_LINUX)
virtual bool GetLinuxWindowProperties(
CefRefPtr<CefWindow> window,
CefLinuxWindowProperties& properties) override;
#endif
void OnWindowCreated(CefRefPtr<CefWindow> window) override;
void OnWindowClosing(CefRefPtr<CefWindow> window) override;
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override;