Merge pull request #659 from agx/alpha

Make wlr_render_with_matrix use alpha
This commit is contained in:
Drew DeVault 2018-02-25 13:16:35 -05:00 committed by GitHub
commit 3296365ce5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 55 additions and 22 deletions

View file

@ -23,6 +23,16 @@
#include "rootston/view.h"
#include "rootston/xcursor.h"
struct roots_view *view_create() {
struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) {
return NULL;
}
view->alpha = 1.0f;
return view;
}
void view_get_box(const struct roots_view *view, struct wlr_box *box) {
box->x = view->x;
box->y = view->y;
@ -269,6 +279,15 @@ void view_rotate(struct roots_view *view, float rotation) {
view_damage_whole(view);
}
void view_cycle_alpha(struct roots_view *view) {
view->alpha -= 0.05;
/* Don't go completely transparent */
if (view->alpha < 0.1) {
view->alpha = 1.0;
}
view_damage_whole(view);
}
void view_close(struct roots_view *view) {
if (view->close) {
view->close(view);

View file

@ -106,6 +106,11 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard,
}
} else if (strcmp(command, "next_window") == 0) {
roots_seat_cycle_focus(seat);
} else if (strcmp(command, "alpha") == 0) {
struct roots_view *focus = roots_seat_get_focus(seat);
if (focus != NULL) {
view_cycle_alpha(focus);
}
} else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) {
const char *shell_cmd = command + strlen(exec_prefix);
pid_t pid = fork();

View file

@ -202,6 +202,7 @@ struct render_data {
struct roots_output *output;
struct timespec *when;
pixman_region32_t *damage;
float alpha;
};
/**
@ -296,7 +297,7 @@ static void render_surface(struct wlr_surface *surface, double lx, double ly,
pixman_box32_t *rects = pixman_region32_rectangles(&damage, &nrects);
for (int i = 0; i < nrects; ++i) {
scissor_output(output, &rects[i]);
wlr_render_with_matrix(renderer, surface->texture, &matrix);
wlr_render_with_matrix(renderer, surface->texture, &matrix, data->alpha);
}
damage_finish:
@ -355,7 +356,7 @@ static void render_decorations(struct roots_view *view,
float matrix[16];
wlr_matrix_project_box(&matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL,
view->rotation, &output->wlr_output->transform_matrix);
float color[] = { 0.2, 0.2, 0.2, 1 };
float color[] = { 0.2, 0.2, 0.2, view->alpha };
int nrects;
pixman_box32_t *rects =
@ -376,6 +377,7 @@ static void render_view(struct roots_view *view, struct render_data *data) {
return;
}
data->alpha = view->alpha;
render_decorations(view, data);
view_for_each_surface(view, render_surface, data);
}

View file

@ -42,8 +42,10 @@ meta-key = Logo
# - "exec" to execute a shell command
# - "close" to close the current view
# - "next_window" to cycle through windows
# - "alpha" to cycle a window's alpha channel
[bindings]
Logo+Shift+e = exit
Logo+q = close
Logo+m = maximize
Alt+Tab = next_window
Ctrl+Shift+a = alpha

View file

@ -227,7 +227,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
roots_surface->surface_commit.notify = handle_surface_commit;
wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
struct roots_view *view = view_create();
if (!view) {
free(roots_surface);
return;

View file

@ -333,7 +333,7 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
roots_surface->new_popup.notify = handle_new_popup;
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
struct roots_view *view = view_create();
if (!view) {
free(roots_surface);
return;

View file

@ -333,7 +333,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
roots_surface->new_popup.notify = handle_new_popup;
wl_signal_add(&surface->events.new_popup, &roots_surface->new_popup);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
struct roots_view *view = view_create();
if (!view) {
free(roots_surface);
return;

View file

@ -317,7 +317,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
wl_signal_add(&surface->surface->events.commit,
&roots_surface->surface_commit);
struct roots_view *view = calloc(1, sizeof(struct roots_view));
struct roots_view *view = view_create();
if (view == NULL) {
free(roots_surface);
return;