summary refs log tree commit diff
path: root/src/xtypes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/xtypes.rs')
-rw-r--r--src/xtypes.rs29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/xtypes.rs b/src/xtypes.rs
index 3f67e58..89bb622 100644
--- a/src/xtypes.rs
+++ b/src/xtypes.rs
@@ -2,6 +2,7 @@ use std::borrow::Borrow;
 use std::sync::Arc;
 use std::ops::Deref;
 
+use xcb::XidNew;
 use xcb::x::{
   self,
   Atom,
@@ -10,7 +11,7 @@ use xcb::x::{
   InternAtom,
   MapWindow,
   PropMode,
-  Screen
+  Screen,
 };
 
 
@@ -72,7 +73,7 @@ impl Window {
     let display_ref: &Display = display.borrow();
     let connection: &Connection = &display_ref.connection;
 
-    let window_id: x::Window = connection.0.generate_id();
+    let window_id: x::Window = connection.generate_id();
 
     create_window.wid = window_id;
     let cookie = connection.send_request_checked(create_window);
@@ -136,27 +137,37 @@ impl HasConnection for Connection {
   fn connection(&self) -> &Connection { self }
 }
 
-impl<T: HasDisplay> HasConnection for T {
-  fn connection(&self) -> &Connection { &self.display().connection }
+impl HasConnection for Arc<Display> {
+  fn connection(&self) -> &Connection { &self.connection }
+}
+
+impl HasConnection for Window {
+  fn connection(&self) -> &Connection { &self.display.connection }
 }
 
 
 pub trait HasDisplay {
-  fn display(&self) -> &Display;
+  fn display(&self) -> &Arc<Display>;
 
   fn atoms(&self) -> &Atoms { &self.display().atoms }
 }
 
-impl HasDisplay for Display {
-  fn display(&self) -> &Display { self }
+impl HasDisplay for Arc<Display> {
+  fn display(&self) -> &Arc<Display> { self }
 }
 
-impl<T: HasWindow> HasDisplay for T {
-  fn display(&self) -> &Display { self.window().display.borrow() }
+impl HasDisplay for Window {
+  fn display(&self) -> &Arc<Display> { &self.display }
 }
 
 
 pub trait ConnectionExt: HasConnection {
+  fn generate_id<T: XidNew>(&self) -> T {
+    let connection = self.connection();
+
+    connection.0.generate_id()
+  }
+
   fn get_atom(&self, name: &[u8]) -> xcb::Result<Atom> {
     let connection = self.connection();