CtrlLib: Ch X11 now reading font from dump_xsettings

This commit is contained in:
Mirek Fidler 2025-11-03 20:21:34 +01:00
parent 9404fd8338
commit b2258957fa
4 changed files with 73 additions and 8 deletions

View file

@ -872,10 +872,78 @@ void ChFlatDarkSkin()
#ifdef GUI_X11 #ifdef GUI_X11
void SetupFont()
{
String s = Sys("dump_xsettings");
StringStream ss(s);
String font_name;
int scaling = 1;
int xdpi = 98347;
while(!ss.IsEof()) {
String l = ss.GetLine();
int q = l.Find(' ');
if(q >= 0) {
String id = l.Mid(0, q);
String value = l.Mid(q + 1);
if(id == "Gdk/WindowScalingFactor")
scaling = max(Atoi(value), 1);
if(id == "Gtk/FontName")
font_name = value;
if(id == "Xft/DPI")
xdpi = Nvl(StrInt(value), 98347);
}
}
int fontface = Font::ARIAL;
int fontheight = 13;
bool bold = false;
bool italic = false;
const char *q = strrchr(font_name, ' ');
if(q) {
int h = atoi(q);
if(h)
fontheight = h;
String face(font_name, q);
fontface = Font::FindFaceNameIndex(face);
if(fontface == 0) {
for(;;) {
const char *q = strrchr(face, ' ');
if(!q) break;
const char *s = q + 1;
if(stricmp(s, "Bold") == 0 || stricmp(s, "Heavy") == 0)
bold = true;
else
if(stricmp(s, "Italic") == 0 || stricmp(s, "Oblique") == 0)
italic = true;
else
if(stricmp(s, "Regular") == 0 || stricmp(s, "Light") || stricmp(s, "Medium"))
;
else
continue;
face = String(~face, q);
}
fontface = Font::FindFaceNameIndex(face);
if(fontface == 0) {
if(ToUpper(face[0]) == 'M')
fontface = Font::COURIER;
else
if(ToUpper(face[0]) == 'S' && ToUpper(face[1]) == 'e')
fontface = Font::ROMAN;
else
fontface = Font::ARIAL;
}
}
}
Font gui_font = Font(fontface, fround(fontheight * xdpi / (72*1024.0))).Bold(bold).Italic(italic);
Font::SetDefaultFont(gui_font);
}
void ChHostSkin() void ChHostSkin()
{ {
int h = Ctrl::GetPrimaryScreenArea().Height(); SetupFont();
Font::SetDefaultFont(Arial(h > 1300 ? 26 : h > 800 ? 14 : 12));
SColorFace_Write(Color(242, 241, 240)); SColorFace_Write(Color(242, 241, 240));
SColorMenu_Write(Color(242, 241, 240)); SColorMenu_Write(Color(242, 241, 240));
SColorHighlight_Write(Color(50, 50, 250)); SColorHighlight_Write(Color(50, 50, 250));

View file

@ -34,8 +34,6 @@ void SetupFont()
String font_name = GtkSettingsString("gtk-font-name"); String font_name = GtkSettingsString("gtk-font-name");
// double xdpi = Nvl(GtkSettingsInt("gtk-xft-dpi"), 72 * 1024);
double xdpi = gdk_screen_get_resolution(gdk_display_get_default_screen(gdk_display_get_default())); double xdpi = gdk_screen_get_resolution(gdk_display_get_default_screen(gdk_display_get_default()));
const char *q = strrchr(font_name, ' '); const char *q = strrchr(font_name, ' ');

View file

@ -63,12 +63,10 @@ void DisplayPopup::RefreshRect()
Ctrl *top = ctrl->GetTopCtrl(); Ctrl *top = ctrl->GetTopCtrl();
top->RefreshFrame(screen_rect - top->GetScreenRect().TopLeft()); top->RefreshFrame(screen_rect - top->GetScreenRect().TopLeft());
Ctrl *owner = top->GetOwner(); Ctrl *owner = top->GetOwner();
if(owner) { if(owner)
Rect owa = owner->GetScreenRect();
owner->RefreshFrame(screen_rect - owner->GetScreenRect().TopLeft()); owner->RefreshFrame(screen_rect - owner->GetScreenRect().TopLeft());
} }
} }
}
void DisplayPopup::Sync() void DisplayPopup::Sync()
{ {

View file

@ -7,5 +7,6 @@ file
app.tpp; app.tpp;
mainconfig mainconfig
"" = "GUI"; "" = "GUI",
"" = "GUI X11";