chore: linting

This commit is contained in:
Almamu 2024-05-05 23:48:25 +02:00
parent ca3c73740c
commit 02fd7effbb
6 changed files with 87 additions and 104 deletions

View File

@ -307,7 +307,8 @@ void CApplicationContext::printHelp (const char* route) {
sLog.out ("\t--set-property <name=value>\tOverrides the default value of the given property"); sLog.out ("\t--set-property <name=value>\tOverrides the default value of the given property");
sLog.out ("\t--no-fullscreen-pause\tPrevents the background pausing when an app is fullscreen"); sLog.out ("\t--no-fullscreen-pause\tPrevents the background pausing when an app is fullscreen");
sLog.out ("\t--disable-mouse\tDisables mouse interactions"); sLog.out ("\t--disable-mouse\tDisables mouse interactions");
sLog.out ("\t--bg <background_path/background_id>\tAfter --screen-root uses the specified background only on that screen"); sLog.out (
"\t--bg <background_path/background_id>\tAfter --screen-root uses the specified background only on that screen");
sLog.out ( sLog.out (
"\t--scaling <mode>\t Scaling mode for wallpaper. Can be stretch, fit, fill, default. Must be used before wallpaper provided.\n\ "\t--scaling <mode>\t Scaling mode for wallpaper. Can be stretch, fit, fill, default. Must be used before wallpaper provided.\n\
\t\t For default wallpaper last specified value will be used.\n\ \t\t For default wallpaper last specified value will be used.\n\

View File

@ -20,7 +20,7 @@ CProject* CProject::fromFile (const std::string& filename, CContainer* container
json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container)); json content = json::parse (WallpaperEngine::FileSystem::loadFullFile (filename, container));
std::string dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency"); std::string dependency = jsonFindDefault<std::string> (content, "dependency", "No dependency");
if(dependency=="No dependency"){ if (dependency == "No dependency") {
std::string title = *jsonFindRequired (content, "title", "Project title missing"); std::string title = *jsonFindRequired (content, "title", "Project title missing");
std::string type = *jsonFindRequired (content, "type", "Project type missing"); std::string type = *jsonFindRequired (content, "type", "Project type missing");
std::string file = *jsonFindRequired (content, "file", "Project's main file missing"); std::string file = *jsonFindRequired (content, "file", "Project's main file missing");
@ -45,7 +45,7 @@ CProject* CProject::fromFile (const std::string& filename, CContainer* container
if (general != content.end ()) { if (general != content.end ()) {
const auto properties = general->find ("properties"); const auto properties = general->find ("properties");
if (properties != general-> end ()) { if (properties != general->end ()) {
for (const auto& cur : properties->items ()) { for (const auto& cur : properties->items ()) {
Projects::CProperty* property = Projects::CProperty::fromJSON (cur.value (), cur.key ()); Projects::CProperty* property = Projects::CProperty::fromJSON (cur.value (), cur.key ());
if (property != nullptr) if (property != nullptr)
@ -54,9 +54,8 @@ CProject* CProject::fromFile (const std::string& filename, CContainer* container
} }
} }
return project; return project;
} } else {
else{ sLog.exception ("Project have dependency. They are not supported, quiting");
sLog.exception("Project have dependency. They are not supported, quiting");
} }
} }

View File

@ -1,10 +1,9 @@
#include "CWeb.h" #include "CWeb.h"
#include <utility>
#include "common.h" #include "common.h"
#include <utility>
static void CEFsetUp(int argc, char** argv) static void CEFsetUp (int argc, char** argv) {
{
// This function should be called from the application entry point function to // This function should be called from the application entry point function to
// execute a secondary process. It can be used to run secondary processes from // execute a secondary process. It can be used to run secondary processes from
// the browser client executable (default behavior) or from a separate // the browser client executable (default behavior) or from a separate
@ -15,56 +14,48 @@ static void CEFsetUp(int argc, char** argv)
// the process exit code. The |application| parameter may be empty. The // the process exit code. The |application| parameter may be empty. The
// |windows_sandbox_info| parameter is only used on Windows and may be NULL (see // |windows_sandbox_info| parameter is only used on Windows and may be NULL (see
// cef_sandbox_win.h for details). // cef_sandbox_win.h for details).
CefMainArgs args(argc,argv); CefMainArgs args (argc, argv);
int exit_code = CefExecuteProcess(args, nullptr, nullptr); int exit_code = CefExecuteProcess (args, nullptr, nullptr);
if (exit_code >= 0) if (exit_code >= 0) {
{ sLog.debug ("CEF sub proccess has endend");
sLog.debug("CEF sub proccess has endend");
// Sub proccess has endend, so exit // Sub proccess has endend, so exit
exit(exit_code); exit (exit_code);
} } else if (exit_code == -1) {
else if (exit_code == -1)
{
// If called for the browser process (identified by no "type" command-line value) // If called for the browser process (identified by no "type" command-line value)
// it will return immediately with a value of -1 // it will return immediately with a value of -1
} }
// Configurate Chromium // Configurate Chromium
CefSettings settings; CefSettings settings;
//CefString(&settings.locales_dir_path) = "OffScreenCEF/godot/locales"; // CefString(&settings.locales_dir_path) = "OffScreenCEF/godot/locales";
//CefString(&settings.resources_dir_path) = "OffScreenCEF/godot/"; // CefString(&settings.resources_dir_path) = "OffScreenCEF/godot/";
//CefString(&settings.framework_dir_path) = "OffScreenCEF/godot/"; // CefString(&settings.framework_dir_path) = "OffScreenCEF/godot/";
//CefString(&settings.cache_path) = "OffScreenCEF/godot/"; // CefString(&settings.cache_path) = "OffScreenCEF/godot/";
settings.windowless_rendering_enabled = true; settings.windowless_rendering_enabled = true;
#if defined(CEF_NO_SANDBOX) #if defined(CEF_NO_SANDBOX)
settings.no_sandbox = true; settings.no_sandbox = true;
#endif #endif
bool result = CefInitialize(args, settings, nullptr, nullptr); bool result = CefInitialize (args, settings, nullptr, nullptr);
if (!result) if (!result) {
{ sLog.error ("CefInitialize: failed");
sLog.error("CefInitialize: failed"); exit (-2);
exit(-2);
} }
} }
using namespace WallpaperEngine::Core; using namespace WallpaperEngine::Core;
const std::string& CWeb::getFilename () const std::string& CWeb::getFilename () {
{
return this->m_filename; return this->m_filename;
} }
CWeb::CWeb (std::string filename, CProject& project) : CWeb::CWeb (std::string filename, CProject& project) : CWallpaper (Type, project), m_filename (std::move (filename)) {
CWallpaper (Type, project), if (!g_CEFused) {
m_filename (std::move(filename)) sLog.debug ("Setting up CEF");
{
if(!g_CEFused) {
sLog.debug("Setting up CEF");
// char** argv = new char*("linux-wallpaper\n"); // char** argv = new char*("linux-wallpaper\n");
// CEFsetUp(1, argv); // CEFsetUp(1, argv);
// delete argv; // delete argv;
g_CEFused=true; g_CEFused = true;
} }
} }

View File

@ -1,8 +1,8 @@
#include "CWallpaper.h" #include "CWallpaper.h"
#include "CScene.h" #include "CScene.h"
#include "CVideo.h" #include "CVideo.h"
#include "common.h"
#include "CWeb.h" #include "CWeb.h"
#include "common.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
@ -25,8 +25,7 @@ CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CRend
a_TexCoord (GL_NONE), a_TexCoord (GL_NONE),
m_vaoBuffer (GL_NONE), m_vaoBuffer (GL_NONE),
m_audioContext (audioContext), m_audioContext (audioContext),
m_state (scalingMode) m_state (scalingMode) {
{
// generate the VAO to stop opengl from complaining // generate the VAO to stop opengl from complaining
glGenVertexArrays (1, &this->m_vaoBuffer); glGenVertexArrays (1, &this->m_vaoBuffer);
glBindVertexArray (this->m_vaoBuffer); glBindVertexArray (this->m_vaoBuffer);
@ -287,8 +286,8 @@ CWallpaper* CWallpaper::fromWallpaper (Core::CWallpaper* wallpaper, CRenderConte
return new WallpaperEngine::Render::CScene (wallpaper->as<Core::CScene> (), context, audioContext, scalingMode); return new WallpaperEngine::Render::CScene (wallpaper->as<Core::CScene> (), context, audioContext, scalingMode);
if (wallpaper->is<Core::CVideo> ()) if (wallpaper->is<Core::CVideo> ())
return new WallpaperEngine::Render::CVideo (wallpaper->as<Core::CVideo> (), context, audioContext, scalingMode); return new WallpaperEngine::Render::CVideo (wallpaper->as<Core::CVideo> (), context, audioContext, scalingMode);
else if (wallpaper->is <Core::CWeb> ()) else if (wallpaper->is<Core::CWeb> ())
return new WallpaperEngine::Render::CWeb (wallpaper->as <Core::CWeb> (), context, audioContext, scalingMode); return new WallpaperEngine::Render::CWeb (wallpaper->as<Core::CWeb> (), context, audioContext, scalingMode);
else else
sLog.exception ("Unsupported wallpaper type"); sLog.exception ("Unsupported wallpaper type");
} }

View File

@ -5,36 +5,35 @@
using namespace WallpaperEngine::Render; using namespace WallpaperEngine::Render;
CWeb::CWeb (Core::CWeb* web, CRenderContext& context, CAudioContext& audioContext, const CWallpaperState::TextureUVsScaling& scalingMode) : CWeb::CWeb (Core::CWeb* web, CRenderContext& context, CAudioContext& audioContext,
const CWallpaperState::TextureUVsScaling& scalingMode) :
CWallpaper (web, Type, context, audioContext, scalingMode), CWallpaper (web, Type, context, audioContext, scalingMode),
m_width (context.getOutput ().getFullWidth ()), m_width (context.getOutput ().getFullWidth ()),
m_height (context.getOutput ().getFullHeight ()), m_height (context.getOutput ().getFullHeight ()),
m_browser(), m_browser (),
m_client() m_client () {
{
// setup framebuffers // setup framebuffers
this->setupFramebuffers(); this->setupFramebuffers ();
CefWindowInfo window_info; CefWindowInfo window_info;
window_info.SetAsWindowless(0); window_info.SetAsWindowless (0);
this->m_render_handler = new RenderHandler(this); this->m_render_handler = new RenderHandler (this);
CefBrowserSettings browserSettings; CefBrowserSettings browserSettings;
//Documentaion says that 60 fps is maximum value // Documentaion says that 60 fps is maximum value
browserSettings.windowless_frame_rate = std::max(60,context.getApp().getContext().settings.render.maximumFPS); browserSettings.windowless_frame_rate = std::max (60, context.getApp ().getContext ().settings.render.maximumFPS);
m_client = new BrowserClient(m_render_handler); m_client = new BrowserClient (m_render_handler);
std::filesystem::path htmlpath = this->getWeb ()->getProject ().getContainer ()->resolveRealFile (this->getWeb ()->getFilename ()); std::filesystem::path htmlpath =
//To open local file in browser URL must be "file:///path/to/file.html" this->getWeb ()->getProject ().getContainer ()->resolveRealFile (this->getWeb ()->getFilename ());
const std::string htmlURL = std::string("file:///") + htmlpath.c_str(); // To open local file in browser URL must be "file:///path/to/file.html"
m_browser = CefBrowserHost::CreateBrowserSync(window_info, m_client.get(), const std::string htmlURL = std::string ("file:///") + htmlpath.c_str ();
htmlURL, browserSettings, m_browser =
nullptr, nullptr); CefBrowserHost::CreateBrowserSync (window_info, m_client.get (), htmlURL, browserSettings, nullptr, nullptr);
} }
void CWeb::setSize (int64_t width, int64_t height) void CWeb::setSize (int64_t width, int64_t height) {
{
this->m_width = width > 0 ? width : this->m_width; this->m_width = width > 0 ? width : this->m_width;
this->m_height = height > 0 ? height : this->m_height; this->m_height = height > 0 ? height : this->m_height;
@ -43,73 +42,67 @@ void CWeb::setSize (int64_t width, int64_t height)
return; return;
// reconfigure the texture // reconfigure the texture
glBindTexture (GL_TEXTURE_2D, this->getWallpaperTexture()); glBindTexture (GL_TEXTURE_2D, this->getWallpaperTexture ());
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, this->getWidth(), this->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, this->getWidth (), this->getHeight (), 0, GL_RGBA, GL_UNSIGNED_BYTE,
nullptr);
// Notify cef that it was resized(maybe it's not even needed) // Notify cef that it was resized(maybe it's not even needed)
m_browser->GetHost()->WasResized(); m_browser->GetHost ()->WasResized ();
} }
void CWeb::renderFrame (glm::ivec4 viewport) void CWeb::renderFrame (glm::ivec4 viewport) {
{
// ensure the virtual mouse position is up to date // ensure the virtual mouse position is up to date
this->updateMouse (viewport); this->updateMouse (viewport);
// use the scene's framebuffer by default // use the scene's framebuffer by default
glBindFramebuffer (GL_FRAMEBUFFER, this->getWallpaperFramebuffer()); glBindFramebuffer (GL_FRAMEBUFFER, this->getWallpaperFramebuffer ());
// ensure we render over the whole framebuffer // ensure we render over the whole framebuffer
glViewport (0, 0, this->getWidth (), this->getHeight ()); glViewport (0, 0, this->getWidth (), this->getHeight ());
//Cef processes all messages, including OnPaint, which renders frame // Cef processes all messages, including OnPaint, which renders frame
//If there is no OnPaint in message loop, we will not update(render) frame // If there is no OnPaint in message loop, we will not update(render) frame
// This means some frames will not have OnPaint call in cef messageLoop // This means some frames will not have OnPaint call in cef messageLoop
// Because of that glClear will result in flickering on higher fps // Because of that glClear will result in flickering on higher fps
// Do not use glClear until some method to control rendering with cef is supported // Do not use glClear until some method to control rendering with cef is supported
//We might actually try to use cef to execute javascript, and not using off-screen rendering at all // We might actually try to use cef to execute javascript, and not using off-screen rendering at all
//But for now let it be like this // But for now let it be like this
// glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
CefDoMessageLoopWork(); CefDoMessageLoopWork ();
} }
void CWeb::updateMouse (glm::ivec4 viewport)
{ void CWeb::updateMouse (glm::ivec4 viewport) {
// update virtual mouse position first // update virtual mouse position first
glm::dvec2 position = this->getContext ().getInputContext ().getMouseInput ().position(); glm::dvec2 position = this->getContext ().getInputContext ().getMouseInput ().position ();
CefMouseEvent evt; CefMouseEvent evt;
// Set mouse current position. Maybe clamps are not needed // Set mouse current position. Maybe clamps are not needed
evt.x = std::clamp(int(position.x - viewport.x),0,viewport.z); evt.x = std::clamp (int (position.x - viewport.x), 0, viewport.z);
evt.y = std::clamp(int(position.y - viewport.y),0,viewport.w); evt.y = std::clamp (int (position.y - viewport.y), 0, viewport.w);
// Send mouse position to cef // Send mouse position to cef
m_browser->GetHost()->SendMouseMoveEvent(evt, false); m_browser->GetHost ()->SendMouseMoveEvent (evt, false);
} }
CWeb::~CWeb(){ CWeb::~CWeb () {
CefDoMessageLoopWork(); CefDoMessageLoopWork ();
m_browser->GetHost()->CloseBrowser(true); m_browser->GetHost ()->CloseBrowser (true);
} }
CWeb::RenderHandler::RenderHandler (CWeb* webdata) : m_webdata (webdata) {}
CWeb::RenderHandler::RenderHandler(CWeb* webdata): CWeb::RenderHandler::~RenderHandler () {}
m_webdata(webdata)
{ // Required by CEF
void CWeb::RenderHandler::GetViewRect (CefRefPtr<CefBrowser> browser, CefRect& rect) {
rect = CefRect (0, 0, this->m_webdata->getWidth (), this->m_webdata->getHeight ());
} }
CWeb::RenderHandler::~RenderHandler(){
} // Will be executed in CEF message loop
//Required by CEF void CWeb::RenderHandler::OnPaint (CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList& dirtyRects,
void CWeb::RenderHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect) const void* buffer, int width, int height) {
{ // sLog.debug("BrowserView::RenderHandler::OnPaint");
rect = CefRect(0, 0, this->m_webdata->getWidth(), this->m_webdata->getHeight()); glActiveTexture (GL_TEXTURE0);
} glBindTexture (GL_TEXTURE_2D, this->texture ());
//Will be executed in CEF message loop glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, (unsigned char*) buffer);
void CWeb::RenderHandler::OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, glBindTexture (GL_TEXTURE_2D, 0);
const RectList &dirtyRects, const void *buffer,
int width, int height)
{
//sLog.debug("BrowserView::RenderHandler::OnPaint");
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, this->texture());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA_EXT,
GL_UNSIGNED_BYTE, (unsigned char*)buffer);
glBindTexture(GL_TEXTURE_2D, 0);
} }
const std::string CWeb::Type = "web"; const std::string CWeb::Type = "web";

0
tools/linting.sh Normal file → Executable file
View File