tony / oxwm

Merge pull request #24 from tonybanters/optimizations-multi-monitor Browse files
Multi Monitor Support + Optimizations
Tony, btw. committed 2025-10-25 parents 0b23d5f f82213a commit 7209679a4efc76519a462b12e2bb782eb9282f19
Showing 15 changed files with 1226 additions and 291 deletions. UnifiedSplit
+45 −109 Cargo.lock
@@ -13,9 +13,9 @@ dependencies = [
13 13
14 [[package]] 14 [[package]]
15 name = "anyhow" 15 name = "anyhow"
16 -version = "1.0.99" 16 +version = "1.0.100"
17 source = "registry+https://github.com/rust-lang/crates.io-index" 17 source = "registry+https://github.com/rust-lang/crates.io-index"
18 -checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" 18 +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
19 19
20 [[package]] 20 [[package]]
21 name = "autocfg" 21 name = "autocfg"
@@ -31,11 +31,11 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
31 31
32 [[package]] 32 [[package]]
33 name = "bitflags" 33 name = "bitflags"
34 -version = "2.9.4" 34 +version = "2.10.0"
35 source = "registry+https://github.com/rust-lang/crates.io-index" 35 source = "registry+https://github.com/rust-lang/crates.io-index"
36 -checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" 36 +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
37 dependencies = [ 37 dependencies = [
38 - "serde", 38 + "serde_core",
39 ] 39 ]
40 40
41 [[package]] 41 [[package]]
@@ -46,9 +46,9 @@ checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
46 46
47 [[package]] 47 [[package]]
48 name = "cc" 48 name = "cc"
49 -version = "1.2.40" 49 +version = "1.2.41"
50 source = "registry+https://github.com/rust-lang/crates.io-index" 50 source = "registry+https://github.com/rust-lang/crates.io-index"
51 -checksum = "e1d05d92f4b1fd76aad469d46cdd858ca761576082cd37df81416691e50199fb" 51 +checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7"
52 dependencies = [ 52 dependencies = [
53 "find-msvc-tools", 53 "find-msvc-tools",
54 "shlex", 54 "shlex",
@@ -56,9 +56,9 @@ dependencies = [
56 56
57 [[package]] 57 [[package]]
58 name = "cfg-if" 58 name = "cfg-if"
59 -version = "1.0.3" 59 +version = "1.0.4"
60 source = "registry+https://github.com/rust-lang/crates.io-index" 60 source = "registry+https://github.com/rust-lang/crates.io-index"
61 -checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" 61 +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
62 62
63 [[package]] 63 [[package]]
64 name = "chrono" 64 name = "chrono"
@@ -107,23 +107,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
107 checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" 107 checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
108 dependencies = [ 108 dependencies = [
109 "libc", 109 "libc",
110 - "windows-sys 0.61.0", 110 + "windows-sys 0.61.2",
111 ] 111 ]
112 112
113 [[package]] 113 [[package]]
114 name = "find-msvc-tools" 114 name = "find-msvc-tools"
115 -version = "0.1.3" 115 +version = "0.1.4"
116 source = "registry+https://github.com/rust-lang/crates.io-index" 116 source = "registry+https://github.com/rust-lang/crates.io-index"
117 -checksum = "0399f9d26e5191ce32c498bebd31e7a3ceabc2745f0ac54af3f335126c3f24b3" 117 +checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
118 118
119 [[package]] 119 [[package]]
120 name = "gethostname" 120 name = "gethostname"
121 -version = "1.0.2" 121 +version = "1.1.0"
122 source = "registry+https://github.com/rust-lang/crates.io-index" 122 source = "registry+https://github.com/rust-lang/crates.io-index"
123 -checksum = "fc257fdb4038301ce4b9cd1b3b51704509692bb3ff716a410cbd07925d9dae55" 123 +checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"
124 dependencies = [ 124 dependencies = [
125 "rustix", 125 "rustix",
126 - "windows-targets 0.52.6", 126 + "windows-link",
127 ] 127 ]
128 128
129 [[package]] 129 [[package]]
@@ -173,9 +173,9 @@ dependencies = [
173 173
174 [[package]] 174 [[package]]
175 name = "libc" 175 name = "libc"
176 -version = "0.2.175" 176 +version = "0.2.177"
177 source = "registry+https://github.com/rust-lang/crates.io-index" 177 source = "registry+https://github.com/rust-lang/crates.io-index"
178 -checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" 178 +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
179 179
180 [[package]] 180 [[package]]
181 name = "libredox" 181 name = "libredox"
@@ -222,7 +222,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
222 222
223 [[package]] 223 [[package]]
224 name = "oxwm" 224 name = "oxwm"
225 -version = "0.2.0" 225 +version = "0.3.0"
226 dependencies = [ 226 dependencies = [
227 "anyhow", 227 "anyhow",
228 "chrono", 228 "chrono",
@@ -290,7 +290,7 @@ dependencies = [
290 "errno", 290 "errno",
291 "libc", 291 "libc",
292 "linux-raw-sys", 292 "linux-raw-sys",
293 - "windows-sys 0.61.0", 293 + "windows-sys 0.61.2",
294 ] 294 ]
295 295
296 [[package]] 296 [[package]]
@@ -337,9 +337,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
337 337
338 [[package]] 338 [[package]]
339 name = "syn" 339 name = "syn"
340 -version = "2.0.106" 340 +version = "2.0.107"
341 source = "registry+https://github.com/rust-lang/crates.io-index" 341 source = "registry+https://github.com/rust-lang/crates.io-index"
342 -checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" 342 +checksum = "2a26dbd934e5451d21ef060c018dae56fc073894c5a7896f882928a76e6d081b"
343 dependencies = [ 343 dependencies = [
344 "proc-macro2", 344 "proc-macro2",
345 "quote", 345 "quote",
@@ -368,9 +368,9 @@ dependencies = [
368 368
369 [[package]] 369 [[package]]
370 name = "unicode-ident" 370 name = "unicode-ident"
371 -version = "1.0.19" 371 +version = "1.0.20"
372 source = "registry+https://github.com/rust-lang/crates.io-index" 372 source = "registry+https://github.com/rust-lang/crates.io-index"
373 -checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" 373 +checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06"
374 374
375 [[package]] 375 [[package]]
376 name = "wasi" 376 name = "wasi"
@@ -439,9 +439,9 @@ dependencies = [
439 439
440 [[package]] 440 [[package]]
441 name = "windows-core" 441 name = "windows-core"
442 -version = "0.62.1" 442 +version = "0.62.2"
443 source = "registry+https://github.com/rust-lang/crates.io-index" 443 source = "registry+https://github.com/rust-lang/crates.io-index"
444 -checksum = "6844ee5416b285084d3d3fffd743b925a6c9385455f64f6d4fa3031c4c2749a9" 444 +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
445 dependencies = [ 445 dependencies = [
446 "windows-implement", 446 "windows-implement",
447 "windows-interface", 447 "windows-interface",
@@ -452,9 +452,9 @@ dependencies = [
452 452
453 [[package]] 453 [[package]]
454 name = "windows-implement" 454 name = "windows-implement"
455 -version = "0.60.1" 455 +version = "0.60.2"
456 source = "registry+https://github.com/rust-lang/crates.io-index" 456 source = "registry+https://github.com/rust-lang/crates.io-index"
457 -checksum = "edb307e42a74fb6de9bf3a02d9712678b22399c87e6fa869d6dfcd8c1b7754e0" 457 +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
458 dependencies = [ 458 dependencies = [
459 "proc-macro2", 459 "proc-macro2",
460 "quote", 460 "quote",
@@ -463,9 +463,9 @@ dependencies = [
463 463
464 [[package]] 464 [[package]]
465 name = "windows-interface" 465 name = "windows-interface"
466 -version = "0.59.2" 466 +version = "0.59.3"
467 source = "registry+https://github.com/rust-lang/crates.io-index" 467 source = "registry+https://github.com/rust-lang/crates.io-index"
468 -checksum = "c0abd1ddbc6964ac14db11c7213d6532ef34bd9aa042c2e5935f59d7908b46a5" 468 +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
469 dependencies = [ 469 dependencies = [
470 "proc-macro2", 470 "proc-macro2",
471 "quote", 471 "quote",
@@ -474,24 +474,24 @@ dependencies = [
474 474
475 [[package]] 475 [[package]]
476 name = "windows-link" 476 name = "windows-link"
477 -version = "0.2.0" 477 +version = "0.2.1"
478 source = "registry+https://github.com/rust-lang/crates.io-index" 478 source = "registry+https://github.com/rust-lang/crates.io-index"
479 -checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" 479 +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
480 480
481 [[package]] 481 [[package]]
482 name = "windows-result" 482 name = "windows-result"
483 -version = "0.4.0" 483 +version = "0.4.1"
484 source = "registry+https://github.com/rust-lang/crates.io-index" 484 source = "registry+https://github.com/rust-lang/crates.io-index"
485 -checksum = "7084dcc306f89883455a206237404d3eaf961e5bd7e0f312f7c91f57eb44167f" 485 +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
486 dependencies = [ 486 dependencies = [
487 "windows-link", 487 "windows-link",
488 ] 488 ]
489 489
490 [[package]] 490 [[package]]
491 name = "windows-strings" 491 name = "windows-strings"
492 -version = "0.5.0" 492 +version = "0.5.1"
493 source = "registry+https://github.com/rust-lang/crates.io-index" 493 source = "registry+https://github.com/rust-lang/crates.io-index"
494 -checksum = "7218c655a553b0bed4426cf54b20d7ba363ef543b52d515b3e48d7fd55318dda" 494 +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
495 dependencies = [ 495 dependencies = [
496 "windows-link", 496 "windows-link",
497 ] 497 ]
@@ -502,14 +502,14 @@ version = "0.48.0"
502 source = "registry+https://github.com/rust-lang/crates.io-index" 502 source = "registry+https://github.com/rust-lang/crates.io-index"
503 checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" 503 checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
504 dependencies = [ 504 dependencies = [
505 - "windows-targets 0.48.5", 505 + "windows-targets",
506 ] 506 ]
507 507
508 [[package]] 508 [[package]]
509 name = "windows-sys" 509 name = "windows-sys"
510 -version = "0.61.0" 510 +version = "0.61.2"
511 source = "registry+https://github.com/rust-lang/crates.io-index" 511 source = "registry+https://github.com/rust-lang/crates.io-index"
512 -checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa" 512 +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
513 dependencies = [ 513 dependencies = [
514 "windows-link", 514 "windows-link",
515 ] 515 ]
@@ -520,29 +520,13 @@ version = "0.48.5"
520 source = "registry+https://github.com/rust-lang/crates.io-index" 520 source = "registry+https://github.com/rust-lang/crates.io-index"
521 checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" 521 checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
522 dependencies = [ 522 dependencies = [
523 - "windows_aarch64_gnullvm 0.48.5", 523 + "windows_aarch64_gnullvm",
524 - "windows_aarch64_msvc 0.48.5", 524 + "windows_aarch64_msvc",
525 - "windows_i686_gnu 0.48.5", 525 + "windows_i686_gnu",
526 - "windows_i686_msvc 0.48.5", 526 + "windows_i686_msvc",
527 - "windows_x86_64_gnu 0.48.5", 527 + "windows_x86_64_gnu",
528 - "windows_x86_64_gnullvm 0.48.5", 528 + "windows_x86_64_gnullvm",
529 - "windows_x86_64_msvc 0.48.5", 529 + "windows_x86_64_msvc",
530 -]
531 -
532 -[[package]]
533 -name = "windows-targets"
534 -version = "0.52.6"
535 -source = "registry+https://github.com/rust-lang/crates.io-index"
536 -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
537 -dependencies = [
538 - "windows_aarch64_gnullvm 0.52.6",
539 - "windows_aarch64_msvc 0.52.6",
540 - "windows_i686_gnu 0.52.6",
541 - "windows_i686_gnullvm",
542 - "windows_i686_msvc 0.52.6",
543 - "windows_x86_64_gnu 0.52.6",
544 - "windows_x86_64_gnullvm 0.52.6",
545 - "windows_x86_64_msvc 0.52.6",
546 ] 530 ]
547 531
548 [[package]] 532 [[package]]
@@ -551,90 +535,42 @@ version = "0.48.5"
551 source = "registry+https://github.com/rust-lang/crates.io-index" 535 source = "registry+https://github.com/rust-lang/crates.io-index"
552 checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" 536 checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
553 537
554 -[[package]]
555 -name = "windows_aarch64_gnullvm"
556 -version = "0.52.6"
557 -source = "registry+https://github.com/rust-lang/crates.io-index"
558 -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
559 -
560 [[package]] 538 [[package]]
561 name = "windows_aarch64_msvc" 539 name = "windows_aarch64_msvc"
562 version = "0.48.5" 540 version = "0.48.5"
563 source = "registry+https://github.com/rust-lang/crates.io-index" 541 source = "registry+https://github.com/rust-lang/crates.io-index"
564 checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" 542 checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
565 543
566 -[[package]]
567 -name = "windows_aarch64_msvc"
568 -version = "0.52.6"
569 -source = "registry+https://github.com/rust-lang/crates.io-index"
570 -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
571 -
572 [[package]] 544 [[package]]
573 name = "windows_i686_gnu" 545 name = "windows_i686_gnu"
574 version = "0.48.5" 546 version = "0.48.5"
575 source = "registry+https://github.com/rust-lang/crates.io-index" 547 source = "registry+https://github.com/rust-lang/crates.io-index"
576 checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" 548 checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
577 549
578 -[[package]]
579 -name = "windows_i686_gnu"
580 -version = "0.52.6"
581 -source = "registry+https://github.com/rust-lang/crates.io-index"
582 -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
583 -
584 -[[package]]
585 -name = "windows_i686_gnullvm"
586 -version = "0.52.6"
587 -source = "registry+https://github.com/rust-lang/crates.io-index"
588 -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
589 -
590 [[package]] 550 [[package]]
591 name = "windows_i686_msvc" 551 name = "windows_i686_msvc"
592 version = "0.48.5" 552 version = "0.48.5"
593 source = "registry+https://github.com/rust-lang/crates.io-index" 553 source = "registry+https://github.com/rust-lang/crates.io-index"
594 checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" 554 checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
595 555
596 -[[package]]
597 -name = "windows_i686_msvc"
598 -version = "0.52.6"
599 -source = "registry+https://github.com/rust-lang/crates.io-index"
600 -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
601 -
602 [[package]] 556 [[package]]
603 name = "windows_x86_64_gnu" 557 name = "windows_x86_64_gnu"
604 version = "0.48.5" 558 version = "0.48.5"
605 source = "registry+https://github.com/rust-lang/crates.io-index" 559 source = "registry+https://github.com/rust-lang/crates.io-index"
606 checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" 560 checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
607 561
608 -[[package]]
609 -name = "windows_x86_64_gnu"
610 -version = "0.52.6"
611 -source = "registry+https://github.com/rust-lang/crates.io-index"
612 -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
613 -
614 [[package]] 562 [[package]]
615 name = "windows_x86_64_gnullvm" 563 name = "windows_x86_64_gnullvm"
616 version = "0.48.5" 564 version = "0.48.5"
617 source = "registry+https://github.com/rust-lang/crates.io-index" 565 source = "registry+https://github.com/rust-lang/crates.io-index"
618 checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" 566 checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
619 567
620 -[[package]]
621 -name = "windows_x86_64_gnullvm"
622 -version = "0.52.6"
623 -source = "registry+https://github.com/rust-lang/crates.io-index"
624 -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
625 -
626 [[package]] 568 [[package]]
627 name = "windows_x86_64_msvc" 569 name = "windows_x86_64_msvc"
628 version = "0.48.5" 570 version = "0.48.5"
629 source = "registry+https://github.com/rust-lang/crates.io-index" 571 source = "registry+https://github.com/rust-lang/crates.io-index"
630 checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" 572 checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
631 573
632 -[[package]]
633 -name = "windows_x86_64_msvc"
634 -version = "0.52.6"
635 -source = "registry+https://github.com/rust-lang/crates.io-index"
636 -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
637 -
638 [[package]] 574 [[package]]
639 name = "x11" 575 name = "x11"
640 version = "2.21.0" 576 version = "2.21.0"
+2 −2 Cargo.toml
@@ -1,6 +1,6 @@
1 [package] 1 [package]
2 name = "oxwm" 2 name = "oxwm"
3 -version = "0.2.0" 3 +version = "0.3.0"
4 edition = "2024" 4 edition = "2024"
5 5
6 [lib] 6 [lib]
@@ -13,7 +13,7 @@ path = "src/bin/main.rs"
13 13
14 [dependencies] 14 [dependencies]
15 x11 = { version = "2.21", features = ["xlib", "xft"] } 15 x11 = { version = "2.21", features = ["xlib", "xft"] }
16 -x11rb = { version = "0.13", features = ["cursor"] } 16 +x11rb = { version = "0.13", features = ["cursor", "xinerama"] }
17 anyhow = "1" 17 anyhow = "1"
18 chrono = "0.4" 18 chrono = "0.4"
19 dirs = "5.0" 19 dirs = "5.0"
+7 −2 justfile
@@ -19,12 +19,17 @@ test-clean:
19 pkill Xephyr || true 19 pkill Xephyr || true
20 rm -rf ~/.config/oxwm 20 rm -rf ~/.config/oxwm
21 Xephyr -screen 1280x800 :1 & sleep 1 21 Xephyr -screen 1280x800 :1 & sleep 1
22 - DISPLAY=:1 cargo run --release 22 + DISPLAY=:1 cargo run --release -- --config test-config.ron
23 23
24 test: 24 test:
25 pkill Xephyr || true 25 pkill Xephyr || true
26 Xephyr -screen 1280x800 :1 & sleep 1 26 Xephyr -screen 1280x800 :1 & sleep 1
27 - DISPLAY=:1 cargo run --release 27 + DISPLAY=:1 cargo run --release -- --config test-config.ron
28 +
29 +test-multimon:
30 + pkill Xephyr || true
31 + Xephyr +xinerama -screen 640x480 -screen 640x480 :1 & sleep 1
32 + DISPLAY=:1 cargo run --release -- --config test-config.ron
28 33
29 init: 34 init:
30 cargo run --release -- --init 35 cargo run --release -- --init
+20 −25 src/bar/bar.rs
@@ -14,9 +14,7 @@ pub struct Bar {
14 height: u16, 14 height: u16,
15 graphics_context: Gcontext, 15 graphics_context: Gcontext,
16 16
17 - font: Font,
18 font_draw: FontDraw, 17 font_draw: FontDraw,
19 - display: *mut x11::xlib::Display,
20 18
21 tag_widths: Vec<u16>, 19 tag_widths: Vec<u16>,
22 needs_redraw: bool, 20 needs_redraw: bool,
@@ -38,27 +36,23 @@ impl Bar {
38 screen: &Screen, 36 screen: &Screen,
39 screen_num: usize, 37 screen_num: usize,
40 config: &Config, 38 config: &Config,
39 + display: *mut x11::xlib::Display,
40 + font: &Font,
41 + x: i16,
42 + y: i16,
43 + width: u16,
41 ) -> Result<Self, X11Error> { 44 ) -> Result<Self, X11Error> {
42 let window = connection.generate_id()?; 45 let window = connection.generate_id()?;
43 let graphics_context = connection.generate_id()?; 46 let graphics_context = connection.generate_id()?;
44 47
45 - let width = screen.width_in_pixels;
46 -
47 - let display = unsafe { x11::xlib::XOpenDisplay(std::ptr::null()) };
48 - if display.is_null() {
49 - return Err(X11Error::DisplayOpenFailed.into());
50 - }
51 -
52 - let font = Font::new(display, screen_num as i32, &config.font)?;
53 -
54 let height = (font.height() as f32 * 1.4) as u16; 48 let height = (font.height() as f32 * 1.4) as u16;
55 49
56 connection.create_window( 50 connection.create_window(
57 COPY_DEPTH_FROM_PARENT, 51 COPY_DEPTH_FROM_PARENT,
58 window, 52 window,
59 screen.root, 53 screen.root,
60 - 0, 54 + x,
61 - 0, 55 + y,
62 width, 56 width,
63 height, 57 height,
64 0, 58 0,
@@ -116,9 +110,7 @@ impl Bar {
116 width, 110 width,
117 height, 111 height,
118 graphics_context, 112 graphics_context,
119 - font,
120 font_draw, 113 font_draw,
121 - display,
122 tag_widths, 114 tag_widths,
123 needs_redraw: true, 115 needs_redraw: true,
124 blocks, 116 blocks,
@@ -174,8 +166,11 @@ impl Bar {
174 pub fn draw( 166 pub fn draw(
175 &mut self, 167 &mut self,
176 connection: &RustConnection, 168 connection: &RustConnection,
169 + font: &Font,
170 + display: *mut x11::xlib::Display,
177 current_tags: u32, 171 current_tags: u32,
178 occupied_tags: u32, 172 occupied_tags: u32,
173 + draw_blocks: bool,
179 ) -> Result<(), X11Error> { 174 ) -> Result<(), X11Error> {
180 if !self.needs_redraw { 175 if !self.needs_redraw {
181 return Ok(()); 176 return Ok(());
@@ -213,17 +208,17 @@ impl Bar {
213 &self.scheme_normal 208 &self.scheme_normal
214 }; 209 };
215 210
216 - let text_width = self.font.text_width(tag); 211 + let text_width = font.text_width(tag);
217 let text_x = x_position + ((tag_width - text_width) / 2) as i16; 212 let text_x = x_position + ((tag_width - text_width) / 2) as i16;
218 213
219 let top_padding = 4; 214 let top_padding = 4;
220 - let text_y = top_padding + self.font.ascent(); 215 + let text_y = top_padding + font.ascent();
221 216
222 self.font_draw 217 self.font_draw
223 - .draw_text(&self.font, scheme.foreground, text_x, text_y, tag); 218 + .draw_text(font, scheme.foreground, text_x, text_y, tag);
224 219
225 if is_selected { 220 if is_selected {
226 - let font_height = self.font.height(); 221 + let font_height = font.height();
227 let underline_height = font_height / 8; 222 let underline_height = font_height / 8;
228 let bottom_gap = 3; 223 let bottom_gap = 3;
229 let underline_y = self.height as i16 - underline_height as i16 - bottom_gap; 224 let underline_y = self.height as i16 - underline_height as i16 - bottom_gap;
@@ -251,23 +246,23 @@ impl Bar {
251 x_position += tag_width as i16; 246 x_position += tag_width as i16;
252 } 247 }
253 248
254 - if !self.status_text.is_empty() { 249 + if draw_blocks && !self.status_text.is_empty() {
255 let padding = 10; 250 let padding = 10;
256 let mut x_position = self.width as i16 - padding; 251 let mut x_position = self.width as i16 - padding;
257 252
258 for (i, block) in self.blocks.iter_mut().enumerate().rev() { 253 for (i, block) in self.blocks.iter_mut().enumerate().rev() {
259 if let Ok(text) = block.content() { 254 if let Ok(text) = block.content() {
260 - let text_width = self.font.text_width(&text); 255 + let text_width = font.text_width(&text);
261 x_position -= text_width as i16; 256 x_position -= text_width as i16;
262 257
263 let top_padding = 4; 258 let top_padding = 4;
264 - let text_y = top_padding + self.font.ascent(); 259 + let text_y = top_padding + font.ascent();
265 260
266 self.font_draw 261 self.font_draw
267 - .draw_text(&self.font, block.color(), x_position, text_y, &text); 262 + .draw_text(font, block.color(), x_position, text_y, &text);
268 263
269 if self.block_underlines[i] { 264 if self.block_underlines[i] {
270 - let font_height = self.font.height(); 265 + let font_height = font.height();
271 let underline_height = font_height / 8; 266 let underline_height = font_height / 8;
272 let bottom_gap = 3; 267 let bottom_gap = 3;
273 let underline_y = self.height as i16 - underline_height as i16 - bottom_gap; 268 let underline_y = self.height as i16 - underline_height as i16 - bottom_gap;
@@ -297,7 +292,7 @@ impl Bar {
297 } 292 }
298 connection.flush()?; 293 connection.flush()?;
299 unsafe { 294 unsafe {
300 - x11::xlib::XFlush(self.display); 295 + x11::xlib::XFlush(display);
301 } 296 }
302 self.needs_redraw = false; 297 self.needs_redraw = false;
303 298
+1 −1 src/bar/mod.rs
@@ -1,6 +1,6 @@
1 mod bar; 1 mod bar;
2 mod blocks; 2 mod blocks;
3 -mod font; 3 +pub mod font;
4 4
5 pub use bar::Bar; 5 pub use bar::Bar;
6 pub use blocks::{BlockCommand, BlockConfig}; 6 pub use blocks::{BlockCommand, BlockConfig};
+27 −12 src/bin/main.rs
@@ -4,6 +4,8 @@ use std::path::PathBuf;
4 fn main() -> Result<()> { 4 fn main() -> Result<()> {
5 let args: Vec<String> = std::env::args().collect(); 5 let args: Vec<String> = std::env::args().collect();
6 6
7 + let mut custom_config_path: Option<PathBuf> = None;
8 +
7 match args.get(1).map(|s| s.as_str()) { 9 match args.get(1).map(|s| s.as_str()) {
8 Some("--version") => { 10 Some("--version") => {
9 println!("oxwm {}", env!("CARGO_PKG_VERSION")); 11 println!("oxwm {}", env!("CARGO_PKG_VERSION"));
@@ -17,10 +19,18 @@ fn main() -> Result<()> {
17 init_config()?; 19 init_config()?;
18 return Ok(()); 20 return Ok(());
19 } 21 }
22 + Some("--config") => {
23 + if let Some(path) = args.get(2) {
24 + custom_config_path = Some(PathBuf::from(path));
25 + } else {
26 + eprintln!("Error: --config requires a path argument");
27 + std::process::exit(1);
28 + }
29 + }
20 _ => {} 30 _ => {}
21 } 31 }
22 32
23 - let config = load_config()?; 33 + let config = load_config(custom_config_path)?;
24 34
25 let mut wm = oxwm::window_manager::WindowManager::new(config)?; 35 let mut wm = oxwm::window_manager::WindowManager::new(config)?;
26 let should_restart = wm.run()?; 36 let should_restart = wm.run()?;
@@ -36,14 +46,18 @@ fn main() -> Result<()> {
36 Ok(()) 46 Ok(())
37 } 47 }
38 48
39 -fn load_config() -> Result<oxwm::Config> { 49 +fn load_config(custom_path: Option<PathBuf>) -> Result<oxwm::Config> {
40 - let config_path = get_config_path().join("config.ron"); 50 + let config_path = if let Some(path) = custom_path {
41 - 51 + path
42 - if !config_path.exists() { 52 + } else {
43 - println!("No config found at {:?}", config_path); 53 + let default_path = get_config_path().join("config.ron");
44 - println!("Creating default config..."); 54 + if !default_path.exists() {
45 - init_config()?; 55 + println!("No config found at {:?}", default_path);
46 - } 56 + println!("Creating default config...");
57 + init_config()?;
58 + }
59 + default_path
60 + };
47 61
48 let config_str = 62 let config_str =
49 std::fs::read_to_string(&config_path).with_context(|| "Failed to read config file")?; 63 std::fs::read_to_string(&config_path).with_context(|| "Failed to read config file")?;
@@ -78,9 +92,10 @@ fn print_help() {
78 println!("USAGE:"); 92 println!("USAGE:");
79 println!(" oxwm [OPTIONS]\n"); 93 println!(" oxwm [OPTIONS]\n");
80 println!("OPTIONS:"); 94 println!("OPTIONS:");
81 - println!(" --init Create default config in ~/.config/oxwm/config.ron"); 95 + println!(" --init Create default config in ~/.config/oxwm/config.ron");
82 - println!(" --version Print version information"); 96 + println!(" --config <PATH> Use custom config file");
83 - println!(" --help Print this help message\n"); 97 + println!(" --version Print version information");
98 + println!(" --help Print this help message\n");
84 println!("CONFIG:"); 99 println!("CONFIG:");
85 println!(" Location: ~/.config/oxwm/config.ron"); 100 println!(" Location: ~/.config/oxwm/config.ron");
86 println!(" Edit the config file and use Mod+Shift+R to reload"); 101 println!(" Edit the config file and use Mod+Shift+R to reload");
+5 −0 src/keyboard/handlers.rs
@@ -19,7 +19,12 @@ pub enum KeyAction {
19 ToggleGaps, 19 ToggleGaps,
20 ToggleFullScreen, 20 ToggleFullScreen,
21 ToggleFloating, 21 ToggleFloating,
22 + ChangeLayout,
23 + CycleLayout,
22 MoveToTag, 24 MoveToTag,
25 + FocusMonitor,
26 + SmartMoveWin,
27 + ExchangeClient,
23 None, 28 None,
24 } 29 }
25 30
+22 −0 src/layout/mod.rs
@@ -1,3 +1,4 @@
1 +pub mod normie;
1 pub mod tiling; 2 pub mod tiling;
2 3
3 use x11rb::protocol::xproto::Window; 4 use x11rb::protocol::xproto::Window;
@@ -9,6 +10,26 @@ pub struct GapConfig {
9 pub outer_vertical: u32, 10 pub outer_vertical: u32,
10 } 11 }
11 12
13 +pub const TILING: &str = "tiling";
14 +pub const NORMIE: &str = "normie";
15 +pub const FLOATING: &str = "floating";
16 +
17 +pub fn layout_from_str(s: &str) -> Result<Box<dyn Layout>, String> {
18 + match s.to_lowercase().as_str() {
19 + TILING => Ok(Box::new(tiling::TilingLayout)),
20 + NORMIE | FLOATING => Ok(Box::new(normie::NormieLayout)),
21 + _ => Err(format!("Unknown layout: {}", s)),
22 + }
23 +}
24 +
25 +pub fn next_layout(current_name: &str) -> &'static str {
26 + match current_name {
27 + TILING => NORMIE,
28 + NORMIE => TILING,
29 + _ => TILING,
30 + }
31 +}
32 +
12 pub trait Layout { 33 pub trait Layout {
13 fn arrange( 34 fn arrange(
14 &self, 35 &self,
@@ -17,6 +38,7 @@ pub trait Layout {
17 screen_height: u32, 38 screen_height: u32,
18 gaps: &GapConfig, 39 gaps: &GapConfig,
19 ) -> Vec<WindowGeometry>; 40 ) -> Vec<WindowGeometry>;
41 + fn name(&self) -> &'static str;
20 } 42 }
21 43
22 pub struct WindowGeometry { 44 pub struct WindowGeometry {
+40 −0 src/layout/normie.rs new file mode 100644
@@ -0,0 +1,40 @@
1 +use super::{GapConfig, Layout, WindowGeometry};
2 +use x11rb::protocol::xproto::Window;
3 +
4 +pub struct NormieLayout;
5 +
6 +// This layout should return a no-op similar to DWM.C's "null" mode.
7 +impl Layout for NormieLayout {
8 + fn name(&self) -> &'static str {
9 + super::NORMIE
10 + }
11 +
12 + fn arrange(
13 + &self,
14 + windows: &[Window],
15 + screen_width: u32,
16 + screen_height: u32,
17 + _gaps: &GapConfig,
18 + ) -> Vec<WindowGeometry> {
19 + const DEFAULT_WIDTH_RATIO: f32 = 0.6;
20 + const DEFAULT_HEIGHT_RATIO: f32 = 0.6;
21 +
22 + windows
23 + .iter()
24 + .map(|_| {
25 + let width = ((screen_width as f32) * DEFAULT_WIDTH_RATIO) as u32;
26 + let height = ((screen_height as f32) * DEFAULT_HEIGHT_RATIO) as u32;
27 +
28 + let x = ((screen_width - width) / 2) as i32;
29 + let y = ((screen_height - height) / 2) as i32;
30 +
31 + WindowGeometry {
32 + x_coordinate: x,
33 + y_coordinate: y,
34 + width,
35 + height,
36 + }
37 + })
38 + .collect()
39 + }
40 +}
+4 −0 src/layout/tiling.rs
@@ -4,6 +4,10 @@ use x11rb::protocol::xproto::Window;
4 pub struct TilingLayout; 4 pub struct TilingLayout;
5 5
6 impl Layout for TilingLayout { 6 impl Layout for TilingLayout {
7 + fn name(&self) -> &'static str {
8 + super::TILING
9 + }
10 +
7 fn arrange( 11 fn arrange(
8 &self, 12 &self,
9 windows: &[Window], 13 windows: &[Window],
+26 −0 src/lib.rs
@@ -3,6 +3,7 @@ pub mod config;
3 pub mod errors; 3 pub mod errors;
4 pub mod keyboard; 4 pub mod keyboard;
5 pub mod layout; 5 pub mod layout;
6 +pub mod monitor;
6 pub mod window_manager; 7 pub mod window_manager;
7 8
8 pub mod prelude { 9 pub mod prelude {
@@ -98,6 +99,7 @@ impl Default for Config {
98 ]), 99 ]),
99 ), 100 ),
100 Key::new(vec![MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), 101 Key::new(vec![MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
102 + Key::new(vec![MODKEY], keycodes::N, KeyAction::CycleLayout, Arg::None),
101 Key::new( 103 Key::new(
102 vec![MODKEY, SHIFT], 104 vec![MODKEY, SHIFT],
103 keycodes::F, 105 keycodes::F,
@@ -130,6 +132,30 @@ impl Default for Config {
130 KeyAction::FocusStack, 132 KeyAction::FocusStack,
131 Arg::Int(1), 133 Arg::Int(1),
132 ), 134 ),
135 + Key::new(
136 + vec![MODKEY, SHIFT],
137 + keycodes::K,
138 + KeyAction::ExchangeClient,
139 + Arg::Int(0), // UP
140 + ),
141 + Key::new(
142 + vec![MODKEY, SHIFT],
143 + keycodes::J,
144 + KeyAction::ExchangeClient,
145 + Arg::Int(1), // DOWN
146 + ),
147 + Key::new(
148 + vec![MODKEY, SHIFT],
149 + keycodes::H,
150 + KeyAction::ExchangeClient,
151 + Arg::Int(2), // LEFT
152 + ),
153 + Key::new(
154 + vec![MODKEY, SHIFT],
155 + keycodes::L,
156 + KeyAction::ExchangeClient,
157 + Arg::Int(3), // RIGHT
158 + ),
133 Key::new( 159 Key::new(
134 vec![MODKEY], 160 vec![MODKEY],
135 keycodes::KEY_1, 161 keycodes::KEY_1,
+107 −0 src/monitor.rs new file mode 100644
@@ -0,0 +1,107 @@
1 +use crate::errors::WmError;
2 +use x11rb::protocol::xinerama::ConnectionExt as _;
3 +use x11rb::protocol::xproto::{Screen, Window};
4 +use x11rb::rust_connection::RustConnection;
5 +
6 +type WmResult<T> = Result<T, WmError>;
7 +
8 +#[derive(Debug, Clone)]
9 +pub struct Monitor {
10 + pub x: i32,
11 + pub y: i32,
12 + pub width: u32,
13 + pub height: u32,
14 + pub selected_tags: u32,
15 + pub focused_window: Option<Window>,
16 +}
17 +
18 +impl Monitor {
19 + pub fn new(x: i32, y: i32, width: u32, height: u32) -> Self {
20 + Self {
21 + x,
22 + y,
23 + width,
24 + height,
25 + selected_tags: 1,
26 + focused_window: None,
27 + }
28 + }
29 +
30 + pub fn contains_point(&self, x: i32, y: i32) -> bool {
31 + x >= self.x
32 + && x < self.x + self.width as i32
33 + && y >= self.y
34 + && y < self.y + self.height as i32
35 + }
36 +}
37 +
38 +pub fn detect_monitors(
39 + connection: &RustConnection,
40 + screen: &Screen,
41 + _root: Window,
42 +) -> WmResult<Vec<Monitor>> {
43 + let fallback_monitors = || {
44 + vec![Monitor::new(
45 + 0,
46 + 0,
47 + screen.width_in_pixels as u32,
48 + screen.height_in_pixels as u32,
49 + )]
50 + };
51 +
52 + let mut monitors = Vec::<Monitor>::new();
53 +
54 + let xinerama_active = connection
55 + .xinerama_is_active()
56 + .ok()
57 + .and_then(|cookie| cookie.reply().ok())
58 + .map_or(false, |reply| reply.state != 0);
59 +
60 + if xinerama_active {
61 + let Ok(xinerama_cookie) = connection.xinerama_query_screens() else {
62 + return Ok(fallback_monitors());
63 + };
64 + let Ok(xinerama_reply) = xinerama_cookie.reply() else {
65 + return Ok(fallback_monitors());
66 + };
67 +
68 + for screen_info in &xinerama_reply.screen_info {
69 + let has_valid_dimensions = screen_info.width > 0 && screen_info.height > 0;
70 + if !has_valid_dimensions {
71 + continue;
72 + }
73 +
74 + let x_position = screen_info.x_org as i32;
75 + let y_position = screen_info.y_org as i32;
76 + let width_in_pixels = screen_info.width as u32;
77 + let height_in_pixels = screen_info.height as u32;
78 +
79 + let is_duplicate_monitor = monitors.iter().any(|monitor| {
80 + monitor.x == x_position
81 + && monitor.y == y_position
82 + && monitor.width == width_in_pixels
83 + && monitor.height == height_in_pixels
84 + });
85 +
86 + if !is_duplicate_monitor {
87 + monitors.push(Monitor::new(
88 + x_position,
89 + y_position,
90 + width_in_pixels,
91 + height_in_pixels,
92 + ));
93 + }
94 + }
95 + }
96 +
97 + if monitors.is_empty() {
98 + monitors = fallback_monitors();
99 + }
100 +
101 + monitors.sort_by(|a, b| match a.y.cmp(&b.y) {
102 + std::cmp::Ordering::Equal => a.x.cmp(&b.x),
103 + other => other,
104 + });
105 +
106 + Ok(monitors)
107 +}
+772 −140 src/window_manager.rs Large diff collapsed, click to expand
@@ -3,8 +3,9 @@ use crate::bar::Bar;
3 use crate::errors::WmError; 3 use crate::errors::WmError;
4 use crate::keyboard::{self, Arg, KeyAction, handlers}; 4 use crate::keyboard::{self, Arg, KeyAction, handlers};
5 use crate::layout::GapConfig; 5 use crate::layout::GapConfig;
6 -use crate::layout::Layout;
7 use crate::layout::tiling::TilingLayout; 6 use crate::layout::tiling::TilingLayout;
7 +use crate::layout::{Layout, layout_from_str, next_layout};
8 +use crate::monitor::{Monitor, detect_monitors};
8 use std::collections::HashSet; 9 use std::collections::HashSet;
9 use x11rb::cursor::Handle as CursorHandle; 10 use x11rb::cursor::Handle as CursorHandle;
10 11
@@ -18,6 +19,34 @@ pub fn tag_mask(tag: usize) -> TagMask {
18 1 << tag 19 1 << tag
19 } 20 }
20 21
22 +struct AtomCache {
23 + net_current_desktop: Atom,
24 + net_client_info: Atom,
25 + wm_state: Atom,
26 +}
27 +
28 +impl AtomCache {
29 + fn new(connection: &RustConnection) -> WmResult<Self> {
30 + let net_current_desktop = connection
31 + .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
32 + .reply()?
33 + .atom;
34 +
35 + let net_client_info = connection
36 + .intern_atom(false, b"_NET_CLIENT_INFO")?
37 + .reply()?
38 + .atom;
39 +
40 + let wm_state = connection.intern_atom(false, b"WM_STATE")?.reply()?.atom;
41 +
42 + Ok(Self {
43 + net_current_desktop,
44 + net_client_info,
45 + wm_state,
46 + })
47 + }
48 +}
49 +
21 pub struct WindowManager { 50 pub struct WindowManager {
22 config: Config, 51 config: Config,
23 connection: RustConnection, 52 connection: RustConnection,
@@ -25,14 +54,20 @@ pub struct WindowManager {
25 root: Window, 54 root: Window,
26 screen: Screen, 55 screen: Screen,
27 windows: Vec<Window>, 56 windows: Vec<Window>,
28 - focused_window: Option<Window>,
29 layout: Box<dyn Layout>, 57 layout: Box<dyn Layout>,
30 window_tags: std::collections::HashMap<Window, TagMask>, 58 window_tags: std::collections::HashMap<Window, TagMask>,
31 - selected_tags: TagMask, 59 + window_monitor: std::collections::HashMap<Window, usize>,
60 + window_geometries: std::collections::HashMap<Window, (i16, i16, u16, u16)>,
32 gaps_enabled: bool, 61 gaps_enabled: bool,
33 fullscreen_window: Option<Window>, 62 fullscreen_window: Option<Window>,
34 floating_windows: HashSet<Window>, 63 floating_windows: HashSet<Window>,
35 - bar: Bar, 64 + bars: Vec<Bar>,
65 + monitors: Vec<Monitor>,
66 + selected_monitor: usize,
67 + atoms: AtomCache,
68 + previous_focused: Option<Window>,
69 + display: *mut x11::xlib::Display,
70 + font: crate::bar::font::Font,
36 } 71 }
37 72
38 type WmResult<T> = Result<T, WmError>; 73 type WmResult<T> = Result<T, WmError>;
@@ -61,7 +96,8 @@ impl WindowManager {
61 | EventMask::SUBSTRUCTURE_NOTIFY 96 | EventMask::SUBSTRUCTURE_NOTIFY
62 | EventMask::PROPERTY_CHANGE 97 | EventMask::PROPERTY_CHANGE
63 | EventMask::KEY_PRESS 98 | EventMask::KEY_PRESS
64 - | EventMask::BUTTON_PRESS, 99 + | EventMask::BUTTON_PRESS
100 + | EventMask::POINTER_MOTION,
65 ), 101 ),
66 )? 102 )?
67 .check()?; 103 .check()?;
@@ -90,11 +126,35 @@ impl WindowManager {
90 u16::from(config.modkey).into(), 126 u16::from(config.modkey).into(),
91 )?; 127 )?;
92 128
93 - let bar = Bar::new(&connection, &screen, screen_number, &config)?; 129 + let monitors = detect_monitors(&connection, &screen, root)?;
130 +
131 + let display = unsafe { x11::xlib::XOpenDisplay(std::ptr::null()) };
132 + if display.is_null() {
133 + return Err(WmError::X11(crate::errors::X11Error::DisplayOpenFailed));
134 + }
135 +
136 + let font = crate::bar::font::Font::new(display, screen_number as i32, &config.font)?;
137 +
138 + let mut bars = Vec::new();
139 + for monitor in monitors.iter() {
140 + let bar = Bar::new(
141 + &connection,
142 + &screen,
143 + screen_number,
144 + &config,
145 + display,
146 + &font,
147 + monitor.x as i16,
148 + monitor.y as i16,
149 + monitor.width as u16,
150 + )?;
151 + bars.push(bar);
152 + }
94 153
95 - let selected_tags = Self::get_saved_selected_tags(&connection, root, config.tags.len())?;
96 let gaps_enabled = config.gaps_enabled; 154 let gaps_enabled = config.gaps_enabled;
97 155
156 + let atoms = AtomCache::new(&connection)?;
157 +
98 let mut window_manager = Self { 158 let mut window_manager = Self {
99 config, 159 config,
100 connection, 160 connection,
@@ -102,14 +162,20 @@ impl WindowManager {
102 root, 162 root,
103 screen, 163 screen,
104 windows: Vec::new(), 164 windows: Vec::new(),
105 - focused_window: None,
106 layout: Box::new(TilingLayout), 165 layout: Box::new(TilingLayout),
107 window_tags: std::collections::HashMap::new(), 166 window_tags: std::collections::HashMap::new(),
108 - selected_tags, 167 + window_monitor: std::collections::HashMap::new(),
168 + window_geometries: std::collections::HashMap::new(),
109 gaps_enabled, 169 gaps_enabled,
110 fullscreen_window: None, 170 fullscreen_window: None,
111 floating_windows: HashSet::new(), 171 floating_windows: HashSet::new(),
112 - bar, 172 + bars,
173 + monitors,
174 + selected_monitor: 0,
175 + atoms,
176 + previous_focused: None,
177 + display,
178 + font,
113 }; 179 };
114 180
115 window_manager.scan_existing_windows()?; 181 window_manager.scan_existing_windows()?;
@@ -118,7 +184,12 @@ impl WindowManager {
118 Ok(window_manager) 184 Ok(window_manager)
119 } 185 }
120 186
121 - fn get_saved_selected_tags( 187 + /**
188 + *
189 + * This function is deprecated for now, but will potentially be used in the future.
190 + *
191 + */
192 + fn _get_saved_selected_tags(
122 connection: &RustConnection, 193 connection: &RustConnection,
123 root: Window, 194 root: Window,
124 tag_count: usize, 195 tag_count: usize,
@@ -154,20 +225,11 @@ impl WindowManager {
154 225
155 fn scan_existing_windows(&mut self) -> WmResult<()> { 226 fn scan_existing_windows(&mut self) -> WmResult<()> {
156 let tree = self.connection.query_tree(self.root)?.reply()?; 227 let tree = self.connection.query_tree(self.root)?.reply()?;
157 - let net_client_info = self 228 + let net_client_info = self.atoms.net_client_info;
158 - .connection 229 + let wm_state_atom = self.atoms.wm_state;
159 - .intern_atom(false, b"_NET_CLIENT_INFO")?
160 - .reply()?
161 - .atom;
162 -
163 - let wm_state_atom = self
164 - .connection
165 - .intern_atom(false, b"WM_STATE")?
166 - .reply()?
167 - .atom;
168 230
169 for &window in &tree.children { 231 for &window in &tree.children {
170 - if window == self.bar.window() { 232 + if self.bars.iter().any(|bar| bar.window() == window) {
171 continue; 233 continue;
172 } 234 }
173 235
@@ -183,6 +245,7 @@ impl WindowManager {
183 let tag = self.get_saved_tag(window, net_client_info)?; 245 let tag = self.get_saved_tag(window, net_client_info)?;
184 self.windows.push(window); 246 self.windows.push(window);
185 self.window_tags.insert(window, tag); 247 self.window_tags.insert(window, tag);
248 + self.window_monitor.insert(window, self.selected_monitor);
186 continue; 249 continue;
187 } 250 }
188 251
@@ -207,12 +270,13 @@ impl WindowManager {
207 let tag = self.get_saved_tag(window, net_client_info)?; 270 let tag = self.get_saved_tag(window, net_client_info)?;
208 self.windows.push(window); 271 self.windows.push(window);
209 self.window_tags.insert(window, tag); 272 self.window_tags.insert(window, tag);
273 + self.window_monitor.insert(window, self.selected_monitor);
210 } 274 }
211 } 275 }
212 } 276 }
213 277
214 if let Some(&first) = self.windows.first() { 278 if let Some(&first) = self.windows.first() {
215 - self.set_focus(Some(first))?; 279 + self.set_focus(first)?;
216 } 280 }
217 281
218 self.apply_layout()?; 282 self.apply_layout()?;
@@ -243,15 +307,15 @@ impl WindowManager {
243 } 307 }
244 } 308 }
245 309
246 - Ok(self.selected_tags) 310 + Ok(self
311 + .monitors
312 + .get(self.selected_monitor)
313 + .map(|m| m.selected_tags)
314 + .unwrap_or(tag_mask(0)))
247 } 315 }
248 316
249 fn save_client_tag(&self, window: Window, tag: TagMask) -> WmResult<()> { 317 fn save_client_tag(&self, window: Window, tag: TagMask) -> WmResult<()> {
250 - let net_client_info = self 318 + let net_client_info = self.atoms.net_client_info;
251 - .connection
252 - .intern_atom(false, b"_NET_CLIENT_INFO")?
253 - .reply()?
254 - .atom;
255 319
256 let bytes = tag.to_ne_bytes().to_vec(); 320 let bytes = tag.to_ne_bytes().to_vec();
257 321
@@ -270,11 +334,7 @@ impl WindowManager {
270 } 334 }
271 335
272 fn set_wm_state(&self, window: Window, state: u32) -> WmResult<()> { 336 fn set_wm_state(&self, window: Window, state: u32) -> WmResult<()> {
273 - let wm_state_atom = self 337 + let wm_state_atom = self.atoms.wm_state;
274 - .connection
275 - .intern_atom(false, b"WM_STATE")?
276 - .reply()?
277 - .atom;
278 338
279 let data = [state, 0u32]; 339 let data = [state, 0u32];
280 let bytes: Vec<u8> = data.iter().flat_map(|&v| v.to_ne_bytes()).collect(); 340 let bytes: Vec<u8> = data.iter().flat_map(|&v| v.to_ne_bytes()).collect();
@@ -300,24 +360,30 @@ impl WindowManager {
300 self.update_bar()?; 360 self.update_bar()?;
301 361
302 loop { 362 loop {
303 - self.bar.update_blocks(); 363 + while let Some(event) = self.connection.poll_for_event()? {
304 -
305 - if let Ok(Some(event)) = self.connection.poll_for_event() {
306 if let Some(should_restart) = self.handle_event(event)? { 364 if let Some(should_restart) = self.handle_event(event)? {
307 return Ok(should_restart); 365 return Ok(should_restart);
308 } 366 }
309 } 367 }
310 368
311 - if self.bar.needs_redraw() { 369 + if let Some(bar) = self.bars.get_mut(self.selected_monitor) {
370 + bar.update_blocks();
371 + }
372 +
373 + if self.bars.iter().any(|bar| bar.needs_redraw()) {
312 self.update_bar()?; 374 self.update_bar()?;
313 } 375 }
314 376
315 - std::thread::sleep(std::time::Duration::from_millis(10)); 377 + std::thread::sleep(std::time::Duration::from_millis(100));
316 } 378 }
317 } 379 }
318 380
319 fn toggle_floating(&mut self) -> WmResult<()> { 381 fn toggle_floating(&mut self) -> WmResult<()> {
320 - if let Some(focused) = self.focused_window { 382 + if let Some(focused) = self
383 + .monitors
384 + .get(self.selected_monitor)
385 + .and_then(|m| m.focused_window)
386 + {
321 if self.floating_windows.contains(&focused) { 387 if self.floating_windows.contains(&focused) {
322 self.floating_windows.remove(&focused); 388 self.floating_windows.remove(&focused);
323 self.apply_layout()?; 389 self.apply_layout()?;
@@ -326,9 +392,10 @@ impl WindowManager {
326 let float_height = (self.screen.height_in_pixels / 2) as u32; 392 let float_height = (self.screen.height_in_pixels / 2) as u32;
327 393
328 let border_width = self.config.border_width; 394 let border_width = self.config.border_width;
329 - 395 +
330 - let center_width = ((self.screen.width_in_pixels - float_width as u16)/2) as i32; 396 + let center_width = ((self.screen.width_in_pixels - float_width as u16) / 2) as i32;
331 - let center_height = ((self.screen.height_in_pixels - float_height as u16)/2) as i32; 397 + let center_height =
398 + ((self.screen.height_in_pixels - float_height as u16) / 2) as i32;
332 399
333 self.connection.configure_window( 400 self.connection.configure_window(
334 focused, 401 focused,
@@ -349,28 +416,367 @@ impl WindowManager {
349 Ok(()) 416 Ok(())
350 } 417 }
351 418
419 + fn smart_move_window(&mut self, direction: i32) -> WmResult<()> {
420 + let focused = match self
421 + .monitors
422 + .get(self.selected_monitor)
423 + .and_then(|m| m.focused_window)
424 + {
425 + Some(win) => win,
426 + None => return Ok(()),
427 + };
428 +
429 + if self.fullscreen_window == Some(focused) {
430 + return Ok(());
431 + }
432 +
433 + if !self.floating_windows.contains(&focused) {
434 + let float_width = (self.screen.width_in_pixels / 2) as u32;
435 + let float_height = (self.screen.height_in_pixels / 2) as u32;
436 + let border_width = self.config.border_width;
437 + let center_width = ((self.screen.width_in_pixels - float_width as u16) / 2) as i32;
438 + let center_height = ((self.screen.height_in_pixels - float_height as u16) / 2) as i32;
439 +
440 + self.connection.configure_window(
441 + focused,
442 + &ConfigureWindowAux::new()
443 + .x(center_width)
444 + .y(center_height)
445 + .width(float_width)
446 + .height(float_height)
447 + .border_width(border_width)
448 + .stack_mode(StackMode::ABOVE),
449 + )?;
450 + self.floating_windows.insert(focused);
451 + }
452 +
453 + let current_geom = match self.connection.get_geometry(focused)?.reply() {
454 + Ok(geom) => geom,
455 + Err(_) => return Ok(()),
456 + };
457 +
458 + let c_x = current_geom.x as i32;
459 + let c_y = current_geom.y as i32;
460 + let c_width = current_geom.width as i32;
461 + let c_height = current_geom.height as i32;
462 +
463 + let monitor = match self.monitors.get(self.selected_monitor) {
464 + Some(m) => m,
465 + None => return Ok(()),
466 + };
467 +
468 + let (gap_ih, gap_iv, gap_oh, gap_ov) = if self.gaps_enabled {
469 + (
470 + self.config.gap_inner_horizontal as i32,
471 + self.config.gap_inner_vertical as i32,
472 + self.config.gap_outer_horizontal as i32,
473 + self.config.gap_outer_vertical as i32,
474 + )
475 + } else {
476 + (0, 0, 0, 0)
477 + };
478 +
479 + let (new_x, new_y) = match direction {
480 + 0 => {
481 + // UP
482 + let mut target = i32::MIN;
483 + let top = c_y;
484 + let mut ny = c_y - (monitor.height as i32 / 4);
485 +
486 + for &other_window in &self.windows {
487 + if other_window == focused {
488 + continue;
489 + }
490 + if !self.floating_windows.contains(&other_window) {
491 + continue;
492 + }
493 + if !self.is_window_visible(other_window) {
494 + continue;
495 + }
496 + let other_mon = self.window_monitor.get(&other_window).copied().unwrap_or(0);
497 + if other_mon != self.selected_monitor {
498 + continue;
499 + }
500 +
501 + let other_geom = match self.connection.get_geometry(other_window)?.reply() {
502 + Ok(geom) => geom,
503 + Err(_) => continue,
504 + };
505 +
506 + let o_x = other_geom.x as i32;
507 + let o_y = other_geom.y as i32;
508 + let o_width = other_geom.width as i32;
509 + let o_height = other_geom.height as i32;
510 +
511 + if c_x + c_width < o_x || c_x > o_x + o_width {
512 + continue;
513 + }
514 +
515 + let bottom = o_y + o_height + gap_iv;
516 + if top > bottom && ny < bottom {
517 + target = target.max(bottom);
518 + }
519 + }
520 +
521 + if target != i32::MIN {
522 + ny = target;
523 + }
524 + ny = ny.max(monitor.y as i32 + gap_ov);
525 + (c_x, ny)
526 + }
527 + 1 => {
528 + // DOWN
529 + let mut target = i32::MAX;
530 + let bottom = c_y + c_height;
531 + let mut ny = c_y + (monitor.height as i32 / 4);
532 +
533 + for &other_window in &self.windows {
534 + if other_window == focused {
535 + continue;
536 + }
537 + if !self.floating_windows.contains(&other_window) {
538 + continue;
539 + }
540 + if !self.is_window_visible(other_window) {
541 + continue;
542 + }
543 + let other_mon = self.window_monitor.get(&other_window).copied().unwrap_or(0);
544 + if other_mon != self.selected_monitor {
545 + continue;
546 + }
547 +
548 + let other_geom = match self.connection.get_geometry(other_window)?.reply() {
549 + Ok(geom) => geom,
550 + Err(_) => continue,
551 + };
552 +
553 + let o_x = other_geom.x as i32;
554 + let o_y = other_geom.y as i32;
555 + let o_width = other_geom.width as i32;
556 +
557 + if c_x + c_width < o_x || c_x > o_x + o_width {
558 + continue;
559 + }
560 +
561 + let top = o_y - gap_iv;
562 + if bottom < top && (ny + c_height) > top {
563 + target = target.min(top - c_height);
564 + }
565 + }
566 +
567 + if target != i32::MAX {
568 + ny = target;
569 + }
570 + ny = ny.min(monitor.y as i32 + monitor.height as i32 - c_height - gap_ov);
571 + (c_x, ny)
572 + }
573 + 2 => {
574 + // LEFT
575 + let mut target = i32::MIN;
576 + let left = c_x;
577 + let mut nx = c_x - (monitor.width as i32 / 6);
578 +
579 + for &other_window in &self.windows {
580 + if other_window == focused {
581 + continue;
582 + }
583 + if !self.floating_windows.contains(&other_window) {
584 + continue;
585 + }
586 + if !self.is_window_visible(other_window) {
587 + continue;
588 + }
589 + let other_mon = self.window_monitor.get(&other_window).copied().unwrap_or(0);
590 + if other_mon != self.selected_monitor {
591 + continue;
592 + }
593 +
594 + let other_geom = match self.connection.get_geometry(other_window)?.reply() {
595 + Ok(geom) => geom,
596 + Err(_) => continue,
597 + };
598 +
599 + let o_x = other_geom.x as i32;
600 + let o_y = other_geom.y as i32;
601 + let o_width = other_geom.width as i32;
602 + let o_height = other_geom.height as i32;
603 +
604 + if c_y + c_height < o_y || c_y > o_y + o_height {
605 + continue;
606 + }
607 +
608 + let right = o_x + o_width + gap_ih;
609 + if left > right && nx < right {
610 + target = target.max(right);
611 + }
612 + }
613 +
614 + if target != i32::MIN {
615 + nx = target;
616 + }
617 + nx = nx.max(monitor.x as i32 + gap_oh);
618 + (nx, c_y)
619 + }
620 + 3 => {
621 + // RIGHT
622 + let mut target = i32::MAX;
623 + let right = c_x + c_width;
624 + let mut nx = c_x + (monitor.width as i32 / 6);
625 +
626 + for &other_window in &self.windows {
627 + if other_window == focused {
628 + continue;
629 + }
630 + if !self.floating_windows.contains(&other_window) {
631 + continue;
632 + }
633 + if !self.is_window_visible(other_window) {
634 + continue;
635 + }
636 + let other_mon = self.window_monitor.get(&other_window).copied().unwrap_or(0);
637 + if other_mon != self.selected_monitor {
638 + continue;
639 + }
640 +
641 + let other_geom = match self.connection.get_geometry(other_window)?.reply() {
642 + Ok(geom) => geom,
643 + Err(_) => continue,
644 + };
645 +
646 + let o_x = other_geom.x as i32;
647 + let o_y = other_geom.y as i32;
648 + let o_height = other_geom.height as i32;
649 +
650 + if c_y + c_height < o_y || c_y > o_y + o_height {
651 + continue;
652 + }
653 +
654 + let left = o_x - gap_ih;
655 + if right < left && (nx + c_width) > left {
656 + target = target.min(left - c_width);
657 + }
658 + }
659 +
660 + if target != i32::MAX {
661 + nx = target;
662 + }
663 + nx = nx.min(monitor.x as i32 + monitor.width as i32 - c_width - gap_oh);
664 + (nx, c_y)
665 + }
666 + _ => return Ok(()),
667 + };
668 +
669 + self.connection.configure_window(
670 + focused,
671 + &ConfigureWindowAux::new()
672 + .x(new_x)
673 + .y(new_y)
674 + .stack_mode(StackMode::ABOVE),
675 + )?;
676 +
677 + self.connection.flush()?;
678 + Ok(())
679 + }
680 +
681 + fn exchange_client(&mut self, direction: i32) -> WmResult<()> {
682 + let focused = match self
683 + .monitors
684 + .get(self.selected_monitor)
685 + .and_then(|m| m.focused_window)
686 + {
687 + Some(win) => win,
688 + None => return Ok(()),
689 + };
690 +
691 + if self.fullscreen_window == Some(focused) || self.floating_windows.contains(&focused) {
692 + return Ok(());
693 + }
694 +
695 + let visible = self.visible_windows();
696 + if visible.len() < 2 {
697 + return Ok(());
698 + }
699 +
700 + let current_idx = match visible.iter().position(|&w| w == focused) {
701 + Some(idx) => idx,
702 + None => return Ok(()),
703 + };
704 +
705 + let target_idx = match direction {
706 + 0 | 2 => {
707 + // UP or LEFT - previous in stack
708 + if current_idx == 0 {
709 + visible.len() - 1
710 + } else {
711 + current_idx - 1
712 + }
713 + }
714 + 1 | 3 => {
715 + // DOWN or RIGHT - next in stack
716 + (current_idx + 1) % visible.len()
717 + }
718 + _ => return Ok(()),
719 + };
720 +
721 + let target = visible[target_idx];
722 +
723 + let focused_pos = self.windows.iter().position(|&w| w == focused);
724 + let target_pos = self.windows.iter().position(|&w| w == target);
725 +
726 + if let (Some(f_pos), Some(t_pos)) = (focused_pos, target_pos) {
727 + self.windows.swap(f_pos, t_pos);
728 +
729 + self.apply_layout()?;
730 +
731 + self.set_focus(focused)?;
732 +
733 + if let Ok(geometry) = self.connection.get_geometry(focused)?.reply() {
734 + self.connection.warp_pointer(
735 + x11rb::NONE,
736 + focused,
737 + 0,
738 + 0,
739 + 0,
740 + 0,
741 + geometry.width as i16 / 2,
742 + geometry.height as i16 / 2,
743 + )?;
744 + }
745 + }
746 +
747 + Ok(())
748 + }
749 +
352 fn toggle_fullscreen(&mut self) -> WmResult<()> { 750 fn toggle_fullscreen(&mut self) -> WmResult<()> {
353 - if let Some(focused) = self.focused_window { 751 + if let Some(focused) = self
752 + .monitors
753 + .get(self.selected_monitor)
754 + .and_then(|m| m.focused_window)
755 + {
354 if self.fullscreen_window == Some(focused) { 756 if self.fullscreen_window == Some(focused) {
355 self.fullscreen_window = None; 757 self.fullscreen_window = None;
356 758
357 - self.connection.map_window(self.bar.window())?; 759 + for bar in &self.bars {
760 + self.connection.map_window(bar.window())?;
761 + }
358 762
359 self.apply_layout()?; 763 self.apply_layout()?;
360 - self.update_focus_visuals()?;
361 } else { 764 } else {
362 self.fullscreen_window = Some(focused); 765 self.fullscreen_window = Some(focused);
363 766
364 - self.connection.unmap_window(self.bar.window())?; 767 + if let Some(bar) = self.bars.get(self.selected_monitor) {
768 + self.connection.unmap_window(bar.window())?;
769 + }
365 770
366 - let screen_width = self.screen.width_in_pixels as u32; 771 + let monitor = &self.monitors[self.selected_monitor];
367 - let screen_height = self.screen.height_in_pixels as u32; 772 + let screen_width = monitor.width;
773 + let screen_height = monitor.height;
368 774
369 self.connection.configure_window( 775 self.connection.configure_window(
370 focused, 776 focused,
371 &ConfigureWindowAux::new() 777 &ConfigureWindowAux::new()
372 - .x(0) 778 + .x(monitor.x)
373 - .y(0) 779 + .y(monitor.y)
374 .width(screen_width) 780 .width(screen_width)
375 .height(screen_height) 781 .height(screen_height)
376 .border_width(0) 782 .border_width(0)
@@ -384,14 +790,27 @@ impl WindowManager {
384 } 790 }
385 791
386 fn update_bar(&mut self) -> WmResult<()> { 792 fn update_bar(&mut self) -> WmResult<()> {
387 - let mut occupied_tags: TagMask = 0; 793 + for (monitor_index, monitor) in self.monitors.iter().enumerate() {
388 - for &tags in self.window_tags.values() { 794 + if let Some(bar) = self.bars.get_mut(monitor_index) {
389 - occupied_tags |= tags; 795 + let mut occupied_tags: TagMask = 0;
390 - } 796 + for (&window, &tags) in &self.window_tags {
797 + if self.window_monitor.get(&window).copied().unwrap_or(0) == monitor_index {
798 + occupied_tags |= tags;
799 + }
800 + }
391 801
392 - self.bar.invalidate(); 802 + let draw_blocks = monitor_index == self.selected_monitor;
393 - self.bar 803 + bar.invalidate();
394 - .draw(&self.connection, self.selected_tags, occupied_tags)?; 804 + bar.draw(
805 + &self.connection,
806 + &self.font,
807 + self.display,
808 + monitor.selected_tags,
809 + occupied_tags,
810 + draw_blocks,
811 + )?;
812 + }
813 + }
395 Ok(()) 814 Ok(())
396 } 815 }
397 816
@@ -399,7 +818,11 @@ impl WindowManager {
399 match action { 818 match action {
400 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?, 819 KeyAction::Spawn => handlers::handle_spawn_action(action, arg)?,
401 KeyAction::KillClient => { 820 KeyAction::KillClient => {
402 - if let Some(focused) = self.focused_window { 821 + if let Some(focused) = self
822 + .monitors
823 + .get(self.selected_monitor)
824 + .and_then(|m| m.focused_window)
825 + {
403 match self.connection.kill_client(focused) { 826 match self.connection.kill_client(focused) {
404 Ok(_) => { 827 Ok(_) => {
405 self.connection.flush()?; 828 self.connection.flush()?;
@@ -413,10 +836,44 @@ impl WindowManager {
413 KeyAction::ToggleFullScreen => { 836 KeyAction::ToggleFullScreen => {
414 self.toggle_fullscreen()?; 837 self.toggle_fullscreen()?;
415 } 838 }
839 + KeyAction::ChangeLayout => {
840 + if let Arg::Str(layout_name) = arg {
841 + match layout_from_str(layout_name) {
842 + Ok(layout) => {
843 + self.layout = layout;
844 + self.apply_layout()?;
845 + }
846 + Err(e) => eprintln!("Failed to change layout: {}", e),
847 + }
848 + }
849 + }
850 + KeyAction::CycleLayout => {
851 + let current_name = self.layout.name();
852 + let next_name = next_layout(current_name);
853 + match layout_from_str(next_name) {
854 + Ok(layout) => {
855 + self.layout = layout;
856 + self.apply_layout()?;
857 + }
858 + Err(e) => eprintln!("Failed to cycle layout: {}", e),
859 + }
860 + }
416 KeyAction::ToggleFloating => { 861 KeyAction::ToggleFloating => {
417 self.toggle_floating()?; 862 self.toggle_floating()?;
418 } 863 }
419 864
865 + KeyAction::SmartMoveWin => {
866 + if let Arg::Int(direction) = arg {
867 + self.smart_move_window(*direction)?;
868 + }
869 + }
870 +
871 + KeyAction::ExchangeClient => {
872 + if let Arg::Int(direction) = arg {
873 + self.exchange_client(*direction)?;
874 + }
875 + }
876 +
420 KeyAction::FocusStack => { 877 KeyAction::FocusStack => {
421 if let Arg::Int(direction) = arg { 878 if let Arg::Int(direction) = arg {
422 self.cycle_focus(*direction)?; 879 self.cycle_focus(*direction)?;
@@ -448,14 +905,50 @@ impl WindowManager {
448 self.gaps_enabled = !self.gaps_enabled; 905 self.gaps_enabled = !self.gaps_enabled;
449 self.apply_layout()?; 906 self.apply_layout()?;
450 } 907 }
908 + KeyAction::FocusMonitor => {
909 + if let Arg::Int(direction) = arg {
910 + self.focus_monitor(*direction)?;
911 + }
912 + }
451 KeyAction::None => {} 913 KeyAction::None => {}
452 } 914 }
453 Ok(()) 915 Ok(())
454 } 916 }
455 917
918 + fn focus_monitor(&mut self, direction: i32) -> WmResult<()> {
919 + if self.monitors.is_empty() {
920 + return Ok(());
921 + }
922 +
923 + let new_monitor = if direction > 0 {
924 + (self.selected_monitor + 1) % self.monitors.len()
925 + } else {
926 + (self.selected_monitor + self.monitors.len() - 1) % self.monitors.len()
927 + };
928 +
929 + if new_monitor == self.selected_monitor {
930 + return Ok(());
931 + }
932 +
933 + self.selected_monitor = new_monitor;
934 +
935 + self.update_bar()?;
936 +
937 + let visible = self.visible_windows_on_monitor(new_monitor);
938 + if let Some(&win) = visible.first() {
939 + self.set_focus(win)?;
940 + }
941 +
942 + Ok(())
943 + }
944 +
456 fn is_window_visible(&self, window: Window) -> bool { 945 fn is_window_visible(&self, window: Window) -> bool {
946 + let window_mon = self.window_monitor.get(&window).copied().unwrap_or(0);
947 +
457 if let Some(&tags) = self.window_tags.get(&window) { 948 if let Some(&tags) = self.window_tags.get(&window) {
458 - (tags & self.selected_tags) != 0 949 + let monitor = self.monitors.get(window_mon);
950 + let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0);
951 + (tags & selected_tags) != 0
459 } else { 952 } else {
460 false 953 false
461 } 954 }
@@ -469,6 +962,32 @@ impl WindowManager {
469 .collect() 962 .collect()
470 } 963 }
471 964
965 + fn visible_windows_on_monitor(&self, monitor_index: usize) -> Vec<Window> {
966 + self.windows
967 + .iter()
968 + .filter(|&&w| {
969 + let window_mon = self.window_monitor.get(&w).copied().unwrap_or(0);
970 + if window_mon != monitor_index {
971 + return false;
972 + }
973 + if let Some(&tags) = self.window_tags.get(&w) {
974 + let monitor = self.monitors.get(monitor_index);
975 + let selected_tags = monitor.map(|m| m.selected_tags).unwrap_or(0);
976 + (tags & selected_tags) != 0
977 + } else {
978 + false
979 + }
980 + })
981 + .copied()
982 + .collect()
983 + }
984 +
985 + fn get_monitor_at_point(&self, x: i32, y: i32) -> Option<usize> {
986 + self.monitors
987 + .iter()
988 + .position(|mon| mon.contains_point(x, y))
989 + }
990 +
472 fn update_window_visibility(&self) -> WmResult<()> { 991 fn update_window_visibility(&self) -> WmResult<()> {
473 for &window in &self.windows { 992 for &window in &self.windows {
474 if self.is_window_visible(window) { 993 if self.is_window_visible(window) {
@@ -488,10 +1007,14 @@ impl WindowManager {
488 1007
489 if self.fullscreen_window.is_some() { 1008 if self.fullscreen_window.is_some() {
490 self.fullscreen_window = None; 1009 self.fullscreen_window = None;
491 - self.connection.map_window(self.bar.window())?; 1010 + for bar in &self.bars {
1011 + self.connection.map_window(bar.window())?;
1012 + }
492 } 1013 }
493 1014
494 - self.selected_tags = tag_mask(tag_index); 1015 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
1016 + monitor.selected_tags = tag_mask(tag_index);
1017 + }
495 1018
496 self.save_selected_tags()?; 1019 self.save_selected_tags()?;
497 1020
@@ -499,20 +1022,23 @@ impl WindowManager {
499 self.apply_layout()?; 1022 self.apply_layout()?;
500 self.update_bar()?; 1023 self.update_bar()?;
501 1024
502 - let visible = self.visible_windows(); 1025 + let visible = self.visible_windows_on_monitor(self.selected_monitor);
503 - self.set_focus(visible.first().copied())?; 1026 + if let Some(&win) = visible.first() {
1027 + self.set_focus(win)?;
1028 + }
504 1029
505 Ok(()) 1030 Ok(())
506 } 1031 }
507 1032
508 fn save_selected_tags(&self) -> WmResult<()> { 1033 fn save_selected_tags(&self) -> WmResult<()> {
509 - let net_current_desktop = self 1034 + let net_current_desktop = self.atoms.net_current_desktop;
510 - .connection
511 - .intern_atom(false, b"_NET_CURRENT_DESKTOP")?
512 - .reply()?
513 - .atom;
514 1035
515 - let desktop = self.selected_tags.trailing_zeros(); 1036 + let selected_tags = self
1037 + .monitors
1038 + .get(self.selected_monitor)
1039 + .map(|m| m.selected_tags)
1040 + .unwrap_or(tag_mask(0));
1041 + let desktop = selected_tags.trailing_zeros();
516 1042
517 let bytes = (desktop as u32).to_ne_bytes(); 1043 let bytes = (desktop as u32).to_ne_bytes();
518 self.connection.change_property( 1044 self.connection.change_property(
@@ -534,7 +1060,11 @@ impl WindowManager {
534 return Ok(()); 1060 return Ok(());
535 } 1061 }
536 1062
537 - if let Some(focused) = self.focused_window { 1063 + if let Some(focused) = self
1064 + .monitors
1065 + .get(self.selected_monitor)
1066 + .and_then(|m| m.focused_window)
1067 + {
538 let mask = tag_mask(tag_index); 1068 let mask = tag_mask(tag_index);
539 self.window_tags.insert(focused, mask); 1069 self.window_tags.insert(focused, mask);
540 1070
@@ -555,7 +1085,12 @@ impl WindowManager {
555 return Ok(()); 1085 return Ok(());
556 } 1086 }
557 1087
558 - let next_window = if let Some(current) = self.focused_window { 1088 + let current = self
1089 + .monitors
1090 + .get(self.selected_monitor)
1091 + .and_then(|m| m.focused_window);
1092 +
1093 + let next_window = if let Some(current) = current {
559 if let Some(current_index) = visible.iter().position(|&w| w == current) { 1094 if let Some(current_index) = visible.iter().position(|&w| w == current) {
560 let next_index = if direction > 0 { 1095 let next_index = if direction > 0 {
561 (current_index + 1) % visible.len() 1096 (current_index + 1) % visible.len()
@@ -570,41 +1105,55 @@ impl WindowManager {
570 visible[0] 1105 visible[0]
571 }; 1106 };
572 1107
573 - self.set_focus(Some(next_window))?; 1108 + self.set_focus(next_window)?;
574 Ok(()) 1109 Ok(())
575 } 1110 }
576 1111
577 - pub fn set_focus(&mut self, window: Option<Window>) -> WmResult<()> { 1112 + pub fn set_focus(&mut self, window: Window) -> WmResult<()> {
578 - self.focused_window = window; 1113 + let old_focused = self.previous_focused;
579 1114
580 - if let Some(win) = window { 1115 + if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
581 - self.connection 1116 + monitor.focused_window = Some(window);
582 - .set_input_focus(InputFocus::POINTER_ROOT, win, x11rb::CURRENT_TIME)?;
583 - self.connection.flush()?;
584 } 1117 }
585 1118
586 - self.update_focus_visuals()?; 1119 + self.connection
1120 + .set_input_focus(InputFocus::POINTER_ROOT, window, x11rb::CURRENT_TIME)?;
1121 + self.connection.flush()?;
1122 +
1123 + self.update_focus_visuals(old_focused, window)?;
1124 + self.previous_focused = Some(window);
587 Ok(()) 1125 Ok(())
588 } 1126 }
589 1127
590 - fn update_focus_visuals(&self) -> WmResult<()> { 1128 + fn update_focus_visuals(
591 - for &window in &self.windows { 1129 + &self,
592 - let (border_color, border_width) = if self.focused_window == Some(window) { 1130 + old_focused: Option<Window>,
593 - (self.config.border_focused, self.config.border_width) 1131 + new_focused: Window,
594 - } else { 1132 + ) -> WmResult<()> {
595 - (self.config.border_unfocused, self.config.border_width) 1133 + if let Some(old_win) = old_focused {
596 - }; 1134 + if old_win != new_focused {
597 - 1135 + self.connection.configure_window(
598 - self.connection.configure_window( 1136 + old_win,
599 - window, 1137 + &ConfigureWindowAux::new().border_width(self.config.border_width),
600 - &ConfigureWindowAux::new().border_width(border_width), 1138 + )?;
601 - )?;
602 1139
603 - self.connection.change_window_attributes( 1140 + self.connection.change_window_attributes(
604 - window, 1141 + old_win,
605 - &ChangeWindowAttributesAux::new().border_pixel(border_color), 1142 + &ChangeWindowAttributesAux::new().border_pixel(self.config.border_unfocused),
606 - )?; 1143 + )?;
1144 + }
607 } 1145 }
1146 +
1147 + self.connection.configure_window(
1148 + new_focused,
1149 + &ConfigureWindowAux::new().border_width(self.config.border_width),
1150 + )?;
1151 +
1152 + self.connection.change_window_attributes(
1153 + new_focused,
1154 + &ChangeWindowAttributesAux::new().border_pixel(self.config.border_focused),
1155 + )?;
1156 +
608 self.connection.flush()?; 1157 self.connection.flush()?;
609 Ok(()) 1158 Ok(())
610 } 1159 }
@@ -742,20 +1291,33 @@ impl WindowManager {
742 return Ok(None); 1291 return Ok(None);
743 } 1292 }
744 1293
1294 + if let Ok(geom) = self.connection.get_geometry(event.window)?.reply() {
1295 + self.window_geometries
1296 + .insert(event.window, (geom.x, geom.y, geom.width, geom.height));
1297 + }
1298 +
745 self.connection.map_window(event.window)?; 1299 self.connection.map_window(event.window)?;
746 self.connection.change_window_attributes( 1300 self.connection.change_window_attributes(
747 event.window, 1301 event.window,
748 &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW), 1302 &ChangeWindowAttributesAux::new().event_mask(EventMask::ENTER_WINDOW),
749 )?; 1303 )?;
750 1304
1305 + let selected_tags = self
1306 + .monitors
1307 + .get(self.selected_monitor)
1308 + .map(|m| m.selected_tags)
1309 + .unwrap_or(tag_mask(0));
1310 +
751 self.windows.push(event.window); 1311 self.windows.push(event.window);
752 - self.window_tags.insert(event.window, self.selected_tags); 1312 + self.window_tags.insert(event.window, selected_tags);
1313 + self.window_monitor
1314 + .insert(event.window, self.selected_monitor);
753 self.set_wm_state(event.window, 1)?; 1315 self.set_wm_state(event.window, 1)?;
754 - let _ = self.save_client_tag(event.window, self.selected_tags); 1316 + let _ = self.save_client_tag(event.window, selected_tags);
755 1317
756 self.apply_layout()?; 1318 self.apply_layout()?;
757 self.update_bar()?; 1319 self.update_bar()?;
758 - self.set_focus(Some(event.window))?; 1320 + self.set_focus(event.window)?;
759 } 1321 }
760 Event::UnmapNotify(event) => { 1322 Event::UnmapNotify(event) => {
761 if self.windows.contains(&event.window) && self.is_window_visible(event.window) { 1323 if self.windows.contains(&event.window) && self.is_window_visible(event.window) {
@@ -772,7 +1334,26 @@ impl WindowManager {
772 return Ok(None); 1334 return Ok(None);
773 } 1335 }
774 if self.windows.contains(&event.event) { 1336 if self.windows.contains(&event.event) {
775 - self.set_focus(Some(event.event))?; 1337 + self.set_focus(event.event)?;
1338 + }
1339 + }
1340 + Event::MotionNotify(event) => {
1341 + if event.event != self.root {
1342 + return Ok(None);
1343 + }
1344 +
1345 + if let Some(monitor_index) =
1346 + self.get_monitor_at_point(event.root_x as i32, event.root_y as i32)
1347 + {
1348 + if monitor_index != self.selected_monitor {
1349 + self.selected_monitor = monitor_index;
1350 + self.update_bar()?;
1351 +
1352 + let visible = self.visible_windows_on_monitor(monitor_index);
1353 + if let Some(&win) = visible.first() {
1354 + self.set_focus(win)?;
1355 + }
1356 + }
776 } 1357 }
777 } 1358 }
778 Event::KeyPress(event) => { 1359 Event::KeyPress(event) => {
@@ -784,12 +1365,21 @@ impl WindowManager {
784 } 1365 }
785 } 1366 }
786 Event::ButtonPress(event) => { 1367 Event::ButtonPress(event) => {
787 - if event.event == self.bar.window() { 1368 + let is_bar_click = self
788 - if let Some(tag_index) = self.bar.handle_click(event.event_x) { 1369 + .bars
1370 + .iter()
1371 + .enumerate()
1372 + .find(|(_, bar)| bar.window() == event.event);
1373 +
1374 + if let Some((monitor_index, bar)) = is_bar_click {
1375 + if let Some(tag_index) = bar.handle_click(event.event_x) {
1376 + if monitor_index != self.selected_monitor {
1377 + self.selected_monitor = monitor_index;
1378 + }
789 self.view_tag(tag_index)?; 1379 self.view_tag(tag_index)?;
790 } 1380 }
791 } else if event.child != x11rb::NONE { 1381 } else if event.child != x11rb::NONE {
792 - self.set_focus(Some(event.child))?; 1382 + self.set_focus(event.child)?;
793 1383
794 if event.detail == ButtonIndex::M1.into() { 1384 if event.detail == ButtonIndex::M1.into() {
795 self.move_mouse(event.child)?; 1385 self.move_mouse(event.child)?;
@@ -799,9 +1389,12 @@ impl WindowManager {
799 } 1389 }
800 } 1390 }
801 Event::Expose(event) => { 1391 Event::Expose(event) => {
802 - if event.window == self.bar.window() { 1392 + for bar in &mut self.bars {
803 - self.bar.invalidate(); 1393 + if event.window == bar.window() {
804 - self.update_bar()?; 1394 + bar.invalidate();
1395 + self.update_bar()?;
1396 + break;
1397 + }
805 } 1398 }
806 } 1399 }
807 _ => {} 1400 _ => {}
@@ -813,12 +1406,12 @@ impl WindowManager {
813 if self.fullscreen_window.is_some() { 1406 if self.fullscreen_window.is_some() {
814 return Ok(()); 1407 return Ok(());
815 } 1408 }
816 - let screen_width = self.screen.width_in_pixels as u32;
817 - let screen_height = self.screen.height_in_pixels as u32;
818 - let border_width = self.config.border_width;
819 1409
820 - let bar_height = self.bar.height() as u32; 1410 + if self.layout.name() == crate::layout::NORMIE {
821 - let usable_height = screen_height.saturating_sub(bar_height); 1411 + return Ok(());
1412 + }
1413 +
1414 + let border_width = self.config.border_width;
822 1415
823 let gaps = if self.gaps_enabled { 1416 let gaps = if self.gaps_enabled {
824 GapConfig { 1417 GapConfig {
@@ -836,54 +1429,93 @@ impl WindowManager {
836 } 1429 }
837 }; 1430 };
838 1431
839 - let visible: Vec<Window> = self 1432 + for (monitor_index, monitor) in self.monitors.iter().enumerate() {
840 - .visible_windows() 1433 + let visible: Vec<Window> = self
841 - .into_iter() 1434 + .windows
842 - .filter(|w| !self.floating_windows.contains(w)) 1435 + .iter()
843 - .collect(); 1436 + .filter(|&&w| {
1437 + let window_mon = self.window_monitor.get(&w).copied().unwrap_or(0);
1438 + if window_mon != monitor_index {
1439 + return false;
1440 + }
1441 + if self.floating_windows.contains(&w) {
1442 + return false;
1443 + }
1444 + if let Some(&tags) = self.window_tags.get(&w) {
1445 + (tags & monitor.selected_tags) != 0
1446 + } else {
1447 + false
1448 + }
1449 + })
1450 + .copied()
1451 + .collect();
1452 +
1453 + let bar_height = self
1454 + .bars
1455 + .get(monitor_index)
1456 + .map(|b| b.height() as u32)
1457 + .unwrap_or(0);
1458 + let usable_height = monitor.height.saturating_sub(bar_height);
844 1459
845 - let geometries = self 1460 + let geometries = self
846 - .layout 1461 + .layout
847 - .arrange(&visible, screen_width, usable_height, &gaps); 1462 + .arrange(&visible, monitor.width, usable_height, &gaps);
848 1463
849 - for (window, geometry) in visible.iter().zip(geometries.iter()) { 1464 + for (window, geometry) in visible.iter().zip(geometries.iter()) {
850 - let adjusted_width = geometry.width.saturating_sub(2 * border_width); 1465 + let adjusted_width = geometry.width.saturating_sub(2 * border_width);
851 - let adjusted_height = geometry.height.saturating_sub(2 * border_width); 1466 + let adjusted_height = geometry.height.saturating_sub(2 * border_width);
852 1467
853 - let adjusted_y = geometry.y_coordinate + bar_height as i32; 1468 + let adjusted_x = geometry.x_coordinate + monitor.x;
1469 + let adjusted_y = geometry.y_coordinate + monitor.y + bar_height as i32;
854 1470
855 - self.connection.configure_window( 1471 + self.connection.configure_window(
856 - *window, 1472 + *window,
857 - &ConfigureWindowAux::new() 1473 + &ConfigureWindowAux::new()
858 - .x(geometry.x_coordinate) 1474 + .x(adjusted_x)
859 - .y(adjusted_y) 1475 + .y(adjusted_y)
860 - .width(adjusted_width) 1476 + .width(adjusted_width)
861 - .height(adjusted_height), 1477 + .height(adjusted_height),
862 - )?; 1478 + )?;
1479 + }
863 } 1480 }
1481 +
864 self.connection.flush()?; 1482 self.connection.flush()?;
865 Ok(()) 1483 Ok(())
866 } 1484 }
867 1485
1486 + pub fn change_layout<L: Layout + 'static>(&mut self, new_layout: L) -> WmResult<()> {
1487 + self.layout = Box::new(new_layout);
1488 + self.apply_layout()?;
1489 + Ok(())
1490 + }
1491 +
868 fn remove_window(&mut self, window: Window) -> WmResult<()> { 1492 fn remove_window(&mut self, window: Window) -> WmResult<()> {
869 let initial_count = self.windows.len(); 1493 let initial_count = self.windows.len();
870 self.windows.retain(|&w| w != window); 1494 self.windows.retain(|&w| w != window);
871 self.window_tags.remove(&window); 1495 self.window_tags.remove(&window);
1496 + self.window_monitor.remove(&window);
1497 + self.window_geometries.remove(&window);
872 self.floating_windows.remove(&window); 1498 self.floating_windows.remove(&window);
873 1499
874 if self.fullscreen_window == Some(window) { 1500 if self.fullscreen_window == Some(window) {
875 self.fullscreen_window = None; 1501 self.fullscreen_window = None;
876 - self.connection.map_window(self.bar.window())?; 1502 + for bar in &self.bars {
1503 + self.connection.map_window(bar.window())?;
1504 + }
877 } 1505 }
878 1506
879 if self.windows.len() < initial_count { 1507 if self.windows.len() < initial_count {
880 - if self.focused_window == Some(window) { 1508 + let focused = self
881 - let new_focus = if self.windows.is_empty() { 1509 + .monitors
882 - None 1510 + .get(self.selected_monitor)
883 - } else { 1511 + .and_then(|m| m.focused_window);
884 - Some(self.windows[self.windows.len() - 1]) 1512 + if focused == Some(window) {
885 - }; 1513 + let visible = self.visible_windows_on_monitor(self.selected_monitor);
886 - self.set_focus(new_focus)?; 1514 + if let Some(&new_win) = visible.last() {
1515 + self.set_focus(new_win)?;
1516 + } else if let Some(monitor) = self.monitors.get_mut(self.selected_monitor) {
1517 + monitor.focused_window = None;
1518 + }
887 } 1519 }
888 1520
889 self.apply_layout()?; 1521 self.apply_layout()?;
+4 −0 templates/config.ron
@@ -26,11 +26,15 @@
26 (modifiers: [Mod4], key: Q, action: KillClient), 26 (modifiers: [Mod4], key: Q, action: KillClient),
27 (modifiers: [Mod4, Shift], key: F, action: ToggleFullScreen), 27 (modifiers: [Mod4, Shift], key: F, action: ToggleFullScreen),
28 (modifiers: [Mod4, Shift], key: Space, action: ToggleFloating), 28 (modifiers: [Mod4, Shift], key: Space, action: ToggleFloating),
29 + (modifiers: [Mod4], key: F, action: ChangeLayout, arg: "normie"),
30 + (modifiers: [Mod4], key: C, action: ChangeLayout, arg: "tiling"),
29 (modifiers: [Mod4], key: A, action: ToggleGaps), 31 (modifiers: [Mod4], key: A, action: ToggleGaps),
30 (modifiers: [Mod4, Shift], key: Q, action: Quit), 32 (modifiers: [Mod4, Shift], key: Q, action: Quit),
31 (modifiers: [Mod4, Shift], key: R, action: Restart), 33 (modifiers: [Mod4, Shift], key: R, action: Restart),
32 (modifiers: [Mod4], key: J, action: FocusStack, arg: -1), 34 (modifiers: [Mod4], key: J, action: FocusStack, arg: -1),
33 (modifiers: [Mod4], key: K, action: FocusStack, arg: 1), 35 (modifiers: [Mod4], key: K, action: FocusStack, arg: 1),
36 + (modifiers: [Mod4], key: Comma, action: FocusMonitor, arg: -1),
37 + (modifiers: [Mod4], key: Period, action: FocusMonitor, arg: 1),
34 (modifiers: [Mod4], key: Key1, action: ViewTag, arg: 0), 38 (modifiers: [Mod4], key: Key1, action: ViewTag, arg: 0),
35 (modifiers: [Mod4], key: Key2, action: ViewTag, arg: 1), 39 (modifiers: [Mod4], key: Key2, action: ViewTag, arg: 1),
36 (modifiers: [Mod4], key: Key3, action: ViewTag, arg: 2), 40 (modifiers: [Mod4], key: Key3, action: ViewTag, arg: 2),
+144 −0 test-config.ron new file mode 100644
@@ -0,0 +1,144 @@
1 +#![enable(implicit_some)]
2 +// OXWM Configuration File
3 +// Edit this file and reload with Mod+Shift+R (no compilation needed!)
4 +
5 +(
6 + border_width: 2,
7 + border_focused: 0x6dade3,
8 + border_unfocused: 0xbbbbbb,
9 + font: "JetBrainsMono Nerd Font:style=Bold:size=12",
10 +
11 + gaps_enabled: true,
12 + gap_inner_horizontal: 5,
13 + gap_inner_vertical: 5,
14 + gap_outer_horizontal: 5,
15 + gap_outer_vertical: 5,
16 +
17 + terminal: "st",
18 + modkey: Mod1,
19 +
20 + tags: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
21 +
22 + // Alternative icon tags (uncomment to use):
23 + // tags: ["", "󰊯", "", "", "󰙯", "󱇤", "", "󱘶", "󰧮"],
24 +
25 + // Alternative text tags (uncomment to use):
26 + // tags: ["DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC"],
27 +
28 + keybindings: [
29 + (modifiers: [Mod1], key: Return, action: Spawn, arg: "st"),
30 + (modifiers: [Mod1], key: D, action: Spawn, arg: ["sh", "-c", "dmenu_run -l 10"]),
31 + (modifiers: [Mod1], key: S, action: Spawn, arg: ["sh", "-c", "maim -s | xclip -selection clipboard -t image/png"]),
32 + (modifiers: [Mod1], key: Q, action: KillClient),
33 + (modifiers: [Mod1, Shift], key: F, action: ToggleFullScreen),
34 + (modifiers: [Mod1, Shift], key: Space, action: ToggleFloating),
35 + (modifiers: [Mod1], key: F, action: ChangeLayout, arg: "normie"),
36 + (modifiers: [Mod1], key: C, action: ChangeLayout, arg: "tiling"),
37 + (modifiers: [Mod1], key: N, action: CycleLayout),
38 + (modifiers: [Mod1], key: A, action: ToggleGaps),
39 + (modifiers: [Mod1, Shift], key: Q, action: Quit),
40 + (modifiers: [Mod1, Shift], key: R, action: Restart),
41 + (modifiers: [Mod1], key: J, action: FocusStack, arg: -1),
42 + (modifiers: [Mod1], key: K, action: FocusStack, arg: 1),
43 + // Exchange client (vim-style with Mod+Shift)
44 + (modifiers: [Mod1, Shift], key: K, action: ExchangeClient, arg: 0), // UP
45 + (modifiers: [Mod1, Shift], key: J, action: ExchangeClient, arg: 1), // DOWN
46 + (modifiers: [Mod1, Shift], key: H, action: ExchangeClient, arg: 2), // LEFT
47 + (modifiers: [Mod1, Shift], key: L, action: ExchangeClient, arg: 3), // RIGHT
48 + (modifiers: [Mod1], key: Key1, action: ViewTag, arg: 0),
49 + (modifiers: [Mod1], key: Key2, action: ViewTag, arg: 1),
50 + (modifiers: [Mod1], key: Key3, action: ViewTag, arg: 2),
51 + (modifiers: [Mod1], key: Key4, action: ViewTag, arg: 3),
52 + (modifiers: [Mod1], key: Key5, action: ViewTag, arg: 4),
53 + (modifiers: [Mod1], key: Key6, action: ViewTag, arg: 5),
54 + (modifiers: [Mod1], key: Key7, action: ViewTag, arg: 6),
55 + (modifiers: [Mod1], key: Key8, action: ViewTag, arg: 7),
56 + (modifiers: [Mod1], key: Key9, action: ViewTag, arg: 8),
57 + (modifiers: [Mod1, Shift], key: Key1, action: MoveToTag, arg: 0),
58 + (modifiers: [Mod1, Shift], key: Key2, action: MoveToTag, arg: 1),
59 + (modifiers: [Mod1, Shift], key: Key3, action: MoveToTag, arg: 2),
60 + (modifiers: [Mod1, Shift], key: Key4, action: MoveToTag, arg: 3),
61 + (modifiers: [Mod1, Shift], key: Key5, action: MoveToTag, arg: 4),
62 + (modifiers: [Mod1, Shift], key: Key6, action: MoveToTag, arg: 5),
63 + (modifiers: [Mod1, Shift], key: Key7, action: MoveToTag, arg: 6),
64 + (modifiers: [Mod1, Shift], key: Key8, action: MoveToTag, arg: 7),
65 + (modifiers: [Mod1, Shift], key: Key9, action: MoveToTag, arg: 8),
66 + ],
67 +
68 + status_blocks: [
69 + // Battery block (shows charging/discharging status)
70 + (
71 + format: "",
72 + command: "Battery",
73 + battery_formats: (
74 + charging: "󰂄 Bat: {}%",
75 + discharging: "󰁹 Bat:{}%",
76 + full: "󰁹 Bat: {}%",
77 + ),
78 + interval_secs: 30,
79 + color: 0x9ece6a,
80 + underline: true,
81 + ),
82 +
83 + // Separator
84 + (
85 + format: " │ ",
86 + command: "Static",
87 + interval_secs: 18446744073709551615,
88 + color: 0xa9b1d6,
89 + underline: false,
90 + ),
91 +
92 + // RAM usage
93 + (
94 + format: "󰍛 {used}/{total} GB",
95 + command: "Ram",
96 + interval_secs: 5,
97 + color: 0x7aa2f7,
98 + underline: true,
99 + ),
100 +
101 + // Separator
102 + (
103 + format: " │ ",
104 + command: "Static",
105 + interval_secs: 18446744073709551615,
106 + color: 0xa9b1d6,
107 + underline: false,
108 + ),
109 +
110 + // Kernel version
111 + (
112 + format: " {}",
113 + command: "Shell",
114 + command_arg: "uname -r",
115 + interval_secs: 18446744073709551615,
116 + color: 0xf7768e,
117 + underline: true,
118 + ),
119 +
120 + // Separator
121 + (
122 + format: " │ ",
123 + command: "Static",
124 + interval_secs: 18446744073709551615,
125 + color: 0xa9b1d6,
126 + underline: false,
127 + ),
128 +
129 + // Date and time
130 + (
131 + format: "󰸘 {}",
132 + command: "DateTime",
133 + command_arg: "%a, %b %d - %-I:%M %P",
134 + interval_secs: 1,
135 + color: 0x0db9d7,
136 + underline: true,
137 + ),
138 + ],
139 +
140 + scheme_normal: (foreground: 0xbbbbbb, background: 0x1a1b26, underline: 0x444444),
141 + scheme_occupied: (foreground: 0x0db9d7, background: 0x1a1b26, underline: 0x0db9d7),
142 + scheme_selected: (foreground: 0x0db9d7, background: 0x1a1b26, underline: 0xad8ee6),
143 +)
144 +