Aylur / astal

Building blocks for creating custom desktop shells
https://aylur.github.io/astal/
GNU Lesser General Public License v2.1
287 stars 37 forks source link

How to manage multiple widgets correctly? #111

Closed iCultureBud closed 5 days ago

iCultureBud commented 1 week ago

Have you read through the documentation?

Describe what have you tried so far I already set up a waybar-like widget (based on the bar example). Now I want to add more widgets to the screen (e.g. a controlcenter, mediaplayer, etc.) and they should align under the bar.

Describe your question Reading through the source code and docs didn't get me an answer. If I use a window for each widget I get a GTK Warning, but if I only use box the alignment is always center.

So what's the correct way to handle multiple widgets in one "app"? Just wrap all widgets into one window as boxes or each in just one window?

Thank you!

Aylur commented 5 days ago

In Gtk3 your only option is using windows

function Bar() {
  function openPopup() {
    App.get_window("some-popup")!.show()
  }

  return <window>
    <box>
      <button onClicked={openPopup} />
    </box>
  </window>
}

function SomePopup() {
  return <window name="some-popup" application={App}>
  </window>
}

App.start({
  main() {
    Bar()
    SomePopup()
  }
})

You can enhance the popup with click away to close, or press ESC to close

In Gtk4 (not yet documented, and no JSX support yet) you can use the above window technique or you can also use Gtk.Popover