10 Commits

Author SHA1 Message Date
64e1555d56 Fixed DNS, TCP and UDP on Windows.
All checks were successful
Build & Release / Linux-AMD64-Build (push) Successful in 1m5s
Build & Release / Windows-AMD64-Build (push) Successful in 3m43s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m31s
2024-07-10 02:36:21 -07:00
a65c8d64b5 Fixed constructor to use move constructors.
Some checks failed
Build & Release / Linux-AMD64-Build (push) Successful in 1m44s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m46s
Build & Release / Windows-AMD64-Build (push) Failing after 7h1m29s
2024-07-09 19:23:24 -07:00
fa2b801690 Fixed Spotify.Play and fixed TCP.Connect. 2024-07-09 17:39:01 -07:00
4e887b1ac2 Added new DNS::Resolve static method and organized it per OS. 2024-07-09 16:41:43 -07:00
126fc92fae Fixed Wayland window resizing and closing. 2024-07-08 21:17:09 -07:00
2ef28273b0 Fixed Wayland window decoration. 2024-07-05 13:15:34 -07:00
04bf7d43ff Added second wl_display_roundtrip before wl_surface_commit. 2024-07-04 12:12:19 -07:00
fb86dca332 Added features to readme. 2024-07-03 19:49:18 -07:00
7e380efd7d Added features to readme. 2024-07-01 22:15:49 -07:00
b5e05864b6 Removed const arguments from GC header. 2024-07-01 20:23:17 -07:00
31 changed files with 1276 additions and 167 deletions

View File

