From cf857ecf7bf5d1c0dd103554a8d42c93c91e7e37 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Mon, 19 Sep 2022 00:16:24 +0300 Subject: [PATCH] meson: add -Wfloat-conversion --- backend/drm/cvt.c | 41 ++++++++++----------- backend/libinput/pointer.c | 4 +- examples/dmabuf-capture.c | 2 +- examples/fullscreen-shell.c | 10 ++--- examples/input-inhibitor.c | 4 +- examples/layer-shell.c | 16 ++++---- examples/output-layout.c | 23 ++++++------ examples/quads.c | 4 +- examples/tablet.c | 24 ++++++------ examples/text-input.c | 6 +-- meson.build | 2 + render/gles2/renderer.c | 8 ++-- render/pixman/renderer.c | 38 +++++++++---------- render/vulkan/renderer.c | 14 +++---- tinywl/tinywl.c | 8 ++-- types/output/cursor.c | 28 +++++++------- types/output/output.c | 8 ++-- types/scene/wlr_scene.c | 40 +++++++++++--------- types/seat/wlr_seat_pointer.c | 4 +- types/tablet_v2/wlr_tablet_v2_pad.c | 5 ++- types/tablet_v2/wlr_tablet_v2_tool.c | 8 ++-- types/wlr_compositor.c | 23 ++++++------ types/wlr_cursor.c | 6 +-- types/wlr_layer_shell_v1.c | 2 +- types/wlr_matrix.c | 10 ++--- types/wlr_output_management_v1.c | 2 +- types/wlr_screencopy_v1.c | 8 ++-- types/wlr_xcursor_manager.c | 3 +- types/xdg_shell/wlr_xdg_surface.c | 7 +++- util/box.c | 11 ++++-- util/region.c | 55 ++++++++++++++-------------- 31 files changed, 220 insertions(+), 204 deletions(-) diff --git a/backend/drm/cvt.c b/backend/drm/cvt.c index 40f156b71..d5736decf 100644 --- a/backend/drm/cvt.c +++ b/backend/drm/cvt.c @@ -23,7 +23,7 @@ #include "backend/drm/cvt.h" /* top/bottom margin size (% of height) - default: 1.8 */ -#define CVT_MARGIN_PERCENTAGE 1.8 +#define CVT_MARGIN_PERCENTAGE 1.8f /* character cell horizontal granularity (pixels) - default 8 */ #define CVT_H_GRANULARITY 8 @@ -39,7 +39,7 @@ /* Minimum time of vertical sync + back porch interval (µs) * default 550.0 */ -#define CVT_MIN_VSYNC_BP 550.0 +#define CVT_MIN_VSYNC_BP 550 /* Nominal hsync width (% of line period) - default 8 */ #define CVT_HSYNC_PERCENTAGE 8 @@ -57,18 +57,18 @@ /* Scaling factor weighting - default 20 */ #define CVT_J_FACTOR 20 -#define CVT_M_PRIME CVT_M_FACTOR * CVT_K_FACTOR / 256 -#define CVT_C_PRIME (CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \ +#define CVT_M_PRIME CVT_M_FACTOR * CVT_K_FACTOR / 256.0f +#define CVT_C_PRIME (CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256.0f + \ CVT_J_FACTOR /* Minimum vertical blanking interval time (µs) - default 460 */ -#define CVT_RB_MIN_VBLANK 460.0 +#define CVT_RB_MIN_VBLANK 460 /* Fixed number of clocks for horizontal sync */ -#define CVT_RB_H_SYNC 32.0 +#define CVT_RB_H_SYNC 32 /* Fixed number of clocks for horizontal blanking */ -#define CVT_RB_H_BLANK 160.0 +#define CVT_RB_H_BLANK 160 /* Fixed number of lines for vertical front porch - default 3 */ #define CVT_RB_VFPORCH 3 @@ -98,8 +98,8 @@ void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, float interlace; /* Please rename this */ /* CVT default is 60.0Hz */ - if (!vrefresh) { - vrefresh = 60.0; + if (vrefresh != 0.0f) { + vrefresh = 60.0f; } /* 1. Required field rate */ @@ -115,7 +115,7 @@ void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, /* 3. Determine left and right borders */ if (margins) { /* right margin is actually exactly the same as left */ - hmargin = (((float) hdisplay_rnd) * CVT_MARGIN_PERCENTAGE / 100.0); + hmargin = (int)(((float)hdisplay_rnd) * CVT_MARGIN_PERCENTAGE / 100.0f); hmargin -= hmargin % CVT_H_GRANULARITY; } else { hmargin = 0; @@ -135,7 +135,7 @@ void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, /* nope. */ if (margins) { /* top and bottom margins are equal again. */ - vmargin = (((float) vdisplay_rnd) * CVT_MARGIN_PERCENTAGE / 100.0); + vmargin = (int)(((float)vdisplay_rnd) * CVT_MARGIN_PERCENTAGE / 100.0f); } else { vmargin = 0; } @@ -186,18 +186,17 @@ void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, (void) vblank_porch; /* 11. Find total number of lines in vertical field */ - mode->vtotal = vdisplay_rnd + 2 * vmargin + vsync_and_back_porch + interlace - + CVT_MIN_V_PORCH; + mode->vtotal = vdisplay_rnd + 2 * vmargin + vsync_and_back_porch + CVT_MIN_V_PORCH; /* 12. Find ideal blanking duty cycle from formula */ - hblank_percentage = CVT_C_PRIME - CVT_M_PRIME * hperiod / 1000.0; + hblank_percentage = CVT_C_PRIME - CVT_M_PRIME * hperiod / 1000.0f; /* 13. Blanking time */ if (hblank_percentage < 20) { hblank_percentage = 20; } - hblank = mode->hdisplay * hblank_percentage / (100.0 - hblank_percentage); + hblank = (int)(mode->hdisplay * hblank_percentage / (100.0f - hblank_percentage)); hblank -= hblank % (2 * CVT_H_GRANULARITY); /* 14. Find total number of pixels in a line. */ @@ -218,11 +217,11 @@ void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, int vbi_lines; /* 8. Estimate Horizontal period. */ - hperiod = ((float) (1000000.0 / vfield_rate - CVT_RB_MIN_VBLANK)) / + hperiod = ((float)(1000000.0 / vfield_rate - CVT_RB_MIN_VBLANK)) / (vdisplay_rnd + 2 * vmargin); /* 9. Find number of lines in vertical blanking */ - vbi_lines = ((float) CVT_RB_MIN_VBLANK) / hperiod + 1; + vbi_lines = (int)((float)CVT_RB_MIN_VBLANK / hperiod) + 1; /* 10. Check if vertical blanking is sufficient */ if (vbi_lines < (CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH)) { @@ -230,7 +229,7 @@ void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, } /* 11. Find total number of lines in vertical field */ - mode->vtotal = vdisplay_rnd + 2 * vmargin + interlace + vbi_lines; + mode->vtotal = vdisplay_rnd + 2 * vmargin + vbi_lines; /* 12. Find total number of pixels in a line */ mode->htotal = mode->hdisplay + CVT_RB_H_BLANK; @@ -245,12 +244,12 @@ void generate_cvt_mode(drmModeModeInfo *mode, int hdisplay, int vdisplay, } /* 15/13. Find pixel clock frequency (kHz for xf86) */ - mode->clock = mode->htotal * 1000.0 / hperiod; + mode->clock = (uint32_t)(mode->htotal * 1000.0f / hperiod); mode->clock -= mode->clock % CVT_CLOCK_STEP; /* 17/15. Find actual Field rate */ - mode->vrefresh = (1000.0 * ((float) mode->clock)) / - ((float) (mode->htotal * mode->vtotal)); + mode->vrefresh = (uint32_t)((1000.0f * mode->clock) / + (mode->htotal * mode->vtotal)); /* 18/16. Find actual vertical frame frequency */ /* ignore - just set the mode flag for interlaced */ diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 48f8ae128..ea7378202 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -117,7 +117,7 @@ void handle_pointer_axis(struct libinput_event *event, wlr_event.delta = libinput_event_pointer_get_axis_value(pevent, axes[i]); wlr_event.delta_discrete = - libinput_event_pointer_get_axis_value_discrete(pevent, axes[i]); + (int)libinput_event_pointer_get_axis_value_discrete(pevent, axes[i]); wlr_event.delta_discrete *= WLR_POINTER_AXIS_DISCRETE_STEP; wl_signal_emit_mutable(&pointer->events.axis, &wlr_event); } @@ -155,7 +155,7 @@ void handle_pointer_axis_value120(struct libinput_event *event, libinput_event_pointer_get_scroll_value(pevent, axes[i]); if (source == WLR_AXIS_SOURCE_WHEEL) { wlr_event.delta_discrete = - libinput_event_pointer_get_scroll_value_v120(pevent, axes[i]); + (int)libinput_event_pointer_get_scroll_value_v120(pevent, axes[i]); } wl_signal_emit_mutable(&pointer->events.axis, &wlr_event); } diff --git a/examples/dmabuf-capture.c b/examples/dmabuf-capture.c index 58bf64195..1983bffa4 100644 --- a/examples/dmabuf-capture.c +++ b/examples/dmabuf-capture.c @@ -633,7 +633,7 @@ static int init_encoding(struct capture_context *ctx) { return 1; ctx->avctx->opaque = ctx; - ctx->avctx->bit_rate = (int)ctx->out_bitrate*1000000.0f; + ctx->avctx->bit_rate = (int)(ctx->out_bitrate * 1000000.0f); ctx->avctx->pix_fmt = ctx->software_format; ctx->avctx->time_base = (AVRational){ 1, 1000 }; ctx->avctx->compression_level = 7; diff --git a/examples/fullscreen-shell.c b/examples/fullscreen-shell.c index bc4bb7a86..04ddd8bf8 100644 --- a/examples/fullscreen-shell.c +++ b/examples/fullscreen-shell.c @@ -62,10 +62,10 @@ static void render_surface(struct wlr_surface *surface, } struct wlr_box box = { - .x = sx * output->scale, - .y = sy * output->scale, - .width = surface->current.width * output->scale, - .height = surface->current.height * output->scale, + .x = (int)(sx * output->scale), + .y = (int)(sy * output->scale), + .width = (int)(surface->current.width * output->scale), + .height = (int)(surface->current.height * output->scale), }; float matrix[9]; @@ -95,7 +95,7 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { wlr_renderer_begin(renderer, width, height); - float color[4] = {0.3, 0.3, 0.3, 1.0}; + float color[4] = {0.3f, 0.3f, 0.3f, 1.0f}; wlr_renderer_clear(renderer, color); if (output->surface != NULL) { diff --git a/examples/input-inhibitor.c b/examples/input-inhibitor.c index 6440b2b72..23205a30b 100644 --- a/examples/input-inhibitor.c +++ b/examples/input-inhibitor.c @@ -26,9 +26,9 @@ static void render_frame(void) { glViewport(0, 0, width, height); if (keys) { - glClearColor(1.0, 1.0, 1.0, 1.0); + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); } else { - glClearColor(0.8, 0.4, 1.0, 1.0); + glClearColor(0.8f, 0.4f, 1.0f, 1.0f); } glClear(GL_COLOR_BUFFER_BIT); diff --git a/examples/layer-shell.c b/examples/layer-shell.c index f2e0aaa71..f8cd22267 100644 --- a/examples/layer-shell.c +++ b/examples/layer-shell.c @@ -39,13 +39,13 @@ struct wl_egl_window *popup_egl_window; static uint32_t popup_width = 256, popup_height = 256; struct wlr_egl_surface *popup_egl_surface; struct wl_callback *popup_frame_callback; -float popup_alpha = 1.0, popup_red = 0.5f; +float popup_alpha = 1.0f, popup_red = 0.5f; static uint32_t layer = ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; static uint32_t anchor = 0; static uint32_t width = 256, height = 256; static int32_t margin_top = 0; -static double alpha = 1.0; +static float alpha = 1.0f; static bool run_display = true; static bool animate = false; static enum zwlr_layer_surface_v1_keyboard_interactivity keyboard_interactive = @@ -148,15 +148,15 @@ static void draw(void) { } static void draw_popup(void) { - static float alpha_mod = -0.01; + static float alpha_mod = -0.01f; eglMakeCurrent(egl_display, popup_egl_surface, popup_egl_surface, egl_context); glViewport(0, 0, popup_width, popup_height); glClearColor(popup_red * popup_alpha, 0.5f * popup_alpha, 0.5f * popup_alpha, popup_alpha); popup_alpha += alpha_mod; - if (popup_alpha < 0.01 || popup_alpha >= 1.0f) { - alpha_mod *= -1.0; + if (popup_alpha < 0.01f || popup_alpha >= 1.0f) { + alpha_mod *= -1.0f; } glClear(GL_COLOR_BUFFER_BIT); @@ -324,9 +324,9 @@ static void wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } else if (input_surface == popup_wl_surface) { if (state == WL_POINTER_BUTTON_STATE_PRESSED) { if (button == BTN_LEFT && popup_red <= 0.9f) { - popup_red += 0.1; + popup_red += 0.1f; } else if (button == BTN_RIGHT && popup_red >= 0.1f) { - popup_red -= 0.1; + popup_red -= 0.1f; } } } else { @@ -541,7 +541,7 @@ int main(int argc, char **argv) { break; } case 't': - alpha = atof(optarg); + alpha = (float)atof(optarg); break; case 'm': { char *endptr = optarg; diff --git a/examples/output-layout.c b/examples/output-layout.c index 97939953f..78b893844 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -82,25 +82,25 @@ static void animate_cat(struct sample_state *sample, sample->x_offs = l_output->x + 20; sample->y_offs = l_output->y + 20; } else if (ur_collision && ul_collision) { - sample->y_vel = fabs(sample->y_vel); + sample->y_vel = fabsf(sample->y_vel); } else if (lr_collision && ll_collision) { - sample->y_vel = -fabs(sample->y_vel); + sample->y_vel = -fabsf(sample->y_vel); } else if (ll_collision && ul_collision) { - sample->x_vel = fabs(sample->x_vel); + sample->x_vel = fabsf(sample->x_vel); } else if (ur_collision && lr_collision) { - sample->x_vel = -fabs(sample->x_vel); + sample->x_vel = -fabsf(sample->x_vel); } else { if (ur_collision || lr_collision) { - sample->x_vel = -fabs(sample->x_vel); + sample->x_vel = -fabsf(sample->x_vel); } if (ul_collision || ll_collision) { - sample->x_vel = fabs(sample->x_vel); + sample->x_vel = fabsf(sample->x_vel); } if (ul_collision || ur_collision) { - sample->y_vel = fabs(sample->y_vel); + sample->y_vel = fabsf(sample->y_vel); } if (ll_collision || lr_collision) { - sample->y_vel = -fabs(sample->y_vel); + sample->y_vel = -fabsf(sample->y_vel); } } @@ -119,12 +119,12 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { wlr_output_attach_render(wlr_output, NULL); wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height); - wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); + wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1.0f}); animate_cat(sample, output->output); struct wlr_box box = { - .x = sample->x_offs, .y = sample->y_offs, + .x = (int)sample->x_offs, .y = (int)sample->y_offs, .width = 128, .height = 128, }; if (wlr_output_layout_intersects(sample->layout, output->output, &box)) { @@ -135,7 +135,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { &local_x, &local_y); wlr_render_texture(sample->renderer, sample->cat_texture, - wlr_output->transform_matrix, local_x, local_y, 1.0f); + wlr_output->transform_matrix, + (int)local_x, (int)local_y, 1.0f); } wlr_renderer_end(sample->renderer); diff --git a/examples/quads.c b/examples/quads.c index a9c7a14b8..27e6dba02 100644 --- a/examples/quads.c +++ b/examples/quads.c @@ -87,9 +87,9 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { wlr_output_commit(wlr_output); //TODO rotate with a delta time - rotation += 0.05; + rotation += 0.05f; if (rotation > 2 * M_PI) { - rotation = 0.f; + rotation = 0.0f; } sample->last_frame = now; diff --git a/examples/tablet.c b/examples/tablet.c index 1fb0233bb..7e4bfec18 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -91,17 +91,17 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { wlr_renderer_begin(sample->renderer, wlr_output->width, wlr_output->height); wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1}); - float distance = 0.8f * (1 - sample->distance); + float distance = 0.8f * (float)(1.0 - sample->distance); float tool_color[4] = { distance, distance, distance, 1 }; for (size_t i = 0; sample->button && i < 4; ++i) { tool_color[i] = sample->tool_color[i]; } float scale = 4; - float pad_width = sample->width_mm * scale; - float pad_height = sample->height_mm * scale; - float left = width / 2.0f - pad_width / 2.0f; - float top = height / 2.0f - pad_height / 2.0f; + int pad_width = (int)(sample->width_mm * scale); + int pad_height = (int)(sample->height_mm * scale); + int left = (int)(width / 2.0f - pad_width / 2.0f); + int top = (int)(height / 2.0f - pad_height / 2.0f); const struct wlr_box box = { .x = left, .y = top, .width = pad_width, .height = pad_height, @@ -111,18 +111,18 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { if (sample->proximity) { struct wlr_box box = { - .x = (sample->x * pad_width) - 8 * (sample->pressure + 1) + left, - .y = (sample->y * pad_height) - 8 * (sample->pressure + 1) + top, - .width = 16 * (sample->pressure + 1), - .height = 16 * (sample->pressure + 1), + .x = (int)((sample->x * pad_width) - 8 * (sample->pressure + 1) + left), + .y = (int)((sample->y * pad_height) - 8 * (sample->pressure + 1) + top), + .width = (int)(16 * (sample->pressure + 1)), + .height = (int)(16 * (sample->pressure + 1)), }; float matrix[9]; wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, - sample->ring, wlr_output->transform_matrix); + (float)sample->ring, wlr_output->transform_matrix); wlr_render_quad_with_matrix(sample->renderer, tool_color, matrix); - box.x += sample->x_tilt; - box.y += sample->y_tilt; + box.x += (int)sample->x_tilt; + box.y += (int)sample->y_tilt; box.width /= 2; box.height /= 2; wlr_render_rect(sample->renderer, &box, tool_color, diff --git a/examples/text-input.c b/examples/text-input.c index 2f530d274..19b58959a 100644 --- a/examples/text-input.c +++ b/examples/text-input.c @@ -69,9 +69,9 @@ struct wlr_egl_surface *egl_surface; static void draw(void) { eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context); - float color[] = {1.0, 1.0, 0.0, 1.0}; - color[0] = enabled * 1.0; - color[1] = entered * 1.0; + float color[] = {1.0f, 1.0f, 0.0f, 1.0f}; + color[0] = enabled * 1.0f; + color[1] = entered * 1.0f; glViewport(0, 0, width, height); glClearColor(color[0], color[1], color[2], 1.0); diff --git a/meson.build b/meson.build index 1473e2389..da2a54522 100644 --- a/meson.build +++ b/meson.build @@ -46,6 +46,8 @@ add_project_arguments(cc.get_supported_arguments([ '-Wno-missing-braces', '-Wno-missing-field-initializers', '-Wno-unused-parameter', + + '-Wfloat-conversion', ]), language: 'c') # Compute the relative path used by compiler invocations. diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index c00a7f51c..caf78d01b 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -305,10 +305,10 @@ static bool gles2_render_subtexture_with_matrix( glUniform1i(shader->tex, 0); glUniform1f(shader->alpha, alpha); - const GLfloat x1 = box->x / wlr_texture->width; - const GLfloat y1 = box->y / wlr_texture->height; - const GLfloat x2 = (box->x + box->width) / wlr_texture->width; - const GLfloat y2 = (box->y + box->height) / wlr_texture->height; + const GLfloat x1 = (GLfloat)(box->x / wlr_texture->width); + const GLfloat y1 = (GLfloat)(box->y / wlr_texture->height); + const GLfloat x2 = (GLfloat)((box->x + box->width) / wlr_texture->width); + const GLfloat y2 = (GLfloat)((box->y + box->height) / wlr_texture->height); const GLfloat texcoord[] = { x2, y1, // top right x1, y1, // top left diff --git a/render/pixman/renderer.c b/render/pixman/renderer.c index 2853b7047..fc1639342 100644 --- a/render/pixman/renderer.c +++ b/render/pixman/renderer.c @@ -169,10 +169,10 @@ static void pixman_clear(struct wlr_renderer *wlr_renderer, struct wlr_pixman_buffer *buffer = renderer->current_buffer; const struct pixman_color colour = { - .red = color[0] * 0xFFFF, - .green = color[1] * 0xFFFF, - .blue = color[2] * 0xFFFF, - .alpha = color[3] * 0xFFFF, + .red = (uint16_t)(color[0] * 0xFFFF), + .green = (uint16_t)(color[1] * 0xFFFF), + .blue = (uint16_t)(color[2] * 0xFFFF), + .alpha = (uint16_t)(color[3] * 0xFFFF), }; pixman_image_t *fill = pixman_image_create_solid_fill(&colour); @@ -247,12 +247,12 @@ static bool pixman_render_subtexture_with_matrix( // TODO: don't create a mask if alpha == 1.0 struct pixman_color mask_colour = {0}; - mask_colour.alpha = 0xFFFF * alpha; + mask_colour.alpha = (uint16_t)(0xFFFF * alpha); pixman_image_t *mask = pixman_image_create_solid_fill(&mask_colour); float m[9]; memcpy(m, matrix, sizeof(m)); - wlr_matrix_scale(m, 1.0 / fbox->width, 1.0 / fbox->height); + wlr_matrix_scale(m, 1.0f / (float)fbox->width, 1.0f / (float)fbox->height); struct pixman_transform transform = {0}; matrix_to_pixman_transform(&transform, m); @@ -279,11 +279,11 @@ static void pixman_render_quad_with_matrix(struct wlr_renderer *wlr_renderer, struct wlr_pixman_renderer *renderer = get_renderer(wlr_renderer); struct wlr_pixman_buffer *buffer = renderer->current_buffer; - struct pixman_color colour = { - .red = color[0] * 0xFFFF, - .green = color[1] * 0xFFFF, - .blue = color[2] * 0xFFFF, - .alpha = color[3] * 0xFFFF, + const struct pixman_color colour = { + .red = (uint16_t)(color[0] * 0xFFFF), + .green = (uint16_t)(color[1] * 0xFFFF), + .blue = (uint16_t)(color[2] * 0xFFFF), + .alpha = (uint16_t)(color[3] * 0xFFFF), }; pixman_image_t *fill = pixman_image_create_solid_fill(&colour); @@ -294,21 +294,21 @@ static void pixman_render_quad_with_matrix(struct wlr_renderer *wlr_renderer, // TODO get the width/height from the caller instead of extracting them float width, height; if (matrix[1] == 0.0 && matrix[3] == 0.0) { - width = fabs(matrix[0]); - height = fabs(matrix[4]); + width = fabsf(matrix[0]); + height = fabsf(matrix[4]); } else { - width = sqrt(matrix[0] * matrix[0] + matrix[1] * matrix[1]); - height = sqrt(matrix[3] * matrix[3] + matrix[4] * matrix[4]); + width = sqrtf(matrix[0] * matrix[0] + matrix[1] * matrix[1]); + height = sqrtf(matrix[3] * matrix[3] + matrix[4] * matrix[4]); } - wlr_matrix_scale(m, 1.0 / width, 1.0 / height); + wlr_matrix_scale(m, 1.0f / width, 1.0f / height); - pixman_image_t *image = pixman_image_create_bits(PIXMAN_a8r8g8b8, width, - height, NULL, 0); + pixman_image_t *image = pixman_image_create_bits(PIXMAN_a8r8g8b8, + (int)width, (int)height, NULL, 0); // TODO find a way to fill the image without allocating 2 images pixman_image_composite32(PIXMAN_OP_SRC, fill, NULL, image, - 0, 0, 0, 0, 0, 0, width, height); + 0, 0, 0, 0, 0, 0, (int)width, (int)height); pixman_image_unref(fill); struct pixman_transform transform = {0}; diff --git a/render/vulkan/renderer.c b/render/vulkan/renderer.c index 45796ca9b..9550b9812 100644 --- a/render/vulkan/renderer.c +++ b/render/vulkan/renderer.c @@ -59,9 +59,9 @@ struct vert_pcr_data { // https://www.w3.org/Graphics/Color/srgb static float color_to_linear(float non_linear) { - return (non_linear > 0.04045) ? - pow((non_linear + 0.055) / 1.055, 2.4) : - non_linear / 12.92; + return (non_linear > 0.04045f) ? + powf((non_linear + 0.055f) / 1.055f, 2.4f) : + non_linear / 12.92f; } // renderer @@ -776,10 +776,10 @@ static bool vulkan_render_subtexture_with_matrix(struct wlr_renderer *wlr_render struct vert_pcr_data vert_pcr_data; mat3_to_mat4(final_matrix, vert_pcr_data.mat4); - vert_pcr_data.uv_off[0] = box->x / wlr_texture->width; - vert_pcr_data.uv_off[1] = box->y / wlr_texture->height; - vert_pcr_data.uv_size[0] = box->width / wlr_texture->width; - vert_pcr_data.uv_size[1] = box->height / wlr_texture->height; + vert_pcr_data.uv_off[0] = (float)(box->x / wlr_texture->width); + vert_pcr_data.uv_off[1] = (float)(box->y / wlr_texture->height); + vert_pcr_data.uv_size[0] = (float)(box->width / wlr_texture->width); + vert_pcr_data.uv_size[1] = (float)(box->height / wlr_texture->height); vkCmdPushConstants(cb, renderer->pipe_layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(vert_pcr_data), &vert_pcr_data); diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index 4fc8477c7..d04ae82f2 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -366,8 +366,8 @@ static struct tinywl_view *desktop_view_at( static void process_cursor_move(struct tinywl_server *server, uint32_t time) { /* Move the grabbed view to the new position. */ struct tinywl_view *view = server->grabbed_view; - view->x = server->cursor->x - server->grab_x; - view->y = server->cursor->y - server->grab_y; + view->x = (int)(server->cursor->x - server->grab_x); + view->y = (int)(server->cursor->y - server->grab_y); wlr_scene_node_set_position(&view->scene_tree->node, view->x, view->y); } @@ -383,8 +383,8 @@ static void process_cursor_resize(struct tinywl_server *server, uint32_t time) { * commit any movement that was prepared. */ struct tinywl_view *view = server->grabbed_view; - double border_x = server->cursor->x - server->grab_x; - double border_y = server->cursor->y - server->grab_y; + int border_x = (int)(server->cursor->x - server->grab_x); + int border_y = (int)(server->cursor->y - server->grab_y); int new_left = server->grab_geobox.x; int new_right = server->grab_geobox.x + server->grab_geobox.width; int new_top = server->grab_geobox.y; diff --git a/types/output/cursor.c b/types/output/cursor.c index b4eb55af4..2db699bc7 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -81,8 +81,8 @@ static void output_scissor(struct wlr_output *output, pixman_box32_t *rect) { */ static void output_cursor_get_box(struct wlr_output_cursor *cursor, struct wlr_box *box) { - box->x = cursor->x - cursor->hotspot_x; - box->y = cursor->y - cursor->hotspot_y; + box->x = (int)(cursor->x - cursor->hotspot_x); + box->y = (int)(cursor->y - cursor->hotspot_y); box->width = cursor->width; box->height = cursor->height; } @@ -287,8 +287,8 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor) } struct wlr_box cursor_box = { - .width = texture->width * output->scale / scale, - .height = texture->height * output->scale / scale, + .width = (int)(texture->width * output->scale / scale), + .height = (int)(texture->height * output->scale / scale), }; float output_matrix[9]; @@ -300,11 +300,11 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor) }; wlr_box_transform(&tr_size, &tr_size, output->transform, 0, 0); - wlr_matrix_translate(output_matrix, buffer->width / 2.0, - buffer->height / 2.0); + wlr_matrix_translate(output_matrix, buffer->width / 2.0f, + buffer->height / 2.0f); wlr_matrix_transform(output_matrix, output->transform); - wlr_matrix_translate(output_matrix, - tr_size.width / 2.0, - - tr_size.height / 2.0); + wlr_matrix_translate(output_matrix, - tr_size.width / 2.0f, + - tr_size.height / 2.0f); } float matrix[9]; @@ -446,12 +446,12 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor, // Some clients commit a cursor surface with a NULL buffer to hide it. cursor->enabled = wlr_surface_has_buffer(surface); - cursor->width = surface->current.width * cursor->output->scale; - cursor->height = surface->current.height * cursor->output->scale; + cursor->width = (int)(surface->current.width * cursor->output->scale); + cursor->height = (int)(surface->current.height * cursor->output->scale); output_cursor_update_visible(cursor); if (update_hotspot) { - cursor->hotspot_x -= surface->current.dx * cursor->output->scale; - cursor->hotspot_y -= surface->current.dy * cursor->output->scale; + cursor->hotspot_x -= (int32_t)(surface->current.dx * cursor->output->scale); + cursor->hotspot_y -= (int32_t)(surface->current.dy * cursor->output->scale); } if (output_cursor_attempt_hardware(cursor)) { @@ -478,8 +478,8 @@ static void output_cursor_handle_destroy(struct wl_listener *listener, void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { - hotspot_x *= cursor->output->scale; - hotspot_y *= cursor->output->scale; + hotspot_x = (int32_t)(hotspot_x * cursor->output->scale); + hotspot_y = (int32_t)(hotspot_y * cursor->output->scale); if (surface && surface == cursor->surface) { // Only update the hotspot: surface hasn't changed diff --git a/types/output/output.c b/types/output/output.c index cd0cc9344..5bee4d273 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -197,10 +197,10 @@ static void output_update_matrix(struct wlr_output *output) { wlr_output_transformed_resolution(output, &tr_width, &tr_height); wlr_matrix_translate(output->transform_matrix, - output->width / 2.0, output->height / 2.0); + output->width / 2.0f, output->height / 2.0f); wlr_matrix_transform(output->transform_matrix, output->transform); wlr_matrix_translate(output->transform_matrix, - - tr_width / 2.0, - tr_height / 2.0); + - tr_width / 2.0f, - tr_height / 2.0f); } } @@ -439,8 +439,8 @@ void wlr_output_transformed_resolution(struct wlr_output *output, void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height) { wlr_output_transformed_resolution(output, width, height); - *width /= output->scale; - *height /= output->scale; + *width = (int)(*width / output->scale); + *height = (int)(*height / output->scale); } struct wlr_output_mode *wlr_output_preferred_mode(struct wlr_output *output) { diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index dff664d27..f2b2b9568 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -601,7 +601,8 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff wlr_region_transform(&trans_damage, damage, scene_buffer->transform, buffer->width, buffer->height); pixman_region32_intersect_rect(&trans_damage, &trans_damage, - box.x, box.y, box.width, box.height); + (int)box.x, (int)box.y, + (unsigned int)box.width, (unsigned int)box.height); struct wlr_scene *scene = scene_node_get_root(&scene_buffer->node); struct wlr_scene_output *scene_output; @@ -610,18 +611,21 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff pixman_region32_t output_damage; pixman_region32_init(&output_damage); wlr_region_scale_xy(&output_damage, &trans_damage, - output_scale * scale_x, output_scale * scale_y); + (float)(output_scale * scale_x), + (float)(output_scale * scale_y)); pixman_region32_t cull_region; pixman_region32_init(&cull_region); wlr_region_scale(&cull_region, &scene_buffer->node.visible, output_scale); - pixman_region32_translate(&cull_region, -lx * output_scale, -ly * output_scale); + pixman_region32_translate(&cull_region, + (int)(-lx * output_scale), + (int)(-ly * output_scale)); pixman_region32_intersect(&output_damage, &output_damage, &cull_region); pixman_region32_fini(&cull_region); pixman_region32_translate(&output_damage, - (lx - scene_output->x) * output_scale, - (ly - scene_output->y) * output_scale); + (int)((lx - scene_output->x) * output_scale), + (int)((ly - scene_output->y) * output_scale)); if (wlr_damage_ring_add(&scene_output->damage_ring, &output_damage)) { wlr_output_schedule_frame(scene_output->output); } @@ -740,14 +744,14 @@ static void scene_node_get_size(struct wlr_scene_node *node, } static int scale_length(int length, int offset, float scale) { - return round((offset + length) * scale) - round(offset * scale); + return (int)(round((offset + length) * scale) - round(offset * scale)); } static void scale_box(struct wlr_box *box, float scale) { box->width = scale_length(box->width, box->x, scale); box->height = scale_length(box->height, box->y, scale); - box->x = round(box->x * scale); - box->y = round(box->y * scale); + box->x = (int)round(box->x * scale); + box->y = (int)round(box->y * scale); } void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled) { @@ -900,8 +904,8 @@ void wlr_scene_node_for_each_buffer(struct wlr_scene_node *node, } struct node_at_data { - double lx, ly; - double rx, ry; + int lx, ly; + int rx, ry; struct wlr_scene_node *node; }; @@ -909,8 +913,8 @@ static bool scene_node_at_iterator(struct wlr_scene_node *node, int lx, int ly, void *data) { struct node_at_data *at_data = data; - double rx = at_data->lx - lx; - double ry = at_data->ly - ly; + int rx = at_data->lx - lx; + int ry = at_data->ly - ly; if (node->type == WLR_SCENE_NODE_BUFFER) { struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node); @@ -930,15 +934,15 @@ static bool scene_node_at_iterator(struct wlr_scene_node *node, struct wlr_scene_node *wlr_scene_node_at(struct wlr_scene_node *node, double lx, double ly, double *nx, double *ny) { struct wlr_box box = { - .x = floor(lx), - .y = floor(ly), + .x = (int)floor(lx), + .y = (int)floor(ly), .width = 1, .height = 1 }; struct node_at_data data = { - .lx = lx, - .ly = ly + .lx = (int)lx, + .ly = (int)ly }; if (scene_nodes_in_box(node, &box, scene_node_at_iterator, &data)) { @@ -1545,7 +1549,7 @@ bool wlr_scene_output_commit(struct wlr_scene_output *scene_output) { struct timespec time_diff; timespec_sub(&time_diff, &now, &damage->when); int64_t time_diff_ms = timespec_to_msec(&time_diff); - float alpha = 1.0 - (double)time_diff_ms / HIGHLIGHT_DAMAGE_FADEOUT_TIME; + float alpha = 1.0f - (float)time_diff_ms / HIGHLIGHT_DAMAGE_FADEOUT_TIME; int nrects; pixman_box32_t *rects = pixman_region32_rectangles(&damage->region, &nrects); @@ -1557,7 +1561,7 @@ bool wlr_scene_output_commit(struct wlr_scene_output *scene_output) { .height = rects[i].y2 - rects[i].y1, }; - float color[4] = { alpha * .5, 0.0, 0.0, alpha * .5 }; + float color[4] = { alpha * 0.5f, 0.0f, 0.0f, alpha * 0.5f }; wlr_render_rect(renderer, &box, color, output->transform_matrix); } } diff --git a/types/seat/wlr_seat_pointer.c b/types/seat/wlr_seat_pointer.c index 8d6154b02..17a9dae02 100644 --- a/types/seat/wlr_seat_pointer.c +++ b/types/seat/wlr_seat_pointer.c @@ -350,8 +350,8 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time, if (send_source && version >= WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { wl_pointer_send_axis_source(resource, source); } - if (value) { - if (value_discrete) { + if (value != 0.0) { + if (value_discrete != 0) { if (version >= WL_POINTER_AXIS_VALUE120_SINCE_VERSION) { // High resolution discrete scrolling wl_pointer_send_axis_value120(resource, orientation, diff --git a/types/tablet_v2/wlr_tablet_v2_pad.c b/types/tablet_v2/wlr_tablet_v2_pad.c index 1bdb4ab76..68dcbfe76 100644 --- a/types/tablet_v2/wlr_tablet_v2_pad.c +++ b/types/tablet_v2/wlr_tablet_v2_pad.c @@ -505,7 +505,7 @@ void wlr_send_tablet_v2_tablet_pad_strip(struct wlr_tablet_v2_tablet_pad *pad, if (position < 0) { zwp_tablet_pad_strip_v2_send_stop(resource); } else { - zwp_tablet_pad_strip_v2_send_position(resource, position * 65535); + zwp_tablet_pad_strip_v2_send_position(resource, (int)(position * 65535)); } zwp_tablet_pad_strip_v2_send_frame(resource, time); } @@ -526,7 +526,8 @@ void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad, if (position < 0) { zwp_tablet_pad_ring_v2_send_stop(resource); } else { - zwp_tablet_pad_ring_v2_send_angle(resource, position); + zwp_tablet_pad_ring_v2_send_angle(resource, + wl_fixed_from_double(position)); } zwp_tablet_pad_ring_v2_send_frame(resource, time); } diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index df8ab7618..a4aee1f2b 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -415,7 +415,7 @@ void wlr_send_tablet_v2_tablet_tool_pressure( struct wlr_tablet_v2_tablet_tool *tool, double pressure) { if (tool->current_client) { zwp_tablet_tool_v2_send_pressure(tool->current_client->resource, - pressure * 65535); + (uint32_t)(pressure * 65535)); queue_tool_frame(tool->current_client); } @@ -425,7 +425,7 @@ void wlr_send_tablet_v2_tablet_tool_distance( struct wlr_tablet_v2_tablet_tool *tool, double distance) { if (tool->current_client) { zwp_tablet_tool_v2_send_distance(tool->current_client->resource, - distance * 65535); + (uint32_t)(distance * 65535)); queue_tool_frame(tool->current_client); } @@ -462,7 +462,7 @@ void wlr_send_tablet_v2_tablet_tool_slider( } zwp_tablet_tool_v2_send_slider(tool->current_client->resource, - position * 65535); + (uint32_t)(position * 65535)); queue_tool_frame(tool->current_client); } @@ -489,7 +489,7 @@ void wlr_send_tablet_v2_tablet_tool_wheel( struct wlr_tablet_v2_tablet_tool *tool, double degrees, int32_t clicks) { if (tool->current_client) { zwp_tablet_tool_v2_send_wheel(tool->current_client->resource, - clicks, degrees); + wl_fixed_from_double(degrees), clicks); queue_tool_frame(tool->current_client); } diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index 03acb6ec9..ddd71c613 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -164,8 +164,8 @@ static void surface_state_viewport_src_size(struct wlr_surface_state *state, } if (state->viewport.has_src) { - *out_width = state->viewport.src.width; - *out_height = state->viewport.src.height; + *out_width = (int)state->viewport.src.width; + *out_height = (int)state->viewport.src.height; } else { surface_state_transformed_buffer_size(state, out_width, out_height); @@ -248,13 +248,13 @@ static void surface_update_damage(pixman_region32_t *buffer_damage, float scale_x = (float)pending->viewport.dst_width / src_width; float scale_y = (float)pending->viewport.dst_height / src_height; wlr_region_scale_xy(&surface_damage, &surface_damage, - 1.0 / scale_x, 1.0 / scale_y); + 1.0f / scale_x, 1.0f / scale_y); } if (pending->viewport.has_src) { // This is lossy: do a best-effort conversion pixman_region32_translate(&surface_damage, - floor(pending->viewport.src.x), - floor(pending->viewport.src.y)); + (int)floor(pending->viewport.src.x), + (int)floor(pending->viewport.src.y)); } wlr_region_scale(&surface_damage, &surface_damage, pending->scale); @@ -795,7 +795,8 @@ bool wlr_surface_point_accepts_input(struct wlr_surface *surface, double sx, double sy) { return sx >= 0 && sx < surface->current.width && sy >= 0 && sy < surface->current.height && - pixman_region32_contains_point(&surface->current.input, floor(sx), floor(sy), NULL); + pixman_region32_contains_point(&surface->current.input, + (int)floor(sx), (int)floor(sy), NULL); } struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface, @@ -1018,14 +1019,14 @@ void wlr_surface_get_effective_damage(struct wlr_surface *surface, wlr_region_transform(damage, &surface->buffer_damage, surface->current.transform, surface->current.buffer_width, surface->current.buffer_height); - wlr_region_scale(damage, damage, 1.0 / (float)surface->current.scale); + wlr_region_scale(damage, damage, 1.0f / (float)surface->current.scale); if (surface->current.viewport.has_src) { struct wlr_box src_box = { - .x = floor(surface->current.viewport.src.x), - .y = floor(surface->current.viewport.src.y), - .width = ceil(surface->current.viewport.src.width), - .height = ceil(surface->current.viewport.src.height), + .x = (int)floor(surface->current.viewport.src.x), + .y = (int)floor(surface->current.viewport.src.y), + .width = (int)ceil(surface->current.viewport.src.width), + .height = (int)ceil(surface->current.viewport.src.height), }; crop_region(damage, damage, &src_box); } diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index aafae2482..c5c4fe1d6 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -280,7 +280,7 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev, result = wlr_box_contains_point(&mapping, lx, ly); } else { result = wlr_output_layout_contains_point(cur->state->layout, NULL, - lx, ly); + (int)lx, (int)ly); } if (result) { @@ -818,8 +818,8 @@ static void handle_layout_change(struct wl_listener *listener, void *data) { wl_container_of(listener, state, layout_change); struct wlr_output_layout *layout = data; - if (!wlr_output_layout_contains_point(layout, NULL, state->cursor->x, - state->cursor->y)) { + if (!wlr_output_layout_contains_point(layout, NULL, + (int)state->cursor->x, (int)state->cursor->y)) { // the output we were on has gone away so go to the closest boundary // point double x, y; diff --git a/types/wlr_layer_shell_v1.c b/types/wlr_layer_shell_v1.c index f21ae7999..67b9b35f2 100644 --- a/types/wlr_layer_shell_v1.c +++ b/types/wlr_layer_shell_v1.c @@ -558,7 +558,7 @@ void wlr_layer_surface_v1_for_each_popup_surface(struct wlr_layer_surface_v1 *su continue; } - double popup_sx, popup_sy; + int popup_sx, popup_sy; popup_sx = popup->current.geometry.x - popup->base->current.geometry.x; popup_sy = popup->current.geometry.y - popup->base->current.geometry.y; diff --git a/types/wlr_matrix.c b/types/wlr_matrix.c index 7b6671f57..6deb86a43 100644 --- a/types/wlr_matrix.c +++ b/types/wlr_matrix.c @@ -63,9 +63,9 @@ void wlr_matrix_scale(float mat[static 9], float x, float y) { void wlr_matrix_rotate(float mat[static 9], float rad) { float rotate[9] = { - cos(rad), -sin(rad), 0.0f, - sin(rad), cos(rad), 0.0f, - 0.0f, 0.0f, 1.0f, + cosf(rad), -sinf(rad), 0.0f, + sinf(rad), cosf(rad), 0.0f, + 0.0f, 0.0f, 1.0f, }; wlr_matrix_multiply(mat, mat, rotate); } @@ -133,8 +133,8 @@ void matrix_projection(float mat[static 9], int width, int height, mat[4] = y * -t[4]; // Translation - mat[2] = -copysign(1.0f, mat[0] + mat[1]); - mat[5] = -copysign(1.0f, mat[3] + mat[4]); + mat[2] = -copysignf(1.0f, mat[0] + mat[1]); + mat[5] = -copysignf(1.0f, mat[3] + mat[4]); // Identity mat[8] = 1.0f; diff --git a/types/wlr_output_management_v1.c b/types/wlr_output_management_v1.c index 3fb9cf432..aa7f96933 100644 --- a/types/wlr_output_management_v1.c +++ b/types/wlr_output_management_v1.c @@ -247,7 +247,7 @@ static void config_head_handle_set_scale(struct wl_client *client, return; } - float scale = wl_fixed_to_double(scale_fixed); + float scale = (float)wl_fixed_to_double(scale_fixed); if (scale <= 0) { wl_resource_post_error(config_head_resource, ZWLR_OUTPUT_CONFIGURATION_HEAD_V1_ERROR_INVALID_SCALE, diff --git a/types/wlr_screencopy_v1.c b/types/wlr_screencopy_v1.c index 30e529a9a..b8409c191 100644 --- a/types/wlr_screencopy_v1.c +++ b/types/wlr_screencopy_v1.c @@ -570,10 +570,10 @@ static void capture_output(struct wl_client *wl_client, buffer_box = *box; wlr_box_transform(&buffer_box, &buffer_box, output->transform, ow, oh); - buffer_box.x *= output->scale; - buffer_box.y *= output->scale; - buffer_box.width *= output->scale; - buffer_box.height *= output->scale; + buffer_box.x = (int)(buffer_box.x * output->scale); + buffer_box.y = (int)(buffer_box.y * output->scale); + buffer_box.width = (int)(buffer_box.width * output->scale); + buffer_box.height = (int)(buffer_box.height * output->scale); } frame->box = buffer_box; diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c index 3526285bb..d5f570162 100644 --- a/types/wlr_xcursor_manager.c +++ b/types/wlr_xcursor_manager.c @@ -46,7 +46,8 @@ bool wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager, return false; } theme->scale = scale; - theme->theme = wlr_xcursor_theme_load(manager->name, manager->size * scale); + theme->theme = wlr_xcursor_theme_load(manager->name, + (int)(manager->size * scale)); if (theme->theme == NULL) { free(theme); return false; diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index ae0dfcc14..75d7a5f51 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -528,16 +528,19 @@ static void xdg_surface_for_each_popup_surface(struct wlr_xdg_surface *surface, double popup_sx, popup_sy; wlr_xdg_popup_get_position(popup, &popup_sx, &popup_sy); + int sx = x + (int)popup_sx, sy = y + (int)popup_sy; + struct xdg_surface_iterator_data data = { .user_iterator = iterator, .user_data = user_data, - .x = x + popup_sx, .y = y + popup_sy, + .x = sx, + .y = sy, }; wlr_surface_for_each_surface(popup->base->surface, xdg_surface_iterator, &data); xdg_surface_for_each_popup_surface(popup->base, - x + popup_sx, y + popup_sy, iterator, user_data); + sx, sy, iterator, user_data); } } diff --git a/util/box.c b/util/box.c index d7d226179..01d964cfe 100644 --- a/util/box.c +++ b/util/box.c @@ -50,10 +50,13 @@ bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a, return false; } - int x1 = fmax(box_a->x, box_b->x); - int y1 = fmax(box_a->y, box_b->y); - int x2 = fmin(box_a->x + box_a->width, box_b->x + box_b->width); - int y2 = fmin(box_a->y + box_a->height, box_b->y + box_b->height); + int x1 = box_a->x > box_b->x ? box_a->x : box_b->x; + int y1 = box_a->y > box_b->y ? box_a->y : box_b->y; + + int x2a = box_a->x + box_a->width, x2b = box_b->x + box_b->width; + int y2a = box_a->y + box_a->height, y2b = box_b->y + box_b->height; + int x2 = x2a < x2b ? x2a : x2b; + int y2 = y2a < y2b ? y2a : y2b; dest->x = x1; dest->y = y1; diff --git a/util/region.c b/util/region.c index c5bd9e85e..cd058402d 100644 --- a/util/region.c +++ b/util/region.c @@ -25,10 +25,10 @@ void wlr_region_scale_xy(pixman_region32_t *dst, pixman_region32_t *src, } for (int i = 0; i < nrects; ++i) { - dst_rects[i].x1 = floor(src_rects[i].x1 * scale_x); - dst_rects[i].x2 = ceil(src_rects[i].x2 * scale_x); - dst_rects[i].y1 = floor(src_rects[i].y1 * scale_y); - dst_rects[i].y2 = ceil(src_rects[i].y2 * scale_y); + dst_rects[i].x1 = (int)floorf(src_rects[i].x1 * scale_x); + dst_rects[i].x2 = (int)ceilf(src_rects[i].x2 * scale_x); + dst_rects[i].y1 = (int)floorf(src_rects[i].y1 * scale_y); + dst_rects[i].y2 = (int)ceilf(src_rects[i].y2 * scale_y); } pixman_region32_fini(dst); @@ -152,32 +152,32 @@ void wlr_region_rotated_bounds(pixman_region32_t *dst, pixman_region32_t *src, } for (int i = 0; i < nrects; ++i) { - double x1 = src_rects[i].x1 - ox; - double y1 = src_rects[i].y1 - oy; - double x2 = src_rects[i].x2 - ox; - double y2 = src_rects[i].y2 - oy; + float x1 = src_rects[i].x1 - ox; + float y1 = src_rects[i].y1 - oy; + float x2 = src_rects[i].x2 - ox; + float y2 = src_rects[i].y2 - oy; - double rx1 = x1 * cos(rotation) - y1 * sin(rotation); - double ry1 = x1 * sin(rotation) + y1 * cos(rotation); + float rx1 = x1 * cosf(rotation) - y1 * sinf(rotation); + float ry1 = x1 * sinf(rotation) + y1 * cosf(rotation); - double rx2 = x2 * cos(rotation) - y1 * sin(rotation); - double ry2 = x2 * sin(rotation) + y1 * cos(rotation); + float rx2 = x2 * cosf(rotation) - y1 * sinf(rotation); + float ry2 = x2 * sinf(rotation) + y1 * cosf(rotation); - double rx3 = x2 * cos(rotation) - y2 * sin(rotation); - double ry3 = x2 * sin(rotation) + y2 * cos(rotation); + float rx3 = x2 * cosf(rotation) - y2 * sinf(rotation); + float ry3 = x2 * sinf(rotation) + y2 * cosf(rotation); - double rx4 = x1 * cos(rotation) - y2 * sin(rotation); - double ry4 = x1 * sin(rotation) + y2 * cos(rotation); + float rx4 = x1 * cosf(rotation) - y2 * sinf(rotation); + float ry4 = x1 * sinf(rotation) + y2 * cosf(rotation); - x1 = fmin(fmin(rx1, rx2), fmin(rx3, rx4)); - y1 = fmin(fmin(ry1, ry2), fmin(ry3, ry4)); - x2 = fmax(fmax(rx1, rx2), fmax(rx3, rx4)); - y2 = fmax(fmax(ry1, ry2), fmax(ry3, ry4)); + x1 = fminf(fminf(rx1, rx2), fminf(rx3, rx4)); + y1 = fminf(fminf(ry1, ry2), fminf(ry3, ry4)); + x2 = fmaxf(fmaxf(rx1, rx2), fmaxf(rx3, rx4)); + y2 = fmaxf(fmaxf(ry1, ry2), fmaxf(ry3, ry4)); - dst_rects[i].x1 = floor(ox + x1); - dst_rects[i].x2 = ceil(ox + x2); - dst_rects[i].y1 = floor(oy + y1); - dst_rects[i].y2 = ceil(oy + y2); + dst_rects[i].x1 = (int)floorf(ox + x1); + dst_rects[i].x2 = (int)ceilf(ox + x2); + dst_rects[i].y1 = (int)floorf(oy + y1); + dst_rects[i].y2 = (int)ceilf(oy + y2); } pixman_region32_fini(dst); @@ -210,8 +210,8 @@ static void region_confine(pixman_region32_t *region, double x1, double y1, doub double y = fmax(fmin(delta * dy + y1, box.y2 - 1), box.y1); // Go one unit past the boundary to find an adjacent box. - int x_ext = floor(x) + (dx == 0 ? 0 : dx > 0 ? 1 : -1); - int y_ext = floor(y) + (dy == 0 ? 0 : dy > 0 ? 1 : -1); + int x_ext = (int)floor(x) + (dx == 0 ? 0 : dx > 0 ? 1 : -1); + int y_ext = (int)floor(y) + (dy == 0 ? 0 : dy > 0 ? 1 : -1); if (pixman_region32_contains_point(region, x_ext, y_ext, &box)) { return region_confine(region, x, y, x2, y2, x2_out, y2_out, box); @@ -245,7 +245,8 @@ static void region_confine(pixman_region32_t *region, double x1, double y1, doub bool wlr_region_confine(pixman_region32_t *region, double x1, double y1, double x2, double y2, double *x2_out, double *y2_out) { pixman_box32_t box; - if (pixman_region32_contains_point(region, floor(x1), floor(y1), &box)) { + if (pixman_region32_contains_point(region, + (int)floor(x1), (int)floor(y1), &box)) { region_confine(region, x1, y1, x2, y2, x2_out, y2_out, box); return true; } else {