Commit graph

703 commits

Author SHA1 Message Date
Pedro Côrte-Real e3a3917d3a Layout tiled using a width/height fraction
Instead of using container->width/height as both the input and output
of the layout calculation have container->width_fraction/height_fraction
as the share of the parent this container occupies and calculate the
layout based on that. That way the container arrangement can always be
recalculated even if width/height have been altered by things like
fullscreen.

To do this several parts are reworked:

- The vertical and horizontal arrangement code is ajusted to work with
  fractions instead of directly with width/height
- The resize code is then changed to manipulate the fractions when
  working on tiled containers.
- Finally the places that manipulated width/height are adjusted to
  match. The adjusted parts are container split, swap, and the input
  seat code.

It's possible that some parts of the code are now adjusting width and
height only for those to be immediately recalculated. That's harmless
and since non-tiled containers are still sized with width/height
directly it may avoid breaking other corner cases.

Fixes #3547
Fixes #4297
2019-07-14 11:13:55 -04:00
Brian Ashworth c312a10cc7 cmd_split: fix toggle split for non-split layouts
Previously, `layout toggle` and `layout toggle split` would set L_VERT
when layout was L_HORIZ, otherwise it would set L_HORIZ. This meant
that when the layout was L_TABBED or L_STACKED, it would always be
L_HORIZ. This extends #4315 (which corrects the handling when multiple
layouts are given) to try prev_split_layout,
config->default_orientation, and then falling back to L_VERT when the
output is taller than wide and L_HORIZ when wider than tall.
2019-07-11 10:46:56 -04:00
Brian Ashworth 5ffcea4c28 cmd_layout: toggle split for tabbed/stack default
This fixes the logic of split for layout toggle when the default
layout is L_TABBED or L_STACKED. When the default layout is L_TABBED
or L_STACKED, the container/workspace may not have a prev_split_layout.
This was causing L_NONE to be returned by get_layout_toggle, which was
being handled as a syntax error. This adds logic to try
config->default_orientation when prev_split_layout is L_NONE. If that
is also L_NONE, then L_VERT is used when the output is taller than
wide, otherwise, L_HORIZ is used.
2019-07-10 15:29:38 -04:00
Brian Ashworth 152e30c374 cmd_bindswitch: add option to execute on reload
This adds a --reload flag to cmd_bindswitch that allows for the binding
to be executed on reload. One possible use case for this is to  allow
users to disable outputs when the lid closes and enable them when the
lid opens without having to open and re-close the lid after a reload.
2019-07-09 10:00:57 +03:00
Sebastian Parborg 538b36c0e2 Make mouse drag in tiled mode swap containers if no edge is selected
Now the highlighted center area of containers triggers a swap action
instead of moving around the containers.
2019-07-09 02:56:55 -04:00
Sergei Dolgov c9cb5ced7f calibration_matrix: expect 6 individual values
Example usage from command line:

    swaymsg input type:touch calibration_matrix -- -1 0 1 0 -1 1
2019-07-05 18:41:56 +03:00
Sergei Dolgov bcceb61b43 Use isnan 2019-07-05 18:41:56 +03:00
Sergei Dolgov 01ec18e802 Add calibration_matrix config option
Can be used to change the orientation of a touchscreen.

Example usage with swaymsg:

    # identity
    swaymsg input type:touch calibration_matrix '"1 0 0 0 1 0"'

    # 90 degree clockwise
    swaymsg input type:touch calibration_matrix '"0 -1 1 1 0 0"'

    # 180 degree clockwise
    swaymsg input type:touch calibration_matrix '"-1 0 1 0 -1 1"'

    # 270 degree clockwise
    swaymsg input type:touch calibration_matrix '"0 1 0 -1 0 1"'

Documentation:

    https://wayland.freedesktop.org/libinput/doc/latest/absolute-axes.html#calibration-of-absolute-devices
