~sircmpwn/scurvy

44cef8cc170a13a70d53b6b4966c2012ec9c5224 — Drew DeVault 4 years ago
Initial commit

Pulls in some code from sway, aerc, and chopsui
A  => .gitignore +13 -0
@@ 1,13 @@
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt
*.swp
*.o
*.a
bin/
test/
build/
.lvimrc
wayland-*-protocol.*

A  => CMake/FindA2X.cmake +75 -0
@@ 1,75 @@
#
# (c)2015 KiCad Developers
# (c)2015 Brian Sidebotham <brian.sidebotham@gmail.com>
#
# CMake module to find a2x (part of the asciidoc toolchain).
#
# Variables generated:
#
# A2X_FOUND     true when A2X_COMMAND is valid
# A2X_COMMAND   The command to run a2x (may be a list including an interpreter)
# A2X_VERSION   The a2x version that has been found
#

# Have a go at finding a a2x executable
find_program( A2X_PROGRAM a2x )

# Found something, attempt to try and use it...
if( A2X_PROGRAM )
    execute_process(
        COMMAND ${A2X_PROGRAM} --version
        OUTPUT_VARIABLE _OUT
        ERROR_VARIABLE _ERR
        RESULT_VARIABLE _RES
        OUTPUT_STRIP_TRAILING_WHITESPACE )

    # If it worked, set the A2X_COMMAND
    if( _RES MATCHES 0 )
        set( A2X_COMMAND "${A2X_PROGRAM}" )
    endif()
endif()

# If nothing could be found, test to see if we can just find the script file,
# that we'll then run with the python interpreter
if( NOT A2X_COMMAND )
    find_file( A2X_SCRIPT a2x.py )

    if( A2X_SCRIPT )
        # Find the python interpreter quietly
        if( NOT PYTHONINTERP_FOUND )
            find_package( PYTHONINTERP QUIET )
        endif()

        if( NOT PYTHONINTERP_FOUND )
            # Python's not available so can't find a2x...
            set( A2X_COMMAND "" )
        else()
            # Build the python based command
            set( A2X_COMMAND "${PYTHON_EXECUTABLE}" "${A2X_SCRIPT}" )

            execute_process(
                COMMAND ${A2X_COMMAND} --version
                OUTPUT_VARIABLE _OUT
                ERROR_VARIABLE _ERR
                RESULT_VARIABLE _RES
                OUTPUT_STRIP_TRAILING_WHITESPACE )

            # If it still can't be run, then give up
            if( NOT _RES MATCHES 0 )
                set( A2X_COMMAND "" )
            endif()
        endif()
    endif()
endif()

# If we've found a command that works, check the version
if( A2X_COMMAND )
    string(REGEX REPLACE ".*a2x[^0-9.]*\([0-9.]+\).*" "\\1" A2X_VERSION "${_OUT}")
endif()

# Generate the *_FOUND as necessary, etc.
include( FindPackageHandleStandardArgs )
find_package_handle_standard_args(
    A2X
    REQUIRED_VARS A2X_COMMAND
    VERSION_VAR A2X_VERSION )

A  => CMake/FindCairo.cmake +42 -0
@@ 1,42 @@
# - Try to find the cairo library
# Once done this will define
#
#  CAIRO_FOUND - system has cairo
#  CAIRO_INCLUDE_DIRS - the cairo include directory
#  CAIRO_LIBRARIES - Link these to use cairo
#
# Define CAIRO_MIN_VERSION for which version desired.
#

find_package(PkgConfig)

if(Cairo_FIND_REQUIRED)
	set(_pkgconfig_REQUIRED "REQUIRED")
else(Cairo_FIND_REQUIRED)
	set(_pkgconfig_REQUIRED "")
endif(Cairo_FIND_REQUIRED)

if(CAIRO_MIN_VERSION)
	pkg_check_modules(CAIRO ${_pkgconfig_REQUIRED} cairo>=${CAIRO_MIN_VERSION})
else(CAIRO_MIN_VERSION)
	pkg_check_modules(CAIRO ${_pkgconfig_REQUIRED} cairo)
endif(CAIRO_MIN_VERSION)

if(NOT CAIRO_FOUND AND NOT PKG_CONFIG_FOUND)
	find_path(CAIRO_INCLUDE_DIRS cairo.h)
	find_library(CAIRO_LIBRARIES cairo)
else(NOT CAIRO_FOUND AND NOT PKG_CONFIG_FOUND)
	# Make paths absolute https://stackoverflow.com/a/35476270
	# Important on FreeBSD because /usr/local/lib is not on /usr/bin/ld's default path
	set(CAIRO_LIBS_ABSOLUTE)
	foreach(lib ${CAIRO_LIBRARIES})
		set(var_name CAIRO_${lib}_ABS)
		find_library(${var_name} ${lib} ${CAIRO_LIBRARY_DIRS})
		list(APPEND CAIRO_LIBS_ABSOLUTE ${${var_name}})
	endforeach()
	set(CAIRO_LIBRARIES ${CAIRO_LIBS_ABSOLUTE})
endif(NOT CAIRO_FOUND AND NOT PKG_CONFIG_FOUND)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CAIRO DEFAULT_MSG CAIRO_LIBRARIES CAIRO_INCLUDE_DIRS)
mark_as_advanced(CAIRO_LIBRARIES CAIRO_INCLUDE_DIRS)

A  => CMake/FindLibvterm.cmake +26 -0
@@ 1,26 @@
# Try to find libvterm
# Once done this will define
#
#  LIBVTERM_FOUND - system has libvterm
#  LIBVTERM_LIBRARIES - Link these to use libvterm

if(LIBVTERM_LIBRARIES)
    set (LIBVTERM_FIND_QUIETLY TRUE)
endif()

FIND_PATH(LIBVTERM_INCLUDE_DIRS vterm.h)
FIND_LIBRARY(LIBVTERM_LIBRARIES NAMES vterm)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBVTERM DEFAULT_MSG LIBVTERM_LIBRARIES LIBVTERM_INCLUDE_DIRS)

if (LIBVTERM_FOUND)
    message (STATUS "Found components for libvterm")
    message (STATUS "LIBVTERM_LIBRARIES = ${LIBVTERM_LIBRARIES}")
else (LIBVTERM_FOUND)
    if (LIBVTERM_FIND_REQUIRED)
        message (FATAL_ERROR "Could not find libvterm!")
    endif (LIBVTERM_FIND_REQUIRED)
endif (LIBVTERM_FOUND)

MARK_AS_ADVANCED(LIBVTERM_LIBRARIES LIBVTERM_INCLUDE_DIRS)

A  => CMake/FindPango.cmake +42 -0
@@ 1,42 @@
# - Try to find the pango library
# Once done this will define
#
#  PANGO_FOUND - system has pango
#  PANGO_INCLUDE_DIRS - the pango include directory
#  PANGO_LIBRARIES - Link these to use pango
#
# Define PANGO_MIN_VERSION for which version desired.
#

find_package(PkgConfig)

if(Pango_FIND_REQUIRED)
	set(_pkgconfig_REQUIRED "REQUIRED")
else(Pango_FIND_REQUIRED)
	set(_pkgconfig_REQUIRED "")
endif(Pango_FIND_REQUIRED)

if(PANGO_MIN_VERSION)
	pkg_check_modules(PANGO ${_pkgconfig_REQUIRED} "pango>=${PANGO_MIN_VERSION}" "pangocairo>=${PANGO_MIN_VERSION}")
else(PANGO_MIN_VERSION)
	pkg_check_modules(PANGO ${_pkgconfig_REQUIRED} pango pangocairo)
endif(PANGO_MIN_VERSION)

if(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND)
	find_path(PANGO_INCLUDE_DIRS pango.h)
	find_library(PANGO_LIBRARIES pango pangocairo)
else(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND)
	# Make paths absolute https://stackoverflow.com/a/35476270
	# Important on FreeBSD because /usr/local/lib is not on /usr/bin/ld's default path
	set(PANGO_LIBS_ABSOLUTE)
	foreach(lib ${PANGO_LIBRARIES})
		set(var_name PANGO_${lib}_ABS)
		find_library(${var_name} ${lib} ${PANGO_LIBRARY_DIRS})
		list(APPEND PANGO_LIBS_ABSOLUTE ${${var_name}})
	endforeach()
	set(PANGO_LIBRARIES ${PANGO_LIBS_ABSOLUTE})
endif(NOT PANGO_FOUND AND NOT PKG_CONFIG_FOUND)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PANGO DEFAULT_MSG PANGO_LIBRARIES PANGO_INCLUDE_DIRS)
mark_as_advanced(PANGO_LIBRARIES PANGO_INCLUDE_DIRS)

