Control window look, feel, or behavior with "hey"

A few tips on this site allude to ways in which you can control the window look, feel, or behavior of your BeOS applications by sending them BMessages with hey (see for example Keep focus when switching workspaces). What’s not obvious from reading those tips is how one determines the magic numbers used in the hey commands.
The secret lies in the file /boot/develop/headers/be/interface/Window.h — a header file which contains a pile of window properties. If you look through this file, you’ll notice that it’s broken up into several sections:


and a separate section for defining behaviors. The three sections above have numerical identifiers as standard integers, while the behaviors section has identifiers expressed in hexadecimal. Each BeOS application determines its own properties internally, but these properties can be overridden by sending appropriate message to an application or to a window.
It’s quite easy to change the type, look, or feel of any given application window. For example, say you want to change the look of an open NetPositive window to „bordered.“ In Window.h, you find a line:


So you can simply type:

hey NetPositive set Look of Window 0 to 20

And boom — that NetPositive window loses its title tab and most of its chrome. So much for look and feel.
Because window behaviors are expressed in hex, and because behaviors can be a combination of one or more properties, things get a little more complex when changing behaviors.
Specifically, the behaviour of a window is based on the value [val] passed to its SetFlags() function, and [val] can be a combination of any flags specified in Window.h. There’s also a SetFeel() function which acts on additional behaviour fields.
The usual „algorithm“ is to run:

hey ApplicationName get Flags

although in most cases you’ll have to also name a specific window of the application, like:

hey ApplicationName get Flags of Window 0

hey will return two numbers — something like:

Reply BMessage(B_REPLY):
   "result" (B_INT32_TYPE) : 16450 (0x00004042)

The first number in the result is a decimal value (16450 in this case). To change the behavior of this window, you need to add this value to the converted value you wish to change it to (behaviors are additive). Sound tricky? Bear with me. Looking again in Window.h, you see:

 B_AVOID_FRONT = 0x00000080,

so to make this window not take focus automatically when switching workspaces (as described in the Keep focus when switching workspaces tip), you would convert 0x00000080 to its equivalent decimal values (try this handy web-based converter), sum them, and set the window to the new value. You get 128+ 16450, or 16578. Now, you can simply enter:

hey NetPositive set Flags of Window 1 to 16578

and your window will add the „Avoid front“ property to its current properties (if you switch to another workspace and back, that window will refuse to be at the front when you return to the workspace).
This technique isn’t 100% foolproof (for example if you set an already set flag you might end up adding another random one, etc.) so a little caution is advised. But you won’t blow up your computer with hey, and you’ll get the original values back by simply restarting the application in question).
For more on using hey, see Chris Herborth’s Scripting chapter in the BeOS Bible, or Seth Flaxman’s hey tutorial at BeNews.



No comments so far.

(comments are closed)