Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'vanilla/next' into gaps-next
  • Loading branch information
Airblader committed Jun 10, 2020
2 parents 93e799c + cf09cc7 commit 9bc3f9c
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 6 deletions.
4 changes: 3 additions & 1 deletion AnyEvent-I3/lib/AnyEvent/I3.pm
Expand Up @@ -101,11 +101,13 @@ use constant TYPE_GET_BINDING_MODES => 8;
use constant TYPE_GET_CONFIG => 9;
use constant TYPE_SEND_TICK => 10;
use constant TYPE_SYNC => 11;
use constant TYPE_GET_BINDING_STATE => 12;

our %EXPORT_TAGS = ( 'all' => [
qw(i3 TYPE_RUN_COMMAND TYPE_COMMAND TYPE_GET_WORKSPACES TYPE_SUBSCRIBE TYPE_GET_OUTPUTS
TYPE_GET_TREE TYPE_GET_MARKS TYPE_GET_BAR_CONFIG TYPE_GET_VERSION
TYPE_GET_BINDING_MODES TYPE_GET_CONFIG TYPE_SEND_TICK TYPE_SYNC)
TYPE_GET_BINDING_MODES TYPE_GET_CONFIG TYPE_SEND_TICK TYPE_SYNC
TYPE_GET_BINDING_STATE)
] );

our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } );
Expand Down
1 change: 1 addition & 0 deletions RELEASE-NOTES-next
Expand Up @@ -43,3 +43,4 @@ working. Please reach out to us in that case!
• build: fix issues with parallel build
• set _NET_DESKTOP_VIEWPORT after randr changes
• fix a bug with i3-nagbar not starting after it has already started once
• fix conflict when moving parent of fullscreen window to workspace
14 changes: 14 additions & 0 deletions docs/ipc
Expand Up @@ -66,6 +66,7 @@ to do that).
| 9 | +GET_CONFIG+ | <<_config_reply,CONFIG>> | Returns the last loaded i3 config.
| 10 | +SEND_TICK+ | <<_tick_reply,TICK>> | Sends a tick event with the specified payload.
| 11 | +SYNC+ | <<_sync_reply,SYNC>> | Sends an i3 sync event with the specified random value to the specified window.
| 12 | +GET_BINDING_STATE+ | <<_binding_state_reply,BINDING_STATE>> | Request the current binding state, e.g. the currently active binding mode name.
|======================================================

So, a typical message could look like this:
Expand Down Expand Up @@ -131,6 +132,8 @@ GET_CONFIG (9)::
Reply to the GET_CONFIG message.
TICK (10)::
Reply to the SEND_TICK message.
GET_BINDING_STATE (12)::
Reply to the GET_BINDING_STATE message.

[[_command_reply]]
=== COMMAND reply
Expand Down Expand Up @@ -709,6 +712,17 @@ responded to.
{ "success": true }
-------------------

[[_binding_state_reply]]
=== GET_BINDING_STATE reply

The binding_state reply is a map which currently only contains the "name"
member, which is the name of the currently active binding mode as a string.

*Example:*
-------------------
{ "name": "default" }
-------------------

== Events

