0

On geometry the X man page says:

"GEOMETRY SPECIFICATIONS: ... most X programs accept a command line argument of the form -geometry WIDTHxHEIGHT+XOFF+YOFF (where WIDTH, HEIGHT, XOFF, and YOFF are numbers) for specifying a preferred size and location for this application's main window. The WIDTH and HEIGHT parts of the geometry specification are usually measured in either pixels or characters, depending on the application ..."

Seems for both xterm and xfce4-terminal the WIDTH and HEIGHT of -geometry option are in units of characters. In order to launch such a terminal with a specific geometry relative to the screen programatically (example, tiling: cover each quadrant with a terminal window) I need to know the size of the screen in units of characters. I can find in pixels with xwininfo -root but can't figure out how to find in character units. How do do this? Answer specific to XFCE4 would be fine.

10
  • xwininfo also doesn't tell you the usable dimensions (e.g you have to subtract some for borders, scrollbars, window decorations, menu bars and such). And it also depends on the size of your font. But you can always open an xterm and resize it: it'll tell you its geometry in characters while you are resizing it, so just remember the numbers when you are happy with it and let go of the mouse button. I just found out however that the offsets are in pixels, so I have to say xterm -geometry 104x32+960+540 to get one that's a quarter size and placed in the lower right quadrant of my screen.
    – NickD
    Apr 6, 2022 at 4:13
  • I want to do this programatically. For example, script to start 4 different networking monitoring tools and tile terminals over screen. You right about having to account for things like panels but I guess close enough is good enough as a first step. Yes the pixel to character unit conversion depends on the font. And yes it is rather odd that xoff, yoff are in pixels but w, h are in characters!
    – spinkus
    Apr 6, 2022 at 4:30
  • If you're running a shell inside the terminal, you can use tput cols and tput lines (if ncurses is installed). Not sure if it's possible to do it from outside a shell running in the terminal in question, though.
    – frabjous
    Apr 6, 2022 at 4:32
  • Thanks @frabjous, was aware of tput cols|lines. A tput option analoguous to xwininfo's -root would be perfect but AFAIK not such thing exists. I think tput is never going to be window manager aware - as far as it's concerned there is just one terminal screen and that's that.
    – spinkus
    Apr 6, 2022 at 4:36
  • 1
    You need -i I think to use window IDs.
    – NickD
    Apr 12, 2022 at 5:09

1 Answer 1

1

Answering own question: Using wmctrl as suggested by @NickD came up with a hacky solution:

#!/bin/bash

get_window_id() { # Convert window title into wmctrl window id
  wmctrl -l | grep "$1" | cut -f1 -d" " | tail -n1
}

screen_dim=( $(xwininfo -root | grep "\-geometry" | sed -r 's/.* ([0-9]+)x([0-9]+)\+0\+0/\1 \2/gp' -n) )

w=$((screen_dim[0] / 2))
h=$((screen_dim[1] / 2))
k=40

xfce4-terminal --title="My Window 1"
xfce4-terminal --title="My Window 2"
xfce4-terminal --title="My Window 3"
xfce4-terminal --title="My Window 4"

wmctrl -i -r $(get_window_id "My Window 1") -e 0,0,0,$w,$((h - k))
wmctrl -i -r $(get_window_id "My Window 2") -e 0,$w,0,$w,$((h - k))
wmctrl -i -r $(get_window_id "My Window 3") -e 0,0,$h,$w,$((h - k))
wmctrl -i -r $(get_window_id "My Window 4") -e 0,$w,$h,$w,$((h - k))

The k parameter is a crude adjustment to account for task bar issue as also mentioned by @NickD.

If I could somehow find the pixel dimensions of a character could just pass geometry straight to xfce4-terminal, which is a bit cleaner:

screen_dim=( $(xwininfo -root | grep "\-geometry" | sed -r 's/.* ([0-9]+)x([0-9]+)\+0\+0/\1 \2/gp' -n) )
w=$((screen_dim[0] / 2))
h=$((screen_dim[1] / 2))
cw=$((c/character_width))
ch=$((h/character_height))
k=1
xfce4-terminal --title="My Window 1" --geometry=${cw}x${ch}+0+0
...

But can't figure out how to get character_width, character_height.

1
  • Alas, character width and height of your xfce4-terminal depend on the font settings of your xfce4-terminal. What you would need is a way to interrogate xfce4-terminal for these settings before you start the actual xfce4-terminal terminal window. Such a feature is probably not going to be implemented ever. Until then, and once you settle for a particular terminal font and font size, you could manually determine width and height in characters of a full screen terminal window, and put these for instance in your login script for central reference.
    – db-inf
    Sep 17, 2022 at 16:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .