Add Xsettings support, for setting scaling related settings

This allows for most GTK and Qt apps to be scaled properly.
In the case of mixed DPI, it will default to using the smallest monitor scale.
This commit is contained in:
Shawn Wallace 2025-05-23 23:25:33 -04:00
parent ec9ff64c1e
commit 572fa4a2bf
9 changed files with 466 additions and 11 deletions

View file

@ -1272,6 +1272,7 @@ impl<C: XConnection> GlobalDispatch<WlOutput, Global> for ServerState<C> {
Output::new(client, server).into()
});
state.output_keys.insert(key, ());
state.output_scales_updated = true;
}
}
global_dispatch_with_events!(WlDrmServer, WlDrmClient);

View file

@ -822,6 +822,10 @@ impl Output {
scale: 1,
}
}
pub(super) fn scale(&self) -> i32 {
self.scale
}
}
#[derive(Debug)]
@ -1027,6 +1031,7 @@ impl Output {
self.server.scale(factor);
}
state.output_scales_updated = true;
}
_ => simple_event_shunt! {
self.server, event: Event => [

View file

@ -522,6 +522,8 @@ pub struct ServerState<C: XConnection> {
activation_state: Option<ActivationState>,
global_output_offset: GlobalOutputOffset,
global_offset_updated: bool,
output_scales_updated: bool,
new_scale: Option<i32>,
decoration_manager: Option<ZxdgDecorationManagerV1>,
}
@ -611,6 +613,8 @@ impl<C: XConnection> ServerState<C> {
},
},
global_offset_updated: false,
output_scales_updated: false,
new_scale: None,
decoration_manager,
}
}
@ -1058,6 +1062,42 @@ impl<C: XConnection> ServerState<C> {
self.global_offset_updated = false;
}
if self.output_scales_updated {
let mut mixed_scale = false;
let mut scale;
'b: {
let mut keys_iter = self.output_keys.iter();
let (key, _) = keys_iter.next().unwrap();
let Some::<&Output>(output) = &mut self.objects.get(key).map(AsRef::as_ref) else {
// This should never happen, but you never know...
break 'b;
};
scale = output.scale();
for (key, _) in keys_iter {
let Some::<&Output>(output) = self.objects.get(key).map(AsRef::as_ref) else {
continue;
};
if output.scale() != scale {
mixed_scale = true;
scale = scale.min(output.scale());
}
}
if mixed_scale {
warn!("Mixed output scales detected, choosing to give apps the smallest detected scale ({scale}x)");
}
debug!("Using new scale {scale}");
self.new_scale = Some(scale);
}
self.output_scales_updated = false;
}
{
if let Some(FocusData {
window,
@ -1083,6 +1123,10 @@ impl<C: XConnection> ServerState<C> {
.expect("Failed flushing clientside events");
}
pub fn new_global_scale(&mut self) -> Option<i32> {
self.new_scale.take()
}
pub fn new_selection(&mut self) -> Option<ForeignSelection> {
self.clipboard_data.as_mut().and_then(|c| {
c.source.take().and_then(|s| match s {