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 2014-02-26 20:05:51 +0000

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.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2014-03-27 14:54:32 +0000

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();
edit flag offensive delete link more
-1

answered 2014-02-26 20:13:27 +0000

uzsolt gravatar image

updated 2014-02-26 21:34:45 +0000

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
edit flag offensive delete link more

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 ( 2014-02-26 20:27:52 +0000 )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 ( 2014-02-26 20:54:02 +0000 )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 ( 2014-02-26 20:59:14 +0000 )edit

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

uzsolt gravatar imageuzsolt ( 2014-02-26 21:03:13 +0000 )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 ( 2014-02-26 21:10:14 +0000 )edit

Question Tools

Stats

Asked: 2014-02-26 20:05:51 +0000

Seen: 582 times

Last updated: Mar 27 '14