Skip to content

Commit 088c3ec

Browse files
committed
Add Windows platform implementations for display, tray, menu, window,
and accessibility managers
1 parent 073107b commit 088c3ec

11 files changed

+1806
-67
lines changed

include/nativeapi_c.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#include "../src/capi/display_c.h"

src/capi/display_c.c

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#include "display_c.h"
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
nativeapi_display_t* nativeapi_display_create(void) {
6+
nativeapi_display_t* display = (nativeapi_display_t*)malloc(sizeof(nativeapi_display_t));
7+
if (!display) {
8+
return NULL;
9+
}
10+
11+
// Initialize all fields to default values
12+
display->id = NULL;
13+
display->name = NULL;
14+
display->position.x = 0.0;
15+
display->position.y = 0.0;
16+
display->size.width = 0.0;
17+
display->size.height = 0.0;
18+
display->work_area.x = 0.0;
19+
display->work_area.y = 0.0;
20+
display->work_area.width = 0.0;
21+
display->work_area.height = 0.0;
22+
display->scale_factor = 0.0;
23+
display->is_primary = false;
24+
display->orientation = NATIVEAPI_DISPLAY_ORIENTATION_PORTRAIT;
25+
display->refresh_rate = 0;
26+
display->bit_depth = 0;
27+
display->manufacturer = NULL;
28+
display->model = NULL;
29+
display->serial_number = NULL;
30+
31+
return display;
32+
}
33+
34+
void nativeapi_display_destroy(nativeapi_display_t* display) {
35+
if (!display) {
36+
return;
37+
}
38+
39+
// Free all allocated strings
40+
free(display->id);
41+
free(display->name);
42+
free(display->manufacturer);
43+
free(display->model);
44+
free(display->serial_number);
45+
46+
// Free the display structure itself
47+
free(display);
48+
}
49+
50+
static bool set_string_field(char** field, const char* value) {
51+
if (!field) {
52+
return false;
53+
}
54+
55+
// Free existing string if any
56+
free(*field);
57+
*field = NULL;
58+
59+
if (!value) {
60+
return true; // Setting to NULL is valid
61+
}
62+
63+
// Allocate and copy new string
64+
size_t len = strlen(value) + 1;
65+
*field = (char*)malloc(len);
66+
if (!*field) {
67+
return false;
68+
}
69+
70+
strcpy(*field, value);
71+
return true;
72+
}
73+
74+
bool nativeapi_display_set_id(nativeapi_display_t* display, const char* id) {
75+
if (!display) {
76+
return false;
77+
}
78+
return set_string_field(&display->id, id);
79+
}
80+
81+
bool nativeapi_display_set_name(nativeapi_display_t* display, const char* name) {
82+
if (!display) {
83+
return false;
84+
}
85+
return set_string_field(&display->name, name);
86+
}
87+
88+
bool nativeapi_display_set_manufacturer(nativeapi_display_t* display, const char* manufacturer) {
89+
if (!display) {
90+
return false;
91+
}
92+
return set_string_field(&display->manufacturer, manufacturer);
93+
}
94+
95+
bool nativeapi_display_set_model(nativeapi_display_t* display, const char* model) {
96+
if (!display) {
97+
return false;
98+
}
99+
return set_string_field(&display->model, model);
100+
}
101+
102+
bool nativeapi_display_set_serial_number(nativeapi_display_t* display, const char* serial_number) {
103+
if (!display) {
104+
return false;
105+
}
106+
return set_string_field(&display->serial_number, serial_number);
107+
}
108+
109+
void nativeapi_display_set_position(nativeapi_display_t* display, double x, double y) {
110+
if (!display) {
111+
return;
112+
}
113+
display->position.x = x;
114+
display->position.y = y;
115+
}
116+
117+
void nativeapi_display_set_size(nativeapi_display_t* display, double width, double height) {
118+
if (!display) {
119+
return;
120+
}
121+
display->size.width = width;
122+
display->size.height = height;
123+
}
124+
125+
void nativeapi_display_set_work_area(nativeapi_display_t* display, double x, double y, double width, double height) {
126+
if (!display) {
127+
return;
128+
}
129+
display->work_area.x = x;
130+
display->work_area.y = y;
131+
display->work_area.width = width;
132+
display->work_area.height = height;
133+
}
134+
135+
void nativeapi_display_set_scale_factor(nativeapi_display_t* display, double scale_factor) {
136+
if (!display) {
137+
return;
138+
}
139+
display->scale_factor = scale_factor;
140+
}
141+
142+
void nativeapi_display_set_primary(nativeapi_display_t* display, bool is_primary) {
143+
if (!display) {
144+
return;
145+
}
146+
display->is_primary = is_primary;
147+
}
148+
149+
void nativeapi_display_set_orientation(nativeapi_display_t* display, nativeapi_display_orientation_t orientation) {
150+
if (!display) {
151+
return;
152+
}
153+
display->orientation = orientation;
154+
}
155+
156+
void nativeapi_display_set_refresh_rate(nativeapi_display_t* display, int refresh_rate) {
157+
if (!display) {
158+
return;
159+
}
160+
display->refresh_rate = refresh_rate;
161+
}
162+
163+
void nativeapi_display_set_bit_depth(nativeapi_display_t* display, int bit_depth) {
164+
if (!display) {
165+
return;
166+
}
167+
display->bit_depth = bit_depth;
168+
}

