yes
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
|
#ifdef TARGET_OS_OSX
|
||||||
|
#include <stdlib.h>
|
||||||
|
#else
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define GTK_DECLARE_FUNCS
|
#define GTK_DECLARE_FUNCS
|
||||||
#include "gtk-imports.h"
|
#include "gtk-imports.h"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ extern "C" {
|
|||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux
|
#if defined(__linux) || defined(TARGET_OS_OSX)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -69,6 +69,33 @@ void GtkLoader::loadLibraryLinux(const char *lib, void **handle)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GtkLoader::loadLibraryOSX(const char *lib, void **handle)
|
||||||
|
{
|
||||||
|
#ifdef TARGET_OS_OSX
|
||||||
|
std::string full_lib_path = std::string("/opt/homebrew/lib/") + lib;
|
||||||
|
*handle = ::dlopen(full_lib_path.c_str(), RTLD_LAZY);
|
||||||
|
if (*handle == NULL) {
|
||||||
|
throw std::string("Cannot load library '") + lib + "'";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void GtkLoader::loadFunctionOSX(const char *func, void **func_ptr)
|
||||||
|
{
|
||||||
|
#ifdef TARGET_OS_OSX
|
||||||
|
*func_ptr = nullptr;
|
||||||
|
std::list<void *>::const_iterator it = library_handles.begin();
|
||||||
|
while(*func_ptr == nullptr && it != library_handles.end()) {
|
||||||
|
void *handle = *it;
|
||||||
|
*func_ptr = dlsym(handle, func);
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
if (*func_ptr == nullptr) {
|
||||||
|
throw std::string("Cannot load function '") + func;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void GtkLoader::loadFunctionWin64(const char *func, void **func_ptr)
|
void GtkLoader::loadFunctionWin64(const char *func, void **func_ptr)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -141,6 +168,23 @@ void GtkLoader::dlopen()
|
|||||||
loadLibraryLinux(libs[i], &lib);
|
loadLibraryLinux(libs[i], &lib);
|
||||||
if (lib) { library_handles.push_back(lib); }
|
if (lib) { library_handles.push_back(lib); }
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef TARGET_OS_OSX
|
||||||
|
const char *libs[] = {
|
||||||
|
"libgtk-3.0.dylib",
|
||||||
|
"libgobject-2.0.dylib",
|
||||||
|
"libgio-2.0.dylib",
|
||||||
|
"libglib-2.0.dylib",
|
||||||
|
"libgdk-3.dylib",
|
||||||
|
"libgdk_pixbuf-2.0.dylib",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
for(i = 0; libs[i] != NULL; i++) {
|
||||||
|
void *lib;
|
||||||
|
loadLibraryOSX(libs[i], &lib);
|
||||||
|
if (lib) { library_handles.push_back(lib); }
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,6 +197,9 @@ void GtkLoader::loadFunction(const char *func, void **func_ptr)
|
|||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
loadFunctionLinux(func, func_ptr);
|
loadFunctionLinux(func, func_ptr);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef TARGET_OS_OSX
|
||||||
|
loadFunctionOSX(func, func_ptr);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loader(const char *func, void **func_ptr, void *user_data)
|
static void loader(const char *func, void **func_ptr, void *user_data)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ private:
|
|||||||
void loadFunctionWin64(const char *func, void **func_ptr);
|
void loadFunctionWin64(const char *func, void **func_ptr);
|
||||||
void loadLibraryLinux(const char *lib, void **handle);
|
void loadLibraryLinux(const char *lib, void **handle);
|
||||||
void loadFunctionLinux(const char *func, void **func_ptr);
|
void loadFunctionLinux(const char *func, void **func_ptr);
|
||||||
|
void loadLibraryOSX(const char *lib, void **handle);
|
||||||
|
void loadFunctionOSX(const char *func, void **func_ptr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void dlopen();
|
void dlopen();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "utils/whereami.h"
|
#include "utils/whereami.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#ifdef __linux
|
#if defined(__linux) || defined(TARGET_OS_OSX)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -26,19 +26,19 @@ std::string InfoOverMe::containingFolder()
|
|||||||
wai_getExecutablePath(path, len, NULL);
|
wai_getExecutablePath(path, len, NULL);
|
||||||
path[len] = '\0';
|
path[len] = '\0';
|
||||||
|
|
||||||
std::string p(path);
|
std::filesystem::path p(path);
|
||||||
std::filesystem::path pp(p);
|
if (std::filesystem::is_regular_file(p)) {
|
||||||
if (std::filesystem::is_regular_file(pp)) {
|
std::filesystem::path pp = p.parent_path();
|
||||||
pp = pp.parent_path();
|
|
||||||
}
|
|
||||||
|
|
||||||
return pp.string();
|
return pp.string();
|
||||||
|
} else {
|
||||||
|
return p.string();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InfoOverMe::myHostname()
|
std::string InfoOverMe::myHostname()
|
||||||
{
|
{
|
||||||
char buf[10240];
|
char buf[10240];
|
||||||
#ifdef __linux
|
#if defined(__linux) || defined(TARGET_OS_OSX)
|
||||||
int r = gethostname(buf, 10240);
|
int r = gethostname(buf, 10240);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -59,9 +59,13 @@ std::string InfoOverMe::myOsHostname()
|
|||||||
#else
|
#else
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
os = "windows";
|
os = "windows";
|
||||||
|
#else
|
||||||
|
#ifdef TARGET_OS_OSX
|
||||||
|
os = "osx";
|
||||||
#else
|
#else
|
||||||
os = "unknown";
|
os = "unknown";
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return os + "_" + myHostname();
|
return os + "_" + myHostname();
|
||||||
}
|
}
|
||||||
|
|||||||
14
main.cpp
14
main.cpp
@@ -8,8 +8,11 @@ extern "C" {
|
|||||||
#include "yellownotes.h"
|
#include "yellownotes.h"
|
||||||
#include "info_over_me.h"
|
#include "info_over_me.h"
|
||||||
|
|
||||||
SIGNAL(YellowNotes, on_tray_activate, popupTrayMenu)
|
#ifndef TARGET_OS_OSX
|
||||||
|
SIGNAL(YellowNotes, on_tray_activate, popupTrayMenu);
|
||||||
|
#else
|
||||||
|
BSIGNAL2(YellowNotes, on_tray_btn, popupTrayMenuBtn, GdkEventButton);
|
||||||
|
#endif
|
||||||
static void activate (GtkApplication* app, gpointer user_data)
|
static void activate (GtkApplication* app, gpointer user_data)
|
||||||
{
|
{
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
@@ -17,7 +20,11 @@ static void activate (GtkApplication* app, gpointer user_data)
|
|||||||
|
|
||||||
std::string img_file = notes->imageFile("yellownotes");
|
std::string img_file = notes->imageFile("yellownotes");
|
||||||
GtkStatusIcon *tray = gtk_status_icon_new_from_file(img_file.c_str());
|
GtkStatusIcon *tray = gtk_status_icon_new_from_file(img_file.c_str());
|
||||||
|
#ifdef TARGET_OS_OSX
|
||||||
|
g_signal_connect(tray, "button_press_event", on_tray_btn, notes);
|
||||||
|
#else
|
||||||
g_signal_connect(tray, "activate", on_tray_activate, notes);
|
g_signal_connect(tray, "activate", on_tray_activate, notes);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int runMain(int argc, char **argv);
|
static int runMain(int argc, char **argv);
|
||||||
@@ -42,12 +49,11 @@ int runMain(int argc, char **argv)
|
|||||||
|
|
||||||
srand(time(NULL)); // seed with current time
|
srand(time(NULL)); // seed with current time
|
||||||
|
|
||||||
std::string my_path = w.containingFolder();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
l.loadGtk();
|
l.loadGtk();
|
||||||
} catch(std::string msg) {
|
} catch(std::string msg) {
|
||||||
std::cerr << msg << std::endl;
|
std::cerr << msg << std::endl;
|
||||||
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkApplication *app;
|
GtkApplication *app;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __linux
|
#if defined(__linux) || defined(TARGET_OS_OSX)
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
@@ -260,22 +260,31 @@ SIGNAL(YellowNotes, on_monitors_changed, monitorsChanged);
|
|||||||
|
|
||||||
std::string YellowNotes::imageFile(const char *name)
|
std::string YellowNotes::imageFile(const char *name)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32) || defined(TARGET_OS_OSX)
|
||||||
std::string ext = ".png";
|
std::string ext = ".png";
|
||||||
#else
|
#else
|
||||||
std::string ext = ".svg";
|
std::string ext = ".svg";
|
||||||
#endif
|
#endif
|
||||||
return appDir() + "/" + name + ext;
|
|
||||||
|
std::string file = name + ext;
|
||||||
|
std::string path1 = appDir() + "/images/" + file;
|
||||||
|
if (std::filesystem::is_regular_file(path1)) {
|
||||||
|
return path1;
|
||||||
|
} else {
|
||||||
|
std::string path2 = appDir() + "/../../" + file;
|
||||||
|
if (std::filesystem::is_regular_file(path2)) {
|
||||||
|
return path2;
|
||||||
|
} else {
|
||||||
|
std::cerr << "No such image file: " << path2 << std::endl;
|
||||||
|
throw std::string("No such image file: " + file);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string YellowNotes::appDir()
|
std::string YellowNotes::appDir()
|
||||||
{
|
{
|
||||||
#ifdef __linux
|
InfoOverMe info;
|
||||||
std::string base = "/home/hans/src/yellownotes";
|
std::string base = info.containingFolder();
|
||||||
#endif
|
|
||||||
#ifdef _WIN32
|
|
||||||
std::string base = "c:/devel/yellownotes";
|
|
||||||
#endif
|
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,6 +300,11 @@ std::string YellowNotes::notesDir()
|
|||||||
snprintf(homedir, 10240, "%s%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
|
snprintf(homedir, 10240, "%s%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef TARGET_OS_OSX
|
||||||
|
struct passwd *pw = getpwuid(getuid());
|
||||||
|
const char *homedir = pw->pw_dir;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string home_dir = homedir;
|
std::string home_dir = homedir;
|
||||||
std::string notes_dir = home_dir + "/yellownotes";
|
std::string notes_dir = home_dir + "/yellownotes";
|
||||||
|
|
||||||
@@ -489,6 +503,11 @@ int YellowNotes::iconSize()
|
|||||||
return _font_size * 1.5;
|
return _font_size * 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool YellowNotes::popupTrayMenuBtn(void *sender, GdkEventButton *evt)
|
||||||
|
{
|
||||||
|
popupTrayMenu(sender);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void YellowNotes::popupTrayMenu(void *sender)
|
void YellowNotes::popupTrayMenu(void *sender)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void popupTrayMenu(void *sender);
|
void popupTrayMenu(void *sender);
|
||||||
|
bool popupTrayMenuBtn(void *sender, GdkEventButton *evt);
|
||||||
void newNote(void *sender);
|
void newNote(void *sender);
|
||||||
void showNotes(void *sender);
|
void showNotes(void *sender);
|
||||||
void notesToDesktop(void *sender);
|
void notesToDesktop(void *sender);
|
||||||
@@ -123,6 +124,7 @@ public:
|
|||||||
static void func(GObject *obj, void *arg, gpointer user_data) { type *o = reinterpret_cast<type *>(user_data); o->member(obj, reinterpret_cast<argtype *>(arg)); }
|
static void func(GObject *obj, void *arg, gpointer user_data) { type *o = reinterpret_cast<type *>(user_data); o->member(obj, reinterpret_cast<argtype *>(arg)); }
|
||||||
|
|
||||||
#define BSIGNAL2(type, func, member, argtype) \
|
#define BSIGNAL2(type, func, member, argtype) \
|
||||||
static gboolean func(GObject *obj, void *arg, gpointer user_data) { type *o = reinterpret_cast<type *>(user_data); return o->member(obj, reinterpret_cast<argtype *>(arg)); }
|
static gboolean func(GObject *obj, void *arg, gpointer user_data) { \
|
||||||
|
type *o = reinterpret_cast<type *>(user_data); return o->member(obj, reinterpret_cast<argtype *>(arg)); }
|
||||||
|
|
||||||
#endif // YELLOWNOTES_H
|
#endif // YELLOWNOTES_H
|
||||||
|
|||||||
Reference in New Issue
Block a user