A  => CMake/FindWayland.cmake +67 -0
@@ 1,67 @@
# Try to find Wayland on a Unix system
#
# This will define:
#
#   WAYLAND_FOUND       - True if Wayland is found
#   WAYLAND_LIBRARIES   - Link these to use Wayland
#   WAYLAND_INCLUDE_DIR - Include directory for Wayland
#   WAYLAND_DEFINITIONS - Compiler flags for using Wayland
#
# In addition the following more fine grained variables will be defined:
#
#   WAYLAND_CLIENT_FOUND  WAYLAND_CLIENT_INCLUDE_DIR  WAYLAND_CLIENT_LIBRARIES
#   WAYLAND_SERVER_FOUND  WAYLAND_SERVER_INCLUDE_DIR  WAYLAND_SERVER_LIBRARIES
#   WAYLAND_EGL_FOUND     WAYLAND_EGL_INCLUDE_DIR     WAYLAND_EGL_LIBRARIES
#   WAYLAND_CURSOR_FOUND  WAYLAND_CURSOR_INCLUDE_DIR  WAYLAND_CURSOR_LIBRARIES
#
# Copyright (c) 2013 Martin Gräßlin <mgraesslin@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

IF (NOT WIN32)
  IF (WAYLAND_INCLUDE_DIR AND WAYLAND_LIBRARIES)
    # In the cache already
    SET(WAYLAND_FIND_QUIETLY TRUE)
  ENDIF ()

  # Use pkg-config to get the directories and then use these values
  # in the FIND_PATH() and FIND_LIBRARY() calls
  FIND_PACKAGE(PkgConfig)
  PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor)

  SET(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS})

  FIND_PATH(WAYLAND_CLIENT_INCLUDE_DIR  NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
  FIND_PATH(WAYLAND_SERVER_INCLUDE_DIR  NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
  FIND_PATH(WAYLAND_EGL_INCLUDE_DIR     NAMES wayland-egl.h    HINTS ${PKG_WAYLAND_INCLUDE_DIRS})
  FIND_PATH(WAYLAND_CURSOR_INCLUDE_DIR  NAMES wayland-cursor.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS})

  FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
  FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
  FIND_LIBRARY(WAYLAND_EGL_LIBRARIES    NAMES wayland-egl      HINTS ${PKG_WAYLAND_LIBRARY_DIRS})
  FIND_LIBRARY(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor   HINTS ${PKG_WAYLAND_LIBRARY_DIRS})

  set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR})

  set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES})

  list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIR)

  include(FindPackageHandleStandardArgs)

  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CLIENT  DEFAULT_MSG  WAYLAND_CLIENT_LIBRARIES  WAYLAND_CLIENT_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_SERVER  DEFAULT_MSG  WAYLAND_SERVER_LIBRARIES  WAYLAND_SERVER_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_EGL     DEFAULT_MSG  WAYLAND_EGL_LIBRARIES     WAYLAND_EGL_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CURSOR  DEFAULT_MSG  WAYLAND_CURSOR_LIBRARIES  WAYLAND_CURSOR_INCLUDE_DIR)
  FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND         DEFAULT_MSG  WAYLAND_LIBRARIES         WAYLAND_INCLUDE_DIR)

  MARK_AS_ADVANCED(
        WAYLAND_INCLUDE_DIR         WAYLAND_LIBRARIES
        WAYLAND_CLIENT_INCLUDE_DIR  WAYLAND_CLIENT_LIBRARIES
        WAYLAND_SERVER_INCLUDE_DIR  WAYLAND_SERVER_LIBRARIES
        WAYLAND_EGL_INCLUDE_DIR     WAYLAND_EGL_LIBRARIES
        WAYLAND_CURSOR_INCLUDE_DIR  WAYLAND_CURSOR_LIBRARIES
  )

ENDIF ()

A  => CMake/FindXKBCommon.cmake +19 -0
@@ 1,19 @@
# - Find XKBCommon
# Once done, this will define
#
#   XKBCOMMON_FOUND - System has XKBCommon
#   XKBCOMMON_INCLUDE_DIRS - The XKBCommon include directories
#   XKBCOMMON_LIBRARIES - The libraries needed to use XKBCommon
#   XKBCOMMON_DEFINITIONS - Compiler switches required for using XKBCommon

find_package(PkgConfig)
pkg_check_modules(PC_XKBCOMMON QUIET xkbcommon)
find_path(XKBCOMMON_INCLUDE_DIRS NAMES xkbcommon/xkbcommon.h HINTS ${PC_XKBCOMMON_INCLUDE_DIRS})
find_library(XKBCOMMON_LIBRARIES NAMES xkbcommon HINTS ${PC_XKBCOMMON_LIBRARY_DIRS})

set(XKBCOMMON_DEFINITIONS ${PC_XKBCOMMON_CFLAGS_OTHER})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(XKBCOMMON DEFAULT_MSG XKBCOMMON_LIBRARIES XKBCOMMON_INCLUDE_DIRS)
mark_as_advanced(XKBCOMMON_LIBRARIES XKBCOMMON_INCLUDE_DIRS)


A  => CMake/Wayland.cmake +77 -0
@@ 1,77 @@
#=============================================================================
# Copyright (C) 2012-2013 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
#   notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
#
# * Neither the name of Pier Luigi Fiorini nor the names of his
#   contributors may be used to endorse or promote products derived
#   from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================

find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner)

# wayland_add_protocol_client(outfiles inputfile basename)
function(WAYLAND_ADD_PROTOCOL_CLIENT _sources _protocol _basename)
    if(NOT WAYLAND_SCANNER_EXECUTABLE)
        message(FATAL "The wayland-scanner executable has not been found on your system. You must install it.")
    endif()

    get_filename_component(_infile ${_protocol} ABSOLUTE)
    set(_client_header "${CMAKE_CURRENT_BINARY_DIR}/wayland-${_basename}-client-protocol.h")
    set(_code "${CMAKE_CURRENT_BINARY_DIR}/wayland-${_basename}-client-protocol.c")

    add_custom_command(OUTPUT "${_client_header}"
        COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header < ${_infile} > ${_client_header}
        DEPENDS ${_infile} VERBATIM)

    add_custom_command(OUTPUT "${_code}"
        COMMAND ${WAYLAND_SCANNER_EXECUTABLE} code < ${_infile} > ${_code}
        DEPENDS ${_infile} VERBATIM)

    list(APPEND ${_sources} "${_client_header}" "${_code}")
    set(${_sources} ${${_sources}} PARENT_SCOPE)
endfunction()

# wayland_add_protocol_server(outfiles inputfile basename)
function(WAYLAND_ADD_PROTOCOL_SERVER _sources _protocol _basename)
    if(NOT WAYLAND_SCANNER_EXECUTABLE)
        message(FATAL "The wayland-scanner executable has not been found on your system. You must install it.")
    endif()

    get_filename_component(_infile ${_protocol} ABSOLUTE)
    set(_server_header "${CMAKE_CURRENT_BINARY_DIR}/wayland-${_basename}-server-protocol.h")
    set(_code "${CMAKE_CURRENT_BINARY_DIR}/wayland-${_basename}-server-protocol.c")

    add_custom_command(OUTPUT "${_server_header}"
        COMMAND ${WAYLAND_SCANNER_EXECUTABLE} server-header < ${_infile} > ${_server_header}
        DEPENDS ${_infile} VERBATIM)

    add_custom_command(OUTPUT "${_code}"
        COMMAND ${WAYLAND_SCANNER_EXECUTABLE} code < ${_infile} > ${_code}
        DEPENDS ${_infile} VERBATIM)

    list(APPEND ${_sources} "${_server_header}" "${_code}")
    set(${_sources} ${${_sources}} PARENT_SCOPE)
endfunction()

A  => CMakeLists.txt +37 -0
@@ 1,37 @@
cmake_minimum_required(VERSION 3.1.0)

project(scurvy C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
if (CMAKE_COMPILER_IS_GNUCC)
    if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 7.0)
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wimplicit-fallthrough=0")
    endif()
endif()

list(INSERT CMAKE_MODULE_PATH 0
	${CMAKE_CURRENT_SOURCE_DIR}/CMake
)

find_package(Cairo REQUIRED)
find_package(Pango REQUIRED)

add_subdirectory(src/wayland)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)

add_executable(scurvy
    src/main.c
    src/ini.c
    src/colors.c
)

target_link_libraries(scurvy
    scurvy-wayland
)

A  => LICENSE +19 -0
@@ 1,19 @@
Copyright (c) 2017 Drew DeVault

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

A  => include/colors.h +8 -0
@@ 1,8 @@
#ifndef _SCURVY_COLORS_H
#define _SCURVY_COLORS_H

