Compare commits

..

19 Commits

Author SHA1 Message Date
b52d247977 Better behaviour of the resize cursor. 2026-01-05 14:32:28 +01:00
1a33db1bf5 readint integer validation made better 2025-11-28 11:24:02 +01:00
4c6f260bb9 window title 2025-11-27 22:50:12 +01:00
b91d093b1f small fixes 2025-11-27 09:53:46 +01:00
c968774e62 yes 2025-11-27 09:46:00 +01:00
441e903c67 windows changes 2025-11-27 09:43:32 +01:00
28f0fdb520 osx 2025-11-26 22:31:09 +01:00
5023b63a7e windows integration
Signed-off-by: Hans Dijkema <hans@dijkewijk.nl>
2025-11-26 13:56:19 +01:00
bf62ec97dc stuff 2025-11-25 11:06:56 +01:00
f2e3242d82 win32 2025-11-25 11:06:11 +01:00
e82038e7cf win32
Signed-off-by: Hans Dijkema <hans@dijkewijk.nl>
2025-11-25 11:05:08 +01:00
4c10bb6b9f name of yellownotes turned around, makes it easier to monitor them 2025-11-24 21:30:15 +01:00
c62a9c7610 on new note, make it 'loaded' 2025-11-24 21:27:05 +01:00
aaeb793703 Settings - font sizes 2025-11-24 16:24:35 +01:00
9befee44a5 color updates 2025-11-24 15:00:39 +01:00
6cfa0d5a2d application path 2025-11-24 14:52:58 +01:00
80ee3fcadf Many changes to setup colours, update window positions, put notes on desktop, etc.
Signed-off-by: Hans Dijkema <hans@dijkewijk.nl>
2025-11-24 14:52:17 +01:00
a0ac0420da gtk3 subfolder ignored. 2025-11-20 17:00:49 +01:00
ea3f447af1 Working YellowNotes on Windows. 2025-11-20 16:59:14 +01:00
30 changed files with 3790 additions and 222 deletions

1
.gitignore vendored
View File

@@ -35,4 +35,5 @@
# Project specific # Project specific
*.user *.user
build build
gtk3

View File

