Commit Graph

605 Commits

Author SHA1 Message Date
Ryan Dwyer 9ea71f292b Introduce cursor_rebase
This function "rebases" the cursor on top of whatever is underneath it,
without triggering any focus changes.
2018-10-19 22:47:54 +10:00
Drew DeVault 96e3686ae8
Merge pull request #2875 from RedSoxFan/input-device-bindings
cmd_bind{sym,code}: Implement per-device bindings
2018-10-19 14:00:03 +02:00
Ryan Dwyer a2fdac2c4b Consider cursor warp when switching workspaces
Fixes a regression introduced in
24a90e5d86.

consider_warp_to_focus has been renamed to seat_consider_warp_to_focus,
moved to seat.c and made public. It is now called when switching
workspaces via `workspace <ws>`.
2018-10-19 08:00:13 +10:00
Brian Ashworth 2e637b7368 cmd_bind{sym,code}: Implement per-device bindings
bindsym --input-device=<identifier> ...
bindcode --input-device=<identifier> ...
2018-10-18 13:42:01 -04:00
Ryan Dwyer 24a90e5d86 Remove cursor warping from seat_set_focus
Because cursor warping was the default behaviour in seat_set_focus,
there may be cases where we may have been warping the cursor
unintentionally. This patch removes cursor warping from seat_set_focus
and only does it in the focus command. This is managed by a static
function in focus.c.

To know whether to warp or not, we need to know which node had focus
previously. To keep track of this easily, seat->prev_focus has been
introduced and is set to the previous in seat_set_focus.
2018-10-18 23:08:45 +10:00
Drew DeVault 10d07478ad
Merge pull request #2858 from RyanDwyer/fix-move-to-floating-ws
Fix moving tiled containers to workspaces which only have floating views
2018-10-17 16:16:12 +02:00
Ryan Dwyer 17014c34e2 Fix crashes when running certain commands on an empty workspace
This fixes crashes when running the border, mark, unmark and
title_format commands on an empty workspace.
2018-10-17 19:55:00 +10:00
Ryan Dwyer 799f285cd1 Fix moving tiled containers to workspaces which only have floating views
* Make a workspace which only contains floating views
* Switch to another workspace and create a tiled view
* Move the tiled view to the workspace with
`move container to workspace N`

The container would be added as a sibling to the floating view, which
makes the container floating while having the geometry of a tiled
container.

This changes it so it only looks for tiled containers in the workspace
with a fallback to the workspace itself.
2018-10-17 16:57:32 +10:00
Ryan Dwyer d0974d5c50 Fix crash when using workspace back_and_forth with no previous 2018-10-16 23:42:53 +10:00
Ian Fan ac20690945
Merge branch 'master' into set-set-raw-focus 2018-10-16 10:50:56 +01:00
Ryan Dwyer 05284b65db Prevent duplicate workspace::focus events
Previously we would compare the last focus's workspace with the new
focus's workspace to determine if we need to emit an IPC
workspace::focus event. This doesn't work when moving the focused
container to a new workspace.

This adds a workspace property to the seat which stores the last emitted
workspace::focus workspace. Using this method, after moving the
container, refocusing it will trigger exactly one workspace::focus
event: from the old workspace to the new workspace.
2018-10-16 08:17:24 +10:00
Ryan Dwyer 26278b694c Introduce seat_set_raw_focus and remove notify argument from seat_set_focus_warp
This introduces seat_set_raw_focus: a function that manipulates the
focus stack without doing any other behaviour whatsoever. There are a
few places where this is useful, such as where we set focus_inactive
followed by another call to set the real focus again. With this change,
the notify argument to seat_set_focus_warp is also removed as these
cases now use the raw function instead.

A bonus of this is we are no longer emitting window::focus IPC events
when setting focus_inactive, nor are we sending focus/unfocus events to
the surface.

This also fixes the following:

* When running `move workspace to output <name>` and moving the last
workspace from the source output, the workspace::focus IPC event is no
longer emitted for the newly created workspace.
* When splitting the currently focused container, unfocus/focus events
will not be sent to the surface when giving focus_inactive to the newly
created parent, and window::focus events will not be emitted.
2018-10-15 21:06:24 +10:00
Ryan Dwyer fe803b89a7 Fix crash in swap command
When swapping containers that are in the root of the workspace, parent
will be NULL.
2018-10-15 19:40:40 +10:00
Drew DeVault 7f2e6d812a Document `border csd` 2018-10-14 10:23:40 -04:00
Ian Fan 1f90f92f45 commands: fix sending bar mode/hidden_state updates to all bars
Previously, if a change was sent to all bars, it would only actually
change the first bar it encountered, due to return value handling
2018-10-14 13:33:12 +01:00
Drew DeVault abde9d6627
Merge pull request #2808 from RedSoxFan/bar-subcommands
Fix bar subcommand handler structs and selection
2018-10-14 14:30:52 +02:00
Brian Ashworth 2a0c7ebd43 cmd_bar: simplify logic 2018-10-13 17:56:11 -04:00
Brian Ashworth 84b28dc593 cmd_bar: fix bar id issues
Allows bar-subcommand to be a valid bar-ids
Destroys runtime created bar if trying to use a config only subcommand
Allow subcommands (except for id) to be ids
2018-10-13 17:55:49 -04:00
Tarmack 36d9037f2c fix_edge_gaps: Allow negative values for outer gaps.
While allowing negative values for the outer gaps it is still prevented that negative values move windows out of the container. This replaces the non-i3 option for edge_gaps.
2018-10-13 17:42:49 +02:00
Brian Ashworth 2340b14eba bar_cmd_status_command: only reload current bar
Ideally, this will be replaced with an IPC barconfig_update event in the
near future
2018-10-13 08:00:01 -04:00
Brian Ashworth 00745d6280 Fix bar subcommand handler structs and selection 2018-10-13 08:00:01 -04:00
meak 9e96ce4a46 fix: cmd_sticky crash sway with empty container 2018-10-11 22:29:41 +02:00
Ian Fan cd6917d4a8
Merge branch 'master' into bar-bindsym 2018-10-10 12:23:04 +00:00
Rouven Czerwinski 41991542ca Add mouse_warping container
This option always moves the cursor into the middle of the container if the warp
variable is true in seat_set_focus_warp.

Fixes #2577
2018-10-10 12:45:21 +02:00
Ryan Dwyer 61699a1146 resize: Determine if anything changed using before/after check
Returning a boolean from container_resize_tiled and resize_tiled doesn't
work in all cases. This patch changes it back to void and does a
before/after check to see if the container was resized.
2018-10-09 22:25:21 +10:00
Brian Ashworth d3f0e52784 bar-bindsym: address ianyfan's comments 2018-10-09 08:12:46 -04:00
Brian Ashworth 1c969e86f5 Implement bar bindsym 2018-10-09 08:12:46 -04:00
Brian Ashworth 3f328b6276
Merge branch 'master' into popup-during-fullscreen 2018-10-08 15:18:49 -04:00
Ian Fan efb123899f commands: when setting urgency, check container is not null 2018-10-08 17:48:25 +01:00
Brian Ashworth 09c3c33081 Allow swaynag to be disabled 2018-10-08 09:59:38 -04:00
emersion 45f2cd0c73
Merge pull request #2793 from emersion/disable-swaybg
Allow swaybg to be disabled
2018-10-08 15:50:56 +02:00
emersion ab3a397d58 Fix memory leak in status_command handler 2018-10-08 15:21:20 +02:00
John Axel Eriksson 08139daaa4
Check if there is a current container before setting it's opacity 2018-10-08 15:17:37 +02:00
emersion c988b03d85 Allow swaybg to be disabled
Same as #2791 but for swaybg.

Fixes #2790
2018-10-08 15:08:33 +02: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
Ryan Dwyer 5e1983660d Allow status_command to be disabled via IPC 2018-10-08 22:23:55 +10:00
Ryan Dwyer e168e8f0ff Don't apply seat config when validating 2018-10-08 21:18:30 +10:00
Ryan Dwyer 82423991a8 Reload config using idle event
This patch makes it so when you run reload, the actual reloading is
deferred to the next time the event loop becomes idle. This avoids
several use-after-frees and removes the workarounds we have to avoid
them.

When you run reload, we validate the config before creating the idle
event. This is so the reload command will still return an error if there
are validation errors. To allow this, load_main_config has been adjusted
so it doesn't apply the config if validating is true rather than
applying it unconditionally.

