2023-02-27 16:24:28 +01:00
# define WLR_USE_UNSTABLE
# include <unistd.h>
# include <any>
2023-04-27 00:44:12 +02:00
# include <hyprland/src/Compositor.hpp>
2024-03-20 04:02:10 +01:00
# include <hyprland/src/desktop/Window.hpp>
2023-04-27 00:44:12 +02:00
# include <hyprland/src/config/ConfigManager.hpp>
2023-02-27 16:24:28 +01:00
# include "borderDeco.hpp"
# include "globals.hpp"
// Do NOT change this function.
2023-02-28 13:06:21 +01:00
APICALL EXPORT std : : string PLUGIN_API_VERSION ( ) {
return HYPRLAND_API_VERSION ;
}
2023-02-27 16:24:28 +01:00
void onNewWindow ( void * self , std : : any data ) {
// data is guaranteed
2024-04-27 14:03:46 +02:00
const auto PWINDOW = std : : any_cast < PHLWINDOW > ( data ) ;
2023-02-27 16:24:28 +01:00
2023-11-11 15:39:46 +01:00
HyprlandAPI : : addWindowDecoration ( PHANDLE , PWINDOW , std : : make_unique < CBordersPlusPlus > ( PWINDOW ) ) ;
2023-02-27 16:24:28 +01:00
}
APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT ( HANDLE handle ) {
PHANDLE = handle ;
2023-10-19 15:12:55 +02:00
const std : : string HASH = __hyprland_api_get_hash ( ) ;
if ( HASH ! = GIT_COMMIT_HASH ) {
HyprlandAPI : : addNotification ( PHANDLE , " [borders-plus-plus] Failure in initialization: Version mismatch (headers ver is not equal to running hyprland ver) " ,
2024-12-04 15:58:09 +01:00
CHyprColor { 1.0 , 0.2 , 0.2 , 1.0 } , 5000 ) ;
2023-10-19 15:12:55 +02:00
throw std : : runtime_error ( " [bpp] Version mismatch " ) ;
}
2024-02-18 16:30:21 +01:00
HyprlandAPI : : addConfigValue ( PHANDLE , " plugin:borders-plus-plus:add_borders " , Hyprlang : : INT { 1 } ) ;
HyprlandAPI : : addConfigValue ( PHANDLE , " plugin:borders-plus-plus:natural_rounding " , Hyprlang : : INT { 1 } ) ;
2023-10-19 15:43:54 +02:00
for ( size_t i = 0 ; i < 9 ; + + i ) {
2024-11-19 22:45:50 +01:00
HyprlandAPI : : addConfigValue ( PHANDLE , " plugin:borders-plus-plus:col.border_ " + std : : to_string ( i + 1 ) , Hyprlang : : INT { * configStringToInt ( " rgba(000000ee) " ) } ) ;
2024-02-18 16:30:21 +01:00
HyprlandAPI : : addConfigValue ( PHANDLE , " plugin:borders-plus-plus:border_size_ " + std : : to_string ( i + 1 ) , Hyprlang : : INT { - 1 } ) ;
2023-10-19 15:43:54 +02:00
}
2023-02-27 16:24:28 +01:00
2023-11-11 15:39:46 +01:00
HyprlandAPI : : reloadConfig ( ) ;
2024-04-22 16:57:18 +02:00
static auto P = HyprlandAPI : : registerCallbackDynamic ( PHANDLE , " openWindow " , [ & ] ( void * self , SCallbackInfo & info , std : : any data ) { onNewWindow ( self , data ) ; } ) ;
2023-02-27 16:24:28 +01:00
// add deco to existing windows
for ( auto & w : g_pCompositor - > m_vWindows ) {
if ( w - > isHidden ( ) | | ! w - > m_bIsMapped )
continue ;
2024-04-27 14:03:46 +02:00
HyprlandAPI : : addWindowDecoration ( PHANDLE , w , std : : make_unique < CBordersPlusPlus > ( w ) ) ;
2023-02-27 16:24:28 +01:00
}
2024-12-04 15:58:09 +01:00
HyprlandAPI : : addNotification ( PHANDLE , " [borders-plus-plus] Initialized successfully! " , CHyprColor { 0.2 , 1.0 , 0.2 , 1.0 } , 5000 ) ;
2023-02-27 16:24:28 +01:00
2023-02-28 13:06:21 +01:00
return { " borders-plus-plus " , " A plugin to add more borders to windows. " , " Vaxry " , " 1.0 " } ;
2023-02-27 16:24:28 +01:00
}
2023-02-28 13:06:21 +01:00
APICALL EXPORT void PLUGIN_EXIT ( ) {
;
2024-11-19 22:45:50 +01:00
}