Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Windows support #8809

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5cbc0e7
build target add
JunkuiZhang Mar 1, 2024
ebf3943
terminal fix
JunkuiZhang Mar 1, 2024
d4daee3
rename to cross_platfrom
JunkuiZhang Mar 1, 2024
a8e8225
basic impl
JunkuiZhang Mar 1, 2024
4e2af69
fix build on wsl
JunkuiZhang Mar 1, 2024
0d3ea37
fix build on linux
JunkuiZhang Mar 1, 2024
f0e58cc
draw window every 16ms
JunkuiZhang Mar 1, 2024
47aa507
better error
JunkuiZhang Mar 1, 2024
ab57500
fix cursor
JunkuiZhang Mar 1, 2024
305b3ea
mouse hwheel
JunkuiZhang Mar 1, 2024
e002a03
scale factor issue
JunkuiZhang Mar 1, 2024
d5427ff
temp fix on scale factor
JunkuiZhang Mar 1, 2024
832a825
fix clipboard
JunkuiZhang Mar 1, 2024
b3715f7
update clipboard
JunkuiZhang Mar 2, 2024
5ed1a6c
update read clipboard fn
JunkuiZhang Mar 2, 2024
80e2690
refine error handling
JunkuiZhang Mar 2, 2024
5f646ce
some cleanup
JunkuiZhang Mar 2, 2024
475255e
disable mouse leave event
JunkuiZhang Mar 2, 2024
95a418a
fix ime
JunkuiZhang Mar 2, 2024
c791e4c
small fix
JunkuiZhang Mar 2, 2024
d875469
remove unused
JunkuiZhang Mar 2, 2024
6eaa7f1
update shortcuts
JunkuiZhang Mar 3, 2024
7176433
destroy accel
JunkuiZhang Mar 3, 2024
b86caf1
credential stuff
JunkuiZhang Mar 3, 2024
2259868
small fix
JunkuiZhang Mar 3, 2024
5213f4a
small fix
JunkuiZhang Mar 3, 2024
6460099
revoke terminal change
JunkuiZhang Mar 4, 2024
f03226a
fix error
JunkuiZhang Mar 4, 2024
2925897
fix typo
JunkuiZhang Mar 4, 2024
6514fe5
fix build on linux
JunkuiZhang Mar 4, 2024
38327bb
use workspace windows crate
JunkuiZhang Mar 4, 2024
c36b2ab
fix fs
JunkuiZhang Mar 4, 2024
2756425
fix a crash
JunkuiZhang Mar 4, 2024
c2a1a28
remove extra deps
JunkuiZhang Mar 4, 2024
423e1d3
run cargo clippy
JunkuiZhang Mar 4, 2024
0a8739a
fix typo
JunkuiZhang Mar 4, 2024
0a125e6
fix mac imports
JunkuiZhang Mar 4, 2024
01cdc70
fix typo
JunkuiZhang Mar 4, 2024
d163ba4
need a deeper look into the `input()` and `input_handler()` functions
JunkuiZhang Mar 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 36 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ hex = "0.4.3"
ignore = "0.4.22"
indoc = "1"
# We explicitly disable http2 support in isahc.
isahc = { version = "1.7.2", default-features = false, features = ["static-curl", "text-decoding"] }
isahc = { version = "1.7.2", default-features = false, features = [
"static-curl",
"text-decoding",
] }
itertools = "0.11.0"
lazy_static = "1.4.0"
linkify = "0.10.0"
Expand All @@ -238,7 +241,10 @@ semver = "1.0"
serde = { version = "1.0", features = ["derive", "rc"] }
serde_derive = { version = "1.0", features = ["deserialize_in_place"] }
serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }
serde_json_lenient = { version = "0.1", features = ["preserve_order", "raw_value"] }
serde_json_lenient = { version = "0.1", features = [
"preserve_order",
"raw_value",
] }
serde_repr = "0.1"
sha2 = "0.10"
shellexpand = "2.1.0"
Expand All @@ -249,7 +255,11 @@ sysinfo = "0.29.10"
tempfile = "3.9.0"
thiserror = "1.0.29"
tiktoken-rs = "0.5.7"
time = { version = "0.3", features = ["serde", "serde-well-known", "formatting"] }
time = { version = "0.3", features = [
"serde",
"serde-well-known",
"formatting",
] }
toml = "0.8"
tower-http = "0.4.4"
tree-sitter = { version = "0.20", features = ["wasm"] }
Expand Down Expand Up @@ -310,16 +320,35 @@ which = "6.0.0"
sys-locale = "0.3.1"

