增加wayland下的窗口图标

This commit is contained in:
pointer-to-bios 2024-04-27 15:19:08 +08:00
parent 8718b67942
commit d88811e125
3 changed files with 56 additions and 14 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
build
release-build
.vscode

34
inc/native.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef NATIVE_H
#define NATIVE_H
#include <GLFW/glfw3.h>
#include <string>
#include <iostream>
#include <fstream>
#include <filesystem>
// A temprary .desktop needed under wayland
std::string desktop_file =
"[Desktop Entry]\n"
"Name=jungle\n"
"Icon={cwd}/icon.png\n"
"Type=Application\n"
"Categories=Game;\n";
std::string desktop_path = "{home}/.local/share/applications/jungle.desktop";
std::string home_path = std::getenv("HOME");
void nativeSetIcon()
{
// setting desktop file
std::string cwd = "{cwd}";
int pos = desktop_file.find(cwd);
desktop_file.replace(pos, cwd.length(), std::filesystem::current_path());
std::string home = "{home}";
pos = desktop_path.find(home);
desktop_path.replace(pos, home.length(), home_path);
std::ofstream desktop(desktop_path);
desktop << desktop_file;
desktop.close();
}
#endif

View File

@ -10,6 +10,7 @@
#include "shader_m.h"
#include "camera.h"
#include "cube_model.h"
#include "native.h"
#include <iostream>
#include <string>
@ -68,13 +69,17 @@ int curr_x;
int curr_y;
// monitors controlling
int monitor_count;
// int monitor_count;
// GLFWmonitor **monitors;
GLFWimage icon;
int main()
{
#ifdef __linux__
nativeSetIcon();
#endif
// std::cout << "debug";
// glfw: initialize and configure
// ------------------------------
@ -132,7 +137,6 @@ int main()
// ------------------------------------
Shader ourShader("demo.vs", "demo.fs");
unsigned int VBO, VAO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
@ -180,7 +184,6 @@ int main()
}
stbi_image_free(data);
// tell opengl for each sampler to which texture unit it belongs to (only has to be done once)
// -------------------------------------------------------------------------------------------
ourShader.use();
@ -256,7 +259,8 @@ int main()
glfwPollEvents();
timer += deltaTime;
if(timer > 0.3f){
if (timer > 0.3f)
{
glfwSetWindowTitle(window, ("fps:" + std::to_string(int(1.0f / deltaTime)) + " X:" + std::to_string(camera.Position.x) + " Y:" + std::to_string(camera.Position.y) + " Z:" + std::to_string(camera.Position.z)).c_str());
timer -= 0.3f;
}
@ -396,8 +400,8 @@ void focus_callback(GLFWwindow *window, int focused)
}
}
void glfwDump(GLFWwindow *window){
void glfwDump(GLFWwindow *window)
{
int clientAPI = glfwGetWindowAttrib(window, GLFW_CLIENT_API);
int contextAPI = glfwGetWindowAttrib(window, GLFW_CONTEXT_CREATION_API);
int contextVersionMajor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
@ -424,7 +428,10 @@ void glfwDump(GLFWwindow *window){
std::cout << "Forward compatibility: " << forwardCompat << std::endl;
std::cout << "Debug context: " << debugContext << std::endl;
std::cout << "Window size: " << " width-" << windowSizeWidth << " height-" << windowSizeHeight << std::endl;
std::cout << "FrameBuffer size: " << " width-" << bufferSizeWidth << " height-" << bufferSizeHeight << std::endl;
std::cout << "Window Scale: " << " X-" << bufferSizeWidth << " Y-" << bufferSizeHeight << std::endl;
std::cout << "Window size: "
<< " width-" << windowSizeWidth << " height-" << windowSizeHeight << std::endl;
std::cout << "FrameBuffer size: "
<< " width-" << bufferSizeWidth << " height-" << bufferSizeHeight << std::endl;
std::cout << "Window Scale: "
<< " X-" << bufferSizeWidth << " Y-" << bufferSizeHeight << std::endl;
}