summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-08-10 13:11:05 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2022-08-11 11:50:40 +0200
commit9480ac658ec8ddb445f629b4db66fce07649feab (patch)
treea1e717e85d410f6c91df67793b9e327d7c4c23d0
parent75f2b5a5ed1c0df2487c7be3312e89daf295491e (diff)
gtk3: silence 'invalid cast from 'GtkWindow' to 'GtkMenuShell' warning
from the sidebar tab due to the accelerators in there its a bogus check in gtk3 in this case of a menu attached to a MenuButton Change-Id: Ie5216e749993f3d44bfc2e4560cd3b2f49aa8aec Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138114 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> Tested-by: Jenkins
-rw-r--r--vcl/unx/gtk3/gtkinst.cxx28
1 files changed, 28 insertions, 0 deletions
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 9529668c5639..ca997a5193c3 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -22441,16 +22441,44 @@ bool IsAllowedBuiltInIcon(std::u16string_view iconName)
namespace {
+#if !GTK_CHECK_VERSION(4, 0, 0)
+void silence_gwarning(const gchar* /*log_domain*/,
+ GLogLevelFlags /*log_level*/,
+ const gchar* /*message*/,
+ gpointer /*user_data*/)
+{
+}
+#endif
+
void load_ui_file(GtkBuilder* pBuilder, const OUString& rUri)
{
#if GTK_CHECK_VERSION(4, 0, 0)
builder_add_from_gtk3_file(pBuilder, rUri);
#else
+ guint nLogHandlerId = 0;
+ GLogLevelFlags nFatalMask(static_cast<GLogLevelFlags>(G_LOG_FLAG_RECURSION|G_LOG_LEVEL_ERROR));
+ if (rUri.endsWith("sfx/ui/tabbarcontents.ui"))
+ {
+ // gtk unhelpfully has a bogus warning for the accelerator in this .ui because it assumes menus with accelerators
+ // if attached to something are attached to a MenuShell, but it's a MenuButton in this case. Turn off warnings, and
+ // in the case of fatal-warnings temp disable fatal warnings, for this case.
+ nLogHandlerId = g_log_set_handler("GLib-GObject",
+ static_cast<GLogLevelFlags>(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
+ silence_gwarning, nullptr);
+ nFatalMask = g_log_set_always_fatal(nFatalMask);
+ }
+
OUString aPath;
osl::FileBase::getSystemPathFromFileURL(rUri, aPath);
GError *err = nullptr;
auto rc = gtk_builder_add_from_file(pBuilder, OUStringToOString(aPath, RTL_TEXTENCODING_UTF8).getStr(), &err);
+ if (nLogHandlerId)
+ {
+ g_log_remove_handler("GLib-GObject", nLogHandlerId);
+ g_log_set_always_fatal(nFatalMask);
+ }
+
if (!rc)
{
SAL_WARN( "vcl.gtk", "GtkInstanceBuilder: error when calling gtk_builder_add_from_file: " << err->message);