Coder Social home page Coder Social logo

drakulix / wlc.rs Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 4.0 10.04 MB

Safe Rust Cloudef/wlc bindings (Wayland Compositor C Library)

License: MIT License

Rust 99.91% C++ 0.09%
wlc compositor wayland-compositor wayland rust crates window-manager windowmanager

wlc.rs's Introduction

wlc Bindings for Rust Build Status Crates.io Crates.io

Completely safe and idiomatic bindings to the wayland compositor library.

Example

// for a more functional example see /examples/example.rs
use wlc::*;

struct Compositor;
impl Callback for Compositor
{
    fn view_created(&mut self, view: &View) -> bool
    {
        view.set_visibility(view.output().visibility());
        view.bring_to_front();
        view.focus();
        true
    }

    fn view_focus(&mut self, view: &View, focus: bool)
    {
        view.set_state(ViewState::Activated, focus);
    }
}

fn main()
{
    wlc::init(Compositor).unwrap()
}

Usage

This crate currently requires nightly Rust to mark certain ffi-related structs explicitly as not Send.

You can opt-out of this behaviour with a feature-flag (unsafe-stable). Make you never pass View, Output including their Weak-Variants, Positioner or Wlc to another thread.

Add to your Cargo.toml

wlc = "0.1"

For stable

wlc = { version = "1.0", features = "unsafe-stable" }

For static compilation (combination is possible)

wlc = { version = "1.0", features = "static" }

See wlc for build dependencies, when doing a static build.

Additionally libclang>=3.8 is needed for code generation during build.

If you have libclang in another path then /usr/lib you have to provide it when building your binary:

LIBCLANG_PATH=/usr/lib64 cargo build --release

See https://github.com/KyleMayes/clang-sys#environment-variables for more options.

The features render and wayland enable the optional extensions wlc provides.

In that case WlcSurface, WlcSubSurface and GLES2Renderer should also not be send across threads, when using unsafe-stable.

A note on rust-wlc

rust-wlc has some short comings this crate tries to avoid. It was build without any parts of the original rust-wlc source code and may have its own problems, but it tries to deal with the following issues differently:

(In the following statements wlc refers to the original C Library and rust-wlc to the alternative wlc bindings)

  • wlc does not transfer the ownership of views and output structs to the implementing compositor. Instead any view or output might be deallocated by the library after a view_destroyed/output_destroyed callback. rust-wlc does not model this relationship correctly in my opinion. See DESIGN.md to understand how this library models View and Output.
  • rust-wlc lets you use extern functions and directly interfere with C-code. This implementation almost requires a global singleton and the usage of lazy_static. This crate provides you with a Trait to be used for you custom compositor and hides these implementation details.
  • This crate provides a safer alternative to wlc's userdata API. It is still unsafe in some aspects and should be abstracted by any compositor implementation, but it is easier to handle.
  • Exposes run loop functions.
  • This crate implements most of wlc's render and wayland api's.
  • rust-wlc is most likely better tested, as it has likely some more users and a simple mocking library (if I am correct). So please report any issues you may find.

Please note, that I do not try to compete with rust-wlc in anyway. I also respect the work they have done and their window manager way-cooler is certainly an interesting project. I just did not like their design decisions and decided to build my own wlc-bindings and my own window manager.

wlc.rs's People

Contributors

drakulix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wlc.rs's Issues

unresolved import wlc

Hi, trying to add your crate to dependencies, but can't import it.
Tried all three ways

Add to your Cargo.toml
wlc = "0.1"
For stable
wlc = { version = "1.0", features = "unsafe-stable" }
For static compilation (combination is possible)
wlc = { version = "1.0", features = "static" }

Adding Mocks

I must say, this is a very interesting project that seemed to come out of no where. You did a very good job wrapping wlc. I've been meaning to go back and fix some of things you have already addressed with this project (the ugly lazy_statics! being the main thing). Seems I don't have to now :).

I want to look into using this for Way Cooler, but it seems like you don't have any way to mock the objects yet. I would be more than happy to add this feature to this project. Do you have any particular way you would like it to be done? Behind a feature flag? In a separate repo?

While it looks ugly, I suggest using a different repo. If it is behind a feature flag, then when using mocks in test you run into this problem with cargo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.