这是楼主的第一个Wayland程序:
效果图:
程序源代码:
//wayland-hello.h
/*
Copyright (c) 第三界主 2014
代码使用MIT协议发布
*/
#ifndef WAYLAND_HELLO_H
#define WAYLAND_HELLO_H
#include
#include
#include
#include
#include
#include
#include
#include
/* 某些struct wl_开头的对象实际上是wl_proxy对象的id,与windows下的Handle类似。 */
typedef struct wl_display* HDISPLAY;
typedef struct wl_registry* HREGISTRY;
typedef struct wl_compositor* HCOMPOSITOR;
typedef struct wl_shell* HSHELL;
typedef struct wl_shm* HSHM;
typedef struct wl_shm_pool* HSHMPOOL;
typedef struct wl_seat* HSEAT;
typedef struct wl_pointer* HPOINTER;
typedef struct wl_surface* HSURFACE;
typedef struct wl_shell_surface * HSHELLSURFACE;
typedef struct wl_callback* HCALLBACK;
typedef struct wl_buffer* HBUFFER;
typedef struct wl_keyboard* HKEYBOARD;
typedef void* LPVOID;
typedef struct _WAYLANDREGISTRY
{
/* 所有API都需要wl_display */
HDISPLAY s_display;
/* 合成器 */
HCOMPOSITOR s_compositor;
/* shell提供接口,与窗口操作有关 */
HSHELL s_shell;
/* 缓存管理器,与绘制相关 */
HSHM s_shm;
uint32_t shm_formats;
/* 输入设备管理器,管理键盘鼠标 */
HSEAT s_seat;
/* 鼠标控制器 */
HPOINTER s_pointer;
/* 键盘控制器 */
HKEYBOARD s_keyboard;
/* 鼠标当前窗口 */
HSURFACE s_pointer_surface;
/* 键盘当前窗口 */
HSURFACE s_kb_surface;
} WAYLANDREGISTRY, *LPWAYLANDREGISTRY;
/* wayland的全局对象都放在registry中 */
LPWAYLANDREGISTRY wlGetRegistry();
typedef struct _PAINTBUFFER
{
HBUFFER buffer;
void *data;
int busy;
}PAINTBUFFER, *LPPAINTBUFFER;
typedef struct _PAINTSTRUCTURE
{
LPPAINTBUFFER buffer;
} PAINTSTRUCTURE, *LPPAINTSTRUCTURE;
typedef void(*REPAINTPROC)(HSURFACE hSurface, LPPAINTSTRUCTURE lpPaint, uint32_t time);
typedef struct _SURFACEPRIVATE
{
struct wl_surface *surface;
struct wl_shell_surface *shell_surface;
int width, height;
REPAINTPROC surfaceproc;
PAINTBUFFER buffer[2];
} SURFACEPRIVATE, *LPSURFACEPRIVATE;
typedef struct _SIZE
{
int width, height;
} SIZE;
typedef int POINTERPROC;
typedef int KEYBOARDPROC;
static inline HDISPLAY wlGetDisplay()
{
return wlGetRegistry()->s_display;
}
static inline HCOMPOSITOR wlGetCompositor()
{
return wlGetRegistry()->s_compositor;
}
static inline HSHELL wlGetShell()
{
return wlGetRegistry()->s_shell;
}
static inline HPOINTER wlGetPointer()
{
return wlGetRegistry()->s_pointer;
}
static inline HKEYBOARD wlGetKeyboard()
{
return wlGetRegistry()->s_keyboard;
}
LPSURFACEPRIVATE _wlGetSurfacePrivate(HSURFACE surface);
void _wlCreatePaintStructure(int width, int height, LPPAINTBUFFER lpBuffer);
void _wlSetFrameListener(HSURFACE surface);
void _wlDrawFrame(HSURFACE surface, uint32_t time);
void wlBeginPaint(HSURFACE surface, LPPAINTSTRUCTURE lpPaint);
void wlEndPaint(HSURFACE surface, LPPAINTSTRUCTURE lpPaint);
int wlInit();
void wlTerminate();
HSURFACE wlCreateSurface(const char* title, int width, int height);
void wlSetPaintProc(HSURFACE surf

本文分享了作者的首个Wayland程序实现过程,包括程序的截图和源代码,为Linux环境下Wayland开发提供了入门示例。
最低0.47元/天 解锁文章
1405





