设置为仅在启动器中显示当前工作空间的应用程序?

是否可以在启动器中打开当前工作空间的应用程序,而不是其他工作空间中的应用程序?

如何在(其他)工作空间中使应用程序无法实现

使用xdotoolwindowunmap ,可以完全隐藏窗口。 窗口及其应用程序在启动器图标中不再出现,甚至不再在wmctrl的输出中wmctrl

从理论上讲,这可以连接到“工作空间引擎”,这在本答案中使用。 那将是最优雅的解决方案。

但是, 在其他工作空间中隐藏窗口并自动提升当前工作空间上的窗口的过程要求在正在进行的后台脚本中使用(目前),并且不太可能“感冒”。 由于窗口在出现错误时会丢失,因此我决定不将该过程作为自动(后台)过程提供。

如果这个答案对你有用或取决于你的情况,以及为什么你想隐藏应用程序的图标,在其他工作区上运行的原因; 决定权在你。

解决方案; 它是什么以及它在实践中如何运作

  • 一个脚本,在快捷键下可用,似乎使当前工作区 (以及应用程序)上所有窗口完全消失。 这意味着Unity启动器中的应用程序图标不显示应用程序的活动:

    三个运行应用: 在此处输入图像描述 按下快捷键后: 在此处输入图像描述

  • 再次按下schortcut键组合,窗口及其应用程序将重新出现。

  • 由于组合键只会隐藏当前工作区中的窗口和应用程序,因此您可以随后切换到另一个工作区,而不会显示当前工作区中的(隐藏)内容。
  • 同时取消隐藏(仅)在当前工作空间中完成,因此简而言之,隐藏和取消隐藏的过程在每个工作空间中完全独立。

剧本

 #!/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]]) 

如何使用

  1. 该脚本需要wmctrlxdotool

     sudo apt-get install wmctrl xdotool 
  2. 将脚本复制到空文件中,将其另存为toggle_visibility.py
  3. 测试运行脚本:在终端窗口中,运行命令:

     python3 /path/to/toggle_visibility.py 

    现在打开一个新的终端窗口(因为第一个看起来从地球表面消失了)并再次运行相同的命令。 所有窗口都应该重新出现。

    注意 :确保在测试时没有打开“有价值”的窗口

  4. 如果一切正常,请将命令添加到快捷键组合中:选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。 单击“+”并添加命令:

     python3 /path/to/toggle_visibility.py 

说明

如上所述,该脚本使用xdotoolwindowunmap来(完全)隐藏窗口及其所属的应用程序。 剧本:

  • 读取当前工作空间的内容
  • 读取当前工作空间中存在的窗口(仅限)
  • 将窗口列表写入以当前工作空间命名的文件
  • 隐藏窗户

在下一次运行时,脚本:

  • 检查是否存在与当前工作空间对应的文件
  • 如果是这样,请读取窗口列表并取消隐藏窗口。

从而切换当前工作空间上的窗口和应用程序的可见性。

好吧,其他答案都很老了,所以我觉得值得加入最新的答案。 现在可以这样做而不是太难(使用Ubuntu 17.10并且它有Gnome)。

只需使用dconf-editor

 sudo apt install dconf-editor 

导航到org> gnome> shell> extensions> dash-to-dock并检查isolate-workspaces 在此处输入图像描述

不幸的是,这是不可能的。

Unity始终显示来自任何地方的所有应用程序,并且无法更改此设置。 有一个错误报告 – https://bugs.launchpad.net/ayatana-design/+bug/683170但似乎开发人员不会做任何事情。 可能如果您在页面顶部标记此错误会影响您,则可以帮助开发人员了解此类选项的重要性。