commit 3dabb7149de6e2145296967fd57e2e978a1a66b2 Author: Florian RICHER Date: Wed Jun 5 21:07:23 2024 +0200 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..9534c33 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Tutorial + +- https://wayland-book.com/ + +## Compiling + +Server +```bash +cc -o server server.c -lwayland-server +``` + +Client +```bash +cc -o client client.c -lwayland-client +``` + +## Run + +Server +```bash +./server & +``` + +Client + +```bash +WAYLAND_DISPLAY=wayland-1 ./client +``` diff --git a/client.cpp b/client.cpp new file mode 100644 index 0000000..a674f1f --- /dev/null +++ b/client.cpp @@ -0,0 +1,15 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + struct wl_display *display = wl_display_connect(NULL); + if (!display) { + fprintf(stderr, "Failed to connect to Wayland display.\n"); + return 1; + } + fprintf(stderr, "Connection established!\n"); + + wl_display_disconnect(display); + return 0; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e8bbef9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1717399147, + "narHash": "sha256-eCWaE/q1VItpFAxxLVt171MdtDcjEnwi6QB/yuF73JU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "4a4ecb0ab415c9fccfb005567a215e6a9564cdf5", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6e5f3bc --- /dev/null +++ b/flake.nix @@ -0,0 +1,27 @@ +{ + description = "Wayland dev environment"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachSystem flake-utils.lib.allSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + devShells = { + default = pkgs.mkShell { + packages = with pkgs; [ + pkg-config + imagemagick + wayland-scanner + wayland + wayland-protocol + ]; + }; + }; + }); +} diff --git a/server.cpp b/server.cpp new file mode 100644 index 0000000..6904579 --- /dev/null +++ b/server.cpp @@ -0,0 +1,23 @@ +#include +#include + +int main(int argc, char *argv[]) +{ + struct wl_display *display = wl_display_create(); + if (!display) { + fprintf(stderr, "Unable to create Wayland display.\n"); + return 1; + } + + const char *socket = wl_display_add_socket_auto(display); + if (!socket) { + fprintf(stderr, "Unable to add socket to Wayland display.\n"); + return 1; + } + + fprintf(stderr, "Running Wayland display on %s\n", socket); + wl_display_run(display); + + wl_display_destroy(display); + return 0; +}