Commit graph

84 commits

Author SHA1 Message Date
Delgan
b85ba99980 Apply "clang-format" preferences globally 2024-04-07 10:05:10 +02:00
Haden Collins
89ae7bd743
Handle reload workspace events from sway correctly
Closes #361
2024-03-14 16:14:53 -05:00
Delgan
195ac5d1cd
Fix incorrect empty/title state of i3 workspaces 2024-02-05 12:45:02 +01:00
Armin Fisslthaler
f21db9caca i3: add "native" sway/i3 sort mode
This adds a sort mode for workspaces which corresponds to the default
behavior in sway/i3.
2023-03-24 17:48:26 +01:00
Daniel Eklöf
73ccafdade
module/i3: fix regression in handling of persistent workspaces
bbd2394601 added support for ‘rename’
and ‘move’ events. In order to do that, it changed how workspace
events are matched against our internal workspace list: from string
comparing the workspace name, to checking i3/sway’s workspace ID
parameter.

This introduced a regression in our handling of persistent
workspaces. A persistent workspace is one that isn’t removed from the
bar when it’s deleted (empty, and switched away from) by i3/sway.

This concept doesn’t exist in i3/sway, but is something we’ve
added. Put simple, the way we do this is be keeping the workspace in
our list, even when i3/sway tells us it has been deleted.

However, at this point the workspace doesn’t have an ID anymore. And
the same is true at startup; when we initialize the persistent
workspaces, we only have their names. Not their IDs (since the
workspaces don’t actually exist yet).

To this the regression, we need to:

a) fallback to looking up workspaces by name. That is, if we fail to
  find one with a matching ID, try again using the workspace name. For
  _this_ to match, we also required the matched workspace to be a
  persistent workspace, with an ID < 0 (which essentially means the
  workspace doesn’t exist yet).

b) reset the ID to -1 when a persistent workspace is "deleted".

Closes #253
2022-12-28 15:21:46 +01:00
Daniel Eklöf
3ca274759a
module: const:ify ‘module’ argument to module->description() 2022-12-14 12:05:17 +01:00
Timur Celik
24a3b90a01
modules: Implement workspace move event
Implementing the move event required to pass the IPC socket to
`i3_ipc_callback_t`, because we won't get notified about any visibility
changes of other workspaces.  That's why we query all workspaces again
after a focused workspace was moved.
2022-12-13 16:21:55 +01:00
Timur Celik
8f89545b32
modules: Warn for all unknown workspace events 2022-12-13 16:19:11 +01:00
Timur Celik
bbd2394601
modules: Implement workspace rename event
A renamed workspace caused yambar to abort in a failed assertion,
because workspace lookup was done by name and the `rename` event was not
implemented.  To resolve this issue this patch implements the `rename`
event and as a necessity changes workspace_lookup() to use ids instead
of names.
2022-12-13 16:16:16 +01:00
Daniel Eklöf
b0e132beaf
module/i3: if a new workspace is created, but unfocused, assume it’s not empty
If a window is created on an unfocused workspace, yambar did not
update the empty tag correctly. At least not for persistent
workspaces.

This is because yambar relies on focus events to determine a
workspace's "empty" state. Since the new window, on the new workspace,
isn't focused, there's no focus event, and yambar thinks the workspace
is still empty.

This patch changes the logic slightly; a new workspace is considered
non-empty if it isn't focused (and has a non-zero node count).

Closes #191
2022-06-11 11:59:41 +02:00
Daniel Eklöf
4bb81e8940
modules: add SOCK_CLOEXEC to all socket() calls 2022-03-29 18:21:13 +02:00
Daniel Eklöf
c44970717b
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.
2022-02-15 21:14:08 +01:00
Daniel Eklöf
ca407cd166
module/i3: treat workspaces on the form N:name as numerical 2022-02-14 18:33:14 +01:00
Daniel Eklöf
a2cf05a64d
module/i3: add ‘strip-workspace-numbers’ option
This is a boolean option. When set, “N:” prefixes will be stripped
from the workspaces’ name tag, *after* having been sorted (if the
‘sort’ option is being used).

This makes it useful to arrange the workspaces in a fixed order, by
prefixing the names with a number in the Sway config:

  set $ws1 “1:xyz”
  set $ws2 “2:abc”

