Skip to content

Commit

Permalink
fix macos warnings, add RGFW_setClassName
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Sep 21, 2024
1 parent fb46099 commit d6e006c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LIB_EXT = .dll

LIBS += -D _WIN32_WINNT="0x0501"

WARNINGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wstrict-prototypes -Wold-style-definition -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-missing-braces -Wno-missing-variable-declarations -Wno-redundant-decls -Wno-unused-function -Wno-unused-label -Wno-unused-result -Wno-incompatible-pointer-types -Wno-format -Wno-format-extra-args -Wno-implicit-function-declaration -Wno-implicit-int -Wno-pointer-sign -Wno-switch -Wno-switch-default -Wno-switch-enum -Wno-unused-value -Wno-type-limits
WARNINGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wstrict-prototypes -Wold-style-definition -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-missing-braces -Wno-missing-variable-declarations -Wno-redundant-decls -Wno-unused-function -Wno-unused-label -Wno-unused-result -Wno-incompatible-pointer-types -Wno-format -Wno-format-extra-args -Wno-implicit-function-declaration -Wno-implicit-int -Wno-pointer-sign -Wno-switch -Wno-switch-default -Wno-switch-enum -Wno-unused-value -Wno-type-limits
OS_DIR = \\

NO_GLES = 1
Expand Down
37 changes: 34 additions & 3 deletions RGFW.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ typedef struct RGFW_window {
/** * @defgroup Window_management
* @{ */


/*!
* the class name for X11 and WinAPI. apps with the same class will be grouped by the WM
* by default the class name will == the root window's name
*/
RGFWDEF void RGFW_setClassName(char* name);

/*! this has to be set before createWindow is called, else the fulscreen size is used */
RGFWDEF void RGFW_setBufferSize(RGFW_area size); /*!< the buffer cannot be resized (by RGFW) */

Expand Down Expand Up @@ -1637,6 +1644,11 @@ RGFW_window* RGFW_root = NULL;
#define RGFW_HOLD_MOUSE (1L<<2) /*!< hold the moues still */
#define RGFW_MOUSE_LEFT (1L<<3) /* if mouse left the window */

char* RGFW_className = NULL;
void RGFW_setClassName(char* name) {
RGFW_className = name;
}

void RGFW_clipboardFree(char* str) { RGFW_FREE(str); }

RGFW_keyState RGFW_mouseButtons[5] = { {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0} };
Expand Down Expand Up @@ -2563,9 +2575,13 @@ Start of Linux / Unix defines
// In your .desktop app, if you set the property
// StartupWMClass=RGFW that will assoicate the launcher icon
// with your application - robrohan

if (RGFW_className == NULL)
RGFW_className = (char*)name;

XClassHint *hint = XAllocClassHint();
assert(hint != NULL);
hint->res_class = (char*)"RGFW";
hint->res_class = (char*)RGFW_className;
hint->res_name = (char*)name; // just use the window name as the app name
XSetClassHint((Display*) win->src.display, win->src.window, hint);
XFree(hint);
Expand Down Expand Up @@ -4965,7 +4981,9 @@ static const struct wl_callback_listener wl_surface_frame_listener = {
#include <windowsx.h>
#include <shellapi.h>
#include <shellscalingapi.h>


#include <winuser.h>

__declspec(dllimport) int __stdcall WideCharToMultiByte( UINT CodePage, DWORD dwFlags, const WCHAR* lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);

#ifndef RGFW_NO_XINPUT
Expand Down Expand Up @@ -5185,6 +5203,7 @@ RGFW_UNUSED(win); /*!< if buffer rendering is not being used */
}

void RGFW_releaseCursor(RGFW_window* win) {
RGFW_UNUSED(win);
ClipCursor(NULL);
const RAWINPUTDEVICE id = { 0x01, 0x02, RIDEV_REMOVE, NULL };
RegisterRawInputDevices(&id, 1, sizeof(id));
Expand Down Expand Up @@ -5247,7 +5266,10 @@ RGFW_UNUSED(win); /*!< if buffer rendering is not being used */
WNDCLASSA Class = { };
#endif

Class.lpszClassName = name;
if (RGFW_className == NULL)
RGFW_className = (char*)name;

Class.lpszClassName = RGFW_className;
Class.hInstance = inh;
Class.hCursor = LoadCursor(NULL, IDC_ARROW);
Class.lpfnWndProc = WndProc;
Expand Down Expand Up @@ -7191,6 +7213,12 @@ RGFW_UNUSED(win); /*!< if buffer rendering is not being used */

((void (*)(id, SEL, NSUInteger))objc_msgSend)
(NSApp, sel_registerName("setActivationPolicy:"), NSApplicationActivationPolicyRegular);

if (RGFW_className != NULL) {
NSString* str = NSString_stringWithUTF8String(RGFW_className);
((void (*)(id, SEL, NSString))objc_msgSend)
(NSApp, sel_registerName("setName:"), str);
}
}

RGFW_window* win = RGFW_window_basic_init(rect, args);
Expand Down Expand Up @@ -7894,6 +7922,7 @@ RGFW_UNUSED(win); /*!< if buffer rendering is not being used */
}

void RGFW_releaseCursor(RGFW_window* win) {
RGFW_UNUSED(win);
CGAssociateMouseAndMouseCursorPosition(1);
}

Expand Down Expand Up @@ -8049,6 +8078,8 @@ RGFW_UNUSED(win); /*!< if buffer rendering is not being used */
#if defined(RGFW_OPENGL)

NSOpenGLContext_setValues(win->src.ctx, &swapInterval, 222);
#else
RGFW_UNUSED(swapInterval);
#endif
}
#endif
Expand Down
1 change: 1 addition & 0 deletions examples/basic/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void refreshCallback(RGFW_window* win) {
RGFW_window* win2;

int main(void) {
RGFW_setClassName("RGFW Basic");
RGFW_window* win = RGFW_createWindow("RGFW Example Window", RGFW_RECT(500, 500, 500, 500), RGFW_ALLOW_DND | RGFW_CENTER);
RGFW_window_makeCurrent(win);

Expand Down

0 comments on commit d6e006c

Please sign in to comment.