/* * Copyright 2014 (c) Anna Schumaker. */ #include #include #include static Glib::RefPtr 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); } const std::string lib :: share_file(const std::string &f) { return share_dir + f; } Glib::RefPtr &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); }