Skip to content
This repository has been archived by the owner on Jan 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from Immington-Industries/resolution-changes
Browse files Browse the repository at this point in the history
Added resolution changes for wlc e9d8e98
  • Loading branch information
SnirkImmington authored Aug 15, 2016
2 parents f5a0090 + b0741c9 commit f64db44
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
11 changes: 10 additions & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn get_topmost_view(output: WlcOutput, offset: usize) -> Option<WlcView> {
}

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; }

Expand Down Expand Up @@ -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;
}
}
}
Expand Down
28 changes: 20 additions & 8 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<Size> {
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<Size> {
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.
Expand Down
7 changes: 7 additions & 0 deletions src/xkb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit f64db44

Please sign in to comment.