#include <stdint.h>

bool color_parse(const char *str, uint32_t *val);

#endif

A  => include/ini.h +93 -0
@@ 1,93 @@
/* inih -- simple .INI file parser

inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info:

https://github.com/benhoyt/inih

*/

#ifndef __INI_H__
#define __INI_H__

/* Make this header file easier to include in C++ code */
#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>

/* Typedef for prototype of handler function. */
typedef int (*ini_handler)(void* user, const char* section,
                           const char* name, const char* value);

/* Typedef for prototype of fgets-style reader function. */
typedef char* (*ini_reader)(char* str, int num, void* stream);

/* Parse given INI-style file. May have [section]s, name=value pairs
   (whitespace stripped), and comments starting with ';' (semicolon). Section
   is "" if name=value pair parsed before any section heading. name:value
   pairs are also supported as a concession to Python's configparser.

   For each name=value pair parsed, call handler function with given user
   pointer as well as section, name, and value (data only valid for duration
   of handler call). Handler should return nonzero on success, zero on error.

   Returns 0 on success, line number of first error on parse error (doesn't
   stop on first error), -1 on file open error, or -2 on memory allocation
   error (only when INI_USE_STACK is zero).
*/
int ini_parse(const char* filename, ini_handler handler, void* user);

/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
   close the file when it's finished -- the caller must do that. */
int ini_parse_file(FILE* file, ini_handler handler, void* user);

/* Same as ini_parse(), but takes an ini_reader function pointer instead of
   filename. Used for implementing custom or string-based I/O. */
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
                     void* user);

/* Nonzero to allow multi-line value parsing, in the style of Python's
   configparser. If allowed, ini_parse() will call the handler with the same
   name for each subsequent line parsed. */
#ifndef INI_ALLOW_MULTILINE
#define INI_ALLOW_MULTILINE 1
#endif

/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
   the file. See http://code.google.com/p/inih/issues/detail?id=21 */
#ifndef INI_ALLOW_BOM
#define INI_ALLOW_BOM 1
#endif

/* Nonzero to allow inline comments (with valid inline comment characters
   specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
   Python 3.2+ configparser behaviour. */
#ifndef INI_ALLOW_INLINE_COMMENTS
#define INI_ALLOW_INLINE_COMMENTS 1
#endif
#ifndef INI_INLINE_COMMENT_PREFIXES
#define INI_INLINE_COMMENT_PREFIXES ";"
#endif

/* Nonzero to use stack, zero to use heap (malloc/free). */
#ifndef INI_USE_STACK
#define INI_USE_STACK 1
#endif

/* Stop parsing on first error (default is to keep parsing). */
#ifndef INI_STOP_ON_FIRST_ERROR
#define INI_STOP_ON_FIRST_ERROR 0
#endif

/* Maximum line length for any line in INI file. */
#ifndef INI_MAX_LINE
#define INI_MAX_LINE 2000
#endif

#ifdef __cplusplus
}
#endif

#endif /* __INI_H__ */

A  => include/wayland/buffer.h +7 -0
@@ 1,7 @@
#ifndef _BUFFER_H
#define _BUFFER_H
#include "wayland/window.h"

struct buffer *get_next_buffer(struct window *state);

#endif

A  => include/wayland/registry.h +63 -0
@@ 1,63 @@
#ifndef _SWAY_CLIENT_REGISTRY_H
#define _SWAY_CLIENT_REGISTRY_H

#include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>

enum mod_bit {
	MOD_SHIFT = 1<<0,
	MOD_CAPS = 1<<1,
	MOD_CTRL = 1<<2,
	MOD_ALT = 1<<3,
	MOD_MOD2 = 1<<4,
	MOD_MOD3 = 1<<5,
	MOD_LOGO = 1<<6,
	MOD_MOD5 = 1<<7,
};

enum mask {
	MASK_SHIFT,
	MASK_CAPS,
	MASK_CTRL,
	MASK_ALT,
	MASK_MOD2,
	MASK_MOD3,
	MASK_LOGO,
	MASK_MOD5,
	MASK_LAST
};

struct xkb {
	struct xkb_state *state;
	struct xkb_context *context;
	struct xkb_keymap *keymap;
	xkb_mod_mask_t masks[MASK_LAST];
};

struct input {
	struct xkb xkb;

	xkb_keysym_t sym;
	uint32_t code;
	uint32_t last_code;
	uint32_t modifiers;

	void (*notify)(enum wl_keyboard_key_state state, xkb_keysym_t sym,
			uint32_t code, uint32_t codepoint);
};

struct registry {
	struct wl_compositor *compositor;
	struct wl_display *display;
	struct wl_pointer *pointer;
	struct wl_keyboard *keyboard;
	struct wl_seat *seat;
	struct wl_shell *shell;
	struct wl_shm *shm;
	struct input *input;
};

struct registry *registry_poll(void);
void registry_teardown(struct registry *registry);

#endif

A  => include/wayland/window.h +68 -0
@@ 1,68 @@
#ifndef _CLIENT_H
#define _CLIENT_H

#include <wayland-client.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <stdbool.h>
#include "wayland/registry.h"

struct window;

struct buffer {
	struct wl_buffer *buffer;
	cairo_surface_t *surface;
	cairo_t *cairo;
	PangoContext *pango;
	uint32_t width, height;
	bool busy;
};

struct cursor {
	struct wl_surface *surface;
	struct wl_cursor_theme *cursor_theme;
	struct wl_cursor *cursor;
	struct wl_pointer *pointer;
};

enum scroll_direction {
	SCROLL_UP,
	SCROLL_DOWN,
	SCROLL_LEFT,
	SCROLL_RIGHT,
};

struct pointer_input {
	int last_x;
	int last_y;

	void (*notify_button)(struct window *window, int x, int y,
			uint32_t button, uint32_t state_w);
	void (*notify_scroll)(struct window *window,
			enum scroll_direction direction);
};

struct window {
	struct registry *registry;
	struct buffer buffers[2];
	struct buffer *buffer;
	struct wl_surface *surface;
	struct wl_shell_surface *shell_surface;
	struct wl_callback *frame_cb;
	struct cursor cursor;
	uint32_t width, height;
	int32_t scale;
	char *font;
	cairo_t *cairo;
	struct pointer_input pointer_input;
	void (*notify_resize)(struct window *window);
};

struct window *window_setup(struct registry *registry,
		uint32_t width, uint32_t height, int32_t scale, bool shell_surface);
void window_teardown(struct window *state);
int window_prerender(struct window *state);
int window_render(struct window *state);
void window_make_shell(struct window *window);

#endif

A  => scurvy.conf +27 -0
@@ 1,27 @@
# Scurvy configuration
[scurvy]
#
# Pango font name, supports fallback fonts
font=monospace 10
#
# Executed when you click on a link
url=xdg-open
#
# Override $TERM environment variable
term=xterm

[colors]
#
# Configure colors using CSS specifications
# Supports color names, #HEXHEX, or #HEXHEXAA for alpha
# TODO: rgb, hsl, rgba, hsla
foreground="white"
background="black"
color0="black"
color1="red"
color2="green"
color3="yellow"
color4="blue"
color5="darkmagenta"
color6="cyan"
color7="white"

A  => src/colors.c +207 -0
@@ 1,207 @@
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

struct named_color {
	const char *name;
	uint32_t color;
};

struct named_color colors[] = {
	{ "aqua", 0x00FFFF },
	{ "blue", 0x0000FF },
	{ "aliceblue", 0xF0F8FF },
	{ "antiquewhite", 0xFAEBD7 },
	{ "aquamarine", 0x7FFFD4 },
	{ "azure", 0xF0FFFF },
	{ "beige", 0xF5F5DC },
	{ "bisque", 0xFFE4C4 },
	{ "black", 0x000000 },
	{ "blanchedalmond", 0xFFEBCD },
	{ "blueviolet", 0x8A2BE2 },
	{ "brown", 0xA52A2A },
	{ "burlywood", 0xDEB887 },
	{ "cadetblue", 0x5F9EA0 },
	{ "chartreuse", 0x7FFF00 },
	{ "chocolate", 0xD2691E },
	{ "coral", 0xFF7F50 },
	{ "cornflowerblue", 0x6495ED },
	{ "cornsilk", 0xFFF8DC },
	{ "crimson", 0xDC143C },
	{ "darkblue", 0x00008B },
	{ "darkcyan", 0x008B8B },
	{ "darkgoldenrod", 0xB8860B },
	{ "darkgray", 0xA9A9A9 },
	{ "darkgreen", 0x006400 },
	{ "darkgrey", 0xA9A9A9 },
	{ "darkkhaki", 0xBDB76B },
	{ "darkmagenta", 0x8B008B },
	{ "darkolivegreen", 0x556B2F },
	{ "darkorange", 0xFF8C00 },
	{ "darkorchid", 0x9932CC },
	{ "darkred", 0x8B0000 },
	{ "darksalmon", 0xE9967A },
	{ "darkseagreen", 0x8FBC8F },
	{ "darkslateblue", 0x483D8B },
	{ "darkslategray", 0x2F4F4F },
	{ "darkslategrey", 0x2F4F4F },
	{ "darkturquoise", 0x00CED1 },
	{ "darkviolet", 0x9400D3 },
	{ "deeppink", 0xFF1493 },
	{ "deepskyblue", 0x00BFFF },
	{ "dimgray", 0x696969 },
	{ "dimgrey", 0x696969 },
	{ "dodgerblue", 0x1E90FF },
	{ "firebrick", 0xB22222 },
	{ "floralwhite", 0xFFFAF0 },
	{ "forestgreen", 0x228B22 },
	{ "fuchsia", 0xFF00FF },
	{ "gainsboro", 0xDCDCDC },
	{ "ghostwhite", 0xF8F8FF },
	{ "gold", 0xFFD700 },
	{ "goldenrod", 0xDAA520 },
	{ "greenyellow", 0xADFF2F },
	{ "gray", 0x808080 },
	{ "grey", 0x808080 },
	{ "green", 0x008000 },
	{ "honeydew", 0xF0FFF0 },
	{ "hotpink", 0xFF69B4 },
	{ "indianred", 0xCD5C5C },
	{ "indigo", 0x4B0082 },
	{ "ivory", 0xFFFFF0 },
	{ "khaki", 0xF0E68C },
	{ "lavender", 0xE6E6FA },
	{ "lavenderblush", 0xFFF0F5 },
	{ "lawngreen", 0x7CFC00 },
	{ "lemonchiffon", 0xFFFACD },
	{ "lightblue", 0xADD8E6 },
	{ "lightcoral", 0xF08080 },
	{ "lightcyan", 0xE0FFFF },
	{ "lightgoldenrodyellow", 0xFAFAD2 },
	{ "lightgray", 0xD3D3D3 },
	{ "lightgreen", 0x90EE90 },
	{ "lightgrey", 0xD3D3D3 },
	{ "lightpink", 0xFFB6C1 },
	{ "lightsalmon", 0xFFA07A },
	{ "lightseagreen", 0x20B2AA },
	{ "lightskyblue", 0x87CEFA },
	{ "lightslategray", 0x778899 },
	{ "lightslategrey", 0x778899 },
	{ "lightsteelblue", 0xB0C4DE },
	{ "lightyellow", 0xFFFFE0 },
	{ "lime", 0x00FF00 },
	{ "limegreen", 0x32CD32 },
	{ "linen", 0xFAF0E6 },
	{ "maroon", 0x800000 },
	{ "mediumaquamarine", 0x66CDAA },
	{ "mediumblue", 0x0000CD },
	{ "mediumorchid", 0xBA55D3 },
	{ "mediumpurple", 0x9370DB },
	{ "mediumseagreen", 0x3CB371 },
	{ "mediumslateblue", 0x7B68EE },
	{ "mediumspringgreen", 0x00FA9A },
	{ "mediumturquoise", 0x48D1CC },
	{ "mediumvioletred", 0xC71585 },
	{ "midnightblue", 0x191970 },
	{ "mintcream", 0xF5FFFA },
	{ "mistyrose", 0xFFE4E1 },
	{ "moccasin", 0xFFE4B5 },
	{ "navajowhite", 0xFFDEAD },
	{ "navy", 0x000080 },
	{ "oldlace", 0xFDF5E6 },
	{ "olive", 0x808000 },
	{ "olivedrab", 0x6B8E23 },
	{ "orange", 0xFFA500 },
	{ "orangered", 0xFF4500 },
	{ "orchid", 0xDA70D6 },
	{ "palegoldenrod", 0xEEE8AA },
	{ "palegreen", 0x98FB98 },
	{ "paleturquoise", 0xAFEEEE },
	{ "palevioletred", 0xDB7093 },
	{ "papayawhip", 0xFFEFD5 },
	{ "peachpuff", 0xFFDAB9 },
	{ "peru", 0xCD853F },
	{ "pink", 0xFFC0CB },
	{ "plum", 0xDDA0DD },
	{ "powderblue", 0xB0E0E6 },
	{ "purple", 0x800080 },
	{ "rebeccapurple", 0x663399 },
	{ "red", 0xFF0000 },
	{ "rosybrown", 0xBC8F8F },
	{ "royalblue", 0x4169E1 },
	{ "saddlebrown", 0x8B4513 },
	{ "salmon", 0xFA8072 },
	{ "sandybrown", 0xF4A460 },
	{ "seagreen", 0x2E8B57 },
	{ "seashell", 0xFFF5EE },
	{ "sienna", 0xA0522D },
	{ "silver", 0xC0C0C0 },
	{ "skyblue", 0x87CEEB },
	{ "slateblue", 0x6A5ACD },
	{ "slategray", 0x708090 },
	{ "slategrey", 0x708090 },
	{ "snow", 0xFFFAFA },
	{ "springgreen", 0x00FF7F },
	{ "steelblue", 0x4682B4 },
	{ "tan", 0xD2B48C },
	{ "teal", 0x008080 },
	{ "thistle", 0xD8BFD8 },
	{ "tomato", 0xFF6347 },
	{ "turquoise", 0x40E0D0 },
	{ "violet", 0xEE82EE },
	{ "wheat", 0xF5DEB3 },
	{ "white", 0xFFFFFF },
	{ "whitesmoke", 0xF5F5F5 },
	{ "yellow", 0xFFFF00 },
	{ "yellowgreen", 0x9ACD32 },
};

static int color_cmp(const void *_a, const void *_b) {
	struct named_color const *a = _a;
	struct named_color const *b = _b;
	return strcmp(a->name, b->name);
}

static bool get_named_color(const char *name, uint32_t *color) {
	struct named_color key = { name, 0 };
	struct named_color *res = bsearch(&key,
		&colors, sizeof(colors) / sizeof(colors[0]),
		sizeof(colors[0]), color_cmp);
	if (!res) {
		return false;
	}
	*color = (res->color << 8) | 0xFF;
	return true;
}

static bool parse_hex_color(const char *str, uint32_t *val) {
	int len = strlen(str);
	if (len != 7 && len != 9) {
		return false;
	}
	char *end;
	*val = strtoul(str + 1, &end, 16);
	if (*end) {
		return false;
	}
	if (len == 7) {
		*val = (*val << 8) | 0xFF;
	}
	return true;
}

bool color_parse(const char *str, uint32_t *val) {
	if (strncmp(str, "rgba(", 5) == 0) {
		return false; // TODO
	} else if (strncmp(str, "rgb(", 4) == 0) {
		return false; // TODO
	} else if (strncmp(str, "hsla(", 5) == 0) {
		return false; // TODO
	} else if (strncmp(str, "hsl(", 4) == 0) {
		return false; // TODO
	} else if (*str == '#') {
		return parse_hex_color(str, val);
	}
	return get_named_color(str, val);
}

A  => src/ini.c +194 -0
@@ 1,194 @@
/* inih -- simple .INI file parser

inih is released under the New BSD license (see LICENSE.txt). Go to the project
home page for more info:

https://github.com/benhoyt/inih

*/

#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>
#include <ctype.h>
#include <string.h>

#include "ini.h"

#if !INI_USE_STACK
#include <stdlib.h>
#endif

#define MAX_SECTION 50
#define MAX_NAME 50

/* Strip whitespace chars off end of given string, in place. Return s. */
static char* rstrip(char* s)
{
    char* p = s + strlen(s);
    while (p > s && isspace((unsigned char)(*--p)))
        *p = '\0';
    return s;
}

/* Return pointer to first non-whitespace char in given string. */
static char* lskip(const char* s)
{
    while (*s && isspace((unsigned char)(*s)))
        s++;
    return (char*)s;
}

/* Return pointer to first char (of chars) or inline comment in given string,
   or pointer to null at end of string if neither found. Inline comment must
   be prefixed by a whitespace character to register as a comment. */
static char* find_chars_or_comment(const char* s, const char* chars)
{
#if INI_ALLOW_INLINE_COMMENTS
    int was_space = 0;
    while (*s && (!chars || !strchr(chars, *s)) &&
           !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) {
        was_space = isspace((unsigned char)(*s));
        s++;
    }
#else
    while (*s && (!chars || !strchr(chars, *s))) {
        s++;
    }
#endif
    return (char*)s;
}

/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
static char* strncpy0(char* dest, const char* src, size_t size)
{
    strncpy(dest, src, size);
    dest[size - 1] = '\0';
    return dest;
}

/* See documentation in header file. */
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
                     void* user)
{
    /* Uses a fair bit of stack (use heap instead if you need to) */
#if INI_USE_STACK
    char line[INI_MAX_LINE];
#else
    char* line;
#endif
    char section[MAX_SECTION] = "";
    char prev_name[MAX_NAME] = "";

    char* start;
    char* end;
    char* name;
    char* value;
    int lineno = 0;
    int error = 0;

#if !INI_USE_STACK
    line = (char*)malloc(INI_MAX_LINE);
    if (!line) {
        return -2;
    }
#endif

    /* Scan through stream line by line */
    while (reader(line, INI_MAX_LINE, stream) != NULL) {
        lineno++;

        start = line;
#if INI_ALLOW_BOM
        if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
                           (unsigned char)start[1] == 0xBB &&
                           (unsigned char)start[2] == 0xBF) {
            start += 3;
        }
#endif
        start = lskip(rstrip(start));

        if (*start == ';' || *start == '#') {
            /* Per Python configparser, allow both ; and # comments at the
               start of a line */
        }
#if INI_ALLOW_MULTILINE
        else if (*prev_name && *start && start > line) {
            /* Non-blank line with leading whitespace, treat as continuation
               of previous name's value (as per Python configparser). */
            if (!handler(user, section, prev_name, start) && !error)
                error = lineno;
        }
#endif
        else if (*start == '[') {
            /* A "[section]" line */
            end = find_chars_or_comment(start + 1, "]");
            if (*end == ']') {
                *end = '\0';
                strncpy0(section, start + 1, sizeof(section));
                *prev_name = '\0';
            }
            else if (!error) {
                /* No ']' found on section line */
                error = lineno;
            }
        }
        else if (*start) {
            /* Not a comment, must be a name[=:]value pair */
            end = find_chars_or_comment(start, "=:");
            if (*end == '=' || *end == ':') {
                *end = '\0';
                name = rstrip(start);
                value = lskip(end + 1);
#if INI_ALLOW_INLINE_COMMENTS
                end = find_chars_or_comment(value, NULL);
                if (*end)
                    *end = '\0';
#endif
                rstrip(value);

                /* Valid name[=:]value pair found, call handler */
                strncpy0(prev_name, name, sizeof(prev_name));
                if (!handler(user, section, name, value) && !error)
                    error = lineno;
            }
            else if (!error) {
                /* No '=' or ':' found on name[=:]value line */
                error = lineno;
            }
        }

#if INI_STOP_ON_FIRST_ERROR
        if (error)
            break;
#endif
    }

#if !INI_USE_STACK
    free(line);
#endif

    return error;
}

/* See documentation in header file. */
int ini_parse_file(FILE* file, ini_handler handler, void* user)
{
    return ini_parse_stream((ini_reader)fgets, file, handler, user);
}

/* See documentation in header file. */
int ini_parse(const char* filename, ini_handler handler, void* user)
{
    FILE* file;
    int error;

    file = fopen(filename, "r");
    if (!file)
        return -1;
    error = ini_parse_file(file, handler, user);
    fclose(file);
    return error;
}

A  => src/main.c +5 -0
@@ 1,5 @@
int wayland_main();

int main(int argc, char **argv) {
	return wayland_main();
}

A  => src/wayland/CMakeLists.txt +34 -0
@@ 1,34 @@
include(Wayland)
find_package(Wayland REQUIRED)
find_package(XKBCommon REQUIRED)

WAYLAND_ADD_PROTOCOL_CLIENT(proto-client-xdg-shell
	xdg-shell.xml
	xdg-shell
)

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/../../include
    ${CMAKE_BINARY_DIR}/wayland/
	${XKBCOMMON_INCLUDE_DIRS}
	${WAYLAND_INCLUDE_DIR}
    ${PANGO_INCLUDE_DIRS}
)

add_library(scurvy-wayland STATIC
	${proto-client-xdg-shell}
    main.c
    registry.c
    window.c
    buffers.c
)

target_link_libraries(scurvy-wayland
	${PANGO_LIBRARIES}
	${XKBCOMMON_LIBRARIES}
	${EPOLLSHIM_LIBRARIES}
	${WAYLAND_CLIENT_LIBRARIES}
	${WAYLAND_CURSOR_LIBRARIES}
	${CAIRO_LIBRARIES}
	${PANGO_LIBRARIES}
)

A  => src/wayland/buffers.c +133 -0
@@ 1,133 @@
#define _XOPEN_SOURCE 500
#include <wayland-client.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include "wayland/buffer.h"

static int create_pool_file(size_t size, char **name) {
	static const char template[] = "scurvy-XXXXXX";
	const char *path = getenv("XDG_RUNTIME_DIR");
		if (!path) {
		return -1;
	}

	int ts = (path[strlen(path) - 1] == '/');

	*name = malloc(
		strlen(template) +
		strlen(path) +
		(ts ? 0 : 1) + 1);
	sprintf(*name, "%s%s%s", path, ts ? "" : "/", template);

	int fd = mkstemp(*name);

	if (fd < 0) {
		return -1;
	}

	if (ftruncate(fd, size) < 0) {
		close(fd);
		return -1;
	}

	return fd;
}

static void buffer_release(void *data, struct wl_buffer *wl_buffer) {
	struct buffer *buffer = data;
	buffer->busy = false;
}

static const struct wl_buffer_listener buffer_listener = {
	.release = buffer_release
};

static struct buffer *create_buffer(struct window *window, struct buffer *buf,
		int32_t width, int32_t height, int32_t scale, uint32_t format) {

	width *= scale;
	height *= scale;
	uint32_t stride = width * 4;
	uint32_t size = stride * height;

	char *name;
	int fd = create_pool_file(size, &name);
	if (fd == -1) {
		// TODO: logging
		exit(1);
		return NULL; // never reached
	}
	void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	struct wl_shm_pool *pool = wl_shm_create_pool(window->registry->shm, fd, size);
	buf->buffer = wl_shm_pool_create_buffer(pool, 0,
			width, height, stride, format);
	wl_shm_pool_destroy(pool);
	close(fd);
	unlink(name);
	free(name);
	fd = -1;

	buf->width = width;
	buf->height = height;
	buf->surface = cairo_image_surface_create_for_data(data,
			CAIRO_FORMAT_ARGB32, width, height, stride);
	buf->cairo = cairo_create(buf->surface);
	buf->pango = pango_cairo_create_context(buf->cairo);

	wl_buffer_add_listener(buf->buffer, &buffer_listener, buf);
	return buf;
}

static void destroy_buffer(struct buffer *buffer) {
	if (buffer->buffer) {
		wl_buffer_destroy(buffer->buffer);
	}
	if (buffer->cairo) {
		cairo_destroy(buffer->cairo);
	}
	if (buffer->surface) {
		cairo_surface_destroy(buffer->surface);
	}
	if (buffer->pango) {
		g_object_unref(buffer->pango);
	}
	memset(buffer, 0, sizeof(struct buffer));
}

struct buffer *get_next_buffer(struct window *window) {
	struct buffer *buffer = NULL;

	int i;
	for (i = 0; i < 2; ++i) {
		if (window->buffers[i].busy) {
			continue;
		}
		buffer = &window->buffers[i];
	}

	if (!buffer) {
		return NULL;
	}

	if (buffer->width != window->width || buffer->height != window->height) {
		destroy_buffer(buffer);
	}

	if (!buffer->buffer) {
		if (!create_buffer(window, buffer,
					window->width, window->height, window->scale,
					WL_SHM_FORMAT_ARGB8888)) {
			return NULL;
		}
	}

	window->cairo = buffer->cairo;
	window->buffer = buffer;
	return buffer;
}

A  => src/wayland/main.c +33 -0
@@ 1,33 @@
#include <wayland-client.h>
#include <cairo/cairo.h>
#include <stdbool.h>
#include <stdint.h>
#include "wayland/window.h"
#include "wayland/registry.h"

void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
	cairo_set_source_rgba(cairo,
			(color >> (3*8) & 0xFF) / 255.0,
			(color >> (2*8) & 0xFF) / 255.0,
			(color >> (1*8) & 0xFF) / 255.0,
			(color >> (0*8) & 0xFF) / 255.0);
}

struct registry *registry;
struct window *win;

int wayland_main(void) {
	registry = registry_poll();
	win = window_setup(registry, 640, 480, 1, true);
	while (wl_display_dispatch(registry->display) != -1) {
		if (window_prerender(win) && win->cairo) {
			cairo_set_source_u32(win->cairo, 0xFF0000FF);
			cairo_paint(win->cairo);
			window_render(win);
			wl_display_flush(registry->display);
		}
	}
	window_teardown(win);
	registry_teardown(registry);
	return 0;
}