@@ -122,7 +122,7 @@ set(EHS_SOURCES
src/io/socket/Request.cpp include/ehs/io/socket/Request.h src/io/socket/Request.cpp include/ehs/io/socket/Request.h
src/io/socket/Response.cpp include/ehs/io/socket/Response.h src/io/socket/Response.cpp include/ehs/io/socket/Response.h
src/io/socket/DNS.cpp include/ehs/io/socket/DNS.h src/io/socket/BaseDNS.cpp include/ehs/io/socket/BaseDNS.h
src/io/socket/BaseUDP.cpp include/ehs/io/socket/BaseUDP.h src/io/socket/BaseUDP.cpp include/ehs/io/socket/BaseUDP.h
src/io/socket/BaseTCP.cpp include/ehs/io/socket/BaseTCP.h src/io/socket/BaseTCP.cpp include/ehs/io/socket/BaseTCP.h
src/io/socket/SSL.cpp include/ehs/io/socket/SSL.h src/io/socket/SSL.cpp include/ehs/io/socket/SSL.h
@@ -133,6 +133,7 @@ set(EHS_SOURCES
include/ehs/io/socket/Socket.h include/ehs/io/socket/Socket.h
include/ehs/io/socket/TCP.h include/ehs/io/socket/TCP.h
include/ehs/io/socket/UDP.h include/ehs/io/socket/UDP.h
include/ehs/io/socket/DNS.h
src/io/audio/Audio.cpp include/ehs/io/audio/Audio.h src/io/audio/Audio.cpp include/ehs/io/audio/Audio.h
src/io/audio/BaseAudioDevice.cpp include/ehs/io/audio/BaseAudioDevice.h src/io/audio/BaseAudioDevice.cpp include/ehs/io/audio/BaseAudioDevice.h
@@ -182,6 +183,7 @@ if (IS_OS_WINDOWS)
list(APPEND EHS_SOURCES list(APPEND EHS_SOURCES
src/io/socket/UDP_W32.cpp include/ehs/io/socket/UDP_W32.h src/io/socket/UDP_W32.cpp include/ehs/io/socket/UDP_W32.h
src/io/socket/TCP_W32.cpp include/ehs/io/socket/TCP_W32.h src/io/socket/TCP_W32.cpp include/ehs/io/socket/TCP_W32.h
src/io/socket/DNS_W32.cpp include/ehs/io/socket/DNS_W32.h
src/system/Semaphore_W32.cpp include/ehs/system/Semaphore_W32.h src/system/Semaphore_W32.cpp include/ehs/system/Semaphore_W32.h
src/system/System_W32.cpp include/ehs/system/System_W32.h src/system/System_W32.cpp include/ehs/system/System_W32.h
src/system/Mutex_W32.cpp include/ehs/system/Mutex_W32.h src/system/Mutex_W32.cpp include/ehs/system/Mutex_W32.h
@@ -198,6 +200,7 @@ elseif (IS_OS_LINUX)
list(APPEND EHS_SOURCES list(APPEND EHS_SOURCES
src/io/socket/UDP_BSD.cpp include/ehs/io/socket/UDP_BSD.h src/io/socket/UDP_BSD.cpp include/ehs/io/socket/UDP_BSD.h
src/io/socket/TCP_BSD.cpp include/ehs/io/socket/TCP_BSD.h src/io/socket/TCP_BSD.cpp include/ehs/io/socket/TCP_BSD.h
src/io/socket/DNS_LNX.cpp include/ehs/io/socket/DNS_LNX.h
src/system/Semaphore_P.cpp include/ehs/system/Semaphore_P.h src/system/Semaphore_P.cpp include/ehs/system/Semaphore_P.h
src/system/System_LNX.cpp include/ehs/system/System_LNX.h src/system/System_LNX.cpp include/ehs/system/System_LNX.h
src/system/Open_UNX.cpp include/ehs/system/Open_UNX.h src/system/Open_UNX.cpp include/ehs/system/Open_UNX.h
@@ -215,7 +218,10 @@ elseif (IS_OS_LINUX)
if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland") if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland")
add_compile_definitions(EHS_WS_WAYLAND) add_compile_definitions(EHS_WS_WAYLAND)
list(APPEND EHS_SOURCES src/io/xdg-shell-protocol.c include/ehs/io/xdg-shell-client-protocol.h src/io/Window_Way.cpp include/ehs/io/Window_Way.h) list(APPEND EHS_SOURCES
src/io/xdg-shell-protocol.c include/ehs/io/xdg-shell-client-protocol.h
src/io/xdg-decoration.c include/ehs/io/xdg-decoration.h
src/io/Window_Way.cpp include/ehs/io/Window_Way.h)
message("Building for Wayland.") message("Building for Wayland.")
elseif (LINUX_WINDOW_SYSTEM STREQUAL "XCB") elseif (LINUX_WINDOW_SYSTEM STREQUAL "XCB")
add_compile_definitions(EHS_WS_XCB) add_compile_definitions(EHS_WS_XCB)

View File

@@ -8,6 +8,7 @@ This project does not fully follow the C++ standard.
### Features ### Features
- Audio IO/Processing/Manipulation - Audio IO/Processing/Manipulation
- Image Processing/Manipulation - Image Processing/Manipulation
- Databases
- 3D Model & Mesh Processing/Manipulation - 3D Model & Mesh Processing/Manipulation
- File IO - File IO
- Basic File Monitoring - Basic File Monitoring
@@ -20,7 +21,7 @@ This project does not fully follow the C++ standard.
- Mutexes - Mutexes
- Semaphores - Semaphores
- CPU information and features at runtime - CPU information and features at runtime
- HTTP(S) Sockets - HTTP(S) Socket Layer
- TCP Socket - TCP Socket
- UDP Socket - UDP Socket
- COM (Serial) IO - COM (Serial) IO
@@ -29,12 +30,13 @@ This project does not fully follow the C++ standard.
- Twitch Integration - Twitch Integration
- Json Parsing/Writing - Json Parsing/Writing
- User Friendly HID Input - User Friendly HID Input
- Basic Garbage Collector - Heap Garbage Collector
- Linked List - Linked List
- Array - Array
- Vector - Vector
- Asynchronous Task System - Asynchronous Task System
- URI Parsing - URI Parsing
- USB (WIP)
### Supported Architectures ### Supported Architectures
- AMD64 - AMD64

View File

@@ -36,7 +36,7 @@ namespace ehs
/// Sets the maximum amount of garbage to delete per poll. /// Sets the maximum amount of garbage to delete per poll.
/// @param[in] newMax The new maximum. /// @param[in] newMax The new maximum.
static void SetMax(const UInt_64 newMax); static void SetMax(UInt_64 newMax);
/// Gets the maximum amount of garbage to delete per poll. /// Gets the maximum amount of garbage to delete per poll.
/// @returns The maximum. /// @returns The maximum.
@@ -44,7 +44,7 @@ namespace ehs
/// Sets a new amount for memory pre-allocation to save on memory operations. /// Sets a new amount for memory pre-allocation to save on memory operations.
/// @param[in] newStride The stride to pre-allocate. /// @param[in] newStride The stride to pre-allocate.
static void SetStride(const UInt_64 newStride); static void SetStride(UInt_64 newStride);
/// The amount of data pre-allocated to save on memory operations. /// The amount of data pre-allocated to save on memory operations.
/// @returns The stride. /// @returns The stride.

View File

@@ -1888,11 +1888,7 @@ namespace ehs
if (aSize != bSize) if (aSize != bSize)
return false; return false;
for (UInt_64 i = 0; i < aSize; ++i) return Util::Compare(a, b, aSize);
if (a[i] != b[i])
return false;
return true;
} }
}; };

View File

@@ -1,9 +1,7 @@
#pragma once #pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h" #include "ehs/Str.h"
#include "ehs/Vec2.h" #include "ehs/Vec2.h"
#include "ehs/Rect.h"
#include "ehs/io/hid/Input.h" #include "ehs/io/hid/Input.h"
namespace ehs namespace ehs
@@ -60,10 +58,6 @@ namespace ehs
bool HasFocus() const; bool HasFocus() const;
void EnableResizing(bool enable);
bool IsResizable() const;
/// Gets the cursors position on the desktop in pixels. /// Gets the cursors position on the desktop in pixels.
/// @param [in] relative Whether the position should be relative to the windows client. /// @param [in] relative Whether the position should be relative to the windows client.
/// @returns The current value. /// @returns The current value.

View File

@@ -4,21 +4,27 @@
#include <wayland-client.h> #include <wayland-client.h>
#include "xdg-shell-client-protocol.h" #include "xdg-shell-client-protocol.h"
#include "xdg-decoration.h"
namespace ehs namespace ehs
{ {
class Window : public BaseWindow class Window : public BaseWindow
{ {
private: protected:
wl_display* display; wl_display *display;
wl_registry *registry; wl_registry *registry;
wl_compositor* compositor; wl_compositor *compositor;
wl_surface* surface; wl_surface *wlSurface;
xdg_wm_base *xdgShell; xdg_wm_base *xdgShell;
xdg_surface *xdgSurface; xdg_surface *xdgSurface;
xdg_toplevel *xdgToplevel; xdg_toplevel *xdgToplevel;
zxdg_decoration_manager_v1 *decManager;
zxdg_toplevel_decoration_v1 *dec;
wl_seat *seat;
wl_pointer *pointer;
Vec2_u32 scale;
static void SurfaceConfigure(void *data, xdg_surface *xdg_surface, UInt_32 serial); static void SurfaceConfigEvent(void *data, xdg_surface *xdg_surface, UInt_32 serial);
static void ShellPing(void *data, xdg_wm_base *shell, UInt_32 serial); static void ShellPing(void *data, xdg_wm_base *shell, UInt_32 serial);
@@ -26,16 +32,32 @@ namespace ehs
static void RegistryRemoved(void *data, wl_registry *registry, UInt_32 id); static void RegistryRemoved(void *data, wl_registry *registry, UInt_32 id);
static void ResizeEvent(void *data, xdg_toplevel *xdg_toplevel, Int_32 width, Int_32 height, wl_array *states);
static void CloseEvent(void *data, xdg_toplevel *xdg_toplevel);
static void SeatCapabilitiesEvent(void *data, wl_seat *seat, UInt_32 capabilities);
static void PointerMotionEvent(void *data, wl_pointer *pointer, UInt_32 time, wl_fixed_t sx, wl_fixed_t sy);
public: public:
~Window() override; ~Window() override;
Window(); Window();
void Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) override; Window(Window &&win) noexcept;
void Create_16(const Str_16& title, const Vec2_s32& pos, const Vec2_u32 scale) override; Window(const Window &win);
void Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) override; Window &operator=(Window &&win) noexcept;
Window &operator=(const Window &win);
void Create_32(const Str_32& title, const Vec2_s32& pos, Vec2_u32 scale) override;
void Create_16(const Str_16& title, const Vec2_s32& pos, Vec2_u32 scale) override;
void Create_8(const Str_8& title, const Vec2_s32& pos, Vec2_u32 scale) override;
void OnCreated() override; void OnCreated() override;

View File

@@ -0,0 +1,18 @@
#pragma once
#include "Socket.h"
#include "ehs/Str.h"
namespace ehs
{
class BaseDNS
{
public:
static Str_8 Resolve(AddrType type, const Str_8 &hostname);
/// Resolves a hostname to an ip address.
/// @param [in] hostname The given hostname to resolve.
/// @returns The resulting ip address.
static Str_8 Resolve(const Str_8 &hostname);
};
}

View File

@@ -146,6 +146,10 @@ namespace ehs
/// @returns The result. /// @returns The result.
virtual bool IsBlocking() const = 0; virtual bool IsBlocking() const = 0;
virtual void SetIPv6Only(bool value) = 0;
virtual bool IsIPv6Only() const = 0;
/// Retrieves whether or not this socket was initialized. /// Retrieves whether or not this socket was initialized.
/// @returns The result. /// @returns The result.
virtual bool IsValid() const = 0; virtual bool IsValid() const = 0;

View File

@@ -69,6 +69,10 @@ namespace ehs
/// @returns The result. /// @returns The result.
virtual bool IsBlocking() const = 0; virtual bool IsBlocking() const = 0;
virtual void SetIPv6Only(bool value) = 0;
virtual bool IsIPv6Only() const = 0;
/// Retrieves the bound ip version. /// Retrieves the bound ip version.
/// @returns The result. /// @returns The result.
AddrType GetLocalAddressType() const; AddrType GetLocalAddressType() const;

View File

@@ -1,17 +1,9 @@
#pragma once #pragma once
#include "ehs/EHS.h" #include "ehs/system/OS.h"
#include "ehs/Str.h"
#include "Socket.h"
namespace ehs #if defined(EHS_OS_WINDOWS)
{ #include "DNS_W32.h"
class DNS #elif defined(EHS_OS_LINUX)
{ #include "DNS_LNX.h"
public: #endif
/// Resolves a hostname to an ip address.
/// @param [in] hostname The given hostname to resolve.
/// @returns The resulting ip address.
static Str_8 Resolve(const Str_8& hostname);
};
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "BaseDNS.h"
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "Socket.h"
namespace ehs
{
class DNS final : public BaseDNS
{
public:
static Str_8 Resolve(AddrType type, const Str_8 &hostname);
static Str_8 Resolve(const Str_8 &hostname);
};
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include "BaseDNS.h"
namespace ehs
{
class DNS final : public BaseDNS
{
public:
static Str_8 Resolve(AddrType type, const Str_8 &hostname);
static Str_8 Resolve(const Str_8 &hostname);
};
}

View File

@@ -80,6 +80,10 @@ namespace ehs
/// @returns The result. /// @returns The result.
bool IsBlocking() const override; bool IsBlocking() const override;
void SetIPv6Only(bool value) override;
bool IsIPv6Only() const override;
bool IsValid() const override; bool IsValid() const override;
private: private:

View File

@@ -80,6 +80,10 @@ namespace ehs
/// @returns The result. /// @returns The result.
bool IsBlocking() const override; bool IsBlocking() const override;
void SetIPv6Only(bool value) override;
bool IsIPv6Only() const override;
bool IsValid() const override; bool IsValid() const override;
private: private:

View File

@@ -68,6 +68,10 @@ namespace ehs
/// @returns The result. /// @returns The result.
bool IsBlocking() const override; bool IsBlocking() const override;
void SetIPv6Only(bool value) override;
bool IsIPv6Only() const override;
bool IsValid() const override; bool IsValid() const override;
private: private:

View File

@@ -68,6 +68,10 @@ namespace ehs
/// @returns The result. /// @returns The result.
bool IsBlocking() const override; bool IsBlocking() const override;
void SetIPv6Only(bool value) override;
bool IsIPv6Only() const override;
bool IsValid() const override; bool IsValid() const override;
private: private:

View File

@@ -21,7 +21,7 @@ namespace ehs
Str_8 id; Str_8 id;
}; };
class Spotify class Spotify final
{ {
private: private:
SSL client; SSL client;
@@ -40,14 +40,14 @@ namespace ehs
Spotify(); Spotify();
Spotify(const Str_8& clientId, const Str_8& secret, const Str_8& redURI, const Array<Str_8>& scopes, const bool forceVerify); Spotify(Str_8 clientId, Str_8 secret, Str_8 redURI, Array<Str_8> scopes, bool forceVerify);
bool Authorize(); bool Authorize();
/// Sets the volume for a device. /// Sets the volume for a device.
/// @param [in] level The percentage to set the volume to. /// @param [in] level The percentage to set the volume to.
/// @returns The response code. /// @returns The response code.
UInt_32 SetVolume(const UInt_8 level); UInt_32 SetVolume(UInt_8 level);
/// Resume playback for a device. /// Resume playback for a device.
/// @returns The response code. /// @returns The response code.
@@ -60,12 +60,12 @@ namespace ehs
/// Repeats playback for a device. /// Repeats playback for a device.
/// @param [in] status The status to set it to. /// @param [in] status The status to set it to.
/// @returns The response code. /// @returns The response code.
UInt_32 SetRepeat(const SpotifyState state); UInt_32 SetRepeat(SpotifyState state);
/// Shuffles playback for a device. /// Shuffles playback for a device.
/// @param [in] state The state to set shuffle to. /// @param [in] state The state to set shuffle to.
/// @returns The response code. /// @returns The response code.
UInt_32 SetShuffle(const bool state); UInt_32 SetShuffle(bool state);
UInt_32 SearchTrack(Vector<Str_8>& artists, Str_8& id, Str_8& name); UInt_32 SearchTrack(Vector<Str_8>& artists, Str_8& id, Str_8& name);
@@ -93,7 +93,7 @@ namespace ehs
/// Seeks to a position of the currently playing track in milliseconds. /// Seeks to a position of the currently playing track in milliseconds.
/// @param [in] pos The position in milliseconds to seek to. /// @param [in] pos The position in milliseconds to seek to.
/// @returns The response code. /// @returns The response code.
UInt_32 Seek(const UInt_32 pos); UInt_32 Seek(UInt_32 pos);
Str_8 GetClientId() const; Str_8 GetClientId() const;

View File

@@ -0,0 +1,377 @@
/* Generated by wayland-scanner 1.23.0 */
#ifndef XDG_DECORATION_UNSTABLE_V1_CLIENT_PROTOCOL_H
#define XDG_DECORATION_UNSTABLE_V1_CLIENT_PROTOCOL_H
#include <stdint.h>
#include <stddef.h>
#include "wayland-client.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @page page_xdg_decoration_unstable_v1 The xdg_decoration_unstable_v1 protocol
* @section page_ifaces_xdg_decoration_unstable_v1 Interfaces
* - @subpage page_iface_zxdg_decoration_manager_v1 - window decoration manager
* - @subpage page_iface_zxdg_toplevel_decoration_v1 - decoration object for a toplevel surface
* @section page_copyright_xdg_decoration_unstable_v1 Copyright
* <pre>
*
* 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.
* </pre>
*/
struct xdg_toplevel;
struct zxdg_decoration_manager_v1;
struct zxdg_toplevel_decoration_v1;
#ifndef ZXDG_DECORATION_MANAGER_V1_INTERFACE
#define ZXDG_DECORATION_MANAGER_V1_INTERFACE
/**
* @page page_iface_zxdg_decoration_manager_v1 zxdg_decoration_manager_v1
* @section page_iface_zxdg_decoration_manager_v1_desc Description
*
* 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.
* @section page_iface_zxdg_decoration_manager_v1_api API
* See @ref iface_zxdg_decoration_manager_v1.
*/
/**
* @defgroup iface_zxdg_decoration_manager_v1 The zxdg_decoration_manager_v1 interface
*
* 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.
*/
extern const struct wl_interface zxdg_decoration_manager_v1_interface;
#endif
#ifndef ZXDG_TOPLEVEL_DECORATION_V1_INTERFACE
#define ZXDG_TOPLEVEL_DECORATION_V1_INTERFACE
/**
* @page page_iface_zxdg_toplevel_decoration_v1 zxdg_toplevel_decoration_v1
* @section page_iface_zxdg_toplevel_decoration_v1_desc Description
*
* 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.
* @section page_iface_zxdg_toplevel_decoration_v1_api API
* See @ref iface_zxdg_toplevel_decoration_v1.
*/
/**
* @defgroup iface_zxdg_toplevel_decoration_v1 The zxdg_toplevel_decoration_v1 interface
*
* 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.
*/
extern const struct wl_interface zxdg_toplevel_decoration_v1_interface;
#endif
#define ZXDG_DECORATION_MANAGER_V1_DESTROY 0
#define ZXDG_DECORATION_MANAGER_V1_GET_TOPLEVEL_DECORATION 1
/**
* @ingroup iface_zxdg_decoration_manager_v1
*/
#define ZXDG_DECORATION_MANAGER_V1_DESTROY_SINCE_VERSION 1
/**
* @ingroup iface_zxdg_decoration_manager_v1
*/
#define ZXDG_DECORATION_MANAGER_V1_GET_TOPLEVEL_DECORATION_SINCE_VERSION 1
/** @ingroup iface_zxdg_decoration_manager_v1 */
static inline void
zxdg_decoration_manager_v1_set_user_data(struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) zxdg_decoration_manager_v1, user_data);
}
/** @ingroup iface_zxdg_decoration_manager_v1 */
static inline void *
zxdg_decoration_manager_v1_get_user_data(struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) zxdg_decoration_manager_v1);
}
static inline uint32_t
zxdg_decoration_manager_v1_get_version(struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1)
{
return wl_proxy_get_version((struct wl_proxy *) zxdg_decoration_manager_v1);
}
/**
* @ingroup iface_zxdg_decoration_manager_v1
*
* Destroy the decoration manager. This doesn't destroy objects created
* with the manager.
*/
static inline void
zxdg_decoration_manager_v1_destroy(struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1)
{
wl_proxy_marshal_flags((struct wl_proxy *) zxdg_decoration_manager_v1,
ZXDG_DECORATION_MANAGER_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zxdg_decoration_manager_v1), WL_MARSHAL_FLAG_DESTROY);
}
/**
* @ingroup iface_zxdg_decoration_manager_v1
*
* 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.
*/
static inline struct zxdg_toplevel_decoration_v1 *
zxdg_decoration_manager_v1_get_toplevel_decoration(struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1, struct xdg_toplevel *toplevel)
{
struct wl_proxy *id;
id = wl_proxy_marshal_flags((struct wl_proxy *) zxdg_decoration_manager_v1,
ZXDG_DECORATION_MANAGER_V1_GET_TOPLEVEL_DECORATION, &zxdg_toplevel_decoration_v1_interface, wl_proxy_get_version((struct wl_proxy *) zxdg_decoration_manager_v1), 0, NULL, toplevel);
return (struct zxdg_toplevel_decoration_v1 *) id;
}
#ifndef ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ENUM
#define ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ENUM
enum zxdg_toplevel_decoration_v1_error {
/**
* xdg_toplevel has a buffer attached before configure
*/
ZXDG_TOPLEVEL_DECORATION_V1_ERROR_UNCONFIGURED_BUFFER = 0,
/**
* xdg_toplevel already has a decoration object
*/
ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ALREADY_CONSTRUCTED = 1,
/**
* xdg_toplevel destroyed before the decoration object
*/
ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ORPHANED = 2,
};
#endif /* ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ENUM */
#ifndef ZXDG_TOPLEVEL_DECORATION_V1_MODE_ENUM
#define ZXDG_TOPLEVEL_DECORATION_V1_MODE_ENUM
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
* window decoration modes
*
* These values describe window decoration modes.
*/
enum zxdg_toplevel_decoration_v1_mode {
/**
* no server-side window decoration
*/
ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE = 1,
/**
* server-side window decoration
*/
ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE = 2,
};
#endif /* ZXDG_TOPLEVEL_DECORATION_V1_MODE_ENUM */
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
* @struct zxdg_toplevel_decoration_v1_listener
*/
struct zxdg_toplevel_decoration_v1_listener {
/**
* notify a decoration mode change
*
* The configure event configures the effective 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.
* @param mode the decoration mode
*/
void (*configure)(void *data,
struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1,
uint32_t mode);
};
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
*/
static inline int
zxdg_toplevel_decoration_v1_add_listener(struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1,
const struct zxdg_toplevel_decoration_v1_listener *listener, void *data)
{
return wl_proxy_add_listener((struct wl_proxy *) zxdg_toplevel_decoration_v1,
(void (**)(void)) listener, data);
}
#define ZXDG_TOPLEVEL_DECORATION_V1_DESTROY 0
#define ZXDG_TOPLEVEL_DECORATION_V1_SET_MODE 1
#define ZXDG_TOPLEVEL_DECORATION_V1_UNSET_MODE 2
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
*/
#define ZXDG_TOPLEVEL_DECORATION_V1_CONFIGURE_SINCE_VERSION 1
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
*/
#define ZXDG_TOPLEVEL_DECORATION_V1_DESTROY_SINCE_VERSION 1
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
*/
#define ZXDG_TOPLEVEL_DECORATION_V1_SET_MODE_SINCE_VERSION 1
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
*/
#define ZXDG_TOPLEVEL_DECORATION_V1_UNSET_MODE_SINCE_VERSION 1
/** @ingroup iface_zxdg_toplevel_decoration_v1 */
static inline void
zxdg_toplevel_decoration_v1_set_user_data(struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) zxdg_toplevel_decoration_v1, user_data);
}
/** @ingroup iface_zxdg_toplevel_decoration_v1 */
static inline void *
zxdg_toplevel_decoration_v1_get_user_data(struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) zxdg_toplevel_decoration_v1);
}
static inline uint32_t
zxdg_toplevel_decoration_v1_get_version(struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1)
{
return wl_proxy_get_version((struct wl_proxy *) zxdg_toplevel_decoration_v1);
}
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
*
* Switch back to a mode without any server-side decorations at the next
* commit.
*/
static inline void
zxdg_toplevel_decoration_v1_destroy(struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1)
{
wl_proxy_marshal_flags((struct wl_proxy *) zxdg_toplevel_decoration_v1,
ZXDG_TOPLEVEL_DECORATION_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) zxdg_toplevel_decoration_v1), WL_MARSHAL_FLAG_DESTROY);
}
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
*
* 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 an 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 an 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.
*/
static inline void
zxdg_toplevel_decoration_v1_set_mode(struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, uint32_t mode)
{
wl_proxy_marshal_flags((struct wl_proxy *) zxdg_toplevel_decoration_v1,
ZXDG_TOPLEVEL_DECORATION_V1_SET_MODE, NULL, wl_proxy_get_version((struct wl_proxy *) zxdg_toplevel_decoration_v1), 0, mode);
}
/**
* @ingroup iface_zxdg_toplevel_decoration_v1
*
* 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.
*/
static inline void
zxdg_toplevel_decoration_v1_unset_mode(struct zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1)
{
wl_proxy_marshal_flags((struct wl_proxy *) zxdg_toplevel_decoration_v1,
ZXDG_TOPLEVEL_DECORATION_V1_UNSET_MODE, NULL, wl_proxy_get_version((struct wl_proxy *) zxdg_toplevel_decoration_v1), 0);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,10 +1,20 @@
#include "ehs/io/Window_Way.h" #include "ehs/io/Window_Way.h"
#include <unistd.h>
#include <sys/mman.h>
#include "ehs/io/Console.h"
#include "ehs/io/xdg-shell-client-protocol.h"
namespace ehs namespace ehs
{ {
void Window::SurfaceConfigure(void* data, xdg_surface* xdg_surface, UInt_32 serial) void Window::SurfaceConfigEvent(void* data, xdg_surface* xdg_surface, UInt_32 serial)
{ {
xdg_surface_ack_configure(xdg_surface, serial); xdg_surface_ack_configure(xdg_surface, serial);
//Window* win = (Window *)data;
//wl_surface_commit(win->wlSurface);
} }
void Window::ShellPing(void* data, xdg_wm_base* shell, UInt_32 serial) void Window::ShellPing(void* data, xdg_wm_base* shell, UInt_32 serial)
@@ -14,43 +24,162 @@ namespace ehs
void Window::RegistryHandler(void* data, wl_registry* registry, UInt_32 id, const char* interface, UInt_32 version) void Window::RegistryHandler(void* data, wl_registry* registry, UInt_32 id, const char* interface, UInt_32 version)
{ {
Serializer<UInt_64>* ser = (Serializer<UInt_64>*)data; Window *win = (Window *)data;
if (Str_8::Cmp(interface, "wl_compositor")) if (Str_8::Cmp(interface, wl_compositor_interface.name))
{ win->compositor = (wl_compositor*)wl_registry_bind(registry, id, &wl_compositor_interface, 1);
ser->SetOffset(0); else if (Str_8::Cmp(interface, xdg_wm_base_interface.name))
wl_compositor** comp = ser->Read<wl_compositor**>(); win->xdgShell = (xdg_wm_base*)wl_registry_bind(registry, id, &xdg_wm_base_interface, 1);
*comp = (wl_compositor*)wl_registry_bind(registry, id, &wl_compositor_interface, 1); else if (Str_8::Cmp(interface, zxdg_decoration_manager_v1_interface.name))
} win->decManager = (zxdg_decoration_manager_v1*)wl_registry_bind(registry, id, &zxdg_decoration_manager_v1_interface, 1);
else if (Str_8::Cmp(interface, wl_seat_interface.name))
if (Str_8::Cmp(interface, "xdg_wm_base")) win->seat = (wl_seat *)wl_registry_bind(registry, id, &wl_seat_interface, 1);
{
ser->SetOffset(sizeof(void*));
xdg_wm_base** base = ser->Read<xdg_wm_base**>();
*base = (xdg_wm_base*)wl_registry_bind(registry, id, &xdg_wm_base_interface, 1);
}
} }
void Window::RegistryRemoved(void* data, wl_registry* registry, UInt_32 id) void Window::RegistryRemoved(void* data, wl_registry* registry, UInt_32 id)
{ {
} }
void Window::ResizeEvent(void *data, struct xdg_toplevel *xdg_toplevel, Int_32 width, Int_32 height, wl_array *states)
{
if (!width && !height)
return;
Window *win = (Window *)data;
win->scale = {(UInt_32)width, (UInt_32)height};
}
void Window::CloseEvent(void *data, xdg_toplevel *xdg_toplevel)
{
Window *win = (Window *)data;
win->Close();
}
void Window::SeatCapabilitiesEvent(void *data, wl_seat *seat, UInt_32 capabilities)
{
Window *win = (Window *)data;
if (capabilities & WL_SEAT_CAPABILITY_POINTER)
{
win->pointer = wl_seat_get_pointer(seat);
static const wl_pointer_listener pointer_listener = {
.motion = PointerMotionEvent
};
wl_pointer_add_listener(win->pointer, &pointer_listener, win);
}
}
void Window::PointerMotionEvent(void *data, wl_pointer *pointer, UInt_32 time, wl_fixed_t sx, wl_fixed_t sy)
{
EHS_LOG_INT(LogType::INFO, 0, "Pointer Pos: <" + Str_8::FromNum(wl_fixed_to_double(sx)) + ", " + Str_8::FromNum(wl_fixed_to_double(sy)) + ">");
}
Window::~Window() Window::~Window()
{ {
if (!created)
return;
zxdg_toplevel_decoration_v1_destroy(dec);
zxdg_decoration_manager_v1_destroy(decManager);
xdg_toplevel_destroy(xdgToplevel); xdg_toplevel_destroy(xdgToplevel);
xdg_surface_destroy(xdgSurface); xdg_surface_destroy(xdgSurface);
xdg_wm_base_destroy(xdgShell); xdg_wm_base_destroy(xdgShell);
wl_surface_destroy(surface); wl_surface_destroy(wlSurface);
wl_compositor_destroy(compositor); wl_compositor_destroy(compositor);
wl_registry_destroy(registry); wl_registry_destroy(registry);
wl_display_disconnect(display); wl_display_disconnect(display);
} }
Window::Window() Window::Window()
: display(nullptr), registry(nullptr), compositor(nullptr) , surface(nullptr) : display(nullptr), registry(nullptr), compositor(nullptr), wlSurface(nullptr), xdgShell(nullptr),
xdgSurface(nullptr), xdgToplevel(nullptr), decManager(nullptr), dec(nullptr), seat(nullptr), pointer(nullptr)
{ {
} }
Window::Window(Window &&win) noexcept
: BaseWindow(win), display(win.display), registry(win.registry), compositor(win.compositor),
wlSurface(win.wlSurface), xdgShell(win.xdgShell), xdgSurface(win.xdgSurface), xdgToplevel(win.xdgToplevel),
decManager(win.decManager), dec(win.dec), seat(win.seat), pointer(win.pointer)
{
win.display = nullptr;
win.registry = nullptr;
win.compositor = nullptr;
win.wlSurface = nullptr;
win.xdgShell = nullptr;
win.xdgSurface = nullptr;
win.xdgToplevel = nullptr;
win.decManager = nullptr;
win.dec = nullptr;
win.seat = nullptr;
win.pointer = nullptr;
}
Window::Window(const Window &win)
: BaseWindow(win), display(nullptr), registry(nullptr), compositor(nullptr), wlSurface(nullptr),
xdgShell(nullptr), xdgSurface(nullptr), xdgToplevel(nullptr), decManager(nullptr), dec(nullptr), seat(nullptr),
pointer(nullptr)
{
}
Window & Window::operator=(Window &&win) noexcept
{
if (this == &win)
return *this;
BaseWindow::operator=(win);
display = win.display;
registry = win.registry;
compositor = win.compositor;
wlSurface = win.wlSurface;
xdgShell = win.xdgShell;
xdgSurface = win.xdgSurface;
xdgToplevel = win.xdgToplevel;
decManager = win.decManager;
dec = win.dec;
seat = win.seat;
pointer = win.pointer;
win.display = nullptr;
win.registry = nullptr;
win.compositor = nullptr;
win.wlSurface = nullptr;
win.xdgShell = nullptr;
win.xdgSurface = nullptr;
win.xdgToplevel = nullptr;
win.decManager = nullptr;
win.dec = nullptr;
win.seat = nullptr;
win.pointer = nullptr;
return *this;
}
Window & Window::operator=(const Window &win)
{
if (this == &win)
return *this;
BaseWindow::operator=(win);
display = nullptr;
registry = nullptr;
compositor = nullptr;
wlSurface = nullptr;
xdgShell = nullptr;
xdgSurface = nullptr;
xdgToplevel = nullptr;
decManager = nullptr;
dec = nullptr;
seat = nullptr;
pointer = nullptr;
return *this;
}
void Window::Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale) void Window::Create_32(const Str_32& title, const Vec2_s32& pos, const Vec2_u32 scale)
{ {
Create_8(UTF::To_8(title), pos, scale); Create_8(UTF::To_8(title), pos, scale);
@@ -63,6 +192,9 @@ namespace ehs
void Window::Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale) void Window::Create_8(const Str_8& title, const Vec2_s32& pos, const Vec2_u32 scale)
{ {
if (created)
return;
display = wl_display_connect(nullptr); display = wl_display_connect(nullptr);
if (!display) if (!display)
{ {
@@ -70,17 +202,13 @@ namespace ehs
return; return;
} }
Serializer<UInt_64> data(Endianness::LE);
data.Write(&compositor);
data.Write(&xdgShell);
static constexpr wl_registry_listener registry_listener = { static constexpr wl_registry_listener registry_listener = {
RegistryHandler, .global = RegistryHandler,
RegistryRemoved .global_remove = RegistryRemoved
}; };
registry = wl_display_get_registry(display); registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, &registry_listener, &data); wl_registry_add_listener(registry, &registry_listener, this);
wl_display_dispatch(display); wl_display_dispatch(display);
wl_display_roundtrip(display); wl_display_roundtrip(display);
@@ -91,26 +219,68 @@ namespace ehs
return; return;
} }
static constexpr xdg_wm_base_listener xdg_shell_listener = {ShellPing}; static constexpr xdg_wm_base_listener xdg_shell_listener = {
.ping = ShellPing
};
xdg_wm_base_add_listener(xdgShell, &xdg_shell_listener, nullptr); xdg_wm_base_add_listener(xdgShell, &xdg_shell_listener, nullptr);
surface = wl_compositor_create_surface(compositor); wl_display_roundtrip(display);
if (!surface)
wlSurface = wl_compositor_create_surface(compositor);
if (!wlSurface)
{ {
EHS_LOG_INT(LogType::ERR, 2, "Can't create surface."); EHS_LOG_INT(LogType::ERR, 2, "Can't create surface.");
return; return;
} }
xdgSurface = xdg_wm_base_get_xdg_surface(xdgShell, surface); xdgSurface = xdg_wm_base_get_xdg_surface(xdgShell, wlSurface);
static constexpr xdg_surface_listener surfaceListener = {
.configure = SurfaceConfigEvent
};
xdg_surface_add_listener(xdgSurface, &surfaceListener, this);
wl_display_roundtrip(display);
xdgToplevel = xdg_surface_get_toplevel(xdgSurface); xdgToplevel = xdg_surface_get_toplevel(xdgSurface);
static constexpr xdg_surface_listener surfaceListener = {SurfaceConfigure}; static constexpr xdg_toplevel_listener topLevelListener = {
.configure = ResizeEvent,
.close = CloseEvent
};
xdg_surface_add_listener(xdgSurface, &surfaceListener, nullptr); xdg_toplevel_add_listener(xdgToplevel, &topLevelListener, this);
wl_display_roundtrip(display);
xdg_toplevel_set_title(xdgToplevel, title); xdg_toplevel_set_title(xdgToplevel, title);
wl_surface_commit(surface); xdg_toplevel_set_app_id(xdgToplevel, title);
wl_display_roundtrip(display);
dec = zxdg_decoration_manager_v1_get_toplevel_decoration(decManager, xdgToplevel);
zxdg_toplevel_decoration_v1_set_mode(dec, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
wl_display_roundtrip(display);
static constexpr wl_seat_listener seat_listener = {
.capabilities = SeatCapabilitiesEvent
};
wl_seat_add_listener(seat, &seat_listener, this);
wl_display_roundtrip(display);
wl_surface_commit(wlSurface);
wl_display_roundtrip(display);
this->scale = scale;
created = true;
OnCreated();
} }
void Window::OnCreated() void Window::OnCreated()
@@ -119,6 +289,15 @@ namespace ehs
void Window::Close() void Window::Close()
{ {
if (!created)
return;
zxdg_toplevel_decoration_v1_destroy(dec);
dec = nullptr;
zxdg_decoration_manager_v1_destroy(decManager);
decManager = nullptr;
xdg_toplevel_destroy(xdgToplevel); xdg_toplevel_destroy(xdgToplevel);
xdgToplevel = nullptr; xdgToplevel = nullptr;
@@ -128,8 +307,8 @@ namespace ehs
xdg_wm_base_destroy(xdgShell); xdg_wm_base_destroy(xdgShell);
xdgShell = nullptr; xdgShell = nullptr;
wl_surface_destroy(surface); wl_surface_destroy(wlSurface);
surface = nullptr; wlSurface = nullptr;
wl_compositor_destroy(compositor); wl_compositor_destroy(compositor);
compositor = nullptr; compositor = nullptr;
@@ -139,6 +318,8 @@ namespace ehs
wl_display_disconnect(display); wl_display_disconnect(display);
display = nullptr; display = nullptr;
created = false;
} }
void Window::Show() void Window::Show()
@@ -151,7 +332,11 @@ namespace ehs
bool Window::Poll() bool Window::Poll()
{ {
wl_display_dispatch(display); if (wl_display_dispatch_pending(display) == -1)
return false;
if (!created)
return false;
return true; return true;
} }
@@ -206,7 +391,7 @@ namespace ehs
Vec2_u32 Window::GetScale() const Vec2_u32 Window::GetScale() const
{ {
return {}; return scale;
} }
Serializer<UInt_64> Window::GetClipboard() Serializer<UInt_64> Window::GetClipboard()

18
src/io/socket/BaseDNS.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "ehs/io/socket/BaseDNS.h"
#include "ehs/Log.h"
namespace ehs
{
Str_8 BaseDNS::Resolve(const AddrType type, const Str_8 &hostname)
{
EHS_LOG_INT(LogType::ERR, 0, "Unsupported Operating System.");
return {};
}
Str_8 BaseDNS::Resolve(const Str_8 &hostname)
{
EHS_LOG_INT(LogType::ERR, 0, "Unsupported Operating System.");
return {};
}
}

View File

@@ -1,73 +0,0 @@
#include "ehs/io/socket/DNS.h"
#include "ehs/Log.h"
#if defined(EHS_OS_WINDOWS)
#include <WinSock2.h>
#include <WS2tcpip.h>
#elif defined(EHS_OS_LINUX)
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#endif
namespace ehs
{
Str_8 DNS::Resolve(const Str_8& hostname)
{
#if defined(EHS_OS_WINDOWS)
WSADATA data = {};
Int_32 wsaCode = WSAStartup(MAKEWORD(2, 2), &data);
if (wsaCode)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to start WSA with error #" + Str_8::FromNum(wsaCode) + ".");
return {};
}
#endif
addrinfo* result = nullptr;
Int_32 code = getaddrinfo(hostname, nullptr, nullptr, &result);
if (code)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + ".");
return {};
}
#if defined(EHS_OS_WINDOWS)
if (WSACleanup() == SOCKET_ERROR)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return {};
}
#endif
if (result->ai_family == AF_INET6)
{
Str_8 ipResult(INET6_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in6*)result->ai_addr)->sin6_addr, ipResult, INET6_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
return ipResult;
}
else if (result->ai_family == AF_INET)
{
Str_8 ipResult(INET_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in*)result->ai_addr)->sin_addr, ipResult, INET_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
return ipResult;
}
return {};
}
}

