Changes related to dpi.
Introduced new function mfb_get_monitor_scale Deprecated function mfb_get_monitor_dpi
This commit is contained in:
parent
17df5633cd
commit
fa8bf266f0
@ -232,6 +232,8 @@ int mfb_get_mouse_x(struct mfb_window *window); // L
|
|||||||
int mfb_get_mouse_y(struct mfb_window *window); // Last mouse pos Y
|
int mfb_get_mouse_y(struct mfb_window *window); // Last mouse pos Y
|
||||||
|
|
||||||
// Not working on Linux (X11 nor Wayland)
|
// Not working on Linux (X11 nor Wayland)
|
||||||
|
void mfb_get_monitor_scale(struct mfb_window *window, float *scale_x, float *scale_y)
|
||||||
|
// [Deprecated] Use mfb_get_monitor_scale instead
|
||||||
void mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y)
|
void mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -39,7 +39,10 @@ void * mfb_get_user_data(struct mfb_window *window);
|
|||||||
bool mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height);
|
bool mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height);
|
||||||
|
|
||||||
// DPI
|
// DPI
|
||||||
|
// [Deprecated]: Probably a better name will be mfb_get_monitor_scale
|
||||||
void mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y);
|
void mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y);
|
||||||
|
// Use this instead
|
||||||
|
void mfb_get_monitor_scale(struct mfb_window *window, float *scale_x, float *scale_y);
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
void mfb_set_active_callback(struct mfb_window *window, mfb_active_func callback);
|
void mfb_set_active_callback(struct mfb_window *window, mfb_active_func callback);
|
||||||
|
@ -13,7 +13,7 @@ mfb_open(const char *title, unsigned width, unsigned height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
mfb_update_state
|
mfb_update_state
|
||||||
mfb_update(struct mfb_window *window, void *buffer) {
|
mfb_update(struct mfb_window *window, void *buffer) {
|
||||||
if (window == 0x0) {
|
if (window == 0x0) {
|
||||||
return STATE_INVALID_WINDOW;
|
return STATE_INVALID_WINDOW;
|
||||||
@ -25,7 +25,7 @@ mfb_update(struct mfb_window *window, void *buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_set_active_callback(struct mfb_window *window, mfb_active_func callback) {
|
mfb_set_active_callback(struct mfb_window *window, mfb_active_func callback) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -34,7 +34,7 @@ mfb_set_active_callback(struct mfb_window *window, mfb_active_func callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_set_resize_callback(struct mfb_window *window, mfb_resize_func callback) {
|
mfb_set_resize_callback(struct mfb_window *window, mfb_resize_func callback) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -43,7 +43,7 @@ mfb_set_resize_callback(struct mfb_window *window, mfb_resize_func callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_set_keyboard_callback(struct mfb_window *window, mfb_keyboard_func callback) {
|
mfb_set_keyboard_callback(struct mfb_window *window, mfb_keyboard_func callback) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -52,7 +52,7 @@ mfb_set_keyboard_callback(struct mfb_window *window, mfb_keyboard_func callback)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_set_char_input_callback(struct mfb_window *window, mfb_char_input_func callback) {
|
mfb_set_char_input_callback(struct mfb_window *window, mfb_char_input_func callback) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -61,7 +61,7 @@ mfb_set_char_input_callback(struct mfb_window *window, mfb_char_input_func callb
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_set_mouse_button_callback(struct mfb_window *window, mfb_mouse_button_func callback) {
|
mfb_set_mouse_button_callback(struct mfb_window *window, mfb_mouse_button_func callback) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -70,7 +70,7 @@ mfb_set_mouse_button_callback(struct mfb_window *window, mfb_mouse_button_func c
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_set_mouse_move_callback(struct mfb_window *window, mfb_mouse_move_func callback) {
|
mfb_set_mouse_move_callback(struct mfb_window *window, mfb_mouse_move_func callback) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -79,7 +79,7 @@ mfb_set_mouse_move_callback(struct mfb_window *window, mfb_mouse_move_func callb
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_set_mouse_scroll_callback(struct mfb_window *window, mfb_mouse_scroll_func callback) {
|
mfb_set_mouse_scroll_callback(struct mfb_window *window, mfb_mouse_scroll_func callback) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -88,7 +88,7 @@ mfb_set_mouse_scroll_callback(struct mfb_window *window, mfb_mouse_scroll_func c
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_set_user_data(struct mfb_window *window, void *user_data) {
|
mfb_set_user_data(struct mfb_window *window, void *user_data) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -107,8 +107,15 @@ mfb_get_user_data(struct mfb_window *window) {
|
|||||||
return 0x0;
|
return 0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [Deprecated]
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
|
mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
||||||
|
mfb_get_monitor_scale(window, dpi_x, dpi_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
void
|
||||||
mfb_close(struct mfb_window *window) {
|
mfb_close(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -117,7 +124,7 @@ mfb_close(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
keyboard_default(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
keyboard_default(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool isPressed) {
|
||||||
kUnused(mod);
|
kUnused(mod);
|
||||||
kUnused(isPressed);
|
kUnused(isPressed);
|
||||||
@ -128,7 +135,7 @@ keyboard_default(struct mfb_window *window, mfb_key key, mfb_key_mod mod, bool i
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
bool
|
bool
|
||||||
mfb_is_window_active(struct mfb_window *window) {
|
mfb_is_window_active(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -138,7 +145,7 @@ mfb_is_window_active(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
unsigned
|
unsigned
|
||||||
mfb_get_window_width(struct mfb_window *window) {
|
mfb_get_window_width(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -148,7 +155,7 @@ mfb_get_window_width(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
unsigned
|
unsigned
|
||||||
mfb_get_window_height(struct mfb_window *window) {
|
mfb_get_window_height(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -158,7 +165,7 @@ mfb_get_window_height(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
int
|
int
|
||||||
mfb_get_mouse_x(struct mfb_window *window) {
|
mfb_get_mouse_x(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -168,7 +175,7 @@ mfb_get_mouse_x(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
int
|
int
|
||||||
mfb_get_mouse_y(struct mfb_window *window) {
|
mfb_get_mouse_y(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -178,7 +185,7 @@ mfb_get_mouse_y(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
float
|
float
|
||||||
mfb_get_mouse_scroll_x(struct mfb_window *window) {
|
mfb_get_mouse_scroll_x(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -188,7 +195,7 @@ mfb_get_mouse_scroll_x(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
float
|
float
|
||||||
mfb_get_mouse_scroll_y(struct mfb_window *window) {
|
mfb_get_mouse_scroll_y(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -198,7 +205,7 @@ mfb_get_mouse_scroll_y(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
const uint8_t *
|
const uint8_t *
|
||||||
mfb_get_mouse_button_buffer(struct mfb_window *window) {
|
mfb_get_mouse_button_buffer(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -208,7 +215,7 @@ mfb_get_mouse_button_buffer(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
const uint8_t *
|
const uint8_t *
|
||||||
mfb_get_key_buffer(struct mfb_window *window) {
|
mfb_get_key_buffer(struct mfb_window *window) {
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -218,7 +225,7 @@ mfb_get_key_buffer(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
const char *
|
const char *
|
||||||
mfb_get_key_name(mfb_key key) {
|
mfb_get_key_name(mfb_key key) {
|
||||||
|
|
||||||
switch (key)
|
switch (key)
|
||||||
@ -586,6 +593,6 @@ mfb_get_key_name(mfb_key key) {
|
|||||||
case KB_KEY_UNKNOWN:
|
case KB_KEY_UNKNOWN:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
@ -250,23 +250,23 @@ mfb_timer_init() {
|
|||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
mfb_get_monitor_scale(struct mfb_window *window, float *scale_x, float *scale_y) {
|
||||||
(void) window;
|
(void) window;
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
|
|
||||||
scale = [[UIScreen mainScreen] scale];
|
scale = [[UIScreen mainScreen] scale];
|
||||||
|
|
||||||
if (dpi_x) {
|
if (scale_x) {
|
||||||
*dpi_x = scale;
|
*scale_x = scale;
|
||||||
if(*dpi_x == 0) {
|
if(*scale_x == 0) {
|
||||||
*dpi_x = 1;
|
*scale_x = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_y) {
|
if (scale_y) {
|
||||||
*dpi_y = scale;
|
*scale_y = scale;
|
||||||
if (*dpi_y == 0) {
|
if (*scale_y == 0) {
|
||||||
*dpi_y = 1;
|
*scale_y = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
|||||||
|
|
||||||
window_data->is_initialized = true;
|
window_data->is_initialized = true;
|
||||||
return (struct mfb_window *) window_data;
|
return (struct mfb_window *) window_data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
@ -175,7 +175,7 @@ destroy_window_data(SWindowData *window_data) {
|
|||||||
if(window_data_osx != 0x0) {
|
if(window_data_osx != 0x0) {
|
||||||
OSXWindow *window = window_data_osx->window;
|
OSXWindow *window = window_data_osx->window;
|
||||||
[window performClose:nil];
|
[window performClose:nil];
|
||||||
|
|
||||||
// Flush events!
|
// Flush events!
|
||||||
NSEvent* event;
|
NSEvent* event;
|
||||||
do {
|
do {
|
||||||
@ -198,7 +198,7 @@ destroy_window_data(SWindowData *window_data) {
|
|||||||
window_data->draw_buffer = 0x0;
|
window_data->draw_buffer = 0x0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(window_data, 0, sizeof(SWindowData));
|
memset(window_data, 0, sizeof(SWindowData));
|
||||||
free(window_data);
|
free(window_data);
|
||||||
}
|
}
|
||||||
@ -247,7 +247,7 @@ mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned
|
|||||||
|
|
||||||
[window_data_osx->viewController resizeTextures];
|
[window_data_osx->viewController resizeTextures];
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(window_data->draw_buffer, buffer, window_data->buffer_stride * window_data->buffer_height);
|
memcpy(window_data->draw_buffer, buffer, window_data->buffer_stride * window_data->buffer_height);
|
||||||
#else
|
#else
|
||||||
if(window_data->buffer_width != width || window_data->buffer_height != height) {
|
if(window_data->buffer_width != width || window_data->buffer_height != height) {
|
||||||
@ -255,7 +255,7 @@ mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned
|
|||||||
window_data->buffer_stride = width * 4;
|
window_data->buffer_stride = width * 4;
|
||||||
window_data->buffer_height = height;
|
window_data->buffer_height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
window_data->draw_buffer = buffer;
|
window_data->draw_buffer = buffer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -553,7 +553,7 @@ mfb_timer_init() {
|
|||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
void
|
void
|
||||||
mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
mfb_get_monitor_scale(struct mfb_window *window, float *scale_x, float *scale_y) {
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
|
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
@ -565,19 +565,18 @@ mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
|||||||
else {
|
else {
|
||||||
scale = [[NSScreen mainScreen] backingScaleFactor];
|
scale = [[NSScreen mainScreen] backingScaleFactor];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_x) {
|
if (scale_x) {
|
||||||
*dpi_x = scale;
|
*scale_x = scale;
|
||||||
if(*dpi_x == 0) {
|
if(*scale_x == 0) {
|
||||||
*dpi_x = 1;
|
*scale_x = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_y) {
|
if (scale_y) {
|
||||||
*dpi_y = scale;
|
*scale_y = scale;
|
||||||
if (*dpi_y == 0) {
|
if (*scale_y == 0) {
|
||||||
*dpi_y = 1;
|
*scale_y = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
void init_keycodes();
|
void init_keycodes();
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_window_data(SWindowData *window_data)
|
destroy_window_data(SWindowData *window_data)
|
||||||
{
|
{
|
||||||
if(window_data == 0x0)
|
if(window_data == 0x0)
|
||||||
return;
|
return;
|
||||||
@ -38,12 +38,12 @@ destroy_window_data(SWindowData *window_data)
|
|||||||
free(window_data);
|
free(window_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy(SWindowData *window_data)
|
destroy(SWindowData *window_data)
|
||||||
{
|
{
|
||||||
if(window_data == 0x0)
|
if(window_data == 0x0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SWindowData_Way *window_data_way = (SWindowData_Way *) window_data->specific;
|
SWindowData_Way *window_data_way = (SWindowData_Way *) window_data->specific;
|
||||||
if (window_data_way == 0x0 || window_data_way->display == 0x0) {
|
if (window_data_way == 0x0 || window_data_way->display == 0x0) {
|
||||||
destroy_window_data(window_data);
|
destroy_window_data(window_data);
|
||||||
@ -79,7 +79,7 @@ destroy(SWindowData *window_data)
|
|||||||
close(window_data_way->fd);
|
close(window_data_way->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This event provides a file descriptor to the client which can be memory-mapped
|
// This event provides a file descriptor to the client which can be memory-mapped
|
||||||
// to provide a keyboard mapping description.
|
// to provide a keyboard mapping description.
|
||||||
// format: keymap format
|
// format: keymap format
|
||||||
// fd: keymap file descriptor
|
// fd: keymap file descriptor
|
||||||
@ -98,7 +98,7 @@ keyboard_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format, int f
|
|||||||
// serial: serial number of the enter event
|
// serial: serial number of the enter event
|
||||||
// surface: surface gaining keyboard focus
|
// surface: surface gaining keyboard focus
|
||||||
// keys: the currently pressed keys
|
// keys: the currently pressed keys
|
||||||
static void
|
static void
|
||||||
keyboard_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
|
keyboard_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
|
||||||
{
|
{
|
||||||
kUnused(keyboard);
|
kUnused(keyboard);
|
||||||
@ -114,7 +114,7 @@ keyboard_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct
|
|||||||
// The leave notification is sent before the enter notification for the new focus.
|
// The leave notification is sent before the enter notification for the new focus.
|
||||||
// serial: serial number of the leave event
|
// serial: serial number of the leave event
|
||||||
// surface: surface that lost keyboard focus
|
// surface: surface that lost keyboard focus
|
||||||
static void
|
static void
|
||||||
keyboard_leave(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface)
|
keyboard_leave(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface)
|
||||||
{
|
{
|
||||||
kUnused(keyboard);
|
kUnused(keyboard);
|
||||||
@ -126,13 +126,13 @@ keyboard_leave(void *data, struct wl_keyboard *keyboard, uint32_t serial, struct
|
|||||||
kCall(active_func, false);
|
kCall(active_func, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A key was pressed or released. The time argument is a timestamp with
|
// A key was pressed or released. The time argument is a timestamp with
|
||||||
// millisecond granularity, with an undefined base.
|
// millisecond granularity, with an undefined base.
|
||||||
// serial: serial number of the key event
|
// serial: serial number of the key event
|
||||||
// time: timestamp with millisecond granularity
|
// time: timestamp with millisecond granularity
|
||||||
// key: key that produced the event
|
// key: key that produced the event
|
||||||
// state: physical state of the key
|
// state: physical state of the key
|
||||||
static void
|
static void
|
||||||
keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
|
keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
|
||||||
{
|
{
|
||||||
kUnused(keyboard);
|
kUnused(keyboard);
|
||||||
@ -183,14 +183,14 @@ keyboard_key(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notifies clients that the modifier and/or group state has changed,
|
// Notifies clients that the modifier and/or group state has changed,
|
||||||
// and it should update its local state.
|
// and it should update its local state.
|
||||||
// serial: serial number of the modifiers event
|
// serial: serial number of the modifiers event
|
||||||
// mods_depressed: depressed modifiers
|
// mods_depressed: depressed modifiers
|
||||||
// mods_latched: latched modifiers
|
// mods_latched: latched modifiers
|
||||||
// mods_locked: locked modifiers
|
// mods_locked: locked modifiers
|
||||||
// group: keyboard layout
|
// group: keyboard layout
|
||||||
static void
|
static void
|
||||||
keyboard_modifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
|
keyboard_modifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
|
||||||
{
|
{
|
||||||
kUnused(data);
|
kUnused(data);
|
||||||
@ -206,7 +206,7 @@ keyboard_modifiers(void *data, struct wl_keyboard *keyboard, uint32_t serial, ui
|
|||||||
// Informs the client about the keyboard's repeat rate and delay.
|
// Informs the client about the keyboard's repeat rate and delay.
|
||||||
// rate: the rate of repeating keys in characters per second
|
// rate: the rate of repeating keys in characters per second
|
||||||
// delay: delay in milliseconds since key down until repeating starts
|
// delay: delay in milliseconds since key down until repeating starts
|
||||||
static void
|
static void
|
||||||
keyboard_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay)
|
keyboard_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay)
|
||||||
{
|
{
|
||||||
kUnused(data);
|
kUnused(data);
|
||||||
@ -215,7 +215,7 @@ keyboard_repeat_info(void *data, struct wl_keyboard *keyboard, int32_t rate, int
|
|||||||
kUnused(delay);
|
kUnused(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
wl_keyboard_listener keyboard_listener = {
|
wl_keyboard_listener keyboard_listener = {
|
||||||
.keymap = keyboard_keymap,
|
.keymap = keyboard_keymap,
|
||||||
.enter = keyboard_enter,
|
.enter = keyboard_enter,
|
||||||
@ -278,7 +278,7 @@ pointer_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl
|
|||||||
//fprintf(stderr, "Pointer left surface %p\n", surface);
|
//fprintf(stderr, "Pointer left surface %p\n", surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notification of pointer location change.
|
// Notification of pointer location change.
|
||||||
//
|
//
|
||||||
// The arguments sx and sy are the location relative to the focused surface.
|
// The arguments sx and sy are the location relative to the focused surface.
|
||||||
//
|
//
|
||||||
@ -329,19 +329,19 @@ pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scroll and other axis notifications.
|
// Scroll and other axis notifications.
|
||||||
//
|
//
|
||||||
// For scroll events (vertical and horizontal scroll axes), the
|
// For scroll events (vertical and horizontal scroll axes), the
|
||||||
// value parameter is the length of a vector along the specified
|
// value parameter is the length of a vector along the specified
|
||||||
// axis in a coordinate space identical to those of motion events,
|
// axis in a coordinate space identical to those of motion events,
|
||||||
// representing a relative movement along the specified axis.
|
// representing a relative movement along the specified axis.
|
||||||
//
|
//
|
||||||
// For devices that support movements non-parallel to axes multiple
|
// For devices that support movements non-parallel to axes multiple
|
||||||
// axis events will be emitted.
|
// axis events will be emitted.
|
||||||
//
|
//
|
||||||
// When applicable, for example for touch pads, the server can
|
// When applicable, for example for touch pads, the server can
|
||||||
// choose to emit scroll events where the motion vector is
|
// choose to emit scroll events where the motion vector is
|
||||||
// equivalent to a motion event vector.
|
// equivalent to a motion event vector.
|
||||||
//
|
//
|
||||||
// When applicable, a client can transform its content relative to
|
// When applicable, a client can transform its content relative to
|
||||||
// the scroll distance.
|
// the scroll distance.
|
||||||
//
|
//
|
||||||
@ -365,20 +365,20 @@ pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
frame(void *data, struct wl_pointer *pointer) {
|
frame(void *data, struct wl_pointer *pointer) {
|
||||||
kUnused(data);
|
kUnused(data);
|
||||||
kUnused(pointer);
|
kUnused(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
axis_source(void *data, struct wl_pointer *pointer, uint32_t axis_source) {
|
axis_source(void *data, struct wl_pointer *pointer, uint32_t axis_source) {
|
||||||
kUnused(data);
|
kUnused(data);
|
||||||
kUnused(pointer);
|
kUnused(pointer);
|
||||||
kUnused(axis_source);
|
kUnused(axis_source);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
axis_stop(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis) {
|
axis_stop(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis) {
|
||||||
kUnused(data);
|
kUnused(data);
|
||||||
kUnused(pointer);
|
kUnused(pointer);
|
||||||
@ -386,7 +386,7 @@ axis_stop(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis)
|
|||||||
kUnused(axis);
|
kUnused(axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
axis_discrete(void *data, struct wl_pointer *pointer, uint32_t axis, int32_t discrete) {
|
axis_discrete(void *data, struct wl_pointer *pointer, uint32_t axis, int32_t discrete) {
|
||||||
kUnused(data);
|
kUnused(data);
|
||||||
kUnused(pointer);
|
kUnused(pointer);
|
||||||
@ -394,7 +394,7 @@ axis_discrete(void *data, struct wl_pointer *pointer, uint32_t axis, int32_t dis
|
|||||||
kUnused(discrete);
|
kUnused(discrete);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
wl_pointer_listener pointer_listener = {
|
wl_pointer_listener pointer_listener = {
|
||||||
.enter = pointer_enter,
|
.enter = pointer_enter,
|
||||||
.leave = pointer_leave,
|
.leave = pointer_leave,
|
||||||
@ -409,7 +409,7 @@ wl_pointer_listener pointer_listener = {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static void
|
static void
|
||||||
seat_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps)
|
seat_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps)
|
||||||
{
|
{
|
||||||
kUnused(data);
|
kUnused(data);
|
||||||
@ -427,28 +427,28 @@ seat_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps
|
|||||||
window_data_way->keyboard = 0x0;
|
window_data_way->keyboard = 0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !window_data_way->pointer)
|
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !window_data_way->pointer)
|
||||||
{
|
{
|
||||||
window_data_way->pointer = wl_seat_get_pointer(seat);
|
window_data_way->pointer = wl_seat_get_pointer(seat);
|
||||||
wl_pointer_add_listener(window_data_way->pointer, &pointer_listener, window_data);
|
wl_pointer_add_listener(window_data_way->pointer, &pointer_listener, window_data);
|
||||||
}
|
}
|
||||||
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && window_data_way->pointer)
|
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && window_data_way->pointer)
|
||||||
{
|
{
|
||||||
wl_pointer_destroy(window_data_way->pointer);
|
wl_pointer_destroy(window_data_way->pointer);
|
||||||
window_data_way->pointer = 0x0;
|
window_data_way->pointer = 0x0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
seat_name(void *data, struct wl_seat *seat, const char *name) {
|
seat_name(void *data, struct wl_seat *seat, const char *name) {
|
||||||
kUnused(data);
|
kUnused(data);
|
||||||
kUnused(seat);
|
kUnused(seat);
|
||||||
printf("Seat '%s'n", name);
|
printf("Seat '%s'n", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
wl_seat_listener seat_listener = {
|
wl_seat_listener seat_listener = {
|
||||||
.capabilities = seat_capabilities,
|
.capabilities = seat_capabilities,
|
||||||
.name = 0x0,
|
.name = 0x0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -460,7 +460,7 @@ wl_seat_listener seat_listener = {
|
|||||||
// for buffers. Known formats include argb8888 and xrgb8888.
|
// for buffers. Known formats include argb8888 and xrgb8888.
|
||||||
//
|
//
|
||||||
// format: buffer pixel format
|
// format: buffer pixel format
|
||||||
static void
|
static void
|
||||||
shm_format(void *data, struct wl_shm *shm, uint32_t format)
|
shm_format(void *data, struct wl_shm *shm, uint32_t format)
|
||||||
{
|
{
|
||||||
kUnused(shm);
|
kUnused(shm);
|
||||||
@ -472,7 +472,7 @@ shm_format(void *data, struct wl_shm *shm, uint32_t format)
|
|||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
// We could do RGBA, but that would not be what is expected from minifb...
|
// We could do RGBA, but that would not be what is expected from minifb...
|
||||||
// case WL_SHM_FORMAT_ARGB8888:
|
// case WL_SHM_FORMAT_ARGB8888:
|
||||||
case WL_SHM_FORMAT_XRGB8888:
|
case WL_SHM_FORMAT_XRGB8888:
|
||||||
window_data_way->shm_format = format;
|
window_data_way->shm_format = format;
|
||||||
break;
|
break;
|
||||||
@ -483,14 +483,14 @@ shm_format(void *data, struct wl_shm *shm, uint32_t format)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
wl_shm_listener shm_listener = {
|
wl_shm_listener shm_listener = {
|
||||||
.format = shm_format
|
.format = shm_format
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static void
|
static void
|
||||||
registry_global(void *data, struct wl_registry *registry, uint32_t id, char const *iface, uint32_t version)
|
registry_global(void *data, struct wl_registry *registry, uint32_t id, char const *iface, uint32_t version)
|
||||||
{
|
{
|
||||||
kUnused(version);
|
kUnused(version);
|
||||||
@ -524,9 +524,9 @@ registry_global(void *data, struct wl_registry *registry, uint32_t id, char cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
wl_registry_listener registry_listener = {
|
wl_registry_listener registry_listener = {
|
||||||
.global = registry_global,
|
.global = registry_global,
|
||||||
.global_remove = 0x0,
|
.global_remove = 0x0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -562,7 +562,7 @@ static const struct wl_shell_surface_listener shell_surface_listener = {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
struct mfb_window *
|
struct mfb_window *
|
||||||
mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
||||||
{
|
{
|
||||||
SWindowData *window_data = (SWindowData *) malloc(sizeof(SWindowData));
|
SWindowData *window_data = (SWindowData *) malloc(sizeof(SWindowData));
|
||||||
@ -592,7 +592,7 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
|||||||
|
|
||||||
init_keycodes();
|
init_keycodes();
|
||||||
|
|
||||||
if (wl_display_dispatch(window_data_way->display) == -1 ||
|
if (wl_display_dispatch(window_data_way->display) == -1 ||
|
||||||
wl_display_roundtrip(window_data_way->display) == -1) {
|
wl_display_roundtrip(window_data_way->display) == -1) {
|
||||||
return 0x0;
|
return 0x0;
|
||||||
}
|
}
|
||||||
@ -631,7 +631,7 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
|||||||
calc_dst_factor(window_data, width, height);
|
calc_dst_factor(window_data, width, height);
|
||||||
|
|
||||||
window_data_way->shm_pool = wl_shm_create_pool(window_data_way->shm, window_data_way->fd, length);
|
window_data_way->shm_pool = wl_shm_create_pool(window_data_way->shm, window_data_way->fd, length);
|
||||||
window_data->draw_buffer = wl_shm_pool_create_buffer(window_data_way->shm_pool, 0,
|
window_data->draw_buffer = wl_shm_pool_create_buffer(window_data_way->shm_pool, 0,
|
||||||
window_data->buffer_width, window_data->buffer_height,
|
window_data->buffer_width, window_data->buffer_height,
|
||||||
window_data->buffer_stride, window_data_way->shm_format);
|
window_data->buffer_stride, window_data_way->shm_format);
|
||||||
|
|
||||||
@ -680,7 +680,7 @@ out:
|
|||||||
// Notify the client when the related request is done.
|
// Notify the client when the related request is done.
|
||||||
//
|
//
|
||||||
// callback_data: request-specific data for the callback
|
// callback_data: request-specific data for the callback
|
||||||
static void
|
static void
|
||||||
frame_done(void *data, struct wl_callback *callback, uint32_t cookie)
|
frame_done(void *data, struct wl_callback *callback, uint32_t cookie)
|
||||||
{
|
{
|
||||||
kUnused(cookie);
|
kUnused(cookie);
|
||||||
@ -689,14 +689,14 @@ frame_done(void *data, struct wl_callback *callback, uint32_t cookie)
|
|||||||
*(uint32_t *)data = 1;
|
*(uint32_t *)data = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct
|
static const struct
|
||||||
wl_callback_listener frame_listener = {
|
wl_callback_listener frame_listener = {
|
||||||
.done = frame_done,
|
.done = frame_done,
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
mfb_update_state
|
mfb_update_state
|
||||||
mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned height)
|
mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
uint32_t done = 0;
|
uint32_t done = 0;
|
||||||
@ -744,11 +744,11 @@ mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned
|
|||||||
resize_dst(window_data, width, height);
|
resize_dst(window_data, width, height);
|
||||||
|
|
||||||
wl_buffer_destroy(window_data->draw_buffer);
|
wl_buffer_destroy(window_data->draw_buffer);
|
||||||
window_data->draw_buffer = wl_shm_pool_create_buffer(window_data_way->shm_pool, 0,
|
window_data->draw_buffer = wl_shm_pool_create_buffer(window_data_way->shm_pool, 0,
|
||||||
window_data->buffer_width, window_data->buffer_height,
|
window_data->buffer_width, window_data->buffer_height,
|
||||||
window_data->buffer_stride, window_data_way->shm_format);
|
window_data->buffer_stride, window_data_way->shm_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update shm buffer
|
// update shm buffer
|
||||||
memcpy(window_data_way->shm_ptr, buffer, window_data->buffer_stride * window_data->buffer_height);
|
memcpy(window_data_way->shm_ptr, buffer, window_data->buffer_stride * window_data->buffer_height);
|
||||||
|
|
||||||
@ -773,7 +773,7 @@ mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
mfb_update_state
|
mfb_update_state
|
||||||
mfb_update_events(struct mfb_window *window)
|
mfb_update_events(struct mfb_window *window)
|
||||||
{
|
{
|
||||||
if(window == 0x0) {
|
if(window == 0x0) {
|
||||||
@ -801,7 +801,7 @@ mfb_update_events(struct mfb_window *window)
|
|||||||
|
|
||||||
extern double g_time_for_frame;
|
extern double g_time_for_frame;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mfb_wait_sync(struct mfb_window *window) {
|
mfb_wait_sync(struct mfb_window *window) {
|
||||||
if(window == 0x0) {
|
if(window == 0x0) {
|
||||||
return false;
|
return false;
|
||||||
@ -820,7 +820,7 @@ mfb_wait_sync(struct mfb_window *window) {
|
|||||||
if (wl_display_dispatch_pending(window_data_way->display) == -1) {
|
if (wl_display_dispatch_pending(window_data_way->display) == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(window_data->close) {
|
if(window_data->close) {
|
||||||
destroy_window_data(window_data);
|
destroy_window_data(window_data);
|
||||||
return false;
|
return false;
|
||||||
@ -846,11 +846,11 @@ mfb_wait_sync(struct mfb_window *window) {
|
|||||||
|
|
||||||
extern short int g_keycodes[512];
|
extern short int g_keycodes[512];
|
||||||
|
|
||||||
void
|
void
|
||||||
init_keycodes(void)
|
init_keycodes(void)
|
||||||
{
|
{
|
||||||
// Clear keys
|
// Clear keys
|
||||||
for (size_t i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
for (size_t i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
||||||
g_keycodes[i] = 0;
|
g_keycodes[i] = 0;
|
||||||
|
|
||||||
g_keycodes[KEY_GRAVE] = KB_KEY_GRAVE_ACCENT;
|
g_keycodes[KEY_GRAVE] = KB_KEY_GRAVE_ACCENT;
|
||||||
@ -974,7 +974,7 @@ init_keycodes(void)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||||
|
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
@ -999,7 +999,7 @@ mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void
|
void
|
||||||
mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
mfb_get_monitor_scale(struct mfb_window *window, float *scale_x, float *scale_y) {
|
||||||
float x = 96.0, y = 96.0;
|
float x = 96.0, y = 96.0;
|
||||||
|
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
@ -1009,17 +1009,17 @@ mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
|||||||
// I cannot find a way to get dpi under VirtualBox
|
// I cannot find a way to get dpi under VirtualBox
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_x) {
|
if (scale_x) {
|
||||||
*dpi_x = x / 96.0f;
|
*scale_x = x / 96.0f;
|
||||||
if(*dpi_x == 0) {
|
if(*scale_x == 0) {
|
||||||
*dpi_x = 1.0f;
|
*scale_x = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_y) {
|
if (scale_y) {
|
||||||
*dpi_y = y / 96.0f;
|
*scale_y = y / 96.0f;
|
||||||
if (*dpi_y == 0) {
|
if (*scale_y == 0) {
|
||||||
*dpi_y = 1.0f;
|
*scale_y = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,8 @@
|
|||||||
#if defined(USE_OPENGL_API)
|
#if defined(USE_OPENGL_API)
|
||||||
#include "gl/MiniFB_GL.h"
|
#include "gl/MiniFB_GL.h"
|
||||||
#endif
|
#endif
|
||||||
#if defined(_DEBUG) || defined(DEBUG)
|
#include <stdio.h>
|
||||||
#include <stdio.h>
|
|
||||||
#endif
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Copied (and modified) from Windows Kit 10 to avoid setting _WIN32_WINNT to a higher version
|
// Copied (and modified) from Windows Kit 10 to avoid setting _WIN32_WINNT to a higher version
|
||||||
@ -35,10 +32,14 @@ typedef enum mfb_MONITOR_DPI_TYPE {
|
|||||||
// user32.dll
|
// user32.dll
|
||||||
typedef BOOL(WINAPI *PFN_SetProcessDPIAware)(void);
|
typedef BOOL(WINAPI *PFN_SetProcessDPIAware)(void);
|
||||||
typedef BOOL(WINAPI *PFN_SetProcessDpiAwarenessContext)(HANDLE);
|
typedef BOOL(WINAPI *PFN_SetProcessDpiAwarenessContext)(HANDLE);
|
||||||
|
typedef UINT(WINAPI *PFN_GetDpiForWindow)(HWND);
|
||||||
|
typedef BOOL(WINAPI *PFN_EnableNonClientDpiScaling)(HWND);
|
||||||
|
|
||||||
HMODULE mfb_user32_dll = 0x0;
|
HMODULE mfb_user32_dll = 0x0;
|
||||||
PFN_SetProcessDPIAware mfb_SetProcessDPIAware = 0x0;
|
PFN_SetProcessDPIAware mfb_SetProcessDPIAware = 0x0;
|
||||||
PFN_SetProcessDpiAwarenessContext mfb_SetProcessDpiAwarenessContext = 0x0;
|
PFN_SetProcessDpiAwarenessContext mfb_SetProcessDpiAwarenessContext = 0x0;
|
||||||
|
PFN_GetDpiForWindow mfb_GetDpiForWindow = 0x0;
|
||||||
|
PFN_EnableNonClientDpiScaling mfb_EnableNonClientDpiScaling = 0x0;
|
||||||
|
|
||||||
// shcore.dll
|
// shcore.dll
|
||||||
typedef HRESULT(WINAPI *PFN_SetProcessDpiAwareness)(mfb_PROCESS_DPI_AWARENESS);
|
typedef HRESULT(WINAPI *PFN_SetProcessDpiAwareness)(mfb_PROCESS_DPI_AWARENESS);
|
||||||
@ -56,6 +57,8 @@ load_functions() {
|
|||||||
if (mfb_user32_dll != 0x0) {
|
if (mfb_user32_dll != 0x0) {
|
||||||
mfb_SetProcessDPIAware = (PFN_SetProcessDPIAware) GetProcAddress(mfb_user32_dll, "SetProcessDPIAware");
|
mfb_SetProcessDPIAware = (PFN_SetProcessDPIAware) GetProcAddress(mfb_user32_dll, "SetProcessDPIAware");
|
||||||
mfb_SetProcessDpiAwarenessContext = (PFN_SetProcessDpiAwarenessContext) GetProcAddress(mfb_user32_dll, "SetProcessDpiAwarenessContext");
|
mfb_SetProcessDpiAwarenessContext = (PFN_SetProcessDpiAwarenessContext) GetProcAddress(mfb_user32_dll, "SetProcessDpiAwarenessContext");
|
||||||
|
mfb_GetDpiForWindow = (PFN_GetDpiForWindow) GetProcAddress(mfb_user32_dll, "GetDpiForWindow");
|
||||||
|
mfb_EnableNonClientDpiScaling = (PFN_EnableNonClientDpiScaling) GetProcAddress(mfb_user32_dll, "EnableNonClientDpiScaling");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,23 +71,56 @@ load_functions() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--
|
||||||
|
// NOT Thread safe. Just convenient (Don't do this at home guys)
|
||||||
|
char *
|
||||||
|
GetErrorMessage() {
|
||||||
|
static char buffer[256];
|
||||||
|
|
||||||
|
buffer[0] = 0;
|
||||||
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL, // Not used with FORMAT_MESSAGE_FROM_SYSTEM
|
||||||
|
GetLastError(),
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
buffer,
|
||||||
|
sizeof(buffer),
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
//--
|
//--
|
||||||
void
|
void
|
||||||
dpi_aware() {
|
dpi_aware() {
|
||||||
if (mfb_SetProcessDpiAwarenessContext != 0x0) {
|
if (mfb_SetProcessDpiAwarenessContext != 0x0) {
|
||||||
mfb_SetProcessDpiAwarenessContext(mfb_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
if(mfb_SetProcessDpiAwarenessContext(mfb_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == false) {
|
||||||
|
uint32_t error = GetLastError();
|
||||||
|
if(error == ERROR_INVALID_PARAMETER) {
|
||||||
|
error = NO_ERROR;
|
||||||
|
if(mfb_SetProcessDpiAwarenessContext(mfb_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE) == false) {
|
||||||
|
error = GetLastError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(error != NO_ERROR) {
|
||||||
|
fprintf(stderr, "Error (SetProcessDpiAwarenessContext): %s\n", GetErrorMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (mfb_SetProcessDpiAwareness != 0x0) {
|
else if (mfb_SetProcessDpiAwareness != 0x0) {
|
||||||
mfb_SetProcessDpiAwareness(mfb_PROCESS_PER_MONITOR_DPI_AWARE);
|
if(mfb_SetProcessDpiAwareness(mfb_PROCESS_PER_MONITOR_DPI_AWARE) != S_OK) {
|
||||||
|
fprintf(stderr, "Error (SetProcessDpiAwareness): %s\n", GetErrorMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (mfb_SetProcessDPIAware != 0x0) {
|
else if (mfb_SetProcessDPIAware != 0x0) {
|
||||||
mfb_SetProcessDPIAware();
|
if(mfb_SetProcessDPIAware() == false) {
|
||||||
|
fprintf(stderr, "Error (SetProcessDPIAware): %s\n", GetErrorMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--
|
//--
|
||||||
void
|
void
|
||||||
get_monitor_dpi(HWND hWnd, float *dpi_x, float *dpi_y) {
|
get_monitor_scale(HWND hWnd, float *scale_x, float *scale_y) {
|
||||||
UINT x, y;
|
UINT x, y;
|
||||||
|
|
||||||
if(mfb_GetDpiForMonitor != 0x0) {
|
if(mfb_GetDpiForMonitor != 0x0) {
|
||||||
@ -98,17 +134,17 @@ get_monitor_dpi(HWND hWnd, float *dpi_x, float *dpi_y) {
|
|||||||
ReleaseDC(NULL, dc);
|
ReleaseDC(NULL, dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_x) {
|
if (scale_x) {
|
||||||
*dpi_x = x / (float) USER_DEFAULT_SCREEN_DPI;
|
*scale_x = x / (float) USER_DEFAULT_SCREEN_DPI;
|
||||||
if(*dpi_x == 0) {
|
if(*scale_x == 0) {
|
||||||
*dpi_x = 1;
|
*scale_x = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_y) {
|
if (scale_y) {
|
||||||
*dpi_y = y / (float) USER_DEFAULT_SCREEN_DPI;
|
*scale_y = y / (float) USER_DEFAULT_SCREEN_DPI;
|
||||||
if (*dpi_y == 0) {
|
if (*scale_y == 0) {
|
||||||
*dpi_y = 1;
|
*scale_y = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,7 +152,7 @@ get_monitor_dpi(HWND hWnd, float *dpi_x, float *dpi_y) {
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void
|
void
|
||||||
mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
mfb_get_monitor_scale(struct mfb_window *window, float *scale_x, float *scale_y) {
|
||||||
HWND hWnd = 0x0;
|
HWND hWnd = 0x0;
|
||||||
|
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
@ -124,7 +160,7 @@ mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
|||||||
SWindowData_Win *window_data_win = (SWindowData_Win *) window_data->specific;
|
SWindowData_Win *window_data_win = (SWindowData_Win *) window_data->specific;
|
||||||
hWnd = window_data_win->window;
|
hWnd = window_data_win->window;
|
||||||
}
|
}
|
||||||
get_monitor_dpi(hWnd, dpi_x, dpi_y);
|
get_monitor_scale(hWnd, scale_x, scale_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -151,6 +187,31 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
|||||||
|
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
|
case WM_NCCREATE:
|
||||||
|
{
|
||||||
|
if(mfb_EnableNonClientDpiScaling)
|
||||||
|
mfb_EnableNonClientDpiScaling(hWnd);
|
||||||
|
|
||||||
|
return DefWindowProc(hWnd, message, wParam, lParam);;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
//case 0x02E4://WM_GETDPISCALEDSIZE:
|
||||||
|
//{
|
||||||
|
// SIZE* size = (SIZE*) lParam;
|
||||||
|
// WORD dpi = LOWORD(wParam);
|
||||||
|
// return true;
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
//case WM_DPICHANGED:
|
||||||
|
//{
|
||||||
|
// const float xscale = HIWORD(wParam);
|
||||||
|
// const float yscale = LOWORD(wParam);
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
|
|
||||||
#if !defined(USE_OPENGL_API)
|
#if !defined(USE_OPENGL_API)
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
@ -292,14 +353,14 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
|||||||
|
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
if (window_data) {
|
if (window_data) {
|
||||||
float scaleX, scaleY;
|
float scale_x, scale_y;
|
||||||
uint32_t width, height;
|
uint32_t width, height;
|
||||||
|
|
||||||
if(wParam == SIZE_MINIMIZED) {
|
if(wParam == SIZE_MINIMIZED) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_monitor_dpi(hWnd, &scaleX, &scaleY);
|
get_monitor_scale(hWnd, &scale_x, &scale_y);
|
||||||
window_data->window_width = LOWORD(lParam);
|
window_data->window_width = LOWORD(lParam);
|
||||||
window_data->window_height = HIWORD(lParam);
|
window_data->window_height = HIWORD(lParam);
|
||||||
resize_dst(window_data, window_data->window_width, window_data->window_height);
|
resize_dst(window_data, window_data->window_width, window_data->window_height);
|
||||||
@ -310,8 +371,8 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
|||||||
resize_GL(window_data);
|
resize_GL(window_data);
|
||||||
#endif
|
#endif
|
||||||
if(window_data->window_width != 0 && window_data->window_height != 0) {
|
if(window_data->window_width != 0 && window_data->window_height != 0) {
|
||||||
width = (uint32_t) (window_data->window_width / scaleX);
|
width = (uint32_t) (window_data->window_width / scale_x);
|
||||||
height = (uint32_t) (window_data->window_height / scaleY);
|
height = (uint32_t) (window_data->window_height / scale_y);
|
||||||
kCall(resize_func, width, height);
|
kCall(resize_func, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -417,11 +478,12 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!(flags & WF_FULLSCREEN)) {
|
else if (!(flags & WF_FULLSCREEN)) {
|
||||||
float dpi_x, dpi_y;
|
float scale_x, scale_y;
|
||||||
get_monitor_dpi(0, &dpi_x, &dpi_y);
|
|
||||||
|
|
||||||
rect.right = (LONG) (width * dpi_x);
|
get_monitor_scale(0, &scale_x, &scale_y);
|
||||||
rect.bottom = (LONG) (height * dpi_y);
|
|
||||||
|
rect.right = (LONG) (width * scale_x);
|
||||||
|
rect.bottom = (LONG) (height * scale_y);
|
||||||
|
|
||||||
AdjustWindowRect(&rect, s_window_style, 0);
|
AdjustWindowRect(&rect, s_window_style, 0);
|
||||||
|
|
||||||
@ -847,7 +909,7 @@ bool
|
|||||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
SWindowData_Win *window_data_win = 0x0;
|
SWindowData_Win *window_data_win = 0x0;
|
||||||
float scaleX, scaleY;
|
float scale_x, scale_y;
|
||||||
|
|
||||||
if(window_data == 0x0) {
|
if(window_data == 0x0) {
|
||||||
return false;
|
return false;
|
||||||
@ -862,12 +924,12 @@ mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y
|
|||||||
|
|
||||||
window_data_win = (SWindowData_Win *) window_data->specific;
|
window_data_win = (SWindowData_Win *) window_data->specific;
|
||||||
|
|
||||||
get_monitor_dpi(window_data_win->window, &scaleX, &scaleY);
|
get_monitor_scale(window_data_win->window, &scale_x, &scale_y);
|
||||||
window_data->dst_offset_x = (uint32_t) (offset_x * scaleX);
|
window_data->dst_offset_x = (uint32_t) (offset_x * scale_x);
|
||||||
window_data->dst_offset_y = (uint32_t) (offset_y * scaleY);
|
window_data->dst_offset_y = (uint32_t) (offset_y * scale_y);
|
||||||
|
|
||||||
window_data->dst_width = (uint32_t) (width * scaleX);
|
window_data->dst_width = (uint32_t) (width * scale_x);
|
||||||
window_data->dst_height = (uint32_t) (height * scaleY);
|
window_data->dst_height = (uint32_t) (height * scale_y);
|
||||||
|
|
||||||
calc_dst_factor(window_data, window_data->window_width, window_data->window_height);
|
calc_dst_factor(window_data, window_data->window_width, window_data->window_height);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
void init_keycodes(SWindowData_X11 *window_data_x11);
|
void init_keycodes(SWindowData_X11 *window_data_x11);
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
stretch_image(uint32_t *srcImage, uint32_t srcX, uint32_t srcY, uint32_t srcWidth, uint32_t srcHeight, uint32_t srcPitch,
|
stretch_image(uint32_t *srcImage, uint32_t srcX, uint32_t srcY, uint32_t srcWidth, uint32_t srcHeight, uint32_t srcPitch,
|
||||||
uint32_t *dstImage, uint32_t dstX, uint32_t dstY, uint32_t dstWidth, uint32_t dstHeight, uint32_t dstPitch);
|
uint32_t *dstImage, uint32_t dstX, uint32_t dstY, uint32_t dstWidth, uint32_t dstHeight, uint32_t dstPitch);
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
|||||||
free(window_data_x11);
|
free(window_data_x11);
|
||||||
return 0x0;
|
return 0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
init_keycodes(window_data_x11);
|
init_keycodes(window_data_x11);
|
||||||
|
|
||||||
window_data_x11->screen = DefaultScreen(window_data_x11->display);
|
window_data_x11->screen = DefaultScreen(window_data_x11->display);
|
||||||
@ -79,7 +79,7 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XFree(formats);
|
XFree(formats);
|
||||||
|
|
||||||
// We only support 32-bit right now
|
// We only support 32-bit right now
|
||||||
@ -120,23 +120,23 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
window_data_x11->window = XCreateWindow(
|
window_data_x11->window = XCreateWindow(
|
||||||
window_data_x11->display,
|
window_data_x11->display,
|
||||||
defaultRootWindow,
|
defaultRootWindow,
|
||||||
posX, posY,
|
posX, posY,
|
||||||
windowWidth, windowHeight,
|
windowWidth, windowHeight,
|
||||||
0,
|
0,
|
||||||
depth,
|
depth,
|
||||||
InputOutput,
|
InputOutput,
|
||||||
visual,
|
visual,
|
||||||
CWBackPixel | CWBorderPixel | CWBackingStore,
|
CWBackPixel | CWBorderPixel | CWBackingStore,
|
||||||
&windowAttributes);
|
&windowAttributes);
|
||||||
if (!window_data_x11->window)
|
if (!window_data_x11->window)
|
||||||
return 0x0;
|
return 0x0;
|
||||||
|
|
||||||
XSelectInput(window_data_x11->display, window_data_x11->window,
|
XSelectInput(window_data_x11->display, window_data_x11->window,
|
||||||
KeyPressMask | KeyReleaseMask
|
KeyPressMask | KeyReleaseMask
|
||||||
| ButtonPressMask | ButtonReleaseMask | PointerMotionMask
|
| ButtonPressMask | ButtonReleaseMask | PointerMotionMask
|
||||||
| StructureNotifyMask | ExposureMask
|
| StructureNotifyMask | ExposureMask
|
||||||
| FocusChangeMask
|
| FocusChangeMask
|
||||||
| EnterWindowMask | LeaveWindowMask
|
| EnterWindowMask | LeaveWindowMask
|
||||||
);
|
);
|
||||||
@ -219,11 +219,11 @@ int translate_key(int scancode);
|
|||||||
int translate_mod(int state);
|
int translate_mod(int state);
|
||||||
int translate_mod_ex(int key, int state, int is_pressed);
|
int translate_mod_ex(int key, int state, int is_pressed);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
processEvent(SWindowData *window_data, XEvent *event) {
|
processEvent(SWindowData *window_data, XEvent *event) {
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
case KeyRelease:
|
case KeyRelease:
|
||||||
{
|
{
|
||||||
mfb_key key_code = (mfb_key) translate_key(event->xkey.keycode);
|
mfb_key key_code = (mfb_key) translate_key(event->xkey.keycode);
|
||||||
int is_pressed = (event->type == KeyPress);
|
int is_pressed = (event->type == KeyPress);
|
||||||
@ -274,10 +274,10 @@ processEvent(SWindowData *window_data, XEvent *event) {
|
|||||||
kCall(mouse_move_func, event->xmotion.x, event->xmotion.y);
|
kCall(mouse_move_func, event->xmotion.x, event->xmotion.y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ConfigureNotify:
|
case ConfigureNotify:
|
||||||
{
|
{
|
||||||
window_data->window_width = event->xconfigure.width;
|
window_data->window_width = event->xconfigure.width;
|
||||||
window_data->window_height = event->xconfigure.height;
|
window_data->window_height = event->xconfigure.height;
|
||||||
resize_dst(window_data, event->xconfigure.width, event->xconfigure.height);
|
resize_dst(window_data, event->xconfigure.width, event->xconfigure.height);
|
||||||
|
|
||||||
#if defined(USE_OPENGL_API)
|
#if defined(USE_OPENGL_API)
|
||||||
@ -292,7 +292,7 @@ processEvent(SWindowData *window_data, XEvent *event) {
|
|||||||
window_data_x11->image_scaler_height = 0;
|
window_data_x11->image_scaler_height = 0;
|
||||||
}
|
}
|
||||||
XClearWindow(window_data_x11->display, window_data_x11->window);
|
XClearWindow(window_data_x11->display, window_data_x11->window);
|
||||||
#endif
|
#endif
|
||||||
kCall(resize_func, window_data->window_width, window_data->window_height);
|
kCall(resize_func, window_data->window_width, window_data->window_height);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -318,7 +318,7 @@ processEvent(SWindowData *window_data, XEvent *event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
processEvents(SWindowData *window_data) {
|
processEvents(SWindowData *window_data) {
|
||||||
XEvent event;
|
XEvent event;
|
||||||
SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific;
|
SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific;
|
||||||
@ -333,7 +333,7 @@ processEvents(SWindowData *window_data) {
|
|||||||
|
|
||||||
void destroy_window_data(SWindowData *window_data);
|
void destroy_window_data(SWindowData *window_data);
|
||||||
|
|
||||||
mfb_update_state
|
mfb_update_state
|
||||||
mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned height) {
|
mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned height) {
|
||||||
if (window == 0x0) {
|
if (window == 0x0) {
|
||||||
return STATE_INVALID_WINDOW;
|
return STATE_INVALID_WINDOW;
|
||||||
@ -387,7 +387,7 @@ mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window_data_x11->image_scaler != 0x0) {
|
if (window_data_x11->image_scaler != 0x0) {
|
||||||
stretch_image((uint32_t *) buffer, 0, 0, window_data->buffer_width, window_data->buffer_height, window_data->buffer_width,
|
stretch_image((uint32_t *) buffer, 0, 0, window_data->buffer_width, window_data->buffer_height, window_data->buffer_width,
|
||||||
(uint32_t *) window_data_x11->image_buffer, 0, 0, window_data->dst_width, window_data->dst_height, window_data->dst_width);
|
(uint32_t *) window_data_x11->image_buffer, 0, 0, window_data->dst_width, window_data->dst_height, window_data->dst_width);
|
||||||
window_data_x11->image_scaler->data = (char *) window_data_x11->image_buffer;
|
window_data_x11->image_scaler->data = (char *) window_data_x11->image_buffer;
|
||||||
XPutImage(window_data_x11->display, window_data_x11->window, window_data_x11->gc, window_data_x11->image_scaler, 0, 0, window_data->dst_offset_x, window_data->dst_offset_y, window_data->dst_width, window_data->dst_height);
|
XPutImage(window_data_x11->display, window_data_x11->window, window_data_x11->gc, window_data_x11->image_scaler, 0, 0, window_data->dst_offset_x, window_data->dst_offset_y, window_data->dst_width, window_data->dst_height);
|
||||||
@ -405,13 +405,13 @@ mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
processEvents(window_data);
|
processEvents(window_data);
|
||||||
|
|
||||||
return STATE_OK;
|
return STATE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
mfb_update_state
|
mfb_update_state
|
||||||
mfb_update_events(struct mfb_window *window) {
|
mfb_update_events(struct mfb_window *window) {
|
||||||
if (window == 0x0) {
|
if (window == 0x0) {
|
||||||
return STATE_INVALID_WINDOW;
|
return STATE_INVALID_WINDOW;
|
||||||
@ -426,7 +426,7 @@ mfb_update_events(struct mfb_window *window) {
|
|||||||
SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific;
|
SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific;
|
||||||
XFlush(window_data_x11->display);
|
XFlush(window_data_x11->display);
|
||||||
processEvents(window_data);
|
processEvents(window_data);
|
||||||
|
|
||||||
return STATE_OK;
|
return STATE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ mfb_update_events(struct mfb_window *window) {
|
|||||||
|
|
||||||
extern double g_time_for_frame;
|
extern double g_time_for_frame;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mfb_wait_sync(struct mfb_window *window) {
|
mfb_wait_sync(struct mfb_window *window) {
|
||||||
if (window == 0x0) {
|
if (window == 0x0) {
|
||||||
return STATE_INVALID_WINDOW;
|
return STATE_INVALID_WINDOW;
|
||||||
@ -456,7 +456,7 @@ mfb_wait_sync(struct mfb_window *window) {
|
|||||||
XNextEvent(window_data_x11->display, &event);
|
XNextEvent(window_data_x11->display, &event);
|
||||||
processEvent(window_data, &event);
|
processEvent(window_data, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(window_data->close) {
|
if(window_data->close) {
|
||||||
destroy_window_data(window_data);
|
destroy_window_data(window_data);
|
||||||
return false;
|
return false;
|
||||||
@ -474,19 +474,19 @@ mfb_wait_sync(struct mfb_window *window) {
|
|||||||
usleep(millis * 1000);
|
usleep(millis * 1000);
|
||||||
//sched_yield();
|
//sched_yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void
|
void
|
||||||
destroy_window_data(SWindowData *window_data) {
|
destroy_window_data(SWindowData *window_data) {
|
||||||
if (window_data != 0x0) {
|
if (window_data != 0x0) {
|
||||||
if (window_data->specific != 0x0) {
|
if (window_data->specific != 0x0) {
|
||||||
SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific;
|
SWindowData_X11 *window_data_x11 = (SWindowData_X11 *) window_data->specific;
|
||||||
|
|
||||||
#if defined(USE_OPENGL_API)
|
#if defined(USE_OPENGL_API)
|
||||||
destroy_GL_context(window_data);
|
destroy_GL_context(window_data);
|
||||||
#else
|
#else
|
||||||
if (window_data_x11->image != 0x0) {
|
if (window_data_x11->image != 0x0) {
|
||||||
@ -495,7 +495,7 @@ destroy_window_data(SWindowData *window_data) {
|
|||||||
XDestroyWindow(window_data_x11->display, window_data_x11->window);
|
XDestroyWindow(window_data_x11->display, window_data_x11->window);
|
||||||
XCloseDisplay(window_data_x11->display);
|
XCloseDisplay(window_data_x11->display);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mfb_timer_destroy(window_data_x11->timer);
|
mfb_timer_destroy(window_data_x11->timer);
|
||||||
memset(window_data_x11, 0, sizeof(SWindowData_X11));
|
memset(window_data_x11, 0, sizeof(SWindowData_X11));
|
||||||
@ -510,7 +510,7 @@ destroy_window_data(SWindowData *window_data) {
|
|||||||
|
|
||||||
extern short int g_keycodes[512];
|
extern short int g_keycodes[512];
|
||||||
|
|
||||||
static int
|
static int
|
||||||
translateKeyCodeB(int keySym) {
|
translateKeyCodeB(int keySym) {
|
||||||
|
|
||||||
switch (keySym)
|
switch (keySym)
|
||||||
@ -674,13 +674,13 @@ static int translateKeyCodeA(int keySym) {
|
|||||||
return KB_KEY_UNKNOWN;
|
return KB_KEY_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_keycodes(SWindowData_X11 *window_data_x11) {
|
init_keycodes(SWindowData_X11 *window_data_x11) {
|
||||||
size_t i;
|
size_t i;
|
||||||
int keySym;
|
int keySym;
|
||||||
|
|
||||||
// Clear keys
|
// Clear keys
|
||||||
for (i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
for (i = 0; i < sizeof(g_keycodes) / sizeof(g_keycodes[0]); ++i)
|
||||||
g_keycodes[i] = KB_KEY_UNKNOWN;
|
g_keycodes[i] = KB_KEY_UNKNOWN;
|
||||||
|
|
||||||
// Valid key code range is [8,255], according to the Xlib manual
|
// Valid key code range is [8,255], according to the Xlib manual
|
||||||
@ -697,7 +697,7 @@ init_keycodes(SWindowData_X11 *window_data_x11) {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int
|
int
|
||||||
translate_key(int scancode) {
|
translate_key(int scancode) {
|
||||||
if (scancode < 0 || scancode > 255)
|
if (scancode < 0 || scancode > 255)
|
||||||
return KB_KEY_UNKNOWN;
|
return KB_KEY_UNKNOWN;
|
||||||
@ -707,7 +707,7 @@ translate_key(int scancode) {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int
|
int
|
||||||
translate_mod(int state) {
|
translate_mod(int state) {
|
||||||
int mod_keys = 0;
|
int mod_keys = 0;
|
||||||
|
|
||||||
@ -729,7 +729,7 @@ translate_mod(int state) {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int
|
int
|
||||||
translate_mod_ex(int key, int state, int is_pressed) {
|
translate_mod_ex(int key, int state, int is_pressed) {
|
||||||
int mod_keys = 0;
|
int mod_keys = 0;
|
||||||
|
|
||||||
@ -775,7 +775,7 @@ translate_mod_ex(int key, int state, int is_pressed) {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
|
|
||||||
@ -791,14 +791,14 @@ mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y
|
|||||||
window_data->dst_width = width;
|
window_data->dst_width = width;
|
||||||
window_data->dst_height = height;
|
window_data->dst_height = height;
|
||||||
calc_dst_factor(window_data, window_data->window_width, window_data->window_height);
|
calc_dst_factor(window_data, window_data->window_width, window_data->window_height);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void
|
void
|
||||||
mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
mfb_get_monitor_scale(struct mfb_window *window, float *scale_x, float *scale_y) {
|
||||||
float x = 96.0, y = 96.0;
|
float x = 96.0, y = 96.0;
|
||||||
|
|
||||||
if(window != 0x0) {
|
if(window != 0x0) {
|
||||||
@ -812,17 +812,17 @@ mfb_get_monitor_dpi(struct mfb_window *window, float *dpi_x, float *dpi_y) {
|
|||||||
// All returning invalid values or 0
|
// All returning invalid values or 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_x) {
|
if (scale_x) {
|
||||||
*dpi_x = x / 96.0f;
|
*scale_x = x / 96.0f;
|
||||||
if(*dpi_x == 0) {
|
if(*scale_x == 0) {
|
||||||
*dpi_x = 1.0f;
|
*scale_x = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi_y) {
|
if (scale_y) {
|
||||||
*dpi_y = y / 96.0f;
|
*scale_y = y / 96.0f;
|
||||||
if (*dpi_y == 0) {
|
if (*scale_y == 0) {
|
||||||
*dpi_y = 1.0f;
|
*scale_y = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ resize(struct mfb_window *window, int width, int height) {
|
|||||||
dis ^= 0x01;
|
dis ^= 0x01;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mfb_update_state state = mfb_update_ex(g_window, g_buffer, g_width, g_height);
|
mfb_update_state state = mfb_update_ex(g_window, g_buffer, g_width, g_height);
|
||||||
if (state != STATE_OK) {
|
if (state != STATE_OK) {
|
||||||
free(g_buffer);
|
free(g_buffer);
|
||||||
@ -89,9 +89,9 @@ resize(struct mfb_window *window, int width, int height) {
|
|||||||
// Override point for customization after application launch.
|
// Override point for customization after application launch.
|
||||||
kUnused(application);
|
kUnused(application);
|
||||||
kUnused(launchOptions);
|
kUnused(launchOptions);
|
||||||
|
|
||||||
if(g_window == 0x0) {
|
if(g_window == 0x0) {
|
||||||
mfb_get_monitor_dpi(0x0, &g_scale, 0x0);
|
mfb_get_monitor_scale(0x0, &g_scale, 0x0);
|
||||||
//g_scale = [UIScreen mainScreen].scale;
|
//g_scale = [UIScreen mainScreen].scale;
|
||||||
g_width = [UIScreen mainScreen].bounds.size.width * g_scale;
|
g_width = [UIScreen mainScreen].bounds.size.width * g_scale;
|
||||||
g_height = [UIScreen mainScreen].bounds.size.height * g_scale;
|
g_height = [UIScreen mainScreen].bounds.size.height * g_scale;
|
||||||
@ -135,7 +135,7 @@ resize(struct mfb_window *window, int width, int height) {
|
|||||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||||
kUnused(application);
|
kUnused(application);
|
||||||
|
|
||||||
mDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(OnUpdateFrame)];
|
mDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(OnUpdateFrame)];
|
||||||
[mDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
[mDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ resize(struct mfb_window *window, int width, int height) {
|
|||||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||||
kUnused(application);
|
kUnused(application);
|
||||||
|
|
||||||
[mDisplayLink invalidate];
|
[mDisplayLink invalidate];
|
||||||
mfb_close(g_window);
|
mfb_close(g_window);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user