Hyperpixel Square with second monitor + xserver, choose on which display to start app

Hi,

I have a Raspberry Pi 5 + Hyperpixel Square + a HDMI monitor connected.
I have a graphical app that needs to be started, and I don’t have the need for an entire desktop UI, so I basically boot into the CLI, and then start X server to just run my App.

So my .xinitrc is basically a one-liner:

exec <app name>

I simply run startx and this works fine: the app starts on my hyperpixel square attached to the PI.

But… there are also cases where I want to run this App on a connected display. Up until now I did this by editing /boot/firmware/config.txt and rebooting the Pi, but surely there must be an easier way than this right?

I tried tinkering with the .xinitrc file, or try adding arguments and stuff, but the best I get is that my HDMI display clones what is shown on the Hyperpixel Square - in a 720x720 square on my 1920x1080 display.

So what are my options here? I’m fine with something like an argument or editing the .xinitrc-file, just as long as it doesn’t require rebooting the Pi everytime. It’s anoying.

Any thoughts on this?

Hi kanduvisla,

Since you want to switch the display dynamically without rebooting, relying on /boot/firmware/config.txt won’t help as it’s parsed only at boot time. Instead of hardcoding it there, you can pass the display geometry or target the specific X display environment directly via your startup script variables.

When I was testing UI scaling and multi-window rendering behaviors for an open-source manga reader app, we faced similar challenges where the software interface had to adapt dynamically to atypical aspect ratios or secondary external displays without crashing the active environment.

For your setup, instead of just running a single-line exec <app name>, you can use the environment variables to target specific screens. Try checking the output of xrandr before running your app, or define the target display dynamically like this inside your .xinitrc:

Specifying the display output dynamically before execution

DISPLAY=:0.1 exec <app_name>

Alternatively, you can create two separate small shell scripts (e.g., start_hyperpixel.sh and start_hdmi.sh) that set the respective xrandr primary display output configuration right before triggering the exec command. This completely bypasses the need to reboot the Pi every time you switch screens.

Hope this points you in the right direction!

`DISPLAY=:0.1` is probably not the way to go here as the Hyperpixel and HDMI are usually served by the same X server. So I would set the primary output or turn on / off the display you want before launching the app (using **XRandR**). Its a pain to edit config.txt and reboot every time . A much cleaner solution is to wrap your startx command in a small programme that runs the appropriate xrandr commands first .