wayland: partially respect window_decorations

When using client-side decorations, we can now skip rendering
the header/title bar.

If you've set NONE decorations, then wezterm will configure
the window that way, but that is only respected when the window
is created, as weston crashed when I tried to change this in
a window config reload event.

The wayland frame now also observes config change events,
so frame color adjustments should now take effect without
restarting.

refs: #1077
This commit is contained in:
Wez Furlong committed 2021-10-09 17:34:26 -07:00
1 parent 64271288ac
commit 8c613d8588
2 files changed
+97 -31

No files matched your search

+52 -29
View File
@@ -21,6 +21,7 @@ use wayland_client::protocol::{
};
use wayland_client::{Attached, DispatchData, Main};
use wezterm_font::{FontConfiguration, FontMetrics, GlyphInfo, RasterizedGlyph};
use wezterm_input_types::WindowDecorations;
fn color_to_paint(c: RgbColor) -> Paint<'static> {
let mut paint = Paint::default();
@@ -507,6 +508,18 @@ impl ConceptFrame {
Some(())
}
fn showing_title_bar(&self, inner: &Inner) -> bool {
if self.hidden || inner.fullscreened {
false
} else {
self.config
.config
.as_ref()
.map(|cfg| cfg.window_decorations.contains(WindowDecorations::TITLE))
.unwrap_or(true)
}
}
}
impl Frame for ConceptFrame {
@@ -778,6 +791,8 @@ impl Frame for ConceptFrame {
let scaled_header_height = HEADER_SIZE * header_scale;
let scaled_header_width = width * header_scale;
let showing_title_bar = self.showing_title_bar(&*inner);
{
// grab the current pool
let pool = match self.pools.pool() {
@@ -797,8 +812,8 @@ impl Frame for ConceptFrame {
pool.resize(4 * pxcount as usize)
.expect("I/O Error while redrawing the borders");
// draw the header bar
{
if showing_title_bar {
// draw the header bar
let mmap = pool.mmap();
{
let colors = self.config.colors();
@@ -900,36 +915,36 @@ impl Frame for ConceptFrame {
if let Err(err) = mmap.flush() {
log::error!("Failed to flush frame memory map: {}", err);
}
}
// Create the buffers
// -> head-subsurface
let buffer = pool.buffer(
0,
scaled_header_width as i32,
scaled_header_height as i32,
4 * scaled_header_width as i32,
wl_shm::Format::Argb8888,
);
parts[HEAD]
.subsurface
.set_position(0, -(HEADER_SIZE as i32));
parts[HEAD].surface.attach(Some(&buffer), 0, 0);
if self.surface_version >= 4 {
parts[HEAD].surface.damage_buffer(
0,
// Create the buffers
// -> head-subsurface
let buffer = pool.buffer(
0,
scaled_header_width as i32,
scaled_header_height as i32,
4 * scaled_header_width as i32,
wl_shm::Format::Argb8888,
);
} else {
// surface is old and does not support damage_buffer, so we damage
// in surface coordinates and hope it is not rescaled
parts[HEAD]
.surface
.damage(0, 0, width as i32, HEADER_SIZE as i32);
.subsurface
.set_position(0, -(HEADER_SIZE as i32));
parts[HEAD].surface.attach(Some(&buffer), 0, 0);
if self.surface_version >= 4 {
parts[HEAD].surface.damage_buffer(
0,
0,
scaled_header_width as i32,
scaled_header_height as i32,
);
} else {
// surface is old and does not support damage_buffer, so we damage
// in surface coordinates and hope it is not rescaled
parts[HEAD]
.surface
.damage(0, 0, width as i32, HEADER_SIZE as i32);
}
parts[HEAD].surface.commit();
}
parts[HEAD].surface.commit();
// -> top-subsurface
let buffer = pool.buffer(
@@ -941,7 +956,11 @@ impl Frame for ConceptFrame {
);
parts[TOP].subsurface.set_position(
-(BORDER_SIZE as i32),
-(HEADER_SIZE as i32 + BORDER_SIZE as i32),
-(if showing_title_bar {
HEADER_SIZE as i32
} else {
0
} + BORDER_SIZE as i32),
);
parts[TOP].surface.attach(Some(&buffer), 0, 0);
if self.surface_version >= 4 {
@@ -1056,7 +1075,7 @@ impl Frame for ConceptFrame {
}
fn subtract_borders(&self, width: i32, height: i32) -> (i32, i32) {
if self.hidden || self.inner.borrow().fullscreened {
if !self.showing_title_bar(&*self.inner.borrow()) {
(width, height)
} else {
(width, height - HEADER_SIZE as i32)
@@ -1064,7 +1083,7 @@ impl Frame for ConceptFrame {
}
fn add_borders(&self, width: i32, height: i32) -> (i32, i32) {
if self.hidden || self.inner.borrow().fullscreened {
if !self.showing_title_bar(&*self.inner.borrow()) {
(width, height)
} else {
(width, height + HEADER_SIZE as i32)
@@ -1072,7 +1091,7 @@ impl Frame for ConceptFrame {
}
fn location(&self) -> (i32, i32) {
if self.hidden || self.inner.borrow().fullscreened {
if !self.showing_title_bar(&*self.inner.borrow()) {
(0, 0)
} else {
(0, -(HEADER_SIZE as i32))
@@ -1081,6 +1100,10 @@ impl Frame for ConceptFrame {
fn set_config(&mut self, config: ConceptConfig) {
self.config = config;
// Refresh parts to reflect window_decorations
self.inner.borrow_mut().parts.clear();
self.set_hidden(self.hidden);
self.redraw();
}
fn set_title(&mut self, title: String) {
+45 -2
View File
@@ -29,7 +29,7 @@ use toolkit::get_surface_scale_factor;
use toolkit::reexports::client::protocol::wl_data_source::Event as DataSourceEvent;
use toolkit::reexports::client::protocol::wl_pointer::ButtonState;
use toolkit::reexports::client::protocol::wl_surface::WlSurface;
use toolkit::window::{Event as SCTKWindowEvent, State};
use toolkit::window::{Decorations, Event as SCTKWindowEvent, State};
use wayland_client::protocol::wl_callback::WlCallback;
use wayland_client::protocol::wl_data_device_manager::WlDataDeviceManager;
use wayland_client::protocol::wl_keyboard::{Event as WlKeyboardEvent, KeyState};
@@ -125,6 +125,8 @@ pub struct WaylandWindowInner {
pending_first_configure: Option<async_channel::Sender<()>>,
frame_callback: Option<Main<WlCallback>>,
invalidated: bool,
font_config: Rc<FontConfiguration>,
config: Option<ConfigHandle>,
// wegl_surface is listed before gl_state because it
// must be dropped before gl_state otherwise the underlying
// libraries will segfault on shutdown
@@ -289,8 +291,24 @@ impl WaylandWindow {
window.set_app_id(class_name.to_string());
window.set_resizable(true);
window.set_title(name.to_string());
let decorations = config
.as_ref()
.map(|c| c.window_decorations)
.unwrap_or(WindowDecorations::default());
window.set_decorate(if decorations == WindowDecorations::NONE {
Decorations::None
} else if decorations == WindowDecorations::default() {
Decorations::FollowServer
} else {
// SCTK/Wayland don't allow more nuance than "decorations are hidden",
// so if we have a mixture of things, then we need to force our
// client side decoration rendering.
Decorations::ClientSide
});
window.set_frame_config(ConceptConfig {
font_config: Some(font_config),
font_config: Some(Rc::clone(&font_config)),
config: config.cloned(),
..Default::default()
});
@@ -304,6 +322,8 @@ impl WaylandWindow {
let inner = Rc::new(RefCell::new(WaylandWindowInner {
window_id,
font_config,
config: config.cloned(),
key_repeat: None,
copy_and_paste,
events: WindowEventSender::new(event_handler),
@@ -769,6 +789,14 @@ impl WindowOps for WaylandWindow {
});
}
fn config_did_change(&self, config: &ConfigHandle) {
let config = config.clone();
WaylandConnection::with_window_inner(self.0, move |inner| {
inner.config_did_change(&config);
Ok(())
});
}
fn show(&self) {
WaylandConnection::with_window_inner(self.0, |inner| {
inner.show();
@@ -1036,4 +1064,19 @@ impl WaylandWindowInner {
fn set_resize_increments(&mut self, x: u16, y: u16) {
self.resize_increments = Some((x, y));
}
fn config_did_change(&mut self, config: &ConfigHandle) {
self.config.replace(config.clone());
if let Some(window) = self.window.as_mut() {
window.set_frame_config(ConceptConfig {
font_config: Some(Rc::clone(&self.font_config)),
config: Some(config.clone()),
..Default::default()
});
// I tried re-applying the config to window.set_decorate
// here, but it crashed weston. I figure that users
// would prefer to manually close wezterm to change
// this setting!
}
}
}