资讯专栏INFORMATION COLUMN

在linux下模拟win+arrow来左右半屏当前窗口

since1986 / 2266人阅读

摘要:目的用习惯了下的来左右窗口,在觉得非常不方便的。所以上网看一下在上可以使用的方法。因为不想依赖,所以找到的最好方法是虽然不太完美,但可以满足的需求了。希望后面的窗口管理器能自动集成这个功能,靠第三方工具是不太可能完美的

目的

用习惯了windows下的win+arrow来左右窗口,在linux觉得非常不方便的。
所以上网看一下在RHEL6上可以使用的方法。因为不想依赖compiz,所以找到的最好方法是xdotool.
虽然不太完美,但可以满足80%的需求了。

安装xdotool

有两种方法,一种是源码安装,一种是yum安装

源码安装 安装meson
[root@pc-harriszh1 xdotool]# pip3 install meson
Collecting meson
  Downloading meson-0.42.1.tar.gz (1.0MB)
    100% |████████████████████████████████| 1.1MB 279kB/s 
Installing collected packages: meson
  Running setup.py install for meson ... done
Successfully installed meson-0.42.1
安装Ninja
[root@pc-harriszh1 libxkbcommon]# cd ..
[root@pc-harriszh1 ~]# git clone git://github.com/ninja-build/ninja.git && cd ninja
Initialized empty Git repository in /root/ninja/.git/
remote: Counting objects: 9572, done.
remote: Total 9572 (delta 0), reused 0 (delta 0), pack-reused 9572
Receiving objects: 100% (9572/9572), 3.39 MiB | 258 KiB/s, done.
Resolving deltas: 100% (6816/6816), done.
[root@pc-harriszh1 ninja]# ./configure.py --bootstrap
bootstrapping ninja...
warning: A compatible version of re2c (>= 0.11.3) was not found; changes to src/*.in.cc will not affect your build.
wrote build.ninja.
bootstrap complete.  rebuilding...
[26/26] LINK ninja

[root@pc-harriszh1 ninja]# cp ninja /usr/local/bin/
安装xkbcommon
[root@pc-harriszh1 libxkbcommon]# !meson
meson build -Denable-wayland=false
The Meson build system
Version: 0.42.1
Source dir: /root/libxkbcommon
Build dir: /root/libxkbcommon/build
Build type: native build
Project name: libxkbcommon
Native C compiler: cc (gcc 4.4.7)
Build machine cpu family: x86_64
Build machine cpu: x86_64
Compiler for C supports argument -fvisibility=hidden: YES
Compiler for C supports argument -Wextra: YES
Compiler for C supports argument -Wno-unused-parameter: YES
Compiler for C supports argument -Wno-missing-field-initializers: YES
Compiler for C supports argument -Wpointer-arith: YES
Compiler for C supports argument -Wmissing-declarations: YES
Compiler for C supports argument -Wformat=2: YES
Compiler for C supports argument -Wstrict-prototypes: YES
Compiler for C supports argument -Wmissing-prototypes: YES
Compiler for C supports argument -Wnested-externs: YES
Compiler for C supports argument -Wbad-function-cast: YES
Compiler for C supports argument -Wshadow: YES
Compiler for C supports argument -Wlogical-op: YES
Compiler for C supports argument -Wdate-time: NO
Compiler for C supports argument -Wwrite-strings: YES
Found pkg-config: /usr/bin/pkg-config (0.23)
Dependency xkeyboard-config found: NO
Checking if "__builtin_expect" links: YES
Checking if "__builtin_popcount" links: YES
Header  has symbol "eaccess": YES
Header  has symbol "euidaccess": YES
Header  has symbol "mmap": YES
Header  has symbol "mkostemp": YES
Header  has symbol "posix_fallocate": YES
Header  has symbol "secure_getenv": NO
Header  has symbol "__secure_getenv": YES
Configuring config.h using configuration
Checking if "-Wl,--version-script" links: YES
Program bison found: YES (/usr/bin/bison)
Native dependency xcb found: YES 1.11
Native dependency xcb-xkb found: YES 1.11
Program test/symbols-leak-test.bash found: YES (/root/libxkbcommon/test/symbols-leak-test.bash)
Has header "linux/input.h": YES
Library rt found: YES
Program doxygen found: YES (/usr/bin/doxygen)
Program scripts/doxygen-wrapper found: YES (/root/libxkbcommon/scripts/doxygen-wrapper)
Configuring Doxyfile using configuration
Build targets in project: 31
[root@pc-harriszh1 libxkbcommon]# ninja -C build
ninja: Entering directory `build"
[6/96] Compiling C object "xkbcommon-internal@sta/xkbcommon-internal@sta_parser.c.o".
In file included from ../src/xkbcomp/parser.y:37:
../src/scanner-utils.h: In function ‘buf_appends’:
../src/scanner-utils.h:163: warning: declaration of ‘str’ shadows a global declaration
../src/scanner-utils.h:141: warning: shadowed declaration is here
[8/96] Compiling C object "xkbcommon-internal@sta/src_compose_parser.c.o".
In file included from ../src/compose/parser.c:58:
../src/scanner-utils.h: In function ‘buf_appends’:
../src/scanner-utils.h:163: warning: declaration of ‘str’ shadows a global declaration
../src/scanner-utils.h:141: warning: shadowed declaration is here
../src/compose/parser.c: In function ‘add_production’:
../src/compose/parser.c:363: warning: declaration of ‘next’ shadows a global declaration
../src/scanner-utils.h:117: warning: shadowed declaration is here
[16/96] Compiling C object "xkbcommon-internal@sta/src_xkbcomp_keymap.c.o".
../src/xkbcomp/keymap.c: In function ‘CompileKeymap’:
../src/xkbcomp/keymap.c:242: warning: comparison of unsigned expression < 0 is always false
[19/96] Compiling C object "xkbcommon-internal@sta/src_xkbcomp_rules.c.o".
In file included from ../src/xkbcomp/rules.c:53:
../src/scanner-utils.h: In function ‘buf_appends’:
../src/scanner-utils.h:163: warning: declaration of ‘str’ shadows a global declaration
../src/scanner-utils.h:141: warning: shadowed declaration is here
[20/96] Compiling C object "xkbcommon-internal@sta/src_xkbcomp_scanner.c.o".
In file included from ../src/xkbcomp/scanner.c:26:
../src/scanner-utils.h: In function ‘buf_appends’:
../src/scanner-utils.h:163: warning: declaration of ‘str’ shadows a global declaration
../src/scanner-utils.h:141: warning: shadowed declaration is here
[30/96] Compiling C object "xkbcommon-internal@sta/src_keysym.c.o".
In file included from ../src/keysym.c:54:
../src/ks_tables.h:8: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
../src/ks_tables.h:2418: warning: expected [error|warning|ignored] after ‘#pragma GCC diagnostic’
[96/96] Generating doc with a custom command.
Warning: ignoring unsupported tag `USE_MDFILE_AS_MAINPAGE =" at line 28, file /root/libxkbcommon/build/Doxyfile
Warning: ignoring unsupported tag `HTML_EXTRA_STYLESHEET  =" at line 37, file /root/libxkbcommon/build/Doxyfile
Failed to map file extension "no_extension" to unsupported language "md".
Check the EXTENSION_MAPPING setting in the config file.
/root/libxkbcommon/xkbcommon/xkbcommon.h:511: Warning: unable to resolve reference to `include-path" for 
ef command
/root/libxkbcommon/xkbcommon/xkbcommon.h:1611: Warning: Found unknown command `parblock"
/root/libxkbcommon/xkbcommon/xkbcommon.h:1763: Warning: Found unknown command `endparblock"
/root/libxkbcommon/xkbcommon/xkbcommon.h:1685: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon.h:1686: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-x11.h:48: Warning: Found unknown command `parblock"
/root/libxkbcommon/xkbcommon/xkbcommon-x11.h:246: Warning: Found unknown command `endparblock"
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:47: Warning: Found unknown command `parblock"
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:56: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:57: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:57: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:59: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:63: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:468: Warning: Found unknown command `endparblock"
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:83: Warning: Found unknown command `parblock"
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:94: Warning: Found unknown command `endparblock"
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:99: Warning: Found unknown command `parblock"
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:103: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:108: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:110: Warning: Unsupported xml/html tag  found
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:115: Warning: Found unknown command `endparblock"
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:116: Warning: end of comment block while expecting command 
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:116: Warning: end of comment block while expecting command 
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:116: Warning: end of comment block while expecting command 
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:154: Warning: Found unknown command `parblock"
/root/libxkbcommon/xkbcommon/xkbcommon-compose.h:232: Warning: Found unknown command `endparblock"

上面步骤失败了, 所以手工来拷贝

cp libxkbcommon.so libxkbcommon.so.0 libxkbcommon.so.0.0.0 libxkbcommon-x11.so libxkbcommon-x11.so.0 libxkbcommon-x11.so.0.0.0 /usr/local/li
cp xkbcommon /usr/local/include/ -rf
安装xdotools
git clone https://github.com/jordansissel/xdotool.git
cd xdotool && make && make install

安装后命令可以执行,但没有效果
所以只能直接安装,这有一个问题是需要root权限


yum直接安装

如果有root权限,那么上面的步骤都不需要,直接用yum安装就好

yum install xtodool

安装后是可以使用


绑定快捷键

一种是利用系统快捷键(推荐),一种是利用xbindkeys(除了做这个其实可以做很多事)

使用系统快捷键
mkdir ~/.winarrow
echo "#!/usr/local/bin/zsh" > ~/.winarrow/leftarrow.sh
echo "xdotool windowsize $(xdotool getwindowfocus) 50% 100% && xdotool windowmove $(xdotool getwindowfocus) 0 y" >> ~/.winarrow/rightarrow.sh
echo "#!/usr/local/bin/zsh" > ~/.winarrow/leftarrow.sh
echo "xdotool windowsize $(xdotool getwindowfocus) 50% 100% && xdotool windowmove $(xdotool getwindowfocus) 9999 y" >> ~/.winarrow/rightarrow.sh

然后到系统快捷键里把win+left映射到/home/harriszh/.winarrow/leftarrow.sh, 把win+right映射到/home/harriszh/.winarrow/rightarrow.sh,

注意:直接把命令写在"custom shortcut"的command里不起作用, 因为这个命令里有$()命令替换


使用xbindkeys 安装guile
yum install guile
安装guile-config

从centos.pkgs.org下载包

rpm -Uvh /mnt/hgfs/ed/13_linux/gmp-4.3.1-12.el6.x86_64.rpm
rpm -ivh /mnt/hgfs/ed/13_linux/gmp-devel-4.3.1-12.el6.x86_64.rpm
rpm -ivh /mnt/hgfs/ed/13_linux/guile-devel-1.8.7-5.el6.x86_64.rpm
安装xbindkeys
./configura && make && make install

在home目录下vi ~/.xbindkeysrc
"xdotool windowsize $(xdotool getwindowfocus) 50% 100% && xdotool windowmove $(xdotool getwindowfocus) 0 y"

     Mod2+Mod4 + Left

"xdotool windowsize $(xdotool getwindowfocus) 50% 100% && xdotool windowmove $(xdotool getwindowfocus) 9999 y"

     Mod2+Mod4 + Right

然后添加到系统启动程序里

后言

xdotool的问题是窗口最大化时没法起作用(用alt+space,x来取消最大化),同时左停靠和右停靠时窗口上下没有最大。
希望后面的窗口管理器能自动集成这个功能,靠第三方工具是不太可能完美的

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/10380.html

相关文章

  • Android Studio 提示与技巧(官方文档翻译)

    摘要:智能渲染使用智能渲染,中显示快速修复渲染的错误的链接。这将提取从调试的过程相关数据,并显示调试器中的中。根据所选中的目录类型,会提供创建适当的文件类型。支持高分辨率视网膜显示在和。文件快速原型文件,不会创造任何项目文件。 这是翻译官方的文档,英语好的可以直接去官方文档查看,英语不好,大家就将就看吧,算是我翻译的第一篇技术文章,因为是个英语渣,技术也渣,所以最近在学英语,就尝试着自己来翻...

    _Dreams 评论0 收藏0
  • vim编辑器

    摘要:编辑器是文本编辑器的一个扩展的程序,可以在命令行接口上使用,也可以在图形用户接口上作为一个独立的应用程序使用。是由根据在计算机上的一个接口的源程序编写,在年首次公开发行。 Vim编辑器 vim(Vi IMproved)是vi文本编辑器的一个扩展的程序,Vim可以在命令行接口上使用,也可以在图形用户接口上作为一个独立的应用程序使用。Vim是由Bram Moolenaar根据Stevie ...

    binta 评论0 收藏0
  • 编辑器之神-VIM

    摘要:在这天地间,流传这两大神器的故事据说是神的编辑器,而是编辑器之神。正所谓,工欲善其事必先利其器。今天就和大家分享一下关于编辑器之神的传说。主要用于用来编写和查看文本文件。 在这天地间,流传这两大神器的故事:据说Emacs是神的编辑器,而Vim是编辑器之神。正所谓,工欲善其事,必先利其器。今天就和大家分享一下关于编辑器之神Vim的传说。 一、Vim的历史 1.下图是关于几款主流编辑器...

    Tikitoo 评论0 收藏0
  • 编辑器之神-VIM

    摘要:在这天地间,流传这两大神器的故事据说是神的编辑器,而是编辑器之神。正所谓,工欲善其事必先利其器。今天就和大家分享一下关于编辑器之神的传说。主要用于用来编写和查看文本文件。 在这天地间,流传这两大神器的故事:据说Emacs是神的编辑器,而Vim是编辑器之神。正所谓,工欲善其事,必先利其器。今天就和大家分享一下关于编辑器之神Vim的传说。 一、Vim的历史 1.下图是关于几款主流编辑器...

    fobnn 评论0 收藏0
  • 编辑器之神-VIM

    摘要:在这天地间,流传这两大神器的故事据说是神的编辑器,而是编辑器之神。正所谓,工欲善其事必先利其器。今天就和大家分享一下关于编辑器之神的传说。主要用于用来编写和查看文本文件。 在这天地间,流传这两大神器的故事:据说Emacs是神的编辑器,而Vim是编辑器之神。正所谓,工欲善其事,必先利其器。今天就和大家分享一下关于编辑器之神Vim的传说。 一、Vim的历史 1.下图是关于几款主流编辑器...

    imingyu 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<