diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-05-24 22:30:44 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-01 23:14:58 +1000 |
commit | 1f2e399ade77070a2d0b82856ad9a3eef96b8676 (patch) | |
tree | c469197e140051aea912cb173723c7e55ce1e410 /sway/desktop/output.c | |
parent | Send frame done to floating views (diff) | |
download | sway-1f2e399ade77070a2d0b82856ad9a3eef96b8676.tar.gz sway-1f2e399ade77070a2d0b82856ad9a3eef96b8676.tar.zst sway-1f2e399ade77070a2d0b82856ad9a3eef96b8676.zip |
Implement floating
Diffstat (limited to 'sway/desktop/output.c')
-rw-r--r-- | sway/desktop/output.c | 114 |
1 files changed, 102 insertions, 12 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 95479819..1d21e80f 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -754,9 +754,87 @@ static void render_container(struct sway_output *output, | |||
754 | case L_TABBED: | 754 | case L_TABBED: |
755 | render_container_tabbed(output, damage, con, parent_focused); | 755 | render_container_tabbed(output, damage, con, parent_focused); |
756 | break; | 756 | break; |
757 | case L_FLOATING: | 757 | } |
758 | // TODO | 758 | } |
759 | break; | 759 | |
760 | static bool floater_intersects_output(struct sway_container *floater, | ||
761 | struct sway_container *output) { | ||
762 | struct wlr_box box = { | ||
763 | .x = floater->x, | ||
764 | .y = floater->y, | ||
765 | .width = floater->width, | ||
766 | .height = floater->height, | ||
767 | }; | ||
768 | return wlr_output_layout_intersects(root_container.sway_root->output_layout, | ||
769 | output->sway_output->wlr_output, &box); | ||
770 | } | ||
771 | |||
772 | static void container_translate(struct sway_container *con, int x, int y) { | ||
773 | con->x += x; | ||
774 | con->y += y; | ||
775 | if (con->type == C_VIEW) { | ||
776 | con->sway_view->x += x; | ||
777 | con->sway_view->y += y; | ||
778 | } else { | ||
779 | for (int i = 0; i < con->children->length; ++i) { | ||
780 | struct sway_container *child = con->children->items[i]; | ||
781 | container_translate(child, x, y); | ||
782 | } | ||
783 | } | ||
784 | } | ||
785 | |||
786 | static void render_floating_container(struct sway_output *soutput, | ||
787 | pixman_region32_t *damage, struct sway_container *con) { | ||
788 | // We need to translate the floating container's coordinates from layout | ||
789 | // coordinates into output-local coordinates. This needs to happen for all | ||
790 | // children of the floating container too. | ||
791 | struct sway_container *output = container_parent(con, C_OUTPUT); | ||
792 | container_translate(con, -output->x, -output->y); | ||
793 | |||
794 | if (con->type == C_VIEW) { | ||
795 | struct sway_view *view = con->sway_view; | ||
796 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
797 | struct sway_container *focus = seat_get_focus(seat); | ||
798 | struct border_colors *colors; | ||
799 | struct wlr_texture *title_texture; | ||
800 | struct wlr_texture *marks_texture; | ||
801 | |||
802 | if (focus == con) { | ||
803 | colors = &config->border_colors.focused; | ||
804 | title_texture = con->title_focused; | ||
805 | marks_texture = view->marks_focused; | ||
806 | } else { | ||
807 | colors = &config->border_colors.unfocused; | ||
808 | title_texture = con->title_unfocused; | ||
809 | marks_texture = view->marks_unfocused; | ||
810 | } | ||
811 | render_titlebar(soutput, damage, con, con->x, con->y, con->width, | ||
812 | colors, title_texture, marks_texture); | ||
813 | render_view(soutput, damage, con, colors); | ||
814 | } else { | ||
815 | render_container(soutput, damage, con, false); | ||
816 | } | ||
817 | // Undo the translation | ||
818 | container_translate(con, output->x, output->y); | ||
819 | } | ||
820 | |||
821 | static void render_floating(struct sway_output *soutput, | ||
822 | pixman_region32_t *damage) { | ||
823 | for (int i = 0; i < root_container.children->length; ++i) { | ||
824 | struct sway_container *output = root_container.children->items[i]; | ||
825 | for (int j = 0; j < output->children->length; ++j) { | ||
826 | struct sway_container *workspace = output->children->items[j]; | ||
827 | struct sway_workspace *ws = workspace->sway_workspace; | ||
828 | bool ws_is_visible = workspace_is_visible(workspace); | ||
829 | for (int k = 0; k < ws->floating->children->length; ++k) { | ||
830 | struct sway_container *floater = | ||
831 | ws->floating->children->items[k]; | ||
832 | if ((ws_is_visible || floater->is_sticky) | ||
833 | && floater_intersects_output(floater, soutput->swayc)) { | ||
834 | render_floating_container(soutput, damage, floater); | ||
835 | } | ||
836 | } | ||
837 | } | ||
760 | } | 838 | } |
761 | } | 839 | } |
762 | 840 | ||
@@ -794,8 +872,6 @@ static void render_output(struct sway_output *output, struct timespec *when, | |||
794 | goto renderer_end; | 872 | goto renderer_end; |
795 | } | 873 | } |
796 | 874 | ||
797 | //wlr_renderer_clear(renderer, (float[]){1, 1, 0, 1}); | ||
798 | |||
799 | struct sway_container *workspace = output_get_active_workspace(output); | 875 | struct sway_container *workspace = output_get_active_workspace(output); |
800 | 876 | ||
801 | if (workspace->sway_workspace->fullscreen) { | 877 | if (workspace->sway_workspace->fullscreen) { |
@@ -818,7 +894,6 @@ static void render_output(struct sway_output *output, struct timespec *when, | |||
818 | } | 894 | } |
819 | } else { | 895 | } else { |
820 | float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; | 896 | float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; |
821 | wlr_renderer_clear(renderer, clear_color); | ||
822 | 897 | ||
823 | int nrects; | 898 | int nrects; |
824 | pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); | 899 | pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); |
@@ -840,6 +915,8 @@ static void render_output(struct sway_output *output, struct timespec *when, | |||
840 | &root_container.sway_root->xwayland_unmanaged); | 915 | &root_container.sway_root->xwayland_unmanaged); |
841 | render_layer(output, damage, | 916 | render_layer(output, damage, |
842 | &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); | 917 | &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); |
918 | |||
919 | render_floating(output, damage); | ||
843 | } | 920 | } |
844 | render_layer(output, damage, | 921 | render_layer(output, damage, |
845 | &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); | 922 | &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); |
@@ -916,6 +993,7 @@ static void send_frame_done(struct sway_output *output, struct timespec *when) { | |||
916 | 993 | ||
917 | struct sway_container *workspace = output_get_active_workspace(output); | 994 | struct sway_container *workspace = output_get_active_workspace(output); |
918 | send_frame_done_container(&data, workspace); | 995 | send_frame_done_container(&data, workspace); |
996 | send_frame_done_container(&data, workspace->sway_workspace->floating); | ||
919 | 997 | ||
920 | send_frame_done_unmanaged(&data, | 998 | send_frame_done_unmanaged(&data, |
921 | &root_container.sway_root->xwayland_unmanaged); | 999 | &root_container.sway_root->xwayland_unmanaged); |
@@ -1037,7 +1115,15 @@ static void output_damage_view(struct sway_output *output, | |||
1037 | 1115 | ||
1038 | void output_damage_from_view(struct sway_output *output, | 1116 | void output_damage_from_view(struct sway_output *output, |
1039 | struct sway_view *view) { | 1117 | struct sway_view *view) { |
1040 | output_damage_view(output, view, false); | 1118 | if (container_self_or_parent_floating(view->swayc)) { |
1119 | view->x -= output->swayc->x; | ||
1120 | view->y -= output->swayc->y; | ||
1121 | output_damage_view(output, view, false); | ||
1122 | view->x += output->swayc->x; | ||
1123 | view->y += output->swayc->y; | ||
1124 | } else { | ||
1125 | output_damage_view(output, view, false); | ||
1126 | } | ||
1041 | } | 1127 | } |
1042 | 1128 | ||
1043 | static void output_damage_whole_container_iterator(struct sway_container *con, | 1129 | static void output_damage_whole_container_iterator(struct sway_container *con, |
@@ -1053,13 +1139,17 @@ static void output_damage_whole_container_iterator(struct sway_container *con, | |||
1053 | 1139 | ||
1054 | void output_damage_whole_container(struct sway_output *output, | 1140 | void output_damage_whole_container(struct sway_output *output, |
1055 | struct sway_container *con) { | 1141 | struct sway_container *con) { |
1056 | float scale = output->wlr_output->scale; | ||
1057 | struct wlr_box box = { | 1142 | struct wlr_box box = { |
1058 | .x = con->x * scale, | 1143 | .x = con->x, |
1059 | .y = con->y * scale, | 1144 | .y = con->y, |
1060 | .width = con->width * scale, | 1145 | .width = con->width, |
1061 | .height = con->height * scale, | 1146 | .height = con->height, |
1062 | }; | 1147 | }; |
1148 | if (con->is_floating) { | ||
1149 | box.x -= output->wlr_output->lx; | ||
1150 | box.y -= output->wlr_output->ly; | ||
1151 | } | ||
1152 | scale_box(&box, output->wlr_output->scale); | ||
1063 | wlr_output_damage_add_box(output->damage, &box); | 1153 | wlr_output_damage_add_box(output->damage, &box); |
1064 | 1154 | ||
1065 | if (con->type == C_VIEW) { | 1155 | if (con->type == C_VIEW) { |