Bug fixes and stuff

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-03 16:59:39 +03:00
parent 952a562bba
commit a2555f5046
6 changed files with 40 additions and 142 deletions

2
.gitmodules vendored
View File

@@ -1,3 +1,3 @@
[submodule "wlroots-lunar"]
path = wlroots-lunar
url = git@github.com:slendidev/wlroots-lunar
url = https://github.com/slendidev/wlroots-lunar

6
flake.lock generated
View File

@@ -97,11 +97,11 @@
]
},
"locked": {
"lastModified": 1759266345,
"narHash": "sha256-BJ+CTRXaFArVFgJfL19QpoR7Ebk8HU63Lz0+jQvhV3Y=",
"lastModified": 1759496058,
"narHash": "sha256-eVgGEO+KhJX307XQ0gbbCWguJfoSJlZRFQrpvalK7kM=",
"owner": "slendidev",
"repo": "wlroots-lunar",
"rev": "1179ca07821decbff320eafd7ffb3caaadcefbf4",
"rev": "00d01dcc297e1991809ad2c0f6b50fb66478d748",
"type": "github"
},
"original": {

View File

@@ -328,16 +328,13 @@ void LunarWM_render_windows(LunarWM *this, bool alpha_check)
if (!tl || !tl->surface) {
continue;
}
if (tl->gles_texture) {
if (alpha_check && tl->composed_has_alpha) {
continue;
}
Texture2D tex = tl->rl_texture;
if (IsTextureValid(tl->surface_rt.texture)) {
Texture2D tex = tl->surface_rt.texture;
bool y_flip = false;
if (IsRenderTextureValid(tl->surface_rt)) {
tex = tl->surface_rt.texture;
tex.width = tl->rl_texture.width;
tex.height = tl->rl_texture.height;
tex.width = tl->surface_rt.texture.width;
tex.height = tl->surface_rt.texture.height;
y_flip = true;
}
if (!tex.id)

View File

@@ -130,15 +130,8 @@ typedef struct {
} u;
struct wlr_surface *surface;
struct wlr_texture *texture;
struct wlr_buffer *locked_buffer;
struct wlr_gles2_texture_attribs attribs;
struct wlr_gles2_texture *gles_texture;
Texture2D rl_texture;
RenderTexture2D surface_rt;
struct wlr_box surface_extents;
bool composed_has_alpha;
} LunarWM_Toplevel;
typedef struct {

View File

@@ -10,6 +10,7 @@
#include <wlr/backend/x11.h>
#include <wlr/render/color.h>
#include <wlr/render/pass.h>
#include <wlr/xwayland/xwayland.h>
#include <assert.h>
#include <math.h>
@@ -427,8 +428,6 @@ static void LunarWM_Toplevel_release_surface_rt(LunarWM_Toplevel *tl)
UnloadRenderTexture(tl->surface_rt);
}
tl->surface_rt = (RenderTexture2D) { 0 };
tl->surface_extents = (struct wlr_box) { 0 };
tl->composed_has_alpha = false;
}
static void remove_windows_for_tl(LunarWM *wm, LunarWM_Toplevel *tl)
@@ -524,16 +523,8 @@ static void toplevel_unmap_notify(struct wl_listener *l, void *data)
if (tl->commit.link.prev || tl->commit.link.next)
wl_list_remove(&tl->commit.link);
if (tl->locked_buffer) {
wlr_buffer_unlock(tl->locked_buffer);
tl->locked_buffer = NULL;
}
tl->texture = NULL;
tl->gles_texture = NULL;
tl->rl_texture = (Texture) { 0 };
LunarWM_Toplevel_release_surface_rt(tl);
tl->surface = NULL;
tl->composed_has_alpha = false;
focus_fallback(tl->server);
}
@@ -601,16 +592,13 @@ bool LunarWM_Toplevel_destroy(LunarWM_Toplevel *this)
wl_list_remove(&this->commit.link);
if (this->destroy.link.prev || this->destroy.link.next)
wl_list_remove(&this->destroy.link);
if (this->locked_buffer)
wlr_buffer_unlock(this->locked_buffer);
LunarWM_Toplevel_release_surface_rt(this);
this->composed_has_alpha = false;
return true;
}
struct SurfaceComposeCtx {
struct wlr_box extents;
bool *has_alpha;
Vector2 size;
LunarWM *wm;
};
char const *GLInternalFormatName(GLenum format)
@@ -647,18 +635,14 @@ static void surface_compose_draw(
struct wlr_surface *surface, int sx, int sy, void *user_data)
{
struct SurfaceComposeCtx *ctx = user_data;
if (!ctx)
if (!ctx) {
return;
}
struct wlr_texture *wlr_tex = wlr_surface_get_texture(surface);
if (!wlr_tex || wlr_tex->width == 0 || wlr_tex->height == 0)
if (!wlr_tex || wlr_tex->width == 0 || wlr_tex->height == 0) {
return;
struct wlr_gles2_texture *gles_tex = gles2_get_texture(wlr_tex);
if (!gles_tex)
return;
if (ctx->has_alpha && gles_tex->has_alpha)
*ctx->has_alpha = true;
}
struct wlr_gles2_texture_attribs attribs;
wlr_gles2_texture_get_attribs(wlr_tex, &attribs);
@@ -666,9 +650,8 @@ static void surface_compose_draw(
.id = (unsigned int)attribs.tex,
.width = (int)wlr_tex->width,
.height = (int)wlr_tex->height,
.mipmaps = 1,
.format = gles_tex->has_alpha ? PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
: PIXELFORMAT_UNCOMPRESSED_R8G8B8,
.mipmaps = 0,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
};
float dest_w = (float)surface->current.width;
@@ -680,16 +663,16 @@ static void surface_compose_draw(
Rectangle src = { 0.0f, 0.0f, (float)tex.width, (float)tex.height };
Rectangle dst = {
(float)(sx - ctx->extents.x),
(float)(sy - ctx->extents.y),
sx,
sy,
dest_w,
dest_h,
};
if (attribs.target == GL_TEXTURE_EXTERNAL_OES) {
static bool external_draw_warned = false;
if (!draw_external_texture(&attribs, tex.width, tex.height, src, dst,
ctx->extents.width, ctx->extents.height)) {
if (!draw_external_texture(
&attribs, tex.width, tex.height, src, dst, dest_w, dest_h)) {
if (!external_draw_warned) {
TraceLog(LOG_WARNING,
"Failed to draw external texture, skipping frame");
@@ -704,88 +687,36 @@ static void surface_compose_draw(
bool LunarWM_Toplevel_update(LunarWM_Toplevel *this)
{
if (!this || !this->surface)
auto texture = wlr_surface_get_texture(this->surface);
if (!texture)
return false;
this->texture = wlr_surface_get_texture(this->surface);
struct wlr_client_buffer *cl_buf = this->surface->buffer;
if ((this->texture == nullptr) || (cl_buf == nullptr)) {
return false;
}
if ((this->locked_buffer != nullptr)
&& this->locked_buffer != &cl_buf->base) {
wlr_buffer_unlock(this->locked_buffer);
this->locked_buffer = nullptr;
}
if (this->locked_buffer == nullptr) {
this->locked_buffer = wlr_buffer_lock(&cl_buf->base);
}
wlr_gles2_texture_get_attribs(this->texture, &this->attribs);
this->gles_texture = gles2_get_texture(this->texture);
if (this->gles_texture == nullptr) {
return false;
}
this->rl_texture.id = (unsigned int)this->attribs.tex;
this->rl_texture.width = (int)this->texture->width;
this->rl_texture.height = (int)this->texture->height;
this->rl_texture.mipmaps = 1;
this->rl_texture.format = this->gles_texture->has_alpha
? PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
: PIXELFORMAT_UNCOMPRESSED_R8G8B8;
SetTextureFilter(this->rl_texture, TEXTURE_FILTER_BILINEAR);
SetTextureWrap(this->rl_texture, TEXTURE_WRAP_CLAMP);
struct wlr_box extents = { 0 };
wlr_surface_get_extents(this->surface, &extents);
if (extents.width <= 0 || extents.height <= 0) {
LunarWM_Toplevel_release_surface_rt(this);
this->composed_has_alpha = this->gles_texture->has_alpha;
return true;
}
bool needs_alpha = this->gles_texture->has_alpha;
if (extents.x != 0 || extents.y != 0
|| extents.width != (int)this->texture->width
|| extents.height != (int)this->texture->height) {
needs_alpha = true;
}
bool const size_changed = !IsRenderTextureValid(this->surface_rt)
|| this->surface_rt.texture.width != extents.width
|| this->surface_rt.texture.height != extents.height;
|| this->surface_rt.texture.width != texture->width
|| this->surface_rt.texture.height != texture->height;
if (size_changed) {
LunarWM_Toplevel_release_surface_rt(this);
this->surface_rt = LoadRenderTexture(extents.width, extents.height);
this->surface_rt = LoadRenderTexture(texture->width, texture->height);
if (!IsRenderTextureValid(this->surface_rt)) {
this->composed_has_alpha = needs_alpha;
return true;
}
SetTextureFilter(this->surface_rt.texture, TEXTURE_FILTER_BILINEAR);
SetTextureWrap(this->surface_rt.texture, TEXTURE_WRAP_CLAMP);
}
rlSetShader(rlGetShaderIdDefault(), rlGetShaderLocsDefault());
BeginTextureMode(this->surface_rt);
ClearBackground(BLANK);
BeginBlendMode(BLEND_ALPHA);
struct SurfaceComposeCtx ctx = {
.extents = extents,
.has_alpha = &needs_alpha,
.size = (Vector2) { texture->width, texture->height },
.wm = this->server,
};
// DrawRectangle(0, 0, this->surface_rt.texture.width,
// this->surface_rt.texture.height, BLACK);
wlr_surface_for_each_surface(this->surface, surface_compose_draw, &ctx);
EndBlendMode();
DrawFPS(0, 0);
EndTextureMode();
this->surface_extents = extents;
Texture2D composed = this->surface_rt.texture;
composed.width = extents.width;
composed.height = extents.height;
this->rl_texture = composed;
this->composed_has_alpha = needs_alpha;
return true;
}
@@ -931,14 +862,6 @@ static void xwl_unmap_toplevel(LunarWM_Toplevel *tl)
if (tl->destroy.link.prev || tl->destroy.link.next)
wl_list_remove(&tl->destroy.link);
if (tl->locked_buffer) {
wlr_buffer_unlock(tl->locked_buffer);
tl->locked_buffer = NULL;
}
tl->texture = NULL;
tl->gles_texture = NULL;
tl->rl_texture = (Texture) { 0 };
LunarWM_Toplevel_release_surface_rt(tl);
tl->surface = NULL;
}
@@ -1635,18 +1558,14 @@ static void handle_output_frame(struct wl_listener *listener, void *data)
struct wlr_render_pass *pass
= wlr_output_begin_render_pass(wlr_output, &state, NULL);
if (pass == NULL) {
wlr_output_state_finish(&state);
wlr_output_schedule_frame(wlr_output);
wlr_log(WLR_ERROR, "Failed to begin render pass for output %s",
wlr_output->name);
return;
}
GLint drawFboId = 0, readFboId = 0;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFboId);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFboId);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
rlMatrixMode(RL_MODELVIEW);
rlLoadIdentity();
@@ -1682,7 +1601,7 @@ static void handle_output_frame(struct wl_listener *listener, void *data)
}
BeginTextureMode(wm->renderer.hud_rt);
{
LunarWM_render_hud(wm, GetFrameTime(), 1);
LunarWM_render_hud(wm, GetFrameTime(), hud_size);
}
EndTextureMode();
@@ -1698,6 +1617,7 @@ static void handle_output_frame(struct wl_listener *listener, void *data)
}
EndMode3D();
DrawFPS(0, 0);
rlDrawRenderBatchActive();
}
EndTextureMode();
@@ -1728,20 +1648,8 @@ static void handle_output_frame(struct wl_listener *listener, void *data)
wm->renderer.camera.target, wm->cman->cfg.space.radius);
}
if (!wlr_render_pass_submit(pass)) {
wlr_output_state_finish(&state);
wlr_output_schedule_frame(wlr_output);
wlr_log(WLR_ERROR, "Failed to submit render pass for output %s",
wlr_output->name);
return;
}
if (!wlr_output_commit_state(wlr_output, &state)) {
wlr_output_state_finish(&state);
wlr_output_schedule_frame(wlr_output);
return;
}
wlr_render_pass_submit(pass);
wlr_output_commit_state(wlr_output, &state);
wlr_output_state_finish(&state);
}