-
Notifications
You must be signed in to change notification settings - Fork 23
floatpos
Function | Expected argument | Default keybindings |
---|---|---|
floatpos | string | Super+Ctrl+g |
The floatpos
function is a versatile feature that can be used to control the floating size and
position of client windows.
This can be used as a client rule option, via keybindings or via external commands.
As an example this is used as a feature of the togglefloating function to center the window to take up 80% of the screen when moving a window from tiled to floating the first time.
The default keybinding of Super+Ctrl+g
will trigger the above behaviour regardless of whether the
floating position of the window has been saved or not.
- monitor size agnostic positioning options for floating windows
- control the size and position of floating windows using keyboard shortcuts
- position floating windows in a grid-like manner
The floatpos
function accepts a string containing two or four parameters on the form of
<value><char>
where <value>
generally indicates change while the <char>
represents the context
of said change.
In general terms the four parameters represents the x
position, the y
position, the width
and
height
of the client, in that order.
If the string only contains two parameters then this will represent either the position or the size depending on context.
As a practical example the string of "50% 50% 800W 800H"
would place the window in the center of
the workspace and resize it to 800x800 pixels. More precisely the string is saying to center
the window on both the x and the y axis and specifying a fixed height and width of 800 pixels.
If a rule includes floatpos attribute, but does not include the Floating flag (i.e. the window will start as tiled), then the float position will be saved and will come into effect when floating layout is used or togglefloating is applied.
-
A
- absolute position in the drawable area (this spans all monitors) -
a
- absolute position relative to the client's current position -
X
- position relative to workspace -
Y
- as above -
x
- position relative to client -
y
- as above -
m
- position relative to mouse cursor -
M
- as above -
%
- specifies the client's mid-point in percentage relative to the window area height / width -
S
- the client's current x / y position is fixed (sticky)- if value is -1 then width / height indicators determines the size of the client
- otherwise the value indicates the next position, determining the size of the client
- this can, as an example, be used to "maximize" a client from it's current position to the edge of the screen
-
C
- as above, but the client's mid-point (center) is fixed (sticky)- this is typically used when resizing clients, making them expand or contract in all directions
-
Z
- as above, but the opposite side of the client is fixed (sticky) (i.e. client position + size) -
G
- indicates that the monitor is split into a grid on which points the client can be positioned- the value defines the size of the grid, if value is 0 then grid dimensions from config is used
NB: in general all positions are restricted to the current workspace, unless absolute positioning is used.
-
A
- absolute height / width -
a
- relative height / width -
H
- defines height of client, but position can take precedence -
h
- defines height relative to client size -
W
- defines width of client, but position can take precedence -
w
- defines width relative to client size -
%
- size determined in percentage of the monitor's window area -
P
- absolute grid position -
p
- relative grid position
NB: the size of the client is inclusive of the window border.
For convenience it is possible to only pass in two values rather than four, which are interpreted as follows:
-
<number><w/W> <number><h/H>
(resize) - x and y coordinates default to-1C
resulting in the client expanding / contracting -
<number><p/P> <number><p/P>
(grid position) - x and y coordinates default to0G
resulting in grid dimensions from config to be used - otherwise the values are interpreted as x and y coordinates
Floating windows can be positioned along a virtual grid which can be handy if positioning windows using the keyboard is the preferred way.
Here is an example moving a window around in a 5x5 grid:
Grid placement takes outer gaps into account.
The grid positions are relative to the size of the floating window.
The default grid size is controlled by the floatposgrid_x
and floatposgrid_y
settings in
config.h:
static int floatposgrid_x = 5; /* float grid columns */
static int floatposgrid_y = 5; /* float grid rows */
As per the rules a lower case p
means an adjustment in position relative to the current position
while an upper case P
means absolute position.
An upper case G
may be used to define the grid size.
Example grid strings and what they mean:
String | Description |
---|---|
"-1p -1p" |
Move left and up (NW) |
" 0p -1p" |
Move up (N) |
" 1p -1p" |
Move right and up (NE) |
"-1p 0p" |
Move left (W) |
" 1p 0p" |
Move right (E) |
"-1p 1p" |
Move left and down (SW) |
" 0p 1p" |
Move down (S) |
" 1p 1p" |
Move right and down (SE) |
"3G 3G 1P 1P" |
In a 3x3 grid, move to the top left corner |
"3G 3G 2P 1P" |
In a 3x3 grid, move to the top center |
"3G 3G 3P 1P" |
In a 3x3 grid, move to the top right corner |
"3G 3G 1P 2P" |
In a 3x3 grid, move to the left center |
"3G 3G 2P 2P" |
In a 3x3 grid, move to the center |
"3G 3G 3P 2P" |
In a 3x3 grid, move to the right center |
"3G 3G 1P 3P" |
In a 3x3 grid, move to the bottom left corner |
"3G 3G 2P 3P" |
In a 3x3 grid, move to the bottom center |
"3G 3G 3P 3P" |
In a 3x3 grid, move to the bottom right corner |
Tip: Using key modes via sxhkd can help save on keybindings.
Here is an example configuration where Super+v
allows you to use u
, i
, o
, j
, k
, l
,
m
, comma
and period
to move a window around in a grid.
super + v : {u,i,o,j,k,l,m,comma,period}
duskc --ignore-reply run_command floatpos {"-1p -1p"," 0p -1p"," 1p -1p","-1p 0p","50% 50%"," 1p 0p","-1p 1p"," 0p 1p"," 1p 1p"}
The size and position of floating windows can be set as part of client rules by
using the floatpos
rule option.
Here is an example using using floatpos to center the GTK File Chooser Dialog in the center of the workspace.
{ .role = "GtkFileChooserDialog", .floatpos = "50% 50%", .flags = AlwaysOnTop|Floating },
Alternatively the same rule but with a traditional struct table.
// class role instance title wintype opacity flags floatpos scratchkey workspace
{ NULL, "GtkFileChooserDialog", NULL, NULL, NULL, 0, AlwaysOnTop|Floating, "50% 50%", NULL, -1,
Here are some example floatpos strings and what they mean.
String | Description |
---|---|
"-26x -26y" |
Adjust x and y coordinates with amounts relative to client position |
" 0x -26y" |
" |
" 26x -26y" |
" |
"-26x 0y" |
" |
" 26x 0y" |
" |
"-26x 26y" |
" |
" 0x 26y" |
" |
" 26x 26y" |
" |
The above moves windows by adjusting x
and y
coordinates with relative amounts.
The width and height of the window remains as-is.
The position of the window is restricted to the workspace area which means that the window will not overlap the bar and it also can't move over to an adjacent monitor or workspace.
String | Description |
---|---|
"-26a -26a" |
Adjust x and y coordinates with absolute amounts relative to client position |
" 0a -26a" |
" |
" 26a -26a" |
" |
"-26a 0a" |
" |
" 26a 0a" |
" |
"-26a 26a" |
" |
" 0a 26a" |
" |
" 26a 26a" |
" |
As example 1 except that the final position is not restricted to the workspace, which means that the window may overlap the bar or cross over to another workspace or monitor.
String | Description |
---|---|
"-26w -26h" |
Reduce both height and width |
" 0w -26h" |
Reduce height only |
" 26w -26h" |
Increase width but reduce height |
"-26w 0h" |
Reduce width only |
" 26w 0h" |
Increase width only |
"-26w 26h" |
Reduce width but increase height |
" 0w 26h" |
Increase height only |
" 26w 26h" |
Increase both width and height |
In this example the height and width of the window is adjusted in different ways.
The coordinates here are not provided and defaults to -1C
causing the client to stay in place when
the size changes (-1C
means that the center position of the window is fixed).
The size of the client is restricted to the workspace area. Increasing the size of a client close to the workspace border will force the center position of the client to change.
String | Description |
---|---|
" 0Z 0Z 0% 0%" |
Maximize window up and to the left |
" 0x 0Z 0% 0%" |
Maximize window up only |
"-1S 0Z 100% 0%" |
Maximize window up and to the right |
" 0Z 0y 0% 0%" |
Maximize window to the left only |
"-1S 0y 100% 0%" |
Maximize window to the right only |
" 0Z -1S 0% 100%" |
Maximize window down and to the left |
" 0x -1S 0% 100%" |
Maximize window down only |
"-1S -1S 100% 100%" |
Maximize window down and to the right |
These instructions may look cryptic and confusing, but they are examples combining fixed client borders with either a size change or position change.
In principle these could all be written using only position changes, e.g. " 0Z -1S 0% 100%"
could be written as "0Z 9999S"
. Similarly the cases where there are positional changes only the
0% 0%
becomes superfluous. While this could be simplified it has been left as-is for demonstration
purposes.
String | Description |
---|---|
" 0% 0%" |
Move window to the top left corner |
" 50% 0%" |
Move window to top center |
"100% 0%" |
Move window to the top right corner |
" 0% 50%" |
Move window to left center |
" 50% 50%" |
Move window to the center of the workspace |
"100% 50%" |
Move window to right center |
" 0% 100%" |
Move window to the bottom left corner |
" 50% 100%" |
Move window to the bottom center |
"100% 100%" |
Move window to the bottom right corner |
This example positions the floating client in any of the four corners, any of the four edge centers and in the middle of the screen.
String | Description |
---|---|
"3G 3G 1P 1P" |
Move window to the top left corner |
"3G 3G 2P 1P" |
Move window to top center |
"3G 3G 3P 1P" |
Move window to the top right corner |
"3G 3G 1P 2P" |
Move window to left center |
"3G 3G 2P 2P" |
Move window to the center of the workspace |
"3G 3G 3P 2P" |
Move window to right center |
"3G 3G 1P 3P" |
Move window to the bottom left corner |
"3G 3G 2P 3P" |
Move window to the bottom center |
"3G 3G 3P 3P" |
Move window to the bottom right corner |
This does exactly the same as example 5, by using explicit positions on a 3x3 grid as seen in the Grid Placement section.
String | Description |
---|---|
"0m 0m 800W 600H" |
Resize window to 800x600 and place it where the mouse cursor is |
In this example the size of the window is specified and the center point of the window will be positioned where the mouse cursor is.
An example use case might be as a client rule for a scratchpad or otherwise. Having a window pop up where the mouse cursor is can be both predictable and convenient.
External command:
duskc run_command floatpos "50% 50%" # center the client on the current workspace
Concepts | Configuration | Features | Flags | Functionality | Functions