View Issue Details

IDProjectCategoryView StatusLast Update
0031199LazarusIDEpublic2018-01-09 16:27
ReporterChris Rorden Assigned ToMichl  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
PlatformLenovo Yoga 2 ProOSUbuntu 
Product Version1.7 (SVN) 
Summary0031199: High-DPI Ubuntu screens not detected
DescriptionIt appears that with Ubuntu the scaling of text is not controlled by the DPI setting. For example, on my laptop Lazarus always reports the DPI as 96, regardless of the values set in the "Displays" control panel. This panel has a slider called "Scale for menu and title bars", which on my computer can be set from x0.5..x3.38. You can work out the intended scaling by reading
 gsettings get org.gnome.desktop.interface scaling-factor
 gsettings get org.gnome.desktop.interface text-scaling-factor
  The scaling factor is an integer: e.g. 1, 2, 3 ...
  The text-scaling-factor is a float in the range 1..1.99999
The desired scaling is the product of these values, so if the user sets the slider to "1.5" the scaling is "1" the text scaling is "1.5", while if the user selects "2.5" they are "2" and "1.25" respectively.


I am including a hack that reads this virtualDPI and scales the Lazarus program using the call
  Self.AutoAdjustLayout(lapDefault, 96, virtualDPI, Self.Width,round(Self.Width * virtualDPI/96), False );
  
I think it would be ideal if this feature could be included into Lazarus to allow automatic Form Scaling on Ubuntu.

Steps To ReproduceWith Ubuntu, adjust "Scale for Menu and title bars" slider. Launch Lazarus application and note they always report a fixed screen DPI, while other Ubuntu Apps change their scaling.
TagsNo tags attached.
Fixed in Revision55635
LazTarget-
WidgetsetGTK 2
Attached Files

Relationships

related to 0031785 closedMichl GTK2 size calculations of dialogs initially wrong using theme oxygen-gtk 
related to 0032268 closedMichl Font issues at high-DPI on Gtk2 

Activities

Chris Rorden

2017-01-06 22:06

reporter  

autosize.zip (129,909 bytes)

Anton Kavalenka

2017-01-06 22:29

reporter   ~0097343

actually the x-server reports the same 96 DPI.
I think under gtk2/3 should be some kind of virtual DPI calculated from that font-scaling factor.

Anton Kavalenka

2017-01-09 21:18

reporter   ~0097384

Last edited: 2017-01-09 21:23

View 2 revisions

https://developer.gnome.org/gdk3/stable/GdkScreen.html#gdk-screen-get-monitor-scale-factor

Zeljan Rikalo

2017-06-07 17:34

developer   ~0100934

That one is deprecated, this one should be used:
https://developer.gnome.org/gdk3/stable/GdkMonitor.html#gdk-monitor-get-scale-factor

Zeljan Rikalo

2017-06-07 17:35

developer   ~0100935

Anyone tested QtLCL on Ubuntu 16.10 + scaling ? Also, what env says ? Scaling could be exported as environment variable so all apps know about it.

Anton Kavalenka

2017-07-08 15:04

reporter   ~0101614

Last edited: 2017-07-29 19:10

View 2 revisions

Easiest way to override default dpi - place something like the following code AFTER widgetset initialization but BEFORE any form creation:

  {$ifndef MSWINDOWS}
  if cmdln.params.NameExists('dpi') then
  begin
      ScreenInfo.PixelsPerInchX:=StrToIntDef(cmdln.params.Value('dpi'),96);
      ScreenInfo.PixelsPerInchY:=ScreenInfo.PixelsPerInchX;
        Screen.UpdateScreen; // this refreshes screen object from the structure
  end;
  {$endif}

This allows testing HIDPI scaling on Linux

Michl

2017-07-29 22:54

developer   ~0101987

Just tested on Linux Mint 18.1 Cinnamon. Here also https://developer.gnome.org/gdk2/stable/GdkScreen.html#gdk-screen-get-resolution (GTK2 2.10 and up) is possible. See fast created patch.

Is it working for you too?

Michl

2017-07-29 22:56

developer  

gtk2widgetset.inc.patch (1,210 bytes)   
Index: lcl/interfaces/gtk2/gtk2widgetset.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2widgetset.inc	(revision 55601)
+++ lcl/interfaces/gtk2/gtk2widgetset.inc	(working copy)
@@ -1004,6 +1004,8 @@
   Result:= lpGtk2;
 end;
 
+function gdk_screen_get_resolution(screen:PGdkScreen):gdouble; cdecl; external gdklib;
+
 {------------------------------------------------------------------------------
   Method: TGtk2WidgetSet.AppInit
   Params:  None
@@ -1025,9 +1027,16 @@
   InitKeyboardTables;
   { Compute pixels per inch variable }
   ScreenInfo.PixelsPerInchX :=
-    RoundToInt(gdk_screen_width / (GetScreenWidthMM / 25.4));
+    RoundToInt(gdk_screen_get_resolution(gdk_screen_get_default));
   ScreenInfo.PixelsPerInchY :=
-    RoundToInt(gdk_screen_height / (GetScreenHeightMM / 25.4));
+    ScreenInfo.PixelsPerInchX;
+  if ScreenInfo.PixelsPerInchX <= 0 then
+  begin
+    ScreenInfo.PixelsPerInchX :=
+      RoundToInt(gdk_screen_width / (GetScreenWidthMM / 25.4));
+    ScreenInfo.PixelsPerInchY :=
+      RoundToInt(gdk_screen_height / (GetScreenHeightMM / 25.4));
+  end;
   ScreenInfo.ColorDepth := gdk_visual_get_system^.depth;
 end;
 
gtk2widgetset.inc.patch (1,210 bytes)   

Ondrej Pokorny

2017-08-05 15:58

developer   ~0102072

Last edited: 2017-08-05 16:05

View 2 revisions

I applied the patch so it makes it into 1.8. Thanks, Michl!

Chris Rorden

2018-01-09 16:27

reporter   ~0105530

Fixed. Thanks

Issue History

Date Modified Username Field Change
2017-01-06 22:06 Chris Rorden New Issue
2017-01-06 22:06 Chris Rorden File Added: autosize.zip
2017-01-06 22:29 Anton Kavalenka Note Added: 0097343
2017-01-09 21:18 Anton Kavalenka Note Added: 0097384
2017-01-09 21:23 Anton Kavalenka Note Edited: 0097384 View Revisions
2017-06-07 17:12 Juha Manninen Relationship added related to 0031785
2017-06-07 17:34 Zeljan Rikalo Note Added: 0100934
2017-06-07 17:35 Zeljan Rikalo Note Added: 0100935
2017-07-08 15:04 Anton Kavalenka Note Added: 0101614
2017-07-29 19:10 Anton Kavalenka Note Edited: 0101614 View Revisions
2017-07-29 22:54 Michl Note Added: 0101987
2017-07-29 22:55 Michl File Added: gtk2widgetset.inc.patch
2017-07-29 22:56 Michl File Deleted: gtk2widgetset.inc.patch
2017-07-29 22:56 Michl File Added: gtk2widgetset.inc.patch
2017-08-05 15:58 Ondrej Pokorny Fixed in Revision => 55635
2017-08-05 15:58 Ondrej Pokorny LazTarget => -
2017-08-05 15:58 Ondrej Pokorny Note Added: 0102072
2017-08-05 15:58 Ondrej Pokorny Status new => resolved
2017-08-05 15:58 Ondrej Pokorny Resolution open => fixed
2017-08-05 15:58 Ondrej Pokorny Assigned To => Michl
2017-08-05 16:05 Ondrej Pokorny Note Edited: 0102072 View Revisions
2017-08-13 23:46 Ondrej Pokorny Relationship added related to 0032268
2018-01-09 16:27 Chris Rorden Note Added: 0105530
2018-01-09 16:27 Chris Rorden Status resolved => closed