我只想设置Emacs来切换(隐藏/显示)可见性,就像我们在guake、tilda或yakuake终端中看到的那样(在这些终端中称为下拉)。例如,我在GUI中使用Emacs,在它后面有一个浏览器窗口,我想用快捷方式(例如F12)隐藏Emacs,然后看到我的浏览器(带有焦点)与任何其他窗口交互,然后再次按F12,我将返回Emacs (我正在运行KDE5.13)。另外,如果您知道如何在XFCE或gnome中这样做,请分享您的知识。
发布于 2021-10-19 07:33:42
我在emacs.stackexchange上也在链接上问过这个问题。我会在这里复印这封信,以供参考。它依赖于X11来工作,并且需要安装xdotool和wmctrl。
#!/bin/bash
######################################################################################################
# This script will toggle minimize/activate first window with specified class
# If window not found program will be launched
#
# window class can be found with next programs:
# wmctrl -x -l
# xprop
# No credit taken.......... Cannot read the original.....
# Found on http://blog.sokolov.me/2014/06/20/linuxx11-toggle-window-minimizemaximize/
# in Russian :) but works when adjusting the wrapping.
######################################################################################################
NEEDED_WINDOW_CLASS="emacs.Emacs"
LAUNCH_PROGRAM="emacs"
######################################################################################################
NEEDED_WINDOW_WINDOW_ID_HEX=`wmctrl -x -l | grep ${NEEDED_WINDOW_CLASS} | awk '{print $1}' | head -n 1`
NEEDED_WINDOW_WINDOW_ID_DEC=$((${NEEDED_WINDOW_WINDOW_ID_HEX}))
if [ -z "${NEEDED_WINDOW_WINDOW_ID_HEX}" ]; then
${LAUNCH_PROGRAM}
else
echo "Found window ID:${NEEDED_WINDOW_WINDOW_ID_DEC}(0x${NEEDED_WINDOW_WINDOW_ID_HEX})"
ACIVE_WINDOW_DEC=`xdotool getactivewindow`
if [ "${ACIVE_WINDOW_DEC}" == "${NEEDED_WINDOW_WINDOW_ID_DEC}" ]; then
xdotool windowminimize ${NEEDED_WINDOW_WINDOW_ID_DEC}
else
xdotool windowactivate ${NEEDED_WINDOW_WINDOW_ID_DEC}
fi
fi发布于 2023-03-09 03:47:56
有点晚了,但想在这里发布一个答案,不是KDE或gnome,而是依靠两个应用程序与底层显示服务器/窗口管理器(即X11或Wayland)交互才能完成任务。
在Ubuntu中进行测试,应该可以在可以安装wmctrl和xdotool的任何地方工作。本例使用konsole终端应用程序,但您可以使用任何您知道的应用程序的类名。若要计算类名,请打开应用程序并运行wmctrl -lx。
#!/usr/bin/env bash
# if app is not open then launch it -- remove this if you don't want your
# shortcut to launch the application if it hasn't been launched yet
if [ -z "$(xdotool search --class konsole)" ]; then
konsole
fi
# get current focused window and visible konsole window
CLASS="konsole"
ACTIVE_WINDOW="$(xdotool getactivewindow)"
APP_WINDOW="$(xdotool search --onlyvisible --class $CLASS)"
# if focused, minimize and hide the konsole, otherwise bring konsole to current desktop and open
if [ "$ACTIVE_WINDOW" = "$APP_WINDOW" ]; then
xdotool getactivewindow windowminimize
else
wmctrl -xR "$CLASS"
fi这个脚本假设了一些事情,即:
$(xdotool search --onlyvisible --class yourApp)返回一个匹配(需要处理数组/多个匹配)如果您不想单独使用xdotool 2和4,我只想更密切地模拟Guake终端的显示/隐藏行为,因此使用wmctrl将GUI应用程序带到当前活动的桌面上并显示出来。
因为它是bash脚本,所以它是可移植的--也就是说,您只需要知道如何在桌面应用程序(KDE、Gnome等)中设置自定义快捷方式,并使用上述快捷方式运行脚本。
https://unix.stackexchange.com/questions/462674
复制相似问题