From 46deb59efd38e135b3ed2fe6bbc17593ffabd2da Mon Sep 17 00:00:00 2001 From: loic Date: Fri, 13 Dec 2024 02:02:58 +0100 Subject: [PATCH] initial commit --- Makefile | 43 ++++++++++++++++++++++++ includes/windowManager/WindowManager.hpp | 25 ++++++++++++++ srcs/main.cpp | 13 +++++++ srcs/windowManager/WindowManager.cpp | 23 +++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 Makefile create mode 100644 includes/windowManager/WindowManager.hpp create mode 100644 srcs/main.cpp create mode 100644 srcs/windowManager/WindowManager.cpp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6c07b90 --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +SRC_DIR = srcs/ +SRCS= \ + $(SRC_DIR)main.cpp \ + $(SRC_DIR)windowManager/WindowManager.cpp + +MAKEFLAGS += --no-print-directory + +NAME = window + +CC = c++ +CFLAGS = -Wall -Wextra -Werror -g3 +CPPFLAGS = -std=c++98 -MMD -MP +BUILDDIR = build/ +INCLUDEDIR = includes/ +DEPENDENCIESDIR = $(BUILDDIR)dependencies/ + +OBJS = $(SRCS:$(SRC_DIR)%.cpp=$(BUILDDIR)%.o) +DEPS = $(SRCS:$(SRC_DIR)%.cpp=$(DEPENDENCIESDIR)%.d) + +-include $(DEPS) + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) -Iincludes/ $(OBJS) -lX11 -o $(NAME) + +$(BUILDDIR)%.o: $(SRC_DIR)%.cpp + @mkdir -p $(@D) + @mkdir -p $(DEPENDENCIESDIR)$(@:$(BUILDDIR)%$(@F)=%) + $(CC) $(CFLAGS) -I$(INCLUDEDIR) $(CPPFLAGS) -c $< -o $@ + @mv $(@:%.o=%.d) $(DEPENDENCIESDIR)$(@:$(BUILDDIR)%.o=%.d) + +clean: + rm -rf $(BUILDDIR) + +fclean: clean + rm -f $(NAME) + +re: fclean + @$(MAKE) all + +.PHONY: all clean fclean re +.DEFAULT_GOAL := all \ No newline at end of file diff --git a/includes/windowManager/WindowManager.hpp b/includes/windowManager/WindowManager.hpp new file mode 100644 index 0000000..0e6a93b --- /dev/null +++ b/includes/windowManager/WindowManager.hpp @@ -0,0 +1,25 @@ + +#ifndef NOISE_GENERATOR_WINDOWMANAGER_HPP +#define NOISE_GENERATOR_WINDOWMANAGER_HPP + +#include +#include "err.h" + +class WindowManager { +public: + WindowManager(int width, int height); + ~WindowManager(); + + void loop(); +private: + Display *_display; + int _screen; + Window root; + Window win; + XEvent event; + int _width; + int _height; + +}; + +#endif //NOISE_GENERATOR_WINDOWMANAGER_HPP diff --git a/srcs/main.cpp b/srcs/main.cpp new file mode 100644 index 0000000..b541fb4 --- /dev/null +++ b/srcs/main.cpp @@ -0,0 +1,13 @@ + +#include "windowManager/WindowManager.hpp" + +#define WIDTH 500 +#define HEIGHT 800 + +int main() { + WindowManager window(WIDTH, HEIGHT); + + window.loop(); + + return 0; +} diff --git a/srcs/windowManager/WindowManager.cpp b/srcs/windowManager/WindowManager.cpp new file mode 100644 index 0000000..3f4287d --- /dev/null +++ b/srcs/windowManager/WindowManager.cpp @@ -0,0 +1,23 @@ +#include "windowManager/WindowManager.hpp" + +WindowManager::WindowManager(int width, int height) : _width(width), _height(height) { + _display = XOpenDisplay(NULL); + if (NULL == _display) errx(2, "unable to open display"); + _screen = DefaultScreen(_display); + root = RootWindow(_display, _screen); + win = XCreateSimpleWindow(_display, root, 0, 0, _width, _height, 10, + 0, 0x0f0f0f); + + XMapWindow(_display, win); + XFlush(_display); +} + +WindowManager::~WindowManager() { + XUnmapWindow(_display, win); + XDestroyWindow(_display, win); + XCloseDisplay(_display); +} + +void WindowManager::loop() { + while (XNextEvent(_display, &event) != 0); +}