현재 포커스가 있는 컨테이너(예: "splith", "tabbed")의 레이아웃을 가져오는 방법은 무엇입니까? 가장 좋은 방법은 swaymsg -t get_tree
(아래 예)를 사용하여 JSON 출력을 구문 분석하는 것이지만 jq
이러한 "n-debth 트리"로 무엇을 해야할지 잘 모르겠습니다.
아주 기본적인 질문일지도 모르지만 json을 다루는 것은 이번이 처음입니다.
"첨부 파일": 샘플 JSON 출력swaymsg -t get-tree
이는 "focused":true 속성을 갖는 포커스된 터미널이 있는 3개의 터미널이 열려 있는 위 명령의 출력입니다.
{
"border": "none",
"current_border_width": 0,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [
3
],
"focused": false,
"fullscreen_mode": 0,
"geometry": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"id": 1,
"layout": "splith",
"marks": [],
"name": "root",
"nodes": [
{
"border": "none",
"current_border_width": 0,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [
2147483646
],
"focused": false,
"fullscreen_mode": 0,
"geometry": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"id": 2147483647,
"layout": "output",
"marks": [],
"name": "__i3",
"nodes": [
{
"border": "none",
"current_border_width": 0,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [],
"focused": false,
"fullscreen_mode": 1,
"geometry": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"id": 2147483646,
"layout": "splith",
"marks": [],
"name": "__i3_scratch",
"nodes": [],
"orientation": "horizontal",
"percent": null,
"rect": {
"height": 720,
"width": 360,
"x": 0,
"y": 0
},
"sticky": false,
"type": "workspace",
"urgent": false,
"window": null,
"window_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
}
}
],
"orientation": "horizontal",
"percent": null,
"rect": {
"height": 720,
"width": 360,
"x": 0,
"y": 0
},
"sticky": false,
"type": "output",
"urgent": false,
"window": null,
"window_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
}
},
{
"active": true,
"adaptive_sync_status": "disabled",
"border": "none",
"current_border_width": 0,
"current_mode": {
"height": 1440,
"refresh": 60006,
"width": 720
},
"current_workspace": "1",
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"dpms": false,
"floating_nodes": [],
"focus": [
30,
32
],
"focused": false,
"fullscreen_mode": 0,
"geometry": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"id": 3,
"layout": "output",
"make": "<Unknown>",
"marks": [],
"max_render_time": 0,
"model": "<Unknown>",
"modes": [
{
"height": 1440,
"refresh": 60006,
"width": 720
}
],
"name": "DSI-1",
"nodes": [
{
"border": "none",
"current_border_width": 0,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [
36,
35
],
"focused": false,
"fullscreen_mode": 1,
"geometry": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"id": 30,
"layout": "splith",
"marks": [],
"name": "1",
"nodes": [
{
"app_id": "foot",
"border": "pixel",
"current_border_width": 3,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [],
"focused": false,
"fullscreen_mode": 0,
"geometry": {
"height": 500,
"width": 700,
"x": 0,
"y": 0
},
"id": 35,
"idle_inhibitors": {
"application": "none",
"user": "none"
},
"inhibit_idle": false,
"layout": "none",
"marks": [],
"max_render_time": 0,
"name": "",
"nodes": [],
"orientation": "none",
"percent": 0.5,
"pid": 25044,
"rect": {
"height": 455,
"width": 180,
"x": 0,
"y": 25
},
"shell": "xdg_shell",
"sticky": false,
"type": "con",
"urgent": false,
"visible": true,
"window": null,
"window_rect": {
"height": 449,
"width": 174,
"x": 3,
"y": 3
}
},
{
"border": "none",
"current_border_width": 0,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [
34
],
"focused": false,
"fullscreen_mode": 0,
"geometry": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"id": 36,
"layout": "splitv",
"marks": [],
"name": null,
"nodes": [
{
"border": "none",
"current_border_width": 0,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [
27,
33
],
"focused": false,
"fullscreen_mode": 0,
"geometry": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"id": 34,
"layout": "splitv",
"marks": [],
"name": null,
"nodes": [
{
"app_id": "foot",
"border": "pixel",
"current_border_width": 3,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [],
"focused": true,
"fullscreen_mode": 0,
"geometry": {
"height": 500,
"width": 700,
"x": 0,
"y": 0
},
"id": 27,
"idle_inhibitors": {
"application": "none",
"user": "none"
},
"inhibit_idle": false,
"layout": "none",
"marks": [],
"max_render_time": 0,
"name": "",
"nodes": [],
"orientation": "none",
"percent": 0.5010989010989011,
"pid": 28522,
"rect": {
"height": 228,
"width": 180,
"x": 180,
"y": 25
},
"shell": "xdg_shell",
"sticky": false,
"type": "con",
"urgent": false,
"visible": true,
"window": null,
"window_rect": {
"height": 222,
"width": 174,
"x": 3,
"y": 3
}
},
{
"app_id": "foot",
"border": "pixel",
"current_border_width": 3,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [],
"focused": false,
"fullscreen_mode": 0,
"geometry": {
"height": 500,
"width": 700,
"x": 0,
"y": 0
},
"id": 33,
"idle_inhibitors": {
"application": "none",
"user": "none"
},
"inhibit_idle": false,
"layout": "none",
"marks": [],
"max_render_time": 0,
"name": "",
"nodes": [],
"orientation": "none",
"percent": 0.4989010989010989,
"pid": 23338,
"rect": {
"height": 227,
"width": 180,
"x": 180,
"y": 253
},
"shell": "xdg_shell",
"sticky": false,
"type": "con",
"urgent": false,
"visible": true,
"window": null,
"window_rect": {
"height": 221,
"width": 174,
"x": 3,
"y": 3
}
}
],
"orientation": "vertical",
"percent": 1,
"rect": {
"height": 455,
"width": 180,
"x": 180,
"y": 25
},
"sticky": false,
"type": "con",
"urgent": false,
"window": null,
"window_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
}
}
],
"orientation": "vertical",
"percent": 0.5,
"rect": {
"height": 455,
"width": 180,
"x": 180,
"y": 25
},
"sticky": false,
"type": "con",
"urgent": false,
"window": null,
"window_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
}
}
],
"num": 1,
"orientation": "horizontal",
"output": "DSI-1",
"percent": null,
"rect": {
"height": 455,
"width": 360,
"x": 0,
"y": 25
},
"representation": "H[foot V[V[foot foot]]]",
"sticky": false,
"type": "workspace",
"urgent": false,
"window": null,
"window_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
}
},
{
"border": "none",
"current_border_width": 0,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [
19
],
"focused": false,
"fullscreen_mode": 1,
"geometry": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"id": 32,
"layout": "splitv",
"marks": [],
"name": "4",
"nodes": [
{
"app_id": "foot",
"border": "pixel",
"current_border_width": 3,
"deco_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
},
"floating_nodes": [],
"focus": [],
"focused": false,
"fullscreen_mode": 0,
"geometry": {
"height": 500,
"width": 700,
"x": 0,
"y": 0
},
"id": 19,
"idle_inhibitors": {
"application": "none",
"user": "none"
},
"inhibit_idle": false,
"layout": "none",
"marks": [],
"max_render_time": 0,
"name": "",
"nodes": [],
"orientation": "none",
"percent": 1,
"pid": 3363,
"rect": {
"height": 455,
"width": 360,
"x": 0,
"y": 25
},
"shell": "xdg_shell",
"sticky": false,
"type": "con",
"urgent": false,
"visible": false,
"window": null,
"window_rect": {
"height": 455,
"width": 360,
"x": 0,
"y": 3
}
}
],
"num": 4,
"orientation": "vertical",
"output": "DSI-1",
"percent": null,
"rect": {
"height": 455,
"width": 360,
"x": 0,
"y": 25
},
"representation": "V[foot]",
"sticky": false,
"type": "workspace",
"urgent": false,
"window": null,
"window_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
}
}
],
"orientation": "none",
"percent": 1,
"primary": false,
"rect": {
"height": 720,
"width": 360,
"x": 0,
"y": 0
},
"scale": 2,
"scale_filter": "nearest",
"serial": "",
"sticky": false,
"transform": "normal",
"type": "output",
"urgent": false,
"window": null,
"window_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
}
}
],
"orientation": "horizontal",
"percent": null,
"rect": {
"height": 720,
"width": 360,
"x": 0,
"y": 0
},
"sticky": false,
"type": "root",
"urgent": false,
"window": null,
"window_rect": {
"height": 0,
"width": 0,
"x": 0,
"y": 0
}
}
답변1
recurse
함수를 사용하여 , 및 컨테이너 (및 중첩된 컨테이너)를 반복적 jq
으로 반복 할 수 있습니다. 이 함수를 사용하면 포커스 컨테이너만 필터링하여 키 값을 얻을 수 있습니다 .nodes
root
output
workspace
con
select
layout
swaymsg -t get_tree | jq 'recurse(.nodes[]) | select(.nodes[].focused == true).layout'