Commit graph

539 commits

Author SHA1 Message Date
M Stoeckl 2a684cad5f Remove now-unused "input" argument of cmd_results_new
Patch tested by compiling with `__attribute__ ((format (printf, 2, 3)))`
applied to `cmd_results_new`.

String usage constants have been converted from pointers to arrays when
encountered. General handler format strings were sometimes modified to
include the old input string, especially for unknown command errors.
2019-01-14 08:05:29 -05:00
M Stoeckl 6d392150a7 Remove 'input' field of IPC command return json
This field is not in i3 and provides imprecise and redundant information.
(Specifically, when swaymsg is given a list of commands, the IPC return
array already indicates precisely which number command failed; knowing
the name of the command is not useful when multiple commands of the
same type are provided.)
2019-01-14 07:58:02 -05:00
Drew DeVault 4879d40695
Merge pull request #3144 from emersion/cmd-xwayland
Add xwayland command
2019-01-13 20:42:39 -05:00
emersion 140bc2dd5b
Merge pull request #3275 from ianyfan/remove-readline
Rewrite strip_whitespace and remove readline.c
2019-01-08 10:05:37 +01:00
Brian Ashworth 5bf4daf263 Implement tiling_drag_threshold
Implements `tiling_drag_threshold <threshold>` to prevent accidental
dragging of tiling containers. If a container (and all of its
descendants) are unfocused and the tile bar is pressed, a threshold
will be used before actually starting the drag. Once the threshold has
been exceeded, the cursor will change to the grab icon and the operation
will switch from `OP_MOVE_TILING_THRESHOLD` to `OP_MOVE_TILING`.
2019-01-02 23:33:33 +01:00
Ian Fan 967566e37f stringop.c: rewrite strip_whitespace 2019-01-01 09:01:24 +00:00
Brian Ashworth 4d88c95790 hide_cursor: change to a seat subcommand
This makes hide_cursor a seat subcommand, which allows for seat specific
timeouts.
2018-12-30 14:17:24 +01:00
Brian Ashworth 3e8f548d1d Revamp seat configs
This makes seat configs work like output and input configs do. This also
adds support for wildcard seat configs. A seat config is still created
in the main seat command handler, but instead of creating a new one in
the subcommands and destroying the main seat command's instance, the
seat subcommands modify the main one. The seat config is then stored,
where it is merged appropriately. The seat config returned from
`store_seat_config` is then applied. When attempting to apply a wildcard
seat config, a seat specific config is queried for and if found, that is
used. Otherwise, the wildcard config is applied directly.

Additionally, instead of adding input devices to the default seat
directly when there is no seat configs, a seat config for the default
seat is created with only fallback set to true, which is more explicit.
It also fixes an issue where running a seat command at runtime (with no
seat config in the sway config), would result in all input devices being
removed from the default seat and leaving sway in an unusable state.

Also, instead of checking for any seat config, the search is for a seat
config with a fallback option seat. This makes it so if there are only
seat configs with fallback set to -1, the default seat is still created
since there is no explicit notion on what to do regarding fallbacks.
However, if there is even a single fallback 0, then the default seat is
not used as a fallback. This will be needed for seat subcommands like
hide_cursor where the user may only want to set that property without
effecting anything else.
2018-12-29 19:40:40 +01:00
Brian Ashworth 5fca74a1f1 Implement hide_cursor <timeout> command
Allows the cursor to be hidden after a specified timeout in
milliseconds
2018-12-25 13:31:56 +01:00
Ian Fan c8776fac42 Cleanup list code 2018-12-09 01:15:38 +00:00
mwenzkowski cf6edaf26a Fix command list execution
Determine the container/workspace a command is run on, each time when a
command of the command list will be run.
Previously the container/workspace was determined only once at the
beginning of command list execution, which led to wrong behaviour
because commands wouldn't take into account when a previous command
changed the focused container.
2018-12-05 11:32:23 +01:00
emersion 048b96a56d
Merge pull request #3204 from RedSoxFan/cmd-res-list
Change execute_command to return a list of results
2018-11-28 09:26:47 +01:00
Brian Ashworth 315bca176c Do not strip quotes for cmd_mode
Like with cmd_bindsym and cmd_bindcode, the quotes should not be
stripped for cmd_mode. cmd_mode performs its own stripping for the mode
name and the only valid subcommands are cmd_bindsym and cmd_bindcode.
2018-11-28 01:28:03 -05:00
Brian Ashworth 5c6f3d7266 Change execute_command to return a list of results
This matches i3's behavior of returning a list of results that contain
the result of each command that was executed. Additionally, the
`parse_error` attribute has been added to the IPC JSON reply.
2018-11-27 21:42:09 -05:00
Brian Ashworth e6562c8cd2 Implement title alignment
This adds support for `i3 4.16`'s ability to set the title alignment.
The command is `title_align left|center|right`.

When the title is on the right, marks are moved to the left. Otherwise,
they are on the right.
2018-11-25 22:08:58 -05:00
Florent de Lamotte 7555c7efdc Adding commands for configuring titlebar borders and padding 2018-11-22 10:30:04 +01:00
emersion 311c7db7e3
Add xwayland command 2018-11-19 17:38:37 +01:00
Brian Ashworth b277000601 Alter config variable replacement process
Currently, variables cannot contain commands and cannot span more than
one argument. This is due to variable replacement happening after
determining the handler and after splitting the config line into
arguments.

This changes the process to:
0. Check for empty lines and block boundaries
1. Split the arguments as before
2. Verify that the first argument is not a variable. If needed the
following occurs
    a. Perform variable replacement on just the first argument
    b. Join the arguments back together then split the arguments again. This is needed when the variable
contains the command and arguments for the command.
3. Determine the handler
4. If the handler is cmd_set, escape the variable name so that it does
not get replaced
5. Join the arguments back together, do variable replacement on the full
command, and split the arguments again
6. Perform any needed quote stripping or unescaping on arguments
7. Run the command handler

This allows for config snippets such as:

```
set $super bindsym Mod4
$super+a exec some-command
```

and

```
set $bg bg #ffffff solid_color
output * $bg
```
2018-11-10 21:53:10 -05:00
Ian Fan 9227cb7d67 commands: replace EXPECTED_LESS_THAN with EXPECTED_AT_MOST
This makes it a bit more obvious what the expected number of arguments is.
2018-10-23 10:51:54 +01:00
Ian Fan 000d96e525 commands: clean-up checkarg function
Consolidates logic and fixes mistake that used argc instead of val for
determining plural.
2018-10-23 10:51:08 +01:00
Ian Fan 5364255f26 commands: remove EXPECTED_MORE_THAN
Its uses have been replaced with EXPECTED_AT_LEAST.
2018-10-23 10:17:58 +01:00
Ryan Dwyer b9b1b0e566 Remove raise_floating directive
The directive controlled whether floating views should raise to the top
when the cursor is moved over it while using focus_follows_mouse. The
default was enabled, which is undesirable. For example, if you have two
floating views where one completely covers the other, the smaller one
would be inaccessible because moving the mouse over the bigger one would
raise it above the smaller one.

There is no known use case for having raise_floating enabled, so this
patch removes the directive and implements the raise_floating disabled
behaviour instead.
2018-10-20 17:51:32 +10:00
Ryan Dwyer c006717910 Minor refactor of input manager
The input manager is a singleton object. Passing the sway_input_manager
argument to each of its functions is unnecessary, while removing the
argument makes it obvious to the caller that it's a singleton. This
patch removes the argument and makes the input manager use server.input
instead.

On a similar note:

* sway_input_manager.server is removed in favour of using the server
global.
* seat.input is removed because it can get it from server.input.

Due to a circular dependency, creating seat0 is now done directly in
server_init rather than in input_manager_create. This is because
creating seats must be done after server.input is set.

Lastly, it now stores the default seat name using a constant and removes
a second reference to seat0 (in input_manager_get_default_seat).
2018-10-20 13:11:43 +10:00
Ryan Dwyer 832ebc8966 Implement popup_during_fullscreen
This introduces a new view_impl function: is_transient_for. Similar to
container_has_ancestor but works using the surface parents rather than
the tree.

This patch modifies view_is_visible, container_at and so on to allow
transient views to function normally when they're in front of a
fullscreen view.
2018-10-08 22:49:59 +10:00
Drew DeVault 92e1fc00fd Shim client.background and client.placeholder
These are not supported by sway, but are valid i3 commands and should not
cause config errors.