101
src/io/socket/DNS_LNX.cpp Normal file
View File

@@ -0,0 +1,101 @@
#include "ehs/io/socket/DNS_LNX.h"
#include "ehs/Log.h"
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
namespace ehs
{
Str_8 DNS::Resolve(const AddrType type, const Str_8 &hostname)
{
addrinfo* result = nullptr;
addrinfo req = {};
if (type == AddrType::IPV6)
req.ai_family = AF_INET6;
else if (type == AddrType::IPV4)
req.ai_family = AF_INET;
Int_32 code = getaddrinfo(hostname, nullptr, &req, &result);
if (code)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + ".");
return {};
}
if (result->ai_family == AF_INET6)
{
Str_8 ipResult(INET6_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in6*)result->ai_addr)->sin6_addr, ipResult, INET6_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
EHS_LOG_SUCCESS();
return ipResult;
}
else if (result->ai_family == AF_INET)
{
Str_8 ipResult(INET_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in*)result->ai_addr)->sin_addr, ipResult, INET_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
EHS_LOG_SUCCESS();
return ipResult;
}
return {};
}
Str_8 DNS::Resolve(const Str_8 &hostname)
{
addrinfo* result = nullptr;
Int_32 code = getaddrinfo(hostname, nullptr, nullptr, &result);
if (code)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + ".");
return {};
}
if (result->ai_family == AF_INET6)
{
Str_8 ipResult(INET6_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in6*)result->ai_addr)->sin6_addr, ipResult, INET6_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
EHS_LOG_SUCCESS();
return ipResult;
}
else if (result->ai_family == AF_INET)
{
Str_8 ipResult(INET_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in*)result->ai_addr)->sin_addr, ipResult, INET_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
EHS_LOG_SUCCESS();
return ipResult;
}
return {};
}
}