This also fixes a memory leak in the reload command where if the config
failed to load, the bar_ids list would not be freed.
2018-10-08 19:28:53 +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
Drew DeVault e60ad3f677 Fix some missing commands in sway-input(5) 2018-10-03 07:50:37 -04:00
Drew DeVault 06c214a800
Merge pull request #2703 from RyanDwyer/csd-border
Add CSD to border modes
2018-10-03 13:03:06 +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
Drew DeVault f1dbdce0b2
Merge pull request #2726 from RyanDwyer/overhaul-gaps
Make gaps implementation consistent with i3-gaps
2018-09-30 13:47:35 +02:00
Drew DeVault 8f6aca2166
Merge pull request #2725 from PumbaPe/add-tap-and-drag
Add tap and drag to sway-input
2018-09-30 13:44:11 +02:00
PP ae2b70f59e add tap-and-drag setting to sway-input 2018-09-29 11:49:41 +02:00
emersion 351e722b6e
Merge pull request #2729 from RyanDwyer/resize-return-false
Return an error when resizing is a no op
2018-09-29 11:24:54 +02:00
Ryan Dwyer 42f1fdf015 Return an error when resizing is a no op 2018-09-29 17:05:55 +10:00
Brian Ashworth af45ee2d8b Handle shell special characters in bg file path
This changes it back so the path given to swaybg is enclosed in quotes.

Additionally, the only character that is escaped in the path stored is
double quotes now. This makes it so we don't need to keep an exhaustive
list of characters that need to be escaped.

The end user will still need to escape these characters in their config
or when passed to swaybg.
2018-09-28 23:12:24 -04:00
Ryan Dwyer bb708d0f82 Don't allow negative gaps 2018-09-29 12:58:54 +10:00
Ryan Dwyer 415a48ac63 Make gaps implementation consistent with i3-gaps
This changes our gaps implementation to behave like i3-gaps.

Our previous implementation allowed you to set gaps on a per container
basis. This isn't supported by i3-gaps and doesn't seem to have a
practical use case. The gaps_outer and gaps_inner properties on
containers are now removed as they just read the gaps_inner from the
workspace.

`gaps inner|outer <px>` no longer changes the gaps for all workspaces.
It only sets defaults for new workspaces.

`gaps inner|outer current|workspace|all set|plus|minus <px>` is now
runtime only, and the workspace option is now removed. `current` now
sets gaps for the current workspace as opposed to the current container.

`workspace <ws> gaps inner|outer <px>` is now implemented. This sets
defaults for a workspace.

This also fixes a bug where changing the layout of a split container
from linear to tabbed would cause gaps to not be applied to it until you
switch to another workspace and back.
2018-09-29 11:08:19 +10:00
Ian Fan 98576b9dda swaybar: fix setting binding mode indicator 2018-09-28 13:48:59 +01:00
Ryan Dwyer 138d10d5d6 Rename workspace_outputs to workspace_configs and fix memory leak
When we eventually implement `workspace <ws> gaps inner|outer <px>`,
we'll need to store the gaps settings for workspaces before they're
created. Rather than create a workspace_gaps struct, the approach I'm
taking is to rename workspace_outputs to workspace_configs and then add
gaps settings to that.

I've added a lookup function workspace_find_config. Note that we have a
similar thing for outputs (output_config struct and output_find_config).

Lastly, when freeing config it would create a memory leak by freeing the
list items but not the workspace or output names inside them. This has
been rectified using a free_workspace_config function.
2018-09-28 22:35:38 +10:00
Ryan Dwyer 21ff87d72b Improve CSD logic
This does the following:

* Removes the xdg-decoration surface_commit listener. I was under the
impression the client could ignore the server's preference and set
whatever decoration they like using this protocol, but I don't think
that's right.
* Adds a listener for the xdg-decoration request_mode signal. The
protocol states that the server should respond to this with its
preference. We'll always respond with SSD here.
* Makes it so tiled views which use CSD will still have sway decorations
rendered. To do this, using_csd had to be added back to the view struct,
and the border is changed when floating or unfloating a view.
2018-09-27 22:51:37 +10:00
Ryan Dwyer efcfe57b10 Remove CSD from toggle list if client doesn't support it 2018-09-27 22:51:37 +10:00
Ryan Dwyer 7b138e5ef0 Add CSD to border modes
This replaces view.using_csd with a new border mode: B_CSD. This also
removes sway_xdg_shell{_v6}_view.deco_mode and
view->has_client_side_decorations as we can now get these from the
border.

You can use `border toggle` to cycle through the modes including CSD, or
use `border csd` to set it directly. The client must support the
xdg-decoration protocol, and the only client I know of that does is the
example in wlroots.

If the client switches from SSD to CSD without us expecting it (via the
server-decoration protocol), we stash the previous border type into
view.saved_border so we can restore it if the client returns to SSD. I
haven't found a way to test this though.
2018-09-27 22:51:37 +10:00
Brian Ashworth baeb28ea62 Implement support for input wildcard 2018-09-23 19:56:52 -04:00
Ryan Dwyer 9753e52d6b Flatten container in workspace_rejigger 2018-09-23 14:32:26 +10:00
Ryan Dwyer 0b7fb6943e Fix some bugs as a result of removing move_out_of_tabs_stacks 2018-09-23 13:55:06 +10:00
Ryan Dwyer 93624599b3 Remove move_out_of_tabs_stacks
This fixes the following. Create these layouts and run move right:

(Initial layout -> expected result -> actual result)

* `H[S[unfocused focused] unfocused]` ->
`H[S[unfocused] focused unfocused]` ->
`H[H[S[unfocused] focused] unfocused]`
* `H[S[unfocused focused] V[unfocused]]` ->
`H[S[unfocused] V[unfocused focused]]` ->
`H[H[S[unfocused] focused] V[unfocused]]`

move_out_of_tabs_stacks was originally made to allow views to move out
of the tabbed/stacked container in the parallel direction, but at some
point this has started working using the regular logic.
2018-09-23 13:10:36 +10: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
Marien Zwart 37e51a20cc Fix compilation against wlroots without X11 backend 2018-09-21 21:25:03 +10:00
Ryan Dwyer db28459634 Introduce create_output command (for developer use)
Should help with testing hotplugging.
2018-09-19 21:54:27 +10:00
William Wold f48999dd24 Fix crash moving out of tab container 2018-09-17 01:20:45 -07:00
Ryan Dwyer f6e218a643 Rename seat_get_active_child to seat_get_active_tiling_child
Also renames container to con in one function to prevent ugly line
wrapping.
2018-09-16 22:01:54 +10:00
Brian Ashworth 17fe8924f2 Address ianyfan's comments
wordexp p is now initialized to {0} to prevent a segfault on wordfree
in the failure case.

File paths with single quotes and double quotes are now supported. The
quote can either be wrapped in the other quote or escaped with three
backslashes.

Additionally to make passing file paths with double quotes to swaybg
easier, instead of enclosing the path given to swaybg in quotes, all
spaces, single quotes, and double quotes in the resulting path are now
escaped with a single backslash.
2018-09-14 08:51:01 -04:00
Brian Ashworth 1cf737489d Escape spaces in background file path 2018-09-13 22:21:10 -04:00
Brian Ashworth 0b64cce733 Allow spaces in background file paths 2018-09-13 22:21:10 -04:00
Ryan Dwyer 2f6935e00f Remove bad assertion in workspace_rejigger
The assertion can be (rightfully) triggered by creating layout
V[H[view view] view] and moving the top right view to the right.

After removing the assertion I found the container being moved needs its
size reset to prevent it from being sized wrongly after arranging.
2018-09-13 17:02:10 +10:00
emersion af9e8f94cc
Merge pull request #2620 from ianyfan/commands
commands: when moving a container, restore focus properly
2018-09-12 09:20:47 +02:00
Brian Ashworth 0b7fe54f9e Update textures for cmd_client_* commands
Since the `client.{focused,focused_inactive,unfocused,urgent}` commands
change colors, the textures need to be updated otherwise the textures
and the rest of the title bar may utilize different colors.
2018-09-11 19:34:57 -04:00
Ian Fan ae535396b0 commands: when moving container, remove its gaps 2018-09-11 16:46:11 +01:00
Ian Fan c770949a9f commands: when moving container, restore focus properly 2018-09-11 16:46:07 +01:00
Ryan Dwyer 8bb40c24c7 Implement tiling drag
Hold floating_modifier and drag a tiling view to a new location.
2018-09-11 21:34:21 +10:00
Ryan Dwyer ec9c4de564 Introduce tiling_drag directive 2018-09-11 17:17:19 +10:00
William Wold e787a1581c Give windows pointer focus immediately when they are switched to
Fixes #2401 (aka #2558)

Previously, when switching windows, pointer focus was not changed until the pointer was moved. This makes the pointer enter happen immediately, without the side effects of other attempted fixes.
2018-09-10 10:18:12 -07:00
Ian Fan 6cd92b193c commands: prevent running empty seat command 2018-09-08 19:53:27 +01:00
Ryan Dwyer 908095ef9a Introduce seat_set_focus_container and seat_set_focus_workspace
These are the same as seat_set_focus, but accept a specific type rather
than using nodes. Doing this adds more typesafety and lets us avoid
using &con->node which looks a little ugly.

This fixes a crash that pretty much nobody would ever come across. If
you have a bindsym for "focus" with no arguments and run it from an
empty workspace, sway would crash because it assumes `container` is not
NULL.
2018-09-06 19:26:56 +10:00
emersion bea9f9c63f
Merge pull request #2578 from RyanDwyer/fix-binding-reload
Fix management of bindings during reload
2018-09-06 10:41:49 +02:00
Ryan Dwyer 1f941163d3 Fix crash when running "layout toggle"
The argc and argv used in this function are the same ones used by the
layout command itself.
2018-09-06 14:29:26 +10:00
Drew DeVault c6a74cb4df
Merge pull request #2586 from RyanDwyer/fix-fullscreen-focus-crash
Fix crash when focusing from fullscreen in an invalid direction
2018-09-05 22:12:54 -04:00
Ryan Dwyer 8859da1dc3 Fix crash when focusing from fullscreen in an invalid direction
* Fullscreen a view
* Run `focus <direction>` where there is no output in that direction

The output returned was rightfully NULL, which needs to be handled.
2018-09-06 12:03:13 +10:00
Ryan Dwyer 01117db6d9 Fix crash when moving view across outputs
It was incorrectly determining that the container being moved and the
destination had the same parent, which resulted in tree corruption. Both
parents can be NULL but the containers may belong to different
workspaces.

To reproduce, create layout H[V[view] view] in one workspace then move a
view left or right from another output into that workspace.
2018-09-06 11:53:55 +10:00
Ryan Dwyer 32c7386b0f Fix management of bindings during reload
seat_execute_command needs to check the flags on `binding_copy`, as
`binding` will be a dangling pointer after a reload command.

handle_keyboard_key needs to set the next_repeat_binding for
non-reloads prior to executing the command in case the binding is
freed by the reload command.
2018-09-06 08:33:00 +10:00
Ryan Dwyer dbf4aa3e33 Allow marked containers to be moved out of the scratchpad via move command 2018-09-05 18:01:43 +10:00
Ryan Dwyer 27d2d37d6e Fix crash when running layout toggle split 2018-09-05 18:01:43 +10:00
Ryan Dwyer 7263e39f64 Fix crash when using focus parent/child from an empty workspace 2018-09-05 18:01:43 +10:00
Ryan Dwyer 7f40b928c7 Fix another focus bug when moving into output
Find the focused_inactive view rather than possibly selecting a parent.
2018-09-05 18:01:43 +10:00
Ryan Dwyer 9d168a693d Fix moving workspace to output 2018-09-05 18:01:43 +10:00
Ryan Dwyer 06d9693829 Remove offset argument to container_add_sibling
I added this thinking that it might come in useful. Turns out it didn't.
2018-09-05 18:01:43 +10:00
Ryan Dwyer 0df04e27b6 Fix crash when focus hits edge of root 2018-09-05 18:01:43 +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
Ryan Dwyer 7797490e9e Deny repeating reload by holding key
Fixes #2568

The binding that gets stored in the keyboard's `repeat_binding` would
get freed on reload, leaving a dangling pointer.

Rather than attempt to unset the keyboard's `repeat_binding` along with
the other bindings, I opted to just not set it for the reload command
because there's no point in reloading repeatedly by holding the binding.
This disables repeat bindings for the reload command.

As we now need to detect whether it's a reload command in two places,
I've added a binding flag to track whether it's a reload or not.
2018-09-04 20:00:04 +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
Drew DeVault 89a045835f
Merge pull request #2547 from RyanDwyer/fix-reload-crash
Fix crash on reload
2018-09-01 10:39:36 -04: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
Ryan Dwyer 7e81e58e7d Allow reload command to exist anywhere in the command string
This fixes a crash if you have commands where reload appears in the
middle or at the end, such as `bindsym r mode default, reload`.
2018-09-01 11:45:48 +10:00
Ryan Dwyer ebe65a4d48 Fix crash on reload
If sway is reloaded using a bindsym which has multiple commands, it
failed to detect the reload command, didn't create a duplicate of the
binding and would crash because the reload command frees the bindings.

For example:

    mode system {
        bindsym r reload, mode default
    }

In this example, the binding->command is "reload, mode default".

Fixes #2545
2018-09-01 11:17:15 +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 79899064b6 commands: fix exec quoting 2018-08-29 10:55:12 +01:00
Ian Fan bc30f2d528 commands: fix moving container to different output
When moving a container to an inactive workspace on a different output, this will change the focus on the destination output back to its last active workspace
2018-08-28 15:08:46 +01:00
Ryan Dwyer 126a82f14f Fix gaps issues
* In layout command, arrange parent of parent - not sure why this is
needed but it is
* Remove gap adjustment when rendering
* Workspace should use outer gaps, not inner
* Add exceptions for tabbed and stacked containers
* Don't mess with gap state when splitting a container
2018-08-28 23:53:51 +10:00
Scott Anderson 31c3c8a365 Initialise variable properly 2018-08-27 18:01:17 +12:00
Ryan Dwyer 5dbbab7bdc Remove layout.c
When we have type safety we'll need to have functions for
workspace_add_tiling and so on. This means the existing container
functions will be just for containers, so they are being moved to
container.c. At this point layout.c doesn't contain much else, so I've
relocated everything and removed the file.

