KDEですべてのウィンドウのウィンドウタイトルを無視し、カスタムウィンドウタイトルを設定する

KDEですべてのウィンドウのウィンドウタイトルを無視し、カスタムウィンドウタイトルを設定する

ここではKDEが使用されていますが、他のデスクトップ環境でも機能するソリューションがあるかもしれません。私はしばしば非常に多くのウィンドウを扱う必要があります。ほとんどのウィンドウには多くのタブが含まれています(たとえば、タブ付きのDolphinウィンドウ、Firefox、Konsoleなど)。ウィンドウのタイトルは現在のタブ(ほとんどの場合役に立ちます)によって変わりますが、あまりにも多くのウィンドウで作業するときは、ウィンドウを少し整理したいと思います。アプリケーションによって提供されたウィンドウのタイトルをオーバーライドして手動でウィンドウの名前を変更する機能。 1 つの Firefox ウィンドウ名を「Research」と指定し、別の Firefox ウィンドウの名前を「Documents」と指定することで、複数のタブを整理およびグループ化するために使用するウィンドウを簡単に区別できます。

理想的には、ウィンドウのタイトルバーをクリックして簡単にカスタム名を指定できますが、機能する限り、もう少し面倒なソリューションを選択します。

これを試しましたが、wmctrl -r :SELECT: -T "Research"これは一時的にのみ機能します(たとえば、タブを切り替えるとアプリがタイトルを変更したときにタイトルが再表示されます)。

ベストアンサー1

私は同じ問題に直面しました。

だから、ショートカットにバインドされるシェルスクリプトを作成しました。

ホットキーを押すと、現在アクティブなウィンドウ(フォーカスがあるウィンドウ)のウィンドウIDを取得します。

これにより、ウィンドウに含めるタイトルを入力できるポップアップダイアログボックスが表示されます。

その後、ウィンドウ名が変更されるたびに、目的のタイトルに戻ります。

このスクリプトを使用するには、次のものが必要です。

  • shell(bashが私に頭痛を与えたfishので、bashの代わりにfishで書いた)

  • kdialog

  • スクリプトをショートカットにバインドする方法(操作するには、次のものを追加するだけです)
    xbindkeys

"[PATH TO SCRIPT]/[NAME OF SCRIPT]" Mod4 + t

(例:ウィンドウキー+ t)
をmy /home/o1/.xbindkeysrc

ありがとうこの男、魔法のxpropに関する情報を提供した人です。

(1年前頃でしたが、今日になってこそ台本を書き始めました。xD)

PS。初心者がこの答えを見つけましたが、使い方がわからない場合は、私に連絡してください。ご案内いたします。 ^^

-ttitle_i_want編集:forおよびforスイッチを介してコマンドライン-wで使用できるように更新しましたwindow_id

スクリプトは次のとおりです。

#!/usr/local/bin/fish

# this block is so you can use it from the command line with -t and -w
if test "$argv" != "" -a (math (count $argv)%2 == 0)
    for i in (seq 1 (count $argv))
        if test $argv[$i] = '-t'
            set title_i_want $argv[(math 1 + $i)]
        else if test $argv[$i] = '-w'
            set window_id $argv[(math 1 + $i)]
        end
    end
    if not test $window_id
        echo "YOU DIDN'T ENTER A `window_id` WITH `-w`,
SO MAKE SURE THE WINDOW YOU WANT HAS FOCUS
TWO SECONDS FROM NOW!"
        sleep 2
    end
end

# get the id of the currently focused window
if not test $window_id
    set window_id (xprop -root _NET_ACTIVE_WINDOW | grep -P -o "0x\w+")
end

# get the title to force on that window

