From dc8b9869ff64d4845ad5fcbbaa4581aa33d674a3 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sun, 14 Aug 2016 18:53:50 -0400 Subject: [PATCH 1/4] Fixed wlc_output_get_resolution to take in scaling --- src/handle.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/handle.rs b/src/handle.rs index f8004d5..ecc6656 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,7 @@ 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_mask(output: uintptr_t) -> u32; @@ -315,8 +312,8 @@ impl WlcOutput { /// /// # 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 views in stack order. From 51d0018cc86847c677887c8ae0b924520defd3e6 Mon Sep 17 00:00:00 2001 From: Timidger Date: Sun, 14 Aug 2016 18:55:24 -0400 Subject: [PATCH 2/4] Added wlc_output_get_scale --- src/handle.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/handle.rs b/src/handle.rs index ecc6656..f97798a 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -55,6 +55,8 @@ extern "C" { 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_mask(output: uintptr_t) -> u32; fn wlc_output_set_mask(output: uintptr_t, mask: u32); @@ -316,6 +318,11 @@ impl WlcOutput { 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. /// /// This is mainly useful for wm's who need another view stack for inplace sorting. From 30b93e7c16b5fe1c9322a7630813bb808a80367f Mon Sep 17 00:00:00 2001 From: Timidger Date: Sun, 14 Aug 2016 18:58:39 -0400 Subject: [PATCH 3/4] Added wlc_output_get_virtual_resolution --- src/handle.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/handle.rs b/src/handle.rs index f97798a..309ae61 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -57,6 +57,8 @@ extern "C" { 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; fn wlc_output_set_mask(output: uintptr_t, mask: u32); @@ -305,11 +307,17 @@ 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 From b0741c9aa002799feb4a51183f96b621c23d548a Mon Sep 17 00:00:00 2001 From: Timidger Date: Sun, 14 Aug 2016 19:44:40 -0400 Subject: [PATCH 4/4] Updated example to have show off scaling #47 --- examples/simple.rs | 11 ++++++++++- src/xkb/mod.rs | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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/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)]