Fixes for GTK

This commit is contained in:
Antoine Pilote
2023-09-30 17:20:12 -04:00
parent b5c976d6f7
commit 44e8951a39
3 changed files with 68 additions and 82 deletions

View File

@@ -12,6 +12,11 @@
#include <commdlg.h>
#endif
#ifdef NK_LINUX
#include "gtk/gtk.h"
#endif
#include <fstream>
#include <iostream>
@@ -327,5 +332,5 @@ namespace Nuake
const auto& split = String::Split(path, '\\');
return String::Split(split[split.size() - 1], '.')[0];
}
}
}

View File

@@ -1,4 +1,4 @@
#include "OS.h"
#include "OS.h"
#include "src/Window.h"
#include "Engine.h"
@@ -16,6 +16,7 @@
#include <gtk/gtk.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#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<char*>(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
}
}
}

View File

@@ -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"
}
}