support update
just some inclusions to work on linux
This commit is contained in:
parent
d29bee1b89
commit
90d6402e06
33 changed files with 478 additions and 19571 deletions
|
@ -68,7 +68,18 @@
|
|||
|
||||
*/
|
||||
|
||||
#include<windows.h>
|
||||
#ifdef _WIN32
|
||||
#include<windows.h>
|
||||
#else
|
||||
#include<X11/Xlib.h>
|
||||
#include<unistd.h> // for sleep()
|
||||
#endif
|
||||
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
|
||||
#include<libcef/capi/cef_app_capi.h>
|
||||
#include<libcef/capi/cef_client_capi.h>
|
||||
#include<libcef/capi/cef_browser_capi.h>
|
||||
|
@ -76,9 +87,8 @@
|
|||
|
||||
#include"display_manager/display_manager.h"
|
||||
|
||||
//#include"cef_manager/cef_custom.h"
|
||||
#include"cef_manager/cef_core.h"
|
||||
|
||||
#include<stdio.h>
|
||||
|
||||
int programLoop = 1; // This is the main loop of the program, if you reset it the program will close
|
||||
|
||||
|
@ -86,122 +96,82 @@ LE_Display *progDisplay; // defined structure of the window handler component
|
|||
|
||||
int cefInitialized = 0;
|
||||
|
||||
// Struct de handler
|
||||
typedef struct
|
||||
{
|
||||
cef_life_span_handler_t handler;
|
||||
} MyLifeSpanHandler;
|
||||
int displayWindowWidth = 417;
|
||||
int displayWindowHeight = 670;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cef_client_t client;
|
||||
} MyClient;
|
||||
// X11 error handlers
|
||||
#ifdef __linux__
|
||||
|
||||
int XErrorHandlerImpl(Display* display, XErrorEvent* event)
|
||||
{
|
||||
fprintf(stderr, "X11 Error: type=%d, serial=%lu, code=%d, request=%d, minor=%d\n",
|
||||
event->type, event->serial, event->error_code,
|
||||
event->request_code, event->minor_code);
|
||||
return 0;
|
||||
}
|
||||
#endif // __linux__
|
||||
|
||||
|
||||
// Handler and client
|
||||
cef_app_t g_app = {0};
|
||||
cef_client_t g_client = {0};
|
||||
|
||||
MyClient g_client;
|
||||
MyLifeSpanHandler g_lifeSpanHandler;
|
||||
|
||||
// Inicializa o CEF com settings básicos
|
||||
void init_cef(HINSTANCE hInstance)
|
||||
{
|
||||
cef_main_args_t main_args = {0};
|
||||
cef_settings_t settings = {0};
|
||||
|
||||
// CefMainArgs
|
||||
|
||||
main_args.instance = hInstance;
|
||||
|
||||
// Settings
|
||||
|
||||
settings.size = sizeof(settings);
|
||||
settings.no_sandbox = 1;
|
||||
settings.multi_threaded_message_loop = 1; // uses the Windows loop
|
||||
settings.single_process = 1; // required for XP
|
||||
|
||||
// Inicializa o CEF
|
||||
cef_initialize(&main_args, &settings, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CEF_CALLBACK on_after_created(struct _cef_life_span_handler_t* self, struct _cef_browser_t* browser)
|
||||
{
|
||||
printf("[CEF] Browser created!\n");
|
||||
}
|
||||
|
||||
// Define a vtable da interface
|
||||
void setup_lifespan_handler()
|
||||
{
|
||||
g_lifeSpanHandler.handler.base.size = sizeof(cef_life_span_handler_t);
|
||||
g_lifeSpanHandler.handler.on_after_created = on_after_created;
|
||||
}
|
||||
|
||||
cef_life_span_handler_t* CEF_CALLBACK get_life_span_handler(struct _cef_client_t* self)
|
||||
{
|
||||
return (cef_life_span_handler_t*)&g_lifeSpanHandler;
|
||||
}
|
||||
|
||||
void setup_client()
|
||||
{
|
||||
g_client.client.base.size = sizeof(cef_client_t);
|
||||
g_client.client.get_life_span_handler = get_life_span_handler;
|
||||
}
|
||||
|
||||
void create_browser()
|
||||
{
|
||||
//CefWindowHandle hwnd = (HWND)progDisplay->platformHandle;
|
||||
cef_window_handle_t hwnd = (cef_window_handle_t)progDisplay->platformHandle;
|
||||
|
||||
cef_window_info_t window_info = {0};
|
||||
cef_browser_settings_t browser_settings = {0};
|
||||
cef_string_utf16_t url = {0};
|
||||
|
||||
|
||||
window_info.parent_window = hwnd;
|
||||
window_info.style = WS_CHILD | WS_VISIBLE;
|
||||
window_info.x = 0;
|
||||
window_info.y = 0;
|
||||
window_info.width = progDisplay->width;
|
||||
window_info.height = progDisplay->height;
|
||||
|
||||
browser_settings.size = sizeof(cef_browser_settings_t);
|
||||
|
||||
cef_string_utf8_to_utf16("http://127.0.0.1/oidc/interaction/login", strlen("http://127.0.0.1/oidc/interaction/login"), &url);
|
||||
|
||||
cef_browser_host_create_browser(&window_info,
|
||||
(cef_client_t*)&g_client,
|
||||
&url,
|
||||
&browser_settings,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
void progLoop()
|
||||
{
|
||||
|
||||
if(!cefInitialized)
|
||||
cef_do_message_loop_work(); // process CEF events
|
||||
//usleep(1000); // avoid 100% CPU usage
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
int result;
|
||||
|
||||
// Phase 1: Before the window (only if multiprocessor)
|
||||
result = cef_setup_pre_display(NULL, argc, argv, &g_app);
|
||||
if(result != 0)
|
||||
{
|
||||
setup_lifespan_handler();
|
||||
setup_client();
|
||||
create_browser();
|
||||
cefInitialized = 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
//http://127.0.0.1/oidc/interaction/login
|
||||
|
||||
progDisplay = engineCreateDisplay("MainWindow",
|
||||
displayWindowWidth,
|
||||
displayWindowHeight); // create Program Display/Window
|
||||
|
||||
result = cef_setup_post_display(progDisplay->platformConnection, argc, argv, &g_app);
|
||||
if (result != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
progDisplay = engineCreateDisplay("MainWindow", 417, 670);
|
||||
|
||||
init_cef(progDisplay->platformConnection);
|
||||
|
||||
|
||||
|
||||
engineSetLoop(progDisplay, &programLoop, progLoop);
|
||||
|
||||
cef_shutdown();
|
||||
|
||||
return 0;
|
||||
|
||||
// X11: configurar handlers de erro
|
||||
#ifdef __linux__
|
||||
XSetErrorHandler(XErrorHandlerImpl); // without this the x11 communication with the cef does not work
|
||||
#endif
|
||||
|
||||
setup_lifespan_handler(&g_lifeSpanHandler);
|
||||
setup_client(&g_client);
|
||||
create_browser("http://127.0.0.1/oidc/interaction/login",
|
||||
&g_client,
|
||||
progDisplay->platformHandle,
|
||||
displayWindowWidth,
|
||||
displayWindowHeight);
|
||||
|
||||
engineSetLoop(progDisplay, &programLoop, progLoop);
|
||||
|
||||
// CEF concludes
|
||||
cef_quit_message_loop();
|
||||
cef_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue