The i3 FAQ has migrated to https://github.com/i3/i3/discussions. All content here is read-only.
Ask Your Question
1

Switch to workspace where a link was opened in Firefox

asked Feb 26 '14

blueyed gravatar image

When I open a link from workspace 1 (terminal, email, etc), it gets opened in the Firefox instance running on workspace 2.

I would like to automatically switch to / focus the Firefox window.

2 answers

Sort by » oldest newest most voted
3

answered Mar 27 '14

TonyC gravatar image

This is not possible with i3 in the current version, but in the next version we can listen to title change events with the new i3ipc library to determine when the tab is opened and then focus the window. This script uses the JavaScript version of the library. You can find the latest version of this script here.

#!/usr/bin/env gjs

/*
   This example shows how to make i3wm automatically switch to a browser that
   has opened a new tab by using the new ipc "title change" event. This event
   will be available in the next released version (after 4.7.2).

   If you have a webpage open that changes the title without any user
   interaction (rare, but possible), you may need to do some additional
   filtering so it does not switch focus unexpectedly.

   https://faq.i3wm.org/question/3434/switch-to-workspace-where-a-link-was-opened-in-firefox/
*/

const i3ipc = imports.gi.i3ipc;

let conn = new i3ipc.Connection;

let browser_re = /- Vimperator$|- Firefox$|- Chromium$/

conn.on('window::title', function(conn, e) {
    if (browser_re.test(e.container.name)) {
        e.container.command('focus');
    }
});

conn.main();
-1

answered Feb 26 '14

uzsolt gravatar image

updated Feb 26 '14

Try create a script (e.g. ~/bin/mybrowser) which changes the workspaces too. And set browser of your programs to ~/bin/mybrowser:

#!/usr/bin/env bash
firefox $*
i3-msg workspace "web"
# blueyed's comment:
# i3-msg [class="Firefox"] focus

Comments

This assumes that the browser is running in a particular workspace always. But I might have multiple instances across different workspaces.

blueyed gravatar imageblueyed (Feb 26 '14)edit

And how do you control which instance will open your URL? I think it's impossible: https://support.mozilla.org/hu/questions/975778

uzsolt gravatar imageuzsolt (Feb 26 '14)edit

That's part of the problem.. :) Apart from that it affects other applications as well. When it is on the same workspace, the focus changes. It would be nice, if this would get done across workspaces, too - preferably with a setting ("focus stealing prevention").

blueyed gravatar imageblueyed (Feb 26 '14)edit

Oh, understand. Do you know about wmctrl? Maybe you can use it. http://www.freedesktop.org/wiki/Software/wmctrl/

uzsolt gravatar imageuzsolt (Feb 26 '14)edit

wmctrl does not appear to work with i3 - I have used it in scripts before (e.g. `wmctrl -a foo` to select a window). For the problem at hand, I could also use `i3-msg '[class=Firefox] focus'` in the custom script, but I would rather have this fixed globally.

blueyed gravatar imageblueyed (Feb 26 '14)edit

Question Tools

Stats

Asked: Feb 26 '14

Seen: 582 times

Last updated: Mar 27 '14