summaryrefslogtreecommitdiffstats
path: root/uwac
diff options
context:
space:
mode:
Diffstat (limited to 'uwac')
-rw-r--r--uwac/CMakeLists.txt100
-rw-r--r--uwac/include/CMakeLists.txt26
-rw-r--r--uwac/include/uwac/uwac-tools.h43
-rw-r--r--uwac/include/uwac/uwac.h668
-rw-r--r--uwac/libuwac/CMakeLists.txt103
-rw-r--r--uwac/libuwac/uwac-clipboard.c280
-rw-r--r--uwac/libuwac/uwac-display.c794
-rw-r--r--uwac/libuwac/uwac-input.c1277
-rw-r--r--uwac/libuwac/uwac-os.c290
-rw-r--r--uwac/libuwac/uwac-os.h45
-rw-r--r--uwac/libuwac/uwac-output.c183
-rw-r--r--uwac/libuwac/uwac-priv.h291
-rw-r--r--uwac/libuwac/uwac-tools.c106
-rw-r--r--uwac/libuwac/uwac-utils.c67
-rw-r--r--uwac/libuwac/uwac-utils.h56
-rw-r--r--uwac/libuwac/uwac-window.c883
-rw-r--r--uwac/protocols/fullscreen-shell-unstable-v1.xml220
-rw-r--r--uwac/protocols/ivi-application.xml100
-rw-r--r--uwac/protocols/keyboard-shortcuts-inhibit-unstable-v1.xml143
-rw-r--r--uwac/protocols/server-decoration.xml96
-rw-r--r--uwac/protocols/viewporter.xml180
-rw-r--r--uwac/protocols/xdg-decoration-unstable-v1.xml156
-rw-r--r--uwac/protocols/xdg-shell.xml1144
-rw-r--r--uwac/templates/CMakeLists.txt47
-rw-r--r--uwac/templates/build-config.h.in22
-rw-r--r--uwac/templates/buildflags.h.in11
-rw-r--r--uwac/templates/config.h.in11
-rw-r--r--uwac/templates/uwac.pc.in15
-rw-r--r--uwac/templates/uwacConfig.cmake.in9
-rw-r--r--uwac/templates/version.h.in32
30 files changed, 7398 insertions, 0 deletions
diff --git a/uwac/CMakeLists.txt b/uwac/CMakeLists.txt
new file mode 100644
index 0000000..6e66c8b
--- /dev/null
+++ b/uwac/CMakeLists.txt
@@ -0,0 +1,100 @@
+# UWAC: Using Wayland As Client
+# cmake build script
+#
+# Copyright 2015 David FORT <contact@hardening-consulting.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Soname versioning
+set(UWAC_VERSION_MAJOR "0")
+set(UWAC_VERSION_MINOR "2")
+set(UWAC_VERSION_REVISION "0")
+set(UWAC_VERSION "${UWAC_VERSION_MAJOR}.${UWAC_VERSION_MINOR}.${UWAC_VERSION_REVISION}")
+set(UWAC_VERSION_FULL "${UWAC_VERSION}")
+set(UWAC_API_VERSION "${UWAC_VERSION_MAJOR}")
+
+if (NOT FREERDP_UNIFIED_BUILD)
+ cmake_minimum_required(VERSION 3.13)
+ project(uwac VERSION ${UWAC_VERSION} LANGUAGES C)
+
+ set(CMAKE_C_STANDARD 11)
+ set(CMAKE_C_STANDARD_REQUIRED ON)
+ set(CMAKE_C_EXTENSIONS ON)
+
+ option(EXPORT_ALL_SYMBOLS "Export all symbols form library" OFF)
+ option(BUILD_TESTING "Build library unit tests" ON)
+
+ if(CMAKE_COMPILER_IS_GNUCC)
+ if(NOT EXPORT_ALL_SYMBOLS)
+ message(STATUS "GCC default symbol visibility: hidden")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
+ endif()
+ endif()
+endif()
+
+option(UWAC_FORCE_STATIC_BUILD "Force UWAC to be build as static libary (recommended)" OFF)
+option(UWAC_HAVE_PIXMAN_REGION "Use PIXMAN or FreeRDP for region calculations" "NOT FREERDP_UNIFIED_BUILD")
+
+# Include our extra modules
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/)
+include(CommonConfigOptions)
+
+# Check for cmake compatibility (enable/disable features)
+include(FindFeature)
+
+if (UWAC_FORCE_STATIC_BUILD)
+ set(BUILD_SHARED_LIBS OFF)
+else()
+ include(SetFreeRDPCMakeInstallDir)
+ include(CMakePackageConfigHelpers)
+endif()
+
+if (NOT IOS)
+ include(CheckIncludeFiles)
+ check_include_files(stdbool.h UWAC_HAVE_STDBOOL_H)
+ if (NOT UWAC_HAVE_STDBOOL_H)
+ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/../compat/stdbool)
+ endif()
+endif()
+
+# Find required libraries
+if (UWAC_HAVE_PIXMAN_REGION)
+ find_package(PkgConfig REQUIRED)
+ pkg_check_modules(pixman REQUIRED pixman-1)
+ include_directories(${pixman_INCLUDE_DIRS})
+elseif (FREERDP_UNIFIED_BUILD)
+ include_directories(${PROJECT_SOURCE_DIR}/winpr/include)
+ include_directories(${PROJECT_BINARY_DIR}/winpr/include)
+ include_directories(${PROJECT_SOURCE_DIR}/include)
+ include_directories(${PROJECT_BINARY_DIR}/include)
+else()
+ find_package(WinPR 3 REQUIRED)
+ find_package(FreeRDP 3 REQUIRED)
+ include_directories(${WinPR_INCLUDE_DIR})
+ include_directories(${FreeRDP_INCLUDE_DIR})
+endif()
+
+set(WAYLAND_FEATURE_PURPOSE "Wayland")
+set(WAYLAND_FEATURE_DESCRIPTION "Wayland client")
+set(WAYLAND_FEATURE_TYPE "REQUIRED")
+find_feature(Wayland ${WAYLAND_FEATURE_TYPE} ${WAYLAND_FEATURE_PURPOSE} ${WAYLAND_FEATURE_DESCRIPTION})
+
+set(UWAC_INCLUDE_DIR include/uwac${UWAC_API_VERSION})
+
+include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include)
+include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include)
+
+add_subdirectory(libuwac)
+add_subdirectory(templates)
+add_subdirectory(include)
+
diff --git a/uwac/include/CMakeLists.txt b/uwac/include/CMakeLists.txt
new file mode 100644
index 0000000..6988200
--- /dev/null
+++ b/uwac/include/CMakeLists.txt
@@ -0,0 +1,26 @@
+# UWAC: Using Wayland As Client
+# cmake build script
+#
+# Copyright 2015 David FORT <contact@hardening-consulting.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+if (NOT UWAC_FORCE_STATIC_BUILD)
+ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
+ DESTINATION ${UWAC_INCLUDE_DIR}
+ FILES_MATCHING PATTERN "*.h")
+
+ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/
+ DESTINATION ${UWAC_INCLUDE_DIR}
+ FILES_MATCHING PATTERN "*.h")
+endif()
diff --git a/uwac/include/uwac/uwac-tools.h b/uwac/include/uwac/uwac-tools.h
new file mode 100644
index 0000000..65d2617
--- /dev/null
+++ b/uwac/include/uwac/uwac-tools.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2015 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+
+#ifndef UWAC_TOOLS_H_
+#define UWAC_TOOLS_H_
+
+#include <stdbool.h>
+#include <uwac/uwac.h>
+
+struct uwac_touch_point
+{
+ uint32_t id;
+ wl_fixed_t x, y;
+};
+typedef struct uwac_touch_point UwacTouchPoint;
+
+struct uwac_touch_automata;
+typedef struct uwac_touch_automata UwacTouchAutomata;
+
+UWAC_API void UwacTouchAutomataInit(UwacTouchAutomata* automata);
+UWAC_API void UwacTouchAutomataReset(UwacTouchAutomata* automata);
+UWAC_API bool UwacTouchAutomataInjectEvent(UwacTouchAutomata* automata, UwacEvent* event);
+
+#endif /* UWAC_TOOLS_H_ */
diff --git a/uwac/include/uwac/uwac.h b/uwac/include/uwac/uwac.h
new file mode 100644
index 0000000..928e693
--- /dev/null
+++ b/uwac/include/uwac/uwac.h
@@ -0,0 +1,668 @@
+/*
+ * Copyright © 2014-2015 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+
+#ifndef UWAC_H_
+#define UWAC_H_
+
+#include <wayland-client.h>
+#include <stdbool.h>
+
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#define UWAC_API __attribute__((visibility("default")))
+#else
+#define UWAC_API
+#endif
+
+typedef struct uwac_position UwacPosition;
+typedef struct uwac_size UwacSize;
+typedef struct uwac_display UwacDisplay;
+typedef struct uwac_output UwacOutput;
+typedef struct uwac_window UwacWindow;
+typedef struct uwac_seat UwacSeat;
+typedef uint32_t UwacSeatId;
+
+/** @brief error codes */
+typedef enum
+{
+ UWAC_SUCCESS = 0,
+ UWAC_ERROR_NOMEMORY,
+ UWAC_ERROR_UNABLE_TO_CONNECT,
+ UWAC_ERROR_INVALID_DISPLAY,
+ UWAC_NOT_ENOUGH_RESOURCES,
+ UWAC_TIMEDOUT,
+ UWAC_NOT_FOUND,
+ UWAC_ERROR_CLOSED,
+ UWAC_ERROR_INTERNAL,
+
+ UWAC_ERROR_LAST,
+} UwacReturnCode;
+
+/** @brief input modifiers */
+enum
+{
+ UWAC_MOD_SHIFT_MASK = 0x01,
+ UWAC_MOD_ALT_MASK = 0x02,
+ UWAC_MOD_CONTROL_MASK = 0x04,
+ UWAC_MOD_CAPS_MASK = 0x08,
+ UWAC_MOD_NUM_MASK = 0x10,
+};
+
+/** @brief a position */
+struct uwac_position
+{
+ int x;
+ int y;
+};
+
+/** @brief a rectangle size measure */
+struct uwac_size
+{
+ int width;
+ int height;
+};
+
+/** @brief event types */
+enum
+{
+ UWAC_EVENT_NEW_SEAT = 0,
+ UWAC_EVENT_REMOVED_SEAT,
+ UWAC_EVENT_NEW_OUTPUT,
+ UWAC_EVENT_CONFIGURE,
+ UWAC_EVENT_POINTER_ENTER,
+ UWAC_EVENT_POINTER_LEAVE,
+ UWAC_EVENT_POINTER_MOTION,
+ UWAC_EVENT_POINTER_BUTTONS,
+ UWAC_EVENT_POINTER_AXIS,
+ UWAC_EVENT_KEYBOARD_ENTER,
+ UWAC_EVENT_KEYBOARD_MODIFIERS,
+ UWAC_EVENT_KEY,
+ UWAC_EVENT_TOUCH_FRAME_BEGIN,
+ UWAC_EVENT_TOUCH_UP,
+ UWAC_EVENT_TOUCH_DOWN,
+ UWAC_EVENT_TOUCH_MOTION,
+ UWAC_EVENT_TOUCH_CANCEL,
+ UWAC_EVENT_TOUCH_FRAME_END,
+ UWAC_EVENT_FRAME_DONE,
+ UWAC_EVENT_CLOSE,
+ UWAC_EVENT_CLIPBOARD_AVAILABLE,
+ UWAC_EVENT_CLIPBOARD_SELECT,
+ UWAC_EVENT_CLIPBOARD_OFFER,
+ UWAC_EVENT_OUTPUT_GEOMETRY,
+ UWAC_EVENT_POINTER_AXIS_DISCRETE,
+ UWAC_EVENT_POINTER_FRAME,
+ UWAC_EVENT_POINTER_SOURCE
+};
+
+/** @brief window states */
+enum
+{
+ UWAC_WINDOW_MAXIMIZED = 0x1,
+ UWAC_WINDOW_RESIZING = 0x2,
+ UWAC_WINDOW_FULLSCREEN = 0x4,
+ UWAC_WINDOW_ACTIVATED = 0x8,
+};
+
+struct uwac_new_output_event
+{
+ int type;
+ UwacOutput* output;
+};
+typedef struct uwac_new_output_event UwacOutputNewEvent;
+
+struct uwac_new_seat_event
+{
+ int type;
+ UwacSeat* seat;
+};
+typedef struct uwac_new_seat_event UwacSeatNewEvent;
+
+struct uwac_removed_seat_event
+{
+ int type;
+ UwacSeatId id;
+};
+typedef struct uwac_removed_seat_event UwacSeatRemovedEvent;
+
+struct uwac_keyboard_enter_event
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+};
+typedef struct uwac_keyboard_enter_event UwacKeyboardEnterLeaveEvent;
+
+struct uwac_keyboard_modifiers_event
+{
+ int type;
+ uint32_t modifiers;
+};
+typedef struct uwac_keyboard_modifiers_event UwacKeyboardModifiersEvent;
+
+struct uwac_pointer_enter_event
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+ uint32_t x, y;
+};
+typedef struct uwac_pointer_enter_event UwacPointerEnterLeaveEvent;
+
+struct uwac_pointer_motion_event
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+ uint32_t x, y;
+};
+typedef struct uwac_pointer_motion_event UwacPointerMotionEvent;
+
+struct uwac_pointer_button_event
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+ uint32_t x, y;
+ uint32_t button;
+ enum wl_pointer_button_state state;
+};
+typedef struct uwac_pointer_button_event UwacPointerButtonEvent;
+
+struct uwac_pointer_axis_event
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+ uint32_t x, y;
+ uint32_t axis;
+ wl_fixed_t value;
+};
+typedef struct uwac_pointer_axis_event UwacPointerAxisEvent;
+
+struct uwac_pointer_frame_event
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+};
+typedef struct uwac_pointer_frame_event UwacPointerFrameEvent;
+
+struct uwac_pointer_source_event
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+ enum wl_pointer_axis_source axis_source;
+};
+typedef struct uwac_pointer_source_event UwacPointerSourceEvent;
+
+struct uwac_touch_frame_event
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+};
+typedef struct uwac_touch_frame_event UwacTouchFrameBegin;
+typedef struct uwac_touch_frame_event UwacTouchFrameEnd;
+typedef struct uwac_touch_frame_event UwacTouchCancel;
+
+struct uwac_touch_data
+{
+ int type;
+ UwacWindow* window;
+ UwacSeat* seat;
+ int32_t id;
+ wl_fixed_t x;
+ wl_fixed_t y;
+};
+typedef struct uwac_touch_data UwacTouchUp;
+typedef struct uwac_touch_data UwacTouchDown;
+typedef struct uwac_touch_data UwacTouchMotion;
+
+struct uwac_frame_done_event
+{
+ int type;
+ UwacWindow* window;
+};
+typedef struct uwac_frame_done_event UwacFrameDoneEvent;
+
+struct uwac_configure_event
+{
+ int type;
+ UwacWindow* window;
+ int32_t width;
+ int32_t height;
+ int states;
+};
+typedef struct uwac_configure_event UwacConfigureEvent;
+
+struct uwac_key_event
+{
+ int type;
+ UwacWindow* window;
+ uint32_t raw_key;
+ uint32_t sym;
+ bool pressed;
+ bool repeated;
+};
+typedef struct uwac_key_event UwacKeyEvent;
+
+struct uwac_close_event
+{
+ int type;
+ UwacWindow* window;
+};
+typedef struct uwac_close_event UwacCloseEvent;
+
+struct uwac_clipboard_event
+{
+ int type;
+ UwacSeat* seat;
+ char mime[64];
+};
+typedef struct uwac_clipboard_event UwacClipboardEvent;
+
+struct uwac_output_geometry_event
+{
+ int type;
+ UwacOutput* output;
+ int x;
+ int y;
+ int physical_width;
+ int physical_height;
+ int subpixel;
+ const char* make;
+ const char* model;
+ int transform;
+};
+typedef struct uwac_output_geometry_event UwacOutputGeometryEvent;
+
+union uwac_event
+{
+ int type;
+ UwacOutputNewEvent output_new;
+ UwacOutputGeometryEvent output_geometry;
+ UwacSeatNewEvent seat_new;
+ UwacSeatRemovedEvent seat_removed;
+ UwacPointerEnterLeaveEvent mouse_enter_leave;
+ UwacPointerMotionEvent mouse_motion;
+ UwacPointerButtonEvent mouse_button;
+ UwacPointerAxisEvent mouse_axis;
+ UwacPointerFrameEvent mouse_frame;
+ UwacPointerSourceEvent mouse_source;
+ UwacKeyboardEnterLeaveEvent keyboard_enter_leave;
+ UwacKeyboardModifiersEvent keyboard_modifiers;
+ UwacClipboardEvent clipboard;
+ UwacKeyEvent key;
+ UwacTouchFrameBegin touchFrameBegin;
+ UwacTouchUp touchUp;
+ UwacTouchDown touchDown;
+ UwacTouchMotion touchMotion;
+ UwacTouchFrameEnd touchFrameEnd;
+ UwacTouchCancel touchCancel;
+ UwacFrameDoneEvent frame_done;
+ UwacConfigureEvent configure;
+ UwacCloseEvent close;
+};
+typedef union uwac_event UwacEvent;
+
+typedef bool (*UwacErrorHandler)(UwacDisplay* d, UwacReturnCode code, const char* msg, ...);
+typedef void (*UwacDataTransferHandler)(UwacSeat* seat, void* context, const char* mime, int fd);
+typedef void (*UwacCancelDataTransferHandler)(UwacSeat* seat, void* context);
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /**
+ * install a handler that will be called when UWAC encounter internal errors. The
+ * handler is supposed to answer if the execution can continue. I can also be used
+ * to log things.
+ *
+ * @param handler the error handling function to install
+ */
+ UWAC_API void UwacInstallErrorHandler(UwacErrorHandler handler);
+
+ /**
+ * Opens the corresponding wayland display, using NULL you will open the default
+ * display.
+ *
+ * @param name the name of the display to open
+ * @return the created UwacDisplay object
+ */
+ UWAC_API UwacDisplay* UwacOpenDisplay(const char* name, UwacReturnCode* err);
+
+ /**
+ * closes the corresponding UwacDisplay
+ *
+ * @param pdisplay a pointer on the display to close
+ * @return UWAC_SUCCESS if the operation was successful, the corresponding error otherwise
+ */
+ UWAC_API UwacReturnCode UwacCloseDisplay(UwacDisplay** pdisplay);
+
+ /**
+ * Returns the file descriptor associated with the UwacDisplay, this is useful when
+ * you want to poll that file descriptor for activity.
+ *
+ * @param display an opened UwacDisplay
+ * @return the corresponding descriptor
+ */
+ UWAC_API int UwacDisplayGetFd(UwacDisplay* display);
+
+ /**
+ * Returns a human readable form of a Uwac error code
+ *
+ * @param error the error number
+ * @return the associated string
+ */
+ UWAC_API const char* UwacErrorString(UwacReturnCode error);
+
+ /**
+ * returns the last error that occurred on a display
+ *
+ * @param display the display
+ * @return the last error that have been set for this display
+ */
+ UWAC_API UwacReturnCode UwacDisplayGetLastError(const UwacDisplay* display);
+
+ /**
+ * retrieves the version of a given interface
+ *
+ * @param display the display connection
+ * @param name the name of the interface
+ * @param version the output variable for the version
+ * @return UWAC_SUCCESS if the interface was found, UWAC_NOT_FOUND otherwise
+ */
+ UWAC_API UwacReturnCode UwacDisplayQueryInterfaceVersion(const UwacDisplay* display,
+ const char* name, uint32_t* version);
+
+ /**
+ * returns the number SHM formats that have been reported by the compositor
+ *
+ * @param display a connected UwacDisplay
+ * @return the number of SHM formats supported
+ */
+ UWAC_API uint32_t UwacDisplayQueryGetNbShmFormats(UwacDisplay* display);
+
+ /**
+ * returns the supported ShmFormats
+ *
+ * @param display a connected UwacDisplay
+ * @param formats a pointer on an array of wl_shm_format with enough place for formats_size
+ *items
+ * @param formats_size the size of the formats array
+ * @param filled the number of filled entries in the formats array
+ * @return UWAC_SUCCESS on success, an error otherwise
+ */
+ UWAC_API UwacReturnCode UwacDisplayQueryShmFormats(const UwacDisplay* display,
+ enum wl_shm_format* formats,
+ int formats_size, int* filled);
+
+ /**
+ * returns the number of registered outputs
+ *
+ * @param display the display to query
+ * @return the number of outputs
+ */
+ UWAC_API uint32_t UwacDisplayGetNbOutputs(const UwacDisplay* display);
+
+ /**
+ * retrieve a particular UwacOutput object
+ *
+ * @param display the display to query
+ * @param index index of the output
+ * @return the given UwacOutput, NULL if something failed (so you should query
+ *UwacDisplayGetLastError() to have the reason)
+ */
+ UWAC_API const UwacOutput* UwacDisplayGetOutput(UwacDisplay* display, int index);
+
+ /**
+ * retrieve the resolution of a given UwacOutput
+ *
+ * @param output the UwacOutput
+ * @param resolution a pointer on the
+ * @return UWAC_SUCCESS on success
+ */
+ UWAC_API UwacReturnCode UwacOutputGetResolution(const UwacOutput* output, UwacSize* resolution);
+
+ /**
+ * retrieve the position of a given UwacOutput
+ *
+ * @param output the UwacOutput
+ * @param pos a pointer on the target position
+ * @return UWAC_SUCCESS on success
+ */
+ UWAC_API UwacReturnCode UwacOutputGetPosition(const UwacOutput* output, UwacPosition* pos);
+
+ /**
+ * creates a window using a SHM surface
+ *
+ * @param display the display to attach the window to
+ * @param width the width of the window
+ * @param height the heigh of the window
+ * @param format format to use for the SHM surface
+ * @return the created UwacWindow, NULL if something failed (use UwacDisplayGetLastError() to
+ *know more about this)
+ */
+ UWAC_API UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t height,
+ enum wl_shm_format format);
+
+ /**
+ * destroys the corresponding UwacWindow
+ *
+ * @param window a pointer on the UwacWindow to destroy
+ * @return if the operation completed successfully
+ */
+ UWAC_API UwacReturnCode UwacDestroyWindow(UwacWindow** window);
+
+ /**
+ * Sets the region that should be considered opaque to the compositor.
+ *
+ * @param window the UwacWindow
+ * @param x The horizontal coordinate in pixels
+ * @param y The vertical coordinate in pixels
+ * @param width The width of the region
+ * @param height The height of the region
+ * @return UWAC_SUCCESS on success, an error otherwise
+ */
+ UWAC_API UwacReturnCode UwacWindowSetOpaqueRegion(UwacWindow* window, uint32_t x, uint32_t y,
+ uint32_t width, uint32_t height);
+
+ /**
+ * Sets the region of the window that can trigger input events
+ *
+ * @param window the UwacWindow
+ * @param x The horizontal coordinate in pixels
+ * @param y The vertical coordinate in pixels
+ * @param width The width of the region
+ * @param height The height of the region
+ * @return UWAC_SUCCESS on success, an error otherwise
+ */
+ UWAC_API UwacReturnCode UwacWindowSetInputRegion(UwacWindow* window, uint32_t x, uint32_t y,
+ uint32_t width, uint32_t height);
+
+ /**
+ * retrieves a pointer on the current window content to draw a frame
+ * @param window the UwacWindow
+ * @return a pointer on the current window content
+ */
+ UWAC_API void* UwacWindowGetDrawingBuffer(UwacWindow* window);
+
+ /**
+ * sets a rectangle as dirty for the next frame of a window
+ *
+ * @param window the UwacWindow
+ * @param x left coordinate
+ * @param y top coordinate
+ * @param width the width of the dirty rectangle
+ * @param height the height of the dirty rectangle
+ * @return UWAC_SUCCESS on success, an Uwac error otherwise
+ */
+ UWAC_API UwacReturnCode UwacWindowAddDamage(UwacWindow* window, uint32_t x, uint32_t y,
+ uint32_t width, uint32_t height);
+
+ /**
+ * returns the geometry of the given UwacWindow buffer
+ *
+ * @param window the UwacWindow
+ * @param geometry the geometry to fill
+ * @param stride the length of a buffer line in bytes
+ * @return UWAC_SUCCESS on success, an Uwac error otherwise
+ */
+ UWAC_API UwacReturnCode UwacWindowGetDrawingBufferGeometry(UwacWindow* window,
+ UwacSize* geometry, size_t* stride);
+
+ /**
+ * Sends a frame to the compositor with the content of the drawing buffer
+ *
+ * @param window the UwacWindow to refresh
+ * @param copyContentForNextFrame if true the content to display is copied in the next drawing
+ *buffer
+ * @return UWAC_SUCCESS if the operation was successful
+ */
+ UWAC_API UwacReturnCode UwacWindowSubmitBuffer(UwacWindow* window,
+ bool copyContentForNextFrame);
+
+ /**
+ * returns the geometry of the given UwacWindows
+ *
+ * @param window the UwacWindow
+ * @param geometry the geometry to fill
+ * @return UWAC_SUCCESS on success, an Uwac error otherwise
+ */
+ UWAC_API UwacReturnCode UwacWindowGetGeometry(UwacWindow* window, UwacSize* geometry);
+
+ /**
+ * Sets or unset the fact that the window is set fullscreen. After this call the
+ * application should get prepared to receive a configure event. The output is used
+ * only when going fullscreen, it is optional and not used when exiting fullscreen.
+ *
+ * @param window the UwacWindow
+ * @param output an optional UwacOutput to put the window fullscreen on
+ * @param isFullscreen set or unset fullscreen
+ * @return UWAC_SUCCESS if the operation was a success
+ */
+ UWAC_API UwacReturnCode UwacWindowSetFullscreenState(UwacWindow* window, UwacOutput* output,
+ bool isFullscreen);
+
+ /**
+ * When possible (depending on the shell) sets the title of the UwacWindow
+ *
+ * @param window the UwacWindow
+ * @param name title
+ */
+ UWAC_API void UwacWindowSetTitle(UwacWindow* window, const char* name);
+
+ /**
+ * Sets the app id of the UwacWindow
+ *
+ * @param window the UwacWindow
+ * @param app_id app id
+ */
+ UWAC_API void UwacWindowSetAppId(UwacWindow* window, const char* app_id);
+
+ /** Dispatch the display
+ *
+ * @param display The display to dispatch
+ * @param timeout The maximum time to wait in milliseconds (-1 == infinite).
+ * @return 1 for success, 0 if display not running, -1 on failure
+ */
+ UWAC_API int UwacDisplayDispatch(UwacDisplay* display, int timeout);
+
+ /**
+ * Returns if you have some pending events, and you can UwacNextEvent() without blocking
+ *
+ * @param display the UwacDisplay
+ * @return if there's some pending events
+ */
+ UWAC_API bool UwacHasEvent(UwacDisplay* display);
+
+ /** Waits until an event occurs, and when it's there copy the event from the queue to
+ * event.
+ *
+ * @param display the Uwac display
+ * @param event the event to fill
+ * @return if the operation completed successfully
+ */
+ UWAC_API UwacReturnCode UwacNextEvent(UwacDisplay* display, UwacEvent* event);
+
+ /**
+ * returns the name of the given UwacSeat
+ *
+ * @param seat the UwacSeat
+ * @return the name of the seat
+ */
+ UWAC_API const char* UwacSeatGetName(const UwacSeat* seat);
+
+ /**
+ * returns the id of the given UwacSeat
+ *
+ * @param seat the UwacSeat
+ * @return the id of the seat
+ */
+ UWAC_API UwacSeatId UwacSeatGetId(const UwacSeat* seat);
+
+ /**
+ *
+ */
+ UWAC_API UwacReturnCode UwacClipboardOfferDestroy(UwacSeat* seat);
+ UWAC_API UwacReturnCode UwacClipboardOfferCreate(UwacSeat* seat, const char* mime);
+ UWAC_API UwacReturnCode UwacClipboardOfferAnnounce(UwacSeat* seat, void* context,
+ UwacDataTransferHandler transfer,
+ UwacCancelDataTransferHandler cancel);
+ UWAC_API void* UwacClipboardDataGet(UwacSeat* seat, const char* mime, size_t* size);
+
+ /**
+ * Inhibits or restores keyboard shortcuts.
+ *
+ * @param seat The UwacSeat to inhibit the shortcuts for
+ * @param inhibit Inhibit or restore keyboard shortcuts
+ *
+ * @return UWAC_SUCCESS or an appropriate error code.
+ */
+ UWAC_API UwacReturnCode UwacSeatInhibitShortcuts(UwacSeat* seat, bool inhibit);
+
+ /**
+ * @brief UwacSeatSetMouseCursor Sets the specified image as the new mouse cursor.
+ * Special values: If data == NULL && lenght == 0
+ * the cursor is hidden, if data == NULL && length != 0
+ * the default system cursor is used.
+ *
+ * @param seat The UwacSeat to apply the cursor image to
+ * @param data A pointer to the image data
+ * @param length The size of the image data
+ * @param width The image width in pixel
+ * @param height The image height in pixel
+ * @param hot_x The hotspot horizontal offset in pixel
+ * @param hot_y The hotspot vertical offset in pixel
+ *
+ * @return UWAC_SUCCESS if successful, an appropriate error otherwise.
+ */
+ UWAC_API UwacReturnCode UwacSeatSetMouseCursor(UwacSeat* seat, const void* data, size_t length,
+ size_t width, size_t height, size_t hot_x,
+ size_t hot_y);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UWAC_H_ */
diff --git a/uwac/libuwac/CMakeLists.txt b/uwac/libuwac/CMakeLists.txt
new file mode 100644
index 0000000..9d57ad8
--- /dev/null
+++ b/uwac/libuwac/CMakeLists.txt
@@ -0,0 +1,103 @@
+# UWAC: Using Wayland As Client
+#
+# Copyright 2015 David FORT <contact@hardening-consulting.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(MODULE_NAME "uwac")
+set(MODULE_PREFIX "UWAC")
+
+set(GENERATED_SOURCES "")
+macro(generate_protocol_file PROTO)
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/protocols/${PROTO}-protocol.c"
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/protocols
+ COMMAND ${WAYLAND_SCANNER} code < ${CMAKE_CURRENT_SOURCE_DIR}/../protocols/${PROTO}.xml > ${CMAKE_CURRENT_BINARY_DIR}/protocols/${PROTO}-protocol.c
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../protocols/${PROTO}.xml
+ )
+
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/protocols/${PROTO}-client-protocol.h"
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/protocols
+ COMMAND ${WAYLAND_SCANNER} client-header < ${CMAKE_CURRENT_SOURCE_DIR}/../protocols/${PROTO}.xml > ${CMAKE_CURRENT_BINARY_DIR}/protocols/${PROTO}-client-protocol.h
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../protocols/${PROTO}.xml
+ )
+
+ list(APPEND GENERATED_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/protocols/${PROTO}-client-protocol.h)
+ list(APPEND GENERATED_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/protocols/${PROTO}-protocol.c)
+endmacro()
+
+generate_protocol_file(xdg-shell)
+generate_protocol_file(viewporter)
+generate_protocol_file(xdg-decoration-unstable-v1)
+generate_protocol_file(server-decoration)
+generate_protocol_file(ivi-application)
+generate_protocol_file(fullscreen-shell-unstable-v1)
+generate_protocol_file(keyboard-shortcuts-inhibit-unstable-v1)
+
+if(FREEBSD)
+ include_directories(${EPOLLSHIM_INCLUDE_DIR})
+endif()
+include_directories(${WAYLAND_INCLUDE_DIR})
+include_directories(${XKBCOMMON_INCLUDE_DIR})
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../include")
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/../include")
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/protocols")
+
+add_definitions(-DBUILD_IVI -DBUILD_FULLSCREEN_SHELL -DENABLE_XKBCOMMON)
+
+set(${MODULE_PREFIX}_SRCS
+ ${GENERATED_SOURCES}
+ uwac-display.c
+ uwac-input.c
+ uwac-clipboard.c
+ uwac-os.c
+ uwac-os.h
+ uwac-output.c
+ uwac-priv.h
+ uwac-tools.c
+ uwac-utils.c
+ uwac-window.c)
+
+
+add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
+
+set_target_properties(${MODULE_NAME} PROPERTIES LINKER_LANGUAGE C)
+set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME ${MODULE_NAME}${UWAC_API_VERSION})
+if (WITH_LIBRARY_VERSIONING)
+ set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${UWAC_VERSION} SOVERSION ${UWAC_API_VERSION})
+endif()
+
+target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS} PRIVATE ${WAYLAND_LIBS} ${XKBCOMMON_LIBS} ${EPOLLSHIM_LIBS})
+if (UWAC_HAVE_PIXMAN_REGION)
+ target_link_libraries(${MODULE_NAME} PRIVATE ${pixman_LINK_LIBRARIES})
+else()
+ target_link_libraries(${MODULE_NAME} PRIVATE freerdp)
+endif()
+
+target_link_libraries(${MODULE_NAME} PRIVATE m)
+
+if (NOT UWAC_FORCE_STATIC_BUILD)
+ target_include_directories(${MODULE_NAME} INTERFACE $<INSTALL_INTERFACE:include/uwac${UWAC_API_VERSION}>)
+
+ install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT uwac
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+endif()
+
+set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "uwac")
+
+if(BUILD_TESTING)
+# add_subdirectory(test)
+endif()
diff --git a/uwac/libuwac/uwac-clipboard.c b/uwac/libuwac/uwac-clipboard.c
new file mode 100644
index 0000000..216d70a
--- /dev/null
+++ b/uwac/libuwac/uwac-clipboard.c
@@ -0,0 +1,280 @@
+/*
+ * Copyright © 2018 Armin Novak <armin.novak@thincast.com>
+ * Copyright © 2018 Thincast Technologies GmbH
+ *
+ * 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.
+ */
+#include "uwac-priv.h"
+#include "uwac-utils.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/timerfd.h>
+#include <sys/epoll.h>
+
+/* paste */
+static void data_offer_offer(void* data, struct wl_data_offer* data_offer,
+ const char* offered_mime_type)
+{
+ UwacSeat* seat = (UwacSeat*)data;
+
+ assert(seat);
+ if (!seat->ignore_announcement)
+ {
+ UwacClipboardEvent* event =
+ (UwacClipboardEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_CLIPBOARD_OFFER);
+
+ if (!event)
+ {
+ assert(uwacErrorHandler(seat->display, UWAC_ERROR_INTERNAL,
+ "failed to allocate a clipboard event\n"));
+ }
+ else
+ {
+ event->seat = seat;
+ snprintf(event->mime, sizeof(event->mime), "%s", offered_mime_type);
+ }
+ }
+}
+
+static const struct wl_data_offer_listener data_offer_listener = { .offer = data_offer_offer };
+
+static void data_device_data_offer(void* data, struct wl_data_device* data_device,
+ struct wl_data_offer* data_offer)
+{
+ UwacSeat* seat = (UwacSeat*)data;
+
+ assert(seat);
+ if (!seat->ignore_announcement)
+ {
+ UwacClipboardEvent* event =
+ (UwacClipboardEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_CLIPBOARD_SELECT);
+
+ if (!event)
+ {
+ assert(uwacErrorHandler(seat->display, UWAC_ERROR_INTERNAL,
+ "failed to allocate a close event\n"));
+ }
+ else
+ event->seat = seat;
+
+ wl_data_offer_add_listener(data_offer, &data_offer_listener, data);
+ seat->offer = data_offer;
+ }
+ else
+ seat->offer = NULL;
+}
+
+static void data_device_selection(void* data, struct wl_data_device* data_device,
+ struct wl_data_offer* data_offer)
+{
+}
+
+static const struct wl_data_device_listener data_device_listener = {
+ .data_offer = data_device_data_offer, .selection = data_device_selection
+};
+
+/* copy */
+static void data_source_target_handler(void* data, struct wl_data_source* data_source,
+ const char* mime_type)
+{
+}
+
+static void data_source_send_handler(void* data, struct wl_data_source* data_source,
+ const char* mime_type, int fd)
+{
+ UwacSeat* seat = (UwacSeat*)data;
+ seat->transfer_data(seat, seat->data_context, mime_type, fd);
+}
+
+static void data_source_cancelled_handler(void* data, struct wl_data_source* data_source)
+{
+ UwacSeat* seat = (UwacSeat*)data;
+ seat->cancel_data(seat, seat->data_context);
+}
+
+static const struct wl_data_source_listener data_source_listener = {
+ .target = data_source_target_handler,
+ .send = data_source_send_handler,
+ .cancelled = data_source_cancelled_handler
+};
+
+static void UwacRegisterDeviceListener(UwacSeat* s)
+{
+ wl_data_device_add_listener(s->data_device, &data_device_listener, s);
+}
+
+static UwacReturnCode UwacCreateDataSource(UwacSeat* s)
+{
+ if (!s)
+ return UWAC_ERROR_INTERNAL;
+
+ s->data_source = wl_data_device_manager_create_data_source(s->display->data_device_manager);
+ wl_data_source_add_listener(s->data_source, &data_source_listener, s);
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacSeatRegisterClipboard(UwacSeat* s)
+{
+ UwacClipboardEvent* event = NULL;
+
+ if (!s)
+ return UWAC_ERROR_INTERNAL;
+
+ if (!s->display->data_device_manager || !s->data_device)
+ return UWAC_NOT_ENOUGH_RESOURCES;
+
+ UwacRegisterDeviceListener(s);
+
+ UwacReturnCode rc = UwacCreateDataSource(s);
+
+ if (rc != UWAC_SUCCESS)
+ return rc;
+ event = (UwacClipboardEvent*)UwacDisplayNewEvent(s->display, UWAC_EVENT_CLIPBOARD_AVAILABLE);
+
+ if (!event)
+ {
+ assert(uwacErrorHandler(s->display, UWAC_ERROR_INTERNAL,
+ "failed to allocate a clipboard event\n"));
+ return UWAC_ERROR_INTERNAL;
+ }
+
+ event->seat = s;
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacClipboardOfferDestroy(UwacSeat* seat)
+{
+ if (!seat)
+ return UWAC_ERROR_INTERNAL;
+
+ if (seat->data_source)
+ wl_data_source_destroy(seat->data_source);
+
+ return UwacCreateDataSource(seat);
+}
+
+UwacReturnCode UwacClipboardOfferCreate(UwacSeat* seat, const char* mime)
+{
+ if (!seat || !mime)
+ return UWAC_ERROR_INTERNAL;
+
+ wl_data_source_offer(seat->data_source, mime);
+ return UWAC_SUCCESS;
+}
+
+static void callback_done(void* data, struct wl_callback* callback, uint32_t serial)
+{
+ *(uint32_t*)data = serial;
+}
+
+static const struct wl_callback_listener callback_listener = { .done = callback_done };
+
+static uint32_t get_serial(UwacSeat* s)
+{
+ struct wl_callback* callback = NULL;
+ uint32_t serial = 0;
+ callback = wl_display_sync(s->display->display);
+ wl_callback_add_listener(callback, &callback_listener, &serial);
+
+ while (serial == 0)
+ {
+ wl_display_dispatch(s->display->display);
+ }
+
+ return serial;
+}
+
+UwacReturnCode UwacClipboardOfferAnnounce(UwacSeat* seat, void* context,
+ UwacDataTransferHandler transfer,
+ UwacCancelDataTransferHandler cancel)
+{
+ if (!seat)
+ return UWAC_ERROR_INTERNAL;
+
+ seat->data_context = context;
+ seat->transfer_data = transfer;
+ seat->cancel_data = cancel;
+ seat->ignore_announcement = true;
+ wl_data_device_set_selection(seat->data_device, seat->data_source, get_serial(seat));
+ wl_display_roundtrip(seat->display->display);
+ seat->ignore_announcement = false;
+ return UWAC_SUCCESS;
+}
+
+void* UwacClipboardDataGet(UwacSeat* seat, const char* mime, size_t* size)
+{
+ ssize_t r = 0;
+ size_t alloc = 0;
+ size_t pos = 0;
+ char* data = NULL;
+ int pipefd[2];
+
+ if (!seat || !mime || !size || !seat->offer)
+ return NULL;
+
+ *size = 0;
+ if (pipe(pipefd) != 0)
+ return NULL;
+
+ wl_data_offer_receive(seat->offer, mime, pipefd[1]);
+ close(pipefd[1]);
+ wl_display_roundtrip(seat->display->display);
+ wl_display_flush(seat->display->display);
+
+ do
+ {
+ void* tmp = NULL;
+ alloc += 1024;
+ tmp = xrealloc(data, alloc);
+ if (!tmp)
+ {
+ free(data);
+ close(pipefd[0]);
+ return NULL;
+ }
+
+ data = tmp;
+ r = read(pipefd[0], &data[pos], alloc - pos);
+ if (r > 0)
+ pos += r;
+ if (r < 0)
+ {
+ free(data);
+ close(pipefd[0]);
+ return NULL;
+ }
+ } while (r > 0);
+
+ close(pipefd[0]);
+ close(pipefd[1]);
+
+ if (alloc > 0)
+ {
+ data[pos] = '\0';
+ *size = pos + 1;
+ }
+ return data;
+}
diff --git a/uwac/libuwac/uwac-display.c b/uwac/libuwac/uwac-display.c
new file mode 100644
index 0000000..1b26e21
--- /dev/null
+++ b/uwac/libuwac/uwac-display.c
@@ -0,0 +1,794 @@
+/*
+ * Copyright © 2014 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+#include "uwac-priv.h"
+#include "uwac-utils.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/epoll.h>
+
+#include "uwac-os.h"
+#include "wayland-cursor.h"
+
+#define TARGET_COMPOSITOR_INTERFACE 3U
+#define TARGET_SHM_INTERFACE 1U
+#define TARGET_SHELL_INTERFACE 1U
+#define TARGET_DDM_INTERFACE 1U
+#define TARGET_SEAT_INTERFACE 5U
+#define TARGET_XDG_VERSION 5U /* The version of xdg-shell that we implement */
+
+#if !defined(NDEBUG)
+static const char* event_names[] = {
+ "new seat", "removed seat", "new output", "configure", "pointer enter",
+ "pointer leave", "pointer motion", "pointer buttons", "pointer axis", "keyboard enter",
+ "key", "touch frame begin", "touch up", "touch down", "touch motion",
+ "touch cancel", "touch frame end", "frame done", "close", NULL
+};
+#endif
+
+static bool uwac_default_error_handler(UwacDisplay* display, UwacReturnCode code, const char* msg,
+ ...)
+{
+ va_list args;
+ va_start(args, msg);
+ vfprintf(stderr, "%s", args);
+ va_end(args);
+ return false;
+}
+
+UwacErrorHandler uwacErrorHandler = uwac_default_error_handler;
+
+void UwacInstallErrorHandler(UwacErrorHandler handler)
+{
+ if (handler)
+ uwacErrorHandler = handler;
+ else
+ uwacErrorHandler = uwac_default_error_handler;
+}
+
+static void cb_shm_format(void* data, struct wl_shm* wl_shm, uint32_t format)
+{
+ UwacDisplay* d = data;
+
+ if (format == WL_SHM_FORMAT_RGB565)
+ d->has_rgb565 = true;
+
+ d->shm_formats_nb++;
+ d->shm_formats =
+ xrealloc((void*)d->shm_formats, sizeof(enum wl_shm_format) * d->shm_formats_nb);
+ d->shm_formats[d->shm_formats_nb - 1] = format;
+}
+
+static struct wl_shm_listener shm_listener = { cb_shm_format };
+
+static void xdg_shell_ping(void* data, struct xdg_wm_base* xdg_wm_base, uint32_t serial)
+{
+ xdg_wm_base_pong(xdg_wm_base, serial);
+}
+
+static const struct xdg_wm_base_listener xdg_wm_base_listener = {
+ xdg_shell_ping,
+};
+
+#ifdef BUILD_FULLSCREEN_SHELL
+static void fullscreen_capability(void* data,
+ struct zwp_fullscreen_shell_v1* zwp_fullscreen_shell_v1,
+ uint32_t capability)
+{
+}
+
+static const struct zwp_fullscreen_shell_v1_listener fullscreen_shell_listener = {
+ fullscreen_capability,
+};
+#endif
+
+static void display_destroy_seat(UwacDisplay* d, uint32_t name)
+{
+ UwacSeat* seat = NULL;
+ UwacSeat* tmp = NULL;
+ wl_list_for_each_safe(seat, tmp, &d->seats, link)
+ {
+ if (seat->seat_id == name)
+ {
+ UwacSeatDestroy(seat);
+ }
+ }
+}
+
+static void UwacSeatRegisterDDM(UwacSeat* seat)
+{
+ UwacDisplay* d = seat->display;
+ if (!d->data_device_manager)
+ return;
+
+ if (!seat->data_device)
+ seat->data_device =
+ wl_data_device_manager_get_data_device(d->data_device_manager, seat->seat);
+}
+
+static void UwacRegisterCursor(UwacSeat* seat)
+{
+ if (!seat || !seat->display || !seat->display->compositor)
+ return;
+
+ seat->pointer_surface = wl_compositor_create_surface(seat->display->compositor);
+}
+
+static void registry_handle_global(void* data, struct wl_registry* registry, uint32_t id,
+ const char* interface, uint32_t version)
+{
+ UwacDisplay* d = data;
+ UwacGlobal* global = NULL;
+ global = xzalloc(sizeof *global);
+ global->name = id;
+ global->interface = xstrdup(interface);
+ global->version = version;
+ wl_list_insert(d->globals.prev, &global->link);
+
+ if (strcmp(interface, "wl_compositor") == 0)
+ {
+ d->compositor = wl_registry_bind(registry, id, &wl_compositor_interface,
+ min(TARGET_COMPOSITOR_INTERFACE, version));
+ }
+ else if (strcmp(interface, "wl_shm") == 0)
+ {
+ d->shm =
+ wl_registry_bind(registry, id, &wl_shm_interface, min(TARGET_SHM_INTERFACE, version));
+ wl_shm_add_listener(d->shm, &shm_listener, d);
+ }
+ else if (strcmp(interface, "wl_output") == 0)
+ {
+ UwacOutput* output = NULL;
+ UwacOutputNewEvent* ev = NULL;
+ output = UwacCreateOutput(d, id, version);
+
+ if (!output)
+ {
+ assert(uwacErrorHandler(d, UWAC_ERROR_NOMEMORY, "unable to create output\n"));
+ return;
+ }
+
+ ev = (UwacOutputNewEvent*)UwacDisplayNewEvent(d, UWAC_EVENT_NEW_OUTPUT);
+
+ if (ev)
+ ev->output = output;
+ }
+ else if (strcmp(interface, "wl_seat") == 0)
+ {
+ UwacSeatNewEvent* ev = NULL;
+ UwacSeat* seat = NULL;
+ seat = UwacSeatNew(d, id, min(version, TARGET_SEAT_INTERFACE));
+
+ if (!seat)
+ {
+ assert(uwacErrorHandler(d, UWAC_ERROR_NOMEMORY, "unable to create new seat\n"));
+ return;
+ }
+
+ UwacSeatRegisterDDM(seat);
+ UwacSeatRegisterClipboard(seat);
+ UwacRegisterCursor(seat);
+ ev = (UwacSeatNewEvent*)UwacDisplayNewEvent(d, UWAC_EVENT_NEW_SEAT);
+
+ if (!ev)
+ {
+ assert(uwacErrorHandler(d, UWAC_ERROR_NOMEMORY, "unable to create new seat event\n"));
+ return;
+ }
+
+ ev->seat = seat;
+ }
+ else if (strcmp(interface, "wl_data_device_manager") == 0)
+ {
+ UwacSeat* seat = NULL;
+ UwacSeat* tmp = NULL;
+
+ d->data_device_manager = wl_registry_bind(registry, id, &wl_data_device_manager_interface,
+ min(TARGET_DDM_INTERFACE, version));
+
+ wl_list_for_each_safe(seat, tmp, &d->seats, link)
+ {
+ UwacSeatRegisterDDM(seat);
+ UwacSeatRegisterClipboard(seat);
+ UwacRegisterCursor(seat);
+ }
+ }
+ else if (strcmp(interface, "wl_shell") == 0)
+ {
+ d->shell = wl_registry_bind(registry, id, &wl_shell_interface,
+ min(TARGET_SHELL_INTERFACE, version));
+ }
+ else if (strcmp(interface, "xdg_wm_base") == 0)
+ {
+ d->xdg_base = wl_registry_bind(registry, id, &xdg_wm_base_interface, 1);
+ xdg_wm_base_add_listener(d->xdg_base, &xdg_wm_base_listener, d);
+ }
+ else if (strcmp(interface, "wp_viewporter") == 0)
+ {
+ d->viewporter = wl_registry_bind(registry, id, &wp_viewporter_interface, 1);
+ }
+ else if (strcmp(interface, "zwp_keyboard_shortcuts_inhibit_manager_v1") == 0)
+ {
+ d->keyboard_inhibit_manager =
+ wl_registry_bind(registry, id, &zwp_keyboard_shortcuts_inhibit_manager_v1_interface, 1);
+ }
+ else if (strcmp(interface, "zxdg_decoration_manager_v1") == 0)
+ {
+ d->deco_manager = wl_registry_bind(registry, id, &zxdg_decoration_manager_v1_interface, 1);
+ }
+ else if (strcmp(interface, "org_kde_kwin_server_decoration_manager") == 0)
+ {
+ d->kde_deco_manager =
+ wl_registry_bind(registry, id, &org_kde_kwin_server_decoration_manager_interface, 1);
+ }
+#if BUILD_IVI
+ else if (strcmp(interface, "ivi_application") == 0)
+ {
+ d->ivi_application = wl_registry_bind(registry, id, &ivi_application_interface, 1);
+ }
+#endif
+#if BUILD_FULLSCREEN_SHELL
+ else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0)
+ {
+ d->fullscreen_shell = wl_registry_bind(registry, id, &zwp_fullscreen_shell_v1_interface, 1);
+ zwp_fullscreen_shell_v1_add_listener(d->fullscreen_shell, &fullscreen_shell_listener, d);
+ }
+#endif
+#if 0
+ else if (strcmp(interface, "text_cursor_position") == 0)
+ {
+ d->text_cursor_position = wl_registry_bind(registry, id, &text_cursor_position_interface, 1);
+ }
+ else if (strcmp(interface, "workspace_manager") == 0)
+ {
+ //init_workspace_manager(d, id);
+ }
+ else if (strcmp(interface, "wl_subcompositor") == 0)
+ {
+ d->subcompositor = wl_registry_bind(registry, id, &wl_subcompositor_interface, 1);
+#endif
+}
+
+static void registry_handle_global_remove(void* data, struct wl_registry* registry, uint32_t name)
+{
+ UwacDisplay* d = data;
+ UwacGlobal* global = NULL;
+ UwacGlobal* tmp = NULL;
+ wl_list_for_each_safe(global, tmp, &d->globals, link)
+ {
+ if (global->name != name)
+ continue;
+
+#if 0
+
+ if (strcmp(global->interface, "wl_output") == 0)
+ display_destroy_output(d, name);
+
+#endif
+
+ if (strcmp(global->interface, "wl_seat") == 0)
+ {
+ UwacSeatRemovedEvent* ev = NULL;
+ display_destroy_seat(d, name);
+ ev = (UwacSeatRemovedEvent*)UwacDisplayNewEvent(d, UWAC_EVENT_REMOVED_SEAT);
+
+ if (ev)
+ ev->id = name;
+ }
+
+ wl_list_remove(&global->link);
+ free(global->interface);
+ free(global);
+ }
+}
+
+static void UwacDestroyGlobal(UwacGlobal* global)
+{
+ free(global->interface);
+ wl_list_remove(&global->link);
+ free(global);
+}
+
+static void* display_bind(UwacDisplay* display, uint32_t name, const struct wl_interface* interface,
+ uint32_t version)
+{
+ return wl_registry_bind(display->registry, name, interface, version);
+}
+
+static const struct wl_registry_listener registry_listener = { registry_handle_global,
+ registry_handle_global_remove };
+
+int UwacDisplayWatchFd(UwacDisplay* display, int fd, uint32_t events, UwacTask* task)
+{
+ struct epoll_event ep;
+ ep.events = events;
+ ep.data.ptr = task;
+ return epoll_ctl(display->epoll_fd, EPOLL_CTL_ADD, fd, &ep);
+}
+
+static void UwacDisplayUnwatchFd(UwacDisplay* display, int fd)
+{
+ epoll_ctl(display->epoll_fd, EPOLL_CTL_DEL, fd, NULL);
+}
+
+static void display_exit(UwacDisplay* display)
+{
+ display->running = false;
+}
+
+static void display_dispatch_events(UwacTask* task, uint32_t events)
+{
+ UwacDisplay* display = container_of(task, UwacDisplay, dispatch_fd_task);
+ struct epoll_event ep;
+ int ret = 0;
+ display->display_fd_events = events;
+
+ if ((events & EPOLLERR) || (events & EPOLLHUP))
+ {
+ display_exit(display);
+ return;
+ }
+
+ if (events & EPOLLIN)
+ {
+ ret = wl_display_dispatch(display->display);
+
+ if (ret == -1)
+ {
+ display_exit(display);
+ return;
+ }
+ }
+
+ if (events & EPOLLOUT)
+ {
+ ret = wl_display_flush(display->display);
+
+ if (ret == 0)
+ {
+ ep.events = EPOLLIN | EPOLLERR | EPOLLHUP;
+ ep.data.ptr = &display->dispatch_fd_task;
+ epoll_ctl(display->epoll_fd, EPOLL_CTL_MOD, display->display_fd, &ep);
+ }
+ else if (ret == -1 && errno != EAGAIN)
+ {
+ display_exit(display);
+ return;
+ }
+ }
+}
+
+UwacDisplay* UwacOpenDisplay(const char* name, UwacReturnCode* err)
+{
+ UwacDisplay* ret = NULL;
+ ret = (UwacDisplay*)xzalloc(sizeof(*ret));
+
+ if (!ret)
+ {
+ *err = UWAC_ERROR_NOMEMORY;
+ return NULL;
+ }
+
+ wl_list_init(&ret->globals);
+ wl_list_init(&ret->seats);
+ wl_list_init(&ret->outputs);
+ wl_list_init(&ret->windows);
+ ret->display = wl_display_connect(name);
+
+ if (ret->display == NULL)
+ {
+ fprintf(stderr, "failed to connect to Wayland display %s: %m\n", name);
+ *err = UWAC_ERROR_UNABLE_TO_CONNECT;
+ goto out_free;
+ }
+
+ ret->epoll_fd = uwac_os_epoll_create_cloexec();
+
+ if (ret->epoll_fd < 0)
+ {
+ *err = UWAC_NOT_ENOUGH_RESOURCES;
+ goto out_disconnect;
+ }
+
+ ret->display_fd = wl_display_get_fd(ret->display);
+ ret->registry = wl_display_get_registry(ret->display);
+
+ if (!ret->registry)
+ {
+ *err = UWAC_ERROR_NOMEMORY;
+ goto out_close_epoll;
+ }
+
+ wl_registry_add_listener(ret->registry, &registry_listener, ret);
+
+ if ((wl_display_roundtrip(ret->display) < 0) || (wl_display_roundtrip(ret->display) < 0))
+ {
+ uwacErrorHandler(ret, UWAC_ERROR_UNABLE_TO_CONNECT,
+ "Failed to process Wayland connection: %m\n");
+ *err = UWAC_ERROR_UNABLE_TO_CONNECT;
+ goto out_free_registry;
+ }
+
+ ret->dispatch_fd_task.run = display_dispatch_events;
+
+ if (UwacDisplayWatchFd(ret, ret->display_fd, EPOLLIN | EPOLLERR | EPOLLHUP,
+ &ret->dispatch_fd_task) < 0)
+ {
+ uwacErrorHandler(ret, UWAC_ERROR_INTERNAL, "unable to watch display fd: %m\n");
+ *err = UWAC_ERROR_INTERNAL;
+ goto out_free_registry;
+ }
+
+ ret->running = true;
+ ret->last_error = *err = UWAC_SUCCESS;
+ return ret;
+out_free_registry:
+ wl_registry_destroy(ret->registry);
+out_close_epoll:
+ close(ret->epoll_fd);
+out_disconnect:
+ wl_display_disconnect(ret->display);
+out_free:
+ free(ret);
+ return NULL;
+}
+
+int UwacDisplayDispatch(UwacDisplay* display, int timeout)
+{
+ int ret = 0;
+ int count = 0;
+ UwacTask* task = NULL;
+ struct epoll_event ep[16];
+ wl_display_dispatch_pending(display->display);
+
+ if (!display->running)
+ return 0;
+
+ ret = wl_display_flush(display->display);
+
+ if (ret < 0 && errno == EAGAIN)
+ {
+ ep[0].events = (EPOLLIN | EPOLLOUT | EPOLLERR | EPOLLHUP);
+ ep[0].data.ptr = &display->dispatch_fd_task;
+ epoll_ctl(display->epoll_fd, EPOLL_CTL_MOD, display->display_fd, &ep[0]);
+ }
+ else if (ret < 0)
+ {
+ return -1;
+ }
+
+ count = epoll_wait(display->epoll_fd, ep, ARRAY_LENGTH(ep), timeout);
+
+ for (int i = 0; i < count; i++)
+ {
+ task = ep[i].data.ptr;
+ task->run(task, ep[i].events);
+ }
+
+ return 1;
+}
+
+UwacReturnCode UwacDisplayGetLastError(const UwacDisplay* display)
+{
+ return display->last_error;
+}
+
+UwacReturnCode UwacCloseDisplay(UwacDisplay** pdisplay)
+{
+ UwacDisplay* display = NULL;
+ UwacSeat* seat = NULL;
+ UwacSeat* tmpSeat = NULL;
+ UwacWindow* window = NULL;
+ UwacWindow* tmpWindow = NULL;
+ UwacOutput* output = NULL;
+ UwacOutput* tmpOutput = NULL;
+ UwacGlobal* global = NULL;
+ UwacGlobal* tmpGlobal = NULL;
+ assert(pdisplay);
+ display = *pdisplay;
+
+ if (!display)
+ return UWAC_ERROR_INVALID_DISPLAY;
+
+ /* destroy windows */
+ wl_list_for_each_safe(window, tmpWindow, &display->windows, link)
+ {
+ UwacDestroyWindow(&window);
+ }
+ /* destroy seats */
+ wl_list_for_each_safe(seat, tmpSeat, &display->seats, link)
+ {
+ UwacSeatDestroy(seat);
+ }
+ /* destroy output */
+ wl_list_for_each_safe(output, tmpOutput, &display->outputs, link)
+ {
+ UwacDestroyOutput(output);
+ }
+ /* destroy globals */
+ wl_list_for_each_safe(global, tmpGlobal, &display->globals, link)
+ {
+ UwacDestroyGlobal(global);
+ }
+
+ if (display->compositor)
+ wl_compositor_destroy(display->compositor);
+
+ if (display->keyboard_inhibit_manager)
+ zwp_keyboard_shortcuts_inhibit_manager_v1_destroy(display->keyboard_inhibit_manager);
+
+ if (display->deco_manager)
+ zxdg_decoration_manager_v1_destroy(display->deco_manager);
+
+ if (display->kde_deco_manager)
+ org_kde_kwin_server_decoration_manager_destroy(display->kde_deco_manager);
+
+#ifdef BUILD_FULLSCREEN_SHELL
+
+ if (display->fullscreen_shell)
+ zwp_fullscreen_shell_v1_destroy(display->fullscreen_shell);
+
+#endif
+#ifdef BUILD_IVI
+
+ if (display->ivi_application)
+ ivi_application_destroy(display->ivi_application);
+
+#endif
+
+ if (display->xdg_toplevel)
+ xdg_toplevel_destroy(display->xdg_toplevel);
+
+ if (display->xdg_base)
+ xdg_wm_base_destroy(display->xdg_base);
+
+ if (display->shell)
+ wl_shell_destroy(display->shell);
+
+ if (display->shm)
+ wl_shm_destroy(display->shm);
+
+ if (display->viewporter)
+ wp_viewporter_destroy(display->viewporter);
+
+ if (display->subcompositor)
+ wl_subcompositor_destroy(display->subcompositor);
+
+ if (display->data_device_manager)
+ wl_data_device_manager_destroy(display->data_device_manager);
+
+ free(display->shm_formats);
+ wl_registry_destroy(display->registry);
+ close(display->epoll_fd);
+ wl_display_disconnect(display->display);
+
+ /* cleanup the event queue */
+ while (display->push_queue)
+ {
+ UwacEventListItem* item = display->push_queue;
+ display->push_queue = item->tail;
+ free(item);
+ }
+
+ free(display);
+ *pdisplay = NULL;
+ return UWAC_SUCCESS;
+}
+
+int UwacDisplayGetFd(UwacDisplay* display)
+{
+ return display->epoll_fd;
+}
+
+static const char* errorStrings[] = {
+ "success",
+ "out of memory error",
+ "unable to connect to wayland display",
+ "invalid UWAC display",
+ "not enough resources",
+ "timed out",
+ "not found",
+ "closed connection",
+
+ "internal error",
+};
+
+const char* UwacErrorString(UwacReturnCode error)
+{
+ if (error < UWAC_SUCCESS || error >= UWAC_ERROR_LAST)
+ return "invalid error code";
+
+ return errorStrings[error];
+}
+
+UwacReturnCode UwacDisplayQueryInterfaceVersion(const UwacDisplay* display, const char* name,
+ uint32_t* version)
+{
+ const UwacGlobal* global = NULL;
+ const UwacGlobal* tmp = NULL;
+
+ if (!display)
+ return UWAC_ERROR_INVALID_DISPLAY;
+
+ wl_list_for_each_safe(global, tmp, &display->globals, link)
+ {
+ if (strcmp(global->interface, name) == 0)
+ {
+ if (version)
+ *version = global->version;
+
+ return UWAC_SUCCESS;
+ }
+ }
+ return UWAC_NOT_FOUND;
+}
+
+uint32_t UwacDisplayQueryGetNbShmFormats(UwacDisplay* display)
+{
+ if (!display)
+ {
+ return 0;
+ }
+
+ if (!display->shm)
+ {
+ display->last_error = UWAC_NOT_FOUND;
+ return 0;
+ }
+
+ display->last_error = UWAC_SUCCESS;
+ return display->shm_formats_nb;
+}
+
+UwacReturnCode UwacDisplayQueryShmFormats(const UwacDisplay* display, enum wl_shm_format* formats,
+ int formats_size, int* filled)
+{
+ if (!display)
+ return UWAC_ERROR_INVALID_DISPLAY;
+
+ *filled = min((int64_t)display->shm_formats_nb, formats_size);
+ memcpy(formats, (const void*)display->shm_formats, *filled * sizeof(enum wl_shm_format));
+ return UWAC_SUCCESS;
+}
+
+uint32_t UwacDisplayGetNbOutputs(const UwacDisplay* display)
+{
+ return wl_list_length(&display->outputs);
+}
+
+const UwacOutput* UwacDisplayGetOutput(UwacDisplay* display, int index)
+{
+ int i = 0;
+ int display_count = 0;
+ UwacOutput* ret = NULL;
+
+ if (!display)
+ return NULL;
+
+ display_count = wl_list_length(&display->outputs);
+ if (display_count <= index)
+ return NULL;
+
+ wl_list_for_each(ret, &display->outputs, link)
+ {
+ if (i == index)
+ break;
+ i++;
+ }
+
+ if (!ret)
+ {
+ display->last_error = UWAC_NOT_FOUND;
+ return NULL;
+ }
+
+ display->last_error = UWAC_SUCCESS;
+ return ret;
+}
+
+UwacReturnCode UwacOutputGetResolution(const UwacOutput* output, UwacSize* resolution)
+{
+ if ((output->resolution.height <= 0) || (output->resolution.width <= 0))
+ return UWAC_ERROR_INTERNAL;
+
+ *resolution = output->resolution;
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacOutputGetPosition(const UwacOutput* output, UwacPosition* pos)
+{
+ *pos = output->position;
+ return UWAC_SUCCESS;
+}
+
+UwacEvent* UwacDisplayNewEvent(UwacDisplay* display, int type)
+{
+ UwacEventListItem* ret = NULL;
+
+ if (!display)
+ {
+ return 0;
+ }
+
+ ret = xzalloc(sizeof(UwacEventListItem));
+
+ if (!ret)
+ {
+ assert(uwacErrorHandler(display, UWAC_ERROR_NOMEMORY, "unable to allocate a '%s' event",
+ event_names[type]));
+ display->last_error = UWAC_ERROR_NOMEMORY;
+ return 0;
+ }
+
+ ret->event.type = type;
+ ret->tail = display->push_queue;
+
+ if (ret->tail)
+ ret->tail->head = ret;
+ else
+ display->pop_queue = ret;
+
+ display->push_queue = ret;
+ return &ret->event;
+}
+
+bool UwacHasEvent(UwacDisplay* display)
+{
+ return display->pop_queue != NULL;
+}
+
+UwacReturnCode UwacNextEvent(UwacDisplay* display, UwacEvent* event)
+{
+ UwacEventListItem* prevItem = NULL;
+ int ret = 0;
+
+ if (!display)
+ return UWAC_ERROR_INVALID_DISPLAY;
+
+ while (!display->pop_queue)
+ {
+ ret = UwacDisplayDispatch(display, 1 * 1000);
+
+ if (ret < 0)
+ return UWAC_ERROR_INTERNAL;
+ else if (ret == 0)
+ return UWAC_ERROR_CLOSED;
+ }
+
+ prevItem = display->pop_queue->head;
+ *event = display->pop_queue->event;
+ free(display->pop_queue);
+ display->pop_queue = prevItem;
+
+ if (prevItem)
+ prevItem->tail = NULL;
+ else
+ display->push_queue = NULL;
+
+ return UWAC_SUCCESS;
+}
diff --git a/uwac/libuwac/uwac-input.c b/uwac/libuwac/uwac-input.c
new file mode 100644
index 0000000..5ad52ae
--- /dev/null
+++ b/uwac/libuwac/uwac-input.c
@@ -0,0 +1,1277 @@
+/*
+ * Copyright © 2014-2015 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+#include "uwac-priv.h"
+#include "uwac-utils.h"
+
+#include <stdio.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <sys/timerfd.h>
+#include <sys/epoll.h>
+
+#include "uwac-os.h"
+#include "wayland-cursor.h"
+#include "wayland-client-protocol.h"
+
+static struct wl_buffer* create_pointer_buffer(UwacSeat* seat, const void* src, size_t size)
+{
+ struct wl_buffer* buffer = NULL;
+ int fd = 0;
+ void* data = NULL;
+ struct wl_shm_pool* pool = NULL;
+
+ assert(seat);
+
+ fd = uwac_create_anonymous_file(size);
+
+ if (fd < 0)
+ return buffer;
+
+ data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+ if (data == MAP_FAILED)
+ {
+ goto error_mmap;
+ }
+ memcpy(data, src, size);
+
+ pool = wl_shm_create_pool(seat->display->shm, fd, size);
+
+ if (!pool)
+ {
+ munmap(data, size);
+ goto error_mmap;
+ }
+
+ buffer =
+ wl_shm_pool_create_buffer(pool, 0, seat->pointer_image->width, seat->pointer_image->height,
+ seat->pointer_image->width * 4, WL_SHM_FORMAT_ARGB8888);
+ wl_shm_pool_destroy(pool);
+
+ if (munmap(data, size) < 0)
+ fprintf(stderr, "%s: munmap(%p, %zu) failed with [%d] %s\n", __func__, data, size, errno,
+ strerror(errno));
+
+error_mmap:
+ close(fd);
+ return buffer;
+}
+
+static void on_buffer_release(void* data, struct wl_buffer* wl_buffer)
+{
+ (void)data;
+ wl_buffer_destroy(wl_buffer);
+}
+
+static const struct wl_buffer_listener buffer_release_listener = { on_buffer_release };
+
+static UwacReturnCode set_cursor_image(UwacSeat* seat, uint32_t serial)
+{
+ struct wl_buffer* buffer = NULL;
+ struct wl_cursor* cursor = NULL;
+ struct wl_cursor_image* image = NULL;
+ struct wl_surface* surface = NULL;
+ int32_t x = 0;
+ int32_t y = 0;
+
+ if (!seat || !seat->display || !seat->default_cursor || !seat->default_cursor->images)
+ return UWAC_ERROR_INTERNAL;
+
+ int scale = 1;
+ if (seat->pointer_focus)
+ scale = seat->pointer_focus->display->actual_scale;
+
+ switch (seat->pointer_type)
+ {
+ case 2: /* Custom poiner */
+ image = seat->pointer_image;
+ buffer = create_pointer_buffer(seat, seat->pointer_data, seat->pointer_size);
+ if (!buffer)
+ return UWAC_ERROR_INTERNAL;
+ if (wl_buffer_add_listener(buffer, &buffer_release_listener, seat) < 0)
+ return UWAC_ERROR_INTERNAL;
+
+ surface = seat->pointer_surface;
+ x = image->hotspot_x / scale;
+ y = image->hotspot_y / scale;
+ break;
+ case 1: /* NULL pointer */
+ break;
+ default: /* Default system pointer */
+ cursor = seat->default_cursor;
+ if (!cursor)
+ return UWAC_ERROR_INTERNAL;
+ image = cursor->images[0];
+ if (!image)
+ return UWAC_ERROR_INTERNAL;
+ x = image->hotspot_x;
+ y = image->hotspot_y;
+ buffer = wl_cursor_image_get_buffer(image);
+ if (!buffer)
+ return UWAC_ERROR_INTERNAL;
+ surface = seat->pointer_surface;
+ break;
+ }
+
+ if (surface && buffer)
+ {
+ wl_surface_set_buffer_scale(surface, scale);
+ wl_surface_attach(surface, buffer, 0, 0);
+ wl_surface_damage(surface, 0, 0, image->width, image->height);
+ wl_surface_commit(surface);
+ }
+
+ wl_pointer_set_cursor(seat->pointer, serial, surface, x, y);
+
+ return UWAC_SUCCESS;
+}
+
+static void keyboard_repeat_func(UwacTask* task, uint32_t events)
+{
+ UwacSeat* input = container_of(task, UwacSeat, repeat_task);
+ assert(input);
+ UwacWindow* window = input->keyboard_focus;
+ uint64_t exp = 0;
+
+ if (read(input->repeat_timer_fd, &exp, sizeof exp) != sizeof exp)
+ /* If we change the timer between the fd becoming
+ * readable and getting here, there'll be nothing to
+ * read and we get EAGAIN. */
+ return;
+
+ if (window)
+ {
+ UwacKeyEvent* key = NULL;
+
+ key = (UwacKeyEvent*)UwacDisplayNewEvent(input->display, UWAC_EVENT_KEY);
+ if (!key)
+ return;
+
+ key->window = window;
+ key->sym = input->repeat_sym;
+ key->raw_key = input->repeat_key;
+ key->pressed = true;
+ key->repeated = true;
+ }
+}
+
+static void keyboard_handle_keymap(void* data, struct wl_keyboard* keyboard, uint32_t format,
+ int fd, uint32_t size)
+{
+ UwacSeat* input = data;
+ struct xkb_keymap* keymap = NULL;
+ struct xkb_state* state = NULL;
+ char* map_str = NULL;
+ int mapFlags = MAP_SHARED;
+
+ if (!data)
+ {
+ close(fd);
+ return;
+ }
+
+ if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1)
+ {
+ close(fd);
+ return;
+ }
+
+ if (input->seat_version >= 7)
+ mapFlags = MAP_PRIVATE;
+
+ map_str = mmap(NULL, size, PROT_READ, mapFlags, fd, 0);
+ if (map_str == MAP_FAILED)
+ {
+ close(fd);
+ return;
+ }
+
+ keymap = xkb_keymap_new_from_string(input->xkb_context, map_str, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+ munmap(map_str, size);
+ close(fd);
+
+ if (!keymap)
+ {
+ assert(uwacErrorHandler(input->display, UWAC_ERROR_INTERNAL, "failed to compile keymap\n"));
+ return;
+ }
+
+ state = xkb_state_new(keymap);
+ if (!state)
+ {
+ assert(
+ uwacErrorHandler(input->display, UWAC_ERROR_NOMEMORY, "failed to create XKB state\n"));
+ xkb_keymap_unref(keymap);
+ return;
+ }
+
+ xkb_keymap_unref(input->xkb.keymap);
+ xkb_state_unref(input->xkb.state);
+ input->xkb.keymap = keymap;
+ input->xkb.state = state;
+
+ input->xkb.control_mask = 1 << xkb_keymap_mod_get_index(input->xkb.keymap, "Control");
+ input->xkb.alt_mask = 1 << xkb_keymap_mod_get_index(input->xkb.keymap, "Mod1");
+ input->xkb.shift_mask = 1 << xkb_keymap_mod_get_index(input->xkb.keymap, "Shift");
+ input->xkb.caps_mask = 1 << xkb_keymap_mod_get_index(input->xkb.keymap, "Lock");
+ input->xkb.num_mask = 1 << xkb_keymap_mod_get_index(input->xkb.keymap, "Mod2");
+}
+
+static void keyboard_handle_key(void* data, struct wl_keyboard* keyboard, uint32_t serial,
+ uint32_t time, uint32_t key, uint32_t state_w);
+
+static void keyboard_handle_enter(void* data, struct wl_keyboard* keyboard, uint32_t serial,
+ struct wl_surface* surface, struct wl_array* keys)
+{
+ UwacSeat* input = (UwacSeat*)data;
+ assert(input);
+
+ UwacKeyboardEnterLeaveEvent* event = (UwacKeyboardEnterLeaveEvent*)UwacDisplayNewEvent(
+ input->display, UWAC_EVENT_KEYBOARD_ENTER);
+ if (!event)
+ return;
+
+ event->window = input->keyboard_focus = (UwacWindow*)wl_surface_get_user_data(surface);
+ event->seat = input;
+
+ /* we may have the keys in the `keys` array, but as this function is called only
+ * when the window gets focus, so there may be keys from other unrelated windows, eg.
+ * this was leading to problems like passing CTRL+D to freerdp from closing terminal window
+ * if it was closing very fast and the keys was still pressed by the user while the freerdp
+ * gets focus
+ *
+ * currently just ignore this, as further key presses will be handled correctly anyway
+ */
+}
+
+static void keyboard_handle_leave(void* data, struct wl_keyboard* keyboard, uint32_t serial,
+ struct wl_surface* surface)
+{
+ struct itimerspec its = { 0 };
+ uint32_t* pressedKey = NULL;
+ size_t i = 0;
+
+ UwacSeat* input = (UwacSeat*)data;
+ assert(input);
+
+ its.it_interval.tv_sec = 0;
+ its.it_interval.tv_nsec = 0;
+ its.it_value.tv_sec = 0;
+ its.it_value.tv_nsec = 0;
+ timerfd_settime(input->repeat_timer_fd, 0, &its, NULL);
+
+ UwacPointerEnterLeaveEvent* event =
+ (UwacPointerEnterLeaveEvent*)UwacDisplayNewEvent(input->display, UWAC_EVENT_POINTER_LEAVE);
+ if (!event)
+ return;
+
+ event->window = input->keyboard_focus;
+
+ /* we are currently loosing input focus of the main window:
+ * check if we currently have some keys pressed and release them as if we enter the window again
+ * it will be still "virtually" pressed in remote even if in reality the key has been released
+ */
+ for (pressedKey = input->pressed_keys.data, i = 0; i < input->pressed_keys.size;
+ i += sizeof(uint32_t))
+ {
+ keyboard_handle_key(data, keyboard, serial, 0, *pressedKey, WL_KEYBOARD_KEY_STATE_RELEASED);
+ pressedKey++;
+ }
+}
+
+static int update_key_pressed(UwacSeat* seat, uint32_t key)
+{
+ uint32_t* keyPtr = NULL;
+ assert(seat);
+
+ /* check if the key is not already pressed */
+ wl_array_for_each(keyPtr, &seat->pressed_keys)
+ {
+ if (*keyPtr == key)
+ return 1;
+ }
+
+ keyPtr = wl_array_add(&seat->pressed_keys, sizeof(uint32_t));
+ if (!keyPtr)
+ return -1;
+
+ *keyPtr = key;
+ return 0;
+}
+
+static int update_key_released(UwacSeat* seat, uint32_t key)
+{
+ size_t toMove = 0;
+ bool found = false;
+
+ assert(seat);
+
+ size_t i = 0;
+ uint32_t* keyPtr = seat->pressed_keys.data;
+ for (; i < seat->pressed_keys.size; i++, keyPtr++)
+ {
+ if (*keyPtr == key)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if (found)
+ {
+ toMove = seat->pressed_keys.size - ((i + 1) * sizeof(uint32_t));
+ if (toMove)
+ memmove(keyPtr, keyPtr + 1, toMove);
+
+ seat->pressed_keys.size -= sizeof(uint32_t);
+ }
+ return 1;
+}
+
+static void keyboard_handle_key(void* data, struct wl_keyboard* keyboard, uint32_t serial,
+ uint32_t time, uint32_t key, uint32_t state_w)
+{
+ UwacSeat* input = (UwacSeat*)data;
+ assert(input);
+
+ UwacWindow* window = input->keyboard_focus;
+ UwacKeyEvent* keyEvent = NULL;
+
+ uint32_t code = 0;
+ uint32_t num_syms = 0;
+ enum wl_keyboard_key_state state = state_w;
+ const xkb_keysym_t* syms = NULL;
+ xkb_keysym_t sym = 0;
+ struct itimerspec its;
+
+ if (state_w == WL_KEYBOARD_KEY_STATE_PRESSED)
+ update_key_pressed(input, key);
+ else
+ update_key_released(input, key);
+
+ input->display->serial = serial;
+ code = key + 8;
+ if (!window || !input->xkb.state)
+ return;
+
+ /* We only use input grabs for pointer events for now, so just
+ * ignore key presses if a grab is active. We expand the key
+ * event delivery mechanism to route events to widgets to
+ * properly handle key grabs. In the meantime, this prevents
+ * key event delivery while a grab is active. */
+ /*if (input->grab && input->grab_button == 0)
+ return;*/
+
+ num_syms = xkb_state_key_get_syms(input->xkb.state, code, &syms);
+
+ sym = XKB_KEY_NoSymbol;
+ if (num_syms == 1)
+ sym = syms[0];
+
+ if (state == WL_KEYBOARD_KEY_STATE_RELEASED && key == input->repeat_key)
+ {
+ its.it_interval.tv_sec = 0;
+ its.it_interval.tv_nsec = 0;
+ its.it_value.tv_sec = 0;
+ its.it_value.tv_nsec = 0;
+ timerfd_settime(input->repeat_timer_fd, 0, &its, NULL);
+ }
+ else if (state == WL_KEYBOARD_KEY_STATE_PRESSED &&
+ xkb_keymap_key_repeats(input->xkb.keymap, code))
+ {
+ input->repeat_sym = sym;
+ input->repeat_key = key;
+ input->repeat_time = time;
+ its.it_interval.tv_sec = input->repeat_rate_sec;
+ its.it_interval.tv_nsec = input->repeat_rate_nsec;
+ its.it_value.tv_sec = input->repeat_delay_sec;
+ its.it_value.tv_nsec = input->repeat_delay_nsec;
+ timerfd_settime(input->repeat_timer_fd, 0, &its, NULL);
+ }
+
+ keyEvent = (UwacKeyEvent*)UwacDisplayNewEvent(input->display, UWAC_EVENT_KEY);
+ if (!keyEvent)
+ return;
+
+ keyEvent->window = window;
+ keyEvent->sym = sym;
+ keyEvent->raw_key = key;
+ keyEvent->pressed = (state == WL_KEYBOARD_KEY_STATE_PRESSED);
+ keyEvent->repeated = false;
+}
+
+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)
+{
+ UwacSeat* input = data;
+ assert(input);
+
+ UwacKeyboardModifiersEvent* event = NULL;
+ xkb_mod_mask_t mask = 0;
+
+ /* If we're not using a keymap, then we don't handle PC-style modifiers */
+ if (!input->xkb.keymap)
+ return;
+
+ xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched, mods_locked, 0, 0, group);
+ mask = xkb_state_serialize_mods(input->xkb.state, XKB_STATE_MODS_DEPRESSED |
+ XKB_STATE_MODS_LATCHED |
+ XKB_STATE_MODS_LOCKED);
+ input->modifiers = 0;
+ if (mask & input->xkb.control_mask)
+ input->modifiers |= UWAC_MOD_CONTROL_MASK;
+ if (mask & input->xkb.alt_mask)
+ input->modifiers |= UWAC_MOD_ALT_MASK;
+ if (mask & input->xkb.shift_mask)
+ input->modifiers |= UWAC_MOD_SHIFT_MASK;
+ if (mask & input->xkb.caps_mask)
+ input->modifiers |= UWAC_MOD_CAPS_MASK;
+ if (mask & input->xkb.num_mask)
+ input->modifiers |= UWAC_MOD_NUM_MASK;
+
+ event = (UwacKeyboardModifiersEvent*)UwacDisplayNewEvent(input->display,
+ UWAC_EVENT_KEYBOARD_MODIFIERS);
+ if (!event)
+ return;
+
+ event->modifiers = input->modifiers;
+}
+
+static void set_repeat_info(UwacSeat* input, int32_t rate, int32_t delay)
+{
+ assert(input);
+
+ input->repeat_rate_sec = input->repeat_rate_nsec = 0;
+ input->repeat_delay_sec = input->repeat_delay_nsec = 0;
+
+ /* a rate of zero disables any repeating, regardless of the delay's
+ * value */
+ if (rate == 0)
+ return;
+
+ if (rate == 1)
+ input->repeat_rate_sec = 1;
+ else
+ input->repeat_rate_nsec = 1000000000 / rate;
+
+ input->repeat_delay_sec = delay / 1000;
+ delay -= (input->repeat_delay_sec * 1000);
+ input->repeat_delay_nsec = delay * 1000 * 1000;
+}
+
+static void keyboard_handle_repeat_info(void* data, struct wl_keyboard* keyboard, int32_t rate,
+ int32_t delay)
+{
+ UwacSeat* input = data;
+ assert(input);
+
+ set_repeat_info(input, rate, delay);
+}
+
+static const struct wl_keyboard_listener keyboard_listener = {
+ keyboard_handle_keymap, keyboard_handle_enter, keyboard_handle_leave,
+ keyboard_handle_key, keyboard_handle_modifiers, keyboard_handle_repeat_info
+};
+
+static bool touch_send_start_frame(UwacSeat* seat)
+{
+ assert(seat);
+
+ UwacTouchFrameBegin* ev =
+ (UwacTouchFrameBegin*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_TOUCH_FRAME_BEGIN);
+ if (!ev)
+ return false;
+
+ seat->touch_frame_started = true;
+ return true;
+}
+
+static void touch_handle_down(void* data, struct wl_touch* wl_touch, uint32_t serial, uint32_t time,
+ struct wl_surface* surface, int32_t id, wl_fixed_t x_w,
+ wl_fixed_t y_w)
+{
+ UwacSeat* seat = data;
+ UwacTouchDown* tdata = NULL;
+
+ assert(seat);
+ assert(seat->display);
+
+ seat->display->serial = serial;
+ if (!seat->touch_frame_started && !touch_send_start_frame(seat))
+ return;
+
+ tdata = (UwacTouchDown*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_TOUCH_DOWN);
+ if (!tdata)
+ return;
+
+ tdata->seat = seat;
+ tdata->id = id;
+
+ float sx = wl_fixed_to_double(x_w);
+ float sy = wl_fixed_to_double(y_w);
+
+ tdata->x = sx;
+ tdata->y = sy;
+
+#if 0
+ struct widget *widget;
+ float sx = wl_fixed_to_double(x);
+ float sy = wl_fixed_to_double(y);
+
+
+ input->touch_focus = wl_surface_get_user_data(surface);
+ if (!input->touch_focus) {
+ DBG("Failed to find to touch focus for surface %p\n", (void*) surface);
+ return;
+ }
+
+ if (surface != input->touch_focus->main_surface->surface) {
+ DBG("Ignoring input event from subsurface %p\n", (void*) surface);
+ input->touch_focus = NULL;
+ return;
+ }
+
+ if (input->grab)
+ widget = input->grab;
+ else
+ widget = window_find_widget(input->touch_focus,
+ wl_fixed_to_double(x),
+ wl_fixed_to_double(y));
+ if (widget) {
+ struct touch_point *tp = xmalloc(sizeof *tp);
+ if (tp) {
+ tp->id = id;
+ tp->widget = widget;
+ tp->x = sx;
+ tp->y = sy;
+ wl_list_insert(&input->touch_point_list, &tp->link);
+
+ if (widget->touch_down_handler)
+ (*widget->touch_down_handler)(widget, input,
+ serial, time, id,
+ sx, sy,
+ widget->user_data);
+ }
+ }
+#endif
+}
+
+static void touch_handle_up(void* data, struct wl_touch* wl_touch, uint32_t serial, uint32_t time,
+ int32_t id)
+{
+ UwacSeat* seat = data;
+ UwacTouchUp* tdata = NULL;
+
+ assert(seat);
+
+ if (!seat->touch_frame_started && !touch_send_start_frame(seat))
+ return;
+
+ tdata = (UwacTouchUp*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_TOUCH_UP);
+ if (!tdata)
+ return;
+
+ tdata->seat = seat;
+ tdata->id = id;
+
+#if 0
+ struct touch_point *tp, *tmp;
+
+ if (!input->touch_focus) {
+ DBG("No touch focus found for touch up event!\n");
+ return;
+ }
+
+ wl_list_for_each_safe(tp, tmp, &input->touch_point_list, link) {
+ if (tp->id != id)
+ continue;
+
+ if (tp->widget->touch_up_handler)
+ (*tp->widget->touch_up_handler)(tp->widget, input, serial,
+ time, id,
+ tp->widget->user_data);
+
+ wl_list_remove(&tp->link);
+ free(tp);
+
+ return;
+ }
+#endif
+}
+
+static void touch_handle_motion(void* data, struct wl_touch* wl_touch, uint32_t time, int32_t id,
+ wl_fixed_t x_w, wl_fixed_t y_w)
+{
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacTouchMotion* tdata = NULL;
+
+ if (!seat->touch_frame_started && !touch_send_start_frame(seat))
+ return;
+
+ tdata = (UwacTouchMotion*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_TOUCH_MOTION);
+ if (!tdata)
+ return;
+
+ tdata->seat = seat;
+ tdata->id = id;
+
+ float sx = wl_fixed_to_double(x_w);
+ float sy = wl_fixed_to_double(y_w);
+
+ tdata->x = sx;
+ tdata->y = sy;
+
+#if 0
+ struct touch_point *tp;
+ float sx = wl_fixed_to_double(x);
+ float sy = wl_fixed_to_double(y);
+
+ DBG("touch_handle_motion: %i %i\n", id, wl_list_length(&seat->touch_point_list));
+
+ if (!seat->touch_focus) {
+ DBG("No touch focus found for touch motion event!\n");
+ return;
+ }
+
+ wl_list_for_each(tp, &seat->touch_point_list, link) {
+ if (tp->id != id)
+ continue;
+
+ tp->x = sx;
+ tp->y = sy;
+ if (tp->widget->touch_motion_handler)
+ (*tp->widget->touch_motion_handler)(tp->widget, seat, time,
+ id, sx, sy,
+ tp->widget->user_data);
+ return;
+ }
+#endif
+}
+
+static void touch_handle_frame(void* data, struct wl_touch* wl_touch)
+{
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacTouchFrameEnd* ev =
+ (UwacTouchFrameEnd*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_TOUCH_FRAME_END);
+ if (!ev)
+ return;
+
+ ev->seat = seat;
+ seat->touch_frame_started = false;
+}
+
+static void touch_handle_cancel(void* data, struct wl_touch* wl_touch)
+{
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacTouchCancel* ev =
+ (UwacTouchCancel*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_TOUCH_CANCEL);
+ if (!ev)
+ return;
+
+ ev->seat = seat;
+ seat->touch_frame_started = false;
+
+#if 0
+ struct touch_point *tp, *tmp;
+
+ DBG("touch_handle_cancel\n");
+
+ if (!input->touch_focus) {
+ DBG("No touch focus found for touch cancel event!\n");
+ return;
+ }
+
+ wl_list_for_each_safe(tp, tmp, &input->touch_point_list, link) {
+ if (tp->widget->touch_cancel_handler)
+ (*tp->widget->touch_cancel_handler)(tp->widget, input,
+ tp->widget->user_data);
+
+ wl_list_remove(&tp->link);
+ free(tp);
+ }
+#endif
+}
+
+static void touch_handle_shape(void* data, struct wl_touch* wl_touch, int32_t id, wl_fixed_t major,
+ wl_fixed_t minor)
+{
+ UwacSeat* seat = data;
+ assert(seat);
+
+ // TODO
+}
+
+static void touch_handle_orientation(void* data, struct wl_touch* wl_touch, int32_t id,
+ wl_fixed_t orientation)
+{
+ UwacSeat* seat = data;
+ assert(seat);
+
+ // TODO
+}
+
+static const struct wl_touch_listener touch_listener = {
+ touch_handle_down, touch_handle_up, touch_handle_motion, touch_handle_frame,
+ touch_handle_cancel, touch_handle_shape, touch_handle_orientation
+};
+
+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)
+{
+ UwacSeat* input = data;
+ UwacWindow* window = NULL;
+ UwacPointerEnterLeaveEvent* event = NULL;
+
+ assert(input);
+
+ float sx = wl_fixed_to_double(sx_w);
+ float sy = wl_fixed_to_double(sy_w);
+
+ if (!surface)
+ {
+ /* enter event for a window we've just destroyed */
+ return;
+ }
+
+ input->display->serial = serial;
+ input->display->pointer_focus_serial = serial;
+ window = wl_surface_get_user_data(surface);
+ if (window)
+ window->pointer_enter_serial = serial;
+ input->pointer_focus = window;
+ input->sx = sx;
+ input->sy = sy;
+
+ event =
+ (UwacPointerEnterLeaveEvent*)UwacDisplayNewEvent(input->display, UWAC_EVENT_POINTER_ENTER);
+ if (!event)
+ return;
+
+ event->seat = input;
+ event->window = window;
+ event->x = sx;
+ event->y = sy;
+
+ /* Apply cursor theme */
+ set_cursor_image(input, serial);
+}
+
+static void pointer_handle_leave(void* data, struct wl_pointer* pointer, uint32_t serial,
+ struct wl_surface* surface)
+{
+ UwacPointerEnterLeaveEvent* event = NULL;
+ UwacWindow* window = NULL;
+ UwacSeat* input = data;
+ assert(input);
+
+ input->display->serial = serial;
+
+ event =
+ (UwacPointerEnterLeaveEvent*)UwacDisplayNewEvent(input->display, UWAC_EVENT_POINTER_LEAVE);
+ if (!event)
+ return;
+
+ window = wl_surface_get_user_data(surface);
+
+ event->seat = input;
+ event->window = window;
+}
+
+static void pointer_handle_motion(void* data, struct wl_pointer* pointer, uint32_t time,
+ wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+ UwacPointerMotionEvent* motion_event = NULL;
+ UwacSeat* input = data;
+ assert(input);
+
+ UwacWindow* window = input->pointer_focus;
+
+ int scale = window->display->actual_scale;
+ int sx_i = wl_fixed_to_int(sx_w) * scale;
+ int sy_i = wl_fixed_to_int(sy_w) * scale;
+ double sx_d = wl_fixed_to_double(sx_w) * scale;
+ double sy_d = wl_fixed_to_double(sy_w) * scale;
+
+ if (!window || (sx_i < 0) || (sy_i < 0))
+ return;
+
+ input->sx = sx_d;
+ input->sy = sy_d;
+
+ motion_event =
+ (UwacPointerMotionEvent*)UwacDisplayNewEvent(input->display, UWAC_EVENT_POINTER_MOTION);
+ if (!motion_event)
+ return;
+
+ motion_event->seat = input;
+ motion_event->window = window;
+ motion_event->x = sx_i;
+ motion_event->y = sy_i;
+}
+
+static void pointer_handle_button(void* data, struct wl_pointer* pointer, uint32_t serial,
+ uint32_t time, uint32_t button, uint32_t state_w)
+{
+ UwacPointerButtonEvent* event = NULL;
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacWindow* window = seat->pointer_focus;
+
+ seat->display->serial = serial;
+
+ event = (UwacPointerButtonEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_POINTER_BUTTONS);
+ if (!event)
+ return;
+
+ event->seat = seat;
+ event->window = window;
+ event->x = seat->sx;
+ event->y = seat->sy;
+ event->button = button;
+ event->state = (enum wl_pointer_button_state)state_w;
+}
+
+static void pointer_handle_axis(void* data, struct wl_pointer* pointer, uint32_t time,
+ uint32_t axis, wl_fixed_t value)
+{
+ UwacPointerAxisEvent* event = NULL;
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacWindow* window = seat->pointer_focus;
+
+ if (!window)
+ return;
+
+ event = (UwacPointerAxisEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_POINTER_AXIS);
+ if (!event)
+ return;
+
+ event->seat = seat;
+ event->window = window;
+ event->x = seat->sx;
+ event->y = seat->sy;
+ event->axis = axis;
+ event->value = value;
+}
+
+static void pointer_frame(void* data, struct wl_pointer* wl_pointer)
+{
+ UwacPointerFrameEvent* event = NULL;
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacWindow* window = seat->pointer_focus;
+
+ if (!window)
+ return;
+
+ event = (UwacPointerFrameEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_POINTER_FRAME);
+ if (!event)
+ return;
+
+ event->seat = seat;
+ event->window = window;
+}
+
+static void pointer_axis_source(void* data, struct wl_pointer* wl_pointer, uint32_t axis_source)
+{
+ UwacPointerSourceEvent* event = NULL;
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacWindow* window = seat->pointer_focus;
+
+ if (!window)
+ return;
+
+ event = (UwacPointerSourceEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_POINTER_SOURCE);
+ if (!event)
+ return;
+
+ event->seat = seat;
+ event->window = window;
+ event->axis_source = axis_source;
+}
+
+static void pointer_axis_stop(void* data, struct wl_pointer* wl_pointer, uint32_t time,
+ uint32_t axis)
+{
+ UwacSeat* seat = data;
+ assert(seat);
+}
+
+static void pointer_axis_discrete(void* data, struct wl_pointer* wl_pointer, uint32_t axis,
+ int32_t discrete)
+{
+ /*UwacSeat *seat = data;*/
+ UwacPointerAxisEvent* event = NULL;
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacWindow* window = seat->pointer_focus;
+
+ if (!window)
+ return;
+
+ event =
+ (UwacPointerAxisEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_POINTER_AXIS_DISCRETE);
+ if (!event)
+ return;
+
+ event->seat = seat;
+ event->window = window;
+ event->x = seat->sx;
+ event->y = seat->sy;
+ event->axis = axis;
+ event->value = discrete;
+}
+
+static void pointer_axis_value120(void* data, struct wl_pointer* wl_pointer, uint32_t axis,
+ int32_t value120)
+{
+ /*UwacSeat *seat = data;*/
+ UwacPointerAxisEvent* event = NULL;
+ UwacSeat* seat = data;
+ assert(seat);
+
+ UwacWindow* window = seat->pointer_focus;
+
+ if (!window)
+ return;
+
+ event =
+ (UwacPointerAxisEvent*)UwacDisplayNewEvent(seat->display, UWAC_EVENT_POINTER_AXIS_DISCRETE);
+ if (!event)
+ return;
+
+ event->seat = seat;
+ event->window = window;
+ event->x = seat->sx;
+ event->y = seat->sy;
+ event->axis = axis;
+ event->value = value120 / 120;
+}
+
+static const struct wl_pointer_listener pointer_listener = {
+ pointer_handle_enter, pointer_handle_leave, pointer_handle_motion, pointer_handle_button,
+ pointer_handle_axis, pointer_frame, pointer_axis_source, pointer_axis_stop,
+ pointer_axis_discrete, pointer_axis_value120
+};
+
+static void seat_handle_capabilities(void* data, struct wl_seat* seat, enum wl_seat_capability caps)
+{
+ UwacSeat* input = data;
+ assert(input);
+
+ if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer)
+ {
+ input->pointer = wl_seat_get_pointer(seat);
+ wl_pointer_set_user_data(input->pointer, input);
+ wl_pointer_add_listener(input->pointer, &pointer_listener, input);
+
+ input->cursor_theme = wl_cursor_theme_load(NULL, 32, input->display->shm);
+ if (!input->cursor_theme)
+ {
+ assert(uwacErrorHandler(input->display, UWAC_ERROR_NOMEMORY,
+ "unable to get wayland cursor theme\n"));
+ return;
+ }
+
+ input->default_cursor = wl_cursor_theme_get_cursor(input->cursor_theme, "left_ptr");
+ if (!input->default_cursor)
+ {
+ assert(uwacErrorHandler(input->display, UWAC_ERROR_NOMEMORY,
+ "unable to get wayland cursor left_ptr\n"));
+ return;
+ }
+ }
+ else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer)
+ {
+#ifdef WL_POINTER_RELEASE_SINCE_VERSION
+ if (input->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION)
+ wl_pointer_release(input->pointer);
+ else
+#endif
+ wl_pointer_destroy(input->pointer);
+ if (input->cursor_theme)
+ wl_cursor_theme_destroy(input->cursor_theme);
+
+ input->default_cursor = NULL;
+ input->cursor_theme = NULL;
+ input->pointer = NULL;
+ }
+
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard)
+ {
+ input->keyboard = wl_seat_get_keyboard(seat);
+ wl_keyboard_set_user_data(input->keyboard, input);
+ wl_keyboard_add_listener(input->keyboard, &keyboard_listener, input);
+ }
+ else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard)
+ {
+#ifdef WL_KEYBOARD_RELEASE_SINCE_VERSION
+ if (input->seat_version >= WL_KEYBOARD_RELEASE_SINCE_VERSION)
+ wl_keyboard_release(input->keyboard);
+ else
+#endif
+ wl_keyboard_destroy(input->keyboard);
+ input->keyboard = NULL;
+ }
+
+ if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch)
+ {
+ input->touch = wl_seat_get_touch(seat);
+ wl_touch_set_user_data(input->touch, input);
+ wl_touch_add_listener(input->touch, &touch_listener, input);
+ }
+ else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch)
+ {
+#ifdef WL_TOUCH_RELEASE_SINCE_VERSION
+ if (input->seat_version >= WL_TOUCH_RELEASE_SINCE_VERSION)
+ wl_touch_release(input->touch);
+ else
+#endif
+ wl_touch_destroy(input->touch);
+ input->touch = NULL;
+ }
+}
+
+static void seat_handle_name(void* data, struct wl_seat* seat, const char* name)
+{
+ UwacSeat* input = data;
+ assert(input);
+
+ if (input->name)
+ free(input->name);
+
+ input->name = strdup(name);
+ if (!input->name)
+ assert(uwacErrorHandler(input->display, UWAC_ERROR_NOMEMORY,
+ "unable to strdup seat's name\n"));
+}
+
+static const struct wl_seat_listener seat_listener = { seat_handle_capabilities, seat_handle_name };
+
+UwacSeat* UwacSeatNew(UwacDisplay* d, uint32_t id, uint32_t version)
+{
+ UwacSeat* ret = xzalloc(sizeof(UwacSeat));
+ if (!ret)
+ return NULL;
+
+ ret->display = d;
+ ret->seat_id = id;
+ ret->seat_version = version;
+
+ wl_array_init(&ret->pressed_keys);
+ ret->xkb_context = xkb_context_new(0);
+ if (!ret->xkb_context)
+ {
+ fprintf(stderr, "%s: unable to allocate a xkb_context\n", __func__);
+ goto fail;
+ }
+
+ ret->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, version);
+ wl_seat_add_listener(ret->seat, &seat_listener, ret);
+ wl_seat_set_user_data(ret->seat, ret);
+
+ ret->repeat_timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
+ if (ret->repeat_timer_fd < 0)
+ {
+ fprintf(stderr, "%s: error creating repeat timer\n", __func__);
+ goto fail;
+ }
+ ret->repeat_task.run = keyboard_repeat_func;
+ if (UwacDisplayWatchFd(d, ret->repeat_timer_fd, EPOLLIN, &ret->repeat_task) < 0)
+ {
+ fprintf(stderr, "%s: error polling repeat timer\n", __func__);
+ goto fail;
+ }
+
+ wl_list_insert(d->seats.prev, &ret->link);
+ return ret;
+
+fail:
+ UwacSeatDestroy(ret);
+ return NULL;
+}
+
+void UwacSeatDestroy(UwacSeat* s)
+{
+ if (!s)
+ return;
+
+ UwacSeatInhibitShortcuts(s, false);
+ if (s->seat)
+ {
+#ifdef WL_SEAT_RELEASE_SINCE_VERSION
+ if (s->seat_version >= WL_SEAT_RELEASE_SINCE_VERSION)
+ wl_seat_release(s->seat);
+ else
+#endif
+ wl_seat_destroy(s->seat);
+ }
+ s->seat = NULL;
+
+ free(s->name);
+ wl_array_release(&s->pressed_keys);
+
+ xkb_state_unref(s->xkb.state);
+ xkb_context_unref(s->xkb_context);
+
+ if (s->pointer)
+ {
+#ifdef WL_POINTER_RELEASE_SINCE_VERSION
+ if (s->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION)
+ wl_pointer_release(s->pointer);
+ else
+#endif
+ wl_pointer_destroy(s->pointer);
+ }
+
+ if (s->touch)
+ {
+#ifdef WL_TOUCH_RELEASE_SINCE_VERSION
+ if (s->seat_version >= WL_TOUCH_RELEASE_SINCE_VERSION)
+ wl_touch_release(s->touch);
+ else
+#endif
+ wl_touch_destroy(s->touch);
+ }
+
+ if (s->keyboard)
+ {
+#ifdef WL_KEYBOARD_RELEASE_SINCE_VERSION
+ if (s->seat_version >= WL_KEYBOARD_RELEASE_SINCE_VERSION)
+ wl_keyboard_release(s->keyboard);
+ else
+#endif
+ wl_keyboard_destroy(s->keyboard);
+ }
+
+ if (s->data_device)
+ wl_data_device_destroy(s->data_device);
+
+ if (s->data_source)
+ wl_data_source_destroy(s->data_source);
+
+ if (s->pointer_surface)
+ wl_surface_destroy(s->pointer_surface);
+
+ free(s->pointer_image);
+ free(s->pointer_data);
+
+ wl_list_remove(&s->link);
+ free(s);
+}
+
+const char* UwacSeatGetName(const UwacSeat* seat)
+{
+ assert(seat);
+ return seat->name;
+}
+
+UwacSeatId UwacSeatGetId(const UwacSeat* seat)
+{
+ assert(seat);
+ return seat->seat_id;
+}
+
+UwacReturnCode UwacSeatInhibitShortcuts(UwacSeat* s, bool inhibit)
+{
+ if (!s)
+ return UWAC_ERROR_CLOSED;
+
+ if (s->keyboard_inhibitor)
+ {
+ zwp_keyboard_shortcuts_inhibitor_v1_destroy(s->keyboard_inhibitor);
+ s->keyboard_inhibitor = NULL;
+ }
+ if (inhibit && s->display && s->display->keyboard_inhibit_manager)
+ s->keyboard_inhibitor = zwp_keyboard_shortcuts_inhibit_manager_v1_inhibit_shortcuts(
+ s->display->keyboard_inhibit_manager, s->keyboard_focus->surface, s->seat);
+
+ if (inhibit && !s->keyboard_inhibitor)
+ return UWAC_ERROR_INTERNAL;
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacSeatSetMouseCursor(UwacSeat* seat, const void* data, size_t length, size_t width,
+ size_t height, size_t hot_x, size_t hot_y)
+{
+ if (!seat)
+ return UWAC_ERROR_CLOSED;
+
+ free(seat->pointer_image);
+ seat->pointer_image = NULL;
+
+ free(seat->pointer_data);
+ seat->pointer_data = NULL;
+ seat->pointer_size = 0;
+
+ /* There is a cursor provided */
+ if ((data != NULL) && (length != 0))
+ {
+ seat->pointer_image = xzalloc(sizeof(struct wl_cursor_image));
+ if (!seat->pointer_image)
+ return UWAC_ERROR_NOMEMORY;
+ seat->pointer_image->width = width;
+ seat->pointer_image->height = height;
+ seat->pointer_image->hotspot_x = hot_x;
+ seat->pointer_image->hotspot_y = hot_y;
+
+ free(seat->pointer_data);
+ seat->pointer_data = xmalloc(length);
+ memcpy(seat->pointer_data, data, length);
+ seat->pointer_size = length;
+
+ seat->pointer_type = 2;
+ }
+ /* We want to use the system cursor */
+ else if (length != 0)
+ {
+ seat->pointer_type = 0;
+ }
+ /* Hide the cursor */
+ else
+ {
+ seat->pointer_type = 1;
+ }
+ if (seat && !seat->default_cursor)
+ return UWAC_SUCCESS;
+ return set_cursor_image(seat, seat->display->pointer_focus_serial);
+}
diff --git a/uwac/libuwac/uwac-os.c b/uwac/libuwac/uwac-os.c
new file mode 100644
index 0000000..c51c5a2
--- /dev/null
+++ b/uwac/libuwac/uwac-os.c
@@ -0,0 +1,290 @@
+/*
+ * Copyright © 2012 Collabora, Ltd.
+ *
+ * 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.
+ */
+
+/*
+ * This file is an adaptation of src/wayland-os.h from the wayland project and
+ * shared/os-compatiblity.h from the weston project.
+ *
+ * Functions have been renamed just to prevent name clashes.
+ */
+
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wreserved-id-macro"
+#endif
+
+#define _GNU_SOURCE
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
+
+#if defined(__FreeBSD__) || defined(__DragonFly__)
+#define USE_SHM
+#endif
+
+/* uClibc and uClibc-ng don't provide O_TMPFILE */
+#if !defined(O_TMPFILE) && !defined(__FreeBSD__)
+#define O_TMPFILE (020000000 | O_DIRECTORY)
+#endif
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#ifdef USE_SHM
+#include <sys/mman.h>
+#endif
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/epoll.h>
+
+#include <uwac/config.h>
+
+#include "uwac-os.h"
+#include "uwac-utils.h"
+
+static int set_cloexec_or_close(int fd)
+{
+ long flags = 0;
+
+ if (fd == -1)
+ return -1;
+
+ flags = fcntl(fd, F_GETFD);
+
+ if (flags == -1)
+ goto err;
+
+ if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+ goto err;
+
+ return fd;
+err:
+ close(fd);
+ return -1;
+}
+
+int uwac_os_socket_cloexec(int domain, int type, int protocol)
+{
+ int fd = 0;
+ fd = socket(domain, type | SOCK_CLOEXEC, protocol);
+
+ if (fd >= 0)
+ return fd;
+
+ if (errno != EINVAL)
+ return -1;
+
+ fd = socket(domain, type, protocol);
+ return set_cloexec_or_close(fd);
+}
+
+int uwac_os_dupfd_cloexec(int fd, long minfd)
+{
+ int newfd = 0;
+ newfd = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
+
+ if (newfd >= 0)
+ return newfd;
+
+ if (errno != EINVAL)
+ return -1;
+
+ newfd = fcntl(fd, F_DUPFD, minfd);
+ return set_cloexec_or_close(newfd);
+}
+
+static ssize_t recvmsg_cloexec_fallback(int sockfd, struct msghdr* msg, int flags)
+{
+ ssize_t len = 0;
+ struct cmsghdr* cmsg = NULL;
+ unsigned char* data = NULL;
+ int* end = NULL;
+ len = recvmsg(sockfd, msg, flags);
+
+ if (len == -1)
+ return -1;
+
+ if (!msg->msg_control || msg->msg_controllen == 0)
+ return len;
+
+ cmsg = CMSG_FIRSTHDR(msg);
+
+ for (; cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg))
+ {
+ if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS)
+ continue;
+
+ data = CMSG_DATA(cmsg);
+ end = (int*)(data + cmsg->cmsg_len - CMSG_LEN(0));
+
+ for (int* fd = (int*)data; fd < end; ++fd)
+ *fd = set_cloexec_or_close(*fd);
+ }
+
+ return len;
+}
+
+ssize_t uwac_os_recvmsg_cloexec(int sockfd, struct msghdr* msg, int flags)
+{
+ ssize_t len = 0;
+ len = recvmsg(sockfd, msg, flags | MSG_CMSG_CLOEXEC);
+
+ if (len >= 0)
+ return len;
+
+ if (errno != EINVAL)
+ return -1;
+
+ return recvmsg_cloexec_fallback(sockfd, msg, flags);
+}
+
+int uwac_os_epoll_create_cloexec(void)
+{
+ int fd = 0;
+#ifdef EPOLL_CLOEXEC
+ fd = epoll_create1(EPOLL_CLOEXEC);
+
+ if (fd >= 0)
+ return fd;
+
+ if (errno != EINVAL)
+ return -1;
+
+#endif
+ fd = epoll_create(1);
+ return set_cloexec_or_close(fd);
+}
+
+static int create_tmpfile_cloexec(char* tmpname)
+{
+ int fd = 0;
+#ifdef USE_SHM
+ fd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600);
+#elif defined(UWAC_HAVE_MKOSTEMP)
+ fd = mkostemp(tmpname, O_CLOEXEC);
+
+ if (fd >= 0)
+ unlink(tmpname);
+
+#else
+ fd = mkstemp(tmpname);
+
+ if (fd >= 0)
+ {
+ fd = set_cloexec_or_close(fd);
+ unlink(tmpname);
+ }
+
+#endif
+ return fd;
+}
+
+/*
+ * Create a new, unique, anonymous file of the given size, and
+ * return the file descriptor for it. The file descriptor is set
+ * CLOEXEC. The file is immediately suitable for mmap()'ing
+ * the given size at offset zero.
+ *
+ * The file should not have a permanent backing store like a disk,
+ * but may have if XDG_RUNTIME_DIR is not properly implemented in OS.
+ *
+ * The file name is deleted from the file system.
+ *
+ * The file is suitable for buffer sharing between processes by
+ * transmitting the file descriptor over Unix sockets using the
+ * SCM_RIGHTS methods.
+ *
+ * If the C library implements posix_fallocate(), it is used to
+ * guarantee that disk space is available for the file at the
+ * given size. If disk space is insufficient, errno is set to ENOSPC.
+ * If posix_fallocate() is not supported, program may receive
+ * SIGBUS on accessing mmap()'ed file contents instead.
+ */
+int uwac_create_anonymous_file(off_t size)
+{
+ static const char template[] = "/weston-shared-XXXXXX";
+ size_t length = 0;
+ char* name = NULL;
+ const char* path = NULL;
+ int fd = 0;
+ int ret = 0;
+ path = getenv("XDG_RUNTIME_DIR");
+
+ if (!path)
+ {
+ errno = ENOENT;
+ return -1;
+ }
+
+#ifdef O_TMPFILE
+ fd = open(path, O_TMPFILE | O_RDWR | O_EXCL, 0600);
+#else
+ /*
+ * Some platforms (e.g. FreeBSD) won't support O_TMPFILE and can't
+ * reasonably emulate it at first blush. Opt to make them rely on
+ * the create_tmpfile_cloexec() path instead.
+ */
+ fd = -1;
+#endif
+
+ if (fd < 0)
+ {
+ length = strlen(path) + sizeof(template);
+ name = xmalloc(length);
+
+ if (!name)
+ return -1;
+
+ snprintf(name, length, "%s%s", path, template);
+ fd = create_tmpfile_cloexec(name);
+ free(name);
+ }
+
+ if (fd < 0)
+ return -1;
+
+#ifdef UWAC_HAVE_POSIX_FALLOCATE
+ ret = posix_fallocate(fd, 0, size);
+
+ if (ret != 0)
+ {
+ close(fd);
+ errno = ret;
+ return -1;
+ }
+
+#else
+ ret = ftruncate(fd, size);
+
+ if (ret < 0)
+ {
+ close(fd);
+ return -1;
+ }
+
+#endif
+ return fd;
+}
diff --git a/uwac/libuwac/uwac-os.h b/uwac/libuwac/uwac-os.h
new file mode 100644
index 0000000..ef14bf4
--- /dev/null
+++ b/uwac/libuwac/uwac-os.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright © 2012 Collabora, Ltd.
+ * Copyright © 2014 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+
+/*
+ * This file is an adaptation of src/wayland-os.h from the wayland project and
+ * shared/os-compatiblity.h from the weston project.
+ *
+ * Functions have been renamed just to prevent name clashes.
+ */
+
+#ifndef UWAC_OS_H
+#define UWAC_OS_H
+
+#include <sys/socket.h>
+
+int uwac_os_socket_cloexec(int domain, int type, int protocol);
+
+int uwac_os_dupfd_cloexec(int fd, long minfd);
+
+ssize_t uwac_os_recvmsg_cloexec(int sockfd, struct msghdr* msg, int flags);
+
+int uwac_os_epoll_create_cloexec(void);
+
+int uwac_create_anonymous_file(off_t size);
+#endif /* UWAC_OS_H */
diff --git a/uwac/libuwac/uwac-output.c b/uwac/libuwac/uwac-output.c
new file mode 100644
index 0000000..079018e
--- /dev/null
+++ b/uwac/libuwac/uwac-output.c
@@ -0,0 +1,183 @@
+/*
+ * Copyright © 2014 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+#include "uwac-priv.h"
+#include "uwac-utils.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#define TARGET_OUTPUT_INTERFACE 2U
+
+static bool dupstr(char** dst, const char* src)
+{
+ assert(dst);
+ free(*dst);
+ *dst = NULL;
+ if (!src)
+ return true;
+ *dst = strdup(src);
+ return *dst != NULL;
+}
+
+static void output_handle_geometry(void* data, struct wl_output* wl_output, int x, int y,
+ int physical_width, int physical_height, int subpixel,
+ const char* make, const char* model, int transform)
+{
+ UwacOutput* output = data;
+ assert(output);
+
+ output->position.x = x;
+ output->position.y = y;
+ output->transform = transform;
+
+ if (!dupstr(&output->make, make))
+ {
+ assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY, "%s: unable to strdup make\n",
+ __func__));
+ }
+
+ if (!dupstr(&output->model, model))
+ {
+ assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY,
+ "%s: unable to strdup model\n", __func__));
+ }
+
+ UwacEvent* event = UwacDisplayNewEvent(output->display, UWAC_EVENT_OUTPUT_GEOMETRY);
+ event->output_geometry.output = output;
+ event->output_geometry.x = x;
+ event->output_geometry.y = y;
+ event->output_geometry.physical_width = physical_width;
+ event->output_geometry.physical_height = physical_height;
+ event->output_geometry.subpixel = subpixel;
+ event->output_geometry.make = output->make;
+ event->output_geometry.model = output->model;
+ event->output_geometry.transform = transform;
+}
+
+static void output_handle_done(void* data, struct wl_output* wl_output)
+{
+ UwacOutput* output = data;
+ assert(output);
+
+ output->doneReceived = true;
+}
+
+static void output_handle_scale(void* data, struct wl_output* wl_output, int32_t scale)
+{
+ UwacOutput* output = data;
+ assert(output);
+
+ output->scale = scale;
+ if (scale > output->display->actual_scale)
+ output->display->actual_scale = scale;
+}
+
+static void output_handle_name(void* data, struct wl_output* wl_output, const char* name)
+{
+ UwacOutput* output = data;
+ assert(output);
+
+ if (!dupstr(&output->name, name))
+ {
+ assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY, "%s: unable to strdup make\n",
+ __func__));
+ }
+}
+
+static void output_handle_description(void* data, struct wl_output* wl_output,
+ const char* description)
+{
+ UwacOutput* output = data;
+ assert(output);
+
+ if (!dupstr(&output->description, description))
+ {
+ assert(uwacErrorHandler(output->display, UWAC_ERROR_NOMEMORY, "%s: unable to strdup make\n",
+ __func__));
+ }
+}
+
+static void output_handle_mode(void* data, struct wl_output* wl_output, uint32_t flags, int width,
+ int height, int refresh)
+{
+ UwacOutput* output = data;
+ assert(output);
+ // UwacDisplay *display = output->display;
+
+ if (output->doneNeeded && output->doneReceived)
+ {
+ /* TODO: we should clear the mode list */
+ }
+
+ if (flags & WL_OUTPUT_MODE_CURRENT)
+ {
+ output->resolution.width = width;
+ output->resolution.height = height;
+ /* output->allocation.width = width;
+ output->allocation.height = height;
+ if (display->output_configure_handler)
+ (*display->output_configure_handler)(
+ output, display->user_data);*/
+ }
+}
+
+static const struct wl_output_listener output_listener = {
+ output_handle_geometry, output_handle_mode, output_handle_done,
+ output_handle_scale, output_handle_name, output_handle_description
+};
+
+UwacOutput* UwacCreateOutput(UwacDisplay* d, uint32_t id, uint32_t version)
+{
+ UwacOutput* o = xzalloc(sizeof *o);
+ if (!o)
+ return NULL;
+
+ o->display = d;
+ o->server_output_id = id;
+ o->doneNeeded = (version > 1);
+ o->doneReceived = false;
+ o->output = wl_registry_bind(d->registry, id, &wl_output_interface,
+ min(TARGET_OUTPUT_INTERFACE, version));
+ wl_output_add_listener(o->output, &output_listener, o);
+
+ wl_list_insert(d->outputs.prev, &o->link);
+ return o;
+}
+
+int UwacDestroyOutput(UwacOutput* output)
+{
+ if (!output)
+ return UWAC_SUCCESS;
+
+ free(output->make);
+ free(output->model);
+ free(output->name);
+ free(output->description);
+
+ wl_output_destroy(output->output);
+ wl_list_remove(&output->link);
+ free(output);
+
+ return UWAC_SUCCESS;
+}
diff --git a/uwac/libuwac/uwac-priv.h b/uwac/libuwac/uwac-priv.h
new file mode 100644
index 0000000..68799f4
--- /dev/null
+++ b/uwac/libuwac/uwac-priv.h
@@ -0,0 +1,291 @@
+/*
+ * Copyright © 2014 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+
+#ifndef UWAC_PRIV_H_
+#define UWAC_PRIV_H_
+
+#include <uwac/config.h>
+
+#include <stdbool.h>
+#include <wayland-client.h>
+#include "xdg-shell-client-protocol.h"
+#include "keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h"
+#include "xdg-decoration-unstable-v1-client-protocol.h"
+#include "server-decoration-client-protocol.h"
+#include "viewporter-client-protocol.h"
+
+#ifdef BUILD_IVI
+#include "ivi-application-client-protocol.h"
+#endif
+#ifdef BUILD_FULLSCREEN_SHELL
+#include "fullscreen-shell-unstable-v1-client-protocol.h"
+#endif
+
+#ifdef UWAC_HAVE_PIXMAN_REGION
+#include <pixman-1/pixman.h>
+#else
+#include <freerdp/codec/region.h>
+#endif
+
+#include <xkbcommon/xkbcommon.h>
+
+#include <uwac/uwac.h>
+
+extern UwacErrorHandler uwacErrorHandler;
+
+typedef struct uwac_task UwacTask;
+
+/** @brief task struct
+ */
+struct uwac_task
+{
+ void (*run)(UwacTask* task, uint32_t events);
+ struct wl_list link;
+};
+
+/** @brief a global registry object
+ */
+struct uwac_global
+{
+ uint32_t name;
+ char* interface;
+ uint32_t version;
+ struct wl_list link;
+};
+typedef struct uwac_global UwacGlobal;
+
+struct uwac_event_list_item;
+typedef struct uwac_event_list_item UwacEventListItem;
+
+/** @brief double linked list element
+ */
+struct uwac_event_list_item
+{
+ UwacEvent event;
+ UwacEventListItem *tail, *head;
+};
+
+/** @brief main connection object to a wayland display
+ */
+struct uwac_display
+{
+ struct wl_list globals;
+
+ struct wl_display* display;
+ struct wl_registry* registry;
+ struct wl_compositor* compositor;
+ struct wp_viewporter* viewporter;
+ struct wl_subcompositor* subcompositor;
+ struct wl_shell* shell;
+ struct xdg_toplevel* xdg_toplevel;
+ struct xdg_wm_base* xdg_base;
+ struct wl_data_device_manager* devicemanager;
+ struct zwp_keyboard_shortcuts_inhibit_manager_v1* keyboard_inhibit_manager;
+ struct zxdg_decoration_manager_v1* deco_manager;
+ struct org_kde_kwin_server_decoration_manager* kde_deco_manager;
+#ifdef BUILD_IVI
+ struct ivi_application* ivi_application;
+#endif
+#ifdef BUILD_FULLSCREEN_SHELL
+ struct zwp_fullscreen_shell_v1* fullscreen_shell;
+#endif
+
+ struct wl_shm* shm;
+ enum wl_shm_format* shm_formats;
+ uint32_t shm_formats_nb;
+ bool has_rgb565;
+
+ struct wl_data_device_manager* data_device_manager;
+ struct text_cursor_position* text_cursor_position;
+ struct workspace_manager* workspace_manager;
+
+ struct wl_list seats;
+
+ int display_fd;
+ UwacReturnCode last_error;
+ uint32_t display_fd_events;
+ int epoll_fd;
+ bool running;
+ UwacTask dispatch_fd_task;
+ uint32_t serial;
+ uint32_t pointer_focus_serial;
+ int actual_scale;
+
+ struct wl_list windows;
+
+ struct wl_list outputs;
+
+ UwacEventListItem *push_queue, *pop_queue;
+};
+
+/** @brief an output on a wayland display */
+struct uwac_output
+{
+ UwacDisplay* display;
+
+ bool doneNeeded;
+ bool doneReceived;
+
+ UwacPosition position;
+ UwacSize resolution;
+ int transform;
+ int scale;
+ char* make;
+ char* model;
+ uint32_t server_output_id;
+ struct wl_output* output;
+
+ struct wl_list link;
+ char* name;
+ char* description;
+};
+
+/** @brief a seat attached to a wayland display */
+struct uwac_seat
+{
+ UwacDisplay* display;
+ char* name;
+ struct wl_seat* seat;
+ uint32_t seat_id;
+ uint32_t seat_version;
+ struct wl_data_device* data_device;
+ struct wl_data_source* data_source;
+ struct wl_pointer* pointer;
+ struct wl_surface* pointer_surface;
+ struct wl_cursor_image* pointer_image;
+ struct wl_cursor_theme* cursor_theme;
+ struct wl_cursor* default_cursor;
+ void* pointer_data;
+ size_t pointer_size;
+ int pointer_type;
+ struct wl_keyboard* keyboard;
+ struct wl_touch* touch;
+ struct wl_data_offer* offer;
+ struct xkb_context* xkb_context;
+ struct zwp_keyboard_shortcuts_inhibitor_v1* keyboard_inhibitor;
+
+ struct
+ {
+ struct xkb_keymap* keymap;
+ struct xkb_state* state;
+ xkb_mod_mask_t control_mask;
+ xkb_mod_mask_t alt_mask;
+ xkb_mod_mask_t shift_mask;
+ xkb_mod_mask_t caps_mask;
+ xkb_mod_mask_t num_mask;
+ } xkb;
+ uint32_t modifiers;
+ int32_t repeat_rate_sec, repeat_rate_nsec;
+ int32_t repeat_delay_sec, repeat_delay_nsec;
+ uint32_t repeat_sym, repeat_key, repeat_time;
+
+ struct wl_array pressed_keys;
+
+ UwacWindow* pointer_focus;
+
+ UwacWindow* keyboard_focus;
+
+ UwacWindow* touch_focus;
+ bool touch_frame_started;
+
+ int repeat_timer_fd;
+ UwacTask repeat_task;
+ float sx, sy;
+ struct wl_list link;
+
+ void* data_context;
+ UwacDataTransferHandler transfer_data;
+ UwacCancelDataTransferHandler cancel_data;
+ bool ignore_announcement;
+};
+
+/** @brief a buffer used for drawing a surface frame */
+struct uwac_buffer
+{
+ bool used;
+ bool dirty;
+#ifdef UWAC_HAVE_PIXMAN_REGION
+ pixman_region32_t damage;
+#else
+ REGION16 damage;
+#endif
+ struct wl_buffer* wayland_buffer;
+ void* data;
+ size_t size;
+};
+typedef struct uwac_buffer UwacBuffer;
+
+/** @brief a window */
+struct uwac_window
+{
+ UwacDisplay* display;
+ int width, height, stride;
+ int surfaceStates;
+ enum wl_shm_format format;
+
+ int nbuffers;
+ UwacBuffer* buffers;
+
+ struct wl_region* opaque_region;
+ struct wl_region* input_region;
+ ssize_t drawingBufferIdx;
+ ssize_t pendingBufferIdx;
+ struct wl_surface* surface;
+ struct wp_viewport* viewport;
+ struct wl_shell_surface* shell_surface;
+ struct xdg_surface* xdg_surface;
+ struct xdg_toplevel* xdg_toplevel;
+ struct zxdg_toplevel_decoration_v1* deco;
+ struct org_kde_kwin_server_decoration* kde_deco;
+#ifdef BUILD_IVI
+ struct ivi_surface* ivi_surface;
+#endif
+ struct wl_list link;
+
+ uint32_t pointer_enter_serial;
+ uint32_t pointer_cursor_serial;
+ int pointer_current_cursor;
+};
+
+/**@brief data to pass to wl_buffer release listener */
+struct uwac_buffer_release_data
+{
+ UwacWindow* window;
+ int bufferIdx;
+};
+typedef struct uwac_buffer_release_data UwacBufferReleaseData;
+
+/* in uwa-display.c */
+UwacEvent* UwacDisplayNewEvent(UwacDisplay* d, int type);
+int UwacDisplayWatchFd(UwacDisplay* display, int fd, uint32_t events, UwacTask* task);
+
+/* in uwac-input.c */
+UwacSeat* UwacSeatNew(UwacDisplay* d, uint32_t id, uint32_t version);
+void UwacSeatDestroy(UwacSeat* s);
+
+/* in uwac-output.c */
+UwacOutput* UwacCreateOutput(UwacDisplay* d, uint32_t id, uint32_t version);
+int UwacDestroyOutput(UwacOutput* output);
+
+UwacReturnCode UwacSeatRegisterClipboard(UwacSeat* s);
+
+#endif /* UWAC_PRIV_H_ */
diff --git a/uwac/libuwac/uwac-tools.c b/uwac/libuwac/uwac-tools.c
new file mode 100644
index 0000000..760970e
--- /dev/null
+++ b/uwac/libuwac/uwac-tools.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2015 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+
+#include <wayland-util.h>
+#include <string.h>
+#include <uwac/uwac-tools.h>
+
+struct uwac_touch_automata
+{
+ struct wl_array tp;
+};
+
+void UwacTouchAutomataInit(UwacTouchAutomata* automata)
+{
+ wl_array_init(&automata->tp);
+}
+
+void UwacTouchAutomataReset(UwacTouchAutomata* automata)
+{
+ automata->tp.size = 0;
+}
+
+bool UwacTouchAutomataInjectEvent(UwacTouchAutomata* automata, UwacEvent* event)
+{
+
+ UwacTouchPoint* tp = NULL;
+
+ switch (event->type)
+ {
+ case UWAC_EVENT_TOUCH_FRAME_BEGIN:
+ break;
+
+ case UWAC_EVENT_TOUCH_UP:
+ {
+ UwacTouchUp* touchUp = &event->touchUp;
+ size_t toMove = automata->tp.size - sizeof(UwacTouchPoint);
+
+ wl_array_for_each(tp, &automata->tp)
+ {
+ if ((int64_t)tp->id == touchUp->id)
+ {
+ if (toMove)
+ memmove(tp, tp + 1, toMove);
+ return true;
+ }
+
+ toMove -= sizeof(UwacTouchPoint);
+ }
+ break;
+ }
+
+ case UWAC_EVENT_TOUCH_DOWN:
+ {
+ UwacTouchDown* touchDown = &event->touchDown;
+
+ wl_array_for_each(tp, &automata->tp)
+ {
+ if ((int64_t)tp->id == touchDown->id)
+ {
+ tp->x = touchDown->x;
+ tp->y = touchDown->y;
+ return true;
+ }
+ }
+
+ tp = wl_array_add(&automata->tp, sizeof(UwacTouchPoint));
+ if (!tp)
+ return false;
+
+ if (touchDown->id < 0)
+ return false;
+
+ tp->id = (uint32_t)touchDown->id;
+ tp->x = touchDown->x;
+ tp->y = touchDown->y;
+ break;
+ }
+
+ case UWAC_EVENT_TOUCH_FRAME_END:
+ break;
+
+ default:
+ break;
+ }
+
+ return true;
+}
diff --git a/uwac/libuwac/uwac-utils.c b/uwac/libuwac/uwac-utils.c
new file mode 100644
index 0000000..f93b5f7
--- /dev/null
+++ b/uwac/libuwac/uwac-utils.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright © 2012 Collabora, Ltd.
+ * Copyright © 2008 Kristian Høgsberg
+ * Copyright © 2014 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+
+#include <uwac/config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "uwac-utils.h"
+
+/*
+ * This part is an adaptation of client/window.c from the weston project.
+ */
+
+static void* fail_on_null(void* p)
+{
+ if (p == NULL)
+ {
+ fprintf(stderr, "out of memory\n");
+ exit(EXIT_FAILURE);
+ }
+
+ return p;
+}
+
+void* xmalloc(size_t s)
+{
+ return fail_on_null(malloc(s));
+}
+
+void* xzalloc(size_t s)
+{
+ return fail_on_null(zalloc(s));
+}
+
+char* xstrdup(const char* s)
+{
+ return fail_on_null(strdup(s));
+}
+
+void* xrealloc(void* p, size_t s)
+{
+ return fail_on_null(realloc(p, s));
+}
diff --git a/uwac/libuwac/uwac-utils.h b/uwac/libuwac/uwac-utils.h
new file mode 100644
index 0000000..89852d5
--- /dev/null
+++ b/uwac/libuwac/uwac-utils.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2014 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+
+#ifndef UWAC_UTILS_H_
+#define UWAC_UTILS_H_
+
+#include <stdlib.h>
+
+#define min(a, b) \
+ ({ \
+ __typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _a < _b ? _a : _b; \
+ })
+
+#define container_of(ptr, type, member) \
+ ({ \
+ __typeof__(((type*)0)->member)* __mptr = (ptr); \
+ (type*)((char*)__mptr - offsetof(type, member)); \
+ })
+
+#define ARRAY_LENGTH(a) (sizeof(a) / sizeof(a)[0])
+
+void* xmalloc(size_t s);
+
+static inline void* zalloc(size_t size)
+{
+ return calloc(1, size);
+}
+
+void* xzalloc(size_t s);
+
+char* xstrdup(const char* s);
+
+void* xrealloc(void* p, size_t s);
+
+#endif /* UWAC_UTILS_H_ */
diff --git a/uwac/libuwac/uwac-window.c b/uwac/libuwac/uwac-window.c
new file mode 100644
index 0000000..49728bd
--- /dev/null
+++ b/uwac/libuwac/uwac-window.c
@@ -0,0 +1,883 @@
+/*
+ * Copyright © 2014 David FORT <contact@hardening-consulting.com>
+ *
+ * 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.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <errno.h>
+
+#include "uwac-priv.h"
+#include "uwac-utils.h"
+#include "uwac-os.h"
+
+#include <uwac/config.h>
+
+#define UWAC_INITIAL_BUFFERS 3
+
+static int bppFromShmFormat(enum wl_shm_format format)
+{
+ switch (format)
+ {
+ case WL_SHM_FORMAT_ARGB8888:
+ case WL_SHM_FORMAT_XRGB8888:
+ default:
+ return 4;
+ }
+}
+
+static void buffer_release(void* data, struct wl_buffer* buffer)
+{
+ UwacBufferReleaseData* releaseData = data;
+ UwacBuffer* uwacBuffer = &releaseData->window->buffers[releaseData->bufferIdx];
+ uwacBuffer->used = false;
+}
+
+static const struct wl_buffer_listener buffer_listener = { buffer_release };
+
+static void UwacWindowDestroyBuffers(UwacWindow* w)
+{
+ for (int i = 0; i < w->nbuffers; i++)
+ {
+ UwacBuffer* buffer = &w->buffers[i];
+#ifdef UWAC_HAVE_PIXMAN_REGION
+ pixman_region32_fini(&buffer->damage);
+#else
+ region16_uninit(&buffer->damage);
+#endif
+ UwacBufferReleaseData* releaseData =
+ (UwacBufferReleaseData*)wl_buffer_get_user_data(buffer->wayland_buffer);
+ wl_buffer_destroy(buffer->wayland_buffer);
+ free(releaseData);
+ munmap(buffer->data, buffer->size);
+ }
+
+ w->nbuffers = 0;
+ free(w->buffers);
+ w->buffers = NULL;
+}
+
+static int UwacWindowShmAllocBuffers(UwacWindow* w, int nbuffers, int allocSize, uint32_t width,
+ uint32_t height, enum wl_shm_format format);
+
+static void xdg_handle_toplevel_configure(void* data, struct xdg_toplevel* xdg_toplevel,
+ int32_t width, int32_t height, struct wl_array* states)
+{
+ UwacWindow* window = (UwacWindow*)data;
+ int scale = window->display->actual_scale;
+ width *= scale;
+ height *= scale;
+ UwacConfigureEvent* event = NULL;
+ int ret = 0;
+ int surfaceState = 0;
+ enum xdg_toplevel_state* state = NULL;
+ surfaceState = 0;
+ wl_array_for_each(state, states)
+ {
+ switch (*state)
+ {
+ case XDG_TOPLEVEL_STATE_MAXIMIZED:
+ surfaceState |= UWAC_WINDOW_MAXIMIZED;
+ break;
+
+ case XDG_TOPLEVEL_STATE_FULLSCREEN:
+ surfaceState |= UWAC_WINDOW_FULLSCREEN;
+ break;
+
+ case XDG_TOPLEVEL_STATE_ACTIVATED:
+ surfaceState |= UWAC_WINDOW_ACTIVATED;
+ break;
+
+ case XDG_TOPLEVEL_STATE_RESIZING:
+ surfaceState |= UWAC_WINDOW_RESIZING;
+ break;
+
+ default:
+ break;
+ }
+ }
+ window->surfaceStates = surfaceState;
+ event = (UwacConfigureEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_CONFIGURE);
+
+ if (!event)
+ {
+ assert(uwacErrorHandler(window->display, UWAC_ERROR_NOMEMORY,
+ "failed to allocate a configure event\n"));
+ return;
+ }
+
+ event->window = window;
+ event->states = surfaceState;
+
+ if ((width > 0 && height > 0) && (width != window->width || height != window->height))
+ {
+ event->width = width;
+ event->height = height;
+ UwacWindowDestroyBuffers(window);
+ window->width = width;
+ window->stride = width * bppFromShmFormat(window->format);
+ window->height = height;
+ ret = UwacWindowShmAllocBuffers(window, UWAC_INITIAL_BUFFERS, window->stride * height,
+ width, height, window->format);
+
+ if (ret != UWAC_SUCCESS)
+ {
+ assert(
+ uwacErrorHandler(window->display, ret, "failed to reallocate a wayland buffers\n"));
+ window->drawingBufferIdx = window->pendingBufferIdx = -1;
+ return;
+ }
+
+ window->drawingBufferIdx = 0;
+ if (window->pendingBufferIdx != -1)
+ window->pendingBufferIdx = window->drawingBufferIdx;
+
+ if (window->viewport)
+ {
+ wp_viewport_set_source(window->viewport, wl_fixed_from_int(0), wl_fixed_from_int(0),
+ wl_fixed_from_int(window->width * scale),
+ wl_fixed_from_int(window->height * scale));
+ wp_viewport_set_destination(window->viewport, window->width * scale,
+ window->height * scale);
+ }
+ }
+ else
+ {
+ event->width = window->width;
+ event->height = window->height;
+ }
+}
+
+static void xdg_handle_toplevel_close(void* data, struct xdg_toplevel* xdg_toplevel)
+{
+ UwacCloseEvent* event = NULL;
+ UwacWindow* window = (UwacWindow*)data;
+ event = (UwacCloseEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_CLOSE);
+
+ if (!event)
+ {
+ assert(uwacErrorHandler(window->display, UWAC_ERROR_INTERNAL,
+ "failed to allocate a close event\n"));
+ return;
+ }
+
+ event->window = window;
+}
+
+static const struct xdg_toplevel_listener xdg_toplevel_listener = {
+ xdg_handle_toplevel_configure,
+ xdg_handle_toplevel_close,
+};
+
+static void xdg_handle_surface_configure(void* data, struct xdg_surface* xdg_surface,
+ uint32_t serial)
+{
+ xdg_surface_ack_configure(xdg_surface, serial);
+}
+
+static const struct xdg_surface_listener xdg_surface_listener = {
+ .configure = xdg_handle_surface_configure,
+};
+
+#if BUILD_IVI
+
+static void ivi_handle_configure(void* data, struct ivi_surface* surface, int32_t width,
+ int32_t height)
+{
+ UwacWindow* window = (UwacWindow*)data;
+ UwacConfigureEvent* event = NULL;
+ int ret = 0;
+ event = (UwacConfigureEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_CONFIGURE);
+
+ if (!event)
+ {
+ assert(uwacErrorHandler(window->display, UWAC_ERROR_NOMEMORY,
+ "failed to allocate a configure event\n"));
+ return;
+ }
+
+ event->window = window;
+ event->states = 0;
+
+ if (width && height)
+ {
+ event->width = width;
+ event->height = height;
+ UwacWindowDestroyBuffers(window);
+ window->width = width;
+ window->stride = width * bppFromShmFormat(window->format);
+ window->height = height;
+ ret = UwacWindowShmAllocBuffers(window, UWAC_INITIAL_BUFFERS, window->stride * height,
+ width, height, window->format);
+
+ if (ret != UWAC_SUCCESS)
+ {
+ assert(
+ uwacErrorHandler(window->display, ret, "failed to reallocate a wayland buffers\n"));
+ window->drawingBufferIdx = window->pendingBufferIdx = -1;
+ return;
+ }
+
+ window->drawingBufferIdx = 0;
+ if (window->pendingBufferIdx != -1)
+ window->pendingBufferIdx = window->drawingBufferIdx;
+ }
+ else
+ {
+ event->width = window->width;
+ event->height = window->height;
+ }
+}
+
+static const struct ivi_surface_listener ivi_surface_listener = {
+ ivi_handle_configure,
+};
+#endif
+
+static void shell_ping(void* data, struct wl_shell_surface* surface, uint32_t serial)
+{
+ wl_shell_surface_pong(surface, serial);
+}
+
+static void shell_configure(void* data, struct wl_shell_surface* surface, uint32_t edges,
+ int32_t width, int32_t height)
+{
+ UwacWindow* window = (UwacWindow*)data;
+ UwacConfigureEvent* event = NULL;
+ int ret = 0;
+ event = (UwacConfigureEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_CONFIGURE);
+
+ if (!event)
+ {
+ assert(uwacErrorHandler(window->display, UWAC_ERROR_NOMEMORY,
+ "failed to allocate a configure event\n"));
+ return;
+ }
+
+ event->window = window;
+ event->states = 0;
+
+ if (width && height)
+ {
+ event->width = width;
+ event->height = height;
+ UwacWindowDestroyBuffers(window);
+ window->width = width;
+ window->stride = width * bppFromShmFormat(window->format);
+ window->height = height;
+ ret = UwacWindowShmAllocBuffers(window, UWAC_INITIAL_BUFFERS, window->stride * height,
+ width, height, window->format);
+
+ if (ret != UWAC_SUCCESS)
+ {
+ assert(
+ uwacErrorHandler(window->display, ret, "failed to reallocate a wayland buffers\n"));
+ window->drawingBufferIdx = window->pendingBufferIdx = -1;
+ return;
+ }
+
+ window->drawingBufferIdx = 0;
+ if (window->pendingBufferIdx != -1)
+ window->pendingBufferIdx = window->drawingBufferIdx;
+ }
+ else
+ {
+ event->width = window->width;
+ event->height = window->height;
+ }
+}
+
+static void shell_popup_done(void* data, struct wl_shell_surface* surface)
+{
+}
+
+static const struct wl_shell_surface_listener shell_listener = { shell_ping, shell_configure,
+ shell_popup_done };
+
+int UwacWindowShmAllocBuffers(UwacWindow* w, int nbuffers, int allocSize, uint32_t width,
+ uint32_t height, enum wl_shm_format format)
+{
+ int ret = UWAC_SUCCESS;
+ UwacBuffer* newBuffers = NULL;
+ int fd = 0;
+ void* data = NULL;
+ struct wl_shm_pool* pool = NULL;
+ size_t pagesize = sysconf(_SC_PAGESIZE);
+ newBuffers = xrealloc(w->buffers, (w->nbuffers + nbuffers) * sizeof(UwacBuffer));
+
+ if (!newBuffers)
+ return UWAC_ERROR_NOMEMORY;
+
+ /* round up to a multiple of PAGESIZE to page align data for each buffer */
+ allocSize = (allocSize + pagesize - 1) & ~(pagesize - 1);
+
+ w->buffers = newBuffers;
+ memset(w->buffers + w->nbuffers, 0, sizeof(UwacBuffer) * nbuffers);
+ fd = uwac_create_anonymous_file(1ull * allocSize * nbuffers);
+
+ if (fd < 0)
+ {
+ return UWAC_ERROR_INTERNAL;
+ }
+
+ data = mmap(NULL, 1ull * allocSize * nbuffers, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+ if (data == MAP_FAILED)
+ {
+ ret = UWAC_ERROR_NOMEMORY;
+ goto error_mmap;
+ }
+
+ pool = wl_shm_create_pool(w->display->shm, fd, allocSize * nbuffers);
+
+ if (!pool)
+ {
+ munmap(data, 1ull * allocSize * nbuffers);
+ ret = UWAC_ERROR_NOMEMORY;
+ goto error_mmap;
+ }
+
+ for (int i = 0; i < nbuffers; i++)
+ {
+ int bufferIdx = w->nbuffers + i;
+ UwacBuffer* buffer = &w->buffers[bufferIdx];
+#ifdef UWAC_HAVE_PIXMAN_REGION
+ pixman_region32_init(&buffer->damage);
+#else
+ region16_init(&buffer->damage);
+#endif
+ buffer->data = &((char*)data)[allocSize * i];
+ buffer->size = allocSize;
+ buffer->wayland_buffer =
+ wl_shm_pool_create_buffer(pool, allocSize * i, width, height, w->stride, format);
+ UwacBufferReleaseData* listener_data = xmalloc(sizeof(UwacBufferReleaseData));
+ listener_data->window = w;
+ listener_data->bufferIdx = bufferIdx;
+ wl_buffer_add_listener(buffer->wayland_buffer, &buffer_listener, listener_data);
+ }
+
+ wl_shm_pool_destroy(pool);
+ w->nbuffers += nbuffers;
+error_mmap:
+ close(fd);
+ return ret;
+}
+
+static UwacBuffer* UwacWindowFindFreeBuffer(UwacWindow* w, ssize_t* index)
+{
+ int ret = 0;
+
+ if (index)
+ *index = -1;
+
+ size_t i = 0;
+ for (; i < w->nbuffers; i++)
+ {
+ if (!w->buffers[i].used)
+ {
+ w->buffers[i].used = true;
+ if (index)
+ *index = i;
+ return &w->buffers[i];
+ }
+ }
+
+ ret = UwacWindowShmAllocBuffers(w, 2, w->stride * w->height, w->width, w->height, w->format);
+
+ if (ret != UWAC_SUCCESS)
+ {
+ w->display->last_error = ret;
+ return NULL;
+ }
+
+ w->buffers[i].used = true;
+ if (index)
+ *index = i;
+ return &w->buffers[i];
+}
+
+static UwacReturnCode UwacWindowSetDecorations(UwacWindow* w)
+{
+ if (!w || !w->display)
+ return UWAC_ERROR_INTERNAL;
+
+ if (w->display->deco_manager)
+ {
+ w->deco = zxdg_decoration_manager_v1_get_toplevel_decoration(w->display->deco_manager,
+ w->xdg_toplevel);
+ if (!w->deco)
+ {
+ uwacErrorHandler(w->display, UWAC_NOT_FOUND,
+ "Current window manager does not allow decorating with SSD");
+ }
+ else
+ zxdg_toplevel_decoration_v1_set_mode(w->deco,
+ ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+ }
+ else if (w->display->kde_deco_manager)
+ {
+ w->kde_deco =
+ org_kde_kwin_server_decoration_manager_create(w->display->kde_deco_manager, w->surface);
+ if (!w->kde_deco)
+ {
+ uwacErrorHandler(w->display, UWAC_NOT_FOUND,
+ "Current window manager does not allow decorating with SSD");
+ }
+ else
+ org_kde_kwin_server_decoration_request_mode(w->kde_deco,
+ ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER);
+ }
+ return UWAC_SUCCESS;
+}
+
+UwacWindow* UwacCreateWindowShm(UwacDisplay* display, uint32_t width, uint32_t height,
+ enum wl_shm_format format)
+{
+ UwacWindow* w = NULL;
+ int allocSize = 0;
+ int ret = 0;
+
+ if (!display)
+ {
+ return NULL;
+ }
+
+ w = xzalloc(sizeof(*w));
+
+ if (!w)
+ {
+ display->last_error = UWAC_ERROR_NOMEMORY;
+ return NULL;
+ }
+
+ w->display = display;
+ w->format = format;
+ w->width = width;
+ w->height = height;
+ w->stride = width * bppFromShmFormat(format);
+ allocSize = w->stride * height;
+ ret = UwacWindowShmAllocBuffers(w, UWAC_INITIAL_BUFFERS, allocSize, width, height, format);
+
+ if (ret != UWAC_SUCCESS)
+ {
+ display->last_error = ret;
+ goto out_error_free;
+ }
+
+ w->buffers[0].used = true;
+ w->drawingBufferIdx = 0;
+ w->pendingBufferIdx = -1;
+ w->surface = wl_compositor_create_surface(display->compositor);
+
+ if (!w->surface)
+ {
+ display->last_error = UWAC_ERROR_NOMEMORY;
+ goto out_error_surface;
+ }
+
+ wl_surface_set_user_data(w->surface, w);
+
+#if BUILD_IVI
+ uint32_t ivi_surface_id = 1;
+ char* env = getenv("IVI_SURFACE_ID");
+ if (env)
+ {
+ unsigned long val = 0;
+ char* endp = NULL;
+
+ errno = 0;
+ val = strtoul(env, &endp, 10);
+
+ if (!errno && val != 0 && val != UINT32_MAX)
+ ivi_surface_id = val;
+ }
+
+ if (display->ivi_application)
+ {
+ w->ivi_surface =
+ ivi_application_surface_create(display->ivi_application, ivi_surface_id, w->surface);
+ assert(w->ivi_surface);
+ ivi_surface_add_listener(w->ivi_surface, &ivi_surface_listener, w);
+ }
+ else
+#endif
+#if BUILD_FULLSCREEN_SHELL
+ if (display->fullscreen_shell)
+ {
+ zwp_fullscreen_shell_v1_present_surface(display->fullscreen_shell, w->surface,
+ ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_CENTER,
+ NULL);
+ }
+ else
+#endif
+ if (display->xdg_base)
+ {
+ w->xdg_surface = xdg_wm_base_get_xdg_surface(display->xdg_base, w->surface);
+
+ if (!w->xdg_surface)
+ {
+ display->last_error = UWAC_ERROR_NOMEMORY;
+ goto out_error_shell;
+ }
+
+ xdg_surface_add_listener(w->xdg_surface, &xdg_surface_listener, w);
+
+ w->xdg_toplevel = xdg_surface_get_toplevel(w->xdg_surface);
+ if (!w->xdg_toplevel)
+ {
+ display->last_error = UWAC_ERROR_NOMEMORY;
+ goto out_error_shell;
+ }
+
+ assert(w->xdg_surface);
+ xdg_toplevel_add_listener(w->xdg_toplevel, &xdg_toplevel_listener, w);
+ wl_surface_commit(w->surface);
+ wl_display_roundtrip(w->display->display);
+ }
+ else
+ {
+ w->shell_surface = wl_shell_get_shell_surface(display->shell, w->surface);
+ assert(w->shell_surface);
+ wl_shell_surface_add_listener(w->shell_surface, &shell_listener, w);
+ wl_shell_surface_set_toplevel(w->shell_surface);
+ }
+
+ if (display->viewporter)
+ {
+ w->viewport = wp_viewporter_get_viewport(display->viewporter, w->surface);
+ if (display->actual_scale != 1)
+ wl_surface_set_buffer_scale(w->surface, display->actual_scale);
+ }
+
+ wl_list_insert(display->windows.prev, &w->link);
+ display->last_error = UWAC_SUCCESS;
+ UwacWindowSetDecorations(w);
+ return w;
+out_error_shell:
+ wl_surface_destroy(w->surface);
+out_error_surface:
+ UwacWindowDestroyBuffers(w);
+out_error_free:
+ free(w);
+ return NULL;
+}
+
+UwacReturnCode UwacDestroyWindow(UwacWindow** pwindow)
+{
+ UwacWindow* w = NULL;
+ assert(pwindow);
+ w = *pwindow;
+ UwacWindowDestroyBuffers(w);
+
+ if (w->deco)
+ zxdg_toplevel_decoration_v1_destroy(w->deco);
+
+ if (w->kde_deco)
+ org_kde_kwin_server_decoration_destroy(w->kde_deco);
+
+ if (w->xdg_surface)
+ xdg_surface_destroy(w->xdg_surface);
+
+#if BUILD_IVI
+
+ if (w->ivi_surface)
+ ivi_surface_destroy(w->ivi_surface);
+
+#endif
+
+ if (w->opaque_region)
+ wl_region_destroy(w->opaque_region);
+
+ if (w->input_region)
+ wl_region_destroy(w->input_region);
+
+ if (w->viewport)
+ wp_viewport_destroy(w->viewport);
+
+ wl_surface_destroy(w->surface);
+ wl_list_remove(&w->link);
+ free(w);
+ *pwindow = NULL;
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacWindowSetOpaqueRegion(UwacWindow* window, uint32_t x, uint32_t y, uint32_t width,
+ uint32_t height)
+{
+ assert(window);
+
+ if (window->opaque_region)
+ wl_region_destroy(window->opaque_region);
+
+ window->opaque_region = wl_compositor_create_region(window->display->compositor);
+
+ if (!window->opaque_region)
+ return UWAC_ERROR_NOMEMORY;
+
+ wl_region_add(window->opaque_region, x, y, width, height);
+ wl_surface_set_opaque_region(window->surface, window->opaque_region);
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacWindowSetInputRegion(UwacWindow* window, uint32_t x, uint32_t y, uint32_t width,
+ uint32_t height)
+{
+ assert(window);
+
+ if (window->input_region)
+ wl_region_destroy(window->input_region);
+
+ window->input_region = wl_compositor_create_region(window->display->compositor);
+
+ if (!window->input_region)
+ return UWAC_ERROR_NOMEMORY;
+
+ wl_region_add(window->input_region, x, y, width, height);
+ wl_surface_set_input_region(window->surface, window->input_region);
+ return UWAC_SUCCESS;
+}
+
+void* UwacWindowGetDrawingBuffer(UwacWindow* window)
+{
+ UwacBuffer* buffer = NULL;
+
+ if (window->drawingBufferIdx < 0)
+ return NULL;
+
+ buffer = &window->buffers[window->drawingBufferIdx];
+ if (!buffer)
+ return NULL;
+
+ return buffer->data;
+}
+
+static void frame_done_cb(void* data, struct wl_callback* callback, uint32_t time);
+
+static const struct wl_callback_listener frame_listener = { frame_done_cb };
+
+#ifdef UWAC_HAVE_PIXMAN_REGION
+static void damage_surface(UwacWindow* window, UwacBuffer* buffer, int scale)
+{
+ int nrects = 0;
+ const pixman_box32_t* box = pixman_region32_rectangles(&buffer->damage, &nrects);
+
+ for (int i = 0; i < nrects; i++, box++)
+ {
+ const int x = ((int)floor(box->x1 / scale)) - 1;
+ const int y = ((int)floor(box->y1 / scale)) - 1;
+ const int w = ((int)ceil((box->x2 - box->x1) / scale)) + 2;
+ const int h = ((int)ceil((box->y2 - box->y1) / scale)) + 2;
+ wl_surface_damage(window->surface, x, y, w, h);
+ }
+
+ pixman_region32_clear(&buffer->damage);
+}
+#else
+static void damage_surface(UwacWindow* window, UwacBuffer* buffer, int scale)
+{
+ uint32_t nrects = 0;
+ const RECTANGLE_16* box = region16_rects(&buffer->damage, &nrects);
+
+ for (UINT32 i = 0; i < nrects; i++, box++)
+ {
+ const int x = ((int)floor(box->left / scale)) - 1;
+ const int y = ((int)floor(box->top / scale)) - 1;
+ const int w = ((int)ceil((box->right - box->left) / scale)) + 2;
+ const int h = ((int)ceil((box->bottom - box->top) / scale)) + 2;
+ wl_surface_damage(window->surface, x, y, w, h);
+ }
+
+ region16_clear(&buffer->damage);
+}
+#endif
+
+static void UwacSubmitBufferPtr(UwacWindow* window, UwacBuffer* buffer)
+{
+ wl_surface_attach(window->surface, buffer->wayland_buffer, 0, 0);
+
+ int scale = window->display->actual_scale;
+ damage_surface(window, buffer, scale);
+
+ struct wl_callback* frame_callback = wl_surface_frame(window->surface);
+ wl_callback_add_listener(frame_callback, &frame_listener, window);
+ wl_surface_commit(window->surface);
+ buffer->dirty = false;
+}
+
+static void frame_done_cb(void* data, struct wl_callback* callback, uint32_t time)
+{
+ UwacWindow* window = (UwacWindow*)data;
+ UwacFrameDoneEvent* event = NULL;
+
+ wl_callback_destroy(callback);
+ window->pendingBufferIdx = -1;
+ event = (UwacFrameDoneEvent*)UwacDisplayNewEvent(window->display, UWAC_EVENT_FRAME_DONE);
+
+ if (event)
+ event->window = window;
+}
+
+#ifdef UWAC_HAVE_PIXMAN_REGION
+UwacReturnCode UwacWindowAddDamage(UwacWindow* window, uint32_t x, uint32_t y, uint32_t width,
+ uint32_t height)
+{
+ UwacBuffer* buf = NULL;
+
+ if (window->drawingBufferIdx < 0)
+ return UWAC_ERROR_INTERNAL;
+
+ buf = &window->buffers[window->drawingBufferIdx];
+ if (!pixman_region32_union_rect(&buf->damage, &buf->damage, x, y, width, height))
+ return UWAC_ERROR_INTERNAL;
+
+ buf->dirty = true;
+ return UWAC_SUCCESS;
+}
+#else
+UwacReturnCode UwacWindowAddDamage(UwacWindow* window, uint32_t x, uint32_t y, uint32_t width,
+ uint32_t height)
+{
+ RECTANGLE_16 box;
+ UwacBuffer* buf = NULL;
+
+ box.left = x;
+ box.top = y;
+ box.right = x + width;
+ box.bottom = y + height;
+
+ if (window->drawingBufferIdx < 0)
+ return UWAC_ERROR_INTERNAL;
+
+ buf = &window->buffers[window->drawingBufferIdx];
+ if (!buf)
+ return UWAC_ERROR_INTERNAL;
+
+ if (!region16_union_rect(&buf->damage, &buf->damage, &box))
+ return UWAC_ERROR_INTERNAL;
+
+ buf->dirty = true;
+ return UWAC_SUCCESS;
+}
+#endif
+
+UwacReturnCode UwacWindowGetDrawingBufferGeometry(UwacWindow* window, UwacSize* geometry,
+ size_t* stride)
+{
+ if (!window || (window->drawingBufferIdx < 0))
+ return UWAC_ERROR_INTERNAL;
+
+ if (geometry)
+ {
+ geometry->width = window->width;
+ geometry->height = window->height;
+ }
+
+ if (stride)
+ *stride = window->stride;
+
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacWindowSubmitBuffer(UwacWindow* window, bool copyContentForNextFrame)
+{
+ UwacBuffer* currentDrawingBuffer = NULL;
+ UwacBuffer* nextDrawingBuffer = NULL;
+ UwacBuffer* pendingBuffer = NULL;
+
+ if (window->drawingBufferIdx < 0)
+ return UWAC_ERROR_INTERNAL;
+
+ currentDrawingBuffer = &window->buffers[window->drawingBufferIdx];
+
+ if ((window->pendingBufferIdx >= 0) || !currentDrawingBuffer->dirty)
+ return UWAC_SUCCESS;
+
+ window->pendingBufferIdx = window->drawingBufferIdx;
+ nextDrawingBuffer = UwacWindowFindFreeBuffer(window, &window->drawingBufferIdx);
+ pendingBuffer = &window->buffers[window->pendingBufferIdx];
+
+ if ((!nextDrawingBuffer) || (window->drawingBufferIdx < 0))
+ return UWAC_ERROR_NOMEMORY;
+
+ if (copyContentForNextFrame)
+ memcpy(nextDrawingBuffer->data, pendingBuffer->data,
+ 1ull * window->stride * window->height);
+
+ UwacSubmitBufferPtr(window, pendingBuffer);
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacWindowGetGeometry(UwacWindow* window, UwacSize* geometry)
+{
+ assert(window);
+ assert(geometry);
+ geometry->width = window->width;
+ geometry->height = window->height;
+ return UWAC_SUCCESS;
+}
+
+UwacReturnCode UwacWindowSetFullscreenState(UwacWindow* window, UwacOutput* output,
+ bool isFullscreen)
+{
+ if (window->xdg_toplevel)
+ {
+ if (isFullscreen)
+ {
+ xdg_toplevel_set_fullscreen(window->xdg_toplevel, output ? output->output : NULL);
+ }
+ else
+ {
+ xdg_toplevel_unset_fullscreen(window->xdg_toplevel);
+ }
+ }
+ else if (window->shell_surface)
+ {
+ if (isFullscreen)
+ {
+ wl_shell_surface_set_fullscreen(window->shell_surface,
+ WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0,
+ output ? output->output : NULL);
+ }
+ else
+ {
+ wl_shell_surface_set_toplevel(window->shell_surface);
+ }
+ }
+
+ return UWAC_SUCCESS;
+}
+
+void UwacWindowSetTitle(UwacWindow* window, const char* name)
+{
+ if (window->xdg_toplevel)
+ xdg_toplevel_set_title(window->xdg_toplevel, name);
+ else if (window->shell_surface)
+ wl_shell_surface_set_title(window->shell_surface, name);
+}
+
+void UwacWindowSetAppId(UwacWindow* window, const char* app_id)
+{
+ if (window->xdg_toplevel)
+ xdg_toplevel_set_app_id(window->xdg_toplevel, app_id);
+}
diff --git a/uwac/protocols/fullscreen-shell-unstable-v1.xml b/uwac/protocols/fullscreen-shell-unstable-v1.xml
new file mode 100644
index 0000000..7d141ee
--- /dev/null
+++ b/uwac/protocols/fullscreen-shell-unstable-v1.xml
@@ -0,0 +1,220 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="fullscreen_shell_unstable_v1">
+
+ <interface name="zwp_fullscreen_shell_v1" version="1">
+ <description summary="displays a single surface per output">
+ Displays a single surface per output.
+
+ This interface provides a mechanism for a single client to display
+ simple full-screen surfaces. While there technically may be multiple
+ clients bound to this interface, only one of those clients should be
+ shown at a time.
+
+ To present a surface, the client uses either the present_surface or
+ present_surface_for_mode requests. Presenting a surface takes effect
+ on the next wl_surface.commit. See the individual requests for
+ details about scaling and mode switches.
+
+ The client can have at most one surface per output at any time.
+ Requesting a surface to be presented on an output that already has a
+ surface replaces the previously presented surface. Presenting a null
+ surface removes its content and effectively disables the output.
+ Exactly what happens when an output is "disabled" is
+ compositor-specific. The same surface may be presented on multiple
+ outputs simultaneously.
+
+ Once a surface is presented on an output, it stays on that output
+ until either the client removes it or the compositor destroys the
+ output. This way, the client can update the output's contents by
+ simply attaching a new buffer.
+
+ Warning! The protocol described in this file is experimental and
+ backward incompatible changes may be made. Backward compatible changes
+ may be added together with the corresponding interface version bump.
+ Backward incompatible changes are done by bumping the version number in
+ the protocol and interface names and resetting the interface version.
+ Once the protocol is to be declared stable, the 'z' prefix and the
+ version number in the protocol and interface names are removed and the
+ interface version number is reset.
+ </description>
+
+ <request name="release" type="destructor">
+ <description summary="release the wl_fullscreen_shell interface">
+ Release the binding from the wl_fullscreen_shell interface.
+
+ This destroys the server-side object and frees this binding. If
+ the client binds to wl_fullscreen_shell multiple times, it may wish
+ to free some of those bindings.
+ </description>
+ </request>
+
+ <enum name="capability">
+ <description summary="capabilities advertised by the compositor">
+ Various capabilities that can be advertised by the compositor. They
+ are advertised one-at-a-time when the wl_fullscreen_shell interface is
+ bound. See the wl_fullscreen_shell.capability event for more details.
+
+ ARBITRARY_MODES:
+ This is a hint to the client that indicates that the compositor is
+ capable of setting practically any mode on its outputs. If this
+ capability is provided, wl_fullscreen_shell.present_surface_for_mode
+ will almost never fail and clients should feel free to set whatever
+ mode they like. If the compositor does not advertise this, it may
+ still support some modes that are not advertised through wl_global.mode
+ but it is less likely.
+
+ CURSOR_PLANE:
+ This is a hint to the client that indicates that the compositor can
+ handle a cursor surface from the client without actually compositing.
+ This may be because of a hardware cursor plane or some other mechanism.
+ If the compositor does not advertise this capability then setting
+ wl_pointer.cursor may degrade performance or be ignored entirely. If
+ CURSOR_PLANE is not advertised, it is recommended that the client draw
+ its own cursor and set wl_pointer.cursor(NULL).
+ </description>
+ <entry name="arbitrary_modes" value="1" summary="compositor is capable of almost any output mode"/>
+ <entry name="cursor_plane" value="2" summary="compositor has a separate cursor plane"/>
+ </enum>
+
+ <event name="capability">
+ <description summary="advertises a capability of the compositor">
+ Advertises a single capability of the compositor.
+
+ When the wl_fullscreen_shell interface is bound, this event is emitted
+ once for each capability advertised. Valid capabilities are given by
+ the wl_fullscreen_shell.capability enum. If clients want to take
+ advantage of any of these capabilities, they should use a
+ wl_display.sync request immediately after binding to ensure that they
+ receive all the capability events.
+ </description>
+ <arg name="capability" type="uint"/>
+ </event>
+
+ <enum name="present_method">
+ <description summary="different method to set the surface fullscreen">
+ Hints to indicate to the compositor how to deal with a conflict
+ between the dimensions of the surface and the dimensions of the
+ output. The compositor is free to ignore this parameter.
+ </description>
+ <entry name="default" value="0" summary="no preference, apply default policy"/>
+ <entry name="center" value="1" summary="center the surface on the output"/>
+ <entry name="zoom" value="2" summary="scale the surface, preserving aspect ratio, to the largest size that will fit on the output" />
+ <entry name="zoom_crop" value="3" summary="scale the surface, preserving aspect ratio, to fully fill the output cropping if needed" />
+ <entry name="stretch" value="4" summary="scale the surface to the size of the output ignoring aspect ratio" />
+ </enum>
+
+ <request name="present_surface">
+ <description summary="present surface for display">
+ Present a surface on the given output.
+
+ If the output is null, the compositor will present the surface on
+ whatever display (or displays) it thinks best. In particular, this
+ may replace any or all surfaces currently presented so it should
+ not be used in combination with placing surfaces on specific
+ outputs.
+
+ The method parameter is a hint to the compositor for how the surface
+ is to be presented. In particular, it tells the compositor how to
+ handle a size mismatch between the presented surface and the
+ output. The compositor is free to ignore this parameter.
+
+ The "zoom", "zoom_crop", and "stretch" methods imply a scaling
+ operation on the surface. This will override any kind of output
+ scaling, so the buffer_scale property of the surface is effectively
+ ignored.
+ </description>
+ <arg name="surface" type="object" interface="wl_surface" allow-null="true"/>
+ <arg name="method" type="uint"/>
+ <arg name="output" type="object" interface="wl_output" allow-null="true"/>
+ </request>
+
+ <request name="present_surface_for_mode">
+ <description summary="present surface for display at a particular mode">
+ Presents a surface on the given output for a particular mode.
+
+ If the current size of the output differs from that of the surface,
+ the compositor will attempt to change the size of the output to
+ match the surface. The result of the mode-switch operation will be
+ returned via the provided wl_fullscreen_shell_mode_feedback object.
+
+ If the current output mode matches the one requested or if the
+ compositor successfully switches the mode to match the surface,
+ then the mode_successful event will be sent and the output will
+ contain the contents of the given surface. If the compositor
+ cannot match the output size to the surface size, the mode_failed
+ will be sent and the output will contain the contents of the
+ previously presented surface (if any). If another surface is
+ presented on the given output before either of these has a chance
+ to happen, the present_cancelled event will be sent.
+
+ Due to race conditions and other issues unknown to the client, no
+ mode-switch operation is guaranteed to succeed. However, if the
+ mode is one advertised by wl_output.mode or if the compositor
+ advertises the ARBITRARY_MODES capability, then the client should
+ expect that the mode-switch operation will usually succeed.
+
+ If the size of the presented surface changes, the resulting output
+ is undefined. The compositor may attempt to change the output mode
+ to compensate. However, there is no guarantee that a suitable mode
+ will be found and the client has no way to be notified of success
+ or failure.
+
+ The framerate parameter specifies the desired framerate for the
+ output in mHz. The compositor is free to ignore this parameter. A
+ value of 0 indicates that the client has no preference.
+
+ If the value of wl_output.scale differs from wl_surface.buffer_scale,
+ then the compositor may choose a mode that matches either the buffer
+ size or the surface size. In either case, the surface will fill the
+ output.
+ </description>
+ <arg name="surface" type="object" interface="wl_surface"/>
+ <arg name="output" type="object" interface="wl_output"/>
+ <arg name="framerate" type="int"/>
+ <arg name="feedback" type="new_id" interface="zwp_fullscreen_shell_mode_feedback_v1"/>
+ </request>
+
+ <enum name="error">
+ <description summary="wl_fullscreen_shell error values">
+ These errors can be emitted in response to wl_fullscreen_shell requests.
+ </description>
+ <entry name="invalid_method" value="0" summary="present_method is not known"/>
+ </enum>
+ </interface>
+
+ <interface name="zwp_fullscreen_shell_mode_feedback_v1" version="1">
+ <event name="mode_successful">
+ <description summary="mode switch succeeded">
+ This event indicates that the attempted mode switch operation was
+ successful. A surface of the size requested in the mode switch
+ will fill the output without scaling.
+
+ Upon receiving this event, the client should destroy the
+ wl_fullscreen_shell_mode_feedback object.
+ </description>
+ </event>
+
+ <event name="mode_failed">
+ <description summary="mode switch failed">
+ This event indicates that the attempted mode switch operation
+ failed. This may be because the requested output mode is not
+ possible or it may mean that the compositor does not want to allow it.
+
+ Upon receiving this event, the client should destroy the
+ wl_fullscreen_shell_mode_feedback object.
+ </description>
+ </event>
+
+ <event name="present_cancelled">
+ <description summary="mode switch cancelled">
+ This event indicates that the attempted mode switch operation was
+ cancelled. Most likely this is because the client requested a
+ second mode switch before the first one completed.
+
+ Upon receiving this event, the client should destroy the
+ wl_fullscreen_shell_mode_feedback object.
+ </description>
+ </event>
+ </interface>
+
+</protocol>
diff --git a/uwac/protocols/ivi-application.xml b/uwac/protocols/ivi-application.xml
new file mode 100644
index 0000000..8f24226
--- /dev/null
+++ b/uwac/protocols/ivi-application.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="ivi_application">
+
+ <copyright>
+ Copyright (C) 2013 DENSO CORPORATION
+ Copyright (c) 2013 BMW Car IT GmbH
+
+ 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 (including the next
+ paragraph) 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.
+ </copyright>
+
+ <interface name="ivi_surface" version="1">
+ <description summary="application interface to surface in ivi compositor"/>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy ivi_surface">
+ This removes link from ivi_id to wl_surface and destroys ivi_surface.
+ The ID, ivi_id, is free and can be used for surface_create again.
+ </description>
+ </request>
+
+ <event name="configure">
+ <description summary="suggest resize">
+ The configure event asks the client to resize its surface.
+
+ The size is a hint, in the sense that the client is free to
+ ignore it if it doesn't resize, pick a smaller size (to
+ satisfy aspect ratio or resize in steps of NxM pixels).
+
+ The client is free to dismiss all but the last configure
+ event it received.
+
+ The width and height arguments specify the size of the window
+ in surface local coordinates.
+ </description>
+ <arg name="width" type="int"/>
+ <arg name="height" type="int"/>
+ </event>
+ </interface>
+
+ <interface name="ivi_application" version="1">
+ <description summary="create ivi-style surfaces">
+ This interface is exposed as a global singleton.
+ This interface is implemented by servers that provide IVI-style user interfaces.
+ It allows clients to associate a ivi_surface with wl_surface.
+ </description>
+
+ <enum name="error">
+ <entry name="role" value="0" summary="given wl_surface has another role"/>
+ <entry name="ivi_id" value="1" summary="given ivi_id is assigned to another wl_surface"/>
+ </enum>
+
+ <request name="surface_create">
+ <description summary="create ivi_surface with numeric ID in ivi compositor">
+ This request gives the wl_surface the role of an IVI Surface. Creating more than
+ one ivi_surface for a wl_surface is not allowed. Note, that this still allows the
+ following example:
+
+ 1. create a wl_surface
+ 2. create ivi_surface for the wl_surface
+ 3. destroy the ivi_surface
+ 4. create ivi_surface for the wl_surface (with the same or another ivi_id as before)
+
+ surface_create will create a interface:ivi_surface with numeric ID; ivi_id in
+ ivi compositor. These ivi_ids are defined as unique in the system to identify
+ it inside of ivi compositor. The ivi compositor implements business logic how to
+ set properties of the surface with ivi_id according to status of the system.
+ E.g. a unique ID for Car Navigation application is used for implementing special
+ logic of the application about where it shall be located.
+ The server regards following cases as protocol errors and disconnects the client.
+ - wl_surface already has an nother role.
+ - ivi_id is already assigned to an another wl_surface.
+
+ If client destroys ivi_surface or wl_surface which is assigne to the ivi_surface,
+ ivi_id which is assigned to the ivi_surface is free for reuse.
+ </description>
+ <arg name="ivi_id" type="uint"/>
+ <arg name="surface" type="object" interface="wl_surface"/>
+ <arg name="id" type="new_id" interface="ivi_surface"/>
+ </request>
+
+ </interface>
+
+</protocol>
diff --git a/uwac/protocols/keyboard-shortcuts-inhibit-unstable-v1.xml b/uwac/protocols/keyboard-shortcuts-inhibit-unstable-v1.xml
new file mode 100644
index 0000000..2774876
--- /dev/null
+++ b/uwac/protocols/keyboard-shortcuts-inhibit-unstable-v1.xml
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="keyboard_shortcuts_inhibit_unstable_v1">
+
+ <copyright>
+ Copyright © 2017 Red Hat Inc.
+
+ 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 (including the next
+ paragraph) 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.
+ </copyright>
+
+ <description summary="Protocol for inhibiting the compositor keyboard shortcuts">
+ This protocol specifies a way for a client to request the compositor
+ to ignore its own keyboard shortcuts for a given seat, so that all
+ key events from that seat get forwarded to a surface.
+
+ Warning! The protocol described in this file is experimental and
+ backward incompatible changes may be made. Backward compatible
+ changes may be added together with the corresponding interface
+ version bump.
+ Backward incompatible changes are done by bumping the version
+ number in the protocol and interface names and resetting the
+ interface version. Once the protocol is to be declared stable,
+ the 'z' prefix and the version number in the protocol and
+ interface names are removed and the interface version number is
+ reset.
+ </description>
+
+ <interface name="zwp_keyboard_shortcuts_inhibit_manager_v1" version="1">
+ <description summary="context object for keyboard grab_manager">
+ A global interface used for inhibiting the compositor keyboard shortcuts.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the keyboard shortcuts inhibitor object">
+ Destroy the keyboard shortcuts inhibitor manager.
+ </description>
+ </request>
+
+ <request name="inhibit_shortcuts">
+ <description summary="create a new keyboard shortcuts inhibitor object">
+ Create a new keyboard shortcuts inhibitor object associated with
+ the given surface for the given seat.
+
+ If shortcuts are already inhibited for the specified seat and surface,
+ a protocol error "already_inhibited" is raised by the compositor.
+ </description>
+ <arg name="id" type="new_id" interface="zwp_keyboard_shortcuts_inhibitor_v1"/>
+ <arg name="surface" type="object" interface="wl_surface"
+ summary="the surface that inhibits the keyboard shortcuts behavior"/>
+ <arg name="seat" type="object" interface="wl_seat"
+ summary="the wl_seat for which keyboard shortcuts should be disabled"/>
+ </request>
+
+ <enum name="error">
+ <entry name="already_inhibited"
+ value="0"
+ summary="the shortcuts are already inhibited for this surface"/>
+ </enum>
+ </interface>
+
+ <interface name="zwp_keyboard_shortcuts_inhibitor_v1" version="1">
+ <description summary="context object for keyboard shortcuts inhibitor">
+ A keyboard shortcuts inhibitor instructs the compositor to ignore
+ its own keyboard shortcuts when the associated surface has keyboard
+ focus. As a result, when the surface has keyboard focus on the given
+ seat, it will receive all key events originating from the specified
+ seat, even those which would normally be caught by the compositor for
+ its own shortcuts.
+
+ The Wayland compositor is however under no obligation to disable
+ all of its shortcuts, and may keep some special key combo for its own
+ use, including but not limited to one allowing the user to forcibly
+ restore normal keyboard events routing in the case of an unwilling
+ client. The compositor may also use the same key combo to reactivate
+ an existing shortcut inhibitor that was previously deactivated on
+ user request.
+
+ When the compositor restores its own keyboard shortcuts, an
+ "inactive" event is emitted to notify the client that the keyboard
+ shortcuts inhibitor is not effectively active for the surface and
+ seat any more, and the client should not expect to receive all
+ keyboard events.
+
+ When the keyboard shortcuts inhibitor is inactive, the client has
+ no way to forcibly reactivate the keyboard shortcuts inhibitor.
+
+ The user can chose to re-enable a previously deactivated keyboard
+ shortcuts inhibitor using any mechanism the compositor may offer,
+ in which case the compositor will send an "active" event to notify
+ the client.
+
+ If the surface is destroyed, unmapped, or loses the seat's keyboard
+ focus, the keyboard shortcuts inhibitor becomes irrelevant and the
+ compositor will restore its own keyboard shortcuts but no "inactive"
+ event is emitted in this case.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the keyboard shortcuts inhibitor object">
+ Remove the keyboard shortcuts inhibitor from the associated wl_surface.
+ </description>
+ </request>
+
+ <event name="active">
+ <description summary="shortcuts are inhibited">
+ This event indicates that the shortcut inhibitor is active.
+
+ The compositor sends this event every time compositor shortcuts
+ are inhibited on behalf of the surface. When active, the client
+ may receive input events normally reserved by the compositor
+ (see zwp_keyboard_shortcuts_inhibitor_v1).
+
+ This occurs typically when the initial request "inhibit_shortcuts"
+ first becomes active or when the user instructs the compositor to
+ re-enable and existing shortcuts inhibitor using any mechanism
+ offered by the compositor.
+ </description>
+ </event>
+
+ <event name="inactive">
+ <description summary="shortcuts are restored">
+ This event indicates that the shortcuts inhibitor is inactive,
+ normal shortcuts processing is restored by the compositor.
+ </description>
+ </event>
+ </interface>
+</protocol>
diff --git a/uwac/protocols/server-decoration.xml b/uwac/protocols/server-decoration.xml
new file mode 100644
index 0000000..7ea135a
--- /dev/null
+++ b/uwac/protocols/server-decoration.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="server_decoration">
+ <copyright><![CDATA[
+ Copyright (C) 2015 Martin Gräßlin
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ ]]></copyright>
+ <interface name="org_kde_kwin_server_decoration_manager" version="1">
+ <description summary="Server side window decoration manager">
+ This interface allows to coordinate whether the server should create
+ a server-side window decoration around a wl_surface representing a
+ shell surface (wl_shell_surface or similar). By announcing support
+ for this interface the server indicates that it supports server
+ side decorations.
+
+ Use in conjunction with zxdg_decoration_manager_v1 is undefined.
+ </description>
+ <request name="create">
+ <description summary="Create a server-side decoration object for a given surface">
+ When a client creates a server-side decoration object it indicates
+ that it supports the protocol. The client is supposed to tell the
+ server whether it wants server-side decorations or will provide
+ client-side decorations.
+
+ If the client does not create a server-side decoration object for
+ a surface the server interprets this as lack of support for this
+ protocol and considers it as client-side decorated. Nevertheless a
+ client-side decorated surface should use this protocol to indicate
+ to the server that it does not want a server-side deco.
+ </description>
+ <arg name="id" type="new_id" interface="org_kde_kwin_server_decoration"/>
+ <arg name="surface" type="object" interface="wl_surface"/>
+ </request>
+ <enum name="mode">
+ <description summary="Possible values to use in request_mode and the event mode."/>
+ <entry name="None" value="0" summary="Undecorated: The surface is not decorated at all, neither server nor client-side. An example is a popup surface which should not be decorated."/>
+ <entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
+ <entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
+ </enum>
+ <event name="default_mode">
+ <description summary="The default mode used on the server">
+ This event is emitted directly after binding the interface. It contains
+ the default mode for the decoration. When a new server decoration object
+ is created this new object will be in the default mode until the first
+ request_mode is requested.
+
+ The server may change the default mode at any time.
+ </description>
+ <arg name="mode" type="uint" summary="The default decoration mode applied to newly created server decorations."/>
+ </event>
+ </interface>
+ <interface name="org_kde_kwin_server_decoration" version="1">
+ <request name="release" type="destructor">
+ <description summary="release the server decoration object"/>
+ </request>
+ <enum name="mode">
+ <description summary="Possible values to use in request_mode and the event mode."/>
+ <entry name="None" value="0" summary="Undecorated: The surface is not decorated at all, neither server nor client-side. An example is a popup surface which should not be decorated."/>
+ <entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
+ <entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
+ </enum>
+ <request name="request_mode">
+ <description summary="The decoration mode the surface wants to use."/>
+ <arg name="mode" type="uint" summary="The mode this surface wants to use."/>
+ </request>
+ <event name="mode">
+ <description summary="The new decoration mode applied by the server">
+ This event is emitted directly after the decoration is created and
+ represents the base decoration policy by the server. E.g. a server
+ which wants all surfaces to be client-side decorated will send Client,
+ a server which wants server-side decoration will send Server.
+
+ The client can request a different mode through the decoration request.
+ The server will acknowledge this by another event with the same mode. So
+ even if a server prefers server-side decoration it's possible to force a
+ client-side decoration.
+
+ The server may emit this event at any time. In this case the client can
+ again request a different mode. It's the responsibility of the server to
+ prevent a feedback loop.
+ </description>
+ <arg name="mode" type="uint" summary="The decoration mode applied to the surface by the server."/>
+ </event>
+ </interface>
+</protocol>
diff --git a/uwac/protocols/viewporter.xml b/uwac/protocols/viewporter.xml
new file mode 100644
index 0000000..d1048d1
--- /dev/null
+++ b/uwac/protocols/viewporter.xml
@@ -0,0 +1,180 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="viewporter">
+
+ <copyright>
+ Copyright © 2013-2016 Collabora, Ltd.
+
+ 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 (including the next
+ paragraph) 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.
+ </copyright>
+
+ <interface name="wp_viewporter" version="1">
+ <description summary="surface cropping and scaling">
+ The global interface exposing surface cropping and scaling
+ capabilities is used to instantiate an interface extension for a
+ wl_surface object. This extended interface will then allow
+ cropping and scaling the surface contents, effectively
+ disconnecting the direct relationship between the buffer and the
+ surface size.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="unbind from the cropping and scaling interface">
+ Informs the server that the client will not be using this
+ protocol object anymore. This does not affect any other objects,
+ wp_viewport objects included.
+ </description>
+ </request>
+
+ <enum name="error">
+ <entry name="viewport_exists" value="0"
+ summary="the surface already has a viewport object associated"/>
+ </enum>
+
+ <request name="get_viewport">
+ <description summary="extend surface interface for crop and scale">
+ Instantiate an interface extension for the given wl_surface to
+ crop and scale its content. If the given wl_surface already has
+ a wp_viewport object associated, the viewport_exists
+ protocol error is raised.
+ </description>
+ <arg name="id" type="new_id" interface="wp_viewport"
+ summary="the new viewport interface id"/>
+ <arg name="surface" type="object" interface="wl_surface"
+ summary="the surface"/>
+ </request>
+ </interface>
+
+ <interface name="wp_viewport" version="1">
+ <description summary="crop and scale interface to a wl_surface">
+ An additional interface to a wl_surface object, which allows the
+ client to specify the cropping and scaling of the surface
+ contents.
+
+ This interface works with two concepts: the source rectangle (src_x,
+ src_y, src_width, src_height), and the destination size (dst_width,
+ dst_height). The contents of the source rectangle are scaled to the
+ destination size, and content outside the source rectangle is ignored.
+ This state is double-buffered, and is applied on the next
+ wl_surface.commit.
+
+ The two parts of crop and scale state are independent: the source
+ rectangle, and the destination size. Initially both are unset, that
+ is, no scaling is applied. The whole of the current wl_buffer is
+ used as the source, and the surface size is as defined in
+ wl_surface.attach.
+
+ If the destination size is set, it causes the surface size to become
+ dst_width, dst_height. The source (rectangle) is scaled to exactly
+ this size. This overrides whatever the attached wl_buffer size is,
+ unless the wl_buffer is NULL. If the wl_buffer is NULL, the surface
+ has no content and therefore no size. Otherwise, the size is always
+ at least 1x1 in surface local coordinates.
+
+ If the source rectangle is set, it defines what area of the wl_buffer is
+ taken as the source. If the source rectangle is set and the destination
+ size is not set, then src_width and src_height must be integers, and the
+ surface size becomes the source rectangle size. This results in cropping
+ without scaling. If src_width or src_height are not integers and
+ destination size is not set, the bad_size protocol error is raised when
+ the surface state is applied.
+
+ The coordinate transformations from buffer pixel coordinates up to
+ the surface-local coordinates happen in the following order:
+ 1. buffer_transform (wl_surface.set_buffer_transform)
+ 2. buffer_scale (wl_surface.set_buffer_scale)
+ 3. crop and scale (wp_viewport.set*)
+ This means, that the source rectangle coordinates of crop and scale
+ are given in the coordinates after the buffer transform and scale,
+ i.e. in the coordinates that would be the surface-local coordinates
+ if the crop and scale was not applied.
+
+ If src_x or src_y are negative, the bad_value protocol error is raised.
+ Otherwise, if the source rectangle is partially or completely outside of
+ the non-NULL wl_buffer, then the out_of_buffer protocol error is raised
+ when the surface state is applied. A NULL wl_buffer does not raise the
+ out_of_buffer error.
+
+ If the wl_surface associated with the wp_viewport is destroyed,
+ all wp_viewport requests except 'destroy' raise the protocol error
+ no_surface.
+
+ If the wp_viewport object is destroyed, the crop and scale
+ state is removed from the wl_surface. The change will be applied
+ on the next wl_surface.commit.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="remove scaling and cropping from the surface">
+ The associated wl_surface's crop and scale state is removed.
+ The change is applied on the next wl_surface.commit.
+ </description>
+ </request>
+
+ <enum name="error">
+ <entry name="bad_value" value="0"
+ summary="negative or zero values in width or height"/>
+ <entry name="bad_size" value="1"
+ summary="destination size is not integer"/>
+ <entry name="out_of_buffer" value="2"
+ summary="source rectangle extends outside of the content area"/>
+ <entry name="no_surface" value="3"
+ summary="the wl_surface was destroyed"/>
+ </enum>
+
+ <request name="set_source">
+ <description summary="set the source rectangle for cropping">
+ Set the source rectangle of the associated wl_surface. See
+ wp_viewport for the description, and relation to the wl_buffer
+ size.
+
+ If all of x, y, width and height are -1.0, the source rectangle is
+ unset instead. Any other set of values where width or height are zero
+ or negative, or x or y are negative, raise the bad_value protocol
+ error.
+
+ The crop and scale state is double-buffered state, and will be
+ applied on the next wl_surface.commit.
+ </description>
+ <arg name="x" type="fixed" summary="source rectangle x"/>
+ <arg name="y" type="fixed" summary="source rectangle y"/>
+ <arg name="width" type="fixed" summary="source rectangle width"/>
+ <arg name="height" type="fixed" summary="source rectangle height"/>
+ </request>
+
+ <request name="set_destination">
+ <description summary="set the surface size for scaling">
+ Set the destination size of the associated wl_surface. See
+ wp_viewport for the description, and relation to the wl_buffer
+ size.
+
+ If width is -1 and height is -1, the destination size is unset
+ instead. Any other pair of values for width and height that
+ contains zero or negative values raises the bad_value protocol
+ error.
+
+ The crop and scale state is double-buffered state, and will be
+ applied on the next wl_surface.commit.
+ </description>
+ <arg name="width" type="int" summary="surface width"/>
+ <arg name="height" type="int" summary="surface height"/>
+ </request>
+ </interface>
+
+</protocol>
diff --git a/uwac/protocols/xdg-decoration-unstable-v1.xml b/uwac/protocols/xdg-decoration-unstable-v1.xml
new file mode 100644
index 0000000..378e8ff
--- /dev/null
+++ b/uwac/protocols/xdg-decoration-unstable-v1.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="xdg_decoration_unstable_v1">
+ <copyright>
+ Copyright © 2018 Simon Ser
+
+ 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 (including the next
+ paragraph) 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.
+ </copyright>
+
+ <interface name="zxdg_decoration_manager_v1" version="1">
+ <description summary="window decoration manager">
+ This interface allows a compositor to announce support for server-side
+ decorations.
+
+ A window decoration is a set of window controls as deemed appropriate by
+ the party managing them, such as user interface components used to move,
+ resize and change a window's state.
+
+ A client can use this protocol to request being decorated by a supporting
+ compositor.
+
+ If compositor and client do not negotiate the use of a server-side
+ decoration using this protocol, clients continue to self-decorate as they
+ see fit.
+
+ Warning! The protocol described in this file is experimental and
+ backward incompatible changes may be made. Backward compatible changes
+ may be added together with the corresponding interface version bump.
+ Backward incompatible changes are done by bumping the version number in
+ the protocol and interface names and resetting the interface version.
+ Once the protocol is to be declared stable, the 'z' prefix and the
+ version number in the protocol and interface names are removed and the
+ interface version number is reset.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the decoration manager object">
+ Destroy the decoration manager. This doesn't destroy objects created
+ with the manager.
+ </description>
+ </request>
+
+ <request name="get_toplevel_decoration">
+ <description summary="create a new toplevel decoration object">
+ Create a new decoration object associated with the given toplevel.
+
+ Creating an xdg_toplevel_decoration from an xdg_toplevel which has a
+ buffer attached or committed is a client error, and any attempts by a
+ client to attach or manipulate a buffer prior to the first
+ xdg_toplevel_decoration.configure event must also be treated as
+ errors.
+ </description>
+ <arg name="id" type="new_id" interface="zxdg_toplevel_decoration_v1"/>
+ <arg name="toplevel" type="object" interface="xdg_toplevel"/>
+ </request>
+ </interface>
+
+ <interface name="zxdg_toplevel_decoration_v1" version="1">
+ <description summary="decoration object for a toplevel surface">
+ The decoration object allows the compositor to toggle server-side window
+ decorations for a toplevel surface. The client can request to switch to
+ another mode.
+
+ The xdg_toplevel_decoration object must be destroyed before its
+ xdg_toplevel.
+ </description>
+
+ <enum name="error">
+ <entry name="unconfigured_buffer" value="0"
+ summary="xdg_toplevel has a buffer attached before configure"/>
+ <entry name="already_constructed" value="1"
+ summary="xdg_toplevel already has a decoration object"/>
+ <entry name="orphaned" value="2"
+ summary="xdg_toplevel destroyed before the decoration object"/>
+ </enum>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the decoration object">
+ Switch back to a mode without any server-side decorations at the next
+ commit.
+ </description>
+ </request>
+
+ <enum name="mode">
+ <description summary="window decoration modes">
+ These values describe window decoration modes.
+ </description>
+ <entry name="client_side" value="1"
+ summary="no server-side window decoration"/>
+ <entry name="server_side" value="2"
+ summary="server-side window decoration"/>
+ </enum>
+
+ <request name="set_mode">
+ <description summary="set the decoration mode">
+ Set the toplevel surface decoration mode. This informs the compositor
+ that the client prefers the provided decoration mode.
+
+ After requesting a decoration mode, the compositor will respond by
+ emitting a xdg_surface.configure event. The client should then update
+ its content, drawing it without decorations if the received mode is
+ server-side decorations. The client must also acknowledge the configure
+ when committing the new content (see xdg_surface.ack_configure).
+
+ The compositor can decide not to use the client's mode and enforce a
+ different mode instead.
+
+ Clients whose decoration mode depend on the xdg_toplevel state may send
+ a set_mode request in response to a xdg_surface.configure event and wait
+ for the next xdg_surface.configure event to prevent unwanted state.
+ Such clients are responsible for preventing configure loops and must
+ make sure not to send multiple successive set_mode requests with the
+ same decoration mode.
+ </description>
+ <arg name="mode" type="uint" enum="mode" summary="the decoration mode"/>
+ </request>
+
+ <request name="unset_mode">
+ <description summary="unset the decoration mode">
+ Unset the toplevel surface decoration mode. This informs the compositor
+ that the client doesn't prefer a particular decoration mode.
+
+ This request has the same semantics as set_mode.
+ </description>
+ </request>
+
+ <event name="configure">
+ <description summary="suggest a surface change">
+ The configure event asks the client to change its decoration mode. The
+ configured state should not be applied immediately. Clients must send an
+ ack_configure in response to this event. See xdg_surface.configure and
+ xdg_surface.ack_configure for details.
+
+ A configure event can be sent at any time. The specified mode must be
+ obeyed by the client.
+ </description>
+ <arg name="mode" type="uint" enum="mode" summary="the decoration mode"/>
+ </event>
+ </interface>
+</protocol>
diff --git a/uwac/protocols/xdg-shell.xml b/uwac/protocols/xdg-shell.xml
new file mode 100644
index 0000000..e259a1f
--- /dev/null
+++ b/uwac/protocols/xdg-shell.xml
@@ -0,0 +1,1144 @@
+<?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
+ Copyright © 2015-2017 Samsung Electronics Co., Ltd
+ Copyright © 2015-2017 Red Hat Inc.
+
+ 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 (including the next
+ paragraph) 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.
+ </copyright>
+
+ <interface name="xdg_wm_base" version="2">
+ <description summary="create desktop-style surfaces">
+ The xdg_wm_base interface is exposed as a global object enabling clients
+ to turn their wl_surfaces into windows in a desktop environment. It
+ defines the basic functionality needed for clients and the compositor to
+ create windows that can be dragged, resized, maximized, etc, as well as
+ creating transient windows such as popup menus.
+ </description>
+
+ <enum name="error">
+ <entry name="role" value="0" summary="given wl_surface has another role"/>
+ <entry name="defunct_surfaces" value="1"
+ summary="xdg_wm_base was destroyed before children"/>
+ <entry name="not_the_topmost_popup" value="2"
+ summary="the client tried to map or destroy a non-topmost popup"/>
+ <entry name="invalid_popup_parent" value="3"
+ summary="the client specified an invalid popup parent surface"/>
+ <entry name="invalid_surface_state" value="4"
+ summary="the client provided an invalid surface state"/>
+ <entry name="invalid_positioner" value="5"
+ summary="the client provided an invalid positioner"/>
+ </enum>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy xdg_wm_base">
+ Destroy this xdg_wm_base object.
+
+ Destroying a bound xdg_wm_base object while there are surfaces
+ still alive created by this xdg_wm_base object instance is illegal
+ and will result in a protocol error.
+ </description>
+ </request>
+
+ <request name="create_positioner">
+ <description summary="create a positioner object">
+ Create a positioner object. A positioner object is used to position
+ surfaces relative to some parent surface. See the interface description
+ and xdg_surface.get_popup for details.
+ </description>
+ <arg name="id" type="new_id" interface="xdg_positioner"/>
+ </request>
+
+ <request name="get_xdg_surface">
+ <description summary="create a shell surface from a surface">
+ This creates an xdg_surface for the given surface. While xdg_surface
+ itself is not a role, the corresponding surface may only be assigned
+ a role extending xdg_surface, such as xdg_toplevel or xdg_popup.
+
+ This creates an xdg_surface for the given surface. An xdg_surface is
+ used as basis to define a role to a given surface, such as xdg_toplevel
+ or xdg_popup. It also manages functionality shared between xdg_surface
+ based surface roles.
+
+ See the documentation of xdg_surface for more details about what an
+ xdg_surface is and how it is used.
+ </description>
+ <arg name="id" type="new_id" interface="xdg_surface"/>
+ <arg name="surface" type="object" interface="wl_surface"/>
+ </request>
+
+ <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. See xdg_wm_base.ping.
+ </description>
+ <arg name="serial" type="uint" summary="serial of the ping event"/>
+ </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. See xdg_wm_base.ping.
+
+ 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.
+
+ A compositor is free to ping in any way it wants, but a client must
+ always respond to any xdg_wm_base object it created.
+ </description>
+ <arg name="serial" type="uint" summary="pass this to the pong request"/>
+ </event>
+ </interface>
+
+ <interface name="xdg_positioner" version="2">
+ <description summary="child surface positioner">
+ The xdg_positioner provides a collection of rules for the placement of a
+ child surface relative to a parent surface. Rules can be defined to ensure
+ the child surface remains within the visible area's borders, and to
+ specify how the child surface changes its position, such as sliding along
+ an axis, or flipping around a rectangle. These positioner-created rules are
+ constrained by the requirement that a child surface must intersect with or
+ be at least partially adjacent to its parent surface.
+
+ See the various requests for details about possible rules.
+
+ At the time of the request, the compositor makes a copy of the rules
+ specified by the xdg_positioner. Thus, after the request is complete the
+ xdg_positioner object can be destroyed or reused; further changes to the
+ object will have no effect on previous usages.
+
+ For an xdg_positioner object to be considered complete, it must have a
+ non-zero size set by set_size, and a non-zero anchor rectangle set by
+ set_anchor_rect. Passing an incomplete xdg_positioner object when
+ positioning a surface raises an error.
+ </description>
+
+ <enum name="error">
+ <entry name="invalid_input" value="0" summary="invalid input provided"/>
+ </enum>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the xdg_positioner object">
+ Notify the compositor that the xdg_positioner will no longer be used.
+ </description>
+ </request>
+
+ <request name="set_size">
+ <description summary="set the size of the to-be positioned rectangle">
+ Set the size of the surface that is to be positioned with the positioner
+ object. The size is in surface-local coordinates and corresponds to the
+ window geometry. See xdg_surface.set_window_geometry.
+
+ If a zero or negative size is set the invalid_input error is raised.
+ </description>
+ <arg name="width" type="int" summary="width of positioned rectangle"/>
+ <arg name="height" type="int" summary="height of positioned rectangle"/>
+ </request>
+
+ <request name="set_anchor_rect">
+ <description summary="set the anchor rectangle within the parent surface">
+ Specify the anchor rectangle within the parent surface that the child
+ surface will be placed relative to. The rectangle is relative to the
+ window geometry as defined by xdg_surface.set_window_geometry of the
+ parent surface.
+
+ When the xdg_positioner object is used to position a child surface, the
+ anchor rectangle may not extend outside the window geometry of the
+ positioned child's parent surface.
+
+ If a negative size is set the invalid_input error is raised.
+ </description>
+ <arg name="x" type="int" summary="x position of anchor rectangle"/>
+ <arg name="y" type="int" summary="y position of anchor rectangle"/>
+ <arg name="width" type="int" summary="width of anchor rectangle"/>
+ <arg name="height" type="int" summary="height of anchor rectangle"/>
+ </request>
+
+ <enum name="anchor">
+ <entry name="none" value="0"/>
+ <entry name="top" value="1"/>
+ <entry name="bottom" value="2"/>
+ <entry name="left" value="3"/>
+ <entry name="right" value="4"/>
+ <entry name="top_left" value="5"/>
+ <entry name="bottom_left" value="6"/>
+ <entry name="top_right" value="7"/>
+ <entry name="bottom_right" value="8"/>
+ </enum>
+
+ <request name="set_anchor">
+ <description summary="set anchor rectangle anchor">
+ Defines the anchor point for the anchor rectangle. The specified anchor
+ is used derive an anchor point that the child surface will be
+ positioned relative to. If a corner anchor is set (e.g. 'top_left' or
+ 'bottom_right'), the anchor point will be at the specified corner;
+ otherwise, the derived anchor point will be centered on the specified
+ edge, or in the center of the anchor rectangle if no edge is specified.
+ </description>
+ <arg name="anchor" type="uint" enum="anchor"
+ summary="anchor"/>
+ </request>
+
+ <enum name="gravity">
+ <entry name="none" value="0"/>
+ <entry name="top" value="1"/>
+ <entry name="bottom" value="2"/>
+ <entry name="left" value="3"/>
+ <entry name="right" value="4"/>
+ <entry name="top_left" value="5"/>
+ <entry name="bottom_left" value="6"/>
+ <entry name="top_right" value="7"/>
+ <entry name="bottom_right" value="8"/>
+ </enum>
+
+ <request name="set_gravity">
+ <description summary="set child surface gravity">
+ Defines in what direction a surface should be positioned, relative to
+ the anchor point of the parent surface. If a corner gravity is
+ specified (e.g. 'bottom_right' or 'top_left'), then the child surface
+ will be placed towards the specified gravity; otherwise, the child
+ surface will be centered over the anchor point on any axis that had no
+ gravity specified.
+ </description>
+ <arg name="gravity" type="uint" enum="gravity"
+ summary="gravity direction"/>
+ </request>
+
+ <enum name="constraint_adjustment" bitfield="true">
+ <description summary="constraint adjustments">
+ The constraint adjustment value define ways the compositor will adjust
+ the position of the surface, if the unadjusted position would result
+ in the surface being partly constrained.
+
+ Whether a surface is considered 'constrained' is left to the compositor
+ to determine. For example, the surface may be partly outside the
+ compositor's defined 'work area', thus necessitating the child surface's
+ position be adjusted until it is entirely inside the work area.
+
+ The adjustments can be combined, according to a defined precedence: 1)
+ Flip, 2) Slide, 3) Resize.
+ </description>
+ <entry name="none" value="0">
+ <description summary="don't move the child surface when constrained">
+ Don't alter the surface position even if it is constrained on some
+ axis, for example partially outside the edge of an output.
+ </description>
+ </entry>
+ <entry name="slide_x" value="1">
+ <description summary="move along the x axis until unconstrained">
+ Slide the surface along the x axis until it is no longer constrained.
+
+ First try to slide towards the direction of the gravity on the x axis
+ until either the edge in the opposite direction of the gravity is
+ unconstrained or the edge in the direction of the gravity is
+ constrained.
+
+ Then try to slide towards the opposite direction of the gravity on the
+ x axis until either the edge in the direction of the gravity is
+ unconstrained or the edge in the opposite direction of the gravity is
+ constrained.
+ </description>
+ </entry>
+ <entry name="slide_y" value="2">
+ <description summary="move along the y axis until unconstrained">
+ Slide the surface along the y axis until it is no longer constrained.
+
+ First try to slide towards the direction of the gravity on the y axis
+ until either the edge in the opposite direction of the gravity is
+ unconstrained or the edge in the direction of the gravity is
+ constrained.
+
+ Then try to slide towards the opposite direction of the gravity on the
+ y axis until either the edge in the direction of the gravity is
+ unconstrained or the edge in the opposite direction of the gravity is
+ constrained.
+ </description>
+ </entry>
+ <entry name="flip_x" value="4">
+ <description summary="invert the anchor and gravity on the x axis">
+ Invert the anchor and gravity on the x axis if the surface is
+ constrained on the x axis. For example, if the left edge of the
+ surface is constrained, the gravity is 'left' and the anchor is
+ 'left', change the gravity to 'right' and the anchor to 'right'.
+
+ If the adjusted position also ends up being constrained, the resulting
+ position of the flip_x adjustment will be the one before the
+ adjustment.
+ </description>
+ </entry>
+ <entry name="flip_y" value="8">
+ <description summary="invert the anchor and gravity on the y axis">
+ Invert the anchor and gravity on the y axis if the surface is
+ constrained on the y axis. For example, if the bottom edge of the
+ surface is constrained, the gravity is 'bottom' and the anchor is
+ 'bottom', change the gravity to 'top' and the anchor to 'top'.
+
+ The adjusted position is calculated given the original anchor
+ rectangle and offset, but with the new flipped anchor and gravity
+ values.
+
+ If the adjusted position also ends up being constrained, the resulting
+ position of the flip_y adjustment will be the one before the
+ adjustment.
+ </description>
+ </entry>
+ <entry name="resize_x" value="16">
+ <description summary="horizontally resize the surface">
+ Resize the surface horizontally so that it is completely
+ unconstrained.
+ </description>
+ </entry>
+ <entry name="resize_y" value="32">
+ <description summary="vertically resize the surface">
+ Resize the surface vertically so that it is completely unconstrained.
+ </description>
+ </entry>
+ </enum>
+
+ <request name="set_constraint_adjustment">
+ <description summary="set the adjustment to be done when constrained">
+ Specify how the window should be positioned if the originally intended
+ position caused the surface to be constrained, meaning at least
+ partially outside positioning boundaries set by the compositor. The
+ adjustment is set by constructing a bitmask describing the adjustment to
+ be made when the surface is constrained on that axis.
+
+ If no bit for one axis is set, the compositor will assume that the child
+ surface should not change its position on that axis when constrained.
+
+ If more than one bit for one axis is set, the order of how adjustments
+ are applied is specified in the corresponding adjustment descriptions.
+
+ The default adjustment is none.
+ </description>
+ <arg name="constraint_adjustment" type="uint"
+ summary="bit mask of constraint adjustments"/>
+ </request>
+
+ <request name="set_offset">
+ <description summary="set surface position offset">
+ Specify the surface position offset relative to the position of the
+ anchor on the anchor rectangle and the anchor on the surface. For
+ example if the anchor of the anchor rectangle is at (x, y), the surface
+ has the gravity bottom|right, and the offset is (ox, oy), the calculated
+ surface position will be (x + ox, y + oy). The offset position of the
+ surface is the one used for constraint testing. See
+ set_constraint_adjustment.
+
+ An example use case is placing a popup menu on top of a user interface
+ element, while aligning the user interface element of the parent surface
+ with some user interface element placed somewhere in the popup surface.
+ </description>
+ <arg name="x" type="int" summary="surface position x offset"/>
+ <arg name="y" type="int" summary="surface position y offset"/>
+ </request>
+ </interface>
+
+ <interface name="xdg_surface" version="2">
+ <description summary="desktop user interface surface base interface">
+ An interface that may be implemented by a wl_surface, for
+ implementations that provide a desktop-style user interface.
+
+ It provides a base set of functionality required to construct user
+ interface elements requiring management by the compositor, such as
+ toplevel windows, menus, etc. The types of functionality are split into
+ xdg_surface roles.
+
+ Creating an xdg_surface does not set the role for a wl_surface. In order
+ to map an xdg_surface, the client must create a role-specific object
+ using, e.g., get_toplevel, get_popup. The wl_surface for any given
+ xdg_surface can have at most one role, and may not be assigned any role
+ not based on xdg_surface.
+
+ A role must be assigned before any other requests are made to the
+ xdg_surface object.
+
+ The client must call wl_surface.commit on the corresponding wl_surface
+ for the xdg_surface state to take effect.
+
+ Creating an xdg_surface from a wl_surface which has a buffer attached or
+ committed is a client error, and any attempts by a client to attach or
+ manipulate a buffer prior to the first xdg_surface.configure call must
+ also be treated as errors.
+
+ Mapping an xdg_surface-based role surface is defined as making it
+ possible for the surface to be shown by the compositor. Note that
+ a mapped surface is not guaranteed to be visible once it is mapped.
+
+ For an xdg_surface to be mapped by the compositor, the following
+ conditions must be met:
+ (1) the client has assigned an xdg_surface-based role to the surface
+ (2) the client has set and committed the xdg_surface state and the
+ role-dependent state to the surface
+ (3) the client has committed a buffer to the surface
+
+ A newly-unmapped surface is considered to have met condition (1) out
+ of the 3 required conditions for mapping a surface if its role surface
+ has not been destroyed.
+ </description>
+
+ <enum name="error">
+ <entry name="not_constructed" value="1"/>
+ <entry name="already_constructed" value="2"/>
+ <entry name="unconfigured_buffer" value="3"/>
+ </enum>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the xdg_surface">
+ Destroy the xdg_surface object. An xdg_surface must only be destroyed
+ after its role object has been destroyed.
+ </description>
+ </request>
+
+ <request name="get_toplevel">
+ <description summary="assign the xdg_toplevel surface role">
+ This creates an xdg_toplevel object for the given xdg_surface and gives
+ the associated wl_surface the xdg_toplevel role.
+
+ See the documentation of xdg_toplevel for more details about what an
+ xdg_toplevel is and how it is used.
+ </description>
+ <arg name="id" type="new_id" interface="xdg_toplevel"/>
+ </request>
+
+ <request name="get_popup">
+ <description summary="assign the xdg_popup surface role">
+ This creates an xdg_popup object for the given xdg_surface and gives
+ the associated wl_surface the xdg_popup role.
+
+ If null is passed as a parent, a parent surface must be specified using
+ some other protocol, before committing the initial state.
+
+ See the documentation of xdg_popup for more details about what an
+ xdg_popup is and how it is used.
+ </description>
+ <arg name="id" type="new_id" interface="xdg_popup"/>
+ <arg name="parent" type="object" interface="xdg_surface" allow-null="true"/>
+ <arg name="positioner" type="object" interface="xdg_positioner"/>
+ </request>
+
+ <request name="set_window_geometry">
+ <description summary="set the new window geometry">
+ The window geometry of a surface 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 window geometry is double buffered, and will be applied at the
+ time wl_surface.commit of the corresponding wl_surface is called.
+
+ When maintaining a position, the compositor should treat the (x, y)
+ coordinate of the window geometry as the top left corner of the window.
+ A client changing the (x, y) window geometry coordinate should in
+ general not alter the position of the window.
+
+ Once the window geometry of the surface is set, 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 never set, the value is the full bounds of the surface,
+ including any subsurfaces. This updates dynamically on every
+ commit. This unset is meant for extremely simple clients.
+
+ The arguments are given in the surface-local coordinate space of
+ the wl_surface associated with this xdg_surface.
+
+ The width and height must be greater than zero. Setting an invalid size
+ will raise an error. When applied, the effective window geometry will be
+ the set window geometry clamped to the bounding rectangle of the
+ combined geometry of the surface of the xdg_surface and the associated
+ subsurfaces.
+ </description>
+ <arg name="x" type="int"/>
+ <arg name="y" type="int"/>
+ <arg name="width" type="int"/>
+ <arg name="height" type="int"/>
+ </request>
+
+ <request name="ack_configure">
+ <description summary="ack a configure event">
+ When a configure event is received, if a client commits the
+ surface in response to the configure event, then the client
+ must make an ack_configure request sometime before the commit
+ request, passing along the serial of the configure event.
+
+ For instance, for toplevel surfaces the compositor might use this
+ information to move a surface to the top left only when the client has
+ drawn itself for the maximized or fullscreen state.
+
+ If the client receives multiple configure events before it
+ can respond to one, it only has to ack the last configure event.
+
+ A client is not required to commit immediately after sending
+ an ack_configure request - it may even ack_configure several times
+ before its next surface commit.
+
+ A client may send multiple ack_configure requests before committing, but
+ only the last request sent before a commit indicates which configure
+ event the client really is responding to.
+ </description>
+ <arg name="serial" type="uint" summary="the serial from the configure event"/>
+ </request>
+
+ <event name="configure">
+ <description summary="suggest a surface change">
+ The configure event marks the end of a configure sequence. A configure
+ sequence is a set of one or more events configuring the state of the
+ xdg_surface, including the final xdg_surface.configure event.
+
+ Where applicable, xdg_surface surface roles will during a configure
+ sequence extend this event as a latched state sent as events before the
+ xdg_surface.configure event. Such events should be considered to make up
+ a set of atomically applied configuration states, where the
+ xdg_surface.configure commits the accumulated state.
+
+ Clients should arrange their surface for the new states, and then send
+ an ack_configure request with the serial sent in this configure event at
+ some point before committing the 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="serial" type="uint" summary="serial of the configure event"/>
+ </event>
+ </interface>
+
+ <interface name="xdg_toplevel" version="2">
+ <description summary="toplevel surface">
+ This interface defines an xdg_surface role which allows a surface to,
+ among other things, set window-like properties such as maximize,
+ fullscreen, and minimize, set application-specific metadata like title and
+ id, and well as trigger user interactive operations such as interactive
+ resize and move.
+
+ Unmapping an xdg_toplevel means that the surface cannot be shown
+ by the compositor until it is explicitly mapped again.
+ All active operations (e.g., move, resize) are canceled and all
+ attributes (e.g. title, state, stacking, ...) are discarded for
+ an xdg_toplevel surface when it is unmapped.
+
+ Attaching a null buffer to a toplevel unmaps the surface.
+ </description>
+
+ <request name="destroy" type="destructor">
+ <description summary="destroy the xdg_toplevel">
+ This request destroys the role surface and unmaps the surface;
+ see "Unmapping" behavior in interface section for details.
+ </description>
+ </request>
+
+ <request name="set_parent">
+ <description summary="set the parent of this surface">
+ Set the "parent" of this surface. This surface should be stacked
+ above the parent surface and all other ancestor surfaces.
+
+ Parent windows should be set on dialogs, toolboxes, or other
+ "auxiliary" surfaces, so that the parent is raised when the dialog
+ is raised.
+
+ Setting a null parent for a child window removes any parent-child
+ relationship for the child. Setting a null parent for a window which
+ currently has no parent is a no-op.
+
+ If the parent is unmapped then its children are managed as
+ though the parent of the now-unmapped parent has become the
+ parent of this surface. If no parent exists for the now-unmapped
+ parent then the children are managed as though they have no
+ parent surface.
+ </description>
+ <arg name="parent" type="object" interface="xdg_toplevel" 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 application ID">
+ Set an application identifier for the surface.
+
+ The app ID identifies the general class of applications to which
+ the surface belongs. The compositor can use this to group multiple
+ surfaces together, or to determine how to launch a new application.
+
+ For D-Bus activatable applications, the app ID is used as the D-Bus
+ service name.
+
+ The compositor shell will try to group application surfaces together
+ by their app ID. As a best practice, it is suggested to select app
+ ID's that match the basename of the application's .desktop file.
+ For example, "org.freedesktop.FooViewer" where the .desktop file is
+ "org.freedesktop.FooViewer.desktop".
+
+ See the desktop-entry specification [0] for more details on
+ application identifiers and how they relate to well-known D-Bus
+ names and .desktop files.
+
+ [0] http://standards.freedesktop.org/desktop-entry-spec/
+ </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 local surface coordinates of
+ the parent surface. There are no guarantees as to what menu items
+ the window menu contains.
+
+ This request must be used in response to some sort of user action
+ like a button press, key press, or touch down event.
+ </description>
+ <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat of the user event"/>
+ <arg name="serial" type="uint" summary="the serial of the user event"/>
+ <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 an interactive, user-driven move of the surface.
+
+ This request must be used in response to some sort of user action
+ like a button press, key press, or touch down event. The passed
+ serial is used to determine the type of interactive move (touch,
+ pointer, etc).
+
+ The server may ignore move requests depending on the state of
+ the surface (e.g. fullscreen or maximized), or if the passed serial
+ is no longer valid.
+
+ If triggered, the surface will lose the focus of the device
+ (wl_pointer, wl_touch, etc) used for the move. It is up to the
+ compositor to visually indicate that the move is taking place, such as
+ updating a pointer cursor, during the move. There is no guarantee
+ that the device focus will return when the move is completed.
+ </description>
+ <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat of the user event"/>
+ <arg name="serial" type="uint" summary="the serial of the user event"/>
+ </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.
+ </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 user-driven, interactive resize of the surface.
+
+ This request must be used in response to some sort of user action
+ like a button press, key press, or touch down event. The passed
+ serial is used to determine the type of interactive resize (touch,
+ pointer, etc).
+
+ The server may ignore resize requests depending on the state of
+ the surface (e.g. fullscreen or maximized).
+
+ If triggered, the client will receive configure events with the
+ "resize" state enum value and the expected sizes. See the "resize"
+ enum value for more details about what is required. The client
+ must also acknowledge configure events using "ack_configure". After
+ the resize is completed, the client will receive another "configure"
+ event without the resize state.
+
+ If triggered, the surface also will lose the focus of the device
+ (wl_pointer, wl_touch, etc) used for the resize. It is up to the
+ compositor to visually indicate that the resize is taking place,
+ such as updating a pointer cursor, during the resize. There is no
+ guarantee that the device focus will return when the resize is
+ completed.
+
+ The edges parameter specifies how the surface should be resized,
+ and is one of the values of the resize_edge enum. The compositor
+ may use this information to update the surface position for
+ example when dragging the top left corner. The compositor may also
+ use this information to adapt its behavior, e.g. choose an
+ appropriate cursor image.
+ </description>
+ <arg name="seat" type="object" interface="wl_seat" summary="the wl_seat of the user event"/>
+ <arg name="serial" type="uint" summary="the serial of the user event"/>
+ <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.
+ </description>
+ <entry name="maximized" value="1" summary="the surface is maximized">
+ <description summary="the surface is maximized">
+ The surface is maximized. The window geometry specified in the configure
+ event must be obeyed by the client.
+
+ The client should draw without shadow or other
+ decoration outside of the window geometry.
+ </description>
+ </entry>
+ <entry name="fullscreen" value="2" summary="the surface is fullscreen">
+ <description summary="the surface is fullscreen">
+ The surface is fullscreen. The window geometry specified in the
+ configure event is a maximum; the client cannot resize beyond it. For
+ a surface to cover the whole fullscreened area, the geometry
+ dimensions must be obeyed by the client. For more details, see
+ xdg_toplevel.set_fullscreen.
+ </description>
+ </entry>
+ <entry name="resizing" value="3" summary="the surface is being resized">
+ <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" summary="the surface is now activated">
+ <description summary="the surface is now activated">
+ 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>
+ <entry name="tiled_left" value="5" since="2">
+ <description summary="the surface is tiled">
+ The window is currently in a tiled layout and the left edge is
+ considered to be adjacent to another part of the tiling grid.
+ </description>
+ </entry>
+ <entry name="tiled_right" value="6" since="2">
+ <description summary="the surface is tiled">
+ The window is currently in a tiled layout and the right edge is
+ considered to be adjacent to another part of the tiling grid.
+ </description>
+ </entry>
+ <entry name="tiled_top" value="7" since="2">
+ <description summary="the surface is tiled">
+ The window is currently in a tiled layout and the top edge is
+ considered to be adjacent to another part of the tiling grid.
+ </description>
+ </entry>
+ <entry name="tiled_bottom" value="8" since="2">
+ <description summary="the surface is tiled">
+ The window is currently in a tiled layout and the bottom edge is
+ considered to be adjacent to another part of the tiling grid.
+ </description>
+ </entry>
+ </enum>
+
+ <request name="set_max_size">
+ <description summary="set the maximum size">
+ Set a maximum size for the window.
+
+ The client can specify a maximum size so that the compositor does
+ not try to configure the window beyond this size.
+
+ The width and height arguments are in window geometry coordinates.
+ See xdg_surface.set_window_geometry.
+
+ Values set in this way are double-buffered. They will get applied
+ on the next commit.
+
+ The compositor can use this information to allow or disallow
+ different states like maximize or fullscreen and draw accurate
+ animations.
+
+ Similarly, a tiling window manager may use this information to
+ place and resize client windows in a more effective way.
+
+ The client should not rely on the compositor to obey the maximum
+ size. The compositor may decide to ignore the values set by the
+ client and request a larger size.
+
+ If never set, or a value of zero in the request, means that the
+ client has no expected maximum size in the given dimension.
+ As a result, a client wishing to reset the maximum size
+ to an unspecified state can use zero for width and height in the
+ request.
+
+ Requesting a maximum size to be smaller than the minimum size of
+ a surface is illegal and will result in a protocol error.
+
+ The width and height must be greater than or equal to zero. Using
+ strictly negative values for width and height will result in a
+ protocol error.
+ </description>
+ <arg name="width" type="int"/>
+ <arg name="height" type="int"/>
+ </request>
+
+ <request name="set_min_size">
+ <description summary="set the minimum size">
+ Set a minimum size for the window.
+
+ The client can specify a minimum size so that the compositor does
+ not try to configure the window below this size.
+
+ The width and height arguments are in window geometry coordinates.
+ See xdg_surface.set_window_geometry.
+
+ Values set in this way are double-buffered. They will get applied
+ on the next commit.
+
+ The compositor can use this information to allow or disallow
+ different states like maximize or fullscreen and draw accurate
+ animations.
+
+ Similarly, a tiling window manager may use this information to
+ place and resize client windows in a more effective way.
+
+ The client should not rely on the compositor to obey the minimum
+ size. The compositor may decide to ignore the values set by the
+ client and request a smaller size.
+
+ If never set, or a value of zero in the request, means that the
+ client has no expected minimum size in the given dimension.
+ As a result, a client wishing to reset the minimum size
+ to an unspecified state can use zero for width and height in the
+ request.
+
+ Requesting a minimum size to be larger than the maximum size of
+ a surface is illegal and will result in a protocol error.
+
+ The width and height must be greater than or equal to zero. Using
+ strictly negative values for width and height will result in a
+ protocol error.
+ </description>
+ <arg name="width" type="int"/>
+ <arg name="height" type="int"/>
+ </request>
+
+ <request name="set_maximized">
+ <description summary="maximize the window">
+ Maximize the surface.
+
+ After requesting that the surface should be maximized, the compositor
+ will respond by emitting a configure event. Whether this configure
+ actually sets the window maximized is subject to compositor policies.
+ The client must then update its content, drawing in the configured
+ state. The client must also acknowledge the configure when committing
+ the new content (see ack_configure).
+
+ It is up to the compositor to decide how and where to maximize the
+ surface, for example which output and what region of the screen should
+ be used.
+
+ If the surface was already maximized, the compositor will still emit
+ a configure event with the "maximized" state.
+
+ If the surface is in a fullscreen state, this request has no direct
+ effect. It may alter the state the surface is returned to when
+ unmaximized unless overridden by the compositor.
+ </description>
+ </request>
+
+ <request name="unset_maximized">
+ <description summary="unmaximize the window">
+ Unmaximize the surface.
+
+ After requesting that the surface should be unmaximized, the compositor
+ will respond by emitting a configure event. Whether this actually
+ un-maximizes the window is subject to compositor policies.
+ If available and applicable, the compositor will include the window
+ geometry dimensions the window had prior to being maximized in the
+ configure event. The client must then update its content, drawing it in
+ the configured state. The client must also acknowledge the configure
+ when committing the new content (see ack_configure).
+
+ It is up to the compositor to position the surface after it was
+ unmaximized; usually the position the surface had before maximizing, if
+ applicable.
+
+ If the surface was already not maximized, the compositor will still
+ emit a configure event without the "maximized" state.
+
+ If the surface is in a fullscreen state, this request has no direct
+ effect. It may alter the state the surface is returned to when
+ unmaximized unless overridden by the compositor.
+ </description>
+ </request>
+
+ <request name="set_fullscreen">
+ <description summary="set the window as fullscreen on an output">
+ Make the surface fullscreen.
+
+ After requesting that the surface should be fullscreened, the
+ compositor will respond by emitting a configure event. Whether the
+ client is actually put into a fullscreen state is subject to compositor
+ policies. The client must also acknowledge the configure when
+ committing the new content (see ack_configure).
+
+ The output passed by the request indicates the client's preference as
+ to which display it should be set fullscreen on. If this value is NULL,
+ it's up to the compositor to choose which display will be used to map
+ this surface.
+
+ If the surface doesn't cover the whole output, the compositor will
+ position the surface in the center of the output and compensate with
+ with border fill covering the rest of the output. The content of the
+ border fill is undefined, but should be assumed to be in some way that
+ attempts to blend into the surrounding area (e.g. solid black).
+
+ If the fullscreened surface is not opaque, the compositor must make
+ sure that other screen content not part of the same surface tree (made
+ up of subsurfaces, popups or similarly coupled surfaces) are not
+ visible below the fullscreened surface.
+ </description>
+ <arg name="output" type="object" interface="wl_output" allow-null="true"/>
+ </request>
+
+ <request name="unset_fullscreen">
+ <description summary="unset the window as fullscreen">
+ Make the surface no longer fullscreen.
+
+ After requesting that the surface should be unfullscreened, the
+ compositor will respond by emitting a configure event.
+ Whether this actually removes the fullscreen state of the client is
+ subject to compositor policies.
+
+ Making a surface unfullscreen sets states for the surface based on the following:
+ * the state(s) it may have had before becoming fullscreen
+ * any state(s) decided by the compositor
+ * any state(s) requested by the client while the surface was fullscreen
+
+ The compositor may include the previous window geometry dimensions in
+ the configure event, if applicable.
+
+ The client must also acknowledge the configure when committing the new
+ content (see ack_configure).
+ </description>
+ </request>
+
+ <request name="set_minimized">
+ <description summary="set the window as minimized">
+ Request that the compositor minimize your surface. There is no
+ way to know if the surface is currently minimized, nor is there
+ any way to unset minimization on this surface.
+
+ If you are looking to throttle redrawing when minimized, please
+ instead use the wl_surface.frame event for this, as this will
+ also work with live previews on windows in Alt-Tab, Expose or
+ similar compositor features.
+ </description>
+ </request>
+
+ <event name="configure">
+ <description summary="suggest a surface change">
+ This configure event asks the client to resize its toplevel surface or
+ to change its state. The configured state should not be applied
+ immediately. See xdg_surface.configure for details.
+
+ The width and height arguments specify a hint to the window
+ about how its surface should be resized in window geometry
+ coordinates. See set_window_geometry.
+
+ If the width or height arguments are zero, it means the client
+ should decide its own window dimension. This may happen when the
+ compositor needs to configure the state of the surface but doesn't
+ have any information about any previous or expected dimension.
+
+ The states listed in the event specify how the width/height
+ arguments should be interpreted, and possibly how it should be
+ drawn.
+
+ Clients must send an ack_configure in response to this event. See
+ xdg_surface.configure and xdg_surface.ack_configure for details.
+ </description>
+ <arg name="width" type="int"/>
+ <arg name="height" type="int"/>
+ <arg name="states" type="array"/>
+ </event>
+
+ <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 the
+ window. The client may choose to ignore this request, or show
+ a dialog to ask the user to save their data, etc.
+ </description>
+ </event>
+ </interface>
+
+ <interface name="xdg_popup" version="2">
+ <description summary="short-lived, popup surfaces for menus">
+ A popup surface is a short-lived, temporary surface. It can be used to
+ implement for example menus, popovers, tooltips and other similar user
+ interface concepts.
+
+ A popup can be made to take an explicit grab. See xdg_popup.grab for
+ details.
+
+ When the popup is dismissed, a popup_done event will be sent out, and at
+ the same time the surface will be unmapped. See the xdg_popup.popup_done
+ event for details.
+
+ Explicitly destroying the xdg_popup object will also dismiss the popup and
+ unmap the surface. Clients that want to dismiss the popup when another
+ surface of their own is clicked should dismiss the popup using the destroy
+ request.
+
+ A newly created xdg_popup will be stacked on top of all previously created
+ xdg_popup surfaces associated with the same xdg_toplevel.
+
+ The parent of an xdg_popup must be mapped (see the xdg_surface
+ description) before the xdg_popup itself.
+
+ The x and y arguments passed when creating the popup object specify
+ where the top left of the popup should be placed, relative to the
+ local surface coordinates of the parent surface. See
+ xdg_surface.get_popup. An xdg_popup must intersect with or be at least
+ partially adjacent to its parent surface.
+
+ The client must call wl_surface.commit on the corresponding wl_surface
+ for the xdg_popup state to take effect.
+ </description>
+
+ <enum name="error">
+ <entry name="invalid_grab" value="0"
+ summary="tried to grab after being mapped"/>
+ </enum>
+
+ <request name="destroy" type="destructor">
+ <description summary="remove xdg_popup interface">
+ This destroys the popup. Explicitly destroying the xdg_popup
+ object will also dismiss the popup, and unmap the surface.
+
+ If this xdg_popup is not the "topmost" popup, a protocol error
+ will be sent.
+ </description>
+ </request>
+
+ <request name="grab">
+ <description summary="make the popup take an explicit grab">
+ This request makes the created popup take an explicit grab. An explicit
+ grab will be dismissed when the user dismisses the popup, or when the
+ client destroys the xdg_popup. This can be done by the user clicking
+ outside the surface, using the keyboard, or even locking the screen
+ through closing the lid or a timeout.
+
+ If the compositor denies the grab, the popup will be immediately
+ dismissed.
+
+ This request must be used in response to some sort of user action like a
+ button press, key press, or touch down event. The serial number of the
+ event should be passed as 'serial'.
+
+ The parent of a grabbing popup must either be an xdg_toplevel surface or
+ another xdg_popup with an explicit grab. If the parent is another
+ xdg_popup it means that the popups are nested, with this popup now being
+ the topmost popup.
+
+ Nested popups must be destroyed in the reverse order they were created
+ in, e.g. the only popup you are allowed to destroy at all times is the
+ topmost one.
+
+ When compositors choose to dismiss a popup, they may dismiss every
+ nested grabbing popup as well. When a compositor dismisses popups, it
+ will follow the same dismissing order as required from the client.
+
+ The parent of a grabbing popup must either be another xdg_popup with an
+ active explicit grab, or an xdg_popup or xdg_toplevel, if there are no
+ explicit grabs already taken.
+
+ If the topmost grabbing popup is destroyed, the grab will be returned to
+ the parent of the popup, if that parent previously had an explicit grab.
+
+ If the parent is a grabbing popup which has already been dismissed, this
+ popup will be immediately dismissed. If the parent is a popup that did
+ not take an explicit grab, an error will be raised.
+
+ During a popup grab, the client owning the grab will receive pointer
+ and touch events for all their surfaces as normal (similar to an
+ "owner-events" grab in X11 parlance), while the top most grabbing popup
+ will always have keyboard focus.
+ </description>
+ <arg name="seat" type="object" interface="wl_seat"
+ summary="the wl_seat of the user event"/>
+ <arg name="serial" type="uint" summary="the serial of the user event"/>
+ </request>
+
+ <event name="configure">
+ <description summary="configure the popup surface">
+ This event asks the popup surface to configure itself given the
+ configuration. The configured state should not be applied immediately.
+ See xdg_surface.configure for details.
+
+ The x and y arguments represent the position the popup was placed at
+ given the xdg_positioner rule, relative to the upper left corner of the
+ window geometry of the parent surface.
+ </description>
+ <arg name="x" type="int"
+ summary="x position relative to parent surface window geometry"/>
+ <arg name="y" type="int"
+ summary="y position relative to parent surface window geometry"/>
+ <arg name="width" type="int" summary="window geometry width"/>
+ <arg name="height" type="int" summary="window geometry height"/>
+ </event>
+
+ <event name="popup_done">
+ <description summary="popup interaction is done">
+ The popup_done event is sent out when a popup is dismissed by the
+ compositor. The client should destroy the xdg_popup object at this
+ point.
+ </description>
+ </event>
+
+ </interface>
+</protocol>
diff --git a/uwac/templates/CMakeLists.txt b/uwac/templates/CMakeLists.txt
new file mode 100644
index 0000000..14dfc68
--- /dev/null
+++ b/uwac/templates/CMakeLists.txt
@@ -0,0 +1,47 @@
+set(UWAC_INCLUDE_DIR "include/uwac${UWAC_VERSION_MAJOR}")
+
+if (NOT UWAC_FORCE_STATIC_BUILD)
+ # cmake package
+ export(PACKAGE uwac)
+
+ SetFreeRDPCMakeInstallDir(UWAC_CMAKE_INSTALL_DIR "uwac${UWAC_VERSION_MAJOR}")
+
+ configure_package_config_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/uwacConfig.cmake.in
+ ${CMAKE_CURRENT_BINARY_DIR}/uwacConfig.cmake
+ INSTALL_DESTINATION ${UWAC_CMAKE_INSTALL_DIR}
+ PATH_VARS UWAC_INCLUDE_DIR)
+
+ write_basic_package_version_file(
+ ${CMAKE_CURRENT_BINARY_DIR}/uwacConfigVersion.cmake
+ VERSION ${UWAC_VERSION}
+ COMPATIBILITY SameMajorVersion)
+
+ install(FILES
+ ${CMAKE_CURRENT_BINARY_DIR}/uwacConfig.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/uwacConfigVersion.cmake
+ DESTINATION ${UWAC_CMAKE_INSTALL_DIR})
+
+ install(EXPORT uwac DESTINATION ${UWAC_CMAKE_INSTALL_DIR})
+endif()
+
+set(UWAC_BUILD_CONFIG_LIST "")
+GET_CMAKE_PROPERTY(res VARIABLES)
+FOREACH(var ${res})
+ IF (var MATCHES "^WITH_*|^BUILD_TESTING|^UWAC_HAVE_*")
+ LIST(APPEND UWAC_BUILD_CONFIG_LIST "${var}=${${var}}")
+ ENDIF()
+ENDFOREACH()
+string(REPLACE ";" " " UWAC_BUILD_CONFIG "${UWAC_BUILD_CONFIG_LIST}")
+configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/uwac/version.h)
+configure_file(buildflags.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/uwac/buildflags.h)
+configure_file(build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/uwac/build-config.h)
+configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/../include/uwac/config.h)
+
+if (NOT UWAC_FORCE_STATIC_BUILD)
+ include(pkg-config-install-prefix)
+ configure_file(uwac.pc.in ${CMAKE_CURRENT_BINARY_DIR}/uwac${UWAC_VERSION_MAJOR}.pc @ONLY)
+
+ set(UWAC_INSTALL_INCLUDE_DIR ${UWAC_INCLUDE_DIR}/uwac)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/uwac${UWAC_VERSION_MAJOR}.pc DESTINATION ${PKG_CONFIG_PC_INSTALL_DIR})
+endif()
diff --git a/uwac/templates/build-config.h.in b/uwac/templates/build-config.h.in
new file mode 100644
index 0000000..a2c103e
--- /dev/null
+++ b/uwac/templates/build-config.h.in
@@ -0,0 +1,22 @@
+#ifndef UWAC_BUILD_CONFIG_H
+#define UWAC_BUILD_CONFIG_H
+
+#define UWAC_DATA_PATH "${WINPR_DATA_PATH}"
+#define UWAC_KEYMAP_PATH "${WINPR_KEYMAP_PATH}"
+#define UWAC_PLUGIN_PATH "${WINPR_PLUGIN_PATH}"
+
+#define UWAC_INSTALL_PREFIX "${WINPR_INSTALL_PREFIX}"
+
+#define UWAC_LIBRARY_PATH "${WINPR_LIBRARY_PATH}"
+
+#define UWAC_ADDIN_PATH "${WINPR_ADDIN_PATH}"
+
+#define UWAC_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}"
+#define UWAC_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}"
+
+#define UWAC_VENDOR_STRING "${VENDOR}"
+#define UWAC_PRODUCT_STRING "${PRODUCT}"
+
+#define UWAC_PROXY_PLUGINDIR "${WINPR_PROXY_PLUGINDIR}"
+
+#endif /* UWAC_BUILD_CONFIG_H */
diff --git a/uwac/templates/buildflags.h.in b/uwac/templates/buildflags.h.in
new file mode 100644
index 0000000..d16dfb9
--- /dev/null
+++ b/uwac/templates/buildflags.h.in
@@ -0,0 +1,11 @@
+#ifndef UWAC_BUILD_FLAGS_H
+#define UWAC_BUILD_FLAGS_H
+
+#define UWAC_CFLAGS "${CMAKE_C_FLAGS}"
+#define UWAC_COMPILER_ID "${CMAKE_C_COMPILER_ID}"
+#define UWAC_COMPILER_VERSION "${CMAKE_C_COMPILER_VERSION}"
+#define UWAC_TARGET_ARCH "${TARGET_ARCH}"
+#define UWAC_BUILD_CONFIG "${UWAC_BUILD_CONFIG}"
+#define UWAC_BUILD_TYPE "${CMAKE_BUILD_TYPE}"
+
+#endif /* UWAC_BUILD_FLAGS_H */
diff --git a/uwac/templates/config.h.in b/uwac/templates/config.h.in
new file mode 100644
index 0000000..90caf39
--- /dev/null
+++ b/uwac/templates/config.h.in
@@ -0,0 +1,11 @@
+#ifndef UWAC_CONFIG_H
+#define UWAC_CONFIG_H
+
+/* Include files */
+#cmakedefine UWAC_HAVE_TM_GMTOFF
+#cmakedefine UWAC_HAVE_POLL_H
+#cmakedefine UWAC_HAVE_SYSLOG_H
+#cmakedefine UWAC_HAVE_JOURNALD_H
+#cmakedefine UWAC_HAVE_PIXMAN_REGION
+
+#endif /* UWAC_CONFIG_H */
diff --git a/uwac/templates/uwac.pc.in b/uwac/templates/uwac.pc.in
new file mode 100644
index 0000000..c0abdee
--- /dev/null
+++ b/uwac/templates/uwac.pc.in
@@ -0,0 +1,15 @@
+prefix=@PKG_CONFIG_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@UWAC_INCLUDE_DIR@
+libs=-luwac@UWAC_VERSION_MAJOR@
+
+Name: uwac@UWAC_API_VERSION@
+Description: uwac: using wayland as a client
+URL: http://www.freerdp.com/
+Version: @UWAC_VERSION@
+Requires:
+Requires.private: wayland-client xkbcommon freerdp@FREERDP_VERSION_MAJOR@
+Libs: -L${libdir} ${libs}
+Libs.private:
+Cflags: -I${includedir}
diff --git a/uwac/templates/uwacConfig.cmake.in b/uwac/templates/uwacConfig.cmake.in
new file mode 100644
index 0000000..2433842
--- /dev/null
+++ b/uwac/templates/uwacConfig.cmake.in
@@ -0,0 +1,9 @@
+@PACKAGE_INIT@
+
+set(UWAC_VERSION_MAJOR "@UWAC_VERSION_MAJOR@")
+set(UWAC_VERSION_MINOR "@UWAC_VERSION_MINOR@")
+set(UWAC_VERSION_REVISION "@UWAC_VERSION_REVISION@")
+
+set_and_check(UWAC_INCLUDE_DIR "@PACKAGE_UWAC_INCLUDE_DIR@")
+
+include("${CMAKE_CURRENT_LIST_DIR}/uwac.cmake")
diff --git a/uwac/templates/version.h.in b/uwac/templates/version.h.in
new file mode 100644
index 0000000..1b941b6
--- /dev/null
+++ b/uwac/templates/version.h.in
@@ -0,0 +1,32 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Version includes
+ *
+ * Copyright 2021 Thincast Technologies GmbH
+ * Copyright 2021 Armin Novak <armin.novak@thincast.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef UWAC_VERSION_H
+#define UWAC_VERSION_H
+
+#define UWAC_VERSION_MAJOR ${UWAC_VERSION_MAJOR}
+#define UWAC_VERSION_MINOR ${UWAC_VERSION_MINOR}
+#define UWAC_VERSION_REVISION ${UWAC_VERSION_REVISION}
+#define UWAC_VERSION_SUFFIX "${UWAC_VERSION_SUFFIX}"
+#define UWAC_API_VERSION "${UWAC_API_VERSION}"
+#define UWAC_VERSION "${UWAC_VERSION}"
+#define UWAC_VERSION_FULL "${UWAC_VERSION_FULL}"
+#define UWAC_GIT_REVISION "${GIT_REVISION}"
+
+#endif /* UWAC_VERSION_H */