diff --git a/crates/gpui/build.rs b/crates/gpui/build.rs index a70f4fb637..32da465007 100644 --- a/crates/gpui/build.rs +++ b/crates/gpui/build.rs @@ -7,14 +7,14 @@ use cbindgen::Config; fn main() { //generate_dispatch_bindings(); - let header_path = generate_shader_bindings(); + let _header_path = generate_shader_bindings(); //#[cfg(feature = "runtime_shaders")] //emit_stitched_shaders(&header_path); //#[cfg(not(feature = "runtime_shaders"))] //compile_metal_shaders(&header_path); } -fn generate_dispatch_bindings() { +fn _generate_dispatch_bindings() { println!("cargo:rustc-link-lib=framework=System"); println!("cargo:rerun-if-changed=src/platform/mac/dispatch.h"); @@ -116,7 +116,7 @@ fn emit_stitched_shaders(header_path: &Path) { println!("cargo:rerun-if-changed={}", &shader_source_path); } #[cfg(not(feature = "runtime_shaders"))] -fn compile_metal_shaders(header_path: &Path) { +fn _compile_metal_shaders(header_path: &Path) { use std::process::{self, Command}; let shader_path = "./src/platform/mac/shaders.metal"; let air_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("shaders.air"); diff --git a/crates/gpui/src/elements/img.rs b/crates/gpui/src/elements/img.rs index cb97309d36..32009e04db 100644 --- a/crates/gpui/src/elements/img.rs +++ b/crates/gpui/src/elements/img.rs @@ -7,6 +7,7 @@ use crate::{ StyleRefinement, Styled, UriOrPath, }; use futures::FutureExt; +#[cfg(target_os = "macos")] use media::core_video::CVImageBuffer; use util::ResultExt; @@ -21,6 +22,7 @@ pub enum ImageSource { Data(Arc), // TODO: move surface definitions into mac platform module /// A CoreVideo image buffer + #[cfg(target_os = "macos")] Surface(CVImageBuffer), } @@ -54,6 +56,7 @@ impl From> for ImageSource { } } +#[cfg(target_os = "macos")] impl From for ImageSource { fn from(value: CVImageBuffer) -> Self { Self::Surface(value) @@ -144,6 +147,7 @@ impl Element for Img { .log_err(); } + #[cfg(target_os = "macos")] ImageSource::Surface(surface) => { let size = size(surface.width().into(), surface.height().into()); let new_bounds = preserve_aspect_ratio(bounds, size); diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index df886fc4d6..194dfe1c54 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -2,6 +2,8 @@ mod app_menu; mod keystroke; #[cfg(target_os = "macos")] mod mac; +#[cfg(target_os = "linux")] +mod linux; #[cfg(any(test, feature = "test-support"))] mod test; @@ -35,6 +37,8 @@ pub use app_menu::*; pub use keystroke::*; #[cfg(target_os = "macos")] pub(crate) use mac::*; +#[cfg(target_os = "linux")] +pub(crate) use linux::*; #[cfg(any(test, feature = "test-support"))] pub(crate) use test::*; use time::UtcOffset; @@ -44,6 +48,10 @@ pub use util::SemanticVersion; pub(crate) fn current_platform() -> Rc { Rc::new(MacPlatform::new()) } +#[cfg(target_os = "linux")] +pub(crate) fn current_platform() -> Rc { + Rc::new(LinuxPlatform::new()) +} pub(crate) trait Platform: 'static { fn background_executor(&self) -> BackgroundExecutor; diff --git a/crates/gpui/src/platform/linux.rs b/crates/gpui/src/platform/linux.rs new file mode 100644 index 0000000000..a979749edd --- /dev/null +++ b/crates/gpui/src/platform/linux.rs @@ -0,0 +1,3 @@ +mod platform; + +pub(crate) use platform::*; diff --git a/crates/gpui/src/platform/linux/platform.rs b/crates/gpui/src/platform/linux/platform.rs new file mode 100644 index 0000000000..245cdbc11d --- /dev/null +++ b/crates/gpui/src/platform/linux/platform.rs @@ -0,0 +1,242 @@ +#![allow(unused)] + +use crate::{ + Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DisplayId, + Keymap, Menu, PathPromptOptions, Platform, PlatformDisplay, PlatformInput, + PlatformTextSystem, PlatformWindow, Result, SemanticVersion, Task, WindowOptions, +}; + +use futures::channel::oneshot; +use parking_lot::Mutex; + +use std::{ + path::{Path, PathBuf}, + rc::Rc, + sync::Arc, + time::Duration, +}; +use time::UtcOffset; + + +pub(crate) struct LinuxPlatform(Mutex); + +pub(crate) struct LinuxPlatformState { +} + +impl Default for LinuxPlatform { + fn default() -> Self { + Self::new() + } +} + +impl LinuxPlatform { + pub(crate) fn new() -> Self { + Self(Mutex::new(LinuxPlatformState { + })) + } +} + +impl Platform for LinuxPlatform { + fn background_executor(&self) -> BackgroundExecutor { + unimplemented!() + } + + fn foreground_executor(&self) -> crate::ForegroundExecutor { + unimplemented!() + } + + fn text_system(&self) -> Arc { + unimplemented!() + } + + fn run(&self, on_finish_launching: Box) { + unimplemented!() + } + + fn quit(&self) { + unimplemented!() + } + + fn restart(&self) { + unimplemented!() + } + + fn activate(&self, ignoring_other_apps: bool) { + unimplemented!() + } + + fn hide(&self) { + unimplemented!() + } + + fn hide_other_apps(&self) { + unimplemented!() + } + + fn unhide_other_apps(&self) { + unimplemented!() + } + + fn displays(&self) -> Vec> { + unimplemented!() + } + + fn display(&self, id: DisplayId) -> Option> { + unimplemented!() + } + + fn active_window(&self) -> Option { + unimplemented!() + } + + fn open_window( + &self, + handle: AnyWindowHandle, + options: WindowOptions, + ) -> Box { + unimplemented!() + } + + fn set_display_link_output_callback( + &self, + display_id: DisplayId, + callback: Box, + ) { + unimplemented!() + } + + fn start_display_link(&self, display_id: DisplayId) { + unimplemented!() + } + + fn stop_display_link(&self, display_id: DisplayId) { + unimplemented!() + } + + fn open_url(&self, url: &str) { + unimplemented!() + } + + fn on_open_urls(&self, callback: Box)>) { + unimplemented!() + } + + fn prompt_for_paths( + &self, + options: PathPromptOptions, + ) -> oneshot::Receiver>> { + unimplemented!() + } + + fn prompt_for_new_path(&self, directory: &Path) -> oneshot::Receiver> { + unimplemented!() + } + + fn reveal_path(&self, path: &Path) { + unimplemented!() + } + + fn on_become_active(&self, callback: Box) { + unimplemented!() + } + + fn on_resign_active(&self, callback: Box) { + unimplemented!() + } + + fn on_quit(&self, callback: Box) { + unimplemented!() + } + + fn on_reopen(&self, callback: Box) { + unimplemented!() + } + + fn on_event(&self, callback: Box bool>) { + unimplemented!() + } + + fn on_app_menu_action(&self, callback: Box) { + unimplemented!() + } + + fn on_will_open_app_menu(&self, callback: Box) { + unimplemented!() + } + + fn on_validate_app_menu_command(&self, callback: Box bool>) { + unimplemented!() + } + + fn os_name(&self) -> &'static str { + "Linux" + } + + fn double_click_interval(&self) -> Duration { + unimplemented!() + } + + fn os_version(&self) -> Result { + unimplemented!() + } + + fn app_version(&self) -> Result { + unimplemented!() + } + + fn app_path(&self) -> Result { + unimplemented!() + } + + fn set_menus(&self, menus: Vec, keymap: &Keymap) { + unimplemented!() + } + + fn local_timezone(&self) -> UtcOffset { + unimplemented!() + } + + fn path_for_auxiliary_executable(&self, name: &str) -> Result { + unimplemented!() + } + + fn set_cursor_style(&self, style: CursorStyle) { + unimplemented!() + } + + fn should_auto_hide_scrollbars(&self) -> bool { + unimplemented!() + } + + fn write_to_clipboard(&self, item: ClipboardItem) { + unimplemented!() + } + + fn read_from_clipboard(&self) -> Option { + unimplemented!() + } + + fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Task> { + unimplemented!() + } + + fn read_credentials(&self, url: &str) -> Task)>>> { + unimplemented!() + } + + fn delete_credentials(&self, url: &str) -> Task> { + unimplemented!() + } +} + +#[cfg(test)] +mod tests { + use crate::ClipboardItem; + + use super::*; + + fn build_platform() -> LinuxPlatform { + let platform = LinuxPlatform::new(); + platform + } +} diff --git a/crates/gpui/src/scene.rs b/crates/gpui/src/scene.rs index 70e24030b1..e1aa7fda20 100644 --- a/crates/gpui/src/scene.rs +++ b/crates/gpui/src/scene.rs @@ -671,6 +671,7 @@ pub(crate) struct Surface { pub order: DrawOrder, pub bounds: Bounds, pub content_mask: ContentMask, + #[cfg(target_os = "macos")] pub image_buffer: media::core_video::CVImageBuffer, } diff --git a/crates/gpui/src/window/element_cx.rs b/crates/gpui/src/window/element_cx.rs index c7814fc101..4e21988a2e 100644 --- a/crates/gpui/src/window/element_cx.rs +++ b/crates/gpui/src/window/element_cx.rs @@ -23,6 +23,7 @@ use std::{ use anyhow::Result; use collections::{FxHashMap, FxHashSet}; use derive_more::{Deref, DerefMut}; +#[cfg(target_os = "macos")] use media::core_video::CVImageBuffer; use smallvec::SmallVec; use util::post_inc; @@ -34,7 +35,7 @@ use crate::{ InputHandler, IsZero, KeyContext, KeyEvent, KeymatchMode, LayoutId, MonochromeSprite, MouseEvent, PaintQuad, Path, Pixels, PlatformInputHandler, Point, PolychromeSprite, Quad, RenderGlyphParams, RenderImageParams, RenderSvgParams, Scene, Shadow, SharedString, Size, - StackingContext, StackingOrder, Style, Surface, TextStyleRefinement, Underline, UnderlineStyle, + StackingContext, StackingOrder, Style, TextStyleRefinement, Underline, UnderlineStyle, Window, WindowContext, SUBPIXEL_VARIANTS, }; @@ -962,6 +963,7 @@ impl<'a> ElementContext<'a> { } /// Paint a surface into the scene for the next frame at the current z-index. + #[cfg(target_os = "macos")] pub fn paint_surface(&mut self, bounds: Bounds, image_buffer: CVImageBuffer) { let scale_factor = self.scale_factor(); let bounds = bounds.scale(scale_factor); @@ -970,7 +972,7 @@ impl<'a> ElementContext<'a> { let window = &mut *self.window; window.next_frame.scene.insert( &window.next_frame.z_index_stack, - Surface { + crate::Surface { view_id: view_id.into(), layer_id: 0, order: 0,