Skip to content

Commit

Permalink
YGDialog::currentWindow() crashes sometime in the YGDialog constructor,
Browse files Browse the repository at this point in the history
left default display and root_window
  • Loading branch information
anaselli committed Sep 30, 2022
1 parent 97c81dd commit fab8049
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/YGDialog.cc
Expand Up @@ -364,17 +364,17 @@ void YGDialog::present()

YGDialog *YGDialog::currentDialog()
{
YDialog *ydialog = YDialog::currentDialog (false);
if (ydialog)
return static_cast <YGDialog *> (ydialog);
return NULL;
YDialog *ydialog = YDialog::currentDialog (false);
if (ydialog)
return dynamic_cast <YGDialog *> (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;
}
Expand Down
42 changes: 24 additions & 18 deletions src/YGUI.cc
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit fab8049

Please sign in to comment.