appearance in wayland: Support changing theme, icon theme, and font #749
Suggest replacing ``system` with `g_spawn_command_line_async``
I just tested that change, and unfortunately I could not get it to work. The reason is that with system() we get the return value of the program being run, and that's what we are using to distinguish the wayland session from an x11 session while running under Xwayland.
With g_spawn_command_line_async() we don't. Since finding nothing on running killall -0 -e <anything> does not seem to be considered an error, using GError doesn't seem to give a way of distinguishing this either. While this function is a gboolean returning TRUE or FALSE, it seems to return TRUE unconditionally when running g_spawn_command_line_async("killall -0 -e Xwayland", NULL);
I tested that by comparing behavior in both wayland and x11 sessions
A different issue cropped up trying to use g_spawn_command_line_async() to start mate-appearance-properties from caja in https://github.com/mate-desktop/caja/pull/1771
if using mate-control-center 1.28.0 or current git master, we cannot open mate-appearance-properties without passing GDK_BACKEND=x11 as an environmental variable. We can get by without it entirely in caja if this PR is applied to mate-control-center, but that would cause caja to have different behavior in wayland depending on which version of m-c-c is installed, shortly after a major release. Not a hard dependency due to the fallback, but something that might generate bug reports.
g_spawn_command_line_async() does not seem to be able to pass environmental variables, and neither do the similar commands such as those that underlie caja_launch_application_from_command. That one can be made to work by setting it to open a command in terminal, but then we have that showing on the desktop plus all the code to run a totally unneeded terminal. Three things worked there: g_spawn_command_line_async() or caja_launch_application_from_command() with this PR applied to m-c-c and not trying to pass any environmental variables, or caja_launch_application_from_command() setting terminal usabe to TRUE, which allowed GDK_BACKEND=x11 to be passed and the background page of this capplet to open.
I agree that it would be good to avoid system() as it is heavy, but this seems to be hard to avoid here. In this case, an alternative mode of detecting that we are in a wayland session from an app running in Xwayland might be able get us around using system() which is rather heavy for this job. In the caja case by comparison, the fork etc should be less of a concern as mate-appearance-properties being launched from there is a whole new toplevel program anyway. There too though we have to run two checks, there too I tested g_spawn_command_line_async() and the checks didn't work.
Thoughts?
Latest force-push adds control of cursor theme, note however that cursor theme setting in wayland has been reported to be buggy no matter how it's done.
Since https://github.com/mate-desktop/mate-control-center/pull/749/commits/3835297e5add6c2d3327d5813b861939e41d1713 the appearance capplet can now run under native wayland. That means we no longer need that system call to detect the session so
https://github.com/mate-desktop/mate-control-center/pull/749/commits/4832386262c8fbadf6cce5bacb0b571b15b99338
removes it, and this should make lighter code
https://github.com/mate-desktop/caja/pull/1771 updated to take advantage of this without depending on it.
Still a draft as I am hoping to get theme customization to apply in wayland. we have fonts, theme, and icon theme now but customization of a theme is only applying on closing and reopening m-c-c.
We also need to suppress the "settings manager is not running" error dialog in wayland, since the settings manager is used only to control Xwayland. Alternately the dialog could be modified under wayland to indicate specifically that settings won't be applied in Xwayland, and suppress it when the appearance capplet is opened to the background page
Since a caja PR takes advantage of this, customized theme support can be included with this if I can find what is needed to apply customization in this timeframe, or it can wait for a followup.
This gives a lot of new functionality in a wayland session as matters stand now,partially resolving one of the biggest user hassles: how to set the theme and font.
Rebased against current master after the 1.29 version bump
Why is it ``0`` here? If multiple monitors are connected, will there be a problem here? I'm not sure
Extra spaces
We are setting the font here, and right now I have yet to figure out how to do this on a per-monitor basis. First priority on that would be showing the caja desktop on all monitors. Monitor 0 (leftmost or only monitor on single monitor setup) is always present, and in the wayland session it's where caja's desktop goes unless manually started from a terminal on another monitor.
If you know a better way I am definately interested in it
This file was converted some time ago to GNOME style 2 space indents. That is the indent under the if statement, same under the else statement. If this makes the file hard to read, I can use brackets instead if you or anyone else prefers.
Would it be better to use ``gdk_display_get_primary_monitor`` ?
Not sure it would alwaya work
https://docs.gtk.org/gdk3/method.Display.get_primary_monitor.html
Says this can return NULL when no primary monitor is configured, and in Wayland the concept of a primary monitor seems to have not been implemented.
Would it be better to use ``gdk_display_get_monitor_at_window`` instead
That might work, will try it when I get home
We don't have the window the capplet is using within get_dpi_from_x_server_or_monitor, and we don't have it in the calling function either. Thus we'd have to pass the window through a lot of other functions to get it here it seems.
In an ideal multimonitor case, an argument could be made for using the monitor the capplet is on, or for using the monitor the desktop is on. Setting a different font for each monitor would require a lot of other changes, notable additional gsettings values to store additional values in, we'd have to show each possible monitor in the capplet at well
I personally think there's no problem. Let others take a look too
Not validated in the Wayland environment, there are no issues with the code logic
Hoping we can get a review by another who has the wayland session set up
Is anyone else able to test this in a wayland session, should I merge it, or something else?
That's a bit… meh. Can't we just check whether the app's display is a Wayland one? The only probable issue is if the app is run under Xwayland, but maybe it's only fair that it might not control the Wayland session in that case?
how does this interact if one of the settings change (either the GNOME or MATE one) from outside? does it sync both, or does this goes crazy? I would think it would just sync both but better safe than sorry
does this add a strong dependency on GNOME desktop schemas?
The comment seems out of sync.
But I like the check better than the system call :)
BTW if it works, maybe we could just bind the two regardless of Wayland? Does it cause any issue on X11? It's just that MCC would partially control the GNOME settings as well, but given some apps use those maybe it's only fair?
(BTW IMO we should at some point have MSD work under Wayland, but I get that it's very far from trivial, so maybe it's not realistic, at least not for now…)
Not a new one, pretty sure gtk3 itself depends on that, correct me if I am wrong.
Thanks for catching this, looks like two code blocks I wrote at two different times used two different methods
All the code does here is write to gsettings. I just checked, having this and dconf-editor open at the same time. If you change it in either one it is applied and immediately reflected in the other.
Binding the GNOME settings when under x11 would probably get complaints from users and even distros, as no doubt some want to have both sessions installed and with different settings. This is no problem under x11 but is impossible under wayland at this time unless we maintain our own compositor (probably a fork of wayfire but with really very few changes). Probably we should submit a PR for wayfire to allow use of MATE or other gsettings for these values.
Another approach might be to add a slider in the control center for something like "Set GNOME values too (needed for wayland session)" and let users decide what to do.
That is fixed, I missed it in the previous commit that removed the same system call elsewhere. Thanks again for finding it.
Last force-push just updates a comment to reflect that in native wayland we no longer have to resort to the system call
Also note that we DO in fact need to run mate-settings-daemon in the x11 session or we don't apply nondefault theme/font/icon theme values in Xwayland apps. It controls only settings of apps running under x11 or xwayland, but without it we can no longer sync the theme etc between a wayland session and apps running under xwayland. Therefore, we run m-s-d under the current wayland session for that purpose
The original reason for this was that at first I had this whole capplet running under xwayland. Once I got past that and got it running under native wayland, there was no more need for this roundabout approach. One of today's updates removed the leftover instance of this,
Probably we should submit a PR for wayfire to allow use of MATE or other gsettings for these values.
Yeah I don't know how wayfire works yet, but possibly a plugin similar to Compiz's MATE integration? Anyway yes if it's at this level that it has to be modified it'd make sense to do so there. But I guess that can be delayed if you prefer.
Apparently it does use it for the Wayland backend indeed. Though, if I read the code properly it's a soft-dependency, and a fallback one at that, and it uses the DBus org.freedesktop.portal.Settings interface on the org.freedesktop.portal.Desktop session bus (plus something for the fontconfig settings). So either that's what Wayfire provides, or we'd just have to provide that instead of an XSettings backend in MSD.
So what I mean is that this does make MCC depend on the GNOME desktop schemas. Whether another component needed for the Wayland session already does or not is yet to be determined.
you could remove the comment or guard with a ! GDK_IS_X11_DISDPLAY() call
BTW if you wanted this schema to be optional (in case it makes any sense to have it optional), you could do something like this:
GSettingsSchemaSource *source = g_settings_schema_source_get_default ();
if (source)
{
GSettingsSchema *schema = g_settings_schema_source_lookup (source, INTERFACE_GNOME_SCHEMA, TRUE);
if (schema)
data->interface_gnome_settings = g_settings_new_full (schema, NULL, NULL);
}
Again, not saying you should do that, as there's no point if we have to have this schema for things to work.
What about doing something like this instead?
if (GDK_IS_X11_DISPLAY ((gdk_display_get_default())))
interface_gnome_settings = g_settings_new (INTERFACE_GNOME_SCHEMA);
else
interface_gnome_settings = NULL;
/* … */
if (interface_gnome_settings)
g_settings_set_string (interface_gnome_settings,
GTK_THEME_KEY, meta_theme_info->gtk_theme_name);
Just to avoid coupling
wayland and interface_gnome_settings.Just an idea, feel free to scrap it :)
Since we no longer use system() to tell if we are under wayland or x11, we no longer have to deal unconditionally with that schema. Wayfire btw does indeed depend on it as wayfire (and probably a lot of other non-GNOME/non-KDE compositors) use the GNOME gsettings values.
Wayfire's Debian package itself does NOT depend on gsettings-desktop-schemas(debian packaging names here), not sure how it handles settings themes etc (maybe using Adwaita unconditionally?) when this is not installed.
Anyway, I can add checking for the existance of the GNOME interface schema so this will not crash if some distro is shipping GTK without it and assuming that works. Debian's GTK 3 builds at least used to depend on it, I've never tested anything without that package as it would break so much of my system
Wayfire's Debian package itself does NOT depend on gsettings-desktop-schemas(debian packaging names here), not sure how it handles settings themes etc (maybe using Adwaita unconditionally?) when this is not installed.
I don't know either but as said it seems that on the GTK side a specific DBus name can provide the data, so they could also potentially get the info from some place else (be it a conffile or whatever) and present it that way. No idea. And the Debian package could be missing a dep as well if nobody noticed, this happens even in Debian :slightly_smiling_face:
Anyway, I can add checking for the existance of the GNOME interface schema so this will not crash if some distro is shipping GTK without it and assuming that works. Debian's GTK 3 builds at least used to depend on it, I've never tested anything without that package as it would break so much of my system
I don't know if it's actually worth it if it looks unlikely anybody is gonna have such a setup, so you can do whichever you prefer I think. And if you don't do it and somebody happen to find a setup where it's a problem, we can always add it…
OTOH if we depend on it we might want to make that explicit. :shrug:
Latest changes simplify the logic for detecting x11 vs wayland, looking for x11 once, loading the gnome schema if we are not under x11, then looking for the settings object it is loaded into. That also paves the way to not depending on the schema at all, just not setting the GNOME preferences (thus not theming anything running under wayfire at least) rather than say, crashing.
last force-push is just a rebase against master
Above commit allows installation when the GNOME schemas are not present, we just lose the ability to actually apply the chosen theme to non-xwayland apps when running under wayland with the GNOME schemas absent. No idea if that will ever be used of course
Thanks, we can keep that definition than
OK, I didn't test this yet, but code looks OK to me :+1:
Last commit just moves initializating of interface_gnome_settings to where it is declared, thus removing one line of code.
Looks good :+1:
Squashed and merged from the command line with https://github.com/mate-desktop/mate-control-center/commit/1e8c08e51ea38d5faec5f352ea5d00c565a0a63d to allow editing the commit message
Thanks everyone for reviewing!
We also have the related caja PR
https://github.com/mate-desktop/caja/pull/1771
which allows setting caja's background from the control center in wayland whenever mate-settings-daemon (as needed for xwayland apps) is running, falls back to the standalone wayland background dialog if it is not running or not installed
zhuyaliang
lukefromdc
If we are in a wayland session, write the gtk theme and icon theme to both org.mate and org.gnome This changes wayland and xwayland themes simultaniously *startup with x11 backend, if we are under wayland without xwayland we don't have mate-settings-daemon anyway