Fix or promote leftover TODOs and GPUI APIs (#12514)

fixes https://github.com/zed-industries/zed/issues/11966

Release Notes:

- N/A
This commit is contained in:
Mikayla Maki 2024-05-31 18:36:15 -07:00 committed by GitHub
parent a6e0c8aca1
commit 94c3101fb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 581 additions and 441 deletions

View file

@ -1,40 +1,29 @@
// todo(linux): remove
#![allow(unused)]
use crate::{
platform::blade::{BladeRenderer, BladeSurfaceConfig},
size, Bounds, DevicePixels, ForegroundExecutor, Modifiers, Pixels, Platform, PlatformAtlas,
PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow, Point, PromptLevel,
Scene, Size, WindowAppearance, WindowBackgroundAppearance, WindowBounds, WindowOptions,
WindowParams, X11Client, X11ClientState, X11ClientStatePtr,
size, AnyWindowHandle, Bounds, DevicePixels, ForegroundExecutor, Modifiers, Pixels,
PlatformAtlas, PlatformDisplay, PlatformInput, PlatformInputHandler, PlatformWindow, Point,
PromptLevel, Scene, Size, WindowAppearance, WindowBackgroundAppearance, WindowBounds,
WindowParams, X11ClientStatePtr,
};
use blade_graphics as gpu;
use parking_lot::Mutex;
use raw_window_handle as rwh;
use util::ResultExt;
use x11rb::{
connection::{Connection as _, RequestConnection as _},
connection::Connection,
protocol::{
render,
xinput::{self, ConnectionExt as _},
xproto::{
self, Atom, ClientMessageEvent, ConnectionExt as _, CreateWindowAux, EventMask,
TranslateCoordinatesReply,
self, ClientMessageEvent, ConnectionExt as _, EventMask, TranslateCoordinatesReply,
},
},
resource_manager::Database,
wrapper::ConnectionExt as _,
xcb_ffi::XCBConnection,
};
use std::ops::Deref;
use std::rc::Weak;
use std::{
cell::{Ref, RefCell, RefMut},
collections::HashMap,
cell::RefCell,
ffi::c_void,
iter::Zip,
mem,
num::NonZeroU32,
ops::Div,
@ -165,29 +154,29 @@ pub struct Callbacks {
appearance_changed: Option<Box<dyn FnMut()>>,
}
pub(crate) struct X11WindowState {
pub struct X11WindowState {
client: X11ClientStatePtr,
executor: ForegroundExecutor,
atoms: XcbAtoms,
x_root_window: xproto::Window,
raw: RawWindow,
_raw: RawWindow,
bounds: Bounds<i32>,
scale_factor: f32,
renderer: BladeRenderer,
display: Rc<dyn PlatformDisplay>,
input_handler: Option<PlatformInputHandler>,
appearance: WindowAppearance,
pub handle: AnyWindowHandle,
}
#[derive(Clone)]
pub(crate) struct X11WindowStatePtr {
pub(crate) state: Rc<RefCell<X11WindowState>>,
pub state: Rc<RefCell<X11WindowState>>,
pub(crate) callbacks: Rc<RefCell<Callbacks>>,
xcb_connection: Rc<XCBConnection>,
x_window: xproto::Window,
}
// todo(linux): Remove other RawWindowHandle implementation
impl rwh::HasWindowHandle for RawWindow {
fn window_handle(&self) -> Result<rwh::WindowHandle, rwh::HandleError> {
let non_zero = NonZeroU32::new(self.window_id).unwrap();
@ -218,6 +207,7 @@ impl rwh::HasDisplayHandle for X11Window {
impl X11WindowState {
#[allow(clippy::too_many_arguments)]
pub fn new(
handle: AnyWindowHandle,
client: X11ClientStatePtr,
executor: ForegroundExecutor,
params: WindowParams,
@ -372,7 +362,7 @@ impl X11WindowState {
client,
executor,
display: Rc::new(X11Display::new(xcb_connection, x_screen_index).unwrap()),
raw,
_raw: raw,
x_root_window: visual_set.root,
bounds: params.bounds.map(|v| v.0),
scale_factor,
@ -380,6 +370,7 @@ impl X11WindowState {
atoms: *atoms,
input_handler: None,
appearance,
handle,
}
}
@ -420,14 +411,15 @@ impl Drop for X11Window {
}
enum WmHintPropertyState {
Remove = 0,
Add = 1,
// Remove = 0,
// Add = 1,
Toggle = 2,
}
impl X11Window {
#[allow(clippy::too_many_arguments)]
pub fn new(
handle: AnyWindowHandle,
client: X11ClientStatePtr,
executor: ForegroundExecutor,
params: WindowParams,
@ -440,6 +432,7 @@ impl X11Window {
) -> Self {
Self(X11WindowStatePtr {
state: Rc::new(RefCell::new(X11WindowState::new(
handle,
client,
executor,
params,
@ -622,8 +615,6 @@ impl X11WindowStatePtr {
let mut state = self.state.borrow_mut();
let old_bounds = mem::replace(&mut state.bounds, bounds);
do_move = old_bounds.origin != bounds.origin;
// todo(linux): use normal GPUI types here, refactor out the double
// viewport check and extra casts ( )
let gpu_size = query_render_extent(&self.xcb_connection, self.x_window);
if state.renderer.viewport_size() != gpu_size {
state
@ -698,8 +689,8 @@ impl PlatformWindow for X11Window {
self.0.state.borrow().appearance
}
fn display(&self) -> Rc<dyn PlatformDisplay> {
self.0.state.borrow().display.clone()
fn display(&self) -> Option<Rc<dyn PlatformDisplay>> {
Some(self.0.state.borrow().display.clone())
}
fn mouse_position(&self) -> Point<Pixels> {
@ -713,9 +704,15 @@ impl PlatformWindow for X11Window {
Point::new((reply.root_x as u32).into(), (reply.root_y as u32).into())
}
// todo(linux)
fn modifiers(&self) -> Modifiers {
Modifiers::default()
self.0
.state
.borrow()
.client
.0
.upgrade()
.map(|ref_cell| ref_cell.borrow().modifiers)
.unwrap_or_default()
}
fn set_input_handler(&mut self, input_handler: PlatformInputHandler) {
@ -792,8 +789,9 @@ impl PlatformWindow for X11Window {
.unwrap();
}
// todo(linux)
fn set_edited(&mut self, edited: bool) {}
fn set_edited(&mut self, _edited: bool) {
log::info!("ignoring macOS specific set_edited");
}
fn set_background_appearance(&mut self, background_appearance: WindowBackgroundAppearance) {
let mut inner = self.0.state.borrow_mut();
@ -801,14 +799,8 @@ impl PlatformWindow for X11Window {
inner.renderer.update_transparency(transparent);
}
// todo(linux), this corresponds to `orderFrontCharacterPalette` on macOS,
// but it looks like the equivalent for Linux is GTK specific:
//
// https://docs.gtk.org/gtk3/signal.Entry.insert-emoji.html
//
// This API might need to change, or we might need to build an emoji picker into GPUI
fn show_character_palette(&self) {
unimplemented!()
log::info!("ignoring macOS specific show_character_palette");
}
fn minimize(&self) {