gdritter repos emenu / 273cc30
just the ability to show a crappy window Getty Ritter 5 years ago
4 changed file(s) with 328 addition(s) and 0 deletion(s). Collapse all Expand all
1 /target
2 **/*.rs.bk
3 *~
1 [[package]]
2 name = "bitflags"
3 version = "1.0.4"
4 source = "registry+https://github.com/rust-lang/crates.io-index"
5
6 [[package]]
7 name = "cairo-rs"
8 version = "0.5.0"
9 source = "registry+https://github.com/rust-lang/crates.io-index"
10 dependencies = [
11 "cairo-sys-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
12 "glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
13 "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
14 "gobject-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
15 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
16 ]
17
18 [[package]]
19 name = "cairo-sys-rs"
20 version = "0.7.0"
21 source = "registry+https://github.com/rust-lang/crates.io-index"
22 dependencies = [
23 "glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
24 "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
25 "gobject-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
26 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
27 "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
28 "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
29 ]
30
31 [[package]]
32 name = "cfg-if"
33 version = "0.1.6"
34 source = "registry+https://github.com/rust-lang/crates.io-index"
35
36 [[package]]
37 name = "emenu"
38 version = "0.1.0"
39 dependencies = [
40 "cairo-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
41 "cairo-sys-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
42 "pango 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
43 "pangocairo 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
44 "xcb 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
45 ]
46
47 [[package]]
48 name = "glib"
49 version = "0.6.0"
50 source = "registry+https://github.com/rust-lang/crates.io-index"
51 dependencies = [
52 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
53 "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
54 "gobject-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
55 "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
56 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
57 ]
58
59 [[package]]
60 name = "glib-sys"
61 version = "0.7.0"
62 source = "registry+https://github.com/rust-lang/crates.io-index"
63 dependencies = [
64 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
65 "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
66 ]
67
68 [[package]]
69 name = "gobject-sys"
70 version = "0.7.0"
71 source = "registry+https://github.com/rust-lang/crates.io-index"
72 dependencies = [
73 "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
74 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
75 "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
76 ]
77
78 [[package]]
79 name = "lazy_static"
80 version = "1.1.0"
81 source = "registry+https://github.com/rust-lang/crates.io-index"
82 dependencies = [
83 "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
84 ]
85
86 [[package]]
87 name = "libc"
88 version = "0.2.43"
89 source = "registry+https://github.com/rust-lang/crates.io-index"
90
91 [[package]]
92 name = "log"
93 version = "0.4.6"
94 source = "registry+https://github.com/rust-lang/crates.io-index"
95 dependencies = [
96 "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
97 ]
98
99 [[package]]
100 name = "pango"
101 version = "0.5.0"
102 source = "registry+https://github.com/rust-lang/crates.io-index"
103 dependencies = [
104 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
105 "glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
106 "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
107 "gobject-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
108 "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
109 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
110 "pango-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
111 ]
112
113 [[package]]
114 name = "pango-sys"
115 version = "0.7.0"
116 source = "registry+https://github.com/rust-lang/crates.io-index"
117 dependencies = [
118 "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
119 "gobject-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
120 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
121 "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
122 ]
123
124 [[package]]
125 name = "pangocairo"
126 version = "0.6.0"
127 source = "registry+https://github.com/rust-lang/crates.io-index"
128 dependencies = [
129 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
130 "cairo-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
131 "cairo-sys-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
132 "glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
133 "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
134 "gobject-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
135 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
136 "pango 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
137 "pango-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
138 "pangocairo-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
139 ]
140
141 [[package]]
142 name = "pangocairo-sys"
143 version = "0.8.0"
144 source = "registry+https://github.com/rust-lang/crates.io-index"
145 dependencies = [
146 "cairo-sys-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
147 "glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
148 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
149 "pango-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
150 "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
151 ]
152
153 [[package]]
154 name = "pkg-config"
155 version = "0.3.14"
156 source = "registry+https://github.com/rust-lang/crates.io-index"
157
158 [[package]]
159 name = "version_check"
160 version = "0.1.5"
161 source = "registry+https://github.com/rust-lang/crates.io-index"
162
163 [[package]]
164 name = "winapi"
165 version = "0.3.6"
166 source = "registry+https://github.com/rust-lang/crates.io-index"
167 dependencies = [
168 "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
169 "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
170 ]
171
172 [[package]]
173 name = "winapi-i686-pc-windows-gnu"
174 version = "0.4.0"
175 source = "registry+https://github.com/rust-lang/crates.io-index"
176
177 [[package]]
178 name = "winapi-x86_64-pc-windows-gnu"
179 version = "0.4.0"
180 source = "registry+https://github.com/rust-lang/crates.io-index"
181
182 [[package]]
183 name = "xcb"
184 version = "0.8.2"
185 source = "registry+https://github.com/rust-lang/crates.io-index"
186 dependencies = [
187 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
188 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
189 ]
190
191 [metadata]
192 "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
193 "checksum cairo-rs 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd940f0d609699e343ef71c4af5f66423afbf30d666f796dabd8fd15229cf5b6"
194 "checksum cairo-sys-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d25596627380be4381247dba06c69ad05ca21b3b065bd9827e416882ac41dcd2"
195 "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
196 "checksum glib 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740f7fda8dde5f5e3944dabdb4a73ac6094a8a7fdf0af377468e98ca93733e61"
197 "checksum glib-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3573351e846caed9f11207b275cd67bc07f0c2c94fb628e5d7c92ca056c7882d"
198 "checksum gobject-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "08475e4a08f27e6e2287005950114735ed61cec2cb8c1187682a5aec8c69b715"
199 "checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
200 "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
201 "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
202 "checksum pango 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4c2cb169402a3eb1ba034a7cc7d95b8b1c106e9be5ba4be79a5a93dc1a2795f4"
203 "checksum pango-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6eb49268e69dd0c1da5d3001a61aac08e2e9d2bfbe4ae4b19b9963c998f6453"
204 "checksum pangocairo 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4325b65f44487564a18d6402bed48c1bc4642167bfe972a753d039d1ac938c21"
205 "checksum pangocairo-sys 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9e79ffb01eae5bc130b44fde529fa493ad6308c340da1358eaa2435ed3580e4f"
206 "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
207 "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
208 "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
209 "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
210 "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
211 "checksum xcb 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5e917a3f24142e9ff8be2414e36c649d47d6cc2ba81f16201cdef96e533e02de"
1 [package]
2 name = "emenu"
3 version = "0.1.0"
4 authors = ["Getty Ritter <gettylefou@gmail.com>"]
5 edition = "2018"
6
7 [dependencies]
8 xcb = "*"
9 cairo-sys-rs = "0.7.0"
10 pango = "*"
11 pangocairo = "*"
12
13 [dependencies.cairo-rs]
14 version = "0.5.0"
15 features = ["xcb"]
1 use cairo::XCBSurface;
2 use cairo::prelude::SurfaceExt;
3 use pango::LayoutExt;
4 use std::mem;
5 use xcb::ffi::*;
6
7 // this should in no way be hard-coded, but hey guess what it is
8 // right now deal with it
9 const WIDTH: i32 = 1920;
10 const HEIGHT: i32 = 38;
11
12 fn find_visual(conn: *mut xcb_connection_t, visual: xcb_visualid_t) -> *mut xcb_visualtype_t {
13 unsafe {
14 let screen_iter = xcb_setup_roots_iterator(xcb_get_setup(conn));
15 while screen_iter.rem > 0 {
16 let depth_iter = xcb_screen_allowed_depths_iterator(screen_iter.data);
17 while depth_iter.rem > 0 {
18 let visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
19 while visual_iter.rem > 0 {
20 if visual == (*visual_iter.data).visual_id {
21 return visual_iter.data;
22 }
23 xcb_visualtype_next(&visual_iter as *const xcb_visualtype_iterator_t as *mut xcb_visualtype_iterator_t);
24 }
25 xcb_depth_next(&depth_iter as *const xcb_depth_iterator_t as *mut xcb_depth_iterator_t);
26 }
27 xcb_screen_next(&screen_iter as *const xcb_screen_iterator_t as *mut xcb_screen_iterator_t);
28 }
29 std::ptr::null_mut()
30 }
31 }
32
33 fn mk_connection() -> *mut xcb_connection_t {
34 unsafe {
35 xcb_connect(std::ptr::null_mut(), std::ptr::null_mut())
36 }
37 }
38
39
40 fn mk_window(conn: *mut xcb_connection_t) -> (*mut xcb_screen_t, xcb_window_t) {
41 unsafe {
42 let screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
43 let window = xcb_generate_id(conn);
44 let mask = [1, XCB_EVENT_MASK_EXPOSURE];
45 xcb_create_window(conn, XCB_COPY_FROM_PARENT as u8, window, (*screen).root,
46 0, 0, WIDTH as u16, HEIGHT as u16, 0,
47 XCB_WINDOW_CLASS_INPUT_OUTPUT as u16,
48 (*screen).root_visual,
49 XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
50 mask.as_ptr());
51 xcb_map_window(conn, window);
52 (screen, window)
53 }
54 }
55
56 fn main () {
57 let conn = mk_connection();
58
59 let (screen, window) = mk_window(conn);
60 let visual = find_visual(conn, unsafe { (*screen).root_visual });
61
62 let s = unsafe {
63 <cairo::Surface as XCBSurface>::create(
64 &cairo::XCBConnection::from_raw_none(mem::transmute::<*mut xcb_connection_t, *mut cairo_sys::xcb_connection_t>(conn)),
65 &cairo::XCBDrawable(window),
66 &cairo::XCBVisualType::from_raw_none(mem::transmute::<*mut xcb_visualtype_t, *mut cairo_sys::xcb_visualtype_t>(visual)),
67 WIDTH,
68 HEIGHT,
69 )
70 };
71 let ctx = cairo::Context::new(&s);
72 unsafe { xcb_flush(conn); }
73
74 loop {
75 let event = unsafe { xcb_wait_for_event(conn) };
76 if let Some(e) = unsafe { event.as_ref() } {
77 if (e.response_type & !0x80) == XCB_EXPOSE {
78 ctx.set_source_rgb(0.2, 0.2, 0.2);
79 ctx.paint();
80
81 ctx.set_source_rgb(1.0, 1.0, 1.0);
82 let layout = pangocairo::functions::create_layout(&ctx).unwrap();
83 layout.set_width(1920 * 1024);
84 let font = pango::FontDescription::from_string("Fira Mono 18");
85 layout.set_font_description(&font);
86 ctx.move_to(6.0, 4.0);
87 layout.set_text("The quick brown fox jumps over the lazy dog.");
88 pangocairo::functions::show_layout(&ctx, &layout);
89 <&cairo::Surface as SurfaceExt>::flush(&&s);
90 }
91 } else {
92 break;
93 }
94 unsafe { xcb_flush(conn); }
95 }
96
97 unsafe { xcb_disconnect(conn); }
98
99 }