我可以设置Hot Corners在Unity中运行自定义命令吗?

我真的很喜欢Hot Corners。 🙂

是否可以在热门角落运行自定义命令,如下所示?

在此处输入图像描述

CCSM

  1. 安装CompizConfig设置管理器(CCSM)。 在终端运行:

    sudo apt-get install compizconfig-settings-manager 
  2. 打开CCSM。

  3. 转到“命令”
  4. 在其中一个插槽中输入所需的命令。 例如:

    CCSM截图 - 命令

  5. 转到“边缘绑定”选项卡

  6. 单击“无”并设置所需的热角(或边缘),这与您刚刚设置的命令相对应

    CCSM截图 - 热门角落

  7. 将鼠标移动到角落

  8. 现在你的命令运行了!

    CCSM截图 - 命令运行

确认工作于14.04。

自定义命令

如果您使用Unity 安装了ccsm,wjandrea的答案当然是您的答案。 如果没有 ,或者在其他发行版上使用,轻量级替代品可能会有用。

使用下面的脚本,您可以设置任何特定于每个hotcorner的命令。

作为一个例子,我做了以下设置:

  • 左上角没有动作
  • 右上角Gedit
  • 左下角没有动作
  • 底部RightRun Gnome终端

当然,您也可以使命令运行外部脚本。

此外,您可以在行中设置热角的大小

 cornersize = 10 

只需更改值(像素)即可。 脚本设置(方形)区域以触发您的命令:

在此处输入图像描述

剧本

 #!/usr/bin/env python3 import subprocess import time cornersize = 20 commands = [ None, "gedit", None, "gnome-terminal", ] def get(cmd): return subprocess.check_output(cmd).decode("utf-8").strip() def get_pos(): return [int(s.split(":")[1]) for s in get(["xdotool", "getmouselocation"]).split()[:2]] scrdata = get("xrandr").split(); resindex = scrdata.index("connected")+2 res = [int(n) for n in scrdata[resindex].split("+")[0].split("x")] match1 = None while True: time.sleep(1) xy = get_pos() x = xy[0]; y = xy[1] test = [ [x < cornersize, y < cornersize], [x > res[0]-cornersize, y < cornersize], [x < cornersize, y > res[1]-cornersize], [x > res[0]-cornersize, y > res[1]-cornersize], ] match2 = [i for i, p in enumerate(test) if all(p)] if match2 != match1: if match2: cmd = commands[match2[0]] if cmd: subprocess.Popen(["/bin/bash", "-c", cmd]) match1 = match2 

建立

  1. 该脚本需要xdotool

     sudo apt install xdotool 
  2. 将脚本复制到空文件中,将i保存为hotcorners2.py
  3. 在脚本的头部,设置您的命令(注意引号)

     commands = [ None, "gedit", None, "gnome-terminal", ] 

    (随后左上/右上,左下/右)

  4. 测试运行脚本:

     python3 /path/to/hotcorners2.py 
  5. 如果一切正常,请添加到启动应用程序:Dash>启动应用程序>添加。 添加命令:

     /bin/bash -c "sleep 5 && python3 /path/to/hotcorners2.py" 

笔记

  • 该脚本当前在(第一个)屏幕上运行。 它可以很容易地编辑以处理多个屏幕,甚至在不同的屏幕上做不同的事情,请提及。
  • 如果有几个人喜欢它,我们可以添加一个gui和一个ppa,方便使用和安装。

编辑

如果我们使用更高级的计算,我们可以使用半径而不是方形区域来触发命令(感谢好的旧@pythagoras):

在此处输入图像描述

差异很小,但只是为了好玩:

剧本

 #!/usr/bin/env python3 import subprocess import math import time # set distance (hotcorner sensitivity) radius = 20 # top-left, top-right, bottom-left, bottom-right commands = [ None, "gedit", None, "gnome-terminal", ] def get(cmd): return subprocess.check_output(cmd).decode("utf-8").strip() def get_pos(): return [int(s.split(":")[1]) for s in get(["xdotool", "getmouselocation"]).split()[:2]] # get the resolution scrdata = get("xrandr").split(); resindex = scrdata.index("connected")+2 res = [int(n) for n in scrdata[resindex].split("+")[0].split("x")] # list the corners, could be more elegant no doubt corners = [[0, 0], [res[0], 0], [0, res[1]], [res[0], res[1]]] match1 = None while True: time.sleep(1) pos = get_pos() # get the current difference from the mousepointer to each of the corner (radius) diff = [int(math.sqrt(sum([(c[i]-pos[i])**2 for i, n in enumerate(res)])))\ for c in corners] # see if any of the corners is "approached" within the radius match2 = [diff.index(n) for n in diff if n < radius] # if so, and the corresponding command is not set to None, run it. if all([match2 != match1, match2]): cmd = commands[match2[0]] if cmd: subprocess.Popen(["/bin/bash", "-c", cmd]) match1 = match2 

用法

几乎是一样的。 在脚本的head部分设置命令和触发的半径。

注意:

对于使用默认Ubuntu或Ubuntu Kylin(或者有compiz作为他们的显示管理器)的人来说, wjandrea的答案是最合适的答案,因此它得到了我的支持和尊重。 下面提供的答案也可以在Unity上使用,但可能会略微多余。 但是,在没有compiz的桌面环境中,可以使用下面显示的指标。 我在Lubuntu 16.04 VM中对它进行了简单的测试,所以我知道它在那里工作,并使它与Kylin 14.04兼容。 对于GNOME和MATE桌面,您需要首先启用对AppIndicators的支持才能使用任何指标。

介绍

我已经实现了indicator-edger ,它允许根据鼠标位置在屏幕的4个边缘的任何位置触发用户定义的命令。 原始版本在一天内完成,大约需要7个小时,因此它相当简约,但可以完成工作。

在此处输入图像描述

该指标通过~/.edger-commands.json文件控制,显然是以json格式。 它可以由用户手动编写,也可以通过指示器的DEFINE COMMANDS选项设置。 记住启用/禁用触发选项并自动写入文件以方便用户。 示例配置文件如下:

 { "right": "gnome-terminal", "top": "firefox", "left": "", "bottom": "gnome-screenshot", "enabled": true } 

注意文件中的"left"条目。 该边缘未设置,但由于json语法,它需要在那里有一个空字符串,即引号""

一旦指示器检测到用户已将鼠标放在任何边缘(约3像素边距),指示器将发送气泡通知并运行相应的命令(如果已定义)。 除非用户将鼠标移离边缘,否则不会重复激活触发器。

在此处输入图像描述

从上面的屏幕截图中可以看出,该指标在命令行中也有调试输出。 如果您发现任何错误,请随时从终端运行它,找出发生的错误,并在项目的GitHub的问题页面上提交相应的错误报告。

目前不支持角落(仅边缘),它是为单显示器设置而构建的(显然,创建后7小时内无法覆盖所有基础),但这些function最终可能在将来可用。

安装和源代码

源代码可在项目GitHub页面或Launchpad中获得 。 通过终端中的以下命令执行安装:

 sudo add-apt-repository ppa:1047481448-2/sergkolo sudo apt-get update sudo apt-get install indicator-edger