mirror of
https://github.com/wizbright/waybox.git
synced 2026-04-06 07:15:41 -04:00
Ensure that a box's dimensions don't exceed the screen size
Having windows that are bigger than the screen might be good enough for Weston, but it's not good enough for me
This commit is contained in:
parent
114e265eef
commit
02ecb67912
2 changed files with 17 additions and 0 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "waybox/output.h"
|
||||
#define MIN(a, b) (a < b ? a : b)
|
||||
|
||||
struct render_data {
|
||||
struct wlr_output *output;
|
||||
|
|
@ -41,6 +42,21 @@ static void render_surface(struct wlr_surface *surface, int sx, int sy, void *da
|
|||
.height = surface->current.height * output->scale,
|
||||
};
|
||||
|
||||
/* Ensure box dimensions of top-level surfaces don't exceed the output's. */
|
||||
if (!strcmp(surface->role->name, "xdg_toplevel")) {
|
||||
double aspect = (box.width * 1.0) / (box.height * 1.0);
|
||||
if (box.x + box.height > output->height) {
|
||||
box.height = output->height - box.x;
|
||||
}
|
||||
if (box.y + box.width > output->width) {
|
||||
/* Under the rare occasions that the height is larger than the
|
||||
* width, we don't want to divide by < 1 (i.e. make the width even
|
||||
* wider); instead we'll multiply. */
|
||||
box.width = MIN((output->width - box.y) / aspect,
|
||||
(output->width - box.y) * aspect);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Those familiar with OpenGL are also familiar with the role of matrices
|
||||
* in graphics programming. We need to prepare a matrix to render the view
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue