<firstname>Parts of this documentation was converted from the KDE UserBase <ulink url=" http://userbase.kde.org/KWin Rules">KWin Rules</ulink> page and updated by the &kde; Documentation team to Plasma 5.8.</firstname>
<para>&kwin; allows the end-user to define rules to alter an application's window attributes.
</para>
<para>For example, when an application is started, it can be forced to always run on <emphasis>Virtual Desktop 2</emphasis>. Or a defect in an application can be worked-around to force the window above others.
</para>
<para>Step-by-step <link linkend="examples">examples</link> are provided along with detailed information on using the <link linkend="kwin-rule-editor">&kwin; Rule Editor</link> to specify <link linkend="window-matching">Window Matching</link> and <link linkend="window-attributes">Window Attributes</link>.
</para>
</chapter>
<chapter id="examples-and-application-workaround"><title>Examples and Application Workaround</title>
<para>To see what's possible, detailed <link linkend="examples">examples</link> are provided which can also be used to model your own rules.
</para>
<para>A special page is to dedicated to address <link linkend="application-workarounds">Application Workaround</link>.
<para>There are several ways to invoke the &kwin; Rule Editor. Below are two:
</para>
<itemizedlist>
<listitem><para>Right-click on the title-bar of any window, choose <menuchoice><guimenu>More Actions</guimenu><guimenuitem>Window Manager Settings...</guimenuitem></menuchoice> and in the <guilabel>Configure</guilabel> window, select <guilabel>Window Rules</guilabel> or</para></listitem>
<para>When an application starts (or the rules are modified), &kwin; evaluates the rules from the top of the list to the bottom. For all rules which match a window, the collective set of attributes are applied to the window, then the window is displayed.
</para>
<para>Should two or more matching rules enable the same attribute, the setting in the <emphasis>first</emphasis> rule in the list is used.
</para>
<para><tip><para>You can tailor children windows for the application by placing the more restrictive rules first - see the <link linkend="application-on-all-desktops-and-handle-one-child-window-uniquely">Kopete and Kopete Chat Window</link> example.</para></tip>
<listitem><para><guilabel>Size & Position</guilabel></para></listitem>
<listitem><para><guilabel>Arrangement & Access</guilabel></para></listitem>
<listitem><para><guilabel>Appearance & Fixes</guilabel></para></listitem>
</orderedlist>
<para>As the name implies, <guilabel>Window matching</guilabel> is used to specify criteria to match one or more windows. The other three tabs are used to alter the attributes of the matching windows.
</para>
<para><tip><para>Panels can also be affected.</para></tip>
<para>Each window rule has user specified <link linkend="window-matching">Window Matching</link> criteria. &kwin; uses the criteria to determine whether the rule is applicable for an application.
<para>Along with Window Matching criteria, each window rule has a set of <link linkend="window-attributes">Window Attributes</link>. The attributes override the corresponding application's settings and are applied before the window is displayed by &kwin;.
<para>The <guilabel>Window Matching</guilabel> tab is used to specify the criteria &kwin; uses to evaluate whether the rule is applicable for a given window.
</para>
<para>Zero (match any window) or more of the following may be specified:
</para>
<itemizedlist>
<listitem><para><guilabel>Window class (application)</guilabel> - match the class.<itemizedlist>
<listitem><para><guilabel>Match whole window class</guilabel> - include matching the secondary class.</para></listitem>
</itemizedlist>
</para></listitem>
<listitem><para><guilabel>Window role</guilabel> - restrict the match to the function of the window (⪚ a <emphasis>main window</emphasis>, a <emphasis>chat window</emphasis>, &etc;)</para></listitem>
<listitem><para><guilabel>Window types</guilabel> - restrict the match to the type of window: <guilabel>Normal Window</guilabel>, <guilabel>Dialog Window</guilabel>, &etc;</para></listitem>
<listitem><para><guilabel>Window title</guilabel> - restrict the match to the title of the window.</para></listitem>
<listitem><para><guilabel>Machine (hostname)</guilabel> - restrict the match to the host name associated with the window.</para></listitem>
</itemizedlist>
<para><tip><para>While it's possible to manually enter the above information, the preferred method is to use the <guilabel>Detect Window Properties</guilabel> button.</para></tip>
</para>
<para>For each field, the following operators can be applied against the field value:
</para>
<itemizedlist>
<listitem><para><guilabel>Unimportant</guilabel> - ignore the field.</para></listitem>
<para><note><para>Both <guilabel>Exact Match</guilabel> and <guilabel>Substring Match</guilabel> implement case insensitive matching. For example, <emphasis>AB</emphasis> matches the string <emphasis>AB</emphasis>, <emphasis>ab</emphasis>, <emphasis>Ab</emphasis> and <emphasis>aB</emphasis>.</para></note>
<para>The <guilabel>Detect Window Properties</guilabel> function simplifies the process of entering the matching-criteria.
</para>
<orderedlist>
<listitem><para>For the application you'd like to create a rule, start the application.</para></listitem>
<listitem><para>Next, in the <guilabel>Window matching</guilabel> tab, set the number of seconds of delay before the <guilabel>Detect Window Properties</guilabel> function starts. The default is zero seconds.</para></listitem>
<listitem><para>Click on <guilabel>Detect Window Properties</guilabel> and</para></listitem>
<listitem><para>When the mouse-cursor turns to cross-hairs, place it inside the application window (not the title bar) and left-click.</para></listitem>
<listitem><para>A new window is presented with information about the selected window. Select the desired fields:<itemizedlist>
<listitem><para><guilabel>Secondary class name</guilabel> - some applications have a secondary class name. This value can be used to restrict windows by this value.</para></listitem>
<para>Click the <guilabel>OK</guilabel> button to back-fill the <guilabel>Window Matching</guilabel> criteria.
</para>
<para>By using a combination of the information, a rule can apply to an entire application (by <guilabel>Class</guilabel>) or a to a specific window <guilabel>Type</guilabel> within the <guilabel>Class</guilabel> - say a <guilabel>Toolbar</guilabel>.
<para>The attributes which can be set are grouped by function in three tabs:
</para>
<orderedlist>
<listitem><para><guilabel>Size & Position</guilabel></para></listitem>
<listitem><para><guilabel>Arrangement & Access</guilabel></para></listitem>
<listitem><para><guilabel>Appearance & Fixes</guilabel></para></listitem>
</orderedlist>
<para>Each attribute has a set of parameters which determines its disposition.
</para>
<sect1 id="parameters"><title>Parameters</title>
<para>Each attribute, minimally, accepts one of the following parameters. Additional, attribute-specific arguments are listed within each <link linkend="attributes">attribute</link> definition.
</para>
<variablelist>
<varlistentry><term><emphasis role="bold">Do Not Affect</emphasis></term>
<listitem>
<para>Ensure a subsequent rule, which matches the window, does not affect the attribute.</para>
<para>The setting cannot be changed at run-time.</para>
</listitem>
</varlistentry>
<varlistentry><term><emphasis role="bold">Apply Now, Force Temporarily</emphasis></term>
<listitem>
<para>Apply/Force the setting once and unset the attribute.The difference between the two is at run-time, <guilabel>Apply Now</guilabel> allows the attribute to be changed and <guilabel>Force Temporarily</guilabel> prohibits it to be altered until all affected windows exit.</para>
</listitem>
</varlistentry>
</variablelist>
<para><warning><para>For <guilabel>Apply Now</guilabel>, if the rule has no other attributes set, the rule is deleted after evaluation whereas <guilabel>Force Temporarily</guilabel>, the rule is deleted after the last affected window terminates.</para></warning>
</para>
</sect1>
<sect1 id="attributes"><title>Attributes</title>
<para><tip><para>The <guilabel>Detect Window Properties</guilabel> button back-fills attribute-specific values - for more information see <link linkend="window-matching">Window Matching</link>. For example the height and width values of the <guilabel>Size</guilabel> attribute is set to the height and width of the detected window.</para></tip>
</para>
<para><tip><para><guilabel>Yes/No</guilabel> arguments are used to toggle on or off attributes. Leniency with grammar helps one understand how a setting will be processed. <inlinemediaobject> <imageobject> <imagedata fileref="Face-smile.png" format="PNG"/> </imageobject> </inlinemediaobject> For example, the attribute <guilabel>Skip taskbar</guilabel>, when set to <guilabel>No</guilabel> means do not skip the taskbar. In other words, show the window in the taskbar. <inlinemediaobject> <imageobject> <imagedata fileref="Face-smile.png" format="PNG"/> </imageobject> </inlinemediaobject></para></tip>
</para>
<sect2 id="size--position"><title>Size & Position</title>
<para>Place the window on the specified <emphasis>(Virtual) Desktop</emphasis>, <emphasis>Activity</emphasis> or <emphasis>Screen</emphasis>. Use <guilabel>All Desktops</guilabel> to place the window on all <emphasis>Virtual Desktops</emphasis>.</para>
<para>Toggle the Fullscreen, Minimize and Shading window attribute. For example, a window can be started Minimized or if it is started Minimized, it can be forced to not.</para>
<para><tip><para>Maximized attribute is emulated by using both <guilabel>Maximized horizontally</guilabel> and <guilabel>Maximized vertically</guilabel> or <guilabel>Initial placement</guilabel> with the <guilabel>Maximizing</guilabel> argument.</para></tip>
<para>Toggle whether to accept or ignore the window's requested geometry position. To avoid conflicts between the default placement strategy and the window's request, the placement strategy is ignored when the window's request is accepted.</para>
</listitem>
</varlistentry>
<varlistentry><term><emphasis role="bold">Minimum size, Maximum size</emphasis></term>
<listitem>
<para>The minimum and maximum size allowed for the window.</para>
<para>Toggle whether to adhere to the window's requested aspect ratio or <emphasis>base increment</emphasis>.In order to understand this attribute, some background is required. Briefly, windows must request from the Window Manager, a base increment: the minimum number of <emphasis>height</emphasis> X <emphasis>width</emphasis> pixels per re-size request. Typically, it's 1x1. Other windows though, for example terminal emulators or editors, use fixed-fonts and request their base-increment according to the size of one character.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="arrangement--access"><title>Arrangement & Access</title>
<para>When a window wants focus, control on a scale (from <guilabel>None</guilabel> to <guilabel>Extreme</guilabel>) whether to honor the request and place above all other windows, or ignore its request (potentially leaving the window behind other windows):</para>
<itemizedlist>
<listitem><para>None - Always grant focus to the window.</para></listitem>
<listitem><para>Low</para></listitem>
<listitem><para>Normal</para></listitem>
<listitem><para>High</para></listitem>
<listitem><para>Extreme - The window's focus request is denied. Focus is only granted by explicitly requesting via the mousing.</para></listitem>
</itemizedlist>
</listitem>
</varlistentry>
</variablelist>
<para><tip><para>See <guilabel>Accept focus</guilabel> to make a window read-only - not accept any keyboard input.</para></tip>
<para>Toggle whether to ignore global shortcuts (as defined by <menuchoice><guimenu>System Settings</guimenu><guisubmenu>Shortcuts and Gestures</guisubmenu><guimenuitem>Global Shortcuts</guimenuitem></menuchoice> or by running <varname>kcmshell5 keys</varname> in <guilabel>konsole</guilabel>) while the window is active.</para>
<para>Toggle whether to display the <guilabel>Close</guilabel> button on the title bar.</para>
</listitem>
</varlistentry>
</variablelist>
<para><tip><para>A terminal window may still be closed by the end user by ending the shell session however using <guilabel>Accept focus</guilabel> to disable keyboard input will make it more difficult to close the window.</para></tip>
<para><warning><para>Use with care because unwanted results may be introduced. For example, a <guilabel>Splash Screen</guilabel> is a automatically closed by &kwin; when clicked.</para></warning>
<para>Toggle whether to disable compositing while the window <emphasis>exists</emphasis>. If compositing is enabled and the rule specifies to disable compositing, while <emphasis>any</emphasis> matching window exists, compositing will be disabled. Compositing is re-enabled when the last matching window terminates.</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
</sect1>
</chapter>
<chapter id="examples"><title>Examples</title>
<para><note><para>The first example details all the necessary steps to create the rules. In order to keep this page a manageable size, subsequent examples only list steps specific to the example.</para></note>
</para>
<para><note><para>The <guilabel>Pager</guilabel> attribute refers to the <guilabel>Virtual Desktop Manager</guilabel>:
<sect1 id="pin-a-window-to-a-desktop-and-set-other-attributes"><title>Pin a Window to a Desktop and set other Attributes</title>
<para>Pin &akregator; to <emphasis>Virtual Desktop 2</emphasis>. Additionally, start the application with a preferred size and position. For each attribute, use the <guilabel>Apply Initially</guilabel> <link linkend="parameters">parameter</link> so it can be overridden at run-time.
</para>
<para>The &kwin; rule is created as follows:
</para>
<orderedlist>
<listitem><para>Start &akregator; on <emphasis>desktop two</emphasis>, size and position it to suit:
<listitem><para>Right-click on the titlebar and select <menuchoice><guimenu>More Actions</guimenu><guimenuitem>Window Manager Settings...</guimenuitem></menuchoice>:
<listitem><para>Click <guilabel>Detect Window Properties</guilabel> with <guilabel>0s delay</guilabel> the cursor immediately turns into cross-hairs. Click (anywhere) inside the &akregator; window (but not the title bar). The window criteria are presented. Match only by primary class name so leave the check boxes unchecked - for additional information see <link linkend="window-matching">window matching</link>:
<listitem><para>Clicking <guilabel>OK</guilabel> the previous window back-fills the results in the <guilabel>Window Matching</guilabel> tab. Enter a meaningful text in the <guilabel>Description</guilabel> field (which is displayed in the <guilabel>KWin Rule</guilabel> window):
<listitem><para>Enable the window attributes: <guilabel>Position</guilabel>, <guilabel>Size</guilabel> and <guilabel>Desktop</guilabel>. The initial values are set by <guilabel>Detect Window Properties</guilabel> and can be overridden:
<listitem><para>Clicking <guilabel>OK</guilabel> in the previous window returns to the main <guilabel>KWin Rules</guilabel>. The new rule with its description is listed:
<listitem><para>Click <guilabel>OK</guilabel> to close the window.</para></listitem>
<listitem><para>Done.</para></listitem>
</orderedlist>
</sect1>
<sect1 id="application-on-all-desktops-and-handle-one-child-window-uniquely"><title>Application on all Desktops and Handle One Child Window Uniquely</title>
<para>Except for conversation windows, display &kopete; and its children windows on all desktops and skip the systray and pager. For children conversation windows, treat them as the parent window except show them in systray.
</para>
<para>For each attribute, use the <guilabel>Force</guilabel> <link linkend="parameters">parameter</link> so it can not be overridden.
</para>
<para>In order to implement the above, two rules need to be created:
</para>
<orderedlist>
<listitem><para>A rule for <guilabel>Kopete Chat</guilabel> and</para></listitem>
<listitem><para>A rule for &kopete;</para></listitem>
</orderedlist>
<para>The <guilabel>Kopete Chat</guilabel> rule's matching-criteria is more restrictive than the <emphasis>Kopete</emphasis> rule as it needs to match a specific Window Role: the chat window. Due to <link linkend="rule-evaluation">rule evaluation</link> processing, the <guilabel>Kopete Chat</guilabel> rule must precede the &kopete; rule in the <link linkend="kopete-kwin-rule-list">KWin Rule list for Kopete</link>.
<para>Assuming a <guilabel>Kopete Chat</guilabel> window is open:
</para>
<orderedlist>
<listitem><para>Use <guilabel>Detect Window Properties</guilabel> and select the <guilabel>Kopete Chat</guilabel> window. Check the <guilabel>Window role</guilabel> box to restrict the criteria to chat windows - for additional information see <link linkend="window-matching">window matching</link>:
<listitem><para>Clicking <guilabel>OK</guilabel> in the previous window back-fills the results in the <guilabel>Window Matching</guilabel> tab. Enter a meaningful text in the <guilabel>Description</guilabel> box:
<listitem><para>Click through to complete entry of the rule.</para></listitem>
</orderedlist>
<para><note><para>The <guilabel>Skip taskbar</guilabel> attribute is set to <guilabel>No</guilabel> to display the window in the taskbar which loosely translates to: <emphasis>no</emphasis> <emphasis>do not</emphasis> <emphasis>skip taskbar</emphasis> <inlinemediaobject> <imageobject> <imagedata fileref="Face-smile.png" format="PNG"/> </imageobject> </inlinemediaobject>.</para></note>
<listitem><para>Use <guilabel>Detect Window Properties</guilabel> and select the &kopete; window. Match only by primary class name so leave the check boxes unchecked - for additional information see <link linkend="window-matching">window matching</link>:
<listitem><para>Clicking <guilabel>OK</guilabel> in the previous window back-fills the results in the <guilabel>Window Matching</guilabel> tab. Enter a meaningful text in the <guilabel>Description</guilabel> box:
<para>As mentioned, due to <link linkend="rule-evaluation">rule evaluation</link> processing, the <guilabel>Kopete Chat</guilabel> rule must precede the &kopete; rule:
<sect1 id="suppress-a-window-from-showing-on-pager"><title>Suppress a Window from showing on Pager</title>
<para><guilabel>KNotes</guilabel> currently does not allow for its notes to skip the pager however a rule easily solves this shortcoming.
</para>
<para>Assuming a <emphasis>sticky note</emphasis>' window is available:
</para>
<orderedlist>
<listitem><para>Use <guilabel>Detect Window Properties</guilabel> and select any <emphasis>sticky note</emphasis> window. Match only by primary class name so leave the check boxes unchecked - for additional information see <link linkend="window-matching">window matching</link>:
<listitem><para>Clicking <guilabel>OK</guilabel> in the previous window back-fills the results in the <guilabel>Window Matching</guilabel> tab. Enter a meaningful text in the <guilabel>Description</guilabel> box:
<listitem><para>Click through to complete entry of the rule.</para></listitem>
</orderedlist>
</sect1>
<sect1 id="force-a-window-to-the-top"><title>Force a Window to the Top</title>
<para>To pop an active window to the top, set its <guilabel>Focus stealing prevention</guilabel> attribute to <guilabel>None</guilabel>, typically, in conjunction with the <guilabel>Force</guilabel> <link linkend="parameters">parameter</link>:
<sect1 id="multiple-rules-per-application"><title>Multiple Rules per Application</title>
<para><application>Thunderbird</application> has several different child windows. This example:
</para>
<itemizedlist>
<listitem><para>Pin <application>Thunderbird</application>'s main window on <emphasis>Virtual Desktop 1</emphasis> with a specific size and location on the desktop.</para></listitem>
<listitem><para>Allow the <application>Thunderbird</application> composer window to reside on any desktop and when activated, force focus and pop it to the top of all windows.</para></listitem>
<listitem><para>Pop the <application>Thunderbird</application> reminder to the top and do not give it focus so it isn't inadvertently dismissed.</para></listitem>
</itemizedlist>
<para>Each rule's matching criteria is sufficiently restrictive so their order within the main &kwin; window is not important to affect <link linkend="rule-evaluation">rule evaluation</link>.
<para>Assuming the <guilabel>Thunderbird Main</guilabel> window is open, sized and position to suit:
</para>
<orderedlist>
<listitem><para>Use <guilabel>Detect Window Properties</guilabel> and select the <guilabel>Thunderbird Main</guilabel> window. Check the <guilabel>Window role</guilabel> box to restrict the criteria to the main window - for additional information see <link linkend="window-matching">window matching</link>:
<listitem><para>Clicking <guilabel>OK</guilabel> in the previous window back-fills the results in the <guilabel>Window Matching</guilabel> tab. Enter a meaningful text in the <guilabel>Description</guilabel> box:
<para>Assuming a <guilabel>Thunderbird Composer</guilabel> window is open:
</para>
<orderedlist>
<listitem><para>Use <guilabel>Detect Window Properties</guilabel> and select the <guilabel>Thunderbird Compose</guilabel> window. Check the <guilabel>Window role</guilabel> and <guilabel>Window type</guilabel> boxes to restrict the criteria to composition windows - for additional information see <link linkend="window-matching">window matching</link>:
<listitem><para>Clicking <guilabel>OK</guilabel> in the previous window back-fills the results in the <guilabel>Window Matching</guilabel> tab. Enter a meaningful text in the <guilabel>Description</guilabel> box:
<para>Assuming a <guilabel>Thunderbird Reminder</guilabel> window is open:
</para>
<orderedlist>
<listitem><para>Use <guilabel>Detect Window Properties</guilabel> and select the <guilabel>Thunderbird Reminder</guilabel> window. Check the <guilabel>Secondary class name</guilabel> and <guilabel>Window Type</guilabel> boxes to restrict the criteria to reminder windows - for additional information see <link linkend="window-matching">window matching</link>:
<listitem><para>Clicking <guilabel>OK</guilabel> in the previous window back-fills the results in the <guilabel>Window Matching</guilabel> tab. Enter a meaningful text in the <guilabel>Description</guilabel> box:
<para>Below are Workarounds for misbehaving applications.
</para>
<para><tip><para>If you are unfamiliar with creating &kwin; Rules, see this <link linkend="pin-a-window-to-a-desktop-and-set-other-attributes">detailed example</link> to base your new rule.</para></tip>
<para>&Emacs; and <guilabel>gVim</guilabel>, when maximized (full-screen mode) and under certain conditions may encounter window re-sizing issues - see <ulink url="https://bugs.kde.org/show_bug.cgi?id=252314">Emacs window resizes ...</ulink> A &kwin; Rule will work-around the issue.
</para>
<para>Assuming an &Emacs; window is open:
</para>
<orderedlist>
<listitem><para>Use <guilabel>Detect Window Properties</guilabel> and select the &Emacs; window. Match only by <guilabel>primary class name</guilabel> so leave the check boxes unchecked - for additional information see <link linkend="window-matching">window matching</link>
<listitem><para>Clicking <guilabel>OK</guilabel> in the previous window back-fills the results in the <guilabel>Window Matching</guilabel> tab. Enter a meaningful text in the <guilabel>Description</guilabel> text box:
<listitem><para>Ignore &Emacs;'s full-screen request by enabling the <guilabel>Obey geometry restrictions</guilabel> attribute, toggling it to off (<guilabel>No</guilabel>) to ignore and selecting the <guilabel>Force</guilabel> <link linkend="parameters">parameter</link>: