mattblovell / kodi_panel

Front panel LCD display for Kodi (via JSON-RPC)
MIT License
12 stars 5 forks source link

run on secondary hdmi/dvi/dp display #49

Open succo69 opened 10 months ago

succo69 commented 10 months ago

i've got an old desktop case with a 7'' display (ahanix MCE 701) and would like to revive it attached to a TV monitor, using the case display to show kodi info, but can't really make luma (i guess i have to use luma-emulator in this setup) to show info on secondary screen, attached via VGA (or DVI, or HDMI), as i can't seem to make the system use one screen to display the kodi interface and the other one to show the panel info... would this be possibie? Any directions?

Thanks

mattblovell commented 10 months ago

You didn't specify what OS you're using, but if it is Linux ...

These days, I believe Kodi takes over the entire GPU, so it won't really coexist well with other graphical applications. Back when Kodi was a windowed application under X, I think what you described would work better.

(One of my naive hopes for the RPi4 is that I could use one HDMI output for Kodi's display -- connecting to a TV -- and the other HDMI port to drive a secondary display. Kodi running on its own, without X, and the modern DRM approach for Linux graphics put the kabosh on that scheme.)

I haven't tried Kodi under Windows in quite a while, so I can't comment on the setup.

If you can provide more details, I might be able to comment more.

mattblovell commented 10 months ago

Looking at the scenario you describe another time, how would the (smaller) case display be driven? Perhaps a distinct (and inexpensive) graphics card separate from the one driving the main HDMI (consumed by Kodi) could be viable?

succo69 commented 10 months ago

sorry, forgot to mention... yes, the pc is running linux (ubuntu devel) in a partition and libreelec (so, linux again) in another. I tried the double graphic card way, but desisted as i didn't know how to say kodi to use fb0 and python to use fb1 (and btw libreelec didn't start at all with two graphic cards), that's why i was trying to use pygame and luma emulator with one monitor attached to the hdmi and the other to the vga/dvi on the same card

mattblovell commented 10 months ago

Yes, under Linux if you could

then you could use kodi_panel_fb.py (updating the device framebuffer file on Line 36 as needed) to have both active. Steering Kodi is the part that I don't know much about, though! I was trying something similar with the RPi4 (with kodi installed under Raspberry Pi OS) but was stymied by a single GPU being responsible for driving both heads. I even tried contacting one of the DRM contributors for the Linux kernel at the time, to no real avail.

(A side issue -- for your scenario, I don't know whether it would be simpler get Kodi running within your Ubuntu installation or to get the necessary (mostly Python) components of kodi_panel installed under LibreELEC.)

I'd look through available Kodi documentation and its online forums to see if there's anything about multi-headed setups. Most such discussions, I bet, would focus on getting Kodi itself to "do something useful" with the second display. Here, though, we really just want to "confine" Kodi to the first GPU / head / framebuffer and leave the second available for (anything) else.

I really think such a setup would be possible, but I obviously had no luck previously.

succo69 commented 10 months ago

well, as i said kodi doesn't start at all with two video cards in LibreELEC, probably because X refuses to start (I'm using generic-legacy, as i mosrly use nvidia cards,but the secondary card is an old radeon). Make kodi_panel an addon is not too difficult (some python must be installed, some can go in the lib folder of the addon) I will try again (under plain ubuntu) and let you know

succo69 commented 4 months ago