2019-07-05 18:41:56 +03:00
Brian Ashworth d0d01810f3 cmd_mode: allow runtime creation and modification
This allows for modes to be created, bindings to be added to modes, and
bindings to be removed from modes at runtime. Additionally, this also
allows for `mode <mode>` to be deferred in the config to set an initial
mode.
2019-06-20 10:14:19 -04:00
Brian Ashworth fc3253cc35 cmd_seat: split action and config handlers
This separates the logic for seat subcommand handlers that only perform
actions on the seat and handlers that alter the seat config. The former
group can immediately free the seat config after running the command as
it is only used by the subcommand to find the name of the seat to
operate on. The latter group alters the seat config so it will need to
go through the storage and application stage (assuming success).
2019-06-20 10:15:09 +03:00
Brian Ashworth 5069b53d6c config/xwayland: retain xwayland status on reload
Since xwayland can only be enabled/disabled at launch, the xwayland
status should be retained on reload. Having `xwayland enabled|disabled`
in the config, should not cause `config->xwayland` to be invalid on
reload. This also returns `CMD_FAILURE` with a message that xwayland
can only be enabled/disabled on launch when trying to set the invalid
status on reload. This allows swaynag to notify the user that the
change will not take effect until sway is restarted.
2019-06-19 07:40:52 +03:00
Rouven Czerwinski ddad41f423 Fix sway crashes for scratchpad layouts
Currently container_replace removes the container from the scratchpad
and re-adds it afterwards. For the split commands this results in the
container being send to the scratchpad, which results in a NULL segfault
if the same container should be shown.
Pass an optional workspace to root_scratchpad_add_container, if the
workspace is passed the window will continue to show on the workspace.
If NULL is passed it is sent to the scratchpad.
This was an issue if no other window except the scratchpad container was
on the workspace.

Fixes #4240
2019-06-16 12:29:16 -04:00
Brian Ashworth 9670ccee68 bindings: defer while initiailizing
This adds the logic to defer binding execution while sway is still
initializing. Without this, the binding command would be executed, but
the command handler would return CMD_DEFER, which was being treated as
a failure to run. To avoid partial executions, this will defer all
bindings while config->active is false.
2019-06-12 07:56:41 +03:00
Simon Ser 2bccb387d8 Add a new xkb_switch_layout command
This allows users to programatically change the active layout.
2019-06-09 15:20:14 -04:00
Brian Ashworth 5b1a8d62b9 config/input: validate xkb keymap before storing
This allows for an optional validation stage when storing an input
config. Currently, only the xkb keymap is validated. If storing the
delta input config will result in any invalid xkb keymaps, the input
config will not be stored and error will be populated with the first
line of the xkbcommon log.
2019-06-09 20:13:22 +03:00
Brian Ashworth be2d2a299a commands/input: perform basic keymap validation
Before the delta input config is stored, this attempts to compile a
keymap with it. If the keymap fails to compile, then the first line of
the xkbcommon log entry will be included with a `CMD_FAILURE`, the
entire xkbcommon log entry will be included in the sway error log, and
the delta will not be stored.

This only handles basic issues such as a layouts not existing. This
will NOT catch more complex issues such as when a variant does
exist, but not for the given layout (ex: `azerty` is a valid variant,
but the `us` layout does not have a `azerty` variant).
2019-06-09 20:13:22 +03:00
Daniel Eklöf 190546fd31 add seat sub command 'xcursor_theme'
New 'seat <name> xcursor_theme <theme> [<size>]' command that
configures the default xcursor theme.

The default seat's xcursor theme is also propagated to XWayland, and
exported through the XCURSOR_THEME and XCURSOR_SIZE environment
variables. This is done every time the default seat's configuration is
changed.
2019-06-05 11:00:10 -04:00
Brian Ashworth 799f5a2cd5 cmd_hide_edge_borders: add missing arg count check
This adds the missing argument count check after the --i3 flag
processing in cmd_hide_edge_borders. Without the check,
`hide_edge_borders --i3` would result in a SIGSEGV instead of a syntax
error. There are some minor adjustments to make it so nothing gets
altered if this check fails
2019-06-04 08:47:36 +03:00
Brian Ashworth 6afb392823 bindings: allow unlocked and locked bindings
This changes the behavior of bindings to make the `BINDING_LOCKED` flag
conflicting, which will allow for both unlocked and locked bindings.

