diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2019-01-25 08:29:21 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2019-01-25 08:29:21 +1000 |
commit | 20aa8ee67dc528299dbc8735220a1c081c7ff9f6 (patch) | |
tree | 685de48be3db51fc01510ccf051e2b63a4655fba /sway/tree/container.c | |
parent | Update for swaywm/wlroots#1402 (diff) | |
download | sway-20aa8ee67dc528299dbc8735220a1c081c7ff9f6.tar.gz sway-20aa8ee67dc528299dbc8735220a1c081c7ff9f6.tar.zst sway-20aa8ee67dc528299dbc8735220a1c081c7ff9f6.zip |
Implement fullscreen global
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 174 |
1 files changed, 123 insertions, 51 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 0c0684c0..d8ad3bc0 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -92,7 +92,7 @@ void container_begin_destroy(struct sway_container *con) { | |||
92 | } | 92 | } |
93 | // The workspace must have the fullscreen pointer cleared so that the | 93 | // The workspace must have the fullscreen pointer cleared so that the |
94 | // seat code can find an appropriate new focus. | 94 | // seat code can find an appropriate new focus. |
95 | if (con->is_fullscreen && con->workspace) { | 95 | if (con->fullscreen_mode == FULLSCREEN_WORKSPACE && con->workspace) { |
96 | con->workspace->fullscreen = NULL; | 96 | con->workspace->fullscreen = NULL; |
97 | } | 97 | } |
98 | wl_signal_emit(&con->node.events.destroy, &con->node); | 98 | wl_signal_emit(&con->node.events.destroy, &con->node); |
@@ -106,6 +106,10 @@ void container_begin_destroy(struct sway_container *con) { | |||
106 | root_scratchpad_remove_container(con); | 106 | root_scratchpad_remove_container(con); |
107 | } | 107 | } |
108 | 108 | ||
109 | if (con->fullscreen_mode == FULLSCREEN_GLOBAL) { | ||
110 | container_fullscreen_disable(con); | ||
111 | } | ||
112 | |||
109 | if (con->parent || con->workspace) { | 113 | if (con->parent || con->workspace) { |
110 | container_detach(con); | 114 | container_detach(con); |
111 | } | 115 | } |
@@ -840,15 +844,15 @@ void container_floating_move_to_center(struct sway_container *con) { | |||
840 | return; | 844 | return; |
841 | } | 845 | } |
842 | struct sway_workspace *ws = con->workspace; | 846 | struct sway_workspace *ws = con->workspace; |
843 | bool full = con->is_fullscreen; | 847 | enum sway_fullscreen_mode fullscreen_mode = con->fullscreen_mode; |
844 | if (full) { | 848 | if (fullscreen_mode) { |
845 | container_set_fullscreen(con, false); | 849 | container_fullscreen_disable(con); |
846 | } | 850 | } |
847 | double new_lx = ws->x + (ws->width - con->width) / 2; | 851 | double new_lx = ws->x + (ws->width - con->width) / 2; |
848 | double new_ly = ws->y + (ws->height - con->height) / 2; | 852 | double new_ly = ws->y + (ws->height - con->height) / 2; |
849 | container_floating_translate(con, new_lx - con->x, new_ly - con->y); | 853 | container_floating_translate(con, new_lx - con->x, new_ly - con->y); |
850 | if (full) { | 854 | if (fullscreen_mode) { |
851 | container_set_fullscreen(con, true); | 855 | container_set_fullscreen(con, fullscreen_mode); |
852 | } | 856 | } |
853 | } | 857 | } |
854 | 858 | ||
@@ -877,59 +881,125 @@ static void set_fullscreen_iterator(struct sway_container *con, void *data) { | |||
877 | } | 881 | } |
878 | } | 882 | } |
879 | 883 | ||
880 | void container_set_fullscreen(struct sway_container *container, bool enable) { | 884 | static void container_fullscreen_workspace(struct sway_container *con) { |
881 | if (container->is_fullscreen == enable) { | 885 | if (!sway_assert(con->fullscreen_mode == FULLSCREEN_NONE, |
886 | "Expected a non-fullscreen container")) { | ||
882 | return; | 887 | return; |
883 | } | 888 | } |
889 | bool enable = true; | ||
890 | set_fullscreen_iterator(con, &enable); | ||
891 | container_for_each_child(con, set_fullscreen_iterator, &enable); | ||
884 | 892 | ||
885 | struct sway_workspace *workspace = container->workspace; | 893 | con->workspace->fullscreen = con; |
886 | if (enable && workspace->fullscreen) { | 894 | con->saved_x = con->x; |
887 | container_set_fullscreen(workspace->fullscreen, false); | 895 | con->saved_y = con->y; |
896 | con->saved_width = con->width; | ||
897 | con->saved_height = con->height; | ||
898 | |||
899 | struct sway_seat *seat; | ||
900 | struct sway_workspace *focus_ws; | ||
901 | wl_list_for_each(seat, &server.input->seats, link) { | ||
902 | focus_ws = seat_get_focused_workspace(seat); | ||
903 | if (focus_ws == con->workspace) { | ||
904 | seat_set_focus_container(seat, con); | ||
905 | } | ||
888 | } | 906 | } |
889 | 907 | ||
890 | set_fullscreen_iterator(container, &enable); | 908 | con->fullscreen_mode = FULLSCREEN_WORKSPACE; |
891 | container_for_each_child(container, set_fullscreen_iterator, &enable); | 909 | container_end_mouse_operation(con); |
910 | ipc_event_window(con, "fullscreen_mode"); | ||
911 | } | ||
912 | |||
913 | static void container_fullscreen_global(struct sway_container *con) { | ||
914 | if (!sway_assert(con->fullscreen_mode == FULLSCREEN_NONE, | ||
915 | "Expected a non-fullscreen container")) { | ||
916 | return; | ||
917 | } | ||
918 | bool enable = true; | ||
919 | set_fullscreen_iterator(con, &enable); | ||
920 | container_for_each_child(con, set_fullscreen_iterator, &enable); | ||
892 | 921 | ||
893 | container->is_fullscreen = enable; | 922 | root->fullscreen_global = con; |
923 | con->saved_x = con->x; | ||
924 | con->saved_y = con->y; | ||
925 | con->saved_width = con->width; | ||
926 | con->saved_height = con->height; | ||
894 | 927 | ||
895 | if (enable) { | 928 | struct sway_seat *seat; |
896 | workspace->fullscreen = container; | 929 | wl_list_for_each(seat, &server.input->seats, link) { |
897 | container->saved_x = container->x; | 930 | struct sway_container *focus = seat_get_focused_container(seat); |
898 | container->saved_y = container->y; | 931 | if (focus && focus != con) { |
899 | container->saved_width = container->width; | 932 | seat_set_focus_container(seat, con); |
900 | container->saved_height = container->height; | ||
901 | |||
902 | struct sway_seat *seat; | ||
903 | struct sway_workspace *focus_ws; | ||
904 | wl_list_for_each(seat, &server.input->seats, link) { | ||
905 | focus_ws = seat_get_focused_workspace(seat); | ||
906 | if (focus_ws) { | ||
907 | if (focus_ws == workspace) { | ||
908 | seat_set_focus_container(seat, container); | ||
909 | } | ||
910 | } | ||
911 | } | 933 | } |
912 | } else { | 934 | } |
913 | workspace->fullscreen = NULL; | 935 | |
914 | if (container_is_floating(container)) { | 936 | con->fullscreen_mode = FULLSCREEN_GLOBAL; |
915 | container->x = container->saved_x; | 937 | container_end_mouse_operation(con); |
916 | container->y = container->saved_y; | 938 | ipc_event_window(con, "fullscreen_mode"); |
917 | container->width = container->saved_width; | 939 | } |
918 | container->height = container->saved_height; | 940 | |
919 | struct sway_output *output = | 941 | void container_fullscreen_disable(struct sway_container *con) { |
920 | container_floating_find_output(container); | 942 | if (!sway_assert(con->fullscreen_mode != FULLSCREEN_NONE, |
921 | if (workspace->output != output) { | 943 | "Expected a fullscreen container")) { |
922 | container_floating_move_to_center(container); | 944 | return; |
945 | } | ||
946 | bool enable = false; | ||
947 | set_fullscreen_iterator(con, &enable); | ||
948 | container_for_each_child(con, set_fullscreen_iterator, &enable); | ||
949 | |||
950 | if (container_is_floating(con)) { | ||
951 | con->x = con->saved_x; | ||
952 | con->y = con->saved_y; | ||
953 | } | ||
954 | con->width = con->saved_width; | ||
955 | con->height = con->saved_height; | ||
956 | |||
957 | if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) { | ||
958 | con->workspace->fullscreen = NULL; | ||
959 | if (container_is_floating(con)) { | ||
960 | struct sway_output *output = container_floating_find_output(con); | ||
961 | if (con->workspace->output != output) { | ||
962 | container_floating_move_to_center(con); | ||
923 | } | 963 | } |
924 | } else { | ||
925 | container->width = container->saved_width; | ||
926 | container->height = container->saved_height; | ||
927 | } | 964 | } |
965 | } else { | ||
966 | root->fullscreen_global = NULL; | ||
928 | } | 967 | } |
929 | 968 | ||
930 | container_end_mouse_operation(container); | 969 | con->fullscreen_mode = FULLSCREEN_NONE; |
970 | container_end_mouse_operation(con); | ||
971 | ipc_event_window(con, "fullscreen_mode"); | ||
972 | } | ||
973 | |||
974 | void container_set_fullscreen(struct sway_container *con, | ||
975 | enum sway_fullscreen_mode mode) { | ||
976 | if (con->fullscreen_mode == mode) { | ||
977 | return; | ||
978 | } | ||
931 | 979 | ||
932 | ipc_event_window(container, "fullscreen_mode"); | 980 | switch (mode) { |
981 | case FULLSCREEN_NONE: | ||
982 | container_fullscreen_disable(con); | ||
983 | break; | ||
984 | case FULLSCREEN_WORKSPACE: | ||
985 | if (root->fullscreen_global) { | ||
986 | container_fullscreen_disable(root->fullscreen_global); | ||
987 | } | ||
988 | if (con->workspace->fullscreen) { | ||
989 | container_fullscreen_disable(con->workspace->fullscreen); | ||
990 | } | ||
991 | container_fullscreen_workspace(con); | ||
992 | break; | ||
993 | case FULLSCREEN_GLOBAL: | ||
994 | if (root->fullscreen_global) { | ||
995 | container_fullscreen_disable(root->fullscreen_global); | ||
996 | } | ||
997 | if (con->fullscreen_mode == FULLSCREEN_WORKSPACE) { | ||
998 | container_fullscreen_disable(con); | ||
999 | } | ||
1000 | container_fullscreen_global(con); | ||
1001 | break; | ||
1002 | } | ||
933 | } | 1003 | } |
934 | 1004 | ||
935 | bool container_is_floating_or_child(struct sway_container *container) { | 1005 | bool container_is_floating_or_child(struct sway_container *container) { |
@@ -941,7 +1011,7 @@ bool container_is_floating_or_child(struct sway_container *container) { | |||
941 | 1011 | ||
942 | bool container_is_fullscreen_or_child(struct sway_container *container) { | 1012 | bool container_is_fullscreen_or_child(struct sway_container *container) { |
943 | do { | 1013 | do { |
944 | if (container->is_fullscreen) { | 1014 | if (container->fullscreen_mode) { |
945 | return true; | 1015 | return true; |
946 | } | 1016 | } |
947 | container = container->parent; | 1017 | container = container->parent; |
@@ -1111,12 +1181,12 @@ list_t *container_get_current_siblings(struct sway_container *container) { | |||
1111 | } | 1181 | } |
1112 | 1182 | ||
1113 | void container_handle_fullscreen_reparent(struct sway_container *con) { | 1183 | void container_handle_fullscreen_reparent(struct sway_container *con) { |
1114 | if (!con->is_fullscreen || !con->workspace || | 1184 | if (con->fullscreen_mode != FULLSCREEN_WORKSPACE || !con->workspace || |
1115 | con->workspace->fullscreen == con) { | 1185 | con->workspace->fullscreen == con) { |
1116 | return; | 1186 | return; |
1117 | } | 1187 | } |
1118 | if (con->workspace->fullscreen) { | 1188 | if (con->workspace->fullscreen) { |
1119 | container_set_fullscreen(con->workspace->fullscreen, false); | 1189 | container_fullscreen_disable(con->workspace->fullscreen); |
1120 | } | 1190 | } |
1121 | con->workspace->fullscreen = con; | 1191 | con->workspace->fullscreen = con; |
1122 | 1192 | ||
@@ -1171,9 +1241,12 @@ void container_add_child(struct sway_container *parent, | |||
1171 | } | 1241 | } |
1172 | 1242 | ||
1173 | void container_detach(struct sway_container *child) { | 1243 | void container_detach(struct sway_container *child) { |
1174 | if (child->is_fullscreen) { | 1244 | if (child->fullscreen_mode == FULLSCREEN_WORKSPACE) { |
1175 | child->workspace->fullscreen = NULL; | 1245 | child->workspace->fullscreen = NULL; |
1176 | } | 1246 | } |
1247 | if (child->fullscreen_mode == FULLSCREEN_GLOBAL) { | ||
1248 | root->fullscreen_global = NULL; | ||
1249 | } | ||
1177 | 1250 | ||
1178 | struct sway_container *old_parent = child->parent; | 1251 | struct sway_container *old_parent = child->parent; |
1179 | struct sway_workspace *old_workspace = child->workspace; | 1252 | struct sway_workspace *old_workspace = child->workspace; |
@@ -1387,4 +1460,3 @@ void container_raise_floating(struct sway_container *con) { | |||
1387 | node_set_dirty(&floater->workspace->node); | 1460 | node_set_dirty(&floater->workspace->node); |
1388 | } | 1461 | } |
1389 | } | 1462 | } |
1390 | |||