an xcb window
This commit is contained in:
parent
cab93ff652
commit
9dba8ce469
10 changed files with 143 additions and 41 deletions
|
@ -6,6 +6,11 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
rustc-link-lib = ["xcb", "cairo"]
|
||||||
|
name = "hic"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.169"
|
libc = "0.2.169"
|
||||||
same-proto = { path = "../same-proto" }
|
same-proto = { path = "../same-proto" }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
cxx = clang++
|
cxx = clang++
|
||||||
cxxflags = -g -Wall -Wextra -Wno-c99-extensions -pedantic -fblocks -O3 -Iinc
|
cxxflags = -g -Wall -Wextra -Wno-c99-extensions -pedantic -fblocks -O3 -Iinc -fPIC
|
||||||
libs = -lxcb -I/usr/include/cairo -I/usr/include/libpng16 -I/usr/include/freetype2 -DWITH_GZFILEOP -I/usr/include/pixman-1 -lcairo
|
libs = -I/usr/include/cairo -I/usr/include/libpng16 -I/usr/include/freetype2 -DWITH_GZFILEOP -I/usr/include/pixman-1
|
||||||
rule cpp
|
rule cpp
|
||||||
depfile = $out.d
|
depfile = $out.d
|
||||||
command = $cxx -c -MD -MF $out.d $cxxflags $libs -o $out $in
|
command = $cxx -c -MD -MF $out.d $cxxflags $libs -o $out $in
|
||||||
|
@ -22,6 +22,7 @@ rule exe
|
||||||
command = $in
|
command = $in
|
||||||
build clean: rm o
|
build clean: rm o
|
||||||
build o: mkdir
|
build o: mkdir
|
||||||
|
build o/str.cpp.o: cpp lib/str.cpp
|
||||||
build o/gui.cpp.o: cpp lib/gui.cpp
|
build o/gui.cpp.o: cpp lib/gui.cpp
|
||||||
build o/libhic.a: lib o/gui.cpp.o
|
build o/libhic.a: lib o/str.cpp.o o/gui.cpp.o
|
||||||
default o/libhic.a
|
default o/libhic.a
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use std::env;
|
use std::{process::Command, env};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
Command::new("ninja").spawn().expect("ninja failed");
|
||||||
|
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
println!(r"cargo:rustc-link-search={}/o/", cwd.display());
|
println!("cargo:rustc-link-search={}/o/", cwd.display());
|
||||||
|
["cairo", "xcb"].iter().for_each(|x| println!("cargo:rustc-link-arg=-l{x}"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
#!/usr/bin/env goal
|
#!/usr/bin/env goal
|
||||||
|
|
||||||
|
/ join by newlines
|
||||||
nl:{x+"\n"+y}
|
nl:{x+"\n"+y}
|
||||||
|
/ join by spaces
|
||||||
sp:{x+" "+y}
|
sp:{x+" "+y}
|
||||||
|
|
||||||
fs:{f:read x;f["name"]@&~f"dir"}
|
/ all files in dir x
|
||||||
|
fs:{f:read x
|
||||||
|
f["name"]@&~f"dir"}
|
||||||
lib:fs "lib"
|
lib:fs "lib"
|
||||||
|
|
||||||
cpp:{x@&{"cpp"~+/|3#|("c"$)'"c"$x}'x}
|
/ get all items of x where ".cpp"~|4#|x
|
||||||
|
/ now you can cpp@fs x
|
||||||
|
cpp:{x@&{".cpp"~+/|4#|("c"$)'"c"$x}'x}
|
||||||
|
|
||||||
|
/ generate the ninja file
|
||||||
say'("cxx = clang++"
|
say'("cxx = clang++"
|
||||||
"cxxflags = "+sp/("-g -Wall -Wextra -Wno-c99-extensions"
|
"cxxflags = "+sp/("-g -Wall -Wextra -Wno-c99-extensions"
|
||||||
"-pedantic -fblocks -O3 -Iinc")
|
"-pedantic -fblocks -O3 -Iinc -fPIC")
|
||||||
"libs = "+sp/{-1_shell "pkg-config --cflags --libs $x"}'"xcb" "cairo"
|
"libs = "+sp/{-1_shell "pkg-config --cflags $x"}'"xcb" "cairo"
|
||||||
rq/rule cpp
|
rq/rule cpp
|
||||||
depfile = $out.d
|
depfile = $out.d
|
||||||
command = $cxx -c -MD -MF $out.d $cxxflags $libs -o $out $in
|
command = $cxx -c -MD -MF $out.d $cxxflags $libs -o $out $in
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
|
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define eprintln(...) { \
|
||||||
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
|
putc('\n', stderr); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define fatal(...) { \
|
||||||
|
eprintln(__VA_ARGS__); \
|
||||||
|
exit(-1); \
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename E>
|
template<typename T, typename E>
|
||||||
struct result {
|
struct result {
|
||||||
union {
|
union {
|
||||||
|
|
|
@ -1,25 +1,55 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
#include <cairo-xcb.h>
|
#include <cairo-xcb.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "com.h"
|
#include "com.h"
|
||||||
|
#include "str.h"
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
|
||||||
/*
|
xcb_connection_t *con;
|
||||||
auto win_t::mk() -> result_t<win_t, std::string> {
|
xcb_screen_t *scr;
|
||||||
win.dpy = XCBConnectBasic();
|
xcb_window_t win;
|
||||||
if (win.dpy == NULL) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
win_t win;
|
extern "C" auto hic_init() -> int {
|
||||||
|
/*
|
||||||
|
* set up the connection and grab a window id
|
||||||
|
*/
|
||||||
|
con = xcb_connect(NULL, NULL);
|
||||||
|
if (con == NULL) return -1;
|
||||||
|
|
||||||
extern "C" auto init(int x, int y) -> int {
|
scr = xcb_setup_roots_iterator(xcb_get_setup(con)).data;
|
||||||
// win.dpy = XCBConnectBasic();
|
if (scr == NULL) return -2;
|
||||||
if (win.dpy == NULL) {
|
|
||||||
err("failed to open display");
|
win = xcb_generate_id(con);
|
||||||
return 1;
|
|
||||||
}
|
/* summon a window */
|
||||||
|
xcb_create_window(
|
||||||
|
con,
|
||||||
|
XCB_COPY_FROM_PARENT, /* depth (same as root) */
|
||||||
|
win,
|
||||||
|
scr->root, /* parent window */
|
||||||
|
0, 0, /* x y */
|
||||||
|
640, 480, /* width height */
|
||||||
|
5, /* border width */
|
||||||
|
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* the window class */
|
||||||
|
scr->root_visual,
|
||||||
|
0, NULL /* masks (unused) */
|
||||||
|
);
|
||||||
|
|
||||||
|
/* map the window onto the screen */
|
||||||
|
xcb_map_window(con, win);
|
||||||
|
|
||||||
|
/* make sure commands are sent before we pause, so window is shown */
|
||||||
|
xcb_flush(con);
|
||||||
|
|
||||||
|
/* now we wait */
|
||||||
|
pause();
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
/*
|
|
||||||
struct win_t {
|
|
||||||
XCBConnection *dpy;
|
|
||||||
|
|
||||||
XCBWINDOW win;
|
|
||||||
XCBGCONTEXT gc;
|
|
||||||
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
XCBVISUALTYPE *visual;
|
|
||||||
|
|
||||||
static result_t<win_t, str_t> mk();
|
|
||||||
~win_t();
|
|
||||||
};
|
|
||||||
*/
|
|
34
hic/lib/str.cpp
Normal file
34
hic/lib/str.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "com.h"
|
||||||
|
#include "str.h"
|
||||||
|
|
||||||
|
str_t::~str_t() {
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CLONE(x) { \
|
||||||
|
i = x.i, len = x.len; \
|
||||||
|
auto size = sizeof(str_t::C) * len; \
|
||||||
|
\
|
||||||
|
buf = (str_t::C*)malloc(size); \
|
||||||
|
if (buf == NULL) fatal( \
|
||||||
|
"malloc() returned NULL in str_t clone. aborting." \
|
||||||
|
); \
|
||||||
|
\
|
||||||
|
memcpy(buf, x.buf, size); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
auto str_t::operator=(const str_t& x) -> str_t& {
|
||||||
|
CLONE(x);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
str_t::str_t(const str_t& x) {
|
||||||
|
CLONE(x)
|
||||||
|
}
|
25
hic/lib/str.h
Normal file
25
hic/lib/str.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
struct str_t {
|
||||||
|
/* the char type
|
||||||
|
* declared because i might change it later and i don't want to rewrite
|
||||||
|
* all the types */
|
||||||
|
using C = uint8_t;
|
||||||
|
|
||||||
|
C *buf;
|
||||||
|
size_t i;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
static auto mk() -> option<str_t> {
|
||||||
|
size_t i = 0, len = 8;
|
||||||
|
auto buf = (C*)malloc(sizeof(C) * len);
|
||||||
|
return buf == NULL
|
||||||
|
? option<str_t>()
|
||||||
|
: option<str_t>(str_t(buf, i, len));
|
||||||
|
}
|
||||||
|
|
||||||
|
str_t(C *buf, size_t i, size_t len) : buf{buf}, i{i}, len{len} {}
|
||||||
|
|
||||||
|
~str_t();
|
||||||
|
|
||||||
|
str_t& operator=(const str_t& x);
|
||||||
|
str_t(const str_t& x);
|
||||||
|
};
|
|
@ -2,10 +2,12 @@ use libc::c_int;
|
||||||
|
|
||||||
#[link(name="hic")]
|
#[link(name="hic")]
|
||||||
unsafe extern "C" {
|
unsafe extern "C" {
|
||||||
fn add(x: c_int, y: c_int) -> c_int;
|
fn hic_init() -> c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{}", unsafe { add(1, 10) });
|
unsafe {
|
||||||
|
hic_init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue