gtkd-developers / GtkD

GtkD is a D binding and OO wrapper of GTK+ originally created by Antonio Monteiro
http://gtkd.org
Other
321 stars 71 forks source link

GtkD global font size #226

Open nicesai opened 6 years ago

nicesai commented 6 years ago

(Originally I posted this on forms.dlang.org:DWT)

I am writing a small GUI application using GtkD3 Builder and Glade. On a HD monitor the default font size is too small. The adwaita theme is not great but I can live with it. Is there any way to globally increase the font size in the GtkD?

I tried the settings.ini file with gtk-font-name = "Sans 15", but that did not help with my GtkD3 app. On the other hand, it did increase the global font size of the Glade tool, just not my application. Is some how GtkD different from pure Gtk application?

Thanks in advance. -Sai

nicesai commented 6 years ago

Maybe I should mention, my OS is Windows with latest dmd and installed GTK & GtkD as instructed on this wiki.

MikeWey commented 6 years ago

settings.ini is the correct place to change the font, i gat an Pango error when using gtk-font-name = "Sans 15" i had to drop the quotes to get things working: gtk-font-name=Sans 15.

Although that doesn't explain the effect it had on Glade.

Do you have multiple versions of the GTK runtime installed? (23bit, 64bit, gtk2, gtk3)

nicesai commented 6 years ago

You are right, I didn't add quotes, here is my settings.ini file:

[Settings] gtk-font-name = Sans 15

It does increase my Glade font size globally. Still no effect on my app :-( Not sure if GTK in Glade is statically compiled or if installs its own GTK.

nicesai commented 6 years ago

Here is the screenshot of glade and my app with this settings.ini:

[Settings] gtk-font-name = Sans 10

image

Here is the screenshot of glade an my app with this settings.ini: [Settings] gtk-font-name = Sans 15

image

I put my settings.ini file here: C:\Users\\AppData\Local\gtk-3.0\settings.ini

Note how Glade font size increased globally by my app font size is still the same microscopic font.

nicesai commented 6 years ago

I am using builderTest.d from demos to load the glade file:

module builder.builderTest;
import gio.Application: GioApplication = Application;
import gtk.Application;
import gtk.ApplicationWindow;
import gtk.Builder;
import gtk.Button;
import std.stdio;
import std.file;
import std.array;

/**
 * Usage ./gladeText /path/to/your/glade/file.glade
 *
 */

int main(string[] args) {
    string gladefile;
    if(args.length > 1) {
        writefln("Loading %s", args[1]);
        gladefile = args[1];
        args = args[0..1];
    } else {
        writeln("No glade file specified, using default \"builderTest.glade\"");
        gladefile = "builderTest.glade";
    }
    auto application = new Application("org.gtkd.demo.builder.builderTest", GApplicationFlags.FLAGS_NONE);

    void buildAndDisplay(GioApplication a) {
        auto builder = new Builder();
        string txt = readText(gladefile);
        txt = txt.replace("GtkWindow", "GtkApplicationWindow");

        if( ! builder.addFromString(txt) ) {
            writeln("Oops, could not create Glade object, check your glade file ;)");
            exit(1);
        }
        auto window = cast(ApplicationWindow)builder.getObject("window");

        if (window !is null) {
            window.setApplication(application);        
            window.setTitle("This is a glade application window");
            auto button = cast(Button)builder.getObject("button");
            if(button !is null) {
                button.addOnClicked( delegate void(Button aux){ a.quit(); } );
                window.showAll();
            } else {
                writeln("No button in the window?");
                exit(1);
            }
        } else {
            writeln("No window?");
            exit(1);
        }
    }

    application.addOnActivate(&buildAndDisplay);
    return application.run(args);
}
MikeWey commented 6 years ago

I don't have any issued when using the glade file from the demo.

Does changing the global setting have any effect? This file is located in: C:\Program Files[ (x86)]\Gtk-Runtime\etc\gtk-3.0\settings.ini

nicesai commented 6 years ago

I put my settings file here: C:\Users\\AppData\Local\gtk-3.0\settings.ini

I will try editing the global file and test it shortly. C:\Program Files[ (x86)]\Gtk-Runtime\etc\gtk-3.0\settings.ini

nicesai commented 6 years ago

Ha! Interesting ... I found that Glade installs its own GTK, so I changed PATH to point to "C:\Users\user\AppData\Local\GNOME Foundation\Glade Interface Designer\bin" and ran my app, and now it works!

set PATH=C:\Users\user\AppData\Local\GNOME Foundation\Glade Interface Designer\bin

image

Instead if I set path to set PATH=C:\Program Files (x86)\Gtk-Runtime\bin it does not work.

image

This seems to indicate that the problem is possibly with the gtk that is linked on GtkD website: https://gtkd.org/Downloads/runtime/gtk3-runtime_3.22.24-1_32bit.exe, which installed GTK at C:\Program Files (x86)\Gtk-Runtime\bin

nicesai commented 6 years ago

Also the default theme of GTK from Glade seems to be different than the one from GtkD website, could this have something to do with this issue?

dangbinghoo commented 6 years ago

GTK theme can be configured using settings.ini, YES, you should set settings.ini in GTK runtime etc, I just download a material design them from https://www.gnome-look.org/browse/cat/135/ , and the name is Materia and hosts on github now. The theme looks great for me, but the default icon is not good, but using icon from linux will simply not work.

nicesai commented 6 years ago

I am a noob in regards to GTK, could GtkD team recompile GTK for windows with a better theme? Please?

Or if there is anyway to bundle the theme with my app (and Gtk dlls) for clients? They may not have admin access to install stuff.

MikeWey commented 6 years ago

Could you post the output of the following program?

import std.stdio;
import glib.Util;

void main()
{
    writeln(Util.getUserConfigDir());
}

For shipping the Gtk runtime with your application, GtkD currently only searches the directories in the path. You might be able to use SetDllDirectory in a static constructor to get gtkD to search in you directory if it can't find GTK on the path.

nicesai commented 6 years ago

The output of that program is: C:\Users\nicesai\AppData\Local

Shipping Gtk with the app seem to be easy, as I can also ship the Gtk dlls along with the app and setting the path accordingly. My problem is how to ship the theme, I am not even sure how to install and test a new theme now, as the default theme on windows is not good (super small font).

MikeWey commented 6 years ago

The output of that program is: C:\Users\nicesai\AppData\Local

Then it's at least looking in the correct location, i don't know if i will be able to track it down further as i don't have the issue locally.

Shipping Gtk with the app seem to be easy, as I can also ship the Gtk dlls along with the app and setting the path accordingly. My problem is how to ship the theme, I am not even sure how to install and test a new theme now, as the default theme on windows is not good (super small font).

For setting the Theme/Icons/Font for a copy of the GTK runtime you ship your self, you should add the setting to etc/gtk-3.0/settings.ini like this:

[Settings]
gtk-icon-theme-name = Adwaita
gtk-theme-name = Adwaita
gtk-font-name = Sans 15

Themes are installed in share/themes/ and icons in share/icons/

nicesai commented 6 years ago

Thanks MikeWey for the info.