1
1
Fork 0
mirror of https://github.com/swaywm/sway synced 2024-05-19 13:26:14 +02:00
Commit Graph

94 Commits

Author SHA1 Message Date
Simon Ser fc640d5f6c Define _POSIX_C_SOURCE globally
See discussion in https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4555
2024-02-23 17:43:19 +03:00
Johan Sköld d952ce403e i3 compat: Adding support for the `all` criteria
Matches all views. i3 PR: https://github.com/i3/i3/pull/4460

Fixes #7110
2023-09-07 10:42:54 +09:00
Ronan Pigott 991d75904f criteria: be lenient on window_role and instance too 2022-12-08 21:20:45 +01:00
Callum Andrew 3e19836f0e criteria: allow matching for NULL string criteria 2022-11-04 10:02:11 +01:00
Puck Meerburg e40eb338b9 criteria: allow matching on empty (NULL) titles 2022-10-30 10:57:19 +01:00
cparm 99fd096d69 Avoid double free in criteria_destroy() 2022-10-13 14:56:10 +02:00
Simon Ser 7a6afc5199 Fix leaks in criteria_destroy() 2022-10-10 09:51:01 -04:00
Simon Ser 1e9be019b2 Replace strncpy with memcpy
strncpy is useless here, is dangerous because it doesn't guarantee
that the string is NUL-terminated and causes the following warning:

    ../sway/criteria.c: In function ‘criteria_parse’:
    ../sway/criteria.c:712:25: error: ‘strncpy’ destination unchanged after copying no bytes [-Werror=stringop-truncation]
      712 |                         strncpy(value, valuestart, head - valuestart);
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-05-11 11:47:49 -04:00
Bill Li f167acce3a Updating criteria checking with PCRE2 2022-03-15 11:28:04 +01:00
ndren f614f35e73
Replace pcre with pcre2
Closes: https://github.com/swaywm/sway/issues/6838
2022-03-12 14:02:32 +01:00
Kenny Levinsen a047b5ee4a container: Move pending state to state struct
Pending state is currently inlined directly in the container struct,
while the current state is in a state struct. A side-effect of this is
that it is not immediately obvious that pending double-buffered state is
accessed, nor is it obvious what state is double-buffered.

Instead, use the state struct for both current and pending.
2021-02-16 22:05:00 -05:00
Paul Riou b5cc11b226 criteria: fix crash when comparing NULL properties
For each following combinations of criteria & command below, the command would
crash sway without the fix.
It's particular about the __focused__ criteria, where the view matches part of
the criteria but not the focused app, leading to a failure when calling
`strcmp` with NULL.

"xterm" is a non-wayland app (X11) and "kitty" is. Both are terminals.

    # "class" is specific to X11
    # The view is X11 (xterm) leading to the criteria checking for the
    # focused app's class, leading to a crash
    for_window [class="__focused__"] floating enable
    exec kitty -e xterm

    # Similarly, crash as the focused app (xterm) has no app_id when the view has one
    for_window [app_id="__focused__"] floating enable
    exec xterm -e kitty

    # If the view has a title but not the focused app: NULL title will crash criteria checking
    for_window [title="__focused__"] floating enable
    exec xterm -title "" -e xterm
2020-12-04 10:49:49 +01:00
Ryan Dwyer 2045ac3472 Introduce pid criteria token
This can be used as a workaround to flag terminal windows as urgent when
commands are completed, until urgency is introduced in the Wayland
protocol.

Configure your shell to run `swaymsg "[pid=$PPID] urgent enable"` when
commands are completed, and use a terminal which uses one process per
window.
2020-02-27 14:03:22 +01:00
Anders 4e46bdf73d criteria: match containers without view
Closes #4929

Replaces criteria_get_views with criteria_get_containers which can
return containers without views when the criteria only contains
container properties.
2020-02-04 19:52:21 -05:00
Ronan Pigott 7c9b71f5c6 criteria: make literal comparison for __focused__ values 2019-10-27 11:06:05 -04:00
Ashkan Kiani e4bba906b6 Avoid adding duplicate criteria for no_focus and command 2019-07-27 03:53:05 +03:00
Brian Ashworth 7d2076cbff criteria: fix __focused__ when no focus or unset
This fixes the behavior of `__focused__` when there is no focused view
to match i3's behavior of successfully matching no views instead of
returning an error of a missing value. It also applies the same logic
when a token is not applicable (or unset) for a view such as `app_id`
for a focused xwayland view or `class` for a focused xdg-shell view.