A  => src/wayland/registry.c +234 -0
@@ 1,234 @@
#include <wayland-client.h>
#include <xkbcommon/xkbcommon.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include "wayland/registry.h"

const char *XKB_MASK_NAMES[MASK_LAST] = {
	XKB_MOD_NAME_SHIFT,
	XKB_MOD_NAME_CAPS,
	XKB_MOD_NAME_CTRL,
	XKB_MOD_NAME_ALT,
	"Mod2",
	"Mod3",
	XKB_MOD_NAME_LOGO,
	"Mod5",
};

const enum mod_bit XKB_MODS[MASK_LAST] = {
	MOD_SHIFT,
	MOD_CAPS,
	MOD_CTRL,
	MOD_ALT,
	MOD_MOD2,
	MOD_MOD3,
	MOD_LOGO,
	MOD_MOD5
};

static void keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
		uint32_t format, int fd, uint32_t size) {
	struct registry *registry = data;
	if (!data) {
		close(fd);
		return;
	}

	if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
		close(fd);
		return;
	}

	char *map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
	if (map_str == MAP_FAILED) {
		close(fd);
		return;
	}

	struct xkb_keymap *keymap = xkb_keymap_new_from_string(registry->input->xkb.context,
			map_str, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
	munmap(map_str, size);
	close(fd);

	if (!keymap) {
		return;
	}

	struct xkb_state *state = xkb_state_new(keymap);
	if (!state) {
		xkb_keymap_unref(keymap);
		return;
	}

	xkb_keymap_unref(registry->input->xkb.keymap);
	xkb_state_unref(registry->input->xkb.state);
	registry->input->xkb.keymap = keymap;
	registry->input->xkb.state = state;

	int i;
	for (i = 0; i < MASK_LAST; ++i) {
		registry->input->xkb.masks[i] = 1 << xkb_keymap_mod_get_index(registry->input->xkb.keymap, XKB_MASK_NAMES[i]);
	}
}

static void keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
		uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
	// this space intentionally left blank
}

static void keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
		uint32_t serial, struct wl_surface *surface) {
	// this space intentionally left blank
}

static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
		uint32_t serial, uint32_t time, uint32_t key, uint32_t state_w) {
	struct registry *registry = data;
	enum wl_keyboard_key_state state = state_w;

	if (!registry->input->xkb.state) {
		return;
	}

	xkb_keysym_t sym = xkb_state_key_get_one_sym(registry->input->xkb.state, key + 8);
	registry->input->sym = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? sym : XKB_KEY_NoSymbol);
	registry->input->code = (state == WL_KEYBOARD_KEY_STATE_PRESSED ? key + 8 : 0);
	uint32_t codepoint = xkb_state_key_get_utf32(registry->input->xkb.state, registry->input->code);
	if (registry->input->notify) {
		registry->input->notify(state, sym, key, codepoint);
	}
}

static void keyboard_handle_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) {
	struct registry *registry = data;

	if (!registry->input->xkb.keymap) {
		return;
	}

	xkb_state_update_mask(registry->input->xkb.state, mods_depressed, mods_latched, mods_locked, 0, 0, group);
	xkb_mod_mask_t mask = xkb_state_serialize_mods(registry->input->xkb.state,
			XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED);

	registry->input->modifiers = 0;
	for (uint32_t i = 0; i < MASK_LAST; ++i) {
		if (mask & registry->input->xkb.masks[i]) {
			registry->input->modifiers |= XKB_MODS[i];
		}
	}
}

static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
		int32_t rate, int32_t delay) {
	// this space intentionally left blank
}

static const struct wl_keyboard_listener keyboard_listener = {
	.keymap = keyboard_handle_keymap,
	.enter = keyboard_handle_enter,
	.leave = keyboard_handle_leave,
	.key = keyboard_handle_key,
	.modifiers = keyboard_handle_modifiers,
	.repeat_info = keyboard_handle_repeat_info
};

static void seat_handle_capabilities(void *data, struct wl_seat *seat,
		enum wl_seat_capability caps) {
	struct registry *reg = data;

	if ((caps & WL_SEAT_CAPABILITY_POINTER) && !reg->pointer) {
		reg->pointer = wl_seat_get_pointer(reg->seat);
	} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && reg->pointer) {
		wl_pointer_destroy(reg->pointer);
		reg->pointer = NULL;
	}

	if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !reg->keyboard) {
		reg->keyboard = wl_seat_get_keyboard(reg->seat);
		wl_keyboard_add_listener(reg->keyboard, &keyboard_listener, reg);
	} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && reg->keyboard) {
		wl_keyboard_destroy(reg->keyboard);
		reg->keyboard = NULL;
	}
}

static void seat_handle_name(void *data, struct wl_seat *seat, const char *name) {
	// this space intentionally left blank
}

static const struct wl_seat_listener seat_listener = {
	.capabilities = seat_handle_capabilities,
	.name = seat_handle_name,
};

static void registry_global(void *data, struct wl_registry *registry,
		uint32_t name, const char *interface, uint32_t version) {
	struct registry *reg = data;
	if (strcmp(interface, wl_compositor_interface.name) == 0) {
		reg->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, version);
	} else if (strcmp(interface, wl_shm_interface.name) == 0) {
		reg->shm = wl_registry_bind(registry, name, &wl_shm_interface, version);
	} else if (strcmp(interface, wl_shell_interface.name) == 0) {
		reg->shell = wl_registry_bind(registry, name, &wl_shell_interface, version);
	} else if (strcmp(interface, wl_seat_interface.name) == 0) {
		reg->seat = wl_registry_bind(registry, name, &wl_seat_interface, version);
		wl_seat_add_listener(reg->seat, &seat_listener, reg);
	}
}

static void registry_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
	// this space intentionally left blank
}

static const struct wl_registry_listener registry_listener = {
	.global = registry_global,
	.global_remove = registry_global_remove
};

struct registry *registry_poll(void) {
	struct registry *registry = malloc(sizeof(struct registry));
	memset(registry, 0, sizeof(struct registry));
	registry->input = calloc(sizeof(struct input), 1);
	registry->input->xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);

	registry->display = wl_display_connect(NULL);
	if (!registry->display) {
		registry_teardown(registry);
		return NULL;
	}

	struct wl_registry *reg = wl_display_get_registry(registry->display);
	wl_registry_add_listener(reg, &registry_listener, registry);
	wl_display_dispatch(registry->display);
	wl_display_roundtrip(registry->display);
	wl_registry_destroy(reg);

	return registry;
}

void registry_teardown(struct registry *registry) {
	if (registry->pointer) {
		wl_pointer_destroy(registry->pointer);
	}
	if (registry->seat) {
		wl_seat_destroy(registry->seat);
	}
	if (registry->shell) {
		wl_shell_destroy(registry->shell);
	}
	if (registry->shm) {
		wl_shm_destroy(registry->shm);
	}
	if (registry->compositor) {
		wl_compositor_destroy(registry->compositor);
	}
	if (registry->display) {
		wl_display_disconnect(registry->display);
	}
	free(registry);
}

A  => src/wayland/window.c +168 -0
@@ 1,168 @@
#include <wayland-client.h>
#include <wayland-cursor.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include "wayland/window.h"
#include "wayland/buffer.h"

static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
		     uint32_t serial, struct wl_surface *surface, wl_fixed_t sx_w, wl_fixed_t sy_w) {
	struct window *window = data;
	if (window->registry->pointer) {
		struct wl_cursor_image *image = window->cursor.cursor->images[0];
		wl_pointer_set_cursor(pointer, serial, window->cursor.surface, image->hotspot_x, image->hotspot_y);
	}
}

static void pointer_handle_leave(void *data, struct wl_pointer *pointer,
		     uint32_t serial, struct wl_surface *surface) {
}

static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
		      uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w) {
	struct window *window = data;

	window->pointer_input.last_x = wl_fixed_to_int(sx_w);
	window->pointer_input.last_y = wl_fixed_to_int(sy_w);
}

static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
		      uint32_t time, uint32_t button, uint32_t state_w) {
	struct window *window = data;
	struct pointer_input *input = &window->pointer_input;

	if (window->pointer_input.notify_button) {
		window->pointer_input.notify_button(window, input->last_x, input->last_y, button, state_w);
	}
}

static void pointer_handle_axis(void *data, struct wl_pointer *pointer,
				uint32_t time, uint32_t axis, wl_fixed_t value) {
	struct window *window = data;
	enum scroll_direction direction;

	switch (axis) {
	case 0:
		direction = wl_fixed_to_double(value) < 0 ? SCROLL_UP : SCROLL_DOWN;
		break;
	case 1:
		direction = wl_fixed_to_double(value) < 0 ? SCROLL_LEFT : SCROLL_RIGHT;
		break;
	default:
		return;
	}

	if (window->pointer_input.notify_scroll) {
		window->pointer_input.notify_scroll(window, direction);
	}
}

static const struct wl_pointer_listener pointer_listener = {
	.enter = pointer_handle_enter,
	.leave = pointer_handle_leave,
	.motion = pointer_handle_motion,
	.button = pointer_handle_button,
	.axis = pointer_handle_axis
};

void shell_surface_configure(void *data, struct wl_shell_surface *wl_shell_surface,
			  uint32_t edges, int32_t width, int32_t height) {
	struct window *window = data;
	window->width = width;
	window->height = height;
	if (window->notify_resize) {
		window->notify_resize(window);
	}
}

static const struct wl_shell_surface_listener surface_listener = {
	.configure = shell_surface_configure
};

void window_make_shell(struct window *window) {
	window->shell_surface = wl_shell_get_shell_surface(window->registry->shell, window->surface);
	wl_shell_surface_add_listener(window->shell_surface, &surface_listener, window);
	wl_shell_surface_set_toplevel(window->shell_surface);
}

struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height,
		int32_t scale, bool shell_surface) {
	struct window *window = malloc(sizeof(struct window));
	memset(window, 0, sizeof(struct window));
	window->width = width;
	window->height = height;
	window->scale = scale;
	window->registry = registry;
	window->font = "monospace 10";

	window->surface = wl_compositor_create_surface(registry->compositor);
	if (shell_surface) {
		window_make_shell(window);
	}
	if (registry->pointer) {
		wl_pointer_add_listener(registry->pointer, &pointer_listener, window);
	}

	get_next_buffer(window);

	if (registry->pointer) {
		// TODO: Configurable?
		const char *cursor_theme = "default";
		const char *cursor_size = "16";

		window->cursor.cursor_theme = wl_cursor_theme_load(cursor_theme,
				atoi(cursor_size) * scale, registry->shm);
		window->cursor.cursor = wl_cursor_theme_get_cursor(
				window->cursor.cursor_theme, "xterm");
		window->cursor.surface = wl_compositor_create_surface(registry->compositor);

		struct wl_cursor_image *image = window->cursor.cursor->images[0];
		struct wl_buffer *cursor_buf = wl_cursor_image_get_buffer(image);
		wl_surface_attach(window->cursor.surface, cursor_buf, 0, 0);
		wl_surface_set_buffer_scale(window->cursor.surface, scale);
		wl_surface_damage(window->cursor.surface, 0, 0,
				image->width, image->height);
		wl_surface_commit(window->cursor.surface);
	}

	return window;
}

static void frame_callback(void *data, struct wl_callback *callback, uint32_t time) {
	struct window *window = data;
	wl_callback_destroy(callback);
	window->frame_cb = NULL;
}

static const struct wl_callback_listener listener = {
	frame_callback
};

int window_prerender(struct window *window) {
	if (window->frame_cb) {
		return 0;
	}
	get_next_buffer(window);
	return 1;
}

int window_render(struct window *window) {
	window->frame_cb = wl_surface_frame(window->surface);
	wl_callback_add_listener(window->frame_cb, &listener, window);

	wl_surface_attach(window->surface, window->buffer->buffer, 0, 0);
	wl_surface_set_buffer_scale(window->surface, window->scale);
	wl_surface_damage(window->surface, 0, 0, window->width, window->height);
	wl_surface_commit(window->surface);
	return 1;
}

void window_teardown(struct window *window) {
	// TODO
}

