Compare commits

..

58 Commits

Author SHA1 Message Date
Slendi 2ed9a495bf 2D rendering (kinda, hud brokey)
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-30 16:36:41 +03:00
Slendi ed429d6a30 Get window up and running
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-30 15:26:30 +03:00
Slendi d193ef0295 SDFas
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-30 09:54:06 +03:00
Slendi a253869c24 yea
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-30 09:53:53 +03:00
Slendi e072b1f6e0 dbug thign
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-30 02:49:34 +03:00
Slendi 9b00e30b97 Format
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-30 01:36:51 +03:00
Slendi e8ee25cd88 update gitignore
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-30 01:24:37 +03:00
Slendi 66a46a9912 fuck...
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-30 01:24:27 +03:00
Slendi 72a6ac3d00 sdf
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-29 23:28:39 +03:00
Slendi 22c005999c add wlroots as a submodule for reference
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-29 23:28:39 +03:00
Slendi 159bd314e5 update wlrotos
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-29 20:40:07 +03:00
Slendi b0a1c2cb27 oops
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-29 18:58:49 +03:00
Slendi 28a9f54227 Organization, render cursor above all else
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-29 18:51:43 +03:00
Slendi a6949eeda0 Mouse cursor
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-04 15:11:29 +03:00
Slendi 1af7357301 Chagne defaujlt
Signed-off-by: Slendi <slendi@socopon.com>
2025-09-03 21:21:25 +03:00
Slendi 70ff013dbc Fallback
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-11 11:00:15 +03:00
Slendi 971040e038 Optizmiatoin
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-11 09:56:45 +03:00
Slendi bf3ed0dd0c Yay
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-11 09:52:57 +03:00
Slendi 794178668e Add recentering
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-11 09:29:38 +03:00
Slendi e3b2f44621 fix some cleanup bugs
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-11 07:12:04 +03:00
Slendi ef96c51566 Stuff
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-11 06:39:52 +03:00
Slendi c9590037aa Stuff
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-11 01:24:53 +03:00
Slendi aa80a4c9d0 Temporarily prevent z fighting
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 13:08:52 +03:00
Slendi 39a27eaae6 Make HUD draw over everything
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 13:07:20 +03:00
Slendi e9a31ac4a6 Enable lazy xwayland by default
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 13:03:05 +03:00
Slendi ec61c13aa6 Add xwayland, fix naming
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 12:58:55 +03:00
Slendi 025ee9da91 Fix defaults
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 12:24:43 +03:00
Slendi ad0d09ebd2 Fix crashing
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 08:45:45 +03:00
Slendi ab7ca71ba2 Clean-up
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 08:00:07 +03:00
Slendi 3e4d4514ad Remove unnecessary lua eval
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 07:45:37 +03:00
Slendi 3a50e5e403 stuff
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 07:40:40 +03:00
Slendi 146c4e27cf Use Lua for config
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 07:25:01 +03:00
Slendi 4e23877697 C++, BYE BYE!! BYE BYE!!!
Signed-off-by: Slendi <slendi@socopon.com>
2025-08-10 06:38:23 +03:00
Slendi d154db1422 Stuff, have to rewrite DHOS config parser
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-23 23:23:56 +03:00
Slendi 14f2e52722 Stuff
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-23 15:57:12 +03:00
Slendi 78c86aaabd Add hands idk they broken
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-16 11:53:27 +03:00
Slendi 7dc90058b2 Add linter and fix issues
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-14 01:05:22 +03:00
Slendi c21397cef5 Get windows to render propely
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-10 07:11:56 +03:00
Slendi c1e331ca7e Manage to get first frame of clients rendering
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-10 05:12:56 +03:00
Slendi 1cc97753a5 Use custom wlroots fork
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-10 02:07:58 +03:00
Slendi dd6cadb50d Input handling
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-09 07:54:10 +03:00
Slendi 9fa2a1e8c7 Raylib
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-09 07:20:12 +03:00
Slendi cecea144e4 Get OpenXR fully up and running
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-09 04:29:40 +03:00
Slendi ccffc7908a wlroots
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-08 00:56:33 +03:00
Slendi 2ebc752cc7 Fix wrong index bug
lmao.

Signed-off-by: Slendi <slendi@socopon.com>
2025-07-05 03:35:48 +03:00
Slendi 21c8c60369 Remove the CMake patching workaround
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-05 03:24:37 +03:00
Slendi 2e38196ea5 import std
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-05 03:17:42 +03:00
Slendi 9d39cd9a38 A lot.
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-05 02:41:08 +03:00
Slendi 470c248bcf yes
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-01 04:00:52 +03:00
Slendi bdb9d472de fuck rust
Signed-off-by: Slendi <slendi@socopon.com>
2025-07-01 00:08:34 +03:00
Slendi fdafccbdad Remove everything, going rustacean
Signed-off-by: Slendi <slendi@socopon.com>
2025-06-29 19:32:27 +03:00
Slendi 1fb48e2426 idk
Signed-off-by: Slendi <slendi@socopon.com>
2025-06-29 19:22:17 +03:00
Slendi d83e7f4337 Add helper scripts and wlroots integration
Signed-off-by: Slendi <slendi@socopon.com>
2025-06-29 17:34:45 +03:00
Slendi 1d99b16685 Fix openxr gl glue
Signed-off-by: Slendi <slendi@socopon.com>
2025-06-29 17:06:08 +03:00
Slendi 1a654ec009 Merge pull request #1 from slendidev/codex/write-glue-code-for-openxr-opengl-and-wlroots
Add OpenXR wlroots backend skeleton
2025-06-29 16:31:56 +03:00
Slendi cc1137c011 Refine OpenXR backend formatting 2025-06-29 16:30:23 +03:00
Slendi 9fdb148c89 add wlroots for reference
Signed-off-by: Slendi <slendi@socopon.com>
2025-06-29 16:00:43 +03:00
Slendi c93ab29a90 Initial commit
Signed-off-by: Slendi <slendi@socopon.com>
2025-06-29 15:57:38 +03:00
13 changed files with 203 additions and 280 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
[submodule "wlroots-lunar"] [submodule "wlroots-lunar"]
path = wlroots-lunar path = wlroots-lunar
url = https://github.com/slendidev/wlroots-lunar url = git@github.com:slendidev/wlroots-lunar
-2
View File
@@ -25,7 +25,6 @@ pkg_check_modules(WLROOTS REQUIRED IMPORTED_TARGET wlroots-0.20)
pkg_check_modules(XKBCOMMON REQUIRED IMPORTED_TARGET xkbcommon) pkg_check_modules(XKBCOMMON REQUIRED IMPORTED_TARGET xkbcommon)
pkg_check_modules(OPENXR REQUIRED IMPORTED_TARGET openxr) pkg_check_modules(OPENXR REQUIRED IMPORTED_TARGET openxr)
pkg_check_modules(LUA REQUIRED IMPORTED_TARGET lua) pkg_check_modules(LUA REQUIRED IMPORTED_TARGET lua)
pkg_check_modules(PIXMAN REQUIRED IMPORTED_TARGET pixman-1)
find_program(WAYLAND_SCANNER_EXECUTABLE wayland-scanner REQUIRED) find_program(WAYLAND_SCANNER_EXECUTABLE wayland-scanner REQUIRED)
message(STATUS "Found wayland-scanner at ${WAYLAND_SCANNER_EXECUTABLE}") message(STATUS "Found wayland-scanner at ${WAYLAND_SCANNER_EXECUTABLE}")
@@ -68,7 +67,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
PkgConfig::WLROOTS PkgConfig::WLROOTS
PkgConfig::OPENXR PkgConfig::OPENXR
PkgConfig::LUA PkgConfig::LUA
PkgConfig::PIXMAN
raylib raylib
) )
Generated
+3 -3
View File
@@ -97,11 +97,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1759496058, "lastModified": 1759215258,
"narHash": "sha256-eVgGEO+KhJX307XQ0gbbCWguJfoSJlZRFQrpvalK7kM=", "narHash": "sha256-Y7aXk0Zxu+X2BbO5MLkCvClrPsKfZ2sm34N2n7tXx4I=",
"owner": "slendidev", "owner": "slendidev",
"repo": "wlroots-lunar", "repo": "wlroots-lunar",
"rev": "00d01dcc297e1991809ad2c0f6b50fb66478d748", "rev": "a9abd5a6e4fb4e5ac6c410e1fb1ad438d3b12001",
"type": "github" "type": "github"
}, },
"original": { "original": {
-1
View File
@@ -36,7 +36,6 @@
ninja ninja
(pkgs.llvmPackages_20.clang-tools.override { enableLibcxx = true; }) (pkgs.llvmPackages_20.clang-tools.override { enableLibcxx = true; })
lldb lldb
valgrind
lua lua
-34
View File
@@ -1,34 +0,0 @@
{
"rdocCaptureSettings": 1,
"settings": {
"autoStart": false,
"commandLine": "",
"environment": [
{
"separator": "Platform style",
"type": "Set",
"value": "1",
"variable": "LWM_NO_XR"
}
],
"executable": "/home/lain/Documents/projs/lunarwm/build/LunarWM",
"inject": false,
"numQueuedFrames": 0,
"options": {
"allowFullscreen": true,
"allowVSync": true,
"apiValidation": false,
"captureAllCmdLists": false,
"captureCallstacks": false,
"captureCallstacksOnlyDraws": false,
"debugOutputMute": true,
"delayForDebugger": 0,
"hookIntoChildren": false,
"refAllResources": false,
"softMemoryLimit": 0,
"verifyBufferAccess": false
},
"queuedFrameCap": 0,
"workingDir": "/home/lain/Documents/projs/lunarwm"
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef LUNAR_WM_H #ifndef LUNAR_WM_H
#define LUNAR_WM_H #define LUNAR_WM_H
#include "LunarWM_core.h"
#include "LunarWM_types.h" #include "LunarWM_types.h"
#include "LunarWM_core.h"
#endif #endif
+3 -23
View File
@@ -120,9 +120,7 @@ static int l_recenter(lua_State *L)
{ {
(void)L; (void)L;
if (g_wm.xr.available) {
LunarWM_set_recenter_from_camera(&g_wm); LunarWM_set_recenter_from_camera(&g_wm);
}
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
@@ -219,24 +217,13 @@ bool LunarWM_init(LunarWM *wm)
return false; return false;
} }
wm->xr.available = false;
{
char *no_xr = getenv("LWM_NO_XR");
bool xr = true;
if (no_xr != NULL && no_xr[0] != '\0')
xr = false;
if (xr) {
if (!LunarWM_xr_init(wm)) { if (!LunarWM_xr_init(wm)) {
wlr_log( wlr_log(WLR_ERROR, "Failed to initialize OpenXR! Disabling XR...");
WLR_ERROR, "Failed to initialize OpenXR! Disabling XR..."); wm->xr.available = false;
LunarWM_xr_cleanup(wm); LunarWM_xr_cleanup(wm);
} else { } else {
wm->xr.available = true; wm->xr.available = true;
} }
}
}
wlr_log(WLR_INFO, "OpenGL ES version: %s", glGetString(GL_VERSION)); wlr_log(WLR_INFO, "OpenGL ES version: %s", glGetString(GL_VERSION));
InitWindow(0, 0, ""); InitWindow(0, 0, "");
@@ -268,13 +255,6 @@ void LunarWM_destroy(LunarWM *wm)
LunarWM_wayland_cleanup(wm); LunarWM_wayland_cleanup(wm);
cleanup_lua_cfg(wm); cleanup_lua_cfg(wm);
for (size_t i = 0; i < ARRAY_SZ(wm->wm.workspaces); ++i) {
if (wm->wm.workspaces[i].v_windows) {
vector_free(wm->wm.workspaces[i].v_windows);
wm->wm.workspaces[i].v_windows = NULL;
}
}
memset(wm, 0, sizeof(*wm)); memset(wm, 0, sizeof(*wm));
} }
@@ -437,7 +417,7 @@ void LunarWM_run(LunarWM *wm)
EndDrawing(); EndDrawing();
} else { } else {
wm->renderer.camera.fovy = 75; wm->renderer.camera.fovy = 90;
} }
} }
} }
+9 -4
View File
@@ -328,13 +328,16 @@ void LunarWM_render_windows(LunarWM *this, bool alpha_check)
if (!tl || !tl->surface) { if (!tl || !tl->surface) {
continue; continue;
} }
if (IsTextureValid(tl->surface_rt.texture)) { if (tl->gles_texture) {
Texture2D tex = tl->surface_rt.texture; if (alpha_check && tl->composed_has_alpha) {
continue;
}
Texture2D tex = tl->rl_texture;
bool y_flip = false; bool y_flip = false;
if (IsRenderTextureValid(tl->surface_rt)) { if (IsRenderTextureValid(tl->surface_rt)) {
tex = tl->surface_rt.texture; tex = tl->surface_rt.texture;
tex.width = tl->surface_rt.texture.width; tex.width = tl->rl_texture.width;
tex.height = tl->surface_rt.texture.height; tex.height = tl->rl_texture.height;
y_flip = true; y_flip = true;
} }
if (!tex.id) if (!tex.id)
@@ -348,6 +351,8 @@ void LunarWM_render_windows(LunarWM *this, bool alpha_check)
void LunarWM_render_3d(LunarWM *this, float /*dt*/) void LunarWM_render_3d(LunarWM *this, float /*dt*/)
{ {
LunarWM_render_windows(this, true);
for (int h = 0; this->xr.hand_tracking_enabled && h < 2; ++h) { for (int h = 0; this->xr.hand_tracking_enabled && h < 2; ++h) {
auto *hand_info = &this->xr.hands[h]; auto *hand_info = &this->xr.hands[h];
if (hand_info->hand_tracker == XR_NULL_HANDLE) if (hand_info->hand_tracker == XR_NULL_HANDLE)
+9 -2
View File
@@ -22,8 +22,8 @@
#include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_data_device.h> #include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_pointer.h> #include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_subcompositor.h> #include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/box.h> #include <wlr/util/box.h>
@@ -112,6 +112,7 @@ typedef struct {
struct wl_listener destroy; struct wl_listener destroy;
} LunarWM_Output; } LunarWM_Output;
typedef struct { typedef struct {
uint32_t id; uint32_t id;
@@ -130,8 +131,15 @@ typedef struct {
} u; } u;
struct wlr_surface *surface; 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; RenderTexture2D surface_rt;
struct wlr_box surface_extents;
bool composed_has_alpha;
} LunarWM_Toplevel; } LunarWM_Toplevel;
typedef struct { typedef struct {
@@ -190,7 +198,6 @@ typedef struct LunarWM {
struct wlr_allocator *allocator; struct wlr_allocator *allocator;
struct wlr_compositor *compositor; struct wlr_compositor *compositor;
struct wl_listener new_surface_listener;
struct wlr_subcompositor *subcompositor; struct wlr_subcompositor *subcompositor;
struct wlr_data_device_manager *data_device_manager; struct wlr_data_device_manager *data_device_manager;
+137 -168
View File
@@ -1,16 +1,12 @@
#include "LunarWM_wayland.h" #include "LunarWM_wayland.h"
#include "LunarWM_core.h"
#include "LunarWM_render.h" #include "LunarWM_render.h"
#include "common.h" #include "common.h"
#include "raylib.h"
#include "vec.h" #include "vec.h"
#include <pixman.h>
#include <wlr/backend/wayland.h>
#include <wlr/backend/x11.h>
#include <wlr/render/color.h> #include <wlr/render/color.h>
#include <wlr/render/pass.h> #include <wlr/render/pass.h>
#include <wlr/xwayland/xwayland.h>
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
@@ -24,7 +20,6 @@
#include <xkbcommon/xkbcommon-keysyms.h> #include <xkbcommon/xkbcommon-keysyms.h>
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <raylib.h>
#include <rlgl.h> #include <rlgl.h>
static void handle_new_output(struct wl_listener *listener, void *data); static void handle_new_output(struct wl_listener *listener, void *data);
@@ -41,90 +36,6 @@ static inline SphericalCoord get_forward_spherical_with_nearest(
return Vector3ToSpherical(vec); return Vector3ToSpherical(vec);
} }
struct SurfaceDamageListener {
struct wl_listener client_commit;
struct wl_listener destroy;
};
static void surface_damage_client_commit(
struct wl_listener *listener, void *data)
{
(void)listener;
struct wlr_surface *surface = data;
if (!surface) {
return;
}
if (!wlr_surface_state_has_buffer(&surface->pending)) {
return;
}
if (pixman_region32_not_empty(&surface->pending.surface_damage)
|| pixman_region32_not_empty(&surface->pending.buffer_damage)) {
return;
}
int surface_width = surface->pending.width > 0 ? surface->pending.width
: surface->current.width;
int surface_height = surface->pending.height > 0 ? surface->pending.height
: surface->current.height;
int buffer_width = surface->pending.buffer_width > 0
? surface->pending.buffer_width
: surface->current.buffer_width;
int buffer_height = surface->pending.buffer_height > 0
? surface->pending.buffer_height
: surface->current.buffer_height;
if (surface_width <= 0 || surface_height <= 0 || buffer_width <= 0
|| buffer_height <= 0) {
return;
}
pixman_region32_union_rect(&surface->pending.surface_damage,
&surface->pending.surface_damage, 0, 0, surface_width, surface_height);
pixman_region32_union_rect(&surface->pending.buffer_damage,
&surface->pending.buffer_damage, 0, 0, buffer_width, buffer_height);
}
static void surface_damage_destroy(struct wl_listener *listener, void *data)
{
(void)data;
struct SurfaceDamageListener *hook
= wl_container_of(listener, hook, destroy);
wl_list_remove(&hook->client_commit.link);
wl_list_remove(&hook->destroy.link);
free(hook);
}
static void surface_damage_track(struct wlr_surface *surface)
{
if (!surface) {
return;
}
struct SurfaceDamageListener *hook = calloc(1, sizeof(*hook));
if (!hook) {
wlr_log(WLR_ERROR, "Failed to allocate surface damage listener");
return;
}
hook->client_commit.notify = surface_damage_client_commit;
wl_signal_add(&surface->events.client_commit, &hook->client_commit);
hook->destroy.notify = surface_damage_destroy;
wl_signal_add(&surface->events.destroy, &hook->destroy);
}
static void compositor_new_surface_notify(
struct wl_listener *listener, void *data)
{
(void)listener;
struct wlr_surface *surface = data;
if (!surface) {
return;
}
surface_damage_track(surface);
}
struct ExternalTexturePipeline { struct ExternalTexturePipeline {
bool attempted_init; bool attempted_init;
bool ready; bool ready;
@@ -428,6 +339,8 @@ static void LunarWM_Toplevel_release_surface_rt(LunarWM_Toplevel *tl)
UnloadRenderTexture(tl->surface_rt); UnloadRenderTexture(tl->surface_rt);
} }
tl->surface_rt = (RenderTexture2D) { 0 }; 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) static void remove_windows_for_tl(LunarWM *wm, LunarWM_Toplevel *tl)
@@ -523,8 +436,16 @@ static void toplevel_unmap_notify(struct wl_listener *l, void *data)
if (tl->commit.link.prev || tl->commit.link.next) if (tl->commit.link.prev || tl->commit.link.next)
wl_list_remove(&tl->commit.link); 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); LunarWM_Toplevel_release_surface_rt(tl);
tl->surface = NULL; tl->surface = NULL;
tl->composed_has_alpha = false;
focus_fallback(tl->server); focus_fallback(tl->server);
} }
@@ -592,13 +513,16 @@ bool LunarWM_Toplevel_destroy(LunarWM_Toplevel *this)
wl_list_remove(&this->commit.link); wl_list_remove(&this->commit.link);
if (this->destroy.link.prev || this->destroy.link.next) if (this->destroy.link.prev || this->destroy.link.next)
wl_list_remove(&this->destroy.link); wl_list_remove(&this->destroy.link);
if (this->locked_buffer)
wlr_buffer_unlock(this->locked_buffer);
LunarWM_Toplevel_release_surface_rt(this); LunarWM_Toplevel_release_surface_rt(this);
this->composed_has_alpha = false;
return true; return true;
} }
struct SurfaceComposeCtx { struct SurfaceComposeCtx {
Vector2 size; struct wlr_box extents;
LunarWM *wm; bool *has_alpha;
}; };
char const *GLInternalFormatName(GLenum format) char const *GLInternalFormatName(GLenum format)
@@ -635,14 +559,18 @@ static void surface_compose_draw(
struct wlr_surface *surface, int sx, int sy, void *user_data) struct wlr_surface *surface, int sx, int sy, void *user_data)
{ {
struct SurfaceComposeCtx *ctx = user_data; struct SurfaceComposeCtx *ctx = user_data;
if (!ctx) { if (!ctx)
return; return;
}
struct wlr_texture *wlr_tex = wlr_surface_get_texture(surface); 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; 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; struct wlr_gles2_texture_attribs attribs;
wlr_gles2_texture_get_attribs(wlr_tex, &attribs); wlr_gles2_texture_get_attribs(wlr_tex, &attribs);
@@ -651,7 +579,8 @@ static void surface_compose_draw(
.width = (int)wlr_tex->width, .width = (int)wlr_tex->width,
.height = (int)wlr_tex->height, .height = (int)wlr_tex->height,
.mipmaps = 1, .mipmaps = 1,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, .format = gles_tex->has_alpha ? PIXELFORMAT_UNCOMPRESSED_R8G8B8A8
: PIXELFORMAT_UNCOMPRESSED_R8G8B8,
}; };
float dest_w = (float)surface->current.width; float dest_w = (float)surface->current.width;
@@ -663,16 +592,16 @@ static void surface_compose_draw(
Rectangle src = { 0.0f, 0.0f, (float)tex.width, (float)tex.height }; Rectangle src = { 0.0f, 0.0f, (float)tex.width, (float)tex.height };
Rectangle dst = { Rectangle dst = {
sx, (float)(sx - ctx->extents.x),
sy, (float)(sy - ctx->extents.y),
dest_w, dest_w,
dest_h, dest_h,
}; };
if (attribs.target == GL_TEXTURE_EXTERNAL_OES) { if (attribs.target == GL_TEXTURE_EXTERNAL_OES) {
static bool external_draw_warned = false; static bool external_draw_warned = false;
if (!draw_external_texture( if (!draw_external_texture(&attribs, tex.width, tex.height, src, dst,
&attribs, tex.width, tex.height, src, dst, dest_w, dest_h)) { ctx->extents.width, ctx->extents.height)) {
if (!external_draw_warned) { if (!external_draw_warned) {
TraceLog(LOG_WARNING, TraceLog(LOG_WARNING,
"Failed to draw external texture, skipping frame"); "Failed to draw external texture, skipping frame");
@@ -681,29 +610,70 @@ static void surface_compose_draw(
} }
} else { } else {
assert(attribs.target == GL_TEXTURE_2D); assert(attribs.target == GL_TEXTURE_2D);
DrawTexturePro(tex, src, dst, (Vector2) { 0.0f, 0.0f }, 0.0f, WHITE);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glDisable(GL_STENCIL_TEST);
DrawTexture(tex, sx, sy, WHITE);
rlDrawRenderBatchActive();
} }
} }
bool LunarWM_Toplevel_update(LunarWM_Toplevel *this) bool LunarWM_Toplevel_update(LunarWM_Toplevel *this)
{ {
if (!this->surface->mapped) { if (!this || !this->surface)
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; return false;
} }
int width = this->surface->current.width;
int height = this->surface->current.height; 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) bool const size_changed = !IsRenderTextureValid(this->surface_rt)
|| this->surface_rt.texture.width != width || this->surface_rt.texture.width != extents.width
|| this->surface_rt.texture.height != height; || this->surface_rt.texture.height != extents.height;
if (size_changed) { if (size_changed) {
LunarWM_Toplevel_release_surface_rt(this); LunarWM_Toplevel_release_surface_rt(this);
this->surface_rt = LoadRenderTexture(width, height); this->surface_rt = LoadRenderTexture(extents.width, extents.height);
if (!IsRenderTextureValid(this->surface_rt)) { if (!IsRenderTextureValid(this->surface_rt)) {
this->composed_has_alpha = needs_alpha;
return true; return true;
} }
SetTextureFilter(this->surface_rt.texture, TEXTURE_FILTER_BILINEAR); SetTextureFilter(this->surface_rt.texture, TEXTURE_FILTER_BILINEAR);
@@ -712,17 +682,22 @@ bool LunarWM_Toplevel_update(LunarWM_Toplevel *this)
BeginTextureMode(this->surface_rt); BeginTextureMode(this->surface_rt);
ClearBackground(BLANK); ClearBackground(BLANK);
BeginBlendMode(BLEND_ALPHA);
struct SurfaceComposeCtx ctx = { struct SurfaceComposeCtx ctx = {
.size = (Vector2) { width, height }, .extents = extents,
.wm = this->server, .has_alpha = &needs_alpha,
}; };
// DrawRectangle(0, 0, this->surface_rt.texture.width,
// this->surface_rt.texture.height, BLACK);
rlSetShader(rlGetShaderIdDefault(), rlGetShaderLocsDefault());
wlr_surface_for_each_surface(this->surface, surface_compose_draw, &ctx); wlr_surface_for_each_surface(this->surface, surface_compose_draw, &ctx);
DrawFPS(0, 0); EndBlendMode();
EndTextureMode(); 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; return true;
} }
@@ -868,6 +843,14 @@ static void xwl_unmap_toplevel(LunarWM_Toplevel *tl)
if (tl->destroy.link.prev || tl->destroy.link.next) if (tl->destroy.link.prev || tl->destroy.link.next)
wl_list_remove(&tl->destroy.link); 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); LunarWM_Toplevel_release_surface_rt(tl);
tl->surface = NULL; tl->surface = NULL;
} }
@@ -1232,7 +1215,6 @@ static void Pointer_motion_notify(struct wl_listener *listener, void *data)
if (p->server->cman->cfg.input.mouse.invert_y) { if (p->server->cman->cfg.input.mouse.invert_y) {
dy *= -1; dy *= -1;
} }
float const R = p->server->cman->cfg.space.radius; float const R = p->server->cman->cfg.space.radius;
float const g = 0.0005f; float const g = 0.0005f;
@@ -1564,19 +1546,44 @@ static void handle_output_frame(struct wl_listener *listener, void *data)
struct wlr_render_pass *pass struct wlr_render_pass *pass
= wlr_output_begin_render_pass(wlr_output, &state, NULL); = 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 draw_fbo = 0; GLint drawFboId = 0, readFboId = 0;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_fbo); 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); rlMatrixMode(RL_MODELVIEW);
rlLoadIdentity(); rlLoadIdentity();
wm->renderer.tmp_rt.id = draw_fbo; // if (!IsTextureValid(wm->renderer.main_rt.texture)) {
// wm->renderer.main_rt = LoadRenderTexture(width, height);
// }
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_log(WLR_ERROR, "Failed to commit state for output %s",
wlr_output->name);
wlr_output_state_finish(&state);
wlr_output_schedule_frame(wlr_output);
return;
}
wm->renderer.tmp_rt.id = drawFboId;
wm->renderer.tmp_rt.texture = (Texture) { wm->renderer.tmp_rt.texture = (Texture) {
.id = draw_fbo, .id = drawFboId,
.width = width, .width = width,
.height = height, .height = height,
.mipmaps = 1, .mipmaps = 1,
@@ -1592,35 +1599,18 @@ static void handle_output_frame(struct wl_listener *listener, void *data)
rlFramebufferAttach(wm->renderer.tmp_rt.id, wm->renderer.tmp_rt.depth.id, rlFramebufferAttach(wm->renderer.tmp_rt.id, wm->renderer.tmp_rt.depth.id,
RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0); RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
if (!wm->xr.available && !wm->renderer.first_frame) { if (!IsTextureValid(wm->renderer.main_rt.texture)) {
wm->renderer.camera.target = SphericalToVector3(wm->wm.pointer); wm->renderer.main_rt = LoadRenderTexture(width, height);
Vector3 forward = Vector3Normalize(Vector3Subtract(
wm->renderer.camera.target, wm->renderer.camera.position));
Vector3 worldUp = (Vector3) { 0, 1, 0 };
if (fabsf(Vector3DotProduct(forward, worldUp)) > 0.999f) {
worldUp = (Vector3) { 0, 0, 1 };
} }
Vector3 right = Vector3Normalize(Vector3CrossProduct(forward, worldUp));
wm->renderer.camera.up
= Vector3Normalize(Vector3CrossProduct(right, forward));
}
int const hud_size = wm->cman->cfg.displays.hud.size; int const hud_size = wm->cman->cfg.displays.hud.size;
if (!IsTextureValid(wm->renderer.hud_rt.texture)) { if (!IsTextureValid(wm->renderer.hud_rt.texture)) {
wm->renderer.hud_rt = LoadRenderTexture(hud_size, hud_size); wm->renderer.hud_rt = LoadRenderTexture(hud_size, hud_size);
} }
BeginTextureMode(wm->renderer.hud_rt); BeginTextureMode(wm->renderer.hud_rt);
{ {
LunarWM_render_hud(wm, GetFrameTime(), hud_size); LunarWM_render_hud(wm, GetFrameTime(), 1);
} }
EndTextureMode(); EndTextureMode();
if (!IsTextureValid(wm->renderer.main_rt.texture)) {
wm->renderer.main_rt = LoadRenderTexture(width, height);
}
BeginTextureMode(wm->renderer.main_rt); BeginTextureMode(wm->renderer.main_rt);
{ {
BeginMode3D(wm->renderer.camera); BeginMode3D(wm->renderer.camera);
@@ -1630,7 +1620,6 @@ static void handle_output_frame(struct wl_listener *listener, void *data)
} }
EndMode3D(); EndMode3D();
DrawFPS(0, 0);
rlDrawRenderBatchActive(); rlDrawRenderBatchActive();
} }
EndTextureMode(); EndTextureMode();
@@ -1654,18 +1643,7 @@ static void handle_output_frame(struct wl_listener *listener, void *data)
} }
EndTextureMode(); EndTextureMode();
if (wm->renderer.first_frame) {
LunarWM_set_recenter_from_camera(wm);
wm->renderer.first_frame = false;
wm->wm.pointer = get_forward_spherical_with_nearest(
wm->renderer.camera.target, wm->cman->cfg.space.radius);
}
wlr_render_pass_submit(pass);
wlr_output_commit_state(wlr_output, &state);
wlr_output_state_finish(&state); wlr_output_state_finish(&state);
EndDrawing();
} }
static void handle_new_output(struct wl_listener *listener, void *data) static void handle_new_output(struct wl_listener *listener, void *data)
@@ -1786,9 +1764,6 @@ bool LunarWM_wayland_init(LunarWM *this)
wlr_log(WLR_ERROR, "Failed to create compositor"); wlr_log(WLR_ERROR, "Failed to create compositor");
return false; return false;
} }
this->wayland.new_surface_listener.notify = compositor_new_surface_notify;
wl_signal_add(&this->wayland.compositor->events.new_surface,
&this->wayland.new_surface_listener);
this->wayland.subcompositor this->wayland.subcompositor
= wlr_subcompositor_create(this->wayland.display); = wlr_subcompositor_create(this->wayland.display);
@@ -1866,12 +1841,6 @@ void LunarWM_wayland_cleanup(LunarWM *this)
this->wayland.new_output_listener.notify = NULL; this->wayland.new_output_listener.notify = NULL;
} }
if (this->wayland.new_surface_listener.link.prev
|| this->wayland.new_surface_listener.link.next) {
wl_list_remove(&this->wayland.new_surface_listener.link);
this->wayland.new_surface_listener.notify = NULL;
}
if (this->wayland.v_outputs) { if (this->wayland.v_outputs) {
for (size_t i = 0; i < vector_size(this->wayland.v_outputs); ++i) { for (size_t i = 0; i < vector_size(this->wayland.v_outputs); ++i) {
destroy_output(this->wayland.v_outputs[i]); destroy_output(this->wayland.v_outputs[i]);
+30 -31
View File
@@ -34,10 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define vec_h #define vec_h
#ifdef __cpp_decltype #ifdef __cpp_decltype
# include <type_traits> #include <type_traits>
# define typeof(T) \ #define typeof(T) std::remove_reference<std::add_lvalue_reference<decltype(T)>::type>::type
std::remove_reference< \
std::add_lvalue_reference<decltype(T)>::type>::type
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
@@ -48,7 +46,7 @@ extern "C" {
#include <stdlib.h> #include <stdlib.h>
// generic type for internal use // generic type for internal use
typedef void *vector; typedef void* vector;
// number of elements in a vector // number of elements in a vector
typedef size_t vec_size_t; typedef size_t vec_size_t;
// number of bytes for a type // number of bytes for a type
@@ -60,59 +58,60 @@ typedef size_t vec_type_t;
// shortcut defines // shortcut defines
// vec_addr is a vector* (aka type**) // vec_addr is a vector* (aka type**)
# define vector_add_dst(vec_addr) \ #define vector_add_dst(vec_addr)\
((typeof(*vec_addr))(_vector_add_dst( \ ((typeof(*vec_addr))(\
(vector *)vec_addr, sizeof(**vec_addr)))) _vector_add_dst((vector*)vec_addr, sizeof(**vec_addr))\
# define vector_insert_dst(vec_addr, pos) \ ))
((typeof(*vec_addr))(_vector_insert_dst( \ #define vector_insert_dst(vec_addr, pos)\
(vector *)vec_addr, sizeof(**vec_addr), pos))) ((typeof(*vec_addr))(\
_vector_insert_dst((vector*)vec_addr, sizeof(**vec_addr), pos)))
# define vector_add(vec_addr, value) (*vector_add_dst(vec_addr) = value) #define vector_add(vec_addr, value)\
# define vector_insert(vec_addr, pos, value) \ (*vector_add_dst(vec_addr) = value)
#define vector_insert(vec_addr, pos, value)\
(*vector_insert_dst(vec_addr, pos) = value) (*vector_insert_dst(vec_addr, pos) = value)
#else #else
# define vector_add_dst(vec_addr, type) \ #define vector_add_dst(vec_addr, type)\
((type *)_vector_add_dst((vector *)vec_addr, sizeof(type))) ((type*)_vector_add_dst((vector*)vec_addr, sizeof(type)))
# define vector_insert_dst(vec_addr, type, pos) \ #define vector_insert_dst(vec_addr, type, pos)\
((type *)_vector_insert_dst((vector *)vec_addr, sizeof(type), pos)) ((type*)_vector_insert_dst((vector*)vec_addr, sizeof(type), pos))
# define vector_add(vec_addr, type, value) \ #define vector_add(vec_addr, type, value)\
(*vector_add_dst(vec_addr, type) = value) (*vector_add_dst(vec_addr, type) = value)
# define vector_insert(vec_addr, type, pos, value) \ #define vector_insert(vec_addr, type, pos, value)\
(*vector_insert_dst(vec_addr, type, pos) = value) (*vector_insert_dst(vec_addr, type, pos) = value)
#endif #endif
// vec is a vector (aka type*) // vec is a vector (aka type*)
#define vector_erase(vec, pos, len) \ #define vector_erase(vec, pos, len)\
(_vector_erase((vector)vec, sizeof(*vec), pos, len)) (_vector_erase((vector)vec, sizeof(*vec), pos, len))
#define vector_remove(vec, pos) (_vector_remove((vector)vec, sizeof(*vec), pos)) #define vector_remove(vec, pos)\
(_vector_remove((vector)vec, sizeof(*vec), pos))
#define vector_reserve(vec_addr, capacity) \ #define vector_reserve(vec_addr, capacity)\
(_vector_reserve((vector *)vec_addr, sizeof(**vec_addr), capacity)) (_vector_reserve((vector*)vec_addr, sizeof(**vec_addr), capacity))
#define vector_copy(vec) (_vector_copy((vector)vec, sizeof(*vec))) #define vector_copy(vec)\
(_vector_copy((vector)vec, sizeof(*vec)))
vector vector_create(void); vector vector_create(void);
void vector_free(vector vec); void vector_free(vector vec);
void *_vector_add_dst(vector *vec_addr, vec_type_t type_size); void* _vector_add_dst(vector* vec_addr, vec_type_t type_size);
void *_vector_insert_dst( void* _vector_insert_dst(vector* vec_addr, vec_type_t type_size, vec_size_t pos);
vector *vec_addr, vec_type_t type_size, vec_size_t pos);
void _vector_erase( void _vector_erase(vector vec_addr, vec_type_t type_size, vec_size_t pos, vec_size_t len);
vector vec_addr, vec_type_t type_size, vec_size_t pos, vec_size_t len);
void _vector_remove(vector vec_addr, vec_type_t type_size, vec_size_t pos); void _vector_remove(vector vec_addr, vec_type_t type_size, vec_size_t pos);
void vector_pop(vector vec); void vector_pop(vector vec);
void _vector_reserve( void _vector_reserve(vector* vec_addr, vec_type_t type_size, vec_size_t capacity);
vector *vec_addr, vec_type_t type_size, vec_size_t capacity);
vector _vector_copy(vector vec, vec_type_t type_size); vector _vector_copy(vector vec, vec_type_t type_size);
+1 -1
View File
@@ -3,6 +3,6 @@ set -euo pipefail
ROOT="$(git rev-parse --show-toplevel)" ROOT="$(git rev-parse --show-toplevel)"
find "$ROOT/src" -type f -name '*.c' -o -name '*.h' -print0 | while IFS= read -r -d '' f; do find "$ROOT/src" -type f -name '*.cppm' -print0 | while IFS= read -r -d '' f; do
clang-format -i --style=file "$f" clang-format -i --style=file "$f"
done done