This adds an `autofail` boolean to `struct criteria`. If it is set to
`true`, then `criteria_matches_view` will immediately bail out as a
no match. If `autofail` is set, the criteria will also not be
considered empty by `criteria_is_empty`.

To set this new `autofail` property, `get_focused_prop` will now take
in a boolean pointer of the same name. If `__focused__` is supported
for the token and there is no focused view or the focused view does not
have a value for the token, then the boolean will be set to true. In
`parse_token`, the boolean value will be checked and if set to true,
then `criteria->autofail` will be set to true and `parse_token` will
bail successfully. Tokens will still be parsed to make sure the whole
criteria is syntactically valid, which is also why
`&criteria->autofail` is not passed to `get_focused_prop` and a local
boolean is declared in `parse_token`.
2019-03-23 09:53:23 +02: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
Jeff Peeler a73e8f1328 fix "directive argument is null" errors 2019-03-09 14:59:28 -07:00
Connor E 49b667272b Revert "Add some missing frees."
This reverts commit b5d95f264d.
2019-02-01 11:51:03 +00: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 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
emersion cad851805b
Use #if instead of #ifdef 2018-11-18 00:33:06 +01:00
Connor E b5d95f264d Add some missing frees. 2018-11-13 13:45:01 +00:00
Ryan Dwyer 9fc736f4e1 Move view marks properties to container struct
Like border properties, this will be needed to implement layout saving
and restoring.
2018-11-01 18:09:51 +10:00
Christian 989bddc765 Parse missing i3 window types
fixes the parsing part of #2906
2018-10-21 15:59:04 +02: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 a519fb6fde Fix tiling criteria 2018-10-03 20:33:32 +10:00
Ragnis Armus 1bd695ffd2 Parse floating criteria 2018-09-30 19:59:32 +03:00
Ryan Dwyer 1f2e0ff54b Fix inversed condition in criteria 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 29f5cc7508 Implement window_role criteria token
Depends on https://github.com/swaywm/wlroots/pull/1226
2018-09-04 08:23:50 +10:00
Pascal Pascher 93673095f0 move criteria "instance", "class" and "window_role" inside HAVE_XWAYLAND ifdefs" 2018-09-03 14:25:48 +02:00
Pascal Pascher 587e320cd8 Fixed window_type with disabled xwayland support. 2018-09-03 11:13:50 +02:00
Ryan Dwyer f4ec308376 Implement window_type criteria token 2018-09-01 23:04:49 +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 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 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
Ian Fan 3a980857cb commands: better type for con_id string length 2018-08-06 14:17:58 +01:00
Ian Fan 11ac66d6fe commands: allow __focused__ for con_id criterion 2018-08-06 14:17:58 +01:00
Ian Fan 710f27d0d2 commands: allow "first", "last", "newest" and "recent" as values for urgent criteria 2018-08-06 14:17:45 +01:00
Pascal Pascher 384c55c0b4 more style fixes, reorder config.h include 2018-07-25 13:43:21 +02:00
Pascal Pascher 79a45d4a40 more style fixes, included "sway/config.h" where needed 2018-07-25 12:17:10 +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 12e90fa600 Store scratchpad list in sway_root instead of server 2018-07-23 08:24:32 +10:00
Ryan Dwyer 81e8f31cc6 Implement scratchpad
Implements the following commands:

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

Also fixes these:

* Fix memory leak when executing command with criteria
(use `list_free(views)` instead of `free(views)`)
* Fix crash when running `move to` with no further arguments
2018-07-23 08:24:32 +10:00
frsfnrrg 600676688a Free individual criteria in free_config
Also free cmd_list when cleaning up a struct criteria.
2018-07-17 11:35:00 -04:00
Ryan Dwyer 315d5311b2 Implement urgency base functionality
Introduces a command to manually set urgency, as well as rendering of
urgent views, sending the IPC event, removing urgency after focused for
one second, and matching urgent views via criteria.
2018-07-16 08:19:25 +10:00
emersion 63b4bf5000
Update for swaywm/wlroots#1126 2018-07-09 22:54:30 +01:00
Dominique Martinet 720313e185 sway/criteria: gcc string truncation warning fix 2018-06-08 22:30:13 +09:00