cargo fmt
This commit is contained in:
parent
9234f050c0
commit
90a25ea988
|
@ -13,52 +13,50 @@ fn main() {
|
||||||
baseview::Window::open(window_open_options, my_program);
|
baseview::Window::open(window_open_options, my_program);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MyProgram {
|
struct MyProgram {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl baseview::Receiver for MyProgram {
|
impl baseview::Receiver for MyProgram {
|
||||||
fn on_message(&mut self, message: Message) {
|
fn on_message(&mut self, message: Message) {
|
||||||
match message {
|
match message {
|
||||||
Message::CursorMotion(x, y) => {
|
Message::CursorMotion(x, y) => {
|
||||||
println!("Cursor moved, x: {}, y: {}", x, y);
|
println!("Cursor moved, x: {}, y: {}", x, y);
|
||||||
},
|
}
|
||||||
Message::MouseDown(button_id) => {
|
Message::MouseDown(button_id) => {
|
||||||
println!("Mouse down, button id: {:?}", button_id);
|
println!("Mouse down, button id: {:?}", button_id);
|
||||||
},
|
}
|
||||||
Message::MouseUp(button_id) => {
|
Message::MouseUp(button_id) => {
|
||||||
println!("Mouse up, button id: {:?}", button_id);
|
println!("Mouse up, button id: {:?}", button_id);
|
||||||
},
|
}
|
||||||
Message::MouseScroll(mouse_scroll) => {
|
Message::MouseScroll(mouse_scroll) => {
|
||||||
println!("Mouse scroll, {:?}", mouse_scroll);
|
println!("Mouse scroll, {:?}", mouse_scroll);
|
||||||
},
|
}
|
||||||
Message::MouseClick(mouse_click) => {
|
Message::MouseClick(mouse_click) => {
|
||||||
println!("Mouse click, {:?}", mouse_click);
|
println!("Mouse click, {:?}", mouse_click);
|
||||||
}
|
}
|
||||||
Message::KeyDown(keycode) => {
|
Message::KeyDown(keycode) => {
|
||||||
println!("Key down, keycode: {}", keycode);
|
println!("Key down, keycode: {}", keycode);
|
||||||
},
|
}
|
||||||
Message::KeyUp(keycode) => {
|
Message::KeyUp(keycode) => {
|
||||||
println!("Key up, keycode: {}", keycode);
|
println!("Key up, keycode: {}", keycode);
|
||||||
},
|
}
|
||||||
Message::CharacterInput(char_code) => {
|
Message::CharacterInput(char_code) => {
|
||||||
println!("Character input, char_code: {}", char_code);
|
println!("Character input, char_code: {}", char_code);
|
||||||
},
|
}
|
||||||
Message::WindowResized(window_info) => {
|
Message::WindowResized(window_info) => {
|
||||||
println!("Window resized, {:?}", window_info);
|
println!("Window resized, {:?}", window_info);
|
||||||
},
|
}
|
||||||
Message::WindowFocus => {
|
Message::WindowFocus => {
|
||||||
println!("Window focused");
|
println!("Window focused");
|
||||||
},
|
}
|
||||||
Message::WindowUnfocus => {
|
Message::WindowUnfocus => {
|
||||||
println!("Window unfocused");
|
println!("Window unfocused");
|
||||||
},
|
}
|
||||||
Message::Opened(window_info) => {
|
Message::Opened(window_info) => {
|
||||||
println!("Window opened, {:?}", window_info);
|
println!("Window opened, {:?}", window_info);
|
||||||
},
|
}
|
||||||
Message::WillClose => {
|
Message::WillClose => {
|
||||||
println!("Window will close");
|
println!("Window will close");
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,4 +35,4 @@ pub struct WindowOpenOptions<'a> {
|
||||||
|
|
||||||
pub trait Receiver {
|
pub trait Receiver {
|
||||||
fn on_message(&mut self, message: Message);
|
fn on_message(&mut self, message: Message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use cocoa::appkit::{
|
||||||
use cocoa::base::{nil, NO};
|
use cocoa::base::{nil, NO};
|
||||||
use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString};
|
use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString};
|
||||||
|
|
||||||
use crate::{WindowOpenOptions, Message, Receiver, MouseButtonID, MouseScroll};
|
use crate::{Message, MouseButtonID, MouseScroll, Receiver, WindowOpenOptions};
|
||||||
|
|
||||||
pub struct Window<R: Receiver> {
|
pub struct Window<R: Receiver> {
|
||||||
receiver: R,
|
receiver: R,
|
||||||
|
@ -44,17 +44,13 @@ impl<R: Receiver> Window<R> {
|
||||||
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
|
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
|
||||||
app.run();
|
app.run();
|
||||||
|
|
||||||
receiver.on_message(Message::Opened(
|
receiver.on_message(Message::Opened(crate::message::WindowInfo {
|
||||||
crate::message::WindowInfo {
|
width: options.width as u32,
|
||||||
width: options.width as u32,
|
height: options.height as u32,
|
||||||
height: options.height as u32,
|
dpi: None,
|
||||||
dpi: None,
|
}));
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
Window {
|
Window { receiver }
|
||||||
receiver,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,12 +43,12 @@ pub enum Message {
|
||||||
MouseUp(MouseButtonID),
|
MouseUp(MouseButtonID),
|
||||||
MouseScroll(MouseScroll),
|
MouseScroll(MouseScroll),
|
||||||
MouseClick(MouseClick),
|
MouseClick(MouseClick),
|
||||||
KeyDown(u8), // keycode
|
KeyDown(u8), // keycode
|
||||||
KeyUp(u8), // keycode
|
KeyUp(u8), // keycode
|
||||||
CharacterInput(u32), // character code
|
CharacterInput(u32), // character code
|
||||||
WindowResized(WindowInfo), // new (width, height)
|
WindowResized(WindowInfo), // new (width, height)
|
||||||
WindowFocus,
|
WindowFocus,
|
||||||
WindowUnfocus,
|
WindowUnfocus,
|
||||||
Opened(WindowInfo),
|
Opened(WindowInfo),
|
||||||
WillClose,
|
WillClose,
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ use self::winapi::um::winuser::{
|
||||||
use self::winapi::ctypes::c_void;
|
use self::winapi::ctypes::c_void;
|
||||||
use crate::Parent::WithParent;
|
use crate::Parent::WithParent;
|
||||||
use crate::{handle_message, WindowOpenOptions};
|
use crate::{handle_message, WindowOpenOptions};
|
||||||
use crate::{Message, Receiver, MouseButtonID, MouseScroll};
|
use crate::{Message, MouseButtonID, MouseScroll, Receiver};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
unsafe fn message_box(title: &str, msg: &str) {
|
unsafe fn message_box(title: &str, msg: &str) {
|
||||||
|
@ -241,13 +241,13 @@ impl<R: Receiver> Window<R> {
|
||||||
|
|
||||||
SetTimer(hwnd, 4242, 13, None);
|
SetTimer(hwnd, 4242, 13, None);
|
||||||
|
|
||||||
window.receiver.on_message(Message::Opened(
|
window
|
||||||
crate::message::WindowInfo {
|
.receiver
|
||||||
|
.on_message(Message::Opened(crate::message::WindowInfo {
|
||||||
width: options.width as u32,
|
width: options.width as u32,
|
||||||
height: options.height as u32,
|
height: options.height as u32,
|
||||||
dpi: window.scaling,
|
dpi: window.scaling,
|
||||||
}
|
}));
|
||||||
));
|
|
||||||
|
|
||||||
// todo: decide what to do with the message pump
|
// todo: decide what to do with the message pump
|
||||||
if parent.is_null() {
|
if parent.is_null() {
|
||||||
|
@ -290,9 +290,6 @@ impl<R: Receiver> Window<R> {
|
||||||
self.r = r;
|
self.r = r;
|
||||||
self.g = g;
|
self.g = g;
|
||||||
|
|
||||||
self.receiver.on_message(Message::CursorMotion(
|
self.receiver.on_message(Message::CursorMotion(x, y));
|
||||||
x,
|
|
||||||
y,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,4 @@ mod window;
|
||||||
pub use window::*;
|
pub use window::*;
|
||||||
|
|
||||||
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
|
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
|
||||||
mod opengl_util;
|
mod opengl_util;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::ffi::{CString, CStr};
|
use std::ffi::{CStr, CString};
|
||||||
use std::os::raw::{c_int, c_void};
|
use std::os::raw::{c_int, c_void};
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
|
|
||||||
|
@ -35,19 +35,16 @@ pub fn fb_config(xcb_connection: &XcbConnection) -> *mut glx::__GLXFBConfigRec {
|
||||||
|
|
||||||
pub fn x_visual_info(
|
pub fn x_visual_info(
|
||||||
xcb_connection: &XcbConnection,
|
xcb_connection: &XcbConnection,
|
||||||
fb_config: *mut glx::__GLXFBConfigRec
|
fb_config: *mut glx::__GLXFBConfigRec,
|
||||||
) -> *const xlib::XVisualInfo {
|
) -> *const xlib::XVisualInfo {
|
||||||
// The GLX framebuffer config holds an XVisualInfo, which we'll need for other X operations.
|
// The GLX framebuffer config holds an XVisualInfo, which we'll need for other X operations.
|
||||||
|
|
||||||
unsafe { glx::glXGetVisualFromFBConfig(
|
unsafe { glx::glXGetVisualFromFBConfig(xcb_connection.conn.get_raw_dpy(), fb_config) }
|
||||||
xcb_connection.conn.get_raw_dpy(),
|
|
||||||
fb_config
|
|
||||||
)}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn glx_context(
|
pub fn glx_context(
|
||||||
xcb_connection: &XcbConnection,
|
xcb_connection: &XcbConnection,
|
||||||
fb_config: *mut glx::__GLXFBConfigRec
|
fb_config: *mut glx::__GLXFBConfigRec,
|
||||||
) -> *mut glx::__GLXcontextRec {
|
) -> *mut glx::__GLXcontextRec {
|
||||||
// Load GLX extensions
|
// Load GLX extensions
|
||||||
// We need at least `GLX_ARB_create_context`
|
// We need at least `GLX_ARB_create_context`
|
||||||
|
@ -182,4 +179,4 @@ pub fn xcb_expose(
|
||||||
glx::glXSwapBuffers(raw_display, window_id as xlib::XID);
|
glx::glXSwapBuffers(raw_display, window_id as xlib::XID);
|
||||||
glx::glXMakeCurrent(raw_display, 0, null_mut());
|
glx::glXMakeCurrent(raw_display, 0, null_mut());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ use ::x11::xlib;
|
||||||
use super::opengl_util;
|
use super::opengl_util;
|
||||||
|
|
||||||
use super::XcbConnection;
|
use super::XcbConnection;
|
||||||
use crate::{Parent, WindowOpenOptions, Message, Receiver, MouseButtonID, MouseScroll};
|
use crate::{Message, MouseButtonID, MouseScroll, Parent, Receiver, WindowOpenOptions};
|
||||||
|
|
||||||
pub struct Window<R: Receiver> {
|
pub struct Window<R: Receiver> {
|
||||||
xcb_connection: XcbConnection,
|
xcb_connection: XcbConnection,
|
||||||
|
@ -42,9 +42,8 @@ impl<R: Receiver> Window<R> {
|
||||||
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
|
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
|
||||||
let fb_config = opengl_util::fb_config(&xcb_connection);
|
let fb_config = opengl_util::fb_config(&xcb_connection);
|
||||||
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
|
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
|
||||||
let x_visual_info: *const xlib::XVisualInfo = {
|
let x_visual_info: *const xlib::XVisualInfo =
|
||||||
opengl_util::x_visual_info(&xcb_connection, fb_config)
|
{ opengl_util::x_visual_info(&xcb_connection, fb_config) };
|
||||||
};
|
|
||||||
|
|
||||||
// Load up DRI2 extensions.
|
// Load up DRI2 extensions.
|
||||||
// See also: https://www.x.org/releases/X11R7.7/doc/dri2proto/dri2proto.txt
|
// See also: https://www.x.org/releases/X11R7.7/doc/dri2proto/dri2proto.txt
|
||||||
|
@ -176,13 +175,13 @@ impl<R: Receiver> Window<R> {
|
||||||
.or(x11_window.get_scaling_screen_dimensions());
|
.or(x11_window.get_scaling_screen_dimensions());
|
||||||
println!("Scale factor: {:?}", x11_window.scaling);
|
println!("Scale factor: {:?}", x11_window.scaling);
|
||||||
|
|
||||||
x11_window.receiver.on_message(Message::Opened(
|
x11_window
|
||||||
crate::message::WindowInfo {
|
.receiver
|
||||||
|
.on_message(Message::Opened(crate::message::WindowInfo {
|
||||||
width: options.width as u32,
|
width: options.width as u32,
|
||||||
height: options.height as u32,
|
height: options.height as u32,
|
||||||
dpi: x11_window.scaling,
|
dpi: x11_window.scaling,
|
||||||
}
|
}));
|
||||||
));
|
|
||||||
|
|
||||||
x11_window.handle_events(window_id);
|
x11_window.handle_events(window_id);
|
||||||
|
|
||||||
|
@ -223,15 +222,15 @@ impl<R: Receiver> Window<R> {
|
||||||
xcb::EXPOSE => {
|
xcb::EXPOSE => {
|
||||||
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
|
#[cfg(all(feature = "gl_renderer", not(feature = "wgpu_renderer")))]
|
||||||
opengl_util::xcb_expose(window_id, raw_display, self.ctx);
|
opengl_util::xcb_expose(window_id, raw_display, self.ctx);
|
||||||
},
|
}
|
||||||
xcb::MOTION_NOTIFY => {
|
xcb::MOTION_NOTIFY => {
|
||||||
let event = unsafe { xcb::cast_event::<xcb::MotionNotifyEvent>(&event) };
|
let event = unsafe { xcb::cast_event::<xcb::MotionNotifyEvent>(&event) };
|
||||||
let detail = event.detail();
|
let detail = event.detail();
|
||||||
|
|
||||||
if detail != 4 && detail != 5 {
|
if detail != 4 && detail != 5 {
|
||||||
self.receiver.on_message(Message::CursorMotion(
|
self.receiver.on_message(Message::CursorMotion(
|
||||||
event.event_x() as i32,
|
event.event_x() as i32,
|
||||||
event.event_y() as i32,
|
event.event_y() as i32,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,20 +240,16 @@ impl<R: Receiver> Window<R> {
|
||||||
|
|
||||||
match detail {
|
match detail {
|
||||||
4 => {
|
4 => {
|
||||||
self.receiver.on_message(Message::MouseScroll(
|
self.receiver.on_message(Message::MouseScroll(MouseScroll {
|
||||||
MouseScroll {
|
x_delta: 0.0,
|
||||||
x_delta: 0.0,
|
y_delta: 1.0,
|
||||||
y_delta: 1.0,
|
}));
|
||||||
}
|
}
|
||||||
));
|
|
||||||
},
|
|
||||||
5 => {
|
5 => {
|
||||||
self.receiver.on_message(Message::MouseScroll(
|
self.receiver.on_message(Message::MouseScroll(MouseScroll {
|
||||||
MouseScroll {
|
x_delta: 0.0,
|
||||||
x_delta: 0.0,
|
y_delta: -1.0,
|
||||||
y_delta: -1.0,
|
}));
|
||||||
}
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
detail => {
|
detail => {
|
||||||
let button_id = mouse_id(detail);
|
let button_id = mouse_id(detail);
|
||||||
|
@ -380,4 +375,4 @@ fn mouse_id(id: u8) -> MouseButtonID {
|
||||||
7 => MouseButtonID::Forward,
|
7 => MouseButtonID::Forward,
|
||||||
id => MouseButtonID::Other(id),
|
id => MouseButtonID::Other(id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue