deps: update for new smithay version
This commit is contained in:
parent
1ab0196502
commit
25b44fde58
11 changed files with 230 additions and 237 deletions
|
|
@ -2,19 +2,22 @@
|
|||
|
||||
use crate::state::get_dnd_icon;
|
||||
use smithay::{
|
||||
backend::{
|
||||
renderer::{gles2, Frame, ImportAll, Renderer, Texture},
|
||||
SwapBuffersError,
|
||||
},
|
||||
desktop::space::{DynamicRenderElements, RenderElement, SpaceOutputTuple, SurfaceTree},
|
||||
backend::renderer::{Frame, ImportAll, ImportMem, Renderer, Texture},
|
||||
desktop::space::{RenderElement, SpaceOutputTuple, SurfaceTree},
|
||||
reexports::wayland_server::protocol::wl_surface,
|
||||
utils::{Buffer, Logical, Point, Rectangle, Size, Transform},
|
||||
utils::{Logical, Point, Rectangle, Size, Transform},
|
||||
wayland::{
|
||||
compositor::{get_role, with_states},
|
||||
seat::{CursorImageAttributes, CursorImageStatus, Seat},
|
||||
},
|
||||
};
|
||||
use std::{cell::RefCell, io::Read, rc::Rc, sync::Mutex};
|
||||
use std::{
|
||||
any::{Any, TypeId},
|
||||
cell::RefCell,
|
||||
collections::HashMap,
|
||||
io::Read,
|
||||
sync::Mutex,
|
||||
};
|
||||
use xcursor::{
|
||||
parser::{parse_xcursor, Image},
|
||||
CursorTheme,
|
||||
|
|
@ -115,15 +118,11 @@ fn load_icon(theme: &CursorTheme) -> Result<Vec<Image>, Error> {
|
|||
parse_xcursor(&cursor_data).ok_or(Error::Parse)
|
||||
}
|
||||
|
||||
pub fn draw_surface_cursor<R, F, E, T>(
|
||||
pub fn draw_surface_cursor(
|
||||
surface: wl_surface::WlSurface,
|
||||
location: impl Into<Point<i32, Logical>>,
|
||||
) -> impl RenderElement<R, F, E, T>
|
||||
) -> SurfaceTree
|
||||
where
|
||||
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportAll + 'static,
|
||||
F: Frame<Error = E, TextureId = T> + 'static,
|
||||
E: std::error::Error + Into<SwapBuffersError> + 'static,
|
||||
T: Texture + 'static,
|
||||
{
|
||||
let mut position = location.into();
|
||||
let ret = with_states(&surface, |states| {
|
||||
|
|
@ -150,16 +149,10 @@ where
|
|||
SurfaceTree { surface, position }
|
||||
}
|
||||
|
||||
pub fn draw_dnd_icon<R, F, E, T>(
|
||||
pub fn draw_dnd_icon(
|
||||
surface: wl_surface::WlSurface,
|
||||
location: impl Into<Point<i32, Logical>>,
|
||||
) -> impl RenderElement<R, F, E, T>
|
||||
where
|
||||
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportAll + 'static,
|
||||
F: Frame<Error = E, TextureId = T> + 'static,
|
||||
E: std::error::Error + Into<SwapBuffersError> + 'static,
|
||||
T: Texture + 'static,
|
||||
{
|
||||
) -> SurfaceTree {
|
||||
if get_role(&surface) != Some("dnd_icon") {
|
||||
slog_scope::warn!(
|
||||
"Trying to display as a dnd icon a surface that does not have the DndIcon role."
|
||||
|
|
@ -194,12 +187,10 @@ impl<T: Texture> PointerElement<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<R, F, E, T> RenderElement<R, F, E, T> for PointerElement<T>
|
||||
impl<R> RenderElement<R> for PointerElement<<R as Renderer>::TextureId>
|
||||
where
|
||||
R: Renderer<Error = E, TextureId = T, Frame = F> + ImportAll + 'static,
|
||||
F: Frame<Error = E, TextureId = T> + 'static,
|
||||
E: std::error::Error + Into<SwapBuffersError> + 'static,
|
||||
T: Texture + 'static,
|
||||
R: Renderer + ImportAll,
|
||||
<R as Renderer>::TextureId: 'static,
|
||||
{
|
||||
fn id(&self) -> usize {
|
||||
0
|
||||
|
|
@ -223,12 +214,12 @@ where
|
|||
fn draw(
|
||||
&self,
|
||||
_renderer: &mut R,
|
||||
frame: &mut F,
|
||||
frame: &mut <R as Renderer>::Frame,
|
||||
scale: f64,
|
||||
position: Point<i32, Logical>,
|
||||
damage: &[Rectangle<i32, Logical>],
|
||||
_log: &slog::Logger,
|
||||
) -> Result<(), R::Error> {
|
||||
) -> Result<(), <R as Renderer>::Error> {
|
||||
frame.render_texture_at(
|
||||
&self.texture,
|
||||
position.to_f64().to_physical(scale as f64).to_i32_round(),
|
||||
|
|
@ -245,26 +236,39 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct CursorState {
|
||||
cursor: Cursor,
|
||||
current_image: RefCell<Option<Image>>,
|
||||
image_cache: RefCell<HashMap<(TypeId, usize), Vec<(Image, Box<dyn Any + 'static>)>>>,
|
||||
}
|
||||
|
||||
pub type Textures = Vec<(Image, gles2::Gles2Texture)>;
|
||||
impl Default for CursorState {
|
||||
fn default() -> CursorState {
|
||||
CursorState {
|
||||
cursor: Cursor::default(),
|
||||
current_image: RefCell::new(None),
|
||||
image_cache: RefCell::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_cursor(
|
||||
renderer: &mut gles2::Gles2Renderer,
|
||||
pub fn draw_cursor<R, I>(
|
||||
renderer: &mut R,
|
||||
seat: &Seat,
|
||||
location: Point<i32, Logical>,
|
||||
start_time: &std::time::Instant,
|
||||
draw_default: bool,
|
||||
) -> Option<DynamicRenderElements<gles2::Gles2Renderer>> {
|
||||
) -> Option<I>
|
||||
where
|
||||
I: From<SurfaceTree> + From<PointerElement<<R as Renderer>::TextureId>>,
|
||||
R: Renderer + ImportAll + ImportMem,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
{
|
||||
// draw the dnd icon if applicable
|
||||
{
|
||||
if let Some(wl_surface) = get_dnd_icon(seat) {
|
||||
if wl_surface.as_ref().is_alive() {
|
||||
return Some(Box::new(draw_dnd_icon(wl_surface, location)));
|
||||
return Some(draw_dnd_icon(wl_surface, location).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -287,10 +291,7 @@ pub fn draw_cursor(
|
|||
.unwrap_or(CursorImageStatus::Default);
|
||||
|
||||
if let CursorImageStatus::Image(wl_surface) = cursor_status {
|
||||
Some(Box::new(draw_surface_cursor(
|
||||
wl_surface.clone(),
|
||||
location,
|
||||
)))
|
||||
Some(draw_surface_cursor(wl_surface.clone(), location).into())
|
||||
} else if draw_default {
|
||||
let seat_userdata = seat.user_data();
|
||||
seat_userdata.insert_if_missing(CursorState::default);
|
||||
|
|
@ -300,75 +301,35 @@ pub fn draw_cursor(
|
|||
.get_image(1, start_time.elapsed().as_millis() as u32);
|
||||
let new_frame = state.current_image.borrow().as_ref() != Some(&frame);
|
||||
|
||||
let egl_userdata = renderer.egl_context().user_data();
|
||||
egl_userdata.insert_if_missing(|| Rc::new(RefCell::new(Textures::new())));
|
||||
let pointer_images = egl_userdata.get::<Rc<RefCell<Textures>>>().unwrap().clone();
|
||||
let pointer_images_ref = &mut *pointer_images.borrow_mut();
|
||||
let pointer_image = pointer_images_ref
|
||||
let mut cache = state.image_cache.borrow_mut();
|
||||
let pointer_images = cache
|
||||
.entry((TypeId::of::<<R as Renderer>::TextureId>(), renderer.id()))
|
||||
.or_default();
|
||||
let pointer_image = pointer_images
|
||||
.iter()
|
||||
.find_map(|(image, texture)| if image == &frame { Some(texture) } else { None })
|
||||
.cloned()
|
||||
.and_then(|texture| {
|
||||
texture
|
||||
.downcast_ref::<<R as Renderer>::TextureId>()
|
||||
.cloned()
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
let texture = import_bitmap(
|
||||
renderer,
|
||||
&frame.pixels_rgba,
|
||||
gles2::ffi::RGBA,
|
||||
(frame.width as i32, frame.height as i32),
|
||||
)
|
||||
.expect("Failed to import cursor bitmap");
|
||||
pointer_images_ref.push((frame.clone(), texture.clone()));
|
||||
let texture = renderer
|
||||
.import_memory(
|
||||
&frame.pixels_rgba,
|
||||
(frame.width as i32, frame.height as i32).into(),
|
||||
false,
|
||||
)
|
||||
.expect("Failed to import cursor bitmap");
|
||||
pointer_images.push((frame.clone(), Box::new(texture.clone())));
|
||||
texture
|
||||
});
|
||||
let hotspot = Point::<i32, Logical>::from((frame.xhot as i32, frame.yhot as i32));
|
||||
*state.current_image.borrow_mut() = Some(frame);
|
||||
|
||||
Some(Box::new(PointerElement::new(
|
||||
pointer_image.clone(),
|
||||
location - hotspot,
|
||||
new_frame,
|
||||
)))
|
||||
Some(PointerElement::new(pointer_image.clone(), location - hotspot, new_frame).into())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn import_bitmap(
|
||||
renderer: &mut gles2::Gles2Renderer,
|
||||
image: impl std::convert::AsRef<[u8]>,
|
||||
format: gles2::ffi::types::GLenum,
|
||||
size: impl Into<Size<i32, Buffer>>,
|
||||
) -> Result<gles2::Gles2Texture, gles2::Gles2Error> {
|
||||
use smithay::backend::renderer::gles2::ffi;
|
||||
|
||||
let size = size.into();
|
||||
renderer.with_context(|renderer, gl| unsafe {
|
||||
let mut tex = 0;
|
||||
gl.GenTextures(1, &mut tex);
|
||||
gl.BindTexture(ffi::TEXTURE_2D, tex);
|
||||
gl.TexParameteri(
|
||||
ffi::TEXTURE_2D,
|
||||
ffi::TEXTURE_WRAP_S,
|
||||
ffi::CLAMP_TO_EDGE as i32,
|
||||
);
|
||||
gl.TexParameteri(
|
||||
ffi::TEXTURE_2D,
|
||||
ffi::TEXTURE_WRAP_T,
|
||||
ffi::CLAMP_TO_EDGE as i32,
|
||||
);
|
||||
gl.TexImage2D(
|
||||
ffi::TEXTURE_2D,
|
||||
0,
|
||||
format as i32,
|
||||
size.w,
|
||||
size.h,
|
||||
0,
|
||||
format,
|
||||
ffi::UNSIGNED_BYTE as u32,
|
||||
image.as_ref().as_ptr() as *const _,
|
||||
);
|
||||
gl.BindTexture(ffi::TEXTURE_2D, 0);
|
||||
|
||||
gles2::Gles2Texture::from_raw(renderer, tex, size)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,52 +3,80 @@
|
|||
use crate::state::Common;
|
||||
#[cfg(feature = "debug")]
|
||||
use crate::{
|
||||
debug::{debug_ui, fps_ui, log_ui},
|
||||
debug::{debug_ui, fps_ui, log_ui, EguiFrame},
|
||||
state::Fps,
|
||||
};
|
||||
|
||||
use slog::Logger;
|
||||
use smithay::{
|
||||
backend::renderer::gles2::Gles2Renderer,
|
||||
desktop::space::{DynamicRenderElements, RenderError},
|
||||
utils::{Logical, Rectangle},
|
||||
backend::renderer::{
|
||||
gles2::{Gles2Renderbuffer, Gles2Renderer, Gles2Texture},
|
||||
ImportAll, Renderer,
|
||||
},
|
||||
desktop::space::{RenderElement, RenderError, SpaceOutputTuple, SurfaceTree},
|
||||
utils::{Logical, Point, Rectangle},
|
||||
wayland::output::Output,
|
||||
};
|
||||
|
||||
mod cursor;
|
||||
use self::cursor::PointerElement;
|
||||
|
||||
pub fn render_output(
|
||||
renderer: &mut Gles2Renderer,
|
||||
smithay::custom_elements! {
|
||||
pub CustomElem<=Gles2Renderer>;
|
||||
SurfaceTree=SurfaceTree,
|
||||
PointerElement=PointerElement::<Gles2Texture>,
|
||||
#[cfg(feature = "debug")]
|
||||
EguiFrame=EguiFrame,
|
||||
}
|
||||
|
||||
pub trait AsGles2Renderer {
|
||||
fn as_gles2(&mut self) -> &mut Gles2Renderer;
|
||||
}
|
||||
impl AsGles2Renderer for Gles2Renderer {
|
||||
fn as_gles2(&mut self) -> &mut Gles2Renderer {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_output<R>(
|
||||
renderer: &mut R,
|
||||
age: u8,
|
||||
state: &mut Common,
|
||||
output: &Output,
|
||||
hardware_cursor: bool,
|
||||
#[cfg(feature = "debug")] fps: &mut Fps,
|
||||
) -> Result<Option<Vec<Rectangle<i32, Logical>>>, RenderError<Gles2Renderer>> {
|
||||
) -> Result<Option<Vec<Rectangle<i32, Logical>>>, RenderError<R>>
|
||||
where
|
||||
R: Renderer + ImportAll + AsGles2Renderer,
|
||||
<R as Renderer>::TextureId: Clone + 'static,
|
||||
CustomElem: RenderElement<R>,
|
||||
{
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
fps.start();
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut custom_elements = Vec::<DynamicRenderElements<Gles2Renderer>>::new();
|
||||
let mut custom_elements = Vec::<CustomElem>::new();
|
||||
|
||||
#[cfg(feature = "debug")]
|
||||
{
|
||||
let space = state.spaces.active_space(output);
|
||||
let output_geo = space.output_geometry(output)
|
||||
let output_geo = space
|
||||
.output_geometry(output)
|
||||
.unwrap_or(Rectangle::from_loc_and_size((0, 0), (0, 0)));
|
||||
let scale = space.output_scale(output).unwrap();
|
||||
|
||||
let fps_overlay = fps_ui(state, fps, output_geo, scale);
|
||||
custom_elements.push(Box::new(fps_overlay));
|
||||
custom_elements.push(fps_overlay.into());
|
||||
|
||||
let mut area = state.spaces.global_space();
|
||||
area.loc = state.spaces.space_relative_output_geometry((0, 0), output);
|
||||
if let Some(log_ui) = log_ui(state, area, scale, output_geo.size.w as f32 * 0.6) {
|
||||
custom_elements.push(Box::new(log_ui));
|
||||
custom_elements.push(log_ui.into());
|
||||
}
|
||||
if let Some(debug_overlay) = debug_ui(state, area, scale) {
|
||||
custom_elements.push(Box::new(debug_overlay));
|
||||
custom_elements.push(debug_overlay.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,11 +85,17 @@ pub fn render_output(
|
|||
Some(ptr) => ptr,
|
||||
None => continue,
|
||||
};
|
||||
let location = state.spaces.space_relative_output_geometry(pointer.current_location().to_i32_round(), output);
|
||||
let location = state
|
||||
.spaces
|
||||
.space_relative_output_geometry(pointer.current_location().to_i32_round(), output);
|
||||
|
||||
if let Some(cursor) =
|
||||
cursor::draw_cursor(renderer, seat, location, &state.start_time, !hardware_cursor)
|
||||
{
|
||||
if let Some(cursor) = cursor::draw_cursor(
|
||||
renderer.as_gles2(),
|
||||
seat,
|
||||
location,
|
||||
&state.start_time,
|
||||
!hardware_cursor,
|
||||
) {
|
||||
custom_elements.push(cursor)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ fn init_egl_client_side(
|
|||
renderer
|
||||
.borrow_mut()
|
||||
.renderer()
|
||||
.import_dmabuf(buffer)
|
||||
.import_dmabuf(buffer, None)
|
||||
.is_ok()
|
||||
},
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ use anyhow::{Context, Result};
|
|||
use smithay::{
|
||||
backend::{
|
||||
allocator::dmabuf::Dmabuf,
|
||||
drm::DrmNode,
|
||||
egl::{EGLContext, EGLDisplay},
|
||||
input::{Event, InputEvent},
|
||||
renderer::{gles2::Gles2Renderer, Bind, ImportDma, ImportEgl},
|
||||
|
|
@ -19,7 +18,7 @@ use smithay::{
|
|||
desktop::layer_map_for_output,
|
||||
reexports::{
|
||||
calloop::{ping, EventLoop, LoopHandle},
|
||||
gbm::Device as GbmDevice,
|
||||
gbm::{Device as GbmDevice, FdWrapper},
|
||||
wayland_server::{
|
||||
protocol::wl_output::{Subpixel, WlOutput},
|
||||
Display,
|
||||
|
|
@ -40,7 +39,7 @@ use std::{
|
|||
use crate::state::Fps;
|
||||
|
||||
pub struct X11State {
|
||||
allocator: Arc<Mutex<GbmDevice<DrmNode>>>,
|
||||
allocator: Arc<Mutex<GbmDevice<FdWrapper>>>,
|
||||
_egl: EGLDisplay,
|
||||
renderer: Rc<RefCell<Gles2Renderer>>,
|
||||
surfaces: Vec<Surface>,
|
||||
|
|
@ -196,12 +195,13 @@ pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Res
|
|||
let handle = backend.handle();
|
||||
|
||||
// Obtain the DRM node the X server uses for direct rendering.
|
||||
let drm_node = handle
|
||||
let (_drm_node, fd) = handle
|
||||
.drm_node()
|
||||
.with_context(|| "Could not get DRM node used by X server")?;
|
||||
|
||||
// Create the gbm device for buffer allocation.
|
||||
let device = GbmDevice::new(drm_node).with_context(|| "Failed to create GBM device")?;
|
||||
let device =
|
||||
unsafe { GbmDevice::new_from_fd(fd) }.with_context(|| "Failed to create GBM device")?;
|
||||
// Initialize EGL using the GBM device.
|
||||
let egl = EGLDisplay::new(&device, None).with_context(|| "Failed to create EGL display")?;
|
||||
// Create the OpenGL context
|
||||
|
|
@ -276,7 +276,7 @@ pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Res
|
|||
surface.render.ping();
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
X11Event::Refresh { window_id } | X11Event::PresentCompleted { window_id } => {
|
||||
if let Some(surface) = state
|
||||
.backend
|
||||
|
|
@ -291,7 +291,7 @@ pub fn init_backend(event_loop: &mut EventLoop<State>, state: &mut State) -> Res
|
|||
surface.pending = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
X11Event::Input(event) => state.process_x11_event(event),
|
||||
})
|
||||
.map_err(|_| anyhow::anyhow!("Failed to insert X11 Backend into event loop"))?;
|
||||
|
|
@ -312,7 +312,7 @@ fn init_egl_client_side(display: &mut Display, renderer: Rc<RefCell<Gles2Rendere
|
|||
init_dmabuf_global(
|
||||
display,
|
||||
dmabuf_formats,
|
||||
move |buffer, _| renderer.borrow_mut().import_dmabuf(buffer).is_ok(),
|
||||
move |buffer, _| renderer.borrow_mut().import_dmabuf(buffer, None).is_ok(),
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
15
src/debug.rs
15
src/debug.rs
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::state::{Common, Fps};
|
||||
use smithay::utils::{Logical, Rectangle};
|
||||
use smithay_egui::EguiFrame;
|
||||
pub use smithay_egui::EguiFrame;
|
||||
|
||||
pub fn fps_ui(
|
||||
state: &Common,
|
||||
|
|
@ -167,10 +167,13 @@ pub fn debug_ui(
|
|||
ui.collapsing(format!("Windows"), |ui| {
|
||||
for window in space.windows() {
|
||||
ui.collapsing(format!("{:?}", window.toplevel()), |ui| {
|
||||
ui.label(format!(
|
||||
"Rect: {:?}",
|
||||
space.window_geometry(window)
|
||||
));
|
||||
ui.label(format!("Rect: {:?}", {
|
||||
let mut geo = window.geometry();
|
||||
geo.loc += space
|
||||
.window_location(window)
|
||||
.unwrap_or((0, 0).into());
|
||||
geo
|
||||
}));
|
||||
ui.label(format!(
|
||||
"Bounding box: {:?}",
|
||||
space.window_bbox(window)
|
||||
|
|
@ -246,8 +249,6 @@ pub fn log_ui(
|
|||
stroke: egui::Stroke::none(),
|
||||
})
|
||||
.default_width(default_width)
|
||||
.default_width(default_width)
|
||||
.default_width(default_width)
|
||||
.show(ctx, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.always_show_scroll(true)
|
||||
|
|
|
|||
|
|
@ -458,8 +458,7 @@ impl Common {
|
|||
.map(|(s, _)| s);
|
||||
}
|
||||
} else if let Some(window) = space.window_under(pos).cloned() {
|
||||
let window_loc =
|
||||
space.window_geometry(&window).unwrap().loc;
|
||||
let window_loc = space.window_location(&window).unwrap();
|
||||
under = window
|
||||
.surface_under(
|
||||
pos - window_loc.to_f64(),
|
||||
|
|
@ -614,7 +613,7 @@ impl Common {
|
|||
)
|
||||
.map(|(s, loc)| (s, loc + layer_loc))
|
||||
} else if let Some(window) = space.window_under(pos) {
|
||||
let window_loc = space.window_geometry(window).unwrap().loc;
|
||||
let window_loc = space.window_location(window).unwrap();
|
||||
window
|
||||
.surface_under(pos - window_loc.to_f64(), WindowSurfaceType::ALL)
|
||||
.map(|(s, loc)| (s, loc + window_loc))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use smithay::{
|
|||
wayland_protocols::xdg_shell::server::xdg_toplevel,
|
||||
wayland_server::protocol::{wl_pointer::ButtonState, wl_surface},
|
||||
},
|
||||
utils::{Logical, Point, Rectangle, Size},
|
||||
utils::{Logical, Point, Size},
|
||||
wayland::{
|
||||
compositor::with_states,
|
||||
seat::{AxisFrame, PointerGrab, PointerGrabStartData, PointerInnerHandle},
|
||||
|
|
@ -306,10 +306,9 @@ impl ResizeSurfaceGrab {
|
|||
start_data: PointerGrabStartData,
|
||||
window: Window,
|
||||
edges: xdg_toplevel::ResizeEdge,
|
||||
initial_window_geometry: Rectangle<i32, Logical>,
|
||||
initial_window_location: Point<i32, Logical>,
|
||||
initial_window_size: Size<i32, Logical>,
|
||||
) -> ResizeSurfaceGrab {
|
||||
let (initial_window_location, initial_window_size) =
|
||||
(initial_window_geometry.loc, initial_window_geometry.size);
|
||||
let resize_state = ResizeState::Resizing(ResizeData {
|
||||
edges: edges.into(),
|
||||
initial_window_location,
|
||||
|
|
@ -393,7 +392,8 @@ impl ResizeSurfaceGrab {
|
|||
|
||||
pub fn apply_resize_state(
|
||||
window: &Window,
|
||||
geometry: Rectangle<i32, Logical>,
|
||||
mut location: Point<i32, Logical>,
|
||||
size: Size<i32, Logical>,
|
||||
) -> Option<Point<i32, Logical>> {
|
||||
let mut new_location = None;
|
||||
|
||||
|
|
@ -413,15 +413,13 @@ impl ResizeSurfaceGrab {
|
|||
} = resize_data;
|
||||
|
||||
if edges.intersects(ResizeEdge::TOP_LEFT) {
|
||||
let mut location = geometry.loc;
|
||||
|
||||
if edges.intersects(ResizeEdge::LEFT) {
|
||||
location.x = initial_window_location.x
|
||||
+ (initial_window_size.w - geometry.size.w);
|
||||
location.x =
|
||||
initial_window_location.x + (initial_window_size.w - size.w);
|
||||
}
|
||||
if edges.intersects(ResizeEdge::TOP) {
|
||||
location.y = initial_window_location.y
|
||||
+ (initial_window_size.h - geometry.size.h);
|
||||
location.y =
|
||||
initial_window_location.y + (initial_window_size.h - size.h);
|
||||
}
|
||||
|
||||
new_location = Some(location);
|
||||
|
|
|
|||
|
|
@ -110,8 +110,7 @@ pub fn init_shell(display: &mut Display) -> ShellStates {
|
|||
.window_for_surface(surface.get_surface().unwrap())
|
||||
.unwrap()
|
||||
.clone();
|
||||
let mut initial_window_location =
|
||||
space.window_geometry(&window).unwrap().loc;
|
||||
let mut initial_window_location = space.window_location(&window).unwrap();
|
||||
|
||||
// If surface is maximized then unmaximize it
|
||||
if let Some(current_state) = surface.current_state() {
|
||||
|
|
@ -172,10 +171,12 @@ pub fn init_shell(display: &mut Display) -> ShellStates {
|
|||
.window_for_surface(surface.get_surface().unwrap())
|
||||
.unwrap()
|
||||
.clone();
|
||||
let geometry = space.window_geometry(&window).unwrap();
|
||||
let location = space.window_location(&window).unwrap();
|
||||
let size = window.geometry().size;
|
||||
|
||||
let grab =
|
||||
grabs::ResizeSurfaceGrab::new(start_data, window, edges, geometry);
|
||||
let grab = grabs::ResizeSurfaceGrab::new(
|
||||
start_data, window, edges, location, size,
|
||||
);
|
||||
|
||||
pointer.set_grab(grab, serial, 0);
|
||||
}
|
||||
|
|
@ -415,7 +416,8 @@ fn commit(surface: &WlSurface, state: &mut State) {
|
|||
{
|
||||
let new_location = grabs::ResizeSurfaceGrab::apply_resize_state(
|
||||
&window,
|
||||
space.window_geometry(&window).unwrap(),
|
||||
space.window_location(&window).unwrap(),
|
||||
window.geometry().size,
|
||||
);
|
||||
if let Some(location) = new_location {
|
||||
space.map_window(&window, location, true);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::{
|
|||
shell::{init_shell, workspaces::Workspaces, ShellStates},
|
||||
};
|
||||
use smithay::{
|
||||
backend::drm::DrmNode,
|
||||
reexports::{
|
||||
calloop::LoopHandle,
|
||||
wayland_server::{protocol::wl_surface::WlSurface, Display},
|
||||
|
|
@ -38,6 +39,7 @@ pub struct Common {
|
|||
pub display: Rc<RefCell<Display>>,
|
||||
pub socket: OsString,
|
||||
pub event_loop_handle: LoopHandle<'static, State>,
|
||||
pub primary_gpu: Option<DrmNode>,
|
||||
|
||||
pub spaces: Workspaces,
|
||||
pub shell: ShellStates,
|
||||
|
|
@ -166,11 +168,16 @@ impl State {
|
|||
#[cfg(feature = "debug")]
|
||||
let dirty_flag = log.dirty_flag.clone();
|
||||
|
||||
let primary_gpu = std::env::var("COSMIC_RENDER_DEVICE")
|
||||
.ok()
|
||||
.and_then(|device| DrmNode::from_path(device).ok());
|
||||
|
||||
State {
|
||||
common: Common {
|
||||
display: Rc::new(RefCell::new(display)),
|
||||
socket,
|
||||
event_loop_handle: handle,
|
||||
primary_gpu,
|
||||
|
||||
spaces: Workspaces::new(),
|
||||
shell: shell_handles,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue