X11 hello world

This commit is contained in:
James Whiteman 2021-12-22 01:47:19 -08:00
commit 41b22dd9a7
17 changed files with 158 additions and 0 deletions

0
.gitignore vendored Normal file
View File

21
LICENSE.md Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 James Whiteman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

12
README.md Normal file
View File

@ -0,0 +1,12 @@
# Develop
If you are on Linux:
- Navigate to command/linux in terminal.
- Run `sh setup.sh` to setup your environment.
- Run `sh rebuild.sh` to build the application.
- Navigate to earn/ and run `executable` to run the built program.
If you are on Windows:
- Navigate to command/windows in command prompt.
- Run `setup.bat` to setup your environment.
- Run `rebuild.bat` to build the application.
- Navigate to earn/ and run `executable.exe` to run the built program.

48
command/linux/rebuild.sh Executable file
View File

@ -0,0 +1,48 @@
#Global definitions.
F_ROOT=$(readlink -f "$0")
D_ROOT=$(dirname "${F_ROOT}")/../../.
D_COMPILE=${D_ROOT}/compile
D_LINK=${D_ROOT}/link
D_EARN=${D_ROOT}/earn
F_COMPILE_LIST=${D_COMPILE}/project_files.txt
F_LINK_LIST=${D_LINK}/project_files.txt
echo "" > ${F_LINK_LIST}
# Compile.
LINE=0
LINE_COUNT=$(cat ${F_COMPILE_LIST} | wc -l)
while true
do
if [ ${LINE} -ge ${LINE_COUNT} ]; then
break
fi
LINE=$((LINE+1))
F_COMPILE=$(head -n ${LINE} ${F_COMPILE_LIST} | tail -n 1)
I_COMPILE=${D_COMPILE}/${F_COMPILE}
O_COMPILE=${D_LINK}/${F_COMPILE}.o
mkdir -p "${O_COMPILE%/*}"
clang++ -I ${D_COMPILE} -c ${I_COMPILE} -o ${O_COMPILE}
echo ${O_COMPILE} >> ${F_LINK_LIST}
done
# Libraries.
F_LIBRARY_LIST=${D_COMPILE}/libraries.txt
F_LIBRARY_OPTIONS=${D_LINK}/library_options.txt
echo "" > ${F_LIBRARY_OPTIONS}
LINE=0
LINE_COUNT=$(cat ${F_LIBRARY_LIST} | wc -l)
while true
do
if [ ${LINE} -ge ${LINE_COUNT} ]; then
break
fi
LINE=$((LINE+1))
LIBRARY="-l$(head -n ${LINE} ${F_LIBRARY_LIST}) "
echo $LIBRARY >> ${F_LIBRARY_OPTIONS}
done
# Link.
I_LINK=$(cat ${F_LINK_LIST})
I_LIBRARIES=$(cat ${F_LIBRARY_OPTIONS})
O_LINK=${D_EARN}/executable
clang++ ${I_LIBRARIES} ${I_LINK} -o ${O_LINK}

0
command/linux/setup.sh Executable file
View File

View File

@ -0,0 +1,7 @@
#ifndef CONTROLLER_EVENT
#define CONTROLLER_EVENT
enum controller_event_t {
start,
stop
};
#endif

View File

@ -0,0 +1,36 @@
#include "controller/root.h"
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
controller_status_t root_controller_t::on_event(controller_event_t event) {
Display *d;
Window w;
XEvent e;
const char *msg = "Hello, World!";
int s;
d = XOpenDisplay(NULL);
if (d == NULL) {
return controller_status_t::error;
}
s = DefaultScreen(d);
w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, BlackPixel(d, s), WhitePixel(d, s));
XSelectInput(d, w, ExposureMask | KeyPressMask);
XMapWindow(d, w);
while (true) {
XNextEvent(d, &e);
if (e.type == Expose) {
XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg));
}
if (e.type == KeyPress)
break;
}
XCloseDisplay(d);
return controller_status_t::ok;
}

11
compile/controller/root.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef CONTROLLER_ROOT
#define CONTROLLER_ROOT
#include "controller/status.h"
#include "controller/event.h"
class root_controller_t {
public:
controller_status_t on_event(controller_event_t event);
};
#endif

View File

@ -0,0 +1,7 @@
#ifndef CONTROLLER_STATUS
#define CONTROLLER_STATUS
enum controller_status_t {
ok,
error
};
#endif

1
compile/libraries.txt Normal file
View File

@ -0,0 +1 @@
X11

8
compile/main.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "controller/root.h"
#include "controller/status.h"
int main(int argc, char *argv[]) {
root_controller_t* controller = new root_controller_t();
controller_status_t status = controller->on_event(controller_event_t::start);
return status;
}

View File

@ -0,0 +1,2 @@
main.cpp
controller/root.cpp

BIN
earn/executable Executable file

Binary file not shown.

BIN
link/controller/root.cpp.o Normal file

Binary file not shown.

2
link/library_options.txt Normal file
View File

@ -0,0 +1,2 @@
-lX11

BIN
link/main.cpp.o Normal file

Binary file not shown.

3
link/project_files.txt Normal file
View File

@ -0,0 +1,3 @@
/home/cogentleman/main/art/cpp_launchpad/command/linux/../.././link/main.cpp.o
/home/cogentleman/main/art/cpp_launchpad/command/linux/../.././link/controller/root.cpp.o