2023-08-07 13:35:19 +02:00
# pragma once
# include <cmath>
2023-08-31 22:52:02 +02:00
# include <csignal>
2024-12-19 02:56:01 +01:00
# include <print>
2023-08-07 13:35:19 +02:00
# include <utility>
2024-06-11 17:17:45 +02:00
# include "helpers/memory/Memory.hpp"
2024-04-27 13:43:12 +02:00
2023-08-07 13:35:19 +02:00
# ifndef NDEBUG
# ifdef HYPRLAND_DEBUG
# define ISDEBUG true
# else
# define ISDEBUG false
# endif
# else
# define ISDEBUG false
# endif
# define SPECIAL_WORKSPACE_START (-99)
# define PI 3.14159265358979
2023-09-12 17:46:22 +02:00
# define STRVAL_EMPTY "[[EMPTY]]"
2024-06-22 23:52:42 +02:00
# define WORKSPACE_INVALID -1L
# define WORKSPACE_NOT_CHANGED -101
2023-11-12 14:34:42 +01:00
2024-08-08 21:01:50 +02:00
# define MONITOR_INVALID -1L
2024-10-30 19:58:36 +01:00
# define MIN_WINDOW_SIZE 20.0
2023-08-07 13:35:19 +02:00
# define LISTENER(name) \
void listener_ # # name ( wl_listener * , void * ) ; \
inline wl_listener listen_ # # name = { . notify = listener_ # # name }
# define DYNLISTENFUNC(name) void listener_##name(void*, void*)
# define DYNLISTENER(name) CHyprWLListener hyprListener_##name
# define DYNMULTILISTENER(name) wl_listener listen_##name
2024-05-11 11:35:20 +02:00
# define VECINRECT(vec, x1, y1, x2, y2) ((vec).x >= (x1) && (vec).x < (x2) && (vec).y >= (y1) && (vec).y < (y2))
2023-08-07 13:35:19 +02:00
# define DELTALESSTHAN(a, b, delta) (abs((a) - (b)) < (delta))
# define STICKS(a, b) abs((a) - (b)) < 2
2024-07-13 12:36:29 +02:00
# define HYPRATOM(name) {name, 0}
2023-08-07 13:35:19 +02:00
# define RASSERT(expr, reason, ...) \
if ( ! ( expr ) ) { \
2023-09-06 12:51:36 +02:00
Debug : : log ( CRIT , " \n ========================================================================================== \n ASSERTION FAILED! \n \n {} \n \n at: line {} in {} " , \
2023-09-20 09:26:20 +02:00
std : : format ( reason , # # __VA_ARGS__ ) , __LINE__ , \
2023-12-06 23:54:56 +01:00
( [ ] ( ) constexpr - > std : : string { return std : : string ( __FILE__ ) . substr ( std : : string ( __FILE__ ) . find_last_of ( ' / ' ) + 1 ) ; } ) ( ) ) ; \
2024-12-19 02:56:01 +01:00
std : : print ( " Assertion failed! See the log in /tmp/hypr/hyprland.log for more info. " ) ; \
2023-08-31 22:52:02 +02:00
raise ( SIGABRT ) ; \
2023-08-07 13:35:19 +02:00
}
# define ASSERT(expr) RASSERT(expr, "?")
2023-09-20 17:25:03 +02:00
// absolutely ridiculous formatter spec parsing
# define FORMAT_PARSE(specs__, type__) \
template < typename FormatContext > \
constexpr auto parse ( FormatContext & ctx ) { \
auto it = ctx . begin ( ) ; \
for ( ; it ! = ctx . end ( ) & & * it ! = ' } ' ; it + + ) { \
switch ( * it ) { specs__ default : throw std : : format_error ( " invalid format specification " ) ; } \
} \
return it ; \
}
# define FORMAT_FLAG(spec__, flag__) \
2023-12-06 23:54:56 +01:00
case spec__ : ( flag__ ) = true ; break ;
2023-09-20 17:25:03 +02:00
# define FORMAT_NUMBER(buf__) \
case ' 0 ' : \
case ' 1 ' : \
case ' 2 ' : \
case ' 3 ' : \
case ' 4 ' : \
case ' 5 ' : \
case ' 6 ' : \
case ' 7 ' : \
case ' 8 ' : \
2023-12-06 23:54:56 +01:00
case ' 9 ' : ( buf__ ) . push_back ( * it ) ; break ;
2023-09-20 17:25:03 +02:00
2023-08-07 13:35:19 +02:00
# if ISDEBUG
# define UNREACHABLE() \
{ \
Debug : : log ( CRIT , " \n \n MEMORY CORRUPTED: Unreachable failed! (Reached an unreachable position, memory corruption!!!) " ) ; \
2023-08-31 22:52:02 +02:00
raise ( SIGABRT ) ; \
2023-08-07 13:35:19 +02:00
}
# else
# define UNREACHABLE() std::unreachable();
2024-06-08 10:07:59 +02:00
# endif
# define GLCALL(__CALL__) \
{ \
__CALL__ ; \
auto err = glGetError ( ) ; \
if ( err ! = GL_NO_ERROR ) { \
Debug : : log ( ERR , " [GLES] Error in call at {}@{}: 0x{:x} " , __LINE__ , \
( [ ] ( ) constexpr - > std : : string { return std : : string ( __FILE__ ) . substr ( std : : string ( __FILE__ ) . find_last_of ( ' / ' ) + 1 ) ; } ) ( ) , err ) ; \
} \
}
2024-06-19 16:20:06 +02:00
# define HYPRUTILS_FORWARD(ns, name) \
namespace Hyprutils { \
namespace ns { \
class name ; \
} \
}
2024-07-21 13:09:54 +02:00
# define AQUAMARINE_FORWARD(name) \
namespace Aquamarine { \
class name ; \
}