Setting to only show applications of current workspace in launcher?

Solution 1:

For Ubuntu Dock shipped with Ubuntu 17.10 and later (with GNOME)

Well, Other answers are pretty old, so I think it is worth to add up-to-date answer. It is possible to do so right now and not too hard tbh (With Ubuntu 17.10 and it having Gnome).

Just use dconf-editor:

sudo apt install dconf-editor

Navigate to org > gnome > shell > extensions > dash-to-dock and check isolate-workspaces enter image description here

Solution 2:

How to make applications untraceable on (other) workspaces

Using xdotool's windowunmap, it is possible to hide a window completely. The window, nor its application, occurs any more in the launcher icon, and is not even listed any more in the output of wmctrl.

Theoretically, this could be connected to the "workspace-engine", that was used in this and this answer. That would have been the most elegant solution.

However, the process of only hiding windows on other workspaces and to automatically raise the ones on the current workspace is too demanding to use in an ongoing background script (for now), and not unlikely "to catch a cold" as well. Since windows are lost for good in case of errors, I therefore decided not to offer the procedure as an automatic (background-) process.

If this answer is nevertheless useful for you or not depends on the situation, and the reason why you'd like to hide icons of applications, running on other workspaces; the decision is yours.

The solution; what it is and how it works in practice

  • A script, available under a shortcut key, seemingly making all windows on the current workspace (and thus applications) disappear completely. That means the application's icon in the Unity launcher shows no activity of the application:

    Three running applications: enter image description here After pressing the shortcut key: enter image description here

  • Pressing the schortcut key combination again, the windows and their applications will re-appear.

  • Since the key combination will only hide the windows and applications from the current workspace, you can subsequently switch to another workspace without a sign of what is (hidden) on the current workspace.
  • Also unhiding is done (only) on the current workspace, so in short, the process of hiding and unhiding is doen completely independent per workspace.

The script

#!/usr/bin/env python3
import subprocess    
import os
import time

datadir = os.environ["HOME"]+"/.config/maptoggle"
if not os.path.exists(datadir):
    os.makedirs(datadir)
workspace_data = datadir+"/wspacedata_"

def get_wlist(res):
    res = get_res()
    try:
        wlist = [l.split() for l in subprocess.check_output(["wmctrl", "-lG"]).decode("utf-8").splitlines()]
        return [w for w in wlist if all([
            0 < int(w[2]) < res[0],
            0 < int(w[3]) < res[1],
            "_NET_WM_WINDOW_TYPE_NORMAL" in subprocess.check_output(["xprop", "-id", w[0]]).decode("utf-8"),
            ])]
    except subprocess.CalledProcessError:
        pass

def get_res():
    # get resolution
    xr = subprocess.check_output(["xrandr"]).decode("utf-8").split()
    pos = xr.index("current")
    return [int(xr[pos+1]), int(xr[pos+3].replace(",", "") )]

def current(res):
    # get the current viewport
    vp_data = subprocess.check_output(
        ["wmctrl", "-d"]
        ).decode("utf-8").split()
    dt = [int(n) for n in vp_data[3].split("x")]
    cols = int(dt[0]/res[0])
    curr_vpdata = [int(n) for n in vp_data[5].split(",")]
    curr_col = int(curr_vpdata[0]/res[0])+1
    curr_row = int(curr_vpdata[1]/res[1])
    return str(curr_col+curr_row*cols)

res = get_res()

try:
    f = workspace_data+current(res)
    wlist = eval(open(f).read().strip())
    for w in wlist:
        subprocess.Popen(["xdotool", "windowmap", w[0]])
    os.remove(f)
except FileNotFoundError:
    current_windows = get_wlist(res)
    open(f, "wt").write(str(current_windows))
    for w in current_windows:
        subprocess.Popen(["xdotool", "windowunmap", w[0]])

How to use

  1. The script needs both wmctrl and xdotool:

    sudo apt-get install wmctrl xdotool
    
  2. Copy the script into an empty file, save it as toggle_visibility.py
  3. Test- run the script: in a terminal window, run the command:

    python3 /path/to/toggle_visibility.py
    

    Now open a new terminal window (since the first one seemingly disappeared from the face of the earth) and run the same command again. All windows should re-appear.

    NB: make sure you do not have "valuable" windows open while testing

  4. If all works fine, add the command to a shortcut key combination: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/toggle_visibility.py
    

Explanation

As said, the script uses xdotool's windowunmap, to (completely) hide windows and the applications they belong to. The script:

  • reads what is the current workspace
  • reads the windows, which exist on the current workspace (only)
  • writes the window list to a file, named after the current workspace
  • hides the windows

On the next run, the script:

  • checks if the file, corresponding to the current workspace exists
  • if so, reads the window list and un- hides the windows.

thus toggling visibility of windows and applications on the current workspace.

Solution 3:

Unfortunately it's impossible.

Unity always shows all applications from everywhere and there are no way to change this. There is a bug report - https://bugs.launchpad.net/ayatana-design/+bug/683170 But seems developers aren't going to do anything. Probably if you mark at the top of the page that this bug affects you it will help developers to understand importance of such option.