2018-11-25 12:12:48 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-01-20 22:21:45 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
2018-09-01 15:04:49 +02:00
|
|
|
#include <strings.h>
|
2018-01-20 22:21:45 +01:00
|
|
|
#include <pcre.h>
|
|
|
|
#include "sway/criteria.h"
|
2018-03-30 05:41:33 +02:00
|
|
|
#include "sway/tree/container.h"
|
2018-01-20 22:21:45 +01:00
|
|
|
#include "sway/config.h"
|
2018-08-26 04:05:16 +02:00
|
|
|
#include "sway/tree/root.h"
|
2018-03-30 05:41:33 +02:00
|
|
|
#include "sway/tree/view.h"
|
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-08-30 13:00:10 +02:00
|
|
|
#include "sway/tree/workspace.h"
|
2018-01-20 22:21:45 +01:00
|
|
|
#include "stringop.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "log.h"
|
2018-07-25 12:17:10 +02:00
|
|
|
#include "config.h"
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
bool criteria_is_empty(struct criteria *criteria) {
|
|
|
|
return !criteria->title
|
2018-05-27 06:14:46 +02:00
|
|
|
&& !criteria->shell
|
2018-05-13 00:16:36 +02:00
|
|
|
&& !criteria->app_id
|
|
|
|
&& !criteria->con_mark
|
|
|
|
&& !criteria->con_id
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-09-03 14:25:48 +02:00
|
|
|
&& !criteria->class
|
2018-05-13 00:16:36 +02:00
|
|
|
&& !criteria->id
|
2018-09-03 14:25:48 +02:00
|
|
|
&& !criteria->instance
|
|
|
|
&& !criteria->window_role
|
2018-09-03 11:13:50 +02:00
|
|
|
&& criteria->window_type == ATOM_LAST
|
2018-07-25 12:17:10 +02:00
|
|
|
#endif
|
2018-05-13 00:16:36 +02:00
|
|
|
&& !criteria->floating
|
|
|
|
&& !criteria->tiling
|
|
|
|
&& !criteria->urgent
|
|
|
|
&& !criteria->workspace;
|
|
|
|
}
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
void criteria_destroy(struct criteria *criteria) {
|
|
|
|
pcre_free(criteria->title);
|
2018-05-27 06:14:46 +02:00
|
|
|
pcre_free(criteria->shell);
|
2018-05-13 00:16:36 +02:00
|
|
|
pcre_free(criteria->app_id);
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-05-13 00:16:36 +02:00
|
|
|
pcre_free(criteria->class);
|
|
|
|
pcre_free(criteria->instance);
|
|
|
|
pcre_free(criteria->window_role);
|
2018-09-03 14:25:48 +02:00
|
|
|
#endif
|
2019-02-01 12:51:03 +01:00
|
|
|
pcre_free(criteria->con_mark);
|
2018-05-13 00:16:36 +02:00
|
|
|
free(criteria->workspace);
|
2019-02-01 12:51:03 +01:00
|
|
|
free(criteria->cmdlist);
|
|
|
|
free(criteria->raw);
|
2018-05-13 00:16:36 +02:00
|
|
|
free(criteria);
|
|
|
|
}
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
static int regex_cmp(const char *item, const pcre *regex) {
|
|
|
|
return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0);
|
2018-05-12 14:52:54 +02:00
|
|
|
}
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-09-03 11:13:50 +02:00
|
|
|
static bool view_has_window_type(struct sway_view *view, enum atom_name name) {
|
2018-09-01 15:04:49 +02:00
|
|
|
if (view->type != SWAY_VIEW_XWAYLAND) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface;
|
|
|
|
struct sway_xwayland *xwayland = &server.xwayland;
|
|
|
|
xcb_atom_t desired_atom = xwayland->atoms[name];
|
|
|
|
for (size_t i = 0; i < surface->window_type_len; ++i) {
|
|
|
|
if (surface->window_type[i] == desired_atom) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-03 11:13:50 +02:00
|
|
|
#endif
|
2018-09-01 15:04:49 +02:00
|
|
|
|
2018-07-15 14:43:33 +02:00
|
|
|
static int cmp_urgent(const void *_a, const void *_b) {
|
|
|
|
struct sway_view *a = *(void **)_a;
|
|
|
|
struct sway_view *b = *(void **)_b;
|
|
|
|
|
|
|
|
if (a->urgent.tv_sec < b->urgent.tv_sec) {
|
|
|
|
return -1;
|
|
|
|
} else if (a->urgent.tv_sec > b->urgent.tv_sec) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (a->urgent.tv_nsec < b->urgent.tv_nsec) {
|
|
|
|
return -1;
|
|
|
|
} else if (a->urgent.tv_nsec > b->urgent.tv_nsec) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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-08-30 13:00:10 +02:00
|
|
|
static void find_urgent_iterator(struct sway_container *con, void *data) {
|
|
|
|
if (!con->view || !view_is_urgent(con->view)) {
|
2018-07-15 14:43:33 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
list_t *urgent_views = data;
|
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-08-30 13:00:10 +02:00
|
|
|
list_add(urgent_views, con->view);
|
2018-07-15 14:43:33 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
static bool criteria_matches_view(struct criteria *criteria,
|
|
|
|
struct sway_view *view) {
|
|
|
|
if (criteria->title) {
|
|
|
|
const char *title = view_get_title(view);
|
|
|
|
if (!title || regex_cmp(title, criteria->title) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
|
|
|
|
2018-05-27 06:14:46 +02:00
|
|
|
if (criteria->shell) {
|
2018-05-27 13:59:38 +02:00
|
|
|
const char *shell = view_get_shell(view);
|
2018-05-27 06:14:46 +02:00
|
|
|
if (!shell || regex_cmp(shell, criteria->shell) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
if (criteria->app_id) {
|
|
|
|
const char *app_id = view_get_app_id(view);
|
|
|
|
if (!app_id || regex_cmp(app_id, criteria->app_id) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-09 06:23:20 +02:00
|
|
|
}
|
2018-09-05 09:37:04 +02:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
if (criteria->con_mark) {
|
2018-05-14 14:47:10 +02:00
|
|
|
bool exists = false;
|
2018-10-31 12:27:38 +01:00
|
|
|
struct sway_container *con = view->container;
|
|
|
|
for (int i = 0; i < con->marks->length; ++i) {
|
|
|
|
if (regex_cmp(con->marks->items[i], criteria->con_mark) == 0) {
|
2018-05-14 14:47:10 +02:00
|
|
|
exists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!exists) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (criteria->con_id) { // Internal ID
|
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-08-30 13:00:10 +02:00
|
|
|
if (!view->container || view->container->node.id != criteria->con_id) {
|
2018-05-13 00:16:36 +02:00
|
|
|
return false;
|
2018-05-09 06:23:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-05-13 00:16:36 +02:00
|
|
|
if (criteria->id) { // X11 window ID
|
|
|
|
uint32_t x11_window_id = view_get_x11_window_id(view);
|
|
|
|
if (!x11_window_id || x11_window_id != criteria->id) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-09 06:23:20 +02:00
|
|
|
}
|
2018-09-03 14:25:48 +02:00
|
|
|
|
|
|
|
if (criteria->class) {
|
|
|
|
const char *class = view_get_class(view);
|
|
|
|
if (!class || regex_cmp(class, criteria->class) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (criteria->instance) {
|
|
|
|
const char *instance = view_get_instance(view);
|
|
|
|
if (!instance || regex_cmp(instance, criteria->instance) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-05-09 06:23:20 +02:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
if (criteria->window_role) {
|
2018-09-02 12:06:25 +02:00
|
|
|
const char *role = view_get_window_role(view);
|
|
|
|
if (!role || regex_cmp(role, criteria->window_role) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
}
|
|
|
|
|
2018-09-01 15:04:49 +02:00
|
|
|
if (criteria->window_type != ATOM_LAST) {
|
|
|
|
if (!view_has_window_type(view, criteria->window_type)) {
|
2018-05-13 00:16:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-09-03 11:13:50 +02:00
|
|
|
#endif
|
2018-05-13 00:16:36 +02:00
|
|
|
|
|
|
|
if (criteria->floating) {
|
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-08-30 13:00:10 +02:00
|
|
|
if (!container_is_floating(view->container)) {
|
2018-05-24 14:30:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (criteria->tiling) {
|
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-08-30 13:00:10 +02:00
|
|
|
if (container_is_floating(view->container)) {
|
2018-05-24 14:30:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (criteria->urgent) {
|
2018-07-15 14:43:33 +02:00
|
|
|
if (!view_is_urgent(view)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
list_t *urgent_views = create_list();
|
2018-08-17 11:48:34 +02:00
|
|
|
root_for_each_container(find_urgent_iterator, urgent_views);
|
2018-07-15 14:43:33 +02:00
|
|
|
list_stable_sort(urgent_views, cmp_urgent);
|
|
|
|
struct sway_view *target;
|
|
|
|
if (criteria->urgent == 'o') { // oldest
|
|
|
|
target = urgent_views->items[0];
|
|
|
|
} else { // latest
|
|
|
|
target = urgent_views->items[urgent_views->length - 1];
|
|
|
|
}
|
|
|
|
list_free(urgent_views);
|
|
|
|
if (view != target) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (criteria->workspace) {
|
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-08-30 13:00:10 +02:00
|
|
|
struct sway_workspace *ws = view->container->workspace;
|
2018-05-13 00:16:36 +02:00
|
|
|
if (!ws || strcmp(ws->name, criteria->workspace) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
list_t *criteria_for_view(struct sway_view *view, enum criteria_type types) {
|
|
|
|
list_t *criterias = config->criteria;
|
|
|
|
list_t *matches = create_list();
|
|
|
|
for (int i = 0; i < criterias->length; ++i) {
|
|
|
|
struct criteria *criteria = criterias->items[i];
|
|
|
|
if ((criteria->type & types) && criteria_matches_view(criteria, view)) {
|
|
|
|
list_add(matches, criteria);
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct match_data {
|
|
|
|
struct criteria *criteria;
|
|
|
|
list_t *matches;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void criteria_get_views_iterator(struct sway_container *container,
|
|
|
|
void *data) {
|
|
|
|
struct match_data *match_data = data;
|
2018-09-05 09:37:04 +02:00
|
|
|
if (container->view) {
|
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-08-30 13:00:10 +02:00
|
|
|
if (criteria_matches_view(match_data->criteria, container->view)) {
|
|
|
|
list_add(match_data->matches, container->view);
|
2018-05-13 00:16:36 +02:00
|
|
|
}
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
list_t *criteria_get_views(struct criteria *criteria) {
|
|
|
|
list_t *matches = create_list();
|
|
|
|
struct match_data data = {
|
|
|
|
.criteria = criteria,
|
|
|
|
.matches = matches,
|
|
|
|
};
|
2018-08-17 11:48:34 +02:00
|
|
|
root_for_each_container(criteria_get_views_iterator, &data);
|
2018-05-13 00:16:36 +02:00
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The error pointer is used for parsing functions, and saves having to pass it
|
|
|
|
// as an argument in several places.
|
|
|
|
char *error = NULL;
|
|
|
|
|
2018-01-20 22:21:45 +01:00
|
|
|
// Returns error string on failure or NULL otherwise.
|
2018-05-13 00:16:36 +02:00
|
|
|
static bool generate_regex(pcre **regex, char *value) {
|
2018-01-20 22:21:45 +01:00
|
|
|
const char *reg_err;
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
*regex = pcre_compile(value, PCRE_UTF8 | PCRE_UCP, ®_err, &offset, NULL);
|
|
|
|
|
|
|
|
if (!*regex) {
|
2018-05-13 00:16:36 +02:00
|
|
|
const char *fmt = "Regex compilation for '%s' failed: %s";
|
2018-01-20 22:21:45 +01:00
|
|
|
int len = strlen(fmt) + strlen(value) + strlen(reg_err) - 3;
|
2018-05-13 00:16:36 +02:00
|
|
|
error = malloc(len);
|
2018-01-20 22:21:45 +01:00
|
|
|
snprintf(error, len, fmt, value, reg_err);
|
2018-05-13 00:16:36 +02:00
|
|
|
return false;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
return true;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-09-01 15:04:49 +02:00
|
|
|
static enum atom_name parse_window_type(const char *type) {
|
|
|
|
if (strcasecmp(type, "normal") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_NORMAL;
|
|
|
|
} else if (strcasecmp(type, "dialog") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_DIALOG;
|
|
|
|
} else if (strcasecmp(type, "utility") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_UTILITY;
|
|
|
|
} else if (strcasecmp(type, "toolbar") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_TOOLBAR;
|
|
|
|
} else if (strcasecmp(type, "splash") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_SPLASH;
|
2018-10-21 15:51:35 +02:00
|
|
|
} else if (strcasecmp(type, "menu") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_MENU;
|
|
|
|
} else if (strcasecmp(type, "dropdown_menu") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
|
|
|
|
} else if (strcasecmp(type, "popup_menu") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_POPUP_MENU;
|
|
|
|
} else if (strcasecmp(type, "tooltip") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_TOOLTIP;
|
|
|
|
} else if (strcasecmp(type, "notification") == 0) {
|
|
|
|
return NET_WM_WINDOW_TYPE_NOTIFICATION;
|
2018-09-01 15:04:49 +02:00
|
|
|
}
|
|
|
|
return ATOM_LAST; // ie. invalid
|
|
|
|
}
|
2018-09-03 11:13:50 +02:00
|
|
|
#endif
|
2018-09-01 15:04:49 +02:00
|
|
|
|
2018-05-13 00:17:46 +02:00
|
|
|
enum criteria_token {
|
|
|
|
T_APP_ID,
|
|
|
|
T_CON_ID,
|
|
|
|
T_CON_MARK,
|
|
|
|
T_FLOATING,
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-09-03 14:25:48 +02:00
|
|
|
T_CLASS,
|
2018-05-13 00:17:46 +02:00
|
|
|
T_ID,
|
2018-09-03 14:25:48 +02:00
|
|
|
T_INSTANCE,
|
|
|
|
T_WINDOW_ROLE,
|
2018-09-03 11:13:50 +02:00
|
|
|
T_WINDOW_TYPE,
|
2018-07-25 13:43:21 +02:00
|
|
|
#endif
|
2018-05-27 06:14:46 +02:00
|
|
|
T_SHELL,
|
2018-05-13 00:17:46 +02:00
|
|
|
T_TILING,
|
|
|
|
T_TITLE,
|
|
|
|
T_URGENT,
|
|
|
|
T_WORKSPACE,
|
|
|
|
|
|
|
|
T_INVALID,
|
|
|
|
};
|
|
|
|
|
|
|
|
static enum criteria_token token_from_name(char *name) {
|
|
|
|
if (strcmp(name, "app_id") == 0) {
|
|
|
|
return T_APP_ID;
|
|
|
|
} else if (strcmp(name, "con_id") == 0) {
|
|
|
|
return T_CON_ID;
|
|
|
|
} else if (strcmp(name, "con_mark") == 0) {
|
|
|
|
return T_CON_MARK;
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-09-03 14:25:48 +02:00
|
|
|
} else if (strcmp(name, "class") == 0) {
|
|
|
|
return T_CLASS;
|
2018-05-13 00:17:46 +02:00
|
|
|
} else if (strcmp(name, "id") == 0) {
|
|
|
|
return T_ID;
|
2018-09-03 14:25:48 +02:00
|
|
|
} else if (strcmp(name, "instance") == 0) {
|
|
|
|
return T_INSTANCE;
|
|
|
|
} else if (strcmp(name, "window_role") == 0) {
|
|
|
|
return T_WINDOW_ROLE;
|
2018-09-03 11:13:50 +02:00
|
|
|
} else if (strcmp(name, "window_type") == 0) {
|
|
|
|
return T_WINDOW_TYPE;
|
2018-07-25 12:17:10 +02:00
|
|
|
#endif
|
2018-05-27 06:14:46 +02:00
|
|
|
} else if (strcmp(name, "shell") == 0) {
|
|
|
|
return T_SHELL;
|
2018-05-13 00:17:46 +02:00
|
|
|
} else if (strcmp(name, "title") == 0) {
|
|
|
|
return T_TITLE;
|
|
|
|
} else if (strcmp(name, "urgent") == 0) {
|
|
|
|
return T_URGENT;
|
|
|
|
} else if (strcmp(name, "workspace") == 0) {
|
|
|
|
return T_WORKSPACE;
|
2018-10-03 12:33:32 +02:00
|
|
|
} else if (strcmp(name, "tiling") == 0) {
|
|
|
|
return T_TILING;
|
2018-09-30 18:59:32 +02:00
|
|
|
} else if (strcmp(name, "floating") == 0) {
|
|
|
|
return T_FLOATING;
|
2018-05-13 00:17:46 +02:00
|
|
|
}
|
|
|
|
return T_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a property of the focused view.
|
|
|
|
*
|
|
|
|
* Note that we are taking the focused view at the time of criteria parsing, not
|
|
|
|
* at the time of execution. This is because __focused__ only makes sense when
|
|
|
|
* using criteria via IPC. Using __focused__ in config is not useful because
|
|
|
|
* criteria is only executed once per view.
|
|
|
|
*/
|
|
|
|
static char *get_focused_prop(enum criteria_token token) {
|
2018-10-18 13:20:00 +02:00
|
|
|
struct sway_seat *seat = input_manager_current_seat();
|
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-08-30 13:00:10 +02:00
|
|
|
struct sway_container *focus = seat_get_focused_container(seat);
|
2018-05-13 00:17:46 +02:00
|
|
|
|
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-08-30 13:00:10 +02:00
|
|
|
if (!focus || !focus->view) {
|
2018-05-13 00:17:46 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
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-08-30 13:00:10 +02:00
|
|
|
struct sway_view *view = focus->view;
|
2018-05-13 00:17:46 +02:00
|
|
|
const char *value = NULL;
|
|
|
|
|
|
|
|
switch (token) {
|
|
|
|
case T_APP_ID:
|
|
|
|
value = view_get_app_id(view);
|
|
|
|
break;
|
2018-05-27 06:14:46 +02:00
|
|
|
case T_SHELL:
|
2018-05-27 13:59:38 +02:00
|
|
|
value = view_get_shell(view);
|
2018-05-27 06:14:46 +02:00
|
|
|
break;
|
2018-05-13 00:17:46 +02:00
|
|
|
case T_TITLE:
|
2018-09-02 12:06:25 +02:00
|
|
|
value = view_get_title(view);
|
2018-05-13 00:17:46 +02:00
|
|
|
break;
|
|
|
|
case T_WORKSPACE:
|
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-08-30 13:00:10 +02:00
|
|
|
if (focus->workspace) {
|
|
|
|
value = focus->workspace->name;
|
2018-05-13 00:17:46 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-07-29 12:16:28 +02:00
|
|
|
case T_CON_ID:
|
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-08-30 13:00:10 +02:00
|
|
|
if (view->container == NULL) {
|
2018-07-29 12:16:28 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
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-08-30 13:00:10 +02:00
|
|
|
size_t id = view->container->node.id;
|
2018-08-01 17:02:56 +02:00
|
|
|
size_t id_size = snprintf(NULL, 0, "%zu", id) + 1;
|
|
|
|
char *id_str = malloc(id_size);
|
|
|
|
snprintf(id_str, id_size, "%zu", id);
|
2018-07-29 12:16:28 +02:00
|
|
|
value = id_str;
|
|
|
|
break;
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-09-03 14:25:48 +02:00
|
|
|
case T_CLASS:
|
|
|
|
value = view_get_class(view);
|
|
|
|
break;
|
|
|
|
case T_INSTANCE:
|
|
|
|
value = view_get_instance(view);
|
|
|
|
break;
|
|
|
|
case T_WINDOW_ROLE:
|
2018-09-02 12:06:25 +02:00
|
|
|
value = view_get_window_role(view);
|
2018-09-03 14:25:48 +02:00
|
|
|
break;
|
2018-09-02 12:06:25 +02:00
|
|
|
case T_WINDOW_TYPE: // These do not support __focused__
|
|
|
|
case T_ID:
|
2018-07-25 12:17:10 +02:00
|
|
|
#endif
|
2018-09-02 12:06:25 +02:00
|
|
|
case T_CON_MARK:
|
|
|
|
case T_FLOATING:
|
2018-05-13 00:17:46 +02:00
|
|
|
case T_TILING:
|
|
|
|
case T_URGENT:
|
|
|
|
case T_INVALID:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (value) {
|
|
|
|
return strdup(value);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
static bool parse_token(struct criteria *criteria, char *name, char *value) {
|
2018-05-13 00:17:46 +02:00
|
|
|
enum criteria_token token = token_from_name(name);
|
|
|
|
if (token == T_INVALID) {
|
|
|
|
const char *fmt = "Token '%s' is not recognized";
|
|
|
|
int len = strlen(fmt) + strlen(name) - 1;
|
|
|
|
error = malloc(len);
|
|
|
|
snprintf(error, len, fmt, name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *effective_value = NULL;
|
|
|
|
if (value && strcmp(value, "__focused__") == 0) {
|
|
|
|
effective_value = get_focused_prop(token);
|
|
|
|
} else if (value) {
|
|
|
|
effective_value = strdup(value);
|
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
// Require value, unless token is floating or tiled
|
2018-05-13 00:17:46 +02:00
|
|
|
if (!effective_value && token != T_FLOATING && token != T_TILING) {
|
2018-05-13 00:16:36 +02:00
|
|
|
const char *fmt = "Token '%s' requires a value";
|
|
|
|
int len = strlen(fmt) + strlen(name) - 1;
|
|
|
|
error = malloc(len);
|
|
|
|
snprintf(error, len, fmt, name);
|
|
|
|
return false;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
|
2018-05-13 00:17:46 +02:00
|
|
|
char *endptr = NULL;
|
|
|
|
switch (token) {
|
|
|
|
case T_TITLE:
|
|
|
|
generate_regex(&criteria->title, effective_value);
|
|
|
|
break;
|
2018-05-27 06:14:46 +02:00
|
|
|
case T_SHELL:
|
|
|
|
generate_regex(&criteria->shell, effective_value);
|
|
|
|
break;
|
2018-05-13 00:17:46 +02:00
|
|
|
case T_APP_ID:
|
|
|
|
generate_regex(&criteria->app_id, effective_value);
|
|
|
|
break;
|
|
|
|
case T_CON_ID:
|
|
|
|
criteria->con_id = strtoul(effective_value, &endptr, 10);
|
2018-05-13 00:16:36 +02:00
|
|
|
if (*endptr != 0) {
|
2018-07-29 12:16:28 +02:00
|
|
|
error = strdup("The value for 'con_id' should be '__focused__' or numeric");
|
2018-05-13 00:16:36 +02:00
|
|
|
}
|
2018-05-13 00:17:46 +02:00
|
|
|
break;
|
|
|
|
case T_CON_MARK:
|
|
|
|
generate_regex(&criteria->con_mark, effective_value);
|
|
|
|
break;
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-09-03 14:25:48 +02:00
|
|
|
case T_CLASS:
|
|
|
|
generate_regex(&criteria->class, effective_value);
|
2018-05-13 00:17:46 +02:00
|
|
|
break;
|
|
|
|
case T_ID:
|
|
|
|
criteria->id = strtoul(effective_value, &endptr, 10);
|
2018-05-13 00:16:36 +02:00
|
|
|
if (*endptr != 0) {
|
|
|
|
error = strdup("The value for 'id' should be numeric");
|
|
|
|
}
|
2018-05-13 00:17:46 +02:00
|
|
|
break;
|
2018-09-03 14:25:48 +02:00
|
|
|
case T_INSTANCE:
|
|
|
|
generate_regex(&criteria->instance, effective_value);
|
|
|
|
break;
|
|
|
|
case T_WINDOW_ROLE:
|
|
|
|
generate_regex(&criteria->window_role, effective_value);
|
|
|
|
break;
|
|
|
|
case T_WINDOW_TYPE:
|
|
|
|
criteria->window_type = parse_window_type(effective_value);
|
|
|
|
break;
|
2018-07-25 12:17:10 +02:00
|
|
|
#endif
|
2018-05-13 00:17:46 +02:00
|
|
|
case T_FLOATING:
|
2018-05-13 00:16:36 +02:00
|
|
|
criteria->floating = true;
|
2018-05-13 00:17:46 +02:00
|
|
|
break;
|
|
|
|
case T_TILING:
|
2018-05-13 00:16:36 +02:00
|
|
|
criteria->tiling = true;
|
2018-05-13 00:17:46 +02:00
|
|
|
break;
|
|
|
|
case T_URGENT:
|
2018-07-29 11:33:21 +02:00
|
|
|
if (strcmp(effective_value, "latest") == 0 ||
|
|
|
|
strcmp(effective_value, "newest") == 0 ||
|
|
|
|
strcmp(effective_value, "last") == 0 ||
|
|
|
|
strcmp(effective_value, "recent") == 0) {
|
2018-05-13 00:16:36 +02:00
|
|
|
criteria->urgent = 'l';
|
2018-07-29 11:33:21 +02:00
|
|
|
} else if (strcmp(effective_value, "oldest") == 0 ||
|
|
|
|
strcmp(effective_value, "first") == 0) {
|
2018-05-13 00:16:36 +02:00
|
|
|
criteria->urgent = 'o';
|
2018-01-20 22:21:45 +01:00
|
|
|
} else {
|
2018-05-13 00:16:36 +02:00
|
|
|
error =
|
2018-07-29 11:33:21 +02:00
|
|
|
strdup("The value for 'urgent' must be 'first', 'last', "
|
|
|
|
"'latest', 'newest', 'oldest' or 'recent'");
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
2018-05-13 00:17:46 +02:00
|
|
|
break;
|
|
|
|
case T_WORKSPACE:
|
|
|
|
criteria->workspace = strdup(effective_value);
|
|
|
|
break;
|
|
|
|
case T_INVALID:
|
|
|
|
break;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
2018-05-13 00:17:46 +02:00
|
|
|
free(effective_value);
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
if (error) {
|
2018-05-12 14:52:54 +02:00
|
|
|
return false;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
2018-05-12 14:52:54 +02:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
return true;
|
2018-05-12 14:52:54 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
static void skip_spaces(char **head) {
|
|
|
|
while (**head == ' ') {
|
|
|
|
++*head;
|
2018-05-12 14:52:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
// Remove escaping slashes from value
|
|
|
|
static void unescape(char *value) {
|
|
|
|
if (!strchr(value, '\\')) {
|
|
|
|
return;
|
2018-05-12 14:52:54 +02:00
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
char *copy = calloc(strlen(value) + 1, 1);
|
|
|
|
char *readhead = value;
|
|
|
|
char *writehead = copy;
|
|
|
|
while (*readhead) {
|
|
|
|
if (*readhead == '\\' && *(readhead + 1) == '"') {
|
|
|
|
// skip the slash
|
|
|
|
++readhead;
|
2018-05-09 06:23:20 +02:00
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
*writehead = *readhead;
|
|
|
|
++writehead;
|
|
|
|
++readhead;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
strcpy(value, copy);
|
|
|
|
free(copy);
|
2018-05-12 14:52:54 +02:00
|
|
|
}
|
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
/**
|
|
|
|
* Parse a raw criteria string such as [class="foo" instance="bar"] into a
|
|
|
|
* criteria struct.
|
|
|
|
*
|
|
|
|
* If errors are found, NULL will be returned and the error argument will be
|
2018-05-13 00:47:22 +02:00
|
|
|
* populated with an error string. It is up to the caller to free the error.
|
2018-05-13 00:16:36 +02:00
|
|
|
*/
|
|
|
|
struct criteria *criteria_parse(char *raw, char **error_arg) {
|
2018-05-13 03:40:05 +02:00
|
|
|
*error_arg = NULL;
|
2018-05-13 00:16:36 +02:00
|
|
|
error = NULL;
|
|
|
|
|
|
|
|
char *head = raw;
|
|
|
|
skip_spaces(&head);
|
|
|
|
if (*head != '[') {
|
|
|
|
*error_arg = strdup("No criteria");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
++head;
|
|
|
|
|
2018-09-01 15:04:49 +02:00
|
|
|
struct criteria *criteria = calloc(1, sizeof(struct criteria));
|
2018-11-18 00:33:06 +01:00
|
|
|
#if HAVE_XWAYLAND
|
2018-09-01 15:04:49 +02:00
|
|
|
criteria->window_type = ATOM_LAST; // default value
|
2018-09-03 11:13:50 +02:00
|
|
|
#endif
|
2018-05-13 00:16:36 +02:00
|
|
|
char *name = NULL, *value = NULL;
|
|
|
|
bool in_quotes = false;
|
|
|
|
|
|
|
|
while (*head && *head != ']') {
|
|
|
|
skip_spaces(&head);
|
|
|
|
// Parse token name
|
|
|
|
char *namestart = head;
|
|
|
|
while ((*head >= 'a' && *head <= 'z') || *head == '_') {
|
|
|
|
++head;
|
2018-05-12 14:52:54 +02:00
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
name = calloc(head - namestart + 1, 1);
|
2018-06-08 14:58:40 +02:00
|
|
|
if (head != namestart) {
|
|
|
|
strncpy(name, namestart, head - namestart);
|
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
// Parse token value
|
|
|
|
skip_spaces(&head);
|
|
|
|
value = NULL;
|
|
|
|
if (*head == '=') {
|
|
|
|
++head;
|
|
|
|
skip_spaces(&head);
|
|
|
|
if (*head == '"') {
|
|
|
|
in_quotes = true;
|
|
|
|
++head;
|
|
|
|
}
|
|
|
|
char *valuestart = head;
|
|
|
|
if (in_quotes) {
|
|
|
|
while (*head && (*head != '"' || *(head - 1) == '\\')) {
|
|
|
|
++head;
|
|
|
|
}
|
|
|
|
if (!*head) {
|
|
|
|
*error_arg = strdup("Quote mismatch in criteria");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (*head && *head != ' ' && *head != ']') {
|
|
|
|
++head;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
value = calloc(head - valuestart + 1, 1);
|
|
|
|
strncpy(value, valuestart, head - valuestart);
|
|
|
|
if (in_quotes) {
|
|
|
|
++head;
|
|
|
|
in_quotes = false;
|
|
|
|
}
|
|
|
|
unescape(value);
|
2019-03-09 04:06:38 +01:00
|
|
|
sway_log(SWAY_DEBUG, "Found pair: %s=%s", name, value);
|
2018-05-13 00:16:36 +02:00
|
|
|
}
|
|
|
|
if (!parse_token(criteria, name, value)) {
|
|
|
|
*error_arg = error;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
skip_spaces(&head);
|
|
|
|
free(name);
|
|
|
|
free(value);
|
|
|
|
name = NULL;
|
|
|
|
value = NULL;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|
2018-05-13 00:16:36 +02:00
|
|
|
if (*head != ']') {
|
|
|
|
*error_arg = strdup("No closing brace found in criteria");
|
|
|
|
goto cleanup;
|
2018-05-09 06:23:20 +02:00
|
|
|
}
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
if (criteria_is_empty(criteria)) {
|
|
|
|
*error_arg = strdup("Criteria is empty");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-01-20 22:21:45 +01:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
++head;
|
|
|
|
int len = head - raw;
|
|
|
|
criteria->raw = calloc(len + 1, 1);
|
|
|
|
strncpy(criteria->raw, raw, len);
|
|
|
|
return criteria;
|
2018-05-12 14:52:54 +02:00
|
|
|
|
2018-05-13 00:16:36 +02:00
|
|
|
cleanup:
|
|
|
|
free(name);
|
|
|
|
free(value);
|
|
|
|
criteria_destroy(criteria);
|
|
|
|
return NULL;
|
2018-01-20 22:21:45 +01:00
|
|
|
}
|