Add inhibit_fullscreen command

inhibit_fullscreen allows a container to service but ignore fullscreen
requests from clients. This allows clients to change to fullscreen mode
without changing dimensions of its container.
This commit is contained in:
Kenny Levinsen 2019-06-15 20:02:17 +02:00 committed by Pedro Côrte-Real
parent 45aa5c104c
commit ab58edfc90
8 changed files with 92 additions and 10 deletions

View file

@ -135,6 +135,7 @@ sway_cmd cmd_fullscreen;
sway_cmd cmd_gaps; sway_cmd cmd_gaps;
sway_cmd cmd_hide_edge_borders; sway_cmd cmd_hide_edge_borders;
sway_cmd cmd_include; sway_cmd cmd_include;
sway_cmd cmd_inhibit_fullscreen;
sway_cmd cmd_inhibit_idle; sway_cmd cmd_inhibit_idle;
sway_cmd cmd_input; sway_cmd cmd_input;
sway_cmd cmd_seat; sway_cmd cmd_seat;

View file

@ -108,6 +108,9 @@ struct sway_container {
enum sway_fullscreen_mode fullscreen_mode; enum sway_fullscreen_mode fullscreen_mode;
bool inhibit_fullscreen;
bool is_fullscreen;
enum sway_container_border border; enum sway_container_border border;
// Used when the view changes to CSD unexpectedly. This will be a non-B_CSD // Used when the view changes to CSD unexpectedly. This will be a non-B_CSD
@ -269,6 +272,8 @@ void container_end_mouse_operation(struct sway_container *container);
void container_set_fullscreen(struct sway_container *con, void container_set_fullscreen(struct sway_container *con,
enum sway_fullscreen_mode mode); enum sway_fullscreen_mode mode);
void container_request_fullscreen(struct sway_container *con, bool enable);
/** /**
* Convenience function. * Convenience function.
*/ */

View file

@ -114,6 +114,7 @@ static struct cmd_handler command_handlers[] = {
{ "exit", cmd_exit }, { "exit", cmd_exit },
{ "floating", cmd_floating }, { "floating", cmd_floating },
{ "fullscreen", cmd_fullscreen }, { "fullscreen", cmd_fullscreen },
{ "inhibit_fullscreen", cmd_inhibit_fullscreen },
{ "inhibit_idle", cmd_inhibit_idle }, { "inhibit_idle", cmd_inhibit_idle },
{ "kill", cmd_kill }, { "kill", cmd_kill },
{ "layout", cmd_layout }, { "layout", cmd_layout },

View file

@ -0,0 +1,45 @@
#include <strings.h>
#include "log.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/view.h"
#include "sway/tree/workspace.h"
#include "util.h"
// inhibit_fullscreen [toggle|enable|disable]
struct cmd_results *cmd_inhibit_fullscreen(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "inhibit_fullscreen", EXPECTED_EQUAL_TO, 1))) {
return error;
}
if (!root->outputs->length) {
return cmd_results_new(CMD_FAILURE,
"Can't run this command while there's no outputs connected.");
}
struct sway_node *node = config->handler_context.node;
struct sway_container *container = config->handler_context.container;
struct sway_workspace *workspace = config->handler_context.workspace;
if (node->type == N_WORKSPACE && workspace->tiling->length == 0) {
return cmd_results_new(CMD_FAILURE,
"Can't fullscreen an empty workspace");
}
// If in the scratchpad, operate on the highest container
if (container && !container->workspace) {
while (container->parent) {
container = container->parent;
}
}
bool enable = false;
if (strcasecmp(argv[0], "toggle") == 0) {
enable = !container->inhibit_fullscreen;
} else {
enable = strcasecmp(argv[0], "enable") == 0;
}
container->inhibit_fullscreen = enable;
return cmd_results_new(CMD_SUCCESS, NULL);
}

View file

@ -363,7 +363,7 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
} }
} }
container_set_fullscreen(view->container, e->fullscreen); container_request_fullscreen(view->container, e->fullscreen);
arrange_root(); arrange_root();
transaction_commit_dirty(); transaction_commit_dirty();

View file

