Skip to content

Commit

Permalink
Add lv_windows_context.
Browse files Browse the repository at this point in the history
  • Loading branch information
MouriNaruto committed Jan 12, 2024
1 parent f81f21f commit b5b483d
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 79 deletions.
2 changes: 2 additions & 0 deletions LvglWindowsSimulator/LvglWindowsSimulator.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\LvglPlatform\lvgl\src\widgets\tileview\lv_tileview.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\LvglPlatform\lvgl\src\widgets\win\lv_win.h" />
<ClInclude Include="lv_conf.h" />
<ClInclude Include="lv_windows_context.h" />
<ClInclude Include="win32drv.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -958,6 +959,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\LvglPlatform\lvgl\src\widgets\tileview\lv_tileview.c" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\LvglPlatform\lvgl\src\widgets\win\lv_win.c" />
<ClCompile Include="LvglWindowsSimulator.cpp" />
<ClCompile Include="lv_windows_context.c" />
<ClCompile Include="win32drv.c" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions LvglWindowsSimulator/LvglWindowsSimulator.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@
</ClInclude>
<ClInclude Include="lv_conf.h" />
<ClInclude Include="win32drv.h" />
<ClInclude Include="lv_windows_context.h" />
</ItemGroup>
<ItemGroup>
<Manifest Include="LvglWindowsSimulator.manifest" />
Expand Down Expand Up @@ -2743,6 +2744,7 @@
</ClCompile>
<ClCompile Include="LvglWindowsSimulator.cpp" />
<ClCompile Include="win32drv.c" />
<ClCompile Include="lv_windows_context.c" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\LvglPlatform\freetype\.clang-format">
Expand Down
60 changes: 60 additions & 0 deletions LvglWindowsSimulator/lv_windows_context.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @file lv_windows_context.c
*
*/

/*********************
* INCLUDES
*********************/

#include "lv_windows_context.h"
#ifdef LV_USE_WINDOWS

/*********************
* DEFINES
*********************/

/**********************
* TYPEDEFS
**********************/

/**********************
* STATIC PROTOTYPES
**********************/

/**********************
* STATIC VARIABLES
**********************/

/**********************
* MACROS
**********************/

/**********************
* GLOBAL FUNCTIONS
**********************/

EXTERN_C HWND lv_windows_get_display_window_handle(
lv_display_t* display)
{
return (HWND)lv_display_get_driver_data(display);
}

EXTERN_C HWND lv_windows_get_indev_window_handle(
lv_indev_t* indev)
{
return lv_windows_get_display_window_handle(lv_indev_get_display(indev));
}

lv_windows_window_context_t* lv_windows_get_window_context(
HWND window_handle)
{
return (lv_windows_window_context_t*)(
GetPropW(window_handle, L"LVGL.Window.Context"));
}

/**********************
* STATIC FUNCTIONS
**********************/

#endif // LV_USE_WINDOWS
118 changes: 118 additions & 0 deletions LvglWindowsSimulator/lv_windows_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/**
* @file lv_windows_context.h
*
*/

#ifndef LV_WINDOWS_CONTEXT_H
#define LV_WINDOWS_CONTEXT_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
* INCLUDES
*********************/

#include "lvgl.h"
#define LV_USE_WINDOWS

//#include "../../display/lv_display.h"
//#include "../../indev/lv_indev.h"

#ifdef LV_USE_WINDOWS

#include <windows.h>

/*********************
* DEFINES
*********************/

/**********************
* TYPEDEFS
**********************/

typedef struct _lv_windows_pointer_context_t
{
lv_indev_state_t state;
lv_point_t point;
lv_indev_t* indev;
} lv_windows_pointer_context_t;

typedef struct _lv_windows_keypad_queue_item_t
{
uint32_t key;
lv_indev_state_t state;
} lv_windows_keypad_queue_item_t;

typedef struct _lv_windows_keypad_context_t
{
CRITICAL_SECTION mutex;
lv_ll_t queue;
uint16_t utf16_high_surrogate;
uint16_t utf16_low_surrogate;
lv_indev_t* indev;
} lv_windows_keypad_context_t;

typedef struct _lv_windows_encoder_context_t
{
lv_indev_state_t state;
int16_t enc_diff;
lv_indev_t* indev;
} lv_windows_encoder_context_t;

typedef struct _lv_windows_window_context_t
{
lv_disp_t* display_device_object;
lv_timer_t* display_timer_object;

int32_t window_dpi;
int32_t zoom_level;
bool allow_dpi_override;
bool simulator_mode;
bool display_resolution_changed;
lv_point_t requested_display_resolution;

HDC display_framebuffer_context_handle;
uint32_t* display_framebuffer_base;
size_t display_framebuffer_size;

lv_windows_pointer_context_t pointer;
lv_windows_keypad_context_t keypad;
lv_windows_encoder_context_t encoder;

} lv_windows_window_context_t;

