LoginSignup
8
8

More than 5 years have passed since last update.

Ubuntu で 窓替えのような機能を実装する

Last updated at Posted at 2016-10-09

Windows の 窓替え が便利すぎる

僕は ctrl + tab で窓替えを起動し、1文字入力で指定ウィンドウに切り替えをしていました。
http://www.vector.co.jp/soft/winnt/util/se431478.html

それをubuntuでも使えるようにしたい。

m-yamashita さんの Quick.pyを利用

なぐり書き実装

Autokeyの中で適当なスプリクトを作成して、下記のように記述。適当なショートカットキーをautokeyで割り振ってください。僕は ctrl+tab が好きです。

適当に必要箇所を変更してください。使い方は Quitck.py と同じですが、Tkinter で超お手軽スイッチャウィンドウを作ってます。

Tkinter のウィンドウ上で一文字の入力を受け付け、それに紐付いたウィンドウがアクティブ化、もしくは起動し、対応するキーがなければ勝手に終了します。

時間の関係上、作りこむ気は今のところありません。

# Enter script code
import Tkinter as tk
import threading
import subprocess

def onKeyPress(event):
    is_found = True
    # Regexp of window title or WM_CLASS.
    if event.char == "f":
        regexp = " - Firefox$"
        command = "firefox"
        options = "-a"
    elif event.char == "a":
        regexp = " Atom$"
        command = "atom"
        options = "-a"
    elif event.char == "e":
        regexp = " Eclipse$"
        command = "eclipse"
        options = "-a"
    else:
        is_found = False

    # Call the main routine(Don't change me!!).
    if is_found:
        subprocess.Popen('python ~/.config/autokey/quickey.py/quickey.py %s "%s" "%s"' % (options, regexp, command), shell=True)
        #subprocess.Popen(['python', '~/.config/autokey/quickey.py/quickey.py', options, regexp, command])
    root.destroy()

root = tk.Tk()
root.geometry('300x200')
text = tk.Text(root, background='black', foreground='white', font=('Comic Sans MS', 12))
text.insert('end', 'a:Atom\n')
text.insert('end', 'e:Eclipse\n')
text.insert('end', 'f:Firefox\n')
text.pack()
root.bind('<KeyPress>', onKeyPress)
root.mainloop()

``
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8