@ -65,6 +65,7 @@ sway_sources = files(
'commands/fullscreen.c', 'commands/fullscreen.c',
'commands/gaps.c', 'commands/gaps.c',
'commands/hide_edge_borders.c', 'commands/hide_edge_borders.c',
'commands/inhibit_fullscreen.c',
'commands/inhibit_idle.c', 'commands/inhibit_idle.c',
'commands/kill.c', 'commands/kill.c',
'commands/mark.c', 'commands/mark.c',

View file

@ -161,6 +161,12 @@ set|plus|minus <amount>
_right_, _bottom_, and _left_ or per direction with _horizontal_ and _right_, _bottom_, and _left_ or per direction with _horizontal_ and
_vertical_. _vertical_.
*inhibit_fullscreen* toggle|enable|disable
Set/unset fullscreen inhibitor for for the container. If enabled, client
requests to fullscreen the container will be ignored. This can be used to
have clients transition to their fullscreen interface, while still
constraining them to their container.
*inhibit_idle* focus|fullscreen|open|none|visible *inhibit_idle* focus|fullscreen|open|none|visible
Set/unset an idle inhibitor for the view. _focus_ will inhibit idle when Set/unset an idle inhibitor for the view. _focus_ will inhibit idle when
the view is focused by any seat. _fullscreen_ will inhibit idle when the the view is focused by any seat. _fullscreen_ will inhibit idle when the

View file

@ -990,9 +990,11 @@ static void container_fullscreen_workspace(struct sway_container *con) {
"Expected a non-fullscreen container")) { "Expected a non-fullscreen container")) {
return; return;
} }
if (!con->inhibit_fullscreen) {
bool enable = true; bool enable = true;
set_fullscreen_iterator(con, &enable); set_fullscreen_iterator(con, &enable);
container_for_each_child(con, set_fullscreen_iterator, &enable); container_for_each_child(con, set_fullscreen_iterator, &enable);
}
con->saved_x = con->x; con->saved_x = con->x;
con->saved_y = con->y; con->saved_y = con->y;
@ -1017,6 +1019,7 @@ static void container_fullscreen_workspace(struct sway_container *con) {
} }
con->fullscreen_mode = FULLSCREEN_WORKSPACE; con->fullscreen_mode = FULLSCREEN_WORKSPACE;
con->is_fullscreen = true;
container_end_mouse_operation(con); container_end_mouse_operation(con);
ipc_event_window(con, "fullscreen_mode"); ipc_event_window(con, "fullscreen_mode");
} }
@ -1026,9 +1029,11 @@ static void container_fullscreen_global(struct sway_container *con) {
"Expected a non-fullscreen container")) { "Expected a non-fullscreen container")) {
return; return;
} }
if (!con->inhibit_fullscreen) {
bool enable = true; bool enable = true;
set_fullscreen_iterator(con, &enable); set_fullscreen_iterator(con, &enable);
container_for_each_child(con, set_fullscreen_iterator, &enable); container_for_each_child(con, set_fullscreen_iterator, &enable);
}
root->fullscreen_global = con; root->fullscreen_global = con;
con->saved_x = con->x; con->saved_x = con->x;
@ -1045,6 +1050,7 @@ static void container_fullscreen_global(struct sway_container *con) {
} }
con->fullscreen_mode = FULLSCREEN_GLOBAL; con->fullscreen_mode = FULLSCREEN_GLOBAL;
con->is_fullscreen = true;
container_end_mouse_operation(con); container_end_mouse_operation(con);
ipc_event_window(con, "fullscreen_mode"); ipc_event_window(con, "fullscreen_mode");
} }
@ -1054,9 +1060,11 @@ void container_fullscreen_disable(struct sway_container *con) {
"Expected a fullscreen container")) { "Expected a fullscreen container")) {
return; return;
} }
if (!con->inhibit_fullscreen) {
bool enable = false; bool enable = false;
set_fullscreen_iterator(con, &enable); set_fullscreen_iterator(con, &enable);
container_for_each_child(con, set_fullscreen_iterator, &enable); container_for_each_child(con, set_fullscreen_iterator, &enable);
}
if (container_is_floating(con)) { if (container_is_floating(con)) {
con->x = con->saved_x; con->x = con->saved_x;
@ -1088,6 +1096,7 @@ void container_fullscreen_disable(struct sway_container *con) {
} }
con->fullscreen_mode = FULLSCREEN_NONE; con->fullscreen_mode = FULLSCREEN_NONE;
con->is_fullscreen = false;
container_end_mouse_operation(con); container_end_mouse_operation(con);
ipc_event_window(con, "fullscreen_mode"); ipc_event_window(con, "fullscreen_mode");
@ -1134,6 +1143,20 @@ void container_set_fullscreen(struct sway_container *con,
} }
} }
void container_request_fullscreen(struct sway_container *con, bool enable) {
if (con->inhibit_fullscreen) {
set_fullscreen_iterator(con, &enable);
container_for_each_child(con, set_fullscreen_iterator, &enable);
if (con->workspace) {
arrange_workspace(con->workspace);
}
con->is_fullscreen = enable;
return;
}
container_set_fullscreen(con, enable);
}
struct sway_container *container_toplevel_ancestor( struct sway_container *container_toplevel_ancestor(
struct sway_container *container) { struct sway_container *container) {
while (container->parent) { while (container->parent) {