-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Settings.set
expects self==PrintSettings
#100
Comments
Thanks for reporting, I will try to investigate that issue in the next few days. |
Seems to be not a bug in the bindings :-) g_object_set() is a low level C function for multiple untyped arguments. That function is not provided by gobject-introspection, so it is not available in most high level GTK bindings including Nim. Instead we use g_object_set_property() in Nim as setProperty(). Unfortunately that procedure needs a GValue as third parameter which makes it use a bit complicated. https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#g-object-set https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#g-object-set-property Unfortunately this is not yet explained in the GTK4 book, but we have examples in the gintro README, just do a text search for the term setProperty: https://github.com/StefanSalewski/gintro https://ssalewski.de/gtkprogramming.html A compiling code would look like
The toBoolVal() is copied from the gintro README. For the last line -- I am not sure if this notation with method call syntax works, I have never used that notation myself. I have no idea what this settings does and of course I can not run the code as it is not complete, but at least it compiles. It is interesting that you are using already GTK4. Not all Linux distros ship it already, and there are still some bugs in GTK4. But I hope that it will be soon official available. Let us know if above code will work for you or if you have more issues. |
thanks for clearing that up, your code seems to compile, but sadly doesn't work as expected.
it should tell gtk to prefer a dark version of the stylesheet (e.g. adwaita-dark instead of adwaita). it doesn't seem to do anything though, while setting the environment variable
yeah it's a hobby project where i don't need to be very compatible right from the start so i figured better futureproof it. minimal reproducing example: # see comments below ("HERE") as to where i tried to insert the following line:
#getDefaultSettings().setProperty("gtk-application-prefer-dark-theme", toBoolVal(true))
import gintro/[gtk4, gobject, gio]
proc toBoolVal(b: bool): Value =
let gtype = typeFromName("gboolean")
discard init(result, gtype)
setBoolean(result, b)
proc appActivate(app: Application) =
#HERE does nothing
let window = newApplicationWindow(app)
#HERE does nothing
window.title = "GTK4 & Nim"
window.defaultSize = (200, 200)
show(window)
proc main =
#HERE would crash
let app = newApplication("org.gtk.example")
#HERE would crash
connect(app, "activate", appActivate)
discard run(app)
main()
where "crash" means (with of course varying line numbers):
so apparently i can't the gtk docs show an example of: gtk_init (&argc, &argv);
g_object_set (gtk_settings_get_default (), "setting", value, NULL); which seems to be way earlier than my when logging the value of the setting i see it change, but it has no effect. which is rather weird since https://gitlab.gnome.org/GNOME/gtk/-/blob/master/gtk/gtksettings.c#L1251 should be even updating all the css stuff. according to https://stackoverflow.com/a/16003697/668125 i need to set it before "creating any widgets (which includes the main window)" but apparently doing it as the first thing in |
I have to admit that I don't know much about setting dark themes. A working C code example would be very helpful, an example in another language would be fine too. Do you think that we can really set dark themes for single apps in GTK? I though of it more about a general decision for whole desktop, but maybe it works? The stack overflow answer is from 2013, since then a lot has changed. And GTK4 may be again different, or maybe it is a GTK bug? Well I will see if I get something working, maybe I will have to ask Mr Bassi or some of the other core GTK devs. |
it's about setting themes at all, the 1670: *theme_variant = g_strdup ("dark");
1676: *theme_name = g_strdup (DEFAULT_THEME_NAME); resulting (on my platform) in verifying with: proc appActivate(app: Application) =
# dumpSetting just gets a property, transforms it to a string GValue and echoes it
getDefaultSettings().setProperty("gtk-application-prefer-dark-theme", toBoolVal(true))
dumpSetting("gtk-application-prefer-dark-theme") # prints TRUE
dumpSetting("gtk-theme-name") # prints Adwaita-dark
let window = newApplicationWindow(app)
# ... double checked it's the right value by commenting out the
According to the gtk3 docs and the gtk4 sources i'm rather positive that should still be possible. According to the docs it's even preferable to do it per-app, since e.g. a browser or text editor with a large bright document might not want the contrast of dark controls around it (as a user i personally disagree, but i see why as a dev it should be a per-app thing). remember, GTK doesn't actually have anything resembling a standardized theme api anyone is supposed to use, it just has platform stylesheets in (usually) a bright and a dark variant. "Adwaita" literally means "the only one" because that's what it's supposed to be: the only css it loads (on a normal desktop at least, phones get their own platform css afaik). |
Well this works:
I get a dark window with that example. |
And this GTK4 example works also for me:
|
And finally this GTK4 app style example works also:
Based on the GTK4 book code from https://github.com/StefanSalewski/GtkProgrammingBook/tree/master/nim If it should not work for you then maybe your GTK4 is broken. My one is very recent, compiled from gitlab sources some days ago. |
ok crazy enough your newest (gtk4 app style) example did work for me. |
And for me all is dark, the window header and the window content. But well there may exists GTK4 bugs still... |
yeah that's how all those methods we tried so far should have behaved, but for me it only worked on your very last code. |
apparently
getDefaultSettings()
returns a value of typeSettings
(as expected), but theset
method inside that expectsself
to be of typePrintSettings
:since your bindings keep changing perfectly fine names around, i'm not sure if i'm doing this right (apparently there's also a
gtk4.Settings
but that doesn't have either ofget_default
norgetDefault
, even though without changing the names around one'd expect it to be exactly that:gtk4.Settings.get_default()
, since the c name isgtk_settings_get_default
).but to me that looks like
PrintSettings
inherits fromSettings
and somehow manages to overwrite instead of overload theset
method.btw, the C equivalent of what i'm trying to do here is:
The text was updated successfully, but these errors were encountered: