py-sdl / py-sdl2

Python ctypes wrapper around SDL2
Other
304 stars 49 forks source link

Events (keyboard kew presses) missing when running app in Debian minimum (console only, no X window manager) #273

Closed TheConceptBoy closed 10 months ago

TheConceptBoy commented 10 months ago

The sample code, where, according to several other people, the input events should be processing:

import urwid
import ctypes
import sys
from sdl2 import *
import time

SDL_Init(SDL_INIT_EVENTS)

w = SDL_CreateWindow(b"test", 0,0, 800,600, SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_SHOWN)
SDL_ShowWindow(w)
SDL_RaiseWindow(w)

window_surface = SDL_GetWindowSurface(w)
r = SDL_CreateSoftwareRenderer(window_surface)
#r = sdl2.ext.Renderer(w, -1, (800,600), sdl2.SDL_RENDERER_SOFTWARE)

#sprite_factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=r)
#sprite = sprite_factory.from_image("resources/imgs/fr.png")

running = True
while running:

        event = SDL_Event()

        while SDL_PollEvent(event) != 0:
                print("events were present", event.key.keysym.sym)
                #print(SDL_GetKeyName(event.key.keysym.sym))
                if event.type == SDL_QUIT:
                        running = False
                        break

                if event.type == SDL_KEYDOWN:
                        #if event.key.keysym.sym == sdl2.SDLK_ESCAPE:
                        running = False
                        print("keydown detected")
                        break

        SDL_RenderClear(r)

        #sprite_render = sprite_factory.create_sprite_render_system(r)
        #sprite_render.render(sprite, x=100, y=100)

        #WHITE = sdl2.ext.Color(255,255,255,255)
        #r.draw_rect((5,5,64,64), WHITE)

        SDL_UpdateWindowSurface(w)
        SDL_RenderPresent(r)

SDL_DestroyWindow(w)
SDL_Quit()
exit()

Running on Debian minimum, on a Libre Potato AML s905X-CC computer.

a-hurst commented 10 months ago

Hi @TheConceptBoy,

Thanks for filing an issue! Are you sure that code's supposed to work properly on a system without a window manager? Having had to dig into the depths of SDL's C code a number of times, I'm pretty sure SDL handles input events through its video subsystem which on Linux can be X11, Wayland, KMS/DRM, or a few more exotic ones. Since your system is running console-only, I don't believe SDL is able to capture the input events you're hoping it to. Has this been reported as working on similar console-only systems?

All the best,

TheConceptBoy commented 10 months ago

Hi @TheConceptBoy,

Thanks for filing an issue! Are you sure that code's supposed to work properly on a system without a window manager? Having had to dig into the depths of SDL's C code a number of times, I'm pretty sure SDL handles input events through its video subsystem which on Linux can be X11, Wayland, KMS/DRM, or a few more exotic ones. Since your system is running console-only, I don't believe SDL is able to capture the input events you're hoping it to. Has this been reported as working on similar console-only systems?

All the best,

  • Austin

I've seen people ask about it but I've never seen any tangible answers. If handling keyboard inputs through SDL is out of the question, what do you reckon is the next best option? I'm still using SDL to render the application.

a-hurst commented 10 months ago

If you're creating a window for rendering with SDL, then input capture should work. What are you rendering to with PySDL2 if you don't have a window manager?

TheConceptBoy commented 10 months ago

If you're creating a window for rendering with SDL, then input capture should work. What are you rendering to with PySDL2 if you don't have a window manager?

You know what. I don't know what I was stressing about because I just installed wayland on this debian os using

sudo apt-get update
sudo apt-get install libwayland-dev

And then at the top of my python script, I used:

import os
os.putenv("SDL_VIDEODRIVER", "wayland")

And I am now receiving the keyboard event messages.

I thought this was going to be a lot more difficult

TheConceptBoy commented 10 months ago

What are you rendering to with PySDL2 if you don't have a window manager?

It was Kiosk style application.

a-hurst commented 10 months ago

If you're creating a window for rendering with SDL, then input capture should work. What are you rendering to with PySDL2 if you don't have a window manager?

You know what. I don't know what I was stressing about because I just installed wayland on this debian os using

sudo apt-get update
sudo apt-get install libwayland-dev

And then at the top of my python script, I used:

import os
os.putenv("SDL_VIDEODRIVER", "wayland")

And I am now receiving the keyboard event messages.

I thought this was going to be a lot more difficult

Fantastic! Yeah, I understand the use-case now. Since SDL2 links X11 and Wayland dynamically (if neither are present it'll fall back to its dummy renderer), you still need to have the libraries installed to be able to create a full-screen window in a system without a desktop environment.

Good luck with the kiosk project!