still troubles, as i wouldn't like to have two video cards active i'm still trying to split the framebuffers for hdmi and dvi on the videocard, with no success... i even tried to attach a cheap usb2vga adapter (with a frescologic chip) but the drivers don't want to work in my system ,the original driver from frescologic doesn't create a framebuffer device at all (creates a /dev/fl2000-0 device which can't be used as a framebuffer device), the drm driver creates it but i can't draw anything (no way to fill it with urandom) is there a way to split fb0 in fb0 for hdmi and fb1 for dvi?

mattblovell commented 4 months ago

is there a way to split fb0 in fb0 for hdmi and fb1 for dvi?

Your question is a good one, but unfortunately I'm not the right one to answer it -- it is a Linux device-driver and DRM question.

With RPi and similar SBCs offering multiple display interfaces, one would think providing a framebuffer per HW interface would be a common desire. That's not the path X and DRM took, though.

For discrete video cards that happen to have multiple outputs, I've no idea what is possible. As with the RPi, there you have a dual-track problem:

succo69 commented 4 months ago

i see... I'm still running the multiple framebuffer path, will try with another USB to VGA adapter (if I succeed in bringing up the second framebuffer). If it doesn't work at all i guess i will have to try with pygame, moving the used area after the main screen (really don't know if it will work)

succo69 commented 4 months ago

no way, even with a DisplayLink adapter... now the screen works, but it's just like when i attach the monitor to the dvi on the video card, there is just one fb device and the second monitor extends (or mirrors) the desktop so, with a FrescoLogic adapter (and drm driver) i have a second fb but it never lights up, with DisplayLink i have light but no new fb... what next? :)

mattblovell commented 4 months ago

what next? :)

I've no real idea, unfortunately -- that's why I went down the completely separate computer route! :)

Kodi is no longer a windowed app, and the modern DRM stack seems like it only wants to deal with one application (e.g., X or Wayland). I've seen hints discussed online about how a main DRM application can "lease out" portions of the display, but I've no idea how to actually accomplish that.

If you want to continue, I think you'll have to "dive down" a bit more (or find the right person) ...

succo69 commented 3 months ago

ok, after a lot of try and error i found a way to make it work with luma.emulator and pygame, but had to modify the pygame luma code to show without any frame and have to start with SDL_VIDEO_WINDOW_POS=2560,0 to put the pygame window on the second screen (attached via dvi on the same video card) but now... I guess the code just doesn't work with PIL 10 (it has getsize(string) which just doesn't work in PIL). I substituted the getsize with getlength but now i end up with ‘float’ object is not subscriptable whenever i use getlength with an array, so, with the [0] removed now it seems to work :)

mattblovell commented 3 months ago

Looks like various getsize() calls were indeed deprecated in Pillow 10.0.0, discussed on this page (some scrolling or a find necessary):

https://pillow.readthedocs.io/en/stable/deprecations.html

The suggested replacement method, depending upon the object, are either getlength() or getbbox(). I've not gone looking to see whether the getsize() calls needing to be updated reside in kodi_panel or in luma (or if luma is generally compatible with the latest Pillow).

Edit: Looks like the Pillow method is also discussed in Issue 7322 for Pillow:

https://github.com/python-pillow/Pillow/issues/7322

The [0] index is being used in existing kodi_panel code to get just the width, as getsize() historically returned both the width and the height. Based on Pillow's ImageFont documentation, looks like getlength() returns just a single dimension (length) in pixels, so no array indexing should then be needed.

mattblovell commented 3 months ago

Looks like the Pillow 10.0.0 update removed some (previously deprecated) methods. I'll try to do a "refresh" sometime soon and get kodi_panel updated accordingly. (I haven't touched my CoreELEC installation in a bit either, so it needs an update, too.)

In the meantime, I think you should be able to just remove the array indexing when using getlength().

succo69 commented 3 months ago

yes, i can confirm it does work, now (as there is no pygame in libreelec)i have to make my ubuntu installment a mediacenter, starting kodi without a full environment and all

succo69 commented 2 months ago

ok, i succeeded in making it run, now i see kodi on the main monitor and panel on the secondary, but kodi is completely unresponsitive, no keypresses, no remote response. I guess it is because somehow the panel window (even if on another monitor) is in front of the kodi window, is there a way to solve this?

right now my kodi_panel.service looks like this:

#
# systemd service file for kodi_panel
#
#   Edit the WorkingDirectory below as appropriate for your
#   installation.
#
#   On an RPi running Raspberry Pi OS, this file should be
#   copied to the directory
#
#     /etc/systemd/service
#
#   after which one can then one commands such as:
#
#     sudo systemctl start kodi_panel
#     sudo systemctl stop kodi_panel
#     sudo systemctl restart kodi_panel
#
#     sudo systemctl enable kodi_panel   # start upon boot
#     sudo systemctl disable kodi_panel  # disable start at boot
#
#   If you are running a different OS, check systemd documentation
#   for your platform for appropriate service file location.
#

