Merge pull request #5 from crsaracco/master
Add build+test CI, make public code platform-independent (ish)
This commit is contained in:
commit
aedaed6766
27
.github/workflows/rust.yml
vendored
Normal file
27
.github/workflows/rust.yml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
name: Rust
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install XCB dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install libx11-xcb-dev libxcb-dri2-0-dev
|
||||
if: contains(matrix.os, 'ubuntu')
|
||||
- name: install rust stable
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
- name: Build
|
||||
run: cargo build --verbose
|
||||
- name: Run tests
|
||||
run: cargo test --verbose
|
|
@ -1,10 +0,0 @@
|
|||
fn main() {
|
||||
let window_open_options = baseview::WindowOpenOptions {
|
||||
title: "baseview",
|
||||
width: 512,
|
||||
height: 512,
|
||||
parent: baseview::Parent::None,
|
||||
};
|
||||
|
||||
baseview::Window::open(window_open_options);
|
||||
}
|
25
examples/open_window.rs
Normal file
25
examples/open_window.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use std::ptr::null_mut;
|
||||
|
||||
fn main() {
|
||||
let window_open_options = baseview::WindowOpenOptions {
|
||||
title: "baseview",
|
||||
width: 512,
|
||||
height: 512,
|
||||
parent: baseview::Parent::None,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "macos")] {
|
||||
baseview::Window::open(window_open_options);
|
||||
}
|
||||
#[cfg(target_os = "windows")] {
|
||||
baseview::create_window(window_open_options);
|
||||
loop {
|
||||
if !baseview::handle_msg(null_mut()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "linux")] {
|
||||
baseview::run(window_open_options);
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
use std::ptr::null_mut;
|
||||
|
||||
use baseview::Parent;
|
||||
use baseview::{create_window, handle_msg, WindowOpenOptions};
|
||||
|
||||
fn main() {
|
||||
let window = WindowOpenOptions {
|
||||
title: "Baseview",
|
||||
width: 800,
|
||||
height: 400,
|
||||
parent: Parent::None,
|
||||
};
|
||||
|
||||
create_window(window);
|
||||
|
||||
loop {
|
||||
if !handle_msg(null_mut()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
fn main() {
|
||||
let window_open_options = baseview::WindowOpenOptions {
|
||||
title: "baseview",
|
||||
width: 512,
|
||||
height: 512,
|
||||
parent: baseview::Parent::None,
|
||||
};
|
||||
|
||||
baseview::run(window_open_options);
|
||||
}
|
13
src/lib.rs
13
src/lib.rs
|
@ -1,12 +1,14 @@
|
|||
mod win;
|
||||
|
||||
pub use win::*;
|
||||
|
||||
use std::ffi::c_void;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod win;
|
||||
#[cfg(target_os = "windows")]
|
||||
pub use win::*;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod x11;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
mod macos;
|
||||
#[cfg(target_os = "macos")]
|
||||
pub use macos::Window;
|
||||
|
||||
pub enum Parent {
|
||||
|
@ -24,6 +26,7 @@ pub struct WindowOpenOptions<'a> {
|
|||
pub parent: Parent,
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn run(options: WindowOpenOptions) {
|
||||
x11::run(options);
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ pub fn run(options: WindowOpenOptions) {
|
|||
|
||||
// Figure out the DPI scaling by opening a new temporary connection and asking XCB
|
||||
// TODO: currently returning (96, 96) on my system, even though I have 4k screens. Problem with my setup perhaps?
|
||||
#[allow(dead_code)]
|
||||
pub fn get_scaling() -> (u32, u32) {
|
||||
let (conn, screen_num) = xcb::Connection::connect_with_xlib_display().unwrap();
|
||||
|
||||
|
|
Loading…
Reference in a new issue