Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1689087
  • 博文数量: 410
  • 博客积分: 9563
  • 博客等级: 中将
  • 技术积分: 4517
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-03 19:59
个人简介

文章分类

全部博文(410)

文章存档

2017年(6)

2016年(1)

2015年(3)

2014年(4)

2013年(32)

2012年(45)

2011年(179)

2010年(140)

分类: LINUX

2012-10-24 16:34:41

一直有个念头,就是能够像xmonad那样方便地用快捷键来控制任务窗口的显示,今天弄wmctrl,刚好有时间实现了,效果非常理想。
一、实现Mod+1..9激活程序窗口,如果该程序没打开,会自动打开程序。


Bash语言:
01 #!/bin/bash
02 
03 
04 if [ $# -lt 3 ]; then
05     echo   ""
06     echo   " 功能:判断进程是否存在,如果不存在就启动它,如果存在就显示它"
07     echo   ""
08     echo   " 用法: active_win   \$1   \$2   \$3"
09     echo   ""
10     echo   " 参数说明:"
11     echo   "           \$1       进程名"
12     echo   "           \$2       窗口名"
13     echo   "           \$3       程序启动文件"
14     echo   " 范例:"
15     echo   "                                 \$1         \$2           \$3"
16     echo   " firefox浏览器   : active_win  firefox      Firefox       firefox   "
17     echo   " Terminator      : active_win  terminator   Terminator   terminator"
18     echo   " Gvim            : active_win    gvim         Gvim         gvim"
19     echo   " XMind           : active_win  xmind-bin    XMind      /usr/local/xmind/xmind-bin"
20     exit 1
21 fi
22 PIDS=$( ps -ef | grep  $1 | grep -v grep | grep -v active_win )
23 if [ "$PIDS" != "" ] ; then
24     wmctrl -x -a  $2
25 #运行进程
26 else
27     sh -c "nohup $3 >/dev/null 2>&1 &"
28 fi

然后设置快捷键mod+1对应相应的程序,比如
active_win  firefox      Firefox       firefox

二、实现当前活动窗口左右窗口移动,同样把下面代码设置快捷键,比如F12,当你按F12时,当前窗口会移动到左侧窗口,再次F12,会移动到右侧,配合mod+1,就可以自由的设置双屏的程序窗口了。


Bash语言:
01 #!/bin/sh
02 
03 next_monitor_x=1920
04 
05 window=`xdotool getwindowfocus`
06 
07 x=`xwininfo -id $window | grep "Absolute upper-left X" | awk '{print $4}'`
08 y=`xwininfo -id $window | grep "Absolute upper-left Y" | awk '{print $4}'`
09 width=`xwininfo -id $window | grep "Width:" | awk '{print $2}'`
10 height=`xwininfo -id $window | grep "Height:" | awk '{print $2}'`
11 
12 
13 
14 if [ "$x" -ge $next_monitor_x ]
15 then
16     # move to left
17     wmctrl  -r :ACTIVE:  -e "0, 0,0,$width,$height"
18 else
19     # move to right
20     wmctrl  -r :ACTIVE: -e "0, $next_monitor_x,0,$width,$height"  
21 fi


使用compiz的方法,在12.04下面比较好用。
  1. Install CompizConfig Settings Manager.
    apt-get install compizconfig-settings-manager
  2. Run it -> Go to bottom (Window managment)-> Go to "Put"
  3. Enable the plugin
  4. Configure shortcut for "Put to next Output"

阅读(4025) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~