[Unit]
Description=kodi_panel display
After=network.target rc-local.service kodi.service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=myuser
KillSignal=SIGINT
# Optional priority change for kodi_panel, uncomment if needed
# Nice=-18
WorkingDirectory=/home/myuser/kodi_panel
Environment=PYTHONUNBUFFERED=1
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/myuser/.Xauthority
Environment=SDL_VIDEO_WINDOW_POS=2560,0
ExecStartPre=/bin/sleep 4
ExecStart=/usr/bin/python3 -u kodi_panel_demo.py --display pygame --width 800 --height 480 --scale 1

[Install]
WantedBy=multi-user.target

Of course, I had to set the monitor size and relative position in xorg (and start kodi with xinit), but what works within the graphical target somehow doesn't in multi-user target

mattblovell commented 2 months ago

ok, i succeeded in making it run, now i see kodi on the main monitor and panel on the secondary, but kodi is completely unresponsitive, no keypresses, no remote response. I guess it is because somehow the panel window (even if on another monitor) is in front of the kodi window, is there a way to solve this?

What you're describing is window focus, right? That would be the realm of the X window manager and pygame, since kodi_panel itself is oblivious that it's even running in such an environment. I don't immediately know of any setting (e.g., environment variable) that would serve to prevent an application from receiving focus, since that's normally governed by direct interactions.

Before pursuing things further, you could try switching the active (focused) window via Alt-Tab or some similar hotkey (as I think would be set by default in most distributions).

mattblovell commented 2 months ago

This might be interesting ...

Bash command to focus a specific window https://superuser.com/questions/142945/bash-command-to-focus-a-specific-window

It was found in a RPi forum asking about pygame and window focus.

succo69 commented 2 months ago

no, wmctrl seems not to work with xinit, it needs a full wm to work, so if i add a post wmctrl command to the panel service it restarts indefinitely (i find a lot ofwmctrl[2230]: Cannot get client list properties. wmctrl[2230]: (_NET_CLIENT_LIST or _WIN_CLIENT_LIST) strings in the service log)

succo69 commented 2 months ago

I really don't know what happened but with the wmcrtl line i had a perpetual restart of the panel service (as wmctrl seems to need a whole wm, not just a bunch of windows), but a simple post line with a sleep 5 made it work :) now i guess i need to configure the output

succo69 commented 2 months ago

ok, what solved the problem was not the sleep interval but the fact that I installed lirc, so that the remote didn't care of keypresses... now the remote works, the panel service works too but anything related tho the keyboard (or joypad) doesn't, so that if I go from kodi to emulationstation the joypad isn't recognized, could it depend from the polling in the main loop of panel_display? should i comment out the lines 3103 to 3107 and see what happens?i won't have touchscreen, but maybe a responsive keyboard :)

mattblovell commented 2 months ago

... could it depend from the polling in the main loop of panel_display? should i comment out the lines 3103 to 3107 and see what happens?i won't have touchscreen, but maybe a responsive keyboard :)

I wouldn't immediately think so. Focus and switching of focus would be the responsibility of the window manager. (I'm assuming you're running some form of window manager, but perhaps I'm mistaken.) While an application can grab focus exclusively, I don't recall the pygame demonstration mode ever doing that (when I was using it for development). I think it would take "extra" options to declare that a window wants focus to the exclusion of all other applications. (See, for instance, the get_focused() method discussed on https://www.pygame.org/docs/ref/key.html.)

The test you propose seems like a good experiment, though.

EDIT: Helps to finish sentences.

succo69 commented 2 months ago

i don't really think it's a focus problem, as with the remote everything works fine... my guess is that somehow pygame is capturing all evdev traffic for its purposes so that the keypress doesn't reach any other program running will try to comment the lines and let you know