Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding horizontal margins in criteria #74

Merged
merged 7 commits into from
Oct 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,
int notif_width =
(style->width <= state->width) ? style->width : state->width;

// Calculate the appropriate offset if we're right-aligned.
bool right_align =
(state->config.anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
int offset_x = right_align ? (state->width - notif_width) : 0;
int offset_x;
if (state->config.anchor & ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT) {
offset_x = state->width - notif_width - style->margin.right;
} else {
offset_x = style->margin.left;
}

set_font_options(cairo, state);

Expand Down Expand Up @@ -197,12 +199,10 @@ int render(struct mako_state *state, struct pool_buffer *buffer, int scale) {
}
format_text(style->format, text, format_notif_text, notif);

if (i > 0) {
if (style->margin.top > pending_bottom_margin) {
total_height += style->margin.top;
} else {
total_height += pending_bottom_margin;
}
if (style->margin.top > pending_bottom_margin) {
total_height += style->margin.top;
} else {
total_height += pending_bottom_margin;
}

int notif_width =
Expand Down
58 changes: 42 additions & 16 deletions wayland.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -393,6 +394,8 @@ void send_frame(struct mako_state *state) {
struct mako_output *output = get_configured_output(state);
int height = render(state, state->current_buffer, scale);

// There are two cases where we want to tear down the surface: zero
// notifications (height = 0) or moving between outputs.
if (height == 0 || state->layer_surface_output != output) {
if (state->layer_surface != NULL) {
zwlr_layer_surface_v1_destroy(state->layer_surface);
Expand All @@ -407,10 +410,15 @@ void send_frame(struct mako_state *state) {
state->configured = false;
}

// If there are no notifications, there's no point in recreating the
// surface right now.
if (height == 0) {
return; // nothing to render
return;
}

// If we've made it here, there is something to draw. If the surface
// doesn't exist (this is the first notification, or we moved to a
// different output), we need to create it.
if (state->layer_surface == NULL) {
struct wl_output *wl_output = NULL;
if (output != NULL) {
Expand All @@ -427,32 +435,50 @@ void send_frame(struct mako_state *state) {
zwlr_layer_surface_v1_add_listener(state->layer_surface,
&layer_surface_listener, state);

// Because we're creating a new surface, we aren't going to draw
// anything into it during this call. We don't know what size the
// surface will be until we've asked the compositor for what we want
// and it has responded with what it actually gave us. We also know
// that the height we would _like_ to draw (greater than zero, or we
// would have bailed already) is different from our state->height
// (which has to be zero here), so we can fall through to the next
// block to let it set the size for us.
}

assert(state->layer_surface);

// We now want to resize the surface if it isn't the right size. If the
// surface is brand new, it doesn't even have a size yet. If it already
// exists, we might need to resize if the list of notifications has changed
// since the last time we drew.
if (state->height != height) {
struct mako_style *style = &state->config.superstyle;

zwlr_layer_surface_v1_set_size(state->layer_surface, style->width,
zwlr_layer_surface_v1_set_size(state->layer_surface,
style->width + style->margin.left + style->margin.right,
height);
zwlr_layer_surface_v1_set_anchor(state->layer_surface,
state->config.anchor);
zwlr_layer_surface_v1_set_margin(state->layer_surface,
style->margin.top, style->margin.right,
style->margin.bottom, style->margin.left);
wl_surface_commit(state->surface);
return;
}

if (!state->configured) {
// Now we're going to bail without drawing anything. This gives the
// compositor a chance to create the surface and tell us what size we
// were actually granted, which may be smaller than what we asked for
// depending on the screen size and layout of other layer surfaces.
// This information is provided in layer_surface_handle_configure,
// which will then call send_frame again. When that call happens, the
// layer surface will exist and the height will hopefully match what
// we asked for. That means we won't return here, and will actually
// draw into the surface down below.
// TODO: If the compositor doesn't send a configure with the size we
// requested, we'll enter an infinite loop. We need to keep track of
// the fact that a request was sent separately from what height we are.
return;
}

// TODO: if the compositor doesn't send a configure with the size we
// requested, we'll enter an infinite loop
if (state->height != height) {
zwlr_layer_surface_v1_set_size(state->layer_surface,
state->config.superstyle.width, height);
wl_surface_commit(state->surface);
return;
}
assert(state->configured);

// Yay we can finally draw something!
struct wl_region *input_region = get_input_region(state);
wl_surface_set_input_region(state->surface, input_region);
wl_region_destroy(input_region);
Expand Down