Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/capi/display_manager_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
#include <iostream>
#include <vector>

#ifdef _WIN32
#define STRDUP _strdup
#else
#define STRDUP strdup
#endif

#include "../display.h"
#include "../display_manager.h"

Expand Down Expand Up @@ -31,13 +37,13 @@ native_display_t to_native_display(const Display& raw_display) {
native_display_t display = {};

// Allocate and copy strings
display.id = strdup(raw_display.id.c_str());
display.name = strdup(raw_display.name.c_str());
display.id = STRDUP(raw_display.id.c_str());
display.name = STRDUP(raw_display.name.c_str());
display.manufacturer = raw_display.manufacturer.empty()
? nullptr
: strdup(raw_display.manufacturer.c_str());
: STRDUP(raw_display.manufacturer.c_str());
display.model =
raw_display.model.empty() ? nullptr : strdup(raw_display.model.c_str());
raw_display.model.empty() ? nullptr : STRDUP(raw_display.model.c_str());
display.serial_number = nullptr; // Not available in the C++ API

// Copy position
Expand Down
1 change: 1 addition & 0 deletions src/keyboard_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class KeyboardMonitor {

private:
class Impl;
friend class Impl; // Allow Impl class to access private members
std::unique_ptr<Impl> impl_;
KeyboardEventHandler* event_handler_;
};
Expand Down
5 changes: 5 additions & 0 deletions src/platform/windows/accessibility_manager_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
#include <windows.h>
#include <oleacc.h>

// SM_SCREENREADER is not defined in all Windows SDK versions
#ifndef SM_SCREENREADER
#define SM_SCREENREADER 40
#endif

namespace nativeapi {

void AccessibilityManager::Enable() {
Expand Down
6 changes: 3 additions & 3 deletions src/platform/windows/display_manager_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ UINT GetMonitorDpi(HMONITOR monitor) {
typedef HRESULT(WINAPI* GetDpiForMonitorFunc)(HMONITOR, int, UINT*, UINT*);

// Try to load GetDpiForMonitor from Shcore.dll (Windows 8.1+)
HMODULE shcore = LoadLibrary(L"Shcore.dll");
HMODULE shcore = LoadLibraryW(L"Shcore.dll");
if (shcore) {
GetDpiForMonitorFunc getDpiForMonitor =
(GetDpiForMonitorFunc)GetProcAddress(shcore, "GetDpiForMonitor");
Expand Down Expand Up @@ -54,7 +54,7 @@ Display CreateDisplayFromMonitor(HMONITOR monitor, bool isPrimary) {
UINT dpi = GetMonitorDpi(monitor);

Display display;
display.name = WideStringToString(std::wstring(info.szDevice));
display.name = std::string(info.szDevice);
display.scaleFactor = static_cast<double>(dpi) / kBaseDpi;
display.isPrimary = isPrimary;

Expand All @@ -74,7 +74,7 @@ Display CreateDisplayFromMonitor(HMONITOR monitor, bool isPrimary) {
DISPLAY_DEVICE displayDevice;
displayDevice.cb = sizeof(DISPLAY_DEVICE);
if (EnumDisplayDevices(info.szDevice, 0, &displayDevice, 0)) {
display.id = WideStringToString(std::wstring(displayDevice.DeviceID));
display.id = std::string(displayDevice.DeviceID);

// Get display settings
DEVMODE devMode;
Expand Down
14 changes: 7 additions & 7 deletions src/platform/windows/menu_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void MenuItem::SetIcon(std::string icon) {
} else if (!icon.empty()) {
// Load icon from file path
std::wstring wicon(icon.begin(), icon.end());
HICON hIcon = (HICON)LoadImage(nullptr, wicon.c_str(), IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
HICON hIcon = (HICON)LoadImageW(nullptr, wicon.c_str(), IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
if (hIcon) {
// Convert HICON to HBITMAP
HDC hdc = GetDC(nullptr);
Expand Down Expand Up @@ -151,8 +151,8 @@ void Menu::AddItem(MenuItem item) {
// Store the item to keep it alive
pimpl_->items_.push_back(item);

MENUITEMINFO mii = {};
mii.cbSize = sizeof(MENUITEMINFO);
MENUITEMINFOW mii = {};
mii.cbSize = sizeof(MENUITEMINFOW);
mii.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA;
mii.wID = item.pimpl_->menu_id_;

Expand All @@ -167,7 +167,7 @@ void Menu::AddItem(MenuItem item) {
mii.hbmpItem = item.pimpl_->icon_bitmap_;
}

InsertMenuItem(pimpl_->hmenu_, GetMenuItemCount(pimpl_->hmenu_), TRUE, &mii);
InsertMenuItemW(pimpl_->hmenu_, GetMenuItemCount(pimpl_->hmenu_), TRUE, &mii);
}

void Menu::RemoveItem(MenuItem item) {
Expand All @@ -188,12 +188,12 @@ void Menu::RemoveItem(MenuItem item) {
void Menu::AddSeparator() {
if (!pimpl_->hmenu_) return;

MENUITEMINFO mii = {};
mii.cbSize = sizeof(MENUITEMINFO);
MENUITEMINFOW mii = {};
mii.cbSize = sizeof(MENUITEMINFOW);
mii.fMask = MIIM_FTYPE;
mii.fType = MFT_SEPARATOR;

InsertMenuItem(pimpl_->hmenu_, GetMenuItemCount(pimpl_->hmenu_), TRUE, &mii);
InsertMenuItemW(pimpl_->hmenu_, GetMenuItemCount(pimpl_->hmenu_), TRUE, &mii);
}

MenuItem Menu::CreateItem(std::string title) {
Expand Down
29 changes: 14 additions & 15 deletions src/platform/windows/tray_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ class Tray::Impl {
// Register window class if not already registered
static bool class_registered = false;
if (!class_registered) {
WNDCLASS wc = {};
WNDCLASSW wc = {};
wc.lpfnWndProc = TrayWindowProc;
wc.hInstance = GetModuleHandle(nullptr);
wc.lpszClassName = TRAY_WINDOW_CLASS;
RegisterClass(&wc);
RegisterClassW(&wc);
class_registered = true;
}

// Create hidden window for tray messages
hwnd_ = CreateWindow(
hwnd_ = CreateWindowW(
TRAY_WINDOW_CLASS,
L"TrayWindow",
WS_OVERLAPPED,
Expand All @@ -122,46 +122,45 @@ class Tray::Impl {
void InitializeTrayIcon() {
if (!hwnd_) return;

nid_.cbSize = sizeof(NOTIFYICONDATA);
nid_.cbSize = sizeof(NOTIFYICONDATAW);
nid_.hWnd = hwnd_;
nid_.uID = tray_uid_;
nid_.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid_.uCallbackMessage = g_tray_message;
nid_.hIcon = LoadIcon(nullptr, IDI_APPLICATION); // Default icon
wcscpy_s(nid_.szTip, L"Tray Icon");
wcscpy_s(nid_.szTip, sizeof(nid_.szTip)/sizeof(wchar_t), L"Tray Icon");

// Store tray pointer in window
SetWindowLongPtr(hwnd_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(tray_ptr_));

Shell_NotifyIcon(NIM_ADD, &nid_);
Shell_NotifyIconW(NIM_ADD, &nid_);
}

void RemoveTrayIcon() {
if (hwnd_) {
Shell_NotifyIcon(NIM_DELETE, &nid_);
Shell_NotifyIconW(NIM_DELETE, &nid_);
}
}

void UpdateIcon() {
if (hwnd_ && icon_) {
nid_.hIcon = icon_;
Shell_NotifyIcon(NIM_MODIFY, &nid_);
Shell_NotifyIconW(NIM_MODIFY, &nid_);
}
}

void UpdateTooltip(const std::string& tooltip) {
if (!hwnd_) return;

std::wstring wtooltip = StringToWideString(tooltip);
wcsncpy_s(nid_.szTip, wtooltip.c_str(), sizeof(nid_.szTip) / sizeof(wchar_t) - 1);
nid_.szTip[sizeof(nid_.szTip) / sizeof(wchar_t) - 1] = L'\0';
wcsncpy_s(nid_.szTip, sizeof(nid_.szTip) / sizeof(wchar_t), wtooltip.c_str(), _TRUNCATE);

Shell_NotifyIcon(NIM_MODIFY, &nid_);
Shell_NotifyIconW(NIM_MODIFY, &nid_);
}

HWND hwnd_;
UINT tray_uid_;
NOTIFYICONDATA nid_;
NOTIFYICONDATAW nid_;
HICON icon_;
std::string title_;
std::string tooltip_;
Expand Down Expand Up @@ -200,7 +199,7 @@ void Tray::SetIcon(std::string icon) {
} else if (!icon.empty()) {
// Load icon from file path
std::wstring wicon = StringToWideString(icon);
pimpl_->icon_ = (HICON)LoadImage(
pimpl_->icon_ = (HICON)LoadImageW(
nullptr,
wicon.c_str(),
IMAGE_ICON,
Expand Down Expand Up @@ -246,9 +245,9 @@ Rectangle Tray::GetBounds() {

if (pimpl_->hwnd_) {
// Get the position of the notification area
HWND hTray = FindWindow(L"Shell_TrayWnd", nullptr);
HWND hTray = FindWindowW(L"Shell_TrayWnd", nullptr);
if (hTray) {
HWND hNotify = FindWindowEx(hTray, nullptr, L"TrayNotifyWnd", nullptr);
HWND hNotify = FindWindowExW(hTray, nullptr, L"TrayNotifyWnd", nullptr);
if (hNotify) {
RECT rect;
GetWindowRect(hNotify, &rect);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/window_manager_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
if (!(exStyle & WS_EX_TOOLWINDOW)) {
// Check if window has a title
wchar_t title[256];
if (GetWindowText(hwnd, title, sizeof(title) / sizeof(wchar_t)) > 0) {
if (GetWindowTextW(hwnd, title, sizeof(title) / sizeof(wchar_t)) > 0) {
windows->push_back(hwnd);
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/platform/windows/window_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ bool Window::IsClosable() const {
if (pimpl_->hwnd_) {
HMENU hMenu = GetSystemMenu(pimpl_->hwnd_, FALSE);
if (hMenu) {
MENUITEMINFO mii = {};
mii.cbSize = sizeof(MENUITEMINFO);
MENUITEMINFOW mii = {};
mii.cbSize = sizeof(MENUITEMINFOW);
mii.fMask = MIIM_STATE;
if (GetMenuItemInfo(hMenu, SC_CLOSE, FALSE, &mii)) {
if (GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii)) {
return !(mii.fState & MFS_GRAYED);
}
}
Expand Down Expand Up @@ -442,16 +442,16 @@ Point Window::GetPosition() {
void Window::SetTitle(std::string title) {
if (pimpl_->hwnd_) {
std::wstring wtitle = StringToWideString(title);
SetWindowText(pimpl_->hwnd_, wtitle.c_str());
SetWindowTextW(pimpl_->hwnd_, wtitle.c_str());
}
}

std::string Window::GetTitle() {
if (pimpl_->hwnd_) {
int length = GetWindowTextLength(pimpl_->hwnd_);
int length = GetWindowTextLengthW(pimpl_->hwnd_);
if (length > 0) {
std::wstring wtitle(length + 1, L'\0');
GetWindowText(pimpl_->hwnd_, &wtitle[0], length + 1);
GetWindowTextW(pimpl_->hwnd_, &wtitle[0], length + 1);
wtitle.resize(length);
return WideStringToString(wtitle);
}
Expand Down Expand Up @@ -571,4 +571,6 @@ void Window::StartResizing() {
void* Window::GetNSWindow() const {
// This method name suggests macOS compatibility - return HWND instead
return pimpl_->hwnd_;
}
}

} // namespace nativeapi
Loading