[workspace.dependencies.windows]
version = "0.53.0"
version = "0.54.0"
features = [
"implement",
"Wdk_System_SystemServices",
"Win32_Foundation",
"Win32_Globalization",
"Win32_Graphics_Gdi",
"Win32_UI_WindowsAndMessaging",
"Win32_Security",
"Win32_Security_Credentials",
"Win32_Storage_FileSystem",
"Win32_System_Com",
"Win32_System_Com_StructuredStorage",
"Win32_System_DataExchange",
"Win32_System_LibraryLoader",
"Win32_System_Memory",
"Win32_System_Ole",
"Win32_System_SystemInformation",
"Win32_System_SystemServices",
"Win32_System_Time",
"Win32_System_Threading",
"Win32_UI_Accessibility",
"Win32_UI_Controls",
"Win32_UI_HiDpi",
"Win32_UI_Input_Ime",
"Win32_UI_Input_KeyboardAndMouse",
"Win32_UI_Shell",
"Win32_UI_WindowsAndMessaging",
]



[patch.crates-io]
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "e4a23971ec3071a09c1e84816954c98f96e98e52" }
# Workaround for a broken nightly build of gpui: See #7644 and revisit once 0.5.3 is released.
Expand Down
5 changes: 1 addition & 4 deletions crates/fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ gpui = { workspace = true, optional = true }
notify = "6.1.1"

[target.'cfg(target_os = "windows")'.dependencies]
windows-sys = { version = "0.52", features = [
"Win32_Foundation",
"Win32_Storage_FileSystem",
] }
windows.workspace = true