126
src/io/socket/DNS_W32.cpp Normal file
View File

@@ -0,0 +1,126 @@
#include "ehs/io/socket/DNS_W32.h"
#include "ehs/Log.h"
#include <WinSock2.h>
#include <WS2tcpip.h>
namespace ehs
{
Str_8 DNS::Resolve(const AddrType type, const Str_8 &hostname)
{
WSADATA data = {};
Int_32 wsaCode = WSAStartup(MAKEWORD(2, 2), &data);
if (wsaCode)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to start WSA with error #" + Str_8::FromNum(wsaCode) + ".");
return {};
}
addrinfo* result = nullptr;
addrinfo req = {};
if (type == AddrType::IPV6)
req.ai_family = AF_INET6;
else if (type == AddrType::IPV4)
req.ai_family = AF_INET;
Int_32 code = getaddrinfo(hostname, nullptr, &req, &result);
if (code)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + ".");
return {};
}
if (WSACleanup() == SOCKET_ERROR)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return {};
}
if (result->ai_family == AF_INET6)
{
Str_8 ipResult(INET6_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in6*)result->ai_addr)->sin6_addr, ipResult, INET6_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
EHS_LOG_SUCCESS();
return ipResult;
}
else if (result->ai_family == AF_INET)
{
Str_8 ipResult(INET_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in*)result->ai_addr)->sin_addr, ipResult, INET_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
EHS_LOG_SUCCESS();
return ipResult;
}
return {};
}
Str_8 DNS::Resolve(const Str_8 &hostname)
{
WSADATA data = {};
Int_32 wsaCode = WSAStartup(MAKEWORD(2, 2), &data);
if (wsaCode)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to start WSA with error #" + Str_8::FromNum(wsaCode) + ".");
return {};
}
addrinfo* result = nullptr;
Int_32 code = getaddrinfo(hostname, nullptr, nullptr, &result);
if (code)
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to resolve host with error #" + Str_8::FromNum(code) + ".");
return {};
}
if (WSACleanup() == SOCKET_ERROR)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return {};
}
if (result->ai_family == AF_INET6)
{
Str_8 ipResult(INET6_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in6*)result->ai_addr)->sin6_addr, ipResult, INET6_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
return ipResult;
}
else if (result->ai_family == AF_INET)
{
Str_8 ipResult(INET_ADDRSTRLEN);
inet_ntop(result->ai_family, &((sockaddr_in*)result->ai_addr)->sin_addr, ipResult, INET_ADDRSTRLEN);
ipResult.ExactSize();
freeaddrinfo(result);
return ipResult;
}
return {};
}
}