src/capi/display_c.h

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#include <stdbool.h>
8+
#include <stdint.h>
9+
10+
/**
11+
* Point is a 2D point in the coordinate system.
12+
*/
13+
typedef struct {
14+
double x;
15+
double y;
16+
} nativeapi_point_t;
17+
18+
/**
19+
* Size is a 2D size in the coordinate system.
20+
*/
21+
typedef struct {
22+
double width;
23+
double height;
24+
} nativeapi_size_t;
25+
26+
/**
27+
* Rectangle is a 2D rectangle in the coordinate system.
28+
*/
29+
typedef struct {
30+
double x;
31+
double y;
32+
double width;
33+
double height;
34+
} nativeapi_rectangle_t;
35+
36+
/**
37+
* Display orientation enumeration
38+
*/
39+
typedef enum {
40+
NATIVEAPI_DISPLAY_ORIENTATION_PORTRAIT = 0,
41+
NATIVEAPI_DISPLAY_ORIENTATION_LANDSCAPE = 90,
42+
NATIVEAPI_DISPLAY_ORIENTATION_PORTRAIT_FLIPPED = 180,
43+
NATIVEAPI_DISPLAY_ORIENTATION_LANDSCAPE_FLIPPED = 270
44+
} nativeapi_display_orientation_t;
45+
46+
/**
47+
* Representation of a display/monitor
48+
*/
49+
typedef struct {
50+
// Basic identification
51+
char* id; // Unique identifier for the display
52+
char* name; // Human-readable display name
53+
54+
// Physical properties
55+
nativeapi_point_t position; // Display position in virtual desktop coordinates
56+
nativeapi_size_t size; // Full display size in logical pixels
57+
nativeapi_rectangle_t work_area; // Available work area (excluding taskbars, docks, etc.)
58+
double scale_factor; // Display scaling factor (1.0 = 100%, 2.0 = 200%, etc.)
59+
60+
// Additional properties
61+
bool is_primary; // Whether this is the primary display
62+
nativeapi_display_orientation_t orientation; // Current display orientation
63+
int refresh_rate; // Refresh rate in Hz (0 if unknown)
64+
int bit_depth; // Color bit depth (0 if unknown)
65+
66+
// Hardware information
67+
char* manufacturer; // Display manufacturer
68+
char* model; // Display model
69+
char* serial_number; // Display serial number (if available)
70+
} nativeapi_display_t;
71+
72+
/**
73+
* Create a new display structure with default values
74+
* @return Pointer to newly allocated display structure, or NULL on failure
75+
*/
76+
nativeapi_display_t* nativeapi_display_create(void);
77+
78+
/**
79+
* Free a display structure and all its allocated strings
80+
* @param display Pointer to display structure to free
81+
*/
82+
void nativeapi_display_destroy(nativeapi_display_t* display);
83+
84+
/**
85+
* Set the ID of a display
86+
* @param display Pointer to display structure
87+
* @param id ID string (will be copied)
88+
* @return true on success, false on failure
89+
*/
90+
bool nativeapi_display_set_id(nativeapi_display_t* display, const char* id);
91+
92+
/**
93+
* Set the name of a display
94+
* @param display Pointer to display structure
95+
* @param name Name string (will be copied)
96+
* @return true on success, false on failure
97+
*/
98+
bool nativeapi_display_set_name(nativeapi_display_t* display, const char* name);
99+
100+
/**
101+
* Set the manufacturer of a display
102+
* @param display Pointer to display structure
103+
* @param manufacturer Manufacturer string (will be copied)
104+
* @return true on success, false on failure
105+
*/
106+
bool nativeapi_display_set_manufacturer(nativeapi_display_t* display, const char* manufacturer);
107+
108+
/**
109+
* Set the model of a display
110+
* @param display Pointer to display structure
111+
* @param model Model string (will be copied)
112+
* @return true on success, false on failure
113+
*/
114+
bool nativeapi_display_set_model(nativeapi_display_t* display, const char* model);
115+
116+
/**
117+
* Set the serial number of a display
118+
* @param display Pointer to display structure
119+
* @param serial_number Serial number string (will be copied)
120+
* @return true on success, false on failure
121+
*/
122+
bool nativeapi_display_set_serial_number(nativeapi_display_t* display, const char* serial_number);
123+
124+
/**
125+
* Set the position of a display
126+
* @param display Pointer to display structure
127+
* @param x X coordinate
128+
* @param y Y coordinate
129+
*/
130+
void nativeapi_display_set_position(nativeapi_display_t* display, double x, double y);
131+
132+
/**
133+
* Set the size of a display
134+
* @param display Pointer to display structure
135+
* @param width Width in logical pixels
136+
* @param height Height in logical pixels
137+
*/
138+
void nativeapi_display_set_size(nativeapi_display_t* display, double width, double height);
139+
140+
/**
141+
* Set the work area of a display
142+
* @param display Pointer to display structure
143+
* @param x X coordinate of work area
144+
* @param y Y coordinate of work area
145+
* @param width Width of work area
146+
* @param height Height of work area
147+
*/
148+
void nativeapi_display_set_work_area(nativeapi_display_t* display, double x, double y, double width, double height);
149+
150+
/**
151+
* Set the scale factor of a display
152+
* @param display Pointer to display structure
153+
* @param scale_factor Scale factor (1.0 = 100%, 2.0 = 200%, etc.)
154+
*/
155+
void nativeapi_display_set_scale_factor(nativeapi_display_t* display, double scale_factor);
156+
157+
/**
158+
* Set whether a display is primary
159+
* @param display Pointer to display structure
160+
* @param is_primary true if primary display, false otherwise
161+
*/
162+
void nativeapi_display_set_primary(nativeapi_display_t* display, bool is_primary);
163+
164+
/**
165+
* Set the orientation of a display
166+
* @param display Pointer to display structure
167+
* @param orientation Display orientation
168+
*/
169+
void nativeapi_display_set_orientation(nativeapi_display_t* display, nativeapi_display_orientation_t orientation);
170+
171+
/**
172+
* Set the refresh rate of a display
173+
* @param display Pointer to display structure
174+
* @param refresh_rate Refresh rate in Hz (0 if unknown)
175+
*/
176+
void nativeapi_display_set_refresh_rate(nativeapi_display_t* display, int refresh_rate);
177+
178+
/**
179+
* Set the bit depth of a display
180+
* @param display Pointer to display structure
181+
* @param bit_depth Color bit depth (0 if unknown)
182+
*/
183+
void nativeapi_display_set_bit_depth(nativeapi_display_t* display, int bit_depth);
184+
185+
#ifdef __cplusplus
186+
}
187+
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "../../accessibility_manager.h"
2+
3+
#include <windows.h>
4+
#include <oleacc.h>
5+
6+
namespace nativeapi {
7+
8+
void AccessibilityManager::Enable() {
9+
// Windows accessibility is typically managed at the system level
10+
// Applications can enable specific accessibility features through COM
11+
// For now, this is a placeholder implementation
12+
}
13+
14+
bool AccessibilityManager::IsEnabled() {
15+
// Check if high contrast is enabled (common accessibility feature)
16+
HIGHCONTRAST hc = {0};
17+
hc.cbSize = sizeof(HIGHCONTRAST);
18+
19+
if (SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(HIGHCONTRAST), &hc, 0)) {
20+
return (hc.dwFlags & HCF_HIGHCONTRASTON) != 0;
21+
}
22+
23+
// If we can't determine high contrast, check for screen reader
24+
// This is a basic check - in practice you might want to check for specific assistive technologies
25+
return GetSystemMetrics(SM_SCREENREADER) != 0;
26+
}
27+
28+
} // namespace nativeapi

0 commit comments

Comments
 (0)