Ubuntu – How to show Unity launcher in only one workspace

launcherunityviewportsworkspaces

I want to keep launcher active only in main workspace. E.g. I like to keep Citrix window in full display mode without launcher (in workspace II).

Best Answer

Like many things, it does not exist as far as I know, BUT, it can be done with a little creativity and the right tools.

enter image description here

How it can be done

Assuming you are on 14.04 (with python3), you can use a script to run in the background, that keeps track of your current viewport and sets the launcher to autohide or not, depending on that current viewport.

  • What you need to do first is install wmctrl:

    sudo apt-get install wmctrl
    

    We need wmctrl to get information about the total size of all viewports and to be able to read information about the current section we are in.

  • Once that is done, copy the script below into an empty file and safe it as autohide_launcher.py (keep the name like that) and make it executable(!).

    In the line hide_launcher, decide for wich viewports you want to autohide the launcher (set "True"), and use the correct number of entries, corresponding with your number of viewports. The list reads per viewport row, from left to right.

#!/usr/bin/env python3

import subprocess
import time

# set the hide-launcher values for your viewports; in rows/columns
hide_launcher = (False, True, True, True)

# don't change anything below (or it must be the time.sleep(2) interval)
key = " org.compiz.unityshell:/org/compiz/profiles/unity/plugins/unityshell/ "
pr_get = "gsettings get "; pr_set = "gsettings set "
check = pr_get+key+"launcher-hide-mode"
hide = pr_set+key+"launcher-hide-mode 1"
show = pr_set+key+"launcher-hide-mode 0"

def get_value(command):
    return subprocess.check_output(
        ["/bin/bash", "-c", command]).decode('utf-8').strip()

# get screen resolution
output = get_value("xrandr").split(); idf = output.index("current")
screen_res = (int(output[idf+1]), int(output[idf+3].replace(",", "")))

while True:
    # get total span size all viewports, position data
    wsp_info = get_value("wmctrl -d").strip()
    scr_data = [item.split("x") for item in wsp_info.split(" ") if "x" in item][0]
    # get current position (viewport coordinates)
    VP = eval(wsp_info[wsp_info.find("VP: "):].split(" ")[1])
    # calculated viewports rows / columns
    VP_hor = int(scr_data[0])/int(screen_res[0])
    VP_vert = int(scr_data[1])/int(screen_res[1])
    # calculated viewport positions
    range_hor = [i*screen_res[0] for i in range(int(VP_hor))]
    range_vert = [i*screen_res[1] for i in range(int(VP_vert))]
    viewports = [(h, range_vert[i])for i in range(len(range_vert)) for h in range_hor]
    current_viewport = viewports.index(VP); a_hide = get_value(check)
    if (hide_launcher[current_viewport], a_hide == "0") == (True, True):
        subprocess.Popen(["/bin/bash", "-c", hide])
    elif (hide_launcher[current_viewport], a_hide == "0") == (False, False):
        subprocess.Popen(["/bin/bash", "-c", show])
    else:
        pass
    time.sleep(1)
  • You can start the script by the command:

    /path/to/autohide_launcher.py
    

Toggle autohide-per-viewport on/of

However, it is more convenient to use the script below to have one command to toggle the script on/of.

Copy the script below into an empty file and save it as start_stop.py, in one and the same folder as the autohide_launcher.py script. Make it executable as well(!). Now you can toggle the autohide function with the command

/path/to/start_stop.py

The start/stop script:

#!/usr/bin/env python3

import os
import subprocess

script_dir = os.path.dirname(os.path.abspath(__file__))
cmd = "ps -ef | grep autohide_launcher.py"
run = subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8").split("\n")
match = [line for line in run if script_dir+"/"+"autohide_launcher.py" in line]

if len(match) != 0:
    subprocess.Popen(["kill", match[0].split()[1]])
    subprocess.Popen(["notify-send", "autohide per viewport stopped..."])
else:
    subprocess.Popen(["/bin/bash", "-c", script_dir+"/"+"autohide_launcher.py"])
    subprocess.Popen(["notify-send", "autohide per viewport started..."])

enter image description here

Alternative ways to start or stop the script

There are several other ways to toggle the script in a convenient way:

Add the script to your startup apoplications

If you permanently want to run the script in the background:

  • Open Startup Applications and choose "Add".
  • Add the command:

    /path/to/autohide_launcher.py
    
  • Give it a name to your liking

Set a keyboard shortcut to toggle the script

  • Open System Settings and choose: "Keyboard" > "Shortcuts" > "Custom Shortcuts".
  • Create a new shortcut of your choice, with the command:

    /path/to/start_stop.py
    

    Now you can toggle autohide-per-viewport with the key combination.


posted on gist.gisthub