initial commit
This commit is contained in:
commit
46deb59efd
4 changed files with 104 additions and 0 deletions
43
Makefile
Normal file
43
Makefile
Normal file
|
|
@ -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
|
||||
25
includes/windowManager/WindowManager.hpp
Normal file
25
includes/windowManager/WindowManager.hpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
#ifndef NOISE_GENERATOR_WINDOWMANAGER_HPP
|
||||
#define NOISE_GENERATOR_WINDOWMANAGER_HPP
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#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
|
||||
13
srcs/main.cpp
Normal file
13
srcs/main.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#include "windowManager/WindowManager.hpp"
|
||||
|
||||
#define WIDTH 500
|
||||
#define HEIGHT 800
|
||||
|
||||
int main() {
|
||||
WindowManager window(WIDTH, HEIGHT);
|
||||
|
||||
window.loop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
srcs/windowManager/WindowManager.cpp
Normal file
23
srcs/windowManager/WindowManager.cpp
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue