24

Is there a command to tell compiz that we want to bring in front and set focus to a specific window? How should we identify the window in that command?

The reason behind this question is the following use-case:

Suppose we have a wiki to keep notes of anything interesting we find out. It would be very convenient to have a keyboard shortcut to bring the browser window with our Wiki page in front and start typing immediately then with another key combination switch to the application we were working before

I know that ALT + TAB switches between the last two used windows but cannot support more complex combinations of applications. E.g Browser+Eclipse+ Wiki

If there is a command like the one described, it is easy to add a shortcut to it from KDE or GNOME interface

rburny
  • 1,559
  • 1
  • 9
  • 28
FossilBit
  • 503
  • 4
  • 7

5 Answers5

28

What you are looking for is wmctrl. For example, add a keyboard shortcut to invoke a command like

wmctrl -Fa 'Wiki - Google Chrome'

to raise and activate the window with that title.

There are different ways of selecting a window by title, id, etc. See man wmctrl. The list of windows can be obtained running

$ wmctrl -l

I haven't tried it with compiz but wmctrl should work for any EWMH compliant window manager.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • 3
    Just a sidenote: wmctrl's -F option makes it look for exact match on window title. Otherwise, its just substring search (which may be better suited for some purposes). – rburny Mar 22 '13 at 22:14
  • Yep, one may use `wmctrl -a 'Google Chrome'` to switch to the first window partially matching that string. – jwav Mar 11 '22 at 10:26
5

This worked for me with Compiz:

xdotool windowactivate `xdotool search --onlyvisible --class firefox`
dave1010
  • 15,135
  • 7
  • 67
  • 64
  • Worked for me just now under Ubuntu 12.04 with Unity, whereas wmctrl did not. Thanks! – Jeff Ward Mar 11 '13 at 20:17
  • 1
    You don't need two separate xdotool commands; you can use %1 to refer to the first search result, or %@ to refer to all of them: xdotool search --onlyvisible --class firefox windowactivate %@ – Don Hatch Jun 10 '16 at 06:12
2

You'll want to send the _NET_ACTIVE_WINDOW client message to the root window. This will alert any compliant window manager (including Compiz) that you are requesting to make active a particular window.

See the EWMH spec, specifically the section on _NET_ACTIVE_WINDOW.

Note that depending on the window manager's configuration, it may refuse to honor your request, or give the user the chance to ignore it.

Adam Goode
  • 7,380
  • 3
  • 29
  • 33
1

I found this web page that has an example source program you could compile that will take bring an X window to the front.

The key is the X11 function XRaiseWindow.

I imagine it would be pretty easy to write a small program and either write a wrapper script or just make the program itself robust, and then set Compiz to attach this to a global keyboard shortcut.

Dave
  • 5,133
  • 21
  • 27
0

The Widget plugin could do what you describe.

  • Configure the Widget plugin to mark the desired windows as widgets (e.g. by matching on window title or role).
  • Configure the Window Rules plugin to make widget windows present on all workspaces (sticky) and to skip the taskbar.

See http://wiki.compiz.org/Plugins/Widget

Jean Jordaan
  • 626
  • 8
  • 24