Kubuntu 16.04下是否有命令可修改活动窗口透明度(支持脚本与快捷键)
Absolutely! Since Kubuntu 16.04 runs KDE Plasma 5 with KWin as its window manager, you have two solid command-line options to tweak active window transparency—ideal for scripting or binding to keyboard shortcuts.
Method 1: Use KWin's Native DBus Interface (Recommended)
KWin exposes a DBus API that lets you directly control the current active window's opacity. This is the most reliable method for KDE systems, as it integrates natively with the window manager.
To set the active window to 80% opacity (20% transparent), run this command:
qdbus org.kde.kwin /KWin setCurrentWindowOpacity 0.8
- Replace
0.8with any value between0(fully transparent) and1(fully opaque) to fine-tune the effect. - This command works instantly and uses tools pre-installed in Kubuntu 16.04, so no extra packages needed.
Method 2: Use X11's xprop Tool (Generic X11 Approach)
If you prefer a more X11-agnostic method that works across most window managers, xprop lets you modify the window's opacity property directly.
Here's a one-liner to set the active window to 80% opacity:
xprop -id $(xprop -root _NET_ACTIVE_WINDOW | awk '{print $5}') -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * 80 / 100)))
- Adjust the
80to your desired opacity percentage (e.g.,60for 60% opaque/40% transparent). - The value
0xffffffffrepresents full opacity; multiplying it by your percentage (divided by 100) converts it to the hexadecimal formatxproprequires.
Using These Commands in Scripts/Keyboard Shortcuts
- For Scripts: Save either command in a shell script (e.g.,
adjust_window_opacity.sh), make it executable withchmod +x adjust_window_opacity.sh, and run it whenever you need to adjust transparency. - For Keyboard Shortcuts:
- Open System Settings → Shortcuts → Custom Shortcuts.
- Click Edit → New → Global Shortcut → Command/URL.
- Name your shortcut (e.g., "Lower Active Window Opacity"), set a trigger like
Ctrl+Alt+Down, and paste the command in the Action field. - Repeat for another shortcut to reset full opacity (e.g.,
Ctrl+Alt+Upwithqdbus org.kde.kwin /KWin setCurrentWindowOpacity 1.0).
内容的提问来源于stack exchange,提问作者DK Bose

