Nazariglez / notan

Cross-platform multimedia layer
https://nazariglez.github.io/notan-web/
Apache License 2.0
802 stars 55 forks source link

Possibility to set app_id #304

Closed martinlindhe closed 8 months ago

martinlindhe commented 9 months ago

app_id is a wayland property which is a string identifier. x11 apps have a similar property called class.

It would be helpful to be able to set this value using the notan api.

winit has a method that wraps the above behavior, called with_name

Currently on a sway setup (swaymsg -t get_tree), running cargo run --release --example draw_image

#11: con "~/.config/sway/config - Sublime Text" (xdg_shell, pid: 1998, app_id: "subl")
#13: con "Issues · Nazariglez/notan — Mozilla Firefox" (xdg_shell, pid: 1922, app_id: "firefox")
#2052: con "Notan App" (xdg_shell, pid: 1248803)
Nazariglez commented 8 months ago

This is interesting, do you think it makes sense to create this id automatically from the app's title? Like from "Notan App" it could be "notan_app". Though I am not sure if it makes sense because the title can change while my guess is that the app_id should remain the same all time.

martinlindhe commented 8 months ago

This is interesting, do you think it makes sense to create this id automatically from the app's title? Like from "Notan App" it could be "notan_app". Though I am not sure if it makes sense because the title can change while my guess is that the app_id should remain the same all time.

The app_id should be a unique non-changing identifier, so I think it should be a separate function. (And don't fill it with a default value, its better left unset rather than multiple applications sharing the same app_id).

For reference, here is a bug report in bevy about this same type of feature with some more information: https://github.com/bevyengine/bevy/issues/4188

Nazariglez commented 8 months ago

I made this PR: https://github.com/Nazariglez/notan/pull/306.

I think it's useful having this because I can use it also as canvas_id for the web target, so the functionality was just there only that the native backend did not use it. Winit has enabled by default the features X11 and Wayland for UNIX so I am not checking which one is the app running on, I am just assuming that the feature is enabled. I tried in X11 without issues. It would be great to see if it works on wayland.

martinlindhe commented 8 months ago

Verified PR #306 works on wayland.

Without changes to the test app (oculante) , app_id is "notan_app":

#75: con "Oculante | 0.8.6" (xdg_shell, pid: 77191, app_id: "notan_app")

With

WindowConfig::new().set_app_id("oculante")

we get:

#77: con "Oculante | 0.8.6" (xdg_shell, pid: 77746, app_id: "oculante")
Nazariglez commented 8 months ago

So nice, thank you for the help!