Commit Graph

1180 Commits

Author SHA1 Message Date
Ryan Walklin bdb402404c Support WLR_INPUT_DEVICE_SWITCH in sway
This commit adds support for laptop lid and tablet
mode switches as provided by evdev/libinput and
handled by wlroots.

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

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

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

(Note that WLR_SWITCH_STATE_TOGGLE doesn't map to
libinput and will trigger at both on and off events)
2019-03-19 23:58:47 -04:00
Ryan Dwyer e9a476244d Remove debug tree
This feature has served its purpose. It's better to use IPC now.
2019-03-18 11:29:19 -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
Brian Ashworth 3106ef23a7 Fix output config retrieval for new outputs
This removes `output_find_config`, which would take the first matching
output config it found. This is fine if only a name output config,
identifier output config, or even just wildcard exist, but if there is
a name output config and identifier output config, they are not merged.
Instead, this introduces find_output_config, which is just a wrapper
for `get_output_config`. This ensures that both the name and identifier
output configs are respected.

This fixes the following case:
- For simplicity in this example, remove all output configs from config
- Run `swaymsg output <name> bg #ff0000 solid_color`
- Run `swaymsg output <identifier> scale 2`
- Disconnect and reconnect output

Without this, the output will have the background, but not the scale.
With this, the output will have both the background and scale
2019-03-16 10:40:46 -06:00
Brian Ashworth 52a61671e9 criteria: change workspace to support regex
This changes the workspace criteria to support regex instead of basic
strings. This matches i3's behavior.
2019-03-12 20:52:09 -06:00
emersion 076257a978 Stop using wlr_output->{lx,ly}
Also fixes sway_output->{lx,ly,width,height} not being updated. Also fixes
output_get_in_direction adding buffer coords to layout coords.
2019-03-11 12:43:01 -04: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
Ian Fan 5c8424c074 stringop.c: remove unused functions
The only use of `join_list` in swaybar/tray/icon.c has been rewritten.
2019-03-11 14:42:58 +01:00
Brian Ashworth 017a7c4da1 sway_view_child: add listener for view unmap
Since not all child views's have an unmap event, it is possible for it
to still be mapped (default state) in the destruction handler. When
the destruction handler is called, the corresponding view may have
already been freed and the memory location reallocated. This adds a
listener for the view unmapping and removes the mapped status. This
ensures that the child view is damaged due to destruction while the
view still exists and not after.
2019-03-11 10:02:52 +01:00
Brian Ashworth 430359519c floating_maximum_size: change default behavior
This changes the way zero (which is the default) is interpreted for both
the width and height of `floating_maximum_size`. It now refers to the
width and height of the entire output layout, which matches i3's
behavior.

This also removes duplicated code to calculate the floating constraints
in three files. Before this, `container_init_floating` used two-thirds
of the workspace width/height as the max and the entire workspace
width/height was used everywhere else. Now, all callers use a single
function `floating_calculate_constraints`.
2019-03-02 09:10:26 +01: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
Milkey Mouse 2f7247e08a swaybar: add overlay mode (fix #1620)
Overlay mode puts the bar above normal windows and passes through/ignores any
touch/mouse/keyboard events that would be sent to it.
2019-02-24 20:05:47 -05:00
db 2510e3df38 add --i3 flag to hide_edge_borders
Enables i3-compatible behavior regarding hiding the title bar on tabbed and
stacked containers with one child.

Related issues and merge requests: #3031, #3002, #2912, #2987.
2019-02-24 15:26:37 -05:00
Connor E d4b1e71b91 Make load_include_configs void. Fix some cases where WD would not be restored. 2019-02-24 00:01:35 -05:00
Drew DeVault 4599907de7 swaybar: process hotspots on touch tap 2019-02-23 20:00:20 +01:00
emersion 656541bcc4
Update for swaywm/wlroots#1517 2019-02-23 19:04:10 +01:00
Drew DeVault 487c83f0de Add workspace {prev,next}_on_output --create
This creates the next workspace if you hit the end.
2019-02-17 11:50:07 -05:00
Drew DeVault cd10e755c1 Remove refs to unimplemented debuglog command
Closes #3695
2019-02-17 09:52:19 -05:00
emersion 7baaa3a0f8 Disconnect swaybg instead of killing it
This is much more reliable. This also fixes race conditions when killing swaybg
while it's doing a wl_display_roundtrip.
2019-02-16 19:11:22 -05:00
emersion 8ab64d3fcc Remove unused header include/sway/tree/output.h 2019-02-16 17:40:56 -05:00
Brian Ashworth 272ca06171 Fix reload freeze when not modsetting current mode
This fixes the issue of the display freezing on reload with
wlroots#1545.

On master, all output configs are applied on reload. This may cause an
output to have its config applied up to three times, instead of just
once. The three cases are: output name, output identifier, and wildcard.
Not only is this inefficient, but it can cause swaybg to be spawned and
immediately killed.

However, swaybg requires two roundtrips of wl_display (to obtain needed
globals) before it enters its normal event loop. Modesetting will
roundtrip the wl_display. Without modesetting, waitpid for killing
swaybg could block infinitely due to swaybg being blocked by
wl_display_roundtrip.

This only configured an output once. It either uses the wildcard config
or creates an empty wildcard config and applies that. This also fixes a
bug where an output would not be reset when there is no output config to
apply to it.
2019-02-16 23:37:36 +01:00
Ian Fan 5484f308b9 swaybar: prevent signal handler from firing during termination
This prevents a heap-use-after-free crash when sway terminates.
2019-02-15 14:09:14 +00: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
Brian Ashworth 7299b9a6ca seat_cmd_cursor: do not create non-existing seat
If a seat does not exist in seat_cmd_cursor, do not create it. A seat
without any attachments is useless since it will have no capabilities.

This changes `input_manager_get_seat` to have an additional argument
that dictates whether or not to create the seat if it does not exist.
2019-02-03 14:01:29 -05: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
v44r 204e1f4712 Rebase #1636 against current master 2019-01-31 15:37:57 +01: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
Brian Ashworth f0fd6119cf Cleanup config reading failure error logs
This cleans up the log when sway fails to read a config file. The
following changes have been made:
- A missing error message has been added to the log when the config file
is a directory instead of a regular file
- In main, `goto` statements have been added after the `sway_terminate`
calls instead of wrapping every block in `if (!terminate_request)`
- Unnecessary NULL-checks around calls to free in `main` have been
removed
- Deferred command execution has been extracted to a separate function
and the `Running deferred commands` log message will not be shown when
there are no deferred commands.
2019-01-29 13:18:53 -05:00
Ryan Dwyer 6b8bf10941 Introduce container_is_scratchpad_hidden
Just a convenience function that improves readability of the code.

Other things worth noting:

* container_get_siblings and container_sibling_index no longer use the
const keyword
* container_handle_fullscreen_reparent is only ever called after
attaching the container to a workspace, so its con->workspace check has
been changed to an assertion
2019-01-28 10:35:40 +01:00
Ryan Dwyer 0a9ff774ad Center surface inside container when it's too small
The goal here is to center fullscreen views when they are both too small
for the output and refuse to resize to the output's dimensions. It has
the side effect of also centering the view when it's too small for its
container.

Example clients that have this behaviour are emersion's hello-wayland
and weston.

It works by introducing surface_{x,y,width,height} properties to the
container struct. The x and y represent layout-local coordinates where
the surface will be rendered. The width and height are only used to
track the surface's previous dimensions so we can detect when the client
has resized it and recenter and apply damage accordingly.

The new surface properties are calculated when a transaction is applied,
as well as when a view resizes itself unexpectedly. The latter is done
in view_update_size. This function was previously restricted to views
which are floating, but can now be called for any views.

For views which refuse to resize *smaller* than a particular size, such
as gnome-calculator, the surface is still anchored to the top left as
per the current behaviour.
2019-01-28 01:17:21 -05: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
emersion 75406bb93b Update for swaywm/wlroots#1402 2019-01-24 11:48:19 +01:00
Jan Beich ba96983bf0 Make json-c include respect pkg-config --cflags
json-c.pc contains `Cflags: -I${includedir}/json-c`, so `<json-c/json.h>`
won't be found unless the parent directory is searched by default.
2019-01-23 21:50:06 -05:00
Ian Fan de9a357de8 util.c: remove numlen function
Its uses have been replaced by snprintf, which is more in line with its usage.
2019-01-22 13:10:25 +01:00
Ryan Dwyer 2301349ad5 Use noop output when there's no outputs connected
Instead of having NULL workspace->output pointers, use a noop output.
This should be safer.
2019-01-22 09:55:13 +01:00
M Stoeckl 4b1eaaf731 Removed unused wlroots dependency for sway(bg|bar|msg|nag)
Also remove direct libm dependency where unused.
2019-01-21 13:04:15 -05:00
M Stoeckl d7ff776552 Move sway-specific functions in common/util.c into sway/
Modifier handling functions were moved into sway/input/keyboard.c;
opposite_direction for enum wlr_direction into sway/tree/output.c;
and get_parent_pid into sway/tree/root.c .
2019-01-21 12:39:16 -05: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 a737d7ecc4
Better handle outputs without CRTC
This happens if you plug in more outputs than supported by your GPU.

This patch makes it so outputs without CRTCs appear as disabled. As soon as
they get a CRTC (signalled via the mode event), we can enable them.
2019-01-18 10:09:10 +01:00
emersion dc1eac0cf1 output: remove output_add_listeners
Simplify the code by registering signals when outputs are created and removing
signals when they are destroyed.
2019-01-18 10:08:34 +01:00
emersion f951c2357f
Remove unicode.c 2019-01-17 12:45:41 +01:00
emersion b29d19bf0d
Remove swaylock headers 2019-01-17 10:26:42 +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
Ryan Dwyer 2024f1da72 Resize only current and immediate siblings rather than all siblings
For example, create layout V[view view view] and resize the leftmost
view using mod+rightclick. Previously, the edge between view 2 and 3
would be adjusted as well. Now this edge will remain constant, which
matches the behaviour of i3.

To do this operation correctly, the resize tiling seatop now keeps track
of two containers, as the container that resizes horizontally will be a
different container to the one which resizes vertically (one will be an
ancestor). The tiling resize seatop now figures out these containers
during the start of the operation and keeps references to them in the
event. A new function container_find_resize_parent has been introduced
to do this. This function is also used by the resize command.

During cursor motion, the seatop logic is similar to before, but now has
to choose the correct container to resize.

In resize.c, container_resize_tiled and resize_tiled have been merged
into one. One of them originally did nothing except pass the values
through to the other.

container_resize_tiled now takes a simplified approach where it just
finds the immediate siblings on either side and resizes them without
worrying about the others. The parellel_coord and parallel_size
functions are no longer needed and have been removed.
2019-01-15 08:01:21 +10:00
Brian Ashworth 2573606b60 Disarm key repeat on reload
When resetting the keyboard during reload, disarm the key repeat on all
keyboards since the bindings (and possibly keyboard) will be freed before
the key repeat can go off.
2019-01-14 20:15:23 +01:00