Skip to content

Commit

Permalink
Merge pull request #77 from anaselli/MainWindows-Size
Browse files Browse the repository at this point in the history
Fixing main windows size
  • Loading branch information
anaselli authored Feb 2, 2021
2 parents 6e1f2a6 + e278a4d commit 7ea8762
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 52 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 "50" )
SET( VERSION_MINOR "51" )
SET( VERSION_PATCH "0" )
SET( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${VERSION_SHA1}" )

Expand Down
2 changes: 1 addition & 1 deletion package/libyui-gtk-doc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
%define so_version 14

Name: %{parent}-doc
Version: 2.50.0
Version: 2.51.0
Release: 0
Source: %{parent}-%{version}.tar.bz2

Expand Down
6 changes: 6 additions & 0 deletions package/libyui-gtk.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Sun Jan 31 18:24:20 CET 2021 - [email protected]

- Evaluate default size by using working area as in Qt. Issue #76
- 2.51.0

-------------------------------------------------------------------
Mon Nov 09 12:01:24 CEST 2020 - [email protected]

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.50.0
Version: 2.51.0
Release: 0
Source: %{name}-%{version}.tar.bz2

Expand Down
33 changes: 8 additions & 25 deletions src/YGDialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,14 @@ class YGWindow
gtk_window_set_decorated (window, FALSE);
}

if (_main_window) {
// window default width is calculated as a proportion of a default
// char and pixel width to compensate for the fact that each widget's
// required size comes from a proportion of both parameters
int width = YGUtils::getCharsWidth (m_widget, DEFAULT_CHAR_WIDTH);
width += DEFAULT_PIXEL_WIDTH;
int height = YGUtils::getCharsHeight (m_widget, DEFAULT_CHAR_HEIGHT);
height += DEFAULT_PIXEL_HEIGHT;

if (YGUI::ui()->isSwsingle())
height += YGUtils::getCharsHeight (m_widget, 10);

width = MIN (width, YUI::app()->displayWidth());
height = MIN (height, YUI::app()->displayHeight());

gtk_window_set_default_size (window, width, height);
gtk_window_resize(window, width, height);

if (YGUI::ui()->setFullscreen())
gtk_window_fullscreen (window);
else if (YUI::app()->displayWidth() <= 800 || YUI::app()->displayHeight() <= 600)
// maximize window for small displays
gtk_window_maximize (window);
}

if (_main_window) {
int width = YUI::app()->defaultWidth();
int height = YUI::app()->defaultHeight();
gtk_window_set_default_size ( window, width, height );
gtk_window_resize( window, width, height );
if (YGUI::ui()->setFullscreen())
gtk_window_fullscreen (window);
}
gtk_window_set_role (window, "yast2");
}

Expand Down
69 changes: 45 additions & 24 deletions src/YGUI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -623,30 +623,21 @@ static inline GdkScreen *getScreen ()
// a reduced display size to compensate for the panel, or the window frame
int YGApplication::displayWidth()
{
# if GTK_CHECK_VERSION (3, 22, 0)
GdkRectangle monitor;
gdk_monitor_get_geometry (
gdk_display_get_primary_monitor (
gdk_display_get_default()),
&monitor);
return monitor.x - 80;
# else
return gdk_screen_get_width (getScreen()) - 80;
# endif
GdkRectangle monitor;
gdk_monitor_get_geometry (
gdk_display_get_primary_monitor(gdk_display_get_default()),
&monitor);
return monitor.width;

}

int YGApplication::displayHeight()
{
# if GTK_CHECK_VERSION (3, 22, 0)
GdkRectangle monitor;
gdk_monitor_get_geometry (
gdk_display_get_primary_monitor (
gdk_display_get_default()),
&monitor);
return monitor.y - 80;
# else
return gdk_screen_get_height (getScreen()) - 80;
# endif
GdkRectangle monitor;
gdk_monitor_get_geometry (
gdk_display_get_primary_monitor (gdk_display_get_default()),
&monitor);
return monitor.height;
}

int YGApplication::displayDepth()
Expand All @@ -662,10 +653,40 @@ int YGApplication::displayDepth()
long YGApplication::displayColors()
{ return 1L << displayDepth(); /*from yast-qt*/ }

// YCP uses defaultWidth/Height() to use their smaller YWizard impl; we
// want to use a smaller default size than qt though, so assume a bigger size
int YGApplication::defaultWidth() { return MIN (displayWidth(), 1024); }
int YGApplication::defaultHeight() { return MIN (displayHeight(), 768); }
// Get default size as in Qt as much as possible
int YGApplication::defaultWidth()
{
GdkRectangle availableSize = {0};
gdk_monitor_get_workarea(
gdk_display_get_primary_monitor(gdk_display_get_default()),
&availableSize);

int width = availableSize.width;
if ( displayWidth() >= 1024 )
{
// Scale down to 70% of screen size
width = std::max( (int) (availableSize.width * 0.7), 800 ) ;
}

return width;
}

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

int height = availableSize.height;
if ( displayWidth() >= 1024 )
{
// Scale down to 70% of screen size
height = std::max( (int) (availableSize.height * 0.7), 600 ) ;
}

return height;
}

YWidgetFactory *YGUI::createWidgetFactory()
{ return new YGWidgetFactory; }
Expand Down

0 comments on commit 7ea8762

Please sign in to comment.