3

Is there a command or setting in the X Toolkit to start xterm minimized?

Having read (1) and man xterm, I tried to start xterm minimized from a gnome-terminal via:

xterm -iconic

or calling the X resource directly xterm -xrm 'xterm*iconic: 1'

However, the argument did not have an effect. xterm did not start minimized.

  • OS: Ubuntu 18.04
  • Gnome: 3.28
  • xterm(330)
Oscillon
  • 154
  • 1
  • 9
  • Indeed, Gnome Shell does not seem to honor xterm's -iconic option. In default Ubuntu (and linux) the window manager provides no build in control for the windows on startup (maximized, minimized, ...). Two old tools that still do the job well are devilspie and devilspie2. These are daemons that take action on specific windows right after they have been created. – vanadium Jan 05 '20 at 11:56
  • If I understand devilspie correctly, it will modify all calls of xterm to start minimized. I would prefer that by default it is called in "normal" size and only in certain cases when I call xterm from the commandline it starts minimized. Is that possible with devilspie? – Oscillon Jan 05 '20 at 20:09
  • Curiously, xterm -maximized starts xterm in a maximized view as expected. – Oscillon Jan 05 '20 at 20:14

1 Answers1

1

I've wanted to do the same thing for debugging. The problem seems to be that window manager is overriding the provided old-style requests. I can give you a kludgy answer, but it will work (sort of).

First, you need the xdotool, a utility that executes X actions from the command line. E.g.

sudo apt install xdotool

Then, you can start an xterm minimized as follows:

(xterm &); xdotool windowminimize $(xdotool search --sync --class xterm |head -1)

Some explanation . . . obviously, the first command starts the xterm. You could start the terminal with a command or whatever. The second command minimizes the window with a supplied window id. The window id is supplied by nested call to xdotool that returns all window ids matching the xterm class. We use the first on the stack, which should almost certainly be the one that we just created. The --sync option is necessary to make xdotool pause until there is an id that is of the xterm window class.

This kludge could fail if you are planning on launching multiple xterm windows in this fashion. In that case, you could add some sleep before the call to xdotool.

Yeah, I know this is a disgusting solution. But it's the only one I know.

Martin W
  • 2,545
  • This works really well for a single xterm! You are exactly right in assuming I want to launch multiple xterm windows. I tried sleep 2 but it only minimizes one window. – Oscillon Jan 06 '20 at 02:09
  • I found the problem: the first xdotool command will only work on a single id. So for multiple ids, one needs a loop: for id in $(xdotool search --sync --class xterm | head -10); do xdotool windowminimize $id; done – Oscillon Jan 06 '20 at 02:40
  • There is no way of setting the id of the spawned xterm window, right? – Oscillon Jan 06 '20 at 02:45
  • Yes, xdotool search --class xterm will return the whole stack. So if you want to instantiate a bunch, your loop should work fine. – Martin W Jan 06 '20 at 15:18
  • The xwindow ID is an internal unique specifier and cannot set. However, you could use PID to find windows, which is often easier since the PID is more accessible. xdotool search can be used to match the PID field as well. Yeah, my point about needed sleep X is waiting for the metadata to appear in the window stack. If there are priorxterm instances, they would get returned before the most recent one. I'm guessing you want to start a bunch at once. In that case, your loop solution is probably sufficient in most cases. – Martin W Jan 06 '20 at 15:24