Also includes a couple of minor touch-ups.
2018-10-07 14:44:37 -04:00
Jonathan Buch 298ccb539c
Add configuration for raising containers on focus
* New configuration option: raise_floating
  (From the discussion on https://github.com/i3/i3/issues/2990)
* By default, it still raises the window on focus, otherwise it
  will raise the window on click.
2018-10-03 16:23:12 +02:00
Brian Ashworth bb25194844 Handle border options for gaps
Fixes `hide_edge_borders smart` when gaps are in use.
Implements `hide_edge_borders smart_no_gaps` and `smart_borders
on|no_gaps|off`.

Since `smart_borders on` is equivalent to `hide_edge_borders smart`
and `smart_borders no_gaps` is equivalent to `hide_edge_borders
smart_no_gaps`, I opted to just save the last value set for
`hide_edge_borders` and restore that on `smart_borders off`. This
simplifies the conditions for setting the border.
2018-10-01 21:19:06 -04:00
Brian Ashworth a125575eb5 Do not strip quotes for cmd_set 2018-09-30 12:35:45 -04:00
Brian Ashworth 87a70b3591 Do not strip quotes for exec or bind commands
Leave quotes intact for cmd_exec, cmd_exec_always, cmd_bindcode,
and cmd_bindsym
2018-09-30 10:39:29 -04:00
Brian Ashworth 0a0cf4540a Fix quote handling for commands
Quotes are now stripped for all arguments and stripped before anything is unescaped
2018-09-28 23:12:24 -04:00
Brian Ashworth baeb28ea62 Implement support for input wildcard 2018-09-23 19:56:52 -04:00
Ryan Dwyer cb66bbea42 Allow running commands on containers without focusing them
This adds a `con` argument to `execute_command` which allows you to
specify the container to execute the command on. In most cases it leaves
it as `NULL` which makes it use the focused node. We only set it when
executing `for_window` criteria such as when a view maps. This means we
don't send unnecessary IPC focus events, and fixes a crash when the
criteria command is `move scratchpad` (because we can't give focus to a
hidden scratchpad container).

Each of the shell map handlers now check to see if the view has a
workspace. It won't have a workspace if criteria has moved it to the
scratchpad.
2018-09-23 08:39:11 +10:00
emersion fa4308c5ab
Merge pull request #2671 from emersion/output-execute-no-focus
Fix segfault when executing command without focus
2018-09-20 18:36:47 +02:00
emersion efc08ec888 Fix segfault when executing command without focus 2018-09-19 15:50:42 +02:00
Ryan Dwyer db28459634 Introduce create_output command (for developer use)
Should help with testing hotplugging.
2018-09-19 21:54:27 +10:00
Ryan Dwyer ec9c4de564 Introduce tiling_drag directive 2018-09-11 17:17:19 +10:00
Ryan Dwyer 7586f150c0 Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers
to layout containers and view containers. Workspaces, outputs and the
root are no longer known as containers. Instead, root, outputs,
workspaces and containers are all a type of node, and containers come in
two types: layout containers and view containers.

In addition to the above, this implements type safe variables. This
means we use specific types such as sway_output and sway_workspace
instead of generic containers or nodes. However, it's worth noting that
in a few places places (eg. seat focus and transactions) referring to
them in a generic way is unavoidable which is why we still use nodes in
some places.

If you want a TL;DR, look at node.h, as well as the struct definitions
for root, output, workspace and container. Note that sway_output now
contains a workspaces list, and workspaces now contain a tiling and
floating list, and containers now contain a pointer back to the
workspace.

There are now functions for seat_get_focused_workspace and
seat_get_focused_container. The latter will return NULL if a workspace
itself is focused. Most other seat functions like seat_get_focus and
seat_set_focus now accept and return nodes.

In the config->handler_context struct, current_container has been
replaced with three pointers: node, container and workspace. node is the
same as what current_container was, while workspace is the workspace
that the node resides on and container is the actual container, which
may be NULL if a workspace itself is focused.

The global root_container variable has been replaced with one simply
called root, which is a pointer to the sway_root instance.

The way outputs are created, enabled, disabled and destroyed has
changed. Previously we'd wrap the sway_output in a container when it is
enabled, but as we don't have containers any more it needs a different
approach. The output_create and output_destroy functions previously
created/destroyed the container, but now they create/destroy the
sway_output. There is a new function output_disable to disable an output
without destroying it.

Containers have a new view property. If this is populated then the
container is a view container, otherwise it's a layout container. Like
before, this property is immutable for the life of the container.

Containers have both a `sway_container *parent` and
`sway_workspace *workspace`. As we use specific types now, parent cannot
point to a workspace so it'll be NULL for containers which are direct
children of the workspace. The workspace property is set for all
containers, except those which are hidden in the scratchpad as they have
no workspace.

In some cases we need to refer to workspaces in a container-like way.
For example, workspaces have layout and children, but when using
specific types this makes it difficult. Likewise, it's difficult for a
container to get its parent's layout when the parent could be another
container or a workspace. To make it easier, some helper functions have
been created: container_parent_layout and container_get_siblings.

container_remove_child has been renamed to container_detach and
container_replace_child has been renamed to container_replace.

`container_handle_fullscreen_reparent(con, old_parent)` has had the
old_parent removed. We now unfullscreen the workspace when detaching the
container, so this function is simplified and only needs one argument
now.

container_notify_subtree_changed has been renamed to
container_update_representation. This is more descriptive of its
purpose. I also wanted to be able to call it with whatever container was
changed rather than the container's parent, which makes bubbling up to
the workspace easier.

There are now state structs per node thing. ie. sway_output_state,
sway_workspace_state and sway_container_state.

The focus, move and layout commands have been completely refactored to
work with the specific types. I considered making these a separate PR,
but I'd be backporting my changes only to replace them again, and it's
easier just to test everything at once.
2018-09-05 18:01:43 +10:00
sghctoma 073dcb3a86 Change _XOPEN_SOURCE defines to _POSIX_C_SOURCE 2018-09-03 09:08:49 +02:00
sghctoma df730a8891 Merge remote-tracking branch 'upstream/master' into fix-freebsd-build 2018-09-03 08:57:17 +02:00
Ryan Dwyer f057a0195e Implement focus_on_window_activation
Depends on https://github.com/swaywm/wlroots/pull/1223
2018-09-02 18:20:34 +10:00
Ryan Dwyer 016d0455f8 Implement deprecated new_window and new_float commands
May as well make it as easy as possible for users who are coming from
i3.

This also changes the `border` command to accept a thickness when
setting the border to normal. This makes it work the same way as the
`default_border` command. Eg. `border normal 5`
2018-09-01 21:28:13 +10:00
sghctoma cc16948c85 Fix feature macros for FreeBSD
On FreeBSD, snprintf and vsnprintf are visible only if
_XOPEN_SOURCE >= 600.
2018-08-30 09:34:26 +02:00
Ian Fan c1af79532f commands: add nop 2018-08-18 15:50:26 +01:00
Brian Ashworth a7f7d4a488 Write to swaynag pipe fd directly on config errors 2018-08-03 10:37:35 -04:00
Brian Ashworth f9a6407111 Show swaynag on config errors 2018-08-03 10:37:35 -04:00
Ryan Dwyer 81e8f31cc6 Implement scratchpad
Implements the following commands:

* move scratchpad
* scratchpad show
* [criteria] scratchpad show

Also fixes these:

* Fix memory leak when executing command with criteria
(use `list_free(views)` instead of `free(views)`)
* Fix crash when running `move to` with no further arguments
2018-07-23 08:24:32 +10:00
Ryan Dwyer 9fbe13b9be Implement floating_modifier and mouse operations for floating views
This implements the following:

* `floating_modifier` configuration directive
* Drag a floating window by its title bar
* Hold mod + drag a floating window from anywhere
* Resize a floating view by dragging the border
* Resize a floating view by holding mod and right clicking anywhere on
the view
* Resize a floating view and keep aspect ratio by holding shift while
resizing using either method
* Mouse cursor turns into resize when hovering floating border or corner
2018-07-22 23:10:19 +10:00
Ryan Dwyer c2ed3d8bd6 Implement force_display_urgency_hint
The directive sets the timeout before an urgent view becomes normal
again after switching to it from another workspace.

Also:

* When an xwayland surface removes the urgent hint while the timer is
active, we now ignore the request. This happens as soon as the view
receives focus, so it was effectively making the timer pointless.
* The timeout is now only applied when switching to it from another
workspace.
2018-07-21 10:28:07 +10:00
Ryan Dwyer 08736255a3 Defer the focus commands 2018-07-19 16:41:02 +10:00
Ryan Dwyer 75c699db62 Implement default_floating_border command and adjust CSD behaviour 2018-07-17 10:14:33 +10:00