From 3b65d725ff54fd389b9930dc3cda5af6a6c028ed Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 30 Aug 2024 15:54:57 -0700 Subject: Initialize X server --- .gitignore | 1 + README.md | 5 +++++ src/Makefile | 17 +++++++++++++++++ src/defs.h | 14 ++++++++++++++ src/main.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/scapx.h | 17 +++++++++++++++++ 6 files changed, 97 insertions(+) create mode 100644 .gitignore create mode 100644 src/Makefile create mode 100644 src/defs.h create mode 100644 src/main.c create mode 100644 src/scapx.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..36f971e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/* diff --git a/README.md b/README.md index c182612..9578369 100644 --- a/README.md +++ b/README.md @@ -1 +1,6 @@ +# Scapx scapx: Selective Screen Capture for X environment + +# TODO + +# References diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..4b00009 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,17 @@ +CC = gcc +CFLAGS = -Wall -Wextra -Wpedantic -std=c99 -Wunreachable-code -Werror-implicit-function-declaration +LD_CFLAGS = -lxcb +BIN_DIR = ../bin +TARGET = $(BIN_DIR)/scapx +#SRC = main.c +#HEADERS = scapx.h + + +all: + $(CC) $(CFLAGS) $(LD_CFLAGS) -o $(BIN_DIR)/scapx main.c + +$(BIN_DIR): + mkdir -p $(BIN_DIR) + +clean: + rm $(BIN_DIR)/*.o diff --git a/src/defs.h b/src/defs.h new file mode 100644 index 0000000..2e40298 --- /dev/null +++ b/src/defs.h @@ -0,0 +1,14 @@ +#include + +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; +typedef uint64_t u64; + +typedef int8_t i8; +typedef int16_t i16; +typedef int32_t i32; +typedef int64_t i64; + +typedef float f32; +typedef double f64; diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..0230dfd --- /dev/null +++ b/src/main.c @@ -0,0 +1,43 @@ +#include "scapx.h" + + +Scr_info *init_XCB_server() +{ + Scr_info *info = malloc(sizeof(Scr_info)); + if (!info) { + fprintf(stderr, "memory allocation failed.\n"); + return NULL; + } + + info->con = xcb_connect(NULL, NULL); + if (xcb_connection_has_error(info->con) > 0) { + fprintf(stderr, "Error opening display.\n"); + free(info); + return NULL; + } + + const xcb_setup_t *setup = xcb_get_setup(info->con); + info->scr = xcb_setup_roots_iterator(setup).data; + + return info; +} + +int main() +{ + Scr_info *info = init_XCB_server(); + + if (!info || !info->scr) { + fprintf(stderr, "Error opening display.\n"); + if (info) { + xcb_disconnect(info->con); + free(info); + } + exit(EXIT_FAILURE); + } + + // TODO: event loop + + xcb_disconnect(info->con); + free(info); + return 0; +} diff --git a/src/scapx.h b/src/scapx.h new file mode 100644 index 0000000..0615e47 --- /dev/null +++ b/src/scapx.h @@ -0,0 +1,17 @@ +#ifndef SCAPX_H +#define SCAPX_H + +#include +#include +#include + +typedef struct { + xcb_connection_t *con; + xcb_screen_t *scr; +} Scr_info; + + +/* Connects to the X Server, and accesses the screen */ +Scr_info *init_XCB_server(); + +#endif -- cgit v1.2.3