summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--PKGBUILD12
-rw-r--r--README34
-rw-r--r--archstr.cc22
-rw-r--r--dbgmsg.cc6
-rw-r--r--getenv.cc5
-rw-r--r--include/luma/main.hh120
-rw-r--r--initgfx.cc13
-rw-r--r--kernelstr.cc34
-rw-r--r--main.cc79
-rw-r--r--msg.cc7
-rw-r--r--msgerr.cc7
-rw-r--r--msgout.cc7
-rw-r--r--setdispsrvproto.cc35
-rw-r--r--stdlibsock/gfx/crtwin.cc9
-rw-r--r--strlen.cc8
-rw-r--r--termgfx.cc5
17 files changed, 310 insertions, 102 deletions
diff --git a/Makefile b/Makefile
index d0bdab8..afabf8d 100644
--- a/Makefile
+++ b/Makefile
@@ -16,8 +16,17 @@ HDRS_CXX = \
SRCS_CXX = \
stdlibsock/gfx/crtwin.cc \
stdlibsock/gfx/destwin.cc \
+ setdispsrvproto.cc \
+ archstr.cc \
+ dbgmsg.cc \
+ getenv.cc \
initgfx.cc \
+ kernelstr.cc \
main.cc \
+ msg.cc \
+ msgerr.cc \
+ msgout.cc \
+ strlen.cc \
termgfx.cc
SRCS=$(SRCS_CXX)
OBJS=$(SRCS:.cc=.o)
diff --git a/PKGBUILD b/PKGBUILD
index e074174..a64401f 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,7 +1,7 @@
pkgname="luma"
-pkgver=x
-pkgrel=10
-arch=("any")
-license=("AGPL3")
-depends=("glm" "gmp" "libxcb" "mpfr" "wayland")
-makedepends=("vulkan-headers")
+pkgver=11
+pkgrel=1
+arch=('any')
+license=('AGPL3')
+depends=('gmp' 'libxcb' 'mpfr' 'wayland')
+makedepends=('glm' 'vulkan-headers')
diff --git a/README b/README
deleted file mode 100644
index 7f6df40..0000000
--- a/README
+++ /dev/null
@@ -1,34 +0,0 @@
-Copyright 2021 Gabriel Jensen
-
-This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-See the GNU Affero General Public License for more details.
-
-You should have received a copy of the GNU Affero General Public License along with this program.
-If not, see <https://www.gnu.org/licenses/>.
-
-IMPORTANT FORMATING INFORMATION ABOUT LITERALS:
-
-Integral literals in Luma are written in base-twelve.
-The number 10 would be written as ↊ (U+218A ↊ Turned Digit Two), and the number 11 would be written as ↋ (U+218B ↋ Turned Digit Three).
-Also, integral literals are also written as little-endian, so numbers increment to the right instead of the left.
-Down below is a short conversion table for how integral literals must be written:
- 8 -> 8
- 9 -> 9
- 10 -> ↊
- 11 -> ↋
- 12 -> 01
- 13 -> 11
- 14 -> 21
- 15 -> 31
- 16 -> 41
- 100 -> 48
- 120 -> 0↊
- 132 -> 0↋
- 144 -> 001
- 156 -> 011
- 168 -> 021
-1000 -> 4↋6
-1728 -> 0001
-Also remember that integral literals must start with '#' (U+0023 # NUMBER SIGN).
diff --git a/archstr.cc b/archstr.cc
new file mode 100644
index 0000000..b07cb32
--- /dev/null
+++ b/archstr.cc
@@ -0,0 +1,22 @@
+# include <luma/main.hh>
+char const * luma::archstr(luma::arch_t arch) {
+ char const * str = "";
+ switch(arch) {
+ default:
+ str = "Unknown";
+ break;
+ case luma::arch_t::aarch64:
+ str = "ARM64/AArch64";
+ break;
+ case luma::arch_t::amd64:
+ str = "AMD64/x86-64";
+ break;
+ case luma::arch_t::ia64:
+ str = "IA-64";
+ break;
+ case luma::arch_t::ppc64:
+ str = "PPC64";
+ break;
+ }
+ return str;
+}
diff --git a/dbgmsg.cc b/dbgmsg.cc
new file mode 100644
index 0000000..f09ebf7
--- /dev/null
+++ b/dbgmsg.cc
@@ -0,0 +1,6 @@
+# include <luma/main.hh>
+void luma::dbgmsg(char const * msg) {
+ if constexpr(debug) {
+ luma::msgerr(msg);
+ }
+}
diff --git a/getenv.cc b/getenv.cc
new file mode 100644
index 0000000..d37a35e
--- /dev/null
+++ b/getenv.cc
@@ -0,0 +1,5 @@
+# include <luma/main.hh>
+# include <unistd.h>
+char const * luma::getenv(char const * envvar) {
+ return "wayland";
+}
diff --git a/include/luma/main.hh b/include/luma/main.hh
index 11df184..9528e92 100644
--- a/include/luma/main.hh
+++ b/include/luma/main.hh
@@ -1,58 +1,102 @@
-# if __cplusplus < 202002L
-# error The compiler seems to not have support for C++20 or newer (__cplusplus is less than 202002L), which is required to build Luma.
-# endif
# if !defined(LUMA__HEADER__MAIN)
# define LUMA__HEADER__MAIN
-# if !defined(LUMA__)
-# if (defined(__DragonFlyBSD__) || defined(__FreeBSD__) || defined(__linux__))
-# define LUMA__X false
-# else
-# define LUMA__X true
-# endif
-# endif
-# include <cstdint>
-# include <iostream>
+# include <fcntl.h>
# include <luma/stdlibsock.hh>
# include <luma/stdlibsock/gfx.hh>
-# include <string>
# include <vector>
# include <vulkan/vulkan.h>
# include <wayland-client.h>
# include <xcb/xcb.h>
-using namespace std::literals::string_literals;
+// enum class -> class -> operator -> constexpr -> function -> variable -> inline function
namespace luma {
- bool constexpr debug =
-# if defined(NDEBUG)
- false;
-# else
- true;
-# endif
- bool constexpr usex = LUMA__X;
- void inline dbgmsg(char const * msg) {
- if constexpr(debug) {
- std::cerr << msg;
- }
- }
- void initgfx();
- void termgfx();
+ enum class arch_t {
+ aarch64,
+ amd64,
+ ia64,
+ ppc64,
+ unknown,
+ };
+ enum class dispsrvproto_t {
+ unknown,
+ wayland,
+ x,
+ };
+ enum class kernel_t {
+ darwinos,
+ dragonflybsd,
+ freebsd,
+ hurd,
+ linux,
+ minix,
+ netbsd,
+ openbsd,
+ unknown,
+ };
class dat_t {
- private:
+ public:
bool gfxisinit;
+ luma::dispsrvproto_t dispsrvproto= luma::dispsrvproto_t::wayland;
std::vector<VkExtensionProperties> vkexts;
std::vector<VkPhysicalDevice> vkphysdevs;
- ::VkApplicationInfo vkappinf {};
+ ::VkApplicationInfo vkappinf {};
::VkInstance vkinst;
::VkInstanceCreateInfo vkinstcrtinf {};
::VkResult vkreslt;
- ::wl_buffer * wlbuff = nullptr;
- ::wl_display * wldisp = nullptr;
- ::wl_shell_surface * wlsurf = nullptr;
- ::xcb_connection_t * xconn = nullptr;
- ::xcb_screen_t * xscrn = nullptr;
+ ::wl_buffer * wlbuff = nullptr;
+ ::wl_display * wldisp = nullptr;
+ ::wl_shell_surface * wlsurf = nullptr;
+ ::xcb_connection_t * xconn = nullptr;
+ ::xcb_screen_t * xscrn = nullptr;
::xcb_window_t xwin;
- friend void luma::initgfx();
- friend std::uint8_t luma::stdlibsock::gfx::crtwin(std::basic_string<char> nm,std::uint16_t pos_x,std::uint16_t pos_y,std::uint16_t res_x,std::uint16_t res_y,bool flscrn);
- friend void luma::termgfx();
} extern dat;
+ bool constexpr debug =
+# if defined(NDEBUG)
+ false;
+# else
+ true;
+# endif
+ luma::arch_t constexpr arch = luma::arch_t::
+# if defined(__aarch64__)
+ aarch64;
+# elif (defined(_M_AMD64) || defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(x86_64__))
+ amd64;
+# elif (defined(_IA64) defined(_M_IA64) || defined(__IA64__) || defined(__ia64__) || defined(__itanium__))
+ ia64;
+# elif (defined(_ARCH_PPC64) || defined(__powerpc64__) || defined(__PPC64__) || defined(__ppc64__))
+ ppc64;
+# else
+ unknown;
+# endif
+ luma::kernel_t constexpr kernel = luma::kernel_t::
+# if defined(__APPLE__)
+ darwinos;
+# elif defined(__DragonFly__)
+ dragonflybsd;
+# elif defined(__FreeBSD__)
+ freebsd;
+# elif (defined(__GNU__) || defined(__gnu_hurd__))
+ hurd;
+# elif defined(__linux__)
+ linux;
+# elif defined(__minix)
+ minix;
+# elif defined(__NetBSD__)
+ netbsd;
+# elif defined(__OpenBSD__)
+ openbsd;
+# else
+ unknown;
+# endif
+ char const * archstr(luma::arch_t arch);
+ char const * getenv(char const * envvar);
+ char const * kernelstr(luma::kernel_t kernel);
+ int strlen(char const * str);
+ void dbgmsg(char const * msg);
+ void initgfx();
+ void msg(int pipe,char const * msg);
+ void msgerr(char const * msg);
+ void msgout(char const * msg);
+ void setdispsrvproto();
+ void termgfx();
}
# endif
diff --git a/initgfx.cc b/initgfx.cc
index 01bd016..ee583c2 100644
--- a/initgfx.cc
+++ b/initgfx.cc
@@ -1,12 +1,12 @@
# include <luma/main.hh>
-# include <cstdint>
-# include <string>
# include <vulkan/vulkan.h>
# include <wayland-client.h>
# include <xcb/xcb.h>
void luma::initgfx() {
luma::dat.gfxisinit = true;
- if constexpr(luma::usex == 0x1) {
+ // Determine if X should be used or if Wayland is da way.
+ luma::setdispsrvproto();
+ if(luma::dat.dispsrvproto == luma::dispsrvproto_t::x) {
luma::dbgmsg("Creating X connection... ");
luma::dat.xconn = xcb_connect(nullptr,nullptr);
luma::dat.xscrn = xcb_setup_roots_iterator(xcb_get_setup(luma::dat.xconn)).data;
@@ -23,6 +23,7 @@ void luma::initgfx() {
luma::dbgmsg("O.K.\n");
}
}
+ // Set data required by Vulkan.
luma::dat.vkappinf.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
luma::dat.vkappinf.pApplicationName = "Luma Standard Library";
luma::dat.vkappinf.pEngineName = "Luma Standard Library";
@@ -31,7 +32,7 @@ void luma::initgfx() {
luma::dat.vkinstcrtinf.enabledLayerCount = 0x0;
luma::dbgmsg("Creating Vulkan instance... ");
luma::dat.vkreslt = vkCreateInstance(&luma::dat.vkinstcrtinf,nullptr,&luma::dat.vkinst);
- if((luma::dat.vkreslt != VK_SUCCESS)) {
+ if(luma::dat.vkreslt != VK_SUCCESS) {
luma::dbgmsg("Error\n");
}
else {
@@ -40,12 +41,12 @@ void luma::initgfx() {
std::uint32_t extcount = 0x0;
luma::dat.vkexts = std::vector<VkExtensionProperties>(extcount);
::vkEnumerateInstanceExtensionProperties(nullptr,&extcount,luma::dat.vkexts.data());
- luma::dbgmsg(std::basic_string<char> {std::to_string(extcount) + " Vulkan extensions supported.\n"s}.c_str());
+ luma::dbgmsg(std::basic_string<char> {std::to_string(extcount) + " Vulkan extensions supported.\n"}.c_str());
luma::dbgmsg("The following Vulkan extensions are supported:\n");
for(auto const & ext : luma::dat.vkexts) {
luma::dbgmsg(ext.extensionName);
}
std::uint32_t devcount = 0x0;
::vkEnumeratePhysicalDevices(luma::dat.vkinst,&devcount,luma::dat.vkphysdevs.data());
- luma::dbgmsg(std::basic_string<char> {std::to_string(devcount) + " Vulkan-compatible device(s) found.\n"s}.c_str());
+ luma::dbgmsg(std::basic_string<char> {std::to_string(devcount) + " Vulkan-compatible device(s) found.\n"}.c_str());
}
diff --git a/kernelstr.cc b/kernelstr.cc
new file mode 100644
index 0000000..9b4aa0c
--- /dev/null
+++ b/kernelstr.cc
@@ -0,0 +1,34 @@
+# include <luma/main.hh>
+char const * luma::kernelstr(luma::kernel_t kernel) {
+ char const * str = "";
+ switch(kernel) {
+ default:
+ str = "Unknown";
+ break;
+ case luma::kernel_t::darwinos:
+ str = "Dawin OS";
+ break;
+ case luma::kernel_t::dragonflybsd:
+ str = "DragonFly BSD";
+ break;
+ case luma::kernel_t::freebsd:
+ str = "FreeBSD";
+ break;
+ case luma::kernel_t::hurd:
+ str = "Hurd";
+ break;
+ case luma::kernel_t::linux:
+ str = "Linux";
+ break;
+ case luma::kernel_t::minix:
+ str = "MINIX";
+ break;
+ case luma::kernel_t::netbsd:
+ str = "NetBSD";
+ break;
+ case luma::kernel_t::openbsd:
+ str = "OpenBSD";
+ break;
+ }
+ return str;
+}
diff --git a/main.cc b/main.cc
index b1d442e..9ba77f6 100644
--- a/main.cc
+++ b/main.cc
@@ -1,20 +1,79 @@
-# include <cstdlib>
-# include <iostream>
+# include <fcntl.h>
# include <luma/main.hh>
-# include <string>
# include <unistd.h>
luma::dat_t luma::dat;
int main(int argc, char * * argv) {
if(argc < 0x2) {
- std::cout << "Missing argument \"file\".\n";
- std::exit(EXIT_FAILURE);
+ luma::msgerr("Missing argument \"file\".\n");
+ ::_exit(0x1);
}
- if((::access(argv[0x1], F_OK) == 0x0)) {
- luma::stdlibsock::gfx::crtwin("luma test"s,0x0,0x0,0x400,0x300,false);
+ luma::msgout(luma::archstr(luma::arch));
+ luma::msgout(luma::kernelstr(luma::kernel));
+ if(!::access(argv[0x1],R_OK)) {
+ int lumafile = ::open(argv[0x1],O_RDONLY);
+ /*
+ char16_t const * alphtokens {
+ u'\u0061', // a
+ u'\u0062', // b
+ u'\u0063', // c
+ u'\u0064', // d
+ u'\u0065', // e
+ u'\u0066', // f
+ u'\u0067', // g
+ u'\u0068', // h
+ u'\u0069', // i
+ u'\u006a', // j
+ u'\u006b', // k
+ u'\u006c', // l
+ u'\u006d', // m
+ u'\u006e', // n
+ u'\u006f', // o
+ u'\u0070', // p
+ u'\u0071', // q
+ u'\u0072', // r
+ u'\u0073', // s
+ u'\u0074', // t
+ u'\u0075', // u
+ u'\u0076', // v
+ u'\u0077', // w
+ u'\u0078', // x
+ u'\u0079', // y
+ u'\u007a' // z
+ };
+ char16_t const * alphtokens {
+ u'\u0028', // (
+ u'\u0029', // )
+ u'\u002b', // +
+ u'\u00d7', // ×
+ u'\u00f7', // ÷
+ u'\u2044', // ⁄
+ u'\u2212', //
+ u'\u221a', // −
+ u'\u2329', // 〈
+ u'\u232a' // 〉
+ };
+ char16_t const * alphtokens {
+ u'\u0030', // 0
+ u'\u0031', // 1
+ u'\u0032', // 2
+ u'\u0033', // 3
+ u'\u0034', // 4
+ u'\u0035', // 5
+ u'\u0036', // 6
+ u'\u0037', // 7
+ u'\u0038', // 8
+ u'\u0039', // 9
+ u'\u218a', // ↊
+ u'\u218b' // ↋
+ };
+ */
+ while(lumafile) {
+ luma::stdlibsock::gfx::crtwin("luma test",0x0,0x0,0x400,0x300,false);
+ }
}
else {
- std::cout << "The file doesn't exist.\n";
- std::exit(EXIT_FAILURE);
+ luma::msgerr("The file doesn't exist.\n");
+ ::_exit(0x1);
}
- std::exit(EXIT_SUCCESS);
+ ::_exit(0x0);
}
diff --git a/msg.cc b/msg.cc
new file mode 100644
index 0000000..94ce824
--- /dev/null
+++ b/msg.cc
@@ -0,0 +1,7 @@
+# include <fcntl.h>
+# include <luma/main.hh>
+# include <unistd.h>
+void luma::msg(int pipe,char const * msg) {
+ if(::write(pipe,msg,luma::strlen(msg)) > 0x0) {
+ }
+}
diff --git a/msgerr.cc b/msgerr.cc
new file mode 100644
index 0000000..b0f601b
--- /dev/null
+++ b/msgerr.cc
@@ -0,0 +1,7 @@
+# include <fcntl.h>
+# include <luma/main.hh>
+# include <unistd.h>
+void luma::msgerr(char const * msg) {
+ int pipe = ::open("/dev/stderr",O_WRONLY);
+ return luma::msg(pipe,msg);
+}
diff --git a/msgout.cc b/msgout.cc
new file mode 100644
index 0000000..e26dcdd
--- /dev/null
+++ b/msgout.cc
@@ -0,0 +1,7 @@
+# include <fcntl.h>
+# include <luma/main.hh>
+# include <unistd.h>
+void luma::msgout(char const * msg) {
+ int pipe = ::open("/dev/stdout",O_WRONLY);
+ return luma::msg(pipe,msg);
+}
diff --git a/setdispsrvproto.cc b/setdispsrvproto.cc
new file mode 100644
index 0000000..3cd2d59
--- /dev/null
+++ b/setdispsrvproto.cc
@@ -0,0 +1,35 @@
+# include <luma/main.hh>
+void luma::setdispsrvproto() {
+ luma::dat.dispsrvproto = luma::dispsrvproto_t::wayland;
+# if 0
+ char const * envval = luma::getenv("LUMA__DISPSRVPROTO");
+ if(envval != "") {
+ if(envval == "x") {
+ luma::dbgmsg("Setting the display server protocol to X.\n");
+ luma::dat.dispsrvproto = luma::dispsrvproto_t::x;
+ }
+ else if(envval == "wayland") {
+ luma::dbgmsg("Setting the display server protocol to Wayland.\n");
+ luma::dat.dispsrvproto = luma::dispsrvproto_t::wayland;
+ }
+ else {
+ //std::cerr << "$LUMA__DISPSRVPROTO is set to \"" + envval + "\", which is an unrecognized display server protocol.\n";
+ }
+ }
+ else {
+ luma::dbgmsg("Getting current display server protocol.\n");
+ std::string xdgsesstype = std::getenv("XDG_SESSION_TYPE");
+ if(xdgsesstype == "wayland") {
+ luma::dbgmsg("It appears to be Wayland.\n");
+ luma::dat.dispsrvproto = luma::dispsrvproto_t::wayland;
+ }
+ else if(xdgsesstype == "x11") {
+ luma::dbgmsg("It appears to be X.\n");
+ luma::dat.dispsrvproto = luma::dispsrvproto_t::x;
+ }
+ else {
+ luma::dbgmsg("Error\n");
+ }
+ }
+# endif
+}
diff --git a/stdlibsock/gfx/crtwin.cc b/stdlibsock/gfx/crtwin.cc
index 3e6f235..884eb24 100644
--- a/stdlibsock/gfx/crtwin.cc
+++ b/stdlibsock/gfx/crtwin.cc
@@ -13,9 +13,11 @@ std::uint8_t luma::stdlibsock::gfx::crtwin(std::basic_string<char> nm,std::uint1
luma::initgfx();
}
if(flscrn) {
- std::cout << "Fullscreen is not supported yet!\n";
+ std::cerr << "Fullscreen is not supported yet!\n";
}
- if constexpr(luma::usex == 0x1) {
+ if(luma::dat.dispsrvproto == luma::dispsrvproto_t::wayland) {
+ }
+ else if(luma::dat.dispsrvproto == luma::dispsrvproto_t::x) {
luma::dbgmsg("Creating X window... ");
::xcb_create_window(luma::dat.xconn,XCB_COPY_FROM_PARENT,luma::dat.xwin,luma::dat.xscrn->root,pos_y,pos_x,res_x,res_y,0xa,XCB_WINDOW_CLASS_INPUT_OUTPUT,luma::dat.xscrn->root_visual,0x0,nullptr);
::xcb_change_property(luma::dat.xconn,XCB_PROP_MODE_REPLACE,luma::dat.xwin,XCB_ATOM_WM_NAME,XCB_ATOM_STRING,0x8,nm.size(),nm.c_str());
@@ -23,9 +25,6 @@ std::uint8_t luma::stdlibsock::gfx::crtwin(std::basic_string<char> nm,std::uint1
::xcb_flush(luma::dat.xconn);
luma::dbgmsg("O.K.\n");
}
- else {
- }
- std::cout <<
::sleep(0x6);
luma::termgfx();
return 0x0;
diff --git a/strlen.cc b/strlen.cc
new file mode 100644
index 0000000..ef81b91
--- /dev/null
+++ b/strlen.cc
@@ -0,0 +1,8 @@
+# include <luma/main.hh>
+int luma::strlen(char const * str) {
+ int len = 0x0;
+ while(str[len] != '\0') {
+ ++len;
+ }
+ return len;
+}
diff --git a/termgfx.cc b/termgfx.cc
index 1df3547..240c1b7 100644
--- a/termgfx.cc
+++ b/termgfx.cc
@@ -1,14 +1,13 @@
-# include <cstdint>
# include <luma/main.hh>
# include <vulkan/vulkan.h>
# include <wayland-client.h>
# include <xcb/xcb.h>
void luma::termgfx() {
::vkDestroyInstance(luma::dat.vkinst,nullptr);
- if constexpr(luma::usex == 0x1) {
+ if(luma::dat.dispsrvproto == luma::dispsrvproto_t::x) {
::xcb_disconnect(luma::dat.xconn);
}
- else {
+ else if(luma::dat.dispsrvproto == luma::dispsrvproto_t::wayland) {
::wl_display_disconnect(luma::dat.wldisp);
}
}