-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xwayland: allow windows to scale themselves
- Loading branch information
Showing
40 changed files
with
800 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! Tools for configuring Xwayland. | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The scaling mode of X windows. | ||
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Eq, PartialEq, Hash, Default)] | ||
pub struct XScalingMode(pub u32); | ||
|
||
impl XScalingMode { | ||
/// The default mode. | ||
/// | ||
/// Currently this means that windows are rendered at the lowest scale and then | ||
/// upscaled if necessary. | ||
pub const DEFAULT: Self = Self(0); | ||
/// Windows are rendered at the highest integer scale and then downscaled. | ||
/// | ||
/// This has significant performance implications unless the window is running on the | ||
/// output with the highest scale and that scale is an integer scale. | ||
/// | ||
/// For example, on a 3840x2160 output with a 1.5 scale, a fullscreen window will be | ||
/// rendered at 3840x2160 * 2 / 1.5 = 5120x2880 pixels and then downscaled to | ||
/// 3840x2160. This overhead gets worse the lower the scale of the output is. | ||
/// | ||
/// Additionally, this mode requires the X window to scale its contents itself. In the | ||
/// example above, you might achieve this by setting the environment variable | ||
/// `GDK_SCALE=2`. | ||
pub const DOWNSCALED: Self = Self(1); | ||
} | ||
|
||
/// Sets the scaling mode for X windows. | ||
pub fn set_x_scaling_mode(mode: XScalingMode) { | ||
get!().set_x_scaling_mode(mode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use { | ||
crate::{ | ||
cli::GlobalArgs, | ||
tools::tool_client::{with_tool_client, Handle, ToolClient}, | ||
wire::{jay_compositor, jay_xwayland, JayXwaylandId}, | ||
}, | ||
clap::{Args, Subcommand, ValueEnum}, | ||
jay_config::xwayland::XScalingMode, | ||
std::{cell::Cell, rc::Rc}, | ||
}; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct XwaylandArgs { | ||
#[clap(subcommand)] | ||
pub command: Option<XwaylandCmd>, | ||
} | ||
|
||
#[derive(Subcommand, Debug, Default)] | ||
pub enum XwaylandCmd { | ||
/// Print the Xwayland status. | ||
#[default] | ||
Status, | ||
/// Set the Xwayland scaling mode. | ||
SetScalingMode(SetScalingModeArgs), | ||
} | ||
|
||
#[derive(Args, Debug)] | ||
pub struct SetScalingModeArgs { | ||
#[clap(value_enum)] | ||
pub mode: CliScalingMode, | ||
} | ||
|
||
#[derive(ValueEnum, Debug, Copy, Clone, Hash, PartialEq)] | ||
pub enum CliScalingMode { | ||
/// The default mode. | ||
Default, | ||
/// Windows are rendered at the highest integer scale and then downscaled. | ||
Downscaled, | ||
} | ||
|
||
pub fn main(global: GlobalArgs, args: XwaylandArgs) { | ||
with_tool_client(global.log_level.into(), |tc| async move { | ||
let xwayland = Xwayland { tc: tc.clone() }; | ||
xwayland.run(args).await; | ||
}); | ||
} | ||
|
||
struct Xwayland { | ||
tc: Rc<ToolClient>, | ||
} | ||
|
||
impl Xwayland { | ||
async fn run(self, args: XwaylandArgs) { | ||
let tc = &self.tc; | ||
let comp = tc.jay_compositor().await; | ||
let xwayland = tc.id(); | ||
tc.send(jay_compositor::GetXwayland { | ||
self_id: comp, | ||
id: xwayland, | ||
}); | ||
match args.command.unwrap_or_default() { | ||
XwaylandCmd::Status => self.status(xwayland).await, | ||
XwaylandCmd::SetScalingMode(args) => self.set_scaling_mode(xwayland, args).await, | ||
} | ||
} | ||
|
||
async fn status(self, xwayland: JayXwaylandId) { | ||
let tc = &self.tc; | ||
tc.send(jay_xwayland::GetScaling { self_id: xwayland }); | ||
let mode = Rc::new(Cell::new(0)); | ||
let scale = Rc::new(Cell::new(None)); | ||
jay_xwayland::ScalingMode::handle(tc, xwayland, mode.clone(), |iv, msg| { | ||
iv.set(msg.mode); | ||
}); | ||
jay_xwayland::ImpliedScale::handle(tc, xwayland, scale.clone(), |iv, msg| { | ||
iv.set(Some(msg.scale)); | ||
}); | ||
tc.round_trip().await; | ||
let mode_str; | ||
let mode = match XScalingMode(mode.get()) { | ||
XScalingMode::DEFAULT => "default", | ||
XScalingMode::DOWNSCALED => "downscaled", | ||
o => { | ||
mode_str = format!("unknown ({})", o.0); | ||
&mode_str | ||
} | ||
}; | ||
println!("scaling mode: {}", mode); | ||
if let Some(scale) = scale.get() { | ||
println!("implied scale: {}", scale); | ||
} | ||
} | ||
|
||
async fn set_scaling_mode(self, xwayland: JayXwaylandId, args: SetScalingModeArgs) { | ||
let tc = &self.tc; | ||
let mode = match args.mode { | ||
CliScalingMode::Default => XScalingMode::DEFAULT, | ||
CliScalingMode::Downscaled => XScalingMode::DOWNSCALED, | ||
}; | ||
tc.send(jay_xwayland::SetScalingMode { | ||
self_id: xwayland, | ||
mode: mode.0, | ||
}); | ||
tc.round_trip().await; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.