4

I have multiple firefox windows, I'd like to use a shortcut of current window manager to resize curent active firefox's window to specific size and position.

How xdotool command to achieve this?

EDIT: For example I have window manager named dwm and I map some shortcuts of this window manager, then I can press a combined keys on the current firefox's window.

Focus still on the firefox'window.

Probably we can map to call a shell script with combined key.

3
  • please explain what 'current active' means. is that the firefox window that has the keyboard focus? in that case typing the xdotool command in a terminal would not work, because it's the terminal which has the focus. If you want to resize all firefox windows: xdotool search --classname Navigator windowsize %@ 800 600; replace %@ with %1 to resize just the first from the list.
    – user313992
    Sep 26, 2018 at 11:33
  • I've just updated the question. Yes, current firefox windows = focus on firefox windows, not terminal.
    – Tuyen Pham
    Sep 26, 2018 at 13:35
  • then the first part of my answer should just work. please comment on it if it does not.
    – user313992
    Sep 26, 2018 at 14:08

1 Answer 1

6

If you want to resize the firefox window that has the keyboard focus:

#! /bin/sh
fw=`xdotool getwindowfocus`
for nw in `xdotool search --classname Navigator`; do
   test "$fw" = "$nw" && xdotool windowsize "$fw" 800 600
done

Notice that this will not work if you're typing the script in a terminal; in that case it's the terminal that has the focus. You can use getactivewindow instead of getwindowfocus if your window manager supports _NET_ACTIVE_WINDOW.

If instead you want to resize the top-first firefox window:

nw=`xdotool search --classname Navigator | tail -1`
test "$nw" && xdotool windowsize "$nw" 800 600

Note

If you're using dwm, then please consider this (from the dwm's homepage):

dwm is customized through editing its source code, which makes it extremely fast and secure - it does not process any input data which isn’t known at compile time, except window titles and status text read from the root window’s name. You don’t have to learn Lua/sh/ruby or some weird configuration file format (like X resource files), beside C, to customize it for your needs: you only have to learn C (at least in order to edit the header file).

Because dwm is customized through editing its source code, it’s pointless to make binary packages of it. This keeps its userbase small and elitist. No novices asking stupid questions.

This means that calling an external script is simply not going to work. You're supposed to resize windows, check their class, etc from C, by modifying dwm's source code.

3
  • I use tmuxvm, how would it apply to this case?
    – Tuyen Pham
    Sep 27, 2018 at 18:22
  • I don't know, it's the first time I hear about it.
    – user313992
    Sep 27, 2018 at 18:29
  • I'll do some hacks into the wm. Your script should work then as I tried to call a script already.
    – Tuyen Pham
    Sep 28, 2018 at 5:28

You must log in to answer this question.

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