/**********************
* GLOBAL PROTOTYPES
**********************/

HWND lv_windows_get_display_window_handle(
lv_display_t* display);

HWND lv_windows_get_indev_window_handle(
lv_indev_t* indev);

/**
* @brief Get the window context from specific LVGL display window.
* @param window_handle The window handle of specific LVGL display window.
* @return The window context from specific LVGL display window.
* @remark This is a private API which is used for LVGL Windows backend
* implementation. LVGL users shouldn't use that because the
* maintainer doesn't promise the application binary interface
* compatibility for this API.
*/
lv_windows_window_context_t* lv_windows_get_window_context(
HWND window_handle);

/**********************
* MACROS
**********************/

#endif // LV_USE_WINDOWS

#ifdef __cplusplus
} /*extern "C"*/
#endif

#endif /*LV_WINDOWS_CONTEXT_H*/
19 changes: 0 additions & 19 deletions LvglWindowsSimulator/win32drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,6 @@ static HWND g_window_handle = NULL;
* GLOBAL FUNCTIONS
**********************/

EXTERN_C lv_windows_window_context_t* lv_windows_get_window_context(
HWND window_handle)
{
return (lv_windows_window_context_t*)(
GetPropW(window_handle, L"LVGL.Window.Context"));
}

static void lv_windows_check_display_existence_timer_callback(lv_timer_t* timer)
{
if (!lv_display_get_next(NULL))
Expand Down Expand Up @@ -598,18 +591,6 @@ EXTERN_C lv_indev_t* lv_windows_acquire_encoder_device(
return context->encoder.indev;
}

EXTERN_C HWND lv_windows_get_display_window_handle(
lv_display_t* display)
{
return (HWND)lv_display_get_driver_data(display);
}

EXTERN_C HWND lv_windows_get_indev_window_handle(
lv_indev_t* indev)
{
return lv_windows_get_display_window_handle(lv_indev_get_display(indev));
}

/**********************
* STATIC FUNCTIONS
**********************/
Expand Down
62 changes: 2 additions & 60 deletions LvglWindowsSimulator/win32drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "lvgl/lvgl.h"

#include "lv_windows_context.h"

#include <windows.h>

#if _MSC_VER >= 1200
Expand Down Expand Up @@ -52,64 +54,10 @@
* TYPEDEFS
**********************/

typedef struct _lv_windows_pointer_context_t
{
lv_indev_state_t state;
lv_point_t point;
lv_indev_t* indev;
} lv_windows_pointer_context_t;

typedef struct _lv_windows_keypad_queue_item_t
{
uint32_t key;
lv_indev_state_t state;
} lv_windows_keypad_queue_item_t;

typedef struct _lv_windows_keypad_context_t
{
CRITICAL_SECTION mutex;
lv_ll_t queue;
uint16_t utf16_high_surrogate;
uint16_t utf16_low_surrogate;
lv_indev_t* indev;
} lv_windows_keypad_context_t;

typedef struct _lv_windows_encoder_context_t
{
lv_indev_state_t state;
int16_t enc_diff;
lv_indev_t* indev;
} lv_windows_encoder_context_t;

typedef struct _lv_windows_window_context_t
{
lv_disp_t* display_device_object;
lv_timer_t* display_timer_object;

int32_t window_dpi;
int32_t zoom_level;
bool allow_dpi_override;
bool simulator_mode;
bool display_resolution_changed;
lv_point_t requested_display_resolution;

HDC display_framebuffer_context_handle;
uint32_t* display_framebuffer_base;
size_t display_framebuffer_size;

lv_windows_pointer_context_t pointer;
lv_windows_keypad_context_t keypad;
lv_windows_encoder_context_t encoder;

} lv_windows_window_context_t;

/**********************
* GLOBAL PROTOTYPES
**********************/

EXTERN_C lv_windows_window_context_t* lv_windows_get_window_context(
HWND window_handle);

EXTERN_C bool lv_windows_platform_init();

EXTERN_C lv_display_t* lv_windows_create_display(
Expand All @@ -129,12 +77,6 @@ EXTERN_C lv_indev_t* lv_windows_acquire_keypad_device(
EXTERN_C lv_indev_t* lv_windows_acquire_encoder_device(
lv_display_t* display);

EXTERN_C HWND lv_windows_get_display_window_handle(
lv_display_t* display);

EXTERN_C HWND lv_windows_get_indev_window_handle(
lv_indev_t* indev);

/**********************
* MACROS
**********************/
Expand Down

0 comments on commit b5b483d

Please sign in to comment.