aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrestis Floros <orestisflo@gmail.com>2022-12-14 14:24:05 +0100
committerGitHub <noreply@github.com>2022-12-14 14:24:05 +0100
commited690c7ba0f3d4e972ebd5a40acf964f7b939754 (patch)
tree877f81e7a479295091e1f0b7c5b2f8d0712c0452
parent1786b13f0dfd6280fc9111576e2fa4869091e773 (diff)
parentd5c8319b6c5a93d32658c22792ca3fc5422937b2 (diff)
downloadi3-ed690c7ba0f3d4e972ebd5a40acf964f7b939754.tar.gz
i3-ed690c7ba0f3d4e972ebd5a40acf964f7b939754.zip
Merge pull request #5324 from orestisfl/5323/mode-in-binding-event
Add "mode" field in binding event
-rw-r--r--docs/ipc2
-rw-r--r--include/ipc.h2
-rw-r--r--release-notes/changes/4-mode-in-binding-event1
-rw-r--r--src/bindings.c6
-rw-r--r--src/ipc.c9
-rw-r--r--testcases/t/238-ipc-binding-event.t25
6 files changed, 41 insertions, 4 deletions
diff --git a/docs/ipc b/docs/ipc
index c9fee469..8d8bdfa5 100644
--- a/docs/ipc
+++ b/docs/ipc
@@ -1099,6 +1099,8 @@ binding that ran a command because of user input. The +change (string)+ field
indicates what sort of binding event was triggered (right now it will always be
+"run"+ but may be expanded in the future).
+The +mode (string)+ field contains the name of the mode the binding was run in.
+
The +binding (object)+ field contains details about the binding that was run:
command (string)::
diff --git a/include/ipc.h b/include/ipc.h
index 732fa9b4..e85e6081 100644
--- a/include/ipc.h
+++ b/include/ipc.h
@@ -133,7 +133,7 @@ void ipc_send_barconfig_update_event(Barconfig *barconfig);
/**
* For the binding events, we send the serialized binding struct.
*/
-void ipc_send_binding_event(const char *event_type, Binding *bind);
+void ipc_send_binding_event(const char *event_type, Binding *bind, const char *modename);
/**
* Set the maximum duration that we allow for a connection with an unwriteable
diff --git a/release-notes/changes/4-mode-in-binding-event b/release-notes/changes/4-mode-in-binding-event
new file mode 100644
index 00000000..e06014d3
--- /dev/null
+++ b/release-notes/changes/4-mode-in-binding-event
@@ -0,0 +1 @@
+add "mode" field in binding event
diff --git a/src/bindings.c b/src/bindings.c
index 0aa960d3..4cb916fa 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -843,6 +843,10 @@ CommandResult *run_binding(Binding *bind, Con *con) {
sasprintf(&command, "[con_id=\"%p\"] %s", con, bind->command);
Binding *bind_cp = binding_copy(bind);
+ /* The "mode" command might change the current mode, so back it up to
+ * correctly produce an event later. */
+ const char *modename = current_binding_mode;
+
CommandResult *result = parse_command(command, NULL, NULL);
free(command);
@@ -868,7 +872,7 @@ CommandResult *run_binding(Binding *bind, Con *con) {
free(pageraction);
}
- ipc_send_binding_event("run", bind_cp);
+ ipc_send_binding_event("run", bind_cp, modename);
binding_free(bind_cp);
return result;
diff --git a/src/ipc.c b/src/ipc.c
index 86ff45de..f69ba2ae 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -1678,7 +1678,7 @@ void ipc_send_barconfig_update_event(Barconfig *barconfig) {
/*
* For the binding events, we send the serialized binding struct.
*/
-void ipc_send_binding_event(const char *event_type, Binding *bind) {
+void ipc_send_binding_event(const char *event_type, Binding *bind, const char *modename) {
DLOG("Issue IPC binding %s event (sym = %s, code = %d)\n", event_type, bind->symbol, bind->keycode);
setlocale(LC_NUMERIC, "C");
@@ -1690,6 +1690,13 @@ void ipc_send_binding_event(const char *event_type, Binding *bind) {
ystr("change");
ystr(event_type);
+ ystr("mode");
+ if (modename == NULL) {
+ ystr("default");
+ } else {
+ ystr(modename);
+ }
+
ystr("binding");
dump_binding(gen, bind);
diff --git a/testcases/t/238-ipc-binding-event.t b/testcases/t/238-ipc-binding-event.t
index bec95a23..6916593d 100644
--- a/testcases/t/238-ipc-binding-event.t
+++ b/testcases/t/238-ipc-binding-event.t
@@ -16,6 +16,7 @@
#
# Test that the binding event works properly
# Ticket: #1210
+# Ticket: #5323
use i3test i3_autostart => 0;
my $keysym = 't';
@@ -28,6 +29,12 @@ my $config = <<EOT;
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
bindsym $binding_symbol $command
+
+bindsym m mode some-mode
+mode some-mode {
+ bindsym a nop
+ bindsym b mode default
+}
EOT
SKIP: {
@@ -46,12 +53,13 @@ SKIP: {
qx(xdotool key $binding_symbol);
},
'binding');
-
is(scalar @events, 1, 'Received 1 event');
is($events[0]->{change}, 'run',
'the `change` field should indicate this binding has run');
+ is($events[0]->{mode}, 'default', 'the `mode` field should be "default"');
+
ok($events[0]->{binding},
'the `binding` field should be a hash that contains information about the binding');
@@ -69,6 +77,21 @@ SKIP: {
is($events[0]->{binding}->{input_code}, 0,
'the input_code should be the specified code if the key was bound with bindcode, and otherwise zero');
+ # Test that the mode field is correct
+ # See #5323.
+ @events = events_for(
+ sub {
+ qx(xdotool key m);
+ qx(xdotool key a);
+ qx(xdotool key b);
+ },
+ 'binding');
+ is(scalar @events, 3, 'Received 3 events');
+
+ is($events[0]->{mode}, 'default', 'Event for binding to enter new mode is atributed to default mode');
+ is($events[1]->{mode}, 'some-mode', 'Event for binding while in mode is attributed to the non-default mode');
+ is($events[2]->{mode}, 'some-mode', 'Event for binding exiting mode is attributed to the non-default mode');
+
exit_gracefully($pid);
}