zoukankan      html  css  js  c++  java
  • wmctrl像xmonad那样方便地用快捷键来控制任务窗口的显示

     

    分类: LINUX

    2012-10-24 16:34:41

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


    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,就可以自由的设置双屏的程序窗口了。


    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"

    使用wmctrl关闭窗口

     
    我可以使用在Ubuntu上运行wine的wmctrl关闭窗口吗?

    对于上下文:

    $wmctrl -m
    Name: compiz
    Class: N/A
    PID: N/A
    Window manager's "showing the desktop" mode: OFF

    也:

    $wmctrl -l
    0x0240a3be -1 mjol N/A
    0x02000003  0 mjol Top Expanded Edge Panel
    0x0200004c  0 mjol Bottom Expanded Edge Panel
    0x01e00024  0 mjol x-nautilus-desktop
    0x04800253  0 mjol using wmctrl to close windows - Stack Overflow - Google Chrome
    0x03c0c8c3  0 mjol Terminal
    0x03c53f25  0 mjol Terminal
    0x04400001  0 mjol Untitled - SketchUp
    0x04400003  0 mjol Instructor
    0x04400009  0 mjol SketchUp

    我要关闭的窗口是最后一个:

    0x04400009  0 mjol SketchUp

    我尝试过以下方法:

    $wmctrl -c "SketchUp"
    
    $wmctrl -c 0x04400009
    
    $wmctrl -i 0x04400009
    
    $wmctrl -c -i 0x04400009

    但没有任何作用.

     
    也许有点晚了,但现在第一次见到. 读取wmctrl的信息,它表示正确的语法是动作之前的’选项’,-i是一个选项,-c是一个动作.试试wmctrl -i -c 0x04400009
     
     
    相关文章
     
     
     
     

    分类: LINUX

    2013-04-10 22:59:10

     
    一直有个误解,就是wmctrl和unity窗口管理器的兼容性不好,因为我原来在10.04下面正常使用的wmctrl命令在12.04下面不正常,今天终于发现了问题的原因。

    事情的起因是我希望实现一键切换显示或者隐藏窗口,比如我有一个帮助文档,希望能够一键给他显示出来,看完给他隐藏。在12.04下面试图使用命令
    1. wmctrl -r 成语接龙含义.pdf -b toggle,shaded
    一直没有效果,后来发现需要先取消掉窗口的最大化状态才行,于是脚本变成这样子


    1. #!/bin/bash
    2. #激活成语接龙文档
    3. #判断进程是否存在,如果不存在就启动它如果存在就显示它
    4. PIDS=$(ps aux | grep 'evince.*成语接龙含义.pdf' | grep -v grep)
    5. if [ "$PIDS" != "" ]
    6. then
    7.     wmctrl -r 成语接龙含义.pdf -b remove,maximized_horz
    8.     wmctrl -r 成语接龙含义.pdf -b remove,maximized_vert
    9.     wmctrl -r 成语接龙含义.pdf -e 0,-1,-1,1920,1200
    10.     wmctrl -r 成语接龙含义.pdf -b toggle,shaded
    11. #运行进程
    12. else
    13.     sh -c "nohup evince /home/bl/Yunio/果果/成语接龙含义.pdf >/dev/null 2>&1 &"
    14. fi
    配个快捷键给他,效果非常理想
     
  • 相关阅读:
    侧方停车 成功50% 一把进不去 出去二把进
    在Windows上使用 Python 安装+ win10启用长路径
    无锡 苏州 上海 古镇 汇总20200129
    win10家庭版升级 到win10企业版
    WPS Office 2019 v11.8.2.8053地方企业版 2016 v10.8.2.6948
    WPS2019党政机关单位版(无广告困扰)
    自用Chrome插件推荐【附教程及下载】
    转载 https://www.cnblogs.com/bobo-pcb/p/11708459.html
    HDU1302_Snail【模拟题】【水题】
    how to add Javascript and CSS in page layout with sharepoint 2013
  • 原文地址:https://www.cnblogs.com/xuanbjut/p/12624702.html
Copyright © 2011-2022 走看看