Skip to content

Commit

Permalink
Merge pull request #85 from anaselli/get_working_area
Browse files Browse the repository at this point in the history
Get working area
  • Loading branch information
anaselli authored Sep 30, 2022
2 parents 39b72a9 + fab8049 commit 6869c86
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 30 deletions.
2 changes: 1 addition & 1 deletion VERSION.cmake
Original file line number Diff line number Diff line change
@@ -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}" )

10 changes: 10 additions & 0 deletions package/libyui-gtk.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Sun Sep 25 19:07:11 CEST 2022 - [email protected]
- 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 - [email protected]
- Fixed CMAKE_INSTALL_LIBDIR for pkgconfig
Expand Down
2 changes: 1 addition & 1 deletion package/libyui-gtk.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: libyui-gtk
Version: 2.52.1
Version: 2.52.2
Release: 0
Source: %{name}-%{version}.tar.bz2

Expand Down
17 changes: 9 additions & 8 deletions src/YGDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,19 @@ 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)
return GTK_WINDOW (ydialog->m_window->getWidget());
return NULL;
YGDialog *ydialog = YGDialog::currentDialog();
if (ydialog)
if (ydialog->m_window && GTK_IS_WINDOW(ydialog->m_window->getWidget()))
return GTK_WINDOW (ydialog->m_window->getWidget());
return NULL;
}

void YGDialog::setCloseCallback (YGWindowCloseFn canClose, void *canCloseData)
Expand Down
91 changes: 71 additions & 20 deletions src/YGUI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -639,25 +639,68 @@ 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()
//
// 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 = gdk_display_get_monitor_at_window (
gdk_display_get_default(),
gdk_get_default_root_window ()
);

return pMonitor;
}

int YGApplication::displayWidth()
{
GdkRectangle monitor;
gdk_monitor_get_geometry (
gdk_display_get_primary_monitor(gdk_display_get_default()),
&monitor);
return monitor.width;
GdkMonitor * pMonitor = getGdkMonitor();

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 = getGdkMonitor();

if (pMonitor)
{
GdkRectangle geometry;
gdk_monitor_get_geometry (pMonitor, &geometry);

return geometry.height;
}

return 480;
}

int YGApplication::displayDepth()
Expand All @@ -676,33 +719,41 @@ long YGApplication::displayColors()
// Get default size as in Qt as much as possible
int YGApplication::defaultWidth()
{
GdkMonitor * pMonitor = getGdkMonitor();

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 )
{
// 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;
}

int YGApplication::defaultHeight()
{
GdkRectangle availableSize = {0};
gdk_monitor_get_workarea(
gdk_display_get_primary_monitor(gdk_display_get_default()),
&availableSize);
GdkMonitor * pMonitor = getGdkMonitor();

GdkRectangle availableSize = {0};

if (pMonitor)
{
gdk_monitor_get_workarea(pMonitor, &availableSize);
}

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 6869c86

Please sign in to comment.