Skip to main content

Crate kwin_mouse_loc

Crate kwin_mouse_loc 

Source
Expand description

§kwin-mouse-loc

A very simple mouse controller that uses libc::process_vm_readv to read mouse location. Need to access kwin_wayland’s memory, may often need root permissions.

§Usage

Since mouse and keyboard operations is very dangerous, it might be easily be poisoned. And since there is no guarateen that crate owner is not evil, I wrote this simple crate.

The main aim of this crate is that, make user ensure they use a SAFE crate that cannot be poisoned. The BEST practice of using this crate should be just copy the build.rs and lib.rs into your project.

If you like this crate, you could make it as an optional dependencies, BUT please keep one thing in mind:

DO NOT ENABLE THE DEPENDENCIES OF THIS CRATE

§Example

(all the tests require root permissions, without root permissions, the program might failed to execute)

use kwin_mouse_loc::pointer::Workspace;
fn main(){
    let mouse = unsafe{Workspace::new(true).get_mouse()};
    let (x,y) = mouse.loc();
    println!("mouse is located at ({x}, {y})");
    // do some other things.
    std::thread::sleep(std::time::Duration::from_millis(300));

    // obtain mouse location again, with display.
    println!("mouse is located at {mouse}");
}

§Features

docgen-detect : for publish (and doc generation without process header file) thus enabled by default. For normal use, just disable it.

keyboard : requires uinput, allow using keyboard commands

uinput : process uinput constants from header files.

test : enable tests, since most of the tests needs root permission, be aware.

update-offset : update the offset of workspace related to libkwin. Especially useful after the libkwin.so updated.

update-pos : requires update-offset, also update the field offset of mouse position

Modules§

consts
Some constants, which could be updated if feature update-offset is set. It is worth mention that, the update-offset feature highly relies on readelf executable, and use the following sections:
pointer
pointer of kwin workspace and its cursor’s position