Then, in the yambar config:

  i3:
    sort: ascending
    strip-workspace-numbers: true
2022-02-11 21:44:43 +01:00
Daniel Eklöf
3e133d8618
module/i3: add ‘empty’ boolean tag
Set to true for empty (no windows) workspaces.

Mostly useful with persistent workspaces, to be able to differentiate
between invisible non-empty workspaces and actually empty
workspaces (the latter not being possible with non-persistent
workspaces).
2021-12-19 17:54:40 +01:00
Daniel Eklöf
f166bbbf54
modules: verify: use conf_verify_unsigned() for options that should be >= 0 2021-11-15 18:17:29 +01:00
Daniel Eklöf
7da13a26d0
module/i3: add ‘persistent’ attribute
Add ‘persistent’, a list-of-strings specifying workspace names that
should be persistent. That is, workspaces that should never be
removed, even if empty.

Note that the workspaces _are_ still destroyed (in i3/Sway), but
yambar keeps abstractions for them around. This is useful to e.g. keep
a strict order between your “core” workspaces.

Closes #72
2021-07-26 21:41:59 +02:00
Daniel Eklöf
ed2b8c4874
modules: implement description() 2021-06-20 21:15:24 +02:00
Daniel Eklöf
5bfa104935
module/i3: separate numerical workspace names from non-numerical
When sorting workspaces in ascending order, put numerical
workspaces *after* non-numerical ones.

When sorting in descending order, put numerical workspaces *before*
non-numerical.

In both cases, sort numerical workspaces using a numerical comparison,
rather that doing a lexicographical sorting.

Closes #30
2021-01-04 20:16:30 +01:00
Daniel Eklöf
3da796810b
module/i3: take lock while updating ‘mode’ 2020-12-12 22:42:19 +01:00
Daniel Eklöf
d9496152e3
module/i3: add new tag ‘mode’
This tag is a string: the name of the currently active mode
2020-12-12 22:42:17 +01:00
Daniel Eklöf
20df360937
module/i3: add option ‘sort’
Possible values: none, ascending, descending. Sorts the workspace list
accordingly. The default value is ‘none’.
2020-12-08 19:03:30 +01:00
Daniel Eklöf
d5fc1074d8
module/i3: revert to old behavior of not sorting workspaces
Sorting workspaces needs a config option.
2020-12-03 19:07:41 +01:00
Daniel Eklöf
678d82e4d4
module/i3: use a tllist for workspaces instead of a dynamic array 2020-12-03 18:31:42 +01:00
Daniel Eklöf
c3b3d6a637
module/i3: workaround 'workspace init' event being sent twice
Sway 1.4 sends two identical 'workspace init' events when a display is
plugged in.
2020-04-28 18:56:39 +02:00
Daniel Eklöf
1d24755f6b
module/i3: log errors when IPC replies/events are missing data 2020-01-24 21:27:07 +01:00
Daniel Eklöf
f4e456a0ad
module/i3: 'pid' is not a standard property of windows event
Don't fail (and terminate the i3 plugin) if we receive a window event
where the 'container' doesn't have a 'pid' property.

This means we won't be able to determine the application the window
belongs to.

Closes #2
2020-01-24 21:27:07 +01:00
Daniel Eklöf
9675b86478
module/i3: window event: use 'app_id' for 'application', if available
We previously used the 'pid' property of the 'container' object in a
window event to lookup the application name under /proc/<pid>/comm.

In many cases, the application name is already available in the window
event itself, in the 'app_id' property.

Use this, if available, and fallback to the old PID method otherwise.

