linux - 使用 wmcrtl 在同一应用程序的窗口中循环

标签 linux focus keyboard-shortcuts console-application window-managers

我正在配置 xbindkeys 以使用快捷方式更改窗口焦点。 例如,我设法创建了一个快捷方式来关注应用程序窗口,假设是一个终止窗口:

wmctrl -xa terminator

不幸的是,它总是聚焦在同一个终结器窗口,阻止我在终结器窗口中循环。

你能建议我一个命令来关注一个终止窗口,如果再次按下,将循环显示所有的终止窗口,好吗?

2013 年 3 月 30 日更新

我修改了这个脚本 http://lars.st0ne.at/blog/switch%20between%20windows%20within%20the%20same%20application 制作这样的脚本

script.sh NAME

关注应用程序 NAME 或循环遍历 NAME 的所有窗口,如果它的一个窗口已经获得焦点,但它不能正常工作。

这是脚本

win_class=$1 # 'terminator' # $1

# get list of all windows matching with the class above
win_list=$(wmctrl -x -l | grep -i $win_class | awk '{print $1}' )

# get id of the focused window
active_win_id=$(xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}')

# get next window to focus on, removing id active
switch_to=$(echo $win_list | sed s/.*$active_win_id// | awk '{print $1}')

# if the current window is the last in the list ... take the first one
if [ "$switch_to" == '' ];then
   switch_to=$(echo $win_list | awk '{print $1}')
fi

# switch to window
wmctrl -i -a $switch_to

该脚本确实专注于应用程序的一个窗口,并循环遍历它们直到它到达一个窗口,我猜是最后创建的。到那时,骑自行车就不再适用了。

最佳答案

如果没有窗口获得焦点,我发现脚本中存在问题。

您可以尝试以下修改后的脚本:

#!/bin/bash
win_class=$1 # 'terminator' # $1

# get list of all windows matching with the class above
win_list=$(wmctrl -x -l | grep -i $win_class | awk '{print $1}' )

# get id of the focused window
active_win_id=$(xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}')
if [ "$active_win_id" == "0" ]; then
    active_win_id=""
fi

# get next window to focus on, removing id active
switch_to=$(echo $win_list | sed s/.*$active_win_id// | awk '{print $1}')

# if the current window is the last in the list ... take the first one
if [ "$switch_to" == '' ];then
   switch_to=$(echo $win_list | awk '{print $1}')
fi

# switch to window
wmctrl -i -a $switch_to

关于linux - 使用 wmcrtl 在同一应用程序的窗口中循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15172735/

相关文章:

linux - `du -sh` 对于同一文件夹在不同机器上产生不同结果

linux - 如果没有/etc/timezone 文件或/usr/share/zoneinfo,我如何在 Linux 中设置时区

linux - 为什么我无法运行位于 bin 中的文件?

javascript - window.close() 不起作用 - 脚本可能只关闭它打开的窗口

macos - iTerm2 中跳转到上一个命令的键盘快捷键?

linux - 如何计算Shell中重复的句子

objective-c - 设置 UIWebView 内容在显示键盘时不移动

WPF 窗口 GotFocus/LostFocus

android - ListView OnFocusChangeListener

xcode - 有没有办法跳转到 Xcode 中的目标/方案选择菜单?