From fc9398a42e1dfc15bbb8490c049981034abb4926 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 3 Apr 2018 00:47:45 -0400 Subject: Implement opacity command --- sway/desktop/output.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'sway/desktop/output.c') diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 8a4fb4a2..6cf5da48 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -75,7 +75,7 @@ static bool surface_intersect_output(struct wlr_surface *surface, static void render_surface(struct wlr_surface *surface, struct wlr_output *wlr_output, struct timespec *when, - double ox, double oy, float rotation) { + double ox, double oy, float rotation, float alpha) { struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); @@ -95,8 +95,8 @@ static void render_surface(struct wlr_surface *surface, wlr_matrix_project_box(matrix, &box, transform, rotation, wlr_output->transform_matrix); - // TODO: configurable alpha - wlr_render_texture_with_matrix(renderer, surface->texture, matrix, 1.0f); + wlr_render_texture_with_matrix(renderer, surface->texture, + matrix, alpha); wlr_surface_send_frame_done(surface, when); } @@ -110,13 +110,13 @@ static void render_surface(struct wlr_surface *surface, surface->current->width, surface->current->height, rotation); render_surface(subsurface->surface, wlr_output, when, - ox + sx, oy + sy, rotation); + ox + sx, oy + sy, rotation, alpha); } } static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, struct wlr_output *wlr_output, struct timespec *when, double base_x, - double base_y, float rotation) { + double base_y, float rotation, float alpha) { double width = surface->surface->current->width; double height = surface->surface->current->height; @@ -136,19 +136,19 @@ static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, width, height, rotation); render_surface(popup->surface, wlr_output, when, - base_x + popup_sx, base_y + popup_sy, rotation); + base_x + popup_sx, base_y + popup_sy, rotation, alpha); render_xdg_v6_popups(popup, wlr_output, when, - base_x + popup_sx, base_y + popup_sy, rotation); + base_x + popup_sx, base_y + popup_sy, rotation, alpha); } } static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, struct wlr_output *wlr_output, struct timespec *when, - double lx, double ly, float rotation, + double lx, double ly, float rotation, float alpha, bool is_child) { if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) { render_surface(surface->surface, wlr_output, when, - lx, ly, rotation); + lx, ly, rotation, alpha); double width = surface->surface->current->width; double height = surface->surface->current->height; @@ -164,7 +164,7 @@ static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, width, height, rotation); render_wl_shell_surface(popup, wlr_output, when, - lx + popup_x, ly + popup_y, rotation, true); + lx + popup_x, ly + popup_y, rotation, alpha, true); } } } @@ -181,6 +181,7 @@ static void render_view(struct sway_container *view, void *data) { struct wlr_output *wlr_output = output->wlr_output; struct sway_view *sway_view = view->sway_view; struct wlr_surface *surface = sway_view->surface; + float alpha = sway_view->swayc->alpha; if (!surface) { return; @@ -191,17 +192,18 @@ static void render_view(struct sway_container *view, void *data) { int window_offset_x = view->sway_view->wlr_xdg_surface_v6->geometry.x; int window_offset_y = view->sway_view->wlr_xdg_surface_v6->geometry.y; render_surface(surface, wlr_output, when, - view->x - window_offset_x, view->y - window_offset_y, 0); + view->x - window_offset_x, view->y - window_offset_y, 0, alpha); render_xdg_v6_popups(sway_view->wlr_xdg_surface_v6, wlr_output, - when, view->x - window_offset_x, view->y - window_offset_y, 0); + when, view->x - window_offset_x, view->y - window_offset_y, 0, alpha); break; } case SWAY_WL_SHELL_VIEW: render_wl_shell_surface(sway_view->wlr_wl_shell_surface, wlr_output, - when, view->x, view->y, 0, false); + when, view->x, view->y, 0, alpha, false); break; case SWAY_XWAYLAND_VIEW: - render_surface(surface, wlr_output, when, view->x, view->y, 0); + render_surface(surface, wlr_output, when, view->x, view->y, + 0, alpha); break; default: break; @@ -214,7 +216,7 @@ static void render_layer(struct sway_output *output, struct timespec *when, wl_list_for_each(sway_layer, layer, link) { struct wlr_layer_surface *layer = sway_layer->layer_surface; render_surface(layer->surface, output->wlr_output, when, - sway_layer->geo.x, sway_layer->geo.y, 0); + sway_layer->geo.x, sway_layer->geo.y, 0, 1.0f); wlr_surface_send_frame_done(layer->surface, when); } } @@ -288,7 +290,7 @@ static void render_output(struct sway_output *output, struct timespec *when, } render_surface(xsurface->surface, wlr_output, &output->last_frame, - view_box.x - output_box->x, view_box.y - output_box->y, 0); + view_box.x - output_box->x, view_box.y - output_box->y, 0, 1.0f); } // TODO: Consider revising this when fullscreen windows are supported -- cgit v1.2.3 From 8eff00f72395add1881aa677e3c718c0554cb096 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 4 Apr 2018 15:53:46 -0400 Subject: Remove unused SWAY_VIEW_TYPES --- include/sway/tree/view.h | 8 +++----- sway/desktop/output.c | 9 ++++----- sway/desktop/wl_shell.c | 4 ++-- sway/desktop/xdg_shell_v6.c | 4 ++-- sway/desktop/xwayland.c | 4 ++-- sway/input/seat.c | 2 +- sway/tree/container.c | 47 +++++++++++++++++++++------------------------ 7 files changed, 36 insertions(+), 42 deletions(-) (limited to 'sway/desktop/output.c') diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 6bc5ceda..f32ccc5a 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -59,11 +59,9 @@ struct sway_wl_shell_surface { }; enum sway_view_type { - SWAY_WL_SHELL_VIEW, - SWAY_XDG_SHELL_V6_VIEW, - SWAY_XWAYLAND_VIEW, - // Keep last - SWAY_VIEW_TYPES, + SWAY_VIEW_WL_SHELL, + SWAY_VIEW_XDG_SHELL_V6, + SWAY_VIEW_XWAYLAND, }; enum sway_view_prop { diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 6cf5da48..38b52a41 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -188,7 +188,7 @@ static void render_view(struct sway_container *view, void *data) { } switch (sway_view->type) { - case SWAY_XDG_SHELL_V6_VIEW: { + case SWAY_VIEW_XDG_SHELL_V6: { int window_offset_x = view->sway_view->wlr_xdg_surface_v6->geometry.x; int window_offset_y = view->sway_view->wlr_xdg_surface_v6->geometry.y; render_surface(surface, wlr_output, when, @@ -197,13 +197,12 @@ static void render_view(struct sway_container *view, void *data) { when, view->x - window_offset_x, view->y - window_offset_y, 0, alpha); break; } - case SWAY_WL_SHELL_VIEW: + case SWAY_VIEW_WL_SHELL: render_wl_shell_surface(sway_view->wlr_wl_shell_surface, wlr_output, when, view->x, view->y, 0, alpha, false); break; - case SWAY_XWAYLAND_VIEW: - render_surface(surface, wlr_output, when, view->x, view->y, - 0, alpha); + case SWAY_VIEW_XWAYLAND: + render_surface(surface, wlr_output, when, view->x, view->y, 0, alpha); break; default: break; diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index 6528a397..a470674d 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -12,7 +12,7 @@ #include "log.h" static bool assert_wl_shell(struct sway_view *view) { - return sway_assert(view->type == SWAY_WL_SHELL_VIEW, + return sway_assert(view->type == SWAY_VIEW_WL_SHELL, "Expecting wl_shell view!"); } @@ -97,7 +97,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { return; } - struct sway_view *view = view_create(SWAY_WL_SHELL_VIEW, &view_impl); + struct sway_view *view = view_create(SWAY_VIEW_WL_SHELL, &view_impl); if (!sway_assert(view, "Failed to allocate view")) { return; } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 49305b39..5cdb8f9f 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -12,7 +12,7 @@ #include "log.h" static bool assert_xdg(struct sway_view *view) { - return sway_assert(view->type == SWAY_XDG_SHELL_V6_VIEW, + return sway_assert(view->type == SWAY_VIEW_XDG_SHELL_V6, "Expected xdg shell v6 view!"); } @@ -126,7 +126,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { return; } - struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW, &view_impl); + struct sway_view *view = view_create(SWAY_VIEW_XDG_SHELL_V6, &view_impl); if (!sway_assert(view, "Failed to allocate view")) { return; } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index bfef68cf..a793928c 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -42,7 +42,7 @@ static void create_unmanaged(struct wlr_xwayland_surface *xsurface) { static bool assert_xwayland(struct sway_view *view) { - return sway_assert(view->type == SWAY_XWAYLAND_VIEW, + return sway_assert(view->type == SWAY_VIEW_XWAYLAND, "Expected xwayland view!"); } @@ -185,7 +185,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { return; } - struct sway_view *view = view_create(SWAY_XWAYLAND_VIEW, &view_impl); + struct sway_view *view = view_create(SWAY_VIEW_XWAYLAND, &view_impl); if (!sway_assert(view, "Failed to allocate view")) { return; } diff --git a/sway/input/seat.c b/sway/input/seat.c index 0699324a..87dbd870 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -66,7 +66,7 @@ static void seat_send_focus(struct sway_seat *seat, return; } struct sway_view *view = con->sway_view; - if (view->type == SWAY_XWAYLAND_VIEW) { + if (view->type == SWAY_VIEW_XWAYLAND) { struct wlr_xwayland *xwayland = seat->input->server->xwayland; wlr_xwayland_set_seat(xwayland, seat->wlr_seat); diff --git a/sway/tree/container.c b/sway/tree/container.c index 3be08645..1ea10759 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -413,31 +413,28 @@ struct sway_container *container_at(struct sway_container *parent, double view_sy = oy - swayc->y; switch (sview->type) { - case SWAY_WL_SHELL_VIEW: - break; - case SWAY_XDG_SHELL_V6_VIEW: - // the top left corner of the sway container is the - // coordinate of the top left corner of the window geometry - view_sx += sview->wlr_xdg_surface_v6->geometry.x; - view_sy += sview->wlr_xdg_surface_v6->geometry.y; - - // check for popups - double popup_sx, popup_sy; - struct wlr_xdg_surface_v6 *popup = - wlr_xdg_surface_v6_popup_at(sview->wlr_xdg_surface_v6, - view_sx, view_sy, &popup_sx, &popup_sy); - - if (popup) { - *sx = view_sx - popup_sx; - *sy = view_sy - popup_sy; - *surface = popup->surface; - return swayc; - } - break; - case SWAY_XWAYLAND_VIEW: - break; - default: - break; + case SWAY_VIEW_XWAYLAND: + case SWAY_VIEW_WL_SHELL: + break; + case SWAY_VIEW_XDG_SHELL_V6: + // the top left corner of the sway container is the + // coordinate of the top left corner of the window geometry + view_sx += sview->wlr_xdg_surface_v6->geometry.x; + view_sy += sview->wlr_xdg_surface_v6->geometry.y; + + // check for popups + double popup_sx, popup_sy; + struct wlr_xdg_surface_v6 *popup = + wlr_xdg_surface_v6_popup_at(sview->wlr_xdg_surface_v6, + view_sx, view_sy, &popup_sx, &popup_sy); + + if (popup) { + *sx = view_sx - popup_sx; + *sy = view_sy - popup_sy; + *surface = popup->surface; + return swayc; + } + break; } // check for subsurfaces -- cgit v1.2.3 From 44b8d30f5254628f8e6d5a12010f6e5f810d756e Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 4 Apr 2018 17:57:12 -0400 Subject: Use new wlr_*_surface_at functions --- sway/desktop/output.c | 2 -- sway/tree/container.c | 45 +++++++++++++++------------------------------ 2 files changed, 15 insertions(+), 32 deletions(-) (limited to 'sway/desktop/output.c') diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 38b52a41..0e8a9485 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -204,8 +204,6 @@ static void render_view(struct sway_container *view, void *data) { case SWAY_VIEW_XWAYLAND: render_surface(surface, wlr_output, when, view->x, view->y, 0, alpha); break; - default: - break; } } diff --git a/sway/tree/container.c b/sway/tree/container.c index 1ea10759..bd9f1edf 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -412,9 +412,17 @@ struct sway_container *container_at(struct sway_container *parent, double view_sx = ox - swayc->x; double view_sy = oy - swayc->y; + double _sx, _sy; + struct wlr_surface *_surface; switch (sview->type) { case SWAY_VIEW_XWAYLAND: + _surface = wlr_surface_surface_at(sview->surface, + view_sx, view_sy, &_sx, &_sy); + break; case SWAY_VIEW_WL_SHELL: + _surface = wlr_wl_shell_surface_surface_at( + sview->wlr_wl_shell_surface, + view_sx, view_sy, &_sx, &_sy); break; case SWAY_VIEW_XDG_SHELL_V6: // the top left corner of the sway container is the @@ -422,38 +430,15 @@ struct sway_container *container_at(struct sway_container *parent, view_sx += sview->wlr_xdg_surface_v6->geometry.x; view_sy += sview->wlr_xdg_surface_v6->geometry.y; - // check for popups - double popup_sx, popup_sy; - struct wlr_xdg_surface_v6 *popup = - wlr_xdg_surface_v6_popup_at(sview->wlr_xdg_surface_v6, - view_sx, view_sy, &popup_sx, &popup_sy); - - if (popup) { - *sx = view_sx - popup_sx; - *sy = view_sy - popup_sy; - *surface = popup->surface; - return swayc; - } + _surface = wlr_xdg_surface_v6_surface_at( + sview->wlr_xdg_surface_v6, + view_sx, view_sy, &_sx, &_sy); break; } - - // check for subsurfaces - double sub_x, sub_y; - struct wlr_subsurface *subsurface = - wlr_surface_subsurface_at(sview->surface, - view_sx, view_sy, &sub_x, &sub_y); - if (subsurface) { - *sx = view_sx - sub_x; - *sy = view_sy - sub_y; - *surface = subsurface->surface; - return swayc; - } - - if (wlr_surface_point_accepts_input( - sview->surface, view_sx, view_sy)) { - *sx = view_sx; - *sy = view_sy; - *surface = swayc->sway_view->surface; + if (_surface) { + *sx = _sx; + *sy = _sy; + *surface = _surface; return swayc; } } else { -- cgit v1.2.3