Small Update to Linux Branch #54

Merged
absquatulate merged 2 commits from linux into linux 2017-04-04 17:29:25 +00:00
3 changed files with 63 additions and 27 deletions

View File

@@ -18,6 +18,10 @@ env = Environment(TARGET_ARCH='x86',ENV=os.environ)
env.VariantDir('#build/obj', 'src') env.VariantDir('#build/obj', 'src')
env.VariantDir('#build/obj/test', 'test') env.VariantDir('#build/obj/test', 'test')
debug = ARGUMENTS.get('debug', 0)
if int(debug):
env.Append(CCFLAGS = '-g')
# This command generates the header with git revision information # This command generates the header with git revision information
def gen_gitrev(env, target, source): def gen_gitrev(env, target, source):
revid = subprocess.check_output(["git", "rev-parse", "HEAD"]); revid = subprocess.check_output(["git", "rev-parse", "HEAD"]);
@@ -46,6 +50,11 @@ if str(platform) == "posix":
env.Append(CXXFLAGS="-std=c++11 -stdlib=libstdc++") env.Append(CXXFLAGS="-std=c++11 -stdlib=libstdc++")
env["CC"] = 'clang' env["CC"] = 'clang'
env["CXX"] = 'clang++' env["CXX"] = 'clang++'
env.Append(LIBPATH=Split("""
/usr/lib
"""), CPPPATH=Split("""
/usr/include
"""))
if str(platform) == "darwin": if str(platform) == "darwin":
env.Append(CXXFLAGS="-std=c++11 -stdlib=libc++", RPATH='../Frameworks') env.Append(CXXFLAGS="-std=c++11 -stdlib=libc++", RPATH='../Frameworks')
env["CC"] = 'clang' env["CC"] = 'clang'
@@ -288,6 +297,7 @@ elif str(platform) == "win32":
elif str(platform) == "posix": elif str(platform) == "posix":
env.Append(LIBS=Split(""" env.Append(LIBS=Split("""
GL GL
X11
""")) """))
Export("env platform") Export("env platform")

View File

