Introduce GET_BINDING_STATE IPC command
fixes #3892
Michael Stapelberg
3 years ago
100 | 100 |
use constant TYPE_GET_CONFIG => 9;
|
101 | 101 |
use constant TYPE_SEND_TICK => 10;
|
102 | 102 |
use constant TYPE_SYNC => 11;
|
|
103 |
use constant TYPE_GET_BINDING_STATE => 12;
|
103 | 104 |
|
104 | 105 |
our %EXPORT_TAGS = ( 'all' => [
|
105 | 106 |
qw(i3 TYPE_RUN_COMMAND TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS
|
106 | 107 |
TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG TYPE_GET_VERSION
|
107 | |
TYPE_GET_BINDING_MODES TYPE_GET_CONFIG TYPE_SEND_TICK TYPE_SYNC)
|
|
108 |
TYPE_GET_BINDING_MODES TYPE_GET_CONFIG TYPE_SEND_TICK TYPE_SYNC
|
|
109 |
TYPE_GET_BINDING_STATE)
|
108 | 110 |
] );
|
109 | 111 |
|
110 | 112 |
our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } );
|
65 | 65 |
| 9 | +GET_CONFIG+ | <<_config_reply,CONFIG>> | Returns the last loaded i3 config.
|
66 | 66 |
| 10 | +SEND_TICK+ | <<_tick_reply,TICK>> | Sends a tick event with the specified payload.
|
67 | 67 |
| 11 | +SYNC+ | <<_sync_reply,SYNC>> | Sends an i3 sync event with the specified random value to the specified window.
|
|
68 |
| 12 | +GET_BINDING_STATE+ | <<_binding_state_reply,BINDING_STATE>> | Request the current binding state, e.g. the currently active binding mode name.
|
68 | 69 |
|======================================================
|
69 | 70 |
|
70 | 71 |
So, a typical message could look like this:
|
|
130 | 131 |
Reply to the GET_CONFIG message.
|
131 | 132 |
TICK (10)::
|
132 | 133 |
Reply to the SEND_TICK message.
|
|
134 |
GET_BINDING_STATE (12)::
|
|
135 |
Reply to the GET_BINDING_STATE message.
|
133 | 136 |
|
134 | 137 |
[[_command_reply]]
|
135 | 138 |
=== COMMAND reply
|
|
708 | 711 |
{ "success": true }
|
709 | 712 |
-------------------
|
710 | 713 |
|
|
714 |
[[_binding_state_reply]]
|
|
715 |
=== GET_BINDING_STATE reply
|
|
716 |
|
|
717 |
The binding_state reply is a map which currently only contains the "name"
|
|
718 |
member, which is the name of the currently active binding mode as a string.
|
|
719 |
|
|
720 |
*Example:*
|
|
721 |
-------------------
|
|
722 |
{ "name": "default" }
|
|
723 |
-------------------
|
|
724 |
|
711 | 725 |
== Events
|
712 | 726 |
|
713 | 727 |
[[events]]
|
65 | 65 |
/** Trigger an i3 sync protocol message via IPC. */
|
66 | 66 |
#define I3_IPC_MESSAGE_TYPE_SYNC 11
|
67 | 67 |
|
|
68 |
/** Request the current binding state. */
|
|
69 |
#define I3_IPC_MESSAGE_TYPE_GET_BINDING_STATE 12
|
|
70 |
|
68 | 71 |
/*
|
69 | 72 |
* Messages from i3 to clients
|
70 | 73 |
*
|
|
81 | 84 |
#define I3_IPC_REPLY_TYPE_CONFIG 9
|
82 | 85 |
#define I3_IPC_REPLY_TYPE_TICK 10
|
83 | 86 |
#define I3_IPC_REPLY_TYPE_SYNC 11
|
|
87 |
#define I3_IPC_REPLY_TYPE_GET_BINDING_STATE 12
|
84 | 88 |
|
85 | 89 |
/*
|
86 | 90 |
* Events from i3 to clients. Events have the first bit set high.
|
57 | 57 |
extern Display *xlibdpy, *xkbdpy;
|
58 | 58 |
extern int xkb_current_group;
|
59 | 59 |
extern TAILQ_HEAD(bindings_head, Binding) * bindings;
|
|
60 |
extern const char *current_binding_mode;
|
60 | 61 |
extern TAILQ_HEAD(autostarts_head, Autostart) autostarts;
|
61 | 62 |
extern TAILQ_HEAD(autostarts_always_head, Autostart) autostarts_always;
|
62 | 63 |
extern TAILQ_HEAD(ws_assignments_head, Workspace_Assignment) ws_assignments;
|
173 | 173 |
SLIST_INSERT_HEAD(&modes, default_mode, modes);
|
174 | 174 |
|
175 | 175 |
bindings = default_mode->bindings;
|
|
176 |
current_binding_mode = default_mode->name;
|
176 | 177 |
|
177 | 178 |
/* Clear the old config or initialize the data structure */
|
178 | 179 |
memset(&config, 0, sizeof(config));
|
1336 | 1336 |
ipc_send_client_message(client, strlen(reply), I3_IPC_REPLY_TYPE_SYNC, (const uint8_t *)reply);
|
1337 | 1337 |
}
|
1338 | 1338 |
|
|
1339 |
IPC_HANDLER(get_binding_state) {
|
|
1340 |
yajl_gen gen = ygenalloc();
|
|
1341 |
|
|
1342 |
y(map_open);
|
|
1343 |
|
|
1344 |
ystr("name");
|
|
1345 |
ystr(current_binding_mode);
|
|
1346 |
|
|
1347 |
y(map_close);
|
|
1348 |
|
|
1349 |
const unsigned char *payload;
|
|
1350 |
ylength length;
|
|
1351 |
y(get_buf, &payload, &length);
|
|
1352 |
|
|
1353 |
ipc_send_client_message(client, length, I3_IPC_REPLY_TYPE_GET_BINDING_STATE, payload);
|
|
1354 |
y(free);
|
|
1355 |
}
|
|
1356 |
|
1339 | 1357 |
/* The index of each callback function corresponds to the numeric
|
1340 | 1358 |
* value of the message type (see include/i3/ipc.h) */
|
1341 | |
handler_t handlers[12] = {
|
|
1359 |
handler_t handlers[13] = {
|
1342 | 1360 |
handle_run_command,
|
1343 | 1361 |
handle_get_workspaces,
|
1344 | 1362 |
handle_subscribe,
|
|
1351 | 1369 |
handle_get_config,
|
1352 | 1370 |
handle_send_tick,
|
1353 | 1371 |
handle_sync,
|
|
1372 |
handle_get_binding_state,
|
1354 | 1373 |
};
|
1355 | 1374 |
|
1356 | 1375 |
/*
|
78 | 78 |
|
79 | 79 |
/* The list of key bindings */
|
80 | 80 |
struct bindings_head *bindings;
|
|
81 |
const char *current_binding_mode = NULL;
|
81 | 82 |
|
82 | 83 |
/* The list of exec-lines */
|
83 | 84 |
struct autostarts_head autostarts = TAILQ_HEAD_INITIALIZER(autostarts);
|
|
0 |
#!perl
|
|
1 |
# vim:ts=4:sw=4:expandtab
|
|
2 |
#
|
|
3 |
# Please read the following documents before working on tests:
|
|
4 |
# • https://build.i3wm.org/docs/testsuite.html
|
|
5 |
# (or docs/testsuite)
|
|
6 |
#
|
|
7 |
# • https://build.i3wm.org/docs/lib-i3test.html
|
|
8 |
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
9 |
#
|
|
10 |
# • https://build.i3wm.org/docs/ipc.html
|
|
11 |
# (or docs/ipc)
|
|
12 |
#
|
|
13 |
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
|
14 |
# (unless you are already familiar with Perl)
|
|
15 |
#
|
|
16 |
# Verifies the GET_BINDING_MODE IPC command
|
|
17 |
# Ticket: #3892
|
|
18 |
# Bug still in: 4.18-318-g50160eb1
|
|
19 |
use i3test i3_config => <<EOT;
|
|
20 |
# i3 config file (v4)
|
|
21 |
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
|
22 |
|
|
23 |
mode "extra" {
|
|
24 |
bindsym Mod1+x nop foo
|
|
25 |
}
|
|
26 |
EOT
|
|
27 |
|
|
28 |
my $i3 = i3(get_socket_path());
|
|
29 |
$i3->connect->recv;
|
|
30 |
# TODO: use the symbolic name for the command/reply type instead of the
|
|
31 |
# numerical 12:
|
|
32 |
my $binding_state = $i3->message(12, "")->recv;
|
|
33 |
is($binding_state->{name}, 'default', 'at startup, binding mode is default');
|
|
34 |
|
|
35 |
cmd 'mode extra';
|
|
36 |
|
|
37 |
$binding_state = $i3->message(12, "")->recv;
|
|
38 |
is($binding_state->{name}, 'extra', 'after switching, binding mode is extra');
|
|
39 |
|
|
40 |
done_testing;
|