summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-10-08 20:33:41 +0200
committerxengineering <me@xengineering.eu>2022-10-08 20:34:00 +0200
commit27879d12f5a9f00b7c6b0d8fb9047710d82046bf (patch)
treedc1b83321eb029d800633c199ee0252689e3589f
parent413e6f664f460a342124103eeb4a5500ca3a5758 (diff)
downloadlimox-27879d12f5a9f00b7c6b0d8fb9047710d82046bf.tar
limox-27879d12f5a9f00b7c6b0d8fb9047710d82046bf.tar.zst
limox-27879d12f5a9f00b7c6b0d8fb9047710d82046bf.zip
Fix SDL2 window creation on Wayland
See this post: https://github.com/libsdl-org/SDL/issues/6074 It seems like SDL2 does not show an empty window on Wayland systems if there is nothing drawn on this. Thus this commit adds an empty white pixel buffer.
-rw-r--r--sdl2.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/sdl2.c b/sdl2.c
index e8a12f9..6b30891 100644
--- a/sdl2.c
+++ b/sdl2.c
@@ -2,8 +2,6 @@
/* mention the SDL2 documentation at http://wiki.libsdl.org/APIByCategory */
-/* WARNING this seems to be not working on Wayland! */
-
#include <SDL2/SDL.h>
#include <stdbool.h>
@@ -17,6 +15,9 @@ void gui_run(void) {
bool quit = false;
SDL_Event event;
SDL_Window* window;
+ SDL_Renderer* renderer;
+ SDL_Texture* texture;
+ uint32_t* pixels;
// init SDL2 and create window
SDL_Init(SDL_INIT_VIDEO);
@@ -28,12 +29,20 @@ void gui_run(void) {
// output video driver to stderr
fprintf(stderr, "SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
+ // create and initialize renderer, texture and pixel buffer
+ renderer = SDL_CreateRenderer(window, -1, 0);
+ texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
+ SDL_TEXTUREACCESS_STATIC, 640, 480);
+ pixels = malloc(sizeof(uint32_t) * 640 * 480);
+ memset(pixels, 255, 640 * 480 * sizeof(uint32_t));
+
// handle failed window creation
if (window == NULL) {
fprintf(stderr, "Failed to create SDL2 window!\n");
return;
} else {
while (!quit) {
+ SDL_UpdateTexture(texture, NULL, pixels, 640 * sizeof(uint32_t));
SDL_WaitEvent(&event);
switch (event.type)
{
@@ -41,10 +50,16 @@ void gui_run(void) {
quit = true;
break;
}
+ SDL_RenderClear(renderer);
+ SDL_RenderCopy(renderer, texture, NULL, NULL);
+ SDL_RenderPresent(renderer);
}
SDL_DestroyWindow(window);
}
+ free(pixels);
+ SDL_DestroyTexture(texture);
+ SDL_DestroyRenderer(renderer);
SDL_Quit();
}