Commit Graph

340 Commits

Author SHA1 Message Date
Drew DeVault cb8f68d74b layer-shell: add support for popups 2019-08-14 22:10:05 +03:00
Brian Ashworth 56b5ad777c input/cursor: do not hide when buttons are pressed
This just adds a small quality of life improvement to the cursor hiding
functionality. The cursor will no longer be hidden unless all buttons
are released.
2019-08-06 11:31:12 +09:00
Alex Maese 4d93b96b6e Unhide cursor on cursor activity after touch 2019-06-08 12:02:28 -04:00
Ryan Dwyer 7b9ae42331 Introduce default seatop
This introduces a `default` seat operation which is used when no mouse
buttons are being held. This means there is now always a seat operation
in progress. It allows us to separate `default` code from the standard
cursor management code.

The sway_seatop_impl struct has gained callbacks `axis`, `rebase` and
`end`, and lost callbacks `finish` and `abort`. `axis` and `rebase` are
only used by the default seatop. `end` is called when a seatop is being
replaced by another one and allows the seatop to free any resources,
though no seatop currently needs to do this. `finish` is no longer
required, as each seatop can gracefully finish in their `button`
callback. And `abort` is not needed, as calling `end` would achieve the
same thing. The struct has also gained a bool named allow_set_cursor
which allows the client to set a new cursor during `default` and `down`
seatops.

Seatops would previously store which button they were started with and
stop when that button was released. This behaviour is changed so that it
only ends once all buttons are released. So you can start a drag with
$mod+left, then click and hold right, release left and it'll continue
dragging while the right button is held.

The motion callback now accepts dx and dy. Most seatops don't use this
as they store the cursor position when the seatop is started and compare
it with the current cursor position. This approach doesn't make sense
for the default seatop though, hence why dx and dy are needed.

The pressed_buttons array has been moved from the sway_cursor struct to
the default seatop's data. This is only used for the default seatop to
check bindings. The total pressed button count remains in the
sway_cursor struct though, because all the other seatops check it to
know if they should end.

The `down` seatop no longer has a `moved` property. This was used to
track if the cursor moved and to recheck focus_follows_mouse, but seems
to work without it.

The logic for focus_follows_mouse has been refactored. As part of this
I've removed the call to wlr_seat_keyboard_has_grab as we don't appear
to use keyboard grabs.

The functions for handling relative motion, absolute motion and tool
axis have been changed. Previously the handler functions were
handle_cursor_motion, handle_cursor_motion_absolute and
handle_tool_axis. The latter two both called cursor_motion_absolute.
Both handle_cursor_motion and cursor_motion_absolute did very similar
things. These are now simplified into three handlers and a single common
function called cursor_motion. All three handlers call cursor_motion. As
cursor_motion works with relative distances, the absolute and tool axis
handlers convert them to relative first.
2019-03-17 10:02:04 -06:00
Ryan Dwyer fb3475e291 Replace seatup allows_events with button callback 2019-03-17 10:02:04 -06:00
Ryan Dwyer 783b3d6b37 Fix click behaviour
By the time seatop_allows_events was called, seatop_impl was already
NULL, causing the function to always return false. This means a press
event was sent to clients without a corresponding release event.

This patch moves the call to seatop_finish to after the
seatop_allows_events check.
2019-03-11 14:55:54 +01:00
Ryan Dwyer d16845d5f0 Don't send button events to surfaces when dragging or resizing
It turns out sending button events during all seat operations is not
desirable. This patch introduces a new property
`seatop_impl.allows_events` which allows each operation to define
whether button events should be passed to the surface or not.

The `down` seat operation is the only one that supports this. As all the
other seatops don't support it, the calls to seat_pointer_notify_button
prior to starting them have been removed.
2019-03-11 14:55:54 +01:00
Ryan Dwyer bdac0df4f8 Allow concurrent clicks
If two cursor buttons are pressed at the same time, the client will now
be notified of the second button press.

The main reason for not sending the concurrent presses was due to an
early return in dispatch_cursor_button if a seatop is in progress. This
patch makes it call seat_pointer_notify_button prior to returning. But
it also has to make sure there's not a mismatch in events such as a
release without a press.

Prior to this patch, the down seatop would send press and release events
in its begin and finish functions. No other seatops did this. A press
event would be sent prior to starting tiling drag, but never an
associated release.

After this patch, no seatops send their own press or release events. We
send them prior to calling the seatop begin functions, then the first
part of dispatch_cursor_button handles all presses during seatops and
when releasing the seatop.
2019-03-04 07:51:22 -07:00
emersion 88b283c557 seat: don't send button release when not pressed
All seat operations except "down" eat the button pressed event and don't send
it to clients. Thus, when ending such seat operations we shouldn't send the
button released event.