* container_swap and its static functions have been moved to the swap
command and made static.
* container_recursive_resize has been moved to the resize command and
made static.
* The following have been moved to container.c:
    * container_handle_fullscreen_reparent
    * container_insert_child
    * container_add_sibling
    * container_add_child
    * container_remove_child
    * container_replace_child
    * container_split
* enum movement_direction and sway_dir_to_wlr have been moved to util.c.

Side note: Several commands included layout.h which then included
root.h. With layout.h gone, root.h has to be included by those commands.
2018-08-26 12:05:16 +10:00
Armin Preiml 1a72149d88 Workspace move cycle
On move workspace to direction: Try the farthest on the opposite
direction if no workspace is found at given direction.
2018-08-25 17:10:41 +02:00
Drew DeVault b945957b9b
Merge pull request #2510 from RyanDwyer/relocate-layout-functions
Relocate container_move, container_move_to and container_get_in_direction
2018-08-25 09:38:33 -04:00
Ryan Dwyer 4b9ad9c238
Merge branch 'master' into commands 2018-08-25 13:06:04 +10:00
Ryan Dwyer f4bc25bcc6 Relocate container_move, container_move_to and container_get_in_direction
* container_move is only called from the move command
* container_move_to was called from both the move command and the sticky
command, but the sticky command can easily not call it
* container_get_in_direction is only called from the focus command

Moving these functions to their respective commands gives better
separation of code and removes bloat from layout.c. These functions will
need to be refactored to take advantage of type safety, so separating
them will make this easier to refactor.

The following static functions have also been moved:

* is_parellel
* invert_movement
* move_offs
* container_limit
* workspace_rejigger
* move_out_of_tabs_stacks
* get_swayc_in_output_direction

They were all used by the move functions, except for the last one which
is used by focus.

Other changes:

* index_child has been renamed to container_sibling_index, moved to
container.c and made public
* sway_output_from_wlr has been renamed to output_from_wlr_output, moved
to output.c and made public
* container_handle_fullscreen_reparent has been made public
* sway_dir_to_wlr has been made public

No changes have been made to any of the moved functions, other than
updating calls to functions that have been renamed.
2018-08-25 12:09:42 +10:00
Ryan Dwyer b6058703fa Refactor destroy functions and save workspaces when there's no outputs
This changes the destroy functions to the following:

* output_begin_destroy
* output_destroy
* workspace_begin_destroy
* workspace_destroy
* container_begin_destroy
* container_destroy
* view_begin_destroy
* view_destroy

The terminology was `destroy` and `free`, and it has been changed to
`begin_destroy` and `destroy` respectively.

When the last output is disconnected, its workspaces will now be stashed
in the root. Upon connection of a new output they will be restored.

There is a new function `workspace_consider_destroy` which decides
whether the given workspace should be destroyed or not (ie. empty and
not visible).

Calling container_begin_destroy will no longer automatically reap the
parents. In some places we want to reap the parents and in some we
don't, so this is left to the caller.

container_reap_empty_recursive and container_reap_empty have been
combined into one function and it will recurse up the tree.
2018-08-24 22:17:28 +10:00
Ryan Dwyer f129b1b89f Replace enum resize_edge with wlr_edges 2018-08-21 12:41:57 +10:00
Ian Fan f51b9478f2 commands: implement move absolute 2018-08-20 10:17:32 +01:00
Ryan Dwyer 0f6d212629 Send output enter/leave events correctly
Previously we used a reparent event to detect when a view changes
parent, then sent an output enter/leave to the surfaces if needed. This
worked for tiling views but not floating views, as floating views can
intersect another output without changing parent.

The solution implemented for floating views also applies cleanly to
tiling views, so the previous method has been completely replaced and
the reparent event has been removed.

This introduces a new function container_discover_outputs. This function
compares the container's `current` position to the outputs, sends enter
and leave events as needed, and keeps track of which outputs it's
intersecting in a new `container->outputs` list. If it has entered a new
output with a different scale then the title and marks textures will
also be recreated at the new scale.