[[events]]
Expand Down
1 change: 1 addition & 0 deletions include/i3.h
Expand Up @@ -58,6 +58,7 @@ extern char **start_argv;
extern Display *xlibdpy, *xkbdpy;
extern int xkb_current_group;
extern TAILQ_HEAD(bindings_head, Binding) * bindings;
extern const char *current_binding_mode;
extern TAILQ_HEAD(autostarts_head, Autostart) autostarts;
extern TAILQ_HEAD(autostarts_always_head, Autostart) autostarts_always;
extern TAILQ_HEAD(ws_assignments_head, Workspace_Assignment) ws_assignments;
Expand Down
4 changes: 4 additions & 0 deletions include/i3/ipc.h
Expand Up @@ -66,6 +66,9 @@ typedef struct i3_ipc_header {
/** Trigger an i3 sync protocol message via IPC. */
#define I3_IPC_MESSAGE_TYPE_SYNC 11

/** Request the current binding state. */
#define I3_IPC_MESSAGE_TYPE_GET_BINDING_STATE 12

/*
* Messages from i3 to clients
*
Expand All @@ -82,6 +85,7 @@ typedef struct i3_ipc_header {
#define I3_IPC_REPLY_TYPE_CONFIG 9
#define I3_IPC_REPLY_TYPE_TICK 10
#define I3_IPC_REPLY_TYPE_SYNC 11
#define I3_IPC_REPLY_TYPE_GET_BINDING_STATE 12

/*
* Events from i3 to clients. Events have the first bit set high.
Expand Down
9 changes: 7 additions & 2 deletions meson.build
Expand Up @@ -611,13 +611,19 @@ complete_run = custom_target(
output: ['complete-run.pl'],
capture: true,
command: replace_dirs,
# build this target when running e.g. ninja or ninja test.
# This is required for older meson versions (< 0.46.0).
build_by_default: true,
)
i3test_pm = custom_target(
'i3test-pm',
input: ['testcases/lib/i3test.pm.in'],
output: ['i3test.pm'],
capture: true,
command: replace_dirs,
# build this target when running e.g. ninja or ninja test.
# This is required for older meson versions (< 0.46.0).
build_by_default: true,
)

if get_option('docs')
Expand Down Expand Up @@ -694,9 +700,8 @@ if meson.version().version_compare('>=0.46.0')
perl,
args: [complete_run],
depends: [
# i3test.pm is generated at meson configure time,
# so no explicit dependency is required.
anyevent_i3,
i3test_pm,
],
)
else
Expand Down
1 change: 1 addition & 0 deletions src/bindings.c
Expand Up @@ -628,6 +628,7 @@ void switch_mode(const char *new_mode) {

ungrab_all_keys(conn);
bindings = mode->bindings;
current_binding_mode = mode->name;
translate_keysyms();
grab_all_keys(conn);

Expand Down
12 changes: 10 additions & 2 deletions src/con.c
Expand Up @@ -1261,9 +1261,17 @@ static bool _con_move_to_con(Con *con, Con *target, bool behind_focused, bool fi
}

/* If moving a fullscreen container and the destination already has a
* fullscreen window on it, un-fullscreen the target's fullscreen con. */
* fullscreen window on it, un-fullscreen the target's fullscreen con.
* con->fullscreen_mode is not enough in some edge cases:
* 1. con is CT_FLOATING_CON, child is fullscreen.
* 2. con is the parent of a fullscreen container, can be triggered by
* moving the parent with command criteria.
*/
Con *fullscreen = con_get_fullscreen_con(target_ws, CF_OUTPUT);
if (con->fullscreen_mode != CF_NONE && fullscreen != NULL) {
const bool con_has_fullscreen = con->fullscreen_mode != CF_NONE ||
con_get_fullscreen_con(con, CF_GLOBAL) ||
con_get_fullscreen_con(con, CF_OUTPUT);
if (con_has_fullscreen && fullscreen != NULL) {
con_toggle_fullscreen(fullscreen, CF_OUTPUT);
fullscreen = NULL;
}
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Expand Up @@ -174,6 +174,7 @@ bool load_configuration(const char *override_configpath, config_load_t load_type
SLIST_INSERT_HEAD(&modes, default_mode, modes);

bindings = default_mode->bindings;
current_binding_mode = default_mode->name;

/* Clear the old config or initialize the data structure */
memset(&config, 0, sizeof(config));
Expand Down
21 changes: 20 additions & 1 deletion src/ipc.c
Expand Up @@ -1366,9 +1366,27 @@ IPC_HANDLER(sync) {
ipc_send_client_message(client, strlen(reply), I3_IPC_REPLY_TYPE_SYNC, (const uint8_t *)reply);
}

IPC_HANDLER(get_binding_state) {
yajl_gen gen = ygenalloc();

y(map_open);

ystr("name");
ystr(current_binding_mode);

y(map_close);

const unsigned char *payload;
ylength length;
y(get_buf, &payload, &length);

ipc_send_client_message(client, length, I3_IPC_REPLY_TYPE_GET_BINDING_STATE, payload);
y(free);
}

/* The index of each callback function corresponds to the numeric
* value of the message type (see include/i3/ipc.h) */
handler_t handlers[12] = {
handler_t handlers[13] = {
handle_run_command,
handle_get_workspaces,
handle_subscribe,
Expand All @@ -1381,6 +1399,7 @@ handler_t handlers[12] = {
handle_get_config,
handle_send_tick,
handle_sync,
handle_get_binding_state,
};

/*
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Expand Up @@ -79,6 +79,7 @@ const int default_shmlog_size = 25 * 1024 * 1024;

/* The list of key bindings */
struct bindings_head *bindings;
const char *current_binding_mode = NULL;

/* The list of exec-lines */
struct autostarts_head autostarts = TAILQ_HEAD_INITIALIZER(autostarts);
Expand Down
47 changes: 47 additions & 0 deletions testcases/t/132-move-workspace.t
Expand Up @@ -339,6 +339,53 @@ $ws = get_ws($tmp2);
is_num_children($tmp2, 0, 'no regular nodes on second workspace');
is(@{$ws->{floating_nodes}}, 1, 'one floating node on second workspace');

###################################################################
# Test that when moving a fullscreen floating window to a workspace
# that already has an other fullscreen container, the second
# container gets un-fullscreened.
# See #4124
###################################################################
$tmp2 = fresh_workspace;
$second = open_window;
cmd 'fullscreen enable';
$ws = get_ws($tmp2);
is($ws->{nodes}->[0]->{fullscreen_mode}, 1, 'sanity check: fullscreen enabled');

$tmp = fresh_workspace;
$first = open_window;
cmd 'floating enable, fullscreen enable';
cmd "move workspace $tmp2";

$ws = get_ws($tmp2);
is_num_children($tmp2, 1, 'one regular node on second workspace');
is_num_fullscreen($tmp2, 1, 'one fullscreen node on second workspace');
is(@{$ws->{floating_nodes}}, 1, 'one floating node on second workspace');
is($ws->{nodes}->[0]->{fullscreen_mode}, 0, 'previous fullscreen disabled');

###################################################################
# Same as above, but trigger the bug with the parent of a
# fullscreen container, instead of a CT_FLOATING_CON.
###################################################################
$tmp2 = fresh_workspace;
$second = open_window;
cmd 'fullscreen enable';
$ws = get_ws($tmp2);
is($ws->{nodes}->[0]->{fullscreen_mode}, 1, 'sanity check: fullscreen enabled');

$tmp = fresh_workspace;
open_window;
$first = open_window;
cmd 'layout tabbed';
cmd 'focus parent, mark a, focus child';
cmd 'fullscreen enable';
cmd "[con_mark=a] move workspace $tmp2";

$ws = get_ws($tmp2);
is(sum_nodes(get_ws_content($tmp2)), 4, '3 leafs & 1 split node in second workspace');
# is_num_fullscreen does not catch this nested fullscreen container
is($ws->{nodes}->[0]->{fullscreen_mode}, 0, 'previous fullscreen disabled');
is($ws->{nodes}->[1]->{nodes}->[1]->{fullscreen_mode}, 1, 'nested fullscreen from moved container preserved');

###################################################################
# Check that moving an empty workspace using criteria doesn't
# create unfocused empty workspace.
Expand Down
41 changes: 41 additions & 0 deletions testcases/t/311-get-binding-modes.t
@@ -0,0 +1,41 @@
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
# (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
# (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
# (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
# (unless you are already familiar with Perl)
#
# Verifies the GET_BINDING_MODE IPC command
# Ticket: #3892
# Bug still in: 4.18-318-g50160eb1
use i3test i3_config => <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
mode "extra" {
bindsym Mod1+x nop foo
}
EOT

my $i3 = i3(get_socket_path());
$i3->connect->recv;
# TODO: use the symbolic name for the command/reply type instead of the
# numerical 12:
my $binding_state = $i3->message(12, "")->recv;
is($binding_state->{name}, 'default', 'at startup, binding mode is default');

cmd 'mode extra';

$binding_state = $i3->message(12, "")->recv;
is($binding_state->{name}, 'extra', 'after switching, binding mode is extra');

done_testing;

0 comments on commit 9bc3f9c

Please sign in to comment.