4

I use SpaceFM as my primary file manager on Ubuntu. I typically open folder directly by keyboard shortcuts, so, e.g. Ctrl+Super+W opens my Work folder.

Specifically, I use execute the command spacefm -w /home/rasmus/Work/ by the above shortcut, with the -w ensuring that SpaceFM opens a new window.

However, this new window is not always open on top of the last active window on the workspace. This is rather annoying, as it means I sometimes have to "dig" for the newly opened window.

So, my question is: Is there something additional I can add to the executed command that will ensure that the fresh window is opened on top?

Alternative solutions to the same effect are welcome.

1

As spacefm used single process. New command just pass signal to the running process and this creates the new window at level just above its last created window.

sudo apt-get install wmctrl
  • With function: It has 1sec delay.

    sfm() { spacefm $* & pid=`pgrep spacefm | head -1`; sleep 1;  wmctrl -i -R `wmctrl -lp | grep " $pid" | tail -1 | awk '{ print $1 }'` }
    
    1. Run spacefm with same arguments $* were passed to the function, & in background
    2. pgrep spacefm | head -1 get PID of main process which is in the head then store it in pid variable
    3. sleep 1 wait for new process to terminal, to avoid raise of two windows (I don't know why, try removing it)
    4. wmctrl -lp get window list | grep " $pid" filter related ones to $pid, | tail -1 filter last line/window then | awk '{ print $1 }' filter out window id (WID) which is in the first column $1
    5. wmctrl -i -R WID Move the window WID to the current desktop, raise the window, and give it focus.
  • With alias: This will raise 2 windows the new one on the top but simpler.

    alias sfm="wmctrl -i -R \`wmctrl -lp | grep ' $(pgrep spacefm)' | tail -1 | awk '{ print $1 }'\`; spacefm"
    
    1. wmctrl -lp get window list | grep " $pid" filter related ones to spacefm, | tail -1 filter last line/window then | awk '{ print $1 }' filter out window id (WID) which is in the first column $1
    2. wmctrl -i -R WID Move the window WID to the current desktop, raise the window, and give it focus.
    3. Run spacefm with arguments coming after. The new window will be created on the top.

- How to use: similar way to the original command.

    sfm -w /home/rasmus/Work/

References: Please look for the man pages.

0

It's an old question but still relevant, so I'll add an alternative solution.

This sounds like a result of Compiz' focus prevention, trying to prevent windows from "stealing" focus while you're working somewhere else.

Focus prevention can be set to different levels (default: low) or completely disabled through CompizConfig Settings Manager.

If not installed yet, do this by running:

sudo apt-get install compizconfig-settings-manager

Then, run it with ccsm, navigate to General Options, switch to the tab Focus & Raise Behaviour and change the field Focus Prevention Level (in your case, you'll probably want Off).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.