Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rudimentary Wayland Support #260

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# If we are a computer with nix-shell available, then use that to setup
# the build environment with exactly what we need.
if has nix; then
use nix
fi
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ docs/apidocs
/macos/cmake-build-debug

# jvm crash logs
hs_err_*.log
hs_err_*.log

experiments/
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if(APPLE)
endif()

if (UNIX AND NOT APPLE)
add_subdirectory(linux)
add_subdirectory(x11)
add_subdirectory(wayland)
message(STATUS "Configure linux platform module")
endif()
endif()
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
let
name = "JWM";
description = "Cross-platform window management and OS integration library for Java";
in
{
inherit name description;

inputs = {
nixpkgs.url = github:nixos/nixpkgs/release-22.05;
flake-utils.url = github:numtide/flake-utils;

# Used for shell.nix
flake-compat = {
url = github:edolstra/flake-compat;
flake = false;
};
};

outputs = {self, nixpkgs, flake-utils, ...} @ inputs:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {inherit system;};
xDependencies = with pkgs; with xorg; [
xorgserver

# development lib
libX11

# xorg input modules
xf86inputevdev
xf86inputsynaptics
xf86inputlibinput

# dyn libs
libXrandr
libXcursor
libXi
];

waylandDependencies = with pkgs; [
wayland
];
in rec {
devShells.default = pkgs.mkShell {
inherit name description;
nativeBuildInputs = with pkgs; [
jdk17
] ++ xDependencies ++ waylandDependencies;

buildInputs = with pkgs; [
python3
libGL
ninja
cmake
gcc
];

CMAKE_MAKE_PROGRAM = pkgs.ninja;
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (with pkgs; [ libGL ] ++ xDependencies ++ waylandDependencies)}:$LD_LIBRARY_PATH";
};

# For compatibility with older versions of the `nix` binary
devShell = self.devShells.${system}.default;
}
);
}
19 changes: 16 additions & 3 deletions script/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! /usr/bin/env python3
import argparse, build_utils, common, glob, os, platform, subprocess, sys

def build_native():
os.chdir(common.basedir + "/" + build_utils.system)
def build_native_system(system):
os.chdir(common.basedir + "/" + system)
subprocess.check_call(["cmake",
"-DCMAKE_BUILD_TYPE=Release",
"-B", "build",
Expand All @@ -25,9 +25,22 @@ def build_native():

return 0

def build_native():
# TODO: There is likely a better folder hierarchy than this.
cur_system = build_utils.system;
if cur_system == "linux":
build_native_system("x11")
build_native_system("wayland")
else:
build_native_system(cur_system)

return 0



def build_java():
os.chdir(common.basedir)
sources = build_utils.files("linux/java/**/*.java", "macos/java/**/*.java", "shared/java/**/*.java", "windows/java/**/*.java",)
sources = build_utils.files("x11/java/**/*.java", "wayland/java/**/*.java", "macos/java/**/*.java", "shared/java/**/*.java", "windows/java/**/*.java",)
build_utils.javac(sources, "target/classes", classpath=common.deps_compile())
return 0

Expand Down
3 changes: 3 additions & 0 deletions shared/java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void start(@NotNull Runnable launcher) {
Log.setVerbose("true".equals(System.getenv("JWM_VERBOSE")));
long t0 = System.currentTimeMillis();
Log.setLogger((s) -> System.out.println("[ " + (System.currentTimeMillis() - t0) + " ] " + s));
Platform.update();
launcher.run();
});
}
Expand All @@ -52,6 +53,8 @@ else if (Platform.CURRENT == Platform.MACOS)
window = new WindowMac();
else if (Platform.CURRENT == Platform.X11)
window = new WindowX11();
else if (Platform.CURRENT == Platform.WAYLAND)
window = new WindowWayland();
else
throw new RuntimeException("Unsupported platform: " + Platform.CURRENT);
_windows.add(window);
Expand Down
19 changes: 16 additions & 3 deletions shared/java/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

public enum Platform {
WINDOWS,
MACOS,
X11,
MACOS;
WAYLAND;

public static final Platform CURRENT;
public static Platform CURRENT;
static {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("mac") || os.contains("darwin"))
Expand All @@ -17,4 +18,16 @@ else if (os.contains("nux") || os.contains("nix"))
else
throw new RuntimeException("Unsupported platform: " + os);
}
}

// Dynamically update the platform name.
// As systems can support both X11 and Wayland,
// we suppport identifying the platform at runtime here.
public static void update() {
// X11 is Linux by default, so we fall back to it.
if (Platform.CURRENT == Platform.X11) {
String sessionType = System.getenv("XDG_SESSION_TYPE");
if (sessionType.equals("wayland"))
CURRENT = WAYLAND;
}
}
}
12 changes: 12 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import
(
let
flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat;
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz";
sha256 = flake-compat.locked.narHash;
}
)
{src = ./.;})
.shellNix
41 changes: 41 additions & 0 deletions wayland/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.9)

# prefer the newer GL library (GLVND)
cmake_policy(SET CMP0072 NEW)

project(jwm LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT JWM_ARCH)
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64")
set(JWM_ARCH "arm64")
else()
set(JWM_ARCH "x64")
endif()
endif()

find_package(X11 REQUIRED)
find_package(OpenGL REQUIRED)

file(GLOB SOURCES_CXX ${CMAKE_CURRENT_LIST_DIR}/../shared/cc/*.cc ${CMAKE_CURRENT_LIST_DIR}/cc/*.cc)
file(GLOB SOURCES_CXX_IMPL ${CMAKE_CURRENT_LIST_DIR}/../shared/cc/impl/*.cc)
add_library(jwm SHARED ${SOURCES_OBJC} ${SOURCES_CXX} ${SOURCES_CXX_IMPL})

set(JAVA_HOME $ENV{JAVA_HOME})
if (NOT JAVA_HOME)
file(GLOB JAVA_HOMES "/usr/lib/jvm/java-*")
if (JAVA_HOMES)
list(GET JAVA_HOMES 0 JAVA_HOME)
message(STATUS "Java home found automatically at ${JAVA_HOME}. Set JAVA_HOME environment variable to override.")
else()
message(FATAL_ERROR "Java home not found! Please set JAVA_HOME environment variable.")
endif()
endif()

target_include_directories(jwm PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../shared/cc ${JAVA_HOME}/include ${JAVA_HOME}/include/linux)
set_target_properties(jwm PROPERTIES OUTPUT_NAME "jwm_${JWM_ARCH}")


target_link_libraries(jwm PRIVATE X11::X11 X11::Xrandr X11::Xcursor X11::Xi)
target_link_libraries(jwm PRIVATE OpenGL::GL)
Loading