A  => src/wayland/xdg-shell.xml +430 -0
@@ 1,430 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="xdg_shell">

  <copyright>
    Copyright © 2008-2013 Kristian Høgsberg
    Copyright © 2013      Rafael Antognolli
    Copyright © 2013      Jasper St. Pierre
    Copyright © 2010-2013 Intel Corporation

    Permission to use, copy, modify, distribute, and sell this
    software and its documentation for any purpose is hereby granted
    without fee, provided that the above copyright notice appear in
    all copies and that both that copyright notice and this permission
    notice appear in supporting documentation, and that the name of
    the copyright holders not be used in advertising or publicity
    pertaining to distribution of the software without specific,
    written prior permission.  The copyright holders make no
    representations about the suitability of this software for any
    purpose.  It is provided "as is" without express or implied
    warranty.

    THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
    SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
    SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
    AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
    THIS SOFTWARE.
  </copyright>

  <interface name="xdg_shell" version="1">
    <description summary="create desktop-style surfaces">
      This interface is implemented by servers that provide
      desktop-style user interfaces.

      It allows clients to associate a xdg_surface with
      a basic surface.
    </description>

    <enum name="version">
      <description summary="latest protocol version">
	The 'current' member of this enum gives the version of the
	protocol.  Implementations can compare this to the version
	they implement using static_assert to ensure the protocol and
	implementation versions match.
      </description>
      <entry name="current" value="4" summary="Always the latest version"/>
    </enum>

    <enum name="error">
      <entry name="role" value="0" summary="given wl_surface has another role"/>
    </enum>

    <request name="use_unstable_version">
      <description summary="enable use of this unstable version">
	Negotiate the unstable version of the interface.  This
	mechanism is in place to ensure client and server agree on the
	unstable versions of the protocol that they speak or exit
	cleanly if they don't agree.  This request will go away once
	the xdg-shell protocol is stable.
      </description>
      <arg name="version" type="int"/>
    </request>

    <request name="get_xdg_surface">
      <description summary="create a shell surface from a surface">
	Create a shell surface for an existing surface.

	This request gives the surface the role of xdg_surface. If the
	surface already has another role, it raises a protocol error.

	Only one shell or popup surface can be associated with a given
	surface.
      </description>
      <arg name="id" type="new_id" interface="xdg_surface"/>
      <arg name="surface" type="object" interface="wl_surface"/>
    </request>

    <request name="get_xdg_popup">
      <description summary="create a shell surface from a surface">
	Create a popup surface for an existing surface.

	This request gives the surface the role of xdg_popup. If the
	surface already has another role, it raises a protocol error.

	Only one shell or popup surface can be associated with a given
	surface.
      </description>
      <arg name="id" type="new_id" interface="xdg_popup"/>
      <arg name="surface" type="object" interface="wl_surface"/>
      <arg name="parent" type="object" interface="wl_surface"/>
      <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat whose pointer is used"/>
      <arg name="serial" type="uint" summary="serial of the implicit grab on the pointer"/>
      <arg name="x" type="int"/>
      <arg name="y" type="int"/>
      <arg name="flags" type="uint"/>
    </request>

    <event name="ping">
      <description summary="check if the client is alive">
        The ping event asks the client if it's still alive. Pass the
        serial specified in the event back to the compositor by sending
        a "pong" request back with the specified serial.

        Compositors can use this to determine if the client is still
        alive. It's unspecified what will happen if the client doesn't
        respond to the ping request, or in what timeframe. Clients should
        try to respond in a reasonable amount of time.
      </description>
      <arg name="serial" type="uint" summary="pass this to the callback"/>
    </event>

    <request name="pong">
      <description summary="respond to a ping event">
	A client must respond to a ping event with a pong request or
	the client may be deemed unresponsive.
      </description>
      <arg name="serial" type="uint" summary="serial of the ping event"/>
    </request>
  </interface>

  <interface name="xdg_surface" version="1">

    <description summary="desktop-style metadata interface">
      An interface that may be implemented by a wl_surface, for
      implementations that provide a desktop-style user interface.

      It provides requests to treat surfaces like windows, allowing to set
      properties like maximized, fullscreen, minimized, and to move and resize
      them, and associate metadata like title and app id.

      On the server side the object is automatically destroyed when
      the related wl_surface is destroyed.  On client side,
      xdg_surface.destroy() must be called before destroying
      the wl_surface object.
    </description>

    <request name="destroy" type="destructor">
      <description summary="remove xdg_surface interface">
	The xdg_surface interface is removed from the wl_surface object
	that was turned into a xdg_surface with
	xdg_shell.get_xdg_surface request. The xdg_surface properties,
	like maximized and fullscreen, are lost. The wl_surface loses
	its role as a xdg_surface. The wl_surface is unmapped.
      </description>
    </request>

    <request name="set_parent">
      <description summary="surface is a child of another surface">
	Child surfaces are stacked above their parents, and will be
	unmapped if the parent is unmapped too. They should not appear
	on task bars and alt+tab.
      </description>
      <arg name="parent" type="object" interface="wl_surface" allow-null="true"/>
    </request>

    <request name="set_title">
      <description summary="set surface title">
	Set a short title for the surface.

	This string may be used to identify the surface in a task bar,
	window list, or other user interface elements provided by the
	compositor.

	The string must be encoded in UTF-8.
      </description>
      <arg name="title" type="string"/>
    </request>

    <request name="set_app_id">
      <description summary="set surface class">
	Set an id for the surface.

	The app id identifies the general class of applications to which
	the surface belongs.

	It should be the ID that appears in the new desktop entry
	specification, the interface name.
      </description>
      <arg name="app_id" type="string"/>
    </request>

    <request name="show_window_menu">
      <description summary="show the window menu">
        Clients implementing client-side decorations might want to show
        a context menu when right-clicking on the decorations, giving the
        user a menu that they can use to maximize or minimize the window.

        This request asks the compositor to pop up such a window menu at
        the given position, relative to the parent surface. There are
        no guarantees as to what the window menu contains.

        Your surface must have focus on the seat passed in to pop up the
        window menu.
      </description>

      <arg name="seat" type="object" interface="wl_seat" summary="the seat to pop the window up on"/>
      <arg name="serial" type="uint" summary="serial of the event to pop up the window for"/>
      <arg name="x" type="int" summary="the x position to pop up the window menu at"/>
      <arg name="y" type="int" summary="the y position to pop up the window menu at"/>
    </request>

    <request name="move">
      <description summary="start an interactive move">
	Start a pointer-driven move of the surface.

	This request must be used in response to a button press event.
	The server may ignore move requests depending on the state of
	the surface (e.g. fullscreen or maximized).
      </description>
      <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat whose pointer is used"/>
      <arg name="serial" type="uint" summary="serial of the implicit grab on the pointer"/>
    </request>

    <enum name="resize_edge">
      <description summary="edge values for resizing">
	These values are used to indicate which edge of a surface
	is being dragged in a resize operation. The server may
	use this information to adapt its behavior, e.g. choose
	an appropriate cursor image.
      </description>
      <entry name="none" value="0"/>
      <entry name="top" value="1"/>
      <entry name="bottom" value="2"/>
      <entry name="left" value="4"/>
      <entry name="top_left" value="5"/>
      <entry name="bottom_left" value="6"/>
      <entry name="right" value="8"/>
      <entry name="top_right" value="9"/>
      <entry name="bottom_right" value="10"/>
    </enum>

    <request name="resize">
      <description summary="start an interactive resize">
	Start a pointer-driven resizing of the surface.

	This request must be used in response to a button press event.
	The server may ignore resize requests depending on the state of
	the surface (e.g. fullscreen or maximized).
      </description>
      <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat whose pointer is used"/>
      <arg name="serial" type="uint" summary="serial of the implicit grab on the pointer"/>
      <arg name="edges" type="uint" summary="which edge or corner is being dragged"/>
    </request>

    <enum name="state">
      <description summary="types of state on the surface">
        The different state values used on the surface. This is designed for
        state values like maximized, fullscreen. It is paired with the
        configure event to ensure that both the client and the compositor
        setting the state can be synchronized.

        States set in this way are double-buffered. They will get applied on
        the next commit.

        Desktop environments may extend this enum by taking up a range of
        values and documenting the range they chose in this description.
        They are not required to document the values for the range that they
        chose. Ideally, any good extensions from a desktop environment should
        make its way into standardization into this enum.

        The current reserved ranges are:

        0x0000 - 0x0FFF: xdg-shell core values, documented below.
        0x1000 - 0x1FFF: GNOME
      </description>
      <entry name="maximized" value="1">
        <description summary="the surface is maximized">
        The surface is maximized. The window geometry specified in the configure
        event must be obeyed by the client.
        </description>
      </entry>
      <entry name="fullscreen" value="2">
        <description summary="the surface is fullscreen">
        The surface is fullscreen. The window geometry specified in the configure
        event must be obeyed by the client.
        </description>
      </entry>
      <entry name="resizing" value="3">
        <description summary="the surface is being resized">
        The surface is being resized. The window geometry specified in the
        configure event is a maximum; the client cannot resize beyond it.
        Clients that have aspect ratio or cell sizing configuration can use
        a smaller size, however.
        </description>
      </entry>
      <entry name="activated" value="4">
        <description summary="the client window is active">
        Client window decorations should be painted as if the window is
        active. Do not assume this means that the window actually has
        keyboard or pointer focus.
        </description>
      </entry>
    </enum>

    <event name="configure">
      <description summary="suggest a surface change">
	The configure event asks the client to resize its surface.

	The width and height arguments specify a hint to the window
        about how its surface should be resized in window geometry
        coordinates. The states listed in the event specify how the
        width/height arguments should be interpreted.

        A client should arrange a new surface, and then send a
        ack_configure request with the serial sent in this configure
        event before attaching a new surface.

	If the client receives multiple configure events before it
        can respond to one, it is free to discard all but the last
        event it received.
      </description>

      <arg name="width" type="int"/>
      <arg name="height" type="int"/>
      <arg name="states" type="array"/>
      <arg name="serial" type="uint"/>
    </event>

    <request name="ack_configure">
      <description summary="ack a configure event">
        When a configure event is received, a client should then ack it
        using the ack_configure request to ensure that the compositor
        knows the client has seen the event.

        By this point, the state is confirmed, and the next attach should
        contain the buffer drawn for the configure event you are acking.
      </description>
      <arg name="serial" type="uint" summary="a serial to configure for"/>
    </request>

    <request name="set_window_geometry">
      <description summary="set the new window geometry">
        The window geometry of a window is its "visible bounds" from the
        user's perspective. Client-side decorations often have invisible
        portions like drop-shadows which should be ignored for the
        purposes of aligning, placing and constraining windows.

        The default value is the full bounds of the surface, including any
        subsurfaces. Once the window geometry of the surface is set once,
        it is not possible to unset it, and it will remain the same until
        set_window_geometry is called again, even if a new subsurface or
        buffer is attached.

        If responding to a configure event, the window geometry in here
        must respect the sizing negotiations specified by the states in
        the configure event.
      </description>
      <arg name="x" type="int"/>
      <arg name="y" type="int"/>
      <arg name="width" type="int"/>
      <arg name="height" type="int"/>
    </request>

    <request name="set_maximized" />
    <request name="unset_maximized" />

    <request name="set_fullscreen">
      <description summary="set the window as fullscreen on a monitor">
	Make the surface fullscreen.

        You can specify an output that you would prefer to be fullscreen.
	If this value is NULL, it's up to the compositor to choose which
        display will be used to map this surface.
      </description>
      <arg name="output" type="object" interface="wl_output" allow-null="true"/>
    </request>
    <request name="unset_fullscreen" />

    <request name="set_minimized" />

    <event name="close">
      <description summary="surface wants to be closed">
        The close event is sent by the compositor when the user
        wants the surface to be closed. This should be equivalent to
        the user clicking the close button in client-side decorations,
        if your application has any...

        This is only a request that the user intends to close your
        window. The client may choose to ignore this request, or show
        a dialog to ask the user to save their data...
      </description>
    </event>
  </interface>

  <interface name="xdg_popup" version="1">
    <description summary="desktop-style metadata interface">
      An interface that may be implemented by a wl_surface, for
      implementations that provide a desktop-style popups/menus. A popup
      surface is a transient surface with an added pointer grab.

      An existing implicit grab will be changed to owner-events mode,
      and the popup grab will continue after the implicit grab ends
      (i.e. releasing the mouse button does not cause the popup to be
      unmapped).

      The popup grab continues until the window is destroyed or a mouse
      button is pressed in any other clients window. A click in any of
      the clients surfaces is reported as normal, however, clicks in
      other clients surfaces will be discarded and trigger the callback.

      The x and y arguments specify the locations of the upper left
      corner of the surface relative to the upper left corner of the
      parent surface, in surface local coordinates.

      xdg_popup surfaces are always transient for another surface.
    </description>

    <request name="destroy" type="destructor">
      <description summary="remove xdg_surface interface">
	The xdg_surface interface is removed from the wl_surface object
	that was turned into a xdg_surface with
	xdg_shell.get_xdg_surface request. The xdg_surface properties,
	like maximized and fullscreen, are lost. The wl_surface loses
	its role as a xdg_surface. The wl_surface is unmapped.
      </description>
    </request>

    <event name="popup_done">
      <description summary="popup interaction is done">
	The popup_done event is sent out when a popup grab is broken,
	that is, when the users clicks a surface that doesn't belong
	to the client owning the popup surface.
      </description>
      <arg name="serial" type="uint" summary="serial of the implicit grab on the pointer"/>
    </event>

  </interface>
</protocol>