Reformatted Source files

This commit is contained in:
Rebekah 2022-04-04 18:19:35 -04:00
parent 9a97f428b0
commit 48bcf8c313
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5
5 changed files with 127 additions and 251 deletions

View File

@ -1,84 +0,0 @@
#!/bin/bash
#
# clang-format-all: a tool to run clang-format on an entire project
# Copyright (C) 2016 Evan Klitzke <evan@eklitzke.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
function usage {
echo "Usage: $0 DIR..."
exit 1
}
if [ $# -eq 0 ]; then
usage
fi
# Variable that will hold the name of the clang-format command
FMT=""
# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
# that the version number be part of the command. We prefer clang-format if
# that's present, otherwise we work backwards from highest version to lowest
# version.
for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do
if which "$clangfmt" &>/dev/null; then
FMT="$clangfmt"
break
fi
done
# Check if we found a working clang-format
if [ -z "$FMT" ]; then
echo "failed to find clang-format"
exit 1
fi
# Check all of the arguments first to make sure they're all directories
for dir in "$@"; do
if [ ! -d "${dir}" ]; then
echo "${dir} is not a directory"
usage
fi
done
# Find a dominating file, starting from a given directory and going up.
find-dominating-file() {
if [ -r "$1"/"$2" ]; then
return 0
fi
if [ "$1" = "/" ]; then
return 1
fi
find-dominating-file "$(realpath "$1"/..)" "$2"
return $?
}
# Run clang-format -i on all of the things
for dir in "$@"; do
pushd "${dir}" &>/dev/null
if ! find-dominating-file . .clang-format; then
echo "Failed to find dominating .clang-format starting at $PWD"
continue
fi
find . \
\( -name '*.c' \
-o -name '*.cc' \
-o -name '*.cpp' \
-o -name '*.h' \
-o -name '*.hh' \
-o -name '*.hpp' \) \
-exec "${FMT}" -i '{}' \;
popd &>/dev/null
done

View File

@ -7,11 +7,11 @@
#pragma once
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glew.h>
#include <GL/glx.h>
typedef struct
typedef struct
{
int version_major;
int version_minor;

View File

@ -8,50 +8,48 @@
#pragma once
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/Xlib.h>
struct xoverlay_library
struct xoverlay_library {
Display* display;
Window window;
Colormap colormap;
GC gc;
XGCValues gcvalues;
XFontStruct font;
int screen;
int width;
int height;
struct
{
Display *display;
Window window;
Colormap colormap;
GC gc;
XGCValues gcvalues;
XFontStruct font;
int screen;
int x;
int y;
} mouse;
int width;
int height;
char init;
char drawing;
char mapped;
};
struct
{
int x;
int y;
} mouse;
extern struct xoverlay_library xoverlay_library;
char init;
char drawing;
char mapped;
};
int xoverlay_init();
extern struct xoverlay_library xoverlay_library;
void xoverlay_destroy();
int xoverlay_init();
void xoverlay_show();
void xoverlay_destroy();
void xoverlay_hide();
void xoverlay_show();
void xoverlay_draw_begin();
void xoverlay_hide();
void xoverlay_draw_begin();
void xoverlay_draw_end();
void xoverlay_draw_end();
#ifdef __cplusplus
}

View File

@ -7,30 +7,29 @@
#include "internal/drawglx.h"
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glew.h>
#include <GL/glx.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <xoverlay.h>
#include <X11/extensions/shape.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/shape.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <xoverlay.h>
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
typedef GLXContext (*glXCreateContextAttribsARBfn)(Display *, GLXFBConfig,
GLXContext, Bool,
const int *);
typedef GLXContext (*glXCreateContextAttribsARBfn)(Display*, GLXFBConfig,
GLXContext, Bool,
const int*);
xoverlay_glx_state glx_state;
// Helper to check for extension string presence. Adapted from:
// http://www.opengl.org/resources/features/OGLextensions/
int glx_is_extension_supported(const char *list, const char *extension)
{
const char *start;
int glx_is_extension_supported(const char* list, const char* extension) {
const char* start;
const char *where, *terminator;
where = strchr(extension, ' ');
@ -38,8 +37,7 @@ int glx_is_extension_supported(const char *list, const char *extension)
return 0;
start = list;
while (1)
{
while (1) {
where = strstr(start, extension);
if (!where)
@ -57,167 +55,143 @@ int glx_is_extension_supported(const char *list, const char *extension)
return 0;
}
int xoverlay_glx_init()
{
int xoverlay_glx_init() {
glXQueryVersion(xoverlay_library.display, &glx_state.version_major,
&glx_state.version_minor);
&glx_state.version_minor);
return 0;
}
int xoverlay_glx_create_window()
{
int xoverlay_glx_create_window() {
GLint attribs[] = { GLX_X_RENDERABLE,
GL_TRUE,
GLX_DRAWABLE_TYPE,
GLX_WINDOW_BIT,
GLX_RENDER_TYPE,
GLX_RGBA_BIT,
GLX_X_VISUAL_TYPE,
GLX_TRUE_COLOR,
GLX_DEPTH_SIZE,
24,
GLX_STENCIL_SIZE,
8,
GLX_RED_SIZE,
8,
GLX_GREEN_SIZE,
8,
GLX_BLUE_SIZE,
8,
GLX_ALPHA_SIZE,
8,
GLX_DOUBLEBUFFER,
GL_TRUE,
None };
GL_TRUE,
GLX_DRAWABLE_TYPE,
GLX_WINDOW_BIT,
GLX_RENDER_TYPE,
GLX_RGBA_BIT,
GLX_X_VISUAL_TYPE,
GLX_TRUE_COLOR,
GLX_DEPTH_SIZE,
24,
GLX_STENCIL_SIZE,
8,
GLX_RED_SIZE,
8,
GLX_GREEN_SIZE,
8,
GLX_BLUE_SIZE,
8,
GLX_ALPHA_SIZE,
8,
GLX_DOUBLEBUFFER,
GL_TRUE,
None };
int fbc_count;
GLXFBConfig *fbc = glXChooseFBConfig(
GLXFBConfig* fbc = glXChooseFBConfig(
xoverlay_library.display, xoverlay_library.screen, attribs, &fbc_count);
if (fbc == NULL)
{
if (fbc == NULL) {
return -1;
}
int fbc_best = -1;
int fbc_best = -1;
int fbc_best_samples = -1;
for (int i = 0; i < fbc_count; ++i)
{
XVisualInfo *info =
glXGetVisualFromFBConfig(xoverlay_library.display, fbc[i]);
for (int i = 0; i < fbc_count; ++i) {
XVisualInfo* info = glXGetVisualFromFBConfig(xoverlay_library.display, fbc[i]);
if (info->depth != 32)
continue;
int samples;
glXGetFBConfigAttrib(xoverlay_library.display, fbc[i], GLX_SAMPLES,
&samples);
if (fbc_best < 0 || samples > fbc_best_samples)
{
fbc_best = i;
&samples);
if (fbc_best < 0 || samples > fbc_best_samples) {
fbc_best = i;
fbc_best_samples = samples;
}
XFree(info);
}
if (fbc_best == -1)
{
if (fbc_best == -1) {
return -1;
}
GLXFBConfig fbconfig = fbc[fbc_best];
XFree(fbc);
XVisualInfo *info =
glXGetVisualFromFBConfig(xoverlay_library.display, fbconfig);
if (info == NULL)
{
XVisualInfo* info = glXGetVisualFromFBConfig(xoverlay_library.display, fbconfig);
if (info == NULL) {
return -1;
}
Window root = DefaultRootWindow(xoverlay_library.display);
Window root = DefaultRootWindow(xoverlay_library.display);
xoverlay_library.colormap = XCreateColormap(xoverlay_library.display, root,
info->visual, AllocNone);
info->visual, AllocNone);
XSetWindowAttributes attr;
attr.background_pixel = 0x0;
attr.border_pixel = 0;
attr.save_under = 1;
attr.background_pixel = 0x0;
attr.border_pixel = 0;
attr.save_under = 1;
attr.override_redirect = 1;
attr.colormap = xoverlay_library.colormap;
attr.event_mask = 0x0;
attr.do_not_propagate_mask =
(KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
PointerMotionMask | ButtonMotionMask);
attr.colormap = xoverlay_library.colormap;
attr.event_mask = 0x0;
attr.do_not_propagate_mask = (KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ButtonMotionMask);
unsigned long mask = CWBackPixel | CWBorderPixel | CWSaveUnder |
CWOverrideRedirect | CWColormap | CWEventMask |
CWDontPropagate;
xoverlay_library.window =
XCreateWindow(xoverlay_library.display, root, 0, 0,
xoverlay_library.width, xoverlay_library.height, 0,
info->depth, InputOutput, info->visual, mask, &attr);
if (xoverlay_library.window == 0)
{
unsigned long mask = CWBackPixel | CWBorderPixel | CWSaveUnder | CWOverrideRedirect | CWColormap | CWEventMask | CWDontPropagate;
xoverlay_library.window = XCreateWindow(xoverlay_library.display, root, 0, 0,
xoverlay_library.width, xoverlay_library.height, 0,
info->depth, InputOutput, info->visual, mask, &attr);
if (xoverlay_library.window == 0) {
return -1;
}
XShapeCombineMask(xoverlay_library.display, xoverlay_library.window,
ShapeInput, 0, 0, None, ShapeSet);
ShapeInput, 0, 0, None, ShapeSet);
XShapeSelectInput(xoverlay_library.display, xoverlay_library.window,
ShapeNotifyMask);
ShapeNotifyMask);
XserverRegion region =
XFixesCreateRegion(xoverlay_library.display, NULL, 0);
XserverRegion region = XFixesCreateRegion(xoverlay_library.display, NULL, 0);
XFixesSetWindowShapeRegion(xoverlay_library.display,
xoverlay_library.window, ShapeInput, 0, 0,
region);
xoverlay_library.window, ShapeInput, 0, 0,
region);
XFixesDestroyRegion(xoverlay_library.display, region);
XFree(info);
XStoreName(xoverlay_library.display, xoverlay_library.window,
"OverlayWindow");
"OverlayWindow");
xoverlay_show();
const char *extensions = glXQueryExtensionsString(xoverlay_library.display,
xoverlay_library.screen);
glXCreateContextAttribsARBfn glXCreateContextAttribsARB =
(glXCreateContextAttribsARBfn) glXGetProcAddressARB(
(const GLubyte *) "glXCreateContextAttribsARB");
const char* extensions = glXQueryExtensionsString(xoverlay_library.display,
xoverlay_library.screen);
glXCreateContextAttribsARBfn glXCreateContextAttribsARB = (glXCreateContextAttribsARBfn)glXGetProcAddressARB(
(const GLubyte*)"glXCreateContextAttribsARB");
if (!glx_is_extension_supported(extensions, "GLX_ARB_create_context"))
{
if (!glx_is_extension_supported(extensions, "GLX_ARB_create_context")) {
glx_state.context = glXCreateNewContext(
xoverlay_library.display, fbconfig, GLX_RGBA_TYPE, NULL, GL_TRUE);
}
else
{
} else {
int ctx_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0, None };
GLX_CONTEXT_MINOR_VERSION_ARB, 0, None };
glx_state.context = glXCreateContextAttribsARB(
xoverlay_library.display, fbconfig, NULL, GL_TRUE, ctx_attribs);
XSync(xoverlay_library.display, GL_FALSE);
}
if (glx_state.context == NULL)
{
if (glx_state.context == NULL) {
return -1;
}
if (!glXIsDirect(xoverlay_library.display, glx_state.context))
;
glXMakeCurrent(xoverlay_library.display, xoverlay_library.window,
glx_state.context);
glx_state.context);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
{
if (glewInit() != GLEW_OK) {
return -1;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT =
(PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddressARB(
(const GLubyte *) "glXSwapIntervalEXT");
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB(
(const GLubyte*)"glXSwapIntervalEXT");
if (glXSwapIntervalEXT)
glXSwapIntervalEXT(xoverlay_library.display, xoverlay_library.window,
0);
0);
glXSwapBuffers(xoverlay_library.display, xoverlay_library.window);
return 0;
}
int xoverlay_glx_destroy()
{
int xoverlay_glx_destroy() {
return 0;
}

View File

@ -8,11 +8,11 @@
#include "internal/drawglx.h"
#include <GL/glx.h>
#include <X11/extensions/shape.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/shape.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <xoverlay.h>
int event_ShapeNotify;
@ -21,34 +21,27 @@ struct xoverlay_library xoverlay_library;
int preinit_done = 0;
int xoverlay_init()
{
int xoverlay_init() {
memset(&xoverlay_library, 0, sizeof(struct xoverlay_library));
xoverlay_library.display = XOpenDisplay(NULL);
if (xoverlay_library.display == NULL)
{
if (xoverlay_library.display == NULL) {
return -2;
}
xoverlay_library.screen = DefaultScreen(xoverlay_library.display);
xoverlay_library.width =
DisplayWidth(xoverlay_library.display, xoverlay_library.screen);
xoverlay_library.height =
DisplayHeight(xoverlay_library.display, xoverlay_library.screen);
xoverlay_library.width = DisplayWidth(xoverlay_library.display, xoverlay_library.screen);
xoverlay_library.height = DisplayHeight(xoverlay_library.display, xoverlay_library.screen);
if (!XShapeQueryExtension(xoverlay_library.display, &event_ShapeNotify,
&event_ShapeError))
{
&event_ShapeError)) {
return -3;
}
if (xoverlay_glx_init() < 0)
{
if (xoverlay_glx_init() < 0) {
return -4;
}
if (xoverlay_glx_create_window() < 0)
{
if (xoverlay_glx_create_window() < 0) {
return -5;
}
@ -57,16 +50,14 @@ int xoverlay_init()
return 0;
}
void xoverlay_destroy()
{
void xoverlay_destroy() {
XDestroyWindow(xoverlay_library.display, xoverlay_library.window);
XCloseDisplay(xoverlay_library.display);
xoverlay_glx_destroy();
xoverlay_library.init = 0;
}
void xoverlay_show()
{
void xoverlay_show() {
if (xoverlay_library.mapped == 1)
return;
@ -74,8 +65,7 @@ void xoverlay_show()
xoverlay_library.mapped = 1;
}
void xoverlay_hide()
{
void xoverlay_hide() {
if (xoverlay_library.mapped == 0)
return;
@ -83,18 +73,16 @@ void xoverlay_hide()
xoverlay_library.mapped = 0;
}
void xoverlay_draw_begin()
{
void xoverlay_draw_begin() {
if (!xoverlay_library.init)
return;
xoverlay_library.drawing = 1;
glXMakeCurrent(xoverlay_library.display, xoverlay_library.window,
glx_state.context);
glx_state.context);
glClear(GL_COLOR_BUFFER_BIT);
}
void xoverlay_draw_end()
{
void xoverlay_draw_end() {
if (!xoverlay_library.init)
return;
glXSwapBuffers(xoverlay_library.display, xoverlay_library.window);