Использование сценария оболочки: Как получить имя иконки (или путь) открытого окна в оконном менеджере на основе X?

604
dgo.a

Я могу получать идентификаторы окон и заголовки окон wmctrl, но пока не смог найти путь к значку, используемому окном. Я пробовал смотреть на утилиты xdg, но самым близким была установка / удаление иконок.

Есть ли способ получить имя иконки, используемой XDG / GTK, или путь dir к иконке в скрипте / командной строке оболочки?

1

2 ответа на вопрос

1
dgo.a

So instead of the name, you can get the image itself:

xprop -id THE_WINDOW_ID -notype 32c _NET_WM_ICON | perl -0777 -pe '@_=/\d+/g; printf "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n", splice@_,0,2; $_=pack "N*", @_; s/(.)(...)/$2$1/gs' > icon.pam 

You can pipe that ouput to pamrgbatopng (from netpbm) to get a PNG image:

xprop -id THE_WINDOW_ID ... | perl -0777 ... | pamrgbatopng > the_icon.png 

It's hacky, kinda slow, but it's something.

Credits: This is a combination of @Thomas Dickey's answer with [How to dump the icon of a running X program?](https://unix.stackexchange.com/questions/48860/how-to-dump-the-icon-of-a-running-x-program.

0
Thomas Dickey

You can't get it from wmctrl because it only knows about window properties. None of the icon-related properties in Extended Window Manager Hints tell where an icon resides. That is because it could be an in-memory pixmap (as xterm does for certain configurations since patch #282).

Presumably you already know about these properties:

But that is only a starting point. Assuming that there is an icon file, you would have to look for it in the directory tree where icons live, e.g., /usr/share/pixmaps, according to the current theme.

A similar question was asked in What's the absolute path of an icon declared in a .desktop file?, which points to

Getting the theme name is desktop-dependent. A related question (and answer) is found in desktop agnostic icon theme lookup

Так что, если я правильно интерпретирую это, приложения обычно предоставляют данные растрового изображения, которые затем используются EWMH-совместимым программным обеспечением для отображения на экране? (Спасибо, что нашли время дать подробный ответ.) dgo.a 8 лет назад 0
Немного упрощенно: большинство приложений, которые вас интересуют, загружают файлы из дерева каталогов `pixmaps`. Но нет никакой гарантии, что это так. Thomas Dickey 8 лет назад 0

Похожие вопросы