From 83c749535e226e1699d3e003b469ef435d30f610 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Sun, 25 Sep 2022 18:08:52 +0200 Subject: [PATCH 1/4] For GTK3 suggestion is to get the GdkWindow out of the GtkWindow widget with gtk_widget_get_window(), and then use gdk_display_get_monitor_at_window() This fixes dnfdragora bug https://github.com/manatools/dnfdragora/issues/207 --- src/YGUI.cc | 70 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/src/YGUI.cc b/src/YGUI.cc index 42a7ecb9..c6b64d31 100644 --- a/src/YGUI.cc +++ b/src/YGUI.cc @@ -639,25 +639,47 @@ float YGApplication::layoutUnits (YUIDimension dim, int units) static inline GdkScreen *getScreen () { return gdk_display_get_default_screen (gdk_display_get_default()); } + // GTK doesn't seem to have some desktopWidth/Height like Qt, so we to report // a reduced display size to compensate for the panel, or the window frame +// +// * For GTK3 get the GdkWindow out of the GtkWindow widget with gtk_widget_get_window(), +// and then use gdk_display_get_monitor_at_window() int YGApplication::displayWidth() { - GdkRectangle monitor; - gdk_monitor_get_geometry ( - gdk_display_get_primary_monitor(gdk_display_get_default()), - &monitor); - return monitor.width; + GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( + gdk_display_get_default(), + gdk_get_default_root_window () + ); + + if (pMonitor) + { + GdkRectangle geometry; + gdk_monitor_get_geometry (pMonitor, &geometry); + + return geometry.width; + } + + return 640; } int YGApplication::displayHeight() { - GdkRectangle monitor; - gdk_monitor_get_geometry ( - gdk_display_get_primary_monitor (gdk_display_get_default()), - &monitor); - return monitor.height; + GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( + gdk_display_get_default(), + gdk_get_default_root_window () + ); + + if (pMonitor) + { + GdkRectangle geometry; + gdk_monitor_get_geometry (pMonitor, &geometry); + + return geometry.height; + } + + return 480; } int YGApplication::displayDepth() @@ -676,10 +698,17 @@ long YGApplication::displayColors() // Get default size as in Qt as much as possible int YGApplication::defaultWidth() { + GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( + gdk_display_get_default(), + gdk_get_default_root_window () + ); + GdkRectangle availableSize = {0}; - gdk_monitor_get_workarea( - gdk_display_get_primary_monitor(gdk_display_get_default()), - &availableSize); + + if (pMonitor) + { + gdk_monitor_get_workarea(pMonitor, &availableSize); + } int width = availableSize.width; if ( displayWidth() >= 1024 ) @@ -693,10 +722,17 @@ int YGApplication::defaultWidth() int YGApplication::defaultHeight() { - GdkRectangle availableSize = {0}; - gdk_monitor_get_workarea( - gdk_display_get_primary_monitor(gdk_display_get_default()), - &availableSize); + GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( + gdk_display_get_default(), + gdk_get_default_root_window () + ); + + GdkRectangle availableSize = {0}; + + if (pMonitor) + { + gdk_monitor_get_workarea(pMonitor, &availableSize); + } int height = availableSize.height; if ( displayWidth() >= 1024 ) From c2f937395e21dfc7ddacfe4d7a0188857023367b Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Sun, 25 Sep 2022 19:03:46 +0200 Subject: [PATCH 2/4] grouped the GdkMonitor calls in one function to avoid writing the same code anytime. --- src/YGDialog.cc | 9 +++++---- src/YGUI.cc | 41 +++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/YGDialog.cc b/src/YGDialog.cc index b9a06486..d69077b7 100644 --- a/src/YGDialog.cc +++ b/src/YGDialog.cc @@ -372,10 +372,11 @@ YGDialog *YGDialog::currentDialog() GtkWindow *YGDialog::currentWindow() { - YGDialog *ydialog = YGDialog::currentDialog(); - if (ydialog) - return GTK_WINDOW (ydialog->m_window->getWidget()); - return NULL; + YGDialog *ydialog = YGDialog::currentDialog(); + if (ydialog) + if (ydialog->m_window) + return GTK_WINDOW (ydialog->m_window->getWidget()); + return NULL; } void YGDialog::setCloseCallback (YGWindowCloseFn canClose, void *canCloseData) diff --git a/src/YGUI.cc b/src/YGUI.cc index c6b64d31..ed1ad6fe 100644 --- a/src/YGUI.cc +++ b/src/YGUI.cc @@ -645,12 +645,30 @@ static inline GdkScreen *getScreen () // // * For GTK3 get the GdkWindow out of the GtkWindow widget with gtk_widget_get_window(), // and then use gdk_display_get_monitor_at_window() +static inline GdkMonitor * getGdkMonitor() +{ + GdkMonitor * pMonitor = NULL; + GtkWidget *widget = GTK_WIDGET (YGDialog::currentWindow()); + if (widget) { + pMonitor = gdk_display_get_monitor_at_window ( + gdk_display_get_default(), + gtk_widget_get_window(widget) + ); + } + else { + // let's try default one + pMonitor = gdk_display_get_monitor_at_window ( + gdk_display_get_default(), + gdk_get_default_root_window () + ); + } + + return pMonitor; +} + int YGApplication::displayWidth() { - GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( - gdk_display_get_default(), - gdk_get_default_root_window () - ); + GdkMonitor * pMonitor = getGdkMonitor(); if (pMonitor) { @@ -666,10 +684,7 @@ int YGApplication::displayWidth() int YGApplication::displayHeight() { - GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( - gdk_display_get_default(), - gdk_get_default_root_window () - ); + GdkMonitor * pMonitor = getGdkMonitor(); if (pMonitor) { @@ -698,10 +713,7 @@ long YGApplication::displayColors() // Get default size as in Qt as much as possible int YGApplication::defaultWidth() { - GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( - gdk_display_get_default(), - gdk_get_default_root_window () - ); + GdkMonitor * pMonitor = getGdkMonitor(); GdkRectangle availableSize = {0}; @@ -722,10 +734,7 @@ int YGApplication::defaultWidth() int YGApplication::defaultHeight() { - GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( - gdk_display_get_default(), - gdk_get_default_root_window () - ); + GdkMonitor * pMonitor = getGdkMonitor(); GdkRectangle availableSize = {0}; From 97c81ddfc2209efff9e5d0c52b2bea4165738d3e Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Sun, 25 Sep 2022 19:11:53 +0200 Subject: [PATCH 3/4] Updated version to 2.52.2 --- VERSION.cmake | 2 +- package/libyui-gtk.changes | 10 ++++++++++ package/libyui-gtk.spec | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/VERSION.cmake b/VERSION.cmake index 1804a58b..456823c1 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -1,5 +1,5 @@ SET( VERSION_MAJOR "2" ) SET( VERSION_MINOR "52" ) -SET( VERSION_PATCH "1" ) +SET( VERSION_PATCH "2" ) SET( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${VERSION_SHA1}" ) diff --git a/package/libyui-gtk.changes b/package/libyui-gtk.changes index b1d8b237..7fa3deaa 100644 --- a/package/libyui-gtk.changes +++ b/package/libyui-gtk.changes @@ -1,3 +1,13 @@ +------------------------------------------------------------------- +Sun Sep 25 19:07:11 CEST 2022 - anaselli@linux.it +- Changed displayWidth/displayHeight implementation For GTK3 + suggestion is to get the GdkWindow out of the GtkWindow widget + with gtk_widget_get_window(), and then use + gdk_display_get_monitor_at_window() + This fixes dnfdragora bug https://github.com/manatools/dnfdragora/issues/207 + when it runs on Gnome desktop. +- 2.51.2 + ------------------------------------------------------------------- Sun Jul 11 15:27:20 CET 2021 - anaselli@linux.it - Fixed CMAKE_INSTALL_LIBDIR for pkgconfig diff --git a/package/libyui-gtk.spec b/package/libyui-gtk.spec index d39f8466..158f18d0 100644 --- a/package/libyui-gtk.spec +++ b/package/libyui-gtk.spec @@ -17,7 +17,7 @@ Name: libyui-gtk -Version: 2.52.1 +Version: 2.52.2 Release: 0 Source: %{name}-%{version}.tar.bz2 From fab804947688d5fd8a997aed7066d04c752c7081 Mon Sep 17 00:00:00 2001 From: Angelo Naselli Date: Fri, 30 Sep 2022 18:15:20 +0200 Subject: [PATCH 4/4] YGDialog::currentWindow() crashes sometime in the YGDialog constructor, left default display and root_window --- src/YGDialog.cc | 10 +++++----- src/YGUI.cc | 42 ++++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/YGDialog.cc b/src/YGDialog.cc index d69077b7..b11a4498 100644 --- a/src/YGDialog.cc +++ b/src/YGDialog.cc @@ -364,17 +364,17 @@ void YGDialog::present() YGDialog *YGDialog::currentDialog() { - YDialog *ydialog = YDialog::currentDialog (false); - if (ydialog) - return static_cast (ydialog); - return NULL; + YDialog *ydialog = YDialog::currentDialog (false); + if (ydialog) + return dynamic_cast (ydialog); + return NULL; } GtkWindow *YGDialog::currentWindow() { YGDialog *ydialog = YGDialog::currentDialog(); if (ydialog) - if (ydialog->m_window) + if (ydialog->m_window && GTK_IS_WINDOW(ydialog->m_window->getWidget())) return GTK_WINDOW (ydialog->m_window->getWidget()); return NULL; } diff --git a/src/YGUI.cc b/src/YGUI.cc index ed1ad6fe..2c107116 100644 --- a/src/YGUI.cc +++ b/src/YGUI.cc @@ -645,23 +645,29 @@ static inline GdkScreen *getScreen () // // * For GTK3 get the GdkWindow out of the GtkWindow widget with gtk_widget_get_window(), // and then use gdk_display_get_monitor_at_window() +// +// The idea was to use YGDialog::currentWindow() but it next function is used in the YGDialog +// constructor and the pointer is not reliable and sometimes crashes (To be investigated more) +// Example of code is the next: +// GdkMonitor * pMonitor = NULL; +// GtkWindow* pWindow = YGDialog::currentWindow(); +// GtkWidget *widget = NULL; +// if (pWindow) +// { +// widget = GTK_WIDGET (pWindow); +// } +// if (widget) { +// pMonitor = gdk_display_get_monitor_at_window ( +// gdk_display_get_default(), +// gtk_widget_get_window(widget) +// ); +// } static inline GdkMonitor * getGdkMonitor() { - GdkMonitor * pMonitor = NULL; - GtkWidget *widget = GTK_WIDGET (YGDialog::currentWindow()); - if (widget) { - pMonitor = gdk_display_get_monitor_at_window ( - gdk_display_get_default(), - gtk_widget_get_window(widget) - ); - } - else { - // let's try default one - pMonitor = gdk_display_get_monitor_at_window ( - gdk_display_get_default(), - gdk_get_default_root_window () - ); - } + GdkMonitor * pMonitor = gdk_display_get_monitor_at_window ( + gdk_display_get_default(), + gdk_get_default_root_window () + ); return pMonitor; } @@ -726,7 +732,7 @@ int YGApplication::defaultWidth() if ( displayWidth() >= 1024 ) { // Scale down to 70% of screen size - width = std::max( (int) (availableSize.width * 0.7), 800 ) ; + width = std::max( (int) (availableSize.width * 0.7), 1024 ) ; } return width; @@ -744,10 +750,10 @@ int YGApplication::defaultHeight() } int height = availableSize.height; - if ( displayWidth() >= 1024 ) + if ( displayHeight() >= 768 ) { // Scale down to 70% of screen size - height = std::max( (int) (availableSize.height * 0.7), 600 ) ; + height = std::max( (int) (availableSize.height * 0.7), 768 ) ; } return height;