Window Rules
Apply a rule to an app's windows: force position and size, move to a monitor, set opacity, keep on top. Matches executable, class and title.
Author: metanoid18
Tell Windows what to do with an app's windows, once, and stop fixing them by
hand. Each rule matches a window (by executable, window class and title) and
asks for one or more of:
- a position and size, in pixels
- a monitor to open on
- an opacity level
- always on top
Rules are tried in order. The first enabled rule that matches a window is the
only one applied to it -- later rules are not consulted for that window, and
actions are never merged across rules. That is the same model KWin rules and
WindowManager use, and it is the one that stays predictable when two of your
rules would both apply.
What it does
Open the app and the rule happens: the window is moved, sized and made
translucent where the rule says so. Move the window yourself and the mod lets go
-- your position wins for the rest of the session, and the rule is not re-applied
to that window until the app is started again. Saving the settings re-applies
every rule to the windows that are open at that moment, so editing a rule shows
you its effect immediately instead of at the next restart.
Nothing else is touched: no focus, no hiding, and no continuous watch over
windows that are already in place.
Always on top
A rule can keep an app's windows above other windows. The window goes up when it
opens and stays up: activating another window does not take the top away, because
Windows keeps a window's topmost bit until something actually removes it.
What it deliberately does not do is fight for the top:
- Another always-on-top window can sit above yours. The taskbar and other
pinned apps are the user's own choices, and the mod does not climb back over
them.
- A fullscreen app on the same monitor makes it step aside. A window pinned by
this mod is lowered while a fullscreen game or video covers its monitor, and
raised again when that app is gone. A maximized window is not fullscreen and
never triggers this.
- If the app clears the bit itself, the mod leaves it cleared, and the journal
says
app-cleared, rather than pinning it again on the next activation.
- Dragging the window stops the mod touching it, the z-order included, for the
rest of the session.
- Turning the rule off takes the window back down. The mod only directly
lowers a window it pinned. Windows may also change the topmost state of that
window's owners or owned windows when it is lowered.
- The same goes for opacity. The mod records the windows it made translucent,
so changing the level takes effect on windows that are already open, and
clearing the level, deleting the rule or turning the mod off puts them back to
fully opaque. Only windows the mod faded itself are touched: an app that draws
its own transparency is never made opaque by this.
One consequence worth knowing before you pin something: a topmost window stays
above whatever you switch to with Alt+Tab, so if the pinned window covers most of
the screen, switching away looks like nothing happened -- the window you wanted is
behind it. That is how the topmost bit works, not something this mod adds. Pin
small windows, or leave the rule on "No change" while you are switching around.
Where windows go, and in what units
Positions and sizes are in physical pixels, not points. A rule that says
800x600 gets a window 800 physical pixels wide whatever the display scale is,
so on a 150% display it will look smaller than the same rule on a 100% one. That
is not adjustable in this version, and it is the same truth the whole mod works
in: the mod reads and writes physical pixels, and reports them in the journal so
that what it did can be checked by hand.
A position is measured from the top-left of the target monitor, not from the
desktop. position: 100,200 means 100 pixels in and 200 down from the corner
of the monitor the rule names -- or of the monitor the window is already on, when
the rule names none. So a rule survives docking, undocking and adding a monitor
above the primary, which the same numbers in desktop coordinates would not. X and
Y may be negative to place a window partly off the edge.
How matching works
A rule has three optional match fields. Every field you fill in must match; a
field you leave blank matches anything. The fields are:
- Executable -- a file name (
notepad or notepad.exe) or a full path.
- Window class -- the window's class name, for example
Notepad or
Chrome_WidgetWin_1.
- Window title -- searched inside the title, so a fragment is enough.
All matching is case-insensitive. * and ? are wildcards, so chrome* matches
chrome.exe and Untitled* matches any title starting that way. To use a full
regular expression, wrap it in slashes: /^Document - \w+\.txt$/. Nothing else
is treated as a pattern, so a path like C:\Program Files (x86)\Steam\steam.exe
or a title like Inbox | Outlook matches literally.
Owned dialogs are excluded unless Include owned dialogs is enabled on the
rule. Child, hidden, cloaked and tool windows are still excluded. For hosted
apps such as Calculator, Match the hosted app executable lets a rule use
the executable of a visible, unambiguous hosted CoreWindow as well as the frame
host. It is off by default; if the app's child is unavailable, the frame host
remains the only executable identity. Both choices are per rule. A recently
created hosted frame can be reconsidered when its title or child arrives or it
becomes uncloaked, for up to five seconds. This depends on Windows reporting the
relevant events and does not guarantee a match for a slowly starting app.
What it does not do, and where the limits are
- Hide a window from the taskbar or Alt+Tab. Toggling the extended window style is
one-shot and applications reset it themselves; a version that cannot re-assert
would be a broken promise, so it is not here yet.
- Move windows between virtual desktops: that needs an undocumented Windows
interface, and this mod does not use one.
- Override an app that insists. A rule is applied when the window appears and
re-applied once if the app immediately moves it somewhere else. An app that
moves its window again after that wins -- the mod stops rather than fighting it.
- A rule waits for a minimized window to be restored. A minimized window has
no meaningful rectangle to move, so nothing is applied while it is minimized;
the rule is applied the moment you restore it, including for an app that starts
in the tray.
- A maximized window stays maximized. The mod does not restore it to normal
first, and what Windows does with a maximized window's restore rectangle is
Windows' business rather than the mod's, so a rule that sets a position may not
show until you restore the window yourself.
- Opacity on a window that is already translucent by itself. Those windows
draw their own transparency; a flat opacity level would replace it with
something that renders wrong, so the mod reports
already-layered in the journal
and leaves them alone.
- Change a window's size when the app is in charge of it. Some apps re-create
their window when resized; they are left as they are after the single retry.
- The invisible border. Since Windows 10 a window's rectangle includes about
seven pixels of invisible resize border on the left, right and bottom, so
position: 0,0 leaves a small visible gap at the left, and an 800x600 window
looks about 14 pixels narrower and 7 shorter. The mod does exactly what the
numbers say in the coordinates Windows reports, and the journal prints them.
- File Explorer windows are not matched.
explorer.exe is on the built-in
exclude list, because the same process owns the taskbar, the desktop and the
shell's own windows. Explorer windows cannot be targeted by a rule in this
version.
- A window on another virtual desktop is left alone until you save the
settings while it is in front of you. Those windows are cloaked, and the mod
ignores cloaked windows on purpose. A newly observed hosted frame may be
reconsidered if it becomes visible within five seconds. If you delete a rule
while one of its
windows sits on another desktop, that window keeps its opacity and its always on
top until the next settings save with it visible, or until you turn the mod off.
Nothing is left behind after that.
- Always on top and fullscreen is detected geometrically. A window counts as
fullscreen when it covers a monitor and is not maximized. A window that nearly
covers a monitor is not detected, so a pinned window can stay above it.
- Multiple monitors. Fullscreen detection across monitors has not been
confirmed on a multi-monitor setup.
Not the same as other mods
- Always On Top Windows pins and unpins the active window with a hotkey, by
hand. This mod keeps an app's windows on top automatically, every time they
open.
- Prevent Focus Stealing and Snap Commander already cover their own
actions (focus, and snapping to screen regions) and this mod deliberately does
not re-implement them.
- Where I Left It remembers where you left a window and puts it back. This
mod puts a window where you say, every time. Do not list the same app in
both mods' settings at once: both would place the window, in an order neither
can control. The same goes for Snap Commander's auto-snap rules.
Diagnostics
Write a diagnostics journal appends to window-rules-journal.txt in a folder
of your own: <Windhawk mod storage>\<your SID>, created with an access control
list that gives full access to you, to SYSTEM and to administrators, and to nobody
else. Journal lines carry executable names and window titles, and the shared mod
storage folder is readable by every account on the machine, so the file is kept
where only you can read it. If that folder cannot be created the journal is simply
not written; the mod itself is unaffected.
Neither the file nor the folder exists until you turn the journal on. It is capped
at 1 MB (past that it starts again from empty, with a line saying so), and it is
off by default; turn it on when a rule does something you did not expect, or
when reporting a bug, and the file will say what the mod decided and why. Every
line is prefixed with what it is doing:
RULES-LOADED and RULE-LOADED -- the rules as the mod understood them, with
any problem it found in a rule, so a typo is visible instead of silent.
RULE-HIT -- which rule matched which window, and which field decided it.
RULE-NONE -- a window that no rule matched (a few per app, not every one).
RULE-FILTER-SKIP -- a window that was never matched at all, and why.
APPLY -- what was done to a matched window, with the rectangle it was at and
the rectangle the rule asked for, and why nothing happened when nothing did
(already-there, overridden, minimized, refused).
SETTLE -- whether the window stayed where the rule put it, was put back once,
or was left alone because the app kept moving it.
OVERRIDE -- you moved a window yourself; the mod has let go of it.
OPACITY -- what happened to the level, and why: applied, already-there,
already-layered (the app draws its own transparency, left alone), failed
(the window refused the change), app-cleared (the app removed the style
itself), withdrawn (the rule stopped asking, or the mod was turned off).
MONITOR-SKIP -- a rule names a monitor that is not there.
TOPMOST -- what happened to the z-order, and why: applied, already-there,
overridden, minimized, refused, yielded (a fullscreen app took the
monitor), reclaimed (it gave the monitor back), app-cleared (the app
removed the bit itself), withdrawn (the rule stopped asking), or
not-claimed (the window is on top, but this mod did not put it there).
REAPPLY-PASS -- the sweep after a settings save, and how many windows it moved.
Settings
Rules are read from the top down, and an entry with every field blank ends the
list -- the settings template ships one blank entry, so a fresh install has no
rules at all until you fill it in. Leave the blank entry last.
A rule with no match fields is not loaded, because it would apply to every window
on the desktop; the journal says RULE-PROBLEM and names the rule. To mean every
window on purpose, put a * in one of the match fields.