View File

@@ -1,5 +1,5 @@
#include "ehs/io/socket/TCP_BSD.h" #include "ehs/io/socket/TCP_BSD.h"
#include "ehs/io/socket/DNS.h" #include "ehs/io/socket/DNS_LNX.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -213,13 +213,23 @@ namespace ehs
return; return;
remoteHostName = address; remoteHostName = address;
remoteAddr = DNS::Resolve(address);
remotePort = port; remotePort = port;
if (addrType == AddrType::IPV6) if (addrType == AddrType::IPV6)
{
if (IsIPv6Only())
remoteAddr = DNS::Resolve(AddrType::IPV6, address);
else
remoteAddr = DNS::Resolve(address);
Connect_v6(remoteAddr, port); Connect_v6(remoteAddr, port);
}
else if (addrType == AddrType::IPV4) else if (addrType == AddrType::IPV4)
{
remoteAddr = DNS::Resolve(AddrType::IPV4, address);
Connect_v4(remoteAddr, port); Connect_v4(remoteAddr, port);
}
connected = true; connected = true;
} }
@@ -326,6 +336,55 @@ namespace ehs
return !(flags & O_NONBLOCK); return !(flags & O_NONBLOCK);
} }
void TCP::SetIPv6Only(const bool value)
{
if (addrType != AddrType::IPV6)
{
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
return;
}
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set IPv6 only mode while socket is not initialized.");
return;
}
const int result = (int)value;
if (setsockopt(hdl, IPPROTO_IPV6, IPV6_V6ONLY, &result, sizeof(int)) == -1)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to set IPv6 only mode with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool TCP::IsIPv6Only() const
{
if (addrType != AddrType::IPV6)
return false;
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set IPv6 only mode while socket is not initialized.");
return false;
}
int result;
socklen_t len = sizeof(int);
if (getsockopt(hdl, IPPROTO_IPV6, IPV6_V6ONLY, &result, &len) == -1)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to set IPv6 only mode with error #" + Str_8::FromNum(errno) + ".");
return false;
}
EHS_LOG_SUCCESS();
return result;
}
bool TCP::IsValid() const bool TCP::IsValid() const
{ {
return hdl != EHS_INVALID_SOCKET; return hdl != EHS_INVALID_SOCKET;

View File

@@ -242,13 +242,23 @@ namespace ehs
return; return;
remoteHostName = address; remoteHostName = address;
remoteAddr = DNS::Resolve(address);
remotePort = port; remotePort = port;
if (addrType == AddrType::IPV6) if (addrType == AddrType::IPV6)
{
if (IsIPv6Only())
remoteAddr = DNS::Resolve(AddrType::IPV6, address);
else
remoteAddr = DNS::Resolve(address);
Connect_v6(remoteAddr, port); Connect_v6(remoteAddr, port);
}
else if (addrType == AddrType::IPV4) else if (addrType == AddrType::IPV4)
{
remoteAddr = DNS::Resolve(AddrType::IPV4, address);
Connect_v4(remoteAddr, port); Connect_v4(remoteAddr, port);
}
connected = true; connected = true;
} }
@@ -347,6 +357,55 @@ namespace ehs
return (bool)r; return (bool)r;
} }
void TCP::SetIPv6Only(const bool value)
{
if (addrType != AddrType::IPV6)
{
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
return;
}
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set IPv6 only mode while socket is not initialized.");
return;
}
const int result = (int)value;
if (setsockopt(hdl, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&result, sizeof(int)) == -1)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to set IPv6 only mode with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool TCP::IsIPv6Only() const
{
if (addrType != AddrType::IPV6)
return false;
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set IPv6 only mode while socket is not initialized.");
return false;
}
int result;
socklen_t len = sizeof(int);
if (getsockopt(hdl, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&result, &len) == -1)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to set IPv6 only mode with error #" + Str_8::FromNum(errno) + ".");
return false;
}
EHS_LOG_SUCCESS();
return result;
}
bool TCP::IsValid() const bool TCP::IsValid() const
{ {
return hdl != EHS_INVALID_SOCKET; return hdl != EHS_INVALID_SOCKET;

View File

@@ -203,6 +203,55 @@ namespace ehs
return (bool)fcntl(hdl, F_GETFL, O_NONBLOCK); return (bool)fcntl(hdl, F_GETFL, O_NONBLOCK);
} }
void UDP::SetIPv6Only(const bool value)
{
if (type != AddrType::IPV6)
{
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
return;
}
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set IPv6 only mode while socket is not initialized.");
return;
}
const int result = (int)value;
if (setsockopt(hdl, IPPROTO_IPV6, IPV6_V6ONLY, &result, sizeof(int)) == -1)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to set IPv6 only mode with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool UDP::IsIPv6Only() const
{
if (type != AddrType::IPV6)
return false;
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set IPv6 only mode while socket is not initialized.");
return false;
}
int result;
socklen_t len = sizeof(int);
if (getsockopt(hdl, IPPROTO_IPV6, IPV6_V6ONLY, &result, &len) == -1)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to set IPv6 only mode with error #" + Str_8::FromNum(errno) + ".");
return false;
}
EHS_LOG_SUCCESS();
return result;
}
bool UDP::IsValid() const bool UDP::IsValid() const
{ {
return hdl != EHS_INVALID_SOCKET; return hdl != EHS_INVALID_SOCKET;

View File

@@ -223,6 +223,55 @@ namespace ehs
return (bool)r; return (bool)r;
} }
void UDP::SetIPv6Only(const bool value)
{
if (type != AddrType::IPV6)
{
EHS_LOG_INT(LogType::WARN, 0, "Cannot set IPv6 only mode while socket is not using IPv6.");
return;
}
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set IPv6 only mode while socket is not initialized.");
return;
}
const int result = (int)value;
if (setsockopt(hdl, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)&result, sizeof(int)) == -1)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to set IPv6 only mode with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool UDP::IsIPv6Only() const
{
if (type != AddrType::IPV6)
return false;
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 1, "Attempted to set IPv6 only mode while socket is not initialized.");
return false;
}
int result;
socklen_t len = sizeof(int);
if (getsockopt(hdl, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&result, &len) == -1)
{
EHS_LOG_INT(LogType::ERR, 2, "Failed to set IPv6 only mode with error #" + Str_8::FromNum(errno) + ".");
return false;
}
EHS_LOG_SUCCESS();
return result;
}
bool UDP::IsValid() const bool UDP::IsValid() const
{ {
return hdl != EHS_INVALID_SOCKET; return hdl != EHS_INVALID_SOCKET;

View File

@@ -1,5 +1,5 @@
#include "ehs/io/socket/rest/Spotify.h" #include "ehs/io/socket/rest/Spotify.h"
#include "ehs/io/socket/DNS.h" #include "ehs/io/socket/DNS_LNX.h"
#include "ehs/system/System.h" #include "ehs/system/System.h"
#include "ehs/URI.h" #include "ehs/URI.h"
@@ -17,8 +17,9 @@ namespace ehs
{ {
} }
Spotify::Spotify(const Str_8& clientId, const Str_8& secret, const Str_8& redURI, const Array<Str_8>& scopes, const bool forceVerify) Spotify::Spotify(Str_8 clientId, Str_8 secret, Str_8 redURI, Array<Str_8> scopes, const bool forceVerify)
: client(AddrType::IPV4), clientId(clientId), secret(secret), redURI(redURI), scopes(scopes), forceVerify(forceVerify) : client(AddrType::IPV4), clientId((Str_8 &&)clientId), secret((Str_8 &&)secret), redURI((Str_8 &&)redURI),
scopes((Array<Str_8> &&)scopes), forceVerify(forceVerify)
{ {
} }
@@ -42,7 +43,7 @@ namespace ehs
TCP server(AddrType::IPV4); TCP server(AddrType::IPV4);
server.Initialize(); server.Initialize();
server.Bind(DNS::Resolve("localhost"), 65534); server.Bind("", 65534);
server.Listen(); server.Listen();
System::OpenURI(uri); System::OpenURI(uri);
@@ -155,9 +156,6 @@ namespace ehs
Request req(Verb::PUT, "/v1/me/player/play"); Request req(Verb::PUT, "/v1/me/player/play");
req.BearerAuth(token); req.BearerAuth(token);
client.Release();
client.Initialize();
client.Connect("", SSL::HTTPS_Port);
client.SendReq(req); client.SendReq(req);
Response res = client.RecvRes(); Response res = client.RecvRes();
@@ -590,7 +588,7 @@ namespace ehs
bool Spotify::ReAuthorize() bool Spotify::ReAuthorize()
{ {
SSL accounts; SSL accounts(AddrType::IPV4);
accounts.Initialize(); accounts.Initialize();
accounts.Connect("accounts.spotify.com", SSL::HTTPS_Port); accounts.Connect("accounts.spotify.com", SSL::HTTPS_Port);

View File

@@ -1,5 +1,5 @@
#include "ehs/io/socket/rest/Twitch.h" #include "ehs/io/socket/rest/Twitch.h"
#include "ehs/io/socket/DNS.h" #include "ehs/io/socket/DNS_LNX.h"
#include "ehs/system/System.h" #include "ehs/system/System.h"
#include "ehs/URI.h" #include "ehs/URI.h"
@@ -39,7 +39,7 @@ namespace ehs
scopesFinal; scopesFinal;
TCP server(AddrType::IPV4); TCP server(AddrType::IPV4);
server.Bind(DNS::Resolve("localhost"), 65535); server.Bind("", 65535);
server.Listen(); server.Listen();
System::OpenURI(uri); System::OpenURI(uri);

View File

@@ -1,5 +1,5 @@
#include "ehs/io/socket/rest/TwitchChat.h" #include "ehs/io/socket/rest/TwitchChat.h"
#include "ehs/io/socket/DNS.h" #include "ehs/io/socket/DNS_LNX.h"
#include "ehs/io/Console.h" #include "ehs/io/Console.h"
namespace ehs namespace ehs

76
src/io/xdg-decoration.c Normal file
View File

@@ -0,0 +1,76 @@
/* Generated by wayland-scanner 1.23.0 */
/*
* 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.
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface xdg_toplevel_interface;
extern const struct wl_interface zxdg_toplevel_decoration_v1_interface;
static const struct wl_interface *xdg_decoration_unstable_v1_types[] = {
NULL,
&zxdg_toplevel_decoration_v1_interface,
&xdg_toplevel_interface,
};
static const struct wl_message zxdg_decoration_manager_v1_requests[] = {
{ "destroy", "", xdg_decoration_unstable_v1_types + 0 },
{ "get_toplevel_decoration", "no", xdg_decoration_unstable_v1_types + 1 },
};
WL_PRIVATE const struct wl_interface zxdg_decoration_manager_v1_interface = {
"zxdg_decoration_manager_v1", 1,
2, zxdg_decoration_manager_v1_requests,
0, NULL,
};
static const struct wl_message zxdg_toplevel_decoration_v1_requests[] = {
{ "destroy", "", xdg_decoration_unstable_v1_types + 0 },
{ "set_mode", "u", xdg_decoration_unstable_v1_types + 0 },
{ "unset_mode", "", xdg_decoration_unstable_v1_types + 0 },
};
static const struct wl_message zxdg_toplevel_decoration_v1_events[] = {
{ "configure", "u", xdg_decoration_unstable_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface zxdg_toplevel_decoration_v1_interface = {
"zxdg_toplevel_decoration_v1", 1,
3, zxdg_toplevel_decoration_v1_requests,
1, zxdg_toplevel_decoration_v1_events,
};