Programmatically hide/show a window in Linux

孤人 提交于 2020-06-13 06:24:06

问题


I've been searching all over the place for a solution to this.

How can I show/hide (or minimize/unminimize if you rather) Linux windows.

I'm interested in any solution in any language.

I use Debian, Gnome, Metacity and Compton composite manager if they're relevant

Note: I tried using wmctrl but the toggle,hidden feature of wmctrl has been broken for a while and it's not been updated in two years so unlikely to work any time soon. The net is full of bug reports concerning this.


回答1:


You can use xdotool:

$ xdotool search --name "Stack Overflo"
24415619
$ xdotool windowminimize 24415619

Basically, you first find a window (by title, by active state etc.), which gives you its ID. Then you invoke commands. There are many ways to find a window, see the manpage.

xdotool is available as a package in at lease Debian, Ubuntu and Fedora.

Note: Shamelessly stolen from this answer: https://superuser.com/questions/186748/how-to-hide-or-minimize-x11-window-from-console




回答2:


Maybe you can try something like this. It uses xdotool like @sleske suggested. I bind the script to a mouse button using xbinkeys.

#!/bin/bash

file=/tmp/last_active_window
if [[ -s $file ]] ; then
    xdotool windowmap `cat $file`
    cat /dev/null > $file
else 
    wid=`xdotool getactivewindow`      
    xdotool windowunmap $wid
    echo $wid > $file
fi


来源:https://stackoverflow.com/questions/26704195/programmatically-hide-show-a-window-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!