Last active
April 20, 2017 15:54
-
-
Save ripread/6defcb029653faff45c577d16f913d3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <wayland-client.h> | |
struct wl_display *display; | |
struct wl_compositor *compositor; | |
struct wl_surface *surface; | |
static void registry_global(void *data, struct wl_registry *registry, uint32_t name, | |
const char *interface, uint32_t version) { | |
printf("%s\n", interface); | |
compositor = wl_registry_bind(registry, name, &wl_compositor_interface, version); | |
wl_display_roundtrip(display); | |
} | |
static void registry_global_remove(void *a, struct wl_registry *b, uint32_t c) {} | |
static const struct wl_registry_listener registry_listener = { | |
.global = registry_global, | |
.global_remove = registry_global_remove | |
}; | |
int main() { | |
struct wl_registry *registry; | |
display = wl_display_connect(NULL); | |
registry = wl_display_get_registry(display); | |
wl_registry_add_listener(registry, ®istry_listener, NULL); | |
wl_display_roundtrip(display); | |
wl_registry_destroy(registry); | |
surface = wl_compositor_create_surface(compositor); | |
wl_surface_attach(surface, NULL, 0, 0); | |
wl_display_roundtrip(display); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code)] | |
#![allow(unused_variables)] | |
extern crate wayland_server; | |
use wayland_server::*; | |
use wayland_server::protocol::*; | |
fn main() { | |
let (mut disp, mut evtloop) = create_display(); | |
disp.add_socket_auto().unwrap(); | |
let compositor_handle = evtloop.add_handler_with_init(CompositorGlobal::new()); | |
let compglob = evtloop.register_global::<wl_compositor::WlCompositor, CompositorGlobal>(compositor_handle, 1); | |
evtloop.run(); | |
} | |
impl wl_compositor::Handler for CompositorHandler { | |
fn create_surface(&mut self, evqh: &mut EventLoopHandle, _client: &Client, | |
_compositor: &wl_compositor::WlCompositor, surface: wl_surface::WlSurface) { | |
evqh.register_with_destructor::<_, CompositorHandler, CompositorHandler>(&surface, self.my_id); | |
} | |
} | |
impl wl_surface::Handler for CompositorHandler { | |
fn attach(&mut self, evqh: &mut EventLoopHandle, _client: &Client, | |
surface: &wl_surface::WlSurface, buffer: Option<&wl_buffer::WlBuffer>, x: i32, y: i32) { | |
println!("never get here"); | |
} | |
} | |
//fluff | |
pub struct CompositorGlobal { | |
handler_id: Option<usize>, | |
} | |
struct CompositorHandler { | |
my_id: usize, | |
} | |
impl CompositorGlobal { | |
pub fn new() -> CompositorGlobal | |
{ | |
CompositorGlobal { | |
handler_id: None, | |
} | |
} | |
} | |
impl GlobalHandler<wl_compositor::WlCompositor> for CompositorGlobal { | |
fn bind(&mut self, evqh: &mut EventLoopHandle, _:&Client, global: wl_compositor::WlCompositor) { | |
let hid = self.handler_id.expect("CompositorGlobal was not initialized"); | |
evqh.register::<_, CompositorHandler>(&global, hid); | |
} | |
} | |
impl Init for CompositorGlobal { | |
fn init(&mut self, evqh: &mut EventLoopHandle, _index: usize) { | |
let hid = evqh.add_handler_with_init(CompositorHandler{ | |
my_id: 0, | |
}); | |
self.handler_id = Some(hid); | |
} | |
} | |
impl Init for CompositorHandler { | |
fn init(&mut self, _evqh: &mut EventLoopHandle, index: usize) { | |
self.my_id = index; | |
} | |
} | |
impl Destroy<wl_surface::WlSurface> for CompositorHandler { | |
fn destroy(surface: &wl_surface::WlSurface) {} | |
} | |
declare_handler!(CompositorHandler, wl_compositor::Handler, wl_compositor::WlCompositor); | |
declare_handler!(CompositorHandler, wl_surface::Handler, wl_surface::WlSurface); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment