freerdp: start using pubSub for client GUI events

This commit is contained in:
Marc-André Moreau 2013-06-15 17:01:10 -04:00
parent 95a129eb69
commit 6c9a3b8e64
7 changed files with 80 additions and 17 deletions

View File

@ -480,6 +480,7 @@ void xf_create_window(xfContext* xfc)
void xf_toggle_fullscreen(xfContext* xfc)
{
Pixmap contents = 0;
WindowStateChangeEventArgs e;
xf_lock_x11(xfc, TRUE);
@ -495,8 +496,9 @@ void xf_toggle_fullscreen(xfContext* xfc)
xf_unlock_x11(xfc, TRUE);
IFCALL(xfc->client->OnWindowStateChange, xfc->instance,
xfc->fullscreen ? FREERDP_WINDOW_STATE_FULLSCREEN : 0);
e.state = xfc->fullscreen ? FREERDP_WINDOW_STATE_FULLSCREEN : 0;
PubSub_OnEvent(xfc->pubSub, "WindowStateChange", xfc, (wEventArgs*) &e);
}
void xf_lock_x11(xfContext* xfc, BOOL display)
@ -771,6 +773,7 @@ BOOL xf_post_connect(freerdp* instance)
rdpCache* cache;
rdpChannels* channels;
rdpSettings* settings;
ResizeWindowEventArgs e;
RFX_CONTEXT* rfx_context = NULL;
NSC_CONTEXT* nsc_context = NULL;
xfContext* xfc = (xfContext*) instance->context;
@ -891,7 +894,10 @@ BOOL xf_post_connect(freerdp* instance)
xf_cliprdr_init(xfc, channels);
IFCALL(xfc->client->OnResizeWindow, instance, settings->DesktopWidth, settings->DesktopHeight);
e.width = settings->DesktopWidth;
e.height = settings->DesktopHeight;
PubSub_OnEvent(xfc->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
return TRUE;
}
@ -1560,11 +1566,16 @@ double freerdp_client_get_scale(rdpContext* context)
void freerdp_client_reset_scale(rdpContext* context)
{
ResizeWindowEventArgs e;
xfContext* xfc = (xfContext*) context;
xfc->scale = 1.0;
XResizeWindow(xfc->display, xfc->window->handle, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
IFCALL(xfc->client->OnResizeWindow, xfc->instance, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
e.width = (int) xfc->originalWidth * xfc->scale;
e.height = (int) xfc->originalHeight * xfc->scale;
PubSub_OnEvent(xfc->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
xf_draw_screen_scaled(xfc);
}

View File

@ -22,6 +22,7 @@
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#include <freerdp/client.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/gdi/dc.h>

View File

@ -156,6 +156,7 @@ void xf_input_detect_pinch(xfContext* xfc)
double dist;
double zoom;
double delta;
ResizeWindowEventArgs e;
if (active_contacts != 2)
{
@ -195,7 +196,10 @@ void xf_input_detect_pinch(xfContext* xfc)
xfc->scale = 0.5;
XResizeWindow(xfc->display, xfc->window->handle, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
IFCALL(xfc->client->OnResizeWindow, xfc->instance, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
e.width = (int) xfc->originalWidth * xfc->scale;
e.height = (int) xfc->originalHeight * xfc->scale;
PubSub_OnEvent(xfc->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
z_vector = 0;
}
@ -208,7 +212,10 @@ void xf_input_detect_pinch(xfContext* xfc)
xfc->scale = 1.5;
XResizeWindow(xfc->display, xfc->window->handle, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
IFCALL(xfc->client->OnResizeWindow, xfc->instance, xfc->originalWidth * xfc->scale, xfc->originalHeight * xfc->scale);
e.width = (int) xfc->originalWidth * xfc->scale;
e.height = (int) xfc->originalHeight * xfc->scale;
PubSub_OnEvent(xfc->pubSub, "ResizeWindow", xfc, (wEventArgs*) &e);
z_vector = 0;
}

View File

@ -26,6 +26,39 @@
#include <freerdp/client/file.h>
#include <freerdp/client/cmdline.h>
static wEvent Client_Events[] =
{
DEFINE_EVENT_ENTRY(WindowStateChange)
DEFINE_EVENT_ENTRY(ResizeWindow)
};
int freerdp_client_common_new(freerdp* instance, rdpContext* context)
{
rdpClientContext* clientContext;
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
clientContext = (rdpClientContext*) context;
pEntryPoints = instance->pClientEntryPoints;
clientContext->pubSub = PubSub_New(TRUE);
PubSub_Publish(clientContext->pubSub, Client_Events, sizeof(Client_Events) / sizeof(wEvent));
return pEntryPoints->ClientNew(instance, context);
}
void freerdp_client_common_free(freerdp* instance, rdpContext* context)
{
rdpClientContext* clientContext;
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
clientContext = (rdpClientContext*) context;
pEntryPoints = instance->pClientEntryPoints;
PubSub_Free(clientContext->pubSub);
pEntryPoints->ClientFree(instance, context);
}
/* Common API */
rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
@ -37,8 +70,10 @@ rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
instance = freerdp_new();
instance->ContextSize = pEntryPoints->ContextSize;
instance->ContextNew = pEntryPoints->ClientNew;
instance->ContextFree = pEntryPoints->ClientFree;
instance->ContextNew = freerdp_client_common_new;
instance->ContextFree = freerdp_client_common_free;
instance->pClientEntryPoints = (RDP_CLIENT_ENTRY_POINTS*) malloc(pEntryPoints->Size);
CopyMemory(instance->pClientEntryPoints, pEntryPoints, pEntryPoints->Size);
freerdp_context_new(instance);
context = instance->context;

View File

@ -55,11 +55,9 @@ struct rdp_client_entry_points_v1
pRdpClientStart ClientStart;
pRdpClientStop ClientStop;
};
typedef struct rdp_client_entry_points_v1 RDP_CLIENT_ENTRY_POINTS_V1;
#define RDP_CLIENT_INTERFACE_VERSION 1
#define RDP_CLIENT_ENTRY_POINT_NAME "RdpClientEntry"
typedef RDP_CLIENT_ENTRY_POINTS_V1 RDP_CLIENT_ENTRY_POINTS;
typedef int (*pRdpClientEntry)(RDP_CLIENT_ENTRY_POINTS* pEntryPoints);
@ -71,23 +69,29 @@ typedef int (*pRdpClientEntry)(RDP_CLIENT_ENTRY_POINTS* pEntryPoints);
#define FREERDP_WINDOW_STATE_FULLSCREEN 3
#define FREERDP_WINDOW_STATE_ACTIVE 4
typedef void (*pOnResizeWindow)(freerdp* instance, int width, int height);
typedef void (*pOnWindowStateChange)(freerdp* instance, int state);
typedef void (*pOnErrorInfo)(freerdp* instance, UINT32 code);
typedef void (*pOnParamChange)(freerdp* instance, int id);
DEFINE_EVENT_BEGIN(ResizeWindow)
int width;
int height;
DEFINE_EVENT_END(ResizeWindow)
DEFINE_EVENT_BEGIN(WindowStateChange)
int state;
DEFINE_EVENT_END(WindowStateChange)
struct rdp_client
{
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
pOnResizeWindow OnResizeWindow;
pOnWindowStateChange OnWindowStateChange;
pOnErrorInfo OnErrorInfo;
pOnParamChange OnParamChange;
};
#define DEFINE_RDP_CLIENT_COMMON() \
HANDLE thread
HANDLE thread; \
wPubSub* pubSub
struct rdp_client_context
{

View File

@ -31,7 +31,10 @@ typedef struct rdp_client rdpClient;
typedef struct rdp_freerdp freerdp;
typedef struct rdp_context rdpContext;
typedef struct rdp_freerdp_peer freerdp_peer;
typedef struct rdp_client_context rdpClientContext;
typedef struct rdp_client_entry_points_v1 RDP_CLIENT_ENTRY_POINTS_V1;
typedef RDP_CLIENT_ENTRY_POINTS_V1 RDP_CLIENT_ENTRY_POINTS;
#include <freerdp/api.h>
#include <freerdp/types.h>
@ -135,7 +138,9 @@ struct rdp_freerdp
Can be allocated by a call to freerdp_context_new().
Must be deallocated by a call to freerdp_context_free() before deallocating the current instance. */
UINT64 paddingA[16 - 1]; /* 1 */
RDP_CLIENT_ENTRY_POINTS* pClientEntryPoints;
UINT64 paddingA[16 - 2]; /* 2 */
ALIGN64 rdpInput* input; /* (offset 16)
Input handle for the connection.

View File

@ -369,7 +369,7 @@ typedef struct _wEvent wEvent;
DEFINE_EVENT_HANDLER(_name);
#define DEFINE_EVENT_ENTRY(_name) \
{ #_name, NULL, { sizeof(MouseMotionEventArgs) } },
{ #_name, NULL, { sizeof( _name ## EventArgs) } },
struct _wPubSub
{