Handling bwindow flags

Hello to all of you,
I’m playing with python and bethon, and while writing the code I stucked on a (maybe trivial) problem.
When I show a modal window it is possible to pass the focus to the main window on the background, giving a modal window unfocused ontop and the main windows focused on the background. I want to avoid this, so I looked for window flags and I found that there’s a B_AVOID_FOCUS flag available, great!

But here’s the problem:
let’s take my self.Flags() is 537395200

if i address a


It works but I erase all previous settings not only focus setting
(btw B_AVOID_FOCUS is 8192)

but I cannot do a

self.SetFlags(self.Flags()|B_AVOID_FOCUS) → Note: “|” is a bitwise operand

I cannot even do a:


the main window is created this way:

BWindow.init(self, frame, ‘Title of window’, B_TITLED_WINDOW, B_WILL_DRAW)

the modal window is created this way:

BWindow.init(self, self.kWindowFrame, self.kWindowName, B_MODAL_WINDOW, B_NOT_RESIZABLE|B_WILL_DRAW)

B_WILL_DRAW is 536870912
looking at init process i thought I could do a self.SetFlags(B_WILL_DRAW), but returns the same error, so I start thinking that the flags are a subset of the actual value of self.Flags()

the error it returns:

BWindow.error: (-2147483643, ‘Invalid Argument’)

Does anyone know some workaround or has any suggestion or see where I’m wrong?
Thank you

Oh my god!
This is because of my flu :man_facepalming: the modal window was not a modal one but a floating one… anyway the flags question remains still unresolved, why self.Flags() cannot be assigned to self.SetFlags()?

B_WILL_DRAW is not a flag you can use on a window, only on a BView.

Also apparently, you need to lock a window before you can set its flags, since that involves transmitting the flags to app_server. I think this also means the window thread must be running already for it to work.

Thank you for your answer,
so I get no errors when I put B_WILL_DRAW at the flags place
BWindow.init(self, frame, ‘xxxxxxxx!’, B_TITLED_WINDOW, B_WILL_DRAW)
but as you explained it’s not correct, should I put 0 instead? (0 seems to work fine) 0 is the default value for flags, right?
because if this is the case everything has more logical sense and one problem is solved, the second problem is:

why when I close the floating window the focus passes to the last opened window and not on the main window?
in my case if I launch from terminal “python myapp.py” which opens a titled windows and a floating window, when I close the floating window the focus passes to the Terminal

Yes, 0 is fine. The list of flags is available here: https://git.haiku-os.org/haiku/tree/headers/os/interface/Window.h#n61

If you are going to use the layout APIs (BLayoutBuilder/BGroupLayout/…) in that window, you can use B_AUTO_UPDATE_SIZE_LIMITS which will let the window compute its minimal and maximal size automatically depending on its content.

1 Like

Oh thank you, there are few more than the ones listed in BeBook


and besides that there’s the equivalent number… thank you

well I don’t really know what you are talking about, sorry :cold_sweat:
maybe those features, which I didn’t know the existence, are not available in bethon (well it could be as it’s an old project)