[dev-dependencies]
gpui = { workspace = true, features = ["test-support"] }
Expand Down
9 changes: 3 additions & 6 deletions crates/fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ async fn file_id(path: impl AsRef<Path>) -> Result<u64> {
use std::os::windows::io::AsRawHandle;

use smol::fs::windows::OpenOptionsExt;
use windows_sys::Win32::{
use windows::Win32::{
Foundation::HANDLE,
Storage::FileSystem::{
GetFileInformationByHandle, BY_HANDLE_FILE_INFORMATION, FILE_FLAG_BACKUP_SEMANTICS,
Expand All @@ -1449,18 +1449,15 @@ async fn file_id(path: impl AsRef<Path>) -> Result<u64> {

let file = smol::fs::OpenOptions::new()
.read(true)
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS)
.custom_flags(FILE_FLAG_BACKUP_SEMANTICS.0)
.open(path)
.await?;

let mut info: BY_HANDLE_FILE_INFORMATION = unsafe { std::mem::zeroed() };
// https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileinformationbyhandle
// This function supports Windows XP+
smol::unblock(move || {
let ret = unsafe { GetFileInformationByHandle(file.as_raw_handle() as HANDLE, &mut info) };
if ret == 0 {
return Err(anyhow!(format!("{}", std::io::Error::last_os_error())));
};
unsafe { GetFileInformationByHandle(HANDLE(file.as_raw_handle() as _), &mut info)? };

Ok(((info.nFileIndexHigh as u64) << 32) | (info.nFileIndexLow as u64))
})
Expand Down
13 changes: 10 additions & 3 deletions crates/gpui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,26 @@ cosmic-text = "0.10.0"
open = "5.0.1"
ashpd = "0.7.0"
xcb = { version = "1.3", features = ["as-raw-xcb-connection", "randr", "xkb"] }
wayland-client= { version = "0.31.2" }
wayland-client = { version = "0.31.2" }
wayland-cursor = "0.31.1"
wayland-protocols = { version = "0.31.2", features = ["client", "staging", "unstable"] }
wayland-protocols = { version = "0.31.2", features = [
"client",
"staging",
"unstable",
] }
wayland-backend = { version = "0.3.3", features = ["client_system"] }
xkbcommon = { version = "0.7", features = ["wayland", "x11"] }
as-raw-xcb-connection = "1"
calloop = "0.12.4"
calloop-wayland-source = "0.2.0"
oo7 = "0.3.0"

[target.'cfg(windows)'.dependencies]
[target.'cfg(target_os = "windows")'.dependencies]
windows.workspace = true

[target.'cfg(target_os = "windows")'.build-dependencies]
winresource = "0.1"

[[example]]
name = "hello_world"
path = "examples/hello_world.rs"
Expand Down
11 changes: 11 additions & 0 deletions crates/gpui/assets/windows/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32'
name='Microsoft.Windows.Common-Controls'
version='6.0.0.0' processorArchitecture='*'
publicKeyToken='6595b64144ccf1df' />
</dependentAssembly>
</dependency>
</assembly>
19 changes: 19 additions & 0 deletions crates/gpui/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ fn main() {
#[cfg(all(target_os = "macos", not(feature = "macos-blade")))]
#[cfg(not(feature = "runtime_shaders"))]
compile_metal_shaders(&header_path);

// We are using Windows Visita+, right..?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We are using Windows Visita+, right..?
// We are using Windows Vista+, right..?

Side note: The rust-toolchain.toml file mandates the Rust version of 1.76, which is incidentally the first version to restrict official Windows support to Windows 10 and Windows 11.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually is news to me. Additionally, the alacritty_terminal dependency that Zed relies on is implemented through conPTY API on Windows, while this API is only supported starting from the Windows 10 Fall 2018 update. So, I guess these users will also be left behind..?

// if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
#[cfg(target_os = "windows")]
{
println!("cargo:rustc-link-arg=/stack:{}", 4 * 1024 * 1024);
println!("cargo:rerun-if-changed=assets/windows/manifest.xml");
let mut res = winresource::WindowsResource::new();
let manifest_path = std::env::current_dir()
.unwrap()
.join("assets")
.join("windows")
.join("manifest.xml");
res.set_manifest_file(manifest_path.to_str().unwrap());
if let Err(e) = res.compile() {
eprintln!("{}", e);
std::process::exit(1);
}
}
}

fn generate_dispatch_bindings() {
Expand Down
10 changes: 5 additions & 5 deletions crates/gpui/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ mod linux;
#[cfg(target_os = "macos")]
mod mac;

#[cfg(target_os = "windows")]
mod windows;

#[cfg(any(target_os = "linux", target_os = "windows", feature = "macos-blade"))]
mod blade;
mod cross_platform;

#[cfg(any(test, feature = "test-support"))]
mod test;

#[cfg(target_os = "windows")]
mod windows;

use crate::{
Action, AnyWindowHandle, AsyncWindowContext, BackgroundExecutor, Bounds, DevicePixels, Font,
FontId, FontMetrics, FontRun, ForegroundExecutor, GlobalPixels, GlyphId, Keymap, LineLayout,
Expand Down Expand Up @@ -68,7 +68,7 @@ pub(crate) fn current_platform() -> Rc<dyn Platform> {
pub(crate) fn current_platform() -> Rc<dyn Platform> {
Rc::new(LinuxPlatform::new())
}
// todo("windows")

#[cfg(target_os = "windows")]
pub(crate) fn current_platform() -> Rc<dyn Platform> {
Rc::new(WindowsPlatform::new())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
mod blade_atlas;
mod blade_belt;
mod blade_renderer;
#[cfg(not(feature = "macos-blade"))]
mod text_system;

pub(crate) use blade_atlas::*;
pub(crate) use blade_renderer::*;
#[cfg(not(feature = "macos-blade"))]
pub(crate) use text_system::*;

use blade_belt::*;
Loading
Loading