979de94712
Setting from argv[0] seemed like a good idea at the time, but argv[0] can change based on how the user calls Ocarina (ocarina, ./ocarina, /usr/bin/ocarina, ...). This patch changes back to using the reliable /proc/self/exe method. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
/*
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/core.h>
|
|
#include <lib/lib.h>
|
|
#include <gtkmm.h>
|
|
|
|
static Glib::RefPtr<Gtk::Builder> builder;
|
|
static std::string share_dir = "";
|
|
|
|
static void setup_share(const std::string &path)
|
|
{
|
|
char buf[1024];
|
|
ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
|
|
|
|
if (len == -1)
|
|
return;
|
|
buf[len] = '\0';
|
|
|
|
share_dir = std::string(buf);
|
|
share_dir = share_dir.substr(0, share_dir.size() - 11);
|
|
share_dir = share_dir + "share/ocarina/";
|
|
}
|
|
|
|
void lib :: init(int *argc, char ***argv, const std::string >k_xml)
|
|
{
|
|
setup_share((*argv)[0]);
|
|
|
|
builder = Gtk::Builder::create();
|
|
if (!builder->add_from_file(lib :: share_file(gtk_xml)))
|
|
exit(1);
|
|
|
|
core :: init(argc, argv);
|
|
}
|
|
|
|
const std::string lib :: share_file(const std::string &f)
|
|
{
|
|
return share_dir + f;
|
|
}
|
|
|
|
Glib::RefPtr<Gtk::Builder> &lib :: get_builder()
|
|
{
|
|
return builder;
|
|
}
|
|
|
|
const std::string lib :: key_name(GdkEventKey *event)
|
|
{
|
|
std::string key = gdk_keyval_name(event->keyval);
|
|
return key;
|
|
}
|
|
|
|
void lib :: idle(bool (*func)())
|
|
{
|
|
Glib :: signal_idle().connect(sigc::ptr_fun(func));
|
|
}
|
|
|
|
void lib :: schedule(bool (*func)(), unsigned int milliseconds)
|
|
{
|
|
Glib :: signal_timeout().connect(sigc::ptr_fun(func), milliseconds);
|
|
}
|