| 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 | #![warn(missing_docs)] |
| 54 | |
| 55 | use std::collections::HashMap; |
| 56 | use std::str::FromStr; |
| 57 | use std::time::Duration; |
| 58 | |
| 59 | use serde::{Deserialize, Serialize}; |
| 60 | |
| 61 | pub mod socket; |
| 62 | pub mod state; |
| 63 | |
| 64 | |
| 65 | #[derive(Debug, Serialize, Deserialize, Clone)] |
| 66 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 67 | pub enum Request { |
| 68 | |
| 69 | Version, |
| 70 | |
| 71 | Outputs, |
| 72 | |
| 73 | Workspaces, |
| 74 | |
| 75 | Windows, |
| 76 | |
| 77 | Layers, |
| 78 | |
| 79 | KeyboardLayouts, |
| 80 | |
| 81 | FocusedOutput, |
| 82 | |
| 83 | FocusedWindow, |
| 84 | |
| 85 | PickWindow, |
| 86 | |
| 87 | PickColor, |
| 88 | |
| 89 | Action(Action), |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | Output { |
| 96 | |
| 97 | output: String, |
| 98 | |
| 99 | action: OutputAction, |
| 100 | }, |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | EventStream, |
| 116 | |
| 117 | ReturnError, |
| 118 | |
| 119 | OverviewState, |
| 120 | |
| 121 | Casts, |
| 122 | } |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | pub type Reply = Result<Response, String>; |
| 133 | |
| 134 | |
| 135 | #[derive(Debug, Serialize, Deserialize, Clone)] |
| 136 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 137 | pub enum Response { |
| 138 | |
| 139 | Handled, |
| 140 | |
| 141 | Version(String), |
| 142 | |
| 143 | |
| 144 | |
| 145 | Outputs(HashMap<String, Output>), |
| 146 | |
| 147 | Workspaces(Vec<Workspace>), |
| 148 | |
| 149 | Windows(Vec<Window>), |
| 150 | |
| 151 | Layers(Vec<LayerSurface>), |
| 152 | |
| 153 | KeyboardLayouts(KeyboardLayouts), |
| 154 | |
| 155 | FocusedOutput(Option<Output>), |
| 156 | |
| 157 | FocusedWindow(Option<Window>), |
| 158 | |
| 159 | PickedWindow(Option<Window>), |
| 160 | |
| 161 | PickedColor(Option<PickedColor>), |
| 162 | |
| 163 | OutputConfigChanged(OutputConfigChanged), |
| 164 | |
| 165 | OverviewState(Overview), |
| 166 | |
| 167 | Casts(Vec<Cast>), |
| 168 | } |
| 169 | |
| 170 | |
| 171 | #[derive(Serialize, Deserialize, Debug, Clone)] |
| 172 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 173 | pub struct Overview { |
| 174 | |
| 175 | pub is_open: bool, |
| 176 | } |
| 177 | |
| 178 | |
| 179 | #[derive(Serialize, Deserialize, Debug, Clone)] |
| 180 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 181 | pub struct PickedColor { |
| 182 | |
| 183 | pub rgb: [f64; 3], |
| 184 | } |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | #[derive(Serialize, Deserialize, Debug, Clone)] |
| 190 | #[cfg_attr(feature = "clap", derive(clap::Parser))] |
| 191 | #[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))] |
| 192 | #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))] |
| 193 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 194 | pub enum Action { |
| 195 | |
| 196 | Quit { |
| 197 | |
| 198 | #[serde(default)] |
| 199 | #[cfg_attr(feature = "clap", arg(short, long))] |
| 200 | skip_confirmation: bool, |
| 201 | }, |
| 202 | |
| 203 | PowerOffMonitors {}, |
| 204 | |
| 205 | PowerOnMonitors {}, |
| 206 | |
| 207 | Spawn { |
| 208 | |
| 209 | #[cfg_attr(feature = "clap", arg(last = true, required = true))] |
| 210 | command: Vec<String>, |
| 211 | }, |
| 212 | |
| 213 | SpawnSh { |
| 214 | |
| 215 | #[cfg_attr(feature = "clap", arg(last = true, required = true))] |
| 216 | command: String, |
| 217 | }, |
| 218 | |
| 219 | DoScreenTransition { |
| 220 | |
| 221 | #[cfg_attr(feature = "clap", arg(short, long))] |
| 222 | delay_ms: Option<u16>, |
| 223 | }, |
| 224 | |
| 225 | Screenshot { |
| 226 | |
| 227 | #[serde(default = "default_true")] |
| 228 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 229 | show_pointer: bool, |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set))] |
| 237 | path: Option<String>, |
| 238 | }, |
| 239 | |
| 240 | ScreenshotScreen { |
| 241 | |
| 242 | |
| 243 | |
| 244 | #[serde(default = "default_true")] |
| 245 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 246 | write_to_disk: bool, |
| 247 | |
| 248 | |
| 249 | #[serde(default = "default_true")] |
| 250 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 251 | show_pointer: bool, |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set))] |
| 259 | path: Option<String>, |
| 260 | }, |
| 261 | |
| 262 | #[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))] |
| 263 | ScreenshotWindow { |
| 264 | |
| 265 | |
| 266 | |
| 267 | #[cfg_attr(feature = "clap", arg(long))] |
| 268 | id: Option<u64>, |
| 269 | |
| 270 | |
| 271 | |
| 272 | #[serde(default = "default_true")] |
| 273 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 274 | write_to_disk: bool, |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | #[serde(default)] |
| 281 | #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = false))] |
| 282 | show_pointer: bool, |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set))] |
| 290 | path: Option<String>, |
| 291 | }, |
| 292 | |
| 293 | ToggleKeyboardShortcutsInhibit {}, |
| 294 | |
| 295 | #[cfg_attr(feature = "clap", clap(about = "Close the focused window"))] |
| 296 | CloseWindow { |
| 297 | |
| 298 | |
| 299 | |
| 300 | #[cfg_attr(feature = "clap", arg(long))] |
| 301 | id: Option<u64>, |
| 302 | }, |
| 303 | |
| 304 | #[cfg_attr( |
| 305 | feature = "clap", |
| 306 | clap(about = "Toggle fullscreen on the focused window") |
| 307 | )] |
| 308 | FullscreenWindow { |
| 309 | |
| 310 | |
| 311 | |
| 312 | #[cfg_attr(feature = "clap", arg(long))] |
| 313 | id: Option<u64>, |
| 314 | }, |
| 315 | |
| 316 | #[cfg_attr( |
| 317 | feature = "clap", |
| 318 | clap(about = "Toggle windowed (fake) fullscreen on the focused window") |
| 319 | )] |
| 320 | ToggleWindowedFullscreen { |
| 321 | |
| 322 | |
| 323 | |
| 324 | #[cfg_attr(feature = "clap", arg(long))] |
| 325 | id: Option<u64>, |
| 326 | }, |
| 327 | |
| 328 | FocusWindow { |
| 329 | |
| 330 | #[cfg_attr(feature = "clap", arg(long))] |
| 331 | id: u64, |
| 332 | }, |
| 333 | |
| 334 | FocusWindowInColumn { |
| 335 | |
| 336 | |
| 337 | |
| 338 | #[cfg_attr(feature = "clap", arg())] |
| 339 | index: u8, |
| 340 | }, |
| 341 | |
| 342 | FocusWindowPrevious {}, |
| 343 | |
| 344 | FocusColumnLeft {}, |
| 345 | |
| 346 | FocusColumnRight {}, |
| 347 | |
| 348 | FocusColumnFirst {}, |
| 349 | |
| 350 | FocusColumnLast {}, |
| 351 | |
| 352 | FocusColumnRightOrFirst {}, |
| 353 | |
| 354 | FocusColumnLeftOrLast {}, |
| 355 | |
| 356 | FocusColumn { |
| 357 | |
| 358 | |
| 359 | |
| 360 | #[cfg_attr(feature = "clap", arg())] |
| 361 | index: usize, |
| 362 | }, |
| 363 | |
| 364 | FocusWindowOrMonitorUp {}, |
| 365 | |
| 366 | FocusWindowOrMonitorDown {}, |
| 367 | |
| 368 | FocusColumnOrMonitorLeft {}, |
| 369 | |
| 370 | FocusColumnOrMonitorRight {}, |
| 371 | |
| 372 | FocusWindowDown {}, |
| 373 | |
| 374 | FocusWindowUp {}, |
| 375 | |
| 376 | FocusWindowDownOrColumnLeft {}, |
| 377 | |
| 378 | FocusWindowDownOrColumnRight {}, |
| 379 | |
| 380 | FocusWindowUpOrColumnLeft {}, |
| 381 | |
| 382 | FocusWindowUpOrColumnRight {}, |
| 383 | |
| 384 | FocusWindowOrWorkspaceDown {}, |
| 385 | |
| 386 | FocusWindowOrWorkspaceUp {}, |
| 387 | |
| 388 | FocusWindowTop {}, |
| 389 | |
| 390 | FocusWindowBottom {}, |
| 391 | |
| 392 | FocusWindowDownOrTop {}, |
| 393 | |
| 394 | FocusWindowUpOrBottom {}, |
| 395 | |
| 396 | MoveColumnLeft {}, |
| 397 | |
| 398 | MoveColumnRight {}, |
| 399 | |
| 400 | MoveColumnToFirst {}, |
| 401 | |
| 402 | MoveColumnToLast {}, |
| 403 | |
| 404 | MoveColumnLeftOrToMonitorLeft {}, |
| 405 | |
| 406 | MoveColumnRightOrToMonitorRight {}, |
| 407 | |
| 408 | MoveColumnToIndex { |
| 409 | |
| 410 | |
| 411 | |
| 412 | #[cfg_attr(feature = "clap", arg())] |
| 413 | index: usize, |
| 414 | }, |
| 415 | |
| 416 | MoveWindowDown {}, |
| 417 | |
| 418 | MoveWindowUp {}, |
| 419 | |
| 420 | MoveWindowDownOrToWorkspaceDown {}, |
| 421 | |
| 422 | MoveWindowUpOrToWorkspaceUp {}, |
| 423 | |
| 424 | #[cfg_attr( |
| 425 | feature = "clap", |
| 426 | clap(about = "Consume or expel the focused window left") |
| 427 | )] |
| 428 | ConsumeOrExpelWindowLeft { |
| 429 | |
| 430 | |
| 431 | |
| 432 | #[cfg_attr(feature = "clap", arg(long))] |
| 433 | id: Option<u64>, |
| 434 | }, |
| 435 | |
| 436 | #[cfg_attr( |
| 437 | feature = "clap", |
| 438 | clap(about = "Consume or expel the focused window right") |
| 439 | )] |
| 440 | ConsumeOrExpelWindowRight { |
| 441 | |
| 442 | |
| 443 | |
| 444 | #[cfg_attr(feature = "clap", arg(long))] |
| 445 | id: Option<u64>, |
| 446 | }, |
| 447 | |
| 448 | ConsumeWindowIntoColumn {}, |
| 449 | |
| 450 | ExpelWindowFromColumn {}, |
| 451 | |
| 452 | SwapWindowRight {}, |
| 453 | |
| 454 | SwapWindowLeft {}, |
| 455 | |
| 456 | ToggleColumnTabbedDisplay {}, |
| 457 | |
| 458 | SetColumnDisplay { |
| 459 | |
| 460 | #[cfg_attr(feature = "clap", arg())] |
| 461 | display: ColumnDisplay, |
| 462 | }, |
| 463 | |
| 464 | CenterColumn {}, |
| 465 | |
| 466 | #[cfg_attr( |
| 467 | feature = "clap", |
| 468 | clap(about = "Center the focused window on the screen") |
| 469 | )] |
| 470 | CenterWindow { |
| 471 | |
| 472 | |
| 473 | |
| 474 | #[cfg_attr(feature = "clap", arg(long))] |
| 475 | id: Option<u64>, |
| 476 | }, |
| 477 | |
| 478 | CenterVisibleColumns {}, |
| 479 | |
| 480 | FocusWorkspaceDown {}, |
| 481 | |
| 482 | FocusWorkspaceUp {}, |
| 483 | |
| 484 | FocusWorkspace { |
| 485 | |
| 486 | #[cfg_attr(feature = "clap", arg())] |
| 487 | reference: WorkspaceReferenceArg, |
| 488 | }, |
| 489 | |
| 490 | FocusWorkspacePrevious {}, |
| 491 | |
| 492 | MoveWindowToWorkspaceDown { |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | #[serde(default = "default_true")] |
| 498 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 499 | focus: bool, |
| 500 | }, |
| 501 | |
| 502 | MoveWindowToWorkspaceUp { |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | #[serde(default = "default_true")] |
| 508 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 509 | focus: bool, |
| 510 | }, |
| 511 | |
| 512 | #[cfg_attr( |
| 513 | feature = "clap", |
| 514 | clap(about = "Move the focused window to a workspace by reference (index or name)") |
| 515 | )] |
| 516 | MoveWindowToWorkspace { |
| 517 | |
| 518 | |
| 519 | |
| 520 | #[cfg_attr(feature = "clap", arg(long))] |
| 521 | window_id: Option<u64>, |
| 522 | |
| 523 | |
| 524 | #[cfg_attr(feature = "clap", arg())] |
| 525 | reference: WorkspaceReferenceArg, |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | #[serde(default = "default_true")] |
| 533 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 534 | focus: bool, |
| 535 | }, |
| 536 | |
| 537 | MoveColumnToWorkspaceDown { |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | #[serde(default = "default_true")] |
| 543 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 544 | focus: bool, |
| 545 | }, |
| 546 | |
| 547 | MoveColumnToWorkspaceUp { |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | #[serde(default = "default_true")] |
| 553 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 554 | focus: bool, |
| 555 | }, |
| 556 | |
| 557 | MoveColumnToWorkspace { |
| 558 | |
| 559 | #[cfg_attr(feature = "clap", arg())] |
| 560 | reference: WorkspaceReferenceArg, |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | #[serde(default = "default_true")] |
| 567 | #[cfg_attr(feature = "clap", arg(long, action = clap::ArgAction::Set, default_value_t = true))] |
| 568 | focus: bool, |
| 569 | }, |
| 570 | |
| 571 | MoveWorkspaceDown {}, |
| 572 | |
| 573 | MoveWorkspaceUp {}, |
| 574 | |
| 575 | #[cfg_attr( |
| 576 | feature = "clap", |
| 577 | clap(about = "Move the focused workspace to a specific index on its monitor") |
| 578 | )] |
| 579 | MoveWorkspaceToIndex { |
| 580 | |
| 581 | #[cfg_attr(feature = "clap", arg())] |
| 582 | index: usize, |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | #[cfg_attr(feature = "clap", arg(long))] |
| 588 | reference: Option<WorkspaceReferenceArg>, |
| 589 | }, |
| 590 | |
| 591 | #[cfg_attr( |
| 592 | feature = "clap", |
| 593 | clap(about = "Set the name of the focused workspace") |
| 594 | )] |
| 595 | SetWorkspaceName { |
| 596 | |
| 597 | #[cfg_attr(feature = "clap", arg())] |
| 598 | name: String, |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | #[cfg_attr(feature = "clap", arg(long))] |
| 604 | workspace: Option<WorkspaceReferenceArg>, |
| 605 | }, |
| 606 | |
| 607 | #[cfg_attr( |
| 608 | feature = "clap", |
| 609 | clap(about = "Unset the name of the focused workspace") |
| 610 | )] |
| 611 | UnsetWorkspaceName { |
| 612 | |
| 613 | |
| 614 | |
| 615 | #[cfg_attr(feature = "clap", arg())] |
| 616 | reference: Option<WorkspaceReferenceArg>, |
| 617 | }, |
| 618 | |
| 619 | FocusMonitorLeft {}, |
| 620 | |
| 621 | FocusMonitorRight {}, |
| 622 | |
| 623 | FocusMonitorDown {}, |
| 624 | |
| 625 | FocusMonitorUp {}, |
| 626 | |
| 627 | FocusMonitorPrevious {}, |
| 628 | |
| 629 | FocusMonitorNext {}, |
| 630 | |
| 631 | FocusMonitor { |
| 632 | |
| 633 | #[cfg_attr(feature = "clap", arg())] |
| 634 | output: String, |
| 635 | }, |
| 636 | |
| 637 | MoveWindowToMonitorLeft {}, |
| 638 | |
| 639 | MoveWindowToMonitorRight {}, |
| 640 | |
| 641 | MoveWindowToMonitorDown {}, |
| 642 | |
| 643 | MoveWindowToMonitorUp {}, |
| 644 | |
| 645 | MoveWindowToMonitorPrevious {}, |
| 646 | |
| 647 | MoveWindowToMonitorNext {}, |
| 648 | |
| 649 | #[cfg_attr( |
| 650 | feature = "clap", |
| 651 | clap(about = "Move the focused window to a specific monitor") |
| 652 | )] |
| 653 | MoveWindowToMonitor { |
| 654 | |
| 655 | |
| 656 | |
| 657 | #[cfg_attr(feature = "clap", arg(long))] |
| 658 | id: Option<u64>, |
| 659 | |
| 660 | |
| 661 | #[cfg_attr(feature = "clap", arg())] |
| 662 | output: String, |
| 663 | }, |
| 664 | |
| 665 | MoveColumnToMonitorLeft {}, |
| 666 | |
| 667 | MoveColumnToMonitorRight {}, |
| 668 | |
| 669 | MoveColumnToMonitorDown {}, |
| 670 | |
| 671 | MoveColumnToMonitorUp {}, |
| 672 | |
| 673 | MoveColumnToMonitorPrevious {}, |
| 674 | |
| 675 | MoveColumnToMonitorNext {}, |
| 676 | |
| 677 | MoveColumnToMonitor { |
| 678 | |
| 679 | #[cfg_attr(feature = "clap", arg())] |
| 680 | output: String, |
| 681 | }, |
| 682 | |
| 683 | #[cfg_attr( |
| 684 | feature = "clap", |
| 685 | clap(about = "Change the width of the focused window") |
| 686 | )] |
| 687 | SetWindowWidth { |
| 688 | |
| 689 | |
| 690 | |
| 691 | #[cfg_attr(feature = "clap", arg(long))] |
| 692 | id: Option<u64>, |
| 693 | |
| 694 | |
| 695 | #[cfg_attr(feature = "clap", arg(allow_hyphen_values = true))] |
| 696 | change: SizeChange, |
| 697 | }, |
| 698 | |
| 699 | #[cfg_attr( |
| 700 | feature = "clap", |
| 701 | clap(about = "Change the height of the focused window") |
| 702 | )] |
| 703 | SetWindowHeight { |
| 704 | |
| 705 | |
| 706 | |
| 707 | #[cfg_attr(feature = "clap", arg(long))] |
| 708 | id: Option<u64>, |
| 709 | |
| 710 | |
| 711 | #[cfg_attr(feature = "clap", arg(allow_hyphen_values = true))] |
| 712 | change: SizeChange, |
| 713 | }, |
| 714 | |
| 715 | #[cfg_attr( |
| 716 | feature = "clap", |
| 717 | clap(about = "Reset the height of the focused window back to automatic") |
| 718 | )] |
| 719 | ResetWindowHeight { |
| 720 | |
| 721 | |
| 722 | |
| 723 | #[cfg_attr(feature = "clap", arg(long))] |
| 724 | id: Option<u64>, |
| 725 | }, |
| 726 | |
| 727 | SwitchPresetColumnWidth {}, |
| 728 | |
| 729 | SwitchPresetColumnWidthBack {}, |
| 730 | |
| 731 | SwitchPresetWindowWidth { |
| 732 | |
| 733 | |
| 734 | |
| 735 | #[cfg_attr(feature = "clap", arg(long))] |
| 736 | id: Option<u64>, |
| 737 | }, |
| 738 | |
| 739 | SwitchPresetWindowWidthBack { |
| 740 | |
| 741 | |
| 742 | |
| 743 | #[cfg_attr(feature = "clap", arg(long))] |
| 744 | id: Option<u64>, |
| 745 | }, |
| 746 | |
| 747 | SwitchPresetWindowHeight { |
| 748 | |
| 749 | |
| 750 | |
| 751 | #[cfg_attr(feature = "clap", arg(long))] |
| 752 | id: Option<u64>, |
| 753 | }, |
| 754 | |
| 755 | SwitchPresetWindowHeightBack { |
| 756 | |
| 757 | |
| 758 | |
| 759 | #[cfg_attr(feature = "clap", arg(long))] |
| 760 | id: Option<u64>, |
| 761 | }, |
| 762 | |
| 763 | MaximizeColumn {}, |
| 764 | |
| 765 | MaximizeWindowToEdges { |
| 766 | |
| 767 | |
| 768 | |
| 769 | #[cfg_attr(feature = "clap", arg(long))] |
| 770 | id: Option<u64>, |
| 771 | }, |
| 772 | |
| 773 | SetColumnWidth { |
| 774 | |
| 775 | #[cfg_attr(feature = "clap", arg(allow_hyphen_values = true))] |
| 776 | change: SizeChange, |
| 777 | }, |
| 778 | |
| 779 | ExpandColumnToAvailableWidth {}, |
| 780 | |
| 781 | SwitchLayout { |
| 782 | |
| 783 | #[cfg_attr(feature = "clap", arg())] |
| 784 | layout: LayoutSwitchTarget, |
| 785 | }, |
| 786 | |
| 787 | ShowHotkeyOverlay {}, |
| 788 | |
| 789 | MoveWorkspaceToMonitorLeft {}, |
| 790 | |
| 791 | MoveWorkspaceToMonitorRight {}, |
| 792 | |
| 793 | MoveWorkspaceToMonitorDown {}, |
| 794 | |
| 795 | MoveWorkspaceToMonitorUp {}, |
| 796 | |
| 797 | MoveWorkspaceToMonitorPrevious {}, |
| 798 | |
| 799 | MoveWorkspaceToMonitorNext {}, |
| 800 | |
| 801 | #[cfg_attr( |
| 802 | feature = "clap", |
| 803 | clap(about = "Move the focused workspace to a specific monitor") |
| 804 | )] |
| 805 | MoveWorkspaceToMonitor { |
| 806 | |
| 807 | #[cfg_attr(feature = "clap", arg())] |
| 808 | output: String, |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | #[cfg_attr(feature = "clap", arg(long))] |
| 814 | reference: Option<WorkspaceReferenceArg>, |
| 815 | }, |
| 816 | |
| 817 | ToggleDebugTint {}, |
| 818 | |
| 819 | DebugToggleOpaqueRegions {}, |
| 820 | |
| 821 | DebugToggleDamage {}, |
| 822 | |
| 823 | ToggleTouchpad {}, |
| 824 | |
| 825 | ToggleWindowFloating { |
| 826 | |
| 827 | |
| 828 | |
| 829 | #[cfg_attr(feature = "clap", arg(long))] |
| 830 | id: Option<u64>, |
| 831 | }, |
| 832 | |
| 833 | MoveWindowToFloating { |
| 834 | |
| 835 | |
| 836 | |
| 837 | #[cfg_attr(feature = "clap", arg(long))] |
| 838 | id: Option<u64>, |
| 839 | }, |
| 840 | |
| 841 | MoveWindowToTiling { |
| 842 | |
| 843 | |
| 844 | |
| 845 | #[cfg_attr(feature = "clap", arg(long))] |
| 846 | id: Option<u64>, |
| 847 | }, |
| 848 | |
| 849 | FocusFloating {}, |
| 850 | |
| 851 | FocusTiling {}, |
| 852 | |
| 853 | SwitchFocusBetweenFloatingAndTiling {}, |
| 854 | |
| 855 | #[cfg_attr(feature = "clap", clap(about = "Move the floating window on screen"))] |
| 856 | MoveFloatingWindow { |
| 857 | |
| 858 | |
| 859 | |
| 860 | #[cfg_attr(feature = "clap", arg(long))] |
| 861 | id: Option<u64>, |
| 862 | |
| 863 | |
| 864 | #[serde(default = "default_position_change")] |
| 865 | #[cfg_attr( |
| 866 | feature = "clap", |
| 867 | arg(short, long, default_value = "+0", allow_hyphen_values = true) |
| 868 | )] |
| 869 | x: PositionChange, |
| 870 | |
| 871 | |
| 872 | #[serde(default = "default_position_change")] |
| 873 | #[cfg_attr( |
| 874 | feature = "clap", |
| 875 | arg(short, long, default_value = "+0", allow_hyphen_values = true) |
| 876 | )] |
| 877 | y: PositionChange, |
| 878 | }, |
| 879 | |
| 880 | #[cfg_attr( |
| 881 | feature = "clap", |
| 882 | clap(about = "Toggle the opacity of the focused window") |
| 883 | )] |
| 884 | ToggleWindowRuleOpacity { |
| 885 | |
| 886 | |
| 887 | |
| 888 | #[cfg_attr(feature = "clap", arg(long))] |
| 889 | id: Option<u64>, |
| 890 | }, |
| 891 | |
| 892 | #[cfg_attr( |
| 893 | feature = "clap", |
| 894 | clap(about = "Set the dynamic cast target to the focused window") |
| 895 | )] |
| 896 | SetDynamicCastWindow { |
| 897 | |
| 898 | |
| 899 | |
| 900 | #[cfg_attr(feature = "clap", arg(long))] |
| 901 | id: Option<u64>, |
| 902 | }, |
| 903 | |
| 904 | #[cfg_attr( |
| 905 | feature = "clap", |
| 906 | clap(about = "Set the dynamic cast target to the focused monitor") |
| 907 | )] |
| 908 | SetDynamicCastMonitor { |
| 909 | |
| 910 | |
| 911 | |
| 912 | #[cfg_attr(feature = "clap", arg())] |
| 913 | output: Option<String>, |
| 914 | }, |
| 915 | |
| 916 | ClearDynamicCastTarget {}, |
| 917 | |
| 918 | |
| 919 | |
| 920 | StopCast { |
| 921 | |
| 922 | |
| 923 | |
| 924 | #[cfg_attr(feature = "clap", arg(long))] |
| 925 | session_id: u64, |
| 926 | }, |
| 927 | |
| 928 | ToggleOverview {}, |
| 929 | |
| 930 | OpenOverview {}, |
| 931 | |
| 932 | CloseOverview {}, |
| 933 | |
| 934 | ToggleWindowUrgent { |
| 935 | |
| 936 | #[cfg_attr(feature = "clap", arg(long))] |
| 937 | id: u64, |
| 938 | }, |
| 939 | |
| 940 | SetWindowUrgent { |
| 941 | |
| 942 | #[cfg_attr(feature = "clap", arg(long))] |
| 943 | id: u64, |
| 944 | }, |
| 945 | |
| 946 | UnsetWindowUrgent { |
| 947 | |
| 948 | #[cfg_attr(feature = "clap", arg(long))] |
| 949 | id: u64, |
| 950 | }, |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | LoadConfigFile { |
| 956 | |
| 957 | |
| 958 | |
| 959 | #[cfg_attr(feature = "clap", arg(long))] |
| 960 | path: Option<String>, |
| 961 | }, |
| 962 | } |
| 963 | |
| 964 | |
| 965 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] |
| 966 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 967 | pub enum SizeChange { |
| 968 | |
| 969 | SetFixed(i32), |
| 970 | |
| 971 | SetProportion(f64), |
| 972 | |
| 973 | AdjustFixed(i32), |
| 974 | |
| 975 | AdjustProportion(f64), |
| 976 | } |
| 977 | |
| 978 | |
| 979 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] |
| 980 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 981 | pub enum PositionChange { |
| 982 | |
| 983 | SetFixed(f64), |
| 984 | |
| 985 | SetProportion(f64), |
| 986 | |
| 987 | AdjustFixed(f64), |
| 988 | |
| 989 | AdjustProportion(f64), |
| 990 | } |
| 991 | |
| 992 | |
| 993 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] |
| 994 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 995 | pub enum WorkspaceReferenceArg { |
| 996 | |
| 997 | Id(u64), |
| 998 | |
| 999 | Index(u8), |
| 1000 | |
| 1001 | Name(String), |
| 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1006 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1007 | pub enum LayoutSwitchTarget { |
| 1008 | |
| 1009 | Next, |
| 1010 | |
| 1011 | Prev, |
| 1012 | |
| 1013 | Index(u8), |
| 1014 | } |
| 1015 | |
| 1016 | |
| 1017 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1018 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1019 | pub enum ColumnDisplay { |
| 1020 | |
| 1021 | Normal, |
| 1022 | |
| 1023 | Tabbed, |
| 1024 | } |
| 1025 | |
| 1026 | |
| 1027 | |
| 1028 | |
| 1029 | #[derive(Serialize, Deserialize, Debug, Clone)] |
| 1030 | #[cfg_attr(feature = "clap", derive(clap::Parser))] |
| 1031 | #[cfg_attr(feature = "clap", command(subcommand_value_name = "ACTION"))] |
| 1032 | #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Actions"))] |
| 1033 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1034 | pub enum OutputAction { |
| 1035 | |
| 1036 | Off, |
| 1037 | |
| 1038 | On, |
| 1039 | |
| 1040 | Mode { |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | #[cfg_attr(feature = "clap", arg())] |
| 1045 | mode: ModeToSet, |
| 1046 | }, |
| 1047 | |
| 1048 | CustomMode { |
| 1049 | |
| 1050 | #[cfg_attr(feature = "clap", arg())] |
| 1051 | mode: ConfiguredMode, |
| 1052 | }, |
| 1053 | |
| 1054 | #[cfg_attr(feature = "clap", arg())] |
| 1055 | Modeline { |
| 1056 | |
| 1057 | #[cfg_attr(feature = "clap", arg())] |
| 1058 | clock: f64, |
| 1059 | |
| 1060 | #[cfg_attr(feature = "clap", arg())] |
| 1061 | hdisplay: u16, |
| 1062 | |
| 1063 | #[cfg_attr(feature = "clap", arg())] |
| 1064 | hsync_start: u16, |
| 1065 | |
| 1066 | #[cfg_attr(feature = "clap", arg())] |
| 1067 | hsync_end: u16, |
| 1068 | |
| 1069 | |
| 1070 | #[cfg_attr(feature = "clap", arg())] |
| 1071 | htotal: u16, |
| 1072 | |
| 1073 | |
| 1074 | #[cfg_attr(feature = "clap", arg())] |
| 1075 | vdisplay: u16, |
| 1076 | |
| 1077 | #[cfg_attr(feature = "clap", arg())] |
| 1078 | vsync_start: u16, |
| 1079 | |
| 1080 | #[cfg_attr(feature = "clap", arg())] |
| 1081 | vsync_end: u16, |
| 1082 | |
| 1083 | #[cfg_attr(feature = "clap", arg())] |
| 1084 | vtotal: u16, |
| 1085 | |
| 1086 | #[cfg_attr(feature = "clap", arg(allow_hyphen_values = true))] |
| 1087 | hsync_polarity: HSyncPolarity, |
| 1088 | |
| 1089 | #[cfg_attr(feature = "clap", arg(allow_hyphen_values = true))] |
| 1090 | vsync_polarity: VSyncPolarity, |
| 1091 | }, |
| 1092 | |
| 1093 | Scale { |
| 1094 | |
| 1095 | #[cfg_attr(feature = "clap", arg())] |
| 1096 | scale: ScaleToSet, |
| 1097 | }, |
| 1098 | |
| 1099 | Transform { |
| 1100 | |
| 1101 | #[cfg_attr(feature = "clap", arg())] |
| 1102 | transform: Transform, |
| 1103 | }, |
| 1104 | |
| 1105 | Position { |
| 1106 | |
| 1107 | #[cfg_attr(feature = "clap", command(subcommand))] |
| 1108 | position: PositionToSet, |
| 1109 | }, |
| 1110 | |
| 1111 | Vrr { |
| 1112 | |
| 1113 | #[cfg_attr(feature = "clap", command(flatten))] |
| 1114 | vrr: VrrToSet, |
| 1115 | }, |
| 1116 | |
| 1117 | MaxBpc { |
| 1118 | |
| 1119 | #[cfg_attr(feature = "clap", arg())] |
| 1120 | max_bpc: MaxBpc, |
| 1121 | }, |
| 1122 | } |
| 1123 | |
| 1124 | |
| 1125 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] |
| 1126 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1127 | pub enum ModeToSet { |
| 1128 | |
| 1129 | Automatic, |
| 1130 | |
| 1131 | Specific(ConfiguredMode), |
| 1132 | } |
| 1133 | |
| 1134 | |
| 1135 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] |
| 1136 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1137 | pub struct ConfiguredMode { |
| 1138 | |
| 1139 | pub width: u16, |
| 1140 | |
| 1141 | pub height: u16, |
| 1142 | |
| 1143 | pub refresh: Option<f64>, |
| 1144 | } |
| 1145 | |
| 1146 | |
| 1147 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1148 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1149 | pub enum HSyncPolarity { |
| 1150 | |
| 1151 | PHSync, |
| 1152 | |
| 1153 | NHSync, |
| 1154 | } |
| 1155 | |
| 1156 | |
| 1157 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1158 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1159 | pub enum VSyncPolarity { |
| 1160 | |
| 1161 | PVSync, |
| 1162 | |
| 1163 | NVSync, |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] |
| 1168 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1169 | pub enum ScaleToSet { |
| 1170 | |
| 1171 | Automatic, |
| 1172 | |
| 1173 | Specific(f64), |
| 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] |
| 1178 | #[cfg_attr(feature = "clap", derive(clap::Subcommand))] |
| 1179 | #[cfg_attr(feature = "clap", command(subcommand_value_name = "POSITION"))] |
| 1180 | #[cfg_attr(feature = "clap", command(subcommand_help_heading = "Position Values"))] |
| 1181 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1182 | pub enum PositionToSet { |
| 1183 | |
| 1184 | #[cfg_attr(feature = "clap", command(name = "auto"))] |
| 1185 | Automatic, |
| 1186 | |
| 1187 | #[cfg_attr(feature = "clap", command(name = "set"))] |
| 1188 | Specific(ConfiguredPosition), |
| 1189 | } |
| 1190 | |
| 1191 | |
| 1192 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] |
| 1193 | #[cfg_attr(feature = "clap", derive(clap::Args))] |
| 1194 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1195 | pub struct ConfiguredPosition { |
| 1196 | |
| 1197 | pub x: i32, |
| 1198 | |
| 1199 | pub y: i32, |
| 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] |
| 1204 | #[cfg_attr(feature = "clap", derive(clap::Args))] |
| 1205 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1206 | pub struct VrrToSet { |
| 1207 | |
| 1208 | #[cfg_attr( |
| 1209 | feature = "clap", |
| 1210 | arg( |
| 1211 | value_name = "ON|OFF", |
| 1212 | action = clap::ArgAction::Set, |
| 1213 | value_parser = clap::builder::BoolishValueParser::new(), |
| 1214 | hide_possible_values = true, |
| 1215 | ), |
| 1216 | )] |
| 1217 | pub vrr: bool, |
| 1218 | |
| 1219 | #[serde(default)] |
| 1220 | #[cfg_attr(feature = "clap", arg(long))] |
| 1221 | pub on_demand: bool, |
| 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | #[derive(Debug, Serialize, Deserialize, Clone)] |
| 1226 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1227 | pub struct Output { |
| 1228 | |
| 1229 | pub name: String, |
| 1230 | |
| 1231 | pub make: String, |
| 1232 | |
| 1233 | pub model: String, |
| 1234 | |
| 1235 | pub serial: Option<String>, |
| 1236 | |
| 1237 | pub physical_size: Option<(u32, u32)>, |
| 1238 | |
| 1239 | pub modes: Vec<Mode>, |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | pub current_mode: Option<usize>, |
| 1244 | |
| 1245 | pub is_custom_mode: bool, |
| 1246 | |
| 1247 | pub vrr_supported: bool, |
| 1248 | |
| 1249 | pub vrr_enabled: bool, |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | pub logical: Option<LogicalOutput>, |
| 1254 | |
| 1255 | pub max_bpc: Option<u8>, |
| 1256 | } |
| 1257 | |
| 1258 | |
| 1259 | #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] |
| 1260 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1261 | pub struct Mode { |
| 1262 | |
| 1263 | pub width: u16, |
| 1264 | |
| 1265 | pub height: u16, |
| 1266 | |
| 1267 | pub refresh_rate: u32, |
| 1268 | |
| 1269 | pub is_preferred: bool, |
| 1270 | } |
| 1271 | |
| 1272 | |
| 1273 | #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] |
| 1274 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1275 | pub struct LogicalOutput { |
| 1276 | |
| 1277 | pub x: i32, |
| 1278 | |
| 1279 | pub y: i32, |
| 1280 | |
| 1281 | pub width: u32, |
| 1282 | |
| 1283 | pub height: u32, |
| 1284 | |
| 1285 | pub scale: f64, |
| 1286 | |
| 1287 | pub transform: Transform, |
| 1288 | } |
| 1289 | |
| 1290 | |
| 1291 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1292 | #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] |
| 1293 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1294 | pub enum Transform { |
| 1295 | |
| 1296 | Normal, |
| 1297 | |
| 1298 | #[serde(rename = "90")] |
| 1299 | _90, |
| 1300 | |
| 1301 | #[serde(rename = "180")] |
| 1302 | _180, |
| 1303 | |
| 1304 | #[serde(rename = "270")] |
| 1305 | _270, |
| 1306 | |
| 1307 | Flipped, |
| 1308 | |
| 1309 | #[cfg_attr(feature = "clap", value(name("flipped-90")))] |
| 1310 | Flipped90, |
| 1311 | |
| 1312 | #[cfg_attr(feature = "clap", value(name("flipped-180")))] |
| 1313 | Flipped180, |
| 1314 | |
| 1315 | #[cfg_attr(feature = "clap", value(name("flipped-270")))] |
| 1316 | Flipped270, |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, Default)] |
| 1321 | #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] |
| 1322 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1323 | pub enum MaxBpc { |
| 1324 | |
| 1325 | #[serde(rename = "6")] |
| 1326 | _6 = 6, |
| 1327 | |
| 1328 | #[default] |
| 1329 | #[serde(rename = "8")] |
| 1330 | _8 = 8, |
| 1331 | |
| 1332 | #[serde(rename = "10")] |
| 1333 | _10 = 10, |
| 1334 | |
| 1335 | #[serde(rename = "12")] |
| 1336 | _12 = 12, |
| 1337 | |
| 1338 | #[serde(rename = "14")] |
| 1339 | _14 = 14, |
| 1340 | |
| 1341 | #[serde(rename = "16")] |
| 1342 | _16 = 16, |
| 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | #[derive(Serialize, Deserialize, Debug, Clone)] |
| 1347 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1348 | pub struct Window { |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | pub id: u64, |
| 1357 | |
| 1358 | pub title: Option<String>, |
| 1359 | |
| 1360 | pub app_id: Option<String>, |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | pub pid: Option<i32>, |
| 1366 | |
| 1367 | pub workspace_id: Option<u64>, |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | pub is_focused: bool, |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | pub is_floating: bool, |
| 1376 | |
| 1377 | pub is_urgent: bool, |
| 1378 | |
| 1379 | pub layout: WindowLayout, |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | |
| 1387 | pub focus_timestamp: Option<Timestamp>, |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1392 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1393 | pub struct Timestamp { |
| 1394 | |
| 1395 | pub secs: u64, |
| 1396 | |
| 1397 | pub nanos: u32, |
| 1398 | } |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | |
| 1413 | |
| 1414 | |
| 1415 | |
| 1416 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] |
| 1417 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1418 | pub struct WindowLayout { |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | pub pos_in_scrolling_layout: Option<(usize, usize)>, |
| 1425 | |
| 1426 | pub tile_size: (f64, f64), |
| 1427 | |
| 1428 | |
| 1429 | |
| 1430 | |
| 1431 | |
| 1432 | |
| 1433 | pub window_size: (i32, i32), |
| 1434 | |
| 1435 | |
| 1436 | |
| 1437 | pub tile_pos_in_workspace_view: Option<(f64, f64)>, |
| 1438 | |
| 1439 | |
| 1440 | |
| 1441 | |
| 1442 | |
| 1443 | pub window_offset_in_tile: (f64, f64), |
| 1444 | } |
| 1445 | |
| 1446 | |
| 1447 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1448 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1449 | pub enum OutputConfigChanged { |
| 1450 | |
| 1451 | Applied, |
| 1452 | |
| 1453 | OutputWasMissing, |
| 1454 | } |
| 1455 | |
| 1456 | |
| 1457 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] |
| 1458 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1459 | pub struct Workspace { |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | pub id: u64, |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | |
| 1476 | pub idx: u8, |
| 1477 | |
| 1478 | pub name: Option<String>, |
| 1479 | |
| 1480 | |
| 1481 | |
| 1482 | pub output: Option<String>, |
| 1483 | |
| 1484 | pub is_urgent: bool, |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | pub is_active: bool, |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | pub is_focused: bool, |
| 1493 | |
| 1494 | pub active_window_id: Option<u64>, |
| 1495 | } |
| 1496 | |
| 1497 | |
| 1498 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] |
| 1499 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1500 | pub struct KeyboardLayouts { |
| 1501 | |
| 1502 | pub names: Vec<String>, |
| 1503 | |
| 1504 | pub current_idx: u8, |
| 1505 | } |
| 1506 | |
| 1507 | |
| 1508 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] |
| 1509 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1510 | pub enum Layer { |
| 1511 | |
| 1512 | Background, |
| 1513 | |
| 1514 | Bottom, |
| 1515 | |
| 1516 | Top, |
| 1517 | |
| 1518 | Overlay, |
| 1519 | } |
| 1520 | |
| 1521 | |
| 1522 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1523 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1524 | pub enum LayerSurfaceKeyboardInteractivity { |
| 1525 | |
| 1526 | None, |
| 1527 | |
| 1528 | Exclusive, |
| 1529 | |
| 1530 | OnDemand, |
| 1531 | } |
| 1532 | |
| 1533 | |
| 1534 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] |
| 1535 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1536 | pub struct LayerSurface { |
| 1537 | |
| 1538 | pub namespace: String, |
| 1539 | |
| 1540 | pub output: String, |
| 1541 | |
| 1542 | pub layer: Layer, |
| 1543 | |
| 1544 | pub keyboard_interactivity: LayerSurfaceKeyboardInteractivity, |
| 1545 | } |
| 1546 | |
| 1547 | |
| 1548 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] |
| 1549 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1550 | pub struct Cast { |
| 1551 | |
| 1552 | pub stream_id: u64, |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | |
| 1557 | |
| 1558 | |
| 1559 | pub session_id: u64, |
| 1560 | |
| 1561 | pub kind: CastKind, |
| 1562 | |
| 1563 | pub target: CastTarget, |
| 1564 | |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | |
| 1569 | pub is_dynamic_target: bool, |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | pub is_active: bool, |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | pub pid: Option<i32>, |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | pub pw_node_id: Option<u32>, |
| 1584 | } |
| 1585 | |
| 1586 | |
| 1587 | #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)] |
| 1588 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1589 | pub enum CastKind { |
| 1590 | |
| 1591 | PipeWire, |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | |
| 1597 | |
| 1598 | WlrScreencopy, |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | ExtImageCopyCapture, |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] |
| 1610 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1611 | pub enum CastTarget { |
| 1612 | |
| 1613 | Nothing {}, |
| 1614 | |
| 1615 | Output { |
| 1616 | |
| 1617 | name: String, |
| 1618 | }, |
| 1619 | |
| 1620 | Window { |
| 1621 | |
| 1622 | id: u64, |
| 1623 | }, |
| 1624 | } |
| 1625 | |
| 1626 | |
| 1627 | #[derive(Serialize, Deserialize, Debug, Clone)] |
| 1628 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
| 1629 | pub enum Event { |
| 1630 | |
| 1631 | WorkspacesChanged { |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | workspaces: Vec<Workspace>, |
| 1637 | }, |
| 1638 | |
| 1639 | WorkspaceUrgencyChanged { |
| 1640 | |
| 1641 | id: u64, |
| 1642 | |
| 1643 | urgent: bool, |
| 1644 | }, |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | WorkspaceActivated { |
| 1650 | |
| 1651 | id: u64, |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | |
| 1656 | focused: bool, |
| 1657 | }, |
| 1658 | |
| 1659 | WorkspaceActiveWindowChanged { |
| 1660 | |
| 1661 | workspace_id: u64, |
| 1662 | |
| 1663 | active_window_id: Option<u64>, |
| 1664 | }, |
| 1665 | |
| 1666 | WindowsChanged { |
| 1667 | |
| 1668 | |
| 1669 | |
| 1670 | |
| 1671 | windows: Vec<Window>, |
| 1672 | }, |
| 1673 | |
| 1674 | WindowOpenedOrChanged { |
| 1675 | |
| 1676 | |
| 1677 | |
| 1678 | window: Window, |
| 1679 | }, |
| 1680 | |
| 1681 | WindowClosed { |
| 1682 | |
| 1683 | id: u64, |
| 1684 | }, |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | WindowFocusChanged { |
| 1689 | |
| 1690 | id: Option<u64>, |
| 1691 | }, |
| 1692 | |
| 1693 | |
| 1694 | |
| 1695 | |
| 1696 | |
| 1697 | WindowFocusTimestampChanged { |
| 1698 | |
| 1699 | id: u64, |
| 1700 | |
| 1701 | focus_timestamp: Option<Timestamp>, |
| 1702 | }, |
| 1703 | |
| 1704 | WindowUrgencyChanged { |
| 1705 | |
| 1706 | id: u64, |
| 1707 | |
| 1708 | urgent: bool, |
| 1709 | }, |
| 1710 | |
| 1711 | WindowLayoutsChanged { |
| 1712 | |
| 1713 | changes: Vec<(u64, WindowLayout)>, |
| 1714 | }, |
| 1715 | |
| 1716 | KeyboardLayoutsChanged { |
| 1717 | |
| 1718 | keyboard_layouts: KeyboardLayouts, |
| 1719 | }, |
| 1720 | |
| 1721 | KeyboardLayoutSwitched { |
| 1722 | |
| 1723 | idx: u8, |
| 1724 | }, |
| 1725 | |
| 1726 | OverviewOpenedOrClosed { |
| 1727 | |
| 1728 | is_open: bool, |
| 1729 | }, |
| 1730 | |
| 1731 | |
| 1732 | |
| 1733 | |
| 1734 | ConfigLoaded { |
| 1735 | |
| 1736 | |
| 1737 | |
| 1738 | failed: bool, |
| 1739 | }, |
| 1740 | |
| 1741 | ScreenshotCaptured { |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | path: Option<String>, |
| 1747 | }, |
| 1748 | |
| 1749 | CastsChanged { |
| 1750 | |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | casts: Vec<Cast>, |
| 1755 | }, |
| 1756 | |
| 1757 | CastStartedOrChanged { |
| 1758 | |
| 1759 | cast: Cast, |
| 1760 | }, |
| 1761 | |
| 1762 | CastStopped { |
| 1763 | |
| 1764 | stream_id: u64, |
| 1765 | }, |
| 1766 | |
| 1767 | TouchpadToggled { |
| 1768 | |
| 1769 | |
| 1770 | |
| 1771 | |
| 1772 | on: bool, |
| 1773 | }, |
| 1774 | } |
| 1775 | |
| 1776 | impl From<Duration> for Timestamp { |
| 1777 | fn from(value: Duration) -> Self { |
| 1778 | Timestamp { |
| 1779 | secs: value.as_secs(), |
| 1780 | nanos: value.subsec_nanos(), |
| 1781 | } |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | impl From<Timestamp> for Duration { |
| 1786 | fn from(value: Timestamp) -> Self { |
| 1787 | Duration::new(value.secs, value.nanos) |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | impl FromStr for WorkspaceReferenceArg { |
| 1792 | type Err = &'static str; |
| 1793 | |
| 1794 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1795 | let reference = if let Ok(index) = s.parse::<i32>() { |
| 1796 | if let Ok(idx) = u8::try_from(index) { |
| 1797 | Self::Index(idx) |
| 1798 | } else { |
| 1799 | return Err("workspace index must be between 0 and 255"); |
| 1800 | } |
| 1801 | } else { |
| 1802 | Self::Name(s.to_string()) |
| 1803 | }; |
| 1804 | |
| 1805 | Ok(reference) |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | impl FromStr for SizeChange { |
| 1810 | type Err = &'static str; |
| 1811 | |
| 1812 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1813 | match s.split_once('%') { |
| 1814 | Some((value, empty)) => { |
| 1815 | if !empty.is_empty() { |
| 1816 | return Err("trailing characters after '%' are not allowed"); |
| 1817 | } |
| 1818 | |
| 1819 | match value.bytes().next() { |
| 1820 | Some(b'-' | b'+') => { |
| 1821 | let value = value.parse().map_err(|_| "error parsing value")?; |
| 1822 | Ok(Self::AdjustProportion(value)) |
| 1823 | } |
| 1824 | Some(_) => { |
| 1825 | let value = value.parse().map_err(|_| "error parsing value")?; |
| 1826 | Ok(Self::SetProportion(value)) |
| 1827 | } |
| 1828 | None => Err("value is missing"), |
| 1829 | } |
| 1830 | } |
| 1831 | None => { |
| 1832 | let value = s; |
| 1833 | match value.bytes().next() { |
| 1834 | Some(b'-' | b'+') => { |
| 1835 | let value = value.parse().map_err(|_| "error parsing value")?; |
| 1836 | Ok(Self::AdjustFixed(value)) |
| 1837 | } |
| 1838 | Some(_) => { |
| 1839 | let value = value.parse().map_err(|_| "error parsing value")?; |
| 1840 | Ok(Self::SetFixed(value)) |
| 1841 | } |
| 1842 | None => Err("value is missing"), |
| 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | impl FromStr for PositionChange { |
| 1850 | type Err = &'static str; |
| 1851 | |
| 1852 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1853 | match s.split_once('%') { |
| 1854 | Some((value, empty)) => { |
| 1855 | if !empty.is_empty() { |
| 1856 | return Err("trailing characters after '%' are not allowed"); |
| 1857 | } |
| 1858 | |
| 1859 | match value.bytes().next() { |
| 1860 | Some(b'-' | b'+') => { |
| 1861 | let value = value.parse().map_err(|_| "error parsing value")?; |
| 1862 | Ok(Self::AdjustProportion(value)) |
| 1863 | } |
| 1864 | Some(_) => { |
| 1865 | let value = value.parse().map_err(|_| "error parsing value")?; |
| 1866 | Ok(Self::SetProportion(value)) |
| 1867 | } |
| 1868 | None => Err("value is missing"), |
| 1869 | } |
| 1870 | } |
| 1871 | None => { |
| 1872 | let value = s; |
| 1873 | match value.bytes().next() { |
| 1874 | Some(b'-' | b'+') => { |
| 1875 | let value = value.parse().map_err(|_| "error parsing value")?; |
| 1876 | Ok(Self::AdjustFixed(value)) |
| 1877 | } |
| 1878 | Some(_) => { |
| 1879 | let value = value.parse().map_err(|_| "error parsing value")?; |
| 1880 | Ok(Self::SetFixed(value)) |
| 1881 | } |
| 1882 | None => Err("value is missing"), |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | impl FromStr for LayoutSwitchTarget { |
| 1890 | type Err = &'static str; |
| 1891 | |
| 1892 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1893 | match s { |
| 1894 | "next" => Ok(Self::Next), |
| 1895 | "prev" => Ok(Self::Prev), |
| 1896 | other => match other.parse() { |
| 1897 | Ok(layout) => Ok(Self::Index(layout)), |
| 1898 | _ => Err(r#"invalid layout action, can be "next", "prev" or a layout index"#), |
| 1899 | }, |
| 1900 | } |
| 1901 | } |
| 1902 | } |
| 1903 | |
| 1904 | impl FromStr for ColumnDisplay { |
| 1905 | type Err = &'static str; |
| 1906 | |
| 1907 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1908 | match s { |
| 1909 | "normal" => Ok(Self::Normal), |
| 1910 | "tabbed" => Ok(Self::Tabbed), |
| 1911 | _ => Err(r#"invalid column display, can be "normal" or "tabbed""#), |
| 1912 | } |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | impl FromStr for Transform { |
| 1917 | type Err = &'static str; |
| 1918 | |
| 1919 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1920 | match s { |
| 1921 | "normal" => Ok(Self::Normal), |
| 1922 | "90" => Ok(Self::_90), |
| 1923 | "180" => Ok(Self::_180), |
| 1924 | "270" => Ok(Self::_270), |
| 1925 | "flipped" => Ok(Self::Flipped), |
| 1926 | "flipped-90" => Ok(Self::Flipped90), |
| 1927 | "flipped-180" => Ok(Self::Flipped180), |
| 1928 | "flipped-270" => Ok(Self::Flipped270), |
| 1929 | _ => Err(concat!( |
| 1930 | r#"invalid transform, can be "90", "180", "270", "#, |
| 1931 | r#""flipped", "flipped-90", "flipped-180" or "flipped-270""# |
| 1932 | )), |
| 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | impl TryFrom<u8> for MaxBpc { |
| 1938 | type Error = &'static str; |
| 1939 | |
| 1940 | fn try_from(value: u8) -> Result<Self, Self::Error> { |
| 1941 | match value { |
| 1942 | 6 => Ok(MaxBpc::_6), |
| 1943 | 8 => Ok(MaxBpc::_8), |
| 1944 | 10 => Ok(MaxBpc::_10), |
| 1945 | 12 => Ok(MaxBpc::_12), |
| 1946 | 14 => Ok(MaxBpc::_14), |
| 1947 | 16 => Ok(MaxBpc::_16), |
| 1948 | _ => Err("invalid max-bpc, can be 6, 8, 10, 12, 14, 16"), |
| 1949 | } |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | impl FromStr for MaxBpc { |
| 1954 | type Err = &'static str; |
| 1955 | |
| 1956 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1957 | Self::try_from(s.parse::<u8>().unwrap_or_default()) |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | impl FromStr for Layer { |
| 1962 | type Err = &'static str; |
| 1963 | |
| 1964 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1965 | match s { |
| 1966 | "background" => Ok(Self::Background), |
| 1967 | "bottom" => Ok(Self::Bottom), |
| 1968 | "top" => Ok(Self::Top), |
| 1969 | "overlay" => Ok(Self::Overlay), |
| 1970 | _ => Err("invalid layer, can be \"background\", \"bottom\", \"top\" or \"overlay\""), |
| 1971 | } |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | impl FromStr for ModeToSet { |
| 1976 | type Err = &'static str; |
| 1977 | |
| 1978 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1979 | if s.eq_ignore_ascii_case("auto") { |
| 1980 | return Ok(Self::Automatic); |
| 1981 | } |
| 1982 | |
| 1983 | let mode = s.parse()?; |
| 1984 | Ok(Self::Specific(mode)) |
| 1985 | } |
| 1986 | } |
| 1987 | |
| 1988 | impl FromStr for ConfiguredMode { |
| 1989 | type Err = &'static str; |
| 1990 | |
| 1991 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1992 | let Some((width, rest)) = s.split_once('x') else { |
| 1993 | return Err("no 'x' separator found"); |
| 1994 | }; |
| 1995 | |
| 1996 | let (height, refresh) = match rest.split_once('@') { |
| 1997 | Some((height, refresh)) => (height, Some(refresh)), |
| 1998 | None => (rest, None), |
| 1999 | }; |
| 2000 | |
| 2001 | let width = width.parse().map_err(|_| "error parsing width")?; |
| 2002 | let height = height.parse().map_err(|_| "error parsing height")?; |
| 2003 | let refresh = refresh |
| 2004 | .map(str::parse) |
| 2005 | .transpose() |
| 2006 | .map_err(|_| "error parsing refresh rate")?; |
| 2007 | |
| 2008 | Ok(Self { |
| 2009 | width, |
| 2010 | height, |
| 2011 | refresh, |
| 2012 | }) |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | impl FromStr for HSyncPolarity { |
| 2017 | type Err = &'static str; |
| 2018 | |
| 2019 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 2020 | match s { |
| 2021 | "+hsync" => Ok(Self::PHSync), |
| 2022 | "-hsync" => Ok(Self::NHSync), |
| 2023 | _ => Err(r#"invalid horizontal sync polarity, can be "+hsync" or "-hsync"#), |
| 2024 | } |
| 2025 | } |
| 2026 | } |
| 2027 | |
| 2028 | impl FromStr for VSyncPolarity { |
| 2029 | type Err = &'static str; |
| 2030 | |
| 2031 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 2032 | match s { |
| 2033 | "+vsync" => Ok(Self::PVSync), |
| 2034 | "-vsync" => Ok(Self::NVSync), |
| 2035 | _ => Err(r#"invalid vertical sync polarity, can be "+vsync" or "-vsync"#), |
| 2036 | } |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | impl FromStr for ScaleToSet { |
| 2041 | type Err = &'static str; |
| 2042 | |
| 2043 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 2044 | if s.eq_ignore_ascii_case("auto") { |
| 2045 | return Ok(Self::Automatic); |
| 2046 | } |
| 2047 | |
| 2048 | let scale = s.parse().map_err(|_| "error parsing scale")?; |
| 2049 | Ok(Self::Specific(scale)) |
| 2050 | } |
| 2051 | } |
| 2052 | |
| 2053 | macro_rules! ensure { |
| 2054 | ($cond:expr, $fmt:literal $($arg:tt)* ) => { |
| 2055 | if !$cond { |
| 2056 | return Err(format!($fmt $($arg)*)); |
| 2057 | } |
| 2058 | }; |
| 2059 | } |
| 2060 | |
| 2061 | impl OutputAction { |
| 2062 | |
| 2063 | pub fn validate(&self) -> Result<(), String> { |
| 2064 | match self { |
| 2065 | OutputAction::Modeline { |
| 2066 | hdisplay, |
| 2067 | hsync_start, |
| 2068 | hsync_end, |
| 2069 | htotal, |
| 2070 | vdisplay, |
| 2071 | vsync_start, |
| 2072 | vsync_end, |
| 2073 | vtotal, |
| 2074 | .. |
| 2075 | } => { |
| 2076 | ensure!( |
| 2077 | hdisplay < hsync_start, |
| 2078 | "hdisplay {} must be < hsync_start {}", |
| 2079 | hdisplay, |
| 2080 | hsync_start |
| 2081 | ); |
| 2082 | ensure!( |
| 2083 | hsync_start < hsync_end, |
| 2084 | "hsync_start {} must be < hsync_end {}", |
| 2085 | hsync_start, |
| 2086 | hsync_end |
| 2087 | ); |
| 2088 | ensure!( |
| 2089 | hsync_end < htotal, |
| 2090 | "hsync_end {} must be < htotal {}", |
| 2091 | hsync_end, |
| 2092 | htotal |
| 2093 | ); |
| 2094 | ensure!(0 < *htotal, "htotal {} must be > 0", htotal); |
| 2095 | ensure!( |
| 2096 | vdisplay < vsync_start, |
| 2097 | "vdisplay {} must be < vsync_start {}", |
| 2098 | vdisplay, |
| 2099 | vsync_start |
| 2100 | ); |
| 2101 | ensure!( |
| 2102 | vsync_start < vsync_end, |
| 2103 | "vsync_start {} must be < vsync_end {}", |
| 2104 | vsync_start, |
| 2105 | vsync_end |
| 2106 | ); |
| 2107 | ensure!( |
| 2108 | vsync_end < vtotal, |
| 2109 | "vsync_end {} must be < vtotal {}", |
| 2110 | vsync_end, |
| 2111 | vtotal |
| 2112 | ); |
| 2113 | ensure!(0 < *vtotal, "vtotal {} must be > 0", vtotal); |
| 2114 | Ok(()) |
| 2115 | } |
| 2116 | OutputAction::CustomMode { |
| 2117 | mode: ConfiguredMode { refresh, .. }, |
| 2118 | } => { |
| 2119 | if refresh.is_none() { |
| 2120 | return Err("refresh rate is required for custom modes".to_string()); |
| 2121 | } |
| 2122 | if let Some(refresh) = refresh { |
| 2123 | if *refresh <= 0. { |
| 2124 | return Err(format!("custom mode refresh rate {refresh} must be > 0")); |
| 2125 | } |
| 2126 | } |
| 2127 | Ok(()) |
| 2128 | } |
| 2129 | _ => Ok(()), |
| 2130 | } |
| 2131 | } |
| 2132 | } |
| 2133 | |
| 2134 | fn default_true() -> bool { |
| 2135 | true |
| 2136 | } |
| 2137 | |
| 2138 | fn default_position_change() -> PositionChange { |
| 2139 | PositionChange::AdjustFixed(0.) |
| 2140 | } |
| 2141 | |
| 2142 | #[cfg(test)] |
| 2143 | mod tests { |
| 2144 | use super::*; |
| 2145 | |
| 2146 | #[test] |
| 2147 | fn parse_size_change() { |
| 2148 | assert_eq!( |
| 2149 | "10".parse::<SizeChange>().unwrap(), |
| 2150 | SizeChange::SetFixed(10), |
| 2151 | ); |
| 2152 | assert_eq!( |
| 2153 | "+10".parse::<SizeChange>().unwrap(), |
| 2154 | SizeChange::AdjustFixed(10), |
| 2155 | ); |
| 2156 | assert_eq!( |
| 2157 | "-10".parse::<SizeChange>().unwrap(), |
| 2158 | SizeChange::AdjustFixed(-10), |
| 2159 | ); |
| 2160 | assert_eq!( |
| 2161 | "10%".parse::<SizeChange>().unwrap(), |
| 2162 | SizeChange::SetProportion(10.), |
| 2163 | ); |
| 2164 | assert_eq!( |
| 2165 | "+10%".parse::<SizeChange>().unwrap(), |
| 2166 | SizeChange::AdjustProportion(10.), |
| 2167 | ); |
| 2168 | assert_eq!( |
| 2169 | "-10%".parse::<SizeChange>().unwrap(), |
| 2170 | SizeChange::AdjustProportion(-10.), |
| 2171 | ); |
| 2172 | |
| 2173 | assert!("-".parse::<SizeChange>().is_err()); |
| 2174 | assert!("10% ".parse::<SizeChange>().is_err()); |
| 2175 | } |
| 2176 | |
| 2177 | #[test] |
| 2178 | fn parse_position_change() { |
| 2179 | assert_eq!( |
| 2180 | "10".parse::<PositionChange>().unwrap(), |
| 2181 | PositionChange::SetFixed(10.), |
| 2182 | ); |
| 2183 | assert_eq!( |
| 2184 | "+10".parse::<PositionChange>().unwrap(), |
| 2185 | PositionChange::AdjustFixed(10.), |
| 2186 | ); |
| 2187 | assert_eq!( |
| 2188 | "-10".parse::<PositionChange>().unwrap(), |
| 2189 | PositionChange::AdjustFixed(-10.), |
| 2190 | ); |
| 2191 | |
| 2192 | assert_eq!( |
| 2193 | "10%".parse::<PositionChange>().unwrap(), |
| 2194 | PositionChange::SetProportion(10.) |
| 2195 | ); |
| 2196 | assert_eq!( |
| 2197 | "+10%".parse::<PositionChange>().unwrap(), |
| 2198 | PositionChange::AdjustProportion(10.) |
| 2199 | ); |
| 2200 | assert_eq!( |
| 2201 | "-10%".parse::<PositionChange>().unwrap(), |
| 2202 | PositionChange::AdjustProportion(-10.) |
| 2203 | ); |
| 2204 | assert!("-".parse::<PositionChange>().is_err()); |
| 2205 | assert!("10% ".parse::<PositionChange>().is_err()); |
| 2206 | } |
| 2207 | } |