Repository navigation
Expand file tree
/
Copy pathipc_commands.cpp
More file actions
1461 lines (1381 loc) · 61.8 KB
/
Copy pathipc_commands.cpp
File metadata and controls
1461 lines (1381 loc) · 61.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "server/ipc_commands.h"
#include "config/change.h"
#include "config/config.h"
#include "input/cursor.h"
#include "input/input_capture.h"
#include "layer/layer_surface.h"
#include "output/identity.h"
#include "output/output.h"
#include "scene/effect_registry.h"
#include "scene/effect_selection.h"
#include "server/action_request.h"
#include "server/focus.h"
#include "server/ipc.h"
#include "server/server.h"
#include "view/view.h"
#include "wlr.h"
#include "workspace/scratchpad.h"
#include "workspace/workspace.h"
#include <algorithm>
#include <cctype>
#include <cmath>
#include <drm_fourcc.h>
#include <format>
#include <map>
#include <nlohmann/json.hpp>
#include <print>
#include <sstream>
#include <string>
#include <utility>
extern "C" {
#include <umbrielfx/render/effect.h>
}
namespace umbriel {
nlohmann::json IpcCommands::inputCapturePermissions(Server& server, IpcArgs /*args*/) {
auto result = nlohmann::json::array();
if (auto* capture = server.inputCapture()) {
for (const auto& permission : capture->permissions()) {
result.push_back(
{{"id", permission.id},
{"application", permission.application},
{"capabilities", permission.capabilities},
{"persist_mode", permission.persistMode}}
);
}
}
return nlohmann::json{{"ok", std::move(result)}};
}
nlohmann::json IpcCommands::inputCaptureRevoke(Server& server, IpcArgs args) {
if (args.size() != 1 || args.front().empty() || args.front().find_first_of(" \t\r\n") != std::string::npos) {
return nlohmann::json{{"err", "usage: input-capture-revoke <id|all>"}};
}
auto* capture = server.inputCapture();
if (capture == nullptr || !capture->revokePermission(args.front())) {
return nlohmann::json{{"err", "unable to revoke input capture permission (invalid id or state write failed)"}};
}
return nlohmann::json{{"ok", true}};
}
std::optional<EffectAudio> IpcCommands::parseAudioSpectrum(const nlohmann::json& request) {
if (!request.is_object()
|| request.size() != 3
|| !request.contains("cmd")
|| request["cmd"] != "effect-audio"
|| !request.contains("version")
|| !request["version"].is_number_integer()
|| request["version"] != 2
|| !request.contains("bands")
|| !request["bands"].is_array()
|| request["bands"].size() != FX_AUDIO_BANDS) {
return std::nullopt;
}
EffectAudio audio{};
for (size_t i = 0; i < FX_AUDIO_BANDS; ++i) {
const auto& band = request["bands"][i];
if (!band.is_number()) {
return std::nullopt;
}
const double value = band.get<double>();
if (std::isnan(value) || value < 0.0 || value > 1.0) {
return std::nullopt;
}
audio[i] = static_cast<float>(value);
}
audio[FX_AUDIO_BANDS] = 1.0F;
return audio;
}
namespace {
const char* layerName(uint32_t layer) {
switch (layer) {
case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND:
return "background";
case ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM:
return "bottom";
case ZWLR_LAYER_SHELL_V1_LAYER_TOP:
return "top";
case ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY:
return "overlay";
default:
return "unknown";
}
}
const char* keyboardInteractivityName(uint32_t interactivity) {
switch (interactivity) {
case ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE:
return "none";
case ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE:
return "exclusive";
case ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND:
return "on_demand";
default:
return "unknown";
}
}
constexpr std::pair<uint32_t, const char*> kLayerAnchors[] = {
{ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP, "top"},
{ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM, "bottom"},
{ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT, "left"},
{ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT, "right"},
};
// One human row per window entry; `focused-window` prints the same row for its reply.
void printWindowRow(const nlohmann::json& entry) {
const std::string appId = entry.value("app_id", "");
const std::string title = entry.value("title", "");
const std::string xdgTag = entry.value("xdg_tag", "");
const std::string xdgTagSuffix = xdgTag.empty() ? "" : " [xdg_tag=" + xdgTag + "]";
const std::string contentType = entry.value("content_type", "none");
const std::string contentTypeSuffix = contentType == "none" ? "" : " [content_type=" + contentType + "]";
const std::string scratchpad = entry.value("scratchpad", "");
const std::string scratchpadSuffix = scratchpad.empty() ? "" : " [scratchpad=" + scratchpad + "]";
const std::string_view minimizedSuffix = entry.value("minimized", false) ? " [minimized]" : "";
std::println(
"{}{}{}\t{}\t[{} {}x{}{:+}{:+}]{}{}{}{}",
entry.value("focused", false) ? "*" : (entry.value("urgent", false) ? "!" : " "),
entry.value("xwayland", false) ? "[Xwayland] " : "", appId.empty() ? "-" : appId, title.empty() ? "-" : title,
entry.value("floating", false) ? "float"
: entry.value("tabbed", false) ? "tab"
: "tile",
entry.value("w", 0), entry.value("h", 0), entry.value("x", 0), entry.value("y", 0), xdgTagSuffix,
contentTypeSuffix, scratchpadSuffix, minimizedSuffix
);
}
void printWindows(const nlohmann::json& ok) {
for (const auto& entry : ok) {
printWindowRow(entry);
}
}
nlohmann::json effectSlotJson(const EffectSlot& slot, bool border = false) {
nlohmann::json result{
{"name", slot.name},
{"pool", slot.pool},
{"source", effectSelectorSourceName(slot.source())},
{"suppressed", slot.suppressed},
};
if (border) {
const EffectPreset* preset = findEffectPreset(config().effects, slot.name);
result["overlay"] = preset != nullptr ? preset->overlay : "";
}
return result;
}
void printEffects(const nlohmann::json& ok) {
std::println("Presets\nNAME\tKIND\tSTATE\tOVERLAY");
for (const auto& preset : ok.at("presets")) {
std::println(
"{}\t{}\t{}\t{}", preset.value("name", ""), preset.value("kind", ""), preset.value("state", ""),
preset.value("overlay", "")
);
}
std::println("\nPools\nNAME\tKIND\tPOLICY\tMEMBERS (held)");
for (const auto& pool : ok.at("pools")) {
std::string members;
for (const auto& member : pool.at("members")) {
if (!members.empty()) {
members += ", ";
}
members += std::format("{} ({})", member.value("name", ""), member.value("held", size_t{0}));
}
std::println(
"{}\t{}\t{}\t{}", pool.value("name", ""), pool.value("kind", ""), pool.value("policy", ""), members
);
}
const auto printSlot = [](std::string_view owner, std::string_view kind, const nlohmann::json& slot) {
std::println(
"{}\t{}\t{}\t{}\t{}\t{}\t{}", owner, kind, slot.value("name", ""), slot.value("pool", ""),
slot.value("source", ""), slot.value("suppressed", false) ? "yes" : "no", slot.value("overlay", "")
);
};
std::println("\nCursor\nOWNER\tSLOT\tNAME\tPOOL\tSOURCE\tSUPPRESSED\tOVERLAY");
printSlot("cursor", "cursor", ok.at("cursor"));
std::println("\nOwners\nOWNER\tSLOT\tNAME\tPOOL\tSOURCE\tSUPPRESSED\tOVERLAY");
for (const auto& owner : ok.at("owners")) {
const std::string label = owner.value("type", "") == "window"
? "window " + owner.value("id", "") + " (" + owner.value("app_id", "") + ")"
: "output " + owner.value("name", "");
for (const auto& [kind, slot] : owner.at("slots").items()) {
printSlot(label, kind, slot);
}
}
}
void printWorkspaces(const nlohmann::json& ok) {
for (const auto& entry : ok) {
const std::string output = entry.value("output", "");
const std::string name = entry.value("name", "");
const std::string layout = entry.value("layout", "unknown");
std::println(
"{} {}: {} [{}]{}", entry.value("active", false) ? "*" : " ", output.empty() ? "-" : output,
name.empty() ? "-" : name, layout, entry.value("focused", false) ? " (focused)" : ""
);
}
}
void printSubmap(const nlohmann::json& ok) {
if (!ok.is_string()) {
return;
}
const std::string name = ok.get<std::string>();
std::println("{}", name.empty() ? "unnamed" : name);
}
void printKeyboardLayouts(const nlohmann::json& ok) {
const size_t currentIndex = ok.value("current_index", size_t{0});
const auto& names = ok.at("names");
for (size_t index = 0; index < names.size(); ++index) {
const std::string name = names.at(index).get<std::string>();
std::println("{} {}", index == currentIndex ? "*" : " ", name.empty() ? "-" : name);
}
}
void printLayers(const nlohmann::json& ok) {
for (const auto& entry : ok) {
const std::string layer = entry.value("layer", "");
const std::string ns = entry.value("namespace", "");
const std::string output = entry.value("output", "");
bool mapped = entry.value("mapped", false);
std::println(
"{}\t{}\t{}\t{}", layer, ns.empty() ? "-" : ns, output.empty() ? "-" : output, mapped ? "yes" : "no"
);
}
}
void printOutputName(const nlohmann::json& ok) { std::println("{}", ok.get<std::string>()); }
const char* transformName(wl_output_transform transform) {
switch (transform) {
case WL_OUTPUT_TRANSFORM_NORMAL:
return "normal";
case WL_OUTPUT_TRANSFORM_90:
return "90";
case WL_OUTPUT_TRANSFORM_180:
return "180";
case WL_OUTPUT_TRANSFORM_270:
return "270";
case WL_OUTPUT_TRANSFORM_FLIPPED:
return "flipped";
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
return "flipped-90";
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
return "flipped-180";
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
return "flipped-270";
}
return "unknown";
}
void printOutputs(const nlohmann::json& ok) {
bool first = true;
for (const auto& output : ok) {
if (!first) {
std::println("");
}
first = false;
std::println("{} \"{}\"", output.value("name", ""), output.value("description", ""));
std::println(" Enabled: {}", output.value("enabled", false) ? "yes" : "no");
std::println(" Power: {}", output.value("powered", false) ? "on" : "off");
std::println(" Focused: {}", output.value("focused", false) ? "yes" : "no");
const std::string workspace = output.value("active_workspace", "");
std::println(" Active workspace: {}", workspace.empty() ? "-" : workspace);
if (output.at("config_name").is_string()) {
std::println(" Config name: \"{}\"", output.at("config_name").get<std::string>());
std::string identity;
for (const auto& [label, key] : {std::pair{"Make", "make"}, {"Model", "model"}, {"Serial", "serial"}}) {
const std::string value = output.value(key, "");
if (value.empty()) {
continue;
}
if (!identity.empty()) {
identity += " ";
}
identity += std::format("{}: {}", label, value);
}
std::println(" {}", identity);
}
const auto& physical = output.at("physical_size");
const int widthMm = physical.value("width_mm", 0);
const int heightMm = physical.value("height_mm", 0);
if (widthMm > 0 || heightMm > 0) {
std::println(" Physical size: {}x{} mm", widthMm, heightMm);
}
const auto& position = output.at("position");
std::println(" Position: {},{}", position.value("x", 0), position.value("y", 0));
std::println(" Transform: {}", output.value("transform", "normal"));
std::println(" Scale: {:f}", output.value("scale", 1.0));
const auto& usable = output.at("usable_area");
std::println(
" Usable area: {}x{}{:+}{:+}", usable.value("width", 0), usable.value("height", 0), usable.value("x", 0),
usable.value("y", 0)
);
if (output.at("adaptive_sync").is_boolean()) {
std::println(" Adaptive sync: {}", output.at("adaptive_sync").get<bool>() ? "enabled" : "disabled");
}
std::println(" HDR: {}", output.value("hdr_active", false) ? "on" : "off");
if (const auto scanout = output.find("direct_scanout"); scanout != output.end() && scanout->is_object()) {
if (scanout->value("active", false)) {
const auto& window = scanout->at("window");
if (window.is_object()) {
std::println(
" Direct scanout: active ({} \"{}\")", window.value("app_id", ""), window.value("title", "")
);
} else {
std::println(" Direct scanout: active");
}
} else {
std::string reason = scanout->value("reason", "");
std::ranges::replace(reason, '_', ' ');
std::println(" Direct scanout: inactive ({})", reason);
}
}
const auto& modes = output.at("modes");
if (modes.empty()) {
continue;
}
std::println(" Modes:");
for (const auto& mode : modes) {
const bool preferred = mode.value("preferred", false);
const bool current = mode.value("current", false);
std::print(
" {}x{} @ {:.3f} Hz", mode.value("width", 0), mode.value("height", 0),
mode.value("refresh_mhz", 0) / 1000.0
);
if (preferred && current) {
std::print(" (preferred, current)");
} else if (preferred) {
std::print(" (preferred)");
} else if (current) {
std::print(" (current)");
}
std::println("");
}
}
}
std::string fourccName(uint32_t format) {
if (format == DRM_FORMAT_INVALID) {
return "invalid";
}
std::string name(4, '?');
for (size_t i = 0; i < name.size(); ++i) {
const auto value = static_cast<unsigned char>((format >> (i * 8)) & 0xFFU);
name[i] = std::isprint(value) != 0 ? static_cast<char>(value) : '?';
}
return name;
}
const char* transferFunctionName(wlr_color_transfer_function value) {
switch (value) {
case WLR_COLOR_TRANSFER_FUNCTION_SRGB:
return "sRGB";
case WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ:
return "PQ";
case WLR_COLOR_TRANSFER_FUNCTION_EXT_LINEAR:
return "extended linear";
case WLR_COLOR_TRANSFER_FUNCTION_GAMMA22:
return "gamma 2.2";
case WLR_COLOR_TRANSFER_FUNCTION_BT1886:
return "BT.1886";
}
return "unknown";
}
const char* primariesName(wlr_color_named_primaries value) {
switch (value) {
case WLR_COLOR_NAMED_PRIMARIES_SRGB:
return "sRGB";
case WLR_COLOR_NAMED_PRIMARIES_BT2020:
return "BT.2020";
}
return "unknown";
}
const char* protocolTransferFunctionName(uint32_t value) {
switch (value) {
case 0:
return "none";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_BT1886:
return "BT.1886";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22:
return "gamma 2.2";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28:
return "gamma 2.8";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST240:
return "ST 240";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR:
return "extended linear";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_LOG_100:
return "log 100";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_LOG_316:
return "log 316";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_XVYCC:
return "xvYCC";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB:
return "sRGB";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_SRGB:
return "extended sRGB";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ:
return "PQ";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST428:
return "ST 428";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG:
return "HLG";
case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_COMPOUND_POWER_2_4:
return "compound power 2.4";
default:
return "unknown";
}
}
const char* protocolPrimariesName(uint32_t value) {
switch (value) {
case 0:
return "none";
case WP_COLOR_MANAGER_V1_PRIMARIES_SRGB:
return "sRGB";
case WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M:
return "PAL-M";
case WP_COLOR_MANAGER_V1_PRIMARIES_PAL:
return "PAL";
case WP_COLOR_MANAGER_V1_PRIMARIES_NTSC:
return "NTSC";
case WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM:
return "generic film";
case WP_COLOR_MANAGER_V1_PRIMARIES_BT2020:
return "BT.2020";
case WP_COLOR_MANAGER_V1_PRIMARIES_CIE1931_XYZ:
return "CIE 1931 XYZ";
case WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3:
return "DCI-P3";
case WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3:
return "Display P3";
case WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB:
return "Adobe RGB";
default:
return "unknown";
}
}
nlohmann::json supportedTransferFunctions(uint32_t supported) {
nlohmann::json names = nlohmann::json::array();
constexpr wlr_color_transfer_function values[] = {
WLR_COLOR_TRANSFER_FUNCTION_SRGB, WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ,
WLR_COLOR_TRANSFER_FUNCTION_EXT_LINEAR, WLR_COLOR_TRANSFER_FUNCTION_GAMMA22,
WLR_COLOR_TRANSFER_FUNCTION_BT1886,
};
for (const auto value : values) {
if ((supported & value) != 0) {
names.push_back(transferFunctionName(value));
}
}
return names;
}
nlohmann::json supportedPrimaries(uint32_t supported) {
nlohmann::json names = nlohmann::json::array();
constexpr wlr_color_named_primaries values[] = {
WLR_COLOR_NAMED_PRIMARIES_SRGB,
WLR_COLOR_NAMED_PRIMARIES_BT2020,
};
for (const auto value : values) {
if ((supported & value) != 0) {
names.push_back(primariesName(value));
}
}
return names;
}
nlohmann::json xy(const wlr_color_cie1931_xy& value) { return {{"x", value.x}, {"y", value.y}}; }
std::string joinNames(const nlohmann::json& names) {
std::string joined;
for (const auto& name : names) {
if (!joined.empty()) {
joined += ", ";
}
joined += name.get<std::string>();
}
return joined.empty() ? "none" : joined;
}
void printColor(const nlohmann::json& ok) {
const auto& renderer = ok.at("renderer");
std::println(
"color manager: {}, renderer input transform: {}, output transform: {}, timeline: {}",
ok.value("color_manager", false) ? "yes" : "no",
renderer.value("input_color_transform", false) ? "yes" : "no",
renderer.value("output_color_transform", false) ? "yes" : "no",
renderer.value("timeline", false) ? "yes" : "no"
);
for (const auto& output : ok.at("outputs")) {
const std::string fallback = output.value("fallback_reason", "");
std::println(
"output {}: HDR mode {}, requested {}, active {}, format {}, {}, {}, SDR white {} cd/m2, SDR transfer {}",
output.value("name", ""), output.value("hdr_mode", "off"),
output.value("hdr_requested", false) ? "yes" : "no", output.value("hdr_active", false) ? "yes" : "no",
output.value("render_format", "invalid"), output.value("transfer_function", "none"),
output.value("primaries", "none"), output.value("sdr_white", 0.0), output.value("sdr_transfer", "gamma22")
);
if (!fallback.empty()) {
std::println(" fallback: {}", fallback);
}
const int configuredDepth = output.value("bit_depth", 8);
const std::string format = output.value("render_format", "invalid");
const std::string_view activeDepth = !output.value("enabled", false) ? "none"
: format == "XR30" || format == "XB30" ? "10"
: format == "XR24" || format == "XB24" ? "8"
: "unknown";
std::println(" bit depth: {} (configured {})", activeDepth, configuredDepth);
if (output.value("enabled", false) && configuredDepth != 8) {
const std::string bitFallback = output.value("bit_depth_fallback_reason", "");
if (!bitFallback.empty()) {
std::println(" 10-bit SDR unavailable: {}", bitFallback);
} else if (output.value("bit_depth_active", false)) {
std::println(" 10-bit SDR: active");
}
}
std::println(
" supported transfer functions: {}; primaries: {}", joinNames(output.at("supported_transfer_functions")),
joinNames(output.at("supported_primaries"))
);
if (output.at("mastering_luminance").is_object()) {
const auto& luminance = output.at("mastering_luminance");
std::println(
" output metadata: {} to {} cd/m2; MaxCLL: {}; MaxFALL: {}", luminance.value("min", 0.0),
luminance.value("max", 0.0), output.value("max_cll", 0.0), output.value("max_fall", 0.0)
);
} else if (output.value("hdr_active", false)) {
std::println(
" output metadata: luminance unavailable; MaxCLL: {}; MaxFALL: {}", output.value("max_cll", 0.0),
output.value("max_fall", 0.0)
);
}
}
for (const auto& surface : ok.at("surfaces")) {
std::println(
"surface {}: {} ({}) {}, {}", surface.value("id", ""), surface.value("title", ""),
surface.value("app_id", ""), surface.value("transfer_function", "none"), surface.value("primaries", "none")
);
if (surface.at("mastering_luminance").is_object()) {
const auto& luminance = surface.at("mastering_luminance");
std::println(
" mastering luminance: {} to {} cd/m2; MaxCLL: {}; MaxFALL: {}", luminance.value("min", 0.0),
luminance.value("max", 0.0), surface.value("max_cll", 0), surface.value("max_fall", 0)
);
} else {
std::println(
" mastering luminance: unset; MaxCLL: {}; MaxFALL: {}", surface.value("max_cll", 0),
surface.value("max_fall", 0)
);
}
std::println(
" mastering display primaries: {}", surface.at("mastering_display_primaries").is_object() ? "set" : "unset"
);
}
}
void printTearing(const nlohmann::json& ok) {
std::println("tearing control: {}", ok.value("protocol", false) ? "yes" : "no");
for (const auto& output : ok.at("outputs")) {
const auto& presentationVsync = output.at("last_presentation_vsync");
const auto& presentationPresented = output.at("last_presentation_presented");
const std::string presentation = presentationPresented.is_boolean() && !presentationPresented.get<bool>()
? "not presented"
: presentationVsync.is_boolean() ? (presentationVsync.get<bool>() ? "vsync" : "async")
: "unknown";
std::println(
"output {}: allowed {}, requested {}, last commit {}, last presentation {}", output.value("name", ""),
output.value("allowed", false) ? "yes" : "no", output.value("requested", false) ? "yes" : "no",
output.value("last_commit_tearing", false) ? "async" : "regular", presentation
);
if (const std::string fallback = output.value("fallback_reason", ""); !fallback.empty()) {
std::println(" fallback: {}", fallback);
}
}
for (const auto& surface : ok.at("surfaces")) {
std::string rule = "inherit";
if (surface.at("rule_override").is_boolean()) {
rule = surface.at("rule_override").get<bool>() ? "force" : "deny";
}
std::println(
"surface {}: {} ({}) output {}, hint {}, rule {}, fullscreen {}, eligible {}", surface.value("id", ""),
surface.value("title", ""), surface.value("app_id", ""), surface.value("output", ""),
surface.value("hint", "vsync"), rule, surface.value("fullscreen", false) ? "yes" : "no",
surface.value("eligible", false) ? "yes" : "no"
);
}
}
using PendingLayouts = std::map<const Workspace*, std::unique_ptr<Layout>>;
// One `windows` listing entry for `view`. `focused-window` shares this builder so its reply is
// byte-identical to the entry the listing prints for the same window.
nlohmann::json windowEntry(Server& server, View& view, PendingLayouts& pendingLayouts) {
nlohmann::json entry;
entry["id"] = view.extForeignIdentifier() != nullptr ? view.extForeignIdentifier() : "";
entry["workspace"] = view.workspace() != nullptr ? view.workspace()->id() : "";
const ScratchpadManager* scratchpads = server.scratchpadManager();
entry["scratchpad"] = scratchpads != nullptr ? std::string(scratchpads->nameFor(&view)) : std::string{};
entry["active"] = view.activated();
entry["app_id"] = view.appId() != nullptr ? view.appId() : "";
entry["title"] = view.title() != nullptr ? view.title() : "";
entry["xdg_tag"] = view.xdgTag().value_or("");
entry["content_type"] = contentTypeName(view.contentType());
entry["floating"] = view.floating();
entry["title_bar"] = view.titleBarHeight() > 0;
entry["fullscreen"] = view.scheduledFullscreen();
entry["maximized"] = view.scheduledMaximized();
entry["maximized_to_edges"] = view.maximizedToEdges();
entry["pinned"] = view.pinned();
// Pinned windows show on every workspace of their output.
entry["visible"] = view.pinned() || (view.onActiveWorkspace() && !view.tabHidden() && !view.minimized());
const Output* output = view.currentOutput();
entry["output"] = output != nullptr ? output->wlr()->name : "";
const View* parent = view.shellParent();
entry["parent"] =
parent != nullptr && parent->extForeignIdentifier() != nullptr ? parent->extForeignIdentifier() : "";
// Membership of a tab group, the tab's place among its tabs, and whether the group shows another tab.
int tabIndex = -1;
int column = -1;
int row = -1;
if (const Workspace* home = view.workspace()) {
const Layout& layout = home->layout();
const int layoutColumn = layout.columnOf(&view);
const TabGroup* group =
layoutColumn >= 0 ? tabGroupOf(layout.columns()[static_cast<size_t>(layoutColumn)], &view) : nullptr;
if (group != nullptr) {
tabIndex = layout.rowOf(&view) - static_cast<int>(group->first);
}
// Only the scrolling strip has an order of columns and rows that holds still for clients.
if (layoutColumn >= 0 && home->scrollingLayout() != nullptr) {
column = layoutColumn;
row = layout.rowOf(&view);
}
}
entry["column"] = column;
entry["row"] = row;
entry["tabbed"] = tabIndex >= 0;
entry["tab_index"] = tabIndex;
entry["tab_hidden"] = view.tabHidden();
entry["minimizable"] = view.minimizable();
entry["minimized"] = view.minimized();
entry["region"] = view.region() ? nlohmann::json(windowRegionName(*view.region())) : nlohmann::json(nullptr);
entry["border_effect"] = effectSlotJson(view.effectSlot(EffectKind::Border), true);
entry["window_effect"] = effectSlotJson(view.effectSlot(EffectKind::Window));
// Workspace-local remembered focus. Seat-global activation is reported
// separately by `active`; scratchpad windows have no workspace focus.
entry["focused"] = view.workspace() != nullptr && view.workspace()->focusedView() == &view;
entry["urgent"] = view.urgent();
entry["xwayland"] = view.xwayland();
// -1 whenever the owning process is unknown: an X11 client that publishes no _NET_WM_PID.
entry["pid"] = view.pid();
// Tiled windows report their layout slot, which the layout computes even for hidden workspaces; floats report
// their own position. Ordering a listing by these positions then matches the strip (scrolling) or tile tree
// (dwindle) regardless of visibility or in-flight animations. A fullscreen tile reports the output box it covers
// instead.
if (Workspace* workspace = view.workspace(); workspace != nullptr && workspace->layout().columnOf(&view) >= 0) {
// Preview stale targets without applying client configures, rules, or bindings.
const Layout* layout = &workspace->layout();
if (workspace->arrangePending()) {
auto [entry, inserted] = pendingLayouts.try_emplace(workspace);
if (inserted) {
entry->second = workspace->previewArrangedLayout();
}
if (entry->second != nullptr) {
layout = entry->second.get();
}
}
const wlr_box box = view.layoutFullscreen() ? workspace->fullscreenTargetBox(&view, layout)
: workspace->presentedTiledBox(&view, layout);
entry["x"] = box.x;
entry["y"] = box.y;
} else if (
(view.floating() && server.cursor()->isDraggingView(&view)) || server.cursor()->toplevelDragView() == &view
) {
// Floating and data-device toplevel drags move the scene node before
// committing the saved target.
entry["x"] = view.layoutX();
entry["y"] = view.layoutY();
} else {
entry["x"] = view.layoutTargetX();
entry["y"] = view.layoutTargetY();
}
// The size the window covers, which is its committed window geometry unless the client left that box behind a
// configure it already redrew for. Reporting the stale box would disagree with what is on screen.
const wlr_box content = view.committedContentBox();
entry["w"] = content.width;
entry["h"] = content.height;
return entry;
}
} // namespace
nlohmann::json IpcCommands::windows(Server& server, IpcArgs /*args*/) {
nlohmann::json windows = nlohmann::json::array();
PendingLayouts pendingLayouts;
for (const auto& v : server.views()) {
if (!v->mapped()) {
continue;
}
windows.push_back(windowEntry(server, *v, pendingLayouts));
}
return nlohmann::json{{"ok", windows}};
}
// The view the window actions target. The qualified call keeps the shared
// focus policy distinct from this command's own name.
nlohmann::json IpcCommands::focusedWindow(Server& server, IpcArgs /*args*/) {
View* view = umbriel::focusedWindow(server);
if (view == nullptr) {
return nlohmann::json{{"err", "no focused window"}};
}
PendingLayouts pendingLayouts;
return nlohmann::json{{"ok", windowEntry(server, *view, pendingLayouts)}};
}
nlohmann::json IpcCommands::effects(Server& server, IpcArgs /*args*/) {
nlohmann::json presets = nlohmann::json::array();
for (const auto& preset : config().effects.presets) {
nlohmann::json entry{
{"name", preset.name},
{"kind", effectKindName(preset.kind)},
{"state", server.effects().programState(preset.name)},
};
if (preset.kind == EffectKind::Border) {
entry["overlay"] = preset.overlay;
}
presets.push_back(std::move(entry));
}
nlohmann::json pools = nlohmann::json::array();
for (const auto& pool : config().effects.pools) {
const auto counts = server.effectHoldCounts(pool);
nlohmann::json members = nlohmann::json::array();
for (size_t index = 0; index < pool.members.size(); ++index) {
members.push_back({{"name", pool.members[index]}, {"held", counts[index]}});
}
pools.push_back(
{{"name", pool.name},
{"kind", effectKindName(pool.kind)},
{"policy", effectSelectionPolicyName(pool.selection)},
{"members", std::move(members)}}
);
}
nlohmann::json owners = nlohmann::json::array();
for (const View* view : server.sortedEffectViews()) {
const char* id = view->extForeignIdentifier();
owners.push_back({
{"type", "window"},
{"id", id != nullptr ? id : ""},
{"app_id", view->appId() != nullptr ? view->appId() : ""},
{"slots",
{{"border", effectSlotJson(view->effectSlot(EffectKind::Border), true)},
{"window", effectSlotJson(view->effectSlot(EffectKind::Window))}}},
});
}
std::vector<const Output*> outputs;
for (const auto& output : server.outputs()) {
outputs.push_back(output.get());
}
std::ranges::sort(outputs, {}, [](const Output* output) { return std::string_view(output->wlr()->name); });
for (const Output* output : outputs) {
owners.push_back(
{{"type", "output"},
{"name", output->wlr()->name},
{"slots", {{"screen", effectSlotJson(output->screenEffectSlot())}}}}
);
}
return nlohmann::json{
{"ok",
{{"presets", std::move(presets)},
{"pools", std::move(pools)},
{"cursor", effectSlotJson(server.cursorEffectSlot())},
{"owners", std::move(owners)}}}
};
}
nlohmann::json IpcCommands::workspaces(Server& server, IpcArgs /*args*/) {
nlohmann::json workspaces = nlohmann::json::array();
const Output* preferred = server.outputFromWlr(server.preferredOutput());
for (const auto& output : server.outputs()) {
WorkspaceGroup* group = output->workspaceGroup();
if (group == nullptr) {
continue;
}
for (size_t index = 0; index < group->workspaceCount(); ++index) {
Workspace* workspace = group->workspaceAt(index);
if (workspace == nullptr) {
continue;
}
const auto& views = workspace->allViews();
const View* focusedView = workspace->focusedView();
const char* focusedId =
focusedView != nullptr && focusedView->mapped() ? focusedView->extForeignIdentifier() : nullptr;
workspaces.push_back({
{"id", workspace->id()},
{"name", workspace->name()},
{"named", workspace->named()},
{"index", workspace->index() + 1},
{"output", output->wlr()->name},
{"active", workspace->active()},
{"focused", output.get() == preferred && workspace->active()},
{"occupied", workspace->occupied()},
{"window_count",
std::ranges::count_if(views, [](const View* view) { return view->mapped() && !view->pinned(); })},
{"focused_window", focusedId != nullptr ? focusedId : ""},
{"urgent", std::ranges::any_of(views, [](const View* view) { return view->urgent(); })},
{"layout", std::string(layoutModeName(workspace->layoutMode()))},
{"layout_override", workspace->layoutModeOverride().has_value()},
});
}
}
return nlohmann::json{{"ok", workspaces}};
}
nlohmann::json IpcCommands::submap(Server& server, IpcArgs /*args*/) {
nlohmann::json active = nullptr;
if (server.inSubmap()) {
active = server.activeSubmap();
}
return nlohmann::json{{"ok", std::move(active)}};
}
nlohmann::json IpcCommands::layers(Server& server, IpcArgs /*args*/) {
nlohmann::json layers = nlohmann::json::array();
for (const auto& l : server.layerSurfaces()) {
auto* s = l->layerSurface();
if (s == nullptr) {
continue;
}
nlohmann::json entry;
const wlr_layer_surface_v1_state& state = s->current;
entry["layer"] = layerName(state.layer);
entry["namespace"] = s->namespace_ != nullptr ? s->namespace_ : "";
entry["output"] = s->output != nullptr ? s->output->name : "";
entry["mapped"] = l->mapped();
entry["pid"] = surfaceClientPid(s->surface);
entry["keyboard_interactivity"] = keyboardInteractivityName(state.keyboard_interactive);
entry["focused"] = l->hasKeyboardFocus();
entry["exclusive_zone"] = state.exclusive_zone;
nlohmann::json anchor = nlohmann::json::array();
for (const auto& [edge, name] : kLayerAnchors) {
if ((state.anchor & edge) != 0) {
anchor.push_back(name);
}
}
entry["anchor"] = std::move(anchor);
entry["margin"] = {
{"top", state.margin.top},
{"right", state.margin.right},
{"bottom", state.margin.bottom},
{"left", state.margin.left},
};
// Layout coordinates of the arranged surface; zero until its first arrange.
int x = 0;
int y = 0;
if (l->scene() != nullptr) {
wlr_scene_node_coords(&l->scene()->tree->node, &x, &y);
}
entry["x"] = x;
entry["y"] = y;
entry["w"] = state.actual_width;
entry["h"] = state.actual_height;
layers.push_back(std::move(entry));
}
return nlohmann::json{{"ok", layers}};
}
nlohmann::json IpcCommands::outputs(Server& server, IpcArgs /*args*/) {
nlohmann::json outputs = nlohmann::json::array();
const Output* preferred = server.outputFromWlr(server.preferredOutput());
for (const auto& output : server.outputs()) {
wlr_output* wlrOutput = output->wlr();
nlohmann::json modes = nlohmann::json::array();
wlr_output_mode* mode = nullptr;
wl_list_for_each(mode, &wlrOutput->modes, link) {
modes.push_back({
{"width", mode->width},
{"height", mode->height},
{"refresh_mhz", mode->refresh},
{"preferred", mode->preferred},
{"current", mode == wlrOutput->current_mode},
});
}
// A custom mode (virtual outputs, `output-create` sizes) is listed as the current one.
if (wlrOutput->current_mode == nullptr && wlrOutput->width > 0 && wlrOutput->height > 0) {
modes.push_back({
{"width", wlrOutput->width},
{"height", wlrOutput->height},
{"refresh_mhz", wlrOutput->refresh},
{"preferred", false},
{"current", true},
});
}
// Unknown when the output can neither change nor report variable refresh.
nlohmann::json adaptiveSync = nullptr;
const bool adaptiveSyncEnabled = wlrOutput->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED;
if (wlrOutput->adaptive_sync_supported || adaptiveSyncEnabled) {
adaptiveSync = adaptiveSyncEnabled;
}
const OutputIdentity identity = output->identity();
const bool hasIdentity = !identity.make.empty() || !identity.model.empty() || !identity.serial.empty();
const bool desktopEnabled = output->desktopEnabled();
const wlr_box layoutBox = output->layoutBox();
const wlr_box usable = desktopEnabled ? output->usableArea() : wlr_box{};
const WorkspaceGroup* group = output->workspaceGroup();
const Workspace* activeWorkspace = group != nullptr ? group->active() : nullptr;
// Unknown while the output is off: nothing is drawn to scan out.
nlohmann::json directScanout = nullptr;
if (desktopEnabled && !output->dpmsOff()) {
const DirectScanoutState& scanout = output->directScanout();
const DirectScanoutTracker& tracker = output->directScanoutTracker();
nlohmann::json window = nullptr;
if (scanout.active && !scanout.windowId.empty()) {
window = {{"id", scanout.windowId}, {"app_id", scanout.appId}, {"title", scanout.title}};
}
directScanout = {
{"active", scanout.active},
{"reason", scanout.active ? nlohmann::json(nullptr) : nlohmann::json(scanout.reason)},
{"window", std::move(window)},
{"commits", tracker.commits()},
{"scanout_commits", tracker.scanoutCommits()},
{"commit_seq", tracker.commitSeq()},
};
}
outputs.push_back({
{"name", wlrOutput->name},
{"description", wlrOutput->description != nullptr ? wlrOutput->description : ""},
{"make", identity.make},
{"model", identity.model},
{"serial", identity.serial},
{"config_name", hasIdentity ? nlohmann::json(outputDescriptor(identity)) : nlohmann::json(nullptr)},
{"physical_size", {{"width_mm", wlrOutput->phys_width}, {"height_mm", wlrOutput->phys_height}}},
{"enabled", desktopEnabled},
{"powered", desktopEnabled && !output->dpmsOff()},
{"focused", output.get() == preferred},
{"active_workspace", activeWorkspace != nullptr ? activeWorkspace->id() : ""},
{"position", {{"x", layoutBox.x}, {"y", layoutBox.y}}},
{"logical_size",
{{"width", desktopEnabled ? layoutBox.width : 0}, {"height", desktopEnabled ? layoutBox.height : 0}}},
{"usable_area", {{"x", usable.x}, {"y", usable.y}, {"width", usable.width}, {"height", usable.height}}},
{"transform", transformName(wlrOutput->transform)},
{"scale", wlrOutput->scale},
{"adaptive_sync", std::move(adaptiveSync)},
{"hdr_active", output->hdrActive()},
{"direct_scanout", std::move(directScanout)},
{"modes", std::move(modes)},
});
}
return nlohmann::json{{"ok", outputs}};
}
nlohmann::json IpcCommands::color(Server& server, IpcArgs /*args*/) {
nlohmann::json outputs = nlohmann::json::array();
for (const auto& output : server.outputs()) {
const wlr_output* wlrOutput = output->wlr();
const wlr_output_image_description* description = wlrOutput->image_description;
const bool hdrRequested = output->hdrRequested();
nlohmann::json entry = {
{"name", wlrOutput->name},
{"enabled", wlrOutput->enabled},
{"hdr_mode", hdrModeName(output->hdrMode())},
{"hdr_requested", hdrRequested},
{"hdr_active", output->hdrActive()},
{"fallback_reason", hdrRequested ? output->hdrFallbackReason() : ""},
{"render_format", fourccName(wlrOutput->render_format)},
{"transfer_function", description != nullptr ? transferFunctionName(description->transfer_function) : "none"},
{"primaries", description != nullptr ? primariesName(description->primaries) : "none"},