You are not logged in.

#1 Today 07:53:35

bivan
Member
Registered: 2026-02-03
Posts: 101

A command or app to display black?

Is there a command or app to display black, on CLI or GUI (at least, KDE)? Not "Turn off screen" on KDE because I need audio, see https://bbs.archlinux.org/viewtopic.php?id=315325 .

Googling "linux how to display black" I found 2 commands using xrandr or xset but as their names suggest it's X, GUI KDE I use Wayland & on CLI they don't work.

#!/bin/bash
gwenview -f /home/a/.png

(.png is a 1920*1080 (resolution of my display) black image) but only GUI & then I must close Gwenview.

The ideal:
I click on a file, I enter a shortcut or a command: black display (still audio),
then any input e.g. pressing any key: back to normal.
On CLI or GUI (at least, KDE).


Arch Linux KDE

Offline

#2 Today 08:40:44

killertofus
Member
Registered: 2025-02-10
Posts: 291

Re: A command or app to display black?

Small python script that renders a black rectangle window that can be maximized with right click and closed with left click. Use -m to start it in fullscreen Requires tk package installed

karabaja4 made the script

 #!/usr/bin/env python3
import sys
import os
import tkinter as tk

class ToggleFullscreenApp:
    def __init__(self, root, start_fullscreen=False):
        self.root = root
        self.fullscreen = False

        # Initial window size (rectangle)
        self.width = 1280
        self.height = 800
        self.root.geometry(f"{self.width}x{self.height}")  # let WM place it
        self.root.configure(background="black")
        
        pid = os.getpid()
        self.root.title(f"OLED saver [{pid}]")

        # Bind click events
        self.root.bind("<Button-3>", self.toggle_fullscreen)
        self.root.bind("<Button-1>", self.exit_app)

        # Force window manager to place window and get actual geometry
        self.root.update_idletasks()
        x = self.root.winfo_x()
        y = self.root.winfo_y()
        w = self.root.winfo_width()
        h = self.root.winfo_height()
        self.saved_geometry = f"{w}x{h}+{x}+{y}"

        # Start in fullscreen if requested
        if start_fullscreen:
            self.toggle_fullscreen()

    def toggle_fullscreen(self, event=None):
        self.fullscreen = not self.fullscreen
        if self.fullscreen:
            # Save current geometry
            self.root.update_idletasks()
            x = self.root.winfo_x()
            y = self.root.winfo_y()
            w = self.root.winfo_width()
            h = self.root.winfo_height()
            self.saved_geometry = f"{w}x{h}+{x}+{y}"

            # Go fullscreen
            self.root.attributes("-fullscreen", True)
        else:
            # Restore original size and position
            self.root.attributes("-fullscreen", False)
            self.root.geometry(self.saved_geometry)

    def exit_app(self, event=None):
        self.root.quit()


if __name__ == "__main__":
    script_name = sys.argv[0]
    
    if "-h" in sys.argv or "--help" in sys.argv:
        print(
            f"Usage: python3 {script_name} [options]\n\n"
            "Options:\n"
            "  -h, --help      Show this help message and exit\n"
            "  -m              Start the application in fullscreen mode\n\n"
            "Controls:\n"
            "  Right-click     Toggle fullscreen on/off\n"
            "  Left-click      Exit the application"
        )
        sys.exit(0)
    
    start_fullscreen = "-m" in sys.argv
    root = tk.Tk()
    app = ToggleFullscreenApp(root, start_fullscreen=start_fullscreen)
    root.mainloop()

I Have Linux Perl Can i Download Gnome???

Offline

#3 Today 09:02:23

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,925

Re: A command or app to display black?

Afaiu DPMS should™ not cut down the audio signal - does your monitor have settings to control its DPMS (powersaving) behavior?
Otherwise it's not very hard to write a tiny Qt/wlr program to create a black window but the most reasonable approach would likely be a kwin script that just stops all rendering.

Edit: F5

Last edited by seth (Today 09:02:45)

Online

#4 Today 12:33:26

bivan
Member
Registered: 2026-02-03
Posts: 101

Re: A command or app to display black?

should is trademarked?

Yes my ViewSonic VP16-OLED has Sleep & Auto Power Off, but what link? Googling "displayport audio only": "It cannot transmit an "audio-only" signal by itself because DisplayPort architecture requires an accompanying video stream/handshake to function." https://en.wikipedia.org/wiki/DisplayPort#Main_link , so "Turn off screen" cuts audio.

According to Gemini & I think it's right: stopping all rendering would freeze...

killertofus I've better: Gemini gave me a C code using SDL: it works! But cuts audio on CLI... https://share.gemini.google/HskqfqlkkigD

Last edited by bivan (Today 13:43:36)


Arch Linux KDE

Offline

#5 Today 13:41:07

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,925

Re: A command or app to display black?

Yes should™ is trademarked to separate it from "should" which indicates a neglect of reality wink

The other thread said HDMI, but either way I'd ask the LLM for a kwin script that will also skip all rendering overhead.
As for the CLI, setterm -blank will likely cause DPMS, but ctrl+l should™ do most of it ?

Online

#6 Today 13:54:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,553
Website

Re: A command or app to display black?

seth wrote:

As for the CLI ... ctrl+l should™ do most of it ?

Or the following script will do all of it.  And if you have a TE with a black (or suitably dark) background, launching a fullscreen terminal to run this script would work in the GUI as well.

#!/bin/sh

printf '\033[?25l'
clear
read -n 1
printf '\033[?25h'

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Online

#7 Today 14:40:00

bivan
Member
Registered: 2026-02-03
Posts: 101

Re: A command or app to display black?

Googling "hdmi vs displayport": it seems complicated... I use HDMI because my old PC hasn't USB-C but in the future I'll use USB-C (DisplayPort & PD power delivery) by a new mini PC.

"a kwin script that will also skip all rendering overhead" like window shadow etc? No need, I all disabled.

setterm --blank returns 0 ...

TE terminal?

Nice your script, there's audio! Good job inspector. But Konsole even fullscreen by F11 there's still a bar above.

Last edited by bivan (Today 14:44:36)


Arch Linux KDE

Offline

#8 Today 14:47:46

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,925

Re: A command or app to display black?

"Terminal Emulator", the command would be "setterm --blank force"

like window shadow etc?

"Like everything" - notably all windows etc.  leaving only the (default black) canvas.

You're losing audio when entering DPMS via HDMI? Is it maybe because the monitor completely shuts down and unregisters?

Online

Board footer

Powered by FluxBB