A quick experiment suggests 'app_id' is set for all Wayland native
applications, but not for X11 applications running under XWayland.
2020-01-24 21:23:21 +01:00
Daniel Eklöf
86522d653d
modules: move 'content' and 'anchors' to MODULE_COMMON_ATTRS
All modules implement these. The only one that differs is the i3
module. It still implements them, but 'content' uses an internal
verifier function.
2020-01-24 21:08:39 +01:00
Daniel Eklöf
393e1909b7
module/i3: plug valgrind detected memory leak
Free previous 'application' string before replacing it with a new one.
2019-09-22 00:44:51 +02:00
Daniel Eklöf
7dc5694965 module/i3: use our own copy of i3/ipc.h
The main advantage is when targeting sway/wayland instead of i3/x11;
sway doesn't package ipc.h. There *is* an ipc.h in the sway sources,
but it doesn't define e.g the header format, and has different names
for the constants.
2019-03-31 12:08:44 +02:00
Daniel Eklöf
cd28099ad8 module/i3: don't try to strdup() a NULL pointer 2019-02-20 18:21:58 +01:00
Daniel Eklöf
b4845a55fe module/i3: remove even more IPC related json error messages 2019-02-17 21:53:01 +01:00
Daniel Eklöf
11eff5b13b module/i3: one more malformed IPC error message removed 2019-02-17 21:51:48 +01:00
Daniel Eklöf
fd955fa3ac module/i3: use json_object_object_get_ex()
json_object_object_get() is deprecated.

At the same time, simplify code by removing error messages; it's
not *our* problem if someone is sending malformed IPC replies.
2019-02-17 21:50:01 +01:00
Daniel Eklöf
546a4b5009 module/i3: improve window event handling
* Only care about 'close', 'focus' and 'title' events
* Remove application/title on 'close'
* Ignore 'title' events if it's not for the currently active
  window (from the last 'focus' event)

This fixes an issue where we rendered a 'title' event just like a
focus event. Meaning that a non-focused window, perhaps even on a
different workspace, that changed its title, would cause us to refresh
with its title being used.
2019-02-17 20:05:44 +01:00
Daniel Eklöf
620d89319b module/i3: reset current window info on a "floating" window event 2019-02-17 12:32:27 +01:00
Daniel Eklöf
ae7f554b8c module/i3: only call bar->refresh() from burst_done() callback
IPC reply and event handlers no longer call bar->refresh()
directly. Instead, they set a 'dirty' bit. Then, in burst_done(), we
call bar->refresh() when the dirty bit has been set.
2019-02-15 22:01:58 +01:00
Daniel Eklöf
5e97c77c24 module/i3: remove unneeded includes 2019-02-15 20:58:43 +01:00
Daniel Eklöf
fce37e86e4 module/i3: break out I3 IPC receive loop 2019-02-15 18:58:21 +01:00
Daniel Eklöf
92319714c7 module/i3: break out send_pkg() 2019-02-13 22:00:13 +01:00
Daniel Eklöf
37d15096f9 module/i3: break out get_socket_address() 2019-02-13 21:55:03 +01:00
Daniel Eklöf
6e44d8e04e module/i3: fix crash when there is no "current" workspace template 2019-02-13 21:46:30 +01:00
Daniel Eklöf
97ff63044f module/i3: cleanup 2019-02-10 12:29:33 +01:00
Daniel Eklöf
d631e47a5e module/i3: detect 'current' workspace while iterating workspaces 2019-02-10 12:29:33 +01:00
Daniel Eklöf
330ad48dfd module/i3: handle 'label' like an extra workspace called 'current' 2019-02-10 12:29:33 +01:00
Daniel Eklöf
a3be2839e5 module/i3: avoid calling json_object_get_int() multiple times 2019-02-10 12:29:33 +01:00
Daniel Eklöf
83db675e01 module/i3: subscribe *before* requesting initial workspace list
This ensures we don't have a race, where we might miss workspace
changes between the initial list and subscribing.
2019-02-10 12:29:33 +01:00
Daniel Eklöf
be4765fadd module/i3: 'dynlist' -> 'workspaces' 2019-02-10 12:29:33 +01:00
Daniel Eklöf
4100922b7a module/i3: allow 'content' to also contain a regular 'label'
Previously, the 'content' of i3 was a map, where the keys where i3
workspace names, mapping to a particle template.

Now, that configuration type is still allowed. But we also allow a
variant where the 'content' is a list, of either 1 or 2 entries.

Both entries *must* be dictionaries. The key is either 'dynlist',
which is the same as the dictionary-only type of
configuration. I.e. it maps to a dictionary where the keys are
workspace names, mapping to particle templates.

If the key is *not* dynlist, then it is assumed to be a particle name,
and we treat that as a "regular" label, that will be appended after
the workspace dynlist when instantiating the content.

This particle will be instantiated with, for now, the title and
application of the _currently focused_ workspace.
2019-02-10 12:29:33 +01:00