swayfx/sway/commands/fullscreen.c
Calvin Lee 069d37f987 Improve criteria handling
This commit changes how commands decide what container to act on.
Commands get the current container though `current_container`, a global
defined in sway/commands.c. If a criteria is given before a command,
then the following command will be run once for every container the
criteria matches with a reference to the matching container in
'current_container'. Commands should use this instead of
`get_focused_container()` from now on.

This commit also fixes a few (minor) mistakes made in implementing marks
such as non-escaped arrows in sway(5) and calling the "mark" command
"floating" by accident. It also cleans up `criteria.c` in a few places.
2017-04-05 22:07:23 -06:00

61 lines
1.9 KiB
C

#include <stdbool.h>
#include <string.h>
#include <wlc/wlc.h>
#include "sway/commands.h"
#include "sway/container.h"
#include "sway/focus.h"
#include "sway/ipc-server.h"
#include "sway/layout.h"
struct cmd_results *cmd_fullscreen(int argc, char **argv) {
struct cmd_results *error = NULL;
if (config->reading) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can't be used in config file.");
if (!config->active) return cmd_results_new(CMD_FAILURE, "fullscreen", "Can only be used when sway is running.");
if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0))) {
return error;
}
swayc_t *container = current_container;
if(container->type != C_VIEW){
return cmd_results_new(CMD_INVALID, "fullscreen", "Only views can fullscreen");
}
swayc_t *workspace = swayc_parent_by_type(container, C_WORKSPACE);
bool current = swayc_is_fullscreen(container);
wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current);
if (container->is_floating) {
if (current) {
// set dimensions back to what they were before we fullscreened this
container->x = container->cached_geometry.origin.x;
container->y = container->cached_geometry.origin.y;
container->width = container->cached_geometry.size.w;
container->height = container->cached_geometry.size.h;
} else {
// cache dimensions so we can reset them after we "unfullscreen" this
struct wlc_geometry geo = {
.origin = {
.x = container->x,
.y = container->y
},
.size = {
.w = container->width,
.h = container->height
}
};
container->cached_geometry = geo;
}
}
// Resize workspace if going from fullscreen -> notfullscreen
// otherwise just resize container
if (!current) {
arrange_windows(workspace, -1, -1);
workspace->fullscreen = container;
} else {
arrange_windows(container, -1, -1);
workspace->fullscreen = NULL;
}
ipc_event_window(container, "fullscreen_mode");
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}