From 850ff6983a933c8f6bfa732988a035e5919d8371 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 2 Oct 2018 23:37:24 +0200 Subject: [PATCH] anvil: Use nested imports --- anvil/src/glium_drawer.rs | 42 +++++++++++--------- anvil/src/input_handler.rs | 28 ++++++++------ anvil/src/main.rs | 3 +- anvil/src/raw_drm.rs | 58 ++++++++++++++++------------ anvil/src/shell.rs | 34 +++++++++++------ anvil/src/shm_load.rs | 3 +- anvil/src/udev.rs | 78 ++++++++++++++++++++++---------------- anvil/src/window_map.rs | 18 +++++---- anvil/src/winit.rs | 32 +++++++++------- 9 files changed, 175 insertions(+), 121 deletions(-) diff --git a/anvil/src/glium_drawer.rs b/anvil/src/glium_drawer.rs index 0520843..135ed5f 100644 --- a/anvil/src/glium_drawer.rs +++ b/anvil/src/glium_drawer.rs @@ -1,24 +1,32 @@ -use glium; -use glium::index::PrimitiveType; -use glium::texture::{MipmapsOption, Texture2d, UncompressedFloatFormat}; -use glium::{Frame, GlObject, Surface}; -use smithay::backend::graphics::egl::error::Result as EGLResult; -use smithay::backend::graphics::egl::wayland::{ - BufferAccessError, EGLDisplay, EGLImages, EGLWaylandExtensions, Format, +use std::{ + cell::{Ref, RefCell}, + rc::Rc, }; -use smithay::backend::graphics::egl::EGLGraphicsBackend; -use smithay::backend::graphics::glium::GliumGraphicsBackend; -use smithay::wayland::compositor::roles::Role; -use smithay::wayland::compositor::{SubsurfaceRole, TraversalAction}; -use smithay::wayland::shm::with_buffer_contents as shm_buffer_contents; -use smithay::wayland_server::protocol::wl_buffer; -use smithay::wayland_server::{Display, Resource}; - -use std::cell::{Ref, RefCell}; -use std::rc::Rc; +use glium::{ + self, + index::PrimitiveType, + texture::{MipmapsOption, Texture2d, UncompressedFloatFormat}, + Frame, GlObject, Surface, +}; use slog::Logger; +use smithay::{ + backend::graphics::{ + egl::{ + error::Result as EGLResult, + wayland::{BufferAccessError, EGLDisplay, EGLImages, EGLWaylandExtensions, Format}, + EGLGraphicsBackend, + }, + glium::GliumGraphicsBackend, + }, + wayland::{ + compositor::{roles::Role, SubsurfaceRole, TraversalAction}, + shm::with_buffer_contents as shm_buffer_contents, + }, + wayland_server::{protocol::wl_buffer, Display, Resource}, +}; + use shaders; use shell::{MyCompositorToken, MyWindowMap}; diff --git a/anvil/src/input_handler.rs b/anvil/src/input_handler.rs index 1d91554..217c5c6 100644 --- a/anvil/src/input_handler.rs +++ b/anvil/src/input_handler.rs @@ -1,19 +1,25 @@ -use std::cell::RefCell; -use std::process::Command; -use std::rc::Rc; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; +use std::{ + cell::RefCell, + process::Command, + rc::Rc, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, +}; use slog::Logger; -use smithay::backend::input::{ - self, Event, InputBackend, InputHandler, KeyState, KeyboardKeyEvent, PointerAxisEvent, - PointerButtonEvent, PointerMotionAbsoluteEvent, PointerMotionEvent, -}; #[cfg(feature = "udev")] use smithay::backend::session::auto::AutoSession; -use smithay::wayland::seat::{keysyms as xkb, KeyboardHandle, Keysym, ModifiersState, PointerHandle}; -use smithay::wayland_server::protocol::wl_pointer; +use smithay::{ + backend::input::{ + self, Event, InputBackend, InputHandler, KeyState, KeyboardKeyEvent, PointerAxisEvent, + PointerButtonEvent, PointerMotionAbsoluteEvent, PointerMotionEvent, + }, + wayland::seat::{keysyms as xkb, KeyboardHandle, Keysym, ModifiersState, PointerHandle}, + wayland_server::protocol::wl_pointer, +}; use shell::MyWindowMap; diff --git a/anvil/src/main.rs b/anvil/src/main.rs index 2727f11..ce4523e 100644 --- a/anvil/src/main.rs +++ b/anvil/src/main.rs @@ -10,8 +10,7 @@ extern crate smithay; extern crate xkbcommon; use slog::Drain; -use smithay::wayland_server::calloop::EventLoop; -use smithay::wayland_server::Display; +use smithay::wayland_server::{calloop::EventLoop, Display}; #[macro_use] mod shaders; diff --git a/anvil/src/raw_drm.rs b/anvil/src/raw_drm.rs index d47ebf5..8e6c01e 100644 --- a/anvil/src/raw_drm.rs +++ b/anvil/src/raw_drm.rs @@ -1,22 +1,29 @@ -use std::cell::RefCell; -use std::fs::{File, OpenOptions}; -use std::os::unix::io::AsRawFd; -use std::os::unix::io::RawFd; -use std::rc::Rc; -use std::time::Duration; +use std::{ + cell::RefCell, + fs::{File, OpenOptions}, + os::unix::io::{AsRawFd, RawFd}, + rc::Rc, + time::Duration, +}; -use smithay::backend::drm::{drm_device_bind, DrmBackend, DrmDevice, DrmHandler}; -use smithay::backend::graphics::egl::wayland::EGLWaylandExtensions; -use smithay::drm::control::connector::{Info as ConnectorInfo, State as ConnectorState}; -use smithay::drm::control::crtc; -use smithay::drm::control::encoder::Info as EncoderInfo; -use smithay::drm::control::{Device as ControlDevice, ResourceInfo}; -use smithay::drm::result::Error as DrmError; -use smithay::drm::Device as BasicDevice; -use smithay::wayland::compositor::CompositorToken; -use smithay::wayland::shm::init_shm_global; -use smithay::wayland_server::calloop::EventLoop; -use smithay::wayland_server::Display; +use smithay::{ + backend::{ + drm::{drm_device_bind, DrmBackend, DrmDevice, DrmHandler}, + graphics::egl::wayland::EGLWaylandExtensions, + }, + drm::{ + control::{ + connector::{Info as ConnectorInfo, State as ConnectorState}, + crtc, + encoder::Info as EncoderInfo, + Device as ControlDevice, ResourceInfo, + }, + result::Error as DrmError, + Device as BasicDevice, + }, + wayland::{compositor::CompositorToken, shm::init_shm_global}, + wayland_server::{calloop::EventLoop, Display}, +}; use glium::Surface; use slog::Logger; @@ -62,13 +69,16 @@ pub fn run_raw_drm(mut display: Display, mut event_loop: EventLoop<()>, log: Log let encoder_info = EncoderInfo::load_from_device(&device, connector_info.encoders()[0]).unwrap(); // use the connected crtc if any - let crtc = encoder_info.current_crtc() + let crtc = encoder_info + .current_crtc() // or use the first one that is compatible with the encoder - .unwrap_or_else(|| - *res_handles.filter_crtcs(encoder_info.possible_crtcs()) - .iter() - .next() - .unwrap()); + .unwrap_or_else(|| { + *res_handles + .filter_crtcs(encoder_info.possible_crtcs()) + .iter() + .next() + .unwrap() + }); // Assuming we found a good connector and loaded the info into `connector_info` let mode = connector_info.modes()[0]; // Use first mode (usually highest resoltion, but in reality you should filter and sort and check and match with other connectors, if you use more then one.) diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 33a3686..dd68aa1 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -1,19 +1,29 @@ -use std::cell::RefCell; -use std::rc::Rc; -use std::sync::{Arc, Mutex}; +use std::{ + cell::RefCell, + rc::Rc, + sync::{Arc, Mutex}, +}; use rand; -use smithay::wayland::compositor::{compositor_init, CompositorToken, SurfaceAttributes, SurfaceEvent}; -use smithay::wayland::shell::legacy::{ - wl_shell_init, ShellRequest, ShellState as WlShellState, ShellSurfaceKind, ShellSurfaceRole, +use smithay::{ + wayland::{ + compositor::{compositor_init, CompositorToken, SurfaceAttributes, SurfaceEvent}, + shell::{ + legacy::{ + wl_shell_init, ShellRequest, ShellState as WlShellState, ShellSurfaceKind, ShellSurfaceRole, + }, + xdg::{ + xdg_shell_init, PopupConfigure, ShellState as XdgShellState, ToplevelConfigure, XdgRequest, + XdgSurfaceRole, + }, + }, + }, + wayland_server::{ + protocol::{wl_buffer, wl_callback, wl_shell_surface, wl_surface}, + Display, Resource, + }, }; -use smithay::wayland::shell::xdg::{ - xdg_shell_init, PopupConfigure, ShellState as XdgShellState, ToplevelConfigure, XdgRequest, - XdgSurfaceRole, -}; -use smithay::wayland_server::protocol::{wl_buffer, wl_callback, wl_shell_surface, wl_surface}; -use smithay::wayland_server::{Display, Resource}; use window_map::{Kind as SurfaceKind, WindowMap}; diff --git a/anvil/src/shm_load.rs b/anvil/src/shm_load.rs index 76b3ac8..ceaa2c6 100644 --- a/anvil/src/shm_load.rs +++ b/anvil/src/shm_load.rs @@ -1,7 +1,6 @@ use std::borrow::Cow; -use smithay::wayland::shm::BufferData; -use smithay::wayland_server::protocol::wl_shm::Format; +use smithay::{wayland::shm::BufferData, wayland_server::protocol::wl_shm::Format}; use glium::texture::{ClientFormat, RawImage2d}; diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 430fb4d..97695ce 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -1,39 +1,53 @@ -use std::cell::RefCell; -use std::collections::HashMap; -use std::io::Error as IoError; -use std::path::PathBuf; -use std::rc::Rc; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; -use std::time::Duration; +use std::{ + cell::RefCell, + collections::HashMap, + io::Error as IoError, + path::PathBuf, + rc::Rc, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, + time::Duration, +}; use glium::Surface; - -use smithay::image::{ImageBuffer, Rgba}; - use slog::Logger; -use smithay::backend::drm::{DevPath, DrmBackend, DrmDevice, DrmHandler}; -use smithay::backend::graphics::egl::wayland::{EGLDisplay, EGLWaylandExtensions}; -use smithay::backend::graphics::GraphicsBackend; -use smithay::backend::input::InputBackend; -use smithay::backend::libinput::{libinput_bind, LibinputInputBackend, LibinputSessionInterface}; -use smithay::backend::session::auto::{auto_session_bind, AutoSession}; -use smithay::backend::session::{Session, SessionNotifier}; -use smithay::backend::udev::{primary_gpu, udev_backend_bind, SessionFdDrmDevice, UdevBackend, UdevHandler}; -use smithay::drm::control::connector::{Info as ConnectorInfo, State as ConnectorState}; -use smithay::drm::control::crtc; -use smithay::drm::control::encoder::Info as EncoderInfo; -use smithay::drm::control::{Device as ControlDevice, ResourceInfo}; -use smithay::drm::result::Error as DrmError; -use smithay::input::Libinput; -use smithay::wayland::compositor::CompositorToken; -use smithay::wayland::output::{Mode, Output, PhysicalProperties}; -use smithay::wayland::seat::{Seat, XkbConfig}; -use smithay::wayland::shm::init_shm_global; -use smithay::wayland_server::calloop::EventLoop; -use smithay::wayland_server::protocol::wl_output; -use smithay::wayland_server::Display; +use smithay::{ + backend::{ + drm::{DevPath, DrmBackend, DrmDevice, DrmHandler}, + graphics::{ + egl::wayland::{EGLDisplay, EGLWaylandExtensions}, + GraphicsBackend, + }, + input::InputBackend, + libinput::{libinput_bind, LibinputInputBackend, LibinputSessionInterface}, + session::{ + auto::{auto_session_bind, AutoSession}, + Session, SessionNotifier, + }, + udev::{primary_gpu, udev_backend_bind, SessionFdDrmDevice, UdevBackend, UdevHandler}, + }, + drm::{ + control::{ + connector::{Info as ConnectorInfo, State as ConnectorState}, + crtc, + encoder::Info as EncoderInfo, + Device as ControlDevice, ResourceInfo, + }, + result::Error as DrmError, + }, + image::{ImageBuffer, Rgba}, + input::Libinput, + wayland::{ + compositor::CompositorToken, + output::{Mode, Output, PhysicalProperties}, + seat::{Seat, XkbConfig}, + shm::init_shm_global, + }, + wayland_server::{calloop::EventLoop, protocol::wl_output, Display}, +}; use glium_drawer::GliumDrawer; use input_handler::AnvilInputHandler; diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index 962d41a..2290837 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -1,10 +1,14 @@ -use smithay::utils::Rectangle; -use smithay::wayland::compositor::roles::Role; -use smithay::wayland::compositor::{CompositorToken, SubsurfaceRole, SurfaceAttributes, TraversalAction}; -use smithay::wayland::shell::legacy::{ShellSurface, ShellSurfaceRole}; -use smithay::wayland::shell::xdg::{ToplevelSurface, XdgSurfaceRole}; -use smithay::wayland_server::protocol::wl_surface; -use smithay::wayland_server::Resource; +use smithay::{ + utils::Rectangle, + wayland::{ + compositor::{roles::Role, CompositorToken, SubsurfaceRole, SurfaceAttributes, TraversalAction}, + shell::{ + legacy::{ShellSurface, ShellSurfaceRole}, + xdg::{ToplevelSurface, XdgSurfaceRole}, + }, + }, + wayland_server::{protocol::wl_surface, Resource}, +}; pub enum Kind { Xdg(ToplevelSurface), diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index 3b2fb68..29566bb 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -1,18 +1,22 @@ -use std::cell::RefCell; -use std::rc::Rc; -use std::sync::atomic::AtomicBool; -use std::sync::Arc; +use std::{ + cell::RefCell, + rc::Rc, + sync::{atomic::AtomicBool, Arc}, +}; -use smithay::backend::graphics::egl::wayland::EGLWaylandExtensions; -use smithay::backend::graphics::egl::EGLGraphicsBackend; -use smithay::backend::input::InputBackend; -use smithay::backend::winit; -use smithay::wayland::output::{Mode, Output, PhysicalProperties}; -use smithay::wayland::seat::{Seat, XkbConfig}; -use smithay::wayland::shm::init_shm_global; -use smithay::wayland_server::calloop::EventLoop; -use smithay::wayland_server::protocol::wl_output; -use smithay::wayland_server::Display; +use smithay::{ + backend::{ + graphics::egl::{wayland::EGLWaylandExtensions, EGLGraphicsBackend}, + input::InputBackend, + winit, + }, + wayland::{ + output::{Mode, Output, PhysicalProperties}, + seat::{Seat, XkbConfig}, + shm::init_shm_global, + }, + wayland_server::{calloop::EventLoop, protocol::wl_output, Display}, +}; use slog::Logger;