Skip to content
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

Application name is not shown in the gnome top bar #7685

Closed
hhyyrylainen opened this issue Feb 23, 2022 · 8 comments
Closed

Application name is not shown in the gnome top bar #7685

hhyyrylainen opened this issue Feb 23, 2022 · 8 comments

Comments

@hhyyrylainen
Copy link

Describe the bug
See this image how just the logo (and no name of any kind) is shown when an avalonia app is running on gnome:
Kuvakaappaus - 2022-02-23 16-58-51

(top left in the image, to the right of the avalonia icon there should be some kind of name)
I was unable find any info about how to fix that.
I tried grabbing:

    <NativeMenu.Menu>
        <NativeMenu />
    </NativeMenu.Menu>

from: https://github.com/VitalElement/Xune/blob/main/Xune.Desktop/App.axaml
but that didn't help at all

To Reproduce
Steps to reproduce the behavior:

  1. Run commands:
dotnet new -i Avalonia.Templates
mkdir MyApp
cd MyApp/
dotnet new avalonia.mvvm
dotnet run
  1. Look at the top left of the screen and notice how the program name is missing

Expected behavior
I expected at least something like MyApp (which seems to be the executable name generated) to be there, but instead it looks like avalonia tries to use some smarter API to report a different name to gnome but that apparently fails entirely.

If this is a documentation issue rather than a bug, this is still pretty serious (and a pretty big oversight in the templates), and doesn't look very professional at all. The other times I've seen this happen basically have been me messing with a GUI framework and making it accidentally broken.

Screenshots
See the first section of this issue

Desktop (please complete the following information):

  • OS: Linux (Fedora 35)
  • Should be the latest templates version (I just ran the avalonia template install command again). Looks like it puts 0.10.12 as the avalonia version in the created MyApp.csproj file

Additional context
Problem visible even with the template application.

@maxkatz6
Copy link
Member

Just for case, have you set Application.Name property?
@kekekeks @jmacato

@hhyyrylainen
Copy link
Author

If you mean the one in App.axaml as an attribute on the first Application XML tag in that file, yes. The template project seems to be missing that, but I have this in another project I'm doing to evaluate avalonia:

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="using:GodotPckTool"
             x:Class="GodotPckTool.App"
             Name="GodotPckTool">

and that shows the same issue, the name doesn't appear.

@hhyyrylainen
Copy link
Author

I investigated this and it seems that Avalonia doesn't call XSetClassHint which is what sets that text. Experimentally I put some code into X11Window.SetIcon to just put a test name on the Window, and a bit surprisingly it actually works:

Kuvakaappaus - 2022-07-25 16-14-58

Here's the relevant code:

                var classHint = XAllocClassHint();

                var classHintData = (XClassHint)Marshal.PtrToStructure(classHint, typeof(XClassHint));

                var classTextData = Marshal.StringToHGlobalAnsi("test name");

                classHintData.ResClass = classTextData;
                classHintData.ResName = classTextData;

                Marshal.StructureToPtr(classHintData, classHint, true);

                XSetClassHint(_x11.Display, _handle, classHint);

                XFree(classHint);

                Marshal.FreeHGlobal(classTextData);

Note I had to add those class hint function and struct definitions as they didn't seem to exist yet.

I'll try to find the right place and attempt to clean up that code a bit, and then I think I could submit a PR.

@kekekeks
Copy link
Member

I believe we do set WM_CLASS property here -

public void SetWmClass(string wmClass)
{
var data = Encoding.ASCII.GetBytes(wmClass);
fixed (void* pdata = data)
{
XChangeProperty(_x11.Display, _handle, _x11.Atoms.XA_WM_CLASS, _x11.Atoms.XA_STRING, 8,
PropertyMode.Replace, pdata, data.Length);
}
}

@hhyyrylainen
Copy link
Author

hhyyrylainen commented Jul 25, 2022

If I replace my code change with SetWmClass("test class"); the name stops working.

I based my solution on this StackOverflow answer: https://stackoverflow.com/a/62849688/4371508 which seems to indicate that this special API needs to be used and it is not a normal property that is set like that. So this text that needs to be set is probably unrelated to WM_CLASS.

@hhyyrylainen
Copy link
Author

I think I can figure out the X11Window class changes that will allow setting the application name, but briefly looking at the way the X11 platform etc. is initialized it doesn't look like I can grab Application.Name from any convenient place.

@hhyyrylainen
Copy link
Author

I opened a draft PR with a dummy "Avalonia Application" now always being set as the application name: #8595

@hhyyrylainen
Copy link
Author

I'll close this as #8597 is now merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants