当前位置: 首页>>技术教程>>正文


xorg – 如何触发一个窗口的颜色反转效果?

,

问题描述

我想要像 compiz 中的 ‘negative’ 一样的反色效果(从亮到暗),但没有 compiz,并且仅适用于一个窗口(如 compiz 的 Super + N )。

有没有办法在不使用 compiz 的情况下获得类似的效果(最好通过组合键切换)?我可以使用 xcalib -I -a 反转整个桌面的颜色,但不能将其限制为单个窗口。

最佳方法

据我所知……要实现这一目标,您将需要 Window Compositor 的帮助。\n您可以尝试安装像 Compton 这样的轻量级独立合成器。

Compton

\\n

Compton is a lightweight compositor for X, and a fork of\\n xcompmgr-dana.

\\n

根据 Man Pages,康普顿有一个反转窗口颜色的选项。

例如:

compton --invert-color-include <CONDITION>

条件可以是窗口的WM_CLASS,要在窗口中查找”WM_CLASS”,可以运行命令xprop

  • xprop | grep WM_CLASS

然后光标将成为”Cross”,您可以在所需的窗口中单击,找到WM_CLASS。

现在你应该有这样的东西:

\\n

WM_CLASS(STRING) = “leafpad”, “Leafpad”

\\n

第二个字符串应该是 WM_CLASS “Leafpad”。\n因此,要反转 Leafpad 编辑器的颜色,您应该运行:

  • compton --invert-color-include 'class_g="Leafpad"'

在某些情况下,您可能只想反转程序的某些窗口(例如反转编辑器窗口,但不反转 “save file” 对话框)。\n为此,您可以使用两个 WM_CLASS 字符串中的第一个(也称为 “instance”):

  • compton --invert-color-include '(class_g="Leafpad" && class_i="leafpad")'

您不需要一直运行 compton,您可以在需要反转窗口颜色时运行它。


注意:在此示例中,我运行 Lubuntu 13.04,并使用 openbox 作为窗口管理器,但默认情况下没有合成器。


安装康普顿

该合成器有自己的PPA

1) 要安装 compton,请打开终端并输入:

  • sudo add-apt-repository ppa:richardgv/compton

  • sudo apt-get update && sudo apt-get install compton

在此示例中,我将创建一个基本的 Bash 脚本(我不是脚本专家)来检测活动窗口并反转其颜色。

2) 创建脚本。

  • sudo apt-get install xdotool

  • mkdir ~/Scripts

  • nano ~/Scripts/invert.sh

脚本内容:

#! /bin/bash

if [ "$(pidof compton)" ];
    then
            pkill compton
    else

        ID=$(xdotool getactivewindow)
        CLASS=$(xprop -id "$ID"  | grep "WM_CLASS" | awk '{print $4}')
        COND="class_g=${CLASS}"
        compton --invert-color-include "$COND" &
fi
exit

\\n

Basically the script will check if compton is running, if it not\\n running xdotool will find the window id of the active window, with the id xprop will find\\n the WM_CLASS, then with the WM_CLASS it will create the condition and\\n finally will run compton with the condition as argument.

\\n

使脚本可执行。

  • chmod +x ~/Scripts/invert.sh

就我而言,我将创建一个到 /usr/bin/目录的软链接,名称为 “invert-color”

  • sudo ln -s ~/Scripts/invert.sh /usr/bin/invert-color

3)创建一个键盘快捷键,例如: Ctrl + Alt + U(在Lubuntu中你应该编辑lubuntu-rc.xml文件)

  • leafpad ~/.config/openbox/lubuntu-rc.xml

添加以下行:

\\n

<!-- Launch invert-color activewindow on Ctrl + Alt + U-->\\n<keybind key="C-A-U">\\n  <action>\\n    <command>invert-color</command>\\n  </action>\\n</keybind>\\n

\\n

最后您可以注销并登录来查看键盘快捷键的变化。


我的意图是,当我需要反转活动窗口中的颜色时,我可以使用快捷键 Ctrl + Alt + U 来完成。如果我想返回正常颜色,我将再次按快捷键,脚本将检测到 compton正在运行,因此 pkill 命令将终止进程 compton。\n因此,我只会在需要时运行合成器。

这里有一些屏幕截图:

希望能帮助到你。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/14319.html,未经允许,请勿转载。