首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有基于文本的窗口切换器吗?

有基于文本的窗口切换器吗?
EN

Ask Ubuntu用户
提问于 2015-07-13 20:03:49
回答 2查看 597关注 0票数 4

视觉开关在提供上下文方面非常差。例如,浏览器窗口缩略图太小,无法区分,而且通常是空白的(见屏幕截图)。

是否有显示窗口标题列表的开关?最好具有智能模糊自动完成(如https://github.com/ctrlpvim/ctrlp.vimhttps://github.com/junegunn/fzf ) :-)

EN

回答 2

Ask Ubuntu用户

回答已采纳

发布于 2015-07-15 18:14:36

“国产产品”的有趣之处在于,你可以完全按照自己的喜好来制作它。可能的缺点是,你很容易被一个项目搞得太过火了,如果你在这个项目上工作的话…

下面的脚本可能是这样的。虽然我更希望添加一个详细的解释,它是如何“在引擎盖下”,这是一个“准备使用”的解决方案。虽然我添加了一些评论行,但很难对代码给出一个简单的内部解释。然而,它似乎接近你正在寻找的东西。

它是什么

该脚本是一种纯粹基于文本的解决方案,可以列出所有打开的、“正常”的应用程序窗口(并引发所选的窗口),但它有许多选项:

  1. 列出按窗口名称排序的窗口:运行命令: python3 -win</div></li></ol><img src="https://i.stack.imgur.com/B7vg7.png" /><div>键入所需窗口的第一个字符(S),然后按“返回”键将窗口带到前面。</div><ol><li><div>列出按应用程序排序的窗口:运行命令: python3 <script> -app</div></li></ol><img src="https://i.stack.imgur.com/hW2m5.png" /><ol><li><div>列出窗口,按工作区排序:使用以下命令运行: python3 <script> -ws</div></li></ol><img src="https://i.stack.imgur.com/vHCef.png" /><div>如您所见,显示的列是:窗口名称、应用程序、工作区。预先设置的排序列总是第一个.</div><h2>模糊?</h2><div>若要从列表中选择项,只需键入第一个字符即可。如果有更多符合类型化字符(S)的项,箭头键将只浏览满足类型化字符的项目:</div><img src="https://i.stack.imgur.com/LlI1J.png" /><h2>Furthermore:</h2><div>工作区指示</div><div class="q"></div><div>当前工作区被标记为<code>*</code>:例如,如果您看到<code>2*</code>,它意味着窗口位于工作区<code>2</code>上,工作区<code>2</code>是当前工作区。不管您有多少工作空间,这都是可行的。</div><div>窗口大小</div><div class="q"></div><div>选择窗口自动设置为窗口的(最长)名称和要显示的窗口数,例如:</div><img src="https://i.stack.imgur.com/pxaBN.png" /><div>或者:</div><img src="https://i.stack.imgur.com/Sw4Uw.png" /><h2>如何使用</h2><div>设置非常简单:</div><ol><li><div>脚本(绝对)需要<code>wmctrl</code>:sudo apt安装wmctrl</div></li><li><div>然后将下面的脚本复制到一个空文件中,保存为<code>list_windows.py</code></div></li><li><div>然后使用以下命令运行它: python3 /path/to/list_windows.py -app python3 /path/to/list_windows.py -win python3 /path/to/list_windows.py -ws</div></li><li><div>如果所有操作正常,则向一个或多个快捷键添加一个或多个首选命令:选择: Settings > "Keyboard“>”快捷方式“>”自定义快捷方式“。单击"+“并添加命令</div></li></ol><h2>脚本</h2><div>(仍然是“未修饰的”代码)</div><pre><code>#!/usr/bin/env python3 import subprocess import socket import sys arg = sys.argv[1] # list (column) header titles and their (data) position in the produced window data list cols = [["Workspace", -1], ["Application name", -2] , ["Window name", -3]] # rearrange columns, depending on the chosen option if arg == "-app": cols = [cols[1], cols[2], cols[0]] elif arg == "-ws": cols = [cols[0], cols[2], cols[1]] elif arg == "-win": cols = [cols[2], cols[1], cols[0]] # extract headers, list positions, to be used in the zenity list col1 = cols[0][0]; i1 = cols[0][1] col2 = cols[1][0]; i2 = cols[1][1] col3 = cols[2][0]; i3 = cols[2][1] # just a helper function get = lambda cmd: subprocess.check_output([ "/bin/bash", "-c", cmd ]).decode("utf-8") # analyse viewport data, to be able to calculate relative/absolute position of windows # and current viewport def get_spandata(): xr = get("xrandr").split(); pos = xr.index("current") res = [int(xr[pos+1]), int(xr[pos+3].replace(",", "") )] spandata = get("wmctrl -d").split() span = [int(n) for n in spandata[3].split("x")] cols = int(span[0]/res[0]); rows = int(span[1]/res[1]) curr_vector = [int(n) for n in spandata[5].split(",")] curr_viewport = int((curr_vector[1]/res[1])*cols + (curr_vector[0]/res[0])+1) return {"resolution": res, "n_columns": cols, "vector": curr_vector, "current_viewport": curr_viewport} posdata = get_spandata() vector = posdata["vector"]; cols = posdata["n_columns"] res = posdata["resolution"]; currvp = posdata["current_viewport"] # function to distinguish "normal" windows from other types (like the desktop etc) def check_window(w_id): w_type = get("xprop -id "+w_id) if " _NET_WM_WINDOW_TYPE_NORMAL" in w_type: return True else: return False # split windowdata by machine name mach_name = socket.gethostname() wlist = [[l.strip() for l in w.split(mach_name)] for w in get("wmctrl -lpG").splitlines()] # split first section of window data for i, w in enumerate(wlist): wlist[i][0] = wlist[i][0].split() # filter only "real" windows real_wlist = [w for w in wlist if check_window(w[0][0]) == True] # adding the viewport to the window's data for w in real_wlist: w.append(get("ps -p "+w[0][2]+" -o comm=").strip()) loc_rel = [int(n) for n in w[0][3:5]] loc_abs = [loc_rel[0]+vector[0], loc_rel[1]+vector[1]] abs_viewport = int((loc_abs[1]/res[1])*cols + (loc_abs[0]/res[0])+1) abs_viewport = str(abs_viewport)+"*" if abs_viewport == currvp else str(abs_viewport) w.append(abs_viewport) # set sorting rules if arg == "-app": real_wlist.sort(key=lambda x: x[-2]) elif arg == "-ws": real_wlist.sort(key=lambda x: x[-1]) elif arg == "-win": real_wlist.sort(key=lambda x: x[-3]) # calculate width and height of the zenity window: # height = 140px + 23px per line h = str(140+(len(real_wlist)*23)) # width = 250px + 8px per character (of the longest window title) w = str(250+(max([len(w[-3]) for w in real_wlist])*8)) # define the zenity window's content cmd = "zenity --list --hide-column=4 --print-column=4 --title='Window list' "\ "--width="+w+" --height="+h+" --column='"+col1+"' --column='"+col2+"' --column='"+col3+\ "' --column='w_id' "+(" ").join([(" ").join([ '"'+w[i1]+'"','"'+w[i2]+'"','"'+w[i3]+'"','"'+w[0][0]+'"' ]) for w in real_wlist]) # finally, call the window list try: w_id = subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8").split("|")[0] subprocess.Popen(["wmctrl", "-ia", w_id]) except subprocess.CalledProcessError: pass</code></pre>
票数 4
EN

Ask Ubuntu用户

发布于 2015-07-13 21:58:15

暂定答复:

  • 我刚发现http://www.webupd8.org/2013/07/fuzzy-window-switcher-for-ubuntu.html链接到https://github.com/XCMer/fuzzy-window-switcher ..。这看起来很有希望。
  • webupd8的评论还指出,Compiz插件具有类似的功能。开始输入并缩小窗口缩略图以匹配搜索。扩展插件还允许显示所有窗口的窗口标题。但是,标题在缩略图宽度处被截断(对于像编辑器和shell这样的长标题的窗口是不好的),搜索也不是模糊的。
  • PyPI的另一家公司:http://pypi.python.org/pypi/windownow/
票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/648010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档