我进入了compizconfig的网格部分,并自定义了所有平铺命令。
当我测试命令时,我没有看到它们中的任何一个有效地居中显示在屏幕中央。
我进入了窗口放置部分,并配置了新窗口以居中打开。但是,如果我将窗口移到右侧,然后将其居中,则不知道如何使用键盘命令执行此操作。“放置中心”将使其最大化,而“还原”将其移至其最新位置/大小。
总结一下
说我有一个窗口遮住屏幕的右半部分。我想保持尺寸/大小不变,但将其居中。
以下脚本将用户活动窗口的中心与屏幕的中心对齐。它旨在绑定到“设置”->“键盘”->“快捷方式”菜单中的键盘快捷键。
~/bin/center_active_window.py
。确保它具有可执行权限chmod +x ~/bin/center_active_window.py
/home/your_user_name/bin/center_active_window.py
。点击ApplyDisabled
文本,并在出现提示后为其分配自定义按键绑定。我正在使用Ctrl+ Super+ C,但是您可以使用任何您喜欢的东西。#!/usr/bin/env python3
# Author: Serg Kolo
# Date: Oct 3rd, 2016
# Description: Script for aligning the center of
# user's active window with the center of the monitor
# Tested on: Ubuntu 16.04
# Written for: http://askubuntu.com/q/832720/295286
from __future__ import print_function
from gi.repository import Gdk
import subprocess
def get_offset(*args):
command = ['xprop','-notype','_NET_FRAME_EXTENTS',
'-id',str(args[0])
]
out = subprocess.check_output(command)
return int(out.decode().strip().split(',')[-2])
def main():
screen = Gdk.Screen.get_default()
window = screen.get_active_window()
window.unmaximize()
window_width = window.get_width()
window_y = window.get_origin()[-1]
print(window_y)
window_monitor = screen.get_monitor_at_window(window)
monitor_center = screen.get_monitor_geometry(window_monitor).width/2
# if centers of window and screen are aligned
# the top left corner will be at screen_center - window_width/2
new_position = monitor_center - window_width /2
# For some reason there is vertical offset necessary
# Apparently this comes form _NET_FRAME_EXTENTS value
offset = get_offset(int(window.get_xid()))
window.move(new_position,window_y-offset)
print(window.get_origin())
if __name__ == '__main__':
main()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句