From 44e8951a3981a188cd385f5a26477bc961d75532 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Sat, 30 Sep 2023 17:20:12 -0400 Subject: [PATCH] Fixes for GTK --- Nuake/src/Core/FileSystem.cpp | 9 +++- Nuake/src/Core/OS.cpp | 82 ++++------------------------------- premake5.lua | 59 ++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 82 deletions(-) diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index f37f916a..4d995c10 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -12,6 +12,11 @@ #include #endif + +#ifdef NK_LINUX +#include "gtk/gtk.h" +#endif + #include #include @@ -327,5 +332,5 @@ namespace Nuake const auto& split = String::Split(path, '\\'); return String::Split(split[split.size() - 1], '.')[0]; } - -} + +} \ No newline at end of file diff --git a/Nuake/src/Core/OS.cpp b/Nuake/src/Core/OS.cpp index 34315766..2cf7b405 100644 --- a/Nuake/src/Core/OS.cpp +++ b/Nuake/src/Core/OS.cpp @@ -1,4 +1,4 @@ -#include "OS.h" +#include "OS.h" #include "src/Window.h" #include "Engine.h" @@ -16,6 +16,7 @@ #include #include #include +#include #endif #include "GLFW/glfw3.h" @@ -39,35 +40,10 @@ namespace Nuake { #endif #ifdef NK_LINUX - Display* display = XOpenDisplay(NULL); - if (display != nullptr) - { - XSetSelectionOwner(display, XA_CLIPBOARD, XDefaultRootWindow(display), CurrentTime); - Atom targets_atom = XInternAtom(display, "TARGETS", False); - Atom clipboard_atom = XInternAtom(display, "CLIPBOARD", False); - Atom utf8_atom = XInternAtom(display, "UTF8_STRING", False); + glfwSetClipboardString(NULL, value.c_str()); - XSetSelectionOwner(display, clipboard_atom, XDefaultRootWindow(display), CurrentTime); - XEvent event; - memset(&event, 0, sizeof(event)); - event.xclient.type = ClientMessage; - event.xclient.window = XDefaultRootWindow(display); - event.xclient.message_type = targets_atom; - event.xclient.format = 32; - event.xclient.data.l[0] = utf8_atom; - event.xclient.data.l[1] = 0; - event.xclient.data.l[2] = 0; - event.xclient.data.l[3] = 0; - event.xclient.data.l[4] = 0; - - XSendEvent(display, XDefaultRootWindow(display), False, NoEventMask, &event); - - XFlush(display); - - XCloseDisplay(display); - } #endif } @@ -88,49 +64,7 @@ namespace Nuake { #endif #ifdef NK_LINUX - Display* display = XOpenDisplay(NULL); - if (display != nullptr) - { - Window owner = XGetSelectionOwner(display, XA_CLIPBOARD); - if (owner != None) - { - Atom target = XInternAtom(display, "UTF8_STRING", False); - - XConvertSelection(display, XA_CLIPBOARD, target, target, XDefaultRootWindow(display), CurrentTime); - - XFlush(display); - - XEvent event; - memset(&event, 0, sizeof(event)); - - XNextEvent(display, &event); - if (event.type == SelectionNotify) - { - if (event.xselection.property != None) - { - Atom type; - int format; - unsigned long nitems; - unsigned long bytes_after; - unsigned char* prop_data; - - XGetWindowProperty(display, XDefaultRootWindow(display), target, 0, LONG_MAX, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &prop_data); - - if (prop_data != nullptr) - { - std::string text(reinterpret_cast(prop_data), nitems); - XFree(prop_data); - - XCloseDisplay(display); - - return text; - } - } - } - } - - XCloseDisplay(display); - } + glfwSetClipboardString(NULL, "A string with words in it"); #endif return ""; @@ -192,7 +126,7 @@ namespace Nuake { #endif #ifdef NK_LINUX - std::string command = Engine::GetProject()->TrenchbroomPath.c_str() + filePath.c_str(); + std::string command = Engine::GetProject()->TrenchbroomPath + filePath.c_str(); system(command.c_str()); #endif } @@ -204,7 +138,7 @@ namespace Nuake { #ifdef NK_WIN TCHAR appDataPath[64]; // Get the path to the AppData folder - if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath) >= 0) + if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath) >= 0) { std::wstring wideString(appDataPath); path = std::string(wideString.begin(), wideString.end()); @@ -215,7 +149,7 @@ namespace Nuake { }), path.end()); std::replace(path.begin(), path.end(), '\\', '/'); } - else + else { path = ""; } @@ -239,4 +173,4 @@ namespace Nuake { system(command.c_str()); #endif } -} +} \ No newline at end of file diff --git a/premake5.lua b/premake5.lua index df0762e3..d8807e7e 100644 --- a/premake5.lua +++ b/premake5.lua @@ -94,6 +94,21 @@ project "Nuake" "GLFW_STATIC", "NK_LINUX" } + + links + { + "glib-2.0" + } + + buildoptions { "`pkg-config --cflags glib-2.0 pango gdk-pixbuf-2.0 atk`" } + linkoptions { "`pkg-config --libs glib-2.0 pango gdk-pixbuf-2.0`" } + + includedirs + { + "/usr/include/gtk-3.0/", + "/usr/lib/glib-2.0/include", + "/usr/include/glib-2.0", + } filter "system:windows" staticruntime "On" @@ -102,8 +117,7 @@ project "Nuake" "NK_WIN" } - buildoptions { "-permissive", "-cxxflags"} - + buildoptions { "-permissive", "-cxxflags", "gtk+-3.0"} filter "configurations:Debug" runtime "Debug" symbols "on" @@ -188,8 +202,22 @@ project "NuakeRuntime" "glad", "X11", "asound", + "glib-2.0", + "gtk-3", + "gobject-2.0" } + + includedirs + { + "/usr/include/gtk-3.0/", + "/usr/lib/glib-2.0/include", + "/usr/include/glib-2.0", + } + + buildoptions { "`pkg-config --cflags glib-2.0 pango gdk-pixbuf-2.0 gtk-3 atk tk-3.0 glib-2.0`" } + linkoptions { "`pkg-config --libs glib-2.0 pango gdk-pixbuf-2.0 gtk-3 glib-2.0 lgobject-2.0`" } + filter "configurations:Debug" runtime "Debug" symbols "on" @@ -250,7 +278,8 @@ project "Editor" "%{prj.name}/../Nuake/src/Vendors/msdfgen", "%{prj.name}/../Nuake/dependencies/JoltPhysics", "%{prj.name}/../Nuake/dependencies/build", - "%{prj.name}/../Nuake/dependencies/soloud/include" + "%{prj.name}/../Nuake/dependencies/soloud/include", + "/usr/include/gtk-3.0/" } libdirs @@ -273,8 +302,8 @@ project "Editor" "glad", "GLFW", "assimp", - "Freetype", - "JoltPhysics", + "Freetype", + "JoltPhysics", "soloud" } @@ -302,14 +331,32 @@ project "Editor" "glad", "X11", "asound", + "glib-2.0", + "gtk-3", + "gobject-2.0", + "asound" } + buildoptions { "`pkg-config --cflags glib-2.0 pango gdk-pixbuf-2.0 gtk-3 atk tk-3.0 glib-2.0`" } + linkoptions { "`pkg-config --libs glib-2.0 pango gdk-pixbuf-2.0 gtk-3 glib-2.0 lgobject-2.0`" } + + + includedirs + { + "/usr/include/gtk-3.0/", + "/usr/lib/glib-2.0/include", + "/usr/include/glib-2.0", + } + + + defines { "GLFW_STATIC", "NK_LINUX" } + filter "configurations:Debug" runtime "Debug" symbols "on" @@ -337,4 +384,4 @@ project "Editor" -- copy a file from the objects directory to the target directory postbuildcommands { --"{COPY} "Nuake/dependencies/GLFW/lib-vc2019/glfw3.dll" " .. "./bin/" .. outputdir .. "/%{prj.name}/glfw3.dll" - } + } \ No newline at end of file