1
0
Fork 0

Add additional CI checks (#182)

This commit is contained in:
Adrien Prokopowicz 2024-03-30 00:55:44 +01:00 committed by GitHub
parent bcbdb8921f
commit 119fc25cd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 61 additions and 34 deletions

View file

@ -1,29 +1,39 @@
name: Rust name: Rust
on: [push, pull_request] on: [push, pull_request]
env:
CARGO_TERM_COLOR: always
jobs: jobs:
build: build:
runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}
env:
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v4
- name: Install XCB and GL dependencies - name: Install XCB and GL dependencies
run: |
sudo apt update
sudo apt install libx11-xcb-dev libxcb-dri2-0-dev libgl1-mesa-dev libxcb-icccm4-dev libxcursor-dev
if: contains(matrix.os, 'ubuntu') if: contains(matrix.os, 'ubuntu')
run: sudo apt-get install libx11-xcb-dev libxcb-dri2-0-dev libgl1-mesa-dev libxcb-icccm4-dev libxcursor-dev
- name: Install rust stable - name: Install rust stable
uses: actions-rs/toolchain@v1 uses: dtolnay/rust-toolchain@stable
with: with:
toolchain: stable toolchain: stable
override: true components: rustfmt, clippy
- name: Build with default features - name: Build Default
run: cargo build --examples --workspace --verbose run: cargo build --workspace --all-targets --verbose
- name: Build again with all features - name: Build All Features
run: cargo build --examples --workspace --all-features --verbose run: cargo build --workspace --all-targets --all-features --verbose
- name: Run tests - name: Run tests
run: cargo test --examples --workspace --all-features --verbose run: cargo test --workspace --all-targets --all-features --verbose
- name: Check docs
run: cargo doc --examples --all-features --no-deps
- name: Clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
- name: Check Formatting (rustfmt)
run: cargo fmt --all -- --check

View file

@ -43,3 +43,16 @@ softbuffer = "0.3.4"
[workspace] [workspace]
members = ["examples/render_femtovg"] members = ["examples/render_femtovg"]
[lints.clippy]
missing-safety-doc = "allow"
[[example]]
name = "open_window"
test = true
doctest = true
[[example]]
name = "open_parented"
test = true
doctest = true

2
clippy.toml Normal file
View file

@ -0,0 +1,2 @@
msrv = '1.59'
check-private-items = true

View file