@@ -5,11 +5,23 @@ project(yellownotes LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(yellownotes main.cpp
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
enable_language("RC")
set (WIN32_RESOURCES ${CMAKE_CURRENT_SOURCE_DIR}/app.rc)
endif()
add_executable(yellownotes WIN32 main.cpp
gtk-imports.h gtk-imports.h
gtkloader.h gtkloader.cpp gtkloader.h gtkloader.cpp
gtk-imports.c gtk-imports.c
yellownotes.h yellownotes.cpp) yellownotes.h yellownotes.cpp
tr.h tr.cpp
utils/whereami.c utils/whereami.h
info_over_me.h info_over_me.cpp
${WIN32_RESOURCES}
)
include(GNUInstallDirs) include(GNUInstallDirs)
install(TARGETS yellownotes install(TARGETS yellownotes

21
Makefile Normal file
View File

@@ -0,0 +1,21 @@
all: release
@echo make install
install: release
mkdir -p /opt/yellownotes
cp build/release/yellownotes /opt/yellownotes
mkdir -p /opt/yellownotes/images
cp *.svg *.png /opt/yellownotes/images
release: build/release/yellownotes
build/release/yellownotes: info_over_me.cpp gtk-imports.c gtkloader.cpp main.cpp tr.cpp yellownotes.cpp utils/whereami.c \
info_over_me.h gtk-imports.h gtkloader.h tr.h yellownotes.h utils/whereami.h
cmake -S . -B build/release
cmake --build build/release --target all
clean:
rm -rf build/release

BIN
app.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

1
app.rc Normal file
View File

@@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "app.ico"

BIN
color.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

17
color.svg Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" standalone="no"?>
<svg width="128" height="128" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Font-Color</title>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Font-Color">
<rect id="Rectangle" fill-rule="nonzero" x="0" y="0" width="24" height="24">
</rect>
<path d="M18,13.1842 C18,16.6723 15.3137,19.5 12,19.5 C8.68629,19.5 6,16.6723 6,13.1842 C6,8.5 12,5 12,5 C12,5 18,8.5 18,13.1842 Z" id="Path" stroke="#0C0310" stroke-width="2" stroke-linecap="round">
</path>
<path d="M12,15.5 C10.8954,15.5 10,14.6046 10,13.5" id="Path" stroke="#0C0310" stroke-width="2" stroke-linecap="round">
</path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 810 B

BIN
delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

10
delete.svg Normal file
View File

@@ -0,0 +1,10 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">
<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: none; fill-rule: nonzero; opacity: 1;" transform="translate(1.4065934065934016 1.4065934065934016) scale(2.81 2.81)">
<path d="M 67.692 90 H 22.308 c -3.042 0 -5.518 -2.476 -5.518 -5.518 v -61 c 0 -1.104 0.896 -2 2 -2 h 52.42 c 1.104 0 2 0.896 2 2 v 61 C 73.21 87.524 70.734 90 67.692 90 z M 20.79 25.482 v 59 c 0 0.837 0.681 1.518 1.518 1.518 h 45.385 c 0.837 0 1.518 -0.681 1.518 -1.518 v -59 H 20.79 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round"/>
<path d="M 73.196 25.482 H 16.804 c -3.042 0 -5.518 -2.475 -5.518 -5.518 v -4.335 c 0 -3.042 2.475 -5.518 5.518 -5.518 h 56.393 c 3.042 0 5.518 2.475 5.518 5.518 v 4.335 C 78.714 23.007 76.238 25.482 73.196 25.482 z M 16.804 14.112 c -0.837 0 -1.518 0.681 -1.518 1.518 v 4.335 c 0 0.837 0.681 1.518 1.518 1.518 h 56.393 c 0.837 0 1.518 -0.681 1.518 -1.518 v -4.335 c 0 -0.837 -0.681 -1.518 -1.518 -1.518 H 16.804 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round"/>
<path d="M 57.197 14.112 H 32.803 c -1.104 0 -2 -0.896 -2 -2 V 5.518 C 30.803 2.476 33.278 0 36.321 0 h 17.358 c 3.043 0 5.519 2.476 5.519 5.518 v 6.594 C 59.197 13.216 58.302 14.112 57.197 14.112 z M 34.803 10.112 h 20.395 V 5.518 C 55.197 4.681 54.516 4 53.679 4 H 36.321 c -0.837 0 -1.518 0.681 -1.518 1.518 V 10.112 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round"/>
<path d="M 45 78.624 c -1.104 0 -2 -0.896 -2 -2 V 34.856 c 0 -1.104 0.896 -2 2 -2 s 2 0.896 2 2 v 41.768 C 47 77.729 46.104 78.624 45 78.624 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round"/>
<path d="M 58.222 78.624 c -1.104 0 -2 -0.896 -2 -2 V 34.856 c 0 -1.104 0.896 -2 2 -2 s 2 0.896 2 2 v 41.768 C 60.222 77.729 59.326 78.624 58.222 78.624 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round"/>
<path d="M 31.779 78.624 c -1.104 0 -2 -0.896 -2 -2 V 34.856 c 0 -1.104 0.896 -2 2 -2 s 2 0.896 2 2 v 41.768 C 33.779 77.729 32.883 78.624 31.779 78.624 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

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

View File

@@ -1,6 +1,8 @@
#ifndef GTK_IMPORTS_H #ifndef GTK_IMPORTS_H
#define GTK_IMPORTS_H #define GTK_IMPORTS_H
#include <stdlib.h>
/************************************************************************************* /*************************************************************************************
* boiler plate code to initialize Gtk functions etc. * boiler plate code to initialize Gtk functions etc.
*************************************************************************************/ *************************************************************************************/
@@ -44,30 +46,58 @@ typedef GtkMenuShell GtkMenu;
typedef void GtkMenuItem; typedef void GtkMenuItem;
typedef void GdkEvent; typedef void GdkEvent;
typedef void GtkTextBuffer; typedef void GtkTextBuffer;
typedef void GtkTextView;
typedef void GtkTextTagTable; typedef void GtkTextTagTable;
typedef void GtkContainer; typedef void GtkContainer;
typedef void GtkLabel; typedef void GtkLabel;
typedef void GtkHeaderBar; typedef void GtkHeaderBar;
typedef void GdkWindow; typedef void GdkWindow;
typedef void GdkDevice; typedef void GdkDevice;
typedef void GtkImage;
typedef void GdkPixbuf;
typedef void GError;
typedef void GtkStyleContext;
typedef void GtkCssProvider;
typedef void GtkStyleProvider;
typedef void GtkWidgetPath;
typedef void GtkAdjustment;
typedef void GtkFrame;
typedef void GtkEventBox;
typedef void GdkCursor;
typedef void GdkDisplay;
typedef void GtkEntry;
typedef void GtkDialog;
typedef void GTimer;
typedef void GtkComboBoxText;
typedef void GtkComboBox;
typedef void GtkGrid;
typedef void GtkColorButton;
typedef void GtkColorChooser;
typedef void GtkSpinButton;
typedef void GdkMonitor;
typedef void GdkScreen;
typedef void GtkAboutDialog;
typedef int gboolean; typedef int gboolean;
typedef int gint; typedef int gint;
typedef char gchar; typedef char gchar;
typedef long glong; typedef long glong;
typedef unsigned long gulong; typedef unsigned long gulong;
typedef unsigned long guint32; typedef unsigned int guint32;
typedef unsigned int guint; typedef unsigned int guint;
typedef long long gint64; typedef long long gint64;
typedef unsigned long long guint64; typedef unsigned long long guint64;
typedef float gfloat; typedef float gfloat;
typedef double gdouble; typedef double gdouble;
typedef char gint8; typedef char gint8;
typedef unsigned char guint8;
typedef short gint16; typedef short gint16;
typedef unsigned short guint16;
typedef size_t gssize;
typedef enum { typedef enum {
GTK_WINDOW_TOPLEVEL = 0 GTK_WINDOW_TOPLEVEL = 0,
GTK_WINDOW_POPUP = 1
} GtkWindowType; } GtkWindowType;
typedef enum { typedef enum {
@@ -115,14 +145,14 @@ typedef enum {
PANGO_ELLIPSIZE_END = 3 PANGO_ELLIPSIZE_END = 3
} PangoEllipsizeMode; } PangoEllipsizeMode;
struct GdkRectangle { typedef struct _GdkRectangle {
int x; int x;
int y; int y;
int width; int width;
int height; int height;
}; } GdkRectangle;
typedef struct GdkRectangle GtkAllocation; typedef struct _GdkRectangle GtkAllocation;
#define G_VALUE_INIT { 0, { { 0 } } } #define G_VALUE_INIT { 0, { { 0 } } }
@@ -172,36 +202,56 @@ typedef struct _GtkTextIter {
typedef enum typedef enum
{ {
GDK_DELETE, GDK_NOTHING = -1,
GDK_MOTION_NOTIFY, GDK_DELETE = 0,
GDK_BUTTON_PRESS, GDK_DESTROY = 1,
GDK_BUTTON_RELEASE, GDK_EXPOSE = 2,
GDK_KEY_PRESS, GDK_MOTION_NOTIFY = 3,
GDK_KEY_RELEASE, GDK_BUTTON_PRESS = 4,
GDK_ENTER_NOTIFY, GDK_2BUTTON_PRESS = 5,
GDK_LEAVE_NOTIFY, GDK_DOUBLE_BUTTON_PRESS = GDK_2BUTTON_PRESS,
GDK_FOCUS_CHANGE, GDK_3BUTTON_PRESS = 6,
GDK_PROXIMITY_IN, GDK_TRIPLE_BUTTON_PRESS = GDK_3BUTTON_PRESS,
GDK_PROXIMITY_OUT, GDK_BUTTON_RELEASE = 7,
GDK_DRAG_ENTER, GDK_KEY_PRESS = 8,
GDK_DRAG_LEAVE, GDK_KEY_RELEASE = 9,
GDK_DRAG_MOTION, GDK_ENTER_NOTIFY = 10,
GDK_DROP_START, GDK_LEAVE_NOTIFY = 11,
GDK_SCROLL, GDK_FOCUS_CHANGE = 12,
GDK_GRAB_BROKEN, GDK_CONFIGURE = 13,
GDK_TOUCH_BEGIN, GDK_MAP = 14,
GDK_TOUCH_UPDATE, GDK_UNMAP = 15,
GDK_TOUCH_END, GDK_PROPERTY_NOTIFY = 16,
GDK_TOUCH_CANCEL, GDK_SELECTION_CLEAR = 17,
GDK_TOUCHPAD_SWIPE, GDK_SELECTION_REQUEST = 18,
GDK_TOUCHPAD_PINCH, GDK_SELECTION_NOTIFY = 19,
GDK_PAD_BUTTON_PRESS, GDK_PROXIMITY_IN = 20,
GDK_PAD_BUTTON_RELEASE, GDK_PROXIMITY_OUT = 21,
GDK_PAD_RING, GDK_DRAG_ENTER = 22,
GDK_PAD_STRIP, GDK_DRAG_LEAVE = 23,
GDK_PAD_GROUP_MODE, GDK_DRAG_MOTION = 24,
GDK_TOUCHPAD_HOLD, GDK_DRAG_STATUS = 25,
GDK_PAD_DIAL, GDK_DROP_START = 26,
GDK_DROP_FINISHED = 27,
GDK_CLIENT_EVENT = 28,
GDK_VISIBILITY_NOTIFY = 29,
GDK_SCROLL = 31,
GDK_WINDOW_STATE = 32,
GDK_SETTING = 33,
GDK_OWNER_CHANGE = 34,
GDK_GRAB_BROKEN = 35,
GDK_DAMAGE = 36,
GDK_TOUCH_BEGIN = 37,
GDK_TOUCH_UPDATE = 38,
GDK_TOUCH_END = 39,
GDK_TOUCH_CANCEL = 40,
GDK_TOUCHPAD_SWIPE = 41,
GDK_TOUCHPAD_PINCH = 42,
GDK_PAD_BUTTON_PRESS = 43,
GDK_PAD_BUTTON_RELEASE = 44,
GDK_PAD_RING = 45,
GDK_PAD_STRIP = 46,
GDK_PAD_GROUP_MODE = 47,
GDK_EVENT_LAST /* helper variable for decls */ GDK_EVENT_LAST /* helper variable for decls */
} GdkEventType; } GdkEventType;
@@ -233,10 +283,24 @@ typedef struct _GdkEventMotion
gint16 is_hint; gint16 is_hint;
GdkDevice *device; GdkDevice *device;
gdouble x_root, y_root; gdouble x_root, y_root;
} GdkEventMotion; } GdkEventMotion;;
typedef struct _GdkEventKey
{
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
guint state;
guint keyval;
gint length;
gchar *string;
guint16 hardware_keycode;
guint8 group;
guint is_modifier : 1;
} GdkEventKey;
#define GDK_KEY_Escape 65307
typedef enum typedef enum
{ {
@@ -268,14 +332,296 @@ typedef enum
GDK_ALL_EVENTS_MASK = 0x3FFFFFE GDK_ALL_EVENTS_MASK = 0x3FFFFFE
} GdkEventMask; } GdkEventMask;
typedef enum
{
GTK_STATE_FLAG_NORMAL = 0,
GTK_STATE_FLAG_ACTIVE = 1 << 0,
GTK_STATE_FLAG_PRELIGHT = 1 << 1,
GTK_STATE_FLAG_SELECTED = 1 << 2,
GTK_STATE_FLAG_INSENSITIVE = 1 << 3,
GTK_STATE_FLAG_INCONSISTENT = 1 << 4,
GTK_STATE_FLAG_FOCUSED = 1 << 5,
GTK_STATE_FLAG_BACKDROP = 1 << 6,
GTK_STATE_FLAG_DIR_LTR = 1 << 7,
GTK_STATE_FLAG_DIR_RTL = 1 << 8,
GTK_STATE_FLAG_LINK = 1 << 9,
GTK_STATE_FLAG_VISITED = 1 << 10,
GTK_STATE_FLAG_CHECKED = 1 << 11,
GTK_STATE_FLAG_DROP_ACTIVE = 1 << 12
} GtkStateFlags;
typedef void (* GtkMenuPositionFunc) (
GtkMenu* menu,
gint* x,
gint* y,
gboolean* push_in,
gpointer user_data
);
typedef struct _GdkRGBA
{
gdouble red;
gdouble green;
gdouble blue;
gdouble alpha;
} GdkRGBA;
typedef struct _GtkRequisition
{
gint width;
gint height;
} GtkRequisition;
typedef enum {
GTK_STYLE_CONTEXT_PRINT_NONE = 0,
GTK_STYLE_CONTEXT_PRINT_RECURSE = 1 << 0,
GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE = 1 << 1
} GtkStyleContextPrintFlags;
typedef enum
{
GTK_WRAP_NONE,
GTK_WRAP_CHAR,
GTK_WRAP_WORD,
GTK_WRAP_WORD_CHAR
} GtkWrapMode;
typedef enum
{
GTK_SHADOW_NONE,
GTK_SHADOW_IN,
GTK_SHADOW_OUT,
GTK_SHADOW_ETCHED_IN,
GTK_SHADOW_ETCHED_OUT
} GtkShadowType;
typedef enum
{
GDK_X_CURSOR = 0,
GDK_ARROW = 2,
GDK_BASED_ARROW_DOWN = 4,
GDK_BASED_ARROW_UP = 6,
GDK_BOAT = 8,
GDK_BOGOSITY = 10,
GDK_BOTTOM_LEFT_CORNER = 12,
GDK_BOTTOM_RIGHT_CORNER = 14,
GDK_BOTTOM_SIDE = 16,
GDK_BOTTOM_TEE = 18,
GDK_BOX_SPIRAL = 20,
GDK_CENTER_PTR = 22,
GDK_CIRCLE = 24,
GDK_CLOCK = 26,
GDK_COFFEE_MUG = 28,
GDK_CROSS = 30,
GDK_CROSS_REVERSE = 32,
GDK_CROSSHAIR = 34,
GDK_DIAMOND_CROSS = 36,
GDK_DOT = 38,
GDK_DOTBOX = 40,
GDK_DOUBLE_ARROW = 42,
GDK_DRAFT_LARGE = 44,
GDK_DRAFT_SMALL = 46,
GDK_DRAPED_BOX = 48,
GDK_EXCHANGE = 50,
GDK_FLEUR = 52,
GDK_GOBBLER = 54,
GDK_GUMBY = 56,
GDK_HAND1 = 58,
GDK_HAND2 = 60,
GDK_HEART = 62,
GDK_ICON = 64,
GDK_IRON_CROSS = 66,
GDK_LEFT_PTR = 68,
GDK_LEFT_SIDE = 70,
GDK_LEFT_TEE = 72,
GDK_LEFTBUTTON = 74,
GDK_LL_ANGLE = 76,
GDK_LR_ANGLE = 78,
GDK_MAN = 80,
GDK_MIDDLEBUTTON = 82,
GDK_MOUSE = 84,
GDK_PENCIL = 86,
GDK_PIRATE = 88,
GDK_PLUS = 90,
GDK_QUESTION_ARROW = 92,
GDK_RIGHT_PTR = 94,
GDK_RIGHT_SIDE = 96,
GDK_RIGHT_TEE = 98,
GDK_RIGHTBUTTON = 100,
GDK_RTL_LOGO = 102,
GDK_SAILBOAT = 104,
GDK_SB_DOWN_ARROW = 106,
GDK_SB_H_DOUBLE_ARROW = 108,
GDK_SB_LEFT_ARROW = 110,
GDK_SB_RIGHT_ARROW = 112,
GDK_SB_UP_ARROW = 114,
GDK_SB_V_DOUBLE_ARROW = 116,
GDK_SHUTTLE = 118,
GDK_SIZING = 120,
GDK_SPIDER = 122,
GDK_SPRAYCAN = 124,
GDK_STAR = 126,
GDK_TARGET = 128,
GDK_TCROSS = 130,
GDK_TOP_LEFT_ARROW = 132,
GDK_TOP_LEFT_CORNER = 134,
GDK_TOP_RIGHT_CORNER = 136,
GDK_TOP_SIDE = 138,
GDK_TOP_TEE = 140,
GDK_TREK = 142,
GDK_UL_ANGLE = 144,
GDK_UMBRELLA = 146,
GDK_UR_ANGLE = 148,
GDK_WATCH = 150,
GDK_XTERM = 152,
GDK_LAST_CURSOR,
GDK_BLANK_CURSOR = -2,
GDK_CURSOR_IS_PIXMAP = -1
} GdkCursorType;
typedef enum
{
GTK_ALIGN_FILL,
GTK_ALIGN_START,
GTK_ALIGN_END,
GTK_ALIGN_CENTER,
GTK_ALIGN_BASELINE
} GtkAlign;
typedef enum
{
GTK_DIALOG_MODAL = 1 << 0,
GTK_DIALOG_DESTROY_WITH_PARENT = 1 << 1,
GTK_DIALOG_USE_HEADER_BAR = 1 << 2
} GtkDialogFlags;
typedef enum
{
GTK_MESSAGE_INFO,
GTK_MESSAGE_WARNING,
GTK_MESSAGE_QUESTION,
GTK_MESSAGE_ERROR,
GTK_MESSAGE_OTHER
} GtkMessageType;
typedef enum
{
GTK_BUTTONS_NONE,
GTK_BUTTONS_OK,
GTK_BUTTONS_CLOSE,
GTK_BUTTONS_CANCEL,
GTK_BUTTONS_YES_NO,
GTK_BUTTONS_OK_CANCEL
} GtkButtonsType;
typedef enum
{
GTK_RESPONSE_NONE = -1,
GTK_RESPONSE_REJECT = -2,
GTK_RESPONSE_ACCEPT = -3,
GTK_RESPONSE_DELETE_EVENT = -4,
GTK_RESPONSE_OK = -5,
GTK_RESPONSE_CANCEL = -6,
GTK_RESPONSE_CLOSE = -7,
GTK_RESPONSE_YES = -8,
GTK_RESPONSE_NO = -9,
GTK_RESPONSE_APPLY = -10,
GTK_RESPONSE_HELP = -11
} GtkResponseType;
typedef struct _GdkEventFocus
{
GdkEventType type;
GdkWindow *window;
gint8 send_event;
gint16 in;
} GdkEventFocus;
typedef gboolean (*GSourceFunc) (gpointer user_data);
typedef enum
{
GDK_WINDOW_TYPE_HINT_NORMAL,
GDK_WINDOW_TYPE_HINT_DIALOG,
GDK_WINDOW_TYPE_HINT_MENU, /* Torn off menu */
GDK_WINDOW_TYPE_HINT_TOOLBAR,
GDK_WINDOW_TYPE_HINT_SPLASHSCREEN,
GDK_WINDOW_TYPE_HINT_UTILITY,
GDK_WINDOW_TYPE_HINT_DOCK,
GDK_WINDOW_TYPE_HINT_DESKTOP,
GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU, /* A drop down menu (from a menubar) */
GDK_WINDOW_TYPE_HINT_POPUP_MENU, /* A popup menu (from right-click) */
GDK_WINDOW_TYPE_HINT_TOOLTIP,
GDK_WINDOW_TYPE_HINT_NOTIFICATION,
GDK_WINDOW_TYPE_HINT_COMBO,
GDK_WINDOW_TYPE_HINT_DND
} GdkWindowTypeHint;
typedef enum
{
GDK_VISIBILITY_UNOBSCURED,
GDK_VISIBILITY_PARTIAL,
GDK_VISIBILITY_FULLY_OBSCURED
} GdkVisibilityState;
typedef struct _GdkEventVisibility
{
GdkEventType type;
GdkWindow *window;
gint8 send_event;
GdkVisibilityState state;
} GdkEventVisibility;
typedef struct _GList {
gpointer data;
gpointer next;
gpointer prev;
} GList;
typedef void GListModel;
typedef enum {
GTK_LICENSE_UNKNOWN,
GTK_LICENSE_CUSTOM,
GTK_LICENSE_GPL_2_0,
GTK_LICENSE_GPL_3_0,
GTK_LICENSE_LGPL_2_1,
GTK_LICENSE_LGPL_3_0,
GTK_LICENSE_BSD,
GTK_LICENSE_MIT_X11,
GTK_LICENSE_ARTISTIC,
GTK_LICENSE_GPL_2_0_ONLY,
GTK_LICENSE_GPL_3_0_ONLY,
GTK_LICENSE_LGPL_2_1_ONLY,
GTK_LICENSE_LGPL_3_0_ONLY,
GTK_LICENSE_AGPL_3_0,
GTK_LICENSE_AGPL_3_0_ONLY,
GTK_LICENSE_BSD_3,
GTK_LICENSE_APACHE_2_0,
GTK_LICENSE_MPL_2_0
} GtkLicense;
#define G_TYPE_FUNDAMENTAL_SHIFT (2) #define G_TYPE_FUNDAMENTAL_SHIFT (2)
#define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT)) #define G_TYPE_MAKE_FUNDAMENTAL(x) ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
#define G_TYPE_INT G_TYPE_MAKE_FUNDAMENTAL (6) #define G_TYPE_INT G_TYPE_MAKE_FUNDAMENTAL (6)
#define GTK_STYLE_PROVIDER_PRIORITY_USER 800
#endif #endif
// GLib
DECL(GTimer*, g_timeout_add, (guint interval, GSourceFunc func, gpointer data));
// Gtk Application / Window / Widget
DECL(GtkApplication *, gtk_application_new, (const char *name, GApplicationFlags flags)) DECL(GtkApplication *, gtk_application_new, (const char *name, GApplicationFlags flags))
DECL(int, g_application_run, (GApplication* application, int argc, char** argv)) DECL(int, g_application_run, (GApplication* application, int argc, char** argv))
@@ -287,47 +633,138 @@ DECL(void, gtk_window_set_decorated, (GtkWindow* window, gboolean setting ))
DECL(void, gtk_widget_show_all, (GtkWindow *window)) DECL(void, gtk_widget_show_all, (GtkWindow *window))
DECL(void, gtk_widget_hide, (GtkWidget* widget )) DECL(void, gtk_widget_hide, (GtkWidget* widget ))
DECL(void, gtk_widget_show, (GtkWidget* widget))
DECL(gboolean, gtk_widget_grab_focus, ( GtkWidget* widget ))
DECL(GtkWidget*, gtk_event_box_new, (void)) DECL(GtkWidget*, gtk_event_box_new, (void))
DECL(void, gtk_event_box_set_visible_window, (GtkEventBox* event_box, gboolean visible_window ))
DECL(void, gtk_window_get_size, (GtkWindow *win, int *width, int *height)) DECL(void, gtk_window_get_size, (GtkWindow *win, int *width, int *height))
DECL(void, gtk_window_resize, (GtkWindow* window, gint width, gint height)) DECL(void, gtk_window_resize, (GtkWindow* window, gint width, gint height))
DECL(void, gtk_window_set_default_size, (GtkWindow *window, gint width, gint height)) DECL(void, gtk_window_set_default_size, (GtkWindow *window, gint width, gint height))
DECL(void, gtk_window_get_position, (GtkWindow* window, gint* root_x, gint* root_y)) DECL(void, gtk_window_get_position, (GtkWindow* window, gint* root_x, gint* root_y))
DECL(void, gtk_window_move, (GtkWindow* window, gint x, gint y)) DECL(void, gtk_window_move, (GtkWindow* window, gint x, gint y))
DECL(void, gtk_window_present, (GtkWindow* window))
DECL(void, gtk_window_set_type_hint, (GtkWindow* window, GdkWindowTypeHint hint))
DECL(void, gtk_window_set_skip_taskbar_hint, (GtkWindow* window, gboolean setting))
DECL(void, gtk_window_set_skip_pager_hint, (GtkWindow* window, gboolean setting))
DECL(void, gtk_widget_set_can_focus, (GtkWidget* widget, gboolean can_focus ))
DECL(void, gtk_window_set_transient_for, (GtkWindow* window, GtkWindow* parent ))
DECL(GType, gtk_window_get_type, (void))
DECL(GObject*, g_object_new, (GType object_type, const gchar* first_property_name, ...))
DECL(void, gtk_widget_set_size_request, (GtkWidget* widget, int width, int height ))
DECL(void, gtk_widget_get_preferred_size, (GtkWidget* widget, GtkRequisition* minimum_size, GtkRequisition* natural_size))
DECL(void, gtk_widget_get_allocation, ( GtkWidget* widget, GtkAllocation* allocation ))
DECL(void, gtk_window_set_resizable, (GtkWindow* window, gboolean resizable)) DECL(void, gtk_window_set_resizable, (GtkWindow* window, gboolean resizable))
DECL(GdkWindow *, gtk_widget_get_window, (GtkWidget *w)); DECL(GdkWindow *, gtk_widget_get_window, (GtkWidget *w));
DECL(GdkWindow*, gdk_window_get_effective_toplevel, (GdkWindow* window))
DECL(void, gdk_window_set_override_redirect, (GdkWindow* window, gboolean override_redirect))
DECL(GtkWidget*, gtk_scrolled_window_new, (GtkAdjustment* hadjustment, GtkAdjustment* vadjustment))
DECL(gboolean, gtk_window_get_decorated, (GtkWindow* window)) DECL(gboolean, gtk_window_get_decorated, (GtkWindow* window))
DECL(void, gdk_window_set_events, (GdkWindow* window, GdkEventMask event_mask )) DECL(void, gdk_window_set_events, (GdkWindow* window, GdkEventMask event_mask ))
DECL(GdkEventMask, gdk_window_get_events, (GdkWindow* window ))
DECL(void, gtk_window_set_title, (GtkWindow* window, const gchar* title)) DECL(void, gtk_window_set_title, (GtkWindow* window, const gchar* title))
DECL(const gchar*, gtk_window_get_title, (GtkWindow* window)) DECL(const gchar*, gtk_window_get_title, (GtkWindow* window))
DECL(void, gtk_widget_destroy, (GtkWidget* widget)) DECL(void, gtk_widget_destroy, (GtkWidget* widget))
DECL(void, gtk_container_add, (GtkContainer* container, GtkWidget* widget)) DECL(void, gtk_container_add, (GtkContainer* container, GtkWidget* widget))
DECL(void, gtk_container_remove, (GtkContainer* container, GtkWidget* widget))
DECL(void, gtk_container_set_border_width, (GtkContainer *container, guint width));
DECL(gboolean, gtk_widget_is_visible, (GtkWidget* widget)) DECL(gboolean, gtk_widget_is_visible, (GtkWidget* widget))
DECL(GtkWidget*, gtk_label_new, (const char* str)) DECL(GtkWidget*, gtk_label_new, (const char* str))
DECL(void, gtk_label_set_ellipsize, (GtkLabel* label, PangoEllipsizeMode mode)) DECL(void, gtk_label_set_ellipsize, (GtkLabel* label, PangoEllipsizeMode mode))
DECL(void, gtk_label_set_label, (GtkLabel* label, const gchar* str)) DECL(void, gtk_label_set_label, (GtkLabel* label, const gchar* str))
DECL(const gchar*, gtk_label_get_text, (GtkLabel* label)) DECL(const gchar*, gtk_label_get_text, (GtkLabel* label))
DECL(GtkWidget*, gtk_entry_new, (void))
DECL(void, gtk_entry_set_text, (GtkEntry* entry, const gchar* text ))
DECL(const gchar*, gtk_entry_get_text, (GtkEntry* entry))
DECL(GtkWidget*, gtk_separator_new, ( GtkOrientation orientation ))
DECL(GtkWidget*, gtk_frame_new, ( const gchar* label ))
DECL(void, gtk_frame_set_shadow_type, (GtkFrame* frame, GtkShadowType type ))
DECL(GtkWidget*, gtk_box_new, (GtkOrientation orientation, gint spacing )) DECL(GtkWidget*, gtk_box_new, (GtkOrientation orientation, gint spacing ))
DECL(void, gtk_widget_set_vexpand, (GtkWidget* widget, gboolean expand ))
DECL(void, gtk_widget_set_hexpand, (GtkWidget* widget, gboolean expand ))
DECL(void, gtk_widget_set_halign, (GtkWidget* widget, GtkAlign align ))
DECL(void, gtk_widget_set_valign, (GtkWidget* widget, GtkAlign align ))
DECL(GtkWidget*,gtk_grid_new, (void))
DECL(void, gtk_grid_attach, (GtkGrid* grid, GtkWidget* child, gint left, gint top, gint width, gint height ))
DECL(GtkWidget*, gtk_color_button_new, (void ))
DECL(void, gtk_color_chooser_set_rgba, (GtkColorChooser* chooser, const GdkRGBA* color ))
DECL(void, gtk_color_chooser_get_rgba, (GtkColorChooser* chooser, GdkRGBA* color ))
DECL(gboolean, gtk_widget_translate_coordinates, ( GtkWidget* src_widget, GtkWidget* dest_widget, gint src_x, gint src_y, gint* dest_x, gint* dest_y))
DECL(void, gtk_main, (void)) DECL(void, gtk_main, (void))
DECL(void, gtk_main_quit, (void)) DECL(void, gtk_main_quit, (void))
DECL(GdkEvent*, gtk_get_current_event, (void ))
DECL(void, gtk_main_do_event, (GdkEvent* event))
DECL(void, gdk_event_free, (GdkEvent* event))
DECL(GtkWidget*, gtk_spin_button_new_with_range, (gdouble min, gdouble max, gdouble step))
DECL(void, gtk_spin_button_set_value, (GtkSpinButton* spin_button, gdouble value ))
DECL(gint, gtk_spin_button_get_value_as_int, (GtkSpinButton* spin_button ))
DECL(unsigned long, g_signal_connect_data, (GObject *obj, const char *signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags)) DECL(unsigned long, g_signal_connect_data, (GObject *obj, const char *signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags))
// Messages
DECL(GtkWidget*, gtk_message_dialog_new, (GtkWindow* parent, GtkDialogFlags flags, GtkMessageType type, GtkButtonsType buttons, const gchar* message_format, ...))
DECL(gint, gtk_dialog_run, (GtkDialog* dialog))
// Dialogs
DECL(GtkWidget*, gtk_dialog_new, (void))
DECL(GtkWidget*, gtk_dialog_add_button, (GtkDialog* dialog, const gchar* button_text, gint response_id ))
DECL(void, gtk_dialog_response, (GtkDialog* dialog, gint response_id ))
//DECL(GtkWidget*, gtk_dialog_new_with_buttons, (const gchar* title, GtkWindow* parent, GtkDialogFlags flags, const gchar* first_button_text, ...))
//DECL(GtkWidget*, gtk_drop_down_new_from_strings, (const char* const* strings ))
DECL(GtkWidget*, gtk_combo_box_new, (void));
DECL(GtkWidget*, gtk_combo_box_text_new, (void))
DECL(void, gtk_combo_box_text_append, ( GtkComboBoxText* combo_box, const gchar* id, const gchar* text ))
DECL(GtkWidget*, gtk_dialog_get_content_area, (GtkDialog* dialog ))
DECL(gboolean, gtk_combo_box_set_active_id, ( GtkComboBox* combo_box, const gchar* active_id ))
DECL(const gchar*, gtk_combo_box_get_active_id, (GtkComboBox* combo_box))
// Gdk Monitor/Screen
DECL(GdkDisplay*, gdk_display_get_default, (void))
DECL(int, gdk_display_get_n_monitors, (GdkDisplay* display))
DECL(GdkMonitor*, gdk_display_get_monitor, (GdkDisplay* display, int monitor_num))
DECL(void, gdk_monitor_get_geometry, (GdkMonitor* monitor, GdkRectangle* geometry))
DECL(GList*, gdk_screen_get_window_stack, (GdkScreen* screen))
DECL(GdkScreen*, gdk_screen_get_default, (void))
// About
DECL(GtkWidget*, gtk_about_dialog_new, (void))
DECL(void, gtk_about_dialog_set_authors, (GtkAboutDialog* about,const gchar** authors))
DECL(void, gtk_about_dialog_set_copyright, (GtkAboutDialog* about, const gchar* copyright ))
DECL(void, gtk_about_dialog_set_license_type, (GtkAboutDialog* about, GtkLicense license_type))
DECL(void, gtk_about_dialog_set_logo, (GtkAboutDialog* about, GdkPixbuf* logo ))
DECL(void, gtk_about_dialog_set_program_name, (GtkAboutDialog* about,const gchar* name))
DECL(void, gtk_about_dialog_set_version, (GtkAboutDialog* about, const gchar* version))
// GObject / GValue // GObject / GValue
DECL(void, g_object_unref, (GObject* object)) DECL(void, g_object_unref, (GObject* object))
DECL(void, g_object_ref, (GObject* object))
DECL(void, g_object_set_property, (GObject* object, const gchar* property_name, const GValue* value)) DECL(void, g_object_set_property, (GObject* object, const gchar* property_name, const GValue* value))
DECL(GValue*, g_value_init, (GValue* value, GType g_type)) DECL(GValue*, g_value_init, (GValue* value, GType g_type))
DECL(void, g_value_unset, (GValue* value)) DECL(void, g_value_unset, (GValue* value))
DECL(void, g_value_set_int, (GValue* value, gint v_int)) DECL(void, g_value_set_int, (GValue* value, gint v_int))
DECL(void, g_free, (gpointer mem))
// Cursors
DECL(GdkCursor*, gdk_cursor_new_from_name, (GdkDisplay* display, const gchar* name ))
DECL(GdkCursor*, gdk_cursor_new, ( GdkCursorType cursor_type ))
DECL(void, gdk_window_set_cursor, (GdkWindow* window, GdkCursor* cursor ))
// Menus // Menus
@@ -338,6 +775,8 @@ DECL(GtkMenuItem *, gtk_menu_item_new, (void));
DECL(GtkMenuItem *, gtk_menu_item_new_with_label, (const gchar *label)); DECL(GtkMenuItem *, gtk_menu_item_new_with_label, (const gchar *label));
DECL(void, gtk_menu_shell_append, (GtkMenuShell* menu_shell, GtkWidget* child)) DECL(void, gtk_menu_shell_append, (GtkMenuShell* menu_shell, GtkWidget* child))
DECL(GtkWidget *, gtk_separator_menu_item_new, (void)) DECL(GtkWidget *, gtk_separator_menu_item_new, (void))
DECL(void, gtk_menu_popup, (GtkMenu* menu, GtkWidget* parent_menu_shell, GtkWidget* parent_menu_item,
GtkMenuPositionFunc func, gpointer data, guint button, guint32 activate_time))
// Text Buffer / Widget // Text Buffer / Widget
DECL(GtkTextBuffer*, gtk_text_buffer_new, (GtkTextTagTable* table)) DECL(GtkTextBuffer*, gtk_text_buffer_new, (GtkTextTagTable* table))
@@ -347,17 +786,42 @@ DECL(void, gtk_text_buffer_get_end_iter, (GtkTextBuffer* buffer, GtkTextIter* it
DECL(GtkWidget*, gtk_text_view_new, (void)) DECL(GtkWidget*, gtk_text_view_new, (void))
DECL(GtkWidget*, gtk_text_view_new_with_buffer, ( GtkTextBuffer* buffer )) DECL(GtkWidget*, gtk_text_view_new_with_buffer, ( GtkTextBuffer* buffer ))
DECL(void, gtk_text_buffer_set_text, (GtkTextBuffer* buffer, const gchar* text, gint len )) DECL(void, gtk_text_buffer_set_text, (GtkTextBuffer* buffer, const gchar* text, gint len ))
DECL(void, gtk_text_view_set_wrap_mode, (GtkTextView* text_view, GtkWrapMode wrap_mode ))
// Titlebar // Titlebar
DECL(GtkWidget*, gtk_header_bar_new, (void)) DECL(GtkWidget*, gtk_header_bar_new, (void))
DECL(void, gtk_header_bar_set_custom_title, (GtkHeaderBar* bar, GtkWidget* title_widget)) DECL(void, gtk_header_bar_set_custom_title, (GtkHeaderBar* bar, GtkWidget* title_widget))
// Deprecated in Gtk3 // Image
DECL(GtkWidget*, gtk_image_new_from_file, (const char* filename ))
DECL(GtkWidget*, gtk_image_new_from_pixbuf, (GdkPixbuf* pixbuf ))
DECL(void, gtk_image_set_from_pixbuf, ( GtkImage* image, GdkPixbuf* pixbuf ))
DECL(GdkPixbuf*, gdk_pixbuf_new_from_file, (const char* filename, GError** error))
DECL(GdkPixbuf*, gdk_pixbuf_new_from_file_at_size, (const char* filename, int width, int height, GError** error))
// Styles
DECL(GtkStyleContext*, gtk_widget_get_style_context, (GtkWidget* widget))
DECL(char*, gtk_style_context_to_string, (GtkStyleContext* context, GtkStyleContextPrintFlags flags))
DECL(GtkCssProvider*, gtk_css_provider_new, (void))
DECL(gboolean, gtk_css_provider_load_from_data, (GtkCssProvider* css_provider, const gchar* data, gssize length, GError** error))
DECL(void, gtk_style_context_add_provider, (GtkStyleContext* context, GtkStyleProvider* provider, guint priority))
DECL(const GtkWidgetPath*, gtk_style_context_get_path, (GtkStyleContext* context))
DECL(char*, gtk_widget_path_to_string, (const GtkWidgetPath* path))
// Deprecated in Gtk3
DECL(GtkStatusIcon*, gtk_status_icon_new, (void )) DECL(GtkStatusIcon*, gtk_status_icon_new, (void ))
DECL(GtkStatusIcon*, gtk_status_icon_new_from_file, (const gchar* filename)) DECL(GtkStatusIcon*, gtk_status_icon_new_from_file, (const gchar* filename))
DECL(void, gtk_widget_override_background_color, (GtkWidget* widget, GtkStateFlags state, const GdkRGBA* color))
DECL(void, gtk_window_set_has_resize_grip, (GtkWindow* window, gboolean value ))
#define g_signal_connect(instance, signal, c_handler, data) \ #define g_signal_connect(instance, signal, c_handler, data) \
g_signal_connect_data(instance, signal, reinterpret_cast<void *>(c_handler), data, NULL, G_CONNECT_DEFAULT) g_signal_connect_data(instance, signal, reinterpret_cast<void *>(c_handler), data, NULL, G_CONNECT_DEFAULT)
// WIN32
#ifdef _WIN32
#include <windows.h>
DECL(HWND, gdk_win32_window_get_handle, (GdkWindow *window));
#endif
#endif // GTK_IMPORTS_H #endif // GTK_IMPORTS_H

View File

@@ -11,22 +11,31 @@ 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
#include <iostream>
#include "info_over_me.h"
void GtkLoader::loadLibraryWin64(const char *lib, void **handle) void GtkLoader::loadLibraryWin64(const char *lib, void **handle)
{ {
#ifdef _WIN32 #ifdef _WIN32
#define DIR "C:\\devel\\yellownotes\\gtk3\\bin" InfoOverMe info;
//#define DIR "C:\\devel\\yellownotes\\gtk3\\bin"
HMODULE dll = nullptr; HMODULE dll = nullptr;
std::string dir = DIR; std::string my_dir = info.containingFolder();
std::string dir = my_dir + "\\gtk3";
std::cout << "my folder = " << dir << std::endl;
*handle = nullptr; *handle = nullptr;
auto mklibname = [](const char *libname) { auto mklibname = [dir](const char *libname) {
std::string dll; std::string dll;
dll = std::string(DIR) + "\\" + libname + ".dll"; dll = std::string(libname) + ".dll";
std::cout << "library: " << dll << std::endl;
return dll; return dll;
}; };
@@ -60,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
@@ -105,6 +141,8 @@ void GtkLoader::dlopen()
"gtk-3-vs17", "gtk-3-vs17",
"glib-2.0-0", "glib-2.0-0",
"gio-2.0-0", "gio-2.0-0",
"gdk-3-vs17",
"gdk_pixbuf-2.0-0",
NULL NULL
}; };
int i; int i;
@@ -121,6 +159,7 @@ void GtkLoader::dlopen()
"libgio-2.0.so", "libgio-2.0.so",
"libglib-2.0.so", "libglib-2.0.so",
"libgdk-3.so", "libgdk-3.so",
"libgdk_pixbuf-2.0.so",
NULL NULL
}; };
int i; int i;
@@ -129,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
} }
} }
@@ -141,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)

View File

@@ -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();

BIN
hide.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

27
hide.svg Normal file
View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg fill="#000000" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="800px" height="800px" viewBox="0 0 572.098 572.098"
xml:space="preserve">
<g>
<g>
<path d="M99.187,398.999l44.333-44.332c-24.89-15.037-47.503-33.984-66.763-56.379c29.187-33.941,66.053-60.018,106.947-76.426
c-6.279,14.002-9.853,29.486-9.853,45.827c0,16.597,3.696,32.3,10.165,46.476l35.802-35.797
c-5.698-5.594-9.248-13.36-9.248-21.977c0-17.02,13.801-30.82,30.82-30.82c8.611,0,16.383,3.55,21.971,9.248l32.534-32.534
l36.635-36.628l18.366-18.373c-21.206-4.186-42.896-6.469-64.848-6.469c-107.663,0-209.732,52.155-273.038,139.518L0,298.288
l13.011,17.957C36.83,349.116,66.151,376.999,99.187,398.999z"/>
<path d="M459.208,188.998l-44.854,44.854c30.539,16.071,58.115,37.846,80.986,64.437
c-52.167,60.662-128.826,96.273-209.292,96.273c-10.3,0-20.533-0.6-30.661-1.744l-52.375,52.375
c26.903,6.887,54.762,10.57,83.036,10.57c107.663,0,209.738-52.154,273.038-139.523l13.011-17.957l-13.011-17.956
C532.023,242.995,497.844,212.15,459.208,188.998z"/>
<path d="M286.049,379.888c61.965,0,112.198-50.234,112.198-112.199c0-5.588-0.545-11.035-1.335-16.402L269.647,378.56
C275.015,379.349,280.461,379.888,286.049,379.888z"/>
<path d="M248.815,373.431L391.79,230.455l4.994-4.994l45.796-45.796l86.764-86.77c13.543-13.543,13.543-35.502,0-49.046
c-6.77-6.769-15.649-10.159-24.523-10.159s-17.754,3.384-24.522,10.159l-108.33,108.336l-22.772,22.772l-29.248,29.248
l-48.14,48.14l-34.456,34.456l-44.027,44.027l-33.115,33.115l-45.056,45.055l-70.208,70.203
c-13.543,13.543-13.543,35.502,0,49.045c6.769,6.77,15.649,10.16,24.523,10.16s17.754-3.385,24.523-10.16l88.899-88.898
l50.086-50.086L248.815,373.431z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

119
info_over_me.cpp Normal file
View File

@@ -0,0 +1,119 @@
#include "info_over_me.h"
#include "utils/whereami.h"
#include <iostream>
#if defined(__linux) || defined(TARGET_OS_OSX)
#include <unistd.h>
#endif
#ifdef _WIN32
#include <windows.h>
#endif
extern "C" {
#include "gtk-imports.h"
}
#include <list>
#include <filesystem>
std::string InfoOverMe::containingFolder()
{
int len = wai_getExecutablePath(NULL, 0, NULL);
char *path = static_cast<char *>(malloc(len + 1));
wai_getExecutablePath(path, len, NULL);
path[len] = '\0';
std::filesystem::path p(path);
if (std::filesystem::is_regular_file(p)) {
std::filesystem::path pp = p.parent_path();
return pp.string();
} else {
return p.string();
}
}
std::string InfoOverMe::myHostname()
{
char buf[10240];
#if defined(__linux) || defined(TARGET_OS_OSX)
int r = gethostname(buf, 10240);
#endif
#ifdef _WIN32
DWORD size = 10240;
bool r = GetComputerNameA(buf, &size);
buf[size] = '\0';
if (!r) { sprintf(buf, "unknown"); }
#endif
std::string name(buf);
return name;
}
std::string InfoOverMe::myOsHostname()
{
std::string os;
#ifdef __linux
os = "linux";
#else
#ifdef _WIN32
os = "windows";
#else
#ifdef TARGET_OS_OSX
os = "osx";
#else
os = "unknown";
#endif
#endif
#endif
return os + "_" + myHostname();
}
std::string InfoOverMe::myId()
{
std::list<GdkRectangle> l;
GdkDisplay *d = gdk_display_get_default();
int n = gdk_display_get_n_monitors(d);
int i;
for(i = 0; i < n; i++) {
GdkMonitor *m = gdk_display_get_monitor(d, i);
GdkRectangle r;
gdk_monitor_get_geometry(m, &r);
l.push_back(r);
//std::cout << r.width << ", " << r.height << ", x = " << r.x << ", y = " << r.y << std::endl;
}
auto compare = [](const GdkRectangle &a, const GdkRectangle &b) {
if (a.x < b.x) {
return true;
} else if (a.x > b. x) {
return false;
} else if (a.y < b.y) {
return true;
} else {
return false;
}
};
l.sort(compare);
std::list<GdkRectangle>::iterator it;
std::string monitor_id;
std::string sep = "";
for(it = l.begin(); it != l.end(); it++) {
char buf[200];
const GdkRectangle &r = *it;
sprintf(buf, "%d-%d-%d-%d", r.x, r.y, r.width, r.height);
std::string geom(buf);
monitor_id += sep;
monitor_id += geom;
sep = "-";
}
monitor_id = myOsHostname() + "/" + monitor_id;
return monitor_id;
}
InfoOverMe::InfoOverMe() {}

20
info_over_me.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef INFO_OVER_ME_H
#define INFO_OVER_ME_H
#include <string>
class InfoOverMe
{
public:
std::string containingFolder();
public:
std::string myHostname();
std::string myOsHostname();
std::string myId();
public:
InfoOverMe();
};
#endif // INFO_OVER_ME_H

View File

@@ -6,26 +6,54 @@ extern "C" {
} }
#include "yellownotes.h" #include "yellownotes.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;
YellowNotes *notes = YELLOWNOTES(user_data); YellowNotes *notes = YELLOWNOTES(user_data);
GtkStatusIcon *tray = gtk_status_icon_new_from_file(notes->imageFile("yellownotes.svg").c_str()); std::string img_file = notes->imageFile("yellownotes");
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);
#ifdef _WIN32
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
return runMain(__argc, __argv);
}
#else
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
return runMain(argc, argv);
}
#endif
int runMain(int argc, char **argv)
{
GtkLoader l; GtkLoader l;
InfoOverMe w;
srand(time(NULL)); // seed with current time
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;

BIN
plus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

4
plus.svg Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg fill="#000000" width="800px" height="800px" viewBox="0 0 256 256" id="Flat" xmlns="http://www.w3.org/2000/svg">
<path d="M228,128a12,12,0,0,1-12,12H140v76a12,12,0,0,1-24,0V140H40a12,12,0,0,1,0-24h76V40a12,12,0,0,1,24,0v76h76A12,12,0,0,1,228,128Z"/>
</svg>

After

Width:  |  Height:  |  Size: 381 B

BIN
title_only.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

2
title_only.svg Normal file
View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg fill="#000000" width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M20 3H4c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2h16c1.103 0 2-.897 2-2V5c0-1.103-.897-2-2-2zm0 2 .001 4H4V5h16zM4 19v-8h16.001l.001 8H4z"/><path d="M14 6h2v2h-2zm3 0h2v2h-2z"/></svg>

After

Width:  |  Height:  |  Size: 414 B

BIN
to_desktop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

4
to_desktop.svg Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M18.3137 0.918778C18.6347 1.36819 18.5307 1.99274 18.0812 2.31375L16.4248 3.49692L17.2572 3.67529C20.0236 4.26809 22 6.71287 22 9.5421V10C22 10.5523 21.5523 11 21 11C20.4477 11 20 10.5523 20 10V9.5421C20 7.65595 18.6824 6.02609 16.8381 5.63089L15.9784 5.44667L16.8682 7.00388C17.1423 7.48339 16.9757 8.09425 16.4961 8.36826C16.0166 8.64227 15.4058 8.47567 15.1318 7.99616L13.1318 4.49616C12.8771 4.05058 13.0012 3.48458 13.4188 3.18629L16.9188 0.686284C17.3682 0.365274 17.9927 0.469365 18.3137 0.918778ZM6 12C6 10.8954 6.89543 10 8 10H16C17.1046 10 18 10.8954 18 12V20C18 21.1046 17.1046 22 16 22H8C6.89543 22 6 21.1046 6 20V12ZM16 20V12H8V20H16ZM4 6.00002C2.89543 6.00002 2 6.89545 2 8.00002V16C2 16.5523 2.44772 17 3 17C3.55228 17 4 16.5523 4 16V8.00002H12C12.5523 8.00002 13 7.5523 13 7.00002C13 6.44773 12.5523 6.00002 12 6.00002H4Z" fill="#000000"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

126
tr.cpp Normal file
View File

@@ -0,0 +1,126 @@
#include "tr.h"
#include <stdarg.h>
#include <iostream>
void tr::add(const char *sentence, ...)
{
va_list args;
va_start(args, sentence);
std::string sent(sentence);
const char *tr = va_arg(args, char *);
while (tr != nullptr) {
std::string t(tr);
size_t pos = t.find(":");
std::string lang = t.substr(0, pos);
std::string str = t.substr(pos + 1);
std::unordered_map<std::string, Translations_t *>::iterator it;
it = _translations.find(lang);
if (it != _translations.end()) {
Translations_t *m = it->second;
std::pair p = { sent, str };
m->insert(p);
} else {
Translations_t *m = new Translations_t();
std::pair p = { sent, str };
m->insert(p);
std::pair lp = { lang, m };
_translations.insert(lp);
}
tr = va_arg(args, char *);
}
va_end(args);
}
const char *tr::translate(const char *str)
{
std::unordered_map<std::string, Translations_t *>::iterator it;
if (_lang == "en") { return str; }
it = _translations.find(_lang);
if (it == _translations.end()) {
std::cerr << "No translation for: " << str << std::endl;
return str;
} else {
Translations_t *m = it->second;
Translations_t::iterator n_it;
std::string s(str);
n_it = m->find(s);
if (n_it == m->end()) {
std::cerr << "No translation for: " << str << std::endl;
return str;
} else {
return n_it->second.c_str();
}
}
}
void tr::setLang(const std::string &l)
{
_lang = l;
}
#define nl(a, b) add(a, "nl:" b, nullptr)
#define en(a, b) add(a, "en:" b, nullptr)
tr::tr()
{
nl("Quit", "Beëindigen");
nl("New Note", "Nieuwe Notitie");
nl("Show Notes", "Notities Presenteren");
nl("Hide Notes", "Notities Verbergen");
nl("Reload Notes", "Notities opnieuw laden");
nl("Setup", "Instellingen");
nl("Notes on desktop", "Noties naar achteren");
nl("Language:", "Taalinstelling:");
nl("Language:", "Taalinstelling:");
nl("Ok", "Ok");
nl("Yellownotes Setup", "Yellownotes Instellingen");
nl("Foreground Color", "Voorgrond kleur");
nl("Background Color", "Achtergrond kleur");
nl("Dark", "Donker");
nl("Yellow", "Geel");
nl("Orange", "Oranje");
nl("Blue", "Blauw");
nl("Cyan", "Cyaan");
nl("Green", "Groen");
nl("Red", "Rood");
nl("Grey", "Grijs");
nl("Font size:", "Lettertype Grootte:");
nl("Actual Font Size in Note", "Werkelijke lettertype grootte in de notitie");
nl("Reorder Notes", "Notities opnieuw ordenen");
nl("About", "Over...");
nl("(c) 2025", "(c) 2025");
nl("Version %s, file format version: %d", "Versie %s, bestandsformaat versie: %d");
nl("Yellow Notes", "Geeltjes");
_lang = "en";
}
static tr *_t = nullptr;
static void init()
{
if (_t == nullptr) {
_t = new tr();
}
}
const char *_(const char *str)
{
init();
return _t->translate(str);
}
void setLang(const std::string &lang)
{
init();
_t->setLang(lang);
}

31
tr.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef TR_H
#define TR_H
#include <string>
#include <unordered_map>
typedef std::unordered_map<std::string, std::string> Translations_t;
class tr
{
private:
std::unordered_map<std::string, Translations_t *> _translations;
std::string _lang;
private:
void add(const char *sentence, ...);
public:
const char *translate(const char *str);
public:
void setLang(const std::string &l);
public:
tr();
};
const char *_(const char *str);
void setLang(const std::string &lang);
#endif // TR_H

815
utils/whereami.c Normal file
View File

@@ -0,0 +1,815 @@
// (‑●‑●)> dual licensed under the WTFPL v2 and MIT licenses
// without any warranty.
// by Gregory Pakosz (@gpakosz)
// https://github.com/gpakosz/whereami
// in case you want to #include "whereami.c" in a larger compilation unit
#if !defined(WHEREAMI_H)
#include "whereami.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__linux__) || defined(__CYGWIN__)
#undef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#elif defined(__APPLE__)
#undef _DARWIN_C_SOURCE
#define _DARWIN_C_SOURCE
#define _DARWIN_BETTER_REALPATH
#endif
#if !defined(WAI_MALLOC) || !defined(WAI_FREE) || !defined(WAI_REALLOC)
#include <stdlib.h>
#endif
#if !defined(WAI_MALLOC)
#define WAI_MALLOC(size) malloc(size)
#endif
#if !defined(WAI_FREE)
#define WAI_FREE(p) free(p)
#endif
#if !defined(WAI_REALLOC)
#define WAI_REALLOC(p, size) realloc(p, size)
#endif
#ifndef WAI_NOINLINE
#if defined(_MSC_VER)
#define WAI_NOINLINE __declspec(noinline)
#elif defined(__GNUC__)
#define WAI_NOINLINE __attribute__((noinline))
#else
#error unsupported compiler
#endif
#endif
#if defined(_MSC_VER)
#define WAI_RETURN_ADDRESS() _ReturnAddress()
#elif defined(__GNUC__)
#define WAI_RETURN_ADDRESS() __builtin_extract_return_addr(__builtin_return_address(0))
#else
#error unsupported compiler
#endif
#if defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#if defined(_MSC_VER)
#pragma warning(push, 3)
#endif
#include <windows.h>
#include <intrin.h>
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#if (_MSC_VER >= 1900)
#include <stdbool.h>
#else
#define bool int
#define false 0
#define true 1
#endif
static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, int* dirname_length)
{
wchar_t buffer1[MAX_PATH];
wchar_t buffer2[MAX_PATH];
wchar_t* path = NULL;
int length = -1;
bool ok;
for (ok = false; !ok; ok = true)
{
DWORD size;
int length_, length__;
size = GetModuleFileNameW(module, buffer1, sizeof(buffer1) / sizeof(buffer1[0]));
if (size == 0)
break;
else if (size == (DWORD)(sizeof(buffer1) / sizeof(buffer1[0])))
{
DWORD size_ = size;
do
{
wchar_t* path_;
path_ = (wchar_t*)WAI_REALLOC(path, sizeof(wchar_t) * size_ * 2);
if (!path_)
break;
size_ *= 2;
path = path_;
size = GetModuleFileNameW(module, path, size_);
}
while (size == size_);
if (size == size_)
break;
}
else
path = buffer1;
if (!_wfullpath(buffer2, path, MAX_PATH))
break;
length_ = (int)wcslen(buffer2);
length__ = WideCharToMultiByte(CP_UTF8, 0, buffer2, length_ , out, capacity, NULL, NULL);
if (length__ == 0)
length__ = WideCharToMultiByte(CP_UTF8, 0, buffer2, length_, NULL, 0, NULL, NULL);
if (length__ == 0)
break;
if (length__ <= capacity && dirname_length)
{
int i;
for (i = length__ - 1; i >= 0; --i)
{
if (out[i] == '\\')
{
*dirname_length = i;
break;
}
}
}
length = length__;
}
if (path != buffer1)
WAI_FREE(path);
return ok ? length : -1;
}
WAI_NOINLINE WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
{
return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length);
}
WAI_NOINLINE WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
HMODULE module;
int length = -1;
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4054)
#endif
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCTSTR)WAI_RETURN_ADDRESS(), &module))
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
{
length = WAI_PREFIX(getModulePath_)(module, out, capacity, dirname_length);
}
return length;
}
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || defined(WAI_USE_PROC_SELF_EXE)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__linux__)
#include <linux/limits.h>
#else
#include <limits.h>
#endif
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#include <stdbool.h>
#if !defined(WAI_PROC_SELF_EXE)
#if defined(__sun)
#define WAI_PROC_SELF_EXE "/proc/self/path/a.out"
#else
#define WAI_PROC_SELF_EXE "/proc/self/exe"
#endif
#endif
WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
{
char buffer[PATH_MAX];
char* resolved = NULL;
int length = -1;
bool ok;
for (ok = false; !ok; ok = true)
{
resolved = realpath(WAI_PROC_SELF_EXE, buffer);
if (!resolved)
break;
length = (int)strlen(resolved);
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
}
return ok ? length : -1;
}
#if !defined(WAI_PROC_SELF_MAPS_RETRY)
#define WAI_PROC_SELF_MAPS_RETRY 5
#endif
#if !defined(WAI_PROC_SELF_MAPS)
#if defined(__sun)
#define WAI_PROC_SELF_MAPS "/proc/self/map"
#else
#define WAI_PROC_SELF_MAPS "/proc/self/maps"
#endif
#endif
#if !defined(WAI_STRINGIZE)
#define WAI_STRINGIZE(s)
#define WAI_STRINGIZE_(s) #s
#endif
#if defined(__ANDROID__) || defined(ANDROID)
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#endif
#include <stdbool.h>
WAI_NOINLINE WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
int length = -1;
FILE* maps = NULL;
for (int r = 0; r < WAI_PROC_SELF_MAPS_RETRY; ++r)
{
maps = fopen(WAI_PROC_SELF_MAPS, "r");
if (!maps)
break;
for (;;)
{
char buffer[128 + PATH_MAX];
uintptr_t low, high;
char perms[5];
uint64_t offset;
uint32_t major, minor, inode;
char path[PATH_MAX + 1];
if (!fgets(buffer, sizeof(buffer), maps))
break;
if (sscanf(buffer, "%" SCNxPTR "-%" SCNxPTR " %s %" SCNx64 " %x:%x %u %" WAI_STRINGIZE(PATH_MAX) "[^\n]\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
{
void* _addr = WAI_RETURN_ADDRESS();
uintptr_t addr = (uintptr_t)_addr;
if (low <= addr && addr <= high)
{
char* resolved;
resolved = realpath(path, buffer);
if (!resolved)
break;
length = (int)strlen(resolved);
#if defined(__ANDROID__) || defined(ANDROID)
if (length > 4
&&buffer[length - 1] == 'k'
&&buffer[length - 2] == 'p'
&&buffer[length - 3] == 'a'
&&buffer[length - 4] == '.')
{
int fd = open(path, O_RDONLY);
if (fd == -1)
{
length = -1; // retry
break;
}
char* begin = (char*)mmap(0, offset, PROT_READ, MAP_SHARED, fd, 0);
if (begin == MAP_FAILED)
{
close(fd);
length = -1; // retry
break;
}
char* p = begin + offset - 30; // minimum size of local file header
while (p >= begin) // scan backwards
{
if (*((uint32_t*)p) == 0x04034b50UL) // local file header signature found
{
uint16_t length_ = *((uint16_t*)(p + 26));
if (length + 2 + length_ < (int)sizeof(buffer))
{
memcpy(&buffer[length], "!/", 2);
memcpy(&buffer[length + 2], p + 30, length_);
length += 2 + length_;
}
break;
}
--p;
}
munmap(begin, offset);
close(fd);
}
#endif
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
break;
}
}
}
fclose(maps);
maps = NULL;
if (length != -1)
break;
}
return length;
}
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <stdbool.h>
WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
{
char buffer1[PATH_MAX];
char buffer2[PATH_MAX];
char* path = buffer1;
char* resolved = NULL;
int length = -1;
bool ok;
for (ok = false; !ok; ok = true)
{
uint32_t size = (uint32_t)sizeof(buffer1);
if (_NSGetExecutablePath(path, &size) == -1)
{
path = (char*)WAI_MALLOC(size);
if (!_NSGetExecutablePath(path, &size))
break;
}
resolved = realpath(path, buffer2);
if (!resolved)
break;
length = (int)strlen(resolved);
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
}
if (path != buffer1)
WAI_FREE(path);
return ok ? length : -1;
}
WAI_NOINLINE WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
char buffer[PATH_MAX];
char* resolved = NULL;
int length = -1;
for(;;)
{
Dl_info info;
if (dladdr(WAI_RETURN_ADDRESS(), &info))
{
resolved = realpath(info.dli_fname, buffer);
if (!resolved)
break;
length = (int)strlen(resolved);
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
}
break;
}
return length;
}
#elif defined(__QNXNTO__)
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <stdbool.h>
#if !defined(WAI_PROC_SELF_EXE)
#define WAI_PROC_SELF_EXE "/proc/self/exefile"
#endif
WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
{
char buffer1[PATH_MAX];
char buffer2[PATH_MAX];
char* resolved = NULL;
FILE* self_exe = NULL;
int length = -1;
bool ok;
for (ok = false; !ok; ok = true)
{
self_exe = fopen(WAI_PROC_SELF_EXE, "r");
if (!self_exe)
break;
if (!fgets(buffer1, sizeof(buffer1), self_exe))
break;
resolved = realpath(buffer1, buffer2);
if (!resolved)
break;
length = (int)strlen(resolved);
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
}
fclose(self_exe);
return ok ? length : -1;
}
WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
char buffer[PATH_MAX];
char* resolved = NULL;
int length = -1;
for(;;)
{
Dl_info info;
if (dladdr(WAI_RETURN_ADDRESS(), &info))
{
resolved = realpath(info.dli_fname, buffer);
if (!resolved)
break;
length = (int)strlen(resolved);
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
}
break;
}
return length;
}
#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <dlfcn.h>
#include <stdbool.h>
#if defined(__OpenBSD__)
#include <unistd.h>
WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
{
char buffer1[4096];
char buffer2[PATH_MAX];
char buffer3[PATH_MAX];
char** argv = (char**)buffer1;
char* resolved = NULL;
int length = -1;
bool ok;
for (ok = false; !ok; ok = true)
{
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
size_t size;
if (sysctl(mib, 4, NULL, &size, NULL, 0) != 0)
break;
if (size > sizeof(buffer1))
{
argv = (char**)WAI_MALLOC(size);
if (!argv)
break;
}
if (sysctl(mib, 4, argv, &size, NULL, 0) != 0)
break;
if (strchr(argv[0], '/'))
{
resolved = realpath(argv[0], buffer2);
if (!resolved)
break;
}
else
{
const char* PATH = getenv("PATH");
if (!PATH)
break;
size_t argv0_length = strlen(argv[0]);
const char* begin = PATH;
while (1)
{
const char* separator = strchr(begin, ':');
const char* end = separator ? separator : begin + strlen(begin);
if (end - begin > 0)
{
if (*(end -1) == '/')
--end;
if (((end - begin) + 1 + argv0_length + 1) <= sizeof(buffer2))
{
memcpy(buffer2, begin, end - begin);
buffer2[end - begin] = '/';
memcpy(buffer2 + (end - begin) + 1, argv[0], argv0_length + 1);
resolved = realpath(buffer2, buffer3);
if (resolved)
break;
}
}
if (!separator)
break;
begin = ++separator;
}
if (!resolved)
break;
}
length = (int)strlen(resolved);
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
}
if (argv != (char**)buffer1)
WAI_FREE(argv);
return ok ? length : -1;
}
#else
WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length)
{
char buffer1[PATH_MAX];
char buffer2[PATH_MAX];
char* path = buffer1;
char* resolved = NULL;
int length = -1;
bool ok;
for (ok = false; !ok; ok = true)
{
#if defined(__NetBSD__)
int mib[4] = { CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME };
#else
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
#endif
size_t size = sizeof(buffer1);
if (sysctl(mib, 4, path, &size, NULL, 0) != 0)
break;
resolved = realpath(path, buffer2);
if (!resolved)
break;
length = (int)strlen(resolved);
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
}
return ok ? length : -1;
}
#endif
WAI_NOINLINE WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
char buffer[PATH_MAX];
char* resolved = NULL;
int length = -1;
for(;;)
{
Dl_info info;
if (dladdr(WAI_RETURN_ADDRESS(), &info))
{
resolved = realpath(info.dli_fname, buffer);
if (!resolved)
break;
length = (int)strlen(resolved);
if (length <= capacity)
{
memcpy(out, resolved, length);
if (dirname_length)
{
int i;
for (i = length - 1; i >= 0; --i)
{
if (out[i] == '/')
{
*dirname_length = i;
break;
}
}
}
}
}
break;
}
return length;
}
#else
#error unsupported platform
#endif
#ifdef __cplusplus
}
#endif

69
utils/whereami.h Normal file
View File

@@ -0,0 +1,69 @@
// (‑●‑●)> dual licensed under the WTFPL v2 and MIT licenses
// without any warranty.
// by Gregory Pakosz (@gpakosz)
// https://github.com/gpakosz/whereami
#ifndef WHEREAMI_H
#define WHEREAMI_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef WAI_FUNCSPEC
#define WAI_FUNCSPEC
#endif
#ifndef WAI_PREFIX
#define WAI_PREFIX(function) wai_##function
#endif
/**
* Returns the path to the current executable.
*
* Usage:
* - first call `int length = wai_getExecutablePath(NULL, 0, NULL);` to
* retrieve the length of the path
* - allocate the destination buffer with `path = (char*)malloc(length + 1);`
* - call `wai_getExecutablePath(path, length, NULL)` again to retrieve the
* path
* - add a terminal NUL character with `path[length] = '\0';`
*
* @param out destination buffer, optional
* @param capacity destination buffer capacity
* @param dirname_length optional recipient for the length of the dirname part
* of the path. Available only when `capacity` is large enough to retrieve the
* path.
*
* @return the length of the executable path on success (without a terminal NUL
* character), otherwise `-1`
*/
WAI_FUNCSPEC
int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length);
/**
* Returns the path to the current module
*
* Usage:
* - first call `int length = wai_getModulePath(NULL, 0, NULL);` to retrieve
* the length of the path
* - allocate the destination buffer with `path = (char*)malloc(length + 1);`
* - call `wai_getModulePath(path, length, NULL)` again to retrieve the path
* - add a terminal NUL character with `path[length] = '\0';`
*
* @param out destination buffer, optional
* @param capacity destination buffer capacity
* @param dirname_length optional recipient for the length of the dirname part
* of the path. Available only when `capacity` is large enough to retrieve the
* path.
*
* @return the length of the module path on success (without a terminal NUL
* character), otherwise `-1`
*/
WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length);
#ifdef __cplusplus
}
#endif
#endif // #ifndef WHEREAMI_H

File diff suppressed because it is too large Load Diff

View File

@@ -3,15 +3,60 @@
#include <string> #include <string>
#include <list> #include <list>
#include <unordered_map>
extern "C" {
#include "gtk-imports.h"
}
class YellowNote; class YellowNote;
class SettingContainer;
#define YELLOWNOTE_MAJOR "1"
#define YELLOWNOTE_MINOR "0"
#define YELLOWNOTE_PATCH "3"
#define YELLOWNOTE_VERSION YELLOWNOTE_MAJOR "." YELLOWNOTE_MINOR "." YELLOWNOTE_PATCH
#define YELLOWNOTE_FILE_VERSION 3
typedef enum {
DARK = 0,
FIRST= DARK,
YELLOW,
ORANGE,
BLUE,
CYAAN,
GREEN,
RED,
GREY,
LAST = GREY
} ColorType_t;
class Geom_t {
public:
int x, y, width, height;
};
class YellowNotes class YellowNotes
{ {
private: private:
void *_tray_menu; void *_tray_menu;
void *_app; void *_app;
void *_dlg;
void *_langs;
std::list<SettingContainer *> _settings_containers;
std::list<YellowNote *> _notes; std::list<YellowNote *> _notes;
int _font_size;
GtkWindow *_toplevel;
std::unordered_map<std::string, std::string> _cfg;
std::list<Geom_t> _monitors;
private:
void loadConfig();
void saveConfig();
public: public:
void loadNotes(); void loadNotes();
@@ -21,11 +66,47 @@ public:
std::string imageFile(const char *name); std::string imageFile(const char *name);
std::string appDir(); std::string appDir();
std::string notesDir(); std::string notesDir();
std::string css(ColorType_t type);
int fontSize();
int iconSize();
GtkWindow *topLevel();
void colorSet(void *sender);
void setFontSize(int size);
public: public:
void popupTrayMenu(); void popupTrayMenu(void *sender);
void newNote(); bool popupTrayMenuBtn(void *sender, GdkEventButton *evt);
void quit(); void newNote(void *sender);
void showNotes(void *sender);
void notesToDesktop(void *sender);
void notesFromDesktop(void *sender);
void reloadNotes(void *sender);
void monitorsChanged(void *sender);
void quit(void *sender);
void topLevelHidden(GtkWidget *sender);
void setup(void *sender);
void reOrder(void *sender);
void setupClose(GtkWidget *sender);
void setupCancel(GtkWidget *sender);
bool setupDel(GtkWidget *sender, void *evt);
void remove(YellowNote *n);
void checkMonitors();
void about(void *sender);
public:
std::string currentLang();
void setCurrentLang(const std::string &l);
bool cfgOnDesktop();
void setCfgOnDesktop(bool y);
std::string getFgColor(ColorType_t type);
std::string getBgColor(ColorType_t type);
void setFgColor(ColorType_t type, const std::string &col);
void setBgColor(ColorType_t type, const std::string &col);
std::string fromRGBA(const GdkRGBA &rgba);
void toRGBA(const std::string &col, GdkRGBA &rgba);
void updateWidgetCss(GtkWidget *w, ColorType_t col);
GtkWidget *getWindow();
public: public:
YellowNotes(void *app); YellowNotes(void *app);
@@ -34,12 +115,16 @@ public:
#define YELLOWNOTES(obj) reinterpret_cast<YellowNotes *>(obj) #define YELLOWNOTES(obj) reinterpret_cast<YellowNotes *>(obj)
#define SIGNAL(type, func, member) \ #define SIGNAL(type, func, member) \
static void func(GObject *obj, gpointer user_data) { type *o = reinterpret_cast<type *>(user_data); o->member(); } static void func(GObject *obj, gpointer user_data) { type *o = reinterpret_cast<type *>(user_data); o->member(obj); }
#define BSIGNAL(type, func, member) \
static gboolean func(GObject *obj, gpointer user_data) { std::cout << user_data << std::endl; type *o = reinterpret_cast<type *>(user_data); return o->member(obj); }
#define SIGNAL2(type, func, member, argtype) \ #define SIGNAL2(type, func, member, argtype) \
static void func(GObject *obj, void *arg, gpointer user_data) { type *o = reinterpret_cast<type *>(user_data); o->member(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(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