@@ -4,33 +4,38 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
Cursor ibeam = XCreateFontCursor(NULL, XC_xterm); Cursor ibeam; // = XCreateFontCursor(NULL, XC_xterm);
extern cursor_type current_cursor; extern cursor_type current_cursor;
extern sf::RenderWindow mainPtr;
cCursor::cCursor(fs::path imgPath, float hotSpotX, float hotSpotY)
: ptr(nullptr) {
cCursor::cCursor(fs::path imgPath, float hotSpotX, float hotSpotY) {
} }
cCursor::~cCursor() { cCursor::~cCursor() {
if (ptr != nullptr) {
Cursor* realPtr = reinterpret_cast<Cursor*>(ptr); Cursor* realPtr = reinterpret_cast<Cursor*>(ptr);
XFreeCursor(NULL, *realPtr); XFreeCursor(NULL, *realPtr);
delete realPtr; delete realPtr;
}
} }
void cCursor::apply() { void cCursor::apply() {
XDefineCursor(NULL, current_window, *reinterpret_cast<Cursor*>(ptr)); // XDefineCursor(NULL, current_window, *reinterpret_cast<Cursor*>(ptr));
} }
void obscureCursor() { void obscureCursor() {
// TODO: This hides it permanently; it should only hide it until it moves // TODO: This hides it permanently; it should only hide it until it moves
XUndefineCursor(NULL, current_window); // XUndefineCursor(NULL, current_window);
} }
void set_cursor(cursor_type which_c) { void set_cursor(cursor_type which_c) {
if(which_c != watch_curs) if(which_c != watch_curs)
current_cursor = which_c; current_cursor = which_c;
if(which_c == text_curs) { if(which_c == text_curs) {
XDefineCursor(NULL, current_window, ibeam); // XDefineCursor(NULL, current_window, ibeam);
} else { } else {
cCursor& curs = *ResMgr::get<CursorRsrc>(cursors[which_c]); cCursor& curs = *ResMgr::get<CursorRsrc>(cursors[which_c]);
curs.apply(); curs.apply();

View File

@@ -6,6 +6,9 @@
#include <sstream> #include <sstream>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <sys/utsname.h>
#include <stdio.h>
extern sf::RenderWindow mainPtr; extern sf::RenderWindow mainPtr;
// TODO: I'm sure there's a better way to do this (maybe one that's keyboard layout agnostic) // TODO: I'm sure there's a better way to do this (maybe one that's keyboard layout agnostic)
@@ -87,8 +90,14 @@ char keyToChar(sf::Keyboard::Key key, bool isShift) {
} }
std::string get_os_version() { std::string get_os_version() {
// TODO: Be more specific utsname details;
return "Linux/BSD"; uname(&details);
std::ostringstream version;
version << details.sysname << ' ' << details.nodename << ' ' << details.release << ' ' << details.version;
return version.str();
} }
void makeFrontWindow(sf::Window& win) { void makeFrontWindow(sf::Window& win) {
@@ -96,14 +105,15 @@ void makeFrontWindow(sf::Window& win) {
void setWindowFloating(sf::Window& win, bool floating) { void setWindowFloating(sf::Window& win, bool floating) {
// Code adapted from <http://stackoverflow.com/a/16235920> // Code adapted from <http://stackoverflow.com/a/16235920>
Atom wmStateAbove = XInternAtom(NULL, "_NET_WM_STATE_ABOVE", true); auto display = XOpenDisplay(NULL);
Atom wmStateAbove = XInternAtom(display, "_NET_WM_STATE_ABOVE", true);
if(wmStateAbove != None) { if(wmStateAbove != None) {
std::cout << "_NET_WM_STATE_ABOVE has atom of " << long(wmStateAbove) << std::endl; std::cout << "_NET_WM_STATE_ABOVE has atom of " << long(wmStateAbove) << std::endl;
} else { } else {
std::cerr << "ERROR: cannot find atom for _NET_WM_STATE_ABOVE!\n"; std::cerr << "ERROR: cannot find atom for _NET_WM_STATE_ABOVE!\n";
} }
Atom wmNetWmState = XInternAtom(NULL, "_NET_WM_STATE", true); Atom wmNetWmState = XInternAtom(display, "_NET_WM_STATE", true);
if(wmNetWmState != None) { if(wmNetWmState != None) {
std::cout << "_NET_WM_STATE has atom of " << long(wmNetWmState) << std::endl; std::cout << "_NET_WM_STATE has atom of " << long(wmNetWmState) << std::endl;
} else { } else {
@@ -114,17 +124,8 @@ void setWindowFloating(sf::Window& win, bool floating) {
XClientMessageEvent xclient; XClientMessageEvent xclient;
memset(&xclient, 0, sizeof(xclient)); memset(&xclient, 0, sizeof(xclient));
//window = the respective client window
//message_type = _NET_WM_STATE
//format = 32
//data.l[0] = the action, as listed below
//data.l[1] = first property to alter
//data.l[2] = second property to alter
//data.l[3] = source indication (0-unk,1-normal app,2-pager)
//other data.l[] elements = 0
xclient.type = ClientMessage; xclient.type = ClientMessage;
xclient.window = mywin; // GDK_WINDOW_XID(window); xclient.window = win.getSystemHandle(); // GDK_WINDOW_XID(window);
xclient.message_type = wmNetWmState; //gdk_x11_get_xatom_by_name_for_display( display, "_NET_WM_STATE" ); xclient.message_type = wmNetWmState; //gdk_x11_get_xatom_by_name_for_display( display, "_NET_WM_STATE" );
xclient.format = 32; xclient.format = 32;
xclient.data.l[0] = floating ? 1 : 0; xclient.data.l[0] = floating ? 1 : 0;
@@ -133,7 +134,7 @@ void setWindowFloating(sf::Window& win, bool floating) {
xclient.data.l[3] = 0; xclient.data.l[3] = 0;
xclient.data.l[4] = 0; xclient.data.l[4] = 0;
XSendEvent(display, XSendEvent(display,
root, // !! DefaultRootWindow( display ) !!! win.getSystemHandle(), // !! DefaultRootWindow( display ) !!!
False, False,
SubstructureRedirectMask | SubstructureNotifyMask, SubstructureRedirectMask | SubstructureNotifyMask,
(XEvent *)&xclient (XEvent *)&xclient
@@ -144,20 +145,40 @@ void setWindowFloating(sf::Window& win, bool floating) {
void init_fileio() { void init_fileio() {
} }
static std::string runFileDialog(const std::string& file, bool save) {
std::string filename;
filename.reserve(1024);
std::string command = "zenity --file-selection";
if (file != "")
command += " --filename=\"" + file + "\"";
if (save)
command += " --save";
FILE* hfile = popen(command.c_str(), "r");
char buffer[128];
while (!feof(hfile)) {
if (fgets(buffer, 128, hfile) != NULL)
filename += buffer;
}
pclose(hfile);
return filename;
}
fs::path nav_get_party() { fs::path nav_get_party() {
return ""; return runFileDialog("Blades of Exile Save.exg", false);
} }
fs::path nav_put_party(fs::path def) { fs::path nav_put_party(fs::path def) {
return ""; if (def.empty())
def = "Blades of Exile Save.exg";
return runFileDialog(def.string(), true);
} }
fs::path nav_get_scenario() { fs::path nav_get_scenario() {
return ""; return runFileDialog("", false);
} }
fs::path nav_put_scenario(fs::path def) { fs::path nav_put_scenario(fs::path def) {
return ""; return runFileDialog(def.string(), false);
} }