X11: move an existing window via command line? - x11

Given an X client window ID, is there a way to move that window or change its geometry from the command line?
$ xlsclients -a
Window 0x3000001:
Machine: ohm
Name: Terminal
Icon Name: foo
Command: foo
Instance/Class: foo/bar
$ xmovewindow -id 0x3000001 --geometry +100+200 <-- this is what I would like to do

I think xdotool will do the job.
xdotool lets you programatically (or manually) simulate keyboard input and mouse activity, move and resize windows, etc. It does this using X11's XTEST extension and other Xlib functions.
E.g.
$ xdotool windowfocus 0x1a00ad2
will focus the window with id 0x1a00ad2. There's also a windowmove command which is probably the one you're looking for.
wmctrl is slighty more advanced. It is compatible with EWMH/NetWM X window managers as you can read on their website. I don't think you'll need it to be compatible with those though.

Related

Why does Fastscripts work with this but Platypus doesn't

Mac running Catalina. This code
#!/bin/bash
pbpaste|pbcopy
pbpaste>/tmp/tmp$$
open -W -a macvim /tmp/tmp$$
while [ `ps -A|grep MacVim|wc -l` -gt 1 ]
do sleep 1
done
cat /tmp/tmp$$|pbcopy
rm -f /tmp/tmp$$
is intended to plain-text the paste buffer then call up a terminal running macvim so I can use vi with less faff then put the result back in the clipboard. Its a way to speed-up editing when using various tools other tools and I just want to edit a section with vi.
I works well when called from Fastscripts or just plain execution but it won't work when I use Platypus to build a menubar app so its one fast click to use it - or rather, it works sometimes. Sometimes it hangs because it cannot connect input to the window in which macvim runs. I have to kill it from Activity Monitor to regain any control of input to other windows such as terminal. I've tried connecting stdin in the "open" command but still only works sometimes. And it shouldn't be standin anyway.
How is Fastscripts launching it and how can I do the same inside the script ?
I'd like very much to be able to launch it with a single click from the menubar but I don't know how to. I can build the platypus app if I know what to put in the shell script.
Thanks
andy

xdotool output lost in iTerm2

I am running Mac OS X 10.7.5. I have installed XQuartz v2.7.4, and along with it X11 v2.6.5. I have started iTerm2 with Xserver, and I believe it's working correctly since when I run xdpyinfo, the beginning of the output in xterm and in iterm2 is the same.
█ $xdpyinfo
name of display: :0
version number: 11.0
vendor string: The X.Org Foundation
vendor release number: 11006000
X.Org version: 1.10.6
...
However, when I run any xdotool commands in iTerm2 the output does not show up in the same window:
█ $ xdotool key f
█ - MacBook-Air:~ ()
Whereas, when I run from xterm:
bash-3.2$ xdotool key f
fbash-3.2$ f
So I can tell that in xterm the output from the command is going to the right window, but that doesn't seem to be the case for iTerm2. Please let me know if you have an idea of what I may be doing incorrectly or missing. Thanks!
The problem is that iTerm2 is not an XQuartz client, and while you are typing the commands, there is no current XQuartz window (since MacOS's focus is on the the iTerm2 window — not an XQuartz window.
The xdotool manual page tells you that the key command has an option which would be used to redirect events to other windows:
--window window
Send keystrokes to a specific window id. . You can use "WINDOW
STACK" references like "%1" and "%#" here. If there is a window
stack, then "%1" is the default, otherwise the current window
is used.
If you gave it a valid window id using --window, it likely would work as intended.

Getting X window id for GLUT program? or, How to remote control a GLUT program on X?

I want to send a keystroke to a GLUT program on X11, but I can't find there's an X11 client attached to the GLUT program.
I do this, using the most excellent demo program for the chipmunk 2d physics package:
xlsclients -a|sort >aa
chipmunk_demos (in another window)
xlsclients -a|sort >bb
diff aa bb
and there's no difference.
My eventual hope is that I can control the GLUT program by sending key events with the equivalent of:
xdotool key --window 0x4000002 a
So my questions:
how can I remote control a GLUT program running on linux/X11?
Is there a way to get an X11 window id for a GLUT program?
Install xtrace, then:
In Terminal 1:
xtrace -d :0 -D :8 | grep CreateWindow
In Terminal 2:
DISPLAY=:8 chipmunk_demos
You should get a line with:
... CreateWindow depth=0x18 window=0x04a00002 ...
Update: xdotool actually contains powerful search functionality, which recent versions make even easier to use. It doesn't make sense to use xtrace like this, just use xdotool search instead

X11: waiting until a window is visible?

I'm running X across a slow network connection. How can I tell when a window has become visible? I need to wait so that I can perform another operation on the visible window.
xterm -T foo &
# how to flush the display, or wait until the window is visible?
# polling the visibility would be acceptable as well
xmovewindow foo 10 20
update: Thanks to Jim Lewis, here's a quick shell function that does the trick.
function xwait() {
while ! xwininfo -name $1|grep 'Map State: IsViewable';do sleep 1;done
}
xterm -T foo &
xwait foo
xmovewindow foo 10 20
You probably want to know when the remote X server has mapped your application's main window. The xwininfo command will let you query the X server by window name -- I think it's part of the standard X11 install. But you'd have to do the polling yourself, rerunning the command until the "Map State" property comes back "IsViewable"
Jonathan Leffler also mentioned Sun's toolwait utility (documentation here). toolwait launches a process (in this case, your xterm command), and returns when the application has mapped a top-level window...it does the polling for you. There's a package that purports to be a Linux clone of toolwait in the X11/xutils directory at www.ibiblio.org (here).
toolwait dates all the way back to OpenWindows -- now that's some old school X window programming, man! I have in front of me a Solaris man page dated 1994, which states "The OpenWindows environment may no longer be supported in a future release. You may want to migrate to CDE, the Common Desktop Environment..."

Using keyboard to navigate the OS X terminal scrollback buffer

I hate using the mouse. When working in the OS X terminal, sometimes I want to navigate to a line in the bash shell a few rows up, copy a word or two. For this I always end up using the mouse. Any solution for this? Perhaps the terminal supports a key combination that puts it in to navigation/select/copy mode, where I can use the usual C-F, C-B, C-N and C-P keys.
If you feel comfortable with Vi key combinations, you can use this command to switch to vi-mode and use key strokes:
$ set -o vi
Or use C-xC-e to open current line in your $EDITOR.

Resources