5

Is it possible to use wmctrl or something else to make a specific window automatically display on all desktops?

I use the Prime Player Google Play Music miniplayer Chrome extension to control music playback. I already have a bash alias I can invoke to make the miniplayer stay on top of other windows, but I want to also have it send the miniplayer window to all desktops so I don't have to right-click and select Send to DesktopAll Desktops (via openbox).

Ideally, I would have a script run something in the background and as soon as it detects the miniplayer window it puts it on top and sends to all desktops. Is this possible?

2 Answers 2

9

You can actually do this without a third party script. Openbox supports an extensive range of per-application settings.

Creating an app-specific rule

Application rules are matched against different properties like the window name, class, role or title. Most of these properties can be obtained for a specific window by running

obxprop | grep "^_OB_APP"

and clicking on the window in question.

Seeing how you are planning to specify the rule for a Chrome extension window you might want to supply as many matching properties as possible so as to make the rule as specific as possible. You don't want it to apply to all Chrome windows. Try out different matching properties and see what works best for you.

Having defined the matching window you can set different properties that will exclusively apply to the window/application in question. Here's an excerpt of the default rc.xml which describes all available properties:

# each rule element can be left out or set to 'default' to specify to not 
# change that attribute of the window

<decor>yes</decor>
# enable or disable window decorations

<shade>no</shade>
# make the window shaded when it appears, or not

<position force="no">
  # the position is only used if both an x and y coordinate are provided
  # (and not set to 'default')
  # when force is "yes", then the window will be placed here even if it
  # says you want it placed elsewhere.  this is to override buggy
  # applications who refuse to behave
  <x>center</x>
  # a number like 50, or 'center' to center on screen. use a negative number
  # to start from the right (or bottom for <y>), ie -50 is 50 pixels from
  # the right edge (or bottom). use 'default' to specify using value
  # provided by the application, or chosen by openbox, instead.
  <y>200</y>
  <monitor>1</monitor>
  # specifies the monitor in a xinerama setup.
  # 1 is the first head, or 'mouse' for wherever the mouse is
</position>

<size>
  # the size to make the window.
  <width>20</width>
  # a number like 20, or 'default' to use the size given by the application.
  # you can use fractions such as 1/2 or percentages such as 75% in which
  # case the value is relative to the size of the monitor that the window
  # appears on.
  <height>30%</height>
</size>

<focus>yes</focus>
# if the window should try be given focus when it appears. if this is set
# to yes it doesn't guarantee the window will be given focus. some
# restrictions may apply, but Openbox will try to

<desktop>1</desktop>
# 1 is the first desktop, 'all' for all desktops

<layer>normal</layer>
# 'above', 'normal', or 'below'

<iconic>no</iconic>
# make the window iconified when it appears, or not

<skip_pager>no</skip_pager>
# asks to not be shown in pagers

<skip_taskbar>no</skip_taskbar>
# asks to not be shown in taskbars. window cycling actions will also
# skip past such windows

<fullscreen>yes</fullscreen>
# make the window in fullscreen mode when it appears

<maximized>true</maximized>
# 'Horizontal', 'Vertical' or boolean (yes/no)

In your specific case you will be interested in specifying the layer and desktop of the application. Here's an example of a rule that would designate all windows of a specific application to be always on top and omnipresent on all available desktops:

<application name="miniplayer" class="miniplayer" type="normal">
  <layer>above</layer>
  <desktop>all</desktop>
</application>

I chose an arbitrary application name and class for this example. As stated before you will have to make sure to find the correct values for your specific application.


Edit: I looked into your specific application and came up with a rule that works on my system:

<application name="crx_npngaakpdgeaajbnidkkginekmnaejbi" class="Google-chrome" type="normal" role="pop-up">
  <layer>above</layer>
  <desktop>all</desktop>
</application>

I hope this works for you as well.


Modifiying your openbox configuration to add an app specific rule

To add an application rule open your openbox rc.xml (found under ~/.config/openbox/rc.xml for stock openbox or ~/.config/openbox/lxde-rc.xml for LXDE) and navigate to the <applications> section at the very end of the file.

Insert your application specific rules between the <applications>..</applications> tags. Then save the file and proceed to reload the configuration by executing:

openbox --reconfigure

The application specific rules should be in effect after this and will automatically get applied to newly spawned windows.

4
  • @user216838 I think your comment got cut off there. I suspect it's not working for you? Don't worry, I installed the extensions and found a matching rule that works for me. I will edit my question with the updated rule. Please check if it's working for you. Commented Apr 9, 2014 at 17:12
  • Your instructions were very easy to follow, thanks. It doesn't seem to work, though. When I right-click on the window border and select send to desktop, all desktops has four little dots next to it indicating that it's selected. But, the window is still displayed only on desktop 1, and it's not above the other windows. Given the output of: obxprop | grep "^_OB_APP" I've added the following to my openbox config file: <application name="crx_npngaakpdgeaajbnidkkginekmnaejbi" class="Google-chrome" type="normal"> <layer>above</layer> <desktop>all</desktop> </application>
    – Sophie
    Commented Apr 9, 2014 at 17:18
  • @user216838 Looks almost identical to the rule I edited my answer with (which worked for me). Please try my version out and see if it works for you. (Don't forget to reconfigure openbox! That's what I always forget.) If everything works the window should be both on top and follow you around to all other desktops. Commented Apr 9, 2014 at 17:20
  • It works now, thanks. I didn't have the code in between the <application>...</application> tags.
    – Sophie
    Commented Apr 9, 2014 at 18:18
3

Found more general solution using Python 2.7 and library python-wnck.

If interested in details check this and this

If not just do this steps. Steps 1-2 should be already done in Ubuntu:

  1. install python2.7. sudo apt-get install python2.7

  2. install python-wnck. sudo apt-get install python-wnck

  3. create file stick_player.py. touch stick_player.py

  4. add python shebang.

echo '#!'which python > stick_player.py

  1. make it executable. chmod +x stick_player.py

  2. paste this script in stick_player.py. It should look like

#!/usr/bin/python

import wnck

screen = wnck.screen_get_default()
screen.force_update()

for win in screen.get_windows():
    if win.get_name() == 'Prime Player':
        win.stick()
  1. run your player in new window. In my case window name was "Prime Player". If it is not let me know.

  2. run script. ./stick_player.py


If you also want to undo "visible on all workspaces" do this. make steps 3-7 again, but.

  1. create file unstick_player.py. touch unstick_player.py

  2. add python shebang.

echo '#!'which python > unstick_player.py

  1. make it executable. chmod +x unstick_player.py

  2. change last line from win.stick() to win.unstick()

  3. run script. ./unstick_player.py


Also

You can find all your windows names using this script:

#!/usr/bin/python

import wnck

screen = wnck.screen_get_default()
screen.force_update()

for win in screen.get_windows():
    print win.get_name()

You must log in to answer this question.

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