May 7th, 2009 Shell hook patch was completely rewritten as a new line of patches related to general window information handling. Also, added killclient patch.
Bug.n is a great Autohotkey script that brings functionality of the DWM window manager to Windows operating system. This includes automatic Window placement and resizing, and support for multiple virtual workspaces. The project webpage can be located at:
However, I did encounter certain annoyances. Hence I have prepared a set of patches that removes my personal itches. Below you can find in-depth description of each of the issues and solutions I have prepared.
All my patches are available both as a textual file to be applied with command
patch -p0 in distribution directory, and as a Bazaar 1.14 repository. In particular I imported Bug.n 3.5.1 into repository
http://pitkali.info/bugn/upstream. Each patch has a branch derived from this one (level 1 patches) or from branch of another patch (level 2 patches.) Patch files were generated using appropriate
bzr diff command.
Disclaimer Even though I do have some experience in development, never before have I seen or even heard of Autohotkey. I’ve been learning its language during modyfing Bug.n code. Hence my patches probably could use some tweaking by people more experienced in Autohotkey development.
Do take also note that I have not used nor seen the original DWM window manager. Under my Linux I am planning to use awesome 3 (compiled, installed and learned lua, time to learn API for configuration file…)
I am very fond of focus follows mouse idea. Which is why I used Powertoys to enable it under my Windows XP system (here it is called X-mouse.) However, this means that what to my mouse has influence on window focus, and thus — window arrangement. Even though it did work pretty well by default, it sometimes failed to do what I consider best. Hence I created a patch to explicitly manage my mouse.
I have prepared a patch that does the following (configurable through
BUGN_arrangeMouse variable, enabled by default):
bzr branch http://pitkali.info/bugn/patch1-move-mouse
I happen to use tags a lot. This also means switching between them quite often. I found it counter-intuitive and counter-productive that each time I switch between tags, different window is placed in master area (or is the topmost window in monocle layout, for that matter.)
BREW_master(if variable is not empty) is placed at master area, activated for gaplessgrid layout, brought to top for other layouts.
Note that this is level 2 patch that is technically dependent on the previous one. This pertains to the last of the above-mentioned points only so it is easy to manually remove this dependency.
Bzr (includes dependency):
bzr branch http://pitkali.info/bugn/patch2-save-master
Each new window that is not excluded from BUGN should be supplied to
BUGN_manage function. It remembers its properties and restores them upon quiting bug.n (or reload.) However, new windows are managed like that only if they are detected by a shell hook, so only if:
wParam = 1event.
However, it is possible to have windows that are being arranged by BUGN and were not processed by
BUGN_manage function. For example:
BUGN_arrange, which detected its window as non-excluded. But it is not known — the call to
BUGN_manageis missing here.
The patch is quite simple.
BUGN_scan function that collects available windows for arrangement may check each non-excluded window for being listed in
BUGN_wins_id array. If window is not there, it should be supplied to
bzr branch http://pitkali.info/bugn/patch1-scan-detection-fix
It seems to be sufficient to check for WS_POPUP (0x80000000) style of window upon its detection. Then its ID can be added to
BUGN_wins_floating array. If previous patch was applied (fix for window detection upon BUGN scan operation), it is sufficient to modify
BUGN_manage function, so that it checks new windows for this style item. This seems to work pretty well for various boxes and even Kaspersky Internet Security’s non-resizable windows.
Note: The dialog box was floating before forced rearrangement, because Windows did not send shell event for it.
Note: This patch does not, technically, depend on previous one, as in: they touch different parts of code. Logically, it works best with the previous patch applied.
bzr branch http://pitkali.info/bugn/patch1-dialog-detection
It all started with Opera widgets. It seems that they (or, at least, the Post It widget) work best when excluded from Bug.n. Unfortunately enough, all Opera windows have class OpWindow and may be distinguished only by title: browser windows have titles ending with string ’ - Opera’.
So you could create an exclusion rule just for those widgets that you use. Not very elegant. And not working very well, because Opera windows are detected before they have the right title set. So I decided the following regex would solve my problem:
OpWindow,,.+(?<! - Opera);
This uses negative look-behind feature that translates exactly to OpWindows with titles NOT ending with string ’ - Opera’.
Originally bug.n uses three string searches within exclusion string to determine, if a window should excluded from BUGN module. This is fast. Regular expressions on the other hand may be slow, if used the wrong way. Admittedly, my first attempt to implement this was quite lousy and caused deterioration in performance that was noticeable even on my quite speedy laptop.
This patch is my third, and most successful attempt. For each window, it checks length of class name and title, and performs a single
This is done by taking an exclusion string and converting it into a regular expression with alternatives. Additionally, each alternative has ^ at its beginning and ends with $.
Note that this would allow to replace most of default rules with a single expression:
I decided to leave them be, for the time being. It will be easier to merge in changes from next bug.n releases, should this patch be rejected.
Note: I have isolated the rule processing code in a single function in file BUGN.ahk. The file config.ahk only calls this function with different exclusion string. This will make it easier to modify rule processing code in the future. If the user needs super-flexibility, they can still just do something else instead of calling this function.
bzr branch http://pitkali.info/bugn/patch1-bugn.excl-regexp
PS: I think it could be interesting to enable using regular expressions in other exclusions and BREW rule matching. Though I am currently out of spare time until I finish my Master’s Thesis…
Under certain circumnstances it may happen that after using a hotkey to kill a client (invoking
BUGN_killclient function) the client is killed (window is closed) but windows stay arranged as if that window was still present.
This happens if
BUGN_arrange is called too early after
WinClose command. The solution is to add
WinWaitClose waiting for window to be closed. I also use a timeout of 1 second.
bzr branch http://pitkali.info/bugn/patch1-killclient
It all started with a previously described shell hook fix that enabled detection of new windows not only on
wParam = 1 or 2, but also for values of 4 and 6. I was initially confused whether it’s useful at all, but then I realised that at my office awfully many windows appear with only
wParam of 4 (activation) and without 1.
Hence I started using this patch, discovered a number of vaguely related issues and rewritten the patch as a series of different patches. They fix the following issues:
BUGN_scanshould now be never called for an excluded window. This means that on reload, for example, BUGN will not try to alter windows that are excluded from BUGN.
BREW_wParamvariable is now periodically reset (removes space leak.)
BUGN_scannot only detects new windows but also checks for removed windows.
shellMsgDelaywas not declared, hence this setting was never effective), moving sleep command to better place, and changing default shell message delay for better window handling.
BREW_arrangefully synchronise information on existing windows (for appropriate views, that is) before hiding and showing windows. This in particular fixes various issues arising when using Skype and Psi, and hiding their windows.
BREW_tagwill not call
BREW_arrangebut just hide the altered window (if need be.)
BREW_arrange. This fixes bug with windows being tagged by visible and invisible tag at the same time (flickering windows and windows stealing focus every now and then.)
The base patch is scan detection fix described above: patch1-scan-detection-fix.patch. The remaining patches are, in order of application:
bzr branch http://pitkali.info/bugn/patch2-wininfo-removal
bzr branch http://pitkali.info/bugn/patch3-shell-hook-fixes
bzr branch http://pitkali.info/bugn/patch4-windestroy-fix
Note: Each patch file was generated against a lower level patch, so to get all the changes in the series you need to apply all of them. But each bazaar repository contains all of the series up to and including current level patch. Hence to get bazaar repository with all of the series, it is sufficient to branch only the last repository.
Most of these patches are prepared against base version (Bug.n 3.5.1). They are, however, quite compatible. I managed to merge them all into all.patch with only a few simple to remove text conflicts. Feel free to examine
http://pitkali.info/bugn/all-patches repository containing all these patches. Additionally,
http://pitkali.info/bugn/myconfig repository contains all patches and some of my personal tweaks (including custom hotkeys.)
Feel free to .