diff --git a/examples/simple.rs b/examples/simple.rs index 5dbb5c2..21cb568 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -101,7 +101,7 @@ fn get_topmost_view(output: WlcOutput, offset: usize) -> Option { } fn render_output(output: WlcOutput) { - let resolution = output.get_resolution().unwrap(); + let resolution = output.get_virtual_resolution().unwrap(); let views = output.get_views(); if views.is_empty() { return; } @@ -180,6 +180,15 @@ extern fn on_keyboard_key(view: WlcView, _time: u32, mods: &KeyboardModifiers, k .unwrap_or_else(|e| { println!("Error spawning child: {}", e); panic!("spawning child")}); return true; + } else if sym.raw() >= keysyms::KEY_1.raw() && sym.raw() <= keysyms::KEY_9.raw() { + let outputs = WlcOutput::list(); + let scale = (sym.raw() - keysyms::KEY_1.raw()) + 1; + for output in outputs { + output.set_resolution(output.get_resolution() + .expect("No resolution"), scale); + } + println!("scale: {}", scale); + return true; } } } diff --git a/src/handle.rs b/src/handle.rs index f8004d5..309ae61 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -6,10 +6,7 @@ //! - **Clone**: View handles can safely be cloned. extern crate libc; -use libc::{uintptr_t, c_char, c_void}; - -#[cfg(feature="wlc-wayland")] -use libc::uint32_t; +use libc::{uintptr_t, c_char, c_void, uint32_t}; #[cfg(feature="wlc-wayland")] use wayland_sys::server::{wl_resource, wl_client}; @@ -56,7 +53,11 @@ extern "C" { fn wlc_output_get_resolution(output: uintptr_t) -> *const Size; - fn wlc_output_set_resolution(output: uintptr_t, resolution: *const Size); + fn wlc_output_set_resolution(output: uintptr_t, resolution: *const Size, scale: uint32_t); + + fn wlc_output_get_scale(output: uintptr_t) -> uint32_t; + + fn wlc_output_get_virtual_resolution(output: uintptr_t) -> *const Size; fn wlc_output_get_mask(output: uintptr_t) -> u32; @@ -306,17 +307,28 @@ impl WlcOutput { unsafe { wlc_output_set_sleep(self.0, sleep); } } - /// Gets the output resolution in pixels. + /// Gets the output's real resolution. Do not use for coordinate boundary. pub fn get_resolution(self) -> Option { unsafe { wlc_output_get_resolution(self.0).as_ref().map(|&x| x) } } + /// Get the virtual resolution. Helpful for getting resolution on high dpi displays. + /// Use this to calculate coordinate boundary. + pub fn get_virtual_resolution(self) -> Option { + unsafe { wlc_output_get_virtual_resolution(self.0).as_ref().map(|&x| x) } + } + /// Sets the resolution of the output. /// /// # Safety /// This method will crash the program if use when wlc is not running. - pub fn set_resolution(self, size: Size) { - unsafe { wlc_output_set_resolution(self.0, &size); } + pub fn set_resolution(self, size: Size, scaling: u32) { + unsafe { wlc_output_set_resolution(self.0, &size, scaling); } + } + + /// Get the scaling for the output. + pub fn get_scale(self) -> u32 { + unsafe { wlc_output_get_scale(self.0) as u32} } /// Get views in stack order. diff --git a/src/xkb/mod.rs b/src/xkb/mod.rs index ec855e0..4f9b084 100644 --- a/src/xkb/mod.rs +++ b/src/xkb/mod.rs @@ -128,6 +128,13 @@ use std::mem; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct Keysym(u32); +impl Keysym { + /// Get the raw value of the keysym + pub fn raw(self) -> u32 { + self.0 + } +} + /// Represents flags used for `Keysym::from_name` #[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]