web-dev-qa-db-ja.com

選択した方向で、ウィンドウのサイズを半分のサイズに変更するようにキーバインドを設定できますか?

Ubuntu 14.04を使用して、40インチ4kディスプレイを取得することを検討しており、ウィンドウのサイズを画面の4分の1に縮小する方法を見つけましたが、必要に応じてさらに縮小することもできます。たとえば、デフォルトのcompizをキーバインドして全画​​面ウィンドウを取得し、画面の左上4分の1に配置しますが、もう一度押すと、画面の左上8分の1にさらに縮小するか、ウィンドウを右下4分の1に配置します画面の上部4分の1(画面の垂直方向と水平方向の8分の1を占める)この機能は、compizや他のよく知らないアプリケーションに隠されていますか?

2
Travis

以下のスクリプトは、14.04の「四分の一サイズ変更」オプションの追加機能として使用できます。 「左」、「右」、「上」、「下」という引数を指定して実行すると、四半期をさらに8にカットできます。

それがすること

ウィンドウを画面の4分の1に移動した場合:

enter image description here

スクリプトは、ウィンドウを実行する引数に応じて、ウィンドウを左、右、上、または下半分に半分にカットします(以下を参照)。

使い方

  • スクリプトはwmctrlを使用しますが、これはデフォルトではシステムにありません。

    Sudo apt-get install wmctrl
    
  • 以下のスクリプトを空のファイルにコピーし、organize_wという名前でディレクトリ~/binに保存します。スクリプトを実行可能にします。おそらく、ディレクトリ~/binを作成する必要があります。スクリプトの名前だけでスクリプトを実行できるという利点があります。

  • カスタムキーボードショートカットに4つのコマンドを追加します。システム設定>「キーボード」>「ショートカット」>「カスタムショートカット」を開きます。キーの組み合わせに4つのコマンドを追加します。
    私のシステムでは、4つの非常に適合するショートカットがまだ利用可能であることがわかりました。これらのキーの組み合わせの下にコマンドを追加することをお勧めします。

    organize_w left 
    

    Shift+Ctrl+テンキー <

    効果:

    enter image description here

    organize_w right 
    

    Shift+Ctrl+テンキー >

    効果:

    enter image description here

    organize_w up 
    

    Shift+Ctrl+テンキー ^

    効果:

    enter image description here

    organize_w down 
    

    Shift+Ctrl +テンキー v

    効果:

    enter image description here

    このように、いくつかのキーストロークでウィンドウを下のように配置できます:

  • enter image description here

スクリプト:

#!/usr/bin/env python3
import subprocess
import sys

arg = sys.argv[1]
WA_correction = 28

def get(command):
    return subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")

def execute(command):
    subprocess.Popen(["/bin/bash", "-c", command])

xprop_data = get("xprop -root").split()
w_id = xprop_data[xprop_data.index("_NET_ACTIVE_WINDOW(WINDOW):")+4].replace(",", "")
frontmost = w_id[:2]+"0"+w_id[2:]
w_data = [l for l in get("wmctrl -lG").splitlines() if frontmost in l][0].split()
new_G = w_data[2:6]
new_G[1] = str(int(int(new_G[1])-WA_correction))
xy_corr = lambda x: -10 if int(x) < 100 else 0
if arg == "left":
    new_G[2] = str(int(int(new_G[2])/2 + xy_corr(new_G[0])))
    new_G[3] = str(int(int(new_G[3]) + xy_corr(new_G[1])))            
Elif arg == "right":
    new_G[0] = str(int(int(new_G[0])+int(new_G[2])/2))    
    new_G[2] = str(int(int(new_G[2])/2))
    new_G[3] = str(int(int(new_G[3]) + xy_corr(new_G[1])))
Elif arg == "up":
    new_G[2] = str(int(new_G[2]) + xy_corr(new_G[0]))
    new_G[3] = str(int(int(new_G[3])/2 + xy_corr(new_G[1])))
Elif arg == "down":
    new_G[1] = str(int(int(new_G[1]) + int(new_G[3])/2))
    new_G[2] = str(int(new_G[2]) + xy_corr(new_G[0]))
    new_G[3] = str(int(int(new_G[3])/2))

execute("wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz")
execute("wmctrl -ir "+frontmost+" -e 0,"+(",").join(new_G))



edit:

XFCEバージョン

いくつかのマイナーな変更により、スクリプトを使用して、XFCEでウィンドウのサイズを半分/ 4分の1または8に変更することもできます(14.04でテスト済み)。

Unityのバージョンとまったく同じように使用します。

#!/usr/bin/env python3
import subprocess
import sys

arg = sys.argv[1]
WA_correction = 48

def get(command):
    return subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")

def execute(command):
    subprocess.Popen(["/bin/bash", "-c", command])

xprop_data = get("xprop -root").split()
w_id = xprop_data[xprop_data.index("_NET_ACTIVE_WINDOW(WINDOW):")+4].replace(",", "")
frontmost = w_id[:2]+"0"+w_id[2:]
w_data = [l for l in get("wmctrl -lG").splitlines() if frontmost in l][0].split()
new_G = w_data[2:6]
new_G[1] = str(int(int(new_G[1])-WA_correction))
if arg == "left":
    new_G[2] = str(int(int(new_G[2])/2))      
Elif arg == "right":
    new_G[0] = str(int(int(new_G[0])+int(new_G[2])/2))    
    new_G[2] = str(int(int(new_G[2])/2))
Elif arg == "up":
    new_G[3] = str(int(int(new_G[3])/2))
Elif arg == "down":
    new_G[1] = str(int(int(new_G[1]) + int(new_G[3])/2))
    new_G[3] = str(int(int(new_G[3])/2))

execute("wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz")
execute("wmctrl -ir "+frontmost+" -e 0,"+(",").join(new_G))

(XFCEバージョンも Gist.gisthub に投稿されています)

2
Jacob Vlijm