This commit moves the logic used to send pressed/released into the "down"
operation.
2019-02-28 23:02:06 -05:00
Rouven Czerwinski 4e028dba47 cursor: intitialize sx and sy to zero
If node_at_coords does an early return without setting these values, they can be
used uninitialized later. Initialize both to zero.
2019-02-27 00:35:51 -05:00
Rouven Czerwinski 35d610a43c cursor: remove unused node assignement
The node variable is not used before its reassigned later in the function,
remove the assignement.
2019-02-27 00:35:51 -05:00
emersion 656541bcc4
Update for swaywm/wlroots#1517 2019-02-23 19:04:10 +01:00
Brian Ashworth f078a1ccb8 input/cursor: allow whole-window bindings on ws
To match i3's behavior, this allows mouse bindings to be triggered over
a workspace when `--whole-window` is given.
2019-02-22 13:32:34 +01:00
Brian Ashworth d3d7956576 Handle NULL from output_get_active_workspace
This modifies the places where output_get_active_workspace is called to
handle a NULL result. Some places already handled it and did not need a
change, some just have guard off code blocks, others return errors, and
some have sway_asserts since the case should never happen. A lot of this
is probably just safety precautions since they probably will never be
called when `output_get_active_workspace` is not fully configured with a
workspace.
2019-02-21 21:18:03 +01:00
Vincent Vanlaer cfacf85755 Check layout before getting pointer surface coords
This fixes issues of clients at the edge of the screen, like swaybar,
ignoring buttons.
2019-02-16 21:46:19 +01:00
Brian Ashworth 1bccde68a4 cursor: relative-pointer-v1 time is usec
In handle_cursor_motion, the timestamp passed to
`wlr_relative_pointer_manager_v1_send_relative_motion` should be
microseconds (not milliseconds) according to relative-pointer-v1 spec.
2019-02-13 09:49:34 +01:00
emersion 97c89b24b8
Rebase cursor when a layer surface maps
Also removes an extraneous arrange_outputs call, it's already called if
necessary in arrange_layers.

Updates https://github.com/swaywm/sway/issues/3080
2019-02-12 22:57:23 +01:00
Drew DeVault a1a99421a1
Merge pull request #3562 from vilhalmer/focus_follows_mouse-workspace-last-inactive
Focus workspace inactive node with focus_follows_mouse
2019-02-03 20:15:21 +01:00
vilhalmer f8a9117149
Fall back to wildcard in sway_cursor_constrain 2019-02-03 13:46:44 -05:00
vilhalmer 907595b10d
Skip constraining cursor if no seat config 2019-02-03 13:44:37 -05:00
vilhalmer a3332c70bf
Focus ws inactive node with focus_follows_mouse 2019-02-03 12:12:40 -05:00
Drew DeVault de76c4e071
Merge pull request #3543 from emersion/relative-pointer-usec
relative-pointer-v1: time is in usec, not msec
2019-02-01 09:27:00 +01:00
Brian Ashworth ebe5399ed6 pointer_constraint: change to a seat subcommand
This changes the `pointer_constraint` command to be a subcommand of seat
to allow for per-seat settings. The current implementation that is not a
seat subcommand will only operate on the current seat and will segfault
in the config due to `config->handler_context.seat` only being set at
runtime.

This also allows for the wildcard identifier to be used to alter the
pointer constraint settings on all seats and allows for the setting to
be merged with the rest of the seat config.
2019-01-31 22:58:52 -05:00
emersion dde9fc19de
relative-pointer-v1: time is in usec, not msec 2019-01-30 21:30:44 +01:00
Drew DeVault 0c975af1fb Send pointer frames on tool events 2019-01-30 14:09:50 -05:00
Drew DeVault 4b87edeba4 Missed a spot in pointer constraints 2019-01-30 14:06:44 -05:00
Drew DeVault a6d41254c9 Add pointer_constraint command 2019-01-30 19:53:59 +01:00
absrd ee4b8a3938 Add relative pointer 2019-01-30 19:53:59 +01:00
Las cedde21c96 Implement pointer-constraints-unstable-v1 2019-01-30 19:53:59 +01:00
Drew DeVault 783fadab28
Merge pull request #3423 from RyanDwyer/fullscreen-global
Implement fullscreen global
2019-01-27 18:06:50 -05:00
emersion a452f8f822
Update for swaywm/wlroots#1503 2019-01-27 12:59:46 +01:00
Ryan Dwyer 20aa8ee67d Implement fullscreen global 2019-01-25 08:29:21 +10:00
M Stoeckl 1211a81aad Replace wlr_log with sway_log
This commit mostly duplicates the wlr_log functions, although
with a sway_* prefix. (This is very similar to PR #2009.)
However, the logging function no longer needs to be replaceable,
so sway_log_init's second argument is used to set the exit
callback for sway_abort.

wlr_log_init is still invoked in sway/main.c

This commit makes it easier to remove the wlroots dependency for
the helper programs swaymsg, swaybg, swaybar, and swaynag.
2019-01-21 12:59:42 +01:00
emersion 3b7a7462a2 Fix crash in cursor_rebase with multiple screens
Designing the output configuration sequence without invalid state is tricky.

We have one function, apply_output_config, that takes an output and (besides
other things) performs a modeset and inserts the output in the output layout.
The modeset can fail, in which case we don't want the output to be enabled.
We also have an output_enable function, which calls output_apply_config and
also configures the output's workspace and inserts it in the root container.

Now, we have two choices.

Either we configure the output before it's been inserted in the root container
and then, if the modeset was successful, we insert it and create the workspace.
The main issue with this approach is that configuring the output triggers a
handful of signals, namely wlr_output.mode and wlr_output_layout.change. In
those event handlers, we need to make sure to ignore these outputs in the
process of being configured.

Either we first insert the output, create the workspace and then try to
configure it. It means we need to undo everything if the modeset fails. The
main issue with this solution is that it enables and disables the output very
quickly, creates a workspace and immediately destroys it, and maybe moves
views back and forth (see output_evacuate).

I've tried to make it so an output isn't enabled then immediately disabled. We
already have code for ignoring outputs when the output is being destructed.

Fixes https://github.com/swaywm/sway/issues/3462
2019-01-19 08:29:46 +01:00
Brian Ashworth 02bbefda20 bar_cmd_tray_bind: Use mouse button helpers
This modifies `bar_cmd_tray_bindsym` to use `get_mouse_bindsym` for
parsing mouse buttons. This also introduces `bar_cmd_tray_bindcode`,
which will use `get_mouse_bindcode` for parsing mouse buttons. Like with
sway bindings, the two commands are encapsulated in a single file to
maximize shared code.

This also modifies tray bindings to work off of events codes rather than
x11 buttons, which allows for any mouse buttons to be used.

For `get_bar_config`, `event_code` has been added to the `tray_bindings`
section and will include to event code for the button. If the event code
can be mapped to a x11 button, `input_code` will still be the x11 button
number. Otherwise, `input_code` will be `0`.
2019-01-16 11:12:45 +01:00
Rouven Czerwinski f7309778a7 cursor: send clear_focus on hide and enter event on unhide
Clear the focus when we hide the cursor and show it again during the unhide
action. The unhide function will rebase the cursor after the unhide.

Tested by looking at the WAYLAND_DEBUG=1 output of termite.

Also call cursor_handle_activity before sending pointer events to send the enter
events to the surface if the cursor was hidden before.

Fixes #3431
2019-01-15 14:06:48 -05:00
Drew DeVault 9f9ef76175
Merge pull request #3343 from RedSoxFan/seat-cursor-buttons-improved
Improve mouse button parsing: seat cursor buttons
2019-01-13 20:40:42 -05:00
Drew DeVault db1631b67d
Merge pull request #3342 from RedSoxFan/scroll-buttons-improved
Improve mouse button parsing: input scroll_button
2019-01-13 20:40:00 -05:00
Brian Ashworth 4e6bd53abf input_cmd_scroll_button: utilize mouse btn helpers
This modifies `input_cmd_scroll_button` to utilize the mouse button
helper `get_mouse_button` when parsing the button. x11 axis buttons are
not supported with this command and `CMD_INVALID` will be returned, but
all other x11 buttons, button event names, and button event codes should
be working
2019-01-10 12:45:52 -05:00
Brian Ashworth aa1c838f97 seat_cmd_cursor: utilize mouse button helpers
This modifies `seat_cmd_cursor` to utilize `get_mouse_button` when
parsing mouse buttons for the `press` and `release` operations. All x11
buttons, button event names, and button event codes are supported.
For x11 axis buttons, `dispatch_cursor_axis` is used instead of
`dispatch_cursor_button`. However the `press`/`release` state is ignored
and the either axis event is processed. This also removes support for
`left` and `right` in favor of `BTN_LEFT` and `BTN_RIGHT`.
2019-01-10 11:47:34 -05:00
Ryan Dwyer ed5aafd90b Refactor seat operations to use an interface
This splits each seat operation (drag/move tiling/floating etc) into a
separate file and introduces a struct sway_seatop_impl to abstract the
operation.

The move_tiling_threshold operation has been merged into move_tiling.

The main logic for each operation is untouched aside from variable
renames.

The following previously-static functions have been made public:
* node_at_coords
* container_raise_floating
* render_rect
* premultiply_alpha
* scale_box
2019-01-10 22:04:42 +10:00
Ian Fan 15ac580b28
Merge pull request #3341 from RedSoxFan/mouse-bindings-improved
Improve mouse button parsing: helpers and bind{code/sym}
2019-01-10 10:55:22 +00:00
emersion 9abac85888
Merge pull request #3399 from RedSoxFan/fix-output-destruction-segfaults
Fix segfaults on output destruction
2019-01-10 09:20:07 +01:00
Brian Ashworth 8fd3f32c79 Fix segfaults on output destruction
This fixes two causes of segfaulting when an output is destroyed.

The first occurred when an output was never enabled. The issue was that
the destroy signal was never initialized so when it was emitted, sway
segfaulted. This was fixed by moving the initialization into
`output_create` since all outputs, regardless of whether they have ever
been enabled, will be destroyed at some point.

The second occurred when the cursor was on an output that was being
destroyed. The sway output would have already been removed, but if there
are other outputs, a cursor rebase would still occur. Since the
wlr_output still existed and the sway output was destroyed, the cursor
could be over nothing, resulting in a segfault when trying to get the
sway output, which was destroyed.
2019-01-10 03:07:36 -05:00
Brian Ashworth a8b3ae9284 cursor: allow scrolling tabs/stack on title border
This allows tabbed and stacked containers to be scrolled through when
the cursor is over the border of the title bar. The borders around the
other three edges of the contents should not be affected by this change.
2019-01-09 18:15:15 -05:00
Brian Ashworth 6f6a9af60e Add helpers for improved mouse button parsing
The following helper functions have been added to aid with parsing mouse
buttons from a string:

1. `get_mouse_bindsym`: attempts to parse the string as an x11 button
(button[1-9]) or as an event name (ex BTN_LEFT or BTN_SIDE)
2. `get_mouse_bindcode`: attempts to parse the string as an event code
and validates that the event code is a button (starts with `BTN_`).
3. `get_mouse_button`: this is a conveniency function for callers that
do not care whether a bindsym or bindcode are used and attempts to parse
the string as a bindsym and then bindcode.

None of these functions are used in this commit. The sole purpose of
this commit is to make the larger set more granular and easier to
review/manipulate. There will be a series of commits following this one
that will modify any command which uses a mouse button to use these
helpers.
2019-01-09 11:29:04 -05:00
Jan Beich 0a4c4f3e52 Simplify evdev includes on FreeBSD by relying on up-to-date package
evdev-proto is installed by a dependency, so some files have been missed:

  In file included from ../sway/input/cursor.c:3:
  /usr/local/include/libevdev-1.0/libevdev/libevdev.h:30:10: fatal error: 'linux/input.h' file not found
  #include <linux/input.h>
	   ^~~~~~~~~~~~~~~
  ../swaybar/i3bar.c:3:10: fatal error: 'linux/input-event-codes.h' file not found
  #include <linux/input-event-codes.h>
	   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-01-09 11:02:05 +00:00
Rouven Czerwinski fde900861a cursor: move unhide and timeout retrieval into separate functions
The unhide and timeout retrieval functions are needed in a later commit. No
functional changes.
2019-01-07 10:30:19 -05:00
David96 ee50134634 Apply tiling_drag_threshold to all containers 2019-01-03 12:52:37 -05: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
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 0dbf2673a1 Remove button from state on release during op
This fixes a bug in `dispatch_cursor_button` where if there was an
operation occurring, the button would not be removed from the state on
release. This resulted in the button appearing to be permanently pressed
and caused mouse bindings to not match correctly.
2018-12-29 16:36:48 +01:00
Brian Ashworth 3248c823ed Split image_surface handling into own function 2018-12-25 13:31:56 +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
Brian Ashworth a223030b70 Change mouse buttons to x11 map and libevdev names
This modifies the way mouse bindings are parsed. Instead of adding to
BTN_LEFT, which results in button numbers that may not be expected,
buttons will be parsed in one of the following ways:

1. `button[1-9]` will now map to their x11 equivalents. This is already
the case for bar bindings. This adds support for binding to axis events,
which was not possible in the previous approach.

2. Anything that starts with `BTN_` will be parsed as an event code name
using `libevdev_event_code_from_name`. This allows for any button to be
mapped to instead of limiting usage to the ones near BTN_LEFT. This also
adds a dependency on libevdev, but since libevdev is already a dependency
of libinput, this should be fine. If needed, this option can have dependency
guards added.

Binding changes:
- button1: BTN_LEFT -> BTN_LEFT
- button2: BTN_RIGHT -> BTN_MIDDLE
- button3: BTN_MIDDLE -> BTN_RIGHT
- button4: BTN_SIDE -> SWAY_SCROLL_UP
- button5: BTN_EXTRA -> SWAY_SCROLL_DOWN
- button6: BTN_FORWARD -> SWAY_SCROLL_LEFT
- button7: BTN_BACK -> SWAY_SCROLL_RIGHT
- button8: BTN_TASK -> BTN_SIDE
- button9: BTN_JOYSTICK -> BTN_EXTRA

Since the axis events need to be mapped to an event code, this uses the
following mappings to avoid any conflicts:
- SWAY_SCROLL_UP: KEY_MAX + 1
- SWAY_SCROLL_DOWN: KEY_MAX + 2
- SWAY_SCROLL_LEFT: KEY_MAX + 3
- SWAY_SCROLL_RIGHT: KEY_MAX + 4
2018-12-25 13:27:08 +01:00
Brian Ashworth 0ea54833d4 Focus node before tiling drag if on titlebar
Before attempting to drag a tiling container by its titlebar,
focus it. This fixes clicking on titlebars to focus a container.
2018-12-17 16:55:44 -05:00
Brian Ashworth 8d7ebc258a Allow tiling views to be dragged by the titlebar
Enables titling views to be dragged by the titlebar. This is in addition
to using the modifier and dragging them from anywhere on the container
surface. Floating views already allow this behavior.
2018-12-17 09:08:26 +01:00
emersion 3a310f92ab
Replace _XOPEN_SOURCE with _POSIX_C_SOURCE
And make sure we don't define both in the same source file.
2018-11-25 17:19:43 +01:00
Spencer Michaels 70bc4c3ab6 Add scroll factor config option. 2018-11-18 13:49:30 -05:00
emersion cad851805b
Use #if instead of #ifdef 2018-11-18 00:33:06 +01:00
Ryan Dwyer be9348d25c Move view {x,y,width,height} into container struct
This renames/moves the following properties:

* sway_view.{x,y,width,height} ->
sway_container.content_{x,y,width,height}
    * This is required to support placeholder containers as they don't
    have a view.
* sway_container_state.view_{x,y,width,height} ->
sway_container_state.content_{x,y,width,height}
    * To remain consistent with the above.
* sway_container_state.con_{x,y,width,height} ->
sway_container_state.{x,y,width,height}
    * The con prefix was there to give it contrast from the view
    properties, and is no longer useful.

The function container_set_geometry_from_floating_view has also been
renamed to container_set_geometry_from_content.
2018-11-17 21:29:42 +10:00
emersion 4ce18d2744
Fix segfault in dispatch_cursor_button 2018-11-15 16:35:19 +01:00
Connor E 4a21981855 Add focus_follows_mouse always. (#3081)
* Add focus_follows_mouse_mode.

* Fail if focus_follows_mouse is invalid.

* Fix indentation.
2018-11-06 21:58:08 +01:00
Ryan Dwyer 528c7495bb Move view border properties to container struct
This will be needed to implement layout saving and restoring, as we need
to be able to configure borders on a placeholder container which has no
view.
2018-10-31 23:56:20 +10:00
mwenzkowski 66ae58d62a cursor: fix uninitialized pointer in cursor_rebase 2018-10-28 17:33:27 +01:00
Ryan Dwyer 641fbe576e When scrolling on a tab titlebar, set focus_inactive if not focused
For example, create layout H[view T[view view view]], focus the view in
the hsplit and scroll the mouse wheel over the tab title bars. Prior to
this patch, focus would be given to a descendant of the tabbed
container. This patch keeps the focus on the hsplit view.

This also renames some of the variables used in this part of the code to
make it be easier to follow.
2018-10-24 23:59:09 +10:00
Ryan Dwyer 450a0661d7 Fix dormant cursor when using multiple seats
The cursor's image would be removed or set when the seat's capabilities
were updated, but there was nothing to prevent the image from being set
at other times.
2018-10-23 21:38:30 +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 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
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 765c80e5f7
Merge pull request #2820 from Emantor/fix-mouse-warping-container
Fix mouse warping container
2018-10-17 15:57:13 +02:00
Rouven Czerwinski 0969bf758b cursor: functions to warp cursor to container and workspace
The new functions allow a cursor to be warped without changing the focus.
This is a preparation commit to handle cursor warping not only in
seat_set_focus_warp.
2018-10-16 15:47:02 +02: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 416bb7a214 Fix floating click events
* Set focus to a floating container when clicking its title bar.
* Raise floating when user clicks title bar or decorations (in the
seat_begin functions).
* In container_at, it only returned a floating container if the user had
clicked the surface. This makes it use floating_container_at instead.
2018-10-10 16:58:32 +10:00
Ryan Dwyer f23588de3c Introduce container_is_transient_for 2018-10-08 23:00:36 +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
Ryan Dwyer 4feedbf7cf Ignore unrelated cursor buttons while doing seat operations
* Click and hold a scrollbar
* Drag the cursor onto another surface
* While still holding the original button, press and release another
cursor button
* Things get weird

There's two ways to fix this. Either cancel the seat operation and do
the other click, or continue the seat operation and ignore the other
click. I opted for the latter (ignoring the click) because it's easier
to implement, and I suspect a second click during a seat operation is
probably unintentional anyway.
2018-10-04 20:57:03 +10:00
Jonathan Buch 7727d54faf
Fix focusing topmost floating windows
Re-focus on the container on which the cursor hovers over.  A
special case is, if there are menus or other subsurfaces open
in the focused container.  It will prefer the focused container
as long as there are subsurfaces.

This commit starts caching the previous node as well as the
previous x/y cursor position.  Re-calculating the previous
focused node by looking at the current state of the cursor
position does not work, if the environment changes.
2018-10-03 16:23:14 +02: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
Arkadiusz Hiler 1e70f7b19e Turn funcs() into funcs(void)
If they really do not take undefined number of arguments.
2018-09-30 14:09:05 +03:00
emersion a53171669a
Merge pull request #2698 from ianyfan/hide-cursor
Only show cursor if pointer configured
2018-09-29 14:32:05 +02: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
Alexander Bakker d129108cdd Add a missing null check for moving tiling containers 2018-09-25 22:19:46 +02:00
Ian Fan a10fef9ae8 cursor: allow cursor_set_image to accept a NULL image to hide cursor 2018-09-24 12:34:09 +01:00
Ryan Dwyer bf5933c501 Implement tab cycling using mouse wheel
Firstly, a change had to be made to the container_at functions. If you
create layout `T[view H[view view]]` and hover the second tab, the
container_at functions would return the focus_inactive child. They now
return the split container itself. To compensate for this,
dispatch_cursor_button has been adjusted to find the focus_inactive
child before focusing it.

The actual implementation of wheel scrolling is pretty straightforward.
This uses handle_cursor_axis, so I took a similar approach to
handle_cursor_button (ie. creating a dispatch_cursor_axis function).
2018-09-22 10:42:59 +10:00
emersion 7699c5444c Update for swaywm/wlroots#1243 2018-09-14 19:21:44 +02:00
Ryan Dwyer 679c7eb08c Minor fixes to tiling drag implementation
* Make container_add_sibling's `after` argument a boolean.
* Use a constant for drop layout border
* Make thickness an int
* Add button state check
* Move comments in seat_end_move_tiling
2018-09-12 08:46:46 +10: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 d4e80cf301 Rename OP_MOVE to OP_MOVE_FLOATING
In preparation for introducing OP_MOVE_TILING.
2018-09-11 16:56:05 +10:00
Drew DeVault 030b5bc024
Merge pull request #2603 from emersion/fix-dnd
Fix drag-and-drop
2018-09-07 11:09:02 -04:00
emersion 251a7ebc4b Fix drag-and-drop 2018-09-07 15:43:15 +02: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
Ryan Dwyer 6f71749398 Fix clicking workspace buttons
Because node_at_coords was returning the workspace's node, it
interpreted this as clicking the focused workspace which was a no op.
2018-09-05 18:01:43 +10:00
Ryan Dwyer e5c9204b49 Focus empty workspace when clicking it
Also removes container_at_coords as this function is no longer
necessary.
2018-09-05 18:01:43 +10:00
Ryan Dwyer eccfcde2eb Fix crash when moving mouse over a fullscreen split container 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 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
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
Drew DeVault d4a32800d5
Merge pull request #2460 from RyanDwyer/implement-mousedown
Implement mousedown operation
2018-08-18 09:32:04 -04:00
Ryan Dwyer d22420689d Fix mod+resize
Fixes #2479.

It was missing a mod_pressed check.

This also moves the parent traversal into the `if` block.
2018-08-18 17:50:37 +10:00
Ryan Dwyer 07a897b3b7 Don't send motion if the cursor hasn't moved
Prevents GTK+ comboboxes from immediately closing.
2018-08-18 09:29:18 +10:00
Ryan Dwyer b637b61a7a Rename mousedown to down and make seat operation a named enum 2018-08-18 09:18:32 +10:00
Ryan Dwyer a36625a482 Implement mousedown operation
This allows you to move the cursor off the surface while dragging its
scrollbar.
2018-08-18 09:18:32 +10:00
Ryan Dwyer 4d023c0390 Make mod+resize a floating container resize the container itself
Rather than resizing the split within the container.
2018-08-12 10:45:54 +10:00
Ryan Dwyer e9d46ccbdd Use col-resize and row-resize cursor images 2018-08-12 10:45:54 +10:00
Ryan Dwyer 1893515d3a Fix right-click/popups and add state checks 2018-08-12 10:45:54 +10:00
Ryan Dwyer 2dceae6224 Allow resizing tiled views via mod key 2018-08-12 10:45:54 +10:00
Ryan Dwyer f4280e506b Refactor dispatch_cursor_button
There was a separate function dispatch_cursor_button_floating which
dealt with the resize and move operations, but as resize is not really
limited to floating views, it doesn't make as much sense to have this
separate. So both functions are now combined into one.

Additionally, dispatch_cursor_button now uses a pattern of returning
early instead of using else-ifs.
2018-08-12 10:45:54 +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 f5dc3ac09d Don't call send_pointer_notify_button when doing move or resize 2018-08-08 22:32:59 +10:00
Ryan Dwyer 4c5dc6f135 Focus floating views when beginning move/resize operations 2018-08-08 22:28:13 +10:00
Ryan Dwyer c17f0870ef Fix crash when moving cursor over a fullscreen split container
Calling container_at_view fails an assertion if the container isn't a
view. Calling tiling_container_at works correctly, as that function
checks if the container is a view and calls container_at_view if so.
2018-08-03 18:08:20 +10:00
emersion b336564511 Fix pointer events for fullscreen views 2018-08-02 22:48:43 +01:00
minus e72f86784c Fix crash on mouse motion on fullscreen container
container_at expects a workspace, not the fullscreened container.
Fixes #2409
2018-08-02 23:19:01 +02:00
Ryan Dwyer 8392eae40f Revert "Revert "Fix popups""
This reverts commit 9aa258d33a.

Reverting the revert, so that popups can be fixed.
2018-08-02 23:36:36 +10:00
Drew DeVault 9aa258d33a Revert "Fix popups"
This reverts commit de86d65627.
2018-08-02 09:05:46 -04:00
Drew DeVault 9564c73c0d
Merge pull request #2391 from RyanDwyer/fix-popups-v2
Fix popups (v2)
2018-08-01 22:02:12 -04:00
Ian Fan 03eaf444a4 ipc: prevent emitting a workspace::focus event when moving a container to a different workspace or output
When a container is moved from, say, workspace 1 to workspace 2, workspace 2 is focused in order to arrange the windows before focus is moved back to workspace 1, which caused a workspace:focus event from workspace 2 to workspace 1 to be emitted. This commit inhibits that event.
2018-08-01 16:57:15 +01:00
Ryan Dwyer de86d65627 Fix popups
Fixes the render and container_at order for popups.

Fixes #2210

For rendering:

* render_view_surfaces has been renamed to render_view_toplevels
* render_view_toplevels now uses output_surface_for_each_surface (which
is now public), as that function uses wlr_surface_for_each_surface which
doesn't descend into popups
* Views now have a for_each_popup iterator, which is used by the
renderer to render the focused view's popups
* When rendering a popup, toplevels (xdg subsurfaces) of that popup are
also rendered

For sending frame done, the logic has been updated to match the
rendering logic:

* send_frame_done_container no longer descends into popups
* for_each_popup is used to send frame done to the focused view's popups
and their child toplevels

For container_at:

* floating_container_at is now static, which means it had to be moved
higher in the file.
* container_at now considers popups for the focused view before checking
containers.
* tiling_container_at has been introduced, so that it doesn't call
container_at recursively (it would check popups recursively if it did)
2018-07-31 18:41:30 +10:00
Ryan Dwyer 0b6b6716e2 Fix clicking a floating split container
It would focus the split container rather than the child.

This commit makes it track the child and the split container separately
and send the surface click to the child.
2018-07-28 22:41:04 +10:00
Ryan Dwyer 08cfba2192 Allow containers to float
Things worth noting:

* When a fullscreen view unmaps, the check to unset fullscreen on the
workspace has been moved out of view_unmap and into container_destroy,
because containers can be fullscreen too
* The calls to `container_reap_empty_recursive(workspace)` have been
removed from `container_set_floating`. That function reaps upwards so it
wouldn't do anything. I'm probably the one who originally added it...
* My fix (b14bd1b0b1) for the tabbed child
crash has a side effect where when you close a floating container, focus
is not given to the tiled container again. I've removed my fix and
removed the call to `send_cursor_motion` from `seat_set_focus_warp`. We
should consider calling it from somewhere earlier in the call stack.
2018-07-28 22:41:04 +10:00
Ryan Dwyer 27a20a4884 Allow containers to be fullscreen 2018-07-26 08:27:07 +10:00
Drew DeVault fc718f629a
Merge pull request #2350 from ppascher/xwayland-optional
Added meson option to allow building sway without xwayland support
2018-07-25 08:27:40 -04:00
Pascal Pascher f95cb9a7c1 reverted includes of "sway/config.h" and replaced with "config.h" from meson build 2018-07-25 13:32:20 +02:00
Pascal Pascher 79a45d4a40 more style fixes, included "sway/config.h" where needed 2018-07-25 12:17:10 +02:00
Brian Ashworth 3a75bb7f32 Change button var passed to seat_begin_move 2018-07-24 18:52:54 -04:00
Brian Ashworth dca02944ce Implement floating_modifier <mod> [inverse|normal] 2018-07-24 18:41:08 -04:00
Pascal Pascher 2bf893248a style fixes, exclude sway/desctop/xwayland.c when enable_xwayland: false 2018-07-24 23:37:41 +02:00
Pascal Pascher 24ad1c3983 Added meson option "enable_xwayland" (default: true) to enable/disable xwayland support 2018-07-24 22:16:06 +02:00
Ryan Dwyer 2f1b84a0f3 Fix crash when clicking certain surfaces
cont was NULL.
2018-07-24 21:12:24 +10:00
Ryan Dwyer e7c10f1871 Make mod+resize work in any direction
This makes it so if you hold mod and right click on a surface to resize
it, the resize direction is chosen based on which quarter of the surface
you've clicked. The previous implementation only resized towards the
bottom right.
2018-07-24 20:20:00 +10:00
frsfnrrg 94dd8823a0 Invoke mouse bindings
The mouse binding logic is inspired/copied from the
keyboard binding logic; we store a sorted list of the
currently pressed buttons, and trigger a binding when
the currently pressed (or just recently pressed, in
the case of a release binding) buttons, as well as
modifiers/container region, match those of a given
binding.

As the code to execute a binding is not very keyboard
specific, keyboard_execute_command is renamed to
seat_execute_command and moved to where the other
binding handling functions are. The call to
transaction_commit_dirty has been lifted out.
2018-07-23 21:38:29 -04:00
Ryan Dwyer 0db6f2ef58 Fix some cases where the cursor doesn't update
cursor_set_image only uploads the named image if it doesn't match the
previous named image. This means when setting the cursor image to a
surface as given by a client, we have to clear the currently stored
image.
2018-07-24 09:09:49 +10:00
Ryan Dwyer d21d4b83a3 Set cursor when beginning resize and move operations 2018-07-22 23:10:19 +10:00
Ryan Dwyer 009b426024 Fix damage when shrinking a floating view using cursor 2018-07-22 23:10:19 +10:00
Ryan Dwyer 5ba2ae9c6a Implement request_move and request_resize for xwayland views
I discovered we have to send a click event when ending the move or
resize operation to make xwayland's requests work correctly.
2018-07-22 23:10:19 +10:00
Ryan Dwyer 3faceadffe Fix focus bug with floating containers 2018-07-22 23:10:19 +10:00
Ryan Dwyer 011d1ebfa4 Consider view's min/max sizes when resizing 2018-07-22 23:10:19 +10:00
Ryan Dwyer 9df660ee31 Store last button and use it when views request to move or resize 2018-07-22 23:10:19 +10:00
Ryan Dwyer 6767d8a593 Prevent re-uploading the same cursor image multiple times 2018-07-22 23:10:19 +10:00
Ryan Dwyer 0c87bff5d1 Replace static handle_end_operation with seat_end_mouse_operation 2018-07-22 23:10:19 +10:00
Ryan Dwyer ff445cc855 Implement xdg shell request_move and request_resize events
Also does a few other related things:

* Now uses enum wlr_edges instead of our own enum resize_edge
* Now uses wlr_xcursor_get_resize_name and removes our own
find_resize_edge_name
* Renames drag to move for consistency
2018-07-22 23:10:19 +10:00
Ryan Dwyer 1b3b75a094 Use wlr_keyboard_get_modifiers 2018-07-22 23:10:19 +10:00
Ryan Dwyer dd337127d8 Use separate function for choosing edge cursor 2018-07-22 23:10:19 +10:00
Ryan Dwyer 350e9ea929 Fix clicking xwayland menus 2018-07-22 23:10:19 +10:00
Ryan Dwyer c299b6b5cd Use max multiplier when resizing while preserving ratio 2018-07-22 23:10:19 +10:00
Ryan Dwyer 2c6616050a Make mod + resize do it from the top left corner 2018-07-22 23:10:19 +10:00
Ryan Dwyer 3aadf944ae Use WLR_MODIFIER_SHIFT 2018-07-22 23:10:19 +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