@ -40,7 +40,7 @@ impl WindowHandler for OpenWindowExample {
fn on_event(&mut self, _window: &mut Window, event: Event) -> EventStatus { fn on_event(&mut self, _window: &mut Window, event: Event) -> EventStatus {
match &event { match &event {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
Event::Mouse(MouseEvent::ButtonPressed { .. }) => copy_to_clipboard(&"This is a test!"), Event::Mouse(MouseEvent::ButtonPressed { .. }) => copy_to_clipboard("This is a test!"),
Event::Window(WindowEvent::Resized(info)) => { Event::Window(WindowEvent::Resized(info)) => {
println!("Resized: {:?}", info); println!("Resized: {:?}", info);
let new_size = info.physical_size(); let new_size = info.physical_size();
@ -78,7 +78,7 @@ fn main() {
std::thread::spawn(move || loop { std::thread::spawn(move || loop {
std::thread::sleep(Duration::from_secs(5)); std::thread::sleep(Duration::from_secs(5));
if let Err(_) = tx.push(Message::Hello) { if tx.push(Message::Hello).is_err() {
println!("Failed sending message"); println!("Failed sending message");
} }
}); });

View file

@ -121,10 +121,8 @@ impl GlContext {
let framework_name = CFString::from_str("com.apple.opengl").unwrap(); let framework_name = CFString::from_str("com.apple.opengl").unwrap();
let framework = let framework =
unsafe { CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef()) }; unsafe { CFBundleGetBundleWithIdentifier(framework_name.as_concrete_TypeRef()) };
let addr = unsafe {
CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef()) unsafe { CFBundleGetFunctionPointerForName(framework, symbol_name.as_concrete_TypeRef()) }
};
addr as *const c_void
} }
pub fn swap_buffers(&self) { pub fn swap_buffers(&self) {

View file

@ -43,7 +43,6 @@ impl WindowHandle {
pub fn is_open(&self) -> bool { pub fn is_open(&self) -> bool {
self.state.window_inner.open.get() self.state.window_inner.open.get()
} }
} }
unsafe impl HasRawWindowHandle for WindowHandle { unsafe impl HasRawWindowHandle for WindowHandle {
@ -289,7 +288,9 @@ impl<'a> Window<'a> {
unsafe { unsafe {
let view = self.inner.ns_view.as_mut().unwrap(); let view = self.inner.ns_view.as_mut().unwrap();
let window: id = msg_send![view, window]; let window: id = msg_send![view, window];
if window == nil { return false; }; if window == nil {
return false;
};
let first_responder: id = msg_send![window, firstResponder]; let first_responder: id = msg_send![window, firstResponder];
let is_key_window: BOOL = msg_send![window, isKeyWindow]; let is_key_window: BOOL = msg_send![window, isKeyWindow];
let is_focused: BOOL = msg_send![view, isEqual: first_responder]; let is_focused: BOOL = msg_send![view, isEqual: first_responder];

View file

@ -15,7 +15,7 @@ use winapi::um::oleidl::{
IDropTarget, IDropTargetVtbl, DROPEFFECT_COPY, DROPEFFECT_LINK, DROPEFFECT_MOVE, IDropTarget, IDropTargetVtbl, DROPEFFECT_COPY, DROPEFFECT_LINK, DROPEFFECT_MOVE,
DROPEFFECT_NONE, DROPEFFECT_SCROLL, DROPEFFECT_NONE, DROPEFFECT_SCROLL,
}; };
use winapi::um::shellapi::DragQueryFileW; use winapi::um::shellapi::{DragQueryFileW, HDROP};
use winapi::um::unknwnbase::{IUnknown, IUnknownVtbl}; use winapi::um::unknwnbase::{IUnknown, IUnknownVtbl};
use winapi::um::winuser::CF_HDROP; use winapi::um::winuser::CF_HDROP;
use winapi::Interface; use winapi::Interface;
@ -135,7 +135,7 @@ impl DropTarget {
return; return;
} }
let hdrop = transmute((*medium.u).hGlobal()); let hdrop = *(*medium.u).hGlobal() as HDROP;
let item_count = DragQueryFileW(hdrop, 0xFFFFFFFF, null_mut(), 0); let item_count = DragQueryFileW(hdrop, 0xFFFFFFFF, null_mut(), 0);
if item_count == 0 { if item_count == 0 {
@ -153,7 +153,7 @@ impl DropTarget {
DragQueryFileW( DragQueryFileW(
hdrop, hdrop,
i, i,
transmute(buffer.spare_capacity_mut().as_mut_ptr()), buffer.spare_capacity_mut().as_mut_ptr().cast(),
buffer_size as u32, buffer_size as u32,
); );
buffer.set_len(buffer_size); buffer.set_len(buffer_size);
@ -175,7 +175,7 @@ impl DropTarget {
return S_OK; return S_OK;
} }
return E_NOINTERFACE; E_NOINTERFACE
} }
unsafe extern "system" fn add_ref(this: *mut IUnknown) -> ULONG { unsafe extern "system" fn add_ref(this: *mut IUnknown) -> ULONG {

View file

@ -6,9 +6,9 @@ use winapi::um::ole2::{OleInitialize, RegisterDragDrop, RevokeDragDrop};
use winapi::um::oleidl::LPDROPTARGET; use winapi::um::oleidl::LPDROPTARGET;
use winapi::um::winuser::{ use winapi::um::winuser::{
AdjustWindowRectEx, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, AdjustWindowRectEx, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW,
GetDpiForWindow, GetMessageW, GetWindowLongPtrW, LoadCursorW, PostMessageW, RegisterClassW, GetDpiForWindow, GetFocus, GetMessageW, GetWindowLongPtrW, LoadCursorW, PostMessageW,
ReleaseCapture, SetCapture, SetProcessDpiAwarenessContext, SetTimer, SetWindowLongPtrW, RegisterClassW, ReleaseCapture, SetCapture, SetFocus, SetProcessDpiAwarenessContext, SetTimer,
SetWindowPos, SetFocus, GetFocus, TrackMouseEvent, TranslateMessage, UnregisterClassW, CS_OWNDC, SetWindowLongPtrW, SetWindowPos, TrackMouseEvent, TranslateMessage, UnregisterClassW, CS_OWNDC,
GET_XBUTTON_WPARAM, GWLP_USERDATA, IDC_ARROW, MSG, SWP_NOMOVE, SWP_NOZORDER, TRACKMOUSEEVENT, GET_XBUTTON_WPARAM, GWLP_USERDATA, IDC_ARROW, MSG, SWP_NOMOVE, SWP_NOZORDER, TRACKMOUSEEVENT,
WHEEL_DELTA, WM_CHAR, WM_CLOSE, WM_CREATE, WM_DPICHANGED, WM_INPUTLANGCHANGE, WM_KEYDOWN, WHEEL_DELTA, WM_CHAR, WM_CLOSE, WM_CREATE, WM_DPICHANGED, WM_INPUTLANGCHANGE, WM_KEYDOWN,
WM_KEYUP, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEHWHEEL, WM_KEYUP, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MBUTTONDOWN, WM_MBUTTONUP, WM_MOUSEHWHEEL,
@ -174,7 +174,7 @@ unsafe fn wnd_proc_inner(
if *mouse_was_outside_window { if *mouse_was_outside_window {
// this makes Windows track whether the mouse leaves the window. // this makes Windows track whether the mouse leaves the window.
// When the mouse leaves it results in a `WM_MOUSELEAVE` event. // When the mouse leaves it results in a `WM_MOUSELEAVE` event.
let mut track_mouse =TRACKMOUSEEVENT { let mut track_mouse = TRACKMOUSEEVENT {
cbSize: std::mem::size_of::<TRACKMOUSEEVENT>() as u32, cbSize: std::mem::size_of::<TRACKMOUSEEVENT>() as u32,
dwFlags: winapi::um::winuser::TME_LEAVE, dwFlags: winapi::um::winuser::TME_LEAVE,
hwndTrack: hwnd, hwndTrack: hwnd,
@ -186,7 +186,12 @@ unsafe fn wnd_proc_inner(
*mouse_was_outside_window = false; *mouse_was_outside_window = false;
let enter_event = Event::Mouse(MouseEvent::CursorEntered); let enter_event = Event::Mouse(MouseEvent::CursorEntered);
window_state.handler.borrow_mut().as_mut().unwrap().on_event(&mut window, enter_event); window_state
.handler
.borrow_mut()
.as_mut()
.unwrap()
.on_event(&mut window, enter_event);
} }
let x = (lparam & 0xFFFF) as i16 as i32; let x = (lparam & 0xFFFF) as i16 as i32;

View file

@ -23,7 +23,7 @@ pub struct WindowHandle {
impl WindowHandle { impl WindowHandle {
fn new(window_handle: platform::WindowHandle) -> Self { fn new(window_handle: platform::WindowHandle) -> Self {
Self { window_handle, phantom: PhantomData::default() } Self { window_handle, phantom: PhantomData }
} }
/// Close the window /// Close the window

View file

@ -91,10 +91,8 @@ impl XcbConnection {
let _xres = width_px * 25.4 / width_mm; let _xres = width_px * 25.4 / width_mm;
let yres = height_px * 25.4 / height_mm; let yres = height_px * 25.4 / height_mm;
let yscale = yres / 96.0;
// TODO: choose between `xres` and `yres`? (probably both are the same?) // TODO: choose between `xres` and `yres`? (probably both are the same?)
yscale yres / 96.0
} }
#[inline] #[inline]