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

Open application and fix workspace

asked Nov 5 '13

jr gravatar image

If i launch an application lets say on workspace1 and switch to another workspace before the application has started, the application launches on the new workspace. Instead i would like the app. to stay at workspace1 Is it somehow possible to fix this?

3 answers

Sort by » oldest newest most voted
2

answered Nov 5 '13

Adaephon gravatar image

updated Nov 5 '13

This already works, if you use

i3-msg exec application

to start your application it will appear on the workspace on which you called it. See here


For example, if you are using dmenu_run to start your application you can use this instead:

#!/bin/sh
exe=`dmenu_path | dmenu ${1+"$@"}` && i3-msg "exec $exe"

Comments

does the behaviour of i3-msg exec application depends on the i3 version? the script runs but the behaviour is the same as the default setting edit: i compiled i3 from source and it works now but not with each programm. Is there a variable which contains the current worksp. so i can set it explict?

jr gravatar imagejr (Nov 5 '13)edit

The User's guide and Flugsio mentioned that some apps that do not support this feature. You can retrieve the current workspace with `i3-msg -t get_workspaces`. This returns a list of all workspaces in JSON format. The current one has its "focused" flag set to true.

Adaephon gravatar imageAdaephon (Nov 5 '13)edit
0

answered Nov 5 '13

Flugsio gravatar image

updated Nov 5 '13

Not at the moment, (edit) unless the application is startup-notification aware; see Adaephon's answer. http://build.i3wm.org/docs/hacking-ho...usingcgroupsperworkspace

Although, you can pre-assign certain applications to workspaces http://i3wm.org/docs/userguide.html#automaticallyputtingclientsonspecificworkspaces

Comments

1

The part of the document you linked seems to be rather old (at least 2012 going by the ©) and the main focus is on cgroups not workspace awareness. I guess it did not get updated when the feature in question was introduced.

Adaephon gravatar imageAdaephon (Nov 5 '13)edit

I had completely missed that feature. But there are some exception as the document says. chromium won't work with cgroups but might be fixable with startup-notification awareness. urxvt could be solved with either. Using exec for those doesn't work for me at the moment. i3 version 4.6 2013-08-07

Flugsio gravatar imageFlugsio (Nov 5 '13)edit
0

answered Feb 7 '14

I wrote a python script to implement this. So here is my config:

bindsym $mod+d exec /path/to/script.py

And my script contains the following, apologies for the verbosity:

#!/usr/bin/python3
import subprocess
import json
from os.path import expanduser

def get_workspace():
  test = subprocess.Popen(["i3-msg","-t","get_workspaces"], stdout=subprocess.PIPE)
  output = test.communicate()[0]
  data = json.loads(output.decode())
  data = sorted(data, key=lambda k: k['name']) 
  for i in data:
    if(i['focused']):
      return i['name']

home = expanduser("~")
applications = open(home+"/.cache/dmenu_run")
dmenu_run = subprocess.Popen(["dmenu","-b"], stdout=subprocess.PIPE, stdin=applications)
output = (dmenu_run.communicate()[0]).decode().strip()
subprocess.Popen(["i3-msg","workspace "+get_workspace()+"; exec " + output], stdout=subprocess.PIPE)

The script simply:

  1. Pipes the current dmenurun cache (located at ~/.cache/dmenurun) of applications to dmenu
  2. Gets the result from dmenu and calls i3msg 'workspace <current>; exec <dmenu_result>' where current is the current workspace and dmenu_result is what you enter into the dmenu prompt

Question Tools

Stats

Asked: Nov 5 '13

Seen: 891 times

Last updated: Feb 07 '14