The function is called when a transaction applies. This is convenient as
it means we don't have to call it from various places.

There is imperfect rendering when a floating view overlaps two outputs
with different scales. It renders correctly for the most recently
entered output, but there is only one title texture so it renders
incorrectly on the old output.

Fixes #2482
2018-08-20 09:23:24 +10:00
Ryan Dwyer 2b5a404ac9 Replace hacky L_FLOATING container with a list
Workspaces previously had a magical `workspace->floating` container,
which had a layout of L_FLOATING and whose children were actual floating
views. This allowed some conveniences, but was a hacky solution because
the container has to be exempt from focus, coordinate transactions with
the workspace, and omit emitting IPC events (which we didn't do).

This commit changes it to be a list directly in the sway_workspace. The
L_FLOATING layout is no longer used so this has been removed as well.

* Fixes incorrect check in the swap command (it checked if the
containers had the L_FLOATING layout, but this layout applied to the
magical container).
* Introduces workspace_add_floating
2018-08-19 16:18:33 +10:00
Ian Fan 37e37627ca commands: move newly-stickied containers to focused workspace 2018-08-18 18:29:18 +01:00
Ian Fan b3f7801fca commands: prevent focusing mode with no containers
Explicitly fail when trying to focus tiling/floating when there are no tiling/floating containers.
2018-08-18 17:25:06 +01:00
Ian Fan 23601a8771 commands: complete assign command 2018-08-18 17:25:06 +01:00
Ian Fan e81cc8a575 commands: saner workspace number handling 2018-08-18 17:25:06 +01:00
Ian Fan 69e00151bb commands: handle quoted exec command 2018-08-18 15:50:26 +01:00
Ian Fan 453646b887 commands: fix documentation formatting mistakes for move command 2018-08-18 15:50:26 +01:00
Ian Fan 7717c2231a commands: require set variable to start with $ 2018-08-18 15:50:26 +01:00
Ian Fan c1af79532f commands: add nop 2018-08-18 15:50:26 +01:00
Ryan Dwyer d6cd79c342 Implement iterators per container type
This introduces the following `for_each` functions:

* root_for_each_workspace
* root_for_each_container
* output_for_each_workspace
* output_for_each_container
* workspace_for_each_container

And introduces the following `find` functions:

* root_find_output
* root_find_workspace
* root_find_container
* output_find_workspace
* output_find_container
* workspace_find_container
* container_find_child

And removes the following functions:

* container_descendants
* container_for_each_descendant
* container_find

This change is preparing the way for demoting sway_container. Eventually
these functions will accept and return sway_outputs, sway_workspaces and
sway_containers (meaning a C_CONTAINER or C_VIEW).

This change also makes it easy to handle abnormalities like the
workspace floating list, root's scratchpad list and (once implemented)
root's saved workspaces list for when there's no connected outputs.
2018-08-18 23:38:54 +10:00
Ryan Dwyer 16c663ed49 Rename container_sort_workspaces and container_wrap_children
This commit renames container_sort_workspaces to output_sort_workspaces
and moves it to output.c.

This also renames container_wrap_children to workspace_wrap_children and
moves it to workspace.c. This function is only called with workspaces.
2018-08-18 22:02:03 +10:00
Ryan Dwyer 3a888163a0 Refactor seat_get_focus functions
Fixes #2467.

This commit introduces seat_get_focus_inactive_floating to supplement
seat_get_focus_inactive_tiling, and uses it during `focus mode_toggle`
which fixes a focus bug.

This also refactors the seat_get_focus_inactive functions so that they
do their selection logic themselves rather than offloading it to
seat_get_focus_by_type which was getting bloated. seat_get_focus_by_type
is now removed.

Lastly, this commit changes seat_get_focus to just return the first
container in the focus stack rather than looping and calling
seat_get_focus_by_type.
2018-08-17 17:32:53 +10:00
Ryan Dwyer b4a0363d17 Implement resizing tiled containers via cursor
* The OP_RESIZE seat operation has been renamed to OP_RESIZE_FLOATING,
and OP_RESIZE_TILING has been introduced.
* Similar to the above, seat_begin_resize and handle_resize_motion have
been renamed and tiling variants introduced.
* resize.c's resize_tiled has to be used, so container_resize_tiled has
been introduced in resize.c to allow external code to call it.
2018-08-12 10:45:54 +10:00
Ryan Dwyer 4ad1ccc9dc Remove container_for_each_descendant_bfs
The function was not used.

Also renames container_for_each_descendant_dfs to just
container_for_each_descendant.
2018-08-11 15:57:09 +10:00
Ryan Dwyer 6c730a2cb2 Implement resize set <width> <height> for tiled containers
Unlike i3, this implementation allows px measurements.

Also fixes a sane size check.
2018-08-10 08:50:15 +10:00
Ryan Dwyer 9395d3c93c Implement resize grow|shrink <direction> <amount> for tiled containers 2018-08-10 08:50:15 +10:00
Brian Ashworth b6f4623551 Don't call swaynag_log for bg when not reading 2018-08-08 17:04:12 -04:00
Brian Ashworth 43d1ffc9dd Allow a fallback color to be specified for swaybg
This allows for a color to be set when the wallpaper does not fill the
entire output. If specified, the fallback color is also used when the
image path is inaccessible.
2018-08-08 15:37:06 -04:00
Ryan Dwyer 5653fc754b Deny moving a sticky container to workspace if it's the same output
Rationale: Sticky containers are always assigned to the visible
workspace.

The basic idea here is to check the destination's output (move.c:190).
But if the command was `move container to workspace x` then a workspace
might have been created for it. We could destroy the workspace in this
case, but that results in unnecessary IPC events.

To avoid this, the logic for `move container to workspace x` has been
adjusted. It now delays creating the workspace until the end, and uses
`workspace_get_initial_output` to determine and check the output before
creating it.
2018-08-08 12:50:42 +10:00
Ryan Dwyer 5ac6f2f429 Fix crash when running `move container to workspace back_and_forth`
The back_and_forth condition is intended to be handled in the else-if
block, but this was never reached because it remained in the first
block's conditions.
2018-08-07 23:04:21 +10:00
Brian Ashworth 639f3368e1
Merge branch 'master' into workspace-move-to-output 2018-08-06 11:47:00 -04:00
Ryan Dwyer f57a3919cf Move workspace moving code out of container_move_to
container_move_to handled moving containers to new parents, as well as
moving workspaces to new outputs.

This commit removes the workspace-moving code from this function and
introduces workspace_move_to_output. Moving workspaces using
container_move_to only happened from the move command, so it's been
implemented as a static function in that file.

Simplifying container_move_to makes it easier for me to fix some issues
in #2420.
2018-08-07 00:03:01 +10:00
Ian Fan f7c21451df commands: fix workspace edge cases 2018-08-06 14:17:58 +01:00
Ian Fan 667b8dcb67 commands: check for special workspaces in workspace & move commands 2018-08-06 14:17:58 +01:00
Ian Fan dd48c8a579 commands: add optional flags to move 2018-08-06 14:17:58 +01:00
Ian Fan 85ae121caa commands: complete workspace implementation
Allow optional --no-auto-back-and-forth flag, as well as refactoring some logic
2018-08-06 14:17:58 +01:00
Ian Fan 356063b6c0 commands: fix layout implementation (also better name for previous split layout) 2018-08-06 14:17:58 +01:00
Ian Fan 69e1a421fc commands: complete move implementation 2018-08-06 14:17:58 +01:00
Ian Fan be64c46624 commands: complete layout implementation 2018-08-06 14:17:58 +01:00
Ryan Dwyer 30e7e0f7c7 Move workspace pid code to root.c 2018-08-04 14:01:49 +10:00
Ryan Dwyer 04489ff420 Separate root-related code
This creates a root.c and moves bits and pieces from elsewhere into it.

* layout_init has been renamed to root_create and moved into root.c
* root_destroy has been created and is called on shutdown
* scratchpad code has been moved into root.c, because hidden scratchpad
containers are stored in the root struct
2018-08-04 14:01:20 +10: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 9e8d628a17 Deny "move container" when an empty workspace is focused 2018-08-03 17:13:37 +10:00
Drew DeVault 8e60f6a732
Merge pull request #2404 from RyanDwyer/move-containers-when-workspace-focused
Allow moving containers when workspace itself is focused
2018-08-02 08:11:23 -04:00
Marien Zwart 7d8413d962 Reset signal mask after fork
wlroots uses wl_event_loop_add_signal to handle SIGUSR1 from Xwayland.
wl_event_loop_add_signal works by masking the signal and receiving it from a
signalfd. The signal mask is preserved across fork and exec, so subprocesses
spawned by Sway start with SIGUSR1 masked. Most subprocesses do not expect this
and never unmask the signal, resulting in missing functionality or unexpected
behavior for processes that use SIGUSR1 (such as i3status).

Fix this by unmasking all signals between fork and exec.
2018-08-02 21:31:34 +10:00