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,8 +7,8 @@
#pragma once
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glew.h>
#include <GL/glx.h>
typedef struct

View File

@ -8,15 +8,13 @@
#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;

View File

@ -7,16 +7,16 @@
#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
@ -28,8 +28,7 @@ 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)
{
int glx_is_extension_supported(const char* list, const char* extension) {
const char* start;
const char *where, *terminator;
@ -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,15 +55,13 @@ 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);
return 0;
}
int xoverlay_glx_create_window()
{
int xoverlay_glx_create_window() {
GLint attribs[] = { GLX_X_RENDERABLE,
GL_TRUE,
GLX_DRAWABLE_TYPE,
@ -93,39 +89,32 @@ int xoverlay_glx_create_window()
int fbc_count;
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_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)
{
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);
@ -138,19 +127,13 @@ int xoverlay_glx_create_window()
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.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,
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)
{
if (xoverlay_library.window == 0) {
return -1;
}
@ -159,8 +142,7 @@ int xoverlay_glx_create_window()
XShapeSelectInput(xoverlay_library.display, xoverlay_library.window,
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);
@ -174,25 +156,20 @@ int xoverlay_glx_create_window()
const char* extensions = glXQueryExtensionsString(xoverlay_library.display,
xoverlay_library.screen);
glXCreateContextAttribsARBfn glXCreateContextAttribsARB =
(glXCreateContextAttribsARBfn) glXGetProcAddressARB(
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_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))
@ -200,14 +177,12 @@ int xoverlay_glx_create_window()
glXMakeCurrent(xoverlay_library.display, xoverlay_library.window,
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(
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB(
(const GLubyte*)"glXSwapIntervalEXT");
if (glXSwapIntervalEXT)
glXSwapIntervalEXT(xoverlay_library.display, xoverlay_library.window,
@ -217,7 +192,6 @@ int xoverlay_glx_create_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,8 +73,7 @@ void xoverlay_hide()
xoverlay_library.mapped = 0;
}
void xoverlay_draw_begin()
{
void xoverlay_draw_begin() {
if (!xoverlay_library.init)
return;
xoverlay_library.drawing = 1;
@ -93,8 +82,7 @@ void xoverlay_draw_begin()
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);