aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/fullscreen.c
blob: 83bbc66f2c0ed1019a79147882f0b6251947a2e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdbool.h>
#include <string.h>
#include <wlc/wlc.h>
#include "commands.h"
#include "container.h"
#include "focus.h"
#include "ipc-server.h"
#include "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 = get_focused_view(&root_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);
}