module/i3: workspace::focus is apparently Sway only

On i3, users are currently greeted with:

  err: modules/i3.c:94: workspace reply/event without 'name' and/or
       'output', and/or 'focus' properties

This patch makes ‘focus’ an optional attribute. When missing, we
assume a node-count of 0, which means the workspace’s ‘empty’ tag will
always be true. Document this in the i3 man page.
This commit is contained in:
Daniel Eklöf 2022-02-15 21:14:08 +01:00
parent 1ce108f24e
commit c44970717b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 18 additions and 7 deletions

View file

@ -23,6 +23,12 @@
### Deprecated ### Deprecated
### Removed ### Removed
### Fixed ### Fixed
* i3: fixed “missing workspace indicator” (_err: modules/i3.c:94:
workspace reply/event without 'name' and/or 'output', and/or 'focus'
properties_).
### Security ### Security
### Contributors ### Contributors

View file

@ -37,7 +37,7 @@ with the _application_ and _title_ tags to replace the X11-only
: True if the workspace has the urgent flag set : True if the workspace has the urgent flag set
| empty | empty
: bool : bool
: True if the workspace is empty : True if the workspace is empty (Sway only)
| state | state
: string : string
: One of *urgent*, *focused*, *unfocused* or *invisible* (note: : One of *urgent*, *focused*, *unfocused* or *invisible* (note:

View file

@ -103,16 +103,18 @@ static bool
workspace_from_json(const struct json_object *json, struct workspace *ws) workspace_from_json(const struct json_object *json, struct workspace *ws)
{ {
/* Always present */ /* Always present */
struct json_object *name, *output, *focus; struct json_object *name, *output;
if (!json_object_object_get_ex(json, "name", &name) || if (!json_object_object_get_ex(json, "name", &name) ||
!json_object_object_get_ex(json, "output", &output) || !json_object_object_get_ex(json, "output", &output))
!json_object_object_get_ex(json, "focus", &focus))
{ {
LOG_ERR("workspace reply/event without 'name' and/or 'output', " LOG_ERR("workspace reply/event without 'name' and/or 'output' "
"and/or 'focus' properties"); "properties");
return false; return false;
} }
/* Sway only */
struct json_object *focus = NULL;
json_object_object_get_ex(json, "focus", &focus);
/* Optional */ /* Optional */
struct json_object *visible = NULL, *focused = NULL, *urgent = NULL; struct json_object *visible = NULL, *focused = NULL, *urgent = NULL;
@ -122,7 +124,10 @@ workspace_from_json(const struct json_object *json, struct workspace *ws)
const char *name_as_string = json_object_get_string(name); const char *name_as_string = json_object_get_string(name);
const size_t node_count = json_object_array_length(focus); const size_t node_count = focus != NULL
? json_object_array_length(focus)
: 0;
const bool is_empty = node_count == 0; const bool is_empty = node_count == 0;
int name_as_int = workspace_name_as_int(name_as_string); int name_as_int = workspace_name_as_int(name_as_string);