How to disable window backdrop?

I’m writing a virtual on-screen numpad keyboard app in GTK. It stays on top and is unfocused when user clicks buttons on it. However, Adwaita dims inactive windows’ buttons, so I would like to make them styled the same way as focused window is.

I’ve tried sending unset_state_flags on state-flags-changed to main window, but it doesn’t work properly (only top bar is themed as focused, and the rest of the app stays the same).

Is there any way to completely disable backdrop?

1 Like

Could you provide a link to the app? I would like to test it.

Not programmatically. GTK sets the “backdrop” CSS class recursively, depending on the focus state on the top level window.

You may want to try and create a GTK_WINDOW_POPUP top level, to ensure that it does not get managed by the window manager.

Yes, here it is: https://github.com/konradmb/no-name-yet
It is written in Nim, but the bindings are similar to C.

For now, I’ve came up with this:

  • I’m adding a 500 ms timeout, that calls a unsetBackdrop function.
  • In unsetBackdrop I call unsetStateFlags({StateFlag.backdrop}) on main grid inside window.
  • To be sure that it’s really unset, I added another 1500 ms timeout.

It’s ugly, but it works. :smile:

@ebassi I’ve tried GTK_WINDOW_POPUP, but the main window doesn’t show up.

You’re not “completely disabling” backdrop; you’re just removing a state from a widget, but GTK is entirely free to reset that state any time that it wants, and there’s nothing that lets you prevent that programmatically.

The only way to avoid that is to literally side-load a theme in your application that has no rules for the backdrop CSS classes, but then you get to maintain your own theme.

“Doesn’t show up” is fairly vague.

Yes, the solution that I’ve proposed is only a workaround.

I know, I’m sorry. When I run the app, the window doesn’t show up anymore. There are no warnings.

Maybe I understand it differently? I’ve changed GtkApplicationWindow type from Top Level to Popup in Glade. Is that what you’re proposing?

Yes; though I would not recommend using GtkApplication and GtkApplicationWindow. To be fair, what you’re describing seems to be the job of an input method, more than an application.

Additionally, since you’re writing what amounts to a virtual keyboard, you’re going to have to fight against the system itself; I’d recommend making it part of the window manager/system compositor, as that would remove the need for dealing with client-related functionality, like dealing with the stacking order, or with the backdrop state.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.