If there are two matching bindings and one has `--locked` and the other
does not, the one with `--locked` will be preferred when locked and
the one without will be preferred when unlocked.

If there are two matching bindings and one has both a matching
`--input-device=<input>` and `--locked` and the other has neither, the
former will be preferred for both unlocked and locked.

This also refactors `get_active_binding` in `sway/input/keyboard.c`
to make it easier to read.
2019-05-30 10:47:42 +03:00
Brian Ashworth 00cffb8e20 commands/bar: fix mode and hidden_state at runtime
For compatibility with i3, `bar mode` and `bar hidden_state` do not
require bar-ids (in the normal location) at runtime since they follow
the alternative syntax: `bar mode|hidden_state <option> [<bar-id>]`

This removes the incorrect error that the bar-id is missing for those
two bar subcommands
2019-05-22 22:33:10 +03:00
Alyssa Ross e4f1ffe601 commands/bar: improve error for invalid subcommand
Running a command like this produced a confusing error message:

    $ swaymsg bar bar-0 colors background #ff0000
    Error: Unknown/invalid command 'bar-0'

This patch makes the error message use argv[1] instead of argv[0] (from
config_subcommand's implementation), so it actually uses the name of the
command, rather than the id of the bar.
2019-05-19 11:47:16 -04:00
Alyssa Ross 5fb5984e94 bar: fix segfault with missing or invalid bar id
Prior to this patch, if I ran something like this, sway would crash:

    swaymsg bar height 50

or

    swaymsg bar not-a-bar-id color bg #ff0000

This was in contrast to other bar subcommands, like status_command,
which would exit with a "No bar defined" message.

The difference between the subcommands that crashed and the ones that
exited was that some subcommands had a check to see if a bar was
specified, while others just assumed that it had been and carried on
until they segfaulted.

Because this check was identical in every subcommand it was present in,
and I couldn't think of a case where it would be valid to run a bar
subcommand without specifying which bar to apply it to, I moved this
check from individual subcommands into the bar command, which is already
responsible for actually setting the specified bar. This reduced code
duplication, and fixed the crash for the subcommands that were missing
this check.
2019-05-17 15:33:57 -04:00
Moelf ed2e553b8d Implement output toggle
discussed in #4136, this can't handle wildcard but won't crash.
2019-05-14 00:11:04 -04:00
Brian Ashworth 13cbb3b7fc cmd_move: add support for output current
This adds support for the following commands for i3 compatibility:
- `move [window|container] [to] output current`
- `move workspace to [output] current`
- `move workspace [to] output current`

The above commands are only useful when used with criteria.
2019-04-30 15:22:02 -06:00
Konstantin Pospelov ddf63ffabe bindsym: consider xkb_rule_names for --to-code 2019-04-26 20:56:48 +03:00
Konstantin Pospelov 998de8fbc5 bindsym: change default keymap for --to-code
Replace XKB_DEFAULT_LAYOUT with NULL as the default layout.
2019-04-26 20:56:48 +03:00
Konstantin Pospelov f1609abe4c config: simplify keysym translation fields
Do not store `xkb_keymap` since it can be retrieved from `xkb_state`.
2019-04-26 20:56:48 +03:00
Konstantin Pospelov a09c144b8b Implement bindsym --to-code
* `bindsym --to-code` enables keysym to keycode translation.
* If there are no `xkb_layout` commands in the config file, the translation
uses the XKB_DEFAULT_LAYOUT value.
* It there is one or more `xkb_layout` command, the translation uses
the first one.
* If the translation is unsuccessful, a message is logged and the binding
is stored as BINDING_KEYSYM.
* The binding keysyms are stored and re-translated when a change in the input
configuration may affect the translated bindings.
2019-04-26 20:56:48 +03:00
Brian Ashworth 09595da0bc cmd_move: allow for all i3 syntax options
This modifies cmd_move to allow for the syntax options allowed by i3.
The following syntaxes are supported:
- `move left|right|up|down [<amount> [px]]`
- `move [--no-auto-back-and-forth] [window|container] [to] workspace
   <name>|next|prev|next_on_output|prev_on_output|current|number <num>`
- `move [window|container] [to] output <name/id>|left|right|up|down`
- `move [window|container] [to] mark <mark>`
- `move workspace to [output] <name/id>|left|right|up|down`
- `move [window|container] [to] [absolute] position <x> [px] <y> [px]`
- `move [window|container] [to] [absolute] position center`
- `move [window|container] [to] position mouse|cursor|pointer`

This also allows retains the following syntax option that is not
supported by i3, but is supported in sway 1.0:
- `move workspace [to] output <name/id>|left|right|up|down`

The changes are:
- `window` and `container` are now optional
- `output` is now optional for `move workspace` when `to` is given

There is also stricter command checking now. If `absolute` or
`--no-auto-back-and-forth` are given for commands that do not support
them, it will be treated as invalid syntax instead of being silently
ignored.
2019-04-19 08:39:57 -06:00
mwenzkowski 5e925f06e0 hide_edge_borders.c: add missing case for --i3
Disable the i3-compatible behavior if the option '--i3' is not given.
Previously it was only possible to disable it by changing the config
file. Now it also works via swaymsg.
2019-04-19 00:05:49 +03:00
Alex Maese 35ddd9aab3 Add unbindsym/unbindcode command for swaybar 2019-04-17 23:29:43 -04:00
Alex Maese 8d4f8aea46 Add unbindswitch command 2019-04-17 23:29:43 -04:00
Alex Maese 852f1f0b34 Create unbindsym and unbindcode commands 2019-04-17 23:29:43 -04:00
Connor E b2cfcebef6 Add deprecation warnings for new_float, new_window, and force_focus_wrapping. 2019-04-14 20:44:12 -04:00
Brian Ashworth 69a1a0ff99 Fix scratchpad fullscreen behavior and crash
When setting fullscreen on a hidden scratchpad container, there was a
check to see if there was an existing fullscreen container on the
workspace so it could be fullscreen disabled first. Since the workspace
is NULL, it would cause a SIGSEGV. This adds a NULL check to avoid the
crash.

This also changes the behavior of how fullscreen is handled when adding
a container to the scratchpad or changing visibility of a scratchpad
container to match i3's. The behavior is as follows:
- When adding a container to the scratchpad or hiding a container back
  into the scratchpad, there is an implicit fullscreen disable
- When setting fullscreen on a container that is hidden in the
  scratchpad, it will be fullscreen when shown (and fullscreen disabled
  when hidden as stated above)
- When setting fullscreen global on a container that is hidden in the
  scratchpad, it will be shown immediately as fullscreen global. The
  container is not moved to a workspace and remains in the
  scratchpad. The container will be visible until fullscreen disabled
  or killed. Since the container is in the scratchpad, running
  `scratchpad show` or `move container to scratchpad` will have no
  effect

This also changes `container_replace` to transfer fullscreen and
scratchpad status.
2019-04-13 08:48:37 -06:00
Ashkan Kiani 913445e112 Fix potential null accesses 2019-04-13 08:35:17 -06:00
Brian Ashworth bd4c3957ba cmd_focus: raise floating for <criteria> focus
Floaters are currently raised for `focus <direction>`. This extends the
same functionality to `<criteria> focus`.
2019-04-11 09:19:45 -06:00
Brian Ashworth 75e7bd24cc swaybg: one instance for all outputs
This makes it so there will only be one swaybg instance running
instead of one per output. swaybg's cli has been changed to a xrandr
like interface, where you select an output and then change properties
for that output and then select another output and repeat. This also
makes it so swaybg is only killed and respawned when a background
changes or when reloading.
2019-04-04 20:08:21 +03:00
Jan Pokorný bfdee1319f bindings: fix overwrite log argument mismatch
Thanks, @RedSoxFan, for the review spotting another instance.
2019-03-27 12:07:52 -04:00
Ashkan Kiani 3a31889d7c Fix crash for floating command on scratchpad window 2019-03-26 23:38:23 -04:00
Brian Ashworth d9de5b8758 Implement inhibit_idle command
This implements the following command to set/unset a user idle
inhibitor for a view:
`inhibit_idle focus|fullscreen|open|none|visible`

The modes are as follows:
- focus: inhibited when the view is focused by any seat
- fullscreen: inhibited when the view is fullscreen (or a descendant of
  a fullscreen container) and is visible on any output
- open: inhibited until the view is closed or the inhibitor is unset or
  changed
- none: unsets any user set idle inhibitors for the view
- visible: inhibited when the view is visible on any output

This should have no effect on idle inhibitors set by the applications
themselves and those should still work as intended.

Since this operates on the view in the handler context, it is possible
to set it on the currently focused view, on any existing view with
criteria, or for any future view with for_window.
2019-03-24 19:26:12 -06:00
Geoff Greer 6e3046878d Add support for manually setting subpixel hinting on outputs.
Many laptop screens report unknown subpixel order. Allow users to manually set subpixel hinting to work around this.

Addresses https://github.com/swaywm/sway/issues/3163
2019-03-24 09:37:24 +02:00
mliszcz 200833caae Allow for workspace renaming during exec handling
This change adds support for renaming a workspace when `exec` command
is being processed by keeping sway_workspace and pid_workspace names in
sync.

The change can be verified by running following command:

swaymsg exec <application>; swaymsg rename workspace number 1 to 5

Fixes: #3952
2019-03-23 17:49:27 -04:00
Brian Ashworth 8cd7f0171a cmd_mode: allow cmd_set to be a subcommand
This allows set to be used in mode blocks
2019-03-23 08:07:25 +02:00
Ryan Dwyer cdcc2a5bb5 Support focus <direction> for floating containers
This kind of worked before in that focus would change, but it wasn't
intentionally supported and had side effects such as not raising
the container, and being unable to cycle through all floaters depending
on the direction used.

This commit makes it properly supported. The new focus is chosen based
on the distance to the center point of each floating container in the
workspace, and the container is raised.

In a multi output setup, if both visible workspaces have floating
containers, focus will NOT cross into the other output. It is assumed
the user will use a workspace binding in this case.

If two floating containers occupy the exact same center point and you
try to focus in a direction, the behaviour is undefined.
2019-03-20 08:55:28 -06:00
Ryan Walklin bdb402404c Support WLR_INPUT_DEVICE_SWITCH in sway
This commit adds support for laptop lid and tablet
mode switches as provided by evdev/libinput and
handled by wlroots.

Adds a new bindswitch command with syntax:
bindswitch <switch>:<state> <command>

Where <switch> is one of:
tablet for WLR_SWITCH_TYPE_TABLET_MODE
lid for WLR_SWITCH_TYPE_LID

<state> is one of:
on for WLR_SWITCH_STATE_ON
off for WLR_SWITCH_STATE_OFF
toggle for WLR_SWITCH_STATE_TOGGLE

(Note that WLR_SWITCH_STATE_TOGGLE doesn't map to
libinput and will trigger at both on and off events)
2019-03-19 23:58:47 -04:00
Brian Ashworth e687e120e0 output_cmd_background: validate colors
This validates the color and fallback color in `output_cmd_background`
to ensure that only colors of the form `#RRGGBB` are accepted.
2019-03-15 09:50:10 +02:00
Brian Ashworth 3330faded5 Handle seat_get_focused_workspace returning NULL
This modifiers the callers of seat_get_focused_workspace to handle
getting NULL as the return value, if they did not already.
2019-03-12 19:14:04 +01:00
Ian Fan 055d662baa commands: allow tiled sticky containers to be moved
Namely, to a workspace on the same output.
However, tiled sticky children of floating containers are still restricted.
2019-03-11 21:49:37 -04:00
emersion 191305468c Fix crash in cmd_workspace when layer surface has focus 2019-03-10 14:59:34 -06:00