if not test $title_i_want
    set title_i_want (kdialog --title "entitled" --inputbox "type the title you want and hit enter.
to stop renaming,
just enter nothing and hit esc")
end

# this bit is needed for a kludge that allows window renaming
set has_renamed_before "FALSE"
set interrupt_message "WAIT WAIT I WANT A TURN BLOO BLOO BLEE BLUH BLOO" # hopefully i never want to actually use that as a title xD
xprop -f _NET_WM_NAME 8u -set _NET_WM_NAME $interrupt_message -id $window_id

# take the output of xprop
# pipe it into a while loop
# everytime it outputs a new line
# stuff it into a variable named "current_title"
xprop -spy _NET_WM_NAME -id $window_id | while read current_title

    # cut off extraneous not-the-title bits of that string
    set current_title (echo $current_title | grep -P -o '(?<=_NET_WM_NAME\(UTF8_STRING\) = ").*(?="\z)')

    # if the current title is the interrupt message
    # AND
    # this script has renamed the window at least once before
    # then we wanna let the new name take over
    if test $current_title = $interrupt_message -a $has_renamed_before = "TRUE"
        exit
    # if title_i_want is an empty string, exit
    else if test $title_i_want = ""
        xprop -f _NET_WM_NAME 8u -set _NET_WM_NAME "WIDNOW WILL START RENAMING ITSELF AS NORMAL" -id $window_id
        exit
    # otherwise just change the title to what i want
    else if test $current_title != $title_i_want
        xprop -f _NET_WM_NAME 8u -set _NET_WM_NAME "$title_i_want" -id $window_id
        set has_renamed_before "TRUE"
    end
end

編集:私は実際にこのFishスクリプトを使用しなくなりました。
Rubyで書き直しました。

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

require 'trollop'
opts = Trollop.options do
                        opt :title_i_want,  "title_i_want",     default: ""
                        opt :bluh,          "write to bluh",    default: nil
                        opt :copy_title,    "copy_title",       default: nil
# TODO - AUTO OPTION                                            
                        opt :auto,          "auto",             default: nil
end

title_i_want    = opts[:title_i_want]


def get_current_wid
    `xprop -root _NET_ACTIVE_WINDOW`[/0x\w+/]
end

def with_current_title wid, &block
    IO.popen("xprop -spy _NET_WM_NAME _NET_WM_ICON_NAME -id #{wid}") do |io|
        loop do
            line = io.gets
            exit if line.nil?
            line = line.strip
            # cut off extraneous not-the-title bits of that string
            current_title = line[/(?:_NET_WM_(?:ICON_)?NAME\(UTF8_STRING\) = ")(.*)("$)/, 1]

            block.call current_title unless current_title.nil?
        end
    end
end
def get_current_title wid
    IO.popen("xprop _NET_WM_NAME _NET_WM_ICON_NAME -id #{wid}") do |io|
            line = io.gets.strip
            # cut off extraneous not-the-title bits of that string
            current_title = line[/(?:_NET_WM_(?:ICON_)?NAME\(UTF8_STRING\) = ")(.*)("$)/, 1]

            return current_title unless current_title.nil?
    end
end

if opts[:copy_title]
    # require "muflax"
    p 1
    wid = get_current_wid
    `echo -n '#{get_current_title wid}(WID: #{wid})'|xclip -selection c`
    exit
end
if opts[:bluh]
    require "muflax"
    loop do
        # p 1   #db
        wid = get_current_wid
        # p 2   #db
        File.open "bluh", "a+" do |f| f.puts get_current_title wid end
        while wid == get_current_wid
            # puts "..."    #db
            sleep 1
        end
    end
    exit
end

#> 1A - from terminal - give title_i_want
if not title_i_want.empty?
#> 1A.1 - get current wid - assume it's the terminal_wid
    terminal_wid = get_current_wid
#> 1A.2 - wait for wid to change
    while get_current_wid == terminal_wid
        puts "focus the window you want to title «#{title_i_want}»..."
        sleep 1
    end
#> 1A.3 - set new wid to target TWID
    TWID = get_current_wid

#> 1B - from hotkey (or just sleeping) - no give title_i_want
else
#> 1B.1 - set current wid to target TWID
    TWID = get_current_wid
#> 1B.2 - get title_i_want (with kdialog)
#> 1B.2.1 - default to current title
    with_current_title TWID do |current_title|
        # v :current_title  #db
        default_title = current_title

        sublime_match = /
            (?<beginning>.*?)                                   # beginning might be...
                                                                #           path
                                                                #           untitled, find results, other useless junk
                                                                #           

おすすめ記事