chore: improve formating
This commit is contained in:
@@ -7,21 +7,18 @@
|
|||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define WIDTH 1920
|
#define WIDTH 1920
|
||||||
#define HEIGHT 1080
|
#define HEIGHT 1080
|
||||||
|
|
||||||
char *hyprland_socket_path;
|
char *hyprland_socket_path;
|
||||||
|
|
||||||
Vector2 hyprland_get_cursor_position()
|
Vector2 hyprland_get_cursor_position() {
|
||||||
{
|
|
||||||
Vector2 pos = {0};
|
Vector2 pos = {0};
|
||||||
|
|
||||||
int sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
int sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sock_fd == -1)
|
if (sock_fd == -1) {
|
||||||
{
|
|
||||||
perror("socket");
|
perror("socket");
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
@@ -30,8 +27,7 @@ Vector2 hyprland_get_cursor_position()
|
|||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
strncpy(addr.sun_path, hyprland_socket_path, sizeof(addr.sun_path) - 1);
|
strncpy(addr.sun_path, hyprland_socket_path, sizeof(addr.sun_path) - 1);
|
||||||
|
|
||||||
if (connect(sock_fd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
|
if (connect(sock_fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
|
||||||
{
|
|
||||||
printf("Using hyprland socket: %s\n", hyprland_socket_path);
|
printf("Using hyprland socket: %s\n", hyprland_socket_path);
|
||||||
perror("connect");
|
perror("connect");
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
@@ -39,8 +35,7 @@ Vector2 hyprland_get_cursor_position()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *message = "/cursorpos";
|
const char *message = "/cursorpos";
|
||||||
if (send(sock_fd, message, strlen(message), 0) == -1)
|
if (send(sock_fd, message, strlen(message), 0) == -1) {
|
||||||
{
|
|
||||||
perror("send");
|
perror("send");
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
return pos;
|
return pos;
|
||||||
@@ -48,8 +43,7 @@ Vector2 hyprland_get_cursor_position()
|
|||||||
|
|
||||||
char buffer[256] = {0};
|
char buffer[256] = {0};
|
||||||
ssize_t bytes_received = recv(sock_fd, buffer, sizeof(buffer) - 1, 0);
|
ssize_t bytes_received = recv(sock_fd, buffer, sizeof(buffer) - 1, 0);
|
||||||
if (bytes_received == -1)
|
if (bytes_received == -1) {
|
||||||
{
|
|
||||||
perror("recv");
|
perror("recv");
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
return pos;
|
return pos;
|
||||||
@@ -58,8 +52,7 @@ Vector2 hyprland_get_cursor_position()
|
|||||||
// format is x, y so parse here
|
// format is x, y so parse here
|
||||||
buffer[bytes_received] = '\0';
|
buffer[bytes_received] = '\0';
|
||||||
|
|
||||||
if (sscanf(buffer, "%f, %f", &pos.x, &pos.y) != 2)
|
if (sscanf(buffer, "%f, %f", &pos.x, &pos.y) != 2) {
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to parse cursor position\n");
|
fprintf(stderr, "Failed to parse cursor position\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,58 +60,51 @@ Vector2 hyprland_get_cursor_position()
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D load_texture_from_file(const char *file_path)
|
Texture2D load_texture_from_file(const char *file_path) {
|
||||||
{
|
|
||||||
Texture2D texture = {0};
|
Texture2D texture = {0};
|
||||||
|
|
||||||
if (FileExists(file_path))
|
if (FileExists(file_path)) {
|
||||||
{
|
|
||||||
texture = LoadTexture(file_path);
|
texture = LoadTexture(file_path);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
const char *system_path = TextFormat("/usr/share/wallpaper/%s", file_path);
|
const char *system_path = TextFormat("/usr/share/wallpaper/%s", file_path);
|
||||||
if (FileExists(system_path))
|
if (FileExists(system_path)) {
|
||||||
{
|
|
||||||
texture = LoadTexture(system_path);
|
texture = LoadTexture(system_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texture.id == 0)
|
if (texture.id == 0) {
|
||||||
{
|
|
||||||
TraceLog(LOG_ERROR, "Failed to load texture from file: %s", file_path);
|
TraceLog(LOG_ERROR, "Failed to load texture from file: %s", file_path);
|
||||||
}
|
}
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader load_shader_from_file(const char *vs_path, const char *fs_path)
|
Shader load_shader_from_file(const char *vs_path, const char *fs_path) {
|
||||||
{
|
|
||||||
Shader shader = {0};
|
Shader shader = {0};
|
||||||
|
|
||||||
if (FileExists(vs_path) && FileExists(fs_path))
|
if (FileExists(vs_path) && FileExists(fs_path)) {
|
||||||
{
|
|
||||||
shader = LoadShader(vs_path, fs_path);
|
shader = LoadShader(vs_path, fs_path);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
const char *system_vs_path = TextFormat("/usr/share/wallpaper/%s", vs_path);
|
const char *system_vs_path = TextFormat("/usr/share/wallpaper/%s", vs_path);
|
||||||
const char *system_fs_path = TextFormat("/usr/share/wallpaper/%s", fs_path);
|
const char *system_fs_path = TextFormat("/usr/share/wallpaper/%s", fs_path);
|
||||||
if (FileExists(system_vs_path) && FileExists(system_fs_path))
|
if (FileExists(system_vs_path) && FileExists(system_fs_path)) {
|
||||||
{
|
|
||||||
shader = LoadShader(system_vs_path, system_fs_path);
|
shader = LoadShader(system_vs_path, system_fs_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shader.id == 0)
|
if (shader.id == 0) {
|
||||||
{
|
|
||||||
TraceLog(LOG_ERROR, "Failed to load shader from files: %s, %s", vs_path, fs_path);
|
TraceLog(LOG_ERROR, "Failed to load shader from files: %s, %s", vs_path, fs_path);
|
||||||
}
|
}
|
||||||
return shader;
|
return shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
const char* get_window_title() {
|
||||||
{
|
return getenv("DEBUG") != NULL ? "pihkaal-wallpaper-debug" : "pihkaal-wallpaper";
|
||||||
InitWindow(WIDTH, HEIGHT, "pihkaal-wallpaper");
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
InitWindow(WIDTH, HEIGHT, get_window_title());
|
||||||
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
@@ -133,10 +119,10 @@ int main(void)
|
|||||||
// initialize shader
|
// initialize shader
|
||||||
Shader shader = load_shader_from_file("resources/shaders/basic.vs", "resources/shaders/distance_field.fs");
|
Shader shader = load_shader_from_file("resources/shaders/basic.vs", "resources/shaders/distance_field.fs");
|
||||||
|
|
||||||
int resolutionLoc = GetShaderLocation(shader, "resolution");
|
int resolutionLoc = GetShaderLocation(shader, "resolution");
|
||||||
int mousePosLoc = GetShaderLocation(shader, "mousePos");
|
int mousePosLoc = GetShaderLocation(shader, "mousePos");
|
||||||
int ballRadiusLoc = GetShaderLocation(shader, "ballRadius");
|
int ballRadiusLoc = GetShaderLocation(shader, "ballRadius");
|
||||||
int shapeInfluenceLoc = GetShaderLocation(shader, "shapeInfluence");
|
int shapeInfluenceLoc = GetShaderLocation(shader, "shapeInfluence");
|
||||||
int distanceFieldTexLoc = GetShaderLocation(shader, "distanceFieldTex");
|
int distanceFieldTexLoc = GetShaderLocation(shader, "distanceFieldTex");
|
||||||
|
|
||||||
Vector2 resolution = {WIDTH, HEIGHT};
|
Vector2 resolution = {WIDTH, HEIGHT};
|
||||||
@@ -151,13 +137,11 @@ int main(void)
|
|||||||
int textureUnit = 1;
|
int textureUnit = 1;
|
||||||
SetShaderValue(shader, distanceFieldTexLoc, &textureUnit, SHADER_UNIFORM_INT);
|
SetShaderValue(shader, distanceFieldTexLoc, &textureUnit, SHADER_UNIFORM_INT);
|
||||||
|
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose()) {
|
||||||
{
|
|
||||||
int screenWidth = GetScreenWidth();
|
int screenWidth = GetScreenWidth();
|
||||||
int screenHeight = GetScreenHeight();
|
int screenHeight = GetScreenHeight();
|
||||||
|
|
||||||
if (IsWindowResized())
|
if (IsWindowResized()) {
|
||||||
{
|
|
||||||
UnloadRenderTexture(target);
|
UnloadRenderTexture(target);
|
||||||
target = LoadRenderTexture(screenWidth, screenHeight);
|
target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
@@ -193,4 +177,4 @@ int main(void)
|
|||||||
free(hyprland_socket_path);
|
free(hyprland_socket_path);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user